TensorTau PathToAGI Classical Machine Learning Level 04

Level 04 · Classical Machine Learning · Chapter 050

Expectation Maximization

How do we learn parameters when part of the information needed for learning is hidden?

Where We Are

A Gaussian Mixture Model would be easy to fit if every point told us which Gaussian created it. But those component labels are hidden.

Expectation Maximization (EM) turns that circular problem into an alternating conversation.

1. The chicken-and-egg problem

To estimate component means, we want assignments. To estimate assignments, we want component means.

need assignments ──→ estimate parameters
      ↑                    │
      └──── need parameters┘

EM does not solve both simultaneously. It alternates.

2. E-step: estimate hidden membership

Using current parameters, compute responsibilities

rik=p(zi=k∣xi).r_{ik}=p(z_i=k\mid x_i).

For a GMM,

rik=πkN(xi∣μk,Σk)∑jπjN(xi∣μj,Σj).r_{ik}=\frac{\pi_k\mathcal N(x_i\mid\mu_k,\Sigma_k)}{\sum_j\pi_j\mathcal N(x_i\mid\mu_j,\Sigma_j)}.

This is Bayes’ rule from Chapter 086 returning in a practical algorithm.

3. M-step: update parameters

Treat responsibilities as fractional membership. Define

Nk=∑irik.N_k=\sum_i r_{ik}.

Then

μk=1Nk∑irikxi,\mu_k=\frac{1}{N_k}\sum_i r_{ik}x_i,

πk=NkN,\pi_k=\frac{N_k}{N},

with covariance updated by a responsibility-weighted variance calculation.

A point with responsibility 0.8 contributes 0.8 of itself to that component’s statistics.

4. Repeat

initialize parameters
      ↓
E: infer hidden variables
      ↓
M: improve parameters
      ↓
likelihood converged? ──no──↺

Each iteration does not decrease the observed-data likelihood, but EM can converge to a local optimum. Initialization matters.

5. Why EM is a bigger idea than GMMs

The pattern applies whenever a useful variable is latent:

  • infer hidden structure under current parameters;
  • optimize parameters under the inferred structure.

The mathematics can be derived using Jensen’s inequality and a lower bound on log likelihood. The intuitive story, however, is already powerful: guess hidden explanations, improve the model, then improve the explanations.

6. Relationship to K-Means

K-Means alternates assignments and centres. EM for a GMM alternates soft assignments and distribution parameters. This makes K-Means feel less like an isolated trick and more like part of a family of alternating optimization methods.

What to Remember

  • EM is useful when learning involves latent variables.
  • E-step estimates a distribution over hidden variables.
  • M-step optimizes parameters using those estimates.
  • Likelihood improves monotonically, but local optima remain possible.

Next → PCA from Eigenvectors: clustering asks for hidden groups. Can we instead discover hidden directions that explain most of the variation?

Six ways to work the chapter, climbing from explaining it in your own words to investigating it like a researcher. Reading is not enough — this is where the chapter lands.

1 — Explain it

Describe EM using a chicken-and-egg analogy: unknown groups and unknown group statistics.

2 — Calculate it

Given responsibilities [0.8,0.2] for two points 2 and 10 in one component, compute its updated mean.

3 — Predict it

If responsibilities become nearly 0 or 1, which earlier clustering algorithm does EM begin to resemble?

4 — Break it

Run a GMM from several poor initializations and record different local solutions.

5 — Build it

Implement EM for a two-component 1-D Gaussian mixture.

6 — Investigate it

Track log likelihood every iteration for many random initializations. Test the claim that EM iterations do not decrease it and discuss numerical exceptions.