Skip to the lesson
FixTheRobot Explore Robotics / Probability for Robotics / M2 Random Variables and Probability Distributions / M2-T3

Probability for Robotics · Theory · M2

M2-T3 — The Gaussian Distribution

Two numbers describe a Gaussian: where it is centred and how far a typical error reaches. Nearly every sensor model in robotics is built from them.

  • Lesson 3 of 4
  • Beginner
  • Module 2: Random Variables and Probability Distributions
  • Theory
  • About 18 minutes to read

If you remember one distribution from this course, make it the Gaussian. Range readings, encoder drift, IMU noise and position estimates are all modelled with it, and the Kalman filter works because it is the one distribution whose shape survives addition, scaling and multiplication. This lesson explains what its two parameters mean physically, what the 68-95-99.7 rule tells you about a sensor, why errors end up bell-shaped, and where the bell is a poor model.

Learning objectives

After this lesson, you should be able to:

  • Read the mean and standard deviation of a Gaussian as a centre and a typical error, and sketch the curve from them.
  • Use the 68-95-99.7 rule, z-scores and the standard normal table (or gaussian_cdf) to compute probabilities and tolerances.
  • Derive the Gaussian normalization constant and the Gaussian shape from independence and rotational symmetry.
  • Explain why the sum of many small independent errors is nearly Gaussian, and name three situations where a Gaussian is a poor model.

The intuition

Repeat the same measurement many times and plot the results. The values bunch around a centre, thin out symmetrically on both sides, and almost never lie far away. The smooth curve that describes this is the Gaussian, or normal, distribution. Two numbers are enough to draw it.

  • The mean μ\mu is the centre: where the curve peaks. A sensor whose mean error is not zero has a bias: it is wrong in the same direction every time.
  • The standard deviation σ\sigma is the width: the typical distance of a reading from the centre. It has the unit of the measurement, so a range sensor has a σ\sigma in centimetres. A smaller σ\sigma gives a taller, narrower curve; the area is always 1.
How the mean and the standard deviation shape a Gaussian, and the 68-95-99.7 ruleLeft: three bell curves. Changing the mean moves the centre, shown by a curve centred at minus 1.5 and another at 2 with the same width. A curve with a standard deviation of 0.5 is tall and narrow, one with 2 is low and wide. Right: one bell curve with the region within 1 standard deviation of the centre shaded and labelled 68 percent, the region within 2 labelled 95 percent and within 3 labelled 99.7 percent.-5-3-1135x σ = 0.5σ = 1σ = 2mean −3, σ = 1 -4-3-2-101234distance from the mean, in standard deviations 68.3%95.4%99.7%
Left: the mean slides the bell along the axis and the standard deviation stretches it. Right: the fixed shares of a Gaussian: 68.3% of the probability lies within one standard deviation of the mean, 95.4% within two and 99.7% within three.

The right-hand panel is the most useful fact in this lesson. It lets you read a sensor's data sheet. If a range sensor has σ=2\sigma = 2 cm, then about two readings in three are within 2 cm of the truth, about 19 in 20 are within 4 cm, and a reading more than 6 cm off is a one-in-370 event. Note the wording: typical distance does not mean maximum distance.

Why a bell?

The bell shape is not an arbitrary choice. Most measurement errors are made of many tiny, independent causes: thermal noise in an electronic component, small vibrations, rounding, slight air turbulence, the jitter of a clock. Each contributes a little, in a random direction, and the total is their sum. The figure below shows what happens when you add independent errors that are individually not bell-shaped at all. One uniform error is flat. The sum of two is a triangle. The sum of three is already rounded, and the sum of twelve lies almost on top of the Gaussian curve.

Adding independent errors makes the total bell-shapedFour histograms of 6000 simulated totals. The first is a single error drawn uniformly, which is flat. The second is the sum of 2 such errors, a triangle. The third is the sum of 3, rounded. The fourth is the sum of 12, which lies almost exactly on the orange Gaussian curve. Every total is rescaled to have standard deviation 1 so the shapes can be compared.-3.503.5one error-3.503.5sum of 2 errors-3.503.5sum of 3 errors-3.503.5sum of 12 errors
Totals of 1, 2, 3 and 12 independent uniform errors, each total rescaled to a standard deviation of 1. The more errors are added, the closer the shape is to the Gaussian (orange). This is the central limit theorem at work.

That behaviour is the central limit theorem: the sum of many independent small errors is approximately Gaussian, whatever the shape of the individual errors. It explains why the Gaussian is a good default, and the conditions in its statement (many, small, independent) tell you when to distrust it.

There is a second reason, a practical one. The Gaussian is the one distribution family for which the operations of a filter keep the answer inside the family. Add two independent Gaussian errors and the total is Gaussian. Multiply a Gaussian error by a constant and it is still Gaussian. Fuse two Gaussian beliefs about the same thing and the result is Gaussian. Because of this, a belief can be stored as two numbers, a mean and a variance, instead of a whole curve, and that is the Kalman filter (module 7).

Remember the three numbers 68, 95 and 99.7, with 1, 2 and 3 standard deviations. They turn a standard deviation on a data sheet into a statement about how often a reading is wrong by how much.

Definitions

Gaussian N(μ,σ2)\mathcal{N}(\mu, \sigma^2)
The distribution with mean μ\mu and variance σ2\sigma^2. We write X∼N(μ,σ2)X \sim \mathcal{N}(\mu, \sigma^2) for “XX is Gaussian with these parameters”. The second argument is the variance, the square of the standard deviation; some software expects the standard deviation instead, a classic source of errors.
Mean μ\mu
The centre of the curve and its long-run average.
Standard deviation σ\sigma
The width: the typical distance from the centre. Same unit as XX.
Variance σ2\sigma^2
The square of the standard deviation. Unit: the unit of XX squared. Variances add for independent errors; standard deviations do not.
Standard normal ZZ
The Gaussian with μ=0\mu = 0 and σ=1\sigma = 1. Its cumulative distribution is written Φ(z)\Phi(z).
z-score
z=(x−μ)/σz = (x - \mu)/\sigma: how many standard deviations xx lies from the centre. A z-score is a pure number and does not depend on the unit.
Gaussian density
f(x)=1σ2π exp⁡ ⁣(−(x−μ)22σ2)f(x) = \frac{1}{\sigma\sqrt{2\pi}}\, \exp\!\left(-\frac{(x-\mu)^2}{2\sigma^2}\right)
The exponent is −12z2-\tfrac{1}{2}z^2 with z=(x−μ)/σz = (x-\mu)/\sigma: the density falls off with the square of the z-score. The factor in front makes the area equal to 1 and gives the density the unit 1/(unit of xx).
Standardization
X=μ+σZ⟺Z=X−μσ∼N(0,1)X = \mu + \sigma Z \qquad\Longleftrightarrow\qquad Z = \frac{X - \mu}{\sigma} \sim \mathcal{N}(0, 1)
Every Gaussian probability reduces to one table: the standard normal. gaussian_cdf(x, mu, sigma) does the conversion for you.
Probability within k standard deviations
P(∣X−μ∣≤kσ)=Φ(k)−Φ(−k)P(|X - \mu| \le k\sigma) = \Phi(k) - \Phi(-k)
It does not depend on the mean or the standard deviation, only on k.
Probability that a Gaussian value lies within k standard deviations of its mean
kP(∣X−μ∣≤kσ)P(|X-\mu| \le k\sigma)Outside, one in aboutComment
10.68273a typical error
1.960.950020the usual 95% interval
20.954522
2.5760.9900100the usual 99% interval
30.9973370the “three-sigma” rule
40.9999415 800a rare event, but see the beam example below

Properties used constantly

Closure properties of the Gaussian family
OperationResultMeaning
Shift and scale: aX+baX + bN(aμ+b,  a2σ2)\mathcal{N}(a\mu + b,\; a^2\sigma^2)The centre moves like any value; the standard deviation scales by ∣a∣|a|, the variance by a2a^2.
Sum of independent: X+YX + YN(μX+μY,  σX2+σY2)\mathcal{N}(\mu_X + \mu_Y,\; \sigma_X^2 + \sigma_Y^2)Variances add. The standard deviations add in quadrature: σ=σX2+σY2\sigma = \sqrt{\sigma_X^2 + \sigma_Y^2}. Two errors of 3 cm and 4 cm combine to 5 cm, not 7 cm.
Average of nn independent copiesN(μ,  σ2/n)\mathcal{N}(\mu,\; \sigma^2/n)Standard deviation σ/n\sigma/\sqrt{n}: the reason averaging helps, and the reason for the square-root law of the Monte Carlo lesson.
Product of two Gaussian densities of the same variableproportional to a GaussianThe heart of the Kalman filter: a Gaussian belief times a Gaussian likelihood is a Gaussian (module 4).

The proofs of the sum rule and of the product rule are in M4-T1: Expectation and Variance and M4-T5: Conditioning and Fusing Gaussians.

Derivation: where the constant and the bell come from

Why the factor 1/2π1/\sqrt{2\pi}

The area under e−x2/2e^{-x^2/2} must be computed so that the density integrates to 1. There is no antiderivative in elementary functions, but the area itself has a classical closed form, found by squaring it and changing to polar coordinates.

  1. I=∫−∞∞e−x2/2 dx    ⇒    I2=∫−∞∞ ⁣∫−∞∞e−(x2+y2)/2 dx dyI = \int_{-\infty}^{\infty} e^{-x^2/2}\,dx \;\;\Rightarrow\;\; I^2 = \int_{-\infty}^{\infty}\!\int_{-\infty}^{\infty} e^{-(x^2 + y^2)/2}\,dx\,dy

    Square the integral and write it as a double integral over the whole plane, using a different name for the second variable.

  2. I2=∫02π ⁣∫0∞e−r2/2 r dr dθI^2 = \int_0^{2\pi}\!\int_0^{\infty} e^{-r^2/2}\, r\,dr\,d\theta

    Switch to polar coordinates: x2+y2=r2x^2 + y^2 = r^2 and the area element is r dr dθr\,dr\,d\theta. The extra factor rr is what makes the integral doable.

  3. ∫0∞e−r2/2 r dr=[−e−r2/2]0∞=1    ⇒    I2=2π\int_0^{\infty} e^{-r^2/2}\, r\,dr = \Bigl[-e^{-r^2/2}\Bigr]_0^{\infty} = 1 \;\;\Rightarrow\;\; I^2 = 2\pi

    The inner integral has the antiderivative −e−r2/2-e^{-r^2/2}. The angle integral is just 2π2\pi.

  4. I=2π    ⇒    ∫12π e−z2/2 dz=1I = \sqrt{2\pi} \;\;\Rightarrow\;\; \int \frac{1}{\sqrt{2\pi}}\, e^{-z^2/2}\,dz = 1

    Divide by II to normalize the standard normal. With the unit-change rule of the last lesson, X=μ+σZX = \mu + \sigma Z gives the density 1σφ(x−μσ)\tfrac{1}{\sigma}\varphi\bigl(\tfrac{x-\mu}{\sigma}\bigr), the formula above.

Why the bell: no preferred direction

Rover drops a part on a table at a target point. The landing error has a horizontal part xx and a vertical part yy. Make two assumptions that are easy to state physically, and the Gaussian is the only answer.

  1. density of the point (x,y)=f(x) f(y)\text{density of the point } (x, y) = f(x)\, f(y)

    The two components are independent and have the same shape ff (the robot is no better at one axis than the other).

  2. f(x) f(y)=g(x2+y2)f(x)\, f(y) = g(x^2 + y^2)

    There is no preferred direction: the density depends only on the distance r2=x2+y2r^2 = x^2 + y^2 from the target, for some function gg. A rotated table gives the same statistics.

  3. h(x)=ln⁡f(x)f(0)    ⇒    h(x)+h(y)=h(x2+y2)h(x) = \ln\dfrac{f(x)}{f(0)} \;\;\Rightarrow\;\; h(x) + h(y) = h\bigl(\sqrt{x^2 + y^2}\bigr)

    Put y=0y = 0 to get g(x2)=f(x)f(0)g(x^2) = f(x)f(0), substitute that back into the first line to eliminate gg, divide by f(0)2f(0)^2 and take logarithms.

  4. k(u)=h(u)    ⇒    k(x2)+k(y2)=k(x2+y2),so k(u+v)=k(u)+k(v)k(u) = h(\sqrt{u}) \;\;\Rightarrow\;\; k(x^2) + k(y^2) = k(x^2 + y^2),\quad\text{so } k(u + v) = k(u) + k(v)

    A function whose value at a sum is the sum of its values. For a continuous function this forces k(u)=−αuk(u) = -\alpha u for a constant α\alpha (the only continuous solutions are straight lines through the origin; the sign is negative so that the area is finite).

  5. f(x)=f(0) e−αx2f(x) = f(0)\, e^{-\alpha x^2}

    Undo the substitutions: h(x)=k(x2)=−αx2h(x) = k(x^2) = -\alpha x^2. This is a Gaussian with σ2=1/(2α)\sigma^2 = 1/(2\alpha), and normalization fixes f(0)f(0).

A two-dimensional error cloud with independent axes and no preferred direction must be Gaussian. That is why the round, symmetric cloud of position errors in the Kalman filter is a Gaussian, and why a cloud that is stretched along a particular direction needs a covariance matrix (module 4) instead of a single σ.

A worked example

A range sensor has a Gaussian error with μ=0\mu = 0 and σ=2\sigma = 2 cm. Five questions about it, all answered by the program below.

  1. Tolerance. How often is a reading within ±3 cm of the truth? z=3/2=1.5z = 3/2 = 1.5, so P=Φ(1.5)−Φ(−1.5)=0.8664P = \Phi(1.5) - \Phi(-1.5) = 0.8664: about 87%.
  2. Specification. A new application needs 99% of the readings within ±5 cm. For 99% two-sided the z-score is 2.576, so σ≤5/2.576=1.94\sigma \le 5/2.576 = 1.94 cm. The sensor must be slightly better than the one we have.
  3. Averaging. The mean of 16 independent readings has σ/16=0.5\sigma/\sqrt{16} = 0.5 cm. The probability that this average is within ±1 cm is z=1/0.5=2z = 1/0.5 = 2, so 0.9545. (The 16 readings must be independent; the correlation warning of the binomial lesson applies again.)
  4. The bell from nothing. Add 12 independent uniform numbers on [−0.5,0.5][-0.5, 0.5]. Each has variance 1/121/12, so the sum has variance 1 and standard deviation 1. Simulating 20 000 such sums gives mean −0.002, standard deviation 0.999, and shares within 1, 2 and 3 of 0.6807, 0.9553 and 0.9978, against the Gaussian's 0.6827, 0.9545 and 0.9973.
  5. Three sigma is routine. A scanning lidar delivers 1000 beams at 10 Hz, 10 000 readings a second. A fraction 0.0027 lies beyond 3σ even when nothing is wrong: 27 beams every second. Beyond 4σ it is still 0.63 beams a second. “More than three standard deviations” is therefore a poor definition of a faulty reading on its own.
from robotprob import Rng, gaussian_cdf, gaussian_ppf, mean, std

sigma = 0.02                                   # 2 cm, in metres
print('P(|e| <= 3 cm)          =', round(gaussian_cdf(0.03, 0.0, sigma) - gaussian_cdf(-0.03, 0.0, sigma), 4))

z = gaussian_ppf(0.995)                        # 99% two-sided leaves 0.5% in each tail
print('z for 99% two-sided     =', round(z, 3), ' sigma needed =', round(5 / z, 2), 'cm')

n = 16
s_mean = sigma / n ** 0.5                      # the average of n independent readings
print('sigma of the mean of', n, '  =', s_mean)
print('P(|mean error| <= 1 cm) =', round(gaussian_cdf(0.01, 0.0, s_mean) - gaussian_cdf(-0.01, 0.0, s_mean), 4))

rng = Rng(11)                                  # a sum of 12 uniform numbers is almost Gaussian
s = [sum(rng.uniform(-0.5, 0.5) for _ in range(12)) for _ in range(20000)]
print('sum of 12 uniforms: mean', round(mean(s), 3), 'std', round(std(s), 3))
for k in (1, 2, 3):
    print('within', k, 'sigma:', round(sum(1 for v in s if abs(v) <= k) / len(s), 4), ' Gaussian:', round(gaussian_cdf(k) - gaussian_cdf(-k), 4))

rate = 1000 * 10                               # beams per second
for k in (3, 4):
    q = 2 * (1 - gaussian_cdf(k))
    print(k, 'sigma: fraction', round(q, 6), '->', round(q * rate, 2), 'beams per second')
P(|e| <= 3 cm)          = 0.8664
z for 99% two-sided     = 2.576  sigma needed = 1.94 cm
sigma of the mean of 16   = 0.005
P(|mean error| <= 1 cm) = 0.9545
sum of 12 uniforms: mean -0.002 std 0.999
within 1 sigma: 0.6807  Gaussian: 0.6827
within 2 sigma: 0.9553  Gaussian: 0.9545
within 3 sigma: 0.9978  Gaussian: 0.9973
3 sigma: fraction 0.0027 -> 27.0 beams per second
4 sigma: fraction 6.3e-05 -> 0.63 beams per second
gaussian_cdf(x, mu, sigma) and gaussian_ppf(p) are the cumulative distribution and its inverse. The second argument of the lesson’s notation is a variance; the library, like most, takes the standard deviation.

In robotics

Reading a data sheet

Data sheets quote noise in several ways, and the first job is to find out which. “Accuracy ±3 cm” may be a guaranteed bound, a 1σ value or a 95% interval. “Noise density 0.01 °/s/√Hz” for a gyroscope means a standard deviation that grows with the measurement bandwidth. Converting to a common σ before combining sensors is basic hygiene; the UAV course shows it for inertial sensors in IMU noise and bias modelling.

Combining independent errors

A ground robot's position error at the end of a corridor is the sum of a heading error and a distance error. Each is a Gaussian, so their combination is another, with variance equal to the sum. Square, add, and take the root: this is how an error budget is computed. Errors of 3 cm, 4 cm and 12 cm give 13 cm, and shrinking the smallest ones barely helps: improve the biggest first.

Setting thresholds and gates

A fixed threshold on a measurement residual, “reject if the difference between measured and predicted range exceeds 3σ”, is the Gaussian rule in practice. The Kalman filter gates with the Mahalanobis distance, the multi-dimensional version of the z-score (M4-T3: The Multivariate Gaussian and Covariance Ellipses, M8-T2: EKF Localization with Landmarks). As the beam example showed, a 3σ gate rejects 0.27% of perfectly good measurements; whether that is acceptable is an engineering decision.

Where a Gaussian is a poor model

  • Heavy tails and outliers. A lidar beam that hits a person walking through the scan, a GPS multipath jump or a camera mismatch produces errors far beyond any Gaussian tail. Real sensor error is often a Gaussian core plus a small share of outliers; the next lesson models this.
  • Bounded quantities. A range cannot be negative and a battery level cannot exceed 100%. A Gaussian puts a little probability on impossible values; when the mean is many σ from the boundary the effect is negligible, and when it is not (a sensor reading near zero range) it matters.
  • Several modes. A robot in a corridor with three identical doors has a belief with three peaks. A single Gaussian cannot represent it, which is why module 6 begins with the histogram filter and module 9 with particles.
  • Angles. A heading is on a circle, so a Gaussian on the real line is wrong near ±180°. Module 12 treats uncertainty on angles properly.

The SLAM and Perception courses use the same normal distribution; the SLAM view of it is in Probability and Uncertainty.

Common misconceptions

“A standard deviation of 2 cm means readings are never more than 2 cm off.”

It is the typical distance, not a bound. A third of the readings are further than one standard deviation away, and one in 22 is further than two. Specify a maximum error with a probability attached: “99% within ±5 cm”.

“Two errors of 3 cm and 4 cm add up to 7 cm.”

Only if they are perfectly aligned. Independent errors add in quadrature: the combined standard deviation is √(3² + 4²) = 5 cm. The variances add, the standard deviations do not. For the average of n independent readings the error falls as 1/√n.

“Everything is Gaussian.”

The central limit theorem needs many independent, small contributions of finite spread. A bumper that is either pressed or not, an outlier from a reflective surface, a quantized count and an angle are not Gaussian. A filter that assumes it anyway is overconfident exactly when the data are strangest.

“N(0, 2) has a standard deviation of 2.”

In the usual notation the second argument is the variance, so that Gaussian has σ = √2 = 1.41. Software differs: some libraries take σ and some take σ². Check the documentation, and test with a case whose spread you know, before trusting a simulated noise level.

Key takeaways

  1. A Gaussian is fixed by its mean (the centre, the place a bias moves) and its standard deviation (a typical error, in the unit of the measurement).
  2. About 68% of values lie within 1σ, 95% within 2σ (1.96 for exactly 95%) and 99.7% within 3σ. A z-score counts standard deviations and has no unit.
  3. Independent Gaussian errors add in variance, so standard deviations combine in quadrature. The average of n independent readings has standard deviation σ/√n.
  4. Sums of many small independent errors are nearly Gaussian (the central limit theorem). A symmetric, independent two-dimensional error cloud must be Gaussian.
  5. The Gaussian is a model. It fails for outliers, bounded quantities, several modes and angles, and 3σ readings are routine when there are thousands of readings a second.

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 depth camera’s datasheet says “depth noise 1.5 cm at 3 m (1σ)”. Estimate the probability that a single reading is wrong by more than 3 cm, and the number of independent readings you would average to bring the typical error to 0.5 cm.

Explanation

A 3 cm error is 2σ, so the probability of being off by more than that in either direction is about 1 − 0.9545 = 4.6%. Averaging n independent readings gives σ/√n, so 1.5/√n = 0.5 requires √n = 3 and n = 9 readings. This assumes the errors are independent between readings; for a camera, part of the noise is a fixed pattern (bias) that is the same every frame and does not average away, so the true improvement is smaller and a calibration is also needed.

Question 2

A robot’s position error after a straight run has two independent Gaussian contributions: a 4 cm error from wheel slip and a 3 cm error from the start position. What is the standard deviation of the total, and why is it not 7 cm? What if the two errors were perfectly correlated?

Explanation

The total standard deviation is √(4² + 3²) = 5 cm, because variances of independent errors add (16 + 9 = 25 cm²) and the standard deviation is the square root. A sum of 7 cm would require the two errors to always have the same sign and size, which independent errors do not. If they were perfectly correlated (one always equal to the other, scaled), the standard deviations would add and the total would be 7 cm. Correlation changes the combination rule, which is why module 4 introduces covariance.

Question 3

Why is a Gaussian a poor model for the error of a range sensor that sometimes returns the distance to a wall behind a window, and what does that do to a filter that assumes a Gaussian?

Explanation

The window produces a wrong reading that is not a small perturbation of the truth but a different quantity entirely, many metres off, with some probability. The error distribution is a narrow Gaussian core plus a rare far-away component, so its tails are far heavier than a Gaussian’s. A filter that assumes a Gaussian assigns that reading an almost-zero likelihood, or, if it does not gate, lets it pull the estimate by an amount proportional to its enormous error, because a Gaussian model treats a huge residual as overwhelming evidence. Remedies are gating on the Mahalanobis distance, a mixture model with an explicit outlier component, or a robust loss.

What’s next

A real sensor is rarely a clean Gaussian. The next lesson separates what is in a typical sensor’s error (bias, noise, quantization and outliers) and builds models for each.

Practice this lesson

Sensor Noise Explorer

A range sensor reads a wall at a fixed distance and the readings scatter. Build the histogram, estimate bias and spread, and find the outliers a Gaussian cannot explain.

Next lesson

M2-T4 — Distributions of Real Sensor Noise

Separate bias, random noise, quantization and outliers in sensor data, and model them with uniform, exponential and mixture distributions.

Nothing below is required to finish this lesson.

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