gpflux.sampling.sample#

This module enables you to sample from (Deep) GPs using different approaches.

Module Contents#

efficient_sample[source]#

A function that returns a Sample of a GP posterior.

class Sample[source]#

Bases: abc.ABC

This class represents a sample from a GP that you can evaluate by using the __call__ at new locations within the support of the GP.

Importantly, the same function draw (sample) is evaluated when calling it multiple times. This property is called consistency. Achieving consistency for vanilla GPs is costly because it scales cubically with the number of evaluation points, but works with any kernel. It is implemented in _efficient_sample_conditional_gaussian(). For KernelWithFeatureDecomposition, the more efficient approach following Wilson et al. [WBT+20] is implemented in _efficient_sample_matheron_rule().

See the tutorial notebooks Efficient sampling and Weight Space Approximation with Random Fourier Features for an in-depth overview.

abstract __call__(X: gpflow.base.TensorType) tf.Tensor[source]#

Return the evaluation of the GP sample \(f(X)\) for \(f \sim GP(0, k)\).

Parameters:

X – The inputs, a tensor with the shape [N, D], where D is the input dimensionality.

Returns:

Function values, a tensor with the shape [N, P], where P is the output dimensionality.

__add__(other: Sample | Callable[[gpflow.base.TensorType], gpflow.base.TensorType]) Sample[source]#

Allow for the summation of two instances that implement the __call__ method.

_efficient_sample_conditional_gaussian(inducing_variable: gpflow.inducing_variables.InducingVariables, kernel: gpflow.kernels.Kernel, q_mu: tf.Tensor, *, q_sqrt: gpflow.base.TensorType | None = None, whiten: bool = False) Sample[source]#

Most costly implementation for obtaining a consistent GP sample. However, this method can be used for any kernel.

_efficient_sample_matheron_rule(inducing_variable: gpflow.inducing_variables.InducingVariables, kernel: gpflux.sampling.kernel_with_feature_decomposition.KernelWithFeatureDecomposition, q_mu: tf.Tensor, *, q_sqrt: gpflow.base.TensorType | None = None, whiten: bool = False) Sample[source]#

Implements the efficient sampling rule from Wilson et al. [WBT+20] using the Matheron rule. To use this sampling scheme, the GP has to have a kernel of the KernelWithFeatureDecomposition type .

Parameters:
  • kernel – A kernel of the KernelWithFeatureDecomposition type, which holds the covariance function and the kernel’s features and coefficients.

  • q_mu – A tensor with the shape [M, P].

  • q_sqrt – A tensor with the shape [P, M, M].

  • whiten – Determines the parameterisation of the inducing variables.