trieste.models.gpflux.sampler#

Module Contents#

class DeepGaussianProcessReparamSampler(sample_size: int, model: trieste.models.gpflux.interface.GPfluxPredictor)[source]#

Bases: trieste.models.interfaces.ReparametrizationSampler[trieste.models.gpflux.interface.GPfluxPredictor]

This sampler employs the reparameterization trick to approximate samples from a GPfluxPredictor‘s predictive distribution, when the GPfluxPredictor has an underlying DeepGP.

Parameters
  • sample_size – The number of samples for each batch of points. Must be positive.

  • model – The model to sample from.

Raises

ValueError (or InvalidArgumentError) – If sample_size is not positive, if the model is not a GPfluxPredictor, of if its underlying model_gpflux is not a DeepGP.

sample(self, at: trieste.types.TensorType, *, jitter: float = DEFAULTS.JITTER)trieste.types.TensorType[source]#

Return approximate samples from the model specified at __init__(). Multiple calls to sample(), for any given DeepGaussianProcessReparamSampler and at, will produce the exact same samples. Calls to sample() on different DeepGaussianProcessReparamSampler instances will produce different samples.

Parameters
  • at – Where to sample the predictive distribution, with shape […, 1, D], for points of dimension D.

  • jitter – The size of the jitter to use when stabilizing the Cholesky decomposition of the covariance matrix.

Returns

The samples, of shape […, S, 1, L], where S is the sample_size and L is the number of latent model dimensions.

Raises

ValueError (or InvalidArgumentError) – If at has an invalid shape or jitter is negative.

class DeepGaussianProcessDecoupledTrajectorySampler(model: trieste.models.gpflux.interface.GPfluxPredictor, num_features: int = 1000)[source]#

Bases: trieste.models.interfaces.TrajectorySampler[trieste.models.gpflux.interface.GPfluxPredictor]

This sampler employs decoupled sampling (see [WBT+20]) to build functions that approximate a trajectory sampled from an underlying deep Gaussian process model. In particular, this sampler provides trajectory functions for GPfluxPredictors with underlying DeepGP models by using a feature decomposition using both random Fourier features and canonical features centered at inducing point locations. This allows for cheap approximate trajectory samples, as opposed to exact trajectory sampling, which scales cubically in the number of query points.

Note that we do not currently support deep GP models with multiple outputs.

Parameters
  • model – The model to sample from.

  • num_features – The number of random Fourier features to use.

Raises

ValueError (or InvalidArgumentError) – If the model is not a GPfluxPredictor, or its underlying model_gpflux is not a DeepGP, or num_features is not positive.

get_trajectory(self)trieste.models.interfaces.TrajectoryFunction[source]#

Generate an approximate function draw (trajectory) from the deep GP model.

Returns

A trajectory function representing an approximate trajectory from the deep GP, taking an input of shape [N, B, D] and returning shape [N, B].

update_trajectory(self, trajectory: trieste.models.interfaces.TrajectoryFunction)trieste.models.interfaces.TrajectoryFunction[source]#

Efficiently update a TrajectoryFunction to reflect an update in its underlying ProbabilisticModel and resample accordingly.

Parameters

trajectory – The trajectory function to be updated and resampled.

Returns

The updated and resampled trajectory function.

Raises

InvalidArgumentError – If trajectory is not a dgp_feature_decomposition_trajectory

resample_trajectory(self, trajectory: trieste.models.interfaces.TrajectoryFunction)trieste.models.interfaces.TrajectoryFunction[source]#

Efficiently resample a TrajectoryFunction in-place to avoid function retracing with every new sample.

Parameters

trajectory – The trajectory function to be resampled.

Returns

The new resampled trajectory function.

Raises

InvalidArgumentError – If trajectory is not a dgp_feature_decomposition_trajectory

class DeepGaussianProcessDecoupledLayer(layer: gpflux.layers.GPLayer, num_features: int = 1000)[source]#

Bases: abc.ABC

Layer that samples an approximate decoupled trajectory for a GPflux GPLayer using Matheron’s rule ([WBT+20]). Note that the only multi-output kernel that is supported is a SharedIndependent kernel.

Parameters
  • layer – The layer that we wish to sample from.

  • num_features – The number of features to use in the random feature approximation.

Raises

ValueError (or InvalidArgumentError) – If the layer is not a GPLayer, the layer’s kernel is not supported, or if num_features is not positive.

__call__(self, x: trieste.types.TensorType)trieste.types.TensorType[source]#

Evaluate trajectory function for layer at input.

Parameters

x – Input location with shape [N, B, D], where N is the number of points, B is the batch dimension, and D is the input dimensionality.

Returns

Trajectory for the layer evaluated at the input, with shape [N, B, P], where P is the number of latent GPs in the layer.

Raises

InvalidArgumentError – If the provided batch size does not match with the layer’s batch size.

resample(self)None[source]#

Efficiently resample in-place without retracing.

update(self)None[source]#

Efficiently update the trajectory with a new weight distribution and resample its weights.

_prepare_weight_sampler(self)Callable[[int], trieste.types.TensorType][source]#

Prepare the sampler function that provides samples of the feature weights for both the RFF and canonical feature functions, i.e. we return a function that takes in a batch size B and returns B samples for the weights of each of the L RFF features and M canonical features for P outputs.

class ResampleableDecoupledDeepGaussianProcessFeatureFunctions(layer: gpflux.layers.GPLayer, n_components: int)[source]#

Bases: RFF

A wrapper around GPflux’s random Fourier feature function that allows for efficient in-place updating when generating new decompositions. In addition to providing Fourier features, this class concatenates a layer’s Fourier feature expansion with evaluations of the canonical basis functions.

Parameters
  • layer – The layer that will be approximated by the feature functions.

  • n_components – The number of features.

Raises

ValueError – If the layer is not a GPLayer.

resample(self)None[source]#

Resample weights and biases.

__call__(self, x: trieste.types.TensorType)trieste.types.TensorType[source]#

Evaluate and combine prior basis functions and canonical basic functions at the input.

class dgp_feature_decomposition_trajectory(sampling_layers: List[DeepGaussianProcessDecoupledLayer])[source]#

Bases: trieste.models.interfaces.TrajectoryFunctionClass

An approximate sample from a deep Gaussian process’s posterior, where the samples are represented as a finite weighted sum of features. This class essentially takes a list of DeepGaussianProcessDecoupledLayers and iterates through them to sample, update and resample. Note that we assume that the model only has one output.

Parameters

sampling_layers – Samplers corresponding to each layer of the DGP model.

__call__(self, x: trieste.types.TensorType)trieste.types.TensorType[source]#

Call trajectory function by looping through layers.

Parameters

x – Input location with shape [N, B, D], where N is the number of points, B is the batch dimension, and D is the input dimensionality.

Returns

Trajectory samples with shape [N, B].

update(self)None[source]#

Update the layers with new features and weights.

resample(self)None[source]#

Resample the layer weights.