Skip to content

Thompson Sampling

ThompsonSampling dataclass

ThompsonSampling(num_features=100)

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_objective_present(posteriors, datasets)

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

build_utility_function(posteriors, datasets, key)

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.