Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Random Walk and Limit Theorems

Random Walk in 1D

Consider a system with a binary outcome, where each trial results in either a “+” or “−” outcome with fixed probabilities

p++p=1p_{+} + p_{-} = 1

A classic example is a one-dimensional random walk of NN steps, where a particle moves right (+1)(+1) or left (1)(-1) at each step.

Other equivalent examples include:

  • tossing NN coins (heads or tails),

  • counting NN non-interacting molecules on the left vs right side of a container.

Microstates

Each experiment generates a specific sequence of outcomes, for example

+1,1,1,+1,1+1, -1, -1, +1, -1

or equivalently for coin tosses

HTHTTHTHTT

Each sequence represents a single microstate.
Since each step has two possible outcomes, the total number of microstates is

Ω=2N\Omega = 2^N
  • For an unbiased random walk (p+=p=1/2)(p_{+} = p_{-} = 1/2), all microstates are equally probable, with probability 1/2N1/2^N.

  • For a biased random walk (p+p)(p_{+} \neq p_{-}), microstate probabilities depend on the number of ++ and - steps.

Macrostates

Often, we are not interested in the exact order of steps, but only in how many steps go to the right or left.

These quantities define a macrostate:

N++N=NN_{+} + N_{-} = N

The net displacement from the origin is

ΔN=N+N\Delta N = N_{+} - N_{-}

Many different microstates correspond to the same macrostate.

For large NN, the binomial is well-approximated by a normal distribution, so xx is also approximately normal:

x    N ⁣(N(p+p),4Np+p).x \;\approx\; \mathcal{N}\!\big(N(p_{+}-p_{-}),\,4Np_{+}p_{-}\big).

Equivalently, the standardized displacement converges in distribution to a standard Gaussian:

z=xN(p+p)2Np+p  N  N(0,1),z = \frac{x-N(p_{+}-p_{-})}{2\sqrt{Np_{+}p_{-}}} \;\xrightarrow[N\to\infty]{}\; \mathcal{N}(0,1), \qquad
P(xN,p+)122πNp+pexp ⁣[(xN(p+p))28Np+p]P(x\mid N,p_{+}) \approx \frac{1}{2\sqrt{2\pi Np_{+}p_{-}}} \exp\!\left[-\frac{\big(x-N(p_{+}-p_{-})\big)^2}{8Np_{+}p_{-}}\right]
Source
import numpy as np
import matplotlib.pyplot as plt
from scipy.special import comb

def P_x(N, x, p):
    """
    Binomial probability written in terms of
    x = N_+ - N_- with N fixed
    """
    # Only valid when (N + x) is even
    if (N + x) % 2 != 0:
        return 0.0

    k = (N + x) // 2  # number of '+' outcomes
    return comb(N, k) * (p**k) * ((1 - p)**(N - k))


# -------------------------------
# Parameters students can change
# -------------------------------
p = 0.5            # probability of '+'
N_values = [10, 50, 100, 200]

# -------------------------------
# Plot
# -------------------------------
plt.figure(figsize=(7, 5))

for N in N_values:
    x_vals = np.arange(-N, N + 1, 2)
    x_norm = x_vals / N

    P_vals = [P_x(N, x, p) for x in x_vals]
    plt.plot(x_norm, P_vals, marker="o", label=f"N = {N}")

plt.xlabel(r"$x/N$")
plt.ylabel(r"$P(x)$")
plt.title(fr"Binomial distribution in $x = N_+ - N_-$  (p = {p})")
plt.legend()
plt.tight_layout()
plt.show()

Log of Macrostate Probability, Entropy, and Fluctuations

A macrostate of a random walk with NN steps is specified by the number of “+” steps N+N_{+} (with N=NN+N_{-} = N - N_{+}).

The logarithm of the probability of observing a given macrostate is

logP(N+N,p+)=logN!N+!N!+log[p+N+pN]\log P(N_{+} \mid N, p_{+}) = \log \frac{N!}{N_{+}! N_{-}!} + \log \left[ p_{+}^{N_{+}} \, p_{-}^{N_{-}} \right]

Frequencies and Probabilities

In simulations, we measure the fractions of steps

f±=N±Nf_{\pm} = \frac{N_{\pm}}{N}

These fractions fluctuate in finite simulations but converge to the true probabilities in the long-time limit:

f±p±f_{\pm} \to p_{\pm}

Since f++f=1f_{+} + f_{-} = 1 and p++p=1p_{+} + p_{-} = 1, we introduce the shorthand notation

ff+,pp+f \equiv f_{+}, \qquad p \equiv p_{+}

With this notation, the logarithm of the macrostate probability can be written as

logP(fN,p)=S(f)E(f)\log P(f \mid N, p) = S(f) - E(f)

where

  • S(f)S(f) is an entropy term, related to the number of microstates in a macrostate

  • E(f)E(f) is an energy-like term encoding the bias in step probabilities

Energy as a Measure of Bias

The probability factor contributes an energy-like term

E=log[pNf(1p)N(1f)]E = - \log \left[ p^{Nf} (1-p)^{N(1-f)} \right]

which simplifies to

E=N[flogp+(1f)log(1p)]=Nϵ(f)E = -N \left[ f \log p + (1-f) \log (1-p) \right] = -N \, \epsilon(f)

where ϵ(f)=E/N\epsilon(f) = E/N is the energy per step.

When p=12p = \frac{1}{2}, there is no bias and the energy reduces to

E=Nlog2E = N \log 2

Entropy as the Logarithm of the Number of Microstates

The entropy term arises from the combinatorial factor. Using Stirling’s approximation,

S(f)=logN!N+!N!NlogNN+logN+NlogNS(f) = \log \frac{N!}{N_{+}! N_{-}!} \approx N \log N - N_{+} \log N_{+} - N_{-} \log N_{-}

Rewriting in terms of the fraction f=N+/Nf = N_{+}/N gives

S(f)=N[flogf(1f)log(1f)]S(f) = N \left[ - f \log f - (1-f) \log (1-f) \right]

where s(f)=S/Ns(f) = S/N is the entropy per step.

Large Deviation Theory

  • For many systems, the probability of observing a macrostate characterized by a fraction ff has the form

logPN(f)N[ϵ(f)s(f)]=NI(f)\log P_N(f) \approx - N \big[ \epsilon(f) - s(f) \big] = -N I(f)
  • where I(f)I(f) is a function that does not depend on NN.

  • As the number of steps, molecules, or components NN increases, the probability distribution becomes sharply concentrated near the minimum of I(f)I(f).

  • This function therefore controls both the shape and decay of the probability distribution in the large-NN limit. This general scaling behavior is known as Large Deviation Theory.

Example: Random Walk

  • For a random walk, the large deviation function measures how deviations of the empirical fractions f±f_{\pm} from the true probabilities p±p_{\pm} are suppressed as NN increases:

I(f)=f+logf+p++flogfpI(f) = f_{+} \log \frac{f_{+}}{p_{+}} + f_{-} \log \frac{f_{-}}{p_{-}}
  • As NN grows, fluctuations away from f+=p+f_{+} = p_{+} become exponentially unlikely.

Source
# Re-import required libraries since execution state was reset
import numpy as np
import matplotlib.pyplot as plt

# Define parameters
p_plus = 0.7  # Biased probability
p_minus = 1 - p_plus  # Complementary probability

# Define range for f_+
f_plus_values = np.linspace(0.01, 0.99, 200)  # Avoid log(0) issues
f_minus_values = 1 - f_plus_values  # f_- = 1 - f_+

# Compute entropy component s(f_+)
s_values = -(f_plus_values * np.log(f_plus_values) + f_minus_values * np.log(f_minus_values))

# Compute energy component ε(f_+)
epsilon_values = - (f_plus_values * np.log(p_plus) + f_minus_values * np.log(p_minus))

# Compute large deviation rate function I(f_+)
I_values = f_plus_values * np.log(f_plus_values / p_plus) + f_minus_values * np.log(f_minus_values / p_minus)

# Compute probability P_N(f_+) using large deviation approximation
N = 50  # Arbitrary large N
P_x_values = np.exp(-N * I_values)  # Exponential suppression
P_x_values /= np.trapz(P_x_values, f_plus_values)  # Normalize for probability density

# Create subplots
fig, axes = plt.subplots(1, 2, figsize=(12, 5))

# First subplot: Entropy and Energy Components
axes[0].plot(f_plus_values, s_values, label=r"$s(f)$ (Entropy)", color="blue")
axes[0].plot(f_plus_values, epsilon_values, label=r"$\epsilon(f_+)$ (Energy)", color="green")
axes[0].plot(f_plus_values, I_values, label=r"$I(f)$ (Rate Function)", color="red")
axes[0].axvline(p_plus, linestyle="--", color="black", label=r"$f_+ = p_+$")
axes[0].set_xlabel(r"$f_+$")
axes[0].set_ylabel("Value")
axes[0].set_title("Entropy, Energy, and Rate Function")
axes[0].legend()
axes[0].grid()

# Second subplot: Probability Distribution P_N(f_+)
axes[1].plot(f_plus_values, P_x_values, label=r"$P_N(f_+)$", color="purple")
axes[1].axvline(p_plus, linestyle="--", color="black", label=r"$f_+ = p_+$")
axes[1].set_xlabel(r"$f_+$")
axes[1].set_ylabel(r"$P_N(f_+)$")
axes[1].set_title("Probability Distribution")
axes[1].legend()
axes[1].grid()

plt.tight_layout()
plt.show()
Source
import numpy as np
import matplotlib.pyplot as plt
from scipy.special import comb

def plot_large_deviation(N, theta, color):
    """Plots the large deviation approximation for given N and bias theta."""
    f = np.linspace(0.01, 0.99, 200)  # Avoid log(0) issues

    # Compute the rate function I(f)
    I = f * np.log(f / theta) + (1 - f) * np.log((1 - f) / (1 - theta))

    # Compute normalized probability P_LDT(f) ∼ exp(-N I(f))
    p_ldt = np.exp(-N * I)
    p_ldt /= np.trapz(p_ldt, f)  # Normalize using trapezoidal rule for integration

    plt.plot(f, p_ldt, color=color, linestyle="-", linewidth=2, label=f"LDT Approx. (N={N})")

def plot_binomial(N, theta, color):
    """Plots the exact binomial distribution for given N and bias theta."""
    n = np.arange(N + 1)
    f = n / N  # Convert discrete counts to fractions

    # Compute binomial probability mass function
    prob = comb(N, n) * theta**n * (1 - theta)**(N - n)

    # Normalize probability for direct comparison with LDT curve
    prob /= np.trapz(prob, f)

    plt.plot(f, prob, 'o', color=color, markersize=5, label=f"Binomial (N={N})")

# Parameters
theta = 0.5  # Fair coin
Ns = [5, 10, 20, 50, 100]  # Different values of N
colors = plt.cm.viridis(np.linspace(0.2, 0.8, len(Ns)))  # Use colormap for better distinction

# Create the plot
plt.figure(figsize=(8, 6))
for i, N in enumerate(Ns):
    plot_large_deviation(N, theta, colors[i])
    plot_binomial(N, theta, colors[i])

# Labels and formatting
plt.xlabel(r"$f_+$", fontsize=14)
plt.ylabel(r"Probability Density", fontsize=14)
plt.title("Comparison of Binomial Distribution (Points) and Large Deviation Approximation (Lines)", fontsize=12)
plt.legend(loc="upper left", fontsize=10)
plt.grid()
plt.show()

Gaussian Nature of Fluctuations

  • For large systems, the probability of observing a fraction ff typically has the large-deviation form

P(f)eNI(f)P(f) \sim e^{-N I(f)}
  • where I(f)I(f) is the large deviation function. The most probable value fminf_{\text{min}} minimizes I(f)I(f). To understand small fluctuations, we expand I(f)I(f) around this minimum:

I(f)=I(fmin)+12I(fmin)(ffmin)2+I(f)= I(f_{\text{min}}) + \frac{1}{2} I''(f_{\text{min}}) (f - f_{\text{min}})^2 + \cdots
  • Keeping only the quadratic term we once again we see that for large NN, fluctuations around the most probable value are Gaussian, with a width that shrinks as 1/N1/\sqrt{N}.

P(f)exp[N2I(fmin)(ffmin)2]P(f) \approx \exp\left[ - \frac{N}{2} I''(f_{\text{min}}) (f - f_{\text{min}})^2 \right]

Big Picture: LLN, CLT, and LDT for a 1D Random Walk

Consider a biased random walk with

  • NN steps

  • step si=±1s_i = \pm 1

  • P(si=+1)=pP(s_i=+1)=p, P(si=1)=1pP(s_i=-1)=1-p

Define total displacement

x=i=1Nsi,μ=E[si]=p(1p)=2p1,σ2=Var(si)=4p(1p).x = \sum_{i=1}^N s_i, \qquad \mu = \mathbb{E}[s_i]=p-(1-p)=2p-1, \qquad \sigma^2=\mathrm{Var}(s_i)=4p(1-p).
TheoremWhat it describesScaling with NNStatement for random walkWhat it tells us physically
Law of Large Numbers (LLN)Typical valueFluctuations 1/N\sim 1/\sqrt{N}
xNμ\frac{x}{N} \to \mu
The average velocity converges to the drift
Central Limit Theorem (CLT)Typical fluctuationsWidth N\sim \sqrt{N}
xNμNN(0,σ2)\frac{x-N\mu}{\sqrt{N}} \Rightarrow \mathcal{N}(0,\sigma^2)
Near the mean, distribution becomes Gaussian
Large Deviation Theory (LDT)Rare eventsProbability eNI(f)\sim e^{-N I(f)}
P ⁣(xN=f)eNI(f)P\!\left(\frac{x}{N}=f\right)\approx e^{-N I(f)}
Exponentially small probability of atypical drift

Hierarchy of Approximations

Conceptually:

  • LLN → tells us where the distribution concentrates

  • CLT → tells us its Gaussian shape near the peak

  • LDT → tells us how the tails decay far from the peak

Graphically:

  • LLN identifies the maximum of the distribution

  • CLT describes the quadratic expansion near the maximum

  • LDT provides the full rate function governing global shape

P ⁣(xN=f)exp[NI(f)]\boxed{ P\!\left(\frac{x}{N}=f\right) \approx \exp[-N I(f)] }

Near the minimum of I(f)I(f):

I(f)(fμ)22σ2CLT GaussianI(f) \approx \frac{(f-\mu)^2}{2\sigma^2} \quad \Longrightarrow \quad \text{CLT Gaussian}
Exercises
  • add gausian curve to binomial distribution plot. Keep in mind when comparing discrete and continuous distribution: You are comparing P(xn)P(x_n) to P(x)ΔxP(x)\Delta x where Δx\Delta x is spacing between discrete points!

  • Plot entropy as a function of molecules going to the left/right corners

  • Plot energy as a function of bias to go left/right

  • Plot the large deviation function as a function of fraction