State space models and Kalman smoothing
Track scalar Gaussian states with exact filtering and backward smoothing, declaring which observations each estimate can use.
On this page
The question for today
What you’ll understand
- Compute prediction and update distributions for a linear Gaussian state model.
- Apply one backward Rauch–Tung–Striebel smoothing step with valid variances.
- Separate a retrospective state estimate from a forecast available at an earlier origin.
A state space model separates an evolving hidden quantity from noisy measurements of it. Filtering updates knowledge of the current state using observations available so far. Smoothing revises an earlier state after later observations have arrived. Both can be exact Gaussian calculations, yet they answer different information questions. Confusing them can turn an excellent retrospective reconstruction into an impossible live forecast. The distinction matters as much as the algebra when measurements arrive slowly or a hidden trend is used as a feature.
Independence and positive variance support the recursion
Use the scalar model x_t=a x at t−1 plus w_t and y_t=h x_t plus v_t. The initial state is Gaussian with known mean and nonnegative variance. Process noises are independent centered Gaussian variables with variance q greater than zero; measurement noises have variance r greater than zero. These noise sequences and the initial state are mutually independent. Parameters are treated as known. These conditions make the conditional distributions Gaussian and ensure the denominators used below are positive.
Suppose the previous filtering mean and variance are m and P. Prediction gives a times m and a-squared times P plus q. The new measurement residual is its observed value minus h times the predicted mean, with variance S=h-squared times predicted variance plus r. Gaussian conditioning yields gain K equal to predicted variance times h divided by S. Updating adds K times the residual to the mean and reduces uncertainty according to the displayed variance formula.
A backward pass uses later available evidence
After filtering through a terminal time T, the Rauch–Tung–Striebel smoother proceeds backward. It starts from the final filtering distribution. The gain J at t equals the filtered variance times a divided by the next predicted variance. The next smoothed mean differs from its earlier prediction because later observations supplied additional evidence. Multiplying that discrepancy by J transfers the appropriate correction to the earlier state. The covariance recursion transfers its associated reduction in uncertainty.
The smoothed state at t conditions on all measurements through T, including some after t. It is legitimate for reconstructing history once those measurements exist. A prediction issued at time t cannot use that later evidence. Conversely, smoothing entirely within a training record ending at a forecast origin is allowed, provided no post-origin data enter the fitted features. The information boundary is the last available observation, rather than the name of the numerical algorithm.
Conditional uncertainty has a specified scope
A future state forecast propagates the current filtering distribution without incorporating unobserved future measurements. Its variance accumulates process noise at each step. Forecasting a future measured value adds measurement variance as well. Those two variances answer different questions: uncertainty about an underlying signal is smaller than uncertainty about a fresh noisy measurement of it. Reporting only state uncertainty as an observation interval understates the latter.
Without joint Gaussianity, the same covariance calculations can describe best linear estimators under the corresponding second-moment and independence assumptions, but generally not the unrestricted conditional mean or its full distribution. Estimated parameters introduce uncertainty beyond the known-parameter filter covariance. Near-singular multivariate problems require numerical care and possibly alternative factorizations. A state space representation is a precise modeling choice; it does not by itself establish that a latent component is a physical cause or that the measurement errors match the assumed law.
Work it through
A later measurement revises an earlier state
Let a=h=q=r=1 and the initial state have mean zero and variance one. Observe y-one=2 and y-two=0. Filter both states and smooth state one using both observations.
At time one, predicted variance is two, gain is 2/3, filtered mean is 4/3 and filtered variance is 2/3.
At time two, predicted mean is 4/3 and variance is 5/3. The gain is 5/8; updating with residual −4/3 gives mean 1/2 and variance 5/8.
The backward gain for time one is (2/3)/(5/3)=2/5. Its smoothed mean is 4/3+(2/5)(1/2−4/3)=1.
Its smoothed variance is 2/3+(4/25)(5/8−5/3)=1/2. The later low measurement reduces both the earlier mean and its remaining uncertainty.
Filtering state one gives mean 4/3 and variance 2/3; smoothing it after time two gives mean one and variance one half. Only the first pair was available at time one.
The living notebook
Explore the model
Interactive lab · matrix
A shared Gaussian coordinate makes a measurement informative
Pause and reset, then set both controls to a = 1 and b = 0. For independent standard normal input coordinates, X=Z-one and Y=Z-two are independent, so observing Y leaves variance of X equal to one. For a fresh comparison, pause and reset, then set a = 1 and b = 1: X=Z-one+Z-two and Y=Z-two. Predict unconditional variance two, conditional mean Y and conditional variance one. The selected A illustrates one Gaussian conditioning step; the geometric animation does not run a time sequence or RTS pass.
- Area scale · det A
- 1.4
- Singular values · σmax, σmin
- 1.597, 0.876
- Condition number · κ₂(A)
- 1.823
The selected matrix is A = [[a,b],[0,1]]. Playback interpolates geometry between the identity and A; readouts always describe A. Its determinant is a and its singular values come from AᵀA. Positive a makes every supported matrix invertible. This two-dimensional family is not a general eigensolver or a learned network. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forAn observation reduces state uncertainty through shared covariance, under the declared probability model.
Pause & reason
Check your understanding
Your turn
Try it yourself
Take a=h=q=1 and r=3. The initial state is known to be zero. After observing y-one=4, find the filtering mean and variance, then the mean and variance of the measured value y-three forecast from time one.
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Begin with initial variance zero, add one process-noise variance at each future step, and add measurement variance only for the measured-value forecast.
Compare with the solution
The first predicted variance is one and the innovation variance is four, so the gain is one quarter. The updated mean is one and variance is three quarters. Two future state transitions keep the mean one and add two, giving state-three variance eleven quarters. The independent measurement variance adds three, so y-three has conditional mean one and variance twenty-three quarters. This is a known-parameter Gaussian forecast; using eleven quarters for the measured-value uncertainty would omit fresh observation noise.
Keep the idea
Take it with you
- Filtering conditions on observations through the current time; smoothing conditions on a longer available record.
- Positive innovation and predicted variances justify the ordinary scalar divisions.
- State forecasts, observation forecasts and parameter uncertainty have different variance contributions.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.