S1436 of 55
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

S14 · Lesson 36 · Mixture models and EM

Clustering with k-means, Gaussian mixture densities and the responsibility each component takes for a point, the expectation-maximization algorithm's two steps worked by hand, why the likelihood never decreases, and the collapse that regularization prevents

A batch of measurements from two production lines, mixed together without labels, forms a lumpy distribution that no single Gaussian fits. A mixture model explains it as several Gaussians added together, and fitting one is a chicken-and-egg problem: knowing which line each measurement came from would make the fit trivial, and knowing the fit would tell you which line each came from. The expectation-maximization algorithm breaks the circle by alternating between the two, softly, and it's guaranteed to improve every round. The same idea trains hidden Markov models (lesson 42) and decodes many communication codes.

  • A mixture of two unit-variance Gaussians with means a and b and weights π and 1 − π, and the responsibility of the first component: the posterior probability that a point at x came from it.
  • Between the means, responsibility switches from one component to the other; the switch moves toward the lighter component as π grows.
  • Overlapping components share responsibility over a wide range, which makes the clusters harder to separate.

Predict

Two equally weighted unit-variance components sit at 0 and 3. What responsibility does the first take for a point at x = 1?

Name it

k-means

Pick K centers; assign each point to its nearest center; move each center to the mean of its points; repeat. Each step lowers the total squared distance J=∑n‖𝐱n−𝝁k(n)‖2, so it stops, though perhaps at a local minimum. It makes hard, all-or-nothing assignments.

Gaussian mixtures

p(𝐱)=∑k=1Kπk𝒩(𝐱|𝝁k,Σk),∑kπk=1

The responsibility of component k for point n is its posterior probability:

γnk=πk𝒩(𝐱n|𝝁k,Σk)∑jπj𝒩(𝐱n|𝝁j,Σj)

In D dimensions with full covariances, K components have K(D+D(D+1)2)+K−1 parameters.

Expectation-maximization

  • E step: compute every γnk from the current parameters.
  • M step: refit each component as a weighted Gaussian. With Nk=∑nγnk:
𝝁k=1Nk∑nγnk𝐱n,Σk=1Nk∑nγnk(𝐱n−𝝁k)(𝐱n−𝝁k)T,πk=NkN

Each round never decreases the log-likelihood ∑nln⁡p(𝐱n), so EM converges, to a local maximum that depends on the start. k-means is the limit of EM with equal, vanishing variances.

Collapse

If a component shrinks onto a single data point, its density there grows without bound and so does the likelihood. Practical EM floors the variances or adds a prior on them.

Worked example

A component has responsibilities 0.9, 0.7 and 0.1 for the points 0, 1 and 4. Carry out its M step.

Show the solution
  1. Effective count and weight. N1=1.7π1=1.7/3=0.567
  2. Mean. μ1=(0.9×0+0.7×1+0.1×4)/1.7=0.647
  3. Variance. σ12=[0.9(0.647)2+0.7(0.353)2+0.1(3.353)2]/1.7=0.934
  4. The far point. The point at 4 counts only a tenth, but it still widens the component.

Answer π1 = 0.567, the mean is 0.647 and the variance is 0.934.

Worked example

What's the log-likelihood of a point at x = 1 under the predict question's mixture, and how many parameters does a three-component mixture in two dimensions have?

Show the solution
  1. Density at x = 1. p(1)=0.5×0.242+0.5×0.054=0.148 so ln p = −1.911.
  2. Three components in 2D. 3×(2+3)+2=17
  3. Five components in 10D. 5×(10+55)+4=329

Answer the log-likelihood is −1.911, and the three-component mixture in two dimensions has 17 parameters.

Worked example

Run k-means with k = 2 on the points 0, 1, 4, 5 and 9, starting with centers at 0 and 9.

Show the solution
  1. Assign. Each point goes to its nearer center: 0, 1 and 4 go to the first (4 is 4 from 0 and 5 from 9), 5 and 9 to the second.
  2. Update. The new centers are the means: μ1=(0+1+4)/3=1.67μ2=(5+9)/2=7
  3. Reassign. Nothing changes (4 is 2.33 from 1.67 and 3 from 7; 5 is 3.33 and 2), so the algorithm has converged.
  4. Distortion. J=2.78+0.44+5.44+4+4=16.7
  5. Link to EM. k-means is EM's limit for equal, vanishing variances: hard assignments in place of responsibilities.

Answer k-means converges to clusters {0, 1, 4} and {5, 9}, with centers 1.67 and 7 and a distortion of 16.7.

Check

A mixture has unit-variance components at −1 and 1.5 with weights 0.8 and 1 − 0.8. What responsibility does the first take for a point at 1?

Check

A component's responsibilities for the points 1, 2 and 5 are 0.2, 0.4 and 0.6. What's its new mean in the M step?

Check

Out of 10 points, a component's responsibilities are 0.2, 0.4 and 0.6 (zero for the rest). What's its new mixing weight?

Check

A component takes responsibilities 0.5 and 0.3 for the points 1 and 5. What's its new variance?

Check

How many parameters does a 4-component Gaussian mixture with full covariances have in 2 dimensions?

Check

What's the log-likelihood of a point at 2 under a mixture of unit-variance Gaussians at 0 and 3 with weights 0.6 and 1 − 0.6?

Check

A Gaussian mixture with 3 components and diagonal covariances models 10000 points in 2 dimensions.

(a)

How many free parameters does it have?

(b)

How much does BIC subtract from the log-likelihood for it?

Check

A two-component mixture has weights P and 1 − P, means a and b, and standard deviations s and u; a point x arrives.

Step 1

What responsibility does the first component take for it?

Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.

Explain why

Why does EM need responsibilities, and why does the likelihood never go down?

Practice

Keep practicing

10 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.