Skip to content

Chapter 11 Formula Sheet

One page for the whole chapter. Equation numbers are the book’s; the measured columns are this module’s, computed on the chapter’s own seven-point example X={3,2.5,1,0,2,4,5}\mathcal{X} = \{-3, -2.5, -1, 0, 2, 4, 5\} with K=3K = 3 unless stated otherwise.

Three parameters, one derivation run three times.

§11.2.2 the means§11.2.3 the covariances§11.2.4 the weights
theorem11.111.211.3
the updateμk=1Nknrnkxn\boldsymbol\mu_k = \frac{1}{N_k}\sum_n r_{nk}\mathbf{x}_nΣk=1Nknrnk(xnμk)(xnμk)\boldsymbol\Sigma_k = \frac{1}{N_k}\sum_n r_{nk}(\mathbf{x}_n-\boldsymbol\mu_k)(\mathbf{x}_n-\boldsymbol\mu_k)^\topπk=NkN\pi_k = \frac{N_k}{N}
equation11.2011.3011.42
what cancelsΣk1\boldsymbol\Sigma_k^{-1}, on the rightΣk1\boldsymbol\Sigma_k^{-1}, on both sidesnothing
needs a multipliernonoyes, λ=N\lambda = -N
reads the data valuesyesyesno
nats gained on Example 11.3–11.512.3212.321.461.460.140.14
all three areresponsibility-weighted averages, and none is a closed form — each mentions every other parameter through rnkr_{nk}
whatequation
a mixture densityp(x)=k=1Kπkpk(x)p(\mathbf{x}) = \sum_{k=1}^{K}\pi_k p_k(\mathbf{x})11.1
the weights0πk10 \leq \pi_k \leq 1, kπk=1\sum_k \pi_k = 111.2, both halves needed
the GMMp(xθ)=kπkN(xμk,Σk)p(\mathbf{x}\mid\boldsymbol\theta) = \sum_k \pi_k\,\mathcal{N}(\mathbf{x}\mid\boldsymbol\mu_k,\boldsymbol\Sigma_k)11.3
its weight constraints0πk10 \leq \pi_k \leq 1, kπk=1\sum_k \pi_k = 111.4, with θ:={μk,Σk,πk}\boldsymbol\theta := \{\boldsymbol\mu_k,\boldsymbol\Sigma_k,\pi_k\} named in the text beneath it
the running example0.5N(x2,12)+0.2N(x1,2)+0.3N(x4,1)0.5\,\mathcal{N}(x\mid-2,\tfrac12) + 0.2\,\mathcal{N}(x\mid1,2) + 0.3\,\mathcal{N}(x\mid4,1)11.5
the meanE[x]=kπkμk\mathbb{E}[x] = \sum_k \pi_k\mu_k — a weighted average
the varianceV[x]=kπkσk2+kπk(μkE[x])2\mathbb{V}[x] = \sum_k \pi_k\sigma_k^2 + \sum_k \pi_k(\mu_k-\mathbb{E}[x])^2not a weighted average

§11.2 Maximum likelihood and the obstacle

Section titled “§11.2 Maximum likelihood and the obstacle”
whatequation
the likelihoodp(Xθ)=np(xnθ)p(\mathcal{X}\mid\boldsymbol\theta) = \prod_n p(\mathbf{x}_n\mid\boldsymbol\theta)11.9
the log-likelihoodL=nlogkπkN(xnμk,Σk)L = \sum_{n}\log\sum_{k}\pi_k\,\mathcal{N}(\mathbf{x}_n\mid\boldsymbol\mu_k,\boldsymbol\Sigma_k)11.10
the K=1K=1 casethe log lands on the Gaussian and the answer is closed-form — 11.11
the stationarity conditionsL/μk=0\partial L/\partial\boldsymbol\mu_k = \mathbf{0}, L/Σk=0\partial L/\partial\boldsymbol\Sigma_k = \mathbf{0}, L/πk=0\partial L/\partial\pi_k = 011.1211.14
the chain rulelogp(xnθ)θ=1p(xnθ)p(xnθ)θ\frac{\partial\log p(\mathbf{x}_n\mid\boldsymbol\theta)}{\partial\boldsymbol\theta} = \frac{1}{p(\mathbf{x}_n\mid\boldsymbol\theta)}\frac{\partial p(\mathbf{x}_n\mid\boldsymbol\theta)}{\partial\boldsymbol\theta}11.15
the factor it drags in1p(xnθ)=(jπjN(xnμj,Σj))1\frac{1}{p(\mathbf{x}_n\mid\boldsymbol\theta)} = \big(\sum_j\pi_j\mathcal{N}(\mathbf{x}_n\mid\boldsymbol\mu_j,\boldsymbol\Sigma_j)\big)^{-1}11.16
whatequation
the responsibilityrnk:=πkN(xnμk,Σk)jπjN(xnμj,Σj)r_{nk} := \dfrac{\pi_k\mathcal{N}(\mathbf{x}_n\mid\boldsymbol\mu_k,\boldsymbol\Sigma_k)}{\sum_j\pi_j\mathcal{N}(\mathbf{x}_n\mid\boldsymbol\mu_j,\boldsymbol\Sigma_j)}11.17
each rowrn=[rn1,,rnK]\mathbf{r}_n = [r_{n1},\ldots,r_{nK}]^\top, a probability vector — 11.18
the book’s matrixR\mathbf{R} for the seven points — 11.19
the effective countNk:=nrnkN_k := \sum_n r_{nk}, fractional, kNk=N\sum_k N_k = N11.24
the data-side probability vectorrk\mathbf{r}_k with entries rnk/Nkr_{nk}/N_k11.25
as a softmaxrnk=eEnk/jeEnjr_{nk} = e^{-E_{nk}}/\sum_j e^{-E_{nj}}, Enk=12(xnμk)Σk1(xnμk)+12logdetΣklogπkE_{nk} = \tfrac12(\mathbf{x}_n-\boldsymbol\mu_k)^\top\boldsymbol\Sigma_k^{-1}(\mathbf{x}_n-\boldsymbol\mu_k) + \tfrac12\log\det\boldsymbol\Sigma_k - \log\pi_k
whatequation
the Gaussian’s μ\boldsymbol\mu-gradientNμk=(xnμk)Σk1N\frac{\partial\mathcal{N}}{\partial\boldsymbol\mu_k} = (\mathbf{x}_n-\boldsymbol\mu_k)^\top\boldsymbol\Sigma_k^{-1}\mathcal{N}11.21b
assembledLμk=nrnk(xnμk)Σk1\frac{\partial L}{\partial\boldsymbol\mu_k} = \sum_n r_{nk}(\mathbf{x}_n-\boldsymbol\mu_k)^\top\boldsymbol\Sigma_k^{-1}11.22c
setting it to zeronrnkxn=Nkμknew\sum_n r_{nk}\mathbf{x}_n = N_k\boldsymbol\mu_k^{\text{new}}11.23
Theorem 11.1μknew=nrnkxnNk\boldsymbol\mu_k^{\text{new}} = \dfrac{\sum_n r_{nk}\mathbf{x}_n}{N_k}11.20
as an expectationμknew=Erk[X]\boldsymbol\mu_k^{\text{new}} = \mathbb{E}_{\mathbf{r}_k}[\mathcal{X}]11.26
Example 11.342.701230-4 \to -2.701230, 00.4034110 \to -0.403411, 83.7042878 \to 3.70428711.2711.29
whatequation
the Gaussian’s Σ\boldsymbol\Sigma-gradientpΣk=πkN(12(Σk1Σk1(xnμk)(xnμk)Σk1))\frac{\partial p}{\partial\boldsymbol\Sigma_k} = \pi_k\mathcal{N}\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)11.35
stationarityNkΣk1=Σk1(nrnk(xnμk)(xnμk))Σk1N_k\boldsymbol\Sigma_k^{-1} = \boldsymbol\Sigma_k^{-1}\big(\sum_n r_{nk}(\mathbf{x}_n-\boldsymbol\mu_k)(\mathbf{x}_n-\boldsymbol\mu_k)^\top\big)\boldsymbol\Sigma_k^{-1}11.37a
Theorem 11.2Σknew=1Nknrnk(xnμk)(xnμk)\boldsymbol\Sigma_k^{\text{new}} = \dfrac{1}{N_k}\sum_n r_{nk}(\mathbf{x}_n-\boldsymbol\mu_k)(\mathbf{x}_n-\boldsymbol\mu_k)^\top11.30
as an expectationan importance-weighted mean of X~k={xnμk}\widetilde{\mathcal{X}}_k = \{\mathbf{x}_n-\boldsymbol\mu_k\}11.38
Example 11.410.141 \to 0.14, 0.20.440.2 \to 0.44, 31.533 \to 1.5311.3911.41
whatequation
the LagrangianL=L+λ(kπk1)\mathfrak{L} = L + \lambda\big(\sum_k\pi_k - 1\big)11.43a
the derivativeLπk=Nkπk+λ\frac{\partial\mathfrak{L}}{\partial\pi_k} = \frac{N_k}{\pi_k} + \lambda11.44b
the constraintLλ=kπk1=0\frac{\partial\mathfrak{L}}{\partial\lambda} = \sum_k\pi_k - 1 = 011.45
solvingπk=Nk/λ\pi_k = -N_k/\lambda11.46, then kNk=N\sum_k N_k = N11.47
the multiplierλ=N\lambda = -N11.48
Theorem 11.3πknew=NkN\pi_k^{\text{new}} = \dfrac{N_k}{N}11.42
Example 11.5130.293890, 0.287001, 0.419109\tfrac13 \to 0.293890,\ 0.287001,\ 0.419109 — the book’s 0.290.29, 0.290.29, 0.420.42
stepequation
initialiseμk,Σk,πk\boldsymbol\mu_k,\boldsymbol\Sigma_k,\pi_k
E-steprnk=πkN(xnμk,Σk)jπjN(xnμj,Σj)r_{nk} = \dfrac{\pi_k\mathcal{N}(\mathbf{x}_n\mid\boldsymbol\mu_k,\boldsymbol\Sigma_k)}{\sum_j\pi_j\mathcal{N}(\mathbf{x}_n\mid\boldsymbol\mu_j,\boldsymbol\Sigma_j)}11.53
M-step, in this orderμk=1Nknrnkxn\boldsymbol\mu_k = \frac{1}{N_k}\sum_n r_{nk}\mathbf{x}_n11.54
Σk=1Nknrnk(xnμk)(xnμk)\boldsymbol\Sigma_k = \frac{1}{N_k}\sum_n r_{nk}(\mathbf{x}_n-\boldsymbol\mu_k)(\mathbf{x}_n-\boldsymbol\mu_k)^\top11.55
πk=Nk/N\pi_k = N_k/N11.56
the guaranteeLL is non-decreasing at every step (Neal and Hinton, 1999)
measured on the book’s examplevalue
negative log-likelihood, start to first cycle28.32553614.41048528.325536 \to 14.410485 — the book’s 28.328.3 and 14.414.4
Example 11.6’s “after five iterations”the 10610^{-6} criterion, reproduced exactly; 88 at 10910^{-9}
LL settles before the parameters do55 against 1111 iterations at 10610^{-6}
whatequation
the indicatorz=[z1,,zK]\mathbf{z} = [z_1,\ldots,z_K]^\top, one-hot — defined in the text of §11.4.1, unnumbered
the conditionalp(xzk=1)=N(xμk,Σk)p(\mathbf{x}\mid z_k=1) = \mathcal{N}(\mathbf{x}\mid\boldsymbol\mu_k,\boldsymbol\Sigma_k)11.58
the priorp(z)=πp(\mathbf{z}) = \boldsymbol\pi, πk=p(zk=1)\pi_k = p(z_k=1)11.59, 11.60
the joint, one componentp(x,zk=1)=πkN(xμk,Σk)p(\mathbf{x},z_k=1) = \pi_k\mathcal{N}(\mathbf{x}\mid\boldsymbol\mu_k,\boldsymbol\Sigma_k)11.61
the joint, stackedthe KK-vector of those products — 11.62, “which fully specifies the probabilistic model”
marginalising z\mathbf{z}p(xθ)=zp(xθ,z)p(zθ)p(\mathbf{x}\mid\boldsymbol\theta) = \sum_{\mathbf{z}}p(\mathbf{x}\mid\boldsymbol\theta,\mathbf{z})p(\mathbf{z}\mid\boldsymbol\theta), recovering Equation 11.3 — 11.63, 11.65, 11.66b
the dataset likelihoodp(Xθ)=nkπkN(xnμk,Σk)p(\mathcal{X}\mid\boldsymbol\theta) = \prod_n\sum_k\pi_k\mathcal{N}(\mathbf{x}_n\mid\boldsymbol\mu_k,\boldsymbol\Sigma_k)11.67, i.e. Equation 11.9 again
the posteriorp(zk=1x)=πkN(xμk,Σk)jπjN(xμj,Σj)p(z_k=1\mid\mathbf{x}) = \dfrac{\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)}11.69
the conditional factorisesp(x1,,xNz1,,zN)=np(xnzn)p(\mathbf{x}_1,\ldots,\mathbf{x}_N\mid\mathbf{z}_1,\ldots,\mathbf{z}_N) = \prod_n p(\mathbf{x}_n\mid\mathbf{z}_n)11.71
and over a datasetp(znk=1xn)=rnkp(z_{nk}=1\mid\mathbf{x}_n) = r_{nk}11.72b, the identification the chapter was built toward
the E-step’s objectQ(θθ(t))=Ezx,θ(t)[logp(x,zθ)]Q(\boldsymbol\theta\mid\boldsymbol\theta^{(t)}) = \mathbb{E}_{\mathbf{z}\mid\mathbf{x},\boldsymbol\theta^{(t)}}[\log p(\mathbf{x},\mathbf{z}\mid\boldsymbol\theta)]11.73a
the M-stepθ(t+1)=argmaxθQ(θθ(t))\boldsymbol\theta^{(t+1)} = \arg\max_{\boldsymbol\theta} Q(\boldsymbol\theta\mid\boldsymbol\theta^{(t)})

§11.5 What the chapter assumes, and what it costs

Section titled “§11.5 What the chapter assumes, and what it costs”

§11.5 is a page of caveats. Page 1109 runs each one.

what §11.5 sayswhat page 1109 measured
KK is known… in practice this is often not the case”; use nested cross-validationheld-out LL, BIC and AIC pick 33, 33 and 44 on the same table
— the same, as NN growsBIC reaches 20/2020/20; held-out LL peaks at 19/2019/20 and falls back to 14/2014/20
— the same, on non-Gaussian dataa uniform asks for 55 or 66, a Student-tt for 33 that mean nothing
“the likelihood approaches infinity” when a component collapsesa floor prices that at 1.15131.1513 nats per decade; the honest optimum is 128.9013-128.9013
a Bayesian prior would give “a principled way to determine the number of mixture components”BIC, its asymptotic approximation, is the only criterion here that stays right as NN grows
histograms and kernel density estimation as the non-parametric route600600 stored points, 13.713.7 nats behind 88 numbers, and the bandwidth swings the score 273273
(not mentioned) the covariance structure of Equation 11.3tying costs 1.87691.8769 nats held out; BIC then prefers the tied model
(not mentioned) identifiabilityevery optimum has K!K! copies, identical to a spread of 0.000×1000.000\times10^{0}
quantityvaluepage
variance of Equation 11.5, within / between0.950.95 / 6.846.84 (87.80%87.80\%) of 7.797.791101
skewness, excess kurtosis of Equation 11.50.4271850.427185, 1.294278-1.2942781101
KL to the closest single Gaussian0.3305850.330585 nats1101
two equal Gaussians merge atd=1.0000000d = 1.0000000 (2σ2\sigma apart); 1.6572511.657251 at weight 0.90.91101
a GMM’s edge over one Gaussian1.3886101.388610 nats per point, for 1212 extra parameters1101
the book’s starting negative log-likelihood28.32553628.325536 — its 28.328.31102
Equation 11.9’s product underflows atabout 200200 data points1102
K=1K=1 closed form vs an optimiser6×1086\times10^{-8}1102
analytic gradient vs central differences3×10103\times10^{-10}1102
feeding Equation 11.20 back inmoves the means 4.2957134.295713, then 0.1307750.130775, then 0.0184140.0184141102
400400 restarts on 77 points1717 distinct optima; 218218 (54.5%54.5\%) collapse1102
the unbounded likelihood+16.377668+16.377668 at σ2=1030\sigma^2 = 10^{-30}1102
the book’s basin vs the best honest one13.973323-13.973323 vs 13.906162-13.9061621102
Equation 11.19’s disputed entry (x=0x=0)printed 0.0010.001; computed 0.000150\mathbf{0.000150}1103
responsibilities as a softmax of E-\mathbf{E}1.1×10161.1\times10^{-16}1103
mean row entropy at convergence0.0140.014 against a possible 1.0991.0991103
Equation 11.17 typed as written2121 NaNs of 2121; log-space agrees to 2.2×10162.2\times10^{-16}1103
K-means from the same startcentres 1.5041191.504119 apart, split 33-22-221103
Example 11.3 reproduced2.701230-2.701230, 0.403411-0.403411, 3.7042873.7042871104
means stay inside the data’s range00 excursions over 4,0004{,}000 starts1104
kNkμk=nxn\sum_k N_k\boldsymbol\mu_k = \sum_n \mathbf{x}_n3.6×10153.6\times10^{-15} over 2,0002{,}000 matrices1104
component death, NkN_k underflows atμ3=73.585070\mu_3 = 73.585070 (and 69.812512-69.812512)1104
the mean update alone12.32138512.321385 nats, stalling at 15.964728-15.9647281104
Equation 11.30 with old vs new means1.83/0.60/19.981.83/0.60/19.98 vs 0.14/0.44/1.530.14/0.44/1.53 — factor 13.087813.08781105
positive semi-definiteness00 negatives in 60,00060{,}000 values, no repair step1105
the mixture’s variance after any M-step== the sample variance, 3.6×10153.6\times10^{-15} over 20,00020{,}0001105
that total on the book’s example8.3367358.336735 from the first M-step onward1105
the singularity from the variance side2.5×1042.5\times10^{-4} at a responsibility of 0.999990.999991105
unconstrained ascent on the weightsthe sum reaches 2.542.54 in six steps1106
the Lagrange multiplierexactly N-N, deviation 001106
Example 11.5 reproduced0.2938900.293890, 0.2870010.287001, 0.4191090.4191091106
one full cycle28.32553614.41048528.325536 \to 14.410485 — the book’s 28.314.428.3 \to 14.41106
the split of the 13.9213.92 natsmeans 12.3212.32, variances 1.461.46, weights 0.140.141106
“after five iterations”the 10610^{-6} criterion exactly; 88 at 10910^{-9}1107
LL vs parameters settling55 against 1111 iterations at 10610^{-6}1107
monotonicity over 180,000180{,}000 steps11,16311{,}163 negative, none above 8.9×10158.9\times10^{-15}1107
median decrease1.776×10151.776\times10^{-15} — one ULP1107
overlap and the convergence rate10451045 iterations at 53%53\% ambiguous vs 33 at 0%0\%1107
K-means initialisationmedian 581958 \to 19; best optimum 96%100%96\% \to 100\%1107
Equation 11.69 vs Equation 11.170.00.01108
the M-step as the argmax of QQ5.3×10155.3\times10^{-15} over 4040 restarts1108
L=Q+H(r)L = Q + H(\mathbf{r})1.1×10141.1\times10^{-14}1108
the step’s rise in LL and in QQ13.91505013.915050 against 13.48007013.4800701108
parameter recovery, N=200N = 200 to 200,000200{,}000errors fall by factors of 1010, 2020 and 11111108
choosing KK: train / held-out / BIC / AIC66 / 3\mathbf{3} / 3\mathbf{3} / 441109
a variance floor’s price12ln10=1.1513\tfrac12\ln 10 = 1.1513 nats per decade1109
the honest six-component optimum128.9013-128.9013, against 120.9761-120.9761 for a spike1109
label switching, all 3!3! relabellingsspread 0.000×1000.000\times10^{0}1109
GMM as a classifier, held out0.96500.9650 — equal to the labelled fit, Bayes rate 0.96330.96331109
tying the variancescosts 1.87691.8769 nats held out, saves 8.88568.8856 of BIC1109
held-out LL recovering KK as NN grows111919151411 \to 19 \to 19 \to 15 \to 14 of 20201109
BIC recovering KK as NN grows101320202010 \to 13 \to 20 \to 20 \to 20 of 20201109
GMM vs the best KDE88 numbers, 13.713.7 nats ahead of 600600 points1109
  1. A mixture buys multimodality for a handful of parameters1.3886101.388610 nats per point for twelve of them — and pays with the closed form.
  2. Equation 11.2 needs both halves. Weights that sum to one but go negative still integrate to one and are still not a density.
  3. The variance of a mixture is not the average of the variances, and that decomposition is conserved by every M-step.
  4. Equation 11.10’s log sits outside a sum, so the chain rule drags 1/p(xn)1/p(\mathbf{x}_n) into every derivative and every parameter’s equation mentions every other.
  5. Equation 11.20 is a fixed point, not a formula. Feeding it back in moves the means by 4.2957134.295713.
  6. The responsibility is that dragged-in factor, named — and §11.4 shows it is a posterior, exactly.
  7. All three updates are the same derivation: weighted average of the data, of the squared deviations, of nothing at all.
  8. Only the weights need a Lagrange multiplier, because only they are constrained — and it comes out as N-N, carrying no information.
  9. Order the M-step. Equation 11.30 with stale means is wrong by a factor of 13.087813.0878 on the book’s third component.
  10. EM’s guarantee holds to one ULP, so test convergence against a tolerance and never against zero.
  11. The maximum likelihood estimate does not exist. A floor prices the singularity at 1.15131.1513 nats per decade; a prior removes it.
  12. §11.5’s ”KK is known” is doing the heaviest lifting in the chapter — held-out likelihood is not even a consistent estimator of it.

Back to the start: Density Estimation Overview

pch.coffeeTagline

pch.coffeeCta

pch.feedbackHeading

pch.feedbackSubheading