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.

Markov Gaussian Processes — Matern Kernels in State-Space Form

Open In Colab

This notebook is the first installment of pyrox’s Markov-GP track. It introduces MaternSDE — the state-space representation of the Matern-ν\nu kernel for ν∈{1/2,3/2,5/2}\nu \in \{1/2, 3/2, 5/2\} — and verifies, end-to-end, that the SDE formulation and the dense kernel describe the same Gaussian process. Once a kernel is in state-space form, GP inference on a 1-D grid drops from O(N3)\mathcal{O}(N^3) Cholesky to O(N d3)\mathcal{O}(N\,d^3) Kalman filtering, where d∈{1,2,3}d \in \{1, 2, 3\} is the SDE state dimension.

Subsequent notebooks (issues #37 finish, #38) will compose SDE kernels, run Kalman / RTS smoothing, and expose MarkovGPPrior for NumPyro models. This one stays focused on the representation layer: math, identities, and visual sanity checks.

Background — from kernel to SDE

Any stationary GP kernel k(τ)k(\tau) on R\mathbb{R} whose spectral density is rational in ω2\omega^2 admits an exact, finite-dimensional state-space representation as a linear time-invariant SDE

dx(t)=F x(t) dt+L dw(t),f(t)=H x(t),d\mathbf{x}(t) = F\,\mathbf{x}(t)\,dt + L\,dw(t), \qquad f(t) = H\,\mathbf{x}(t),

with white-noise driver w(t)w(t) of spectral density QcQ_c and stationary state covariance P∞P_\infty solving the continuous Lyapunov equation

FP∞+P∞F⊤+LQcL⊤=0.F P_\infty + P_\infty F^\top + L Q_c L^\top = 0.

Discretising at non-uniform observation times t1<t2<⋯<tNt_1 < t_2 < \dots < t_N with Δtk=tk+1−tk\Delta t_k = t_{k+1} - t_k gives the discrete-time linear-Gaussian model

xk+1=Akxk+qk,qk∼N(0,Qk),fk=H xk,\mathbf{x}_{k+1} = A_k \mathbf{x}_k + \mathbf{q}_k, \qquad \mathbf{q}_k \sim \mathcal{N}(0, Q_k), \qquad f_k = H\,\mathbf{x}_k,

with Ak=exp⁡(F Δtk)A_k = \exp(F\,\Delta t_k) and Qk=P∞−AkP∞Ak⊤Q_k = P_\infty - A_k P_\infty A_k^\top. The recovered continuous autocovariance is k(τ)=Hexp⁡(Fτ)P∞H⊤k(\tau) = H \exp(F\tau) P_\infty H^\top for τ≥0\tau \geq 0, which we will verify against the dense Matern kernel below.

Matern-ν\nu companion form

For Matern-ν\nu with ν=p+1/2\nu = p + 1/2 and λ=2ν/ℓ\lambda = \sqrt{2\nu}/\ell, the state has dimension d=p+1d = p + 1 and FF is the companion matrix of (λ+s)d(\lambda + s)^d. Concretely:

Order ppν\nuddλ\lambdaClosed-form kernel
01/211/ℓ1/\ellσ2exp⁡(−r/ℓ)\sigma^2 \exp(-r/\ell)
13/223/ℓ\sqrt{3}/\ellσ2(1+3r/ℓ)exp⁡(−3r/ℓ)\sigma^2 (1 + \sqrt{3} r/\ell)\exp(-\sqrt{3} r/\ell)
25/235/ℓ\sqrt{5}/\ellσ2(1+5r/ℓ+5r2/(3ℓ2))exp⁡(−5r/ℓ)\sigma^2 (1 + \sqrt{5} r/\ell + 5 r^2/(3\ell^2))\exp(-\sqrt{5} r/\ell)

MaternSDE ships these three orders. Composition rules (sum / product), CosineSDE, PeriodicSDE, and the Kalman-based MarkovGPPrior follow in subsequent PRs.

Setup

Detect Colab and install pyrox-gp[colab] (which pulls in matplotlib and watermark) only when running there.

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.2.1
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. Inspecting the SDE parameters

A MaternSDE(variance, lengthscale, order) produces a closed-form (F,L,H,Qc,P∞)(F, L, H, Q_c, P_\infty) tuple via sde_params(). We instantiate one kernel per order and print the structural matrices alongside two structural identities:

  1. Variance recovery: HP∞H⊤=σ2H P_\infty H^\top = \sigma^2.

  2. Lyapunov closure: FP∞+P∞F⊤+LQcL⊤=0F P_\infty + P_\infty F^\top + L Q_c L^\top = 0.

--- Matern-1/2  (order p = 0, state dim d = 1) ---
F =
[[-2.]]
H = [1.],  L^T = [1.],  Q_c = 4.0000
P_inf =
[[1.]]
H P_inf H^T = 1.000000  (expected sigma^2 = 1.0)
||F P_inf + P_inf F^T + L Q_c L^T||_inf = 0.00e+00

--- Matern-3/2  (order p = 1, state dim d = 2) ---
F =
[[  0.           1.        ]
 [-12.          -6.92820323]]
H = [1. 0.],  L^T = [0. 1.],  Q_c = 166.2769
P_inf =
[[ 1.  0.]
 [ 0. 12.]]
H P_inf H^T = 1.000000  (expected sigma^2 = 1.0)
||F P_inf + P_inf F^T + L Q_c L^T||_inf = 0.00e+00

--- Matern-5/2  (order p = 2, state dim d = 3) ---
F =
[[  0.           1.           0.        ]
 [  0.           0.           1.        ]
 [-89.4427191  -60.         -13.41640786]]
H = [1. 0. 0.],  L^T = [0. 0. 1.],  Q_c = 9540.5567
P_inf =
[[  1.           0.          -6.66666667]
 [  0.           6.66666667   0.        ]
 [ -6.66666667   0.         400.        ]]
H P_inf H^T = 1.000000  (expected sigma^2 = 1.0)
||F P_inf + P_inf F^T + L Q_c L^T||_inf = 5.68e-14

Both invariants hold to machine precision in float64. The variance-recovery identity says the SDE state encodes the GP value plus d−1d-1 derivative-like coordinates; the Lyapunov identity says the stationary state covariance is consistent with the drift FF and the diffusion LQcL⊤L Q_c L^\top.

2. SDE autocovariance vs. dense Matern kernel

The continuous-time stationary autocovariance recovered from the SDE is

kSDE(τ)  =  H exp⁡(Fτ) P∞ H⊤,τ≥0.k_{\text{SDE}}(\tau) \;=\; H\,\exp(F \tau)\,P_\infty\,H^\top, \qquad \tau \geq 0.

This must equal the dense Matern Gram value at lag τ\tau. We compute both on a fine grid and overlay them.

<Figure size 1350x360 with 3 Axes>

All three orders agree to numerical precision. The SDE is not an approximation of the Matern kernel — for ν∈{1/2,3/2,5/2}\nu \in \{1/2, 3/2, 5/2\} it is an exact reformulation.

3. Discretisation: AkA_k and QkQ_k as functions of Δt\Delta t

Given a time step Δt\Delta t, the discrete-time transition is A(Δt)=exp⁡(F Δt)A(\Delta t) = \exp(F\,\Delta t) and the process-noise covariance is Q(Δt)=P∞−A(Δt)P∞A(Δt)⊤Q(\Delta t) = P_\infty - A(\Delta t) P_\infty A(\Delta t)^\top. Two endpoints are worth checking:

  • As Δt→0\Delta t \to 0, A→IA \to I and Q→0Q \to 0 (no time elapsed, no uncertainty added).

  • As Δt→∞\Delta t \to \infty, AP∞A⊤→0A P_\infty A^\top \to 0 (the dynamics decay back to the stationary distribution) and so Q→P∞Q \to P_\infty (the next state is independent of the previous one and has the stationary distribution).

We plot ∥A(Δt)∥2\|A(\Delta t)\|_2 and the trace of Q(Δt)Q(\Delta t) over a log-spaced range of step sizes.

<Figure size 1100x360 with 2 Axes>

Dotted horizontal lines mark tr P∞\mathrm{tr}\,P_\infty for each order — the asymptote QQ relaxes onto. Higher-order Materns relax slower (more oscillatory state coordinates carry inertia), but the limit is the same.

4. Sample paths via forward simulation of the discrete-time SDE

We can draw GP sample paths without ever forming a dense Gram matrix. The recipe is the standard linear-Gaussian forward simulation of the discrete state-space model:

  1. Sample x0∼N(0,P∞)\mathbf{x}_0 \sim \mathcal{N}(0, P_\infty).

  2. For k=0,1,…,N−1k = 0, 1, \dots, N-1: sample xk+1=Akxk+qk\mathbf{x}_{k+1} = A_k \mathbf{x}_k + \mathbf{q}_k with qk∼N(0,Qk)\mathbf{q}_k \sim \mathcal{N}(0, Q_k).

  3. Read out fk=H xkf_k = H\,\mathbf{x}_k.

All work is local in time; no N×NN \times N Cholesky. We compare paths drawn this way against paths drawn from the dense Matern Cholesky for the same time grid.

<Figure size 1200x750 with 6 Axes>

Each row pairs the same kernel order; the seeds differ across columns so the realisations are independent draws. Visually the rougher Matern-1/2 paths sit on top, the smoother Matern-5/2 paths at the bottom, with the SDE and dense columns indistinguishable in their statistical character. The variances and correlation lengths match by construction.

5. Empirical covariance of SDE samples matches the analytic kernel

A stronger check than visual matching: estimate the covariance C^ij=Cov[f(ti),f(tj)]\hat C_{ij} = \mathrm{Cov}[f(t_i), f(t_j)] from many SDE-simulated paths and compare to the closed-form Matern Gram on the same grid.

<Figure size 1350x400 with 3 Axes>

Solid lines are Monte-Carlo estimates from nmc=2000n_\text{mc} = 2000 forward simulations; dashed lines are the closed-form values. They overlap to the precision afforded by 2000 samples.

6. The kernel zoo — primitives and composition rules

Matern alone is enough to cover smooth time series, but real signals usually have more structure: a fixed offset, a carrier oscillation, an annual cycle, a quasi-periodic modulation. State-space form scales gracefully here too — every additional kernel is another small block in the state, not another factor of NN in inference cost.

This section walks through the four new primitive / composition kernels added on top of MaternSDE:

ClassMathState dim
ConstantSDE(σ²)k(τ)=σ2k(\tau) = \sigma^21
CosineSDE(σ², ω)k(τ)=σ2cos⁡(ω τ)k(\tau) = \sigma^2 \cos(\omega\,\tau)2
PeriodicSDE(σ², ℓ, T, J)MacKay periodic, Fourier-truncated to JJ harmonics1+2J1 + 2J
SumSDE((k₁, …))k(τ)=∑iki(τ)k(\tau) = \sum_i k_i(\tau)∑idi\sum_i d_i
ProductSDE(k₁, k₂)k(τ)=k1(τ) k2(τ)k(\tau) = k_1(\tau)\,k_2(\tau)d1⋅d2d_1 \cdot d_2
QuasiPeriodicSDE(matern, periodic)thin wrapper for ProductSDEdM(1+2J)d_M (1 + 2J)

SumSDE is block-diagonal in FF, LL, QcQ_c and P∞P_\infty, with the readouts HH concatenated. ProductSDE uses Kronecker-sum drift F=F1⊗I+I⊗F2F = F_1 \otimes I + I \otimes F_2 and Kronecker-product readout / stationary covariance H=H1⊗H2H = H_1 \otimes H_2, P∞=P∞,1⊗P∞,2P_\infty = P_{\infty,1} \otimes P_{\infty,2}. The diffusion is a sum of two Kronecker terms — see the ProductSDE docstring for the full formula.

6.1 Building blocks: ConstantSDE, CosineSDE, PeriodicSDE

We instantiate one of each, draw a few sample paths via the same forward-simulation recipe used for Matern in §4, and overlay the SDE autocovariance against a dense reference where one is available. PeriodicSDE uses n_harmonics = 7 — enough to match the MacKay periodic kernel to better than 1e-4 in the typical hyperparameter regime.

<Figure size 1300x780 with 6 Axes>
  • ConstantSDE paths are flat realisations: each draw is a single Gaussian random variable replicated across time. The autocovariance is the constant σ2\sigma^2.

  • CosineSDE paths are pure sinusoids with random amplitude and phase. The covariance oscillates exactly as σ2cos⁡(ωτ)\sigma^2 \cos(\omega\tau).

  • PeriodicSDE paths are smooth, period-aware, and not sinusoidal — they live in the function space of the MacKay periodic kernel. Truncating the Fourier expansion at J=7J=7 matches the dense kernel within plotting precision.

6.2 Composition: trend + offset via SumSDE

A common modelling pattern is “smooth trend on top of a fixed offset”. With dense kernels this is one line: RBF + Constant. In state-space form it’s exactly the same — just SumSDE. The block-diagonal construction keeps each component’s state space disjoint, so the cost is purely additive (∑idi\sum_i d_i).

SumSDE state dim: 3  (= 2 + 1)
<Figure size 1200x360 with 2 Axes>

Sample paths show the Matern wiggle riding on independently-drawn constant offsets — exactly the prior we wanted. The autocovariance recovers kMatern(τ)+σC2k_{\rm Matern}(\tau) + \sigma_C^2 to machine precision.

6.3 Composition: damped oscillation via ProductSDE

The product of a Matern and a Cosine is the subband Matern kernel — a stationary kernel whose spectral density is centred on a non-zero carrier ω0\omega_0. It’s the right prior for narrowband oscillatory signals (audio harmonics, geophysical resonances, modulated sensor traces). State dim is dM⋅dCd_M \cdot d_C — for Matern-3/2 × Cosine that’s 2⋅2=42 \cdot 2 = 4.

ProductSDE state dim: 4
<Figure size 1200x360 with 2 Axes>

The paths are oscillations whose envelope drifts on the Matern lengthscale — a damped carrier signal. The product autocovariance matches kM(τ)cos⁡(ω0τ)k_M(\tau) \cos(\omega_0 \tau) to numerical precision (the slight curvature of the envelope reflects the Matern factor).

6.4 Quasi-periodic kernels — modulated periodic structure

The classic “stellar” prior: a periodic signal whose amplitude drifts slowly over time. Mathematically it’s kMatern(τ)⋅kPeriodic(τ)k_{\rm Matern}(\tau) \cdot k_{\rm Periodic}(\tau) — a ProductSDE of two stationary kernels. QuasiPeriodicSDE is just a thin convenience wrapper that documents the standard recipe.

QuasiPeriodicSDE state dim: 24  (= 2 * (1 + 2*5))
<Figure size 1300x340 with 1 Axes>

Each draw shows a clear period of about 0.6 time units, but the amplitude drifts on a slow Matern timescale — short bursts of high-amplitude oscillation followed by quiescent stretches, exactly the prior class used for stellar light curves and modulated seasonal signals.

7. From the kernel zoo to geoscience signals

Section 6 showed that every class above is an exact state-space kernel. This section is about when to reach for each one. The useful question is rarely “which kernel is best” but three narrower ones: what does the variable’s power spectrum look like, along which axis (time, a transect, a spatial field) is the kernel defined, and how was the variable sampled. We read each class through its spectrum, map it to geophysical signals where the literature motivates that choice, and end with the successes and failures to look out for.

7.1 Every SDE kernel is a statement about a spectrum

A stationary SDE dx=F x dt+L dβ\mathrm{d}\mathbf{x} = F\,\mathbf{x}\,\mathrm{d}t + L\,\mathrm{d}\boldsymbol{\beta} with readout f=Hxf = H\mathbf{x} is a linear filter driven by white noise, so its output has the power spectral density

S(ω)=H (iωI−F)−1 L Qc L⊤ (iωI−F)−H H⊤,S(\omega) = H\,(i\omega I - F)^{-1}\,L\,Q_c\,L^\top\,(i\omega I - F)^{-\mathsf{H}}\,H^\top,

and the Wiener–Khinchin theorem returns the kernel as k(τ)=12π∫S(ω) eiωτ dωk(\tau) = \frac{1}{2\pi}\int S(\omega)\,e^{i\omega\tau}\,\mathrm{d}\omega (Särkkä & Solin, 2019). Three facts follow, and they are most of what you need to choose a kernel.

  • Matern sets a knee and a slope. For Matern-ν\nu, S(ω)∝(λ2+ω2)−(ν+1/2)S(\omega) \propto (\lambda^2 + \omega^2)^{-(\nu + 1/2)} with λ=2ν/ℓ\lambda = \sqrt{2\nu}/\ell. The spectrum is flat below the knee ω≈λ\omega \approx \lambda and falls as ω−(2ν+1)\omega^{-(2\nu+1)} above it: slopes of -2, -4 and -6 for orders p=0,1,2p = 0, 1, 2. The lengthscale places the knee; the order sets how fast high-frequency variance dies, which is the same thing as how many derivatives the paths have.

  • Sums add spectra. SumSDE puts each component’s variance in its own band, which is why decompositions such as trend + seasonal cycle + anomaly are natural in this form.

  • Products move spectra. Multiplying a kernel by cos⁡(ω0τ)\cos(\omega_0\tau) convolves its spectrum with lines at ±ω0\pm\omega_0, so ProductSDE(MaternSDE, CosineSDE) is a band centred on ω0\omega_0 whose width is set by the Matern knee λ\lambda. QuasiPeriodicSDE places one such band at every harmonic jω0j\omega_0. CosineSDE, PeriodicSDE and ConstantSDE on their own carry no diffusion (Qc=0Q_c = 0): all their variance sits on exact lines at ω0\omega_0, at jω0j\omega_0, or at ω=0\omega = 0.

The helper below evaluates S(ω)S(\omega) from sde_params() directly and checks two of these facts numerically: that 12π∫S dω\frac{1}{2\pi}\int S\,\mathrm{d}\omega recovers the Matern variance, and that the spectrum of a SumSDE equals the sum of its components’ spectra.

Matern-1/2: (1/2pi) * integral of S = 0.9994  (variance = 1.0)
Matern-3/2: (1/2pi) * integral of S = 1.0000  (variance = 1.0)
Matern-5/2: (1/2pi) * integral of S = 1.0000  (variance = 1.0)

The Matern-1/2 integral comes out slightly low only because its ω−2\omega^{-2} tail extends past the finite grid; the smoother orders converge to the variance.

The left panel below shows the knee-and-slope picture for the three Matern orders. The right panel is a schematic spectrum assembled from blocks, each placed in the band where the literature in §7.2 uses it: a red-noise anomaly, a seasonal cycle with drifting amplitude, an intraseasonal 40–50 day band and four tidal lines. It is not one real variable (sea level, winds and sea-surface temperature are mixed for illustration), and the variances are chosen for display. Frequencies are in cycles per day, ω/2π\omega / 2\pi.

SumSDE state dim: 25;  max rel |S_sum - sum of parts| = 4.8e-16
<Figure size 1300x440 with 2 Axes>

Reading the right panel from low to high frequency: the red-noise block is flat at periods longer than its 30-day memory and falls as ω−2\omega^{-2} beyond it; the seasonal block puts narrow peaks at one cycle per year and its harmonics, broadened only slightly because its amplitude envelope drifts over five years, plus a hump at periods longer than about five years from the periodic kernel’s constant (j=0j = 0) term riding on the same envelope; the intraseasonal block is a single hump around 1/45 cycles per day; the tides are exact lines because their frequencies are fixed by astronomy. The SumSDE curve is the sum of the dashed ones to round-off, as printed above.

7.2 Which class for which signal

ClassSpectrumReach for it whenGeoscience exampleLiterature
MaternSDE, order 0 (Ornstein–Uhlenbeck)flat, then ω−2\omega^{-2}the signal is rough and mean-reverting with one memory time ℓ\ellSST anomalies integrating weather noise; the red-noise null hypothesis for climate spectraHasselmann (1976); Frankignoul & Hasselmann (1977)
MaternSDE, orders 1 and 2flat, then ω−4\omega^{-4} or ω−6\omega^{-6}the paths should be once or twice differentiable; the default for smooth physical fieldsa slowly varying trend; interpolating a smooth state between sparse observationsStein (1999); Rasmussen & Williams (2006)
ConstantSDEall variance at ω=0\omega = 0a level that is unknown but fixed over the recorda station, instrument or retrieval offset—
SumSDE of CosineSDEslines at known ωk\omega_kthe frequencies are fixed by physics and only amplitude and phase are unknowntidal constituents M2, S2, K1, O1 in a tide-gauge or altimetry recordPawlowicz et al. (2002)
PeriodicSDElines at jω0j\omega_0a cycle repeats with a fixed, non-sinusoidal shapea climatological diurnal or seasonal cycleSolin & Särkkä (2014)
QuasiPeriodicSDEbands at jω0j\omega_0the cycle repeats but its amplitude and shape driftthe seasonal cycle of atmospheric CO₂ at Mauna LoaRasmussen & Williams (2006, §5.4.3)
ProductSDE(MaternSDE, CosineSDE)one band at ω0\omega_0, width ∼λ\sim\lambdavariability is concentrated in one band around a single frequency, with a phase that wandersthe 40–50 day Madden–Julian oscillation in tropical windsMadden & Julian (1971); Foreman-Mackey et al. (2017)
SumSDE of the abovethe sumyou want the posterior of each component, not only of the totaltrend + seasonal + anomaly + noise decompositionsRasmussen & Williams (2006, §5.4.3)

Two of these deserve a sentence each. Hasselmann’s stochastic climate model treats a slow component (ocean temperature) as integrating fast weather forcing against a restoring feedback, which is exactly the Ornstein–Uhlenbeck SDE, so Matern-1/2 is the physically motivated null model for a mixed-layer anomaly rather than an arbitrary choice. The Mauna Loa CO₂ model in Rasmussen & Williams is a dense-GP sum of a long-term smooth trend, a periodic-times-decay seasonal term, medium-term irregularities and noise; in state-space form the same decomposition is SumSDE((MaternSDE(..., order=2), QuasiPeriodicSDE(...), MaternSDE(..., order=1))) plus a Gaussian likelihood, at linear cost in the record length. Their squared-exponential and rational-quadratic terms have no finite-dimensional SDE, which is why Matern blocks stand in for them here. Foreman-Mackey et al. reach the same band-limited class from the other direction: their celerite kernels are mixtures of stochastically driven damped harmonic oscillators, the stellar-variability analogue of the Matern × Cosine block.

7.3 Time, space and the axis a kernel lives on

Every kernel in this notebook is defined on one axis. That axis is usually time, and time is where the state-space form is strongest: it is causal, and irregular time stamps are handled exactly, because discretise_sequence takes each Δtk\Delta t_k separately. Satellite overpasses with cloud gaps, or a buoy that drops out for a month, need no gridding or interpolation.

A one-dimensional spatial coordinate works the same way: distance along an altimeter ground track, an aircraft or ship transect, or altitude in a vertical profile. The Markov property then runs along the transect; the filter has a direction, but the smoother uses both sides, so the posterior does not.

For a field over 2-D or 3-D space and time there are two standard routes. The first keeps the SDE in time and puts a spatial kernel across locations, k((s,t),(s′,t′))=ks(s,s′) kt(t,t′)k\big((\mathbf{s}, t), (\mathbf{s}', t')\big) = k_s(\mathbf{s}, \mathbf{s}')\,k_t(t, t'), so the Kalman state holds the whole spatial field at each time step (Särkkä, Solin & Hartikainen, 2013; Hamelijnck et al., 2021). The second writes a spatial Matern field as the solution of a stochastic PDE and discretises it into a sparse Gaussian Markov random field (Lindgren, Rue & Lindström, 2011); in pyrox that route belongs to pyrox_lgm. The limitation of the first route is separability: a product kernel cannot represent a signal that propagates, such as the annual-period westward Rossby waves that Schlax & Chelton (1994) found in North Atlantic altimetry. Propagating signals need a non-separable space-time covariance (Gneiting, 2002).

7.4 Successes and failures to look out for

Where these kernels do well.

  • Long, irregularly sampled records: the cost is O(N d3)\mathcal{O}(N\,d^3), decades of hourly data are routine, and gaps cost nothing.

  • Decompositions: with a SumSDE, the smoother returns the posterior of each block (trend, season, anomaly) separately, so the components are interpretable without fitting them one after another.

  • Known frequencies: when physics fixes ωk\omega_k, as for tides, a CosineSDE block constrains the signal far more tightly than any flexible kernel could.

What to look out for.

  1. Smoothness mismatch. The squared-exponential (RBF) kernel has no finite-dimensional SDE and only an approximate state-space form (Hartikainen & Särkkä, 2010); Stein (1999) argues it is too smooth for most physical processes anyway. Matern is available only for ν∈{1/2,3/2,5/2}\nu \in \{1/2, 3/2, 5/2\}, so check the observed spectral slope before choosing the order: an inertial-range turbulent signal, whose spectrum falls as ω−5/3\omega^{-5/3} (Kolmogorov, 1941), is rougher than even Matern-1/2.

  2. Variance and lengthscale trade off. Under denser sampling of a fixed record, the variance and lengthscale of a Matern kernel cannot both be estimated consistently; only a combination of them can (Zhang, 2004). A short record constrains the slow components poorly, so put priors on ℓ\ell and interpret the fitted variance together with it.

  3. Aliasing. A signal sampled less often than twice per period appears at a false, lower frequency. A CosineSDE at the true frequency still fits aliased data correctly, because it is evaluated at the true time stamps; a flexible kernel that lets the data choose the frequency will fit the alias instead. The figure below shows the classic case.

  4. A strictly periodic kernel where the cycle drifts. PeriodicSDE on its own has no diffusion: once its amplitude and phase are drawn, the cycle repeats exactly, so a cycle whose length or phase wanders lies outside its prior. Multiplying by a Matérn envelope removes that constraint: in both QuasiPeriodicSDE and Matern × CosineSDE the envelope broadens the spectral lines and lets phase coherence decay over the envelope’s lengthscale (each nonzero harmonic of QuasiPeriodicSDE is itself a Matern × Cosine band). Choose between the two by harmonic content. QuasiPeriodicSDE keeps the periodic kernel’s harmonics, for a non-sinusoidal cycle such as a seasonal cycle with a sharp peak; Matern × CosineSDE is a single band, for a near-sinusoidal oscillation such as the Madden–Julian oscillation.

  5. State dimension. Sharp cycle features need more harmonics JJ (Solin & Särkkä, 2014), and a product multiplies state dimensions: Matern-5/2 × PeriodicSDE with J=10J = 10 has d=3×21=63d = 3 \times 21 = 63, so each filter step costs about 633.

  6. Non-stationary or non-Gaussian variables. All these kernels are stationary. A trend whose rate changes needs a long-lengthscale Matern trend block, not a stationary anomaly kernel. Precipitation, counts and positive concentrations need a non-Gaussian likelihood on a latent Markov GP, which the non-Gaussian Markov notebook covers.

M2: true period 12.4206 h  ->  alias period   62.1 d
S2: true period 12.0000 h  ->  alias period   58.7 d
K1: true period 23.9345 h  ->  alias period  173.2 d
O1: true period 25.8193 h  ->  alias period   45.7 d
<Figure size 1300x340 with 1 Axes>

Every sample lies on the slow curve, so from the samples alone a 62-day oscillation and a 12.42-hour tide are indistinguishable. All the aliases printed above except K1’s are shorter than 90 days, as Schlax & Chelton (1994) show for this orbit, so they sit in the same band as real intraseasonal ocean variability. The defence is the one in item 3: put the tide in the model as CosineSDE blocks at the astronomical frequencies and evaluate them at the true observation times.

What this PR ships and what comes next

PR 1 (issue #37 partial, #112 — already merged). The SDEKernel protocol and the MaternSDE family for ν∈{1/2,3/2,5/2}\nu \in \{1/2, 3/2, 5/2\}.

This PR (issue #37 finish). The kernel zoo on top of MaternSDE:

  • Primitives: ConstantSDE, CosineSDE (closed-form rotation discretise), PeriodicSDE (Solin & Sarkka 2014, Fourier-truncated MacKay periodic kernel via a stable log-space Bessel helper).

  • Composition rules: SumSDE (block-diagonal) and ProductSDE (Kronecker-sum drift, Kronecker-product readout / stationary covariance, with the diffusion matrix derived from the Lyapunov identity).

  • Convenience: QuasiPeriodicSDE as a documented ProductSDE(MaternSDE, PeriodicSDE).

Next up — issue #38. MarkovGPPrior plus the Kalman filter / RTS smoother. Once that lands, every kernel above can be plugged directly into a NumPyro model with linear-time temporal inference: f = numpyro.sample("f", MarkovGPPrior(QuasiPeriodicSDE(...), times)).

References.

  1. Sarkka, S. & Solin, A. (2019). Applied Stochastic Differential Equations. Cambridge University Press, Ch. 12.

  2. Hartikainen, J. & Sarkka, S. (2010). Kalman Filtering and Smoothing Solutions to Temporal Gaussian Process Regression Models. IEEE MLSP.

  3. Solin, A. & Sarkka, S. (2014). Explicit Link Between Periodic Covariance Functions and State Space Models. AISTATS.

  4. Wilkinson, W. J., Sarkka, S. & Solin, A. (2023). Bayes-Newton Methods for Approximate Bayesian Inference with PSD Guarantees. JMLR 24(83).

  5. Hasselmann, K. (1976). Stochastic climate models. Part I. Theory. Tellus 28(6), 473–485.

  6. Frankignoul, C. & Hasselmann, K. (1977). Stochastic climate models. Part II. Application to sea-surface temperature anomalies and thermocline variability. Tellus 29(4), 289–305.

  7. Stein, M. L. (1999). Interpolation of Spatial Data: Some Theory for Kriging. Springer.

  8. Rasmussen, C. E. & Williams, C. K. I. (2006). Gaussian Processes for Machine Learning. MIT Press, §5.4.3.

  9. Pawlowicz, R., Beardsley, B. & Lentz, S. (2002). Classical tidal harmonic analysis including error estimates in MATLAB using T_TIDE. Computers & Geosciences 28(8), 929–937.

  10. Madden, R. A. & Julian, P. R. (1971). Detection of a 40–50 day oscillation in the zonal wind in the tropical Pacific. Journal of the Atmospheric Sciences 28, 702–708.

  11. Foreman-Mackey, D., Agol, E., Ambikasaran, S. & Angus, R. (2017). Fast and scalable Gaussian process modeling with applications to astronomical time series. The Astronomical Journal 154, 220.

  12. Särkkä, S., Solin, A. & Hartikainen, J. (2013). Spatiotemporal learning via infinite-dimensional Bayesian filtering and smoothing. IEEE Signal Processing Magazine 30(4), 51–61.

  13. Hamelijnck, O., Wilkinson, W. J., Loppi, N., Solin, A. & Damoulas, T. (2021). Spatio-temporal variational Gaussian processes. NeurIPS 34.

  14. Lindgren, F., Rue, H. & Lindström, J. (2011). An explicit link between Gaussian fields and Gaussian Markov random fields: the stochastic partial differential equation approach. JRSS B 73(4), 423–498.

  15. Schlax, M. G. & Chelton, D. B. (1994). Aliased tidal errors in TOPEX/POSEIDON sea surface height data. Journal of Geophysical Research 99(C12). doi:10.1029/94JC01925.

  16. Gneiting, T. (2002). Nonseparable, stationary covariance functions for space–time data. JASA 97(458), 590–600.

  17. Kolmogorov, A. N. (1941). The local structure of turbulence in incompressible viscous fluid for very large Reynolds numbers. Doklady Akademii Nauk SSSR 30, 301–305.

  18. Zhang, H. (2004). Inconsistent estimation and asymptotically equal interpolations in model-based geostatistics. JASA 99(465), 250–261.