Open this lesson in your favourite AI. It'll walk you through the why, explain the demo, and quiz you on the try-it list.
The law of total probability lets you compute when you only know on a partition of the universe. In practice this is how almost every real probability gets calculated: you condition on a hidden cause, sum out, and collapse to the marginal. Diagnostics, mixture models, importance sampling, dynamic programming on probabilistic transitions — they all reduce to this one identity. Once you see it everywhere, you stop trying to compute probabilities directly when conditioning would make the problem trivial.
If partitions (pairwise disjoint, covering all of ) with each , then the marginal is the weighted average of the conditionals , weighted by .
Use these three in order. Each builds on the one before.
In one paragraph, state the law of total probability in plain English and give an everyday example where you use it without realising — say, computing the probability of being late to work given two possible commute routes.
Walk me step by step through the proof of the law of total probability from the three Kolmogorov axioms plus the definition of conditional probability. Where exactly do you use disjointness?
Generalise the law of total probability to continuous conditioning: replace the sum with an integral and explain what 'partition' means there. State the law of total expectation $E[X] = E[E[X \mid Y]]$ and explain why it is the same identity in disguise.
// main.go
// Two urns. Pick an urn, then a ball.
// Urn 1: 7 red, 3 blue. Urn 2: 2 red, 8 blue.
// Pick urn 1 with prob 0.6, urn 2 with prob 0.4.
package main
import (
"fmt"
"math/rand"
)
func main() {
pU1, pU2 := 0.6, 0.4
pRgivenU1 := 7.0 / 10.0
pRgivenU2 := 2.0 / 10.0
pR := pRgivenU1*pU1 + pRgivenU2*pU2
fmt.Println("P(red) =", pR) // 0.5
// Verify by Monte Carlo
rng := rand.New(rand.NewSource(0))
N := 200_000
hits := 0
for i := 0; i < N; i++ {
var pR2 float64
if rng.Float64() < pU1 {
pR2 = pRgivenU1
} else {
pR2 = pRgivenU2
}
if rng.Float64() < pR2 {
hits++
}
}
fmt.Println("Monte Carlo P(red) =", float64(hits)/float64(N))
}go run main.go