gpflux.sampling.sample#
This module enables you to sample from (Deep) GPs using different approaches.
Module Contents#
- class Sample[source]#
Bases:
abc.ABCThis 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(). ForKernelWithFeatureDecomposition, 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.
- abstractmethod __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], whereDis the input dimensionality.- Returns:
Function values, a tensor with the shape
[N, P], wherePis the output dimensionality.
- _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
kernelof theKernelWithFeatureDecompositiontype .- Parameters:
kernel – A kernel of the
KernelWithFeatureDecompositiontype, 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.