Prior#

class gpjax.gps.Prior(kernel, mean_function, jitter=1e-06)[source]#

Bases: AbstractPrior[M, K]

A Gaussian process prior object.

The GP is parameterised by a mean and kernel function.

A Gaussian process prior parameterised by a mean function \(m(\cdot)\) and a kernel function \(k(\cdot, \cdot)\) is given by \(p(f(\cdot)) = \mathcal{GP}(m(\cdot), k(\cdot, \cdot))\).

To invoke a Prior distribution, a kernel and mean function must be specified.

Example

>>> import gpjax as gpx
>>> kernel = gpx.kernels.RBF()
>>> meanf = gpx.mean_functions.Zero()
>>> prior = gpx.gps.Prior(mean_function=meanf, kernel = kernel)

See also

New to Gaussian Processes? derives the prior from first principles, and Regression puts one to work end to end.

Expand for references to gpjax.gps.Prior

Prior

GPJax / “Hello, GP!”

fit

ConjugatePosterior

conjugate_loocv

StateSpaceConjugatePosterior

StateSpacePrior

Parameters:
  • kernel (K)

  • mean_function (M)

  • jitter (float)

predict(test_inputs, *, return_covariance_type='dense')[source]#

Compute the predictive prior distribution for a given set of parameters. The output of this function is a GaussianDistribution for a given set of inputs.

In the following example, we compute the predictive prior distribution and then evaluate it on the interval \([0, 1]\):

Example

>>> import gpjax as gpx
>>> import jax.numpy as jnp
>>> kernel = gpx.kernels.RBF()
>>> mean_function = gpx.mean_functions.Zero()
>>> prior = gpx.gps.Prior(mean_function=mean_function, kernel=kernel)
>>> prior.predict(jnp.linspace(0, 1, 100)[:, None])
Parameters:
  • test_inputs (Float[Array, "N D"]) – The inputs at which to evaluate the prior distribution.

  • return_covariance_type (Literal['dense', 'diagonal']) – Literal denoting whether to return the full covariance of the joint predictive distribution at the test_inputs (dense) or just the the standard-deviation of the predictive distribution at the test_inputs.

Returns:

A multivariate normal random variable representation

of the Gaussian process.

Return type:

GaussianDistribution

Expand for references to gpjax.gps.Prior.predict

Prior

StateSpacePrior

sample_approx(num_samples, key, num_features=100)[source]#

Approximate samples from the Gaussian process prior.

Build an approximate sample from the Gaussian process prior. This method provides a function that returns the evaluations of a sample across any given inputs.

In particular, we approximate the Gaussian processes’ prior as the finite feature approximation \(\hat{f}(x) = \sum_{i=1}^m\phi_i(x)\theta_i\) where \(\phi_i\) are \(m\) features sampled from the Fourier feature decomposition of the model’s kernel and \(\theta_i\) are samples from a unit Gaussian.

A key property of such functional samples is that the same sample draw is evaluated for all queries. Consistency is a property that is prohibitively costly to ensure when sampling exactly from the GP prior, as the cost of exact sampling scales cubically with the size of the sample. In contrast, finite feature representations can be evaluated with constant cost regardless of the required number of queries.

In the following example, we build 10 such samples and then evaluate them over the interval \([0, 1]\):

For a prior distribution, the following code snippet will build and evaluate an approximate sample.

Example

>>> import gpjax as gpx
>>> import jax.numpy as jnp
>>> import jax.random as jr
>>> key = jr.key(123)
>>>
>>> meanf = gpx.mean_functions.Zero()
>>> kernel = gpx.kernels.RBF(n_dims=1)
>>> prior = gpx.gps.Prior(mean_function=meanf, kernel = kernel)
>>>
>>> sample_fn = prior.sample_approx(10, key)
>>> sample_fn(jnp.linspace(0, 1, 100).reshape(-1, 1))
Parameters:
  • num_samples (int) – The desired number of samples.

  • key (KeyArray) – The random seed used for the sample(s).

  • num_features (int) – The number of features used when approximating the kernel.

Returns:

A function representing an approximate sample from the

Gaussian process prior.

Return type:

FunctionalSample

Expand for references to gpjax.gps.Prior.sample_approx

Prior