Approximate a belief with particles.
Propagate, weight and resample possible positions. Compare a seeded particle filter with exact inference and diagnose lost diversity.
By the end: Explain particle weighting and resampling, measure approximation error, and distinguish sample depletion from model failure.
Start with something concrete.
Represent an uncertain location with eight possible positions. What happens when a sensor strongly favors a position represented by only one of your samples?
Try the interactive model ↓After resampling, several particles are identical copies of one parent. What does this mean?
Change one thing. Watch what follows.
- Step through propagation, likelihood weighting and resampling on the authored track.
- Compare weighted mass and resampled counts against the exact posterior on the same fixed axes.
- Repeat the same prefix with 8 and 128 particles, then vary the seed.
- Inspect effective sample size, parent identities and occupied states; explain their different meanings.
- Use one particle and a perfect sensor to find sample depletion while exact evidence remains possible.
- Use Never move to create agreement with an exact but wrong model. Export an audit of the distinction.
Loading this browser experiment…
A sample is a possibility
Imagine eight cards, each naming a possible location. Five say Left, two say Middle and one says Right. Counting cards gives an approximate belief: 5/8, 2/8 and 1/8. The cards represent uncertainty about one object; they are not eight objects or eight independent sensor measurements.
Each card is a particle. A particle filter carries a fixed number of these samples through time. This can help when the possible state space is too large to enumerate. Our three-position task is deliberately small enough to calculate the exact answer too. Here exact filtering is cheaper; the particles are a teaching comparison, not a speed improvement.
Entering midway? The state is hidden, the reading is noisy, and a belief distributes probability across possible states. Every step first applies motion, then uses that step’s reading. The exact filtering lesson explains the same transition and observation model.
Move each possibility, then weight the evidence
For each particle, draw its next position using the transition probabilities from its current position. With slow motion, a particle at Left has an 80% chance of staying and a 20% chance of moving to Middle. Eight independent motion draws do not guarantee exactly 80% will stay.
Suppose a predicted four-particle cloud is Left, Left, Middle, Right. The sensor reports Left with 80% accuracy, splitting its remaining 20% equally between the other positions. The particle weights are 0.8, 0.8, 0.1 and 0.1. Their sum is 1.8. Each Left particle gets normalized weight 0.8/1.8; the total Left mass is 1.6/1.8 = 88.89%. Middle and Right each get 5.56%.
Let N be the number of particles, xᵏ the predicted position of particle k, and y the current reading. Its raw weight wᵏ is the likelihood of y at xᵏ. The normalized weight αᵏ divides by the total weight:
Read this as: give more weight to hypotheses that better explain the reading, then scale weights to sum to one. To find a position’s probability, add the normalized weights of every particle there. Do not normalize over distinct positions while ignoring repeated samples.
Resample: spend samples on supported possibilities
Draw N parent particles with replacement, choosing each according to its normalized weight. Copy each selected parent’s position into the new cloud. The next step starts with these N equally weighted particles. This is multinomial resampling. It is a random allocation, not rounding probability percentages to fixed counts.
Resampling may copy one parent many times and omit others. It adds another source of sampling error. A position present before resampling may disappear afterwards. Resampling cannot invent an absent position; a later transition can restore it only if the motion model permits that move.
Losing useful hypotheses through repeated copying is called particle impoverishment. The lab reports distinct immediate parents and occupied positions separately. A concentrated true posterior may correctly occupy very few states, so fewer states alone do not prove failure. Parent counts describe the latest resampling step, not the number of independent full trajectories.
Measure concentration without confusing it with certainty
A common diagnostic is effective sample size, or ESS. With normalized weights αᵏ, its formula is:
Equal weights give ESS = N. If one particle holds all the weight, ESS = 1. For the four-particle worked example, ESS = 1.8²/(0.8² + 0.8² + 0.1² + 0.1²) ≈ 2.49. It measures weight concentration, not correctness, unique positions or new information. After resampling all weights are equal, even if many states are copies, so an apparently restored ESS does not mean lost diversity has returned.
A missing reading gives every particle weight 1. There is no sensor correction. This teaching implementation still resamples at every step, which can lose diversity unnecessarily. Practical variants may resample only when a concentration criterion is met; that policy is not implemented here.
Separate three kinds of failure
Approximation error: the finite particle cloud differs from the exact posterior under the same assumptions. The lab reports total-variation distance: add the absolute differences between the three probabilities and divide by two. Zero means the distributions agree; one means they have no overlapping probability mass. It is not a measurement of physical tracking accuracy.
Sample depletion: all sampled states have zero likelihood, but the exact model still gives the reading positive probability. With one particle, motion may miss Middle even though the model allows it. A perfect Middle reading then gives the sampled cloud zero total weight. Division cannot define a posterior. Increasing the count or changing the proposal may help future attempts, but the failed update remains a failure.
Model failure: even exact inference may exclude the actual movement. With known Left and Never move, the exact filter and every particle stay Left. They agree perfectly while the authored object moves. Increasing the sample count cannot repair the excluded dynamics. A reading with zero probability even under the exact model is an impossible-model-evidence case, distinct from finite-sample depletion.
The lab stops on either zero-weight failure and labels its cause. Some implementations reinitialize after depletion; that is a separate recovery policy with assumptions about the new prior. We deliberately do not silently restart or treat the reading as missing.
Investigate before choosing a budget
Keep the same observation prefix, initial belief and model. Compare 8 and 128 particles over several public seeds. Record both weighted and after-resampling errors. More samples generally support better approximation, but a particular larger run can still be worse by chance. Choosing the best seed is not evidence of reliable performance.
Guided learners can explain one step with counts and draw a before/after cloud. Engineers can independently implement categorical draws and resampling, testing interval boundaries, zero weights and exact comparisons on short prefixes. Managers can propose an error threshold, a repeatable evaluation and a response to lost support before allowing a tracking decision. All three can use the same temporary audit captures.
Try an unfamiliar arithmetic case without copying the example: the predicted cloud is Left, Middle, Middle, Right; a Middle reading has 60% likelihood there and 20% elsewhere. What fraction of weighted mass belongs to Middle, and can resampling introduce a fourth position?
Check this practice reasoning
The total weight is 0.2 + 0.6 + 0.6 + 0.2 = 1.6. Middle receives 1.2/1.6 = 75%. Resampling copies existing predicted states and cannot invent a fourth position. This is explained practice, not an independent project assessment.
The model supports at most 256 particles and sixteen readings; this interface uses up to six. Manual stages need no animation, background computation or GPU. Captures are temporary and exportable. Learner pilots, independent project review and broader device profiling remain pending.
The particle approximation and exact filter both assign 100% probability to Left while the object has moved. What should you investigate?
Take this idea with you.
Particle filtering approximates a belief with weighted samples and resampling. Diagnose numerical approximation separately from the model; track lost diversity and never hide a zero-weight failure.