botorch.posteriors

botorch.posteriors.posterior

Abstract base module for all botorch posteriors.

Posterior

class botorch.posteriors.posterior.Posterior[source]

Abstract base class for botorch posteriors.

abstract property device

The torch device of the posterior.

Return type

device

abstract property dtype

The torch dtype of the posterior.

Return type

dtype

abstract property event_shape

The event shape (i.e. the shape of a single sample).

Return type

Size

property mean

The mean of the posterior as a (b) x n x m-dim Tensor.

Return type

Tensor

abstract rsample(sample_shape=None, base_samples=None)[source]

Sample from the posterior (with gradients).

Parameters
  • sample_shape (Optional[Size]) – A torch.Size object specifying the sample shape. To draw n samples, set to torch.Size([n]). To draw b batches of n samples each, set to torch.Size([b, n]).

  • base_samples (Optional[Tensor]) – An (optional) Tensor of N(0, I) base samples of appropriate dimension, typically obtained from a Sampler. This is used for deterministic optimization.

Return type

Tensor

Returns

A sample_shape x event-dim Tensor of samples from the posterior.

sample(sample_shape=None, base_samples=None)[source]

Sample from the posterior (without gradients).

This is a simple wrapper calling rsample using with torch.no_grad().

Parameters
  • sample_shape (Optional[Size]) – A torch.Size object specifying the sample shape. To draw n samples, set to torch.Size([n]). To draw b batches of n samples each, set to torch.Size([b, n]).

  • base_samples (Optional[Tensor]) – An (optional) Tensor of N(0, I) base samples of appropriate dimension, typically obtained from a Sampler object. This is used for deterministic optimization.

Return type

Tensor

Returns

A sample_shape x event_shape-dim Tensor of samples from the posterior.

property variance

The variance of the posterior as a (b) x n x m-dim Tensor.

Return type

Tensor

botorch.posteriors.gpytorch

Posterior Module to be used with GPyTorch models.

GPyTorchPosterior

class botorch.posteriors.gpytorch.GPyTorchPosterior(mvn)[source]

A posterior based on GPyTorch’s multi-variate Normal distributions.

A posterior based on GPyTorch’s multi-variate Normal distributions.

Parameters

mvn (MultivariateNormal) – A GPyTorch MultivariateNormal (single-output case) or MultitaskMultivariateNormal (multi-output case).

property device

The torch device of the posterior.

Return type

device

property dtype

The torch dtype of the posterior.

Return type

dtype

property event_shape

The event shape (i.e. the shape of a single sample) of the posterior.

Return type

Size

property mean

The posterior mean.

Return type

Tensor

rsample(sample_shape=None, base_samples=None)[source]

Sample from the posterior (with gradients).

Parameters
  • sample_shape (Optional[Size]) – A torch.Size object specifying the sample shape. To draw n samples, set to torch.Size([n]). To draw b batches of n samples each, set to torch.Size([b, n]).

  • base_samples (Optional[Tensor]) – An (optional) Tensor of N(0, I) base samples of appropriate dimension, typically obtained from a Sampler. This is used for deterministic optimization.

Return type

Tensor

Returns

A sample_shape x event_shape-dim Tensor of samples from the posterior.

property variance

The posterior variance.

Return type

Tensor