GaussianProcess

class itergp.GaussianProcess(mean, cov)

Bases: RandomProcess[Union[ndarray, _SupportsArray[dtype], _NestedSequence[_SupportsArray[dtype]], bool, int, float, complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]], ndarray]

Gaussian processes.

A Gaussian process is a continuous stochastic process which if evaluated at a finite set of inputs returns a random variable with a normal distribution. Gaussian processes are fully characterized by their mean and covariance function.

Parameters
  • mean – Mean function.

  • cov – Covariance function or kernel.

See also

RandomProcess

Random processes.

MarkovProcess

Random processes with the Markov property.

Examples

Define a Gaussian process with a zero mean function and RBF kernel.

>>> from probnum import backend
>>> from probnum.randprocs.mean_fns import Zero
>>> from probnum.randprocs.kernels import ExpQuad
>>> from probnum.randprocs import GaussianProcess
>>> mu = Zero(input_shape=())
>>> k = ExpQuad(input_shape=())
>>> gp = GaussianProcess(mu, k)

Sample from the Gaussian process.

>>> x = backend.linspace(-1, 1, 5)
>>> rng_state = backend.random.rng_state(seed=42)
>>> gp.sample(rng_state, x)
array([ 0.30471708, -0.22021158, -0.36160304,  0.05888274,  0.27793918])
>>> gp.cov.matrix(x)
array([[1.        , 0.8824969 , 0.60653066, 0.32465247, 0.13533528],
       [0.8824969 , 1.        , 0.8824969 , 0.60653066, 0.32465247],
       [0.60653066, 0.8824969 , 1.        , 0.8824969 , 0.60653066],
       [0.32465247, 0.60653066, 0.8824969 , 1.        , 0.8824969 ],
       [0.13533528, 0.32465247, 0.60653066, 0.8824969 , 1.        ]])

Attributes Summary

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.

marginal(args)

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

plot(X[, data, stdevs, samples, rng_state, ax])

Plot the Gaussian process.

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)

Variance function.

Attributes Documentation

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)[source]

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

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,), samples=0, rng_state=SeedSequence(entropy=0), ax=None, **kwargs)

Plot the Gaussian process.

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

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

  • 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.

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

  • rng_state (SeedSequence) – Random number generator state for plotting samples.

  • ax (Optional[Axis]) – Plot axis.

Return type

Axis

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)

Variance function.

Returns the variance function which is the value of the covariance or kernel evaluated elementwise at args for each output dimension separately.

Parameters

args (InputType) – shape= batch_shape + input_shape – (Batch of) input(s) at which to evaluate the variance function.

Returns

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

Return type

OutputType