Skip to content

The Latent Variable Perspective

Everything so far has worked without a story. §11.4 supplies one, and is explicit that it is not decoration:

The advantages of the probabilistic perspective are that (i) it will justify some ad hoc decisions we made in the previous sections, (ii) it allows for a concrete interpretation of the responsibilities as posterior probabilities, and (iii) the iterative algorithm for updating the model parameters can be derived in a principled manner.

All three are checkable, and this page checks them.

  • Equations 11.58–11.62: the one-hot latent z\mathbf{z}, the prior p(z)=πp(\mathbf{z}) = \boldsymbol\pi, and the joint.
  • Ancestral sampling, run 1.51.5 million times: the samples reproduce Equation 11.66b to 3.4×1043.4\times10^{-4} in bin probability, against a sampling floor of 1.7×1041.7\times10^{-4}.
  • Equation 11.72b: the responsibility is a posterior. Computed the long way — joint over marginal — it matches Equation 11.17 to 0.0\mathbf{0.0}, and the empirical posterior from labelled samples matches it too.
  • Equation 11.73’s Q(θθ(t))Q(\boldsymbol\theta\mid\boldsymbol\theta^{(t)}), and §11.4.5’s claim that the M-step maximises it — verified against a 4040-restart numerical search: 5.3×10155.3\times10^{-15}, with every parameter agreeing to six decimals.
  • The decomposition L=Q+HL = Q + H, tight at θ(t)\boldsymbol\theta^{(t)} to 1.1×10141.1\times10^{-14}, which is why raising QQ raises LL.
  • And the one thing the generative story buys that the algebra could not: data. Generate from a known mixture, refit, and watch the errors fall — μ\mu from 0.2314410.231441 to 0.0229240.022924 as NN goes from 200200 to 200,000200{,}000.

Imagine the dataset had one more column: which component produced each point. Fitting would be trivial — split by that column and use Chapter 8’s closed forms. The column exists; you just cannot see it.

That is the whole content of §11.4. zn\mathbf{z}_n is the missing entry, one-hot over KK values. Everything the previous sections invented — the responsibilities, the weighted averages, the alternation — is what you get by writing down that model and applying Bayes’ theorem. The responsibility stops being a useful weight and becomes the posterior over the missing column.

diagram Section 11.4's model, and what each piece was called earlier mermaid

A binary indicator zk{0,1}z_k \in \{0,1\} says whether component kk made the point:

p(xzk=1)=N(xμk,Σk)(11.58)p(\mathbf{x}\mid z_k = 1) = \mathcal{N}(\mathbf{x}\mid\boldsymbol\mu_k,\boldsymbol\Sigma_k) \qquad \text{(11.58)}

z=[z1,,zK]\mathbf{z} = [z_1,\ldots,z_K]^\top has K1K-1 zeros and exactly one 11 — a one-hot encoding. Since the indicators are not observed, they get a prior:

p(z)=π=[π1,,πK],πk=p(zk=1)(11.59), (11.60)p(\mathbf{z}) = \boldsymbol\pi = [\pi_1,\ldots,\pi_K]^\top, \qquad \pi_k = p(z_k = 1) \qquad \text{(11.59), (11.60)}

and the joint follows:

p(x,zk=1)=p(xzk=1)p(zk=1)=πkN(xμk,Σk)(11.61)p(\mathbf{x}, z_k = 1) = p(\mathbf{x}\mid z_k = 1)p(z_k = 1) = \pi_k\mathcal{N}(\mathbf{x}\mid\boldsymbol\mu_k,\boldsymbol\Sigma_k) \qquad \text{(11.61)}

Ancestral sampling — sample z\mathbf{z}, then x\mathbf{x} given it, then throw z\mathbf{z} away — gives “valid samples from the GMM”. Run 1.51.5 million times:

value
empirical mean1.3360791.336079 against a theoretical 1.3333331.333333
empirical variance26.29664126.296641 against 26.28888926.288889
largest gap in bin probability, 120120 bins3.367×1043.367\times10^{-4}
total variation distance0.0025490.002549
sampling floor, pmax/M\sqrt{p_{\max}/M}1.696×1041.696\times10^{-4}
figure The generative story really does generate the density matplotlib
Top left, a grey histogram with three humps under a yellow curve that traces it exactly. Top right, three pairs of near-identical bars around one third. Bottom, three pairs of bar charts, each pair matching closely. Top left, a grey histogram with three humps under a yellow curve that traces it exactly. Top right, three pairs of near-identical bars around one third. Bottom, three pairs of bar charts, each pair matching closely.
The samples never see Equation 11.66b — they come from drawing a component and then a point from it. The bottom row is Equation 11.72b checked empirically: take every sample that landed near a given x, look up which component actually produced it, and the proportions are the responsibilities.

§11.4.3 The responsibility is a posterior

Section titled “§11.4.3 The responsibility is a posterior”

Bayes’ theorem on the joint:

p(zk=1x)=p(zk=1)p(xzk=1)jp(zj=1)p(xzj=1)=πkN(xμk,Σk)jπjN(xμj,Σj)(11.69)p(z_k = 1\mid\mathbf{x}) = \frac{p(z_k = 1)p(\mathbf{x}\mid z_k = 1)}{\sum_j p(z_j = 1)p(\mathbf{x}\mid z_j = 1)} = \frac{\pi_k\mathcal{N}(\mathbf{x}\mid\boldsymbol\mu_k,\boldsymbol\Sigma_k)}{\sum_j\pi_j\mathcal{N}(\mathbf{x}\mid\boldsymbol\mu_j,\boldsymbol\Sigma_j)} \qquad \text{(11.69)}

which we identify as the responsibility of the kkth mixture component for data point x\mathbf{x}.

Computed the long way on the book’s seven points — form the joint of Equation 11.61, divide by the marginal of Equation 11.66b — against page 1103’s Equation 11.17:

value
maxp(znk=1xn)rnk\max\lvert p(z_{nk}=1\mid\mathbf{x}_n) - r_{nk}\rvert0.0\mathbf{0.0}

Not approximately. The same arithmetic, written twice, three sections apart.

Given the current parameters θ(t)\boldsymbol\theta^{(t)}, the E-step computes

Q(θθ(t))=Ezx,θ(t)[logp(x,zθ)](11.73a)Q(\boldsymbol\theta\mid\boldsymbol\theta^{(t)}) = \mathbb{E}_{\mathbf{z}\mid\mathbf{x},\boldsymbol\theta^{(t)}}\left[\log p(\mathbf{x},\mathbf{z}\mid\boldsymbol\theta)\right] \qquad \text{(11.73a)}

and “the M-step selects an updated set of model parameters θ(t+1)\boldsymbol\theta^{(t+1)} by maximizing” it. The book states this and stops. Checked, on the book’s own initialisation:

QQ
at the M-step’s answer (Equations 11.54–11.56)15.3098303659-15.3098303659
at a 4040-restart Nelder–Mead maximum of QQ15.3098303659-15.3098303659
difference+5.3×1015\mathbf{+5.3\times10^{-15}}

and parameter by parameter:

optimiserthe M-step
π\boldsymbol\pi0.287001, 0.293890, 0.4191090.287001,\ 0.293890,\ 0.4191090.287001, 0.293890, 0.4191090.287001,\ 0.293890,\ 0.419109
μ\boldsymbol\mu2.701230, 0.403411, 3.704287-2.701230,\ -0.403411,\ 3.7042872.701230, 0.403411, 3.704287-2.701230,\ -0.403411,\ 3.704287
σ2\boldsymbol\sigma^20.144000, 0.438492, 1.5265940.144000,\ 0.438492,\ 1.5265940.144000, 0.438492, 1.5265940.144000,\ 0.438492,\ 1.526594
figure The three weighted averages are not a heuristic — they are an exact maximisation matplotlib
Left, a blue parabola-like curve peaking at a marked red point where a dashed yellow curve touches it. Right, four bars in two groups, the blue slightly taller than the yellow in each. Left, a blue parabola-like curve peaking at a marked red point where a dashed yellow curve touches it. Right, four bars in two groups, the blue slightly taller than the yellow in each.
On the left, Q as a function of the first mean with everything else held at the M-step's answer; the red marker is where Equations 11.54 to 11.56 put it, and it is the peak. The dashed curve is the actual log-likelihood, which touches Q at that point and is larger everywhere else.

What the story buys that the algebra could not

Section titled “What the story buys that the algebra could not”

Generate data from a known mixture — π=(0.5,0.2,0.3)\boldsymbol\pi = (0.5, 0.2, 0.3), μ=(2,1,4)\boldsymbol\mu = (-2, 1, 4), σ2=(0.5,2,1)\boldsymbol\sigma^2 = (0.5, 2, 1) — and fit it back, best of five restarts:

NNmaxμtruth\max\lvert\boldsymbol\mu - \text{truth}\rvertmaxσ2truth\max\lvert\boldsymbol\sigma^2 - \text{truth}\rvertmaxπtruth\max\lvert\boldsymbol\pi - \text{truth}\rvert
2002000.2314410.2314411.6053731.6053730.0605640.060564
200020000.3610820.3610821.0522171.0522170.0450840.045084
20,00020{,}0000.0687190.0687190.5560540.5560540.0365190.036519
200,000200{,}0000.022924\mathbf{0.022924}0.080283\mathbf{0.080283}0.005596\mathbf{0.005596}

Each row is a single dataset, so individual rows fluctuate — the N=2000N = 2000 draw is unlucky on the means. Across the three orders of magnitude the trend is unambiguous: μ\mu improves by 10×10\times, σ2\sigma^2 by 20×20\times, π\boldsymbol\pi by 11×11\times, against the 100031.6\sqrt{1000} \approx 31.6 a perfectly behaved estimator would give.

This check is only possible because of §11.4. Without a generative process there is no “truth” to recover — you can measure a likelihood, but you cannot ask whether the parameters are right.

pch.quizTag Does the latent-variable view land?
  1. What is the latent variable z in Section 11.4?

    pch.quizShowAnswer

    B — A one-hot indicator saying which of the K components generated the point — Chapter 10's latent variable was continuous and lived in R^M; this one is discrete with K states. Think of it as a missing column in the dataset: if you could see which component made each point, fitting would be Chapter 8's closed forms applied group by group.

  2. What is the relationship between the responsibility and the posterior over z?

    pch.quizShowAnswer

    B — They are the same quantity — computing the joint over the marginal reproduces Equation 11.17 to exactly 0.0 — Section 11.2.1 could only call the responsibility a soft assignment. Now it has a referent: the probability that component k did in fact generate the point. That is what licenses treating the column sums as counts, and what makes the assignment differentiable.

  3. Does the M-step really maximise Q, or is that an approximation?

    pch.quizShowAnswer

    B — It is exact — a 40-restart numerical maximisation of Q lands on the same parameters to six decimals, differing in Q by 5.3e-15 — Every parameter agrees: the weights, the means and the variances. The three weighted averages of Section 11.2 are not a heuristic that happens to work — they are the closed-form argmax of the expected complete-data log-likelihood.

  4. Why does raising Q raise L?

    pch.quizShowAnswer

    B — Because L = Q + H with H the entropy of the responsibilities, so Q is a lower bound on L that is tight at the current parameters — Measured at the book's initialisation: Q is minus 28.7899, H is 0.4644, and their sum is L to 1.1e-14. After the M-step, Q rose by 13.480070 and L by 13.915050 — L gains more, because the new responsibilities are more confident and the entropy term grows too.

Exercise 1 – Sample from the story, recover the density

Section titled “Exercise 1 – Sample from the story, recover the density”

Exercise 2 – The responsibility, computed as a posterior

Section titled “Exercise 2 – The responsibility, computed as a posterior”

Exercise 3 – Does the M-step maximise Q?

Section titled “Exercise 3 – Does the M-step maximise Q?”
  • Section 11.4 adds a missing column to the dataset: a one-hot indicator saying which component made each point. If you could see it, fitting would be Chapter 8’s closed forms group by group.
  • Chapter 10’s latent variable was continuous; this one is discrete with K states, and the prior over it is the mixture weights.
  • Ancestral sampling from the model reproduces the mixture density — 1.5 million draws matching Equation 11.66b to a bin-probability gap of 3.4e-04, against a sampling floor of 1.7e-04.
  • The responsibility is a posterior, exactly. Computing the joint over the marginal reproduces Equation 11.17 to 0.0, not approximately.
  • That is what licenses three earlier moves: summing responsibilities as counts, differentiating a soft assignment, and alternating at all.
  • The M-step is the exact argmax of Q, the expected complete-data log-likelihood — matched by a forty-restart numerical search to 5.3e-15, with every parameter agreeing to six decimals.
  • So the three weighted averages of Section 11.2 are not heuristics. They are a closed-form maximisation of something.
  • L equals Q plus the entropy of the responsibilities, measured to 1.1e-14, so Q is a lower bound that is tight at the current parameters.
  • Raising a tight lower bound cannot lower what it bounds, which is page 1107’s monotonicity guarantee with a reason attached.
  • And L rises by more than Q does — 13.915050 against 13.480070 — because the new responsibilities are sharper, so the entropy grows too.
  • The generative story also supplies a truth to recover. Fitting data generated from known parameters, the errors fall by factors of 10, 20 and 11 as N goes from 200 to 200,000.
  • Without Section 11.4 that check does not exist: you can measure a likelihood, but you cannot ask whether the parameters are right.

Next: Chapter 11 Worked Problems — problems built from the chapter’s own claims, this module’s own.

pch.coffeeTagline

pch.coffeeCta

pch.feedbackHeading

pch.feedbackSubheading