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.

Ensembles: a tracer channel with an ensemble Kalman likelihood, and an ensemble of variational fits

Open In Colab

In Examples 1 to 4 the state was small, a few values per station, so the Kalman filter carried its full covariance and integrated the path out. Here the state is a gridded field: the anomaly of a tracer in every cell of a channel, moved along by a transport model. On a real grid of thousands of cells the Dx×DxD_x \times D_x covariance of a Kalman filter cannot be stored, let alone propagated. An ensemble Kalman filter carries NExN_{\mathcal{E}_x} copies of the state instead and runs the transport model on each. Its innovations give an estimate of the log likelihood, which we add to a NumPyro model as a factor. In Example 5a we infer the advection speed and the diffusivity of the channel from that factor with NUTS. We keep the channel small and the dynamics linear on purpose, so that the exact Kalman log likelihood still exists and we can measure what the ensemble costs us in bias. In Example 5b we run a different kind of ensemble on the same model, the ensemble of variational fits of pyrox.inference.ensemble_vi. Its members mean something else.

pyrox-ssm capability shown: pyrox_ssm.ensemble.ensemble_factor (behind the [ensemble] extra), which runs filterax.differentiable_assimilate with a deterministic square-root filter (filterax.filters.ETKF here) from an initial ensemble passed in as data. It adds the sum of the per-step log likelihoods as a NumPyro factor and returns the filterax AssimilationResult, whose analysis ensembles give us the filtered field. For 5b, pyrox.inference.ensemble_vi from the core package. Cost: every log-density evaluation is one assimilation run. Per step that is NExN_{\mathcal{E}_x} runs of the transport model plus an analysis in the space of the members, O(NEx2(Dx+Dy)+NEx3)\mathcal{O}(N_{\mathcal{E}_x}^2 (D_x + D_y) + N_{\mathcal{E}_x}^3), against O(Dx3)\mathcal{O}(D_x^3) for the Kalman filter. The gradient adds a backward pass that recomputes the forecasts (filterax’s RecursiveCheckpointAdjoint, the default). We time one gradient at three ensemble sizes and for the Kalman filter in section 6.

What you’ll learn:

  1. How to write a transport model as a filterax dynamics module and infer its parameters with ensemble_factor in a plain NumPyro model, with the initial ensemble drawn once outside the model.

  2. How the NUTS posterior compares with the truth, and how to get the filtered field with bands from the analysis members.

  3. How large the bias of the ensemble log likelihood is at 16, 32 and 128 members, against the exact Kalman filter, and what each costs per gradient.

  4. What ensemble_vi puts in its ensemble (fits from different starts), and when that helps.

The NUTS workflow and the posterior predictive over draws are explained in Example 1, and the Kalman recursions in Kalman filtering and RTS smoothing. We reuse them here without deriving them again.

Background

The physical symbols of this page are below. Everything else follows the notation of the earlier examples, with the state x\mathbf{x}, the observations y\mathbf{y} and the parameters θ\boldsymbol{\theta}.

SymbolMeaningShape, units
x(s,t)x(s, t)tracer anomaly (concentration minus its background)R\mathbb{R}, tracer units
ssposition along the channel[0,L)[0, L), km
uuadvection speedR\mathbb{R}, km h⁻¹
KKeddy diffusivityR>0\mathbb{R}_{>0}, km² h⁻¹
κ\kappawavenumberWs,x\mathcal{W}_{s,x}, rad km⁻¹

The tracer anomaly lives on a periodic channel of length L=64L = 64 km. It is carried along at the speed uu and spread by the diffusivity KK,

∂x∂t=−u∂x∂s+K∂2x∂s2\frac{\partial x}{\partial t} = -u \frac{\partial x}{\partial s} + K \frac{\partial^2 x}{\partial s^2}

We split the channel into Dx=NΩx=64D_x = N_{\Omega_x} = 64 cells of 1 km, so the state xk∈RDx\mathbf{x}_k \in \mathbb{R}^{D_x} is the field in every cell at the time tk=kt_k = k hours, k=1,…,Tk = 1, \ldots, T, with T=16T = 16 and t0=0t_0 = 0. On a periodic grid each Fourier mode evolves on its own, so we can step the equation exactly. With x^(κ,t)\hat{x}(\kappa, t) the discrete Fourier transform of the field at the wavenumber κ∈Ws,x\kappa \in \mathcal{W}_{s,x} (the DxD_x wavenumbers 2πn/L2 \pi n / L that the grid resolves) and i\mathrm{i} the imaginary unit,

x^(κ,tk)=exp⁡((−iuκ−Kκ2)(tk−tk−1))x^(κ,tk−1)\hat{x}(\kappa, t_k) = \exp((-\mathrm{i} u \kappa - K \kappa^2)(t_k - t_{k-1})) \hat{x}(\kappa, t_{k-1})

This is the dynamics xk=f(xk−1;θ)\mathbf{x}_k = f(\mathbf{x}_{k-1}; \boldsymbol{\theta}), with the parameters θ=(u,K)∈R2\boldsymbol{\theta} = (u, K) \in \mathbb{R}^{2}. It has no model noise. It is also linear, f(x;θ)=F(θ)xf(\mathbf{x}; \boldsymbol{\theta}) = \mathbf{F}(\boldsymbol{\theta}) \mathbf{x} with F(θ)∈RDx×Dx\mathbf{F}(\boldsymbol{\theta}) \in \mathbb{R}^{D_x \times D_x}, which a real transport model would not be. We keep it linear so that the exact Kalman log likelihood is there as a reference. The initial field is a draw from a stationary Gaussian, and Dy=NΩy=8D_y = N_{\Omega_y} = 8 sensors, one every 8 km, measure the field with noise every hour,

x0∼N(0,Σx,0)\mathbf{x}_0 \sim \mathcal{N}(\mathbf{0}, \boldsymbol{\Sigma}_{x,0})
yk=Hxk+εk\mathbf{y}_k = \mathbf{H} \mathbf{x}_k + \boldsymbol{\varepsilon}_k
εk∼N(0,Σε)\boldsymbol{\varepsilon}_k \sim \mathcal{N}(\mathbf{0}, \boldsymbol{\Sigma}_\varepsilon)

where Σx,0∈RDx×Dx\boldsymbol{\Sigma}_{x,0} \in \mathbb{R}^{D_x \times D_x} has unit variance and a Gaussian spectrum with a 4 km lengthscale, H∈{0,1}Dy×Dx\mathbf{H} \in \{0, 1\}^{D_y \times D_x} picks the sensor cells, so the observation operator is h(x)=Hxh(\mathbf{x}) = \mathbf{H} \mathbf{x}, and Σε=σε2IDy\boldsymbol{\Sigma}_\varepsilon = \sigma_\varepsilon^2 \mathbf{I}_{D_y} with σε=0.1\sigma_\varepsilon = 0.1.

The ensemble Kalman log likelihood. The ETKF (ensemble transform Kalman filter) carries NExN_{\mathcal{E}_x} members xk∣k(e)∈RDx\mathbf{x}_{k \mid k}^{(e)} \in \mathbb{R}^{D_x}, e∈Exe \in \mathcal{E}_x, in place of a mean and a covariance. It starts from the initial ensemble X0∈RNEx×Dx\mathbf{X}_0 \in \mathbb{R}^{N_{\mathcal{E}_x} \times D_x}, whose rows x0∣0(e)∼N(0,Σx,0)\mathbf{x}_{0 \mid 0}^{(e)} \sim \mathcal{N}(\mathbf{0}, \boldsymbol{\Sigma}_{x,0}) we draw once. At every step it runs the transport model on each member, xk∣k−1(e)=f(xk−1∣k−1(e);θ)\mathbf{x}_{k \mid k-1}^{(e)} = f(\mathbf{x}_{k-1 \mid k-1}^{(e)}; \boldsymbol{\theta}), and scores yk\mathbf{y}_k under the Gaussian that the forecast members imply,

log⁡p(y1:T∣θ)≈∑k=1Tlog⁡N(yk;hˉk,H~kH~k⊤+Σε)\log p(\mathbf{y}_{1:T} \mid \boldsymbol{\theta}) \approx \sum_{k=1}^{T} \log \mathcal{N}(\mathbf{y}_k; \bar{\mathbf{h}}_k, \tilde{\mathbf{H}}_k \tilde{\mathbf{H}}_k^\top + \boldsymbol{\Sigma}_\varepsilon)
hˉk=1NEx∑e∈Exh(xk∣k−1(e))\bar{\mathbf{h}}_k = \frac{1}{N_{\mathcal{E}_x}} \sum_{e \in \mathcal{E}_x} h(\mathbf{x}_{k \mid k-1}^{(e)})

where column ee of H~k∈RDy×NEx\tilde{\mathbf{H}}_k \in \mathbb{R}^{D_y \times N_{\mathcal{E}_x}} is the anomaly (h(xk∣k−1(e))−hˉk)/NEx−1(h(\mathbf{x}_{k \mid k-1}^{(e)}) - \bar{\mathbf{h}}_k) / \sqrt{N_{\mathcal{E}_x} - 1}. Then a square-root analysis moves the members to xk∣k(e)\mathbf{x}_{k \mid k}^{(e)} without drawing random numbers. The Kalman filter computes the same sum exactly, with Hμx,k∣k−1\mathbf{H} \boldsymbol{\mu}_{x,k \mid k-1} and HΣx,k∣k−1H⊤+Σε\mathbf{H} \boldsymbol{\Sigma}_{x,k \mid k-1} \mathbf{H}^\top + \boldsymbol{\Sigma}_\varepsilon in place of hˉk\bar{\mathbf{h}}_k and H~kH~k⊤+Σε\tilde{\mathbf{H}}_k \tilde{\mathbf{H}}_k^\top + \boldsymbol{\Sigma}_\varepsilon, where μx,k∣k−1∈RDx\boldsymbol{\mu}_{x,k \mid k-1} \in \mathbb{R}^{D_x} and Σx,k∣k−1∈RDx×Dx\boldsymbol{\Sigma}_{x,k \mid k-1} \in \mathbb{R}^{D_x \times D_x} are the forecast mean and covariance.

Two properties decide how we can use this in NUTS or SVI. First, X0\mathbf{X}_0 is data and the filter draws no random numbers. So the log likelihood is a deterministic and smooth function of θ\boldsymbol{\theta}, as every evaluation sees the same members (common random numbers). Second, it is biased, not exact. The mean and covariance of the members are Monte Carlo estimates from NExN_{\mathcal{E}_x} draws, and the covariance has rank at most NEx−1N_{\mathcal{E}_x} - 1. The bias shrinks as NExN_{\mathcal{E}_x} grows. For linear-Gaussian dynamics like ours the log likelihood converges to the Kalman log marginal of lgssm_factor, and that is the check we run in section 6.

Setup

We detect Colab and install pyrox, pyrox-gp[colab] (which pulls in matplotlib and watermark) and pyrox-ssm[ensemble] (which pulls in filterax) only when the notebook runs 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
filterax  : 0.0.8
gaussx    : 0.6.15
pyrox     : 0.2.1
pyrox_ssm : 0.1.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. A tracer moved along a periodic channel

We simulate one record from the model, so that we know the truth: an advection speed u=2u = 2 km h⁻¹ and a diffusivity K=0.3K = 0.3 km² h⁻¹. Over the 16 hours the field moves 32 km, so every feature passes four sensors. The AdvectionDiffusion module below is the exact Fourier step of the Background section, written as a filterax.AbstractDynamics whose fields are θ\boldsymbol{\theta}, and observe is hh. We draw x0\mathbf{x}_0 by colouring white noise with the square root of the spectrum, through the FFT.

D_x = 64 cells, D_y = 8 sensors, T = 16 hours, 128 observations
the tracer moves 32 km over the record
<Figure size 1300x450 with 3 Axes>

The left panel shows the true field as a space-time (Hovmöller) diagram, with the sensor cells dotted. The bands of positive and negative anomaly slope to the right at the advection speed. The right panel shows four of the eight sensor records, where a feature seen at one sensor turns up at the next one about 4 hours later (8 km at 2 km h⁻¹).

2. The model as a plain NumPyro function

We draw the initial ensemble of NEx=32N_{\mathcal{E}_x} = 32 members here, once, outside the model, and pass it in as data. Drawing it inside the model would give every evaluation of the log density new random numbers, so NUTS would see a noisy log density. A wind measurement puts the advection speed near 1.5 km h⁻¹, give or take 1 km h⁻¹, so we take u∼N(1.5,12)u \sim \mathcal{N}(1.5, 1^2), and the diffusivity gets K∼LogNormal(log⁡0.5,1)K \sim \mathrm{LogNormal}(\log 0.5, 1). Then ensemble_factor takes the filter, the dynamics built from the two sample sites, hh, X0\mathbf{X}_0, the record, the observation times and Σε\boldsymbol{\Sigma}_\varepsilon, and registers the factor "y".

site 'speed'        Normal     value shape=()
site 'diffusivity'  LogNormal  value shape=()
site 'y'            factor     value shape=(0,)

So the trace holds two scalar sample sites and one factor, as in Example 1. However, here the factor is an estimate: the 64-cell field is carried by the 32 members inside the filter, and NUTS never sees it.

3. NUTS

We run two chains of 200 draws after 100 warm-up steps with a dense mass matrix. Both chains start at the prior medians (init_to_median). The log likelihood in uu has a second local mode near u=−0.6u = -0.6 km h⁻¹, and section 7 shows fits from random starts (NumPyro’s default) ending there. Each leapfrog step is one assimilation run and its gradient. The wall-clock time includes JIT compilation.


                   mean       std    median      5.0%     95.0%     n_eff     r_hat
  diffusivity      0.31      0.06      0.30      0.21      0.40    346.39      1.00
        speed      1.97      0.02      1.97      1.94      1.99    304.32      1.00

Number of divergences: 0
NUTS wall-clock: 52.5 s for 2 chains x 300 iterations, 0 divergences
leapfrog steps after warm-up: 1428, 3.6 per draw

4. The transport parameters against the truth

parameter      truth         mean ± sd          90% interval
speed           2.00    1.966 ± 0.018   [ 1.937,  1.996] out
diffusivity     0.30    0.306 ± 0.061   [ 0.216,  0.414]  in
<Figure size 550x450 with 1 Axes>

Both chains agree (R^=1.00\hat{R} = 1.00), with no divergences and 3.6 leapfrog steps per draw. The diffusivity’s 90 % interval, [0.216, 0.414] km² h⁻¹, contains the true 0.3. The speed is pinned down far more tightly, at 1.966 ± 0.018 km h⁻¹, and its 90 % interval [1.937, 1.996] stops just short of the true 2.0. Section 6 shows that this miss is not the ensemble’s doing: the exact Kalman posterior puts the speed at 1.970 ± 0.018 km h⁻¹ as well, so it belongs to this realisation of the record.

5. The filtered field

The AssimilationResult that ensemble_factor returns holds the analysis members xk∣k(e)\mathbf{x}_{k \mid k}^{(e)} at every step (analysis_history, shaped (T,NEx,Dx)(T, N_{\mathcal{E}_x}, D_x)). So for one θ\boldsymbol{\theta} the filtered field is their mean xˉk∣k(θ)∈RDx\bar{\mathbf{x}}_{k \mid k}(\boldsymbol{\theta}) \in \mathbb{R}^{D_x}, and its uncertainty is their variance (with 1/(NEx−1)1 / (N_{\mathcal{E}_x} - 1), as in the filter). We run the filter at NEθ=50N_{\mathcal{E}_\theta} = 50 NUTS draws, the set Eθ\mathcal{E}_\theta, with jax.vmap, and combine them as in Example 1, so the bands carry the uncertainty of θ\boldsymbol{\theta} too,

E[xk∣y1:k]≈1NEθ∑θ∈Eθxˉk∣k(θ)\mathbb{E}[\mathbf{x}_k \mid \mathbf{y}_{1:k}] \approx \frac{1}{N_{\mathcal{E}_\theta}} \sum_{\boldsymbol{\theta} \in \mathcal{E}_\theta} \bar{\mathbf{x}}_{k \mid k}(\boldsymbol{\theta})

and the variance in each cell is the mean of the member variances over Eθ\mathcal{E}_\theta plus the variance of xˉk∣k(θ)\bar{\mathbf{x}}_{k \mid k}(\boldsymbol{\theta}) over Eθ\mathcal{E}_\theta. These are filtered estimates, so step kk uses the observations up to yk\mathbf{y}_k only (the draws of θ\boldsymbol{\theta} come from the whole record). We score them against the true field, at the sensor cells and in the cells between them.

50 assimilation runs: 1.8 s (with JIT)
sensor cells   RMSE = 0.047, mean sd = 0.050, coverage of ±2σ = 100.0 %
cells between  RMSE = 0.114, mean sd = 0.071, coverage of ±2σ =  98.8 %
<Figure size 1500x800 with 9 Axes>

After the first two or three hours the filtered mean is hard to tell from the truth, also in the cells that no sensor sees. The filter updates the members where the sensors are, and the dynamics carry those corrections along the channel. The standard deviation is largest at the first step, when the members still carry the prior, and it averages 0.050 at the sensor cells and 0.071 between them. Between the sensors the RMSE (0.114) is above that average, and yet 98.8 % of the cell-hours there fall within ±2σ\pm 2\sigma (100 % at the sensors). The large errors sit in the first hours, where the band is wide too, as the bottom panels show for two cells without a sensor.

6. The bias in NExN_{\mathcal{E}_x}, and the cost

We now measure the bias of the ensemble log likelihood, and what it does to the posterior, at NEx=16N_{\mathcal{E}_x} = 16, 32 (the X0\mathbf{X}_0 that NUTS used) and 128 members. The reference is the exact Kalman filter. The dynamics are linear, so we build F(θ)\mathbf{F}(\boldsymbol{\theta}) by applying ff to the columns of IDx\mathbf{I}_{D_x}, and give it to LinearGaussianSSMPrior with zero model noise and Σx,0\boldsymbol{\Sigma}_{x,0} as the initial covariance. Then lgssm_factor gives the exact log likelihood. With two parameters we can also compute each posterior on a 25 × 15 grid of θ\boldsymbol{\theta} around the mode, with no sampling error: the weights are p(y1:T∣θ)p(θ)p(\mathbf{y}_{1:T} \mid \boldsymbol{\theta}) p(\boldsymbol{\theta}) normalised over the grid. We also time one jitted evaluation and its gradient, the price of every NUTS leapfrog step and SVI step.

             log p(y | theta_true)       u mean ± sd       K mean ± sd  grad, ms
Kalman                       77.34    1.9696 ± 0.0182    0.3295 ± 0.0561       7.2
N_Ex = 16                    67.74    1.9864 ± 0.0171    0.3306 ± 0.0543       6.6
N_Ex = 32                    74.36    1.9670 ± 0.0182    0.3046 ± 0.0550       8.6
N_Ex = 128                   77.62    1.9696 ± 0.0182    0.3313 ± 0.0560      18.8
(4 grid posteriors and gradient timings: 28.8 s)

At the true θ\boldsymbol{\theta} the ensemble log likelihood is 9.60 below the exact 77.34 with 16 members, 2.98 below with 32 and 0.28 above with 128. Each row uses one X0\mathbf{X}_0, so the size of the error is itself random, but it shrinks with NExN_{\mathcal{E}_x}. On the posterior the effect is smaller than these gaps suggest. What moves the posterior is how the error changes with θ\boldsymbol{\theta}, not its level. With 16 members the speed shifts by 0.017 km h⁻¹, about one posterior standard deviation. With 32 the speed is within 0.003 km h⁻¹ of the exact posterior mean and the diffusivity is 0.025 km² h⁻¹ low, under half a standard deviation. With 128 both are within 0.002 of the exact values. The grid posterior at 32 members also matches the NUTS one (1.967 against 1.966 km h⁻¹ for uu, 0.305 against 0.306 km² h⁻¹ for KK). So NUTS sampled the ensemble posterior well, and the miss of the true speed in section 4 is in the data.

One gradient costs 6.6 ms with 16 members, 8.6 ms with 32 and 18.8 ms with 128, against 7.2 ms for the Kalman filter. At Dx=64D_x = 64 the Kalman filter is as cheap as a small ensemble, because Dx3D_x^3 is small. The ensemble pays off when the state is too large for a Dx×DxD_x \times D_x covariance: its cost grows with the number of members and model runs, not with Dx3D_x^3, and it never stores Σx\boldsymbol{\Sigma}_x.

7. Example 5b: an ensemble of variational fits with ensemble_vi

pyrox.inference.ensemble_vi uses the word ensemble for a different object. It runs NEνN_{\mathcal{E}_\nu} independent SVI fits of one guide q(θ;ν)q(\boldsymbol{\theta}; \boldsymbol{\nu}), each from its own random start, vmapped into one computation. It returns the stacked variational parameters ν(e)\boldsymbol{\nu}^{(e)}, e∈Eνe \in \mathcal{E}_\nu, and the loss history of every fit. So a member in 5a is a state xk(e)\mathbf{x}_k^{(e)} inside one evaluation of the log likelihood, and the members together estimate the distribution of the state for one θ\boldsymbol{\theta}. A member in 5b is a whole approximate posterior q(θ;ν(e))q(\boldsymbol{\theta}; \boldsymbol{\nu}^{(e)}). The spread over these members says where the optimiser can end up, not how uncertain θ\boldsymbol{\theta} is. That is useful when the loss has several local optima, as this one has in uu.

ensemble_vi takes any NumPyro model whose two arguments are the data, so we pass tracer_model unchanged, with data=(init_ensemble, y), and an AutoNormal guide. Its default starts each fit at a uniform point in [−2,2][-2, 2] on the unconstrained scale. Each of the NEν=8N_{\mathcal{E}_\nu} = 8 fits minimises LELBO(ν)=−ELBO\mathcal{L}_\text{ELBO}(\boldsymbol{\nu}) = -\mathrm{ELBO} with Adam for 200 steps. Every step of every fit is one assimilation run with the same 32-member X0\mathbf{X}_0. ensemble_vi does not return where each fit started, so we rebuild the starts with EnsembleVI.init and the same seed.

ensemble_vi wall-clock: 26.4 s for 8 fits x 200 steps
 fit  start u       u       K  final -ELBO
   0    -1.30   2.000   0.298        -68.3
   1     1.29   1.972   0.299        -69.2
   2    -0.28  -0.630   0.042        435.8
   3     0.28  -0.608   0.025        433.5
   4    -1.29  -0.608   0.043        436.4
   5    -1.89  -0.611   0.032        434.2
   6     0.19   1.967   0.299        -69.4
   7    -0.53   1.973   0.310        -69.3
<Figure size 1300x420 with 2 Axes>

The black curve is the exact log likelihood in uu at the true KK (the Kalman filter of section 6), and the dotted lines mark where each fit started. Four of the eight fits end at the main mode, with uu between 1.967 and 2.000 km h⁻¹, KK between 0.298 and 0.310 km² h⁻¹ and a final LELBO\mathcal{L}_\text{ELBO} of about −69. The other four end at the second mode, with uu between −0.630 and −0.608 km h⁻¹ and almost no diffusion (KK between 0.025 and 0.043). Their loss, between 433.5 and 436.4, is about 500 nats worse. (They sit above the black curve because they also lowered KK, which the curve holds at the truth.) Which mode a fit reaches depends on its start, but not simply. The fit that started at −1.30 km h⁻¹ crossed to the main mode, while the one that started at 0.28 km h⁻¹ went to the second one. Since the final losses separate the two groups by hundreds of nats, we keep the fits at the best loss and drop the rest. Averaging all eight would mix two modes that the posterior does not mix. The uncertainty of θ\boldsymbol{\theta} then comes from the guide of a best fit, or from NUTS as in section 3, started inside the right mode.

The 8 fits took 26.4 s. Both kinds of ensemble multiply the work, but in different places. 5a multiplies every log-density evaluation by NExN_{\mathcal{E}_x} model runs, and 5b multiplies the whole fit by NEνN_{\mathcal{E}_\nu}.

Summary

  • A transport model with an ensemble Kalman likelihood is a plain NumPyro function: priors on uu and KK, a filterax.AbstractDynamics built from them, and ensemble_factor("y", flx.filters.ETKF(), dynamics, observe, init_ensemble, y, obs_times, obs_noise). The initial ensemble is drawn once, outside the model, so the factor is deterministic and smooth in θ\boldsymbol{\theta}.

  • NUTS on the two parameters, with 32 members, took 52.5 s with 3.6 leapfrog steps per draw. The diffusivity’s 90 % interval holds the truth, and the speed’s misses it by 0.004 km h⁻¹, as the exact Kalman posterior does too.

  • The analysis members in the returned AssimilationResult, averaged over 50 NUTS draws, give the filtered field with bands. Between the sensors the RMSE is 0.114 and 98.8 % of the cell-hours fall within ±2σ\pm 2\sigma.

  • The ensemble log likelihood is biased: 9.60 below the exact value at the truth with 16 members, 2.98 with 32 and 0.28 above with 128. Its posterior is within 0.003 km h⁻¹ of the exact one in uu from 32 members on, and with 16 members it is off by about one posterior standard deviation. Report NExN_{\mathcal{E}_x} with any result.

  • One gradient costs 8.6 ms with 32 members and 7.2 ms with the Kalman filter at Dx=64D_x = 64. The ensemble is for states too large for a Dx×DxD_x \times D_x covariance, where the Kalman filter is not an option.

  • ensemble_vi is an ensemble of fits, not of states. On this model four of eight fits from random starts ended at a second mode of uu, about 500 nats worse in LELBO\mathcal{L}_\text{ELBO}, so it is a way to find the modes before fitting the posterior in the right one.

For nonlinear dynamics or observations with a moment-matched filter, see Example 6. For the exact Kalman filter on a small state, see Example 1.