Probability for Robotics · Theory · M11
M11-T1 — Maximum Likelihood Estimation
Choose the state that makes the readings most probable. For Gaussian noise that is least squares, and its uncertainty is the inverse of the information.
Until now we kept a belief and updated it as readings arrived. Module 11 looks at the same problems as optimisation: given all the readings, find the best state. The simplest principle is maximum likelihood: choose the state that makes the data most probable. This lesson derives it, shows that under Gaussian noise it is least squares, solves a position estimate from ranges by Gauss–Newton, and uses the Fisher information to say how accurate any such estimate can be.
Learning objectives
After this lesson, you should be able to:
- Define the likelihood and the maximum likelihood estimate, and derive the MLE of a Gaussian mean and variance.
- Show that maximum likelihood with Gaussian noise is (weighted) least squares, and solve it by Gauss–Newton.
- Compute the Fisher information and the Cramér–Rao bound, and read the uncertainty ellipse of an estimate.
- Explain why geometry (the placement of landmarks) decides accuracy, and why the 1/n variance estimate is biased.
The intuition
A robot measures its distance to three landmarks and gets three noisy numbers. The true position is the one that would have produced those distances; the readings do not quite agree, so there is no point that fits all three. The maximum likelihood estimate is the point that makes the observed readings most probable: for each candidate position, compute the probability of the three readings (the likelihood), and take the best.
If the noise is Gaussian, the probability of a reading falls off with the square of its error, so maximising the likelihood is the same as minimising the sum of squared errors, each divided by its variance: the familiar least-squares fit.
The left panel repeats the experiment 2 000 times (400 shown) for each of two layouts. When the landmarks surround the robot, the estimates form a round cloud of standard deviation 8.5 and 8.1 cm in x and y: three readings of 10 cm each combine into something slightly better than one. When the landmarks are all on one side, the cloud is stretched: 16 cm in x, 6.7 cm in y. The reason is geometry: a range to a distant landmark only tells you the position along the line to it, and when the three lines are nearly parallel nothing constrains the direction across them. The ellipses are not fitted to the clouds. They are computed from the Jacobian alone, before any data, by the Cramér–Rao bound, and they match: 0.084 and 0.082 against 0.085 and 0.081.
The right panel is a warning that the best-known estimator has a flaw. The maximum likelihood estimate of a variance divides the sum of squares by n, and it is biased low: by −σ²/n. With 3 readings and a true variance of 4 it is wrong by −1.31 on average, and with 50 readings by −0.07. Dividing by n − 1 removes the bias (the measured bias of that version is 0.04, −0.01, 0.00 and 0.01).
Maximum likelihood turns estimation into optimisation: write the negative log-likelihood, minimise it. With Gaussian noise it is a weighted sum of squares, and the curvature at the minimum is the information about the state.
Definitions
- Likelihood
- read as a function of the parameters with the data fixed. It is not a probability distribution over .
- Maximum likelihood estimate
- .
- Residual
- : the reading minus the reading the state would give.
- Fisher information
- : the expected curvature of the log-likelihood; for Gaussian noise .
- Cramér–Rao bound
- The covariance of any unbiased estimator is at least . The MLE reaches it as the number of readings grows (for Gaussian noise with linear models, exactly).
Derivation: Gaussian MLE, least squares, and the bound
The Gaussian mean and variance
For independent readings :
The log of the product of Gaussian densities: independent readings multiply, so their logs add.
Setting the derivative to zero gives the sample mean.
The MLE of the variance divides by n.
Because was fitted to the same data, the residuals are smaller than the true deviations. The expectation is : a bias of .
Least squares and Gauss–Newton
With Gaussian noise , the log-density is a quadratic in the residual. Minimising it is the least-squares problem.
Linearise the residuals () around the current estimate: the same first-order step as the EKF.
A linear weighted least-squares problem: the normal equations. Solve, update, repeat. Near the solution the convergence is quadratic for small residuals.
The information and the bound
The Hessian of the quadratic negative log-likelihood is (Gauss–Newton ignores the residual-curvature term, which has expectation zero at the truth).
To first order the estimation error is a linear function of the noise, so it is Gaussian with covariance equal to the inverse information. This is the Cramér–Rao bound, attained.
Information adds across independent readings, the same additivity as the precisions of the fusion lesson of Module 4.
Geometry
For a range to a landmark in direction from the robot, and . Each landmark adds information only along its own direction. Three landmarks in widely different directions give a well-conditioned ; three almost in the same direction give a nearly singular one, with a small eigenvalue along the unconstrained direction: the long axis of the orange ellipse. The ratio of the standard deviations is the same geometric dilution of precision that GPS engineers quote.
MLE is optimisation; its covariance comes for free as the inverse of the Gauss–Newton matrix JᵀR⁻¹J. The weights R⁻¹ matter: they are what makes the estimate the maximum likelihood and the covariance the right one.
A worked example
Two programs.
- Gaussian MLE. Readings of a quantity with true variance 4.0, 20 000 trials per n. The 1/n variance has an average error of −1.309 for n = 3, −0.809 for n = 5, −0.400 for n = 10 and −0.072 for n = 50: −σ²/n = −1.33, −0.8, −0.4 and −0.08. The 1/(n−1) version has errors of 0.036, −0.011, −0.001 and 0.008, all within the noise of the experiment.
- Position from three ranges. A robot at (4, 3) with 10 cm of noise on each range, estimated by Gauss–Newton from a start 0.7 m away; 2 000 trials. Landmarks spread around: standard deviations 0.085 and 0.081 against the bound 0.084 and 0.082, correlation −0.14. Landmarks on one side: 0.160 and 0.067 against 0.160 and 0.065, correlation 0.30. The bound predicts the scatter in both cases.
- Interpretation. The one-sided layout makes the x error twice as large as the y error because the landmarks, all in the +y direction, constrain y directly and x only through the small angular differences. The root-mean-square position error is 0.117 m for the spread layout and 0.173 m for the one-sided one, although the sensor is the same.
import math
from robotprob import Rng, mean, variance, solve, matmul, transpose, matvec, inverse, sample_mvn
# 1. the maximum likelihood estimates of a Gaussian: the sample mean, and a variance with 1/n
print('n bias of the 1/n variance bias of the 1/(n-1) variance (true variance 4.0, 20000 trials)')
for n in (3, 5, 10, 50):
rng = Rng(n)
a, b = [], []
for _ in range(20000):
xs = [rng.gauss(10.0, 2.0) for _ in range(n)]
a.append(variance(xs, ddof=0)); b.append(variance(xs, ddof=1))
print(str(n).rjust(3), str(round(mean(a) - 4.0, 3)).rjust(16), str(round(mean(b) - 4.0, 3)).rjust(28))
# 2. maximum likelihood position from ranges to landmarks, found by Gauss-Newton, against the Cramer-Rao bound
def locate(landmarks, ranges, sigma, x0):
x = list(x0)
for _ in range(20):
J, r = [], []
for (lx, ly), z in zip(landmarks, ranges):
d = math.hypot(x[0] - lx, x[1] - ly)
J.append([(x[0] - lx) / d / sigma, (x[1] - ly) / d / sigma]) # the rows are scaled by 1/sigma: weighted least squares
r.append((z - d) / sigma)
JT = transpose(J)
step = solve(matmul(JT, J), matvec(JT, r))
x = [x[0] + step[0], x[1] + step[1]]
if abs(step[0]) + abs(step[1]) < 1e-9: break
return x, matmul(JT, J)
true_pos, sigma = (4.0, 3.0), 0.1
setups = {'landmarks spread around': [(0.0, 0.0), (10.0, 0.0), (5.0, 9.0)],
'landmarks all on one side': [(0.0, 9.0), (3.0, 9.5), (6.0, 9.0)]}
print('MLE of a position from 3 range readings (noise 0.1 m), 2000 trials each')
print('geometry std x std y Cramer-Rao std x, y rms error corr(x, y)')
for name, lm in setups.items():
rng = Rng(21)
est = []
for _ in range(2000):
z = [math.hypot(true_pos[0] - lx, true_pos[1] - ly) + rng.gauss(0.0, sigma) for lx, ly in lm]
x, info = locate(lm, z, sigma, (true_pos[0] + 0.5, true_pos[1] - 0.5))
est.append(x)
ex, ey = [e[0] for e in est], [e[1] for e in est]
_, info = locate(lm, [math.hypot(true_pos[0] - lx, true_pos[1] - ly) for lx, ly in lm], sigma, true_pos)
crb = inverse(info)
sx, sy = math.sqrt(variance(ex)), math.sqrt(variance(ey))
cxy = sum((a - mean(ex)) * (b - mean(ey)) for a, b in zip(ex, ey)) / (len(ex) - 1) / (sx * sy)
rms = math.sqrt(mean([(a - true_pos[0]) ** 2 + (b - true_pos[1]) ** 2 for a, b in est]))
print(name.ljust(26), str(round(sx, 3)).rjust(6), str(round(sy, 3)).rjust(7), ' ', (round(math.sqrt(crb[0][0]), 3), round(math.sqrt(crb[1][1]), 3)), str(round(rms, 3)).rjust(12), str(round(cxy, 2)).rjust(9))n bias of the 1/n variance bias of the 1/(n-1) variance (true variance 4.0, 20000 trials) 3 -1.309 0.036 5 -0.809 -0.011 10 -0.4 -0.001 50 -0.072 0.008 MLE of a position from 3 range readings (noise 0.1 m), 2000 trials each geometry std x std y Cramer-Rao std x, y rms error corr(x, y) landmarks spread around 0.085 0.081 (0.084, 0.082) 0.117 -0.14 landmarks all on one side 0.16 0.067 (0.16, 0.065) 0.173 0.3
locate is Gauss–Newton: the Jacobian rows are divided by σ and the residuals too, which makes the normal equations the weighted ones. The matrix JᵀJ it returns is the Fisher information, and its inverse the Cramér–Rao covariance.In robotics
Everywhere a state is fitted to data
Maximum likelihood is the principle behind calibration (camera intrinsics by reprojection error, IMU biases), trilateration with UWB or range beacons, bundle adjustment, scan matching (ICP minimises squared distances, a least-squares fit) and the front end of every SLAM system. The SLAM course builds on it in its optimisation lessons.
Reading the information matrix
- The eigenvectors of are the axes of the uncertainty ellipse; the eigenvalues are the variances along them.
- A small eigenvalue of (a large one of the covariance) marks a direction that the data barely constrain: a weakly observable direction (Module 7). The solver converges slowly and noise is amplified in that direction.
- A zero eigenvalue means a gauge freedom or an unobservable state, as for the sum of two constants in Module 7. It must be fixed by a prior or an anchor.
Design before data
Since the bound depends only on the Jacobian and the noise, it can be computed before building the system: how many beacons, where to put them, which sensors to add. It gives the best that any estimator can do, which is also the benchmark to compare an implementation against: an estimator whose scatter is far above the bound has a bug or a model error.
Practical points about Gauss–Newton
- Start from a reasonable estimate (an odometry guess). A bad start can converge to a local minimum, or diverge.
- Add damping (Levenberg–Marquardt) when the step is too long: .
- Use the covariance in the weights: readings with different noise must be weighted by their own R, not equally.
- Check the Jacobian against finite differences, as for the EKF.
Common misconceptions
“The likelihood is the probability of the parameters.”
It is the probability of the data as a function of the parameters. It does not integrate to one over θ and says nothing about which parameters are likely until a prior is added (next lesson).
“The MLE is unbiased.”
Often only asymptotically. The MLE of a Gaussian variance divides by n and is biased by −σ²/n; with 3 readings it is 33% too small. The unbiased version divides by n − 1.
“Least squares is a heuristic.”
It is the maximum likelihood estimate when the noise is Gaussian, and then it comes with its covariance. With heavy-tailed noise it is not optimal (the robust losses of lesson 4).
“More readings always shrink the uncertainty equally in every direction.”
Information adds along the directions the readings measure. Adding readings from the same direction does nothing for the perpendicular one. The one-sided landmark layout is stuck at 16 cm in x however many ranges are taken from the same side.
Key takeaways
- Maximum likelihood chooses the state that makes the data most probable: minimise the negative log-likelihood.
- For Gaussian noise this is weighted least squares: Σ rᵀR⁻¹r. Gauss–Newton solves it by repeated linearisation: JᵀR⁻¹J Δ = JᵀR⁻¹ r.
- The Fisher information JᵀR⁻¹J is the curvature of the objective, and its inverse is the covariance of the estimate: the Cramér–Rao bound, which the experiments met (0.085 against 0.084).
- Geometry decides accuracy: landmarks in similar directions leave one direction poorly known (16 cm against 6.7 cm). The bound can be computed before any data.
- The MLE of a variance has bias −σ²/n; divide by n − 1 for small samples.
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, section 3.2 for the relation with the information form, and chapter 11 on SLAM as least squares. Paid book.
- T. D. Barfoot, State Estimation for Robotics, 2nd edition, 2024 , chapter 2 (primer on probability: the MLE, Fisher information and the Cramér–Rao bound) and chapter 4. Free to read as the author’s PDF; the book is copyrighted.
- Y. Bar-Shalom, X. R. Li and T. Kirubarajan, Estimation with Applications to Tracking and Navigation, Wiley, 2001, chapter 2 (the Cramér–Rao lower bound) and chapter 3. Paid book.
- C. Stachniss, “Graph-based SLAM using Pose Graphs” (video lecture) , which uses this least-squares view. Free to watch.
Knowledge check
Three questions. Write an answer, then reveal the explanation. Your answers stay in your browser.
Question 1
Five readings of a distance are 2.1, 1.9, 2.0, 2.2 and 1.8 m. Give the ML estimate of the mean and the variance, and the unbiased variance.
Explanation
The mean is (2.1 + 1.9 + 2.0 + 2.2 + 1.8)/5 = 2.0 m. The squared deviations are 0.01, 0.01, 0, 0.04 and 0.04, which sum to 0.10. The ML variance is 0.10/5 = 0.020 m² (standard deviation 0.141 m); the unbiased estimate divides by 4: 0.025 m² (0.158 m). With so few readings the two differ by 25%, which is the (n − 1)/n factor.
Question 2
A robot measures its distance to a single landmark 10 m away in the +y direction, with noise σ = 0.1 m. What is the Fisher information matrix for the position (x, y) and what does it say?
Explanation
The Jacobian of the range is the unit vector to the landmark, (0, 1) (up to sign). So J^T J / σ² = [[0, 0], [0, 100]]. The information is 100 per m² in y (a standard deviation of 0.1 m) and zero in x: one range tells nothing about the position across the line of sight. The matrix is singular, so the covariance in x is unbounded. A second landmark in another direction adds information along its own direction and makes the matrix invertible.
Question 3
In the one-sided layout the x standard deviation is 16 cm and the y standard deviation 6.7 cm. A colleague proposes averaging more ranges to the same three landmarks. How much will x improve with 4 times more readings, and what would help more?
Explanation
Averaging four times more readings halves every standard deviation: x goes from 16 to 8 cm and y from 6.7 to 3.4 cm. It improves both in proportion, so x remains twice as bad as y. What helps more is changing the geometry: a landmark seen from a different direction (for example, on the left or right side) adds information along x and brings the x standard deviation down much faster than repeating the same readings. The Cramér–Rao bound can be recomputed for the candidate position before installing anything.
What’s next
Maximum likelihood ignores what we knew before the readings. The next lesson adds a prior, which turns the estimate into a MAP estimate, and shows that the Kalman filter is exactly this kind of problem solved recursively.
Related content
Nothing below is required to finish this lesson.
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.