Sum Rule, Product Rule, and Bayes Theorem
This is the shortest section in the chapter and the one everything else uses. The book’s claim:
Once we have defined probability distributions corresponding to the uncertainties of the data and our problem, it turns out that there are only two fundamental rules, the sum rule and the product rule.
Two rules. Bayes’ theorem is not a third — it is those two, rearranged in two lines. Everything in Chapters 8 through 12 is an application.
What you’ll learn
Section titled “What you’ll learn”- Equation 6.20, the sum rule, also called the marginalization property — and Equation 6.21’s general form with the “all except ” notation.
- Why the book calls the sum rule the source of “many of the computational challenges of probabilistic modeling”, with the cost measured.
- Equation 6.22, the product rule, and the fact that it holds in both orderings.
- Bayes’ theorem, Equation 6.23, derived from the product rule in three lines (6.24–6.26), with all four parts named.
- Why the likelihood is not a distribution in the variable it is a likelihood of — measured on a table.
- Equation 6.27: the evidence as an integral and as an expectation under the prior.
- The base-rate fallacy, which is what happens when Bayes’ theorem is skipped: measured at eleven times too confident.
- Why a zero in the prior can never be undone, and why the book warns about it explicitly.
Intuition: two moves on a table
Section titled “Intuition: two moves on a table”Everything here is one of two moves on a table of joint probabilities.
Collapse an axis. You have and you stop caring about . Add up each column. What is left is . That is the sum rule, and “marginal” is just the name for a number written in the margin of the table.
Split a cell. Any cell can be written as “how likely is this column at all” times “how likely is this row, given we are in this column” — . That is the product rule.
Now: the second move can be made in either order. Split by column, or split by row. Both give the same cell, so the two expressions are equal — and solving that equality for one conditional gives Bayes’ theorem. There is no third idea.
The practical content of Bayes is that it reverses a conditional. You know how often a test fires when the disease is present; you want to know how often the disease is present when the test fires. Those are different numbers, sometimes by a factor of eleven, and the prior is what converts one into the other.
flowchart TD J["joint p(x, y)
Eq 6.9"] J -->|"sum out y
Eq 6.20"| MX["marginal p(x)"] J -->|"sum out x"| MY["marginal p(y)"] J -->|"split by x
Eq 6.22"| F1["p(y | x) p(x)"] J -->|"split by y"| F2["p(x | y) p(y)"] F1 --> EQ["the two are equal
Eq 6.24 to 6.26"] F2 --> EQ EQ --> B["Bayes: p(x|y) = p(y|x) p(x) / p(y)
Eq 6.23"] MY --> EV["p(y) = E_prior[p(y|x)]
Eq 6.27, the evidence"] EV --> B B --> POST["posterior: what you know
about x after seeing y"] MX -.->|"the cost"| HARD["2^D terms for D binary variables
no polynomial-time exact algorithm"]
The math
Section titled “The math”Equation 6.20: the sum rule
Section titled “Equation 6.20: the sum rule”You sum out (or integrate out) the states of . The sum rule is also called the marginalization property, and it relates a joint to a marginal.
With more than two variables it applies to any subset. For :
where reads “all except ”.
Equation 6.22: the product rule
Section titled “Equation 6.22: the product rule”Every joint distribution of two random variables factorises into the marginal of the first and the conditional of the second given the first. And since the ordering in is arbitrary, the product rule equally implies
Measured on a real table, both factorisations reproduce every one of fifteen cells to . The factorisation is an identity, not an approximation.
Equations 6.24 to 6.26: Bayes in three lines
Section titled “Equations 6.24 to 6.26: Bayes in three lines”That the same joint has two factorisations is the entire derivation:
which is Bayes’ theorem:
The four parts, in the book’s words:
The prior encapsulates subjective prior knowledge of the unobserved variable before any data. “We can choose any prior that makes sense to us, but it is critical to ensure that the prior has a nonzero pdf (or pmf) on all plausible , even if they are very rare.” That sentence is measured below, and it is not optional advice.
The likelihood describes how and are related — for discrete distributions, the probability of the data if we knew the latent variable. And then a warning that catches almost everyone:
Note that the likelihood is not a distribution in , but only in . We call either the “likelihood of (given )” or the “probability of given ” but never the likelihood of .
The posterior is the quantity of interest: what you know about after observing .
The evidence:
also called the marginal likelihood. Read the right-hand side: it is the expected likelihood under the prior. It does not depend on , so its only job in Equation 6.23 is to normalise the posterior — but it is also central to Bayesian model selection (§8.6), and “due to the integration, the evidence is often hard to compute”.
Bayes’ theorem inverts the relationship the likelihood gives, which is why it is sometimes called the probabilistic inverse.
Worked example by hand
Section titled “Worked example by hand”Take §6.2’s table again — with five states, with three, — and run all three rules on it.
Sum rule. Collapse the axis: . Collapse the axis: . Each set sums to .
Product rule. Take the cell . Its joint is . Now factorise:
Both give the joint. Notice the two conditionals — and — are different numbers for the same cell. That difference is what Bayes’ theorem accounts for.
Bayes. Recover from the other three, never looking at the joint:
which matches the direct computation exactly.
Where the evidence comes from. was a row sum, but Equation 6.27 says it is also the expected likelihood under the prior:
Same number, and the second route never mentions the joint table.
The likelihood is not a distribution in x
Section titled “The likelihood is not a distribution in x”Here is the MacKay point as arithmetic. The likelihood table sums to down each column, because each column is one fixed and the -probabilities within it must total one:
Sum along the rows instead — that is, fix and add up the likelihood across values of — and you get
Not one. Not close to one. Worst deviation . The likelihood, read as a function of , is not normalised and has no reason to be: it is not a probability distribution over . It only becomes one after multiplying by the prior and dividing by the evidence — which is exactly what Equation 6.23 does.
See it move
Section titled “See it move”From scratch
Section titled “From scratch”"""Section 6.3 — the two rules, Bayes, and the four ways they get misused."""
import math
import numpy as np
np.set_printoptions(precision=6, suppress=True, linewidth=150)
# The same count table as Section 6.2, so the rules can be checked on numbers
# that were already verified there.
N_IJ = np.array([
[12, 30, 18, 8, 4],
[6, 22, 40, 26, 10],
[2, 8, 14, 30, 20],
])
N = N_IJ.sum()
joint = N_IJ / N # p(x, y), rows are y, columns are x
px = joint.sum(axis=0) # p(x)
py = joint.sum(axis=1) # p(y)
p_y_given_x = joint / px[None, :] # p(y | x)
p_x_given_y = joint / py[:, None] # p(x | y)
print("########## sum_rule")
print("Eq 6.20 p(x) = sum_y p(x, y) -- marginalise by summing the OTHER axis")
print(f" p(x) from the joint: {joint.sum(axis=0)}")
print(f" p(y) from the joint: {joint.sum(axis=1)}")
print(f" p(x) sums to {px.sum():.10f} p(y) sums to {py.sum():.10f}")
print()
print("Eq 6.21 the general form: integrate out everything except x_i.")
# Three binary variables, so the marginal of any one is a sum over four cells.
rng = np.random.default_rng(3)
P3 = rng.random((2, 2, 2))
P3 /= P3.sum()
print(f" a joint over three binary variables, shape {P3.shape}, sums to {P3.sum():.10f}")
for axis, name in ((0, "x1"), (1, "x2"), (2, "x3")):
others = tuple(a for a in range(3) if a != axis)
m = P3.sum(axis=others)
print(f" p({name}) = {m} sums to {m.sum():.10f} "
f"({2 ** len(others)} terms summed per state)")
print()
print("########## the_sum_rule_is_expensive")
print(" the book's Remark: marginalising is a high-dimensional sum.")
print(f" {'D binary vars':>14} {'joint entries 2^D':>20} {'terms per marginal':>20}")
for D in (3, 10, 20, 30, 50, 100):
print(f" {D:>14} {2 ** D:>20,} {2 ** (D - 1):>20,}")
print(" at D = 100 the joint has 1.3e30 entries. There is no known polynomial-time")
print(" algorithm for the exact sum, which is why Chapter 11 and variational")
print(" inference exist at all.")
print()
print("########## product_rule")
print("Eq 6.22 p(x, y) = p(y | x) p(x) -- checked on all 15 cells")
recon1 = p_y_given_x * px[None, :]
recon2 = p_x_given_y * py[:, None]
print(f" worst gap, p(y|x) p(x) vs the joint: {np.abs(recon1 - joint).max():.1e}")
print(f" worst gap, p(x|y) p(y) vs the joint: {np.abs(recon2 - joint).max():.1e}")
print(" both factorisations reproduce the same joint, which is the symmetry that")
print(" makes Bayes' theorem a two-line derivation rather than a new axiom.")
print()
print("########## bayes")
print("Eq 6.23 p(x | y) = p(y | x) p(x) / p(y)")
# Recover p(x | y) from the other three, never touching the joint.
bayes = (p_y_given_x * px[None, :]) / py[:, None]
print(f" worst gap against the directly computed p(x | y): {np.abs(bayes - p_x_given_y).max():.1e}")
print()
print(" a single cell, spelled out. Take y = y1, x = x2:")
j, i = 0, 1
print(f" likelihood p(y1 | x2) = {p_y_given_x[j, i]:.6f}")
print(f" prior p(x2) = {px[i]:.6f}")
print(f" evidence p(y1) = {py[j]:.6f}")
print(f" posterior p(x2 | y1) = {p_y_given_x[j, i] * px[i] / py[j]:.6f}")
print(f" direct = {p_x_given_y[j, i]:.6f}")
print()
print("########## the_likelihood_is_not_a_distribution_in_x")
# MacKay's point, as arithmetic. p(y | x) normalises over y, never over x.
print(" p(y | x) summed over Y (the correct axis):")
print(f" {p_y_given_x.sum(axis=0)}")
print(" p(y | x) summed over X (the WRONG axis):")
print(f" {p_y_given_x.sum(axis=1)}")
print(f" those do not sum to 1 -- worst deviation "
f"{np.abs(p_y_given_x.sum(axis=1) - 1).max():.4f}")
print(" so 'the likelihood of x' is a function of x that is NOT a distribution")
print(" over x. It needs the prior and the evidence to become one. This is why the")
print(" book insists on 'likelihood of x given y' and never 'likelihood of y'.")
print()
print("########## evidence_is_an_expectation")
# Eq 6.27: p(y) = integral p(y|x) p(x) dx = E_X[p(y|x)]
print("Eq 6.27 p(y) = sum_x p(y | x) p(x) = E_X[p(y | x)]")
ev_sum = (p_y_given_x * px[None, :]).sum(axis=1)
ev_exp = np.array([float(np.dot(p_y_given_x[j], px)) for j in range(3)])
print(f" by the sum rule: {ev_sum}")
print(f" as an expectation: {ev_exp}")
print(f" p(y) from the joint: {py}")
print(f" worst gap: {max(np.abs(ev_sum - py).max(), np.abs(ev_exp - py).max()):.1e}")
print(" the evidence does not depend on x -- it is what makes the posterior sum to")
print(f" one. Check: posterior rows sum to {p_x_given_y.sum(axis=1)}")
print()
print("########## base_rate")
# The classic. A test with excellent sensitivity and specificity, a rare disease.
sens, spec = 0.99, 0.99
print(f" a test with sensitivity {sens} and specificity {spec}")
print(f" {'prevalence':>11} {'P(disease | positive)':>22} {'naive guess':>12}")
for prev in (0.5, 0.1, 0.01, 0.001, 1e-4):
num = sens * prev
den = sens * prev + (1 - spec) * (1 - prev)
print(f" {prev:>11.4f} {num / den:>22.6f} {sens:>12.2f}")
print(" the 'naive guess' is the sensitivity, which is what people report when they")
print(" confuse p(positive | disease) with p(disease | positive). At a prevalence of")
print(" 0.001 the true posterior is 0.0902 against a naive 0.99 -- an eleven-fold")
print(" overstatement, and the whole reason Bayes' theorem is called the")
print(" probabilistic inverse.")
prev = 0.001
num = sens * prev
den = sens * prev + (1 - spec) * (1 - prev)
print(f" ratio at prevalence {prev}: {sens / (num / den):.2f}x too confident")
print()
print("########## a_zero_prior_is_permanent")
# The book: "it is critical to ensure that the prior has a nonzero pdf on all
# plausible x, even if they are very rare."
STATES = np.array([0.1, 0.3, 0.5, 0.7, 0.9])
TRUE = 0.7
prior_ok = np.full(5, 1 / 5)
prior_bad = np.array([0.25, 0.25, 0.25, 0.0, 0.25]) # zero on the truth
rng2 = np.random.default_rng(11)
data = rng2.random(400) < TRUE
print(f" five candidate values for a coin's bias, truth = {TRUE}")
print(f" {'draws':>7} {'posterior mass on 0.7, good prior':>34} {'with a zero prior':>18}")
for n in (0, 5, 20, 100, 400):
k = int(data[:n].sum())
ll = np.array([b ** k * (1 - b) ** (n - k) for b in STATES])
for name, pr in (("ok", prior_ok), ("bad", prior_bad)):
post = pr * ll
s = post.sum()
post = post / s if s > 0 else post
if name == "ok":
good = post[3]
else:
bad = post[3]
print(f" {n:>7} {good:>34.10f} {bad:>18.10f}")
print(" the zero stays zero forever: the posterior is a PRODUCT with the prior, so")
print(" a state ruled out a priori can never be recovered by any amount of data.")
print()
print("########## conjugate_check")
# A continuous Bayes example where the evidence is computable in closed form, so
# the numerical integral can be scored against it.
a0, b0 = 2.0, 5.0 # Beta prior
n, k = 40, 26 # observed successes
print(f" Beta({a0}, {b0}) prior, {k} successes in {n} trials")
a1, b1 = a0 + k, b0 + n - k
print(f" posterior is Beta({a1}, {b1}) -- conjugate, so exact")
print(f" prior mean {a0 / (a0 + b0):.6f}")
print(f" posterior mean {a1 / (a1 + b1):.6f}")
print(f" MLE (k/n) {k / n:.6f}")
# The evidence in closed form: the beta-binomial normaliser.
log_ev = (math.lgamma(a0 + b0) - math.lgamma(a0) - math.lgamma(b0)
+ math.lgamma(a1) + math.lgamma(b1) - math.lgamma(a1 + b1)
+ math.lgamma(n + 1) - math.lgamma(k + 1) - math.lgamma(n - k + 1))
print(f" evidence p(y), closed form: {math.exp(log_ev):.10e}")
# The same thing by quadrature over the prior, which is Eq 6.27 literally.
grid = np.linspace(0, 1, 2_000_001)
prior_pdf = (grid ** (a0 - 1) * (1 - grid) ** (b0 - 1)
/ math.exp(math.lgamma(a0) + math.lgamma(b0) - math.lgamma(a0 + b0)))
lik = (math.comb(n, k) * grid ** k * (1 - grid) ** (n - k))
ev_num = np.trapezoid(lik * prior_pdf, grid)
print(f" evidence by quadrature: {ev_num:.10e}")
print(f" relative gap: {abs(ev_num - math.exp(log_ev)) / math.exp(log_ev):.2e}")
print(" and Eq 6.27 read as an expectation: the same number is the average of the")
print(" likelihood under the PRIOR, not under the posterior.")
print()
print("########## posterior_versus_a_point_statistic")
# The book's Remark: collapsing the posterior to a statistic loses information.
# A bimodal posterior where the MAP is a bad summary.
xs = np.linspace(-4, 6, 200_001)
post = 0.45 * np.exp(-0.5 * ((xs - 0.0) / 0.35) ** 2) / (0.35 * np.sqrt(2 * np.pi)) \
+ 0.55 * np.exp(-0.5 * ((xs - 3.5) / 1.30) ** 2) / (1.30 * np.sqrt(2 * np.pi))
post /= np.trapezoid(post, xs)
mapx = float(xs[int(np.argmax(post))])
mean = float(np.trapezoid(xs * post, xs))
cdf = np.concatenate([[0.0], np.cumsum((post[1:] + post[:-1]) / 2 * np.diff(xs))])
median = float(xs[int(np.searchsorted(cdf, 0.5))])
print(f" a bimodal posterior: MAP {mapx:.4f} mean {mean:.4f} median {median:.4f}")
# Split at the trough between the modes, so the two masses partition the line.
band = (xs > mapx) & (xs < 3.5)
trough = float(xs[band][int(np.argmin(post[band]))])
left = float(np.trapezoid(post[xs <= trough], xs[xs <= trough]))
right = float(np.trapezoid(post[xs > trough], xs[xs > trough]))
print(f" the trough between the modes is at x = {trough:.4f}")
print(f" mass left of it (contains the MAP): {left:.4f}")
print(f" mass right of it : {right:.4f}")
print(f" they partition the line: {left + right:.10f}")
print(" the MAP sits in the mode holding the MINORITY of the mass -- it is the")
print(" taller peak only because it is NARROWER. The posterior mean lands at")
print(f" {mean:.4f}, in the gap between the two modes, where the density is low;")
print(" the median at {:.4f} is in the heavier mode. Three different 'summaries',".format(median))
print(" three different answers, and each one discards what the other two saw.")
print(" This is the loss of information the book's Remark warns about.")########## sum_rule
Eq 6.20 p(x) = sum_y p(x, y) -- marginalise by summing the OTHER axis
p(x) from the joint: [0.08 0.24 0.288 0.256 0.136]
p(y) from the joint: [0.288 0.416 0.296]
p(x) sums to 1.0000000000 p(y) sums to 1.0000000000
Eq 6.21 the general form: integrate out everything except x_i.
a joint over three binary variables, shape (2, 2, 2), sums to 1.0000000000
p(x1) = [0.593987 0.406013] sums to 1.0000000000 (4 terms summed per state)
p(x2) = [0.295868 0.704132] sums to 1.0000000000 (4 terms summed per state)
p(x3) = [0.508403 0.491597] sums to 1.0000000000 (4 terms summed per state)
########## the_sum_rule_is_expensive
the book's Remark: marginalising is a high-dimensional sum.
D binary vars joint entries 2^D terms per marginal
3 8 4
10 1,024 512
20 1,048,576 524,288
30 1,073,741,824 536,870,912
50 1,125,899,906,842,624 562,949,953,421,312
100 1,267,650,600,228,229,401,496,703,205,376 633,825,300,114,114,700,748,351,602,688
at D = 100 the joint has 1.3e30 entries. There is no known polynomial-time
algorithm for the exact sum, which is why Chapter 11 and variational
inference exist at all.
########## product_rule
Eq 6.22 p(x, y) = p(y | x) p(x) -- checked on all 15 cells
worst gap, p(y|x) p(x) vs the joint: 1.4e-17
worst gap, p(x|y) p(y) vs the joint: 1.4e-17
both factorisations reproduce the same joint, which is the symmetry that
makes Bayes' theorem a two-line derivation rather than a new axiom.
########## bayes
Eq 6.23 p(x | y) = p(y | x) p(x) / p(y)
worst gap against the directly computed p(x | y): 5.6e-17
a single cell, spelled out. Take y = y1, x = x2:
likelihood p(y1 | x2) = 0.500000
prior p(x2) = 0.240000
evidence p(y1) = 0.288000
posterior p(x2 | y1) = 0.416667
direct = 0.416667
########## the_likelihood_is_not_a_distribution_in_x
p(y | x) summed over Y (the correct axis):
[1. 1. 1. 1. 1.]
p(y | x) summed over X (the WRONG axis):
[1.592647 1.92259 1.484763]
those do not sum to 1 -- worst deviation 0.9226
so 'the likelihood of x' is a function of x that is NOT a distribution
over x. It needs the prior and the evidence to become one. This is why the
book insists on 'likelihood of x given y' and never 'likelihood of y'.
########## evidence_is_an_expectation
Eq 6.27 p(y) = sum_x p(y | x) p(x) = E_X[p(y | x)]
by the sum rule: [0.288 0.416 0.296]
as an expectation: [0.288 0.416 0.296]
p(y) from the joint: [0.288 0.416 0.296]
worst gap: 5.6e-17
the evidence does not depend on x -- it is what makes the posterior sum to
one. Check: posterior rows sum to [1. 1. 1.]
########## base_rate
a test with sensitivity 0.99 and specificity 0.99
prevalence P(disease | positive) naive guess
0.5000 0.990000 0.99
0.1000 0.916667 0.99
0.0100 0.500000 0.99
0.0010 0.090164 0.99
0.0001 0.009804 0.99
the 'naive guess' is the sensitivity, which is what people report when they
confuse p(positive | disease) with p(disease | positive). At a prevalence of
0.001 the true posterior is 0.0902 against a naive 0.99 -- an eleven-fold
overstatement, and the whole reason Bayes' theorem is called the
probabilistic inverse.
ratio at prevalence 0.001: 10.98x too confident
########## a_zero_prior_is_permanent
five candidate values for a coin's bias, truth = 0.7
draws posterior mass on 0.7, good prior with a zero prior
0 0.2000000000 0.0000000000
5 0.2121426317 0.0000000000
20 0.5800990294 0.0000000000
100 0.9998151217 0.0000000000
400 1.0000000000 0.0000000000
the zero stays zero forever: the posterior is a PRODUCT with the prior, so
a state ruled out a priori can never be recovered by any amount of data.
########## conjugate_check
Beta(2.0, 5.0) prior, 26 successes in 40 trials
posterior is Beta(28.0, 19.0) -- conjugate, so exact
prior mean 0.285714
posterior mean 0.595745
MLE (k/n) 0.650000
evidence p(y), closed form: 8.8204971186e-03
evidence by quadrature: 8.8204971186e-03
relative gap: 3.13e-14
and Eq 6.27 read as an expectation: the same number is the average of the
likelihood under the PRIOR, not under the posterior.
########## posterior_versus_a_point_statistic
a bimodal posterior: MAP 0.0023 mean 1.8555 median 1.6494
the trough between the modes is at x = 1.0688
mass left of it (contains the MAP): 0.4735
mass right of it : 0.5265
they partition the line: 0.9999982635
the MAP sits in the mode holding the MINORITY of the mass -- it is the
taller peak only because it is NARROWER. The posterior mean lands at
1.8555, in the gap between the two modes, where the density is low;
the median at 1.6494 is in the heavier mode. Three different 'summaries',
three different answers, and each one discards what the other two saw.
This is the loss of information the book's Remark warns about.Five things worth stopping on.
The product rule is exact. Both factorisations reproduce all fifteen joint cells to , and Bayes recovers the conditional to . These are identities; any discrepancy larger than round-off means a table is transposed.
The likelihood summed over the wrong axis gives , , . Worst deviation from one: . It is not a distribution over and was never supposed to be.
The evidence is an expectation under the prior. Equation 6.27 computed three ways — as a row sum of the joint, as a sum-rule contraction, and as — agrees to . On the conjugate example the closed-form evidence matches quadrature to a relative .
The base rate dominates. With sensitivity and specificity both , the posterior falls from at prevalence to at prevalence — while the test’s characteristics never change. Quoting the sensitivity there overstates confidence by a factor of .
A zero prior is permanent. With mass everywhere, the posterior on the true
state climbs . With a prior of
exactly zero on that state it reads 0.0000000000 at every sample size including
. Equation 6.23 multiplies by the prior, and nothing multiplies zero back
up.
On real data
Section titled “On real data”Reading the plot
Section titled “Reading the plot”From the first figure. The right panel is the one to internalise. Two completely different quantities — a joint probability and a product of a conditional with a marginal — land on the same fifteen points. That is not a fit; it is Equation 6.22 being an identity. And once you accept that both orderings of the split give the same joint, Bayes’ theorem is forced.
From the second figure. Cover the left panel and look only at the right. The green bar is people; the red bar is . Everyone in both bars got a positive result from a test that is right of the time in both directions. The posterior is a ratio of bar heights, and the prior is what set those heights. When someone reports “the test is 99% accurate”, ask which conditional they mean.
From the third figure. The red line is the whole point. It is not small, or slowly rising, or noisy — it is exactly zero, at every sample size, forever. If your model cannot represent the truth, no quantity of data will fix it, and the failure is silent: the posterior over the states you did allow will look perfectly well behaved.
Pitfalls
Section titled “Pitfalls”Compare
Section titled “Compare”| Sum rule | Product rule | Bayes’ theorem | |
|---|---|---|---|
| Book | Equation 6.20, 6.21 | Equation 6.22 | Equation 6.23 |
| Relates | joint to marginal | joint to conditional | one conditional to the other |
| Operation | collapse an axis | factorise a cell | rearrange the two factorisations |
| Also called | marginalization | — | probabilistic inverse |
| Cost | terms, hard in general | free | the evidence is the hard part |
| Quantity | Symbol | Normalises over | Depends on |
|---|---|---|---|
| prior | nothing observed | ||
| likelihood | , not | both | |
| evidence | — (a number) | only | |
| posterior | both |
-
How many fundamental rules does Section 6.3 claim probability has?
Because p(x,y) factorises as p(x|y)p(y) and as p(y|x)p(x), setting those equal and dividing gives Bayes in one line. Nothing new is assumed.
pch.quizShowAnswer
B — Two. Bayes' theorem is not a third rule — it is the product rule written in both orderings and solved for one conditional, which is Equations 6.24 to 6.26 — Because p(x,y) factorises as p(x|y)p(y) and as p(y|x)p(x), setting those equal and dividing gives Bayes in one line. Nothing new is assumed.
-
Summing the likelihood table p(y|x) across values of x gave 1.59, 1.92 and 1.48. What does that show?
This is why the book insists on 'likelihood of x given y' or 'probability of y given x' and never 'likelihood of y'. Normalising a likelihood over x by hand silently imposes a uniform prior.
pch.quizShowAnswer
B — That the likelihood is not a distribution over x — it normalises over y only. It becomes a distribution over x only after multiplying by the prior and dividing by the evidence — This is why the book insists on 'likelihood of x given y' or 'probability of y given x' and never 'likelihood of y'. Normalising a likelihood over x by hand silently imposes a uniform prior.
-
A test has sensitivity and specificity both 0.99. At a prevalence of 0.001, what is P(disease | positive)?
Nothing about the test changed; the prior did. This is the base-rate fallacy, and it is the practical reason Bayes' theorem is called the probabilistic inverse.
pch.quizShowAnswer
B — 0.0902 — in a population of 100000 there are 99 true positives against 999 false ones, so 99/1098. Quoting 0.99 overstates it by a factor of 10.98 — Nothing about the test changed; the prior did. This is the base-rate fallacy, and it is the practical reason Bayes' theorem is called the probabilistic inverse.
-
You assign a prior of exactly zero to one candidate state, and it turns out to be the true one. What happens as data accumulates?
And the failure is silent: the posterior over the states you did allow still normalises and looks perfectly reasonable. This is why the book requires a nonzero prior on every plausible state, however rare.
pch.quizShowAnswer
B — Nothing — the posterior mass on it stays exactly zero forever, measured at 0.0000000000 after 400 confirming observations, because Equation 6.23 multiplies by the prior — And the failure is silent: the posterior over the states you did allow still normalises and looks perfectly reasonable. This is why the book requires a nonzero prior on every plausible state, however rare.
-
Why does the book warn against replacing the posterior with its maximum?
The book cites Deisenroth et al. (2015): in model-based reinforcement learning the full posterior gives data-efficient learning while using the maximum leads to consistent failures. Three summaries of one posterior gave three unrepresentative answers here.
pch.quizShowAnswer
B — Because a summary discards information the posterior holds. Measured on a bimodal posterior: the MAP sits in the mode with 0.4735 of the mass while the other holds 0.5265, the mean lands in the low-density gap between them, and the median is somewhere else again — The book cites Deisenroth et al. (2015): in model-based reinforcement learning the full posterior gives data-efficient learning while using the maximum leads to consistent failures. Three summaries of one posterior gave three unrepresentative answers here.
🧪 Try It Yourself
Section titled “🧪 Try It Yourself”Exercise 1 – The sum rule on a three-variable joint
Section titled “Exercise 1 – The sum rule on a three-variable joint”Exercise 2 – The product rule, cell by cell
Section titled “Exercise 2 – The product rule, cell by cell”Exercise 3 – Bayes, and the base rate
Section titled “Exercise 3 – Bayes, and the base rate”Exercise 4 – A zero prior never recovers
Section titled “Exercise 4 – A zero prior never recovers”Exercise 5 – The evidence as an expectation
Section titled “Exercise 5 – The evidence as an expectation”Recall card
Section titled “Recall card”- There are only two rules. The sum rule (Eq 6.20) collapses an axis of the joint; the product rule (Eq 6.22) factorises a cell. Bayes’ theorem is not a third rule.
- Bayes is two lines of algebra. p(x,y) = p(x|y)p(y) and p(x,y) = p(y|x)p(x), so setting them equal and dividing gives Eq 6.23. Equations 6.24 to 6.26 are the whole derivation.
- The sum rule is where the cost lives. For D binary variables the joint has 2^D entries — 1.27e30 at D = 100 — and there is no known polynomial-time exact algorithm. That Remark is why variational inference and MCMC exist.
- Both factorisations are exact. Measured on a 15-cell table: worst gap 1.4e-17, and Bayes recovers the reverse conditional to 5.6e-17.
- The likelihood is not a distribution in x. Summed over x it gave 1.59, 1.92, 1.48 — worst deviation 0.9226. Never say “the likelihood of y”.
- The evidence (Eq 6.27) is the likelihood averaged under the PRIOR, E_X[p(y|x)]. It does not depend on x, it normalises the posterior, and it is the hard integral.
- p(y|x) and p(x|y) are different numbers. On one cell: 0.5 against 0.416667. On a medical test: 0.99 against 0.0902.
- The base-rate fallacy, measured. With sensitivity and specificity both 0.99, P(disease|+) is 0.99 at prevalence 0.5 but 0.0902 at 0.001 — an overstatement by a factor of 10.98. In 100000 people that is 99 true positives against 999 false ones.
- A zero in the prior is permanent. Measured at exactly 0.0000000000 after 400 confirming observations, because Eq 6.23 multiplies by the prior. The book’s requirement of a nonzero prior on every plausible state is hard, and the failure is silent.
- Conjugacy makes the evidence checkable. Beta(2,5) prior with 26 of 40 successes gives a Beta(28,19) posterior and an evidence of 8.8204971186e-03, matching quadrature to a relative 3.1e-14.
- A point summary of the posterior can misrepresent it. On a bimodal posterior the MAP was 0.0023 in the mode holding 0.4735 of the mass, the mean 1.8555 sat in the low-density gap, and the median was 1.6494. Three summaries, three answers, none representative.
Next: Summary Statistics and Independence — means, variances, covariance, and the several inequivalent things “independent” can mean.
pch.coffeeTagline
pch.coffeeCtapch.feedbackHeading
pch.feedbackSubheading