custom_torch#

Custom implementations of PyTorch surrogate models using BoTorch API

Classes

DNN(train_X, train_Y[, p_dropout, h_width, ...])

DNNPosterior(values)

class obsidian.surrogates.custom_torch.DNN(train_X: Tensor, train_Y: Tensor, p_dropout: float = 0.2, h_width: int = 16, h_layers: int = 2, num_outputs: int = 1)[source]#

Bases: EnsembleModel, FantasizeMixin

condition_on_observations(X: Tensor, Y: Tensor) TFantasizeMixin[source]#

Condition the model to new observations, returning a fantasy model

fantasize(X: Tensor) Model[source]#

Construct a fantasy model.

Constructs a fantasy model in the following fashion: (1) compute the model posterior at X, including observation noise. If observation_noise is a Tensor, use it directly as the observation noise to add. (2) sample from this posterior (using sampler) to generate “fake” observations. (3) condition the model on the new fake observations.

Parameters:
  • X – A batch_shape x n’ x d-dim Tensor, where d is the dimension of the feature space, n’ is the number of points per batch, and batch_shape is the batch shape (must be compatible with the batch shape of the model).

  • sampler – The sampler used for sampling from the posterior at X.

  • observation_noise – A model_batch_shape x 1 x m-dim tensor or a model_batch_shape x n’ x m-dim tensor containing the average noise for each batch and output, where m is the number of outputs. noise must be in the outcome-transformed space if an outcome transform is used. If None and using an inferred noise likelihood, the noise will be the inferred noise level. If using a fixed noise likelihood, the mean across the observation noise in the training data is used as observation noise.

  • kwargs – Will be passed to model.condition_on_observations

Returns:

The constructed fantasy model.

forward(x: Tensor) Tensor[source]#

Compute the (ensemble) model output at X.

Parameters:

X – A batch_shape x n x d-dim input tensor X.

Returns:

A batch_shape x s x n x m-dimensional output tensor where s is the size of the ensemble.

property num_outputs: int#

Number of outputs of the model

posterior(X: Tensor, n_sample: int = 512, output_indices: list[int] | None = None, observation_noise: bool | Tensor = False) Posterior[source]#

Calculates the posterior distribution of the model at X

transform_inputs(X: Tensor, input_transform: Module | None = None) Tensor[source]#

Transform inputs.

Parameters:
  • X – A tensor of inputs

  • input_transform – A Module that performs the input transformation.

Returns:

A tensor of transformed inputs

class obsidian.surrogates.custom_torch.DNNPosterior(values: Tensor)[source]#

Bases: EnsemblePosterior

quantile(value: Tensor) Tensor[source]#

Quantile of the ensemble posterior