← Playground← 놀이터

PRISM · Machine Learning PlaygroundPRISM · 머신러닝 놀이터

MCMC · Metropolis–HastingsMCMC · 메트로폴리스–헤이스팅스
Sample a distribution you can't integrate, with a guided random walk적분할 수 없는 분포를, 안내된 무작위 걸음으로 표집한다

Often you can compute a distribution's density up to a constant but can't integrate it — so you can't sample directly. Metropolis–Hastings builds a random walk that visits each region in proportion to its probability: propose a nearby move, then accept it with probability min(1, p(x′)/p(x)) — always step uphill, sometimes step down. Over time the walker's footprints are the distribution. Watch the samples fill it in.흔히 분포의 밀도를 상수배까지는 계산할 수 있지만 적분은 못 해 — 직접 표집할 수 없다. 메트로폴리스–헤이스팅스는 각 영역을 그 확률에 비례해 방문하는 무작위 걸음을 만든다: 가까운 이동을 제안하고, 확률 min(1, p(x′)/p(x))수락한다 — 언제나 오르막으로, 때로는 내리막으로. 시간이 지나면 걸음꾼의 발자국이 곧 분포다. 표본이 채워지는 것을 보라.

The chain & its samples체인과 그 표본 x′ = x + σ·z
target density목표 밀도 accepted samples수락된 표본 current walker현재 걸음꾼
Marginal — samples vs truth주변분포 — 표본 vs 진실 x-coordinatex좌표
x = −2.20x = +2.2
Controls제어판

Target distribution목표 분포

Proposal step σ제안 스텝 σ jump size도약 크기0.35
Watch the acceptance rate: aim near ~25–50% for good mixing.수락률을 보세요: 좋은 혼합을 위해 ~25–50% 근처를 목표로.
Measurements측정값
acceptance rate수락률
samples표본 수
proposals제안 수
step σ스텝 σ
Things to try해볼 것들
  1. Step too small: drop σ low — nearly every move is accepted, but the walker crawls and mixes slowly.스텝이 너무 작으면: σ를 낮추면 거의 모든 이동이 수락되지만, 걸음꾼이 기어가며 느리게 섞인다.
  2. Step too big: raise σ high — most proposals land in low probability and get rejected, so the chain gets stuck.스텝이 너무 크면: σ를 높이면 대부분의 제안이 낮은 확률에 떨어져 기각되고, 체인이 멈춘다.
  3. Crossing modes: with Two modes, a tiny step traps the walker in one mode — bigger jumps are needed to hop between them.봉우리 넘기: 두 봉우리에서 작은 스텝은 걸음꾼을 한 봉우리에 가둔다 — 사이를 넘으려면 더 큰 도약이 필요하다.
  4. Hard geometry: the Banana shows why curved targets are tough — a single step size can't fit both the narrow and wide directions.어려운 기하: 바나나는 휜 목표가 왜 어려운지 보여준다 — 하나의 스텝 크기로는 좁은 방향과 넓은 방향을 모두 맞출 수 없다.

Detailed balance상세 균형

The accept rule min(1, p(x′)/p(x)) is chosen so the chain satisfies detailed balance with the target as its stationary distribution. Only the ratio appears, so the unknown normalizing constant cancels — that's why you can sample without ever computing it.수락 규칙 min(1, p(x′)/p(x))은 체인이 목표를 정상분포로 하는 상세 균형을 만족하도록 선택된다. 비율만 나타나므로 미지의 정규화 상수가 소거된다 — 그래서 그것을 계산하지 않고도 표집할 수 있다.

Mixing & the sweet spot혼합과 최적점

Tiny steps are almost always accepted but explore slowly; huge steps are almost always rejected. The useful regime is in between — theory suggests an acceptance rate around 0.23 for high-dimensional targets. This is the exploration–exploitation tradeoff of sampling.작은 스텝은 거의 항상 수락되지만 탐색이 느리고, 큰 스텝은 거의 항상 기각된다. 유용한 영역은 그 사이다 — 이론은 고차원 목표에서 수락률 0.23 근처를 제안한다. 표집의 탐험–활용 절충이다.

Where it's used쓰이는 곳

MCMC is how Bayesian inference is done in practice — drawing from posteriors over model parameters when they have no closed form. In biomedicine it powers uncertainty-aware modeling of clinical data, pharmacokinetics, and phylogenetics, wherever you need the full posterior, not just a point estimate.MCMC는 실전에서 베이지안 추론을 수행하는 방법이다 — 닫힌 형태가 없는 모델 매개변수의 사후분포에서 표집한다. 생의학에서는 임상 데이터의 불확실성 인식 모델링, 약동학, 계통발생학 등 점 추정이 아니라 완전한 사후분포가 필요한 곳을 뒷받침한다.