Skip to the lesson
FixTheRobot Explore Robotics / Probability for Robotics / M6 Bayesian Filtering and Belief Estimation / M6-T3

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.

  • Lesson 3 of 3
  • Intermediate
  • Module 6: Bayesian Filtering and Belief Estimation
  • Theory
  • About 15 minutes to read

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.
One two-peaked belief stored as a grid, a Gaussian and a set of particlesThree plots over a corridor from 0 to 7 metres, each with the true belief drawn as an orange curve with two narrow peaks at 2 and 5 metres. Left: a grid with cells 0.5 metres wide, drawn as bars, shows broad blocky humps that do not resolve the peaks. Middle: a single Gaussian fitted by matching the mean and variance is a wide low bell centred at 3.5 metres, between the peaks where the robot cannot be, and it puts 26 percent of its mass between 3 and 4 metres. Right: forty particles shown as short vertical ticks cluster around the two peaks.01234567position (m)grid: 0.5 m cellsblurs the peaks 01234567position (m)one Gaussian: mean 3.5, σ 1.526% of its mass where the robot cannot be 01234567position (m)40 particlesboth modes found, with noise
The true belief (orange) and its three representations. The grid blurs the peaks, the Gaussian puts its centre and a quarter of its probability in the gap between them, and forty particles find both peaks, with sampling noise.

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 p(x)=∑kwk N(x;μk,σk2)p(x) = \sum_k w_k\,\mathcal{N}(x; \mu_k, \sigma_k^2)
A belief made from several Gaussians with weights wkw_k that sum to 1.
Mean and variance of a mixture
μ=∑kwk μk,σ2=∑kwk(σk2+μk2)−μ2\mu = \sum_k w_k\,\mu_k, \qquad \sigma^2 = \sum_k w_k\bigl(\sigma_k^2 + \mu_k^2\bigr) - \mu^2
The variance is the average within-mode variance plus the spread of the mode centres. For two modes of 0.2 m at 2 and 5 m: 2.29 m², a standard deviation of 1.51 m.
The best Gaussian is the moment-matched one
q∗=arg⁡min⁡q∈GaussiansKL(p ∥ q)    ⟹    μq=Ep[x],    Σq=Covp(x)q^{*} = \arg\min_{q \in \text{Gaussians}} \mathrm{KL}(p\,\|\,q) \;\;\Longrightarrow\;\; \mu_q = \mathbb{E}_p[x], \;\; \Sigma_q = \mathrm{Cov}_p(x)
KL(p‖q) = ∫ p ln(p/q) is a measure of how badly q describes p. Minimizing it over Gaussians gives the mean and covariance of p.
The chance of losing a hypothesis
P(no particle in a mode of mass w)=(1−w)N≈e−NwP(\text{no particle in a mode of mass } w) = (1 - w)^{N} \approx e^{-N w}
N independent particles, each landing in the mode with probability w. To keep the chance of loss below δ needs N ≥ ln(1/δ) / w.
Size of a grid and of a Gaussian in d dimensions
Ncells=∏i=1dLiΔi,NGaussian=d+d(d+1)2N_{\text{cells}} = \prod_{i=1}^{d} \frac{L_i}{\Delta_i}, \qquad N_{\text{Gaussian}} = d + \frac{d(d+1)}{2}
The grid grows exponentially with the dimension; a Gaussian only quadratically (a mean and a symmetric covariance). A particle set costs N × d numbers, but N must grow with the complexity of the belief.

Derivation: the best Gaussian, and how many particles

The best Gaussian matches mean and variance

Take a one-dimensional belief pp and approximate it by q=N(μ,σ2)q = \mathcal{N}(\mu, \sigma^2), choosing μ\mu and σ\sigma to minimize the Kullback-Leibler divergence KL(p ∥ q)=∫pln⁡(p/q) dx\mathrm{KL}(p\,\|\,q) = \int p \ln(p/q)\,dx.

  1. KL(p ∥ q)=∫pln⁡p dx  −  Ep[ln⁡q(x)]\mathrm{KL}(p\,\|\,q) = \int p\ln p\,dx \;-\; \mathbb{E}_p\bigl[\ln q(x)\bigr]

    Expand the logarithm of the ratio. The first term does not depend on qq.

  2. Ep[ln⁡q(x)]=−12ln⁡(2πσ2)−Ep[(x−μ)2]2σ2\mathbb{E}_p[\ln q(x)] = -\tfrac{1}{2}\ln(2\pi\sigma^2) - \dfrac{\mathbb{E}_p[(x - \mu)^2]}{2\sigma^2}

    Insert the Gaussian density. Minimizing the divergence means maximizing this expression.

  3. ∂∂μ:    Ep[x−μ]σ2=0  ⇒  μ=Ep[x]\dfrac{\partial}{\partial \mu}: \;\; \dfrac{\mathbb{E}_p[x - \mu]}{\sigma^2} = 0 \;\Rightarrow\; \mu = \mathbb{E}_p[x]

    The best centre is the mean of pp, wherever that is.

  4. ∂∂σ2:    −12σ2+Ep[(x−μ)2]2σ4=0  ⇒  σ2=Varp(x)\dfrac{\partial}{\partial \sigma^2}: \;\; -\dfrac{1}{2\sigma^2} + \dfrac{\mathbb{E}_p[(x - \mu)^2]}{2\sigma^4} = 0 \;\Rightarrow\; \sigma^2 = \mathrm{Var}_p(x)

    The best variance is the variance of pp. (The same argument in several dimensions gives the covariance matrix.)

  5. μ=0.5⋅2+0.5⋅5=3.5,σ2=0.5(0.04+4)+0.5(0.04+25)−3.52=2.29\mu = 0.5\cdot 2 + 0.5\cdot 5 = 3.5, \qquad \sigma^2 = 0.5(0.04 + 4) + 0.5(0.04 + 25) - 3.5^2 = 2.29

    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?

  1. P(a given particle lands in the mode)=wP(\text{a given particle lands in the mode}) = w

    A particle is a sample of the belief, so it falls in a mode of mass ww with probability ww.

  2. P(no particle in the mode)=(1−w)N≈e−NwP(\text{no particle in the mode}) = (1 - w)^N \approx e^{-Nw}

    The NN particles are independent (the independence of the Monte Carlo lesson). For small ww, ln⁡(1−w)≈−w\ln(1-w) \approx -w.

  3. (1−w)N≤δ  ⟺  N≥ln⁡(1/δ)−ln⁡(1−w)≈ln⁡(1/δ)w(1 - w)^N \le \delta \;\Longleftrightarrow\; N \ge \dfrac{\ln(1/\delta)}{-\ln(1 - w)} \approx \dfrac{\ln(1/\delta)}{w}

    Solve for NN. For δ=0.05\delta = 0.05 this is N≈3/wN \approx 3/w: 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.

  1. 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 10−610^{-6}. At the true position 2.0 m its density is 0.161 against the true belief's 0.997.
  2. 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.
  3. Particles. A hypothesis of mass 0.05 is missed by 20 particles with probability 0.9520=0.3580.95^{20} = 0.358, by 60 with 0.046 (simulation with 10 000 particle sets: 0.048), by 100 with 0.006, by 300 with 2×10−72\times 10^{-7}. For the two equal doors a few tens of particles suffice; for a 5% alternative, a hundred.
  4. 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
The particle counts in the last table are typical figures, not computed: the number needed depends on the problem and is found by experiment (module 9).

In robotics

A rule for choosing

Choosing a representation
SituationRepresentationWhy
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 isParticles (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 GaussianMixture of Gaussians (multiple hypothesis tracking)A few peaks, each narrow: cheaper than particles, and can carry the peaks separately.
SLAM with many landmarksParticles 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

  1. 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).
  2. 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.
  3. 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.
  4. A grid needs cells smaller than the features of the belief and costs ∏ Lᵢ/Δᵢ. It is suited to low-dimensional or discrete states.
  5. 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.

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.

Next lesson

M7-T1 — The Kalman Filter in One Dimension

Derive the scalar Kalman filter from the fusion of two Gaussians and explain the gain as a ratio of variances.

Nothing below is required to finish this lesson.

Other courses on this site treat neighbouring topics from their own angle: