Probability for Robotics · Theory · M6
M6-T3 — Representing Belief: Parametric and Nonparametric
The same belief can be stored as a table, as two numbers, or as a cloud of samples. Each form can say some things and not others.
Every filter in the rest of the course is the Bayes filter with a particular way of holding the belief. That choice decides what the filter can represent (one peak or several), what it costs, and how it fails. This lesson puts the three standard choices side by side on one example, derives why a single Gaussian puts probability exactly where the robot cannot be, counts how many particles are needed to keep a hypothesis alive, and ends with a rule for choosing.
Learning objectives
After this lesson, you should be able to:
- Describe grid, Gaussian and particle representations of a belief, and what each can and cannot represent.
- Derive that the best single Gaussian approximation matches the mean and covariance of the belief, and compute it for a mixture.
- Compute the probability that a particle set misses a hypothesis, and the number of particles that prevents it.
- Choose a representation for a given problem from its dimension, the number of peaks and the noise.
The intuition
Rover is in a corridor and knows it is at one of two doors: one 2 m along, the other 5 m, with equal belief and about 20 cm of uncertainty about each. Three ways to write that belief down:
- A grid (the histogram filter): divide the corridor into cells and store a probability for each. Any shape is possible, but the cell width limits how sharply a peak can be written. With 50 cm cells the two narrow peaks become blocky humps.
- A Gaussian (the Kalman filter): store a mean and a variance, two numbers. It is compact and fast. But a Gaussian has one peak. The best one can do is to put it at the average, 3.5 m, with a huge spread, 1.5 m. That is the middle of the corridor, where the robot is certainly not.
- Particles (the Monte Carlo filter): store a cloud of sample positions, each a possible truth. Forty samples already cluster around the two peaks. The cloud has no fixed shape and costs more with every sample.
The Gaussian's failure is the one to remember. The mean of a two-peaked belief is not a likely position, and a planner or a controller that takes “the estimate” to be 3.5 m will plan for a robot that is in neither place. In the figure, the Gaussian assigns 26% of the probability to the stretch between 3 and 4 m, where the true belief assigns essentially zero, and at the true position of 2 m its density is 0.16 against the correct 1.0: six times too low.
None of this makes the Gaussian bad. For a robot that has already localized, the belief is a single narrow peak, and then a Gaussian is a perfect and extremely cheap description; the Kalman filter will outperform the other two in speed and accuracy. The two-peaked situation arises in global localization, in symmetric environments, and after failures. So the choice is a question about the problem.
A representation is a bet about what the belief looks like. A Gaussian bets on one peak; a grid bets on a small number of cells; particles bet on enough samples. Choose the bet that the problem can win.
Definitions
- Parametric representation
- A belief of a fixed form described by a few numbers: a Gaussian (mean and covariance), or a mixture of Gaussians (several means, covariances and weights).
- Nonparametric representation
- A belief with no fixed form: a grid of cell probabilities, or a set of weighted samples (particles).
- Moment matching
- Choosing the Gaussian that has the same mean and covariance as the belief it replaces.
- Mode
- A peak of the belief: a hypothesis about where the robot is.
- Mixture
- A belief made from several Gaussians with weights that sum to 1.
Derivation: the best Gaussian, and how many particles
The best Gaussian matches mean and variance
Take a one-dimensional belief and approximate it by , choosing and to minimize the Kullback-Leibler divergence .
Expand the logarithm of the ratio. The first term does not depend on .
Insert the Gaussian density. Minimizing the divergence means maximizing this expression.
The best centre is the mean of , wherever that is.
The best variance is the variance of . (The same argument in several dimensions gives the covariance matrix.)
For the two-door belief. The mean falls in the gap and the variance is dominated by the distance between the modes (2.25), not by the 0.04 of each door.
This is what a Kalman filter does implicitly to any belief it cannot represent: it keeps the mean and the covariance and throws the rest away. For one peak that loses nothing; for two peaks it loses everything that mattered.
How many particles keep a hypothesis alive?
A particle is a sample of the belief, so it falls in a mode of mass with probability .
The particles are independent (the independence of the Monte Carlo lesson). For small , .
Solve for . For this is : a hypothesis of mass 5% needs about 60 particles, one of mass 1% needs 300.
A mode that a filter loses cannot be recovered by correction: there is no particle there to be reweighted. This is particle deprivation, treated in module 9.
Moment matching puts a Gaussian at the mean of the belief with the belief’s variance, even if that is where nothing is. A particle filter loses a hypothesis of mass w with probability e^(−Nw), so it needs N of the order of 3/w particles to keep it.
A worked example
The two-door belief, 0.5 N(2 m, 0.2 m) + 0.5 N(5 m, 0.2 m), represented three ways. All numbers are printed by the program below.
- Gaussian. Moment matching gives mean 3.5 m and standard deviation 1.513 m. It puts 0.259 of its probability between 3 m and 4 m, where the true belief puts less than . At the true position 2.0 m its density is 0.161 against the true belief's 0.997.
- Grid. The total variation distance between a grid belief and the true one (half the integral of the absolute difference: 0 for a perfect copy, 1 for no overlap) is 0.571 for 1 m cells, 0.303 for 0.5 m cells, 0.103 for 0.2 m cells and 0.050 for 0.1 m cells. The cell must be a fraction of the 0.2 m width of the peaks to represent them well; at 10 cm the 70 cells hold the belief with a 5% error.
- Particles. A hypothesis of mass 0.05 is missed by 20 particles with probability , by 60 with 0.046 (simulation with 10 000 particle sets: 0.048), by 100 with 0.006, by 300 with . For the two equal doors a few tens of particles suffice; for a 5% alternative, a hundred.
- Cost. A 1D corridor: 200 cells, 2 Gaussian numbers, about 100 particles. A 3D pose (x, y, heading): 7.2 million cells, 9 numbers, perhaps 1 500 numbers of particles. A 6D pose: 7 trillion cells, 27 numbers, tens of thousands of particle numbers.
import math
from robotprob import Rng, gaussian_pdf, gaussian_cdf
def truth_pdf(x): # the belief: the robot is at one of two doors, 2 m or 5 m along
return 0.5 * gaussian_pdf(x, 2.0, 0.2) + 0.5 * gaussian_pdf(x, 5.0, 0.2)
def truth_cdf(x):
return 0.5 * gaussian_cdf(x, 2.0, 0.2) + 0.5 * gaussian_cdf(x, 5.0, 0.2)
mu = 0.5 * 2.0 + 0.5 * 5.0 # the moment-matched Gaussian: mean and variance of the mixture
var = 0.5 * (0.2 ** 2 + 2.0 ** 2) + 0.5 * (0.2 ** 2 + 5.0 ** 2) - mu ** 2
sd = math.sqrt(var)
print('moment-matched Gaussian: mean', mu, ' std', round(sd, 3))
gap_fit = gaussian_cdf(4.0, mu, sd) - gaussian_cdf(3.0, mu, sd)
gap_true = truth_cdf(4.0) - truth_cdf(3.0)
print('probability between 3 and 4 m, where the robot cannot be: Gaussian', round(gap_fit, 3), ' true belief', round(gap_true, 6))
print('density at the true position 2.0 m: true belief', round(truth_pdf(2.0), 3), ' Gaussian', round(gaussian_pdf(2.0, mu, sd), 3))
def tv_grid(cell): # total variation distance between a grid belief and the true one
n = int(round(7.0 / cell))
masses = [truth_cdf((i + 1) * cell) - truth_cdf(i * cell) for i in range(n)]
step, total, x = 0.005, 0.0, 0.0
while x < 7.0:
i = min(n - 1, int((x + step / 2) / cell))
total += abs(masses[i] / cell - truth_pdf(x + step / 2)) * step
x += step
return 0.5 * total
for cell in (1.0, 0.5, 0.2, 0.1):
print('grid with', cell, 'm cells: total variation distance from the true belief', round(tv_grid(cell), 3))
for n in (20, 60, 100, 300): # the chance that n particles contain none from a mode of mass 0.05
print(n, 'particles: chance of missing a mode of mass 0.05 =', round(0.95 ** n, 4))
rng = Rng(6)
missed = 0
for _ in range(10000):
if not any(rng.random() < 0.05 for _ in range(60)):
missed += 1
print('simulated, 60 particles:', missed / 10000)
for name, cells, gauss, particles in (('1D (x)', 200, 2, 100), ('2D (x, y)', 200 * 200, 5, 500), ('3D (x, y, heading)', 200 * 200 * 180, 9, 1500), ('6D pose', 200 * 200 * 30 * 180 ** 3, 27, 30000)):
print(name.ljust(20), 'grid cells', str(cells).rjust(15), ' gaussian numbers', str(gauss).rjust(3), ' particle numbers (typical)', particles)moment-matched Gaussian: mean 3.5 std 1.513 probability between 3 and 4 m, where the robot cannot be: Gaussian 0.259 true belief 0.0 density at the true position 2.0 m: true belief 0.997 Gaussian 0.161 grid with 1.0 m cells: total variation distance from the true belief 0.571 grid with 0.5 m cells: total variation distance from the true belief 0.303 grid with 0.2 m cells: total variation distance from the true belief 0.103 grid with 0.1 m cells: total variation distance from the true belief 0.05 20 particles: chance of missing a mode of mass 0.05 = 0.3585 60 particles: chance of missing a mode of mass 0.05 = 0.0461 100 particles: chance of missing a mode of mass 0.05 = 0.0059 300 particles: chance of missing a mode of mass 0.05 = 0.0 simulated, 60 particles: 0.0481 1D (x) grid cells 200 gaussian numbers 2 particle numbers (typical) 100 2D (x, y) grid cells 40000 gaussian numbers 5 particle numbers (typical) 500 3D (x, y, heading) grid cells 7200000 gaussian numbers 9 particle numbers (typical) 1500 6D pose grid cells 6998400000000 gaussian numbers 27 particle numbers (typical) 30000
In robotics
A rule for choosing
| Situation | Representation | Why |
|---|---|---|
| A drone in flight, with a good initial estimate: attitude, velocity, biases (15 states) | Gaussian (extended or error-state Kalman filter) | One peak, many states, high rate: a grid is impossible and particles are wasteful. |
| A robot that wakes up in a building with no idea where it is | Particles (Monte Carlo localization) | Many hypotheses at the start, three states, moderate rate. A grid would also work with coarse cells; a Gaussian cannot. |
| A discrete mode: “door open / closed”, “sensor OK / stuck” | Grid (a discrete Bayes filter) | A handful of values: exact, trivial cost. |
| A target that may be one of a few hypotheses, each well described by a Gaussian | Mixture of Gaussians (multiple hypothesis tracking) | A few peaks, each narrow: cheaper than particles, and can carry the peaks separately. |
| SLAM with many landmarks | Particles for the robot path, Gaussians for each landmark (FastSLAM) | Mixes the two: the multimodal part is sampled, the landmarks are conditionally Gaussian. |
The SLAM course discusses the hybrid in Particle Filters and FastSLAM.
Reporting “the estimate” from a multimodal belief
Downstream software wants one pose. For a belief with one dominant peak the mean is fine. For a multimodal belief, the mean can be a place the robot is not: report the mode (the most likely cell or particle cluster) and, importantly, report that the belief is multimodal, so that a planner can stay still, move to disambiguate, or act safely under all hypotheses. Localization stacks expose a covariance or a particle spread for exactly this purpose, and a large one is a reason to slow down.
Switching representations
A common design starts with particles for global localization and, once the cloud has converged to one cluster, hands over to a Kalman filter for efficient tracking, switching back to particles if the covariance grows or the residuals become inconsistent. This uses each representation where it is strongest.
Dimension is the deciding factor
The number of cells grows exponentially with the dimension, the number of particles needed grows with the volume of belief that must be covered, and the Gaussian grows only quadratically. High-dimensional states, such as the full state of a flying robot or of a humanoid, almost always use Gaussian filters (often with careful treatment of rotations, module 12) or optimization over a window of recent states (module 11).
Narrow beliefs and a single Gaussian
If the belief is a narrow single peak, the Gaussian loses nothing. The practical test is the Mahalanobis residuals and consistency checks of module 7: if they stay within their expected range, the Gaussian assumption is doing no harm.
Common misconceptions
“The mean of the belief is the best estimate of the position.”
It is the best estimate in the sense of smallest expected squared error, which is meaningless if the belief has two peaks: the mean falls where the robot cannot be. Report the mode, or report the whole belief.
“Gaussians are exact for Kalman filters and approximations for particles.”
Both are approximations of the true belief. The Kalman filter is exact only for linear models with Gaussian noise, and in every other case it is an approximation of unknown quality. Particle filters are approximations that improve with the number of particles.
“More particles always helps.”
It reduces sampling noise like 1/√N and reduces the risk of losing a hypothesis, but costs linearly and cannot repair a wrong model. A thousand particles with a badly mis-specified sensor model are confidently wrong.
“A fine grid solves everything.”
The cells must also be updated, which costs time proportional to their number. A grid fine enough for a 6D pose does not fit in the memory of any computer; a coarse grid blurs the belief exactly where precision matters.
Key takeaways
- A belief can be a grid (any shape, exponential cost), a Gaussian (one peak, two numbers per dimension plus a covariance), or a particle set (any shape, cost grows with the complexity of the belief).
- The best single Gaussian for any belief has its mean and covariance. For a two-peaked belief that is a wide bell centred between the peaks, where the robot is not.
- A particle set loses a mode of mass w with probability (1 − w)^N ≈ e^(−Nw); keeping it with 95% confidence needs about 3/w particles.
- A grid needs cells smaller than the features of the belief and costs ∏ Lᵢ/Δᵢ. It is suited to low-dimensional or discrete states.
- Choose by problem: Gaussian when the belief is one peak and the state is large, particles for several hypotheses, grids for small discrete states, and report the mode or the whole belief when the belief is multimodal.
References and further reading
Each source is marked free or paid. Free to read does not mean free to reuse: the course resources page lists every source with its licence.
- S. Thrun, W. Burgard and D. Fox, Probabilistic Robotics, MIT Press, 2005, chapters 3 and 4 (Gaussian and nonparametric filters) and the comparison in chapter 8. Paid book.
- T. D. Barfoot, State Estimation for Robotics, 2nd edition, Cambridge University Press, 2024 , chapter “Nonlinear Non-Gaussian Estimation” (representing the posterior). Free to read as the author’s PDF; the book is copyrighted.
- S. Särkkä and L. Svensson, Bayesian Filtering and Smoothing, 2nd edition, Cambridge University Press, 2023 , chapters 7 to 11 (Gaussian and particle approximations). Free to read for personal use; no redistribution or derivative works.
- C. Stachniss, “Particle Filter and Monte Carlo Localization” (video lecture) . Free to watch.
- K. P. Murphy, Probabilistic Machine Learning: An Introduction, MIT Press, 2022 , chapter 6 (information theory, including KL divergence). Free to read as the draft PDF, licence CC BY-NC-ND.
Knowledge check
Three questions. Write an answer, then reveal the explanation. Your answers stay in your browser.
Question 1
A belief has two modes: 70% of the mass at 2 m and 30% at 8 m, both very narrow. What are the mean and standard deviation of the best single Gaussian? Why would a path planner that treats this as “the position” be in trouble?
Explanation
Mean = 0.7 × 2 + 0.3 × 8 = 3.8 m. Variance = 0.7 × 4 + 0.3 × 64 − 3.8² = 2.8 + 19.2 − 14.44 = 7.56 m², so σ = 2.75 m. The estimate 3.8 m is a place where the true belief has no mass: the robot is at 2 m or at 8 m. A planner that takes the Gaussian at face value would plan for a robot at 3.8 m (and, say, drive on that basis), and a collision check around 3.8 ± 2.75 would not even show that both real hypotheses exist. The planner must see the modes: report the larger one, 2 m (70%), and the fact that the belief is bimodal.
Question 2
A particle filter should keep a hypothesis of probability mass 2% alive with 95% confidence. How many particles does it need? What if the hypothesis has mass 0.2%?
Explanation
Need (1 − w)^N ≤ 0.05, so N ≥ ln 0.05 / ln(1 − w). For w = 0.02: −2.996 / −0.0202 = 148, so about 150 particles. For w = 0.002: −2.996 / −0.002002 = 1 497, so about 1 500 particles. The rule N ≈ 3/w gives 150 and 1 500. A rare hypothesis is expensive to keep alive, which is why localizers inject a few random particles on purpose (module 9) instead of trying to carry every tiny possibility.
Question 3
For each problem choose grid, Gaussian or particles and say why: (a) the attitude, velocity and sensor biases of a flying drone; (b) a delivery robot switched on in an unknown place of a large building; (c) whether a lift door is open, closed or jammed.
Explanation
(a) Gaussian (an error-state or extended Kalman filter): the belief is one narrow peak after initialisation, the state has 15 or so dimensions, and the update must run at hundreds of hertz; a grid would have astronomically many cells and particles would be wasteful. (b) Particles (Monte Carlo localization): the initial belief is spread over the whole building and has many peaks that disappear as evidence arrives, the pose is 3-dimensional, and a few thousand particles are affordable; a Gaussian cannot represent several hypotheses. (c) A grid, meaning a discrete Bayes filter: three states, so the exact filter costs three numbers and is trivial.
What’s next
Module 6 is complete: you have the filter and the three ways of storing its belief. Module 7 takes the Gaussian one and derives the Kalman filter, the exact solution when everything is linear and Gaussian.
Related content
Nothing below is required to finish this lesson.
- BeforeM6-T2: Histogram Filters and Grid Localization
Implement the Bayes filter on a discrete grid as a convolution followed by a product, and choose the grid resolution.
Other courses on this site treat neighbouring topics from their own angle:
Get notified when the next lesson and new labs are released.
One email per new lesson or lab.