Files
2nd/10_Wiki/Topics/Computer_Science_and_Theory/Monte-Carlo-Integration.md
T
koriweb d8a80f6272 chore(wiki): dangling 링크 canonical 정규화 (768파일/1200건)
이름만 다른(표기 변형) [[위키링크]]를 대상 문서의 canonical 제목으로 치환해
끊겼던 1,200개 링크를 연결. 제목/파일명 정규화 일치만 적용하고 별칭 매칭은
과병합 위험으로 제외(애매성 가드). 원본은 _link_reconcile_backup/ 에 백업.
도구: Datacollect/scripts/link_reconcile_apply.mjs

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-08 12:24:15 +09:00

3.9 KiB
Raw Blame History

id, title, category, status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, verification_status, tags, raw_sources, last_reinforced, github_commit, tech_stack
id title category status canonical_id aliases duplicate_of source_trust_level confidence_score verification_status tags raw_sources last_reinforced github_commit tech_stack
wiki-2026-0508-monte-carlo-integration Monte Carlo Integration 10_Wiki/Topics verified self
Monte-Carlo-Integration
MC-Integration
몬테카를로-적분
none A 0.95 applied
numerical
integration
sampling
statistics
simulation
2026-05-10 pending
language framework
python numpy-jax

Monte Carlo Integration

매 한 줄

"매 무작위 샘플의 평균이 적분값으로 수렴". ∫f dμ ≈ (1/N)Σf(xᵢ), error O(N⁻¹/²) — 매 dimension에 무관한 게 매 핵심 강점이다. 1949 Metropolis-Ulam에서 Manhattan Project 이후, 2026 LLM 시대에도 매 RLHF reward estimation·diffusion sampling의 backbone.

매 핵심

매 estimator

  • Standard MC: x ~ p, Î = (1/N)Σf(xᵢ); Var = σ²/N.
  • Importance sampling: x ~ q, Î = (1/N)Σf(xᵢ)p(xᵢ)/q(xᵢ).
  • Control variates: f → f c(g E[g]); 매 variance ↓.
  • Stratified: 매 domain partition.
  • Quasi-MC: Sobol/Halton — error O(N⁻¹ logᵈ N).

매 수렴

  • Error std ~ σ/√N (CLT).
  • 매 dim 무관 — high-dim integration의 매 유일한 실용 도구.

매 응용

  1. Bayesian inference — posterior expectation (MCMC).
  2. Computer graphics — path tracing, light transport.
  3. Finance — option pricing (Black-Scholes path).
  4. RLHF — reward expectation.
  5. Diffusion model — score-matching expectation.

💻 패턴

Basic MC integral

import numpy as np
def mc_integrate(f, low, high, n=10000):
    x = np.random.uniform(low, high, n)
    return (high - low) * f(x).mean(), (high - low) * f(x).std() / np.sqrt(n)

Importance sampling

def importance_mc(f, sampler_q, log_p, log_q, n=10000):
    x = sampler_q(n)
    w = np.exp(log_p(x) - log_q(x))
    return (f(x) * w).mean()

Control variates

def cv_mc(f, g, Eg, n=10000):
    x = np.random.uniform(0, 1, n)
    fx, gx = f(x), g(x)
    c = -np.cov(fx, gx)[0, 1] / np.var(gx)
    return (fx + c * (gx - Eg)).mean()

Quasi-MC with Sobol

from scipy.stats.qmc import Sobol
sampler = Sobol(d=5, scramble=True)
points = sampler.random_base2(m=14)  # 2^14 points
estimate = f(points).mean()

MCMC (Metropolis-Hastings)

def mh(log_pi, x0, n=10000, sigma=0.5):
    x, samples = x0, [x0]
    for _ in range(n):
        x_prop = x + sigma * np.random.randn(*x.shape)
        if np.log(np.random.rand()) < log_pi(x_prop) - log_pi(x):
            x = x_prop
        samples.append(x)
    return np.array(samples)

JAX vectorized MC

import jax, jax.numpy as jnp
@jax.jit
def mc(key, n):
    x = jax.random.uniform(key, (n,))
    return jnp.mean(jnp.exp(-x**2))

매 결정 기준

상황 Method
Smooth low-dim Quadrature or QMC
High-dim Vanilla MC
Heavy tail / rare event Importance sampling
Posterior MCMC (NUTS, HMC)
Light transport Path tracing + MIS

기본값: Vanilla MC + control variates (low complexity, low variance).

🔗 Graph

🤖 LLM 활용

언제: High-dim integration, expectation under intractable distribution, simulation. 언제 X: 1-3 dim smooth functions (use Gauss quadrature).

안티패턴

  • Variance 무시: 매 std error 안 보고 estimate 제출.
  • Bad importance proposal: 매 q tail이 p보다 얇으면 explosion.
  • Correlated samples: MCMC autocorrelation 무시 → 매 ESS 부풀려짐.

🧪 검증 / 중복

  • Verified (Robert & Casella "Monte Carlo Statistical Methods").
  • 신뢰도 A.

🕓 Changelog

날짜 변경
2026-05-08 Phase 1
2026-05-10 Manual cleanup — MC variants + JAX/MCMC patterns