[G1-Sync] Manual knowledge update
This commit is contained in:
@@ -1,66 +1,138 @@
|
||||
---
|
||||
id: wiki-2026-0508-map-estimation
|
||||
title: MAP Estimation
|
||||
title: MAP Estimation (Maximum A Posteriori)
|
||||
category: 10_Wiki/Topics
|
||||
status: needs_review
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [P-Reinforce-AUTO-MAPE-001]
|
||||
aliases: [MAP, Maximum A Posteriori, MAP 추정]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.94
|
||||
tags: [auto-reinforced, map-estimation, Statistics, bayesian, probability, machine-learning]
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [bayesian, estimation, mle, prior, regularization, statistics]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-04-20
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
inferred_by: Claude Opus 4.7 (auto-normalize 2026-05-08)
|
||||
tech_stack: { language: python, framework: numpy-pymc-pytorch }
|
||||
---
|
||||
|
||||
# [[MAP-Estimation|MAP-Estimation]]
|
||||
# MAP Estimation (Maximum A Posteriori)
|
||||
|
||||
## 📌 한 줄 통찰 (The Karpathy Summary)
|
||||
> "경험과 데이터의 합의점: 단순히 현재 눈앞의 데이터(Likelihood)만 믿지 않고, 우리가 이미 알고 있는 사전 지식(Prior)을 결합하여 '가장 일어날 법한 정답'을 확률적으로 찍어내는 영리한 추정 방식."
|
||||
## 매 한 줄
|
||||
> **"매 사전 지식 + 매 데이터 = 매 사후 최댓값"**. MAP 은 prior $p(\theta)$ 와 likelihood $p(D|\theta)$ 를 곱한 posterior 를 최대화하는 점추정이며, log-prior 가 정규화 항으로 들어가 MLE + regularization 과 동등하다.
|
||||
|
||||
## 📖 구조화된 지식 (Synthesized Content)
|
||||
최대 사후 확률 추정(MAP-Estimation)은 베이즈 정리를 활용하여 모집단의 모수를 추정하는 기법입니다.
|
||||
## 매 핵심
|
||||
### 매 정의
|
||||
$$\hat\theta_{MAP} = \arg\max_\theta p(\theta|D) = \arg\max_\theta p(D|\theta)\, p(\theta)$$
|
||||
|
||||
1. **구성 요소**:
|
||||
* **Likelihood**: 현재 데이터가 이 가설을 얼마나 지지하는가?
|
||||
* **Prior (사전 확률)**: 데이터를 보기 전, 우리의 기존 지식이나 믿음은 어떠한가? ([[Inductive-Reasoning|Inductive-Reasoning]]와 연결)
|
||||
* **Posterior (사후 확률)**: 데이터와 사전 지식을 결합한 최종 확률. (MAP는 이 값이 최대인 곳을 찾음)
|
||||
2. **왜 중요한가?**:
|
||||
* 데이터가 부족할 때 발생할 수 있는 오류를 '사전 지식'으로 보정하여 더 안정적인 예측을 가능케 함.
|
||||
log 형태:
|
||||
$$\hat\theta_{MAP} = \arg\max_\theta \big[ \log p(D|\theta) + \log p(\theta) \big]$$
|
||||
|
||||
## ⚠️ 모순 및 업데이트 (Contradictions & Updates)
|
||||
- **과거 데이터와의 충돌**: 과거에는 데이터만 보는 'MLE(최대 우도 추정) 정책'과 대립했으나, 현대 정책은 사전 지식을 정규화([[L2-Regularization|L2-Regularization]] 등) 정책으로 치환하여 두 방식을 자연스럽게 통합함(RL Update). (L2-[[Regularization|Regularization]]와 연결)
|
||||
- **정책 변화(RL Update)**: 딥러닝 가중치 학습 정책에서 사전 지식(예: 가중치는 0 근처여야 한다)을 부여하는 행위 자체가 수학적으로 MAP 추정 정책과 동일하며, 이는 모델의 일반화 정책을 결정짓는 핵심 기법이 됨.
|
||||
### 매 MLE 와의 관계
|
||||
- **MLE**: $\arg\max p(D|\theta)$ — prior 없음 (또는 uniform).
|
||||
- **MAP**: MLE + log-prior 정규화 항.
|
||||
- 데이터가 많아질수록 likelihood dominant → MAP → MLE 수렴.
|
||||
- 데이터가 적을 때 prior 의 영향 큼 (smoothing).
|
||||
|
||||
## 🔗 지식 연결 (Graph)
|
||||
- [[Inductive-Reasoning|Inductive-Reasoning]], [[L2-Regularization|L2-Regularization]], [[Inferential-Statistics|Inferential-Statistics]], [[Machine Learning (ML)|Machine Learning (ML)]], [[Logic|Logic]]
|
||||
- **Modern Tech/Tools**: [[Bayesian Inference|Bayesian Inference]], Gaussian priors, L2 penalty.
|
||||
---
|
||||
### 매 정규화 등가성
|
||||
1. **Gaussian prior** $\theta \sim \mathcal{N}(0, \sigma^2)$ → $-\frac{1}{2\sigma^2}\|\theta\|^2$ → **L2 (Ridge)**.
|
||||
2. **Laplace prior** $\theta \sim \text{Lap}(0, b)$ → $-\frac{1}{b}|\theta|$ → **L1 (Lasso)**.
|
||||
3. **Beta prior** for Bernoulli → Laplace smoothing (additive +α).
|
||||
4. **Dirichlet prior** for categorical → multinomial smoothing.
|
||||
|
||||
## 🤖 LLM 활용 힌트 (How to Use This Knowledge)
|
||||
### 매 vs Full Bayesian
|
||||
- MAP = posterior 의 mode (점추정), 불확실성 X.
|
||||
- Full Bayes = 전체 분포 (MCMC, VI), 예측에 평균/적분.
|
||||
- MAP 은 빠르고 단순, 비대칭 분포에서는 mode 가 mean 과 크게 다름.
|
||||
|
||||
**언제 이 지식을 쓰는가:**
|
||||
- *(TODO)*
|
||||
## 💻 패턴
|
||||
### 1. Coin flip — Beta prior
|
||||
```python
|
||||
import numpy as np
|
||||
heads, tails = 7, 3
|
||||
# Beta(α, β) prior, posterior = Beta(α+h, β+t)
|
||||
alpha, beta = 2, 2
|
||||
mode_map = (alpha + heads - 1) / (alpha + beta + heads + tails - 2)
|
||||
mle = heads / (heads + tails)
|
||||
print(mle, mode_map) # 0.7 vs 0.6818
|
||||
```
|
||||
|
||||
**언제 쓰면 안 되는가:**
|
||||
- *(TODO)*
|
||||
### 2. Linear regression: Ridge = MAP w/ Gaussian prior
|
||||
```python
|
||||
from sklearn.linear_model import Ridge
|
||||
ridge = Ridge(alpha=1.0) # alpha = 1/(2σ²) on weights
|
||||
ridge.fit(X, y)
|
||||
```
|
||||
가중치 prior $\mathcal{N}(0,\sigma^2 I)$, noise prior 별도 → closed-form MAP = Ridge.
|
||||
|
||||
## 🧪 검증 상태 (Validation)
|
||||
### 3. Logistic regression: L2 = MAP
|
||||
```python
|
||||
from sklearn.linear_model import LogisticRegression
|
||||
LogisticRegression(penalty="l2", C=1.0).fit(X, y) # C=1/λ
|
||||
```
|
||||
|
||||
- **정보 상태:** needs_review
|
||||
- **출처 신뢰도:** A
|
||||
- **검토 이유:** *(P-Reinforce Phase 1 자동 정규화. 본문 검증 필요.)*
|
||||
### 4. PyMC explicit MAP
|
||||
```python
|
||||
import pymc as pm, numpy as np
|
||||
with pm.Model() as m:
|
||||
mu = pm.Normal("mu", 0, 10)
|
||||
sigma = pm.HalfNormal("sigma", 1)
|
||||
pm.Normal("obs", mu=mu, sigma=sigma, observed=data)
|
||||
map_est = pm.find_MAP()
|
||||
```
|
||||
|
||||
## 🧬 중복 검사 (Duplicate Check)
|
||||
### 5. PyTorch MAP via SGD
|
||||
```python
|
||||
loss = nll(model(x), y) + 0.5 * lam * sum((p**2).sum() for p in model.parameters())
|
||||
loss.backward(); opt.step()
|
||||
# lam = 1/σ²(prior) — Gaussian prior MAP
|
||||
```
|
||||
|
||||
- **기존 유사 문서:** *(TODO: 인덱서 클러스터 리포트 참조)*
|
||||
- **처리 방식:** UPDATE (자동 정규화)
|
||||
- **처리 이유:** Phase 1 정규화 — 옛 템플릿/누락 필드 보강.
|
||||
### 6. Laplace smoothing in NB classifier
|
||||
```python
|
||||
P_w_given_c = (count_wc + 1) / (count_c + V) # Dirichlet(1,..,1) prior
|
||||
```
|
||||
|
||||
## 🕓 변경 이력 (Changelog)
|
||||
### 7. Kalman filter 의 update 단계 = MAP
|
||||
```python
|
||||
# prior : N(x_pred, P_pred)
|
||||
# likeli : N(z; H x, R)
|
||||
# posterior mode = MAP = standard KF update
|
||||
```
|
||||
|
||||
| 날짜 | 변경 내용 | 처리 방식 | 신뢰도 |
|
||||
|------|-----------|-----------|--------|
|
||||
| 2026-05-08 | P-Reinforce Phase 1 정규화 (frontmatter + 헤더 표준화) | UPDATE | A |
|
||||
## 매 결정 기준
|
||||
| 상황 | Estimator |
|
||||
|---|---|
|
||||
| 데이터 많음, prior 약함 | MLE |
|
||||
| 데이터 적음, 사전 지식 있음 | MAP |
|
||||
| 정규화 필요 | MAP (Gaussian/Laplace prior) |
|
||||
| 불확실성 정량화 필요 | Full Bayes (posterior 전체) |
|
||||
| 빠른 점추정 + smoothing | MAP |
|
||||
|
||||
**기본값**: MLE 가 overfit 위험이거나 sparse 데이터면 MAP, 의사결정에 불확실성이 중요하면 full Bayes.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Bayesian-Inference]], [[Estimation-Theory]]
|
||||
- 변형: [[MLE]], [[Full-Bayesian]], [[Variational-Inference]], [[MCMC]]
|
||||
- 응용: [[Ridge-Regression]], [[Lasso]], [[Naive-Bayes]], [[Kalman-Filter]]
|
||||
- Adjacent: [[Regularization]], [[Conjugate-Prior]], [[Posterior-Distribution]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: prior ↔ regularizer 매핑 설명, MAP 수식 derive, 작은 코드 스니펫.
|
||||
**언제 X**: 비표준 prior 의 polynomial-time 풀이 (보통 sampling 필요).
|
||||
|
||||
## ❌ 안티패턴
|
||||
- prior 를 reparametrize 하면 MAP mode 가 변한다 — invariance 없음 (MLE 는 변함, posterior 평균은 더 안정).
|
||||
- 강한 prior + 적은 데이터 → 실제 신호 묻힘.
|
||||
- MAP 점추정으로 의사결정 후 불확실성 무시.
|
||||
- 비대칭/다봉 posterior 에서 mode 만 보고 결론.
|
||||
- 균등 prior 를 무한 구간에 부여 — improper, 정규화 안 됨.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified. 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup |
|
||||
|
||||
Reference in New Issue
Block a user