Home›Part 1 Probability & Statistics›1.2

Part 1 · Probability & Statistics

1.2 Conditional probability and Bayes’ theorem

How much should you trust a pedestrian alarm?

6-minute readPrerequisite: 1.1 What is probability?▶ Video (about 4 min)

What you will learn

  • Explain conditional probability: the probability that B happens given that A has happened
  • Explain why false alarms can outnumber real detections even with a high-performing detector
  • Use Bayes’ theorem to calculate the probability that an alarm is real

Build intuition

Consider a pedestrian detector running on an in-vehicle camera, under the following conditions:

  • Pedestrians appear in 0.1% of the video frames recorded while driving
  • When a pedestrian is present, the detector raises an alarm 99% of the time
  • When no pedestrian is present, it still raises a false alarm 1% of the time

So when the alarm goes off, how likely is it that a pedestrian is really there? It is tempting to say 99%, but the actual answer is about 9%.

Probabilities are hard to picture, so let us count using 100,000 frames.

  • Pedestrian present: 100,000 × 0.1% = 100 frames → alarms in 99% of them: 99 alarms
  • No pedestrian: 99,900 frames → false alarms in 1% of them: 999 alarms

That makes 1,098 alarms in total — and only 99 of them are real.

Breakdown of 1,098 alarms Real: 99 (about 9%) False alarms: 999 (about 91%)
Because scenes with pedestrians are rare to begin with, even a 1% false-alarm rate produces more false alarms than real ones.

The key point is that scenes with pedestrians are rare in the first place (0.1%). When you search for rare events, even a small false-alarm rate is multiplied by the huge number of ordinary cases, so false alarms end up outnumbering the real ones.

Check with math

The probability that B happens given that A has happened is written \(P(B \mid A)\) and is called a conditional probability.

$$P(B \mid A) = \frac{P(A \cap B)}{P(A)}$$

Let \(H\) = “a pedestrian is present” and \(A\) = “the alarm goes off”. We want \(P(H \mid A)\), but what we know is the reverse, \(P(A \mid H)\). Bayes’ theorem is the tool that flips this direction.

$$P(H \mid A) = \frac{P(A \mid H)\,P(H)}{P(A \mid H)\,P(H) + P(A \mid \bar{H})\,P(\bar{H})}$$

Plugging in the numbers gives the same result as counting 100,000 frames.

$$P(H \mid A) = \frac{0.99 \times 0.001}{0.99 \times 0.001 + 0.01 \times 0.999} \approx 0.090$$

\(P(H)\) is called the prior probability (your belief before seeing any data), and \(P(H \mid A)\) the posterior probability (your belief after seeing the evidence — the alarm).

Advanced: how much evidence is a passed test?

Bayes’ theorem applies not only to alarms but also to the evidence “the test was passed”. Suppose a function either meets its requirement (the safe case) or in fact does not (the unsafe case), and that even in the unsafe case a single test passes 90% of the time (a miss rate ten times the requirement is not visible in one trial). In the safe case the pass rate is 99%. When n tests in a row are passed, the ratio of how likely that result is in the safe case to how likely it is in the unsafe case is called the likelihood ratio.

$$\text{likelihood ratio} = \frac{P(\text{pass} \mid \text{safe})}{P(\text{pass} \mid \text{unsafe})} = \left(\frac{0.99}{0.90}\right)^{n}$$

For n = 10 this is about 2.6; for n = 100 about 14,000. If the belief before testing is written as the ratio “safe : unsafe” (the odds), Bayes’ theorem takes this simple form:

$$\text{posterior odds} = \text{prior odds} \times \text{likelihood ratio}$$

Starting from a rather sceptical “1 : 9”, ten passes give 1/9 × 2.6 ≈ 0.29 — a probability of about 22% for the safe case, so the unsafe case is still the more likely. Only a hundred passes push the safe case above 99.9%.

The weight of a pass is set by how well the test would catch the unsafe case (1 − 0.90). A test with few repetitions, or a lenient one that the unsafe case also passes, is weak evidence even when passed. This is the same idea as the “power to find a difference” (statistical power in 1.7), and the foundation for comparing the strength of evidence in a safety case (5.10).

Connection to automated driving

  • Unnecessary hard braking: systems that detect rare events, such as a pedestrian suddenly stepping into the road, are structurally prone to false alarms (false activations). Hard braking triggered by a false activation can cause rear-end collisions, so SOTIF also treats “reacting too much” as a source of hazards.
  • Choosing performance metrics: “detects 99% of pedestrians” (recall) is not enough. You also need to know what percentage of alarms are real (precision). → 2.7 Evaluation metrics
  • The meaning depends on where you drive: even with the same detector, \(P(H)\) differs between a busy urban area and a highway, so the reliability of an alarm changes too. → 4.1 ODD, Quiz Q2

Summary

  • \(P(B \mid A)\) is “the share of B within the world where A has happened”
  • Bayes’ theorem flips \(P(A \mid H)\) into \(P(H \mid A)\)
  • When detecting rare events, a low prior probability leads to many false alarms

Quick quiz

Q1. If the false-alarm rate drops from 1% to 0.1%, what is the probability that an alarm is real?

About 50%. Counting 100,000 frames, there are 99,900 × 0.1% ≈ 100 false alarms and 99 real ones, so 99 ÷ (99 + 100) ≈ 0.50. Even with the false-alarm rate cut to one tenth, half of the alarms are still false.

Q2. What if the same detector (99% detection, 1% false alarms) is used in an urban area where pedestrians appear in 10% of frames?

About 92%. Of 100,000 frames, 10,000 contain pedestrians → 9,900 detections; 90,000 do not → 900 false alarms. 9,900 ÷ 10,800 ≈ 0.92. The detector is the same, but the meaning of its output changes greatly with the operating environment (ODD).

Further reading