Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Training a Markov GP — hyperparameter learning

MarkovGPPrior.log_marginal(y, noise_var) is the Kalman-filter marginal likelihood. It is differentiable in every kernel hyperparameter (variance, lengthscale, noise_var, ...) thanks to JAX’s automatic differentiation through the SDE construction and the lax.scan-based filter. That makes hyperparameter learning a one-line gradient descent.

This notebook

  1. generates a noisy 1-D time series,
  2. defines a MaternSDE prior and treats (log_variance, log_lengthscale, log_noise_var) as free parameters,
  3. minimises the negative log marginal likelihood via L-BFGS,
  4. visualises the learned predictive against the data.
/home/azureuser/localfiles/pyrox/.venv/lib/python3.13/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html
  from .autonotebook import tqdm as notebook_tqdm

Synthetic data

A noisy mixture of two sinusoids on an irregular time grid. Wide enough lengthscale that a Matern-3/2 SDE prior fits cleanly.

<Figure size 880x330 with 1 Axes>

Parameterise the hyperparameters

We optimise in log-space so the constraint σ2,ℓ,σn2>0\sigma^2, \ell, \sigma_n^2 > 0 is automatically satisfied. The model lives in a tiny equinox.Module so it composes cleanly with optax.

initial NLL: 25.522

Optimise with L-BFGS

final NLL: -16.552
learned variance:    0.410
learned lengthscale: 1.692
learned noise_var:   0.0203

Convergence diagnostics

<Figure size 1210x374 with 2 Axes>

Posterior predictive at the learned hyperparameters

<Figure size 935x396 with 1 Axes>

Summary

  • MarkovGPPrior.log_marginal is end-to-end differentiable; any optimiser (L-BFGS, Adam, ...) trains the kernel hyperparameters.
  • Optimising in log-space sidesteps positivity constraints with no manual reparameterisation gymnastics.
  • The fitted hyperparameters give a sensible posterior mean and uncertainty band, and the model extrapolates to the prior beyond the training window — the standard stationary-GP behaviour.

For non-Gaussian likelihoods, plug a MarkovGPPrior into one of the strategies in the companion non-Gaussian Markov GP notebook; the same optimisation workflow applies, just with strategy.fit(...).log_marginal_approx as the loss.