[G1-Sync] Manual knowledge update
This commit is contained in:
@@ -1,67 +1,167 @@
|
||||
---
|
||||
id: wiki-2026-0508-bayes-theorem
|
||||
title: Bayes Theorem
|
||||
title: Bayes' Theorem
|
||||
category: 10_Wiki/Topics
|
||||
status: needs_review
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [P-Reinforce-AUTO-BATH-001]
|
||||
aliases: [Bayes Rule, Bayes Law, Conditional Probability Inversion]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 1.0
|
||||
tags: [auto-reinforced, bayes-theorem, probability, Statistics, rational-decision-making, Logic]
|
||||
confidence_score: 0.98
|
||||
verification_status: applied
|
||||
tags: [probability, statistics, inference, mathematics, decision-theory]
|
||||
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: SciPy / NumPy
|
||||
---
|
||||
|
||||
# [[Bayes-Theorem|Bayes-Theorem]]
|
||||
# Bayes' Theorem
|
||||
|
||||
## 📌 한 줄 통찰 (The Karpathy Summary)
|
||||
> "데이터를 통한 믿음의 업데이트: 새로운 증거가 나타났을 때, 기존의 지식(사전 확률)을 바탕으로 결론(사후 확률)을 어떻게 수정해야 하는지를 수학적으로 명시한 합리적 추론의 공식."
|
||||
## 매 한 줄
|
||||
> **"매 P(A|B) = P(B|A) × P(A) / P(B) — conditional probability 의 inversion 의 통한 evidence-based belief revision 의 mathematical foundation"**. Reverend Thomas Bayes (1763 posthumous) 의 essay, Laplace (1774) 의 generalize, 2026 modern ML 의 entire Bayesian stack — diffusion model 의 noise schedule, Kalman filter, LLM uncertainty calibration — 의 core.
|
||||
|
||||
## 📖 구조화된 지식 (Synthesized Content)
|
||||
베이즈 정리(Bayes-Theorem)는 조건부 확률을 계산하는 정리로, 데이터 기반의 추론과 학급에서 가장 중요한 가동 원리 중 하나입니다.
|
||||
## 매 핵심
|
||||
|
||||
1. **공식의 구성**:
|
||||
* **Prior (사전 확률)**: 새로운 데이터를 보기 전의 믿음.
|
||||
* **Likelihood (우도)**: 가설이 참일 때, 현재 데이터가 나타날 확률.
|
||||
* **Posterior (사후 확률)**: 데이터를 확인한 후 업데이트된 지식/믿음.
|
||||
2. **왜 중요한가?**:
|
||||
* 불확실성이 높은 상황에서도 고정관념에 빠지지 않고 새로운 정보에 따라 유연하게 판단을 수정하게 해줌 (Rationality와의 연결).
|
||||
* 머신러닝의 베이지안 분류기, 스팸 필터링, 그리고 뇌의 인지 과정 모델링에 핵심적으로 쓰임.
|
||||
### 매 공식 the form
|
||||
- **Standard**: `P(A|B) = P(B|A) × P(A) / P(B)`
|
||||
- **Odds form**: `O(A|B) = O(A) × LR` where `LR = P(B|A)/P(B|¬A)`
|
||||
- **Discrete partition**: `P(H_i|E) = P(E|H_i)P(H_i) / Σⱼ P(E|H_j)P(H_j)`
|
||||
- **Continuous**: `p(θ|D) = p(D|θ)p(θ) / ∫p(D|θ)p(θ)dθ`
|
||||
|
||||
## ⚠️ 모순 및 업데이트 (Contradictions & Updates)
|
||||
- **과거 데이터와의 충돌**: 과거의 빈도주의(Frequentist) 통계 정책은 '고정된 확률'에 집착했으나, 현대의 베이지안 정책은 확률을 '개인의 믿음의 정도'로 보고 끊임없이 업데이트하는 유연한 정책으로 승리함(RL Update).
|
||||
- **정책 변화(RL Update)**: AI 모델의 불확실성 관리 정책에서, 모델이 내린 답의 '확신 수준(Confidence)'을 계산하기 위해 베이지안 신경망 기술을 적용하는 것이 안전(Safety) 핵심 가이드라인이 됨.
|
||||
### 매 terminology
|
||||
- **Prior** P(A): pre-evidence belief
|
||||
- **Likelihood** P(B|A): evidence-given-hypothesis
|
||||
- **Posterior** P(A|B): post-evidence belief
|
||||
- **Evidence / Marginal** P(B): normalizing constant
|
||||
|
||||
## 🔗 지식 연결 (Graph)
|
||||
- [[Bayesian Statistics|Bayesian Statistics]], [[Bayesian-Updating|Bayesian-Updating]], Rationality, [[Belief-Revision|Belief-Revision]], [[Information-Theory|Information-Theory]]
|
||||
- **Modern Tech/Tools**: Bayesian Networks, PyMC, Naive Bayes Classifiers.
|
||||
---
|
||||
### 매 응용
|
||||
1. Medical testing — base-rate-aware diagnosis (mammography paradox).
|
||||
2. Spam filtering — Naive Bayes classifier.
|
||||
3. Search & rescue — posterior heatmap update from sensor sweep.
|
||||
4. LLM 의 token sampling — temperature-scaled posterior over vocabulary.
|
||||
|
||||
## 🤖 LLM 활용 힌트 (How to Use This Knowledge)
|
||||
## 💻 패턴
|
||||
|
||||
**언제 이 지식을 쓰는가:**
|
||||
- *(TODO)*
|
||||
### Medical test (base rate problem)
|
||||
```python
|
||||
def bayes_diagnosis(prevalence: float, sensitivity: float, specificity: float) -> dict:
|
||||
"""Disease prevalence 1%, test 99% sensitive + 95% specific.
|
||||
Positive test => actual disease probability?"""
|
||||
p_disease = prevalence
|
||||
p_pos_given_disease = sensitivity
|
||||
p_pos_given_healthy = 1 - specificity
|
||||
|
||||
p_pos = p_pos_given_disease * p_disease + p_pos_given_healthy * (1 - p_disease)
|
||||
p_disease_given_pos = (p_pos_given_disease * p_disease) / p_pos
|
||||
|
||||
return {
|
||||
"P(disease | +test)": p_disease_given_pos,
|
||||
"P(healthy | +test)": 1 - p_disease_given_pos,
|
||||
}
|
||||
|
||||
**언제 쓰면 안 되는가:**
|
||||
- *(TODO)*
|
||||
print(bayes_diagnosis(0.01, 0.99, 0.95)) # ~16.6% — counter-intuitive
|
||||
```
|
||||
|
||||
## 🧪 검증 상태 (Validation)
|
||||
### Naive Bayes spam (log-space)
|
||||
```python
|
||||
import numpy as np
|
||||
from collections import Counter
|
||||
|
||||
- **정보 상태:** needs_review
|
||||
- **출처 신뢰도:** A
|
||||
- **검토 이유:** *(P-Reinforce Phase 1 자동 정규화. 본문 검증 필요.)*
|
||||
class NaiveBayesSpam:
|
||||
def __init__(self, alpha=1.0):
|
||||
self.alpha = alpha # Laplace smoothing
|
||||
|
||||
def fit(self, docs, labels):
|
||||
self.classes = np.unique(labels)
|
||||
self.log_prior = {c: np.log((labels == c).mean()) for c in self.classes}
|
||||
self.vocab = set(w for d in docs for w in d.split())
|
||||
V = len(self.vocab)
|
||||
self.log_lik = {}
|
||||
for c in self.classes:
|
||||
words = Counter(w for d, l in zip(docs, labels) if l == c for w in d.split())
|
||||
total = sum(words.values()) + self.alpha * V
|
||||
self.log_lik[c] = {w: np.log((words.get(w, 0) + self.alpha) / total)
|
||||
for w in self.vocab}
|
||||
return self
|
||||
|
||||
def predict(self, doc):
|
||||
scores = {c: self.log_prior[c] + sum(self.log_lik[c].get(w, 0)
|
||||
for w in doc.split())
|
||||
for c in self.classes}
|
||||
return max(scores, key=scores.get)
|
||||
```
|
||||
|
||||
## 🧬 중복 검사 (Duplicate Check)
|
||||
### Bayesian A/B (closed-form Beta-Binomial)
|
||||
```python
|
||||
from scipy import stats
|
||||
|
||||
- **기존 유사 문서:** *(TODO: 인덱서 클러스터 리포트 참조)*
|
||||
- **처리 방식:** UPDATE (자동 정규화)
|
||||
- **처리 이유:** Phase 1 정규화 — 옛 템플릿/누락 필드 보강.
|
||||
def prob_b_beats_a(a_clicks, a_imp, b_clicks, b_imp, n_samples=100_000):
|
||||
a = stats.beta(1 + a_clicks, 1 + a_imp - a_clicks).rvs(n_samples)
|
||||
b = stats.beta(1 + b_clicks, 1 + b_imp - b_clicks).rvs(n_samples)
|
||||
return (b > a).mean()
|
||||
|
||||
## 🕓 변경 이력 (Changelog)
|
||||
print(f"P(B>A) = {prob_b_beats_a(73, 1000, 91, 1010):.3f}")
|
||||
```
|
||||
|
||||
| 날짜 | 변경 내용 | 처리 방식 | 신뢰도 |
|
||||
|------|-----------|-----------|--------|
|
||||
| 2026-05-08 | P-Reinforce Phase 1 정규화 (frontmatter + 헤더 표준화) | UPDATE | A |
|
||||
### Odds-form rapid update
|
||||
```python
|
||||
def odds_update(prior_odds: float, likelihood_ratio: float) -> float:
|
||||
"""Posterior odds = prior odds × LR. Mental-arithmetic friendly."""
|
||||
return prior_odds * likelihood_ratio
|
||||
|
||||
# DNA match: prior 1:1000, LR = 100,000
|
||||
print(odds_update(1/1000, 100_000)) # 100 → P ≈ 99%
|
||||
```
|
||||
|
||||
### Kalman filter (Bayesian, Gaussian)
|
||||
```python
|
||||
def kalman_step(mu, sigma2, z, R, Q):
|
||||
"""Predict + update; everything Bayesian under Normal-Normal conjugate."""
|
||||
# predict (process noise Q)
|
||||
sigma2 = sigma2 + Q
|
||||
# update (sensor z, sensor noise R)
|
||||
K = sigma2 / (sigma2 + R)
|
||||
mu = mu + K * (z - mu)
|
||||
sigma2 = (1 - K) * sigma2
|
||||
return mu, sigma2
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Conjugate prior 의 fit | closed-form posterior |
|
||||
| Discrete + small | exact enumeration |
|
||||
| Continuous + nonconjugate | MCMC (NUTS / HMC) |
|
||||
| Streaming sensor data | Kalman / particle filter |
|
||||
| Class imbalance + features | Naive Bayes baseline |
|
||||
|
||||
**기본값**: probabilistic classification 의 default — Naive Bayes (log-space) + Laplace smoothing.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Statistical-Analysis]]
|
||||
- 변형: [[Bayesian-Updating]] · [[Belief-Revision]]
|
||||
- 응용: [[Item-Item-Collaborative-Filtering]] · [[몬테카를로 시뮬레이션]]
|
||||
- Adjacent: [[Inference-Coupled Persistence]] · [[Multi-agent-System]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: probabilistic reasoning 의 explanation, base-rate-aware decision, evidence weighting.
|
||||
**언제 X**: deterministic logic 의 sufficient 인 경우 — overhead 의 X.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Base-rate neglect**: P(B|A) 의 confuse with P(A|B) — prosecutor's fallacy.
|
||||
- **Naive equal prior**: domain knowledge 의 ignore 의 인해 prior 의 default uniform.
|
||||
- **Evidence double-counting**: dependent evidence 의 conditional independence 의 assume.
|
||||
- **Improper normalization**: continuous case 의 evidence integral 의 omit.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Jaynes *Probability Theory: The Logic of Science*, Pearl *Causality* 2nd).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — full Bayes' theorem with medical, NB, A/B, Kalman patterns |
|
||||
|
||||
Reference in New Issue
Block a user