Skip to content

Updating the Covariances

The second update runs the same argument as the first, with a harder derivative. §11.2.3 spends three pages on matrix calculus to reach a formula you could have guessed — and the interesting part is what it does to page 1101’s decomposition once it is in place.

  • Theorem 11.2, Equation 11.30, and Example 11.4 reproduced: 10.1440001 \to 0.144000, 0.20.4384920.2 \to 0.438492, 31.5265943 \to 1.526594, rounding to the book’s 0.140.14, 0.440.44, 1.531.53.
  • Which μk\boldsymbol\mu_k Equation 11.30 means. Written with the old means it gives 1.831.83, 0.600.60, 19.9819.98; with the just-updated means it gives the book’s numbers. The equation does not say, and the answer differs by a factor of 1313 on the third component.
  • Equations 11.31–11.38: the proof, and the single cancellation that turns a messy stationarity condition into a weighted second moment. Measured to 2.2×10162.2\times10^{-16}.
  • Why no positive-definiteness repair is ever needed: measured over 60,00060{,}000 variances from random responsibilities, zero negative results.
  • An invariant the book does not state, stronger than page 1104’s: after any M-step, the mixture’s variance equals the sample variance exactly — measured to 3.6×10153.6\times10^{-15} over 20,00020{,}000 arbitrary responsibility matrices, and for every KK from 22 to 1010.
  • So EM moves variance from between components to within them and back, with the total pinned — page 1101’s decomposition, in motion.
  • And the singularity from the covariance side: as a component’s responsibility concentrates on one point, σk20\sigma_k^2 \to 0 linearly in the leftover mass.

Intuition: the same weighted average, one moment up

Section titled “Intuition: the same weighted average, one moment up”

Page 1104’s update was nwnxn\sum_n w_n x_n with wn=rnk/Nkw_n = r_{nk}/N_k. This one is nwn(xnμk)2\sum_n w_n(x_n-\mu_k)^2the same weights, applied to squared deviations instead of positions.

That is the whole of Theorem 11.2. The three pages of matrix calculus exist to show that the derivative of logdet\log\det and the derivative of a quadratic form conspire to leave exactly this, with the inverse covariances cancelling as they did for the means.

diagram The same skeleton, one moment higher mermaid

Theorem 11.2 (Updates of the GMM Covariances). The update of the covariance parameters Σk\boldsymbol\Sigma_k of the GMM is given by

Σknew=1Nkn=1Nrnk(xnμk)(xnμk)(11.30)\boldsymbol\Sigma_k^{\text{new}} = \frac{1}{N_k}\sum_{n=1}^{N} r_{nk}(\mathbf{x}_n-\boldsymbol\mu_k)(\mathbf{x}_n-\boldsymbol\mu_k)^\top \qquad \text{(11.30)}

The proof needs two identities from Chapter 5 — Equation 5.101 for det(Σ)1/2\partial\det(\boldsymbol\Sigma)^{-1/2} and Equation 5.106 for the derivative of the quadratic form — which combine into

p(xnθ)Σk=πkN(xnμk,Σk)(12(Σk1Σk1(xnμk)(xnμk)Σk1))(11.35)\frac{\partial p(\mathbf{x}_n\mid\boldsymbol\theta)}{\partial\boldsymbol\Sigma_k} = \pi_k\mathcal{N}(\mathbf{x}_n\mid\boldsymbol\mu_k,\boldsymbol\Sigma_k)\cdot\left(-\tfrac12\big(\boldsymbol\Sigma_k^{-1}-\boldsymbol\Sigma_k^{-1}(\mathbf{x}_n-\boldsymbol\mu_k)(\mathbf{x}_n-\boldsymbol\mu_k)^\top\boldsymbol\Sigma_k^{-1}\big)\right) \qquad \text{(11.35)}

and, after the responsibilities reappear and the derivative is set to zero,

NkΣk1=Σk1(nrnk(xnμk)(xnμk))Σk1(11.37a)N_k\boldsymbol\Sigma_k^{-1} = \boldsymbol\Sigma_k^{-1}\left(\sum_n r_{nk}(\mathbf{x}_n-\boldsymbol\mu_k)(\mathbf{x}_n-\boldsymbol\mu_k)^\top\right)\boldsymbol\Sigma_k^{-1} \qquad \text{(11.37a)}

Cancelling Σk1\boldsymbol\Sigma_k^{-1} once from each side gives Equation 11.37b and then Equation 11.30. In one dimension, checked on the book’s numbers:

k=1k=1k=2k=2k=3k=3
Nk/σk2N_k/\sigma_k^214.28631914.2863194.5816294.5816291.9217701.921770
(nrnk(xnμk)2)/(σk2)2\left(\sum_n r_{nk}(x_n-\mu_k)^2\right)/(\sigma_k^2)^214.28631914.2863194.5816294.5816291.9217701.921770

with a gap of 2.2×10162.2\times10^{-16}.

The equation writes μk\boldsymbol\mu_k with no superscript. It matters:

k=1k=1k=2k=2k=3k=3
with the old means (4,0,8)(-4, 0, 8)1.8308031.8308030.6012320.60123219.979741\mathbf{19.979741}
with the new means from Equation 11.200.144000\mathbf{0.144000}0.438492\mathbf{0.438492}1.526594\mathbf{1.526594}
Example 11.4 as printed0.140.140.440.441.531.53
figure The equation does not say which mean, and the two answers differ by a factor of 13 matplotlib
Left, three groups of three bars on a log scale; in each group the red bar is much taller than the blue and yellow ones, which match. Right, three dotted bell curves and three solid ones, the solid ones taller and narrower except the middle one which is shorter and wider. Left, three groups of three bars on a log scale; in each group the red bar is much taller than the blue and yellow ones, which match. Right, three dotted bell curves and three solid ones, the solid ones taller and narrower except the middle one which is shorter and wider.
Example 11.4 follows Example 11.3, and the book's Figure 11.6(a) is its Figure 11.5(b) — so the means have already moved. Using them reproduces the printed variances; using the pre-update means gives 19.98 for the third component instead of 1.53.

Equation 11.30 is nwnvnvn\sum_n w_n \mathbf{v}_n\mathbf{v}_n^\top with wn0w_n \geq 0 — a non-negative combination of rank-one positive semi-definite matrices. So the result is positive semi-definite by construction, with no projection, clipping or eigenvalue repair.

Measured in one dimension over 20,00020{,}000 random responsibility matrices (60,00060{,}000 variances):

value
variances that came out negative0\mathbf{0}
smallest value seen1.5084151.508415

Compare page 1005’s measurement, where eigh on a badly conditioned XX\mathbf{X}\mathbf{X}^\top returned 1818 negative eigenvalues of 200200. Here the structure of the update guarantees what the numerics there could not.

Page 1104 measured kNkμk=nxn\sum_k N_k\mu_k = \sum_n x_n. The same swap-the-summation argument, applied to second moments, gives more:

kπk(σk2+μk2)=1Nnxn2\sum_k \pi_k\left(\sigma_k^2 + \mu_k^2\right) = \frac{1}{N}\sum_n x_n^2

so the fitted mixture’s variance is the sample variance, exactly, after any M-step:

value
sample mean0.6428571428570.642857142857
sample variance8.3367346938788.336734693878
worst \lvertmixture mean - sample mean\rvert, 20,00020{,}000 random R\mathbf{R}5.6×10165.6\times10^{-16}
worst \lvertmixture variance - sample variance\rvert3.6×1015\mathbf{3.6\times10^{-15}}

and it does not depend on KK:

KKworst mean gapworst variance gap
225.6×10165.6\times10^{-16}3.6×10153.6\times10^{-15}
335.6×10165.6\times10^{-16}3.6×10153.6\times10^{-15}
556.7×10166.7\times10^{-16}3.6×10153.6\times10^{-15}
10105.6×10165.6\times10^{-16}1.8×10151.8\times10^{-15}
figure The total never moves again after the first M-step matplotlib
Left, a stacked area chart over nine M-steps: a thin blue band at the bottom and a large purple band above it, with a yellow total line that drops once and then runs exactly along a dashed red horizontal line. Right, a log-scale histogram of four thousand values between 1e-17 and 4e-15. Left, a stacked area chart over nine M-steps: a thin blue band at the bottom and a large purple band above it, with a yellow total line that drops once and then runs exactly along a dashed red horizontal line. Right, a log-scale histogram of four thousand values between 1e-17 and 4e-15.
Iteration 0 is the book's initialisation, whose mixture variance is 26.288889 — it has not been fitted to anything yet. Every M-step after that lands the total exactly on the sample variance, 8.336735, and all subsequent movement is variance migrating between the two bands.

As a component’s responsibility concentrates on a single point, Equation 11.30’s weighted second moment about that point collapses:

r11r_{11}μ1\mu_1σ12\sigma_1^2
0.50.50.875000-0.8750008.0885428.088542
0.90.92.575000-2.5750002.3402082.340208
0.990.992.957500-2.9575002.502771×1012.502771\times10^{-1}
0.9990.9992.995750-2.9957502.519027×1022.519027\times10^{-2}
0.999990.999992.999958-2.9999582.520815×104\mathbf{2.520815\times10^{-4}}
figure The variance falls linearly with the mass the component has left elsewhere matplotlib
Left, a straight descending line on log-log axes as the leftover responsibility mass shrinks, with two marked points. Right, four Gaussian curves on a log vertical scale, each narrower and taller than the last, the narrowest a thin spike over the leftmost data point. Left, a straight descending line on log-log axes as the leftover responsibility mass shrinks, with two marked points. Right, four Gaussian curves on a log vertical scale, each narrower and taller than the last, the narrowest a thin spike over the leftmost data point.
Nothing pathological happens at any finite step — the variance simply tracks the leftover responsibility. Page 1102 measured the same event from the likelihood side, where it produced plus 16.377668 at a variance of 1e-30. This is why real implementations floor the variance or put a prior on it.
pch.quizTag Is the covariance update clear?
  1. What does the three-page derivation of Theorem 11.2 actually produce?

    pch.quizShowAnswer

    B — The same responsibility-weighted average as the means, applied to squared deviations instead of positions — The matrix calculus exists to show that the derivatives of the log-determinant and the quadratic form conspire so the inverse covariances cancel, exactly as they did for the means. What is left is a weighted second moment — checked against Equation 11.37b to 0.0.

  2. Equation 11.30 writes mu_k without saying whether it is the old or the new mean. Does it matter?

    pch.quizShowAnswer

    B — Yes — the old means give 1.83, 0.60 and 19.98; the new ones give the book's 0.14, 0.44 and 1.53 — The book resolves it by ordering: Example 11.4 follows Example 11.3, and Figure 11.6(a) is Figure 11.5(b). Section 11.3's algorithm makes it explicit. Using stale means is not merely different but worse — 19.98 is the squared distance from 8 to data that lives below 5.

  3. Why does the covariance update never need a positive-definiteness repair?

    pch.quizShowAnswer

    B — It is a non-negative combination of rank-one positive semi-definite matrices, so the result is PSD by construction — Measured over 60,000 variances from random responsibility matrices: zero negatives. Compare page 1005, where eigh on a badly conditioned product returned 18 negative eigenvalues of 200 — there the numerics broke a mathematical guarantee; here the structure of the update supplies it.

  4. After any M-step, what is the fitted mixture's variance?

    pch.quizShowAnswer

    B — Exactly the sample variance — measured to 3.6e-15 over 20,000 arbitrary responsibility matrices and every K from 2 to 10 — So EM cannot make the model narrower or wider than the data overall. It can only decide how much of the spread is between components and how much is within them — page 1101's decomposition, with the total pinned. A collapsing component satisfies the invariant and is still useless.

Exercise 1 – Reproduce Example 11.4, and find which mean it used

Section titled “Exercise 1 – Reproduce Example 11.4, and find which mean it used”

Exercise 2 – The cancellation in Equation 11.37

Section titled “Exercise 2 – The cancellation in Equation 11.37”

Exercise 3 – A weighted second moment cannot be negative

Section titled “Exercise 3 – A weighted second moment cannot be negative”

Exercise 4 – The invariant, one moment up

Section titled “Exercise 4 – The invariant, one moment up”

Exercise 5 – Watch the within/between trade run

Section titled “Exercise 5 – Watch the within/between trade run”
  • Theorem 11.2 is the mean update one moment higher: the same responsibility weights, applied to squared deviations instead of positions.
  • Three pages of matrix calculus produce one cancellation — an inverse covariance removed from each side of the stationarity condition — and Equation 11.30 falls out. Checked to 2.2e-16.
  • Equation 11.30 does not say which mean it uses, and it matters: the old means give 1.83, 0.60 and 19.98, the just-updated ones give the book’s 0.14, 0.44 and 1.53.
  • The ordering is the answer. Section 11.3’s M-step updates the means first; using stale means measures spread about a point the component has already left.
  • The update is a non-negative combination of squares, so it is positive semi-definite by construction — zero negatives in sixty thousand measured values, with no repair step anywhere.
  • An invariant stronger than page 1104’s: after any M-step the mixture’s variance equals the sample variance exactly, measured to 3.6e-15 over twenty thousand arbitrary responsibility matrices.
  • And it holds for every K from two to ten, because the argument is only the rows of the responsibility matrix summing to one.
  • So EM cannot make the model wider or narrower than the data. It can only decide how much spread is between components and how much is within them.
  • That is page 1101’s decomposition, in motion: on the book’s example the total drops to 8.336735 at the first M-step and never moves again, while within and between keep trading.
  • It also reframes the collapse: a component shrinking to zero width pushes all its variance into the between term, satisfies the invariant, and is useless.
  • From this side the singularity is linear: the variance falls in step with the responsibility mass the component has left elsewhere, reaching 2.5e-04 at a responsibility of 0.99999.

Next: Updating the Mixture Weights — §11.2.4, the shortest of the three, and the only one that needs a Lagrange multiplier.

pch.coffeeTagline

pch.coffeeCta

pch.feedbackHeading

pch.feedbackSubheading