QoILookAhead

class axtreme.acquisition.qoi_look_ahead.QoILookAhead(model: SingleTaskGP, qoi_estimator: QoIEstimator, sampler: PosteriorSampler | None = None)

Bases: AcquisitionFunction

QoILookAhead is a generic acquisition function that estimates the usefulness of a design point.

It estimates the usefulness of a design point by:

  • Creating a new model(s) (e.g the looking ahead) by including the design point in the training data.

    Note

    The new model condition on the design point, it does not update hyperparameters.

  • Calculate the QoI with the new model, and find the variance of this distribution.

The design point that results in the lowest variance QoI is considered the most desireable.

Note on Optimisation:

Optimising the AcquisitionFunction is an important part of the DoE process. The stochasticity and smoothness of the acquisition function determine what optimisers can be used. This acquisition function has the following properties with the default setup:

Smoothness:

QoILookAhead is smooth (twice differentiable) if:

  • The model used for instantiation produces smooth outputs.

  • A sampler produces smooth y values.

  • The method used to produce y_var estimates is smooth.

  • The QoIEstimator is smooth with respect to the model (e.g small changes in the model produce smooth change in the QoIEstimator result.)

The default optimiser assume the QoI may not be smooth, and uses a gradient free optimiser. If your QoI is smooth these setting should be overridden.

Stochasticity:

QoILookAhead is deterministic if all the above components are deterministic. With default settings it is deterministic.

__init__(model: SingleTaskGP, qoi_estimator: QoIEstimator, sampler: PosteriorSampler | None = None) None

QoILookAhead acquisition function.

Parameters:
  • model

    A fitted model. Only SingleTaskGP models are currently supported.

    • General GpytorchModel may eventually be supported.

  • qoi_estimator – A callable conforming to QoIEstimator protocol.

  • sampler

    A sampler that is used to sample fantasy observations for each candidate point. If None, a MeanSampler is used. This then uses the mean of the posterior as the fantasy observation.

    Note

    Sampler choice can effect the stochasticty and smoothness of the acquisition function. See class docs for details.

Methods

__init__(model, qoi_estimator[, sampler])

QoILookAhead acquisition function.

add_module(name, module)

Add a child module to the current module.

apply(fn)

Apply fn recursively to every submodule (as returned by .children()) as well as self.

bfloat16()

Casts all floating point parameters and buffers to bfloat16 datatype.

buffers([recurse])

Return an iterator over module buffers.

children()

Return an iterator over immediate children modules.

compile(*args, **kwargs)

Compile this Module's forward using torch.compile().

cpu()

Move all model parameters and buffers to the CPU.

cuda([device])

Move all model parameters and buffers to the GPU.

double()

Casts all floating point parameters and buffers to double datatype.

eval()

Set the module in evaluation mode.

extra_repr()

Set the extra representation of the module.

float()

Casts all floating point parameters and buffers to float datatype.

forward(X)

Forward method for the QoI acquisition function.

get_buffer(target)

Return the buffer given by target if it exists, otherwise throw an error.

get_extra_state()

Return any extra state to include in the module's state_dict.

get_parameter(target)

Return the parameter given by target if it exists, otherwise throw an error.

get_submodule(target)

Return the submodule given by target if it exists, otherwise throw an error.

half()

Casts all floating point parameters and buffers to half datatype.

ipu([device])

Move all model parameters and buffers to the IPU.

load_state_dict(state_dict[, strict, assign])

Copy parameters and buffers from state_dict into this module and its descendants.

lookahead(x_point, y_point, yvar_point)

Performs a single lookahead calculation.

modules()

Return an iterator over all modules in the network.

named_buffers([prefix, recurse, ...])

Return an iterator over module buffers, yielding both the name of the buffer as well as the buffer itself.

named_children()

Return an iterator over immediate children modules, yielding both the name of the module as well as the module itself.

named_modules([memo, prefix, remove_duplicate])

Return an iterator over all modules in the network, yielding both the name of the module as well as the module itself.

named_parameters([prefix, recurse, ...])

Return an iterator over module parameters, yielding both the name of the parameter as well as the parameter itself.

parameters([recurse])

Return an iterator over module parameters.

register_backward_hook(hook)

Register a backward hook on the module.

register_buffer(name, tensor[, persistent])

Add a buffer to the module.

register_forward_hook(hook, *[, prepend, ...])

Register a forward hook on the module.

register_forward_pre_hook(hook, *[, ...])

Register a forward pre-hook on the module.

register_full_backward_hook(hook[, prepend])

Register a backward hook on the module.

register_full_backward_pre_hook(hook[, prepend])

Register a backward pre-hook on the module.

register_load_state_dict_post_hook(hook)

Register a post hook to be run after module's load_state_dict is called.

register_module(name, module)

Alias for add_module().

register_parameter(name, param)

Add a parameter to the module.

register_state_dict_pre_hook(hook)

Register a pre-hook for the state_dict() method.

requires_grad_([requires_grad])

Change if autograd should record operations on parameters in this module.

set_X_pending([X_pending])

Informs the acquisition function about pending design points.

set_extra_state(state)

Set extra state contained in the loaded state_dict.

share_memory()

See torch.Tensor.share_memory_().

state_dict(*args[, destination, prefix, ...])

Return a dictionary containing references to the whole state of the module.

to(*args, **kwargs)

Move and/or cast the parameters and buffers.

to_empty(*, device[, recurse])

Move the parameters and buffers to the specified device without copying storage.

train([mode])

Set the module in training mode.

type(dst_type)

Casts all parameters and buffers to dst_type.

xpu([device])

Move all model parameters and buffers to the XPU.

zero_grad([set_to_none])

Reset gradients of all model parameters.

Attributes

T_destination

call_super_init

dump_patches

training

forward(X: Tensor) Tensor

Forward method for the QoI acquisition function.

For each candidate point in x this acquisition function does the following:

  • Fantasizes (via the chosen sampler) possible new observations (y) at this candidate point.

  • Trains a new GP with the additional (x,y_i) pair for each fantasy observation y_i.

  • Evaluates the qoi_estimator on these new GPs, and reports the variance in the resulting estimates.

This optimization will pick the point that resulted in the lowest mean variance in the QoI estimates.

Parameters:

X – (t_batch, 1, d) input points to evaluate the acquisiton function at.

Returns:

The output of the QoI acquisition function that will be optimized with shape (num_points,).

Todo

  • This should be updated to use the FantasizeMixin. This is the botorch interface indicating model.fantasize(X) is supported, which does a large chunk of the functionality below. The challenge is model.fantasize(X) adds an additonal dimension at the start of all posteriors calculated e.g. (num_fantasies, batch_shape, n, m). Unclear if our QoI methods can handle/respect the num_fantasies dimension, of if the different fantasy models can easily be extracted. Revisit at a future date.

  • Consider making the jobs batchable or multiprocessed.

lookahead(x_point: Tensor, y_point: Tensor, yvar_point: Tensor | None) Tensor

Performs a single lookahead calculation.

Adds a single additional datapoint to the GP, and determines the QoI with the new GP.

Parameters:
  • x_point – (d,) The x location of the new point

  • y_point – (m,) The y (target) of the new point

  • yvar_point – (m,) The y_var of the new point

Returns:

(,) Variance of the QoI with the lookahead GP