mcmc-dashboard / README.md
Vikingdude81's picture
Upload README.md with huggingface_hub
225e892 verified
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):

  1. Propose: x* ~ N(x_current, ฯƒยฒ)
  2. Accept ratio: ฮฑ = ฯ€(x*) / ฯ€(x_current)
  3. 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

  1. Slow mixing: Set correlation to 0.95, proposal width to 0.3. Watch the walker struggle.
  2. Over-rejection: Set proposal width to 4.0. See acceptance rate plummet.
  3. Sweet spot: Set correlation to 0.5, width to 1.0. Observe healthy mixing.

Interactive demonstration of Bayesian computation fundamentals