Gaussian Mixture Models and the EM Algorithm
Gaussian Mixture Model¶
From K-Means to GMM¶
K-means limitations:
Hard assignments (each point to exactly one cluster)
Represents each cluster only by its centroid
No probabilistic model for the data distribution
GMM provides a soft assignment approach via probabilistic modeling.
Mixture Model¶
Each sample x is generated with a hidden variable z∈{1,…,K} indicating which component generated it:
p(x,z)=p(x∣z)p(z) The marginal distribution (since z is unobserved):
p(x)=k=1∑Kp(x∣z=k)πk where πk=p(z=k) are mixing coefficients with πk≥0 and ∑kπk=1.
Gaussian Mixture Model¶
In a GMM, each component is Gaussian:
p(x∣z=k)=N(x∣μk,Σk) Therefore:
p(x)=k=1∑KπkN(x∣μk,Σk) With sufficiently many components, GMMs can approximate a wide class of densities.
Maximum Likelihood Estimation¶
Given data X={x(1),…,x(N)}, the log-likelihood is:
ℓ(θ)=n=1∑Nlog(k=1∑KπkN(x(n)∣μk,Σk)) Difficulty: the logarithm is outside the summation, so no closed-form solution exists. This motivates the EM algorithm.
Expectation-Maximization Algorithm¶
Preliminaries¶
Jensen’s Inequality: If f is convex, then f(E[X])≤E[f(X)]. For concave f (like log), the inequality reverses.
KL Divergence: For distributions p and q:
KL(q∥p)=z∑q(z)logp(z)q(z)≥0 with equality iff q(z)=p(z). KL divergence is non-negative but not symmetric.
Derivation via Lower Bound¶
For one sample x and any distribution q(z):
logp(x∣θ)=logz∑q(z)q(z)p(x,z∣θ) By Jensen’s inequality (since log is concave):
logp(x∣θ)≥z∑q(z)logq(z)p(x,z∣θ):=F(q,θ) This decomposes as:
logp(x∣θ)=F(q,θ)+KL(q(z)∥p(z∣x,θ)) For the full dataset with auxiliary distributions qn(z(n)):
logp(D∣θ)=n=1∑NFn(qn,θ)+n=1∑NKL(qn(z(n))∥p(z(n)∣x(n),θ)) E-Step¶
Fix θold. To maximize the lower bound, minimize the sum of KL divergences. Since KL ≥0, the minimum is 0, achieved when:
qn∗(z(n))=p(z(n)∣x(n),θold) With this choice, the lower bound becomes tight at θold:
logp(D∣θold)=F({qn∗},θold) M-Step¶
Fix qn. Update θ by maximizing the lower bound:
θnew=argθmaxn=1∑Nz(n)∑qn(z(n))logp(x(n),z(n)∣θ) Define the Q-function:
Q(θ,θold)=n=1∑NEp(z(n)∣x(n),θold)[logp(x(n),z(n)∣θ)] Then θnew=argmaxθQ(θ,θold).
Why EM Increases the Log-Likelihood¶
Let {qn} be the distributions from the E-step.
After E-step: logp(D∣θold)=F({qn},θold) (tight)
After M-step: F({qn},θnew)≥F({qn},θold) (by maximization)
Since log-likelihood ≥ lower bound: logp(D∣θnew)≥F({qn},θnew)
Therefore:
logp(D∣θnew)≥logp(D∣θold) EM guarantees monotonic increase of the observed-data log-likelihood.
EM for GMM¶
E-step: Compute responsibilities (posterior probabilities):
γk(n):=qn(z(n)=k)=∑j=1KπjN(x(n)∣μj,Σj)πkN(x(n)∣μk,Σk) M-step: Update parameters using responsibilities as weights. Define effective sample size:
Nk=n=1∑Nγk(n) Then:
μknew=Nk1n=1∑Nγk(n)x(n) Σknew=Nk1n=1∑Nγk(n)(x(n)−μknew)(x(n)−μknew)⊤ πknew=NNk
Interpretation¶
| Aspect | K-Means | GMM with EM |
|---|
| Assignment | Hard (0 or 1) | Soft (probabilistic responsibilities) |
| Cluster shape | Spherical (implicitly) | Ellipsoidal (via covariance matrices) |
| Update | Mean of assigned points | Weighted mean of all points |
| Objective | Minimize within-cluster variance | Maximize log-likelihood |
If all covariances are fixed as Σk=I, EM for GMM reduces to a soft version of K-means.
GMM Advantages and Disadvantages¶
Advantages:
Soft clustering with posterior probabilities
Flexible cluster shapes via covariance matrices
Probabilistic density estimation
Can handle overlapping clusters
Disadvantages:
Need to choose K
Sensitive to initialization (often initialize means with K-means)
Gaussian assumption may not hold
Risk of singular covariance matrices in high dimensions