01 / 22 · Foundations
What probability is
Why a course on probability opens the site: every model here is a probabilistic statement, and intuition fails exactly where it matters. Three readings of a probability (equally likely outcomes, long-run frequency, degree of belief), four places where intuition goes wrong with the numbers that set it right, and the plan of the course.
On this page 9
Every model on this site makes a probabilistic statement. A classifier outputs a distribution over labels, a language model a distribution over the next token, a diffusion model a distribution over images. Training them usually minimizes a loss that, under a stated model of the data, is a negative log-likelihood, and evaluating them is an estimate with an error bar. Probability theory is the language in which all of this is said, and the calculus that keeps it honest: it gives the right answer in exactly the situations where intuition gives a confident wrong one. This note says what a probability is, shows four such situations, and lays out the course.
Notation. An experiment has a set of possible outcomes ; an event is a subset of ; is its probability. is the number of elements of a finite set.
Three readings of a probability#
The word is used in three ways, and the course needs all three.
Equally likely outcomes. If an experiment has finitely many outcomes and nothing distinguishes one from another, each gets the same share:
A fair die: , “even” is , . This is the classical definition, and it reduces probability to counting, the subject of the next note. It breaks down as soon as the outcomes are not symmetric (a loaded die) or not finite (a random point on a segment).
Long-run frequency. Repeat the experiment many times under the same conditions; the probability is the share of repetitions in which happens, in the limit. The share does settle down, but slowly and with fluctuations:
The share of heads in three runs of coin flips
After 10 flips of a fair coin the first run shows 0.3 heads, after 100 flips 0.53, after 10,000 flips 0.501. The band in the figure holds the share with probability about 0.95 at each fixed (not along the whole path at once) and narrows like ; why it is that width is the subject of the law of large numbers and the central limit theorem. Frequency is how probabilities are checked against the world, and every simulation in this course is a frequency estimate. It cannot, however, define the probability of an event that happens once: rain tomorrow, a particular patient being ill.
Degree of belief. A probability is how strongly a reasoner should believe a statement given what they know, calibrated so that bets at the corresponding odds are fair. This is the Bayesian reading; it covers single events and makes “updating on evidence” a computation, Bayes’ formula.
The three readings disagree about what a probability is and agree completely about how probabilities combine. Kolmogorov’s axioms state the rules of combination without choosing an interpretation, and everything in the course follows from them.
Where intuition fails#
A positive test for a rare disease. A disease affects 1% of people. A test detects 90% of the sick and gives a false positive for 9% of the healthy. A patient tests positive. How likely are they to be ill? When Gigerenzer et al. (2007) gave these numbers to 160 gynecologists, most answered 90% or 81%. Counting, in the natural frequencies that Gigerenzer and Hoffrage (1995) recommend, gives about 9%:
A positive test for a rare disease, in counts out of 1,000 people
Of 1,000 people, 10 are sick and 9 of them test positive; of the 990 healthy, 89 test positive. Of the 98 positive tests only 9 belong to sick people, so . The test is not bad; the disease is rare, and the healthy majority produces most of the positives. Ignoring how common something is before the evidence, the base rate, is the most frequent error in reasoning about evidence, and it is the same error as reading a classifier’s precision off its recall.
Shared birthdays. How many people must be in a room for two of them to share a birthday with probability at least one half? Intuition suggests about 183, half of 365. The answer is 23. The probability that 23 birthdays are all different is , so a shared birthday has probability ; with 50 people it is . Intuition counts the chance that someone shares my birthday; the question is about any of the pairs. The same arithmetic sets how often hash functions and random identifiers collide.
A treatment that wins every group and loses overall. In a study of kidney-stone treatments, treatment A succeeded in 81 of 87 small stones (93%) and 192 of 263 large stones (73%); treatment B in 234 of 270 small stones (87%) and 55 of 80 large ones (69%). A is better for small stones and better for large ones. Pooled, A succeeded in 273 of 350 cases (78%) and B in 289 of 350 (83%), so B looks better. Both statements are true. A was given mostly to large stones (263 of its 350 patients), which are harder to treat, and B mostly to small ones (270 of 350). This is Simpson’s paradox, and every A/B test whose groups differ in composition can produce it.
An average of noisy measurements. A measurement has a random error with standard deviation 1, and the errors of different measurements are independent (uncorrelated is enough). The average of 4 measurements has standard deviation , the average of 100 has : the error falls like , not like . Halving the error of an estimate, an accuracy on a test set or the mean effect in an experiment, costs four times the data. The rule needs the independence: errors that share a common part, such as a miscalibrated instrument, do not average away. The expectation and variance note derives the rule, the joint distributions note the floor that correlated errors leave, and the central limit theorem turns it into error bars.
What the course builds#
The course is built backwards from what machine learning needs. Each note answers a question the previous one could not:
| Question | Note |
|---|---|
| How do we compute a probability when all outcomes are equally likely? | Outcomes, events and counting |
| What if they are not, or there are infinitely many? | Kolmogorov’s axioms |
| How does information change probabilities? | Conditional probability and Bayes’ formula |
| How do we talk about numbers produced by chance? | Discrete and continuous distributions, functions of random variables |
| How do we summarize a distribution by a few numbers? | Expectation and variance |
| How do several random quantities relate? | Joint distributions, the multivariate Gaussian, conditional expectation |
| Why does averaging work, and how fast? | Inequalities, the law of large numbers |
| Why is the Gaussian everywhere? | The central limit theorem |
| How do we go from data back to the distribution? | Estimators, maximum likelihood, Bayesian inference |
| How do we decide if an effect is real? | Confidence intervals, the bootstrap, hypothesis tests |
| How do random systems evolve, and how do we sample from them? | Markov chains, Monte Carlo, MCMC |
The connections to the rest of the site run through these notes. Squared error and cross-entropy are negative log-likelihoods under a Gaussian and a categorical model of the target (maximum likelihood); generalization is a law of large numbers with a deviation bound (concentration); a regularizer is a prior (Bayesian inference); a language model is a chain of conditional distributions, like the n-gram model. Langevin dynamics is a Markov chain Monte Carlo method: it follows the score towards a fixed target. Score-based generative models and diffusion models borrow that score but not the fixed target: they run Langevin steps through a sequence of noise levels, or simulate a time-dependent reverse of a noising process, and they are not MCMC on the data distribution.
What changed#
| Intuition | Probability calculus | |
|---|---|---|
| Positive test, 1% prevalence | about 0.9 | 0.092 |
| Room size for a shared birthday with | about 183 | 23 |
| Kidney-stone treatments | “B is better” (pooled) | A is better in each group; the pooled comparison is confounded |
| Error of an average of 100 measurements | of one | of one |
Limitations#
- The interpretations are not settled. Frequency needs repeatable experiments, belief needs a reasoner; the calculus is the same, but which probability to assign in a real problem is a modelling decision outside the mathematics.
- The calculus is only as good as the model. The test example assumes the 1%, 90% and 9% are known and apply to this patient; the birthday example assumes all 365 days are equally likely, which they are not quite.
- Counting is not causation. Simpson’s paradox shows that probabilities computed from the same data can point in opposite directions; deciding which comparison answers the question needs knowledge of how the data arose.
What you should remember#
- A probability can be read as a share of equally likely outcomes, a long-run frequency or a degree of belief; all three obey the same rules, Kolmogorov’s axioms.
- Frequencies settle slowly: the deviation from the true probability shrinks like .
- Base rates matter: with 1% prevalence, a test with 90% sensitivity and 9% false positives gives .
- Questions about “any pair” grow with the number of pairs: 23 people already give a shared birthday with probability 0.507.
- Pooled comparisons can reverse within-group comparisons (Simpson’s paradox).
Code#
Each example of the note checked by simulation, in NumPy:
import numpy as np, math
rng = np.random.default_rng(0)
# a positive test for a rare disease: 1% prevalence, 90% sensitivity, 9% false positives
n = 1_000_000
sick = rng.random(n) < 0.01
positive = np.where(sick, rng.random(n) < 0.90, rng.random(n) < 0.09)
print(sick[positive].mean()) # 0.0917; exactly 0.009 / 0.0981 = 0.0917
# shared birthdays among 23 people
days = rng.integers(0, 365, size=(100_000, 23))
shared = np.array([len(set(row)) < 23 for row in days]).mean()
print(shared, 1 - math.prod((365 - i) / 365 for i in range(23))) # 0.5066 (simulated), 0.5073 (exact)
# Simpson's paradox: successes and patients, (small stones, large stones)
A = [(81, 87), (192, 263)]; B = [(234, 270), (55, 80)]
for name, groups in [('A', A), ('B', B)]:
print(name, [round(s / m, 3) for s, m in groups], round(sum(s for s, _ in groups) / sum(m for _, m in groups), 3))
# A [0.931, 0.73] 0.78 B [0.867, 0.688] 0.826
# the error of an average falls like 1/sqrt(n)
for m in [1, 4, 100]:
print(m, rng.normal(0, 1, size=(20_000, m)).mean(axis=1).std()) # 0.992, 0.503, 0.099
Next#
The equally-likely reading reduces probability to counting outcomes, and counting is harder than it looks: the birthday problem already needed a product of 23 fractions. The next note builds the tools: sets of outcomes and events, and the rules for counting arrangements and selections with and without order or repetition.
References#
- J. K. Blitzstein, J. Hwang. Introduction to Probability, 2nd ed. CRC Press, 2019. Chapter 1 (interpretations, the birthday problem), Chapter 2 (Bayes and base rates, Simpson’s paradox).
- W. Feller. An Introduction to Probability Theory and Its Applications, Vol. 1, 3rd ed. Wiley, 1968. Chapter II.
- A. N. Shiryaev. Probability-1, 3rd ed. Springer, 2016. Chapter 1, §1.
- G. Gigerenzer, W. Gaissmaier, E. Kurz-Milcke, L. M. Schwartz, S. Woloshin. Helping Doctors and Patients Make Sense of Health Statistics. Psychological Science in the Public Interest, 8(2), 2007. The mammography question put to 160 gynecologists.
- G. Gigerenzer, U. Hoffrage. How to Improve Bayesian Reasoning Without Instruction: Frequency Formats. Psychological Review, 102(4), 1995.
- C. R. Charig, D. R. Webb, S. R. Payne, J. E. Wickham. Comparison of treatment of renal calculi by open surgery, percutaneous nephrolithotomy, and extracorporeal shockwave lithotripsy. BMJ, 292(6524), 1986. The kidney-stone data.