Prior#
- class gpjax.gps.Prior(kernel, mean_function, jitter=1e-06)[source]#
Bases:
_SummaryMixin,Module,Generic[M,K]A Gaussian process prior object.
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
Priordistribution, 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.
- Parameters:
kernel (K)
mean_function (M)
jitter (float)
- predict(test_inputs, *, covariance='dense')[source]#
Compute the prior predictive distribution at the test inputs.
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.
covariance (Literal['dense', 'diagonal']) – Whether to return the dense joint covariance at the test inputs or only the marginal (diagonal) variances.
- Returns:
- A multivariate normal random variable
representation of the Gaussian process.
- Return type:
Expand for references to
gpjax.gps.Prior.predict
- 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 via 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.
The same sample draw is evaluated for all queries, at constant cost per query.
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:
- Returns:
- A function representing an approximate sample
from the Gaussian process prior.
- Return type:
Expand for references to
gpjax.gps.Prior.sample_approx