1. Home
  2. Explore
  3. Physics
  4. Monte Carlo Sampling

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Monte Carlo Sampling

Monte Carlo Simulation in Statistical Mechanics

The Core Idea: Sampling Phase Space

In contrast to molecular dynamics (MD) — where the system follows a deterministic trajectory through phase space — Monte Carlo (MC) simulation directly samples points in phase space according to a target probability density. The key insight is that the probability density approaches a stationary solution (the equilibrium distribution). By sampling phase space according to this density, equilibrium properties can be computed without following time evolution.

This approach is fundamentally a method of integration, not a simulation technique in the traditional sense. Even when calculating thermodynamic properties, those properties derive from integrals over phase space (like the partition function). Monte Carlo evaluates those integrals. The method is purely mathematical and can be applied far beyond thermodynamics to any integration problem.


The Mathematical Problem: The Canonical Ensemble

In the canonical ensemble (NVT), the partition function is:

Z=∑statese−βEjZ = \sum_{\text{states}} e^{-\beta E_j}Z=∑states​e−βEj​

where β=1/kBT\beta = 1 / k_B Tβ=1/kB​T.

In classical mechanics, the phase space of NNN particles is continuous (with 3N3N3N position coordinates qqq and 3N3N3N momentum coordinates ppp). The Hamiltonian H(q,p)H(q,p)H(q,p) is a continuous function, and the sum becomes an integral:

Z=∫dq∫dp  e−H(q,p)/kBTZ = \int dq \int dp \; e^{-H(q,p)/k_B T}Z=∫dq∫dpe−H(q,p)/kB​T

This is a 6N6N6N-dimensional integral. For N∼1023N \sim 10^{23}N∼1023, the dimensionality is astronomical.

Monte Carlo simulation is a statistical method to evaluate high-dimensional integrals by random sampling, focusing computational effort on regions where the integrand is large.


The Impossibility of Traditional Quadrature

A naive approach would be to discretize each variable into MMM grid points and use a quadrature rule (trapezoidal, Simpson's, Gaussian quadrature). For a 1D integral:

∫qaqbf(q)dq≈Δq[12f(qa)+12f(qb)+∑kf(qk)]\int_{q_a}^{q_b} f(q) dq \approx \Delta q \left[ \frac{1}{2}f(q_a) + \frac{1}{2}f(q_b) + \sum_{k} f(q_k) \right]∫qa​qb​​f(q)dq≈Δq[21​f(qa​)+21​f(qb​)+∑k​f(qk​)]

For 2 variables, an M×MM \times MM×M grid is needed. For 6N6N6N variables, the total number of grid points is:

M6NM^{6N}M6N

Even with N=100N = 100N=100 (a tiny system), M6NM^{6N}M6N is astronomically large — impossible on any computer. Additionally, the integrand e−H/kBTe^{-H/k_B T}e−H/kB​T is vanishingly small for most phase-space points (where HHH is large). Wasting computational effort on such points makes quadrature doubly impractical.


Monte Carlo Integration: A Simple Example — Computing π\piπ

The classic demonstration of Monte Carlo integration is computing π\piπ by estimating the area of a unit circle (area=π\text{area} = \piarea=π).

The Setup

Consider a unit circle x2+y2=1x^2 + y^2 = 1x2+y2=1. The area of the quadrant in the first quadrant is:

π4=∫011−x2 dx\frac{\pi}{4} = \int_0^1 \sqrt{1 - x^2} \, dx4π​=∫01​1−x2​dx

Instead of evaluating this integral directly, construct a unit square (0≤x≤10 \le x \le 10≤x≤1, 0≤y≤10 \le y \le 10≤y≤1) that encloses the quadrant.

The Method

  1. Generate random points (x,y)(x,y)(x,y) uniformly within the unit square.

  2. Count how many points satisfy x2+y2≤1x^2 + y^2 \le 1x2+y2≤1 (inside the quadrant).

  3. The ratio of points inside the quadrant to total points approximates the area of the quadrant divided by the area of the square (which is 1):

points insidetotal points≈area of quadrantarea of square=π4\frac{\text{points inside}}{\text{total points}} \approx \frac{\text{area of quadrant}}{\text{area of square}} = \frac{\pi}{4}total pointspoints inside​≈area of squarearea of quadrant​=4π​
  1. Hence:

π≈4×points insidetotal points\pi \approx 4 \times \frac{\text{points inside}}{\text{total points}}π≈4×total pointspoints inside​

Why It Works

This is a numerical experiment akin to throwing darts at a dartboard. The probability of hitting inside a region is proportional to the region's area (when the dartboard is uniformly random). With enough points, the ratio converges to the true area ratio.

Accuracy

  • With 10 points: rough estimate (~3.0)

  • With 100 points: first decimal (~3.1)

  • With 1,000 points: two decimals (~3.14)

  • With 10610^6106 points: three to four decimals correct

The error decreases as 1/N1/\sqrt{N}1/N​, independent of dimensionality. This is the key advantage of Monte Carlo over quadrature for high dimensions.


Random Sampling vs. Importance Sampling

Random (Uniform) Sampling

In the simple π\piπ example, points are generated uniformly over the integration domain. This is the most basic form of Monte Carlo integration. For an integral:

I=∫abf(x)dxI = \int_a^b f(x) dxI=∫ab​f(x)dx

Generate NNN random points xix_ixi​ uniformly in [a,b][a,b][a,b]. The estimator is:

I≈(b−a)⋅1N∑i=1Nf(xi)I \approx (b-a) \cdot \frac{1}{N} \sum_{i=1}^N f(x_i)I≈(b−a)⋅N1​∑i=1N​f(xi​)

But this is inefficient when f(x)f(x)f(x) is sharply peaked or has large regions where it is nearly zero — as in the Boltzmann factor e−H/kBTe^{-H/k_B T}e−H/kB​T over phase space.

Importance Sampling

The central idea: focus sampling where the integrand is large. Rewrite the integral as:

I=∫abf(x)dx=∫abf(x)ρ(x) ρ(x)dxI = \int_a^b f(x) dx = \int_a^b \frac{f(x)}{\rho(x)} \, \rho(x) dxI=∫ab​f(x)dx=∫ab​ρ(x)f(x)​ρ(x)dx

where ρ(x)≥0\rho(x) \ge 0ρ(x)≥0 is a probability density from which points are drawn (not uniformly). The estimator becomes:

I≈1N∑i=1Nf(xi)ρ(xi)I \approx \frac{1}{N} \sum_{i=1}^N \frac{f(x_i)}{\rho(x_i)}I≈N1​∑i=1N​ρ(xi​)f(xi​)​

Here, xix_ixi​ are sampled from ρ(x)\rho(x)ρ(x).

  • If ρ(x)\rho(x)ρ(x) is proportional to f(x)f(x)f(x), the ratio f(x)/ρ(x)f(x)/\rho(x)f(x)/ρ(x) is nearly constant — low variance, high efficiency.

  • Regions where f(x)f(x)f(x) is small are sampled rarely (small ρ\rhoρ), saving effort.

  • Regions where f(x)f(x)f(x) is large are sampled frequently (large ρ\rhoρ), ensuring accuracy.

Importance sampling makes Monte Carlo an intelligent exploration method for phase space. Without it, random sampling would fail for thermodynamic systems because the Boltzmann factor is negligible over most of phase space.

Application to Thermodynamics

For the canonical partition function integral:

Z=∫dq∫dp  e−H(q,p)/kBTZ = \int dq \int dp \; e^{-H(q,p)/k_B T}Z=∫dq∫dpe−H(q,p)/kB​T

The integrand e−H/kBTe^{-H/k_B T}e−H/kB​T is sharply peaked around low-energy configurations (due to the exponential). Importance sampling means generating configurations with probability ∝e−H/kBT\propto e^{-H/k_B T}∝e−H/kB​T — the Boltzmann distribution itself. This ensures that most sampled points significantly contribute to the integral.

How to generate such configurations? Through a Markov chain — propose moves (changes in coordinates) and accept/reject them using a criterion that maintains detailed balance (e.g., the Metropolis algorithm). This is the core of practical Monte Carlo simulations in statistical mechanics.


Key Takeaways

  • Monte Carlo is a method of integration, not a dynamic simulation. It is especially suited for high-dimensional integrals where quadrature fails.

  • The curse of dimensionality makes traditional grid-based integration impossible for systems with many particles — Monte Carlo avoids this by scaling as 1/N1/\sqrt{N}1/N​ regardless of dimension.

  • Random sampling is the simplest form but wastes effort where the integrand is small.

  • Importance sampling concentrates computational resources on important regions of phase space, making Monte Carlo efficient and powerful for thermodynamic problems.

  • Importance sampling requires generating points according to the Boltzmann distribution — this is achieved through Markov chain algorithms like Metropolis.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent