Skip to content
Tactiverge

School/✦ Research Engineer/Week 13

Bayes' rule for sensor readings

The hazard detector beeps. It catches 90% of real hazards and false-alarms only 5% of the time. Is the rock really dangerous? Probably less likely than you think.

About 35 min · 3 goals · Checked by automated tests

1.Why should I care?

An autonomous system never sees the truth, only evidence. Bayes' rule is the exact recipe for turning evidence into belief, and it explains why rare events plus imperfect sensors produce so many false alarms.

  • ◇ Apply Bayes' rule to update a belief after a sensor reading.
  • ◇ Explain prior, likelihood, evidence and posterior in a sensing example.
  • ◇ Chain updates from several independent readings.

2.Watch

→ Watch how the prior and the evidence are drawn as areas: the posterior is the share of the 'evidence happened' area that belongs to each hypothesis.

Pictures prior, evidence and posterior as areas, so updating a belief on new evidence feels like common sense rather than a formula.

Length: see YouTube · captions on YouTube · source

Nothing loads from YouTube until you press play.

The video is optional: everything you need is also in the lesson text and the interactive.

3.Predict

Hazards are 10% of rocks. The detector fires for 90% of hazards and for 5% of safe rocks. It fires. Probability it is a hazard?

Guess first. Being wrong here is how the surprise works.

4.Discover

In the Code Lab, simulate 100,000 rocks: 10% hazards, a detector with 90% hit rate and 5% false-alarm rate. Among rocks where the detector fired, count the fraction that are hazards. Then fire a second, independent detector and update again.

Can't use the interactive? Read a description instead

The Code Lab simulation's result can be checked by the 1,000-rock counting argument in the intuitive mode: 90 true alarms and 45 false alarms out of 135.

5.Checkpoint: guided practice

Check what you just discovered before going on. Hints appear after a wrong answer.

Practice 1

Prior P(H) = 0.2. P(E | H) = 0.8, P(E | not H) = 0.1. What is P(H | E)?

6.Understand

The rule

P(H | E) = P(E | H)·P(H) / P(E), with P(E) = Σ P(E | Hᵢ)P(Hᵢ) over all hypotheses. Prior P(H): belief before the reading. Likelihood P(E | H): how probable the reading is if H is true. Posterior P(H | E): belief after.

Base rates matter

A good sensor on a rare event still gives many false alarms. With a 1% prior, even a 99%-accurate detector with a 1% false-alarm rate gives a posterior of only 50%. Ignoring the prior is the base-rate fallacy.

Updating repeatedly

Today's posterior is tomorrow's prior. Two independent readings multiply their likelihoods. After two alarms from independent detectors in the example, P(hazard) rises from 0.67 to about 0.97. Independence is crucial: two looks by the same camera at the same shadow are not independent evidence.

Explain it another way

Imagine 1,000 rocks. 100 are hazards; the detector flags 90 of them. Of 900 safe rocks it flags 45. So of 135 flags, 90 are real: two-thirds.

Worked example 1

Prior 0.02, hit rate 0.95, false-alarm rate 0.02. Posterior after one alarm?

0.95 × 0.02 = 0.019; 0.02 × 0.98 = 0.0196. P = 0.019/0.0386 ≈ 0.49.

Common mix-ups

  • P(E | H) and P(H | E) are the same thing.
    ✓ They can be wildly different: a 90% hit rate does not make 90% of alarms real.
  • More readings always mean more certainty.
    ✓ Only if they are independent. Correlated readings repeat the same mistake.

7.Practice on your own

Practice, not a test. Wrong answers get a hint and another try.

Practice 2 · a fresh version every time

Before looking, a rover believes there is a 0.02 probability that a rock ahead is a hazard. Its hazard detector fires with probability 0.99 when there is a hazard and 0.02 when there is not. The detector fires. What is the posterior probability of a hazard?

Practice 3

A dust-storm alarm is 99% sensitive and has a 1% false-alarm rate, but storms occur on only 1% of sols. After an alarm, P(storm) is about…

Practice 4

The same camera takes two photos of a rock one second apart; both look like a hazard. Why should you NOT simply apply the update twice?

8.Apply it

Choose a detection threshold for a rover hazard detector. Write down the cost of a missed hazard and the cost of a false stop, then use Bayes' rule with two candidate (hit, false-alarm) pairs to argue which threshold is better.

9.Reflect

Concepts: Bayesian estimation · Conditional probability and Bayes' rule