Infer state across time.
Track a hidden moving object by alternating motion predictions and noisy sensor updates, while keeping a distribution over possible positions.
By the end: Compute a hidden Markov model forward update, compare full-history and latest-only evidence, and distinguish uncertainty, impossible observations and model error.
Start with something concrete.
A noisy sensor reports an object on the right. Was it really there, or did a misleading reading interrupt a steady track? Keep several possible positions until movement and observations provide enough evidence.
Try the interactive model ↓A sensor reading is missing for one time step. What should the filter do?
Change one thing. Watch what follows.
- With known Left and the slow motion model, predict the next distribution before revealing the sensor correction.
- Trace the three predicted probabilities through sensor likelihoods, weights and normalization.
- Process the authored sequence and compare full-history beliefs with the latest-only same-time reference.
- Replace one reading with Missing and verify that only motion changes the belief at that time.
- Use Never move and reveal the authored positions. Explain confident error at time 3 despite exact arithmetic.
- Try a perfect sensor with an incompatible reading. Explain why filtering stops instead of inventing a posterior. Export a comparison.
Loading this browser experiment…
Track possibilities rather than a single guess
An object can occupy three positions: Left, Middle or Right. At time 0 you either know it is Left or start with equal probabilities. After each movement, a noisy sensor reports a position. A reading is evidence about the state, not the state itself.
The lab maintains a belief distribution: three probabilities that sum to one. A belief of (0.6, 0.3, 0.1) means 60% on Left, 30% on Middle and 10% on Right. It does not mean the physical object is split into pieces. Keeping the whole distribution preserves alternatives that a single best guess would discard.
A hidden Markov model, or HMM, supplies an initial distribution, a transition model and an observation model. The state is hidden; the readings are observed. Its Markov assumption says the next state depends on the current state rather than needing the entire past once that current state is known. Its sensor assumption says the current reading depends only on the current state. The lab also keeps both models fixed through time.
These are modeling assumptions, not automatic properties of a real tracking system. Momentum may require adding velocity to the state. Shared sensor interference may make errors dependent across time. The current lesson uses a small exact model so those assumptions and computations remain inspectable.
First predict where probability can move
The transition table uses rows for the previous position and columns for the next position. Under the slow-motion assumption, Left stays Left with probability 0.8 and moves to Middle with probability 0.2. It cannot jump directly to Right in one step. A transition occurs before every numbered reading.
Starting from known Left, the first prediction is therefore (0.8, 0.2, 0). For a mixed preceding belief, each destination receives contributions from all possible previous positions. Let bᵢ be the preceding probability of position i, and Tᵢⱼ the transition probability from i to j:
Read this as: the predicted probability at destination j is the sum of the preceding mass at each source i multiplied by its chance of moving to j. The bar marks a prediction before the new sensor reading. Each transition row sums to one, so this operation preserves total probability.
For a preceding belief (0.6, 0.3, 0.1), the predicted Middle probability is 0.6 × 0.2 + 0.3 × 0.8 + 0.1 × 0.2 = 0.38. The live lab shows the corresponding arithmetic for its current belief, rather than reusing this fixed worked example as though it were the live state.
Then correct using the reading
With 80% sensor accuracy, a reading reports the true position with probability 0.8 and each of the two wrong positions with probability 0.1. If the reading is Left, its likelihood is 0.8 under a Left state but only 0.1 under Middle or Right.
Take the first prediction (0.8, 0.2, 0) and a Left reading. Multiply each predicted probability by the reading likelihood to obtain unnormalized weights: (0.64, 0.02, 0). Their sum is 0.66. Divide each by this total to obtain approximately (0.9697, 0.0303, 0).
Here ℓⱼ is the probability of the current reading if the object is at j. The denominator sums the reading’s contributions across all candidate states. This is the previous lesson’s Bayesian update applied repeatedly after a motion prediction. The same reading can have different implications depending on the prediction that preceded it.
The forward algorithm alternates these two operations: predict through transitions, then multiply by observation likelihoods and normalize. The resulting filtering distribution describes the current state using evidence available up to that time. It does not use future observations to revise the past. That different task is called smoothing and is not implemented in this lab.
Compare history with only the latest reading
The navy bars use the observation history consumed so far. The red reference starts with the same initial belief and evolves it through the same number of transitions, but then uses only the current reading. It deliberately ignores earlier readings.
This same-time reference matters. Restarting from a uniform prior for every reading would change both the history and the prior assumptions. The current comparison isolates the effect of earlier observations while holding initial state, movement and elapsed time fixed.
Inspect a noisy reading that disagrees with the preceding track. A history-aware estimate can resist a misleading reading when the motion and sensor models justify doing so. It can also resist useful new evidence too strongly when those assumptions are wrong. The six-step public example is not proof that one method always wins.
Missing and impossible are different
A missing reading provides no sensor information. The lab assigns likelihood 1 to every possible state, leaving the motion prediction unchanged after normalization. Time still advances. Keeping the old belief without applying motion would ignore the object’s possible movement during the gap.
An impossible reading is different: every candidate state with positive predicted mass assigns it likelihood zero. The total evidence weight is zero, so no posterior is defined. The lab stops at that prefix. It does not silently substitute a uniform distribution, retain a misleading “corrected” belief or continue as if the observation were missing.
Try the never-move model, known Left and a supposedly perfect sensor. A Middle reading contradicts all supported possibilities. A real system would need a response such as checking the sensor, revising the state or motion model, or invoking a separately specified recovery policy. None of those is implied by dividing zero weights.
At 0% sensor accuracy in this particular model, the report is always wrong and the two other reports are equally likely. That is a defined observation mechanism, not a missing sensor. An apparently extreme control setting still needs its exact probabilistic meaning stated.
Exact inference can be confidently wrong
The authored diagnostic trajectory moves from Left to Middle at time 3. With known Left and the never-move model, all predicted probability remains on Left forever. At 80% accuracy, every reading still has some likelihood at Left, so normalization keeps the posterior at 100% Left—even when the diagnostic truth is Middle.
No approximation caused that error. The three-state update is exact for the stated model. The model excluded the movement that actually occurred in the authored example. Increasing numerical precision would not repair that assumption.
The truth-reveal control shows only the consumed portion of the authored trajectory. It never changes the inference. Editing observations creates a custom sequence and removes its diagnostic truth comparison; the app does not invent labels for learner-authored data. Changing model assumptions keeps the same public observations so a comparison does not accidentally switch the underlying example.
The prefix log-evidence score adds the natural logarithm of each conditional observation probability. It describes how probable the observed sequence is under the chosen model. It is not a direct measure of tracking accuracy or proof of a good model, especially after repeatedly choosing assumptions using the same sequence. For an impossible prefix the log probability is mathematically negative infinity; the interface records the zero-probability status and displays no finite score.
Build a tracking audit
For guided practice, predict one step, explain its likelihood-weighted correction and compare a missing reading. For implementation practice, reproduce the recurrence and independently enumerate all latent paths for a short prefix. Verify normalization and stop on impossible evidence; the exact enumeration should agree wherever conditioning is defined.
For a decision brief, distinguish a broad uncertain belief, a confident wrong belief under a bad model and a zero-probability observation. Propose what evidence would justify changing the sensor or transition assumptions before acting. Use the same observation prefix when comparing configurations and identify the public authored trace as practice.
Three temporary captures and a bounded note can be exported. There are at most sixteen observations, no automatic animation and no background work. This lesson does not train a model or grant a new project qualification. Human review and learner pilots remain pending.
An exact filter stays 100% certain of Left while the authored object moves to Middle. Its transition model forbids movement. What failed?
Take this idea with you.
Filtering repeatedly predicts through a transition model and updates from current evidence. Keep model uncertainty distinct from exactness of computation, and never treat missing or impossible evidence as an ordinary measurement.