Foundations to Frontier
Tests
A. Mathematical Foundations › A4 Probability Theory › Basics

Bayes' Theorem

Bayes' theorem reverses a conditional: from how likely the evidence is under each explanation to how likely each explanation is given the evidence. Posterior ∝ likelihood × prior. In odds form, evidence multiplies odds by a likelihood ratio. Applied recursively it becomes the Bayes filter that localizes robots, and as Bayesian search theory it has found lost submarines and aircraft. Base rates are where most intuition goes wrong.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Turning evidence around

A test for a rare illness catches 99% of sick people and wrongly flags only 5% of healthy people. You test positive. Are you probably sick? Most people say yes. But picture 1000 people where only 10 are sick. The test flags about 10 of the sick and about 50 of the 990 healthy. Of 60 positives, only 10 are sick, which is 1 in 6.

Bayes’ theorem is the rule that does this “turning around” correctly. How surprising the evidence is under each explanation, weighed by how common each explanation was to begin with (the base rate), gives the new probabilities.

Bayes with 1000 people: why a good test can still mislead
● sick, tests + : 10
● sick, tests − : 0
● healthy, tests + : 50
● healthy, tests − : 940
P(sick | +) = TP / (TP + FP) ≈ 10 / 60 = 0.167
exact Bayes: 0.1667 · likelihood ratio sens/(1−spec) = 19.8
after 1 positive test: P(sick) = 0.010 → 0.167
When the condition is rare, the few true positives are outnumbered by false positives from the many healthy people. Each independent positive multiplies the odds by the likelihood ratio: yesterday's posterior is today's prior.
Why engineers care

A Mars rover deciding “is this a rock or a shadow?”, a robot working out where it is from a door it just saw, and a search team deciding which ocean square to search next all run Bayes’ theorem, many times a second.

📝 Quick check (Level 0)
0/3 answered
  1. 1. 10 sick + 50 false alarms test positive. P(sick | +) ≈ ?
  2. 2. The 'base rate' is…
  3. 3. Bayes' theorem updates…

Level 1: Beginner

★★☆☆☆ Basic⏱ 15 minSecondary-school mathematics: arithmetic and elementary algebra.

The formula

From P(H∩E)=P(E∣H)P(H)=P(H∣E)P(E)P(H\cap E) = P(E\mid H)P(H) = P(H\mid E)P(E):

P(H∣E)=P(E∣H) P(H)P(E),P(E)=∑iP(E∣Hi)P(Hi)P(H\mid E) = \frac{P(E\mid H)\,P(H)}{P(E)}, \qquad P(E) = \sum_iP(E\mid H_i)P(H_i)
Term Name Meaning
P(H)P(H) prior belief before the evidence
P(E∣H)P(E\mid H) likelihood how well HH predicts EE
P(E)P(E) evidence normalizer (total probability)
P(H∣E)P(H\mid E) posterior belief after the evidence

The diagnostic test: P(D∣+)=0.99×0.010.99×0.01+0.05×0.99≈0.167P(D\mid+) = \frac{0.99\times0.01}{0.99\times0.01 + 0.05\times0.99}\approx0.167.

Odds form: P(H∣E)P(¬H∣E)=P(H)P(¬H)×P(E∣H)P(E∣¬H)⏟likelihood ratio\frac{P(H\mid E)}{P(\neg H\mid E)} = \frac{P(H)}{P(\neg H)}\times\underbrace{\frac{P(E\mid H)}{P(E\mid\neg H)}}_{\text{likelihood ratio}}. The test’s likelihood ratio is 0.99/0.05=19.80.99/0.05 = 19.8. Prior odds of 1:99 become 19.8:99, which is about 1:5.

📝 Quick check (Level 1)
0/3 answered
  1. 1. Prior 0.5, sensitivity = specificity = 0.9. P(D | +) = ?
  2. 2. Likelihood ratio of a 99%-sensitive, 95%-specific test?
  3. 3. Prior probability 0.2 as odds?

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 40 minUndergraduate students and practising engineers.

Recursive Bayes: today’s posterior is tomorrow’s prior

If pieces of evidence E1,E2,…E_1, E_2, \dots are conditionally independent given HH, updating one at a time gives the same answer as updating on all at once. The order doesn’t matter (Practice Code 4).

  • Two independent positive tests take the disease probability from 1% to about 80%.
  • In odds form, each piece of evidence multiplies by its likelihood ratio.
  • In log-odds form, evidence adds. That’s why logistic regression’s logits are additive “evidence” (A3.3-4).

Monty Hall, by Bayes

You pick door 1 and the host, who knows where the car is, opens door 3 to show a goat. The likelihoods of “host opens 3” are: ½ if the car is behind 1, 1 if behind 2, and 0 if behind 3. With uniform priors the posterior is ⅓ for door 1 and ⅔ for door 2, so switch. The host’s action is evidence because it depends on where the car is.

The discrete Bayes filter

A robot in a corridor alternates two steps:

  • sense: multiply its belief by the measurement likelihood, then normalize (Bayes);
  • move: convolve its belief with the motion model (total probability).

From a uniform prior, a few door sightings concentrate the belief on the true position. This is Markov localization (Thrun, Burgard and Fox, 2005; Practice Code 5). Kalman filters (Gaussian beliefs) and particle filters (sampled beliefs) are the same recursion with different representations.

🐍 Exercise 1: base rates, likelihood ratios and sequential updates
Implement Bayes for diagnostic tests (positive and negative results), the odds form with likelihood ratios, and sequential updating. Check that two positives move a 1% prior to about 80%, and that the order of evidence doesn't matter.
📝 Quick check (Level 2)
0/3 answered
  1. 1. Prior 0.2 and likelihood ratio 4. Posterior = ?
  2. 2. In Monty Hall, switching wins with probability…
  3. 3. A Bayes filter's 'move' step uses…

Level 3: Advanced

★★★★☆ Advanced⏱ 40 minGraduate level, with full derivations and proofs.

Derivation and the sequential identity

Bayes. Write P(H∩E)P(H\cap E) both ways with the chain rule, then divide by P(E)P(E). Expand P(E)P(E) by total probability. ∎

Sequential = batch. Suppose P(E1,E2∣H)=P(E1∣H)P(E2∣H)P(E_1, E_2\mid H) = P(E_1\mid H)P(E_2\mid H) for each hypothesis. Then

P(H∣E1,E2)∝P(E2∣H)P(E1∣H)P(H)∝P(E2∣H) P(H∣E1)P(H\mid E_1,E_2)\propto P(E_2\mid H)P(E_1\mid H)P(H)\propto P(E_2\mid H)\,P(H\mid E_1)

So updating with E2E_2 from the posterior after E1E_1 gives the batch answer. ∎

Without conditional independence (two tests sharing the same error source), sequential multiplication double counts evidence and produces overconfident posteriors. The same thing happens in sensor fusion with correlated noise (A4.1-2).

What priors do

  • A zero prior can never be revived. If P(H)=0P(H) = 0, then P(H∣E)=0P(H\mid E) = 0 for any evidence. That’s Cromwell’s rule: don’t assign 0 to anything you can’t rule out.
  • With much data, the likelihood dominates and reasonable priors give similar posteriors. Formally, posterior concentration follows from the Bernstein–von Mises theorem (A4.3).
  • With little data, priors matter, and that’s when Bayesian reasoning helps most: rare events, few experiments, expensive tests.

Bayes vs the Neyman–Pearson view

“P(evidence | innocent) is tiny, so they’re guilty” confuses P(E∣H)P(E\mid H) with P(H∣E)P(H\mid E). That’s the prosecutor’s fallacy, which contributed to wrongful convictions such as R v. Clark (1999–2003). A p-value is a probability of data under a hypothesis, not of the hypothesis (C2).

Exercise 3.1: Use the odds form to find the likelihood ratio needed to move a 1% prior to 50%

The prior odds are 1/991/99 and the target odds are 1. So the evidence must have LR=99\text{LR} = 99. For example, two tests with LR ≈10\approx10 each.

📝 Quick check (Level 3)
0/3 answered
  1. 1. Sequential updating equals batch updating if the evidence is…
  2. 2. A prior of exactly 0 gives a posterior of…
  3. 3. The prosecutor's fallacy confuses…

Level 4: Expert

★★★★★ Expert⏱ 45 minResearchers: original papers and open problems.

Bayesian search theory

To find a lost object, split the area into cells with prior probabilities pip_i (from drift models, last known position, expert scenarios) and detection probabilities qiq_i (terrain, depth, sensor). Search the cell that maximizes piqip_iq_i. After an unsuccessful search of cell jj, Bayes gives

pj←pj(1−qj)1−pjqj,pi←pi1−pjqj (i≠j)p_j\leftarrow\frac{p_j(1-q_j)}{1 - p_jq_j}, \qquad p_i\leftarrow\frac{p_i}{1 - p_jq_j}\ (i\ne j)

Failure is evidence. The method (Koopman, 1946; Stone, 1975) located the H-bomb lost off Palomares (1966) and the submarine USS Scorpion (1968). It guided the successful 2011 search for Air France 447’s wreckage after earlier searches failed (Stone et al., 2014). The US Coast Guard’s SAROPS system uses it today.

🐍 Exercise 2 (research): Bayesian search for a lost object
Run Bayesian search over 60 cells with a peaked prior and varying detection probabilities: search the argmax of p·q and update on failure. Compare the find rate and the mean searches needed against a fixed sweep.

Bayes throughout robotics and AI

  • State estimation. Kalman filters are exact Bayes for linear-Gaussian systems (Kalman, 1960). Particle filters handle anything (Gordon, Salmond and Smith, 1993). FastSLAM and factor-graph SLAM factorize the posterior over map and trajectory (Thrun et al., 2005; Dellaert and Kaess, 2017).
  • Bayesian deep learning and active learning. Posterior uncertainty decides which experiment to run or which data to label next (Bayesian optimization, A6; MacKay, 1992). The same holds for which region a planetary rover should sample.
  • Classification. Naïve Bayes multiplies per-feature likelihoods (conditional independence). Discriminative classifiers estimate posteriors directly, and calibration asks whether “80% confident” is right 80% of the time (Guo et al., 2017).

References

  1. T. Bayes (1763). “An essay towards solving a problem in the doctrine of chances.” Philosophical Transactions of the Royal Society, 53.
  2. P.-S. Laplace (1812). Théorie analytique des probabilités. Paris.
  3. S. Thrun, W. Burgard, D. Fox (2005). Probabilistic Robotics. MIT Press.
  4. B. O. Koopman (1946). Search and Screening. OEG Report 56, US Navy.
  5. L. Stone (1975). Theory of Optimal Search. Academic Press.
  6. L. Stone, C. Keller, T. Kratzke, J. Strumpfer (2014). “Search for the wreckage of Air France Flight AF 447.” Statistical Science, 29(1).
  7. N. Gordon, D. Salmond, A. Smith (1993). “Novel approach to nonlinear/non-Gaussian Bayesian state estimation.” IEE Proceedings F, 140(2).
  8. F. Dellaert, M. Kaess (2017). “Factor graphs for robot perception.” Foundations and Trends in Robotics, 6(1–2).
  9. G. Gigerenzer, U. Hoffrage (1995). “How to improve Bayesian reasoning without instruction: frequency formats.” Psychological Review, 102(4).
  10. C. Guo, G. Pleiss, Y. Sun, K. Weinberger (2017). “On calibration of modern neural networks.” ICML.