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 2: Statistical Tools and Concepts

How Nature Computes | Statistical Thinking Module 1 | COMP 521

Learning Outcomes

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


2.1 Correlation and Independence: When Variables Connect

Priority: 🔴 Essential

Physical intuition: Watch a flock of starlings move through the sky. When one bird turns, nearby birds turn too. Their velocities aren’t independent — they’re correlated. The same thing happens in stellar streams, where stars that were stripped from the same dwarf galaxy move together through space with correlated velocities.

So far, we’ve assumed particle velocities are independent. But what if they’re not? Understanding correlation is crucial for everything from gas dynamics to Gaussian processes. Correlation feels like structure; precisely, it is dependence encoded in covariance. Catchphrase -> Precision: “Structure in data” means measurable dependence that changes variance, uncertainty, and effective sample size.

Physical examples of correlation:

  1. Ideal gas: Particle velocities are independent

    • Pressure tensor is diagonal: Pij=PδijP_{ij} = P\delta_{ij}

    • No shear stress, no viscosity

  2. Stellar streams: Velocities are correlated

    • Stars moving together have correlated velocities

    • Off-diagonal pressure terms represent streaming motion

  3. Turbulence: Strong velocity correlations

    • Eddies create correlated motion

    • Kolmogorov spectrum from correlation functions

Why correlation matters for your projects:

Project 2 (N-body): Initially uncorrelated velocities become correlated through gravity

Project 4 (MCMC): Autocorrelation determines effective sample size

Project 5 (Gaussian Processes): Entire method based on correlation!

Project Hook: This appears in Project 4 when you convert autocorrelation into an effective sample size before trusting posterior uncertainty.

Correlation and Velocity Ellipsoids: How Stellar Dynamics Shape Observable Distributions. This comprehensive demonstration shows how correlation fundamentally shapes velocity distributions in stellar systems, directly connecting statistical concepts to observable astrophysics. Top row: Stellar velocity scatter plots across different dynamical environments, from isotropic spherical halos (\rho=0.0) through increasingly correlated systems representing thick disk (\rho=0.5), thin disk (\rho=0.8), and tidal stream populations (\rho=0.95). Each panel shows 1,500 synthetic stars with speeds color-coded (darker = faster) and confidence ellipsoids (1\sigma, 2\sigma, 3\sigma) revealing the characteristic elliptical structure that emerges from correlation. Bottom row: Principal component analysis of the same systems shows the underlying elliptical geometry explicitly, with major and minor axes proportional to the eigenvalues of the covariance matrix. As correlation increases, the axis ratio grows from 1.33 (nearly circular) to 6.52 (highly elongated), while the orientation encodes the preferred direction of streaming motion. The progression from \rho=0 to \rho=0.95 represents the evolution from relaxed systems (globular clusters, stellar halos) to dynamically young or disturbed populations (stellar streams, spiral arm features). This figure illustrates why velocity ellipsoids are fundamental tools in galactic archaeology - the shape directly encodes the dynamical history and current state of stellar populations, making correlation a powerful diagnostic of astrophysical processes. {#fig-correlation-velocity-ellipsoids width=“100%”}

The key insight: Independence makes problems tractable (can multiply probabilities). Correlation makes problems realistic (real systems have relationships). Understanding when to assume independence and when to model correlation is crucial for both physics and ML.

2.2 Marginalization: The Art of Ignoring

Priority: 🔴 Essential

Physical intuition: Imagine a 3D sculpture casting a shadow on a wall. The 2D shadow is a marginalization of the 3D object — you’ve integrated out the depth dimension. Similarly, when we observe stellar velocities along the line of sight, we’re seeing a marginalization of the full 3D velocity distribution.

We have velocities in 3D but often need just speeds. We know positions and velocities but only care about energy. How do we extract what matters? Through marginalization — integrating out unwanted variables.

The mathematical operation:

p(x)=∫p(x,y) dyp(x) = \int p(x,y)\,dy

“Sum over all possible values of what you don’t care about.”

These demos use numpy, matplotlib, and scipy; if SciPy is missing, run pip install scipy.

Example: From 3D velocities to 1D speeds

Starting with Maxwell-Boltzmann in 3D:

fv⃗(v⃗)=n(m2πkBT)3/2e−m∣v⃗∣2/(2kBT)f_{\vec{v}}(\vec{v}) = n \left(\frac{m}{2\pi k_B T}\right)^{3/2} e^{-m|\vec{v}|^2/(2k_B T)}

To get speed distribution, integrate over all directions:

Marginalization appears everywhere:

ContextMarginalizing OverTo Get
Bayesian inferenceNuisance parametersPosterior of interest
Gaussian ProcessesUnobserved pointsPredictions at test points
Statistical mechanicsMicroscopic detailsMacroscopic observables
Neural networksHidden layersOutput predictions
Image processingNoise dimensionsClean signal

The profound pattern: Complex high-dimensional problem →\to Marginalize →\to Simple low-dimensional answer

This is how we go from 1057 particle coordinates to 4 stellar structure equations!

Marginalization in action: joint velocity distributions map to observationally accessible 1D marginals by integrating out unobserved dimensions. {#fig-marginalization-visualization width=“100%”}

What to notice:

2.3 Ergodicity: When Time Equals Ensemble

Priority: 🔴 Essential

Physical intuition: Drop a blob of cream into your coffee. At first, it stays localized. But as you stir (or just wait), the cream explores the entire cup. Eventually, any small region has the same cream concentration as the time-average. This is ergodicity — one particle’s journey through time tells you about all possible states.

You measure the pressure of a gas over time. You also calculate the ensemble average over all possible microstates. Remarkably, these give the same answer. This is ergodicity — one of the deepest principles in statistical mechanics.

Assumption break cue: This relation can fail in finite windows when stationarity is not reached or when trajectories remain trapped in weakly connected regions.

In finite simulations, we compare time averages to expectations under a stationary distribution and still check stationarity and mixing before trusting the match.

Why ergodicity matters:

For physics: We can’t measure ensemble averages directly (need all possible microstates). But we can measure time averages! Ergodicity says they’re the same.

For MCMC (Project 4): Your Markov chain explores parameter space over “time” (iterations). Under stationarity and adequate mixing:

For molecular dynamics: Simulate one system over time instead of many systems at once

When ergodicity fails:

The profound connection: Ergodicity links:

All give the same answer for ergodic systems!

When Can We Assume Ergodicity?

Key diagnostic questions:

  1. Mixing time vs. observation time: Is τmix≪τobs\tau_{\text{mix}} \ll \tau_{\text{obs}}?

  2. Phase space connectivity: Can the system reach all allowed states?

  3. Energy barriers: Are there insurmountable barriers between regions?

Practical examples:

The MCMC connection (crucial for Project 4): Your Markov chain starts out of stationarity (often near an arbitrary initial guess). After burn-in, we diagnose convergence and mixing before treating chain averages as posterior expectations. The integrated autocorrelation time τint\tau_{\mathrm{int}} sets the effective sample size. This is why we:

  1. Discard burn-in samples (pre-stationary transients)

  2. Estimate effective sample size from τint\tau_{\mathrm{int}} (thinning optional and context-dependent)

  3. Run multiple chains and check diagnostics (for example R^\hat{R} and ESS)

2.4 The Law of Large Numbers: Why Statistics Works

Priority: 🔴 Essential

All these statistical principles work because of a mathematical miracle: as N→∞N \to \infty, randomness vanishes.

The Law of Large Numbers (LLN): For independent samples with standard deviation σ\sigma, the standard error of the sample mean scales as:

σXˉ=σN\sigma_{\bar{X}} = \frac{\sigma}{\sqrt{N}}

Typical relative fluctuations of an average therefore scale as 1/N1/\sqrt{N} (while the variance of the mean scales as 1/N1/N).

Assumption break cue: This scaling can fail when samples are strongly correlated, variance is infinite, or effective sample size is much smaller than nominal NN.

What this means:

At stellar scales, fluctuations are smaller than quantum uncertainty!

This is why:

This N\sqrt{N} scaling has profound implications for how errors propagate through calculations, which we’ll explore next.

2.5 Error Propagation: The Universal N\sqrt{N} Scaling

Priority: 🟡 Standard Path

Every measurement has uncertainty. Every calculation propagates these uncertainties. Understanding error propagation is crucial for both physics and computation. The Law of Large Numbers tells us fluctuations scale as 1/N1/\sqrt{N} — now let’s see how this propagates through calculations.

Assumption break cue: First-order propagation can fail for strongly nonlinear mappings, non-Gaussian uncertainties, or omitted covariance structure.

Monte Carlo error scaling:

For NN samples, the error in the mean scales as:

σxˉ=σN\sigma_{\bar{x}} = \frac{\sigma}{\sqrt{N}}

This 1/N1/\sqrt{N} scaling is universal:

Application to your projects:

Project 2: Energy-error behavior depends on integrator choice: symplectic schemes typically show bounded oscillatory ΔE/E\Delta E/E, while non-symplectic schemes can drift over long runs. Diagnose this empirically with a ΔE/E\Delta E/E vs time plot and timestep refinement tests.

Project 3: Monte Carlo photon error decreases as 1/Nphotons1/\sqrt{N_{\text{photons}}}

Project 4: MCMC error includes autocorrelation:

σMCMC≈σNeff,Neff≈N2τint\sigma_{\text{MCMC}} \approx \frac{\sigma}{\sqrt{N_{\text{eff}}}}, \qquad N_{\text{eff}} \approx \frac{N}{2\tau_{\mathrm{int}}}

Here τint\tau_{\mathrm{int}} is the integrated autocorrelation time (convention-dependent; equivalent N/(1+2τint)N/(1+2\tau_{\mathrm{int}}) forms are common).

2.6 Variance and Standard Deviation: Measuring Spread

Priority: 🔴 Essential

While the mean tells us where a distribution is centered, variance and standard deviation tell us how spread out it is — crucial for understanding everything from temperature to measurement uncertainty.

Definitions: Variance: The average squared deviation from the mean

Var(X)=σ2=E[(X−μ)2]=E[X2]−(E[X])2\text{Var}(X) = \sigma^2 = E[(X - \mu)^2] = E[X^2] - (E[X])^2

Standard Deviation: The square root of variance

σ=Var(X)\sigma = \sqrt{\text{Var}(X)}

Why square root? It puts the measure back in the same units as the original data.

Physical Interpretation

Remember from Part 1: Temperature IS proportional to velocity variance

⟨vx2⟩−⟨vx⟩2=σv2=kBTm\langle v_x^2 \rangle - \langle v_x \rangle^2 = \sigma_v^2 = \frac{k_B T}{m}

This isn’t an analogy — it’s an identity. Higher temperature literally means larger variance in molecular velocities.

Key Properties

  1. Variance of a sum (independent variables):

    Var(X+Y)=Var(X)+Var(Y)\text{Var}(X + Y) = \text{Var}(X) + \text{Var}(Y)
  2. Variance of a scaled variable:

    Var(cX)=c2Var(X)\text{Var}(cX) = c^2 \text{Var}(X)
  3. Standard error of the mean:

    σxˉ=σN\sigma_{\bar{x}} = \frac{\sigma}{\sqrt{N}}

    This is why averaging reduces uncertainty!

Why This Matters for Your Projects

The takeaway: Variance isn’t just a statistical concept — it’s often the physical quantity we’re measuring (temperature, pressure, velocity dispersion).

2.7 Bayesian Thinking: Learning from Data

Priority: 🔴 Essential Physical intuition: You observe a star with a reddish color. Is it red because it’s an intrinsically cool M-dwarf, or is it a hotter star reddened by interstellar dust? Your prior knowledge (most nearby stars aren’t heavily reddened) combines with the observation (the color) to give you a posterior belief about the star’s true nature. This is Bayesian inference — using prior knowledge plus new data to update beliefs.

Bayes’ Theorem: The Learning Equation

At its heart, Bayesian inference is about updating beliefs with data:

P(hypothesis∣data)=P(data∣hypothesis)×P(hypothesis)P(data)\boxed{P(\text{hypothesis} \mid \text{data}) = \frac{P(\text{data} \mid \text{hypothesis}) \times P(\text{hypothesis})}{P(\text{data})}}

Or in the notation you’ll use constantly:

P(θ∣D)=P(D∣θ)×P(θ)P(D)P(\theta \mid D) = \frac{P(D \mid \theta) \times P(\theta)}{P(D)}

where:

The Power and Peril of Priors

The Power: Priors incorporate previous knowledge

The Peril: Priors can bias results

Best Practice:

  1. Use physically motivated priors when possible

  2. Test sensitivity to prior choice

  3. Report both prior and posterior

  4. Use uninformative priors when truly ignorant

Connection to Frequentist Statistics

Bayesian and frequentist approaches answer different questions:

ApproachQuestionAnswer
Frequentist“If I repeated this experiment many times, what would happen?”Confidence intervals, p-values
Bayesian“Given this data, what do I believe about the parameters?”Posterior distributions, credible intervals

Both are valid! Frequentist is about long-run frequencies. Bayesian is about updating beliefs with data. Both paradigms encode modeling assumptions, but they differ in where probability is assigned: frequentist calibration uses repeated-data behavior under fixed parameters, while Bayesian inference assigns probability over parameter states given data.

Part 2 Synthesis: The Statistical Foundation


Bridge to Part 3: From Tools to Information Extraction

You now have the statistical tools. Next, we’ll see how to extract meaningful information from distributions using moments — the mathematical bridge between microscopic chaos and macroscopic order.