M2-055M2: Classical Machine LearningClustering AlgorithmsMedium
⚡Flashcard Drill➔Mastery:

Derive the Expectation-Maximization (EM) Algorithm and Prove Its Monotonic Likelihood Ascent via Jensen's Inequality

📐 Mathematical Definition
Q(θ∣θt)=∑i∑kγiklog⁡p(xi,zi=k∣θ)γikQ(\theta\mid\theta^{t})=\sum_i\sum_k \gamma_{ik}\log\frac{p(x_i,z_i=k\mid\theta)}{\gamma_{ik}}
⚡ One-Sentence Core Answer
The EM algorithm maximizes incomplete log-likelihood with latent variables by iteratively constructing a tight Evidence Lower Bound (ELBO) in the E-step via q(z)=p(z∣x,θ)q(z) = p(z\mid x, \theta) and maximizing that lower bound in the M-step.

📌 Key Takeaways

  • •
    Latent Variable Log-Likelihood: log⁡p(X∣θ)=∑i=1Nlog⁡∑zp(xi,z∣θ)\log p(X\mid \theta) = \sum_{i=1}^N \log \sum_{z} p(x_i, z\mid \theta); intractable sum inside the logarithm.
  • •
    E-step (Expectation): Computes the posterior distribution of latent variables: q(z)=p(z∣x,θ(t))q(z) = p(z\mid x, \theta^{(t)}), making the ELBO touch the true likelihood.
  • •
    M-step (Maximization): Updates parameters by maximizing expected complete log-likelihood: θ(t+1)=arg⁡max⁡θEq[log⁡p(x,z∣θ)]\theta^{(t+1)} = \arg\max_\theta E_{q}[\log p(x, z\mid \theta)].
  • •
    Monotonic Guarantee: log⁡p(X∣θ(t+1))≥log⁡p(X∣θ(t))\log p(X\mid \theta^{(t+1)}) \ge \log p(X\mid \theta^{(t)}); guaranteed never to decrease likelihood.

📐 Mathematical Derivations

Proof of monotonic ascent via Jensen's Inequality: For any arbitrary latent distribution q(z)q(z): log⁡p(x∣θ)=log⁡∑zp(x,z∣θ)=log⁡∑zq(z)p(x,z∣θ)q(z)≥∑zq(z)log⁡p(x,z∣θ)q(z)≡L(q,θ)\log p(x\mid \theta) = \log \sum_z p(x, z\mid \theta) = \log \sum_z q(z) \frac{p(x, z\mid \theta)}{q(z)} \ge \sum_z q(z) \log \frac{p(x, z\mid \theta)}{q(z)} \equiv \mathcal{L}(q, \theta). Decomposing the difference: log⁡p(x∣θ)−L(q,θ)=∑zq(z)log⁡p(x∣θ)−∑zq(z)log⁡p(x,z∣θ)q(z)=∑zq(z)log⁡q(z)p(x∣θ)p(x,z∣θ)=∑zq(z)log⁡q(z)p(z∣x,θ)=DKL(q(z)∥p(z∣x,θ))\log p(x\mid \theta) - \mathcal{L}(q, \theta) = \sum_z q(z) \log p(x\mid \theta) - \sum_z q(z) \log\frac{p(x, z\mid \theta)}{q(z)} = \sum_z q(z) \log\frac{q(z) p(x\mid \theta)}{p(x, z\mid \theta)} = \sum_z q(z) \log\frac{q(z)}{p(z\mid x, \theta)} = D_{\text{KL}}(q(z) \parallel p(z\mid x, \theta)). Thus, log⁡p(x∣θ)=L(q,θ)+DKL(q(z)∥p(z∣x,θ))\log p(x\mid \theta) = \mathcal{L}(q, \theta) + D_{\text{KL}}(q(z) \parallel p(z\mid x, \theta)). In the E-step, setting q(z)=p(z∣x,θ(t))q(z) = p(z\mid x, \theta^{(t)}) drives DKL=0D_{\text{KL}} = 0, making L(q,θ(t))=log⁡p(x∣θ(t))\mathcal{L}(q, \theta^{(t)}) = \log p(x\mid \theta^{(t)}). In the M-step, we choose θ(t+1)=arg⁡max⁡θL(q,θ)\theta^{(t+1)} = \arg\max_\theta \mathcal{L}(q, \theta). Therefore: log⁡p(x∣θ(t+1))≥L(q,θ(t+1))≥L(q,θ(t))=log⁡p(x∣θ(t))\log p(x\mid \theta^{(t+1)}) \ge \mathcal{L}(q, \theta^{(t+1)}) \ge \mathcal{L}(q, \theta^{(t)}) = \log p(x\mid \theta^{(t)}), proving monotonic convergence.

🏭 Production Trade-offs

Classic instances of the EM algorithm in ML: (1) Gaussian Mixture Models (GMM): Latent variables zi∈{1,…,K}z_i \in \{1, \dots, K\}; E-step computes responsibilities γik=P(zi=k∣xi)\gamma_{ik} = P(z_i=k\mid x_i), M-step updates (πk,μk,Σk)(\pi_k, \mu_k, \Sigma_k). (2) Hidden Markov Models (Baum-Welch): Latent sequence states. (3) Variational Autoencoders (VAE): Amortized variational EM optimizing continuous latents.
⚠️ Common Interview Pitfalls
  • ✕
    Assuming EM converges to the global maximum (it is a local ascent algorithm that can get trapped in local maxima or saddle points).
  • ✕
    Singularities in GMM: If a Gaussian component collapses onto a single data point, variance σk2→0\sigma_k^2 \to 0, causing likelihood to diverge to +∞+\infty (must constrain covariance eigenvalues).
🎯 Interviewer Follow-up Inquiries
  • ?
    How does the Evidence Lower Bound (ELBO) in Variational Inference generalize the EM algorithm?
  • ?
    Why do GMM likelihood surfaces have unbounded singularities when covariance matrices approach zero?
⚡
Test muscle memory on this topic via 3-Layer Flashcards
Active Recall: Mentally formulate Prompt ➔ Math Derivation ➔ Benchmark Implementation in 3 minutes.
🎯 Drill This Card Now➔
📚

Associated Knowledge Base Guides & Mindmaps

Explore the comprehensive technical article, exam cards, and global architecture tree.

← PreviousM2-054: Compare K-Means, Gaussian Mixture Models (GMM), and DBSCAN Across Assumptions, Geometry, and Complexity📋Back to BankNext →M2-056: Detail Unsupervised Clustering Evaluation: Internal Metrics vs. External Ground-Truth Metrics
中文速览与面试要点

推导/描述 EM 算法的两步,并说明为什么它单调提升似然。

E 步算后验责任度,M 步最大化期望完全数据对数似然;每轮提升(或不变)观测似然。

核心要点

  • EM 的推导:设隐变量 z(如 GMM 中样本属于哪个分量),完全数据对数似然为 log p(x,z|θ)。因 z 不可观测,改用其 期望 ——E 步计算 z 的后验分布 γ_ik=P(zᵢ=k|xᵢ,θᵗ)(对 GMM 即'责任度':样本 i 属于分量 k 的概率);M 步最大化 Q(θ|θᵗ)=E_z|x,θᵗ[log p(x,z|θ)]=ΣᵢΣₖγ_iklog[p(xᵢ,zᵢ=k|θ)/γ_ik]。 单调性证明 :log p(x|θ)=Q(θ|θᵗ)−H(θ|θᵗ)+KL(γ‖p(z|x,θ)),其中最后一项 ≥0;M 步使 Q 增大(或不变),而 E 步选择 γ 使 KL=0。因此 log p(x|θᵗ⁺¹) ≥ log p(x|θᵗ) + [Q(θᵗ⁺¹|θᵗ)−Q(θᵗ|θᵗ)] ≥ log p(x|θᵗ)。即 每轮迭代观测似然单调不减 ,配合有界性保证收敛(到局部最优或鞍点)。
  • 实践要点:① 收敛性局限 ——单调不减保证收敛,但只到 局部最优 (似然可能多峰),且收敛可能是鞍点;故需 多次随机重启 (不同初始化)取最优似然。② 收敛速度 ——EM 通常前几步快、后期慢(线性收敛,接近最优时步长变小);可用 Aitken 加速或改用二阶方法(但代价高)。③ 初始化策略 ——K-means 的结果常作为 GMM 的初始化(均值取 K-means 中心);或用多次随机初始化。④ 与梯度上升的关系 ——EM 可视为'用 Jensen 不等式构造的下界做坐标上升',它自动保证单调性(无需调学习率),但每步计算量更大(需算全部责任度)。⑤ 退化问题 ——GMM 中若某分量塌缩到单个点,协方差趋于 0、似然趋于无穷(病态解);解法是加协方差下界(regularization)、或使用贝叶斯 GMM(加先验)。⑥ 变体 ——变分 EM(VI)、Monte Carlo EM(M 步用采样近似)用于更复杂模型。
  • 保证收敛到局部最优
  • 初始化影响大 → 多次重启

常见陷阱

  • 认为 EM 保证全局最优(只到局部最优)
  • 不做多次重启(初始化敏感)