Workspace IndexMath › Day 35

Conditional Probability, Bayes' Theorem, Expectation, and the Normal Distribution TODO

Math · Day 35 / 52 · November — Probability, Statistics & Financial Math (Day 35-43)

Concept

Conditional probability P(A|B) is the probability of A given that B has occurred, defined as P(A and B) divided by P(B). Bayes' theorem, P(A|B) = P(B|A)P(A)/P(B), gives the procedure for updating a prior probability with the likelihood of new evidence to get a posterior probability. Expectation is a probability-weighted average, and by linearity the expectation of a sum equals the sum of expectations even when the variables aren't independent — though variance only adds simply when the variables are uncorrelated. The normal distribution is determined entirely by its mean and variance, and it serves as the default model because of the central limit theorem: summing many independent random variables with finite variance produces a sum whose distribution approaches normal. That said, assuming normality for fat-tailed data — like financial returns — badly underestimates the probability of extreme events.

When the base rate is low, even a highly accurate detector produces mostly false positives among its positive calls — a Bayesian conclusion that overturns naive intuition in practice — and a prediction market's price is itself best read as a posterior probability.

Code & Formula

# Day 35 — 조건부확률·베이즈·기대값·정규분포
# 질병 검사 예시로 베이즈 정리를 수치로 계산: P(질병|양성) = P(양성|질병)P(질병) / P(양성)

prior_disease = 0.01          # P(질병) — 사전확률(유병률)
p_positive_given_disease = 0.95   # P(양성|질병) — 민감도
p_positive_given_healthy = 0.05   # P(양성|건강) — 위양성률

p_healthy = 1 - prior_disease
p_positive = (p_positive_given_disease * prior_disease
              + p_positive_given_healthy * p_healthy)

p_disease_given_positive = (p_positive_given_disease * prior_disease) / p_positive

print(f"사전확률 P(질병) = {prior_disease}")
print(f"P(양성) (전체확률) = {p_positive:.4f}")
print(f"베이즈 정리로 계산한 P(질병|양성) = {p_disease_given_positive:.4f}")
print("-> 검사가 정확해 보여도 유병률이 낮으면 사후확률은 여전히 낮다는 직관을 확인한다.\n")

# 기대값과 정규분포: 표준정규분포에서 표본을 뽑아 표본평균이 이론적 기대값(0)에 가까워짐을 확인
import random

random.seed(42)
n = 100_000
samples = [random.gauss(mu=0, sigma=1) for _ in range(n)]
sample_mean = sum(samples) / n
sample_var = sum((s - sample_mean) ** 2 for s in samples) / n

print(f"N(0,1)에서 {n}개 표본 추출")
print(f"표본평균 = {sample_mean:.6f} (이론값 0)")
print(f"표본분산 = {sample_var:.6f} (이론값 1)")

Exercise

For an event with a 1% base rate, detected by a test with 99% sensitivity and 99% specificity, compute by hand the probability that a positive result is actually correct, then verify it with 100,000 simulation runs.

Practical Connection

Verex's market prices are read as participants' posterior probability estimates, and LMSR's per-outcome prices are always maintained as a probability vector summing to 1 — so getting this probabilistic language exactly right is what keeps P&L and settlement calculations from going wrong.

If you study this on a given day, add a note link and a ✅ to this line in the source curriculum (docs/knowledge/math-50-curriculum.md) and this spot will lead straight to the note body. You can also write directly on this page — but regenerating overwrites it, so it's safer to keep anything you want to save as markdown under docs/algorithms/.


한국어

조건부확률·베이즈·기대값·정규분포 TODO

Math · Day 35 / 52 · 11월 — 확률·통계·금융수학 (Day 35–43)

개념

조건부확률 P(A|B)는 B가 일어났다는 정보 아래에서 A가 일어날 확률이며 P(A와 B가 함께)를 P(B)로 나눈 값으로 정의된다. 베이즈 정리는 P(A|B) = P(B|A)P(A)/P(B)로, 사전확률을 새 증거의 우도로 갱신해 사후확률을 얻는 절차를 준다. 기대값은 확률로 가중한 평균이고 선형성 덕분에 독립이 아니어도 합의 기대값은 기대값의 합이지만, 분산은 상관이 없을 때만 단순히 더해진다. 정규분포는 평균과 분산으로 결정되는 분포이며, 독립이고 분산이 유한한 확률변수를 많이 더하면 그 합의 분포가 정규분포에 가까워진다는 중심극한정리 때문에 기본 모형으로 쓰인다. 다만 금융 수익률처럼 꼬리가 두꺼운 데이터에 정규분포를 가정하면 극단 사건의 확률을 크게 과소평가하게 된다.

기저율이 낮으면 정확도 높은 탐지기라도 양성 판정 대부분이 거짓이라는 베이즈적 결론이 실무 판단을 뒤집고, 예측시장 가격 자체가 사후확률로 읽히기 때문이다.

코드 · 수식

# Day 35 — 조건부확률·베이즈·기대값·정규분포
# 질병 검사 예시로 베이즈 정리를 수치로 계산: P(질병|양성) = P(양성|질병)P(질병) / P(양성)

prior_disease = 0.01          # P(질병) — 사전확률(유병률)
p_positive_given_disease = 0.95   # P(양성|질병) — 민감도
p_positive_given_healthy = 0.05   # P(양성|건강) — 위양성률

p_healthy = 1 - prior_disease
p_positive = (p_positive_given_disease * prior_disease
              + p_positive_given_healthy * p_healthy)

p_disease_given_positive = (p_positive_given_disease * prior_disease) / p_positive

print(f"사전확률 P(질병) = {prior_disease}")
print(f"P(양성) (전체확률) = {p_positive:.4f}")
print(f"베이즈 정리로 계산한 P(질병|양성) = {p_disease_given_positive:.4f}")
print("-> 검사가 정확해 보여도 유병률이 낮으면 사후확률은 여전히 낮다는 직관을 확인한다.\n")

# 기대값과 정규분포: 표준정규분포에서 표본을 뽑아 표본평균이 이론적 기대값(0)에 가까워짐을 확인
import random

random.seed(42)
n = 100_000
samples = [random.gauss(mu=0, sigma=1) for _ in range(n)]
sample_mean = sum(samples) / n
sample_var = sum((s - sample_mean) ** 2 for s in samples) / n

print(f"N(0,1)에서 {n}개 표본 추출")
print(f"표본평균 = {sample_mean:.6f} (이론값 0)")
print(f"표본분산 = {sample_var:.6f} (이론값 1)")

연습

기저율 1%인 사건에 민감도 99%·특이도 99%인 탐지기를 적용했을 때 양성 판정이 실제로 맞을 확률을 손으로 계산하고, 10만 회 시뮬레이션으로 검증하기.

실무 · Verex 연결

Verex의 시장 가격은 참가자들의 사후확률 추정으로 해석되고 LMSR의 결과별 가격은 항상 합이 1인 확률 벡터로 유지되므로, 이 확률 언어를 정확히 잡아야 손익과 정산 계산이 어긋나지 않는다.

공부한 날 원본 커리큘럼(docs/knowledge/math-50-curriculum.md)의 이 줄에 노트 링크와 ✅ 를 붙이면, 이 자리는 노트 본문으로 바로 이어집니다. 노트 없이 이 페이지에 바로 적어도 됩니다 — 다만 다시 생성하면 덮어쓰이므로, 남길 글은 docs/algorithms/ 의 마크다운으로 쓰는 편이 안전합니다.

← 34. 볼록집합/볼록함수 판별36. 로그수익률·변동성(σ) →