Computing Library › Worked Examples
Worked Examples

An Ensemble Kalman Filter Update

Assimilate one noisy observation into a small ensemble, computing the Kalman gain from sample statistics and nudging each member.

Problem

The ensemble Kalman filter (EnKF) tracks a distribution over states using a small population of sample states rather than an explicit covariance matrix. This makes it practical for high-dimensional nonlinear systems where storing a full covariance is impossible.

Ensemble and observation

Kronos motion — gain not net

We have five one-dimensional members with mean near 2 and an observation y=3 with measurement variance R=0.5. The forecast covariance P is estimated from the spread of the ensemble, and the gain K = P H' (H P H' + R)^-1 blends model and data.

python
import numpy as np
rng=np.random.default_rng(1)
x=np.array([1.8,2.1,2.4,1.9,2.3])   # forecast ensemble
H=1.0; R=0.5; y=3.0
P=x.var(ddof=1)
K=P*H/(H*P*H+R)
yp=y+rng.normal(0,np.sqrt(R),x.size)  # perturbed observations
xa=x+K*(yp-H*x)
print('P',round(P,3),'K',round(K,3))
print('analysis mean',round(xa.mean(),3))

Result

With P about 0.06 and R=0.5 the gain K is roughly 0.11, so the filter trusts the model far more than this noisy observation and moves the mean only slightly toward 3. Perturbing the observations for each member keeps the updated ensemble spread statistically correct, which a naive shared update would collapse.