trieste.acquisition
#
The acquisition process aims to find the optimal point(s) at which to next evaluate the objective function, with the aim of minimising it. The functionality in this package implements that process. It typically uses the current observations of the objective function, or a posterior over those observations.
In this library, the acquisition rule is the central object of the API, while acquisition functions are supplementary. This is because some acquisition rules, such as Thompson sampling, do not require an acquisition function. This contrasts with other libraries which may consider the acquisition function as the central component of this process and assume Efficient Global Optimization (EGO) for the acquisition rule.
This package contains acquisition rules, as implementations of
AcquisitionRule
, and acquisition functions. It also contains
AcquisitionFunctionBuilder
s which provide a common interface for the rules to build
acquisition functions.
Acquisition rules in this library that use acquisition functions, such as
EfficientGlobalOptimization
, maximize these functions. This defines the sign the
acquisition function should take. Additionally, acquisition functions and builders in this library
are designed to minimize the objective function. For example, we do not provide an implementation of
UCB.
Submodules#
Package Contents#
-
class
Product
(*builders: trieste.acquisition.interface.AcquisitionFunctionBuilder[trieste.models.ProbabilisticModel])[source]# Bases:
Reducer
Reducer
whose resulting acquisition function returns the element-wise product of the outputs of constituent acquisition functions.- Parameters
*builders – Acquisition function builders. At least one must be provided.
- Raises
InvalidArgumentError – If no builders are specified.
-
_reduce
(inputs: collections.abc.Sequence[trieste.types.TensorType]) → trieste.types.TensorType# - Parameters
inputs – The outputs of each acquisition function.
- Returns
The element-wise product of the
inputs
.
-
class
Reducer
(*builders: trieste.acquisition.interface.AcquisitionFunctionBuilder[trieste.models.ProbabilisticModel])[source]# Bases:
trieste.acquisition.interface.AcquisitionFunctionBuilder
[trieste.models.ProbabilisticModel
]A
Reducer
builds anAcquisitionFunction
whose output is calculated from the outputs of a number of otherAcquisitionFunction
s. How these outputs are composed is defined by the method_reduce()
.- Parameters
*builders – Acquisition function builders. At least one must be provided.
- Raises
InvalidArgumentError – If no builders are specified.
-
prepare_acquisition_function
(models: collections.abc.Mapping[trieste.types.Tag, trieste.models.ProbabilisticModel], datasets: Optional[collections.abc.Mapping[trieste.types.Tag, trieste.data.Dataset]] = None) → trieste.acquisition.interface.AcquisitionFunction# Return an acquisition function. This acquisition function is defined by first building acquisition functions from each of the
AcquisitionFunctionBuilder
s specified at__init__()
, then reducing, with_reduce()
, the output of each of those acquisition functions.- Parameters
datasets – The data from the observer.
models – The models over each dataset in
datasets
.
- Returns
The reduced acquisition function.
-
update_acquisition_function
(function: trieste.acquisition.interface.AcquisitionFunction, models: collections.abc.Mapping[trieste.types.Tag, trieste.models.ProbabilisticModel], datasets: Optional[collections.abc.Mapping[trieste.types.Tag, trieste.data.Dataset]] = None) → trieste.acquisition.interface.AcquisitionFunction# - Parameters
function – The acquisition function to update.
models – The model.
datasets – Unused.
-
property
acquisitions
→ collections.abc.Sequence[trieste.acquisition.interface.AcquisitionFunctionBuilder[trieste.models.ProbabilisticModel]]# The acquisition function builders specified at class initialisation.
-
abstract
_reduce
(inputs: collections.abc.Sequence[trieste.types.TensorType]) → trieste.types.TensorType# - Parameters
inputs – The output of each constituent acquisition function.
- Returns
The output of the reduced acquisition function.
-
class
Sum
(*builders: trieste.acquisition.interface.AcquisitionFunctionBuilder[trieste.models.ProbabilisticModel])[source]# Bases:
Reducer
Reducer
whose resulting acquisition function returns the element-wise sum of the outputs of constituent acquisition functions.- Parameters
*builders – Acquisition function builders. At least one must be provided.
- Raises
InvalidArgumentError – If no builders are specified.
-
_reduce
(inputs: collections.abc.Sequence[trieste.types.TensorType]) → trieste.types.TensorType# - Parameters
inputs – The outputs of each acquisition function.
- Returns
The element-wise sum of the
inputs
.
-
class
GIBBON
(search_space: trieste.space.SearchSpace, num_samples: int = 5, grid_size: int = 1000, min_value_sampler: None = None, rescaled_repulsion: bool = True) GIBBON(search_space: trieste.space.SearchSpace, num_samples: int = 5, grid_size: int = 1000, min_value_sampler: Optional[trieste.acquisition.sampler.ThompsonSampler[GIBBONModelType]] = None, rescaled_repulsion: bool = True)# Bases:
trieste.acquisition.interface.SingleModelGreedyAcquisitionBuilder
[GIBBONModelType
]The General-purpose Information-Based Bayesian Optimisation (GIBBON) acquisition function of [MLGR21].
GIBBON
provides a computationally cheap approximation of the information gained about (i.e the change in entropy of) the objective function’s minimum by evaluating a batch of candidate points. Batches are built in a greedy manner.This implementation follows [MLGR21] but is modified for function minimisation (rather than maximisation). We sample the objective’s minimum \(y^*\) across a large set of sampled locations via either a Gumbel sampler, an exact Thompson sampler or an approximate random Fourier feature-based Thompson sampler, with the Gumbel sampler being the cheapest but least accurate. Default behavior is to use the exact Thompson sampler.
- Parameters
search_space – The global search space over which the optimisation is defined.
num_samples – Number of samples to draw from the distribution over the minimum of the objective function.
grid_size – Size of the grid from which to sample the min-values. We recommend scaling this with search space dimension.
min_value_sampler – Sampler which samples minimum values.
rescaled_repulsion – If True, then downweight GIBBON’s repulsion term to improve batch optimization performance.
- Raises
tf.errors.InvalidArgumentError –
If
num_samples
is not positive, orgrid_size
is not positive.
-
prepare_acquisition_function
(model: GIBBONModelType, dataset: Optional[trieste.data.Dataset] = None, pending_points: Optional[trieste.types.TensorType] = None) → trieste.acquisition.interface.AcquisitionFunction# - Parameters
model – The model.
dataset – The data from the observer. Must be populated.
pending_points – The points we penalize with respect to.
- Returns
The GIBBON acquisition function modified for objective minimisation.
- Raises
tf.errors.InvalidArgumentError – If
dataset
is empty.
-
update_acquisition_function
(function: trieste.acquisition.interface.AcquisitionFunction, model: GIBBONModelType, dataset: Optional[trieste.data.Dataset] = None, pending_points: Optional[trieste.types.TensorType] = None, new_optimization_step: bool = True) → trieste.acquisition.interface.AcquisitionFunction# - Parameters
function – The acquisition function to update.
model – The model.
dataset – The data from the observer. Must be populated.
pending_points – Points already chosen to be in the current batch (of shape [M,D]), where M is the number of pending points and D is the search space dimension.
new_optimization_step – Indicates whether this call to update_acquisition_function is to start of a new optimization step, or to continue collecting batch of points for the current step. Defaults to
True
.
- Returns
The updated acquisition function.
-
class
HIPPO
(objective_tag: trieste.types.Tag = OBJECTIVE, base_acquisition_function_builder: AcquisitionFunctionBuilder[ProbabilisticModelType] | SingleModelAcquisitionBuilder[ProbabilisticModelType] | None = None)# Bases:
trieste.acquisition.interface.GreedyAcquisitionFunctionBuilder
[trieste.acquisition.interface.ProbabilisticModelType
]HIPPO: HIghly Parallelizable Pareto Optimization
Builder of the acquisition function for greedily collecting batches by HIPPO penalization in multi-objective optimization by penalizing batch points by their distance in the objective space. The resulting acquistion function takes in a set of pending points and returns a base multi-objective acquisition function penalized around those points.
Penalization is applied to the acquisition function multiplicatively. However, to improve numerical stability, we perform additive penalization in a log space.
Initializes the HIPPO acquisition function builder.
- Parameters
objective_tag – The tag for the objective data and model.
base_acquisition_function_builder – Base acquisition function to be penalized. Defaults to Expected Hypervolume Improvement, also supports its constrained version.
-
prepare_acquisition_function
(models: Mapping[trieste.types.Tag, trieste.acquisition.interface.ProbabilisticModelType], datasets: Optional[Mapping[trieste.types.Tag, trieste.data.Dataset]] = None, pending_points: Optional[trieste.types.TensorType] = None) → trieste.acquisition.interface.AcquisitionFunction# Creates a new instance of the acquisition function.
- Parameters
models – The models.
datasets – The data from the observer. Must be populated.
pending_points – The points we penalize with respect to.
- Returns
The HIPPO acquisition function.
- Raises
tf.errors.InvalidArgumentError – If the
dataset
is empty.
-
update_acquisition_function
(function: trieste.acquisition.interface.AcquisitionFunction, models: Mapping[trieste.types.Tag, trieste.acquisition.interface.ProbabilisticModelType], datasets: Optional[Mapping[trieste.types.Tag, trieste.data.Dataset]] = None, pending_points: Optional[trieste.types.TensorType] = None, new_optimization_step: bool = True) → trieste.acquisition.interface.AcquisitionFunction# Updates the acquisition function.
- Parameters
function – The acquisition function to update.
models – The models.
datasets – The data from the observer. Must be populated.
pending_points – Points already chosen to be in the current batch (of shape [M,D]), where M is the number of pending points and D is the search space dimension.
new_optimization_step – Indicates whether this call to update_acquisition_function is to start of a new optimization step, of to continue collecting batch of points for the current step. Defaults to
True
.
- Returns
The updated acquisition function.
-
class
AugmentedExpectedImprovement
# Bases:
trieste.acquisition.interface.SingleModelAcquisitionBuilder
[trieste.models.interfaces.SupportsGetObservationNoise
]Builder for the augmented expected improvement function for optimization single-objective optimization problems with high levels of observation noise.
-
prepare_acquisition_function
(model: trieste.models.interfaces.SupportsGetObservationNoise, dataset: Optional[trieste.data.Dataset] = None) → trieste.acquisition.interface.AcquisitionFunction# - Parameters
model – The model.
dataset – The data from the observer. Must be populated.
- Returns
The expected improvement function. This function will raise
ValueError
orInvalidArgumentError
if used with a batch size greater than one.- Raises
tf.errors.InvalidArgumentError – If
dataset
is empty.
-
update_acquisition_function
(function: trieste.acquisition.interface.AcquisitionFunction, model: trieste.models.interfaces.SupportsGetObservationNoise, dataset: Optional[trieste.data.Dataset] = None) → trieste.acquisition.interface.AcquisitionFunction# - Parameters
function – The acquisition function to update.
model – The model.
dataset – The data from the observer. Must be populated.
-
-
class
BatchExpectedImprovement
(sample_size: int, *, jitter: float = DEFAULTS.JITTER)# Bases:
trieste.acquisition.interface.SingleModelAcquisitionBuilder
[trieste.models.ProbabilisticModel
]Accurate approximation of the batch expected improvement, using the method of Chvallier and Ginsbourger [CG13].
Internally, this uses a highly accurate approximation of the cumulative density function of the multivariate Gaussian, developed by Alan Genz [GT16].
Initialise the BatchExpectedImprovement instance.
- Parameters
sample_size – int, number of Sobol samples to use.
jitter – float, amount of jitter for Cholesky factorisations.
-
prepare_acquisition_function
(model: trieste.models.ProbabilisticModel, dataset: Optional[trieste.data.Dataset] = None) → trieste.acquisition.interface.AcquisitionFunction# - Parameters
model – The model. Must have event shape [1].
dataset – The data from the observer. Must be populated.
- Returns
The batch expected improvement acquisition function.
- Raises
ValueError (or InvalidArgumentError) – If
dataset
is not populated, ormodel
does not have an event shape of [1].
-
update_acquisition_function
(function: trieste.acquisition.interface.AcquisitionFunction, model: trieste.models.ProbabilisticModel, dataset: Optional[trieste.data.Dataset] = None) → trieste.acquisition.interface.AcquisitionFunction# - Parameters
function – The acquisition function to update.
model – The model. Must have event shape [1].
dataset – The data from the observer. Must be populated.
-
class
BatchMonteCarloExpectedHypervolumeImprovement
(sample_size: int, reference_point_spec: Sequence[float] | TensorType | Callable[…, TensorType] = get_reference_point, *, jitter: float = DEFAULTS.JITTER)# Bases:
trieste.acquisition.interface.SingleModelAcquisitionBuilder
[trieste.models.interfaces.HasReparamSampler
]Builder for the batch expected hypervolume improvement acquisition function. The implementation of the acquisition function largely follows [DBB20]
- Parameters
sample_size – The number of samples from model predicted distribution for each batch of points.
reference_point_spec – this method is used to determine how the reference point is calculated. If a Callable function specified, it is expected to take existing posterior mean-based observations (to screen out the observation noise) and return a reference point with shape [D] (D represents number of objectives). If the Pareto front location is known, this arg can be used to specify a fixed reference point in each bo iteration. A dynamic reference point updating strategy is used by default to set a reference point according to the datasets.
jitter – The size of the jitter to use when stabilising the Cholesky decomposition of the covariance matrix.
- Raises
ValueError (or InvalidArgumentError) – If
sample_size
is not positive, orjitter
is negative.
-
prepare_acquisition_function
(model: trieste.models.interfaces.HasReparamSampler, dataset: Optional[trieste.data.Dataset] = None) → trieste.acquisition.interface.AcquisitionFunction# - Parameters
model – The model. Must have event shape [1].
dataset – The data from the observer. Must be populated.
- Returns
The batch expected hypervolume improvement acquisition function.
-
class
BatchMonteCarloExpectedImprovement
(sample_size: int, *, jitter: float = DEFAULTS.JITTER)# Bases:
trieste.acquisition.interface.SingleModelAcquisitionBuilder
[trieste.models.interfaces.HasReparamSampler
]Expected improvement for batches of points (or \(q\)-EI), approximated using Monte Carlo estimation with the reparametrization trick. See [GLRC10a] for details. Improvement is measured with respect to the minimum predictive mean at observed query points. This is calculated in
BatchMonteCarloExpectedImprovement
by assuming observations at new points are independent from those at known query points. This is faster, but is an approximation for noisy observers.- Parameters
sample_size – The number of samples for each batch of points.
jitter – The size of the jitter to use when stabilising the Cholesky decomposition of the covariance matrix.
- Raises
tf.errors.InvalidArgumentError – If
sample_size
is not positive, orjitter
is negative.
-
prepare_acquisition_function
(model: trieste.models.interfaces.HasReparamSampler, dataset: Optional[trieste.data.Dataset] = None) → trieste.acquisition.interface.AcquisitionFunction# - Parameters
model – The model. Must have event shape [1].
dataset – The data from the observer. Must be populated.
- Returns
The batch expected improvement acquisition function.
- Raises
ValueError (or InvalidArgumentError) – If
dataset
is not populated, ormodel
does not have an event shape of [1].
-
update_acquisition_function
(function: trieste.acquisition.interface.AcquisitionFunction, model: trieste.models.interfaces.HasReparamSampler, dataset: Optional[trieste.data.Dataset] = None) → trieste.acquisition.interface.AcquisitionFunction# - Parameters
function – The acquisition function to update.
model – The model. Must have event shape [1].
dataset – The data from the observer. Must be populated.
-
class
BayesianActiveLearningByDisagreement
(jitter: float = DEFAULTS.JITTER)# Bases:
trieste.acquisition.interface.SingleModelAcquisitionBuilder
[trieste.models.ProbabilisticModel
]Builder for the Bayesian Active Learning By Disagreement acquisition function defined in [HHGL11].
- Parameters
jitter – The size of the jitter to avoid numerical problem caused by the log operation if variance is close to zero.
-
prepare_acquisition_function
(model: trieste.models.ProbabilisticModel, dataset: Optional[trieste.data.Dataset] = None) → trieste.acquisition.interface.AcquisitionFunction# - Parameters
model – The model.
dataset – Unused.
- Returns
The determinant of the predictive function.
-
update_acquisition_function
(function: trieste.acquisition.interface.AcquisitionFunction, model: trieste.models.ProbabilisticModel, dataset: Optional[trieste.data.Dataset] = None) → trieste.acquisition.interface.AcquisitionFunction# - Parameters
function – The acquisition function to update.
model – The model.
dataset – Unused.
-
class
ExpectedConstrainedHypervolumeImprovement
(objective_tag: trieste.types.Tag, constraint_builder: trieste.acquisition.interface.AcquisitionFunctionBuilder[trieste.acquisition.interface.ProbabilisticModelType], min_feasibility_probability: float | TensorType = 0.5, reference_point_spec: Sequence[float] | TensorType | Callable[…, TensorType] = get_reference_point)# Bases:
trieste.acquisition.function.function.ExpectedConstrainedImprovement
[trieste.acquisition.interface.ProbabilisticModelType
]Builder for the constrained expected hypervolume improvement acquisition function. This function essentially combines ExpectedConstrainedImprovement and ExpectedHypervolumeImprovement.
- Parameters
objective_tag – The tag for the objective data and model.
constraint_builder – The builder for the constraint function.
min_feasibility_probability – The minimum probability of feasibility for a “best point” to be considered feasible.
reference_point_spec – this method is used to determine how the reference point is calculated. If a Callable function specified, it is expected to take existing posterior mean-based feasible observations (to screen out the observation noise) and return a reference point with shape [D] (D represents number of objectives). If the feasible Pareto front location is known, this arg can be used to specify a fixed reference point in each bo iteration. A dynamic reference point updating strategy is used by default to set a reference point according to the datasets.
-
_update_expected_improvement_fn
(objective_model: trieste.acquisition.interface.ProbabilisticModelType, feasible_mean: trieste.types.TensorType) → None# Set or update the unconstrained expected improvement function.
- Parameters
objective_model – The objective model.
feasible_mean – The mean of the feasible query points.
-
class
ExpectedConstrainedImprovement
(objective_tag: trieste.types.Tag, constraint_builder: trieste.acquisition.interface.AcquisitionFunctionBuilder[trieste.acquisition.interface.ProbabilisticModelType], min_feasibility_probability: float | TensorType = 0.5, search_space: Optional[trieste.space.SearchSpace] = None)# Bases:
trieste.acquisition.interface.AcquisitionFunctionBuilder
[trieste.acquisition.interface.ProbabilisticModelType
]Builder for the expected constrained improvement acquisition function defined in [GKZ+14]. The acquisition function computes the expected improvement from the best feasible point, where feasible points are those that (probably) satisfy some constraint. Where there are no feasible points, this builder simply builds the constraint function.
- Parameters
objective_tag – The tag for the objective data and model.
constraint_builder – The builder for the constraint function.
min_feasibility_probability – The minimum probability of feasibility for a “best point” to be considered feasible.
search_space – The global search space over which the optimisation is defined. This is only used to determine explicit constraints.
- Raises
ValueError (or tf.errors.InvalidArgumentError) – If
min_feasibility_probability
is not a scalar in the unit interval \([0, 1]\).
-
prepare_acquisition_function
(models: Mapping[trieste.types.Tag, trieste.acquisition.interface.ProbabilisticModelType], datasets: Optional[Mapping[trieste.types.Tag, trieste.data.Dataset]] = None) → trieste.acquisition.interface.AcquisitionFunction# - Parameters
models – The models over each tag.
datasets – The data from the observer.
- Returns
The expected constrained improvement acquisition function. This function will raise
ValueError
orInvalidArgumentError
if used with a batch size greater than one.- Raises
KeyError – If objective_tag is not found in
datasets
andmodels
.tf.errors.InvalidArgumentError – If the objective data is empty.
-
update_acquisition_function
(function: trieste.acquisition.interface.AcquisitionFunction, models: Mapping[trieste.types.Tag, trieste.acquisition.interface.ProbabilisticModelType], datasets: Optional[Mapping[trieste.types.Tag, trieste.data.Dataset]] = None) → trieste.acquisition.interface.AcquisitionFunction# - Parameters
function – The acquisition function to update.
models – The models for each tag.
datasets – The data from the observer.
-
_update_expected_improvement_fn
(objective_model: trieste.acquisition.interface.ProbabilisticModelType, feasible_mean: trieste.types.TensorType) → None# Set or update the unconstrained expected improvement function.
- Parameters
objective_model – The objective model.
feasible_mean – The mean of the feasible query points.
-
class
ExpectedFeasibility
(threshold: float, alpha: float = 1, delta: int = 1)# Bases:
trieste.acquisition.interface.SingleModelAcquisitionBuilder
[trieste.models.ProbabilisticModel
]Builder for the Expected feasibility acquisition function for identifying a failure or feasibility region. It implements two related sampling strategies called bichon criterion ([BES+08]) and ranjan criterion ([RBM08]). The goal of both criteria is to sample points with a mean close to the threshold and a high variance.
- Parameters
threshold – The failure or feasibility threshold.
alpha – The parameter which determines the neighbourhood around the estimated contour line as a percentage of the posterior variance in which to allocate new points. Defaults to value of 1.
delta – The parameter identifying which criterion is used, bichon for value of 1 (default) and ranjan for value of 2.
- Raises
ValueError (or InvalidArgumentError) – If arguments are not a scalar, or alpha is not positive, or delta is not 1 or 2.
-
prepare_acquisition_function
(model: trieste.models.ProbabilisticModel, dataset: Optional[trieste.data.Dataset] = None) → trieste.acquisition.interface.AcquisitionFunction# - Parameters
model – The model.
dataset – Unused.
- Returns
The expected feasibility function. This function will raise
ValueError
orInvalidArgumentError
if used with a batch size greater than one.
-
update_acquisition_function
(function: trieste.acquisition.interface.AcquisitionFunction, model: trieste.models.ProbabilisticModel, dataset: Optional[trieste.data.Dataset] = None) → trieste.acquisition.interface.AcquisitionFunction# - Parameters
function – The acquisition function to update.
model – The model.
dataset – The data from the observer (optional).
- Returns
The updated acquisition function.
-
class
ExpectedHypervolumeImprovement
(reference_point_spec: Sequence[float] | TensorType | Callable[…, TensorType] = get_reference_point)# Bases:
trieste.acquisition.interface.SingleModelAcquisitionBuilder
[trieste.models.ProbabilisticModel
]Builder for the expected hypervolume improvement acquisition function. The implementation of the acquisition function largely follows [YEDBack19]
- Parameters
reference_point_spec – this method is used to determine how the reference point is calculated. If a Callable function specified, it is expected to take existing posterior mean-based observations (to screen out the observation noise) and return a reference point with shape [D] (D represents number of objectives). If the Pareto front location is known, this arg can be used to specify a fixed reference point in each bo iteration. A dynamic reference point updating strategy is used by default to set a reference point according to the datasets.
-
prepare_acquisition_function
(model: trieste.models.ProbabilisticModel, dataset: Optional[trieste.data.Dataset] = None) → trieste.acquisition.interface.AcquisitionFunction# - Parameters
model – The model.
dataset – The data from the observer. Must be populated.
- Returns
The expected hypervolume improvement acquisition function.
-
update_acquisition_function
(function: trieste.acquisition.interface.AcquisitionFunction, model: trieste.models.ProbabilisticModel, dataset: Optional[trieste.data.Dataset] = None) → trieste.acquisition.interface.AcquisitionFunction# - Parameters
function – The acquisition function to update.
model – The model.
dataset – The data from the observer. Must be populated.
-
class
ExpectedImprovement
(search_space: Optional[trieste.space.SearchSpace] = None)# Bases:
trieste.acquisition.interface.SingleModelAcquisitionBuilder
[trieste.models.ProbabilisticModel
]Builder for the expected improvement function where the “best” value is taken to be the minimum of the posterior mean at observed points.
In the presence of constraints in the search_space the “best” value is computed only at the feasible query points. If there are no feasible points, the “best” value is instead taken to be the maximum of the posterior mean at all observed points.
- Parameters
search_space – The global search space over which the optimisation is defined. This is only used to determine explicit constraints.
-
prepare_acquisition_function
(model: trieste.models.ProbabilisticModel, dataset: Optional[trieste.data.Dataset] = None) → trieste.acquisition.interface.AcquisitionFunction# - Parameters
model – The model.
dataset – The data from the observer. Must be populated.
- Returns
The expected improvement function. This function will raise
ValueError
orInvalidArgumentError
if used with a batch size greater than one.- Raises
tf.errors.InvalidArgumentError – If
dataset
is empty.
-
update_acquisition_function
(function: trieste.acquisition.interface.AcquisitionFunction, model: trieste.models.ProbabilisticModel, dataset: Optional[trieste.data.Dataset] = None) → trieste.acquisition.interface.AcquisitionFunction# - Parameters
function – The acquisition function to update.
model – The model.
dataset – The data from the observer. Must be populated.
-
class
Fantasizer
(base_acquisition_function_builder: Optional[AcquisitionFunctionBuilder[SupportsPredictJoint] | SingleModelAcquisitionBuilder[SupportsPredictJoint]] = None, fantasize_method: str = 'KB')# Bases:
trieste.acquisition.interface.GreedyAcquisitionFunctionBuilder
[FantasizerModelOrStack
]Builder of the acquisition function maker for greedily collecting batches. Fantasizer allows us to perform batch Bayesian optimization with any standard (non-batch) acquisition function.
Here, every time a query point is chosen by maximising an acquisition function, its corresponding observation is “fantasized”, and the models are conditioned further on this new artificial data.
This implies that the models need to predict what their updated predictions would be given new data, see
FastUpdateModel
. These equations are for instance in closed form for the GPR model, see [CGE14] (eqs. 8-10) for details.There are several ways to “fantasize” data: the “kriging believer” heuristic (KB, see [GLRC10b]) uses the mean of the model as observations. “sample” uses samples from the model.
- Parameters
base_acquisition_function_builder – The acquisition function builder to use. Defaults to
ExpectedImprovement
.fantasize_method – The following options are available: “KB” and “sample”. See class docs for more details.
- Raises
tf.errors.InvalidArgumentError – If
fantasize_method
is not “KB” or “sample”.
-
prepare_acquisition_function
(models: Mapping[trieste.types.Tag, FantasizerModelOrStack], datasets: Optional[Mapping[trieste.types.Tag, trieste.data.Dataset]] = None, pending_points: Optional[trieste.types.TensorType] = None) → trieste.acquisition.interface.AcquisitionFunction# - Parameters
models – The models over each tag.
datasets – The data from the observer (optional).
pending_points – Points already chosen to be in the current batch (of shape [M,D]), where M is the number of pending points and D is the search space dimension.
- Returns
An acquisition function.
-
update_acquisition_function
(function: trieste.acquisition.interface.AcquisitionFunction, models: Mapping[trieste.types.Tag, FantasizerModelOrStack], datasets: Optional[Mapping[trieste.types.Tag, trieste.data.Dataset]] = None, pending_points: Optional[trieste.types.TensorType] = None, new_optimization_step: bool = True) → trieste.acquisition.interface.AcquisitionFunction# - Parameters
function – The acquisition function to update.
models – The models over each tag.
datasets – The data from the observer (optional).
pending_points – Points already chosen to be in the current batch (of shape [M,D]), where M is the number of pending points and D is the search space dimension.
new_optimization_step – Indicates whether this call to update_acquisition_function is to start of a new optimization step, of to continue collecting batch of points for the current step. Defaults to
True
.
- Returns
The updated acquisition function.
-
class
FastConstraintsFeasibility
(search_space: trieste.space.SearchSpace, smoothing_function: Optional[Callable[[trieste.types.TensorType], trieste.types.TensorType]] = None)# Bases:
trieste.acquisition.interface.SingleModelAcquisitionBuilder
[trieste.models.ProbabilisticModel
]Builds a feasiblity acquisition function from the residuals of explicit constraints defined in the search space.
- Parameters
search_space – The global search space over which the feasibility of the constraints is defined.
smoothing_function – The smoothing function used for constraints residuals. The default is CDF of the Normal distribution with a scale of 1e-3.
- Raises
NotImplementedError – If the search_space does not have constraints.
-
prepare_acquisition_function
(model: trieste.models.ProbabilisticModel, dataset: Optional[trieste.data.Dataset] = None) → trieste.acquisition.interface.AcquisitionFunction# - Parameters
model – Unused.
dataset – Unused.
- Returns
The function for feasibility of constraints.
-
update_acquisition_function
(function: trieste.acquisition.interface.AcquisitionFunction, model: trieste.models.ProbabilisticModel, dataset: Optional[trieste.data.Dataset] = None) → trieste.acquisition.interface.AcquisitionFunction# - Parameters
function – The acquisition function to update.
model – Unused.
dataset – Unused.
- Returns
The function for feasibility of constraints.
-
class
GreedyContinuousThompsonSampling
(select_output: Callable[[trieste.types.TensorType], trieste.types.TensorType] = select_nth_output)# Bases:
trieste.acquisition.interface.SingleModelGreedyAcquisitionBuilder
[trieste.models.interfaces.HasTrajectorySampler
]Acquisition function builder for performing greedy continuous Thompson sampling. This builder return acquisition functions that are the negatives of approximate samples from the given
ProbabilisticModel
, as provided by the model’sget_trajectory()
method. A set of such samples are to be maximized in a sequential greedy manner to provide the next recommended query points. Note that we actually return the negative of the trajectory, so that our acquisition optimizers (which are all maximizers) can be used to extract the minimisers of trajectories.For more details about trajectory-based Thompson sampling see [HernandezLRPKAG17] and [WBT+20].
- Parameters
select_output – A method that returns the desired trajectory from a trajectory sampler with shape […, B], where B is a batch dimension. Defaults to the :func:~`trieste.acquisition.utils.select_nth_output` function with output dimension 0.
-
prepare_acquisition_function
(model: trieste.models.interfaces.HasTrajectorySampler, dataset: Optional[trieste.data.Dataset] = None, pending_points: Optional[trieste.types.TensorType] = None) → trieste.models.interfaces.TrajectoryFunction# - Parameters
model – The model.
dataset – The data from the observer (not used).
pending_points – The points already in the current batch (not used).
- Returns
A negated trajectory sampled from the model.
-
update_acquisition_function
(function: trieste.models.interfaces.TrajectoryFunction, model: trieste.models.interfaces.HasTrajectorySampler, dataset: Optional[trieste.data.Dataset] = None, pending_points: Optional[trieste.types.TensorType] = None, new_optimization_step: bool = True) → trieste.models.interfaces.TrajectoryFunction# - Parameters
function – The trajectory function to update.
model – The model.
dataset – The data from the observer (not used).
pending_points – The points already in the current batch (not used).
new_optimization_step – Indicates whether this call to update_acquisition_function is to start of a new optimization step, of to continue collecting batch of points for the current step. Defaults to
True
.
- Returns
A new trajectory sampled from the model.
-
class
IntegratedVarianceReduction
(integration_points: trieste.types.TensorType, threshold: Optional[Union[float, Sequence[float], trieste.types.TensorType]] = None)# Bases:
trieste.acquisition.interface.SingleModelAcquisitionBuilder
[trieste.models.interfaces.FastUpdateModel
]Builder for the reduction of the integral of the predicted variance over the search space given a batch of query points.
- Parameters
integration_points – set of points to integrate the prediction variance over.
threshold – either None, a float or a sequence of 1 or 2 float values.
-
prepare_acquisition_function
(model: trieste.models.interfaces.FastUpdateModel, dataset: Optional[trieste.data.Dataset] = None) → trieste.acquisition.interface.AcquisitionFunction# - Parameters
model – The model.
dataset – Unused.
- Returns
The integral of the predictive variance.
-
update_acquisition_function
(function: trieste.acquisition.interface.AcquisitionFunction, model: trieste.models.interfaces.FastUpdateModel, dataset: Optional[trieste.data.Dataset] = None) → trieste.acquisition.interface.AcquisitionFunction# - Parameters
function – The acquisition function to update.
model – The model.
dataset – Unused.
-
class
LocalPenalization
(search_space: trieste.space.SearchSpace, num_samples: int = 500, penalizer: Callable[[trieste.models.ProbabilisticModel, trieste.types.TensorType, trieste.types.TensorType, trieste.types.TensorType], Union[trieste.acquisition.interface.PenalizationFunction, trieste.acquisition.interface.UpdatablePenalizationFunction]] = None, base_acquisition_function_builder: ExpectedImprovement | MinValueEntropySearch[ProbabilisticModel] | MakePositive[ProbabilisticModel] | None = None)# Bases:
trieste.acquisition.interface.SingleModelGreedyAcquisitionBuilder
[trieste.models.ProbabilisticModel
]Builder of the acquisition function maker for greedily collecting batches by local penalization. The resulting
AcquisitionFunctionMaker
takes in a set of pending points and returns a base acquisition function penalized around those points. An estimate of the objective function’s Lipschitz constant is used to control the size of penalization.Local penalization allows us to perform batch Bayesian optimization with a standard (non-batch) acquisition function. All that we require is that the acquisition function takes strictly positive values. By iteratively building a batch of points though sequentially maximizing this acquisition function but down-weighted around locations close to the already chosen (pending) points, local penalization provides diverse batches of candidate points.
Local penalization is applied to the acquisition function multiplicatively. However, to improve numerical stability, we perform additive penalization in a log space.
The Lipschitz constant and additional penalization parameters are estimated once when first preparing the acquisition function with no pending points. These estimates are reused for all subsequent function calls.
- Parameters
search_space – The global search space over which the optimisation is defined.
num_samples – Size of the random sample over which the Lipschitz constant is estimated. We recommend scaling this with search space dimension.
penalizer – The chosen penalization method (defaults to soft penalization). This should be a function that accepts a model, pending points, lipschitz constant and eta and returns a PenalizationFunction.
base_acquisition_function_builder – Base acquisition function to be penalized (defaults to expected improvement). Local penalization only supports strictly positive acquisition functions.
- Raises
tf.errors.InvalidArgumentError – If
num_samples
is not positive.
-
prepare_acquisition_function
(model: trieste.models.ProbabilisticModel, dataset: Optional[trieste.data.Dataset] = None, pending_points: Optional[trieste.types.TensorType] = None) → trieste.acquisition.interface.AcquisitionFunction# - Parameters
model – The model.
dataset – The data from the observer. Must be populated.
pending_points – The points we penalize with respect to.
- Returns
The (log) expected improvement penalized with respect to the pending points.
- Raises
tf.errors.InvalidArgumentError – If the
dataset
is empty.
-
update_acquisition_function
(function: trieste.acquisition.interface.AcquisitionFunction, model: trieste.models.ProbabilisticModel, dataset: Optional[trieste.data.Dataset] = None, pending_points: Optional[trieste.types.TensorType] = None, new_optimization_step: bool = True) → trieste.acquisition.interface.AcquisitionFunction# - Parameters
function – The acquisition function to update.
model – The model.
dataset – The data from the observer. Must be populated.
pending_points – Points already chosen to be in the current batch (of shape [M,D]), where M is the number of pending points and D is the search space dimension.
new_optimization_step – Indicates whether this call to update_acquisition_function is to start of a new optimization step, of to continue collecting batch of points for the current step. Defaults to
True
.
- Returns
The updated acquisition function.
-
class
MakePositive
(base_acquisition_function_builder: trieste.acquisition.interface.SingleModelAcquisitionBuilder[trieste.acquisition.interface.ProbabilisticModelType])# Bases:
trieste.acquisition.interface.SingleModelAcquisitionBuilder
[trieste.acquisition.interface.ProbabilisticModelType
]Converts an acquisition function builder into one that only returns positive values, via \(x \mapsto \log(1 + \exp(x))\).
This is sometimes a useful transformation: for example, converting non-batch acquisition functions into batch acquisition functions with local penalization requires functions that only return positive values.
- Parameters
base_acquisition_function_builder – Base acquisition function to be made positive.
-
prepare_acquisition_function
(model: trieste.acquisition.interface.ProbabilisticModelType, dataset: Optional[trieste.data.Dataset] = None) → trieste.acquisition.interface.AcquisitionFunction# - Parameters
model – The model.
dataset – The data to use to build the acquisition function (optional).
- Returns
An acquisition function.
-
update_acquisition_function
(function: trieste.acquisition.interface.AcquisitionFunction, model: trieste.acquisition.interface.ProbabilisticModelType, dataset: Optional[trieste.data.Dataset] = None) → trieste.acquisition.interface.AcquisitionFunction# - Parameters
function – The acquisition function to update.
model – The model.
dataset – The data from the observer (optional).
- Returns
The updated acquisition function.
-
class
MinValueEntropySearch
(search_space: trieste.space.SearchSpace, num_samples: int = 5, grid_size: int = 1000, min_value_sampler: None = None) MinValueEntropySearch(search_space: trieste.space.SearchSpace, num_samples: int = 5, grid_size: int = 1000, min_value_sampler: Optional[trieste.acquisition.sampler.ThompsonSampler[trieste.acquisition.interface.ProbabilisticModelType]] = None)# Bases:
trieste.acquisition.interface.SingleModelAcquisitionBuilder
[trieste.acquisition.interface.ProbabilisticModelType
]Builder for the max-value entropy search acquisition function modified for objective minimisation.
MinValueEntropySearch
estimates the information in the distribution of the objective minimum that would be gained by evaluating the objective at a given point.This implementation largely follows [WJ17] and samples the objective’s minimum \(y^*\) across a large set of sampled locations via either a Gumbel sampler, an exact Thompson sampler or an approximate random Fourier feature-based Thompson sampler, with the Gumbel sampler being the cheapest but least accurate. Default behavior is to use the exact Thompson sampler.
- Parameters
search_space – The global search space over which the optimisation is defined.
num_samples – Number of samples to draw from the distribution over the minimum of the objective function.
grid_size – Size of the grid from which to sample the min-values. We recommend scaling this with search space dimension.
min_value_sampler – Sampler which samples minimum values.
- Raises
tf.errors.InvalidArgumentError –
If
num_samples
orgrid_size
are negative.
-
prepare_acquisition_function
(model: trieste.acquisition.interface.ProbabilisticModelType, dataset: Optional[trieste.data.Dataset] = None) → trieste.acquisition.interface.AcquisitionFunction# - Parameters
model – The model.
dataset – The data from the observer.
- Returns
The max-value entropy search acquisition function modified for objective minimisation. This function will raise
ValueError
orInvalidArgumentError
if used with a batch size greater than one.- Raises
tf.errors.InvalidArgumentError – If
dataset
is empty.
-
update_acquisition_function
(function: trieste.acquisition.interface.AcquisitionFunction, model: trieste.acquisition.interface.ProbabilisticModelType, dataset: Optional[trieste.data.Dataset] = None) → trieste.acquisition.interface.AcquisitionFunction# - Parameters
function – The acquisition function to update.
model – The model.
dataset – The data from the observer.
-
class
MonteCarloAugmentedExpectedImprovement
(sample_size: int, *, jitter: float = DEFAULTS.JITTER)# Bases:
trieste.acquisition.interface.SingleModelAcquisitionBuilder
[trieste.models.interfaces.SupportsReparamSamplerObservationNoise
]Builder for a Monte Carlo-based augmented expected improvement function for use with a model without analytical augmented expected improvement (e.g. a deep GP). The “best” value is taken to be the minimum of the posterior mean at observed points. See
monte_carlo_augmented_expected_improvement
for details.- Parameters
sample_size – The number of samples for each batch of points.
jitter – The jitter for the reparametrization sampler.
- Raises
tf.errors.InvalidArgumentError – If
sample_size
is not positive, orjitter
is negative.
-
prepare_acquisition_function
(model: trieste.models.interfaces.SupportsReparamSamplerObservationNoise, dataset: Optional[trieste.data.Dataset] = None) → trieste.acquisition.interface.AcquisitionFunction# - Parameters
model – The model over the specified
dataset
. Must have output dimension [1].dataset – The data from the observer. Cannot be empty.
- Returns
The estimated expected improvement acquisition function.
- Raises
ValueError (or InvalidArgumentError) – If
dataset
is not populated,model
does not have an output dimension of [1], does not have areparam_sample
method, or does not support observation noise.
-
update_acquisition_function
(function: trieste.acquisition.interface.AcquisitionFunction, model: trieste.models.interfaces.SupportsReparamSamplerObservationNoise, dataset: Optional[trieste.data.Dataset] = None) → trieste.acquisition.interface.AcquisitionFunction# - Parameters
function – The acquisition function to update.
model – The model. Must have output dimension [1]. Unused here
dataset – The data from the observer. Cannot be empty.
-
class
MonteCarloExpectedImprovement
(sample_size: int, *, jitter: float = DEFAULTS.JITTER)# Bases:
trieste.acquisition.interface.SingleModelAcquisitionBuilder
[trieste.models.interfaces.HasReparamSampler
]Builder for a Monte Carlo-based expected improvement function for use with a model without analytical expected improvement (e.g. a deep GP). The “best” value is taken to be the minimum of the posterior mean at observed points. See
monte_carlo_expected_improvement
for details.- Parameters
sample_size – The number of samples for each batch of points.
jitter – The jitter for the reparametrization sampler.
- Raises
tf.errors.InvalidArgumentError – If
sample_size
is not positive, orjitter
is negative.
-
prepare_acquisition_function
(model: trieste.models.interfaces.HasReparamSampler, dataset: Optional[trieste.data.Dataset] = None) → trieste.acquisition.interface.AcquisitionFunction# - Parameters
model – The model over the specified
dataset
. Must have output dimension [1].dataset – The data from the observer. Cannot be empty.
- Returns
The estimated expected improvement acquisition function.
- Raises
ValueError (or InvalidArgumentError) – If
dataset
is not populated,model
does not have an output dimension of [1] or does not have areparam_sample
method.
-
update_acquisition_function
(function: trieste.acquisition.interface.AcquisitionFunction, model: trieste.models.interfaces.HasReparamSampler, dataset: Optional[trieste.data.Dataset] = None) → trieste.acquisition.interface.AcquisitionFunction# - Parameters
function – The acquisition function to update.
model – The model. Must have output dimension [1]. Unused here.
dataset – The data from the observer. Cannot be empty
-
class
MultipleOptimismNegativeLowerConfidenceBound
(search_space: trieste.space.SearchSpace)# Bases:
trieste.acquisition.interface.SingleModelVectorizedAcquisitionBuilder
[trieste.models.ProbabilisticModel
]A simple parallelization of the lower confidence bound acquisition function that produces a vectorized acquisition function which can efficiently optimized even for large batches.
See [TPD20] for details.
- Parameters
search_space – The global search space over which the optimisation is defined.
-
prepare_acquisition_function
(model: trieste.models.ProbabilisticModel, dataset: Optional[trieste.data.Dataset] = None) → trieste.acquisition.interface.AcquisitionFunction# - Parameters
model – The model.
dataset – Unused.
- Returns
The multiple optimism negative lower confidence bound function.
-
update_acquisition_function
(function: trieste.acquisition.interface.AcquisitionFunction, model: trieste.models.ProbabilisticModel, dataset: Optional[trieste.data.Dataset] = None) → trieste.acquisition.interface.AcquisitionFunction# - Parameters
function – The acquisition function to update.
model – The model.
dataset – Unused.
-
class
NegativeLowerConfidenceBound
(beta: float = 1.96)# Bases:
trieste.acquisition.interface.SingleModelAcquisitionBuilder
[trieste.models.ProbabilisticModel
]Builder for the negative of the lower confidence bound. The lower confidence bound is typically minimised, so the negative is suitable for maximisation.
- Parameters
beta – Weighting given to the variance contribution to the lower confidence bound. Must not be negative.
-
prepare_acquisition_function
(model: trieste.models.ProbabilisticModel, dataset: Optional[trieste.data.Dataset] = None) → trieste.acquisition.interface.AcquisitionFunction# - Parameters
model – The model.
dataset – Unused.
- Returns
The negative lower confidence bound function. This function will raise
ValueError
orInvalidArgumentError
if used with a batch size greater than one.- Raises
ValueError – If
beta
is negative.
-
update_acquisition_function
(function: trieste.acquisition.interface.AcquisitionFunction, model: trieste.models.ProbabilisticModel, dataset: Optional[trieste.data.Dataset] = None) → trieste.acquisition.interface.AcquisitionFunction# - Parameters
function – The acquisition function to update.
model – The model.
dataset – Unused.
-
class
NegativePredictiveMean
# Bases:
NegativeLowerConfidenceBound
Builder for the negative of the predictive mean. The predictive mean is minimised on minimising the objective function. The negative predictive mean is therefore maximised.
- Parameters
beta – Weighting given to the variance contribution to the lower confidence bound. Must not be negative.
-
class
ParallelContinuousThompsonSampling
(select_output: Callable[[trieste.types.TensorType], trieste.types.TensorType] = select_nth_output)# Bases:
trieste.acquisition.interface.SingleModelVectorizedAcquisitionBuilder
[trieste.models.interfaces.HasTrajectorySampler
]Acquisition function builder for performing parallel continuous Thompson sampling.
This builder provides broadly the same behavior as our
GreedyContinuousThompsonSampler
however optimizes trajectory samples in parallel rather than sequentially. Consequently,ParallelContinuousThompsonSampling
can choose query points faster thanGreedyContinuousThompsonSampler
however it has much larger memory usage.For a convenient way to control the total memory usage of this acquisition function, see our
split_acquisition_function_calls
wrapper.- Parameters
select_output – A method that returns the desired trajectory from a trajectory sampler with shape […, B], where B is a batch dimension. Defaults to the :func:~`trieste.acquisition.utils.select_nth_output` function with output dimension 0.
-
prepare_acquisition_function
(model: trieste.models.interfaces.HasTrajectorySampler, dataset: Optional[trieste.data.Dataset] = None) → trieste.models.interfaces.TrajectoryFunction# - Parameters
model – The model.
dataset – The data from the observer (not used).
- Returns
A negated trajectory sampled from the model.
-
update_acquisition_function
(function: trieste.models.interfaces.TrajectoryFunction, model: trieste.models.interfaces.HasTrajectorySampler, dataset: Optional[trieste.data.Dataset] = None) → trieste.models.interfaces.TrajectoryFunction# - Parameters
function – The trajectory function to update.
model – The model.
dataset – The data from the observer (not used).
- Returns
A new trajectory sampled from the model.
-
class
PredictiveVariance
(jitter: float = DEFAULTS.JITTER)# Bases:
trieste.acquisition.interface.SingleModelAcquisitionBuilder
[trieste.models.interfaces.SupportsPredictJoint
]Builder for the determinant of the predictive covariance matrix over the batch points. For a batch of size 1 it is the same as maximizing the predictive variance.
- Parameters
jitter – The size of the jitter to use when stabilising the Cholesky decomposition of the covariance matrix.
-
prepare_acquisition_function
(model: trieste.models.interfaces.SupportsPredictJoint, dataset: Optional[trieste.data.Dataset] = None) → trieste.acquisition.interface.AcquisitionFunction# - Parameters
model – The model.
dataset – Unused.
- Returns
The determinant of the predictive function.
-
update_acquisition_function
(function: trieste.acquisition.interface.AcquisitionFunction, model: trieste.models.interfaces.SupportsPredictJoint, dataset: Optional[trieste.data.Dataset] = None) → trieste.acquisition.interface.AcquisitionFunction# - Parameters
function – The acquisition function to update.
model – The model.
dataset – Unused.
-
class
ProbabilityOfFeasibility
(threshold: float | TensorType)# Bases:
trieste.acquisition.interface.SingleModelAcquisitionBuilder
[trieste.models.ProbabilisticModel
]Uses the
probability_below_threshold()
function to build a probability of feasiblity acquisition function, defined in [GKZ+14] as\[\int_{-\infty}^{\tau} p(c(\mathbf{x}) | \mathbf{x}, \mathcal{D}) \mathrm{d} c(\mathbf{x}) \qquad ,\]where \(\tau\) is a threshold. Values below the threshold are considered feasible by the constraint function. See also [SWJ98] for details.
- Parameters
threshold – The (scalar) probability of feasibility threshold.
- Raises
ValueError (or InvalidArgumentError) – If
threshold
is not a scalar.
-
prepare_acquisition_function
(model: trieste.models.ProbabilisticModel, dataset: Optional[trieste.data.Dataset] = None) → trieste.acquisition.interface.AcquisitionFunction# - Parameters
model – The model.
dataset – Unused.
- Returns
The probability of feasibility function. This function will raise
ValueError
orInvalidArgumentError
if used with a batch size greater than one.
-
update_acquisition_function
(function: trieste.acquisition.interface.AcquisitionFunction, model: trieste.models.ProbabilisticModel, dataset: Optional[trieste.data.Dataset] = None) → trieste.acquisition.interface.AcquisitionFunction# - Parameters
function – The acquisition function to update.
model – The model.
dataset – Unused.
-
class
augmented_expected_improvement
(model: trieste.models.interfaces.SupportsGetObservationNoise, eta: trieste.types.TensorType)# Bases:
trieste.acquisition.interface.AcquisitionFunctionClass
An
AcquisitionFunctionClass
is an acquisition function represented using a class rather than as a standalone function. Using a class to represent an acquisition function makes it easier to update it, to avoid having to retrace the function on every call.Return the Augmented Expected Improvement (AEI) acquisition function for single-objective global optimization under homoscedastic observation noise. Improvement is with respect to the current “best” observation
eta
, where an improvement moves towards the objective function’s minimum and the expectation is calculated with respect to themodel
posterior. In contrast to standard EI, AEI has an additional multiplicative factor that penalizes evaluations made in areas of the space with very small posterior predictive variance. Thus, when applying standard EI to noisy optimisation problems, AEI avoids getting trapped and repeatedly querying the same point. For model posterior \(f\), this is .. math:: x mapsto EI(x) * left(1 - frac{tau^2}{sqrt{s^2(x)+tau^2}}right), where \(s^2(x)\) is the predictive variance and \(\tau\) is observation noise. This function was introduced by Huang et al, 2006. See [HANZ06] for details.- Parameters
model – The model of the objective function.
eta – The “best” observation.
- Returns
The expected improvement function. This function will raise
ValueError
orInvalidArgumentError
if used with a batch size greater than one or a model without homoscedastic observation noise.
-
update
(eta: trieste.types.TensorType) → None# Update the acquisition function with a new eta value and noise variance.
-
__call__
(x: trieste.types.TensorType) → trieste.types.TensorType# Call acquisition function.
-
batch_ehvi
(sampler: trieste.models.ReparametrizationSampler[trieste.models.interfaces.HasReparamSampler], sampler_jitter: float, partition_bounds: tuple[trieste.types.TensorType, trieste.types.TensorType]) → trieste.acquisition.interface.AcquisitionFunction# - Parameters
sampler – The posterior sampler, which given query points at, is able to sample the possible observations at ‘at’.
sampler_jitter – The size of the jitter to use in sampler when stabilising the Cholesky decomposition of the covariance matrix.
partition_bounds – with shape ([N, D], [N, D]), partitioned non-dominated hypercell bounds for hypervolume improvement calculation
- Returns
The batch expected hypervolume improvement acquisition function for objective minimisation.
-
class
batch_expected_improvement
(sample_size: int, model: trieste.models.ProbabilisticModel, eta: trieste.types.TensorType, jitter: float)# Bases:
trieste.acquisition.interface.AcquisitionFunctionClass
An
AcquisitionFunctionClass
is an acquisition function represented using a class rather than as a standalone function. Using a class to represent an acquisition function makes it easier to update it, to avoid having to retrace the function on every call.Initialise the batch_expected_improvement instance.
- Parameters
sample_size – int, number of samples to use.
model – Gaussian process regression model.
eta – Tensor of shape (,), expected improvement threshold. This is the best value observed so far durin the BO loop.
jitter – float, amount of jitter for Cholesky factorisations.
-
update
(eta: trieste.types.TensorType) → None# Update the acquisition function with a new eta value and reset the reparam sampler.
-
_compute_bm
(mean: tensorflow.Tensor, threshold: tensorflow.Tensor) → trieste.types.TensorType# Helper function for the batch expected improvement, which computes the tensors b and m as detailed in Chevalier and Ginsbourger [CG13].
- Parameters
mean – Tensor of shape (B, Q)
threshold – Tensor of shape (B,)
- Returns b
Tensor of shape (B, Q, Q)
- Returns m
Tensor of shape (B, Q, Q)
-
_delta
(idx: int, dim: int, B: int, transpose: bool, dtype: tensorflow.DType) → trieste.types.TensorType# Helper function for the _compute_Sigma function, which computes a delta tensor of shape (B, idx, idx) such that
delta[B, i, :] = 1 if i == idx delta[B, i, :] = 0 otherwise.
If transpose == True, then the last two dimensions of the tensor are transposed, in which case
delta[B, :, i] = 1 if i == idx delta[B, :, i] = 0 otherwise.
- Parameters
idx – Index for entries equal to 1.
dim – Dimension of the last and second to last axes.
B – Leading dimension of tensor.
transpose – Whether to transpose the last two dimensions or not.
dtype – The dtype of the tensor, either tf.float32 or tf.float64.
-
_compute_Sigma
(covariance: tensorflow.Tensor) → trieste.types.TensorType# Helper function for the batch expected improvement, which computes the tensor Sigma, as detailed in Chevalier and Ginsbourger [CG13].
- Parameters
covariance – Tensor of shape (B, Q, Q)
- Returns Sigma
Tensor of shape (B, Q, Q, Q)
-
_compute_p
(m_reshaped: tensorflow.Tensor, b_reshaped: tensorflow.Tensor, Sigma_reshaped: tensorflow.Tensor, mvn_cdf: Callable[[trieste.types.TensorType, trieste.types.TensorType, trieste.types.TensorType, float], trieste.types.TensorType]) → trieste.types.TensorType# Helper function for the batch expected improvement, which computes the tensor p, as detailed in Chevalier and Ginsbourger [CG13].
- Parameters
m_reshaped – Tensor of shape (BQ, Q)
b_reshaped – Tensor of shape (BQ, Q)
Sigma_reshaped – Tensor of shape (BQ, Q, Q)
- Returns p
Tensor of shape (B, Q)
-
_compute_c
(m_reshaped: tensorflow.Tensor, b_reshaped: tensorflow.Tensor, Sigma_reshaped: tensorflow.Tensor) → trieste.types.TensorType# Helper function for the batch expected improvement, which computes the tensor c, which is the c^{(i)} tensor detailed in Chevalier and Ginsbourger [CG13].
- Parameters
m_reshaped – Tensor of shape (BQ, Q)
b_reshaped – Tensor of shape (BQ, Q)
Sigma_reshaped – Tensor of shape (BQ, Q, Q)
- Returns c
Tensor of shape (B, Q, Q-1)
-
_compute_R
(Sigma_reshaped: tensorflow.Tensor) → trieste.types.TensorType# Helper function for the batch expected improvement, which computes the tensor R, which is the Sigma^{(i)} tensor detailed in Chevalier and Ginsbourger [CG13].
- Parameters
Sigma_reshaped – Tensor of shape (BQ, Q, Q)
- Returns R
Tensor of shape (B, Q-1, Q-1)
-
_compute_Phi
(c: tensorflow.Tensor, R: tensorflow.Tensor, mvn_cdf: Callable[[trieste.types.TensorType, trieste.types.TensorType, trieste.types.TensorType, float], trieste.types.TensorType]) → trieste.types.TensorType# Helper function for the batch expected improvement, which computes the tensor Phi, which is the tensor of multivariate Gaussian CDFs, in the inner sum of the equation (3) in Chevalier and Ginsbourger [CG13].
- Parameters
c – Tensor of shape (BQ, Q, Q-1).
R – Tensor of shape (BQ, Q, Q-1, Q-1).
mvn_cdf – Multivariate Gaussian CDF, made using MultivariateNormalCDF.
- Returns Phi
Tensor of multivariate Gaussian CDFs.
-
_compute_batch_expected_improvement
(mean: tensorflow.Tensor, covariance: tensorflow.Tensor, threshold: tensorflow.Tensor, mvn_cdf_1: Callable[[trieste.types.TensorType, trieste.types.TensorType, trieste.types.TensorType, float], trieste.types.TensorType], mvn_cdf_2: Callable[[trieste.types.TensorType, trieste.types.TensorType, trieste.types.TensorType, float], trieste.types.TensorType]) → trieste.types.TensorType# Accurate Monte Carlo approximation of the batch expected improvement, using the method of Chevalier and Ginsbourger [CG13].
- Parameters
mean – Tensor of shape (B, Q).
covariance – Tensor of shape (B, Q, Q).
threshold – Tensor of shape (B, Q).
mvn_cdf_1 – Callable computing the multivariate CDF of a Q-dimensional Gaussian.
mvn_cdf_2 – Callable computing the multivariate CDF of a (Q-1)-dimensional Gaussian.
- Returns ei
Tensor of shape (B,), expected improvement.
-
__call__
(x: trieste.types.TensorType) → trieste.types.TensorType# Computes the accurate approximation of the multi-point expected improvement.
- Parameters
x – Tensor of shape (B, Q, D).
- Returns ei
Tensor of shape (B,), expected improvement.
-
class
bayesian_active_learning_by_disagreement
(model: trieste.models.ProbabilisticModel, jitter: float)# Bases:
trieste.acquisition.interface.AcquisitionFunctionClass
An
AcquisitionFunctionClass
is an acquisition function represented using a class rather than as a standalone function. Using a class to represent an acquisition function makes it easier to update it, to avoid having to retrace the function on every call.The Bayesian active learning by disagrement acquisition function computes the information gain of the predictive entropy [HHGL11]. the acquisiton function is calculated by:
\[\mathrm{h}\left(\Phi\left(\frac{\mu_{\boldsymbol{x}, \mathcal{D}}} {\sqrt{\sigma_{\boldsymbol{x}, \mathcal{D}}^{2}+1}}\right)\right) -\frac{C \exp \left(-\frac{\mu_{\boldsymbol{x}, \mathcal{D}}^{2}} {2\left(\sigma_{\boldsymbol{w}, \mathcal{D}}^{+C^{2}}\right)}\right)} {\sqrt{\sigma_{\boldsymbol{x}, \mathcal{D}}^{2}+C^{2}}}\]Here \(\mathrm{h}(p)\) is defined as:
\[\mathrm{h}(p)=-p \log p-(1-p) \log (1-p)\]This acquisition function is intended to use for Binary Gaussian Process Classification model with Bernoulli likelihood. It is designed for VGP but other Gaussian approximation of the posterior can be used. SVGP for instance, or some other model that is not currently supported by Trieste. Integrating over nuisance parameters is currently not supported (see equation 6 of the paper).
- Parameters
model – The model of the objective function.
jitter – The size of the jitter to avoid numerical problem caused by the log operation if variance is close to zero.
- Returns
The Bayesian Active Learning By Disagreement acquisition function.
-
__call__
(x: trieste.types.TensorType) → trieste.types.TensorType# Call acquisition function.
-
bichon_ranjan_criterion
(model: trieste.models.ProbabilisticModel, threshold: float, alpha: float, delta: int) → trieste.acquisition.interface.AcquisitionFunction# Return the bichon criterion ([BES+08]) and ranjan criterion ([RBM08]) used in Expected feasibility acquisition function for active learning of failure or feasibility regions.
The problem of identifying a failure or feasibility region of a function \(f\) can be formalized as estimating the excursion set, \(\Gamma^* = \{ x \in X: f(x) \ge T\}\), or estimating the contour line, \(C^* = \{ x \in X: f(x) = T\}\), for some threshold \(T\) (see [BGL+12] for more details).
It turns out that probabilistic models can be used as classifiers for identifying where excursion probability is larger than 1/2 and this idea is used to build many sequential sampling strategies. We follow [BGL+12] and use a formulation which provides a common expression for these two criteria:
\[\mathbb{E}[\max(0, (\alpha s(x))^\delta - |T - m(x)|^\delta)]\]Here \(m(x)\) and \(s(x)\) are the mean and standard deviation of the predictive posterior of a probabilistic model. Bichon criterion is obtained when \(\delta = 1\) while ranjan criterion is obtained when \(\delta = 2\). \(\alpha>0\) is another parameter that acts as a percentage of standard deviation of the posterior around the current boundary estimate where we want to sample. The goal is to sample a point with a mean close to the threshold \(T\) and a high variance, so that the positive difference in the equation above is as large as possible.
Note that only batches of size 1 are allowed.
- Parameters
model – The probabilistic model of the objective function.
threshold – The failure or feasibility threshold.
alpha – The parameter which determines the neighbourhood around the estimated contour line as a percentage of the posterior variance in which to allocate new points.
delta – The parameter identifying which criterion is used, bichon for value of 1 and ranjan for value of 2.
-
class
expected_hv_improvement
(model: trieste.models.ProbabilisticModel, partition_bounds: tuple[trieste.types.TensorType, trieste.types.TensorType])# Bases:
trieste.acquisition.interface.AcquisitionFunctionClass
An
AcquisitionFunctionClass
is an acquisition function represented using a class rather than as a standalone function. Using a class to represent an acquisition function makes it easier to update it, to avoid having to retrace the function on every call.expected Hyper-volume (HV) calculating using Eq. 44 of [YEDBack19] paper. The expected hypervolume improvement calculation in the non-dominated region can be decomposed into sub-calculations based on each partitioned cell. For easier calculation, this sub-calculation can be reformulated as a combination of two generalized expected improvements, corresponding to Psi (Eq. 44) and Nu (Eq. 45) function calculations, respectively.
Note: 1. Since in Trieste we do not assume the use of a certain non-dominated region partition algorithm, we do not assume the last dimension of the partitioned cell has only one (lower) bound (i.e., minus infinity, which is used in the [YEDBack19] paper). This is not as efficient as the original paper, but is applicable to different non-dominated partition algorithm. 2. As the Psi and nu function in the original paper are defined for maximization problems, we inverse our minimisation problem (to also be a maximisation), allowing use of the original notation and equations.
- Parameters
model – The model of the objective function.
partition_bounds – with shape ([N, D], [N, D]), partitioned non-dominated hypercell bounds for hypervolume improvement calculation
- Returns
The expected_hv_improvement acquisition function modified for objective minimisation. This function will raise
ValueError
orInvalidArgumentError
if used with a batch size greater than one.
-
update
(partition_bounds: tuple[trieste.types.TensorType, trieste.types.TensorType]) → None# Update the acquisition function with new partition bounds.
-
__call__
(x: trieste.types.TensorType) → trieste.types.TensorType# Call acquisition function.
-
class
expected_improvement
(model: trieste.models.ProbabilisticModel, eta: trieste.types.TensorType)# Bases:
trieste.acquisition.interface.AcquisitionFunctionClass
An
AcquisitionFunctionClass
is an acquisition function represented using a class rather than as a standalone function. Using a class to represent an acquisition function makes it easier to update it, to avoid having to retrace the function on every call.Return the Expected Improvement (EI) acquisition function for single-objective global optimization. Improvement is with respect to the current “best” observation
eta
, where an improvement moves towards the objective function’s minimum and the expectation is calculated with respect to themodel
posterior. For model posterior \(f\), this is\[x \mapsto \mathbb E \left[ \max (\eta - f(x), 0) \right]\]This function was introduced by Mockus et al, 1975. See [JSW98] for details.
- Parameters
model – The model of the objective function.
eta – The “best” observation.
- Returns
The expected improvement function. This function will raise
ValueError
orInvalidArgumentError
if used with a batch size greater than one.
-
update
(eta: trieste.types.TensorType) → None# Update the acquisition function with a new eta value.
-
__call__
(x: trieste.types.TensorType) → trieste.types.TensorType# Call acquisition function.
-
fast_constraints_feasibility
(search_space: trieste.space.SearchSpace, smoothing_function: Optional[Callable[[trieste.types.TensorType], trieste.types.TensorType]] = None) → trieste.acquisition.interface.AcquisitionFunction# Returns a feasiblity acquisition function from the residuals of explicit constraints defined in the search space.
- Parameters
search_space – The global search space over which the feasibility of the constraints is defined.
smoothing_function – The smoothing function used for constraints residuals. The default is CDF of the Normal distribution with a scale of 1e-3.
- Returns
The function for feasibility of constraints.
- Raises
NotImplementedError – If the search_space does not have constraints.
-
class
gibbon_quality_term
(model: SupportsCovarianceObservationNoise, samples: trieste.types.TensorType)# Bases:
trieste.acquisition.interface.AcquisitionFunctionClass
An
AcquisitionFunctionClass
is an acquisition function represented using a class rather than as a standalone function. Using a class to represent an acquisition function makes it easier to update it, to avoid having to retrace the function on every call.GIBBON’s quality term measures the amount of information that each individual batch element provides about the objective function’s minimal value \(y^*\) (ensuring that evaluations are targeted in promising areas of the space).
- Parameters
model – The model of the objective function. GIBBON requires a model with a :method:covariance_between_points method and so GIBBON only supports
GaussianProcessRegression
models.samples – Samples from the distribution over \(y^*\).
- Returns
GIBBON’s quality term. This function will raise
ValueError
orInvalidArgumentError
if used with a batch size greater than one.- Raises
ValueError or tf.errors.InvalidArgumentError – If
samples
does not have rank two, or is empty, or ifmodel
has no homoscedastic observation noise.AttributeError – If
model
doesn’t implement covariance_between_points method.
-
update
(samples: trieste.types.TensorType) → None# Update the acquisition function with new samples.
-
__call__
(x: trieste.types.TensorType) → trieste.types.TensorType# Call acquisition function.
-
class
gibbon_repulsion_term
(model: SupportsCovarianceObservationNoise, pending_points: trieste.types.TensorType, rescaled_repulsion: bool = True)# Bases:
trieste.acquisition.interface.UpdatablePenalizationFunction
An
UpdatablePenalizationFunction
builds and updates a penalization function. Defining a penalization function that can be updated avoids having to retrace on every call.GIBBON’s repulsion term encourages diversity within the batch (achieving high values for points with low predictive correlation).
The repulsion term \(r=\log |C|\) is given by the log determinant of the predictive correlation matrix \(C\) between the m pending points and the current candidate. The predictive covariance \(V\) can be expressed as :math:V = [[v, A], [A, B]]` for a tensor \(B\) with shape [m,`m`] and so we can efficiently calculate \(|V|\) using the formula for the determinant of block matrices, i.e \(|V| = (v - A^T * B^{-1} * A) * |B|\). Note that when using GIBBON for purely sequential optimization, the repulsion term is not required.
As GIBBON’s batches are built in a greedy manner, i.e sequentially adding points to build a set of m pending points, we need only ever calculate the entropy reduction provided by adding the current candidate point to the current pending points, not the full information gain provided by evaluating all the pending points. This allows for a modest computational saving.
When performing batch BO, GIBBON’s approximation can sometimes become less accurate as its repulsion term dominates. Therefore, we follow the arguments of [MLGR21] and divide GIBBON’s repulsion term by \(B^{2}\). This behavior can be deactivated by setting rescaled_repulsion to False.
- Parameters
model – The model of the objective function. GIBBON requires a model with a :method:covariance_between_points method and so GIBBON only supports
GaussianProcessRegression
models.pending_points – The points already chosen in the current batch.
rescaled_repulsion – If True, then downweight GIBBON’s repulsion term to improve batch optimization performance.
- Returns
GIBBON’s repulsion term. This function will raise
ValueError
orInvalidArgumentError
if used with a batch size greater than one.- Raises
ValueError or tf.errors.InvalidArgumentError – If
pending_points
does not have rank two, or is empty, or ifmodel
has no homoscedastic observation noise.AttributeError – If
model
doesn’t implement covariance_between_points method.
-
update
(pending_points: trieste.types.TensorType, lipschitz_constant: trieste.types.TensorType = None, eta: trieste.types.TensorType = None) → None# Update the repulsion term with new variable values.
-
__call__
(x: trieste.types.TensorType) → trieste.types.TensorType# Call penalization function..
-
class
hard_local_penalizer
(model: trieste.models.ProbabilisticModel, pending_points: trieste.types.TensorType, lipschitz_constant: trieste.types.TensorType, eta: trieste.types.TensorType)# Bases:
local_penalizer
Return the hard local penalization function used for single-objective greedy batch Bayesian optimization in [ARC+19].
Hard penalization is a stronger penalizer than soft penalization and is sometimes more effective See [ARC+19] for details. Our implementation follows theirs, with the penalization from a set of pending points being the product of the individual penalizations.
- Parameters
model – The model over the specified
dataset
.pending_points – The points we penalize with respect to.
lipschitz_constant – The estimated Lipschitz constant of the objective function.
eta – The estimated global minima.
- Returns
The local penalization function. This function will raise
ValueError
orInvalidArgumentError
if used with a batch size greater than one.
Initialize the local penalizer.
- Parameters
model – The model over the specified
dataset
.pending_points – The points we penalize with respect to.
lipschitz_constant – The estimated Lipschitz constant of the objective function.
eta – The estimated global minima.
- Returns
The local penalization function. This function will raise
ValueError
orInvalidArgumentError
if used with a batch size greater than one.
-
__call__
(x: trieste.types.TensorType) → trieste.types.TensorType# Call penalization function..
-
class
integrated_variance_reduction
(model: trieste.models.interfaces.FastUpdateModel, integration_points: trieste.types.TensorType, threshold: Optional[Union[float, Sequence[float], trieste.types.TensorType]] = None)# Bases:
trieste.acquisition.interface.AcquisitionFunctionClass
The reduction of the (weighted) average of the predicted variance over the integration points (a.k.a. Integrated Means Square Error or IMSE criterion). See [PGR+10] for details.
The criterion (to maximise) writes as:
\[\int_x (v_{old}(x) - v_{new}(x)) * weights(x),\]where \(v_{old}(x)\) is the predictive variance of the model at \(x\), and \(v_{new}(x)\) is the updated predictive variance, given that the GP is further conditioned on the query points.
Note that since \(v_{old}(x)\) is constant w.r.t. the query points, this function only returns \(-\int_x v_{new}(x) * weights(x)\).
If no threshold is provided, the goal is to learn a globally accurate model, and the predictive variance (\(v_{new}\)) is used. Otherwise, learning is ‘targeted’ towards regions where the GP is close to particular values, and the variance is weighted by the posterior GP pdf evaluated at the threshold T (if a single value is given) or by the probability that the GP posterior belongs to the interval between the 2 thresholds T1 and T2 (note the slightly different parametrisation compared to [PGR+10] in that case).
This criterion allows batch size > 1. Note that the computational cost grows cubically with the batch size.
This criterion requires a method (conditional_predict_f) to compute the new predictive variance given that query points are added to the data.
- Parameters
model – The model of the objective function.
integration_points – Points over which to integrate the objective prediction variance.
threshold – Either None, a float or a sequence of 1 or 2 float values. See class docs for details.
- Raises
ValueError (or InvalidArgumentError) – If
threshold
has more than 2 values.
-
__call__
(x: trieste.types.TensorType) → trieste.types.TensorType# Call acquisition function.
-
lower_confidence_bound
(model: trieste.models.ProbabilisticModel, beta: float) → trieste.acquisition.interface.AcquisitionFunction# The lower confidence bound (LCB) acquisition function for single-objective global optimization.
\[x^* \mapsto \mathbb{E} [f(x^*)|x, y] - \beta \sqrt{ \mathrm{Var}[f(x^*)|x, y] }\]See [SKSK10] for details.
- Parameters
model – The model of the objective function.
beta – The weight to give to the standard deviation contribution of the LCB. Must not be negative.
- Returns
The lower confidence bound function. This function will raise
ValueError
orInvalidArgumentError
if used with a batch size greater than one.- Raises
tf.errors.InvalidArgumentError – If
beta
is negative.
-
class
min_value_entropy_search
(model: trieste.models.ProbabilisticModel, samples: trieste.types.TensorType)# Bases:
trieste.acquisition.interface.AcquisitionFunctionClass
An
AcquisitionFunctionClass
is an acquisition function represented using a class rather than as a standalone function. Using a class to represent an acquisition function makes it easier to update it, to avoid having to retrace the function on every call.Return the max-value entropy search acquisition function (adapted from [WJ17]), modified for objective minimisation. This function calculates the information gain (or change in entropy) in the distribution over the objective minimum \(y^*\), if we were to evaluate the objective at a given point.
- Parameters
model – The model of the objective function.
samples – Samples from the distribution over \(y^*\).
- Returns
The max-value entropy search acquisition function modified for objective minimisation. This function will raise
ValueError
orInvalidArgumentError
if used with a batch size greater than one.- Raises
ValueError or tf.errors.InvalidArgumentError – If
samples
has rank less than two, or is empty.
-
update
(samples: trieste.types.TensorType) → None# Update the acquisition function with new samples.
-
__call__
(x: trieste.types.TensorType) → trieste.types.TensorType# Call acquisition function.
-
class
multiple_optimism_lower_confidence_bound
(model: trieste.models.ProbabilisticModel, search_space_dim: int)# Bases:
trieste.acquisition.interface.AcquisitionFunctionClass
The multiple optimism lower confidence bound (MOLCB) acquisition function for single-objective global optimization.
Each batch dimension of this acquisiton function correponds to a lower confidence bound acquisition function with different beta values, i.e. each point in a batch chosen by this acquisition function lies on a gradient of exploration/exploitation trade-offs.
We choose the different beta values following the cdf method of [TPD20]. See their paper for more details.
- Parameters
model – The model of the objective function.
search_space_dim – The dimensions of the optimisation problem’s search space.
- Raises
tf.errors.InvalidArgumentError – If
search_space_dim
is not postive.
-
__call__
(x: trieste.types.TensorType) → trieste.types.TensorType# Call acquisition function.
-
predictive_variance
(model: trieste.models.interfaces.SupportsPredictJoint, jitter: float) → trieste.acquisition.interface.AcquisitionFunction# The predictive variance acquisition function for active learning, based on the determinant of the covariance (see [Mac92] for details). Note that the model needs to supply covariance of the joint marginal distribution, which can be expensive to compute.
- Parameters
model – The model of the objective function.
jitter – The size of the jitter to use when stabilising the Cholesky decomposition of the covariance matrix.
-
class
probability_below_threshold
(model: trieste.models.ProbabilisticModel, threshold: float | TensorType)# Bases:
trieste.acquisition.interface.AcquisitionFunctionClass
An
AcquisitionFunctionClass
is an acquisition function represented using a class rather than as a standalone function. Using a class to represent an acquisition function makes it easier to update it, to avoid having to retrace the function on every call.The probability of being below the threshold. This brings together commonality between probability of improvement and probability of feasiblity. Probability is is caculated with respect to the model posterior. For model posterior \(f\), this is .. math:: x mapsto mathbb P left (f(x) < eta)right] where \(\eta\) is the threshold. :param model: The model of the objective function. :param threshold: The (scalar) probability of feasibility threshold. :return: The probability of feasibility function. This function will raise
ValueError
orInvalidArgumentError
if used with a batch size greater than one. :raise ValueError or tf.errors.InvalidArgumentError: Ifthreshold
is not a scalar.-
__call__
(x: trieste.types.TensorType) → trieste.types.TensorType# Call acquisition function.
-
update
(threshold: trieste.types.TensorType) → None# Update the acquisition function with a new threshold value.
-
-
class
soft_local_penalizer
(model: trieste.models.ProbabilisticModel, pending_points: trieste.types.TensorType, lipschitz_constant: trieste.types.TensorType, eta: trieste.types.TensorType)# Bases:
local_penalizer
Return the soft local penalization function used for single-objective greedy batch Bayesian optimization in [GonzalezDHL16].
Soft penalization returns the probability that a candidate point does not belong in the exclusion zones of the pending points. For model posterior mean \(\mu\), model posterior variance \(\sigma^2\), current “best” function value \(\eta\), and an estimated Lipschitz constant \(L\),the penalization from a set of pending point \(x'\) on a candidate point \(x\) is given by .. math:: phi(x, x’) = frac{1}{2}textrm{erfc}(-z) where \(z = \frac{1}{\sqrt{2\sigma^2(x')}}(L||x'-x|| + \eta - \mu(x'))\).
The penalization from a set of pending points is just product of the individual penalizations. See [GonzalezDHL16] for a full derivation.
- Parameters
model – The model over the specified
dataset
.pending_points – The points we penalize with respect to.
lipschitz_constant – The estimated Lipschitz constant of the objective function.
eta – The estimated global minima.
- Returns
The local penalization function. This function will raise
ValueError
orInvalidArgumentError
if used with a batch size greater than one.
Initialize the local penalizer.
- Parameters
model – The model over the specified
dataset
.pending_points – The points we penalize with respect to.
lipschitz_constant – The estimated Lipschitz constant of the objective function.
eta – The estimated global minima.
- Returns
The local penalization function. This function will raise
ValueError
orInvalidArgumentError
if used with a batch size greater than one.
-
__call__
(x: trieste.types.TensorType) → trieste.types.TensorType# Call penalization function..
-
AcquisitionFunction
[source]# Type alias for acquisition functions.
An
AcquisitionFunction
maps a set of B query points (each of dimension D) to a single value that describes how useful it would be evaluate all these points together (to our goal of optimizing the objective function). Thus, with leading dimensions, anAcquisitionFunction
takes input shape […, B, D] and returns shape […, 1].Note that
AcquisitionFunction`s which do not support batch optimization still expect inputs with a batch dimension, i.e. an input of shape `[..., 1, D]
.
-
class
AcquisitionFunctionBuilder
[source]# Bases:
Generic
[trieste.models.interfaces.ProbabilisticModelType
],abc.ABC
An
AcquisitionFunctionBuilder
builds and updates an acquisition function.-
abstract
prepare_acquisition_function
(models: Mapping[trieste.types.Tag, trieste.models.interfaces.ProbabilisticModelType], datasets: Optional[Mapping[trieste.types.Tag, trieste.data.Dataset]] = None) → AcquisitionFunction# Prepare an acquisition function. We assume that this requires at least models, but it may sometimes also need data.
- Parameters
models – The models for each tag.
datasets – The data from the observer (optional).
- Returns
An acquisition function.
-
update_acquisition_function
(function: AcquisitionFunction, models: Mapping[trieste.types.Tag, trieste.models.interfaces.ProbabilisticModelType], datasets: Optional[Mapping[trieste.types.Tag, trieste.data.Dataset]] = None) → AcquisitionFunction# Update an acquisition function. By default this generates a new acquisition function each time. However, if the function is decorated with @tf.function, then you can override this method to update its variables instead and avoid retracing the acquisition function on every optimization loop.
- Parameters
function – The acquisition function to update.
models – The models for each tag.
datasets – The data from the observer (optional).
- Returns
The updated acquisition function.
-
abstract
-
class
AcquisitionFunctionClass
[source]# Bases:
abc.ABC
An
AcquisitionFunctionClass
is an acquisition function represented using a class rather than as a standalone function. Using a class to represent an acquisition function makes it easier to update it, to avoid having to retrace the function on every call.-
abstract
__call__
(x: trieste.types.TensorType) → trieste.types.TensorType# Call acquisition function.
-
abstract
-
class
GreedyAcquisitionFunctionBuilder
[source]# Bases:
Generic
[trieste.models.interfaces.ProbabilisticModelType
],abc.ABC
A
GreedyAcquisitionFunctionBuilder
builds an acquisition function suitable for greedily building batches for batch Bayesian Optimization. AGreedyAcquisitionFunctionBuilder
differs from anAcquisitionFunctionBuilder
by requiring that a set of pending points is passed to the builder. Note that this acquisition function is typically called B times each Bayesian optimization step, when building batches of size B.-
abstract
prepare_acquisition_function
(models: Mapping[trieste.types.Tag, trieste.models.interfaces.ProbabilisticModelType], datasets: Optional[Mapping[trieste.types.Tag, trieste.data.Dataset]] = None, pending_points: Optional[trieste.types.TensorType] = None) → AcquisitionFunction# Generate a new acquisition function. The first time this is called,
pending_points
will be None. Subsequent calls will be viaupdate_acquisition_function
below, unless that has been overridden.- Parameters
models – The models over each tag.
datasets – The data from the observer (optional).
pending_points – Points already chosen to be in the current batch (of shape [M,D]), where M is the number of pending points and D is the search space dimension.
- Returns
An acquisition function.
-
update_acquisition_function
(function: AcquisitionFunction, models: Mapping[trieste.types.Tag, trieste.models.interfaces.ProbabilisticModelType], datasets: Optional[Mapping[trieste.types.Tag, trieste.data.Dataset]] = None, pending_points: Optional[trieste.types.TensorType] = None, new_optimization_step: bool = True) → AcquisitionFunction# Update an acquisition function. By default this generates a new acquisition function each time. However, if the function is decorated with`@tf.function`, then you can override this method to update its variables instead and avoid retracing the acquisition function on every optimization loop.
- Parameters
function – The acquisition function to update.
models – The models over each tag.
datasets – The data from the observer (optional).
pending_points – Points already chosen to be in the current batch (of shape [M,D]), where M is the number of pending points and D is the search space dimension.
new_optimization_step – Indicates whether this call to update_acquisition_function is to start of a new optimization step, of to continue collecting batch of points for the current step. Defaults to
True
.
- Returns
The updated acquisition function.
-
abstract
-
PenalizationFunction
[source]# An
PenalizationFunction
maps a query point (of dimension D) to a single value that described how heavily it should be penalized (a positive quantity). As penalization is applied multiplicatively to acquisition functions, small penalization outputs correspond to a stronger penalization effect. Thus, with leading dimensions, anPenalizationFunction
takes input shape […, 1, D] and returns shape […, 1].
-
class
SingleModelAcquisitionBuilder
[source]# Bases:
Generic
[trieste.models.interfaces.ProbabilisticModelType
],abc.ABC
Convenience acquisition function builder for an acquisition function (or component of a composite acquisition function) that requires only one model, dataset pair.
-
using
(tag: trieste.types.Tag) → AcquisitionFunctionBuilder[trieste.models.interfaces.ProbabilisticModelType]# - Parameters
tag – The tag for the model, dataset pair to use to build this acquisition function.
- Returns
An acquisition function builder that selects the model and dataset specified by
tag
, as defined inprepare_acquisition_function()
.
-
abstract
prepare_acquisition_function
(model: trieste.models.interfaces.ProbabilisticModelType, dataset: Optional[trieste.data.Dataset] = None) → AcquisitionFunction# - Parameters
model – The model.
dataset – The data to use to build the acquisition function (optional).
- Returns
An acquisition function.
-
update_acquisition_function
(function: AcquisitionFunction, model: trieste.models.interfaces.ProbabilisticModelType, dataset: Optional[trieste.data.Dataset] = None) → AcquisitionFunction# - Parameters
function – The acquisition function to update.
model – The model.
dataset – The data from the observer (optional).
- Returns
The updated acquisition function.
-
-
class
SingleModelGreedyAcquisitionBuilder
[source]# Bases:
Generic
[trieste.models.interfaces.ProbabilisticModelType
],abc.ABC
Convenience acquisition function builder for a greedy acquisition function (or component of a composite greedy acquisition function) that requires only one model, dataset pair.
-
using
(tag: trieste.types.Tag) → GreedyAcquisitionFunctionBuilder[trieste.models.interfaces.ProbabilisticModelType]# - Parameters
tag – The tag for the model, dataset pair to use to build this acquisition function.
- Returns
An acquisition function builder that selects the model and dataset specified by
tag
, as defined inprepare_acquisition_function()
.
-
abstract
prepare_acquisition_function
(model: trieste.models.interfaces.ProbabilisticModelType, dataset: Optional[trieste.data.Dataset] = None, pending_points: Optional[trieste.types.TensorType] = None) → AcquisitionFunction# - Parameters
model – The model.
dataset – The data from the observer (optional).
pending_points – Points already chosen to be in the current batch (of shape [M,D]), where M is the number of pending points and D is the search space dimension.
- Returns
An acquisition function.
-
update_acquisition_function
(function: AcquisitionFunction, model: trieste.models.interfaces.ProbabilisticModelType, dataset: Optional[trieste.data.Dataset] = None, pending_points: Optional[trieste.types.TensorType] = None, new_optimization_step: bool = True) → AcquisitionFunction# - Parameters
function – The acquisition function to update.
model – The model.
dataset – The data from the observer (optional).
pending_points – Points already chosen to be in the current batch (of shape [M,D]), where M is the number of pending points and D is the search space dimension.
new_optimization_step – Indicates whether this call to update_acquisition_function is to start of a new optimization step, of to continue collecting batch of points for the current step. Defaults to
True
.
- Returns
The updated acquisition function.
-
-
class
SingleModelVectorizedAcquisitionBuilder
[source]# Bases:
SingleModelAcquisitionBuilder
[trieste.models.interfaces.ProbabilisticModelType
]Convenience acquisition function builder for vectorized acquisition functions (or component of a composite vectorized acquisition function) that requires only one model, dataset pair.
-
using
(tag: trieste.types.Tag) → AcquisitionFunctionBuilder[trieste.models.interfaces.ProbabilisticModelType]# - Parameters
tag – The tag for the model, dataset pair to use to build this acquisition function.
- Returns
An acquisition function builder that selects the model and dataset specified by
tag
, as defined inprepare_acquisition_function()
.
-
-
class
UpdatablePenalizationFunction
[source]# Bases:
abc.ABC
An
UpdatablePenalizationFunction
builds and updates a penalization function. Defining a penalization function that can be updated avoids having to retrace on every call.-
abstract
__call__
(x: trieste.types.TensorType) → trieste.types.TensorType# Call penalization function..
-
abstract
update
(pending_points: trieste.types.TensorType, lipschitz_constant: trieste.types.TensorType, eta: trieste.types.TensorType) → None# Update penalization function.
-
abstract
-
class
VectorizedAcquisitionFunctionBuilder
[source]# Bases:
AcquisitionFunctionBuilder
[trieste.models.interfaces.ProbabilisticModelType
]An
VectorizedAcquisitionFunctionBuilder
builds and updates a vectorized acquisition function These differ from normal acquisition functions only by their output shape: rather than returning a single value, they return one value per potential query point. Thus, with leading dimensions, they take input shape […, B, D] and returns shape […, B].
-
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# 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 ifsample_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# 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 ifsample_size
is not positive.
-
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 underlyingProbabilisticModel
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# - 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
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# 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 ifsample_size
is not positive.