# GaussianProcess¶

class probnum.randprocs.GaussianProcess(mean, cov)

Bases: probnum.randprocs._random_process.RandomProcess[Union[numpy.floating, numpy.ndarray], Union[numpy.floating, numpy.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

RandomProcess

Random processes.

MarkovProcess

Random processes with the Markov property.

Examples

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

>>> import numpy as np
>>> from probnum.randprocs import GaussianProcess
>>> mu = lambda x : np.zeros_like(x)  # zero-mean function
>>> k = ExpQuad(input_dim=1)  # RBF kernel
>>> gp = GaussianProcess(mu, k)


Sample from the Gaussian process.

>>> x = np.linspace(-1, 1, 5)[:, None]
>>> np.random.seed(42)
>>> gp.sample(x)
array([[-0.35187364],
[-0.41301096],
[-0.65094306],
[-0.56817194],
[ 0.01173088]])
>>> gp.cov(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

 dtype Data type of (elements of) the random process evaluated at an input. input_dim Shape of inputs to the random process. output_dim Shape of the random process evaluated at an input.

Methods Summary

 __call__(args) Evaluate the random process at a set of input arguments. cov(args0[, args1]) Covariance function or kernel. marginal(args) Batch of random variables defining the marginal distributions at the inputs. mean(args) Mean function. push_forward(args, base_measure, sample) Transform samples from a base measure into samples from the random process. sample([args, size, random_state]) Sample paths from the random process. std(args) Standard deviation function. var(args) Variance function.

Attributes Documentation

dtype

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

Return type

dtype

input_dim

Shape of inputs to the random process.

Return type

int

output_dim

Shape of the random process evaluated at an input.

Return type

int

Methods Documentation

__call__(args)[source]

Evaluate the random process at a set of input arguments.

Parameters

args (Union[floating, ndarray]) – shape=(input_dim,) or (n, input_dim) – Input(s) to evaluate random process at.

Returns

shape=(), (output_dim,) or (n, output_dim) – Random process evaluated at the inputs.

Return type

randvars.RandomVariable

cov(args0, args1=None)[source]

Covariance function or kernel.

Returns the covariance function $$\operatorname{Cov}(f(x_0), f(x_1)) = \mathbb{E}[(f(x_0) - \mathbb{E}[f(x_0)])(f(x_0) - \mathbb{E}[f( x_0)])^\top]$$ of the process evaluated at $$x_0$$ and $$x_1$$. If only args0 is given the covariance among the components of the random process at the inputs defined by args0 is computed.

Parameters
Returns

shape=(), (output_dim, output_dim), (n0, n1) or (n0, n1, output_dim, output_dim) – Covariance of the process at args0 and args1. If only args0 is given the kernel matrix $$K=k(x_0, x_0)$$ is computed.

Return type

_OutputType

marginal(args)

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

Parameters

args (~InputType) – shape=(input_dim,) or (n, input_dim) – Input(s) to evaluate random process at.

Return type

_RandomVariableList

mean(args)[source]

Mean function.

Returns the mean function evaluated at the given input(s).

Parameters

args (Union[floating, ndarray]) – shape=(input_dim,) or (n, input_dim) – Input(s) where the mean function is evaluated.

Returns

shape=(), (output_dim, ) or (n, output_dim) – Mean function of the process evaluated at inputs x.

Return type

_OutputType

push_forward(args, base_measure, sample)[source]

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
Return type

ndarray

sample(args=None, size=(), random_state=None)

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 (~InputType) – shape=(input_dim,) or (n, input_dim) – Input(s) to the standard deviation function.

Returns

shape=(), (output_dim,) or (n, output_dim) – 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=(input_dim,) or (n, input_dim) – Input(s) to the variance function.

Returns

shape=(), (output_dim,) or (n, output_dim) – Variance of the process at args.

Return type

_OutputType