← Playground← 놀이터

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

Generative vs Discriminative생성 vs 판별
Learn the distribution, or just the boundary — p(x,y) vs p(y|x)분포를 배울 것인가, 경계만 배울 것인가 — p(x,y) vs p(y|x)

Generative생성 · learn p(x|y)p(y) → p(y|x) via Bayesp(x|y)p(y) 학습 → Bayes로 p(y|x)
+1 −1 learned p(x|y) (1σ·2σ)학습한 p(x|y) (1σ·2σ) generative boundary생성 경계 discriminative boundary판별 경계 generated samples생성된 표본
Discriminative판별 · learn p(y|x) directly — no p(x) → cannot generatep(y|x) 직접 학습 — p(x) 없음 → 생성 불가
discriminative boundary판별 경계 p = 0.1 / 0.9 confidence contoursp = 0.1 / 0.9 확신 등고선 generative boundary생성 경계
Learning curve — test error, retrained on n points from the preset distribution (Ng & Jordan)학습 곡선 — 프리셋 분포에서 n개씩 재학습한 테스트 오차 (Ng & Jordan)
Generative (GDA)생성 (GDA) Discriminative (Logistic)판별 (로지스틱)
GENERATIVE
Maximize the joint likelihood결합 우도를 최대화
Train accuracy훈련 정확도
Test accuracy테스트 정확도
log p(x,y) / n

Learns the whole distribution — enabling generation and OOD detection분포 전체를 배운다 — 그래서 생성·OOD 감지가 가능

DISCRIMINATIVE
Maximize the conditional likelihood조건부 우도를 최대화
Train accuracy훈련 정확도
Test accuracy테스트 정확도
log p(y|x) / n

Learns only the boundary — fewer parameters, less sensitive to distribution assumptions경계만 배운다 — 적은 파라미터, 분포 가정에 덜 민감

COMPARE
Same data, different question같은 데이터, 다른 질문
Boundary disagreement (test)두 경계 불일치 (테스트)
Parameter count파라미터 수

Disagreement region = where the two philosophies actually diverge불일치 영역 = 두 철학이 실제로 갈라지는 곳

Formulas수식
$$\textbf{Generative: }\ \hat\theta=\arg\max_\theta\sum_n\Big[\log p(x_n\mid y_n)+\log p(y_n)\Big]\qquad(\text{joint }\log p(x,y))$$ $$p(y{=}{+}1\mid x)=\frac{\pi_+\,\mathcal N(x\mid\mu_+,\Sigma_+)}{\pi_+\,\mathcal N(x\mid\mu_+,\Sigma_+)+\pi_-\,\mathcal N(x\mid\mu_-,\Sigma_-)}\qquad(\text{Bayes})$$ $$\textbf{Discriminative: }\ \hat{\mathbf w}=\arg\max_{\mathbf w}\sum_n\log p(y_n\mid x_n),\qquad p(y{=}{+}1\mid x)=\sigma\big(\mathbf w^{\top}\phi(x)+b\big)$$ $$\Sigma_+{=}\Sigma_-\ (\text{LDA}):\ \ \log\frac{p(+\mid x)}{p(-\mid x)}=\mathbf w^{\top}x+b\quad\text{(same form as logistic, different estimation)}$$ $$\Sigma_+{\neq}\Sigma_-\ (\text{QDA}):\ \text{quadratic boundary}\ \Longleftrightarrow\ \phi(x)=(x_1,\,x_2,\,x_1^2,\,x_2^2,\,x_1x_2)$$
What to watch수업 관찰 포인트
  1. Same data, different objective: compare the two log-likelihoods on the cards — generative maximizes the joint log p(x,y), discriminative the conditional log p(y|x). Shared Σ (LDA) and linear logistic estimate the same form of linear boundary in different ways (see Formulas).같은 데이터, 다른 목적함수: 카드의 두 로그우도를 비교 — 생성은 결합 log p(x,y), 판별은 조건부 log p(y|x)를 최대화한다. 공유 Σ(LDA)와 선형 로지스틱은 같은 형태의 선형 경계를 다른 방식으로 추정한 것 (수식 참조).
  2. The sample-generation button lives only on the generative side — because it learned p(x). The background shading contrasts too: the discriminative model stays confident even where there is no data, while the generative model fades where the density p(x) is low — the basis for OOD (out-of-distribution) detection.표본 생성 버튼은 생성 모델 쪽에만 있다 — p(x)를 배웠기 때문. 배경 음영도 대비된다: 판별은 데이터가 없는 곳에서도 확신하지만, 생성은 밀도 p(x)가 낮은 곳에서 옅어진다 — OOD(분포 밖) 감지의 근거.
  3. Outlier tail + shared Σ: faraway (correctly labeled) points drag μ and Σ and tilt the generative boundary, but logistic ignores already-correct points since their gradient is ≈0. Click to add an extreme outlier and you'll see only the green boundary move.이상치 꼬리 + 공유 Σ: 멀리 있는 (정답인) 점들이 μ와 Σ를 끌고 가 생성 경계가 기울지만, 로지스틱은 이미 맞춘 점의 기울기가 ≈0이라 무시한다. 클릭으로 극단 이상치를 직접 추가하면 초록 경계만 움직이는 것이 보인다.
  4. Scan n twice: Gaussian/Overlap (assumptions hold) → generative leads slightly at small n, then converges to the same value. Outlier tail (assumptions wrong) → generative error gets stuck on a plateau while discriminative drops lower (e.g. ~4% vs 2.7% at n=256) — the asymptotic cost of misspecification. That said, a well-regularized discriminative model is strong even at small n — the classic Ng & Jordan result assumes unregularized MLE.n 스캔 두 번: 가우시안/겹침(가정이 맞음) → 생성이 작은 n에서 살짝 앞서다 같은 값으로 수렴. 이상치 꼬리(가정이 틀림) → 생성 오차는 평탄선에 갇히고 판별이 아래로 내려간다 (예: n=256에서 약 4% vs 2.7%) — 오지정의 점근적 대가. 단, 잘 정칙화된 판별 모델은 소표본에서도 강하다 — 고전 Ng & Jordan 결과는 비정칙 MLE 기준.
  5. In·Out data: LDA and linear logistic fail, QDA succeeds with a quadratic boundary — and discriminative succeeds too once you turn on quadratic features. The generative model's distribution assumption corresponds to the discriminative model's feature design (links to the Representation playground).안·밖 데이터: LDA와 선형 로지스틱은 실패, QDA는 2차 경계로 성공 — 판별도 이차 특징을 켜면 성공한다. 생성의 분포 가정이 곧 판별의 특징 설계와 대응한다 (Representation 플레이그라운드와 연결).