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.

Part 3: Moments - The Statistical Bridge to Physics

How Nature Computes | Statistical Thinking Module 1 | COMP 521

Learning Outcomes

By the end of Part 3, you will be able to:


3.1 What Are Moments? The Information Extractors

Priority: 🔴 Essential

You have a distribution with 1057 particles. How do you extract useful information without tracking every particle? The answer is moments – weighted averages that capture essential features. Moments feel like compression; precisely, low-order moments summarize constrained information. Catchphrase -> Precision: “Moments compress information” means expectation operators retain specific distribution features while discarding others.

For any probability density p(v)p(v), the nn-th raw moment is:

μnraw=∫−∞∞vnp(v) dv=⟨vn⟩=E[vn]\boxed{\mu_n^{\text{raw}} = \int_{-\infty}^{\infty} v^n p(v)\, dv = \langle v^n \rangle = E[v^n]}

Think of moments as increasingly sophisticated summaries:

3.2 Why Moments Matter Statistically

Priority: 🔴 Essential

Moments are the fundamental tools for characterizing distributions:

TypeDefinitionWhy we use it
Raw momentE[Xn]E[X^n]Directly tracks powers and appears in expansions like the MGF
Central momentE[(X−μ)n]E[(X-\mu)^n]Isolates shape around the mean by removing location shifts
Standardized momentE[((X−μ)/σ)n]E[((X-\mu)/\sigma)^n]Enables scale-free comparisons across datasets

Central moments are invariant to shifts in origin; standardized moments are invariant to both shifts and rescalings.

MomentStatistical NamePhysical MeaningFormula
1stMeanAverage valueμ=E[X]\mu = E[X]
2nd centralVarianceSpread around meanσ2=E[(X−μ)2]\sigma^2 = E[(X-\mu)^2]
3rd standardizedSkewnessAsymmetryγ1=E[(X−μ)3]/σ3\gamma_1 = E[(X-\mu)^3]/\sigma^3
4th standardizedExcess kurtosisTail weight beyond Gaussian baselineγ2=E[(X−μ)4]/σ4−3\gamma_2 = E[(X-\mu)^4]/\sigma^4 - 3

The moment generating function (when it exists) encodes all moments:

MX(t)=E[etX]=∑n=0∞tnn!μnrawM_X(t) = E[e^{tX}] = \sum_{n=0}^{\infty} \frac{t^n}{n!}\mu_n^{\text{raw}}

Taylor expand and each coefficient gives a moment!

Why few moments often suffice (with caveats):

3.3 Example: Moments of Maxwell-Boltzmann

Priority: 🔴 Essential

Let’s extract physics from the Maxwell-Boltzmann distribution using moments.

For the normalized 1D velocity-component PDF, use:

p(vx)=m2πkBTexp⁡(−mvx22kBT)p(v_x) = \sqrt{\frac{m}{2\pi k_B T}} \exp\left(-\frac{m v_x^2}{2k_B T}\right)

If you want number density form, f(vx)=n p(vx)f(v_x) = n\,p(v_x).

First moment (mean velocity):

⟨vx⟩=0\langle v_x \rangle = 0

Symmetric distribution – no net flow.

Second moment (mean square velocity):

⟨vx2⟩=kBTm\langle v_x^2 \rangle = \frac{k_B T}{m}

This IS temperature! Temperature literally is the second moment of velocity. More generally, temperature is tied to the variance ⟨(vx−⟨vx⟩)2⟩\langle (v_x - \langle v_x \rangle)^2\rangle (the second central moment); for equilibrium with zero mean flow, this equals ⟨vx2⟩\langle v_x^2\rangle.

Connection to pressure:

P=nm⟨vx2⟩=nkBTP = nm\langle v_x^2 \rangle = nk_B T

Pressure is mass density times velocity variance!

Project Hook: This appears in Project 2 when you validate whether sampled velocities match target dispersion before N-body integration.

The profound realization:

3.4 Moments in Machine Learning

Priority: 🔴 Essential

ML uses moment estimators to stabilize training. You can read modern training loops as repeated moment estimation: normalize batch statistics so layers stay well-scaled, then accumulate gradient moments so updates are both directional and adaptive.

Batch Normalization: First and Second Central Moments

Code Reliability Contract

import numpy as np

# Minimal runnable setup for one mini-batch
rng = np.random.default_rng(536)
x = rng.normal(loc=0.0, scale=1.0, size=(32, 8))

# For each mini-batch
eps = 1e-8
batch_mean = np.mean(x, axis=0)        # 1st moment
batch_var = np.var(x, axis=0)          # 2nd central moment
normalized = (x - batch_mean) / np.sqrt(batch_var + eps)

BatchNorm keeps layer activations centered and comparably scaled, which improves gradient flow and reduces training instability.

Optimizers (Momentum/Adam): First and Second Gradient Moments

Optimization also runs on moment logic: momentum tracks a first-moment trend in gradients, while Adam pairs first- and second-moment estimates to adapt step sizes dimension by dimension.

import numpy as np

# Minimal runnable setup for gradient moments
rng = np.random.default_rng(536)
x = rng.normal(loc=0.0, scale=1.0, size=(32, 8))
gradient = rng.normal(loc=0.0, scale=1.0, size=x.shape[1])
velocity = np.zeros_like(gradient)
m = np.zeros_like(gradient)
v = np.zeros_like(gradient)
lr = 1e-3
momentum = 0.9
beta1 = 0.9
beta2 = 0.999

# SGD with momentum (1st moment)
velocity = momentum * velocity - lr * gradient

# Adam (1st and 2nd moments)
m = beta1 * m + (1-beta1) * gradient     # 1st moment
v = beta2 * v + (1-beta2) * gradient**2  # 2nd moment

Copy/paste quick-check: Imports: numpy. Seed: use rng = np.random.default_rng(536) for reproducible toy tensors and gradients. Variability: changing the seed changes batch statistics and moment values.

Feature extraction IS moment computation:

The universal principle: Whether extracting features from data or deriving physics from distributions, moments compress information while preserving what matters.

Moment Ladder
p(v) distribution
    -> apply E[v^n]
    -> scalar summaries (mean, variance, skewness, kurtosis)
    -> interpretation (physics state or ML training behavior)

Part 3 Synthesis: Moments Bridge Statistics and Physics


Bridge to Part 4: From Understanding to Implementation

You understand the principles and can extract information using moments. Now comes the crucial step: generating samples from these distributions computationally. This bridges theory to simulation. All of this collapses if your samples don’t represent the distribution — Part 4 is how we manufacture representative samples on purpose.