Random Walk in 1D¶
Consider a system with a binary outcome, where each trial results in either a “+” or “−” outcome with fixed probabilities
A classic example is a one-dimensional random walk of steps, where a particle moves right or left at each step.
Other equivalent examples include:
tossing coins (heads or tails),
counting non-interacting molecules on the left vs right side of a container.
Microstates¶
Each experiment generates a specific sequence of outcomes, for example
or equivalently for coin tosses
Each sequence represents a single microstate.
Since each step has two possible outcomes, the total number of microstates is
For an unbiased random walk , all microstates are equally probable, with probability .
For a biased random walk , 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:
The net displacement from the origin is
Many different microstates correspond to the same macrostate.
For large , the binomial is well-approximated by a normal distribution, so is also approximately normal:
Equivalently, the standardized displacement converges in distribution to a standard Gaussian:
Gaussian or large limit of Binomial Distribution
The binomial distribution for large values of has a sharply peaked distribution around its maximum (most likely) value . This motivates us to seek a continuous approximation by Taylor expanding the probability distribution around its maximum value and keeping terms up to quadratic order.
Thus, from the onset, we aim for a Gaussian distribution. The task is to find the coefficients and justify that the third term in the Taylor expansion is negligible compared to the second.
We evaluate the derivative of in the limit of as:
We could also arrive at the same result by using Stirling’s approximation .
Taking the first derivative of the Taylor expansion for the binomial distribution, we find the peak of the distribution around which we expand:
We recall that is also the mean of the binomial distribution!
Having found the peak of the distribution and knowing the first derivative, we now proceed to compute the second derivative:
While the first derivative gave us the mean of the binomial distribution, we notice that the second derivative produces the variance .
Now, all that remains is to plug the coefficients into our approximated probability distribution and normalize it. Why normalize? The binomial was already properly normalized, but since we made an approximation by neglecting higher-order terms, we must re-normalize.
Normalizing the Gaussian distribution is done via the following integral:
Finally, we obtain the normalized Gaussian approximation to the binomial distribution:
Poisson limit or the limit of large and small such that
This is a situation of rare events like rains in forest or radioactive decay of uranium where each individual event has small chance of happening yet there are large number of samples such that one has a constant average rate of events
In this limit distirbution is no longer well described by the gaussian as the shape of distribution is heavily skewed due to tiny values of p.
Writing factorial explicitely we realize that it is dominated and also
Next let us plug in and recall the definition of exponential
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 steps is specified by the number of “+” steps (with ).
The logarithm of the probability of observing a given macrostate is
Frequencies and Probabilities¶
In simulations, we measure the fractions of steps
These fractions fluctuate in finite simulations but converge to the true probabilities in the long-time limit:
Since and , we introduce the shorthand notation
With this notation, the logarithm of the macrostate probability can be written as
where
is an entropy term, related to the number of microstates in a macrostate
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
which simplifies to
where is the energy per step.
When , there is no bias and the energy reduces to
Entropy as the Logarithm of the Number of Microstates¶
The entropy term arises from the combinatorial factor. Using Stirling’s approximation,
Rewriting in terms of the fraction gives
where is the entropy per step.
Large Deviation Theory¶
For many systems, the probability of observing a macrostate characterized by a fraction has the form
where is a function that does not depend on .
As the number of steps, molecules, or components increases, the probability distribution becomes sharply concentrated near the minimum of .
This function therefore controls both the shape and decay of the probability distribution in the large- 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 from the true probabilities are suppressed as increases:
As grows, fluctuations away from 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 typically has the large-deviation form
where is the large deviation function. The most probable value minimizes . To understand small fluctuations, we expand around this minimum:
Keeping only the quadratic term we once again we see that for large , fluctuations around the most probable value are Gaussian, with a width that shrinks as .
Example of Gaussian limit of Large Deviation function for random walk
The large deviation rate function for a simple random walk is given by:
where and are empirical step probabilities, and , are their expected values with .
Expansion Around the Minimum
The function is minimized at , . Introducing small deviations :
Expanding the logarithms:
Substituting into , the linear terms cancel, and we obtain:
Gaussian Limit
By the large deviation principle:
This is a Gaussian with variance:
Thus, the empirical frequency follows a Gaussian distribution in the large limit.
Big Picture: LLN, CLT, and LDT for a 1D Random Walk¶
Consider a biased random walk with
steps
step
,
Define total displacement
| Theorem | What it describes | Scaling with | Statement for random walk | What it tells us physically |
|---|---|---|---|---|
| Law of Large Numbers (LLN) | Typical value | Fluctuations | The average velocity converges to the drift | |
| Central Limit Theorem (CLT) | Typical fluctuations | Width | Near the mean, distribution becomes Gaussian | |
| Large Deviation Theory (LDT) | Rare events | Probability | 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
Near the minimum of :
Exercises
add gausian curve to binomial distribution plot. Keep in mind when comparing discrete and continuous distribution: You are comparing to where 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