EM, Step by Step
← text notes · Foundations › Probability. Three widgets for the Expectation–Maximization algorithm: watch it cluster, watch it climb, and see where the soft assignments come from.
1. EM on 2-D clusters, one step at a time
Each point is coloured by its responsibilities: a point that's surely in one blob takes that blob's colour, and a point that's split between blobs gets a blend. Ellipses show each Gaussian at 1 and 2 standard deviations, with thickness proportional to its weight πk.
Press E-step and only the colours change: the blobs stay put and the points re-vote. Press M-step and only the ellipses change: each blob moves to the weighted average of the points that voted for it. The button that comes next is outlined. Click the canvas to add points.
2. Climbing the likelihood with lower bounds
The red curve is the log-likelihood of 120 one-dimensional points as a function of one parameter, θ = μ1 (the second blob's mean is fixed at 1.8, both variances at 1, both weights at ½). EM never looks at the red curve directly. E-step builds a bound ℒ(q, θ) that lies under it and touches it at the current θ. M-step jumps to the top of that bound. Drag the start slider and step.
3. Where responsibilities come from
Two weighted Gaussians on a line. At every x, the responsibility of the blue blob is its share of the total height: γ1(x) = π1N(x | μ1, σ²) / p(x). With a shared σ, that share is exactly a logistic sigmoid in x, shown in the lower panel. Shrink σ and it sharpens into a step at the midpoint. That's the k-means limit: nearest centre takes all.
Data are generated in the browser from a fixed seed, so they differ slightly from the figures in the text notes, which come from code/em.py.