Bayes' Theorem
Volume I, Chapter 3 — Part I. From Kolmogorov axioms to conditional probability, the product rule, Bayes' theorem, the law of total probability, sequential updating, and the Bayesian inference framework underlying probabilistic machine learning.
Table of Contents
- Learning Objectives
- Prerequisites
- Notation
- Core Intuition
- Probability Spaces and the Kolmogorov Axioms
- Conditional Probability: Definition and Properties
- The Product Rule and Bayes' Theorem
- The Law of Total Probability
- Bayes' Theorem in Continuous Settings
- Sequential Bayesian Updating
- The Bayesian Inference Framework
- Worked Examples
- Connection to Machine Learning
- Common Pitfalls and Misconceptions
- Research Perspective
- Summary of Takeaways
- Exercises
Learning Objectives
After reading this chapter, you should be able to:
- State the Kolmogorov axioms and verify that conditional probability is a valid probability measure on restricted sample spaces.
- Derive the product rule and Bayes' theorem from the definition of conditional probability, with no logical gaps.
- Apply the law of total probability to compute evidence terms when only conditional probabilities are known.
- Write Bayes' theorem for continuous random variables using densities and explain when ratios of densities are meaningful.
- Perform sequential Bayesian updating and explain why the posterior from one observation becomes the prior for the next.
- Identify the roles of prior, likelihood, posterior, and evidence in Bayesian inference and connect them to Naive Bayes, Bayesian neural networks, and preference modeling.
Prerequisites
This is the opening chapter of Volume I, Chapter 3 (Probability & Statistical Learning). No prior chapters in this volume are required. Familiarity with basic set notation and elementary calculus (for the continuous case) is assumed.
Recommended background from earlier volumes:
- Vectors, Spans & Linear Independence: expectation as a linear operator appears throughout.
- Gradient Descent: optimization of log-posteriors connects to MAP estimation in later chapters.
Notation
- — Probability space
- — Conditional probability
- — Joint probability
- — Prior and likelihood
- — Posterior
- — Densities in continuous settings
Core Intuition
Machine learning is, at its core, learning under uncertainty. We observe data , hold beliefs about unknown quantities (parameters, latent variables, or hypotheses), and wish to update those beliefs in light of evidence. Bayes' theorem is the precise mathematical rule governing this update.
The central question is: Given that we observed evidence , how should we revise our belief about hypothesis ? Before seeing , our belief is captured by the prior . After seeing , it becomes the posterior . Bayes' theorem tells us exactly how to compute this revision using the likelihood — how probable the evidence is under each hypothesis — and the evidence (marginal) , which normalizes the result.
This is not a heuristic or approximation. Bayes' theorem is a theorem — a logical consequence of the definition of conditional probability. Every probabilistic learning algorithm, from Naive Bayes classifiers to variational autoencoders to RLHF reward models, ultimately relies on this identity or an approximation to it.
Series context. This is Part I of Chapter 3 in Volume I: Foundations. Subsequent parts cover the Multivariate Gaussian, Entropy, KL Divergence, Maximum Likelihood Estimation, and the Bias–Variance Tradeoff.
Interactive: Bayes' Theorem
Population of 1000 people tested positive:
True Pos
False Pos
P(+)
10.85%
Bayes Factor
9.5×
Probability Spaces and the Kolmogorov Axioms
Definition 1 (Probability Space). A probability space is a triple where:
- is the sample space — the set of all possible outcomes.
- is a -algebra of events (subsets of closed under complement and countable union).
- is a probability measure satisfying the Kolmogorov axioms.
Axiom 1 (Non-negativity). For every event :
Axiom 2 (Normalization). The entire sample space has probability one:
Axiom 3 (Countable Additivity). For any countable collection of mutually disjoint events with for :
Definition 2 (Random Variable). A random variable is a measurable function (or ). For discrete , the probability mass function (PMF) is . For continuous , the probability density function (PDF) satisfies .
Proposition 1. From the axioms, the following hold:
(i) .
(ii) where .
(iii) If , then .
(iv) (inclusion–exclusion).
Proof of (i). Let and for . Then and by Axiom 3, . The only non-negative solution is .
These elementary consequences will be used repeatedly in what follows.
Conditional Probability: Definition and Properties
Definition 3 (Conditional Probability). Let with . The conditional probability of given is:
Interpretation. Restrict attention to outcomes in . Among these, what fraction also belong to ? The sample space is effectively rescaled so that has probability 1.
Theorem 1. Fix with . The map defines a valid probability measure on .
Proof. We verify the Kolmogorov axioms for .
(Non-negativity.) since and .
(Normalization.) .
(Countable additivity.) Let be disjoint. Then are also disjoint, and
Therefore is a probability measure.
Proposition 2 (Conditional Probability Rules). For events with :
(i) .
(ii) .
(iii) If , then .
(iv) .
Definition 4 (Independence). Events and are independent if , equivalently (when ) if . Knowing does not change the probability of .
Proposition 3. If and are independent, then and , and , and and are also independent.
The Product Rule and Bayes' Theorem
Theorem 2 (Product Rule). If , then:
Proof. This is the definition (4) multiplied by on both sides.
By symmetry of intersection (), we also have:
provided .
Theorem 3 (Bayes' Theorem — Event Form). If and , then:
Proof. Equations (6) and (7) both equal . Equating their right-hand sides:
Dividing both sides by yields (8).
Important equation. Equation (8) is the foundational identity of Bayesian reasoning. Each term has a standard name:
- — Posterior — Updated belief about after observing
- — Likelihood — How probable the evidence is if is true
- — Prior — Belief about before observing
- — Evidence (marginal) — Total probability of observing
Remark. The derivation uses exactly three steps: write the product rule in two directions, equate, divide. There is no additional assumption beyond the Kolmogorov axioms and the definition of conditional probability.
Corollary 1 (Odds Form). The posterior odds equal the prior odds times the likelihood ratio:
Proof. Apply (8) to both and , then divide.
The likelihood ratio is the Bayes factor — a measure of how strongly the evidence supports over its complement.
The Law of Total Probability
In applications, is often not directly available. We compute it by marginalizing over a partition of the hypothesis space.
Definition 5 (Partition). Events form a partition of if they are mutually disjoint and .
Theorem 4 (Law of Total Probability). If is a partition with for all , then for any event :
Proof. Since the partition , we can write , a disjoint union. By countable additivity:
where the last step applies the product rule (6).
Corollary 2 (Binary Case). For hypothesis and its complement:
Corollary 3 (Expanded Bayes' Theorem). Substituting (13) into (8):
This is the form used for computation when only conditional probabilities and the prior are known.
Theorem 5 (Law of Total Probability — Continuous). If is a continuous random variable with PDF , then for any event :
This continuous version is essential for integrating out nuisance parameters in Bayesian models.
Bayes' Theorem in Continuous Settings
For continuous random variables, we work with densities rather than point probabilities.
Definition 6 (Conditional Density). The conditional PDF of given is:
where is the joint density and is the marginal density.
Theorem 6 (Bayes' Theorem — Continuous Form). For parameters and data :
Proof. By definition (16) applied to the joint :
The joint factors as by the product rule for densities (analogous to (7)). The denominator follows from (15).
Remark on notation. We write for the likelihood (density of data given parameters) and for the prior. The posterior is proportional to the product of likelihood and prior:
The evidence serves as the normalization constant. This proportionality is the computational workhorse of Bayesian inference.
Proposition 4. The continuous Bayes' theorem (17) is consistent with the discrete version (8): replacing sums by integrals and probabilities by densities yields the same logical structure.
Sequential Bayesian Updating
A powerful consequence of Bayes' theorem is that learning is additive in log-space and multiplicative in probability-space across independent observations.
Theorem 7 (Sequential Updating). Suppose we observe data in two stages: first , then . Then:
Proof. Apply Bayes' theorem (8) with evidence :
If is conditionally independent of given (written ), then , and (20) simplifies to:
Alternatively, update in two steps: compute from (8), then use it as the prior for the second update:
When , this reduces to (22).
Proposition 5 (Posterior as Prior). The posterior from one observation becomes the prior for the next:
This conjugate updating structure is the foundation of online learning, Kalman filtering, and streaming Bayesian inference.
Proposition 6 (Log-Posterior Additivity). For conditionally independent observations given :
The log-likelihood accumulates evidence; this connects directly to Maximum Likelihood Estimation.
The Bayesian Inference Framework
We now assemble the components into the standard Bayesian inference pipeline.
Definition 7 (Bayesian Model). A Bayesian model consists of:
- A parameter space with prior .
- A likelihood specifying how data is generated given parameters.
- The posterior obtained via Bayes' theorem.
Definition 8 (Posterior Predictive). The posterior predictive distribution for new data is:
This integrates over parameter uncertainty — a key advantage over point estimation.
Definition 9 (Maximum A Posteriori — Preview). The MAP estimator is the mode of the posterior:
When the prior is flat (uniform), MAP coincides with MLE. The log-prior term acts as regularization — developed fully in later chapters.
Theorem 8 (Exchangeability and de Finetti). If observations are exchangeable (invariant under permutations) and the model is parameterized by , then by de Finetti's representation theorem, there exists a prior such that the data are conditionally i.i.d. given . Bayesian updating via Bayes' theorem is then the coherent way to learn about .
This theorem provides the philosophical foundation: if you believe data are exchangeable, you are (implicitly or explicitly) a Bayesian.
Worked Examples
Example 1: Medical Diagnosis (Discrete)
Problem. A disease affects 1% of the population. A diagnostic test has sensitivity and false positive rate . A patient tests positive. What is ?
Step 1 — Identify quantities.
Step 2 — Compute evidence via (13).
Step 3 — Apply Bayes' theorem (8).
Result. Despite 95% sensitivity, the posterior is only 8.76%. The low prior () means false positives from the 99% healthy population dominate.
Verification. , and .
Example 2: Sequential Updating
Using the posterior as the new prior for a second independent positive test:
Two consistent positive tests raise the posterior to roughly 48% — still not certainty, reflecting the imperfect specificity.
Example 3: Beta–Binomial Conjugacy (Continuous Prior)
Setup. trials with successes. Model: , prior .
Likelihood. .
Prior. .
Posterior. By (19):
This is — the same family as the prior. Conjugacy makes updating analytic.
Connection to Machine Learning
Naive Bayes Classification
Given features and class , Bayes' theorem gives:
where the naive assumption for enables factorization via the product rule. Classification: ; the evidence cancels in the argmax.
Bayesian Neural Networks
For weights and data :
The evidence is typically intractable for large networks, motivating Variational Inference and Laplace approximations.
Gaussian Processes and Regression
In Bayesian Linear Regression, the posterior over weights is computed via Bayes' theorem with a Gaussian prior and Gaussian likelihood — a direct application of (17) with conjugate structure developed in The Multivariate Gaussian.
RLHF and Preference Modeling
The Bradley–Terry model defines . Training a reward model from human comparisons is maximum-likelihood (or Bayesian) inference over preferences — Bayes' theorem governs how comparison data updates beliefs about .
Common Pitfalls and Misconceptions
Pitfall 1: Confusing with . These are generally different. The prosecutor's fallacy equates with . Bayes' theorem requires the prior and evidence term to convert between them.
Pitfall 2: Ignoring the base rate. Example 1 shows that high sensitivity does not imply high posterior when the prior is low. Always compute via the law of total probability.
Pitfall 3: Treating the likelihood as a probability over parameters. as a function of with fixed is the likelihood, not a density over . It need not integrate to 1 in .
Pitfall 4: Assuming independence when it fails. Naive Bayes assumes conditional independence of features given the class. Violations degrade performance; structured models (graphical models) relax this assumption.
Pitfall 5: Double-counting evidence. In sequential updating, the prior for step 2 must be the posterior from step 1 — not the original prior combined with both observations simultaneously without accounting for dependence.
Pitfall 6: Confusing "Bayesian" with "subjective." Priors can encode genuine prior knowledge, regularization (as in MAP), or non-informative defaults. The mathematics of Bayes' theorem is agnostic to the prior's source.
Research Perspective
Thomas Bayes (1702–1761) formulated the theorem posthumously in "An Essay towards solving a Problem in the Doctrine of Chances" (1763). Pierre-Simon Laplace independently rediscovered and extended it, applying it to celestial mechanics and demographic estimation. For most of the twentieth century, frequentist methods dominated statistics, partly because computing the evidence integral was intractable.
The Bayesian revival began with conjugate analysis (Raiffa & Schlaifer, 1961), Markov chain Monte Carlo (Metropolis et al., 1953; Hastings, 1970; Geman & Geman, 1984), and variational methods (Jordan et al., 1999). Modern machine learning has made Bayesian reasoning central again: VAEs approximate posteriors via KL Divergence; Bayesian optimization guides hyperparameter search; RLHF uses KL penalties to constrain policy updates.
Open research questions include: scalable exact inference for deep networks, prior specification in high dimensions, and the relationship between SGD-trained overparameterized networks and implicit Bayesian inference (the "Bayesian deep learning" debate).
Summary of Takeaways
- Conditional probability — — Restricted probability measure
- Product rule — — Joint from conditional
- Bayes' theorem — — Belief updating
- Law of total probability — — Compute evidence
- Continuous form — — Parameter inference
- Sequential updating — Posterior prior for next observation — Online learning
Next article: The Multivariate Gaussian Distribution → — the distribution that makes Bayesian inference tractable in continuous settings.
Exercises
Exercise 1 (Verification). Prove Proposition 2 (conditional probability rules) directly from Definition 3.
Exercise 2 (Derivation). Derive the odds form (10) from Bayes' theorem applied to and .
Exercise 3 (Partition). A factory has two machines: Machine 1 produces 60% of items with 2% defect rate; Machine 2 produces 40% with 5% defect rate. An item is defective. What is ? Use (14).
Exercise 4 (Sequential updating). For the medical diagnosis example, compute after three independent positive tests.
Exercise 5 (Continuous). For and , derive the posterior and identify the conjugate family.
Exercise 6 (Conceptual). Explain why is not the probability that the hypothesis is true, and state what additional information Bayes' theorem requires.
Exercise 7 (Proof). Prove that if and are independent, then and .
Exercise 8 (Bayes factor). Show that the posterior odds (10) can be written as prior odds times the Bayes factor, and interpret a Bayes factor of 10.