The Metropolis Algorithm#
The Metropolis algorithm provides an elegant solution to this sampling problems. Rather than trying to calculate absolute probabilities, it works with probability ratios:
Starting from a configuration
Propose a random move to configuration
.Calculate the energy change
.Accept the move with probability:
This acceptance criterion ensures:
Moves that lower energy (
) are always accepted.Moves that raise energy are accepted with probability
The partition function
cancels out in the ratio
Accepting Moves with Probability p#
The Metropolis criterion tells us to accept or reject each proposed move according to the following rules:
If
, we always accept the move.If
, accept the move with a probability .
Accepting Moves with Probability p#
What exactly does it mean to accept a move “with probability
In Metropolis Monte Carlo, the probability comes from the Boltzmann factor
To turn these probabilities into decisions, we use a random number generator. The strategy is straightforward: generate a random number
Take our coin flip example where
is_heads = np.random.rand() <= 0.5
The Metropolis algorithm uses the same logic. For a move that increases energy by
Calculate
Generate a random number
between 0 and 1Accept the move if
Here’s what this looks like for a move where
p = np.exp(-delta_E/kT) # ≈ 0.135
accept = np.random.rand() <= p
In this case, there is about a 13.5% chance of accepting the move. Larger energy increases mean lower acceptance probabilities — the move becomes less likely but remains possible. This mechanism lets our system occasionally climb uphill in energy while generally favoring lower energy states.
This simple accept/reject rule, guided by physically motivated probabilities, lets us efficiently explore possible states while maintaining the correct Boltzmann distribution.