ConditionalGaussianProcess

class itergp.ConditionalGaussianProcess(prior, Xs, Ys, bs, ks, gram_Xs_Xs_inv, representer_weights)

Bases: GaussianProcess

Conditional Gaussian Process.

Gaussian process conditioned on a dataset \((X, y)\) of training inputs \(X\) and corresponding outputs \(y\). Given a Gaussian process prior \(f \sim \mathcal{GP}(\mu, k)\) and likelihood \(y \mid f(x) = f(x) + b = \mathcal{N}(y; f(x) + \mathbb{E}[b], \operatorname{Cov}(b))\), the posterior at a new input \(x_\star\) is given by \(p(f_\star \mid X, y)\) with

\[\begin{split}\begin{align} \mathbb{E}[f_\star] & = \mu(x_\star) + k(x_\star, X)\hat{K}^{-1} (y - \mu(X)), \\ \operatorname{Cov}(f_\star) & = k(x_\star,x_\star) - k(x_\star, X)\hat{K}^{-1} k(X, x_\star), \end{align}\end{split}\]

where \(\hat{K} = K + \operatorname{Cov}(b)\) is the Gram matrix.

Parameters
  • prior – Gaussian process prior.

  • Xs – Training inputs.

  • Ys – Training outputs.

  • bs – Observation noise.

  • ks – Kernel functions.

  • gram_Xs_Xs_inv – Factor of the Gram matrix \(\hat{K} = K + \operatorname{Cov}(b)\).

  • representer_weights – Representer weights \(\hat{K}^{-1}y\).

See also

GaussianProcess

Gaussian Processes.

Attributes Summary

computational_predictive

Computational predictive distribution.

cov

Covariance function \(k(x_0, x_1)\) of the random process.

dtype

Data type of (elements of) the random process evaluated at an input.

input_ndim

Syntactic sugar for len(input_shape).

input_shape

Shape of inputs to the random process.

mean

Mean function \(m(x) := \mathbb{E}[f(x)]\) of the random process.

output_ndim

Syntactic sugar for len(output_shape).

output_shape

Shape of the random process evaluated at an input.

Methods Summary

__call__(args)

Evaluate the random process at a set of input arguments.

condition_on_data(X, Y[, b, approx_method])

Condition the Gaussian process on data.

from_data(prior, X, Y[, b, approx_method])

Construct a ConditionalGaussianProcess from data.

marginal(args)

Batch of random variables defining the marginal distributions at the inputs.

plot(X[, data, stdevs, ...])

Plot the Gaussian process.

predictive(X)

Compute the predictive distribution.

push_forward(args, base_measure, sample)

Transform samples from a base measure into samples from the random process.

sample(rng_state[, args, sample_shape])

Sample paths from the random process.

std(args)

Standard deviation function.

var(args)

Compute variance in a matrix-free fashion.

Attributes Documentation

computational_predictive

Computational predictive distribution.

Returns the Gaussian process quantifying computational uncertainty induced by the numerical approximation method used to compute the representer weights.

cov

Covariance function \(k(x_0, x_1)\) of the random process.

\begin{equation} k(x_0, x_1) := \mathbb{E} \left[ (f(x_0) - \mathbb{E}[f(x_0)]) (f(x_1) - \mathbb{E}[f(x_1)])^\top \right] \end{equation}
dtype

Data type of (elements of) the random process evaluated at an input.

input_ndim

Syntactic sugar for len(input_shape).

input_shape

Shape of inputs to the random process.

mean

Mean function \(m(x) := \mathbb{E}[f(x)]\) of the random process.

output_ndim

Syntactic sugar for len(output_shape).

output_shape

Shape of the random process evaluated at an input.

Methods Documentation

__call__(args)

Evaluate the random process at a set of input arguments.

Parameters

args (Union[ndarray, _SupportsArray[dtype], _NestedSequence[_SupportsArray[dtype]], bool, int, float, complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]]) – shape= batch_shape + input_shape – (Batch of) input(s) at which to evaluate the random process. Currently, we require batch_shape to have at most one dimension.

Returns

shape= batch_shape + output_shape – Random process evaluated at the input(s).

Return type

randvars.RandomVariable

condition_on_data(X, Y, b=None, approx_method=<itergp.methods.Cholesky object>)

Condition the Gaussian process on data.

Given a Gaussian process prior \(f \sim \mathcal{GP}(\mu, k)\), condition on data \((X, y)\) assuming a likelihood of the form \(y \mid f(x) = f(x) + b = \mathcal{N}(y; f(x) + \mathbb{E}[b], \operatorname{Cov}(b))\).

Parameters
  • X (ndarray) – Training inputs.

  • Y (ndarray) – Training outputs.

  • b (Optional[Normal]) – Observation noise.

  • approx_method – (Iterative) approximation method to compute the conditional distribution.

Return type

ConditionalGaussianProcess

classmethod from_data(prior, X, Y, b=None, approx_method=<itergp.methods.Cholesky object>)[source]

Construct a ConditionalGaussianProcess from data.

Parameters
  • prior (GaussianProcess) – Gaussian process prior.

  • X (backend.Array) – Training inputs.

  • Y (backend.Array) – Training outputs.

  • b (Optional[randvars.Normal]) – Observation noise.

  • approx_method (methods.ApproximationMethod) – (Iterative) Approximation method to compute the linear solve \(v \mapsto \hat{K}^{-1} v\).

marginal(args)

Batch of random variables defining the marginal distributions at the inputs.

Parameters

args (InputType) – shape= batch_shape + input_shape – (Batch of) input(s) at which to evaluate the random process. Currently, we require batch_shape to have at most one dimension.

Return type

_RandomVariableList

plot(X, data=None, stdevs=(2,), computational_predictive=False, samples=0, rng_state=SeedSequence(entropy=0), ax=None, color='C0', **kwargs)[source]

Plot the Gaussian process.

Parameters
  • X (ndarray) – Input points to plot at.

  • stdevs (Tuple[float, ...]) – Number of standard deviations to plot around the mean of the Gaussian process. Can be a tuple to plot more than one shaded credible region.

  • computational_predictive (bool) – Whether to plot the computational predictive distribution.

  • samples (int) – Number of samples to plot.

  • rng_state (SeedSequence) – Random number generator state.

  • ax (Optional[Axis]) – Axis to plot into

  • kwargs – Key word arguments passed onto matplotlib.pyplot.plot().

  • data (Optional[Tuple[ndarray, ndarray]]) –

Return type

Axis

predictive(X)[source]

Compute the predictive distribution.

Parameters

X (ndarray) – Inputs to predict at.

Return type

Normal

push_forward(args, base_measure, sample)

Transform samples from a base measure into samples from the random process.

This function can be used to control sampling from the random process by explicitly passing samples from a base measure evaluated at the input arguments.

Parameters
  • args (InputType) – Input arguments.

  • base_measure (Type[RandomVariable]) – Base measure. Given as a type of random variable.

  • sample (ndarray) – shape= sample_shape + input_shape – (Batch of) input(s) at which to evaluate the random process. Currently, we require sample_shape to have at most one dimension.

Return type

ndarray

sample(rng_state, args=None, sample_shape=())

Sample paths from the random process.

If no inputs are provided this function returns sample paths which are callables, otherwise random variables corresponding to the input locations are returned.

Parameters
Return type

Union[Callable[[InputType], OutputType], OutputType]

std(args)

Standard deviation function.

Parameters

args (Union[ndarray, _SupportsArray[dtype], _NestedSequence[_SupportsArray[dtype]], bool, int, float, complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]]) – shape= batch_shape + input_shape – (Batch of) input(s) at which to evaluate the standard deviation function.

Returns

shape= batch_shape + output_shape – Standard deviation of the process at args.

Return type

OutputType

var(args)

Compute variance in a matrix-free fashion.

Parameters

args (Union[ndarray, _SupportsArray[dtype], _NestedSequence[_SupportsArray[dtype]], bool, int, float, complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]]) –

Return type

ndarray