Thompson Sampling
ThompsonSampling
dataclass
Bases: AbstractSinglePointUtilityFunctionBuilder
Form a utility function by drawing an approximate sample from the posterior, using decoupled sampling as introduced in Wilson et. al. (2020). Note that we return the negative of the sample as the utility function, as utility functions are maximised.
Note that this is a single batch utility function, as it doesn't support classical
batching. However, Thompson sampling can be used in a batched setting by drawing a
batch of different samples from the GP posterior. This can be done by calling
build_utility_function
with different keys, an example of which can be seen in the
ask
method of the UtilityDrivenDecisionMaker
class. The samples can then be
optimised sequentially.
Attributes:
-
num_features
(int
) βThe number of random Fourier features to use when drawing the approximate sample from the posterior. Defaults to 100.
check_objective_present
Check that the objective posterior and dataset are present in the posteriors and datasets.
Parameters:
-
posteriors
(Mapping[str, AbstractPosterior]
) βdictionary of posteriors to be used to form the utility function.
-
datasets
(Mapping[str, Dataset]
) βdictionary of datasets which may be used to form the utility function.
Raises:
-
ValueError
βIf the objective posterior or dataset are not present in the posteriors or datasets.
build_utility_function
Draw an approximate sample from the posterior of the objective model and return the negative of this sample as a utility function, as utility functions are maximised.
Parameters:
-
posteriors
(Mapping[str, ConjugatePosterior]
) βDictionary of posteriors to
-
datasets
(Mapping[str, Dataset]
) βDictionary of datasets which may be used
-
key
(KeyArray
) βJAX PRNG key used for random number generation. This can be
Returns:
-
SinglePointUtilityFunction
(SinglePointUtilityFunction
) βAn appproximate sample from the objective model posterior to to be maximised in order to decide which point to query next.