TensorTau PathToAGI Probability and Uncertainty Level 03

Level 03 · Probability and Uncertainty · Chapter 029

Bayes' Rule: What Evidence Does to Belief

How do we reverse a conditional probability without fooling ourselves?

Where We Are

Chapter 028 taught us P(A∣B)P(A\mid B). But evidence often arrives in the opposite direction from the question we care about. A test manufacturer reports P(positive∣disease)P(positive\mid disease). A patient asks for P(disease∣positive)P(disease\mid positive).

Those are not the same probability.


1. The Medical-Test Surprise

Imagine 10,000 people.

  • 1% have a disease → 100 people.
  • The test catches 99% of diseased people → 99 true positives.
  • It falsely marks 5% of healthy people positive → 495 false positives among 9,900 healthy people.

So 594 people test positive, but only 99 are actually ill.

P(D∣+)=99594≈0.167.P(D\mid +)=\frac{99}{594}\approx 0.167.

A 99%-sensitive test produced only about a 17% disease probability after a positive result.

Why? Because the disease was rare before testing. The base rate matters.


2. Derive Bayes Instead of Memorizing It

From conditional probability:

P(A∣B)=P(A∩B)P(B).P(A\mid B)=\frac{P(A\cap B)}{P(B)}.

Also:

P(B∣A)=P(A∩B)P(A).P(B\mid A)=\frac{P(A\cap B)}{P(A)}.

Therefore

P(A∩B)=P(B∣A)P(A).P(A\cap B)=P(B\mid A)P(A).

Substitute:

P(A∣B)=P(B∣A)P(A)P(B).\boxed{P(A\mid B)=\frac{P(B\mid A)P(A)}{P(B)}}.

That is Bayes’ rule. It is not magic. It is the same intersection counted from two directions.


3. Prior, Likelihood, Evidence, Posterior

For a hypothesis HH and evidence EE:

P(H∣E)=P(E∣H)P(H)P(E).P(H\mid E)=\frac{P(E\mid H)P(H)}{P(E)}.

Names:

  • P(H)P(H) — prior: belief before evidence,
  • P(E∣H)P(E\mid H) — likelihood: how compatible evidence is with the hypothesis,
  • P(E)P(E) — evidence or marginal likelihood,
  • P(H∣E)P(H\mid E) — posterior: updated belief.

Mental model:

prior belief
    ×
how well hypothesis predicts evidence
    ↓
renormalize
    ↓
posterior belief

4. Where Does P(E) Come From?

If hypotheses H1,…,HkH_1,\dots,H_k cover all possibilities,

P(E)=∑iP(E∣Hi)P(Hi).P(E)=\sum_i P(E\mid H_i)P(H_i).

For disease vs no disease:

P(+)=P(+∣D)P(D)+P(+∣¬D)P(¬D).P(+)=P(+\mid D)P(D)+P(+\mid \neg D)P(\neg D).

This denominator ensures posterior probabilities sum to one.


5. Odds Form

Bayes can also be written as

posterior odds=prior odds×likelihood ratio.\boxed{posterior\ odds = prior\ odds \times likelihood\ ratio}.

For evidence EE comparing H1H_1 with H0H_0:

P(H1∣E)P(H0∣E)=P(H1)P(H0)P(E∣H1)P(E∣H0).\frac{P(H_1\mid E)}{P(H_0\mid E)} = \frac{P(H_1)}{P(H_0)} \frac{P(E\mid H_1)}{P(E\mid H_0)}.

This makes the update interpretation especially clear: evidence multiplies existing odds.


6. Repeated Evidence

Suppose evidence arrives sequentially. Today we observe E1E_1, tomorrow E2E_2.

Today’s posterior becomes tomorrow’s prior.

prior → evidence 1 → posterior 1
                     ↓
                   new prior → evidence 2 → posterior 2

Bayesian inference is therefore a disciplined way to keep updating beliefs as information arrives.


7. Code From Scratch

def bayes(prior, sensitivity, false_positive_rate):
    p_positive = (
        sensitivity * prior
        + false_positive_rate * (1 - prior)
    )
    return sensitivity * prior / p_positive

print(bayes(0.01, 0.99, 0.05))
# about 0.167

Now vary only the prior from 0.01 to 0.10. The same test gives a very different posterior. That experiment teaches more than memorizing the equation.


8. Bayes in Machine Learning

Bayesian reasoning appears in:

  • Naive Bayes classifiers,
  • Bayesian linear regression,
  • probabilistic graphical models,
  • uncertainty estimation,
  • model comparison,
  • filtering and tracking,
  • scientific inference.

Even when a neural network is not explicitly Bayesian, the distinction between prior information, evidence and updated belief is a powerful way to reason about predictions.


9. Break It: Base-Rate Neglect

A tempting mistake is:

“The test is 99% accurate, so a positive result means 99% chance of disease.”

This silently swaps P(+∣D)P(+\mid D) with P(D∣+)P(D\mid +) and ignores the prior prevalence.

Another mistake is to treat the likelihood as a probability distribution over hypotheses. P(E∣H)P(E\mid H) is a function of HH for fixed evidence, but it does not automatically sum or integrate to one over HH.


10. Shape Check

Suppose there are 4 hypotheses and 20 observations. A table of likelihoods P(Ei∣Hj)P(E_i\mid H_j) has shape

[20, 4]

A prior over the 4 hypotheses has shape [4]. After multiplying each row by the prior and normalizing across hypotheses, the posterior table remains [20, 4].


11. History

Thomas Bayes’ posthumously published work introduced a form of inverse probability; Pierre-Simon Laplace developed the idea much further. The modern Bayesian view is not merely a formula but a framework: represent uncertainty, combine it with evidence, update coherently.


Mastery Check

  1. Why can a highly sensitive medical test still have a modest P(disease∣positive)P(disease\mid positive)?
  2. Derive Bayes’ rule from conditional probability.
  3. Explain prior, likelihood and posterior in ordinary language.
  4. What does the evidence denominator do?
  5. What is base-rate neglect?

Bridge to Chapter 030

So far our events were statements such as “disease” or “positive.” Machine learning works with quantities: price, token count, temperature, class index, reward.

How do we attach probabilities to values a quantity might take?

We need random variables and expectation.

Six ways to work the chapter, climbing from explaining it in your own words to investigating it like a researcher. Reading is not enough — this is where the chapter lands.

1. Explain It

Explain Bayes’ rule as “belief before evidence → evidence → belief after evidence” without using symbols.

2. Calculate It

A disease affects 2% of people. A test has 95% sensitivity and a 4% false-positive rate. Compute P(D∣+)P(D\mid +) using both:

  1. a 10,000-person frequency table,
  2. Bayes’ formula.

Verify they agree.

3. Predict It

Keep the test fixed but increase prevalence from 2% to 20%. Before calculating, predict what happens to P(D∣+)P(D\mid +) and explain why.

4. Break It

Write a deliberately wrong solution that claims P(D∣+)=P(+∣D)P(D\mid +)=P(+\mid D). Identify the exact denominator mistake.

5. Build It

Implement:

def posterior(priors, likelihoods):
    ...

It should multiply prior by likelihood and normalize. Test it with three competing hypotheses.

6. Investigate It

Simulate repeated coin flips for two hypotheses: fair coin (p=0.5p=0.5) and biased coin (p=0.8p=0.8). Start with equal priors and update the posterior after every flip. Plot posterior probability versus number of observations.

Ready to Continue?

You are ready when you can derive Bayes’ rule, explain base-rate neglect, and update a prior with evidence without confusing likelihood and posterior.