docs(10_Wiki): 위키 전체 재구성 — Topic_* 폴더를 4개 카테고리로 통합 + 대규모 중복 제거
Topic_Agent/Topic_Blog/Topics/Topics_Biz/Topics_Meeting/Topics_Rag의 마크다운 지식 문서를 Topic_General/Topic_Programming/Topic_Graphic/Topic_Business 4개 카테고리로 재분류. - 중복 제거: frontmatter의 status:duplicate/merged + duplicate_of/redirect_to 필드로 자기 자신을 중복으로 선언한 리다이렉트 stub 1032개 제거, 완전 동일 내용 파일 472개 제거, 동일 파일명·다른 내용 충돌 시 더 큰(완전한) 버전만 유지(162개 제거) — 총 1639개 중복 제거. - 분류: 폴더 단위로 명확한 항목(AI_and_ML/Coding/Architecture 등 → Programming, Comfyui/Visual_Effects → Graphic, Topics_Biz/Topics_Meeting/사업 등 → Business, Poetic_Blog_Writing/창의성/Game_Design 등 → General)은 폴더 우선순위로, 나머지 혼재 폴더(Topic_Agent/Topic_Blog/Topics 루트/Thinking & Reasoning/Other/UI_UX_Assets)는 title/tags 키워드 스코어링으로 파일 단위 분류(불명확한 경우 General로 폴백). 원본 폴더명은 "From_*" 서브폴더로 보존해 추적 가능성 유지. - 최종 배치: Programming 2784 / General 1608 / Graphic 285 / Business 249 = 4926개 문서. - 에이전트 운영 상태(.astra/.agent/.obsidian/sessions/memory/_company/docs/lessons/_shared/src)는 지식 콘텐츠가 아니므로 재분류 대상에서 제외하고 원위치 유지. - Topics/Topic_email(상위 보호 폴더 Topic_email과 파일명 100% 중복) 삭제 — 보호 폴더 자체는 미변경. - 완전히 비게 된 Topic_Agent/Topic_Blog/Topics_Biz/Topics_Rag 폴더 제거.
This commit is contained in:
@@ -0,0 +1,138 @@
|
||||
---
|
||||
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 |
|
||||
Reference in New Issue
Block a user