Spaces:
Running
Running
metadata
title: MCMC Dashboard
emoji: ๐
colorFrom: indigo
colorTo: blue
sdk: static
pinned: false
short_description: Interactive Metropolis-Hastings sampling visualization
๐ MCMC Dashboard
An interactive visualization of Metropolis-Hastings MCMC sampling from a 2D correlated Gaussian distribution. Watch the Markov chain explore probability space in real-time.
๐ฎ How to Use
Visualizations
| Panel | Description |
|---|---|
| 2D Landscape | Main view showing the target distribution (cyan cloud) and walker trajectory |
| Trace Plot | X-coordinate over time with running mean (yellow line) |
| Histogram | Marginal distribution of X samples vs. ideal Normal (dashed) |
Controls
| Parameter | Effect |
|---|---|
| Target Correlation | Covariance between X and Y (-0.95 to 0.95). Higher = more elongated ellipse |
| Proposal Width | Standard deviation of the proposal distribution. Too small = slow mixing, too large = high rejection |
| Speed | Steps per animation frame (1-50) |
Diagnostics
- Steps: Total MCMC iterations
- Acceptance: Percentage of proposals accepted (ideal: 20-50%)
- Running Mean: Cumulative average of X samples (should โ 0)
- ESS: Effective Sample Size - accounts for autocorrelation
- AutoCorr: Lag-1 autocorrelation (lower = better mixing)
๐ฌ The Algorithm
The Metropolis-Hastings algorithm samples from a target distribution ฯ(x):
- Propose: x* ~ N(x_current, ฯยฒ)
- Accept ratio: ฮฑ = ฯ(x*) / ฯ(x_current)
- Accept/Reject:
- If ฮฑ โฅ 1: Always accept
- If ฮฑ < 1: Accept with probability ฮฑ
Target Distribution
The target is a bivariate Gaussian with covariance:
ฮฃ = [[1, ฯ], [ฯ, 1]]
where ฯ is the correlation parameter.
๐ Key Insights
Proposal Width Tuning
- Too narrow: Walker takes tiny steps โ high acceptance but slow exploration
- Too wide: Walker proposes jumps too far โ high rejection rate
- Optimal: ~23% acceptance rate for Gaussian targets (Roberts et al., 1997)
Correlation Effects
- High |ฯ|: Creates elongated "banana-like" region โ harder to sample efficiently
- Low |ฯ|: Near-circular distribution โ easier for isotropic proposals
Effective Sample Size (ESS)
ESS estimates how many independent samples the chain represents:
ESS โ N ร (1 - ฯโ) / (1 + ฯโ)
where ฯโ is lag-1 autocorrelation. Green = good (>200), Red = needs more samples.
๐งช Experiments to Try
- Slow mixing: Set correlation to 0.95, proposal width to 0.3. Watch the walker struggle.
- Over-rejection: Set proposal width to 4.0. See acceptance rate plummet.
- Sweet spot: Set correlation to 0.5, width to 1.0. Observe healthy mixing.
Interactive demonstration of Bayesian computation fundamentals