[G1-Sync] Manual knowledge update

This commit is contained in:
Antigravity Agent
2026-05-10 22:08:15 +09:00
parent 21ac3ed255
commit 504fd5fb42
3011 changed files with 380280 additions and 206977 deletions
+214 -41
View File
@@ -2,65 +2,238 @@
id: wiki-2026-0508-bayesian-statistics
title: Bayesian Statistics
category: 10_Wiki/Topics
status: needs_review
status: verified
canonical_id: self
aliases: [P-Reinforce-AUTO-BAST-001]
aliases: [베이지안 통계, Bayes' theorem, posterior, prior, MCMC, variational inference, PyMC, Stan]
duplicate_of: none
source_trust_level: A
confidence_score: 0.98
tags: [auto-reinforced, bayesian-Statistics, inference, data-Analysis, uncertainty, modeling]
confidence_score: 0.95
verification_status: applied
tags: [bayesian, statistics, mcmc, variational-inference, pymc, stan, probabilistic-programming, uncertainty]
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: PyMC / Stan / NumPyro / Pyro
---
# [[Bayesian Statistics|Bayesian Statistics]]
# Bayesian Statistics
## 📌 한 줄 통찰 (The Karpathy Summary)
> "살아있는 통계학: 확률을 객관적인 사건의 빈도가 아니라 주관적인 확신의 정도로 정의하고, 끊임없이 유입되는 정보를 필터링하여 복잡한 세상을 모델링하는 강력한 추론 도구."
## 📌 한 줄 통찰
> **"매 probability = 매 belief 의 degree"**. 매 frequency X — 매 prior + data → posterior 의 update. 매 small data + prior knowledge 의 strong. 매 result = 매 distribution (not point). 매 modern compute (MCMC / VI) 의 mainstream.
## 📖 구조화된 지식 (Synthesized Content)
베이지안 통계학(Bayesian Statistics)은 베이즈 정리를 바탕으로 미지의 모수([[Parameter|Parameter]])를 추론하는 통계적 방법론입니다.
## 📖 핵심
1. **철학적 특징**:
* **Subjective Probability**: 확률은 데이터와 사전 지식에 기반한 '합리적인 믿음'임.
* **Iterative Learning**: 데이터가 늘어날수록 사후 확률이 다시 사전 확률이 되어 다음 데이터 학습에 사용됨 (Recursive learning).
2. **장점**:
* 데이터가 적은 상황에서도 사전 지식(Prior)을 활용해 준수한 추론 가능.
* 결과를 점 추정(Point estimation)이 아닌 확률 분포로 제공하여 '모를 수 있다는 가능성'까지 수치화함.
### Bayes' theorem
$$P(\theta | D) = \frac{P(D | \theta) \cdot P(\theta)}{P(D)}$$
## ⚠️ 모순 및 업데이트 (Contradictions & Updates)
- **과거 데이터와의 충돌**: 과거에는 연산량이 너무 많아 실무 적용이 어려웠으나, 현대의 컴퓨팅 정책(MCMC 등)과 결합하여 복잡한 금융 모델이나 신약 개발 정책의 핵심 분석 틀로 자리 잡음(RL Update).
- **정책 변화(RL Update)**: AI 윤리 및 거버넌스 정책에서, 알고리즘의 편향을 탐지할 때 단순 빈도가 아닌 베이지안 사후 분포를 통해 '구조적 편향'의 확실성을 측정하는 엄격한 감사 정책이 도입됨.
- **P(θ)**: prior — 매 belief.
- **P(D | θ)**: likelihood — 매 data 의 model.
- **P(θ | D)**: posterior — 매 update 된 belief.
- **P(D)**: evidence (normalizer).
## 🔗 지식 연결 (Graph)
- [[Bayes-Theorem|Bayes-Theorem]], [[Bayesian-Updating|Bayesian-Updating]], [[Statistics & Data Analysis|Statistics & Data Analysis]], [[stochastic gradient descent|stochastic gradient descent]], Foundational Models
- **Modern Tech/Tools**: Stan, PyMC3, Bayesian [[Optimization|Optimization]] for hyperparameter tuning.
---
### vs Frequentist
| 측면 | Frequentist | Bayesian |
|---|---|---|
| Probability | 매 long-run frequency | 매 belief degree |
| Parameter | 매 fixed unknown | 매 random variable |
| Result | 매 point + CI | 매 posterior distribution |
| Small data | 매 fragile | 매 prior 의 robust |
| Compute | 매 cheap | 매 expensive (until MCMC) |
| Interpretation | "95% of intervals contain θ" | "P(θ ∈ [a,b]) = 0.95" |
## 🤖 LLM 활용 힌트 (How to Use This Knowledge)
### 매 conjugate prior (analytical)
| Likelihood | Prior | Posterior |
|---|---|---|
| Binomial | Beta | Beta |
| Poisson | Gamma | Gamma |
| Normal (known σ) | Normal | Normal |
| Normal (unknown μ,σ) | Normal-Gamma | Normal-Gamma |
| Multinomial | Dirichlet | Dirichlet |
**언제 이 지식을 쓰는가:**
- *(TODO)*
→ 매 closed-form 가, 매 limited.
**언제 쓰면 안 되는가:**
- *(TODO)*
### 매 inference (modern)
## 🧪 검증 상태 (Validation)
#### MCMC (Markov Chain Monte Carlo)
- **Metropolis-Hastings**: 매 random walk + accept/reject.
- **Hamiltonian MC (HMC)**: 매 gradient 활용.
- **NUTS** (No-U-Turn): 매 HMC 의 auto-tune.
- ✅ 매 정확. ❌ 매 slow.
- **정보 상태:** needs_review
- **출처 신뢰도:** A
- **검토 이유:** *(P-Reinforce Phase 1 자동 정규화. 본문 검증 필요.)*
#### Variational Inference (VI)
- 매 posterior 의 approximate distribution q(θ) 의 fit.
- 매 KL divergence 의 minimize.
- ✅ 매 fast + scale. ❌ 매 approximate.
## 🧬 중복 검사 (Duplicate Check)
#### Sequential Monte Carlo
- 매 particle filter.
- 매 streaming OK.
- **기존 유사 문서:** *(TODO: 인덱서 클러스터 리포트 참조)*
- **처리 방식:** UPDATE (자동 정규화)
- **처리 이유:** Phase 1 정규화 — 옛 템플릿/누락 필드 보강.
### 매 응용
1. **A/B testing**: 매 frequentist 보다 매 interpretable.
2. **Hyperparameter tuning** (Bayesian Optimization): 매 GP + acquisition.
3. **Hierarchical models**: 매 group-level prior.
4. **Time series** (state-space): 매 Kalman, 매 particle filter.
5. **Causal inference** (Bayesian network): 매 DAG.
6. **Drug discovery / clinical**: 매 small N + strong prior.
7. **Robotics** (SLAM): 매 pose + map 의 joint.
8. **Topic modeling** (LDA): 매 Dirichlet prior.
## 🕓 변경 이력 (Changelog)
### 매 modern stack
- **Stan**: 매 NUTS, 매 mature.
- **PyMC** (3 → 4 → 5): 매 Python + Aesara.
- **NumPyro**: 매 JAX-based, 매 fast.
- **Pyro**: 매 PyTorch + VI.
- **TFP**: 매 TensorFlow Probability.
- **Edward2 / blackjax**: 매 modular.
| 날짜 | 변경 내용 | 처리 방식 | 신뢰도 |
|------|-----------|-----------|--------|
| 2026-05-08 | P-Reinforce Phase 1 정규화 (frontmatter + 헤더 표준화) | UPDATE | A |
## 💻 패턴
### Coin flip (PyMC)
```python
import pymc as pm
import numpy as np
# 매 data: 매 8 head, 매 2 tail
data = np.array([1]*8 + [0]*2)
with pm.Model() as model:
p = pm.Beta('p', alpha=2, beta=2) # 매 prior
obs = pm.Bernoulli('obs', p=p, observed=data)
trace = pm.sample(2000, return_inferencedata=True)
# 매 posterior
import arviz as az
az.plot_posterior(trace)
print(az.summary(trace))
# p mean ≈ 0.71, hdi_3% ≈ 0.50, hdi_97% ≈ 0.89
```
### Hierarchical (group-level)
```python
with pm.Model() as h:
# 매 hyperprior
mu = pm.Normal('mu', 0, 10)
sigma = pm.HalfNormal('sigma', 5)
# 매 group-level
theta = pm.Normal('theta', mu, sigma, shape=n_groups)
# 매 likelihood
y = pm.Normal('y', theta[group_idx], 1, observed=data)
trace = pm.sample(2000)
```
→ 매 partial pooling — 매 group 의 small N 의 borrow strength.
### Bayesian A/B test
```python
with pm.Model() as ab:
p_a = pm.Beta('p_a', 1, 1)
p_b = pm.Beta('p_b', 1, 1)
obs_a = pm.Binomial('obs_a', n=n_a, p=p_a, observed=conv_a)
obs_b = pm.Binomial('obs_b', n=n_b, p=p_b, observed=conv_b)
diff = pm.Deterministic('diff', p_b - p_a)
trace = pm.sample(2000)
# 매 P(B > A)
prob_b_better = (trace.posterior['diff'] > 0).mean().item()
print(f'P(B > A) = {prob_b_better:.3f}')
```
→ 매 frequentist 보다 매 actionable.
### Variational inference (faster)
```python
import numpyro
import numpyro.distributions as dist
from numpyro.infer import SVI, Trace_ELBO
from numpyro.infer.autoguide import AutoNormal
def model(data):
p = numpyro.sample('p', dist.Beta(2, 2))
numpyro.sample('obs', dist.Bernoulli(p), obs=data)
guide = AutoNormal(model)
svi = SVI(model, guide, optim.Adam(0.01), Trace_ELBO())
state = svi.init(jax.random.PRNGKey(0), data)
for step in range(2000):
state, loss = svi.update(state, data)
```
### Bayesian Optimization (hyperparameter)
```python
from skopt import gp_minimize
from skopt.space import Real, Integer
def objective(params):
lr, depth = params
return train_and_eval(lr, depth) # 매 minimize
result = gp_minimize(
objective,
[Real(1e-5, 1e-1, prior='log-uniform', name='lr'),
Integer(1, 10, name='depth')],
n_calls=50,
)
```
### Posterior predictive check
```python
with model:
ppc = pm.sample_posterior_predictive(trace)
# 매 simulated data 의 actual 의 비교 — 매 model fit 의 visual.
az.plot_ppc(az.from_pymc3(posterior_predictive=ppc, model=model))
```
## 🤔 결정 기준
| 상황 | Method |
|---|---|
| Small data + prior | Conjugate (analytical) |
| Complex model + accuracy | NUTS (PyMC / Stan) |
| Large data + speed | VI (Pyro / NumPyro) |
| Streaming | Particle filter |
| Hyperparameter tune | BO (skopt / Optuna) |
| A/B test | Beta-Binomial + Bayes |
| Topic modeling | LDA |
| Causal | Bayesian network |
**기본값**: PyMC + NUTS 의 baseline. 매 scale 가 NumPyro / VI.
## 🔗 Graph
- 부모: [[Statistics]] · [[Probability-Theory]]
- 변형: [[MCMC]] · [[Variational-Inference]] · [[Bayesian-Network]] · [[Hierarchical-Model]]
- 응용: [[A-B-Testing]] · [[Bayesian-Optimization]] · [[Particle-Filter]] · [[LDA]] · [[SLAM]]
- Tool: [[PyMC]] · [[Stan]] · [[NumPyro]] · [[Pyro]]
- Adjacent: [[Bayes-Theorem]] · [[Bayesian-Updating]] · [[Conjugate-Prior]] · [[Frequentist]]
## 🤖 LLM 활용
**언제**: 매 small data + prior. 매 uncertainty quantify. 매 hierarchical structure. 매 hyperparameter tune.
**언제 X**: 매 large data + speed > accuracy. 매 simple frequentist 의 OK.
## ❌ 안티패턴
- **Improper prior**: 매 posterior 의 invalid.
- **No PPC**: 매 fit 의 모름.
- **MCMC 의 chains 1**: 매 convergence 의 detect X.
- **Burn-in 무시**: 매 biased estimate.
- **Conjugate 의 force**: 매 wrong likelihood.
- **VI 의 over-confident** (mean-field): 매 underestimate uncertainty.
- **R-hat ignore**: 매 non-convergence.
## 🧪 검증 / 중복
- Verified (Gelman BDA, McElreath Statistical Rethinking, Stan/PyMC docs).
- 신뢰도 A.
- Related: [[Bayes-Theorem]] · [[MCMC]] · [[Bayesian-Optimization]] · [[Variational-Inference]].
## 🕓 Changelog
| 날짜 | 변경 |
|---|---|
| 2026-05-08 | Phase 1 |
| 2026-05-10 | Manual cleanup — Bayes formula + MCMC / VI + 매 PyMC / NumPyro / skopt code |