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.

Non-Gaussian Markov GP inference — Laplace, Gauss–Newton, posterior linearisation and EP

Open In Colab

MarkovGPPrior gives linear-time inference for a GP over one axis, O(N d3)\mathcal{O}(N\,d^3) rather than O(N3)\mathcal{O}(N^3), through the Kalman filter and RTS smoother. That recursion needs a Gaussian likelihood. Many geoscience variables are not Gaussian: a day is wet or dry, a satellite counts plume detections, a sensor series has spikes. pyrox_ssm ships four strategies that keep the linear-time recursion for such likelihoods by replacing each non-Gaussian likelihood term with a Gaussian site.

This notebook explains how the four strategies differ, fits all four to three likelihoods (Bernoulli, Poisson and Student-t), compares their fits, convergence and cost, and ends with guidance on which strategy suits which kind of geoscience variable.

Setup

Detect Colab and install pyrox-gp[colab] (which pulls in matplotlib and watermark) and pyrox-ssm only when running there. The likelihoods come from pyrox_gp; the Markov prior and the strategies come from pyrox_ssm.

Python implementation: CPython
Python version       : 3.13.12
IPython version      : 9.13.0

jax       : 0.10.2
equinox   : 0.13.8
numpyro   : 0.21.0
pyrox     : 0.3.0
matplotlib: 3.10.9

Compiler    : Clang 21.1.4 
OS          : Linux
Release     : 6.8.0-1044-azure
Machine     : x86_64
Processor   : x86_64
CPU cores   : 16
Architecture: 64bit

1. One loop, four ways to refresh a site

Every strategy approximates the likelihood term of observation nn by a Gaussian site in the latent fn=f(tn)f_n = f(t_n),

tn(fn)∝exp⁡(λnfn−12Λnfn2)⇔N(y~n∣fn,  1/Λn),y~n=λn/Λn,t_n(f_n) \propto \exp\bigl(\lambda_n f_n - \tfrac12 \Lambda_n f_n^2\bigr) \quad \Leftrightarrow\quad \mathcal{N}\bigl(\tilde y_n \mid f_n,\; 1/\Lambda_n\bigr), \qquad \tilde y_n = \lambda_n / \Lambda_n,

so that the sites look like Gaussian pseudo-observations y~n\tilde y_n with noise variance 1/Λn1/\Lambda_n. One iteration then has two steps:

  1. run the Kalman filter and RTS smoother on the pseudo-observations, which gives the marginal posteriors q(fn)=N(mn,Vn)q(f_n) = \mathcal{N}(m_n, V_n) in O(N d3)\mathcal{O}(N\,d^3);

  2. refresh every site (λn,Λn)(\lambda_n, \Lambda_n) from the likelihood p(yn∣fn)p(y_n \mid f_n) and the current posterior.

The strategies differ only in step 2. Write gng_n and hnh_n for the first and second derivatives of log⁡p(yn∣fn)\log p(y_n \mid f_n) in fnf_n, and q∖n(fn)q_{\setminus n}(f_n) for the cavity, the posterior marginal with site nn divided out.

StrategySite refreshLiterature
LaplaceMarkovInferenceNewton step at the current mean: Λn=max⁡(−hn(mn),ϵ)\Lambda_n = \max(-h_n(m_n), \epsilon), λn=Λnmn+gn(mn)\lambda_n = \Lambda_n m_n + g_n(m_n), with floor ϵ=10−6\epsilon = 10^{-6}Nickisch, Solin & Grigorievskiy (2018); Rue, Martino & Chopin (2009)
GaussNewtonMarkovInferencethe same Newton step with a strict floor ϵ=10−3\epsilon = 10^{-3}, so every site keeps a usable precisionWilkinson, Särkkä & Solin (2023)
PosteriorLinearizationMarkovthe Newton step with gng_n and hnh_n averaged over the cavity, Eq∖n[gn]\mathbb{E}_{q_{\setminus n}}[g_n] and Eq∖n[hn]\mathbb{E}_{q_{\setminus n}}[h_n], by 20-point Gauss–Hermite quadratureGarcía-Fernández et al. (2015); Wilkinson, Särkkä & Solin (2023)
ExpectationPropagationMarkovmatch the mean and variance of the tilted distribution q∖n(fn) p(yn∣fn)q_{\setminus n}(f_n)\,p(y_n \mid f_n), then divide out the cavityMinka (2001); Wilkinson et al. (2020)

Laplace and Gauss–Newton look at the likelihood at one point, the current mean; posterior linearisation and EP look at it across the cavity’s spread, which costs a quadrature per site but sees curvature that a point evaluation misses. In pyrox, GaussNewtonMarkovInference is exactly LaplaceMarkovInference with the larger floor; the Gauss–Newton methods of Wilkinson, Särkkä & Solin (2023) reach the same goal, a positive site precision, by approximating the Hessian instead. Posterior linearisation and EP start damped (damping=0.5); Laplace and Gauss–Newton take full steps (damping=1.0) unless told otherwise.

2. Three likelihoods, three geoscience stand-ins

All three data sets share one irregular grid of N=80N = 80 times on [0,5][0, 5] and a known latent f(t)f(t), so every fit can be scored against the truth.

  • Bernoulli, logit link: occurrence data, such as whether a day is wet or dry at a rain gauge. yn∼Bernoulli(σ(f(tn)))y_n \sim \mathrm{Bernoulli}(\sigma(f(t_n))) with f(t)=1.5sin⁡2t+0.3cos⁡7tf(t) = 1.5 \sin 2t + 0.3 \cos 7t.

  • Poisson, log link: event counts, such as lightning flashes or fire detections per interval. yn∼Poisson(ef(tn))y_n \sim \mathrm{Poisson}(e^{f(t_n)}) with f(t)=1+1.2sin⁡1.5tf(t) = 1 + 1.2 \sin 1.5t.

  • Student-t: a smooth signal measured by a sensor that sometimes spikes, such as a retrieval contaminated by cloud. yn=sin⁡2tn+0.1 εny_n = \sin 2t_n + 0.1\,\varepsilon_n with 8 of the 80 values shifted by ±2.5\pm 2.5 to ±4\pm 4, fitted with a Student-t likelihood (ν=3\nu = 3, scale 0.1).

<Figure size 1400x340 with 3 Axes>

3. Fit all four strategies

The helper below fits each strategy and records whether it converged, how many filter-smoother iterations it used, its wall time, the RMSE of its posterior mean against the true latent, and its largest gap from the EP posterior mean. Each fit runs its iterations inside one optimistix fixed-point solve, and its wall time includes compiling that solve; read it as relative cost on this machine, not as a benchmark. Every fit also reports log_marginal_approx, but its meaning is strategy-specific, so the tables leave it out.

3.1 Bernoulli: occurrence

strategy         converged  iters  seconds    RMSE  max |m - m_EP|
Laplace               True      5      7.1   0.627          0.0603
Gauss-Newton          True      5      1.8   0.627          0.0603
Post. lin.            True     24      3.2   0.612          0.0013
EP                    True     24      2.7   0.612          0.0000
<Figure size 1300x380 with 2 Axes>

The Bernoulli likelihood is log-concave (hn<0h_n < 0 everywhere), so all four strategies converge. Laplace and Gauss–Newton give identical fits: the Bernoulli curvature σ(f)(1−σ(f))\sigma(f)(1 - \sigma(f)) stays far above both floors here, so the floors never act. Posterior linearisation and EP agree with each other closely, and both differ from Laplace by a few hundredths in the mean: Laplace centres each site on the mode of the likelihood at one point, while the other two average over the cavity. This is the pattern Kuss & Rasmussen (2005) report for GP classification, where EP’s posterior is closer to the MCMC reference than Laplace’s. Laplace pays for its bias with speed: it needs the fewest iterations and no quadrature. Past the dotted line (the last observation) every posterior relaxes to the prior mean of zero and the prior variance, because no observation constrains ff there.

3.2 Poisson: counts

strategy         converged  iters  seconds    RMSE  max |m - m_EP|
Laplace               True     10      2.3   0.179          0.0607
Gauss-Newton          True     10      1.9   0.179          0.0607
Post. lin.            True     34      1.7   0.203          0.0263
EP                    True     29      1.5   0.203          0.0000
<Figure size 1300x360 with 1 Axes>

The Poisson likelihood with a log link is also log-concave (hn=−efnh_n = -e^{f_n}), and the picture repeats: everything converges, Laplace and Gauss–Newton coincide, and posterior linearisation and EP sit together a few hundredths away from them. With counts this large the likelihood is close to Gaussian in ff, so the choice of strategy matters little; it matters more for sparse counts, where many zeros make the likelihood strongly skewed.

3.3 Student-t: readings with spikes

strategy         converged  iters  seconds    RMSE  max |m - m_EP|
Laplace               True     21      3.1   0.072          0.0208
Gauss-Newton          True     23      1.9   0.072          0.0208
Post. lin.           False     50      2.3   0.071          0.1671
EP                   False     50      1.6   0.070          0.0000
<Figure size 1300x380 with 1 Axes>

Here the strategies part ways. The Student-t log-likelihood is not log-concave: for a reading far from the current mean, hn>0h_n > 0. Laplace and Gauss–Newton then floor the site precision to ϵ\epsilon, so the site contributes its full gradient gng_n to λn=Λnmn+gn\lambda_n = \Lambda_n m_n + g_n with almost no curvature to balance it. On these readings they still converge with full steps, in 21 and 23 iterations, and their means track the true signal through the spikes. Posterior linearisation and EP average the curvature over the cavity and reach the same RMSE, but neither meets the tolerance within 50 iterations, and at that point their means still differ by up to 0.17.

The cell below gives posterior linearisation and EP 100 iterations.

strategy         converged  iters  seconds    RMSE  max |m - m_EP|
Post. lin., 100 iterations      True     94      1.5   0.071             nan
EP, 100 iterations      True     62      1.9   0.070             nan
<Figure size 1300x380 with 1 Axes>

With more iterations both converge, posterior linearisation in 94 and EP in 62, at the same RMSE as before. Robust regression with a Student-t likelihood is a known hard case for every approximation: Jylänki, Vanhatalo & Vehtari (2011) show that EP itself can fail to converge on it and needs damping or a double-loop scheme, which is why pyrox’s EP starts damped. If a Newton strategy oscillates on such data instead, lower its damping.

4. Convergence and cost

Every strategy costs one filter-smoother pass per iteration, O(I N d3)\mathcal{O}(I\,N\,d^3) for II iterations. Posterior linearisation and EP add a 20-node Gauss–Hermite quadrature per site, which is O(N)\mathcal{O}(N) and small next to the smoother for this dd. Iterations therefore drive the cost, and the iteration count depends on the likelihood and on the damping far more than on the strategy’s per-step work. At 80 points the wall time is dominated by compilation, so it does not follow the iteration counts.

<Figure size 1300x380 with 2 Axes>

On the log-concave cases Laplace and Gauss–Newton converge in the fewest iterations, because a full Newton step is the right step when the curvature is trustworthy; the damped posterior linearisation and EP take three to five times as many. On the Student-t case the undamped Newton strategies again converge first, in about 20 iterations, while posterior linearisation and EP need more than the default 50. Wall time stays between 1.5 and 7.1 s per fit and does not follow the iteration counts, because compilation dominates at this size.

5. Which strategy for which geoscience variable

The deciding property is whether the log-likelihood is concave in ff. If it is, every strategy converges and the choice trades speed (Laplace) against accuracy of the posterior moments (posterior linearisation, EP). If it is not, no strategy is guaranteed to converge, so check converged and be ready to raise max_iter or lower damping.

VariableLikelihoodLog-concave in ff?Suggested strategyLiterature
Precipitation occurrence (wet or dry day)Bernoulli, logit linkyesLaplace for speed; EP or posterior linearisation when the probabilities themselves matterStern & Coe (1984); Kuss & Rasmussen (2005)
Event counts: lightning flashes, fire detections, plume detections per overpassPoisson, log link (a log-Gaussian Cox process in time)yesLaplace, as in INLA; EP for sparse counts with many zerosMøller, Syversveen & Waagepetersen (1998); Rue, Martino & Chopin (2009)
Sensor or retrieval series with spikes (cloud contamination, instrument glitches)Student-tnoLaplace converged fastest here; EP with more iterations; check converged either wayJylänki, Vanhatalo & Vehtari (2011)
Any of the above with gaps (cloudy days, outages)any, with mask=—any; a masked site holds zero naturals and the filter skips it—

Where these strategies do well.

  • Long records: each iteration is linear in NN, so a decade of daily occurrence data or hourly counts is routine.

  • Gaps: every strategy’s fit takes mask=, so missing days need no imputation, and a masked fit equals the fit with those days removed.

  • Forecasts: predict extends past the last observation and relaxes to the prior, which is the honest answer for a stationary kernel.

What to look out for.

  1. Non-log-concave likelihoods. The Student-t case has sites with positive curvature, and no strategy is guaranteed to converge on it; here posterior linearisation and EP needed more than 50 iterations. Check converged, raise max_iter, and lower damping if a strategy oscillates.

  2. Laplace bias for binary data. Laplace’s posterior mean is shrunk relative to EP’s (Kuss & Rasmussen, 2005). If you threshold predicted probabilities, for example to forecast wet days, the difference shows up in calibration.

  3. Gauss–Newton is a floor in pyrox, not a different Hessian. On log-concave likelihoods it is identical to Laplace; its floor only changes sites whose curvature falls below 10-3.

  4. log_marginal_approx is not comparable across strategies. Each strategy reports its own quantity, so do not use it to choose between them; compare predictions instead.

  5. The latent must be scalar per time. All four strategies take a scalar-latent likelihood, one fnf_n per observation.

Summary

  • All four strategies run the same filter-smoother loop and differ only in how they refresh each Gaussian site: at one point (Laplace, Gauss–Newton) or averaged over the cavity (posterior linearisation, EP).

  • On log-concave likelihoods (Bernoulli, Poisson) all four converge; Laplace and Gauss–Newton need the fewest iterations, and posterior linearisation and EP agree closely with each other.

  • On the non-log-concave Student-t likelihood, undamped Laplace and Gauss–Newton converge in about 20 iterations, while posterior linearisation and EP need more than the default 50; all four track the signal through the spikes.

References.

  1. García-Fernández, Á. F., Svensson, L., Morelande, M. R. & Särkkä, S. (2015). Posterior linearization filter: principles and implementation using sigma points. IEEE Transactions on Signal Processing 63(20), 5561–5573.

  2. Jylänki, P., Vanhatalo, J. & Vehtari, A. (2011). Robust Gaussian process regression with a Student-t likelihood. JMLR 12, 3227–3257.

  3. Kuss, M. & Rasmussen, C. E. (2005). Assessing approximate inference for binary Gaussian process classification. JMLR 6, 1679–1704.

  4. Minka, T. P. (2001). Expectation propagation for approximate Bayesian inference. UAI.

  5. Møller, J., Syversveen, A. R. & Waagepetersen, R. P. (1998). Log Gaussian Cox processes. Scandinavian Journal of Statistics 25(3), 451–482.

  6. Nickisch, H., Solin, A. & Grigorievskiy, A. (2018). State space Gaussian processes with non-Gaussian likelihood. ICML, PMLR 80, 3789–3798.

  7. Rue, H., Martino, S. & Chopin, N. (2009). Approximate Bayesian inference for latent Gaussian models by using integrated nested Laplace approximations. JRSS B 71(2), 319–392.

  8. Stern, R. D. & Coe, R. (1984). A model fitting analysis of daily rainfall data. JRSS A 147(1), 1–34.

  9. Wilkinson, W. J., Chang, P. E., Andersen, M. R. & Solin, A. (2020). State space expectation propagation: efficient inference schemes for temporal Gaussian processes. ICML, PMLR 119, 10270–10281.

  10. Wilkinson, W. J., Särkkä, S. & Solin, A. (2023). Bayes-Newton methods for approximate Bayesian inference with PSD guarantees. JMLR 24(83).