← Playground← 놀이터

PRISM · Machine Learning PlaygroundPRISM · 머신러닝 놀이터

EM Algorithm · Gaussian MixtureEM 알고리즘 · 가우시안 혼합
Alternately raise the likelihood's lower bound — coordinate descent for latent-variable estimation우도의 하한을 번갈아 밀어 올려라 — 잠재변수 추정의 좌표 하강

iteration t = 0 · next:다음: E-step (γ)
point color = blend of responsibilities γ점 색 = 책임값 γ의 혼합 ×mean μₖ평균 μₖ 1σ·2σ ellipses1σ·2σ 타원
Mean log-likelihood ℓ/n (solid) vs ELBO ℒ/n (dashed) — the red gap is KL(q‖p): E closes it, M raises ℓ평균 로그우도 ℓ/n (실선) vs ELBO ℒ/n (파선) — 붉은 간격이 KL(q‖p): E가 닫고, M이 ℓ를 올린다
ℓ/n = log p(X|θ)/n ELBO ℒ(q,θ)/n KL(q ‖ p(z|X,θ))
LIKELIHOOD
Log-likelihood ascent로그우도 상승
ℓ/n
Δℓ/n (M-step)
Best ℓ/n (this data)최고 ℓ/n (이 데이터)

In soft EM, ℓ never decreasessoft EM에서 ℓ는 절대 감소하지 않는다

E-STEP
Responsibilities γ = p(z|x,θ)책임값 γ = p(z|x,θ)
Mean max γ평균 max γ
Ambiguous points (max γ < 0.8)애매한 점 (max γ < 0.8)

Set q = posterior ⇒ KL = 0, bound touchesq = 사후분포로 두면 KL = 0, bound 접촉

M-STEP
Parameter re-estimation파라미터 재추정
Mixing weights πₖ혼합비 πₖ
Effective count Nₖ = Σγ유효 표본 Nₖ = Σγ

Re-solve the MLE with γ-weighted samplesγ로 가중된 표본으로 MLE를 다시 푼다

Formulas수식
$$\log p(X\mid\theta)=\sum_n\log\sum_k \pi_k\,\mathcal N(x_n\mid\mu_k,\Sigma_k)$$ $$\mathcal L(q,\theta)=\sum_n\sum_k q_{nk}\log\frac{\pi_k\,\mathcal N(x_n\mid\mu_k,\Sigma_k)}{q_{nk}}=\log p(X\mid\theta)-\mathrm{KL}\big(q\,\big\|\,p(z\mid X,\theta)\big)$$ $$\textbf{E: }\ \gamma_{nk}=\frac{\pi_k\,\mathcal N(x_n\mid\mu_k,\Sigma_k)}{\sum_j\pi_j\,\mathcal N(x_n\mid\mu_j,\Sigma_j)}\ \ \Rightarrow\ \ \mathrm{KL}=0,\ \ \mathcal L=\log p$$ $$\textbf{M: }\ N_k=\sum_n\gamma_{nk},\quad \pi_k=\frac{N_k}{n},\quad \mu_k=\frac{1}{N_k}\sum_n\gamma_{nk}\,x_n,\quad \Sigma_k=\frac{1}{N_k}\sum_n\gamma_{nk}(x_n-\mu_k)(x_n-\mu_k)^\top$$ $$\text{free-energy view: }\ F(q,\theta)=-\mathcal L(q,\theta),\qquad \text{E-step}=\arg\min_q F,\quad \text{M-step}=\arg\min_\theta F$$
What to watch수업 관찰 포인트
  1. Separation of E and M roles: the E-step changes only point colors (γ) and leaves the ellipses fixed; the M-step moves only the ellipses (θ). On the curve, E makes the dashed line (ELBO) touch the solid line (ℓ) (KL=0), and M pushes the bound up — ℓ never decreases.E와 M의 역할 분리: E-step은 점 색(γ)만 바꾸고 타원은 그대로, M-step은 타원(θ)만 움직인다. 곡선에서 E는 파선(ELBO)을 실선(ℓ)에 접촉시키고(KL=0), M은 bound를 밀어 올린다 — ℓ는 절대 감소하지 않는다.
  2. Local optima: repeated reinitialization converges to different solutions on the same data, with a different final ℓ. Compare against the “best ℓ” record — this is why multiple restarts are standard in practice.국소 최적: 재초기화를 반복하면 같은 데이터에서 다른 해로 수렴하고 최종 ℓ가 달라진다. “최고 ℓ” 기록과 비교해 보라 — 실전에서 다중 재시작이 표준인 이유.
  3. Soft vs Hard: on overlapping data, ambiguous points with γ≈0.5 line up along the boundary. Turning on Hard (K-means-style) keeps ELBO from touching ℓ, and a ✗ can appear on Δℓ — the monotonic-increase guarantee belongs to the soft posterior.Soft vs Hard: 겹침 데이터에서 γ≈0.5인 애매한 점들이 경계에 늘어선다. Hard(K-means식)를 켜면 ELBO가 ℓ에 접촉하지 못하고 Δℓ에 ✗가 뜰 수 있다 — 단조 증가 보장은 soft posterior의 것이다.
  4. Model assumptions: elongated data + spherical σ²I splits clusters apart — switching to Full Σ fixes it. Using K=4 on 3 clusters makes one component starve (π→0, component death then reseed) or split a cluster among components.모델 가정: 길쭉 데이터 + 구형 σ²I는 클러스터를 쪼갠다 — Full Σ로 바꾸면 해결. K=4를 3군집에 쓰면 한 성분이 굶거나(π→0, 성분 사멸 후 재시드) 군집을 나눠 갖는다.
  5. Model misspecification: on ring data a GMM only speaks the language of ellipses — increasing K just approximates the arc in pieces. It is not that “EM failed” — the model is wrong.모델 오지정: 고리 데이터에서 GMM은 타원의 언어만 안다 — K를 늘려도 호(arc) 조각 근사일 뿐. “EM이 실패”한 게 아니라 모델이 틀린 것.