ES98D · Course contents

4. Sampling without knowing the partition function

Suppose we want the mean separation of particles under the canonical position law. We can evaluate U(r)U(r) for any proposed configuration, but cannot integrate e−βUe^{-\beta U} over a space with dNdN coordinates. The normalising constant is the very integral we hoped sampling would avoid. How can an algorithm use a distribution it cannot normalise?

The answer will be to compare local probability ratios. Before introducing a chain, we should understand what ordinary independent sampling already provides, and what we give up by replacing it.

4.1 An integral is an expectation under a chosen measure

Let I=∫Df(x)dxI=\int_D f(x)dx and choose a normalised sampling density p(x)p(x) positive wherever ff contributes. If X1,…,XMX_1,\ldots,X_M are independent draws from pp, then

I=Ep[f(X)p(X)],I^M=1M∑n=1Mf(Xn)p(Xn).I=\mathbb E_p\left[\frac{f(X)}{p(X)}\right], \qquad \widehat I_M=\frac1M\sum_{n=1}^M\frac{f(X_n)}{p(X_n)}.

Absolute integrability justifies the expectation and a law of large numbers. If σ2=Var⁡p(f/p)\sigma^2=\operatorname{Var}_p(f/p) is finite, the estimator is unbiased and has variance σ2/M\sigma^2/M. A central limit theorem then gives the familiar M−1/2M^{-1/2} standard-error rate. The exponent does not depend on dimension; the variance and cost per evaluation certainly can.

For a finite-volume domain of volume ∣D∣|D|, uniform sampling gives I^M=∣D∣M−1∑nf(Xn)\widehat I_M=|D|M^{-1}\sum_n f(X_n). Hit-or-miss sampling gives another low-dimensional construction: for 0≤f(x)≤B0\le f(x)\le B, draw uniformly from D×[0,B]D\times[0,B] and estimate II by ∣D∣B|D|B times the fraction lying below the graph. This trades function values for indicators and often increases variance. In low dimensions, smooth deterministic quadrature can be far more efficient.

Independent draws can be obtained by inverse transforms in suitable one-dimensional distributions or by rejection sampling. The latter uses an envelope f(x)≤cp(x)f(x)\le c p(x) for a nonnegative unnormalised target, accepting a proposal X∼pX\sim p with probability f(X)/(cp(X))f(X)/(cp(X)). It does not require the target normaliser, but it does require a valid envelope, which can be extremely inefficient in high dimensions. Thus an unknown partition function is an obstacle, not a proof that all direct sampling is impossible.

4.2 Spend samples where they matter

Importance sampling chooses pp to reduce fluctuations in f/pf/p. For a nonnegative integrand, the ideal choice p∝fp\propto f makes that quantity constant, but normalising this ideal density requires knowing II. For signed ff, p∝∣f∣p\propto|f| minimises the second moment among admissible densities, yet cancellation can still make relative error large.

In statistical mechanics the desired quantity is usually a ratio:

⟨A⟩=∫A(x)e−βU(x)dx∫e−βU(x)dx.\langle A\rangle=\frac{\int A(x)e^{-\beta U(x)}dx} {\int e^{-\beta U(x)}dx}.

If independent samples from π∝e−βU\pi\propto e^{-\beta U} were available, we would simply average AA. Sampling from an accessible auxiliary pp instead gives a self-normalised weighted estimator. It is generally biased at finite MM, and poor overlap can concentrate almost all weight on a handful of observations. We need a way to target the physically relevant configurations without constructing a global independent sampler.

What happens if we transport uniform draws towards the large parts of an integrand, then compensate for the changed sampling density?

Move the samples without changing the integral
A proposal follows the integrand
integrand / proposal densitysample position x0101.7solid: integranddashed: proposal
The weights preserve the answer
estimated integralnumber of samples012101.7teal: importancedashed: uniform

Î = mean[f(X)/p(X)]; ∫₀¹ f(x) dx = 1

22 samples; latest weight 0.037; integral estimate 0.921.

Paused. Play the sequence, step through it, or drag the position slider.

f(x) = 6x(1−x), 0 < x < 1, integral one. The normalised mixture p = (1−η) + ηf is sampled by deterministic bisection of its CDF using a fixed random seed. Curves are finite-run estimates, not confidence bands.

The first panel links the integrand to the proposal density. The second reveals the weighted estimate as samples arrive. At mixture one, p = f and every importance weight is exactly one. ↗

4.3 Replace a global draw by local transitions

A Markov chain X0,X1,…X_0,X_1,\ldots has the property that the law of Xn+1X_{n+1} conditional on its history depends only on XnX_n. Its transition kernel P(x,dy)P(x,dy) describes that law. On a finite state space it is a matrix with nonnegative entries and rows summing to one.

A measure π\pi is stationary when

π(y)=∑xπ(x)P(x,y),\pi(y)=\sum_x\pi(x)P(x,y),

or, in continuous state space, π(B)=∫π(dx)P(x,B)\pi(B)=\int\pi(dx)P(x,B) for every measurable set BB. A chain started at stationarity has the right distribution at every step, although successive states may be strongly correlated. Starting from a convenient x0x_0 instead introduces an equilibration problem.

4.4 Balance probability flow

Stationarity balances all incoming flow. A stronger sufficient condition is detailed balance:

π(x)P(x,y)=π(y)P(y,x).\pi(x)P(x,y)=\pi(y)P(y,x).

Summing over xx proves stationarity because the rows of PP sum to one. Detailed balance also makes the stationary chain reversible: a finite path has the same probability as its time reverse. It is useful for constructing algorithms, but it is not required for equilibrium sampling.

4.5 The Metropolis–Hastings construction

At xx, propose yy from q(x,dy)q(x,dy). When target and proposal densities are available, accept with

α(x,y)=min⁡{1,π(y)q(y,x)π(x)q(x,y)}.\alpha(x,y)=\min\left\{1, \frac{\pi(y)q(y,x)}{\pi(x)q(x,y)}\right\}.

A proposal with positive forward density and zero reverse density has acceptance zero in this construction. For y≠xy\ne x, the probability flux is

π(x)q(x,y)α(x,y)=min⁡{π(x)q(x,y),π(y)q(y,x)}.\pi(x)q(x,y)\alpha(x,y) =\min\{\pi(x)q(x,y),\pi(y)q(y,x)\}.

This expression is symmetric in x,yx,y, proving detailed balance. The unused probability remains at xx, completing the stochastic kernel. The diagonal term must be included; a proposed move and an actual transition are different objects.

For a symmetric proposal and a Boltzmann target,

α(x,y)=min⁡{1,e−βΔU},ΔU=U(y)−U(x).\alpha(x,y)=\min\{1,e^{-\beta\Delta U}\}, \qquad \Delta U=U(y)-U(x).

The partition function cancels in π(y)/π(x)\pi(y)/\pi(x). Downhill moves are accepted; uphill moves are sometimes accepted because equilibrium is a distribution, not an optimisation problem. A practical update draws an independent u∼Uniform(0,1)u\sim\mathrm{Uniform}(0,1) and accepts when log⁡u<min⁡(0,−βΔU)\log u<\min(0,-\beta\Delta U). Rejection records the current state again.

A rejection is part of the sample

Consider two states of energies 00 and Δ\Delta, with e−βΔ=1/4e^{-\beta\Delta}=1/4. Always propose the other state. The transition matrix and stationary probabilities are

P=(3/41/410),π=(4/5,1/5).P=\begin{pmatrix}3/4&1/4\\1&0\end{pmatrix}, \qquad \pi=(4/5,1/5).

The equilibrium flux in either direction is 1/51/5. Imagine deleting every repeated state from a trajectory. What distribution would the remaining sequence represent?

If we save only accepted moves in this two-state chain, what fraction of saved states are excited?
Jump counts and residence counts differ

Count jumps: one visit each

ground → excited → ground1 visit1 visit

Ignoring holding times gives equal jump frequencies.

Count attempts: residence 4 : 1

ground: E[K] = 4excited: E[K] = 1probabilities 4/5 and 1/5

Residence-weighted observations recover the Boltzmann probabilities.

Expected residence lengths per alternating two-jump cycle of the exact two-state chain. These are expectations, not a sample trajectory. ↗

The figure shows expected residence per two-jump cycle, not a randomly generated trajectory. This distinction will explain why rejection-free methods must retain waiting-time information rather than merely delete rejections.

Propose a displacement in a double well, inspect its energy cost, and then watch whether the chain moves or stays.

A rejected proposal is still an observation
Proposal on the potential
potential U(x)configuration x-3305.2proposal rejected
The recorded Markov trajectory
recorded positionattempt (including rejection)0121-2.52.5

α = min(1, exp[−βΔU])

Attempt 22: rejected; ΔU = 0.87; acceptance 0.175.

Paused. Play the sequence, step through it, or drag the position slider.

Seeded Metropolis demonstration in U(x) = (x² − 1)², symmetric uniform displacement in [−1.2,1.2]. This short run starts at x = −1 and is not evidence of equilibration or an estimate of mixing time. Proposals above the energy plot are marked at its upper edge, with their true ΔU in the readout.

The dashed segment marks the latest proposal. The trajectory records every attempted update, including repeated states after rejection. Raising β makes uphill proposals harder to accept. ↗

4.6 Invariance is necessary, exploration is additional

For a finite state space, irreducibility means every state can reach every other in some finite number of transitions. With irreducibility, a stationary probability is unique and time averages of integrable observables obey an ergodic law. Aperiodicity additionally gives convergence of the time-nn distribution from every starting state. A finite irreducible chain is positive recurrent automatically. For countably infinite chains, positive recurrence is an additional requirement; continuous-state theorems use measure-theoretic irreducibility and suitable Harris-recurrence hypotheses. Exact-point reachability is not the right definition for a continuous density.

Rejections can establish aperiodicity if they produce a positive self-transition in an irreducible finite chain. Metropolis does not guarantee that this happens. With a uniform target and a forced two-state flip, every proposal is accepted and the chain alternates forever. It has a valid stationary law and valid time averages, but its one-time distribution does not converge from a fixed initial state. A lazy update, retaining the state with some fixed positive probability, removes that periodicity while preserving the target.

Nor can acceptance rules repair disconnected proposals. Moves restricted to one basin or one conserved sector cannot sample a target that also assigns mass elsewhere. At zero temperature, uphill acceptance vanishes and finite-temperature irreducibility arguments may fail.

4.7 Moves inherit the geometry of the state space

For atomistic NVT sampling, select a particle uniformly and displace it by a symmetric random vector. Periodic wrapping preserves that symmetry when implemented consistently. Only interactions involving the moved particle change for a pairwise model, so the energy difference can often be evaluated locally. Very small displacements give high acceptance but slow exploration; very large ones mostly fail. The useful criterion is uncertainty per computation, not acceptance alone.

For an Ising configuration from Chapter 2, a symmetric single-spin proposal gives

ΔH=2si(∑j:⟨i,j⟩Jijsj+bi),α=min⁡{1,e−βΔH}.\Delta H=2s_i\left(\sum_{j:\langle i,j\rangle}J_{ij}s_j+b_i\right), \qquad \alpha=\min\{1,e^{-\beta\Delta H}\}.

Rotations of rigid molecules, vector-spin rotations, collective displacements and occupation exchanges require proposals defined with respect to their appropriate measures. Particle insertions and deletions target open ensembles, with chemical potential, particle-number factors and proposal volumes in the acceptance ratio; the fixed-NN displacement rule cannot be reused unchanged. Pressure-controlled simulations combine position moves with the volume acceptance ratio.

MCMC constructs a tool for integration. Its step count does not generally represent physical time. We can use it to predict equilibrium energy or structure, but not infer a transport coefficient from an arbitrary sequence of accepted displacements. The next chapter separates these observables and quantifies the information in correlated samples.

Exercises

  1. Verify πP=π\pi P=\pi in the two-state example and show that the accepted-jump chain has a different stationary distribution.
  2. Prove that (I+P)/2(I+P)/2 preserves any stationary measure of PP. What happens to its finite-state period?
  3. Derive the Ising energy change by cancelling all bonds not incident on the flipped site.