trieste.ask_tell_optimization#
This module contains the Ask/Tell API for users of Trieste who would like to perform Bayesian Optimization with external control of the optimization loop.
Module Contents#
- class AskTellOptimizerState[source]#
Bases:
Generic[StateType,ProbabilisticModelType]Internal state for an Ask/Tell optimizer. This can be obtained using the optimizer’s to_state method, and can be used to initialise a new instance of the optimizer.
- record: trieste.bayesian_optimizer.Record[StateType, ProbabilisticModelType][source]#
A record of the current state of the optimization.
- class AskTellOptimizerABC(search_space: SearchSpaceType, datasets: Mapping[trieste.types.Tag, trieste.data.Dataset], models: Mapping[trieste.types.Tag, ProbabilisticModelType], *, fit_model: bool = True, track_data: bool = True, local_data_ixs: Sequence[trieste.types.TensorType] | None = None, local_data_len: int | None = None)[source]#
- class AskTellOptimizerABC(search_space: SearchSpaceType, datasets: Mapping[trieste.types.Tag, trieste.data.Dataset], models: Mapping[trieste.types.Tag, ProbabilisticModelType], acquisition_rule: trieste.acquisition.rule.AcquisitionRule[trieste.types.TensorType, SearchSpaceType, ProbabilisticModelType], *, fit_model: bool = True, track_data: bool = True, local_data_ixs: Sequence[trieste.types.TensorType] | None = None, local_data_len: int | None = None)
- class AskTellOptimizerABC(search_space: SearchSpaceType, datasets: Mapping[trieste.types.Tag, trieste.data.Dataset], models: Mapping[trieste.types.Tag, ProbabilisticModelType], acquisition_rule: trieste.acquisition.rule.AcquisitionRule[trieste.types.State[StateType | None, trieste.types.TensorType], SearchSpaceType, ProbabilisticModelType], acquisition_state: StateType | None, *, fit_model: bool = True, track_data: bool = True, local_data_ixs: Sequence[trieste.types.TensorType] | None = None, local_data_len: int | None = None)
- class AskTellOptimizerABC(search_space: SearchSpaceType, datasets: trieste.data.Dataset, models: ProbabilisticModelType, *, fit_model: bool = True, track_data: bool = True, local_data_ixs: Sequence[trieste.types.TensorType] | None = None, local_data_len: int | None = None)
- class AskTellOptimizerABC(search_space: SearchSpaceType, datasets: trieste.data.Dataset, models: ProbabilisticModelType, acquisition_rule: trieste.acquisition.rule.AcquisitionRule[trieste.types.TensorType, SearchSpaceType, ProbabilisticModelType], *, fit_model: bool = True, track_data: bool = True, local_data_ixs: Sequence[trieste.types.TensorType] | None = None, local_data_len: int | None = None)
- class AskTellOptimizerABC(search_space: SearchSpaceType, datasets: trieste.data.Dataset, models: ProbabilisticModelType, acquisition_rule: trieste.acquisition.rule.AcquisitionRule[trieste.types.State[StateType | None, trieste.types.TensorType], SearchSpaceType, ProbabilisticModelType], acquisition_state: StateType | None = None, *, fit_model: bool = True, track_data: bool = True, local_data_ixs: Sequence[trieste.types.TensorType] | None = None, local_data_len: int | None = None)
Bases:
abc.ABC,Generic[SearchSpaceType,ProbabilisticModelType]This class provides Ask/Tell optimization interface. It is designed for those use cases when control of the optimization loop by Trieste is impossible or not desirable. For the default use case with model training, refer to
AskTellOptimizer. For more details about the Bayesian Optimization routine, refer toBayesianOptimizer.- Parameters:
search_space – The space over which to search for the next query point.
datasets – Already observed input-output pairs for each tag.
models – The model to use for each
Datasetindatasets.acquisition_rule – The acquisition rule, which defines how to search for a new point on each optimization step. Defaults to
EfficientGlobalOptimizationwith default arguments. Note that if the default is used, this implies the tags must be OBJECTIVE and the search space can be anySearchSpace.acquisition_state – The optional acquisition state for stateful acquisitions.
fit_model – If True (default), models passed in will be optimized on the given data. If False, the models are assumed to be optimized already.
track_data – If True (default), the optimizer will track the changing datasets via a local copy. If False, it will infer new datasets from updates to the global datasets (optionally using local_data_ixs and indices passed in to tell).
local_data_ixs – Indices to the local data in the initial datasets. If unspecified, assumes that the initial datasets are global.
local_data_len – Optional length of the data when the passed in local_data_ixs were measured. If the data has increased since then, the indices are extended.
- Raises:
ValueError – If any of the following are true: - the keys in
datasetsandmodelsdo not match -datasetsormodelsare empty - default acquisition is used but incompatible with other inputs
- abstract update_model(model: ProbabilisticModelType, dataset: trieste.data.Dataset) None[source]#
Update the model on the specified dataset, for example by training. Called during the Tell stage and optionally at initial fitting.
- property datasets: Mapping[trieste.types.Tag, trieste.data.Dataset][source]#
The current datasets.
- property dataset: trieste.data.Dataset[source]#
The current dataset when there is just one dataset.
- property local_data_ixs: Sequence[trieste.types.TensorType] | None[source]#
Indices to the local data. Only stored for LocalDatasetsAcquisitionRule rules when track_data is False.
- property local_data_len: int | None[source]#
Data length. Only stored for LocalDatasetsAcquisitionRule rules when track_data is False.
- property model: trieste.models.ProbabilisticModel[source]#
The current model when there is just one model.
- classmethod dataset_len(datasets: Mapping[trieste.types.Tag, trieste.data.Dataset]) int[source]#
Helper method for inferring the global dataset size.
- classmethod from_record(record: trieste.bayesian_optimizer.Record[StateType, ProbabilisticModelType] | trieste.bayesian_optimizer.FrozenRecord[StateType, ProbabilisticModelType], search_space: SearchSpaceType, acquisition_rule: trieste.acquisition.rule.AcquisitionRule[trieste.types.TensorType | trieste.types.State[StateType | None, trieste.types.TensorType], SearchSpaceType, ProbabilisticModelType] | None = None, track_data: bool = True, local_data_ixs: Sequence[trieste.types.TensorType] | None = None, local_data_len: int | None = None) AskTellOptimizerType[source]#
Creates new
AskTellOptimizerinstance from provided optimization state. Model training isn’t triggered upon creation of the instance.- Parameters:
record – Optimization state record.
search_space – The space over which to search for the next query point.
acquisition_rule – The acquisition rule, which defines how to search for a new point on each optimization step. Defaults to
EfficientGlobalOptimizationwith default arguments.track_data – Whether the optimizer tracks the changing datasets via a local copy.
local_data_ixs – Indices to local data for local rules with track_data False.
local_data_len – Original data length for local rules with track_data False.
- Returns:
New instance of
AskTellOptimizer.
- to_record(copy: bool = True) trieste.bayesian_optimizer.Record[StateType, ProbabilisticModelType][source]#
Collects the current state of the optimization, which includes datasets, models and acquisition state (if applicable).
- Parameters:
copy – Whether to return a copy of the current state or the original. Copying is not supported for all model types. However, continuing the optimization will modify the original state.
- Returns:
An optimization state record.
- to_result(copy: bool = True) trieste.bayesian_optimizer.OptimizationResult[StateType, ProbabilisticModelType][source]#
Converts current state of the optimization into a
OptimizationResultobject.- Parameters:
copy – Whether to return a copy of the current state or the original. Copying is not supported for all model types. However, continuing the optimization will modify the original state.
- Returns:
A
OptimizationResultobject.
- classmethod from_state(state: AskTellOptimizerState[StateType, ProbabilisticModelType], search_space: SearchSpaceType, acquisition_rule: trieste.acquisition.rule.AcquisitionRule[trieste.types.TensorType | trieste.types.State[StateType | None, trieste.types.TensorType], SearchSpaceType, ProbabilisticModelType] | None = None, track_data: bool = True) AskTellOptimizerType[source]#
Creates new
AskTellOptimizerinstance from provided AskTellOptimizer state. Model training isn’t triggered upon creation of the instance.- Parameters:
state – AskTellOptimizer state.
search_space – The space over which to search for the next query point.
acquisition_rule – The acquisition rule, which defines how to search for a new point on each optimization step. Defaults to
EfficientGlobalOptimizationwith default arguments.track_data – Whether the optimizer tracks the changing datasets via a local copy.
- Returns:
New instance of
AskTellOptimizer.
- to_state(copy: bool = False) AskTellOptimizerState[StateType, ProbabilisticModelType][source]#
Returns the AskTellOptimizer state, comprising the current optimization state alongside any internal AskTellOptimizer state.
- Parameters:
copy – Whether to return a copy of the current state or the original. Copying is not supported for all model types. However, continuing the optimization will modify the original state.
- Returns:
An
AskTellOptimizerStateobject.
- ask() trieste.types.TensorType[source]#
Suggests a point (or points in batch mode) to observe by optimizing the acquisition function. If the acquisition is stateful, its state is saved.
- Returns:
A
TensorTypeinstance representing suggested point(s).
- tell(new_data: Mapping[trieste.types.Tag, trieste.data.Dataset] | trieste.data.Dataset, new_data_ixs: Sequence[trieste.types.TensorType] | None = None) None[source]#
Updates optimizer state with new data.
- Parameters:
new_data – New observed data. If track_data is False, this refers to all the data.
new_data_ixs – Indices to the new observed local data, if track_data is False. If unspecified, inferred from the change in dataset sizes.
- Raises:
ValueError – If keys in
new_datado not match those in already built dataset.
- TrainableProbabilisticModelType[source]#
Contravariant type variable bound to
TrainableProbabilisticModel.
- class AskTellOptimizer(search_space: SearchSpaceType, datasets: Mapping[trieste.types.Tag, trieste.data.Dataset], models: Mapping[trieste.types.Tag, ProbabilisticModelType], *, fit_model: bool = True, track_data: bool = True, local_data_ixs: Sequence[trieste.types.TensorType] | None = None, local_data_len: int | None = None)[source]#
- class AskTellOptimizer(search_space: SearchSpaceType, datasets: Mapping[trieste.types.Tag, trieste.data.Dataset], models: Mapping[trieste.types.Tag, ProbabilisticModelType], acquisition_rule: trieste.acquisition.rule.AcquisitionRule[trieste.types.TensorType, SearchSpaceType, ProbabilisticModelType], *, fit_model: bool = True, track_data: bool = True, local_data_ixs: Sequence[trieste.types.TensorType] | None = None, local_data_len: int | None = None)
- class AskTellOptimizer(search_space: SearchSpaceType, datasets: Mapping[trieste.types.Tag, trieste.data.Dataset], models: Mapping[trieste.types.Tag, ProbabilisticModelType], acquisition_rule: trieste.acquisition.rule.AcquisitionRule[trieste.types.State[StateType | None, trieste.types.TensorType], SearchSpaceType, ProbabilisticModelType], acquisition_state: StateType | None, *, fit_model: bool = True, track_data: bool = True, local_data_ixs: Sequence[trieste.types.TensorType] | None = None, local_data_len: int | None = None)
- class AskTellOptimizer(search_space: SearchSpaceType, datasets: trieste.data.Dataset, models: ProbabilisticModelType, *, fit_model: bool = True, track_data: bool = True, local_data_ixs: Sequence[trieste.types.TensorType] | None = None, local_data_len: int | None = None)
- class AskTellOptimizer(search_space: SearchSpaceType, datasets: trieste.data.Dataset, models: ProbabilisticModelType, acquisition_rule: trieste.acquisition.rule.AcquisitionRule[trieste.types.TensorType, SearchSpaceType, ProbabilisticModelType], *, fit_model: bool = True, track_data: bool = True, local_data_ixs: Sequence[trieste.types.TensorType] | None = None, local_data_len: int | None = None)
- class AskTellOptimizer(search_space: SearchSpaceType, datasets: trieste.data.Dataset, models: ProbabilisticModelType, acquisition_rule: trieste.acquisition.rule.AcquisitionRule[trieste.types.State[StateType | None, trieste.types.TensorType], SearchSpaceType, ProbabilisticModelType], acquisition_state: StateType | None = None, *, fit_model: bool = True, track_data: bool = True, local_data_ixs: Sequence[trieste.types.TensorType] | None = None, local_data_len: int | None = None)
Bases:
AskTellOptimizerABC[SearchSpaceType,TrainableProbabilisticModelType]This class provides Ask/Tell optimization interface with the default model training using the TrainableProbabilisticModel interface.
- Parameters:
search_space – The space over which to search for the next query point.
datasets – Already observed input-output pairs for each tag.
models – The model to use for each
Datasetindatasets.acquisition_rule – The acquisition rule, which defines how to search for a new point on each optimization step. Defaults to
EfficientGlobalOptimizationwith default arguments. Note that if the default is used, this implies the tags must be OBJECTIVE and the search space can be anySearchSpace.acquisition_state – The optional acquisition state for stateful acquisitions.
fit_model – If True (default), models passed in will be optimized on the given data. If False, the models are assumed to be optimized already.
track_data – If True (default), the optimizer will track the changing datasets via a local copy. If False, it will infer new datasets from updates to the global datasets (optionally using local_data_ixs and indices passed in to tell).
local_data_ixs – Indices to the local data in the initial datasets. If unspecified, assumes that the initial datasets are global.
local_data_len – Optional length of the data when the passed in local_data_ixs were measured. If the data has increased since then, the indices are extended.
- Raises:
ValueError – If any of the following are true: - the keys in
datasetsandmodelsdo not match -datasetsormodelsare empty - default acquisition is used but incompatible with other inputs
- update_model(model: TrainableProbabilisticModelType, dataset: trieste.data.Dataset) None[source]#
Update the model on the specified dataset, for example by training. Called during the Tell stage and optionally at initial fitting.
- class AskTellOptimizerNoTraining(search_space: SearchSpaceType, datasets: Mapping[trieste.types.Tag, trieste.data.Dataset], models: Mapping[trieste.types.Tag, ProbabilisticModelType], *, fit_model: bool = True, track_data: bool = True, local_data_ixs: Sequence[trieste.types.TensorType] | None = None, local_data_len: int | None = None)[source]#
- class AskTellOptimizerNoTraining(search_space: SearchSpaceType, datasets: Mapping[trieste.types.Tag, trieste.data.Dataset], models: Mapping[trieste.types.Tag, ProbabilisticModelType], acquisition_rule: trieste.acquisition.rule.AcquisitionRule[trieste.types.TensorType, SearchSpaceType, ProbabilisticModelType], *, fit_model: bool = True, track_data: bool = True, local_data_ixs: Sequence[trieste.types.TensorType] | None = None, local_data_len: int | None = None)
- class AskTellOptimizerNoTraining(search_space: SearchSpaceType, datasets: Mapping[trieste.types.Tag, trieste.data.Dataset], models: Mapping[trieste.types.Tag, ProbabilisticModelType], acquisition_rule: trieste.acquisition.rule.AcquisitionRule[trieste.types.State[StateType | None, trieste.types.TensorType], SearchSpaceType, ProbabilisticModelType], acquisition_state: StateType | None, *, fit_model: bool = True, track_data: bool = True, local_data_ixs: Sequence[trieste.types.TensorType] | None = None, local_data_len: int | None = None)
- class AskTellOptimizerNoTraining(search_space: SearchSpaceType, datasets: trieste.data.Dataset, models: ProbabilisticModelType, *, fit_model: bool = True, track_data: bool = True, local_data_ixs: Sequence[trieste.types.TensorType] | None = None, local_data_len: int | None = None)
- class AskTellOptimizerNoTraining(search_space: SearchSpaceType, datasets: trieste.data.Dataset, models: ProbabilisticModelType, acquisition_rule: trieste.acquisition.rule.AcquisitionRule[trieste.types.TensorType, SearchSpaceType, ProbabilisticModelType], *, fit_model: bool = True, track_data: bool = True, local_data_ixs: Sequence[trieste.types.TensorType] | None = None, local_data_len: int | None = None)
- class AskTellOptimizerNoTraining(search_space: SearchSpaceType, datasets: trieste.data.Dataset, models: ProbabilisticModelType, acquisition_rule: trieste.acquisition.rule.AcquisitionRule[trieste.types.State[StateType | None, trieste.types.TensorType], SearchSpaceType, ProbabilisticModelType], acquisition_state: StateType | None = None, *, fit_model: bool = True, track_data: bool = True, local_data_ixs: Sequence[trieste.types.TensorType] | None = None, local_data_len: int | None = None)
Bases:
AskTellOptimizerABC[SearchSpaceType,ProbabilisticModelType]This class provides Ask/Tell optimization interface with no model training performed during the Tell stage or at initialization.
- Parameters:
search_space – The space over which to search for the next query point.
datasets – Already observed input-output pairs for each tag.
models – The model to use for each
Datasetindatasets.acquisition_rule – The acquisition rule, which defines how to search for a new point on each optimization step. Defaults to
EfficientGlobalOptimizationwith default arguments. Note that if the default is used, this implies the tags must be OBJECTIVE and the search space can be anySearchSpace.acquisition_state – The optional acquisition state for stateful acquisitions.
fit_model – If True (default), models passed in will be optimized on the given data. If False, the models are assumed to be optimized already.
track_data – If True (default), the optimizer will track the changing datasets via a local copy. If False, it will infer new datasets from updates to the global datasets (optionally using local_data_ixs and indices passed in to tell).
local_data_ixs – Indices to the local data in the initial datasets. If unspecified, assumes that the initial datasets are global.
local_data_len – Optional length of the data when the passed in local_data_ixs were measured. If the data has increased since then, the indices are extended.
- Raises:
ValueError – If any of the following are true: - the keys in
datasetsandmodelsdo not match -datasetsormodelsare empty - default acquisition is used but incompatible with other inputs
- update_model(model: ProbabilisticModelType, dataset: trieste.data.Dataset) None[source]#
Update the model on the specified dataset, for example by training. Called during the Tell stage and optionally at initial fitting.