GaussianProcess¶
- class probnum.randprocs.GaussianProcess(mean, cov)¶
Bases:
probnum.randprocs.RandomProcess
[Union
[numpy.typing._array_like._SupportsArray
[numpy.dtype
],numpy.typing._nested_sequence._NestedSequence
[numpy.typing._array_like._SupportsArray
[numpy.dtype
]],bool
,int
,float
,complex
,str
,bytes
,numpy.typing._nested_sequence._NestedSequence
[Union
[bool
,int
,float
,complex
,str
,bytes
]]],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.
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.
>>> import numpy as np >>> from probnum.randprocs.mean_fns import Zero >>> from probnum.randprocs.kernels import ExpQuad >>> from probnum.randprocs import GaussianProcess >>> mu = Zero(input_shape=()) # zero-mean function >>> k = ExpQuad(input_shape=()) # RBF kernel >>> gp = GaussianProcess(mu, k)
Sample from the Gaussian process.
>>> x = np.linspace(-1, 1, 5) >>> rng = np.random.default_rng(seed=42) >>> gp.sample(rng, x) array([-0.7539949 , -0.6658092 , -0.52972512, 0.0674298 , 0.72066223]) >>> 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
Covariance function \(k(x_0, x_1)\) of the random process.
Data type of (elements of) the random process evaluated at an input.
Syntactic sugar for
len(input_shape)
.Shape of inputs to the random process.
Mean function \(m(x) := \mathbb{E}[f(x)]\) of the random process.
Syntactic sugar for
len(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.
marginal
(args)Batch of random variables defining the marginal distributions at the inputs.
push_forward
(args, base_measure, sample)Transform samples from a base measure into samples from the random process.
sample
(rng[, args, size])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}- Return type
Methods Documentation
- __call__(args)[source]¶
Evaluate the random process at a set of input arguments.
- Parameters
args (
Union
[_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 requirebatch_shape
to have at most one dimension.- Returns
shape=
batch_shape +
output_shape
– Random process evaluated at the input(s).- Return type
- marginal(args)¶
Batch of random variables defining the marginal distributions at the inputs.
- Parameters
args (
TypeVar
(InputType
)) – shape=batch_shape +
input_shape
– (Batch of) input(s) at which to evaluate the random process. Currently, we requirebatch_shape
to have at most one dimension.- Return type
- 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 (
TypeVar
(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 requiresample_shape
to have at most one dimension.
- Return type
- sample(rng, args=None, size=())¶
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
rng (
Generator
) – Random number generator.args (
Optional
[TypeVar
(InputType
)]) – shape=size +
input_shape
– (Batch of) input(s) at which the sample paths will be evaluated. Currently, we requiresize
to have at most one dimension. IfNone
, sample paths, i.e. callables are returned.size (
Union
[int
,Integral
,integer
,Iterable
[Union
[int
,Integral
,integer
]]]) – Size of the sample.
- Return type
Union
[Callable
[[TypeVar
(InputType
)],TypeVar
(OutputType
)],TypeVar
(OutputType
)]
- std(args)¶
Standard deviation function.
- Parameters
args (
TypeVar
(InputType
)) – 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 atargs
.- 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 (
TypeVar
(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 atargs
.- Return type
_OutputType