The last chapter ended with a chicken-and-egg problem. If we knew which component produced each point, fitting the Gaussians would be easy; if we knew the Gaussians, working out which component produced each point would be easy. The expectation-maximisation (EM) algorithm alternates between the two and, unlike a hopeful guess, comes with a proof that every round improves the likelihood. The proof rests on one inequality about convex functions.
Convexity and Jensen's inequality
A function is convex if the chord between any two points on its graph lies on or above the graph: for ,
A bowl such as is convex. A function is concave if the inequality goes the other way (a dome); the logarithm is concave, because its second derivative is negative.
Jensen's inequality extends the definition from two points to any weighted average. For a concave function such as , and weights that sum to 1,
with equality when all the are equal. In words: the log of an average is at least the average of the logs.
A lower bound on the log-likelihood
The GMM log-likelihood is a sum over points of the log of a sum over components. For each point , pick any weights that sum to 1, and multiply and divide inside the sum:
Summing over points gives a lower bound on the whole log-likelihood:
Two facts make this bound useful.
- The bound is easy to maximise over . The log now acts directly on each Gaussian, so the awkward log-of-a-sum is gone. Each component's parameters appear in their own separate terms.
- The bound can be made tight. Jensen's inequality is an equality when the terms inside are equal across , which happens when is proportional to . That is exactly the responsibility from the last chapter:
The two steps
EM starts from a guess and repeats:
E step (expectation). With the current parameters, compute every responsibility . This makes the lower bound touch the log-likelihood at the current .
M step (maximisation). With the responsibilities fixed, maximise the bound over . Setting its derivatives to zero gives closed forms, each a weighted version of the single-Gaussian maximum likelihood answer. Writing for the effective number of points in component :
Each point contributes to every component, in proportion to how responsible that component is for it. (In dimensions, the variance becomes the weighted covariance matrix .)
Why the likelihood never goes down
Let be the current parameters and the responsibilities computed from them. Then
The first inequality is Jensen (the bound is always below the log-likelihood). The second holds because the M step chose to maximise the bound. The equality holds because the E step made the bound tight at . So each round can only raise the log-likelihood, or leave it unchanged. Like k-means, EM climbs steadily, and like k-means it can stop at a local maximum, so the starting point matters (a common choice is to initialise from a k-means solution).
EM and k-means
Put the two algorithms side by side.
| k-means | EM for a GMM | |
|---|---|---|
| Assignment | hard: each point to its nearest mean | soft: responsibilities |
| Update | plain mean of assigned points | weighted means, variances and proportions |
| Cluster shape | Voronoi cells, implicitly equal spread | each component has its own spread and weight |
| Objective | within-cluster squared distance falls | log-likelihood rises |
k-means is in fact a limiting case of EM. Give every component the same small variance and equal proportions, and let . The responsibilities then become 1 for the nearest mean and 0 for all others, the weighted means become plain means, and EM turns into Lloyd's algorithm. The probabilistic model adds what k-means lacked: clusters of different sizes and shapes, and an honest statement of uncertainty for points that sit between clusters.