Neural Linear Bandit
NeuralLinearBandit(network, buffer, n_embedding_size, min_samples_required_for_training=1024, selector=None, train_batch_size=32, lazy_uncertainty_update=False, lambda_=1.0, eps=0.01, weight_decay=0.0, learning_rate=0.001, learning_rate_decay=1.0, learning_rate_scheduler_step_size=1, early_stop_threshold=0.001, initial_train_steps=1024, contextualization_after_network=False, n_arms=None, warm_start=True)
Bases: LinearTSBandit[ActionInputType]
Lightning Module implementing a Neural Linear bandit.
A Neural Linear bandit model consists of a neural network that produces embeddings of the input data and a linear
head that is trained on the embeddings. Since updating the neural network which encodes the inputs into embeddings
is computationally expensive, the neural network is only updated once more than min_samples_required_for_training
samples have been collected. Otherwise, only the linear head is updated.
ActionInputType
The type of the input data to the neural network. Can be a single tensor or a tuple of tensors.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
network
|
Module
|
The neural network to be used to encode the input data into an embedding. |
required |
buffer
|
AbstractBanditDataBuffer[ActionInputType, Any] | None
|
The buffer used for storing the data for continuously updating the neural network and storing the embeddings for the linear head. |
required |
n_embedding_size
|
int
|
The size of the embedding produced by the neural network. Must be greater than 0.
If |
required |
selector
|
AbstractSelector | None
|
The selector used to choose the best action. Default is |
None
|
train_batch_size
|
int
|
The batch size for the neural network update. Must be greater than 0. |
32
|
min_samples_required_for_training
|
int | None
|
The interval (in steps) at which the neural network is updated. None means the neural network is never updated. If not None, it must be greater than 0. Must Default is 1024. |
1024
|
lazy_uncertainty_update
|
bool
|
If |
False
|
lambda_
|
float
|
The regularization parameter for the linear head. Must be greater than 0. |
1.0
|
eps
|
float
|
Small value to ensure invertibility of the precision matrix. Added to the diagonal. Must be greater than 0. |
0.01
|
learning_rate
|
float
|
The learning rate for the optimizer of the neural network.
Passed to |
0.001
|
weight_decay
|
float
|
The regularization parameter for the neural network.
Passed to |
0.0
|
learning_rate_decay
|
float
|
Multiplicative factor for learning rate decay.
Passed to |
1.0
|
learning_rate_scheduler_step_size
|
int
|
The step size for the learning rate decay.
Passed to |
1
|
early_stop_threshold
|
float | None
|
Loss threshold for early stopping. None to disable. Must be greater equal 0. |
0.001
|
initial_train_steps
|
int
|
Number of initial training steps (in samples). Defaults to 1024. Must be greater equal 0. |
1024
|
contextualization_after_network
|
bool
|
If |
False
|
n_arms
|
int | None
|
The number of arms to contextualize after the network. Only needed if
|
None
|
warm_start
|
bool
|
If |
True
|
Source code in src/calvera/bandits/neural_linear_bandit.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
|
HelperNetwork(network, output_size, contextualizer=None)
Bases: Module
A helper network that is used to train the neural network of the NeuralLinearBandit
.
It adds a linear head to the neural network which mocks the linear head of the NeuralLinearBandit
,
hence the single output dimension of the linear layer.
This allows for training an embedding which is useful for the linear head of the NeuralLinearBandit
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
network
|
Module
|
The neural network to be used to encode the input data into an embedding. |
required |
output_size
|
int
|
The size of the output of the neural network. |
required |
contextualizer
|
MultiClassContextualizer | None
|
If provided disjoint model contextualization will be applied to the embeddings. |
None
|