Second Drafts
  • Home
  • Class Notes
  • (Math) Blog
  • Interactive Apps
  • CV

Metropolis-Hastings Algorithm

mcmc
statistics
algorithms
Visualize the Metropolis-Hastings algorithm, a Markov Chain Monte Carlo method for sampling from probability distributions.
Published

January 3, 2025

← Return to Apps

Loading Python environment...

This may take a few seconds on first load.

2.0
20

Statistics

Acceptance Rate
-
Accepted / Total
-
Effective Sample Size
-
Sample Mean
-
Sample Std Dev
-

About This App

The Metropolis-Hastings algorithm is a Markov Chain Monte Carlo (MCMC) method for obtaining a sequence of random samples from a probability distribution for which direct sampling is difficult.

How It Works

The algorithm generates samples by constructing a Markov chain that has the desired distribution as its equilibrium distribution. At each step:

  1. Propose a new state \(x'\) from the current state \(x\) using a proposal distribution \(q(x' | x)\)
  2. Calculate the acceptance ratio: \[\alpha = \min\left(1, \frac{p(x') q(x|x')}{p(x) q(x'|x)}\right)\]
  3. Accept the new state with probability \(\alpha\), otherwise stay at the current state

Where \(p(x)\) is the target probability distribution we want to sample from.

This simple procedure allows us to sample from complex, high-dimensional distributions that would be intractable to sample from directly - making it a cornerstone of modern Bayesian statistics and computational physics.

Back to top
 

Copyright 2025, Apurva Nakade