The Expectation-Maximization Algorithm
EM solves the chicken-and-egg problem of fitting a model when some labels are missing: guess the labels from the parameters, refit the parameters from the guessed labels, repeat. Each round provably never makes the fit worse.
Prerequisites: Maximum Likelihood Estimation (MLE), Gaussian Mixture Models
Fitting a model is easy when you can see everything. If someone hands you a list of daily returns already tagged calm or stressed, estimating the two regimes takes one pass: average the calm days, average the stressed days, done. And if someone hands you the two regimes' parameters, tagging each day is equally easy: work out which regime explains that day better.
The trouble is you get neither. You have the returns and nothing else. You need the labels to fit the parameters, and you need the parameters to work out the labels. That is the deadlock Expectation-Maximization breaks, and it breaks it in the most obvious way imaginable: guess one, derive the other, and go round again.
The two steps
Start from any parameter guess, however crude. Then repeat:
- E-step (Expectation). Hold the parameters fixed and compute, for every data point, the probability that it came from each hidden group. These are soft labels — a point can be 70% one group and 30% the other. They are called responsibilities.
- M-step (Maximization). Hold the responsibilities fixed and refit the parameters as if the soft labels were real, using each point fractionally in each group according to its responsibility.
Stop when the parameters stop moving.
Worked example: two coins, unknown which is which
Two biased coins, A and B, land heads with unknown probabilities and . Someone runs five experiments. Each time they pick a coin at random, flip it ten times, and record only the number of heads, never which coin they used:
| experiment | heads | tails |
|---|---|---|
| 1 | 5 | 5 |
| 2 | 9 | 1 |
| 3 | 8 | 2 |
| 4 | 4 | 6 |
| 5 | 7 | 3 |
Guess and to get started.
E-step. For each experiment, compute how likely that head count is under each coin, then normalise. Take experiment 2, nine heads and one tail:
Coin A explains nine heads about four times better than a fair coin does. Normalising, the responsibility of coin A is
so experiment 2 counts as 80% coin A and 20% coin B. Repeating for all five gives A-responsibilities of — heads-heavy experiments lean towards A, tails-heavy ones towards B, exactly as intuition says.
M-step. Now re-estimate each coin's bias using fractional flips. Coin A's share of the heads is
and its share of the tails, computed the same way, is . So
In plain terms: coin A was credited with 21.24 heads out of 29.8 flips it was probably responsible for. The same arithmetic on coin B gives heads out of , so .
One round moved the estimates from to . Run it again and again and they settle near — close to what you would have got if the coin labels had never been hidden.
Both steps are ordinary, easy calculations. EM is not a clever new estimator; it is a schedule for alternating between two problems you already know how to solve, and its guarantee is that the alternation cannot make the fit worse.
Why it works
Each E-step builds a lower bound on the log-likelihood that touches it exactly at the current parameters. The M-step then jumps to the top of that bound. Since you started on the true curve and moved up the bound, you cannot have gone down on the true curve either. That is the whole proof sketch, and it is why the likelihood trace in the figure only ever climbs.
Where quants meet it
EM is the standard fitting routine for Gaussian Mixture Models, where the hidden label is "which regime produced this return". It is also the engine behind the Baum-Welch algorithm for Hidden Markov Models, the smoothing step in some The Kalman Filter estimation, and a clean way to handle genuinely missing observations — a stock that stopped trading for a week is just another latent quantity to average over rather than a row to delete.
"The likelihood never decreases" is not the same as "EM finds the best answer". EM climbs to a local maximum and where it lands depends entirely on the starting guess — run it from several random starts and keep the best. Worse, for a mixture with free variances the likelihood is unbounded: let one component's width shrink onto a single data point and the likelihood goes to infinity while the fit is meaningless. Real implementations floor the variances for exactly this reason.
Related concepts
Practice in interviews
Further reading
- Dempster, Laird & Rubin, Maximum Likelihood from Incomplete Data via the EM Algorithm (1977)
- Bishop, Pattern Recognition and Machine Learning, ch. 9