Probability: The Language of Uncertainty
Why can't Bolt just use logic? Try writing the rule "if it rains, the delivery is late." It's false. Sometimes it rains and Bolt is on time. Add exceptions: "…unless the path is clear, and Bolt left early, and the lift works, and…". The list never ends. Logic fails for three reasons that AIMA names:
- Laziness: listing every exception is too much work.
- Theoretical ignorance: we don't know all the causes.
- Practical ignorance: even when we know the rules, we can't observe everything in the moment.
Probability summarizes all that ignorance in a number. "P(late | rain) = 0.65" means: given what I know, in situations like this, deliveries are late about 65% of the time.
Frequentist: a probability is a long-run frequency: flip the coin a million times. Bayesian (subjective): a probability is a degree of belief held by an agent, and it is updated when evidence arrives. AI mostly uses the Bayesian view, because agents must assign probabilities to one-off events ("Is there a pothole right here, right now?"). The good news: both views obey the same mathematical rules.
The basic vocabulary
| Term | Meaning | Example |
|---|---|---|
| Sample space \(\Omega\) | Set of all possible worlds (outcomes) | For two dice: 36 pairs |
| Event | A set of worlds | "the dice sum to 7" (6 worlds) |
| Random variable | A function from worlds to values | \(\textit{Weather} \in \{\text{sun, rain, cloud}\}\), \(\textit{Late} \in \{\text{true, false}\}\) |
| Proposition | A statement about random variables | \(\textit{Late}=\text{true} \wedge \textit{Rain}=\text{true}\), written \(late \wedge rain\) |
| Probability distribution | Probabilities for every value of a variable | \(\mathbf{P}(\textit{Weather}) = \langle 0.6, 0.2, 0.2\rangle\) |
| Joint distribution | Probabilities for every combination of values | \(\mathbf{P}(\textit{Rain}, \textit{Jam}, \textit{Late})\), a table of 8 numbers |
Notation: lower-case \(rain\) is short for \(\textit{Rain}=\text{true}\), and \(\neg rain\) for false. Bold \(\mathbf{P}\) denotes a whole distribution (a vector or table of numbers), and plain \(P\) a single number.
The axioms (Kolmogorov)
- \(0 \le P(\omega) \le 1\) for every world \(\omega\), and \(\sum_{\omega \in \Omega} P(\omega) = 1\).
- For an event \(\phi\): \(P(\phi) = \sum_{\omega \in \phi} P(\omega)\).
Everything else follows from these. For example:
- Complement: \(P(\neg a) = 1 - P(a)\).
- Inclusion–exclusion: \(P(a \vee b) = P(a) + P(b) - P(a \wedge b)\). You subtract the overlap because it was counted twice.
Suppose your beliefs violate the axioms, say you believe \(P(rain) = 0.6\) and \(P(\neg rain) = 0.6\). Then a bookie can offer you a set of bets you consider fair on each side, and you lose money no matter what happens. (de Finetti proved this.) The axioms aren't arbitrary math. They are the only consistent way to bet. The same style of argument justifies the axioms of utility in §4.3.
The full joint distribution: Bolt's evening
Three Boolean variables: Rain, Jam (a crowd blocking the hostel gate) and Late (the delivery is late). The full joint distribution lists a probability for each of the \(2^3 = 8\) worlds:
| \(jam\) | \(\neg jam\) | |||
|---|---|---|---|---|
| \(late\) | \(\neg late\) | \(late\) | \(\neg late\) | |
| \(rain\) | 0.090 | 0.010 | 0.040 | 0.060 |
| \(\neg rain\) | 0.096 | 0.064 | 0.064 | 0.576 |
The 8 numbers sum to 1. Any question about these three variables can be answered from this table. That's its power. Its weakness: with \(n\) Boolean variables it has \(2^n\) entries. At 30 variables that's a billion numbers. Chapter 7 (Bayesian networks) exists to fix this.
Marginalization (summing out)
To get the probability of one variable alone, add up every world where it holds:
$$ P(late) = 0.090 + 0.040 + 0.096 + 0.064 = 0.29 $$In general: \(\mathbf{P}(Y) = \sum_{z} \mathbf{P}(Y, z)\), summing over all values \(z\) of the other variables. This is called marginalizing, because people used to write the totals in the margins of the table.
Conditional probability
"Given that the delivery is late, how likely is it that it rained?" Conditioning means zooming in on the worlds where the evidence is true, and rescaling them to sum to 1:
$$ P(a \mid b) = \frac{P(a \wedge b)}{P(b)} \qquad (P(b) > 0) $$ $$ P(rain \mid late) = \frac{P(rain \wedge late)}{P(late)} = \frac{0.090 + 0.040}{0.29} = \frac{0.13}{0.29} \approx 0.448 $$Before learning anything, \(P(rain) = 0.2\). Learning that the delivery was late raised the belief in rain to 0.448. Evidence changes beliefs: that one sentence is the whole of probabilistic reasoning.
The product rule and the chain rule
Rearrange the definition: \(P(a \wedge b) = P(a \mid b)\,P(b)\). Apply it repeatedly and you get the chain rule:
$$ P(x_1, x_2, \dots, x_n) = P(x_1)\,P(x_2 \mid x_1)\,P(x_3 \mid x_1, x_2) \cdots P(x_n \mid x_1, \dots, x_{n-1}) = \prod_{i=1}^{n} P(x_i \mid x_1, \dots, x_{i-1}) $$This identity always holds. It is the foundation of Bayesian networks: they simplify each factor by dropping parents that don't matter (Ch 7).
The normalization trick
Often we want a whole conditional distribution, for example \(\mathbf{P}(Rain \mid jam, late)\). Both entries share the same denominator \(P(jam, late)\), so we can skip computing it:
$$ \mathbf{P}(Rain \mid jam, late) = \alpha\, \mathbf{P}(Rain, jam, late) = \alpha \langle 0.090,\ 0.096\rangle = \langle 0.484,\ 0.516 \rangle $$Here \(\alpha\) is just "whatever makes the vector sum to 1": \(\alpha = 1/(0.090+0.096)\). The order is \(\langle rain, \neg rain\rangle\). You'll see \(\alpha\) all through Bayes' rule, Bayes nets and POMDP belief updates.
To compute \(\mathbf{P}(X \mid e)\) for a query \(X\), evidence \(e\) and hidden variables \(Y\):
$$ \mathbf{P}(X \mid e) = \alpha \sum_{y} \mathbf{P}(X, e, y) $$In words: (1) keep the rows consistent with the evidence, (2) sum out the hidden variables, (3) normalize. Interesting fact: \(P(rain \mid late, jam) = 0.484 > P(rain \mid late, \neg jam) = 0.04/0.104 = 0.385\). A jam makes rain more likely here, because in this world rain makes jams more likely (people crowd under the gate shelter).
import numpy as np
# Full joint distribution P(Rain, Jam, Late), axes: [rain, jam, late], index 1 = true, 0 = false
P = np.zeros((2, 2, 2))
P[1, 1, 1], P[1, 1, 0] = 0.090, 0.010
P[1, 0, 1], P[1, 0, 0] = 0.040, 0.060
P[0, 1, 1], P[0, 1, 0] = 0.096, 0.064
P[0, 0, 1], P[0, 0, 0] = 0.064, 0.576
print("sums to", P.sum())
p_late = P[:, :, 1].sum() # marginalize out Rain and Jam
print("P(late) = %.3f" % p_late)
p_rain_late = P[1, :, 1].sum() # P(rain, late)
print("P(rain | late) = %.3f" % (p_rain_late / p_late))
# the normalization trick: compute unnormalized values for every value of Rain, then rescale
unnorm = P[:, 1, 1] # P(Rain, jam, late) for Rain = false, true
print("P(Rain | jam, late) =", np.round(unnorm / unnorm.sum(), 3), " (false, true)")sums to 1.0
P(late) = 0.290
P(rain | late) = 0.448
P(Rain | jam, late) = [0.516 0.484] (false, true)
Random variables, expectation and variance
For a numeric random variable \(X\):
$$ \mathbb{E}[X] = \sum_x x\,P(X=x), \qquad \operatorname{Var}(X) = \mathbb{E}\big[(X - \mathbb{E}[X])^2\big] = \mathbb{E}[X^2] - \mathbb{E}[X]^2 $$Key facts you've already used in the bias–variance derivation (§2.3):
- Linearity: \(\mathbb{E}[aX + bY + c] = a\mathbb{E}[X] + b\mathbb{E}[Y] + c\), always, even if \(X, Y\) are dependent.
- Independence: if \(X \perp Y\), then \(\mathbb{E}[XY] = \mathbb{E}[X]\mathbb{E}[Y]\). This is why the cross term \(\mathbb{E}[\varepsilon(f-\hat g)]\) vanished.
- \(\operatorname{Var}(aX + b) = a^2 \operatorname{Var}(X)\).
Expected value is the bridge to decisions. If action A gives utility 10 with probability 0.3 and utility 2 otherwise, its expected utility is \(0.3\cdot 10 + 0.7 \cdot 2 = 4.4\). §4.3 explains why we should maximize exactly this quantity.