Basic Prerequisites: 02 · GMM Clustering and Calculus & Optimization (Jensen’s inequality, convexity).


1. Intuition & Practical Objective

Every model in this folder - GMM, HMM/Baum–Welch, and most latent-variable models - is fit by the same algorithm: Expectation–Maximization (EM). The intuition is disarmingly simple: you don’t know the regimes (the hidden ), so you can’t directly maximize the log-likelihood of the observed data alone; EM works around that by (E) guessing the hidden assignments given the current parameters, then (M) re-estimating the parameters as if the guesses were known, and repeating.

The practical objective: understand why EM works (it monotonically increases the observed-data likelihood, never decreases it) and how to derive the GMM updates you used in 02 and the HMM updates in 04 - they are all this one algorithm with different models.

The one-sentence essence. “EM never maximizes the observed-data likelihood directly; it maximizes a lower bound on it (the expected complete-data log-likelihood), and every time the bound is tightened the true likelihood rises too - so EM converges monotonically to a (local) maximum.”


2. Mathematical Ground Truth & Derivations

Setup. Observed data , hidden/latent regime labels (you never see them), parameters . The observed-data log-likelihood is

The sum inside the log is the obstacle. Introduce any distribution over the hidden variables; Jensen’s inequality (log is concave) gives, for every ,

The right-hand side is the evidence lower bound (ELBO) : a lower bound on the true log-likelihood that we can maximize. EM is coordinate ascent on this bound (Bishop Ch 9; the GMM view is ESL Ch 14.3.7):

  • E-step: hold ; the bound is tightest when - i.e. is the posterior over regimes given the current parameters. Then the bound equals (the gap is a KL divergence that the optimal drives to zero). The term that survives is the expected complete-data log-likelihood,
  • M-step: maximize w.r.t. , giving .

Why it can’t decrease the likelihood. After the E-step the bound equals ; the M-step then maximizes the bound, so the bound (and hence ) can only rise:

Deriving the GMM updates. The complete-data log-likelihood is . Taking the expectation over the posterior gives , whose maximization yields the weighted averages (ESL eq. 14.61–14.64):

where - the responsibilities from 02. The HMM (Baum–Welch) is the same skeleton with being the smoothed state posterior and a Markov transition matrix to re-estimate (04).


3. Computational Implementation - 2-D EM with full covariance, verified monotone

Fit a two-component, full-covariance Gaussian mixture in 2-D from scratch, and verify the monotonicity theorem numerically. Stdlib only.

The recovered component means and sit on top of the true centers and , and the log-likelihood rises from to never decreasing (the theorem of §2, verified: monotone non-decreasing? True). Note how fast it converges - the last digits move by iter - the classic EM signature: rapid early progress, slow refinement.


4. Failure Modes & First-Principles Breakdowns

  1. EM finds a local maximum. The bound is concave only per-coordinate, not jointly; different initializations land on different local maxima (the source of the label-swapping runs in 05). Fix: multi-start.
  2. Degenerate collapses. A component can shrink its covariance to a single point (responsibility there, likelihood ) - an unconstrained GMM can diverge. Fix: floor the covariance / weights, or regularize.
  3. Monotonicity ≠ optimality. EM never decreases the likelihood, but it also never proves it found the global max; a plateau can stop it far from the best fit. Use restarts and model-selection (BIC) to compare.
  4. Slow tail convergence. As seen above, EM crawls in later iterations - the Newton-type accelerators or a convergence tolerance matter for large fits.

5. References

  • Dempster, Laird & Rubin, “Maximum Likelihood from Incomplete Data via the EM Algorithm,” JRSS-B 39(1), 1977
  • Bishop, Christopher M., Pattern Recognition and Machine Learning (2006)
  • Hastie, Tibshirani & Friedman, The Elements of Statistical Learning

6. Connected Graph Bridges