d8a80f6272
이름만 다른(표기 변형) [[위키링크]]를 대상 문서의 canonical 제목으로 치환해 끊겼던 1,200개 링크를 연결. 제목/파일명 정규화 일치만 적용하고 별칭 매칭은 과병합 위험으로 제외(애매성 가드). 원본은 _link_reconcile_backup/ 에 백업. 도구: Datacollect/scripts/link_reconcile_apply.mjs Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
139 lines
4.8 KiB
Markdown
139 lines
4.8 KiB
Markdown
---
|
||
id: wiki-2026-0508-map-estimation
|
||
title: MAP Estimation (Maximum A Posteriori)
|
||
category: 10_Wiki/Topics
|
||
status: verified
|
||
canonical_id: self
|
||
aliases: [MAP, Maximum A Posteriori, MAP 추정]
|
||
duplicate_of: none
|
||
source_trust_level: A
|
||
confidence_score: 0.9
|
||
verification_status: applied
|
||
tags: [bayesian, estimation, mle, prior, regularization, statistics]
|
||
raw_sources: []
|
||
last_reinforced: 2026-05-10
|
||
github_commit: pending
|
||
tech_stack: { language: python, framework: numpy-pymc-pytorch }
|
||
---
|
||
|
||
# MAP Estimation (Maximum A Posteriori)
|
||
|
||
## 매 한 줄
|
||
> **"매 사전 지식 + 매 데이터 = 매 사후 최댓값"**. MAP 은 prior $p(\theta)$ 와 likelihood $p(D|\theta)$ 를 곱한 posterior 를 최대화하는 점추정이며, log-prior 가 정규화 항으로 들어가 MLE + regularization 과 동등하다.
|
||
|
||
## 매 핵심
|
||
### 매 정의
|
||
$$\hat\theta_{MAP} = \arg\max_\theta p(\theta|D) = \arg\max_\theta p(D|\theta)\, p(\theta)$$
|
||
|
||
log 형태:
|
||
$$\hat\theta_{MAP} = \arg\max_\theta \big[ \log p(D|\theta) + \log p(\theta) \big]$$
|
||
|
||
### 매 MLE 와의 관계
|
||
- **MLE**: $\arg\max p(D|\theta)$ — prior 없음 (또는 uniform).
|
||
- **MAP**: MLE + log-prior 정규화 항.
|
||
- 데이터가 많아질수록 likelihood dominant → MAP → MLE 수렴.
|
||
- 데이터가 적을 때 prior 의 영향 큼 (smoothing).
|
||
|
||
### 매 정규화 등가성
|
||
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.
|
||
|
||
### 매 vs Full Bayesian
|
||
- MAP = posterior 의 mode (점추정), 불확실성 X.
|
||
- Full Bayes = 전체 분포 (MCMC, VI), 예측에 평균/적분.
|
||
- MAP 은 빠르고 단순, 비대칭 분포에서는 mode 가 mean 과 크게 다름.
|
||
|
||
## 💻 패턴
|
||
### 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
|
||
```
|
||
|
||
### 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.
|
||
|
||
### 3. Logistic regression: L2 = MAP
|
||
```python
|
||
from sklearn.linear_model import LogisticRegression
|
||
LogisticRegression(penalty="l2", C=1.0).fit(X, y) # C=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()
|
||
```
|
||
|
||
### 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
|
||
```
|
||
|
||
### 6. Laplace smoothing in NB classifier
|
||
```python
|
||
P_w_given_c = (count_wc + 1) / (count_c + V) # Dirichlet(1,..,1) prior
|
||
```
|
||
|
||
### 7. Kalman filter 의 update 단계 = MAP
|
||
```python
|
||
# prior : N(x_pred, P_pred)
|
||
# likeli : N(z; H x, R)
|
||
# posterior mode = MAP = standard KF update
|
||
```
|
||
|
||
## 매 결정 기준
|
||
| 상황 | Estimator |
|
||
|---|---|
|
||
| 데이터 많음, prior 약함 | MLE |
|
||
| 데이터 적음, 사전 지식 있음 | MAP |
|
||
| 정규화 필요 | MAP (Gaussian/Laplace prior) |
|
||
| 불확실성 정량화 필요 | Full Bayes (posterior 전체) |
|
||
| 빠른 점추정 + smoothing | MAP |
|
||
|
||
**기본값**: MLE 가 overfit 위험이거나 sparse 데이터면 MAP, 의사결정에 불확실성이 중요하면 full Bayes.
|
||
|
||
## 🔗 Graph
|
||
- 부모: [[Bayesian Inference]]
|
||
- 변형: [[Variational-Inference]], [[MCMC]]
|
||
- 응용: [[Ridge-Regression]], [[Lasso]], [[Naive-Bayes]], [[Kalman-Filter-and-State-Tracking|Kalman-Filter]]
|
||
- Adjacent: [[L1-and-L2-Regularization|Regularization]]
|
||
|
||
## 🤖 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 |
|