trieste.acquisition.sampler#

This module is the home of the sampling functionality required by Trieste’s acquisition functions.

Module Contents#

class ThompsonSampler(sample_min_value: bool = False)[source]#

Bases: abc.ABC, Generic[trieste.models.interfaces.ProbabilisticModelType]

A ThompsonSampler samples either the minimum values or minimisers of a function modeled by an underlying ProbabilisticModel across a discrete set of points.

Sample_min_value

If True then sample from the minimum value of the function, else sample the function’s minimiser.

abstract sample(model: trieste.models.interfaces.ProbabilisticModelType, sample_size: int, at: trieste.types.TensorType, select_output: Callable[[trieste.types.TensorType], trieste.types.TensorType] = select_nth_output)trieste.types.TensorType[source]#
Parameters
  • model – The model to sample from.

  • sample_size – The desired number of samples.

  • at – Input points that define the sampler.

  • select_output – A method that returns the desired output from the model sampler, with shape [S, N] where S is the number of samples and N is the number of locations. Defaults to the :func:~`trieste.acquisition.utils.select_nth_output` function with output dimension 0.

Returns

Samples.

class ExactThompsonSampler(sample_min_value: bool = False)[source]#

Bases: ThompsonSampler[trieste.models.ProbabilisticModel]

This sampler provides exact Thompson samples of the objective function’s minimiser \(x^*\) over a discrete set of input locations. Although exact Thompson sampling is costly (incuring with an \(O(N^3)\) complexity to sample over a set of N locations), this method can be used for any probabilistic model with a sampling method.

Sample_min_value

If True then sample from the minimum value of the function, else sample the function’s minimiser.

sample(model: trieste.models.ProbabilisticModel, sample_size: int, at: trieste.types.TensorType, select_output: Callable[[trieste.types.TensorType], trieste.types.TensorType] = select_nth_output)trieste.types.TensorType[source]#

Return exact samples from either the objective function’s minimiser or its minimal value over the candidate set at.

Parameters
  • model – The model to sample from.

  • sample_size – The desired number of samples.

  • at – Where to sample the predictive distribution, with shape [N, D], for points of dimension D.

  • select_output – A method that returns the desired output from the model sampler, with shape [S, N] where S is the number of samples and N is the number of locations. Defaults to the :func:~`trieste.acquisition.utils.select_nth_output` function with output dimension 0.

Returns

The samples, of shape [S, D] (where S is the sample_size) if sampling the function’s minimiser or shape [S, 1] if sampling the function’s mimimal value.

Raises

ValueError – If at has an invalid shape or if sample_size is not positive.

class GumbelSampler(sample_min_value: bool = False)[source]#

Bases: ThompsonSampler[trieste.models.ProbabilisticModel]

This sampler follows [WJ17] and yields approximate samples of the objective minimum value \(y^*\) via the empirical cdf \(\operatorname{Pr}(y^*<y)\). The cdf is approximated by a Gumbel distribution .. math:: mathcal G(y; a, b) = 1 - e^{-e^frac{y - a}{b}} where \(a, b \in \mathbb R\) are chosen such that the quartiles of the Gumbel and cdf match. Samples are obtained via the Gumbel distribution by sampling \(r\) uniformly from \([0, 1]\) and applying the inverse probability integral transform \(y = \mathcal G^{-1}(r; a, b)\). Note that the GumbelSampler can only sample a function’s minimal value and not its minimiser.

Sample_min_value

If True then sample from the minimum value of the function, else sample the function’s minimiser.

sample(model: trieste.models.ProbabilisticModel, sample_size: int, at: trieste.types.TensorType, select_output: Callable[[trieste.types.TensorType], trieste.types.TensorType] = select_nth_output)trieste.types.TensorType[source]#

Return approximate samples from of the objective function’s minimum value.

Parameters
  • model – The model to sample from.

  • sample_size – The desired number of samples.

  • at – Points at where to fit the Gumbel distribution, with shape [N, D], for points of dimension D. We recommend scaling N with search space dimension.

  • select_output – A method that returns the desired output from the model sampler, with shape [S, N] where S is the number of samples and N is the number of locations. Currently unused.

Returns

The samples, of shape [S, 1], where S is the sample_size.

Raises

ValueError – If at has an invalid shape or if sample_size is not positive.

class ThompsonSamplerFromTrajectory(sample_min_value: bool = False)[source]#

Bases: ThompsonSampler[trieste.models.interfaces.HasTrajectorySampler]

This sampler provides approximate Thompson samples of the objective function’s minimiser \(x^*\) by minimizing approximate trajectories sampled from the underlying probabilistic model. This sampling method can be used for any probabilistic model with a trajectory_sampler() method.

Sample_min_value

If True then sample from the minimum value of the function, else sample the function’s minimiser.

sample(model: trieste.models.ProbabilisticModel, sample_size: int, at: trieste.types.TensorType, select_output: Callable[[trieste.types.TensorType], trieste.types.TensorType] = select_nth_output)trieste.types.TensorType[source]#

Return approximate samples from either the objective function’s minimser or its minimal value over the candidate set at.

Parameters
  • model – The model to sample from.

  • sample_size – The desired number of samples.

  • at – Where to sample the predictive distribution, with shape [N, D], for points of dimension D.

  • select_output – A method that returns the desired output from the model sampler, with shape [S, N] where S is the number of samples and N is the number of locations. Defaults to the :func:~`trieste.acquisition.utils.select_nth_output` function with output dimension 0.

Returns

The samples, of shape [S, D] (where S is the sample_size) if sampling the function’s minimser or shape [S, 1] if sampling the function’s mimimal value.

Raises

ValueError – If at has an invalid shape or if sample_size is not positive.