Metropolis Algorithm
In this lesson, we will learn about the Metropolis Algorithm, and its implementation.
We'll cover the following...
In the previous lesson, we implemented a technique for sampling from a non-normalized target PDF:
- Find an everywhere-larger helper PDF that we can sample from.
- Sample from it.
- Accept or reject the sample via a coin flip with the ratio of weights in the target distribution and the helper distribution.
This technique works, but it has a few drawbacks:
- It’s not at all clear how to find a suitable helper PDF without humans intervening.
- Even with a pretty tight-fitting helper, you potentially still end up rejecting a lot of samples.
The first problem is the big one. It would be great if there were a technique that didn’t require quite so much intervention from experts.
In this lesson, we’ll describe just such a technique; it is called the “Metropolis algorithm” after one of its inventors, Nicholas Metropolis.
Introduction to the Metropolis Algorithm
The co-authors of the 1953 paper that first presented this algorithm are unfairly not credited in the name of the algorithm, but “the Metropolis algorithm” sounds snappy and cool, whereas “the Metropolis-Rosenbluth-Rosenbluth-Teller-and-Teller algorithm” is a bit of a mouthful.
In modern code, we usually use a variation called the “Metropolis-Hastings algorithm”, but we are not going to discuss it in this course.
Pseudocode of the Metropolis Algorithm
Without further ado, here’s a sketch of the Metropolis algorithm:
- We have a non-normalized PDF
f(t)
that takes aT
and returns a double. We want to produce arbitrarily many samples ofT
that conform to this distribution. - The first time that
Sample()
is called, we produce the initial sample. - Now, if we could produce an initial random sample that matched the distribution described by , we’d already have solved the problem! All that we require is an initial random sample that is somewhere in support of