TensorTau PathToAGI Probability and Uncertainty Level 03

Level 03 · Probability and Uncertainty · Chapter 028

Conditional Probability

When new information arrives, how should a probability change?

Where We Are

Chapter 027 gave us probability as a language for uncertainty. But most real decisions are not made with zero context. A doctor learns a test result. A spam filter sees a word. A vision model sees an edge. We need probabilities after we know something.


1. The Problem: The Denominator Changed

Suppose a class has 100 students:

  • 60 play cricket,
  • 40 do not,
  • 30 of the cricket players also play badminton.

If we choose a student from the whole class, the probability of badminton-and-cricket is 30/100.

But now someone tells us:

The chosen student plays cricket.

We are no longer choosing from 100 possible students. Our new world contains only the 60 cricket players. Of those 60, 30 play badminton.

So

P(B∣C)=3060=0.5.P(B\mid C)=\frac{30}{60}=0.5.

The vertical bar means given that.

Conditional probability is ordinary probability after shrinking the universe to cases consistent with what we know.


2. Deriving the Formula

The cases satisfying both AA and BB have probability P(A∩B)P(A\cap B). Once we know BB, the surviving universe has probability mass P(B)P(B).

Therefore

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

provided P(B)>0P(B)>0.

Rearrange:

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

This multiplication rule will become the engine behind Bayes’ rule and probabilistic models.


3. A 2×2 Table Makes It Visible

Suppose 1,000 emails contain:

SpamNot spamTotal
contains “prize”18020200
no “prize”120680800
Total3007001000

Before seeing the word:

P(Spam)=300/1000=0.30.P(Spam)=300/1000=0.30.

After learning the email contains “prize”:

P(Spam∣prize)=180/200=0.90.P(Spam\mid prize)=180/200=0.90.

The evidence changed the reference population from 1,000 emails to 200 emails.


4. Direction Matters

A common mistake is to assume

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

Usually false.

From the table:

P(Spam∣prize)=180/200=0.90P(Spam\mid prize)=180/200=0.90

but

P(prize∣Spam)=180/300=0.60.P(prize\mid Spam)=180/300=0.60.

Same intersection. Different denominator.

This asymmetry is exactly why medical-test reasoning is often surprising.


5. Independence

If learning BB does not change our belief about AA, then

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

We call AA and BB independent.

Substitute into the multiplication rule:

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

Independence does not mean the events cannot happen together. It means knowing one gives no information about the other.

Mutually exclusive events are different: if one happens, the other cannot.


6. The Chain Rule of Probability

For three events,

P(A,B,C)=P(A∣B,C)P(B∣C)P(C).P(A,B,C)=P(A\mid B,C)P(B\mid C)P(C).

More generally,

P(x1,…,xn)=∏i=1nP(xi∣x1,…,xi−1).P(x_1,\dots,x_n)=\prod_{i=1}^{n}P(x_i\mid x_1,\dots,x_{i-1}).

This identity is profound for modern AI. An autoregressive language model uses the same structure:

P(w1,…,wT)=∏tP(wt∣w<t).P(w_1,\dots,w_T)=\prod_t P(w_t\mid w_{<t}).

Predicting the next token is conditional probability repeated through a sequence.


7. Code From Scratch

spam = 300
prize = 200
spam_and_prize = 180

p_spam = spam / 1000
p_spam_given_prize = spam_and_prize / prize
p_prize_given_spam = spam_and_prize / spam

print(p_spam)              # 0.30
print(p_spam_given_prize)  # 0.90
print(p_prize_given_spam)  # 0.60

Do not memorize the division. Ask first: what is my new universe? That tells you the denominator.


8. Shape Check

Suppose a classifier predicts probabilities for a batch of 32 examples and 10 classes.

logits        [32, 10]
softmax       [32, 10]

Each row is a conditional distribution

P(class∣input).P(class\mid input).

The input is the evidence; the row contains beliefs conditioned on that evidence.


9. Break It

Mistake 1 — swapping the condition

P(A∣B)P(A\mid B) and P(B∣A)P(B\mid A) answer different questions.

Mistake 2 — using the old denominator

Once evidence is known, count only cases compatible with it.

Mistake 3 — confusing independence with exclusivity

Independent events may occur together. Mutually exclusive nonzero-probability events cannot be independent.

Mistake 4 — conditioning on an impossible event

The elementary formula requires P(B)>0P(B)>0.


10. Real-World Connection

Conditional probability appears everywhere:

  • diagnosis: P(disease∣symptoms)P(disease\mid symptoms),
  • classification: P(label∣x)P(label\mid x),
  • language models: P(next token∣context)P(next\ token\mid context),
  • recommendation: P(click∣user,item,context)P(click\mid user,item,context),
  • forecasting: P(future∣history)P(future\mid history).

Machine learning is often the problem of learning a useful conditional distribution from data.


11. History / Paper Trail

The idea of conditional probability predates machine learning by centuries. Its importance exploded in statistics because evidence changes what should be believed. Thomas Bayes and Pierre-Simon Laplace pushed this logic into systematic inference. The next chapter derives the rule that reverses a condition.


Mastery Check

Without looking back, explain:

  1. Why does conditioning change the denominator?
  2. Why is P(A∣B)P(A\mid B) generally different from P(B∣A)P(B\mid A)?
  3. What does independence mean in plain English?
  4. Derive P(A∩B)=P(A∣B)P(B)P(A\cap B)=P(A\mid B)P(B).
  5. How does the probability chain rule connect to language models?

Bridge to Chapter 029

We can compute P(test positive∣disease)P(test\ positive\mid disease) from clinical studies. But the patient wants the reverse:

Given a positive test, what is the probability I actually have the disease?

That reversal creates Bayes’ rule.

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.

Use the six-step ladder: explain → calculate → predict → break → build → investigate.

1. Explain It

In one paragraph, explain conditional probability without using a formula. Use the phrase new universe.

2. Calculate It

A school has 200 students. 80 study music, 50 study coding, and 20 study both. Compute:

  • P(M)P(M)
  • P(C)P(C)
  • P(M∩C)P(M\cap C)
  • P(C∣M)P(C\mid M)
  • P(M∣C)P(M\mid C)

Explain why the last two differ.

3. Predict It

A dataset has 1,000 transactions. 100 are fraud. The word urgent appears in 80 fraud transactions and 120 legitimate transactions. Before calculating, predict whether seeing urgent should increase or decrease P(fraud)P(fraud). Then compute the exact conditional probability.

4. Break It

Construct two events that are mutually exclusive but not independent. Show the arithmetic that proves they are not independent.

5. Build It

Write a Python function:

def conditional(intersection_count, condition_count):
    ...

Reject a zero condition count. Test it on at least three examples.

6. Investigate It

Create a synthetic binary dataset with two features. Estimate P(Y=1)P(Y=1), P(Y=1∣X1=1)P(Y=1\mid X_1=1) and P(Y=1∣X1=1,X2=1)P(Y=1\mid X_1=1,X_2=1). Vary how informative the features are and describe what happens.

Shape Check

A batch contains 64 examples and a classifier has 5 classes. What shape should the matrix representing P(class∣x)P(class\mid x) have? What must each row sum to?

Ready to Continue?

You are ready for Bayes’ rule when you can explain why reversing a condition changes the denominator and why evidence can drastically change a probability.