ConditionalGaussianProcess¶
- class itergp.ConditionalGaussianProcess(prior, Xs, Ys, bs, ks, gram_Xs_Xs_inv, representer_weights)¶
Bases:
GaussianProcessConditional 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
GaussianProcessGaussian Processes.
Attributes Summary
Computational predictive distribution.
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.
condition_on_data(X, Y[, b, approx_method])Condition the Gaussian process on data.
from_data(prior, X, Y[, b, approx_method])Construct a
ConditionalGaussianProcessfrom 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 requirebatch_shapeto 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
- Return type
- classmethod from_data(prior, X, Y, b=None, approx_method=<itergp.methods.Cholesky object>)[source]¶
Construct a
ConditionalGaussianProcessfrom 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 requirebatch_shapeto have at most one dimension.- Return type
- 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.
kwargs – Key word arguments passed onto
matplotlib.pyplot.plot().
- 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 (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_shapeto have at most one dimension.
- Return type
- 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
rng_state (SeedSequence) – Random number generator state.
args (Optional[InputType]) – shape=
sample_shape +input_shape– (Batch of) input(s) at which the sample paths will be evaluated. Currently, we requiresample_shapeto have at most one dimension. IfNone, sample paths, i.e. callables are returned.sample_shape (Union[int, Integral, integer, Iterable[Union[int, Integral, integer]]]) – Shape of the sample.
- Return type
- 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 atargs.- Return type
OutputType