Workspace IndexMath › Day 37

Concentration Inequalities (Chebyshev, Hoeffding — Bridge to December) TODO

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

Concept

Concentration inequalities are a family of results bounding how tightly a random variable clusters around its expectation. Markov's inequality is the weakest form, bounding the tail of a non-negative variable using only its mean. Chebyshev's inequality adds variance information, guaranteeing that the probability of deviating from the mean by more than k standard deviations is at most 1/k². Hoeffding's inequality guarantees that for the average of independent variables each bounded within a finite interval, the probability of deviation decays exponentially in both the sample size and the deviation width. The consistent principle across this family is that stronger assumptions — non-negativity, then finite variance, then boundedness plus independence — yield sharper tail bounds. The practical use is solving in reverse: how many samples do you need to hit a target accuracy at a target confidence level — and that guarantee becomes meaningless the moment the independence assumption breaks.

Determining a defensible sample size for sampling-based estimation, A/B decisions, or the failure probability of a randomized algorithm requires these inequalities — a sample count picked by gut feel is usually either too small or wastefully large.

Code & Formula

# Day 37 — 집중부등식(Chebyshev·Hoeffding)
# 시뮬레이션으로 실제 이탈확률을 구하고, Chebyshev·Hoeffding 상한과 비교해 부등식이 보장임을 확인한다.

import random
import math

random.seed(0)

# Chebyshev: P(|X - mu| >= k*sigma) <= 1/k^2, X ~ Uniform(0,1) 표본평균으로 확인
n_trials = 200_000
mu_uniform = 0.5
var_uniform = 1 / 12
sigma_uniform = math.sqrt(var_uniform)

k = 2.0
count_exceed = 0
for _ in range(n_trials):
    x = random.uniform(0, 1)
    if abs(x - mu_uniform) >= k * sigma_uniform:
        count_exceed += 1

empirical_prob = count_exceed / n_trials
chebyshev_bound = 1 / k ** 2
print(f"Chebyshev: P(|X-mu|>={k}*sigma) 실제 = {empirical_prob:.4f}, 상한 1/k^2 = {chebyshev_bound:.4f}")
print(f"-> 실제 <= 상한 ? {empirical_prob <= chebyshev_bound}\n")

# Hoeffding: 독립 [0,1] 변수 n개 평균이 참평균에서 t 이상 벗어날 확률 <= 2*exp(-2*n*t^2)
n_samples = 100
t = 0.1
n_experiments = 20_000
count_exceed_hoeffding = 0
true_mean = 0.5

for _ in range(n_experiments):
    sample = [random.uniform(0, 1) for _ in range(n_samples)]
    sample_mean = sum(sample) / n_samples
    if abs(sample_mean - true_mean) >= t:
        count_exceed_hoeffding += 1

empirical_hoeffding = count_exceed_hoeffding / n_experiments
hoeffding_bound = 2 * math.exp(-2 * n_samples * t ** 2)
print(f"Hoeffding: P(|mean-mu|>={t}) 실제 = {empirical_hoeffding:.5f}, 상한 = {hoeffding_bound:.5f}")
print(f"-> 실제 <= 상한 ? {empirical_hoeffding <= hoeffding_bound}")

Exercise

Compute, using both Chebyshev's and Hoeffding's inequalities, how many coin flips are needed to estimate a biased coin's heads probability to within 0.01 at 95% confidence, and compare how different the two required sample sizes are.

Practical Connection

This same reasoning is exactly what's used to judge how many trials are needed before a measured average from a prediction-market simulation or a matching-engine load test can be trusted.

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/.


한국어

집중부등식(Chebyshev·Hoeffding, 12월 다리) TODO

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

개념

집중부등식은 확률변수가 기댓값 근처에 얼마나 몰려 있는지를 보장하는 부등식들의 총칭이다. Markov 부등식은 음이 아닌 변수에 대해 평균만으로 꼬리를 제한하는 가장 약한 형태이고, Chebyshev 부등식은 여기에 분산 정보를 더해 기댓값에서 표준편차의 k배 이상 벗어날 확률이 1/k² 이하임을 보장한다. Hoeffding 부등식은 서로 독립이고 각각 유한한 구간 안에 갇힌 변수들의 평균에 대해, 벗어남 확률이 표본 수와 벗어남 폭에 대해 지수적으로 감소함을 보장한다. 이 계열의 일관된 원리는 가정을 더 강하게 둘수록(비음수 → 분산 유한 → 유계·독립) 꼬리 경계가 더 날카로워진다는 것이다. 실무적 용도는 '몇 번 표본을 뽑아야 원하는 정확도를 원하는 신뢰수준으로 얻는가'를 역으로 푸는 것이며, 이때 독립성 가정이 깨지면 보장 자체가 무의미해진다.

샘플링 기반 추정, A/B 판단, 랜덤 알고리즘의 실패 확률 산정에서 필요한 표본 수를 근거 있게 정하려면 이 부등식이 있어야 한다. 감으로 정한 표본 수는 대개 과소하거나 과대하다.

코드 · 수식

# Day 37 — 집중부등식(Chebyshev·Hoeffding)
# 시뮬레이션으로 실제 이탈확률을 구하고, Chebyshev·Hoeffding 상한과 비교해 부등식이 보장임을 확인한다.

import random
import math

random.seed(0)

# Chebyshev: P(|X - mu| >= k*sigma) <= 1/k^2, X ~ Uniform(0,1) 표본평균으로 확인
n_trials = 200_000
mu_uniform = 0.5
var_uniform = 1 / 12
sigma_uniform = math.sqrt(var_uniform)

k = 2.0
count_exceed = 0
for _ in range(n_trials):
    x = random.uniform(0, 1)
    if abs(x - mu_uniform) >= k * sigma_uniform:
        count_exceed += 1

empirical_prob = count_exceed / n_trials
chebyshev_bound = 1 / k ** 2
print(f"Chebyshev: P(|X-mu|>={k}*sigma) 실제 = {empirical_prob:.4f}, 상한 1/k^2 = {chebyshev_bound:.4f}")
print(f"-> 실제 <= 상한 ? {empirical_prob <= chebyshev_bound}\n")

# Hoeffding: 독립 [0,1] 변수 n개 평균이 참평균에서 t 이상 벗어날 확률 <= 2*exp(-2*n*t^2)
n_samples = 100
t = 0.1
n_experiments = 20_000
count_exceed_hoeffding = 0
true_mean = 0.5

for _ in range(n_experiments):
    sample = [random.uniform(0, 1) for _ in range(n_samples)]
    sample_mean = sum(sample) / n_samples
    if abs(sample_mean - true_mean) >= t:
        count_exceed_hoeffding += 1

empirical_hoeffding = count_exceed_hoeffding / n_experiments
hoeffding_bound = 2 * math.exp(-2 * n_samples * t ** 2)
print(f"Hoeffding: P(|mean-mu|>={t}) 실제 = {empirical_hoeffding:.5f}, 상한 = {hoeffding_bound:.5f}")
print(f"-> 실제 <= 상한 ? {empirical_hoeffding <= hoeffding_bound}")

연습

치우친 동전의 앞면 비율을 오차 0.01 이내로 95% 신뢰도로 추정하려면 몇 번 던져야 하는지 Chebyshev와 Hoeffding으로 각각 계산해 필요한 표본 수 차이를 비교하라.

실무 · Verex 연결

예측시장 시뮬레이션이나 매칭 엔진 부하 테스트에서 측정한 평균이 몇 번의 시행으로 신뢰할 만해지는지 판단하는 데 그대로 쓰인다.

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

← 36. 로그수익률·변동성(σ)38. 랜덤워크/GBM(개념) →