Hello! Bonjour! Xin Chào! Shimboni!
Welcome to the first week of Statistical Mechanics: Algorithms and computations
from the physics department of Ecole Normale Supérieure.
This week, as any week, there will be a lecture,
a tutorial, and a homework session.
This week's lecture, Lecture 1, will be devoted to an introduction to Monte Carlo algorithms.
The main setting will be in Monaco; more precisely, in Monte Carlo.
We will watch children play in the sand
and adults play on the Monte Carlo Heliport.
They will teach us a crucial lesson about sampling.
This week's tutorial, Tutorial 1, will analyze Monte Carlo algorithms and their convergence.
We will derive a crucial theorem about the convergence of Monte Carlo algorithms
using this 3x3 pebble game.
Finally, this week's homework session, Homework Session 1,
will be all about practical computing.
We will download, take apart, and put back together simple Python programs.
We will, so-to-speak, get out hands dirty,
and we will learn about a crucial rule of thumb,
the famous one half rule.
that will teach us how to choose the parameters of our Monte Carlo computations.
The material of week 1, this week, is roughly on the level of the entire course,
so if you are able to follow Lecture 1, Tutorial 1, and Homework Session 1,
you will be well set to follow the entire course.
So, let's get started, with Statistical Mechanics: Algorithms and Computations.
The first instance of sampling is called direct sampling
Direct sampling is illustrated by this amusing game
that children (if you believe it) play on the Monte Carlo beaches, on free afternoons.
In the sand, they draw a square and a circle. They then throw pebbles..
..randomly into the square.
Each pebble inside the square is counted as a trial,
and each pebble inside the circle counts as a hit.
In fact, the children on the Monte Carlo beach do a direct sampling Monte Carlo simulation.
They compute the number pi from the ratio of the area of the circle to the area of the square.
This ratio is equal to pi/4,
so, the children can compute the number pi by throwing pebbles.
As an example, suppose that in a game of 4000 pebble trials they obtain 3156 hits,
they obtain the approximation pi~3.156 from this calculation.
In the limit of an infinitely long beach party, of an infinite number of pebbles,
the exact value of pi will indeed be computed.
In Python, this gives the following program
its key element are the two random numbers random.uniform,
they give a random position in x between -1 and 1, and a random position in y between -1 and 1,
in total, a random pebble position inside the square.
So, here again is the children's game in Python, in a version which allows us to do many runs,
one afternoon of 4000 pebbles, followed by another afternoon of 4000 pebbles, and so on and so on..
Output of this program is shown here.
Before moving on, please take a moment to download, run and modify some programs.
On the Coursera website, you will find the program direct_pi.py, that allows you to do one game of the children's play.
You will also find the program direct_pi_multirun.py,
that allows you to do many runs of the children's game,
or, if you like, many afternoons on the sunny Monte Carlo beach. that allows you to do many runs of the children's game,
or, if you like, many afternoons on the sunny Monte Carlo beach.
In Monte Carlo, it is not only children who play at pebble games,
adults also play at their version of pebble game on the local heliport.
After storing away all the helicopters, they wander around the square-shaped landing pad,
that looks just like the children's game, only larger.
No one can throw a pebble randomly into such a big field, so the algorithm must be modified.
We start in the upper right corner, our handbag filled with pebbles,
with closed eyes, we throw the pebble in a random direction,
we then walk to the point at which the pebble has landed,
pull out a new pebble, and a new throw will follow.
The aim of the game - as before - is to sweep out evenly the heliport square.
This algorithm will work, but what should we do when we throw a pebble outside of the square?
Should we continue inside the square, as if nothing has happened?
Or should we climb over the fence of the heliport,
and continue outside of the square until eventually we will come back? Or should we climb over the fence of the heliport,
and continue outside of the square until eventually we will come back?
We should ask somebody to bring us the outfielder, and place it on top of the pebble already present,
then we should pull out a new pebble and do a new throw.
If this is again an outfielder, we should again have it brought and place it on top of the pile.
Eventually we will move on, visit other areas of the heliport, and also come close to the center,
where there are no rejections.
At the end of the game, the heliport looks as follows
In the center of the pad, there are only single stones, because from the center there are no outfielders, no rejections.
Close to the boundaries, and especially close to the corners, there are piles, corresponding to rejected moves.
This is quite mind-boggling for us today, and it was even more so in 1953, when this famous Metropolis algorithm was invented.
Before studying why this program is correct, please take a moment to download, run and modify the relevant programs.
On the Coursera website you will find the program markov_pi.py, that allows you to run one party on the Monte Carlo heliport.
The key element of this program is as follows. At position x and y, you move by little random displacement delta_x and delta_y that can be positive or negative.
When the move is rejected, you simply remain where you are, that means, you build a little pile.
On the website, you also find the program markov_pi_multirun.py,
that allows you to simulate many heliport parties. Output of this program is shown here.
You see that although the strategy of piling up pebbles seems a bit strange, the output comes out just right.
We left the Monte Carlo heliport a few moments ago, without clarifying the reason for this pile-up of pebbles, especially near the boundaries.
Remember, we want to spread out the pebbles evenly on the heliport square,
so the strategy of making piles appears very strange indeed. Remember, we want to spread out the pebbles evenly on the heliport square
so the strategy of making piles appears very strange indeed.
to understand why this strategy is ok, let us simplify the game even further
and consider this 3x3 pebble game shown here
the pebbles can move in at most four directions: left, up, right and down
these moves are in the same spirit as those of the heliport
in the configuration a, we can only move to the left or down, to configurations b and c
we can write this into a little equation
in this equation, p(a->b) is the algorithmic transition probability from a to b, etc.
Now, we consider that we have run this program for a long time.
in fact, we suppose that we have reached a steady state.
The probability pi_a to be at configuration a is then given by the probability to be at a and to remain on that site,
plus the probability pi_b to be at configuration b times the probability to move from b to a,
plus the probability pi_c to be at configuration c and to make a transition from c to a
Putting these two equations together, we find..
this equation is the celebrated global balance condition
our Monte Carlo algorithm, which is nothing else but the set of transition probabilities from one site to another, must satisfy it
there are many algorithms, even on the 3x3 pebble game, that satisfy the global balance condition
one way of satisfying the global balance condition consists in equating the pieces involving a and b separately, and also the pieces involving a and c
this is the detailed balance condition, and it is really famous. What does the detailed balance condition mean?
in our 3x3 pebble game, we want to sweep out evenly all the configurations
we want to have pi_a equals to pi_b equals to pi_c, and so on
this implies that we need to have probabilities p(a->b) equal to p(b->a), and p(a->c) equal to p(c->a)
How can we implement this? Well, very simply. By moving from any configuration with probability 1/4 to the right, up ,to the left and down.
All the allowed moves have probability 1/4. This is a simple solution and it involves rejections.
If we are at configuration a, we reject the moves to the right and up. We have a probability of 1/2 of staying at site a.
the probability to move from a to b or from a to c remains 1/4
on configuration b, we have a rejection probability of 1/4
and on configuration c we also have a rejection probability of 1/4
this is the essence of the celebrated Metropolis algorithm, and we will discuss it again in the same setting in Tutorial 1 of Statistical Mechanics, Algorithms and Computations
We have just been able to devise what is called a Markov chain Monte Carlo algorithm for the case where we sweep out all configurations evenly.
before treating the case of general probabilities pi_a, let us ask a few questions
let us suppose that in the 3x3 pebble game, we are in upper right corner at time t=0
we throw a die of the four possible moves to the right, up, to the left, down
we sample the move to the left, where should we move to?
yes, clearly we should move to left. At t=1, the configuration will be as follows
Question 2: at t=1, with the pebble in the upper middle position, we again roll a die (right, up, left, down). We sample the up move, what should we do?
Yes, clearly, we should stay where we are. At time t=2, we are again in the upper middle configuration.
Note that we count this configuration a second time, that we build a pile, so to speak.
Question 3: now, at time t=2, in the upper middle configuration, we again sample a move, we sample the down move. What should we do?
Clearly, we should move down. At time t=3 we are in the center of the square.
Question 4, final question: at time t=3, in the central configuration what will be the rejection probability of the next move?
Yes, clearly, it will be zero. Each of the four moves will be proposed with probability 1/4 and it will be accepted.
Finally, let us consider what we call the inhomogeneous 3x3 pebble game.
The numbers indicate the statistical weights of the configurations.
and the pebble should be twice as often on the upper right corner than on the site in the middle on the top row.
and four times as often on the upper left corner than on the site just below it.
To devise a Markov chain Monte Carlo algorithm for the inhomogeneous pebble game, we must visit again the detailed balance condition
where probabilities pi_a and pi_b are the numbers written up here.
we would now violate the detailed balance condition if we move with the same probability from site a to site b as from site b to site a
Metropolis et al., in 1953, proposed their famous Metropolis acceptance probability to handle the case when the probabilities pi_a on the sites are no longer constant.
they proposed the rule shown here
In this rule either the transition probability p(a->b) or the transition probability p(b->a) is equal to one.
an in both cases, the detailed balance condition is ok
Let us illustrate this most important Metropolis acceptance probability in the pebble game.
Suppose we are in the upper right corner, and we want to move to the left. This move will be proposed with probability 1/4.
we should accept this move with the probability minimum(1, 0.5/1), which is equal to 1/2.
so we should accept this move from the corner to the middle with a probability 1/2, otherwise we should stay where we are.
Likewise, suppose we are in the center-left configuration and we want to move down
the move then will be proposed with probability 1/4 again
we should accept this move with a probability minimum(1, 3/0.5), which is equal to minimum(1,6) which is equal to 1
that is, we should accept this move with probability one
the 3x3 pebble game algorithms can be found on the Coursera website
the homogeneous 3x3 pebble game will be scrutinized in Tutorial 1 under the name of pebble_basic.py
the inhomogeneous pebble game that we just discussed can be found under the name of pebble_basic_inhomogeneous.py
you will see how in that algorithm the propose probability of 1/4 is modified by the Metropolis acceptance probability
of minimum of 1 and probability pi of the site that you want to go to, divided by probability pi of the site where you are at
you are invited to download, run and modify all these programs.
In conclusion, we have plunged in this lecture 1 of Statistical Mechanics: Algorithms and Computations, into the field of Monte Carlo algorithms
the key concept is sampling, obtaining the pebble positions.
we have studied two basic approaches to sampling: direct sampling in the children's algorithm and Markov chain sampling in the adults game on the heliport.
to understand Markov chain sampling, we took to a discretized version of the heliport, namely the 3x3 pebble game
in its homogeneous version and inhomogeneous version, that was governed by the Metropolis acceptance probability
it remains to thank you for your attention.
See you again in further sessions of Statistical Mechanics: Algorithms and Computations, where the concepts introduced today will be considerably deepened.