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.
Subpackages#
Submodules#
Package Contents#
- class Product(*builders: trieste.acquisition.interface.AcquisitionFunctionBuilder[trieste.models.ProbabilisticModelType])[source]#
Bases:
Reducer
[trieste.models.ProbabilisticModelType
]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 [source]#
- 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.ProbabilisticModelType])[source]#
Bases:
trieste.acquisition.interface.AcquisitionFunctionBuilder
[trieste.models.ProbabilisticModelType
]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.
- property acquisitions: collections.abc.Sequence[trieste.acquisition.interface.AcquisitionFunctionBuilder[trieste.models.ProbabilisticModelType]]#
The acquisition function builders specified at class initialisation.
- prepare_acquisition_function(models: collections.abc.Mapping[trieste.types.Tag, trieste.models.ProbabilisticModelType], datasets: collections.abc.Mapping[trieste.types.Tag, trieste.data.Dataset] | None = None) trieste.acquisition.interface.AcquisitionFunction [source]#
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.ProbabilisticModelType], datasets: collections.abc.Mapping[trieste.types.Tag, trieste.data.Dataset] | None = None) trieste.acquisition.interface.AcquisitionFunction [source]#
- Parameters:
function – The acquisition function to update.
models – The model.
datasets – Unused.
- abstract _reduce(inputs: collections.abc.Sequence[trieste.types.TensorType]) trieste.types.TensorType [source]#
- 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.ProbabilisticModelType])[source]#
Bases:
Reducer
[trieste.models.ProbabilisticModelType
]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 [source]#
- 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)[source]#
- class GIBBON(search_space: trieste.space.SearchSpace, num_samples: int = 5, grid_size: int = 1000, min_value_sampler: trieste.acquisition.sampler.ThompsonSampler[GIBBONModelType] | None = 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: trieste.data.Dataset | None = None, pending_points: trieste.types.TensorType | None = None) trieste.acquisition.interface.AcquisitionFunction [source]#
- 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: trieste.data.Dataset | None = None, pending_points: trieste.types.TensorType | None = None, new_optimization_step: bool = True) trieste.acquisition.interface.AcquisitionFunction [source]#
- 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: trieste.acquisition.interface.AcquisitionFunctionBuilder[trieste.acquisition.interface.ProbabilisticModelType] | trieste.acquisition.interface.SingleModelAcquisitionBuilder[trieste.acquisition.interface.ProbabilisticModelType] | None = None)[source]#
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: Mapping[trieste.types.Tag, trieste.data.Dataset] | None = None, pending_points: trieste.types.TensorType | None = None) trieste.acquisition.interface.AcquisitionFunction [source]#
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: Mapping[trieste.types.Tag, trieste.data.Dataset] | None = None, pending_points: trieste.types.TensorType | None = None, new_optimization_step: bool = True) trieste.acquisition.interface.AcquisitionFunction [source]#
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[source]#
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: trieste.data.Dataset | None = None) trieste.acquisition.interface.AcquisitionFunction [source]#
- 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: trieste.data.Dataset | None = None) trieste.acquisition.interface.AcquisitionFunction [source]#
- 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)[source]#
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: trieste.data.Dataset | None = None) trieste.acquisition.interface.AcquisitionFunction [source]#
- 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: trieste.data.Dataset | None = None) trieste.acquisition.interface.AcquisitionFunction [source]#
- 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] | trieste.types.TensorType | Callable[Ellipsis, trieste.types.TensorType] = get_reference_point, *, jitter: float = DEFAULTS.JITTER)[source]#
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: trieste.data.Dataset | None = None) trieste.acquisition.interface.AcquisitionFunction [source]#
- 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)[source]#
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: trieste.data.Dataset | None = None) trieste.acquisition.interface.AcquisitionFunction [source]#
- 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: trieste.data.Dataset | None = None) trieste.acquisition.interface.AcquisitionFunction [source]#
- 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)[source]#
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: trieste.data.Dataset | None = None) trieste.acquisition.interface.AcquisitionFunction [source]#
- 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: trieste.data.Dataset | None = None) trieste.acquisition.interface.AcquisitionFunction [source]#
- 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 | trieste.types.TensorType = 0.5, reference_point_spec: Sequence[float] | trieste.types.TensorType | Callable[Ellipsis, trieste.types.TensorType] = get_reference_point)[source]#
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 [source]#
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 | trieste.types.TensorType = 0.5, search_space: trieste.space.SearchSpace | None = None)[source]#
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: Mapping[trieste.types.Tag, trieste.data.Dataset] | None = None) trieste.acquisition.interface.AcquisitionFunction [source]#
- 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: Mapping[trieste.types.Tag, trieste.data.Dataset] | None = None) trieste.acquisition.interface.AcquisitionFunction [source]#
- 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 [source]#
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)[source]#
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: trieste.data.Dataset | None = None) trieste.acquisition.interface.AcquisitionFunction [source]#
- 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: trieste.data.Dataset | None = None) trieste.acquisition.interface.AcquisitionFunction [source]#
- 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] | trieste.types.TensorType | Callable[Ellipsis, trieste.types.TensorType] = get_reference_point)[source]#
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: trieste.data.Dataset | None = None) trieste.acquisition.interface.AcquisitionFunction [source]#
- 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: trieste.data.Dataset | None = None) trieste.acquisition.interface.AcquisitionFunction [source]#
- Parameters:
function – The acquisition function to update.
model – The model.
dataset – The data from the observer. Must be populated.
- class ExpectedImprovement(search_space: trieste.space.SearchSpace | None = None)[source]#
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: trieste.data.Dataset | None = None) trieste.acquisition.interface.AcquisitionFunction [source]#
- 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: trieste.data.Dataset | None = None) trieste.acquisition.interface.AcquisitionFunction [source]#
- 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: trieste.acquisition.interface.AcquisitionFunctionBuilder[trieste.models.interfaces.SupportsPredictJoint] | trieste.acquisition.interface.SingleModelAcquisitionBuilder[trieste.models.interfaces.SupportsPredictJoint] | None = None, fantasize_method: str = 'KB')[source]#
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: Mapping[trieste.types.Tag, trieste.data.Dataset] | None = None, pending_points: trieste.types.TensorType | None = None) trieste.acquisition.interface.AcquisitionFunction [source]#
- 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: Mapping[trieste.types.Tag, trieste.data.Dataset] | None = None, pending_points: trieste.types.TensorType | None = None, new_optimization_step: bool = True) trieste.acquisition.interface.AcquisitionFunction [source]#
- 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: Callable[[trieste.types.TensorType], trieste.types.TensorType] | None = None)[source]#
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: trieste.data.Dataset | None = None) trieste.acquisition.interface.AcquisitionFunction [source]#
- 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: trieste.data.Dataset | None = None) trieste.acquisition.interface.AcquisitionFunction [source]#
- 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)[source]#
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: trieste.data.Dataset | None = None, pending_points: trieste.types.TensorType | None = None) trieste.models.interfaces.TrajectoryFunction [source]#
- 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: trieste.data.Dataset | None = None, pending_points: trieste.types.TensorType | None = None, new_optimization_step: bool = True) trieste.models.interfaces.TrajectoryFunction [source]#
- 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: float | Sequence[float] | trieste.types.TensorType | None = None)[source]#
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: trieste.data.Dataset | None = None) trieste.acquisition.interface.AcquisitionFunction [source]#
- 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: trieste.data.Dataset | None = None) trieste.acquisition.interface.AcquisitionFunction [source]#
- 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], trieste.acquisition.interface.PenalizationFunction | trieste.acquisition.interface.UpdatablePenalizationFunction] | None = None, base_acquisition_function_builder: trieste.acquisition.function.function.ExpectedImprovement | trieste.acquisition.function.entropy.MinValueEntropySearch[trieste.models.ProbabilisticModel] | trieste.acquisition.function.function.MakePositive[trieste.models.ProbabilisticModel] | None = None)[source]#
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: trieste.data.Dataset | None = None, pending_points: trieste.types.TensorType | None = None) trieste.acquisition.interface.AcquisitionFunction [source]#
- 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: trieste.data.Dataset | None = None, pending_points: trieste.types.TensorType | None = None, new_optimization_step: bool = True) trieste.acquisition.interface.AcquisitionFunction [source]#
- 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])[source]#
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: trieste.data.Dataset | None = None) trieste.acquisition.interface.AcquisitionFunction [source]#
- 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: trieste.data.Dataset | None = None) trieste.acquisition.interface.AcquisitionFunction [source]#
- 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)[source]#
- class MinValueEntropySearch(search_space: trieste.space.SearchSpace, num_samples: int = 5, grid_size: int = 1000, min_value_sampler: trieste.acquisition.sampler.ThompsonSampler[trieste.acquisition.interface.ProbabilisticModelType] | None = 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: trieste.data.Dataset | None = None) trieste.acquisition.interface.AcquisitionFunction [source]#
- 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: trieste.data.Dataset | None = None) trieste.acquisition.interface.AcquisitionFunction [source]#
- 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)[source]#
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: trieste.data.Dataset | None = None) trieste.acquisition.interface.AcquisitionFunction [source]#
- 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: trieste.data.Dataset | None = None) trieste.acquisition.interface.AcquisitionFunction [source]#
- 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)[source]#
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: trieste.data.Dataset | None = None) trieste.acquisition.interface.AcquisitionFunction [source]#
- 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: trieste.data.Dataset | None = None) trieste.acquisition.interface.AcquisitionFunction [source]#
- 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)[source]#
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: trieste.data.Dataset | None = None) trieste.acquisition.interface.AcquisitionFunction [source]#
- 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: trieste.data.Dataset | None = None) trieste.acquisition.interface.AcquisitionFunction [source]#
- Parameters:
function – The acquisition function to update.
model – The model.
dataset – Unused.
- class NegativeLowerConfidenceBound(beta: float = 1.96)[source]#
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: trieste.data.Dataset | None = None) trieste.acquisition.interface.AcquisitionFunction [source]#
- 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: trieste.data.Dataset | None = None) trieste.acquisition.interface.AcquisitionFunction [source]#
- Parameters:
function – The acquisition function to update.
model – The model.
dataset – Unused.
- class NegativePredictiveMean[source]#
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)[source]#
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: trieste.data.Dataset | None = None) trieste.models.interfaces.TrajectoryFunction [source]#
- 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: trieste.data.Dataset | None = None) trieste.models.interfaces.TrajectoryFunction [source]#
- 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)[source]#
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: trieste.data.Dataset | None = None) trieste.acquisition.interface.AcquisitionFunction [source]#
- 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: trieste.data.Dataset | None = None) trieste.acquisition.interface.AcquisitionFunction [source]#
- Parameters:
function – The acquisition function to update.
model – The model.
dataset – Unused.
- class ProbabilityOfFeasibility(threshold: float | trieste.types.TensorType)[source]#
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: trieste.data.Dataset | None = None) trieste.acquisition.interface.AcquisitionFunction [source]#
- 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: trieste.data.Dataset | None = None) trieste.acquisition.interface.AcquisitionFunction [source]#
- 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)[source]#
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.
- 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 [source]#
- 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)[source]#
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 [source]#
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 [source]#
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 [source]#
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 [source]#
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 [source]#
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 [source]#
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 [source]#
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 [source]#
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 [source]#
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.
- class bayesian_active_learning_by_disagreement(model: trieste.models.ProbabilisticModel, jitter: float)[source]#
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.
- bichon_ranjan_criterion(model: trieste.models.ProbabilisticModel, threshold: float, alpha: float, delta: int) trieste.acquisition.interface.AcquisitionFunction [source]#
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])[source]#
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.
- class expected_improvement(model: trieste.models.ProbabilisticModel, eta: trieste.types.TensorType)[source]#
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.
- fast_constraints_feasibility(search_space: trieste.space.SearchSpace, smoothing_function: Callable[[trieste.types.TensorType], trieste.types.TensorType] | None = None) trieste.acquisition.interface.AcquisitionFunction [source]#
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)[source]#
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.
- class gibbon_repulsion_term(model: SupportsCovarianceObservationNoise, pending_points: trieste.types.TensorType, rescaled_repulsion: bool = True)[source]#
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.
- class hard_local_penalizer(model: trieste.models.ProbabilisticModel, pending_points: trieste.types.TensorType, lipschitz_constant: trieste.types.TensorType, eta: trieste.types.TensorType)[source]#
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.
- class integrated_variance_reduction(model: trieste.models.interfaces.FastUpdateModel, integration_points: trieste.types.TensorType, threshold: float | Sequence[float] | trieste.types.TensorType | None = None)[source]#
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.
- lower_confidence_bound(model: trieste.models.ProbabilisticModel, beta: float) trieste.acquisition.interface.AcquisitionFunction [source]#
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)[source]#
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.
- class multiple_optimism_lower_confidence_bound(model: trieste.models.ProbabilisticModel, search_space_dim: int)[source]#
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.
- predictive_variance(model: trieste.models.interfaces.SupportsPredictJoint, jitter: float) trieste.acquisition.interface.AcquisitionFunction [source]#
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 | trieste.types.TensorType)[source]#
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.
- class soft_local_penalizer(model: trieste.models.ProbabilisticModel, pending_points: trieste.types.TensorType, lipschitz_constant: trieste.types.TensorType, eta: trieste.types.TensorType)[source]#
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.
- 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: Mapping[trieste.types.Tag, trieste.data.Dataset] | None = None) AcquisitionFunction [source]#
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: Mapping[trieste.types.Tag, trieste.data.Dataset] | None = None) AcquisitionFunction [source]#
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.
- 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.
- 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: Mapping[trieste.types.Tag, trieste.data.Dataset] | None = None, pending_points: trieste.types.TensorType | None = None) AcquisitionFunction [source]#
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: Mapping[trieste.types.Tag, trieste.data.Dataset] | None = None, pending_points: trieste.types.TensorType | None = None, new_optimization_step: bool = True) AcquisitionFunction [source]#
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.
- 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] [source]#
- 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: trieste.data.Dataset | None = None) AcquisitionFunction [source]#
- 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: trieste.data.Dataset | None = None) AcquisitionFunction [source]#
- 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] [source]#
- 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: trieste.data.Dataset | None = None, pending_points: trieste.types.TensorType | None = None) AcquisitionFunction [source]#
- 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: trieste.data.Dataset | None = None, pending_points: trieste.types.TensorType | None = None, new_optimization_step: bool = True) AcquisitionFunction [source]#
- 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] [source]#
- 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.
- 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 AcquisitionRule[source]#
Bases:
abc.ABC
,Generic
[ResultType
,SearchSpaceType
,trieste.models.interfaces.ProbabilisticModelType
]The central component of the acquisition API.
An
AcquisitionRule
can produce any value from the search space for this step, and the historic data and models. This value is typically a set of query points, either on its own as a TensorType (see e.g.EfficientGlobalOptimization
), or within some context (see e.g.BatchTrustRegion
). Indeed, to use anAcquisitionRule
in the mainBayesianOptimizer
Bayesian optimization loop, the rule must return either a TensorType or State-ful TensorType.Note that an
AcquisitionRule
might only support models with specific features (for example, if it uses an acquisition function that relies on those features). The type of models supported by a rule is indicated by the generic type variable class:ProbabilisticModelType.- abstract acquire(search_space: SearchSpaceType, models: collections.abc.Mapping[trieste.types.Tag, trieste.models.interfaces.ProbabilisticModelType], datasets: collections.abc.Mapping[trieste.types.Tag, trieste.data.Dataset] | None = None) ResultType [source]#
Return a value of type T_co. Typically this will be a set of query points, either on its own as a TensorType (see e.g.
EfficientGlobalOptimization
), or within some context (see e.g.BatchTrustRegion
). We assume that this requires at least models, but it may sometimes also need data.- Type hints:
The search space must be a
SearchSpace
. The exact type ofSearchSpace
depends on the specificAcquisitionRule
.
- Parameters:
search_space – The local acquisition search space for this step.
models – The model for each tag.
datasets – The known observer query points and observations for each tag (optional).
- Returns:
A value of type T_co.
- acquire_single(search_space: SearchSpaceType, model: trieste.models.interfaces.ProbabilisticModelType, dataset: trieste.data.Dataset | None = None) ResultType [source]#
A convenience wrapper for
acquire()
that uses only one model, dataset pair.- Parameters:
search_space – The global search space over which the optimization problem is defined.
model – The model to use.
dataset – The known observer query points and observations (optional).
- Returns:
A value of type T_co.
- filter_datasets(models: collections.abc.Mapping[trieste.types.Tag, trieste.models.interfaces.ProbabilisticModelType], datasets: collections.abc.Mapping[trieste.types.Tag, trieste.data.Dataset]) collections.abc.Mapping[trieste.types.Tag, trieste.data.Dataset] [source]#
Filter the post-acquisition datasets before they are used for model training. For example, this can be used to remove points from the post-acquisition datasets that are no longer in the search space. Some rules may also update their internal state.
- Parameters:
models – The model for each tag.
datasets – The updated datasets after previous acquisition step.
- Returns:
The filtered datasets.
- class AsynchronousGreedy(builder: trieste.acquisition.interface.GreedyAcquisitionFunctionBuilder[trieste.models.interfaces.ProbabilisticModelType] | trieste.acquisition.interface.SingleModelGreedyAcquisitionBuilder[trieste.models.interfaces.ProbabilisticModelType], optimizer: trieste.acquisition.optimizer.AcquisitionOptimizer[SearchSpaceType] | None = None, num_query_points: int = 1)[source]#
Bases:
AcquisitionRule
[trieste.types.State
[Optional
[AsynchronousRuleState
],trieste.types.TensorType
],SearchSpaceType
,trieste.models.interfaces.ProbabilisticModelType
]AsynchronousGreedy rule, as name suggests, is designed for asynchronous BO scenarios. To see what we understand by asynchronous BO, see documentation for
AsynchronousOptimization
.AsynchronousGreedy rule works with greedy batch acquisition functions and performs B steps of a greedy batch collection process, where B is the requested batch size.
- Parameters:
builder – Acquisition function builder. Only greedy batch approaches are supported, because they can be told what points are pending.
optimizer – The optimizer with which to optimize the acquisition function built by
builder
. This should maximize the acquisition function, and must be compatible with the global search space. Defaults toautomatic_optimizer_selector()
.num_query_points – The number of points to acquire.
- acquire(search_space: SearchSpaceType, models: collections.abc.Mapping[trieste.types.Tag, trieste.models.interfaces.ProbabilisticModelType], datasets: collections.abc.Mapping[trieste.types.Tag, trieste.data.Dataset] | None = None) trieste.types.State[AsynchronousRuleState | None, trieste.types.TensorType] [source]#
Constructs a function that, given
AsynchronousRuleState
, returns a new state object and points to evaluate. The state object contains currently known pending points, that is points that were requested for evaluation, but observation for which was not received yet. To keep them up to date, pending points are compared against the given dataset, and whatever points are in the dataset are deleted. Then the current batch is generated by calling the acquisition function, and all points in the batch are added to the known pending points.- Parameters:
search_space – The local acquisition search space for this step.
models – The model of the known data. Uses the single key OBJECTIVE.
datasets – The known observer query points and observations.
- Returns:
A function that constructs the next acquisition state and the recommended query points from the previous acquisition state.
- class AsynchronousOptimization(builder: None = None, optimizer: trieste.acquisition.optimizer.AcquisitionOptimizer[SearchSpaceType] | None = None, num_query_points: int = 1)[source]#
- class AsynchronousOptimization(builder: trieste.acquisition.interface.AcquisitionFunctionBuilder[trieste.models.interfaces.ProbabilisticModelType] | trieste.acquisition.interface.SingleModelAcquisitionBuilder[trieste.models.interfaces.ProbabilisticModelType], optimizer: trieste.acquisition.optimizer.AcquisitionOptimizer[SearchSpaceType] | None = None, num_query_points: int = 1)
Bases:
AcquisitionRule
[trieste.types.State
[Optional
[AsynchronousRuleState
],trieste.types.TensorType
],SearchSpaceType
,trieste.models.interfaces.ProbabilisticModelType
]AsynchronousOptimization rule is designed for asynchronous BO scenarios. By asynchronous BO we understand a use case when multiple objective function can be launched in parallel and are expected to arrive at different times. Instead of waiting for the rest of observations to return, we want to immediately use acquisition function to launch a new observation and avoid wasting computational resources. See [ARC+19] or [KKSP18] for more details.
To make the best decision about next point to observe, acquisition function needs to be aware of currently running observations. We call such points “pending”, and consider them a part of acquisition state. We use
AsynchronousRuleState
to store these points.AsynchronousOptimization works with non-greedy batch acquisition functions. For example, it would work with
BatchMonteCarloExpectedImprovement
, but cannot be used withExpectedImprovement
. If there are P pending points and the batch of size B is requested, the acquisition function is used with batch size P+B. During optimization first P points are fixed to pending, and thus we optimize and return the last B points only.- Parameters:
builder – Batch acquisition function builder. Defaults to
BatchMonteCarloExpectedImprovement
with 10 000 samples.optimizer – The optimizer with which to optimize the acquisition function built by
builder
. This should maximize the acquisition function, and must be compatible with the global search space. Defaults toautomatic_optimizer_selector()
.num_query_points – The number of points to acquire.
- acquire(search_space: SearchSpaceType, models: collections.abc.Mapping[trieste.types.Tag, trieste.models.interfaces.ProbabilisticModelType], datasets: collections.abc.Mapping[trieste.types.Tag, trieste.data.Dataset] | None = None) trieste.types.State[AsynchronousRuleState | None, trieste.types.TensorType] [source]#
Constructs a function that, given
AsynchronousRuleState
, returns a new state object and points to evaluate. The state object contains currently known pending points, that is points that were requested for evaluation, but observation for which was not received yet. To keep them up to date, pending points are compared against the given dataset, and whatever points are in the dataset are deleted.Let’s suppose we have P pending points. To optimize the acquisition function we call it with batches of size P+1, where first P points are fixed to pending points. Optimization therefore happens over the last point only, which is returned.
- Parameters:
search_space – The local acquisition search space for this step.
models – The model of the known data. Uses the single key OBJECTIVE.
datasets – The known observer query points and observations.
- Returns:
A function that constructs the next acquisition state and the recommended query points from the previous acquisition state.
- class BatchHypervolumeSharpeRatioIndicator(num_query_points: int = 1, ga_population_size: int = 500, ga_n_generations: int = 200, filter_threshold: float = 0.1, noisy_observations: bool = True)[source]#
Bases:
AcquisitionRule
[trieste.types.TensorType
,trieste.space.SearchSpace
,trieste.models.ProbabilisticModel
]Implements the Batch Hypervolume Sharpe-ratio indicator acquisition rule, designed for large batches, introduced by Binois et al, 2021. See [BCO21] for details.
- Parameters:
num_query_points – The number of points in a batch. Defaults to 5.
ga_population_size – The population size used in the genetic algorithm that finds points on the Pareto front. Defaults to 500.
ga_n_generations – The number of genenrations to run in the genetic algorithm. Defaults to 200.
filter_threshold – The probability of improvement below which to exlude points from the Sharpe ratio optimisation. Defaults to 0.1.
noisy_observations – Whether the observations have noise. Defaults to True.
- _find_non_dominated_points(model: trieste.models.ProbabilisticModel, search_space: SearchSpaceType) tuple[trieste.types.TensorType, trieste.types.TensorType] [source]#
Uses NSGA-II to find high-quality non-dominated points
- acquire(search_space: trieste.space.SearchSpace, models: collections.abc.Mapping[trieste.types.Tag, trieste.models.ProbabilisticModel], datasets: collections.abc.Mapping[trieste.types.Tag, trieste.data.Dataset] | None = None) trieste.types.TensorType [source]#
Acquire a batch of points to observe based on the batch hypervolume Sharpe ratio indicator method. This method uses NSGA-II to create a Pareto set of the mean and standard deviation of the posterior of the probabilistic model, and then selects points to observe based on maximising the Sharpe ratio.
- Parameters:
search_space – The local acquisition search space for this step.
models – The model for each tag.
datasets – The known observer query points and observations.
- Returns:
The batch of points to query.
- class BatchTrustRegionBox(init_subspaces: None | UpdatableTrustRegionType | Sequence[UpdatableTrustRegionType] = None, rule: AcquisitionRule[trieste.types.TensorType, trieste.space.SearchSpace, trieste.models.interfaces.ProbabilisticModelType] | None = None)[source]#
Bases:
BatchTrustRegion
[trieste.models.interfaces.ProbabilisticModelType
,UpdatableTrustRegionBox
]Implements the
BatchTrustRegion
trust region acquisition rule for box regions. This is intended to be used for single-objective optimization with batching.- Parameters:
init_subspaces – The initial search spaces for each trust region. If None, default subspaces of type
UpdatableTrustRegionType
will be created, with length equal to the number of query points in the base rule.rule –
The acquisition rule that defines how to search for a new query point in each subspace.
If None, defaults to
DiscreteThompsonSampling
with a batch size of 1 for TURBOBox subspaces, andEfficientGlobalOptimization
otherwise.
- acquire(search_space: trieste.space.SearchSpace, models: collections.abc.Mapping[trieste.types.Tag, trieste.models.interfaces.ProbabilisticModelType], datasets: collections.abc.Mapping[trieste.types.Tag, trieste.data.Dataset] | None = None) trieste.types.State[BatchTrustRegion | None, trieste.types.TensorType] [source]#
Use the
rule
specified at__init__()
to find new query points. Return a function that constructs these points given a previous trust region state.If state is None, initialize the subspaces by picking new locations. Otherwise, update the existing subspaces.
Re-initialize the subspaces if necessary, potentially looking at the entire group.
- Parameters:
search_space – The acquisition search space for this step.
models – The model for each tag.
datasets – The known observer query points and observations for each tag.
- Returns:
A function that constructs the next acquisition state and the recommended query points from the previous acquisition state.
- get_initialize_subspaces_mask(subspaces: Sequence[UpdatableTrustRegionBox], models: collections.abc.Mapping[trieste.types.Tag, trieste.models.interfaces.ProbabilisticModelType], datasets: collections.abc.Mapping[trieste.types.Tag, trieste.data.Dataset] | None = None) trieste.types.TensorType [source]#
Return a boolean mask for subspaces that should be initialized. This method is called during the acquisition step to determine which subspaces should be initialized and which should be updated. The subspaces corresponding to True values in the mask will be re-initialized.
- Parameters:
subspaces – The sequence of subspaces.
models – The model for each tag.
datasets – The dataset for each tag.
- Returns:
A boolean mask of length V, where V is the number of subspaces.
- class DiscreteThompsonSampling(num_search_space_samples: int, num_query_points: int, thompson_sampler: None = None, select_output: Callable[[trieste.types.TensorType], trieste.types.TensorType] = select_nth_output)[source]#
- class DiscreteThompsonSampling(num_search_space_samples: int, num_query_points: int, thompson_sampler: trieste.acquisition.sampler.ThompsonSampler[trieste.models.interfaces.ProbabilisticModelType] | None = None, select_output: Callable[[trieste.types.TensorType], trieste.types.TensorType] = select_nth_output)
Bases:
AcquisitionRule
[trieste.types.TensorType
,trieste.space.SearchSpace
,trieste.models.interfaces.ProbabilisticModelType
]Implements Thompson sampling for choosing optimal points.
This rule returns the minimizers of functions sampled from our model and evaluated across a discretization of the search space (containing N candidate points).
The model is sampled either exactly (with an \(O(N^3)\) complexity), or sampled approximately through a random Fourier M feature decompisition (with an \(O(\min(n^3,M^3))\) complexity for a model trained on n points). The number M of Fourier features is specified when building the model.
- Parameters:
num_search_space_samples – The number of points at which to sample the posterior.
num_query_points – The number of points to acquire.
thompson_sampler – Sampler to sample maximisers from the underlying model.
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.
- acquire(search_space: trieste.space.SearchSpace, models: collections.abc.Mapping[trieste.types.Tag, trieste.models.interfaces.ProbabilisticModelType], datasets: collections.abc.Mapping[trieste.types.Tag, trieste.data.Dataset] | None = None) trieste.types.TensorType [source]#
Sample num_search_space_samples (see
__init__()
) points from thesearch_space
. Of those points, return the num_query_points points at which random samples yield the minima of the model posterior.- Parameters:
search_space – The local acquisition search space for this step.
models – The model of the known data. Uses the single key OBJECTIVE.
datasets – The known observer query points and observations.
- Returns:
The
num_query_points
points to query.- Raises:
ValueError – If
models
do not contain the key OBJECTIVE, or it contains any other key.
- class EfficientGlobalOptimization(builder: None = None, optimizer: trieste.acquisition.optimizer.AcquisitionOptimizer[SearchSpaceType] | None = None, num_query_points: int = 1, initial_acquisition_function: trieste.acquisition.interface.AcquisitionFunction | None = None)[source]#
- class EfficientGlobalOptimization(builder: trieste.acquisition.interface.AcquisitionFunctionBuilder[trieste.models.interfaces.ProbabilisticModelType] | trieste.acquisition.interface.GreedyAcquisitionFunctionBuilder[trieste.models.interfaces.ProbabilisticModelType] | trieste.acquisition.interface.SingleModelAcquisitionBuilder[trieste.models.interfaces.ProbabilisticModelType] | trieste.acquisition.interface.SingleModelGreedyAcquisitionBuilder[trieste.models.interfaces.ProbabilisticModelType], optimizer: trieste.acquisition.optimizer.AcquisitionOptimizer[SearchSpaceType] | None = None, num_query_points: int = 1, initial_acquisition_function: trieste.acquisition.interface.AcquisitionFunction | None = None)
Bases:
AcquisitionRule
[trieste.types.TensorType
,SearchSpaceType
,trieste.models.interfaces.ProbabilisticModelType
]Implements the Efficient Global Optimization, or EGO, algorithm.
- Parameters:
builder – The acquisition function builder to use. Defaults to
ExpectedImprovement
.optimizer – The optimizer with which to optimize the acquisition function built by
builder
. This should maximize the acquisition function, and must be compatible with the global search space. Defaults toautomatic_optimizer_selector()
.num_query_points – The number of points to acquire.
initial_acquisition_function – The initial acquisition function to use. Defaults to using the builder to construct one, but passing in a previously constructed function can occasionally be useful (e.g. to preserve random seeds).
- property acquisition_function: trieste.acquisition.interface.AcquisitionFunction | None#
The current acquisition function, updated last time
acquire()
was called.
- acquire(search_space: SearchSpaceType, models: collections.abc.Mapping[trieste.types.Tag, trieste.models.interfaces.ProbabilisticModelType], datasets: collections.abc.Mapping[trieste.types.Tag, trieste.data.Dataset] | None = None) trieste.types.TensorType [source]#
Return the query point(s) that optimizes the acquisition function produced by
builder
(see__init__()
).- Parameters:
search_space – The local acquisition search space for this step.
models – The model for each tag.
datasets – The known observer query points and observations. Whether this is required depends on the acquisition function used.
- Returns:
The single (or batch of) points to query.
- class RandomSampling(num_query_points: int = 1)[source]#
Bases:
AcquisitionRule
[trieste.types.TensorType
,trieste.space.SearchSpace
,trieste.models.ProbabilisticModel
]This class performs random search for choosing optimal points. It uses
sample
method fromSearchSpace
to take random samples from the search space that are used as optimal points. Hence, it does not use any acquisition function. This acquisition rule can be useful as a baseline for other acquisition functions of interest.- Parameters:
num_query_points – The number of points to acquire. By default set to 1 point.
- Raises:
ValueError – If
num_query_points
is less or equal to 0.
- acquire(search_space: trieste.space.SearchSpace, models: collections.abc.Mapping[trieste.types.Tag, trieste.models.ProbabilisticModel], datasets: collections.abc.Mapping[trieste.types.Tag, trieste.data.Dataset] | None = None) trieste.types.TensorType [source]#
Sample
num_query_points
(see__init__()
) points from thesearch_space
.- Parameters:
search_space – The acquisition search space.
models – Unused.
datasets – Unused.
- Returns:
The
num_query_points
points to query.
- class SingleObjectiveTrustRegionBox(global_search_space: trieste.space.SearchSpace, beta: float = 0.7, kappa: float = 0.0001, min_eps: float = 0.01, region_index: int | None = None)[source]#
Bases:
UpdatableTrustRegionBox
An updatable box search space for use with trust region acquisition rules.
Calculates the bounds of the box from the location/centre and global bounds.
- Parameters:
global_search_space – The global search space this search space lives in.
beta – The inverse of the trust region contraction factor.
kappa – Scales the threshold for the minimal improvement required for a step to be considered a success.
min_eps – The minimal size of the search space. If the size of the search space is smaller than this, the search space is reinitialized.
region_index – The index of the region in a multi-region search space. This is used to identify the local models and datasets to use for acquisition. If None, the global models and datasets are used.
- initialize(models: collections.abc.Mapping[trieste.types.Tag, trieste.models.interfaces.ProbabilisticModelType] | None = None, datasets: collections.abc.Mapping[trieste.types.Tag, trieste.data.Dataset] | None = None) None [source]#
Initialize the box by sampling a location from the global search space and setting the bounds.
- update(models: collections.abc.Mapping[trieste.types.Tag, trieste.models.interfaces.ProbabilisticModelType] | None = None, datasets: collections.abc.Mapping[trieste.types.Tag, trieste.data.Dataset] | None = None) None [source]#
Update this box, including centre/location, using the given dataset. If the size of the box is less than the minimum size, re-initialize the box.
If the new optimum improves over the previous optimum by some threshold (that scales linearly with
kappa
), the previous acquisition is considered successful.If the previous acquisition was successful, the size is increased by a factor
1 / beta
. Conversely, if it was unsuccessful, the size is reduced by the factorbeta
.
- get_dataset_min(datasets: collections.abc.Mapping[trieste.types.Tag, trieste.data.Dataset] | None) Tuple[trieste.types.TensorType, trieste.types.TensorType] [source]#
Calculate the minimum of the box using the given dataset.
- class TREGOBox(global_search_space: trieste.space.SearchSpace, beta: float = 0.7, kappa: float = 0.0001, min_eps: float = 0.01, region_index: int | None = None)[source]#
Bases:
SingleObjectiveTrustRegionBox
A box trust region algorithm that alternates between regular EGO steps and local steps within a trust region. See [DPRP22] for details.
At construction, starts in global mode using
global_search_space
as the search space for the first step. Subsequent re-initializations use the trust region as the search space for the next step.If the previous acquisition was successful,
global_search_space
is used as the new search space. If the previous step was unsuccessful, the search space is changed to the trust region if it was global, and vice versa.If the previous acquisition was over the trust region, the size of the trust region is modified.
Note: The acquisition search space will never extend beyond the boundary of the
global_search_space
. For a local search, the actual search space will be the intersection of the trust region andglobal_search_space
.Calculates the bounds of the box from the location/centre and global bounds.
- Parameters:
global_search_space – The global search space this search space lives in.
beta – The inverse of the trust region contraction factor.
kappa – Scales the threshold for the minimal improvement required for a step to be considered a success.
min_eps – The minimal size of the search space. If the size of the search space is smaller than this, the search space is reinitialized.
region_index – The index of the region in a multi-region search space. This is used to identify the local models and datasets to use for acquisition. If None, the global models and datasets are used.
- property eps: trieste.types.TensorType#
The size of the search space.
- initialize(models: collections.abc.Mapping[trieste.types.Tag, trieste.models.interfaces.ProbabilisticModelType] | None = None, datasets: collections.abc.Mapping[trieste.types.Tag, trieste.data.Dataset] | None = None) None [source]#
Initialize the box by sampling a location from the global search space and setting the bounds.
- get_datasets_filter_mask(datasets: collections.abc.Mapping[trieste.types.Tag, trieste.data.Dataset] | None) collections.abc.Mapping[trieste.types.Tag, tensorflow.Tensor] | None [source]#
Return a boolean mask that can be used to filter out points from the datasets that belong to this region.
- Parameters:
datasets – The dataset for each tag.
- Returns:
A mapping for each tag belonging to this region, to a boolean mask that can be used to filter out points from the datasets. A value of True indicates that the corresponding point should be kept.
- get_dataset_min(datasets: collections.abc.Mapping[trieste.types.Tag, trieste.data.Dataset] | None) Tuple[trieste.types.TensorType, trieste.types.TensorType] [source]#
Calculate the minimum of the box using the given dataset.
- class TURBOBox(global_search_space: trieste.space.SearchSpace, L_min: float | None = None, L_init: float | None = None, L_max: float | None = None, success_tolerance: int = 3, failure_tolerance: int | None = None, region_index: int | None = None)[source]#
Bases:
UpdatableTrustRegionBox
Implements the TURBO algorithm as detailed in [EPG+19].
Note that the optional parameters are set by a heuristic if not given by the user.
- Parameters:
global_search_space – The global search space.
L_min – Minimum allowed length of the trust region.
L_init – Initial length of the trust region.
L_max – Maximum allowed length of the trust region.
success_tolerance – Number of consecutive successes before changing region size.
tolerance (failure) – Number of consecutive failures before changing region size.
region_index – The index of the region in a multi-region search space. This is used to identify the local models and datasets to use for acquisition. If None, the global models and datasets are used.
- initialize(models: collections.abc.Mapping[trieste.types.Tag, trieste.models.interfaces.ProbabilisticModelType] | None = None, datasets: collections.abc.Mapping[trieste.types.Tag, trieste.data.Dataset] | None = None) None [source]#
Initialize the search space using the given models and datasets.
- Parameters:
models – The model for each tag.
datasets – The dataset for each tag.
- update(models: collections.abc.Mapping[trieste.types.Tag, trieste.models.interfaces.ProbabilisticModelType] | None = None, datasets: collections.abc.Mapping[trieste.types.Tag, trieste.data.Dataset] | None = None) None [source]#
Update the search space using the given models and datasets.
- Parameters:
models – The model for each tag.
datasets – The dataset for each tag.
- get_dataset_min(datasets: collections.abc.Mapping[trieste.types.Tag, trieste.data.Dataset] | None) Tuple[trieste.types.TensorType, trieste.types.TensorType] [source]#
Calculate the minimum of the box using the given dataset.
- class ExactThompsonSampler(sample_min_value: bool = False)[source]#
Bases:
ThompsonSampler
[trieste.models.ProbabilisticModel
]This sampler provides exact Thompson samples of the objective function’s minimiser \(x^*\) over a discrete set of input locations. Although exact Thompson sampling is costly (incuring with an \(O(N^3)\) complexity to sample over a set of N locations), this method can be used for any probabilistic model with a sampling method.
- Sample_min_value:
If True then sample from the minimum value of the function, else sample the function’s minimiser.
- sample(model: trieste.models.ProbabilisticModel, sample_size: int, at: trieste.types.TensorType, select_output: Callable[[trieste.types.TensorType], trieste.types.TensorType] = select_nth_output) trieste.types.TensorType [source]#
Return exact samples from either the objective function’s minimiser or its minimal value over the candidate set at. Note that minimiser ties aren’t broken randomly.
- 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 [source]#
Return approximate samples from of the objective function’s minimum value.
- Parameters:
model – The model to sample from.
sample_size – The desired number of samples.
at – Points at where to fit the Gumbel distribution, with shape [N, D], for points of dimension D. We recommend scaling N with search space dimension.
select_output – A method that returns the desired output from the model sampler, with shape [S, N] where S is the number of samples and N is the number of locations. Currently unused.
- Returns:
The samples, of shape [S, 1], where S is the sample_size.
- Raises:
ValueError – If
at
has an invalid shape or 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 [source]#
- Parameters:
model – The model to sample from.
sample_size – The desired number of samples.
at – Input points that define the sampler.
select_output – A method that returns the desired output from the model sampler, with shape [S, N] where S is the number of samples and N is the number of locations. Defaults to the :func:~`trieste.acquisition.utils.select_nth_output` function with output dimension 0.
- Returns:
Samples.
- class ThompsonSamplerFromTrajectory(sample_min_value: bool = False)[source]#
Bases:
ThompsonSampler
[trieste.models.interfaces.HasTrajectorySampler
]This sampler provides approximate Thompson samples of the objective function’s minimiser \(x^*\) by minimizing approximate trajectories sampled from the underlying probabilistic model. This sampling method can be used for any probabilistic model with a
trajectory_sampler()
method.- Sample_min_value:
If True then sample from the minimum value of the function, else sample the function’s minimiser.
- sample(model: trieste.models.ProbabilisticModel, sample_size: int, at: trieste.types.TensorType, select_output: Callable[[trieste.types.TensorType], trieste.types.TensorType] = select_nth_output) trieste.types.TensorType [source]#
Return approximate samples from either the objective function’s minimser or its minimal value over the candidate set at. Note that minimiser ties aren’t broken randomly.
- 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.