"매 random variable 의 spread 의 algebra — Var(aX + b) = a²Var(X), 매 independence 매 sum 의 add". 1853 Bienaymé 의 sum-of-independent identity 부터 매 modern propagation-of-uncertainty, finance VaR, ML loss decomposition 까지 — 매 variance algebra 의 매 day-1 statistics 의 still 매 most-used identity.
defwelford_variance(stream):n=0;mean=0.0;M2=0.0forxinstream:n+=1delta=x-meanmean+=delta/nM2+=delta*(x-mean)# 매 use updated meanreturnmean,M2/(n-1)ifn>1elsefloat('nan')
importnumpyasnprng=np.random.default_rng(0)N=1_000_000X=rng.integers(0,3,size=N)# 매 latent classmu_y=np.array([0.0,1.0,5.0])[X]Y=rng.normal(mu_y,scale=1.0)total=Y.var()inner=np.array([Y[X==k].var()forkinrange(3)]).mean()outer=np.array([Y[X==k].mean()forkinrange(3)]).var()print(total,inner+outer)# 매 ≈ equal
Bias-variance decomposition (ML)
defbias_variance(predictions,y_true):# predictions: (n_models, n_samples)mean_pred=predictions.mean(axis=0)bias_sq=((mean_pred-y_true)**2).mean()var=predictions.var(axis=0).mean()noise_lb=0.0# 매 estimable 의 의 separatelyreturnbias_sq,var,noise_lb
Welch's t-test variance handling
fromscipyimportstatst,p=stats.ttest_ind(a,b,equal_var=False)# Welch# 매 unequal variance — Satterthwaite degrees of freedom
매 결정 기준
상황
Approach
Streaming variance
Welford (numerically stable)
Independent sum
Bienaymé — sum the variances
Correlated sum
Full covariance — w^\top \Sigma w
Nonlinear function g(X)
Delta method (1st-order) — or Monte Carlo
Hierarchical / mixture
Law of total variance 의 decompose
ML overfitting diagnose
Bias-variance decomposition
Sample variance
Bessel correction (n-1)
기본값: independence 의 confirm 후 Bienaymé. Doubt — Monte Carlo 의 verify.
🔗 Graph
부모: Probability Theory
응용: Bias-Variance Tradeoff
🤖 LLM 활용
언제: identity recall, derivation hint, code skeleton (Welford, delta).
언제 X: 매 specific paper 의 closed-form — derivation 의 cross-check.
❌ 안티패턴
Bienaymé 의 correlated variable 의 apply: 매 covariance 의 forget — biased toward zero variance.
Two-pass naive variance (\sum x_i^2 - (\sum x_i)^2/n): 매 catastrophic cancellation — Welford 의 use.
Sample variance with $n$: 매 biased — Bessel (n-1).
Affine 매 b 의 add to variance: 매 b 의 drop, only a^2 matters.
Delta method 의 high curvature 의 use: 매 1st-order — large \sigma 의 의 break, 의 Monte Carlo.