Algorithms module#
This module provides some implementations of algorithms that address a specific problem or challenge for easy, off-the-shelf use.
Optimisation#
References
For expected improvement with noisy observations see: - RB Gramacy, Surrogates: Gaussian Process Modeling, Design, and Optimization for the Applied Sciences, 1st ed. Boca Raton, FL: CRC press, 2020.
- nubo.algorithms.optimise.optimise(x_train: Tensor, y_train: Tensor, bounds: Tensor, batch_size: int | None = 1, acquisition: str | None = 'EI', beta: float | None = 4.0, constraints: dict | Tuple[dict] | None = [], discrete: dict | None = None, noisy: bool | None = False, x_pending: Tensor | None = None, mc_samples: int | None = 128, normalise_x: bool | None = False, standardise_y: bool | None = False, num_starts: int | None = 10, num_samples: int | None = 100) Tensor [source]#
Off-the-shelf optimisation step. Allows optimisation of expensive experiments and simulations with single-point and multi-point candidates, input constraints, continuous and discrete parameters, noisy observations, and pending training data points. You can select between expected improvement and upper confidence bound acquisition functions.
Uses analytical acquisition functions with the L-BFGS-B optimiser for single-point optimisation and Monte Carlo acquisition functions with the Adam optimiser for multi-point and asynchronous optimisation. Fixes base samples when input constraints are provided for the latter and optimises all constrained problems via the SLSQP optimiser.
For expected improvement with noisy observaions, the maximum of the Gaussian process posterior mean is taken as a plugin value.
- Parameters:
- x_train
torch.Tensor
(size n x d) Training inputs.
- y_train
torch.Tensor
(size n) Training outputs.
- bounds
torch.Tensor
(size 2 x d) Optimisation bounds of input space.
- batch_size: ``int``, optional
Number of new candidate points to return, default is 1.
- acquisition: ``str``, optional
Acquisition function to use. Must be “EI” or “UCB”, default is “EI”.
- beta: ``int``, optional
Trade-off parameter for UCB acquisition function, default is 4.0. No impact on when EI is specified.
- constraints
dict
orTuple
ofdict
, optional Optimisation constraints on inputs, default is no constraints.
- discrete
dict
, optional Possible values for all discrete inputs in the shape {dim1: [values1], dim2: [values2], etc.}, e.g. {0: [1., 2., 3.], 3: [-0.1, -0.2, 100.]}.
- noisy
bool
, optional Specifies if observations are noisy.
- x_pending
torch.Tensor
, optional (size n x d) Training inputs of currently pending points, default is no pending points.
- mc_samples
int
, optional Number of Monte Carlo samples to approximate the acquisition function, default is 128. Has no effect on analytical acquisition functions.
- normalise_x: bool, optional
Whether inputs should be normalised before optimisation, default is False.
- standardise_y: bool, optional
Whether outpus should be standardised before optimisation, default is False
- num_starts
int
, optional Number of start for multi-start optimisation, default is 10.
- num_samples
int
, optional Number of samples from which to draw the starts, default is 100.
- x_train
- Returns:
torch.Tensor
(size batch_size x d) New candidate inputs.
Environmental conditions#
References
M Diessner, KJ Wilson, and RD Whalley, “On the development of a practical Bayesian optimisation algorithm for expensive experiments and simulations with changing environmental conditions,” arXiv preprint arXiv:2402.03006, 2024.
- class nubo.algorithms.environmental_conditions.ENVBOPredictionModel(x_train: Tensor, y_train: Tensor, env_dims: int | List[int], bounds: Tensor, constraints: dict | Tuple[dict] | None = ())[source]#
Bases:
object
Prediction model for ENVBO algorithm.
Predicts optimal values for controllable parameters conditional on measurements of environmental variables. First, it uses a Gaussian process to model the relationship between all controllable and environmental inputs and the outputs. Second, it predicts optimal input values of the controllable parameters by holding environmental inputs fixed to the provided measurements and maximising the posterior mean of the Gaussian process model. Assumes a maximisation problem.
- Attributes:
- x_train
torch.Tensor
(size n x d) Training inputs.
- y_train
torch.Tensor
(size n) Training outputs.
- env_dims
List
ofint
List of indices of environmental variables.
- env_values
List
offloat
List of values of environmental variables.
- bounds
torch.Tensor
(size 2 x d) Optimisation bounds of input space.
- constraints
dict
orTuple
ofdict
, optional Optimisation constraints, default is no constraints.
- likelihood
gpytorch.likelihoods.Likelihood
Likelihood.
- model
gpytorch.models.GP
Gaussian Process model.
- x_train
- predict(env_values: float | List[float]) Tuple[Tensor, Tensor] [source]#
Predict values for controllable parameters conditional on measurements of environmental variables.
- Parameters:
- env_values
float
orList
offloat
List of values of environmental variables.
- env_values
- Returns:
- x_new
torch.Tensor
(size 1 x d) Minimiser inputs conditional on environmental values.
- pred_new
torch.Tensor
(size 1) Predicted minimiser output conditional on environmental values.
- x_new
- nubo.algorithms.environmental_conditions.envbo(x_train: Tensor, y_train: Tensor, env_dims: int | List[int], env_values: float | List[float], bounds: Tensor, constraints: dict | Tuple[dict] | None = (), normalise_x: bool | None = False, standardise_y: bool | None = False, num_starts: int | None = 10, num_samples: int | None = 100) Tensor [source]#
ENVBO is a Bayesian optimisation algorithm for problems with uncontrollable variables that are given externally by environmental conditions. This function represents a single optimisation step that needs to be wrapped in a loop where new measurements of the environmental variables are provided at each iteration. Assumes a maximisation problem.
- Parameters:
- x_train
torch.Tensor
(size n x d) Training inputs.
- y_train
torch.Tensor
(size n) Training outputs.
- env_dims
int
orList
ofint
List of indices of environmental variables.
- env_values
float
orList
offloat
List of values of environmental variables.
- bounds
torch.Tensor
(size 2 x d) Optimisation bounds of input space.
- constraints
dict
orTuple
ofdict
, optional Optimisation constraints on inputs, default is no constraints.
- normalise_x: bool, optional
Whether inputs should be normalised before optimisation, default is False.
- standardise_y: bool, optional
Whether outpus should be standardised before optimisation, default is False
- num_starts
int
, optional Number of start for multi-start optimisation, default is 10.
- num_samples
int
, optional Number of samples from which to draw the starts, default is 100.
- x_train
- Returns:
torch.Tensor
(size 1 x d) New candidate inputs.