log_posterior_density#

gpjax.objectives.log_posterior_density(model, data)[source]#

The log-posterior density of a non-conjugate Gaussian process. This is sometimes referred to as the marginal log-likelihood.

Evaluate the log-posterior density of a Gaussian process.

Compute the marginal log-likelihood, or log-posterior density of the Gaussian process. The returned function can then be used for gradient based optimisation of the model’s parameters or for model comparison. The implementation given here is general and will work for any likelihood support by GPJax.

Conditioning a ConjugateModel yields an ExactPosterior, whose log_marginal_likelihood is available in closed form. Conditioning a NonConjugateModel instead yields a LatentPosterior, which has no exact marginal log-likelihood: it represents the posterior as a function of the model’s hyperparameters and the latent function, and exposes the unnormalised log_posterior_density in its place. Markov chain Monte Carlo, variational inference, or Laplace approximations can then be used to sample from, or optimise an approximation to, the posterior distribution.

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)
>>> meanf = gpx.mean_functions.Constant()
>>> kernel = gpx.kernels.RBF()
>>> likelihood = gpx.likelihoods.Bernoulli()
>>> prior = gpx.gps.Prior(mean_function=meanf, kernel=kernel)
>>> model = (prior * likelihood).init_latent(D.n)
>>> gpx.objectives.log_posterior_density(model, D)
Parameters:
  • model (NonConjugateModel) – The joint model for which we want to compute the log-posterior density.

  • data (Dataset) – The training dataset used to compute the log-posterior density.

Returns:

The log-posterior density of the Gaussian process.

Return type:

ScalarFloat