Chapter 68: probability tools

Probability Tools for Localization Random variables, distributions, the bell curve and Bayes rule, built from dice and coins

Chapter 67 showed why a robot is never sure where it is and introduced probability, a number between 0 and 1 for how likely something is. This page adds the tools needed to work with those probabilities: random variables, combining two events, the mean and the spread, the bell curve, the total probability rule and Bayes rule. Every symbol is explained in words before it is used, and every formula is shown with real numbers. The last section explains why real sensors are noisy.

Words used on this page (open this if a word is new)
random experimentSomething whose result is decided by chance, like rolling a die.
random variable, XThe set of possible results of a random experiment.
outcomeOne possible result.
P(X)The probability of X: a number from 0 (impossible) to 1 (certain).
independent eventsEvents that do not change each other's probability.
dependent eventsEvents where knowing one changes the probability of the other.
P(Y | X)The probability of Y given X: how likely Y is once X is known to have happened.
∩ (and)Both events happen. P(X ∩ Y) is the probability of X and Y.
∪ (or, union)All the places that belong to either set.
probability distributionA list or curve that gives the probability of every possible value.
uniform distributionA flat distribution: every value has the same probability.
mean (expected value)The most common value: add up value × probability.
variance, σ²How far values are from the mean: add up (distance)² × probability.
standard deviation, σThe square root of the variance. A measure of spread.
Gaussian (normal distribution)The symmetric bell curve described by a mean μ and a standard deviation σ.
μ (mu)The mean: the middle of the bell.
total probability ruleAdd up the probability of an event through each piece of a split world.
priorThe first guess, before the new reading.
likelihoodHow likely the reading is if the guess were true.
marginalHow likely the reading is overall.
posteriorThe updated guess after the reading.
noiseAn unwanted random fluctuation added to a sensor signal.
01

Random variables

A random experiment is something whose result is decided by chance, like a die roll or a coin toss. Before it happens, only the list of possible results is known. Use Next and Back, the sliders and the buttons. Point at a coloured word to light up its part of the picture.

Key idea. A random variable is the set of possible results of a random experiment, for example X = {1, 2, 3, 4, 5, 6} for a die. Every value has a probability between 0 and 1 (0 impossible, 1 certain), and the probabilities of all values add up to 1.

Quick check

02

Two experiments: independent and dependent events

A coin and a die do not affect each other. A robot position and a rock detector do. The way to combine their probabilities is different. Use Next and Back, the sliders and the buttons. Point at a coloured word to light up its part of the picture.

Key idea. Independent events: P(both) = P(first) × P(second). Dependent events: P(X and Y) = P(X) × P(Y given X). Turned around: P(Y given X) = P(X and Y) ÷ P(X). The bar | means given, and ∩ means and.

Quick check

03

Probability distributions

A probability distribution lists the probability of every possible result. Its shape shows at a glance which results are likely. Use Next and Back, the sliders and the buttons. Point at a coloured word to light up its part of the picture.

Key idea. A distribution gives the probability of every value of a random variable. One die gives a flat (uniform) distribution, 1 ÷ 6 for each face. The sum of two dice is not flat: 7 has 6 ways and 2 has 1 way, so 7 is six times as likely. A uniform distribution is the natural starting guess when nothing is known.

Quick check

04

The mean and the spread

Two numbers describe a distribution: where its middle is (the mean), and how far the values are spread around it (the standard deviation). They are built here in small steps from the sum of two dice, one idea at a time, and the last step says why they are needed. Use Next and Back, the sliders and the buttons. Point at a coloured word to light up its part of the picture.

Key idea. The mean (expected value) is the most likely outcome: add up (value × probability). The spread is built in three small steps: the distance from the mean (value − mean), squared so that left and right do not cancel, times the probability and added up: that is the variance. Its square root is the standard deviation σ, back in plain units. For the sum of two dice: mean 7, variance 5.83, σ 2.42. A big σ means a lot of uncertainty, a small σ little.

Quick check

05

The Gaussian: the bell curve

Add up many random pieces and the shape of the result becomes a smooth bell. This curve, the Gaussian or normal distribution, is described by only two numbers. The steps below first stay with the two dice of section 4 and build the bell from its two numbers, then leave the dice for other bells. Use Next and Back, the sliders and the buttons. Point at a coloured word to light up its part of the picture.

Key idea. A Gaussian is fixed by its mean μ (the middle, the most likely value) and its standard deviation σ (the spread). Changing μ slides the bell, changing σ makes it tall and thin or low and wide. Its height depends on z, the number of σ-steps from the mean. The area under the whole curve is 1. A tall thin bell means little uncertainty.

Quick check

06

Combining Gaussians

Gaussians are easy to combine. Multiplying two curves is what happens when a new reading arrives, and adding two curves is what happens when the robot moves. Each gives another Gaussian with simple formulas for the new mean and spread. Use Next and Back, the sliders and the buttons. Point at a coloured word to light up its part of the picture.

Key idea. The product of two Gaussians is another Gaussian: μ = (σB² × μA + σA² × μB) ÷ (σA² + σB²) and 1 ÷ σ² = 1 ÷ σA² + 1 ÷ σB². The sum of two Gaussians is also a Gaussian: μ = μA + μB and σ² = σA² + σB².

Quick check

07

The total probability rule

Sometimes the probability of an event is hard to find directly but easy to find piece by piece. Split the world into regions, work out each piece, and add. Use Next and Back, the sliders and the buttons. Point at a coloured word to light up its part of the picture.

Key idea. Cut the park B into regions that cover everything without overlapping, so their probabilities add up to 1. Then P(A) = P(A given B1) × P(B1) + P(A given B2) × P(B2) + P(A given B3) × P(B3).

Quick check

08

Bayes rule: update with new evidence

After a new reading, how should an old guess change? Bayes rule is the exact recipe. It is built here from areas, using the product rule of section 2 and the total probability rule of section 7. Use Next and Back, the sliders and the buttons. Point at a coloured word to light up its part of the picture.

Key idea. P(A given yes) = P(yes given A) × P(A) ÷ P(yes): posterior = likelihood × prior ÷ marginal. A reading that fits a place raises it, one that does not fit lowers it. The posterior of one reading becomes the prior of the next, so the guess improves with every reading.

Quick check

09

Sensor noise

Why is any of this needed? Real sensors are not perfect, and the encoders in the simulation have been perfect so far. This section shows what a real sensor does and why the tools of this page are needed. Use Next and Back, the sliders and the buttons. Point at a coloured word to light up its part of the picture.

Key idea. Noise is an unwanted random fluctuation added to a sensor signal. It comes from the sensor itself (such as temperature) and from the cables and electronics. A noisy reading is the clean value plus a random number, so the readings have a mean (near the clean value) and a σ (the size of the noise). That is why a probabilistic approach is needed.

Quick check

10

Summary and quiz

Key takeaways

  1. A random variable is the set of possible results of a random experiment. Each value has a probability from 0 (impossible) to 1 (certain), and all of them add up to 1.
  2. Loaded coin: if heads has probability 0.6, tails has 1 − 0.6 = 0.4.
  3. Independent events multiply: heads and a 2 on a die is 1 ÷ 2 × 1 ÷ 6 = 1 ÷ 12.
  4. Dependent events: P(X and Y) = P(X) × P(Y given X). With P(A) = 0.5 and P(rock detected given A) = 0.8, both together is 0.4.
  5. A distribution gives the probability of every value. One die is flat (uniform); the sum of two dice has its peak at 7, six times as likely as 2.
  6. Mean = add up value × probability (7 for two dice). Variance = add up (value − mean)² × probability (5.83). Standard deviation = √variance (2.4).
  7. A Gaussian is fixed by its mean and standard deviation, and the area under it is 1. A tall thin bell means little uncertainty.
  8. Multiplying two Gaussians gives a narrower Gaussian; adding two gives a wider one. Both have simple formulas for the new mean and σ.
  9. Total probability: P(A) = P(A given B1) × P(B1) + P(A given B2) × P(B2) + P(A given B3) × P(B3).
  10. Bayes rule: P(A given B) = P(B given A) × P(A) ÷ P(B). With prior 0.5, likelihood 0.8 and marginal 0.5 the posterior is 0.8.
  11. Real sensors have noise: the clean value plus a random number. The next lab adds a random process to the simulated encoder to make it realistic.

Quiz