StateSpaceConjugatePosterior#

class gpjax.state_space.StateSpaceConjugatePosterior(prior, likelihood, jitter=1e-06)[source]#

Bases: ConjugatePosterior

Conjugate posterior for a state-space (Markovian) GP.

v1 prediction surface:
  • predict : smoothed-latent prediction (Phase 10)

  • predict_filter : causal filtered prediction (Phase 10)

  • __call__ : delegates to predict

Both predict and predict_filter reject return_covariance_type="dense" in favour of v1’s diagonal-only contract before any further dispatch.

Predictive contract (v1): prediction returns diagonal (marginal) covariance only; the marginals are exact. A dense joint predictive is not implemented in v1 and is tracked as a follow-up. This predictive is therefore not Liskov-substitutable for a dense gpjax.gps.ConjugatePosterior predictive.

Example

>>> import gpjax as gpx
>>> from gpjax.state_space import StateSpacePrior
>>> prior = StateSpacePrior(
...     mean_function=gpx.mean_functions.Zero(),
...     kernel=gpx.kernels.Matern32(lengthscale=1.0, variance=1.0),
... )
>>> likelihood = gpx.likelihoods.Gaussian(num_datapoints=20, obs_stddev=0.1)
>>> posterior = prior * likelihood
>>> posterior.__class__.__name__
'StateSpaceConjugatePosterior'
Parameters:
predict(test_inputs, train_data, *, return_covariance_type='diagonal', observation_mask=None)[source]#

Query the predictive posterior distribution.

Conditional on a training data set, compute the GP’s posterior predictive distribution for a given set of parameters. The returned function can be evaluated at a set of test inputs to compute the corresponding predictive density.

The predictive distribution of a conjugate GP is given by

\[\begin{split} p(\mathbf{f}^{\star}\mid \mathbf{y}) & = \int p(\mathbf{f}^{\star} \mathbf{f} \mid \mathbf{y})\\ & =\mathcal{N}(\mathbf{f}^{\star} \boldsymbol{\mu}_{\mid \mathbf{y}}, \boldsymbol{\Sigma}_{\mid \mathbf{y}} \end{split}\]
where
\[\begin{split} \boldsymbol{\mu}_{\mid \mathbf{y}} & = k(\mathbf{x}^{\star}, \mathbf{x})\left(k(\mathbf{x}, \mathbf{x}')+\sigma^2\mathbf{I}_n\right)^{-1}\mathbf{y} \\ \boldsymbol{\Sigma}_{\mid \mathbf{y}} & =k(\mathbf{x}^{\star}, \mathbf{x}^{\star\prime}) -k(\mathbf{x}^{\star}, \mathbf{x})\left( k(\mathbf{x}, \mathbf{x}') + \sigma^2\mathbf{I}_n \right)^{-1}k(\mathbf{x}, \mathbf{x}^{\star}). \end{split}\]

The conditioning set is a GPJax Dataset object, whilst predictions are made on a regular Jax array.

Example

>>> import gpjax as gpx
>>> import jax.numpy as jnp
>>>
>>> xtrain = jnp.linspace(0, 1).reshape(-1, 1)
>>> ytrain = jnp.sin(xtrain)
>>> D = gpx.Dataset(X=xtrain, y=ytrain)
>>> xtest = jnp.linspace(0, 1).reshape(-1, 1)
>>>
>>> prior = gpx.gps.Prior(mean_function = gpx.mean_functions.Zero(), kernel = gpx.kernels.RBF())
>>> posterior = prior * gpx.likelihoods.Gaussian(num_datapoints = D.n)
>>> predictive_dist = posterior(xtest, D)
Parameters:
  • test_inputs (Num[Array, "N D"]) – A Jax array of test inputs at which the predictive distribution is evaluated.

  • train_data (Dataset) – A gpx.Dataset object that contains the input and output data used for training dataset.

  • return_covariance_type – 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 function that accepts an input array and

returns the predictive distribution as a GaussianDistribution.

Return type:

GaussianDistribution