Bayesian Filtering and Belief States › Exact Filtering: The Kalman Filter

Michael BrenndoerferJune 8, 20267 min read
World Models HandbookAll chapters
Part 2 of 12Inference, Decisions, and Control
Chapter 8Bayesian Filtering and Belief States › Exact Filtering: The Kalman Filter
Reading section 4 of 11 · Exact Filtering: The Kalman Filter · 7 minSection 4 of 11 · 7 min

Book contents

Section 4 of 11 · 7 min read

Bayesian Filtering and Belief States › Exact Filtering: The Kalman FilterOne section · Sections in this chapter4 / 11 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

The Bayes filter is exact but involves integrals over arbitrary distributions, which is why it is rarely computable as written. Rudolf Kálmán's 1960 insight was that an entire class of problems admits a closed-form solution: if the transition and observation models are linear, the process and observation noise are Gaussian, and the initial belief is Gaussian, the belief stays Gaussian forever. The recursion then reduces to updating a mean vector and a covariance matrix. This is a remarkable compression of the general problem. Instead of tracking a function over an infinite-dimensional space of distributions, the filter tracks finitely many numbers. Those numbers update through matrix operations that were feasible on 1960s hardware, although numerical stability required careful implementations. The filter was used in Apollo-era navigation within a decade of its publication.

Why Gaussians Close Under Linear Dynamics

Take a linear transition with additive Gaussian noise,

xt=Axt−1+But−1+wt,wt∼N(0,Q),x_t = A x_{t-1} + B u_{t-1} + w_t, \qquad w_t \sim \mathcal{N}(0, Q),

and a linear observation with Gaussian noise,

ot=Hxt+vt,vt∼N(0,R).o_t = H x_t + v_t, \qquad v_t \sim \mathcal{N}(0, R).

Assume that the initial belief, the full process-noise sequence, and the full observation-noise sequence are mutually independent, with fresh noise draws independent across time. If bt−1b_{t-1} is Gaussian, then the prediction bˉt\bar{b}_t is a linear transformation of a Gaussian plus independent Gaussian noise, hence Gaussian, with mean and covariance propagated by matrix algebra. The correction step multiplies the predicted Gaussian density by the likelihood p(ot∣xt)p(o_t \mid x_t) and normalizes the result. The product is proportional to a Gaussian. For a direct scalar observation its precision is the sum of the two scalar precisions; in the general linear case the likelihood contributes H⊤R−1HH^\top R^{-1}H to state-space precision. This closure property does all the work. No integrals remain, only arithmetic on means and covariances.

It is worth spelling out the closure argument once, slowly, because the same pattern recurs whenever someone claims a filter is "exact." A distribution family is closed under an operation if applying the operation to members of the family yields another member. Linear maps take Gaussians to Gaussians, sums of independent Gaussians are Gaussian, and products of Gaussian densities are proportional to Gaussians, exactly Gaussian once normalized, which the correction step does. Since prediction uses linear maps plus sums, and correction uses normalized products, both steps stay inside the family. Nonlinearity breaks the first link, and non-Gaussianity breaks the second and third. The classical approximations below repair one of those broken links; the learned update later replaces the explicit recursion with a trained recurrent computation.

The Filter Equations

Start from an initial Gaussian belief N(x^0,P0)\mathcal{N}(\hat{x}_0, P_0). The mean x^0\hat{x}_0 and covariance P0P_0 are part of the filter specification: they encode what is known before the first measurement.

Predict:

x^t∣t−1=Ax^t−1+But−1,\hat{x}_{t|t-1} = A \hat{x}_{t-1} + B u_{t-1}, Pt∣t−1=APt−1A⊤+Q.P_{t|t-1} = A P_{t-1} A^\top + Q.

Correct:

Kt=Pt∣t−1H⊤(HPt∣t−1H⊤+R)−1,K_t = P_{t|t-1} H^\top \left(H P_{t|t-1} H^\top + R\right)^{-1}, x^t=x^t∣t−1+Kt(ot−Hx^t∣t−1),\hat{x}_t = \hat{x}_{t|t-1} + K_t \left(o_t - H \hat{x}_{t|t-1}\right), Pt=(I−KtH)Pt∣t−1.P_t = \left(I - K_t H\right) P_{t|t-1}.

Here x^t\hat{x}_t and PtP_t are the posterior mean and covariance after absorbing the measurement; the t∣t−1t\mid t-1 subscript marks predicted values computed before it arrives. And ot−Hx^t∣t−1o_t - H\hat{x}_{t|t-1} is the innovation: the part of the measurement the model did not anticipate. Read the equations as a conversation between model and data. The predict step speaks first, asserting where the state should be and how confident the assertion is. The measurement replies, and the innovation records the disagreement. The gain decides how much the disagreement matters, and the final update moves the mean partway toward resolving it while shrinking the covariance to reflect the information gained. Every symbol plays a role in this dialogue, and none of them is decoration.

Reading the Gain

Everything interesting hides in the Kalman gain KtK_t. Look at its structure. The denominator contains HPt∣t−1H⊤H P_{t|t-1} H^\top, the predicted uncertainty of the measurement, plus RR, the sensor noise. The numerator Pt∣t−1H⊤P_{t|t-1}H^\top is the cross-covariance between the state and measurement. So the gain is essentially a ratio:

Kt  ∼  uncertainty in the predictionuncertainty in the prediction+uncertainty in the sensor.K_t \;\sim\; \frac{\text{uncertainty in the prediction}}{\text{uncertainty in the prediction} + \text{uncertainty in the sensor}}.

When the model is confident (PP small) or the sensor is poor (RR large), the gain shrinks and corrections barely move the estimate. When the model is uncertain or the sensor precise, the gain gives more weight to the measurement. The filter continuously re-weights trust between its own model and incoming evidence, and it does so optimally in the mean-squared-error sense for this problem class. This trust-balancing interpretation is the single most transferable idea in the chapter: every estimator, learned or analytic, faces the same question of how much to believe the internal model versus the latest evidence, and the Kalman gain is the optimal answer in the linear-Gaussian setting treated here.

For the scalar observation case plotted below, with H=1H=1, the gain reduces to K=p/(p+R)K=p/(p+R), where pp is the predicted variance. In multiple dimensions K=PH⊤(HPH⊤+R)−1K=P H^\top(H P H^\top+R)^{-1} is a matrix, so neither its entries nor its eigenvalues generally follow the scalar curve.

Out[4]:
Visualization
Line chart of scalar Kalman gain versus predicted variance for three sensor noise levels.
Scalar Kalman gain $K=p/(p+R)$ for a direct observation with $H=1$, shown as a function of predicted variance for several sensor-noise levels.

Each curve traces the scalar trade-off at a different sensor quality. With a precise sensor (R=0.25R = 0.25) the gain climbs quickly: even modest model uncertainty hands most of the correction weight to the measurement. The noisy-sensor curve (R=4R = 4) remains the lowest of the three throughout the plotted range, but it is not always below the half-trust line: it crosses K=0.5K=0.5 at p=4p=4 and reaches K=10/14≈0.714K=10/14\approx0.714 at the right edge. In this H=1H=1 scalar case, each crossing with the dotted half-trust line occurs exactly where p=Rp=R. For a general observation matrix, inspect the full matrix gain and innovation covariance instead of applying this scalar crossing rule componentwise.

Two further facts deepen the picture. First, the covariance update does not depend on the observed values, so with AA, HH, QQ, RR, and P0P_0 fixed, the full sequence of gains can be precomputed offline. Second, for a time-invariant system the gain converges to a fixed matrix solving a discrete algebraic Riccati equation under the usual stabilizability and detectability conditions. This is the object that connects filtering to optimal control. For linear-quadratic-Gaussian problems, the separation principle permits independent estimator and controller design with no loss of optimality. That independence of design generally disappears in nonlinear and learned settings, where the controller changes the distribution of states on which the estimator operates.