Probabilistic Reasoning over Time
A world that changes needs a state variable at every point in time. The Markov assumption cuts the dependence on history down to the previous slice, leaving a transition model and a sensor model that define a temporal Bayesian network.
╌╌╌╌
A Bayesian network reasons about a world that holds still. Diagnose a broken car and you assume the fault stays put while you probe it: each random variable takes one fixed value, and inference infers those values from evidence that is also fixed. Most of the worlds an agent has to act in are not like that. A diabetic patient's blood sugar drifts with food and insulin and the hour of the day; a robot's position slides under its wheels; a tracked aircraft keeps moving between radar sweeps. To reason about any of them the agent must treat the state not as one value but as a sequence of values, one per instant, and connect the instants with a model of how the world evolves.1
This lesson builds the machinery for exactly that. The world becomes a temporal Bayesian network — the same local-dependency graph, unrolled through time — and the questions we asked of a static network (what is the state, given the evidence?) become recursive: each answer is computed from the previous answer plus one new observation, so the agent never re-reads its whole history.
States and observations over time
View the world as a series of snapshots, or time slices, each a set of random variables. Some are hidden, some observed. Write for the set of state variables at time — the things we cannot see directly — and for the evidence variables we do observe at that slice. We assume the interval between slices is fixed, so times are just integers, and by convention evidence begins at . The notation denotes the evidence sequence .2
The running example is deliberately small. You are a security guard in a windowless bunker; the only clue to the weather is whether the director walks in each morning carrying an umbrella. The single state variable is (is it raining today?), hidden from you, and the single evidence variable is (did the umbrella appear?), which you observe. The umbrella does not cause the rain; the rain causes the umbrella — the arrows in the model run from state to sensor, and inference runs against them.
The Markov assumption
The transition model should say how the current state depends on the past: . But the conditioning set grows without bound as increases, so we cannot store a distribution that depends on all of it. The Markov assumption cuts the dependence down to a finite, fixed number of previous slices. The simplest and most common choice is a first-order Markov process, in which the current state depends only on the immediately preceding one:
The state variables thus carry all the information needed to predict the next slice: the future is conditionally independent of the past given the present. A second-order process would keep as well; higher orders gain accuracy at the cost of a larger conditional table.3
The state nodes read and the evidence nodes read ; the slice index belongs to each column and is carried in the caption rather than crammed into the small node font.
The transition and sensor models
Two conditional distributions finish the specification. The transition model says how the state evolves. The sensor model (or observation model) says how the state produces the evidence; it encodes a second, weaker Markov assumption, that a percept depends only on the current state, .
We also assume the process is stationary — the transition and sensor distributions are the same at every — so a single table specifies each, however long the sequence runs. (Stationary is not static: in a stationary process the state still changes; it is the law of change that stays fixed.) For the umbrella world the two tables are tiny:
With a prior added, the model defines the complete joint over every variable, a temporal instance of the Bayes-net chain rule:
The three factors are the initial-state model, the transition model, and the sensor model — the whole temporal network compressed into a prior and two stationary tables.
The four inference tasks
With the model reduced to a prior and two small tables, almost every temporal question is one of four, and each is a recursive message — computed from the previous answer plus one new observation, never from the whole history. That shape is what lets an agent track an endless stream of evidence with fixed memory.
With the structure fixed, four questions can be asked of any temporal model, independent of the particular transition and sensor tables.4
| Task | Query | Reads evidence | Direction |
|---|---|---|---|
| Filtering | up to now | forward | |
| Prediction | , | up to now, project ahead | forward |
| Smoothing | , | up to now, revise past | forward + backward |
| Most likely explanation | up to now | forward (Viterbi) |
Filtering is what a rational agent does to stay current: keep a belief state, the posterior over the latest state given all evidence so far. Prediction projects that belief into the future with no new evidence. Smoothing goes the other way, revising an estimate of a past state now that later evidence has arrived — the extra evidence makes it a better estimate than was available at the time. Most likely explanation asks not for the marginal at each slice but for the single most probable state sequence as a whole. The rest of this section gives each its recursive formula.
Filtering: the forward algorithm
The point of filtering is to avoid re-reading history. Given the belief state at time we want to fold in the new evidence and produce the belief state at directly — recursive estimation. Rearranging the query splits it into a prediction and an update:
where is a normalizing constant. The update factor is read straight off the sensor model. The prediction factor comes from conditioning on the current state and summing it out, using the transition model:
The second factor inside the sum is the previous belief state — the recursion has closed on itself. We can think of the filtered estimate as a forward message that is propagated along the sequence, projected by each transition and reweighted by each observation:
Because each update touches only the previous message and the new evidence, its time and space cost is constant, independent of — exactly the property a memory-bounded agent needs to track an unbounded stream. Written as a procedure:
- 1input: prior , transition model, sensor model, evidence
- 2the initial belief state
- 3for to do
- 4for each state do
- 5project forward
- 6for each state do
- 7weight by the observation
- 8
- 9return
To see it run, filter the umbrella world with a prior , carrying every number through two days on which the umbrella appears. Each day is a predict step (sum over the transition) then an update step (multiply by the sensor model and renormalize).
Day 1, umbrella seen. Predict from to . Rain today has probability , and by symmetry ; the flat prior predicts a flat state. Update by the umbrella-seen sensor vector : the unnormalized belief is , which sums to , so
Day 2, umbrella seen again. Predict from the day-1 belief: and , so the prediction is — the transition alone has pulled the belief a little back toward because the chain forgets. Update: , summing to , giving
Belief in rain climbs from to across the two days: rain persists, and each umbrella confirms it faster than the transition erodes the estimate. The balance between the two steps is the whole content of filtering — the predict step spreads probability out along the chain's tendency to forget, and the update step pulls it back toward whatever the latest observation supports.
Prediction
Prediction is filtering with the update step removed: no new evidence, only the transition model iterated forward. From the state at we get the state at by summing over the transition,
Iterating this recursion, the predicted distribution drifts toward the stationary distribution of the Markov chain — the fixed point of the transition model — after which it stops changing. The number of steps to reach it is the mixing time. Prediction far beyond a small fraction of the mixing time is worthless: the future washes out to the chain's long-run average, and the more uncertain the transition model, the sooner that happens.
Smoothing: the forward–backward algorithm
Smoothing computes for a past slice , using all the evidence, including what arrived after . Split the evidence at into the past and the future :
where is pointwise multiplication. The first factor is the forward message already available from filtering. The second is a new backward message, computed by a recursion that runs backward from :
that is, , initialized with (an empty evidence sequence has probability 1). Each backward step, like each forward step, is constant-time.
Smoothing a single slice is . Smoothing the whole sequence naively would repeat this for every , costing ; the forward–backward algorithm does it in by dynamic programming — run filtering forward once and record every , then sweep the backward recursion from down to 1, combining each stored with the running .
- 1input: evidence , prior
- 2
- 3for to do
- 4store the forward messages
- 5backward message, all ones
- 6for downto do
- 7combine stored forward with backward
- 8
- 9return
Applied to the umbrella world at , given umbrellas on days 1 and 2, the smoothed estimate is — higher than the filtered . The day-2 umbrella makes rain on day 2 more likely, and because rain persists, that raises the estimate of rain on day 1. Learning the transition and sensor models from data (an expectation–maximization procedure) requires smoothing rather than filtering for exactly this reason: inferring what happened needs the evidence from after it happened.
Most likely explanation: the Viterbi algorithm
Given the umbrella sequence, we might want the single most probable weather sequence that explains it — not the most likely weather on each day separately, which can differ. Picture every state sequence as a path through a graph whose nodes are the possible states at each slice; the likelihood of a path is the product of the transition probabilities along it and the observation probabilities at each node. We want the most likely path.
The Markov property gives a recursion. The most likely path to a state consists of the most likely path to some state at followed by a transition into :
This is identical to the filtering equation, with two changes: the forward message is replaced by a message holding the probability of the best path reaching each state, and the summation over becomes a maximization over . The algorithm — the Viterbi algorithm — therefore runs forward like filtering, computing at each slice; at each state it also records which predecessor was best, and following those back-pointers from the best final state recovers the optimal sequence.
Like filtering, Viterbi is linear in ; unlike filtering, it needs space for the back-pointers. The same algorithm is the backbone of sequence labeling in natural-language processing — part-of-speech tagging and speech recognition run Viterbi over a hidden Markov model to recover the most likely tag or word sequence behind a string of sounds or tokens.
Hidden Markov models
A hidden Markov model (HMM) is the special case in which the state is a
single discrete variable. The umbrella world is already an HMM: one state
variable whose values are the possible states of the world. A
model with several discrete state variables still fits, by merging them into one
megavariable
whose values are the tuples. The restriction to a single discrete
variable yields a clean matrix implementation of all four inference tasks.5
For the umbrella world the transition matrix and two sensor matrices (for an umbrella seen, , and not seen, ) are
With the messages as column vectors, filtering and smoothing become matrix–vector products. The forward recursion is
and the backward recursion is . Each step multiplies an -element vector by an matrix, so the forward–backward algorithm runs in time and space. The matrix form also exposes a constant-space variant of smoothing and a constant-time fixed-lag smoother — the algebra of the messages carries the improvements the raw recursions could not.
An HMM localizes a robot the same way it forecasts rain. Put the robot's grid square in the state variable , let the transition model spread probability to neighboring squares, and let a noisy four-bit obstacle sensor drive the sensor model. Filtering with Equation for produces a posterior over locations that sharpens with each reading; even with a per-bit sensor error of — meaning the full reading is wrong more than half the time — a couple of dozen observations pin the robot down to within a square, because filtering integrates evidence over time against the transition constraints.
Kalman filters: continuous state
Discrete states cover a robot on a grid, but a bird flitting through foliage, a blip wandering across a radar screen, or a planet traced from noisy angular sightings all live in a continuous state space — position and velocity, real numbers. Kalman filtering is the continuous analogue of the forward algorithm, and it stays tractable by keeping the whole thing Gaussian.6
The trick is linear Gaussian models. The next state is a linear function of the current state plus Gaussian noise, and each measurement is a linear function of the state plus Gaussian noise. Under those assumptions the belief state, if it starts Gaussian, stays Gaussian for all time: the forward operator maps a Gaussian with mean and covariance to a new Gaussian . Filtering reduces to updating a mean and a covariance — no representation blowup. (This is special: filtering a general continuous or hybrid model produces a belief state whose description grows without bound.)
Each update is a predict step followed by an update step, the same two-part structure as discrete filtering. Predict pushes the Gaussian through the transition, shifting the mean by the motion and inflating the covariance by the transition noise. Update folds in the new measurement, pulling the mean toward the observation and shrinking the covariance.
The new mean is a weighted average of the prediction and the observation, and the weight — the Kalman gain — says how much to trust the measurement. If the sensor is noisy the gain is small and the prediction dominates; if the process is unpredictable the gain is large and the observation dominates. The variance update does not depend on the observation at all, so the sequence of covariances (and gains) can be computed offline in advance; only the mean update runs during tracking, which is why the filter is cheap enough for real-time radar.
Kalman filtering's assumptions are strong. When the transition is nonlinear the extended Kalman filter linearizes it around the current mean — good enough for smooth systems. When the true belief is genuinely non-Gaussian — a bird deciding to dodge left or right of a tree, two distinct outcomes a single Gaussian bump cannot represent — no Kalman variant suffices, and we need a more expressive model and, with it, a more general approximate filter.
This continues in Reasoning over Time: Tracking and Data Association, which introduces dynamic Bayesian networks and particle filtering, then tackles the hardest case — tracking many objects when you do not know which observation came from which.
Footnotes
- Russell & Norvig, AIMA (3rd ed.), Ch. 15 — Probabilistic Reasoning over Time: partially observable environments require a belief state maintained through a transition model and a sensor model, with probability quantifying the degree of belief in each possible world state. ↩
- Russell & Norvig, AIMA, §15.1.1 — States and Observations: the world as time slices of hidden state variables and observed evidence , with the umbrella/rain example and the interval notation. ↩
- Russell & Norvig, AIMA, §15.1.2 — Transition and Sensor Models: the Markov assumption and first-order Markov process (Eq. 15.1), the sensor Markov assumption (Eq. 15.2), and stationarity of the process. ↩
- Russell & Norvig, AIMA, §15.2 — Inference in Temporal Models: the definitions of filtering, prediction, smoothing, and most likely explanation, and the generic recursive algorithms (Eqs. 15.4–15.11). ↩
- Russell & Norvig, AIMA, §15.3 — Hidden Markov Models: the single-discrete-variable case and the matrix form of the forward and backward recursions (Eqs. 15.12–15.13), with the robot-localization example. ↩
- Russell & Norvig, AIMA, §15.4 — Kalman Filters: linear Gaussian transition and sensor models, the predict/update cycle (Eqs. 15.20, 15.22), the Kalman gain, and the extended Kalman filter for nonlinear systems. ↩
╌╌ END ╌╌