Common Probability Distributions: From a Single Coin Flip to the Multivariate Gaussian Bernoulli & binomial · Poisson & exponential · categorical & softmax · Gaussian & CLT · Laplace · multivariate Gaussian & conditioning
Every Training Loss Is a Probability Distribution
Motivation
Loss = Negative Log-Likelihood: Every predictive network implicitly chooses a distribution p(y \mid \hat{y}) for its targets and minimizes -\log p(y \mid \hat{y}).
Moments via X^2 = X:\mathbb{E}[X] = p and \mathrm{Var}(X) = \mathbb{E}[X^2] - p^2 = p(1 - p).
Variance parabola:\mathrm{Var}(X) = p(1-p) vanishes at p \in \{0, 1\} and peaks at 1/4 = 0.25 for a fair coin (p = 1/2), compared with 0.213 at p = 9/13.
The Binomial Distribution: Counting Heads in n Flips
Combinatorial structure:\binom{n}{k} distinct orderings of k heads and n-k tails, each having probability p^k(1-p)^{n-k}.
Moments from X = \sum_{i=1}^n X_i:\mathbb{E}[X] = np and, by independence, \mathrm{Var}(X) = np(1 - p) (if all 13 flips copied one fair flip, variance would jump 13\times from 3.25 to 42.25).
Factorial-Free Binomial Evaluation via Ratios
Numerical Stability & Unimodality
Evaluating n! overflows 64-bit floats for n > 170. Taking the ratio of consecutive probabilities cancels all factorials:
Combinatorial meaning & peak: From k heads, any of n - k tails can flip to a head in k + 1 equivalent ways; the ratio exceeds 1 iff k + 1 < (n + 1)p, proving the binomial rises to a single peak near np.
Factorial-Free Binomial Evaluation via Ratios (cont.)
Numerical Stability & Unimodality
def binomial_pmf(n, p, kmax):"""P(X=k) for k = 0..kmax, built from P(X=0) by the successive ratio.""" pmf = [(1- p) ** n]for k inrange(kmax): pmf.append(pmf[-1] *max(n - k, 0) / (k +1) * p / (1- p))return np.array(pmf)n, p =13, 0.5pmf = binomial_pmf(n, p, n)print(f'P(X=9): by the ratio {pmf[9]:.4f}, by counting {math.comb(13, 9) /2**13:.4f}')print(f'P(X>=9) = {pmf[9:].sum():.4f}')print(f'mean np = {n * p}, variance np(1-p) = {n * p * (1- p)}')
P(X=9): by the ratio 0.0873, by counting 0.0873
P(X>=9) = 0.1334
mean np = 6.5, variance np(1-p) = 3.25
Slicing continuous time: Divide a minute into n tiny slots of arrival probability p_n = \lambda/n; as n \to \infty, (1 - \lambda/n)^n \to e^{-\lambda} and \binom{n}{k}n^{-k} \to 1/k!.
Mean equals variance: For X \sim \mathrm{Poisson}(\lambda), \mathbb{E}[X] = \mathrm{Var}(X) = \lambda.
Convergence to the Poisson Limit & Overdispersion
Approximation Rate & Modeling Diagnostics
Rate of convergence: Total-variation distance \frac{1}{2}\sum_k |P_{\mathrm{Bin}}(k) - P_{\mathrm{Poi}}(k)| shrinks as O(1/n)(0.056 at n=20\to0.010 at n=100\to0.001 at n=1000).
Overdispersion diagnostic: If empirical count variance exceeds the mean (\mathrm{Var} \gg \mathbb{E}), arrival rates fluctuate or cluster (use a Gamma–Poisson / negative binomial mixture instead).
n = 20: total-variation distance 0.056
n = 100: total-variation distance 0.010
n = 1000: total-variation distance 0.001
Categorical, Softmax, and Multinomial Distributions
Multi-Class Labels and Token Counts
A K-class classifier or language model generalizes the Bernoulli coin to K outcomes:
In a continuous-time Poisson process of rate \lambda, the count in any window of length t is N(t) \sim \mathrm{Poisson}(\lambda t).
The fundamental duality: The waiting time T until the first request exceeds tif and only if zero requests arrive in [0, t]: P(T > t) = P\bigl(N(t) = 0\bigr) = e^{-\lambda t}, \quad t \ge 0
At \lambda = 4\text{/min}: mean wait is 15\text{ s}, while median wait F^{-1}(0.5) = \frac{\log 2}{\lambda} is 10.4\text{ s}.
Memorylessness, Gamma Waits, and Sampling
Continuous-Time Stream Verification
Memoryless property: Past waiting time s conveys zero information about remaining wait t: P(T > s + t \mid T > s) = \frac{P(T > s + t)}{P(T > s)} = \frac{e^{-\lambda(s+t)}}{e^{-\lambda s}} = e^{-\lambda t} = P(T > t)
Time of the k-th arrival (T_k \sim \mathrm{Gamma}(k, \lambda)): Since T_k > t \iff N(t) \le k - 1, differentiating \sum_{j=0}^{k-1} e^{-\lambda t}\frac{(\lambda t)^j}{j!} telescopes to the Gamma densityp(t) = \frac{\beta^\alpha t^{\alpha-1}e^{-\beta t}}{\Gamma(\alpha)} with mean \frac{\alpha}{\beta} and variance \frac{\alpha}{\beta^2}.
Inverse-transform sampling (T = -\log(1 - U)/\lambda): Writing 1 - U instead of U \in [0, 1) prevents -\log(0) = \infty:
requests per minute: mean 3.99, variance 4.00
silent minutes 0.0204, waits over 1 min 0.0191, e^-4 = 0.0183
mean wait 0.252 min, minutes with at most 3 requests 0.434
Variance by centering: Shifting [a, b] to [-c, c] with c = (b-a)/2 gives \mathrm{Var}(X) = \int_{-c}^c \frac{y^2}{2c}\,dy = \frac{c^2}{3} = \frac{(b-a)^2}{12}.
Key benchmarks:U(0, 1) has variance 1/12; U(-\sqrt{3}, \sqrt{3}) has mean 0 and unit variance 1.
From the Binomial Ratio to the Gaussian Parabola
De Moivre–Laplace Derivation
What shape does \mathrm{Binomial}(n, p) take near its mean np? Set q = 1 - p, measure count k = np + x by its offset x from the mean, and take the logarithm of the successive ratio using \log(1 + \epsilon) \approx \epsilon:
Linear slope \implies parabolic log-probability: Because each unit step in x changes \log P by -\frac{x}{npq}, summing steps integrates to the parabola \log P(X = np + x) \approx C - \frac{x^2}{2npq}, or P(X = np + x) \approx \frac{1}{\sqrt{2\pi npq}}e^{-x^2/(2npq)}:
n = 13: relative error at the peak 1.66%
n = 100: relative error at the peak 0.25%
n = 1000: relative error at the peak 0.03%
n = 13, k = 9: bell 0.0846, exact 0.0873
Gaussian Normalizer, Moments, and Squared Loss
The Polar Coordinate Integral Trick
To normalize the standard Gaussian density \phi(y) = \frac{1}{\sqrt{2\pi}}e^{-y^2/2}, we evaluate I = \int_{-\infty}^\infty e^{-x^2/2}\,dx by squaring it into a 2D integral and switching to polar coordinates (x, y) = (r\cos\theta, r\sin\theta) with dx\,dy = r\,dr\,d\theta:
Unit variance by parts (u = x, dv = xe^{-x^2/2}dx):\int_{-\infty}^{\infty} x^2 \phi(x)\,dx = \frac{1}{\sqrt{2\pi}}\left(\bigl[-xe^{-x^2/2}\bigr]_{-\infty}^{\infty} + \int_{-\infty}^{\infty} e^{-x^2/2}\,dx\right) = 0 + 1 = 1
General Gaussian X = \mu + \sigma Y \sim \mathcal{N}(\mu, \sigma^2): Change of variables gives p(x) = \frac{1}{\sqrt{2\pi\sigma^2}}\exp\!\left(-\frac{(x-\mu)^2}{2\sigma^2}\right), whose negative log-likelihood -\log p(y \mid \hat{y}) = \frac{(y - \hat{y})^2}{2\sigma^2} + \frac{1}{2}\log(2\pi\sigma^2) is squared-error loss.
The Central Limit Theorem in Action
Universal Convergence of Standardized Sums
Central Limit Theorem (CLT): For any i.i.d. sequence X_1, X_2, \dots with mean \mu and finite variance 0 < \sigma^2 < \infty, the standardized sum S_n = \sum_{i=1}^n X_i converges in distribution to \mathcal{N}(0, 1): \lim_{n \to \infty} P\!\left(\frac{S_n - n\mu}{\sigma\sqrt{n}} \le y\right) = \Phi(y) = \int_{-\infty}^y \phi(u)\,du
Watching uniforms become Gaussian: A single U(0, 1)(n=1) is a flat box; n=2 is a triangle; by n=8 and n=32, the standardized sum is visually indistinguishable from \phi(y).
Why finite variance is mandatory: Cauchy draws (\sigma^2 = \infty) never converge under averaging.
The Laplace Distribution, L1 Loss, and Heavy Tails
A Random Sign Times an Exponential
Construction: Multiply an independent fair sign S \in \{\pm 1\} by an exponential E \sim \mathrm{Exp}(1/b) and shift by \mu to get X = \mu + SE \sim \mathrm{Laplace}(\mu, b): p(x) = \frac{1}{2b}\exp\!\left(-\frac{|x - \mu|}{b}\right)
Moments from X = \mu + SE: Since S^2 = 1 and \mathbb{E}[S] = 0, \mathbb{E}[X] = \mu and \mathrm{Var}(X) = \mathbb{E}[E^2] = 2b^2.
Role in deep learning:
Negative log-density is L_1 / MAE loss|y - \hat{y}|/b (minimized by the outlier-robust sample median).
As a weight prior, it yields LASSO \ell_1 regularization\|\mathbf{w}\|_1.
Simulating Laplace vs. Gaussian Tail Mass
Five Times More Probability Beyond 3σ
At matched variance \sigma^2 = 2b^2, the Laplace tail decays as e^{-|x|/\sigma \cdot \sqrt{2}} rather than e^{-x^2/(2\sigma^2)}, placing P(|X - \mu| > 3\sigma) = e^{-3\sqrt{2}} \approx 1.43\% beyond 3\sigma vs. 0.27\% for a Gaussian (5.3\times heavier):
b, m =1.0, 200000lap = rng.choice([-1.0, 1.0], m) * rng.exponential(b, m) # S * Esigma = math.sqrt(2) * b # matched sdgau = rng.normal(0.0, sigma, m)print(f'sample variances: Laplace {lap.var(ddof=1):.2f}, 'f'Gaussian {gau.var(ddof=1):.2f} (2b^2 = 2)')print(f'P(|X| > 3 sd): Laplace {np.mean(np.abs(lap) >3* sigma):.4f}, 'f'Gaussian {np.mean(np.abs(gau) >3* sigma):.4f}')
Why squared loss is sensitive to outliers: On a 10\sigma outlier, Gaussian NLL incurs penalty \frac{1}{2}(10)^2 = 50, whereas Laplace NLL incurs 10\sqrt{2} \approx 14.1 with a bounded constant gradient \pm 1/b.
The Multivariate Gaussian and Eigen-Ellipsoids
Geometry of Correlated Random Vectors
A vector \mathbf{x} \sim \mathcal{N}(\boldsymbol{\mu}, \boldsymbol{\Sigma}) in \mathbb{R}^d with symmetric positive definite covariance \boldsymbol{\Sigma} \succ \mathbf{0} has density: p(\mathbf{x}) = \frac{1}{(2\pi)^{d/2}|\boldsymbol{\Sigma}|^{1/2}}\exp\!\left(-\frac{1}{2}(\mathbf{x}-\boldsymbol{\mu})^\top\boldsymbol{\Sigma}^{-1}(\mathbf{x}-\boldsymbol{\mu})\right)
Spectral diagonalization: Writing \boldsymbol{\Sigma} = \mathbf{V}\mathrm{diag}(\gamma_1, \dots, \gamma_d)\mathbf{V}^\top and rotating to \mathbf{u} = \mathbf{V}^\top(\mathbf{x} - \boldsymbol{\mu}) decouples the exponent into independent 1D Gaussians: (\mathbf{x}-\boldsymbol{\mu})^\top\boldsymbol{\Sigma}^{-1}(\mathbf{x}-\boldsymbol{\mu}) = \sum_{i=1}^d \frac{u_i^2}{\gamma_i}
Running example \boldsymbol{\Sigma} = \begin{pmatrix}2&1\\1&2\end{pmatrix}: Eigenvectors \mathbf{v}_{1,2} = \frac{1}{\sqrt{2}}(1, \pm 1)^\top have eigenvalues \gamma_1 = 3, \gamma_2 = 1(45^\circ ellipse with half-axes \propto \sqrt{3} : 1).
Linear Maps and the Cholesky Reparameterization
Affine Closure & Sampling Correlated Vectors
Proposition (Affine Closure): If \mathbf{x} \sim \mathcal{N}(\boldsymbol{\mu}, \boldsymbol{\Sigma}) in \mathbb{R}^d and \mathbf{A} \in \mathbb{R}^{m \times d} has full row rank m \le d, then
Sampling via Cholesky factorization (\boldsymbol{\Sigma} = \mathbf{L}\mathbf{L}^\top): Draw standard normal noise \mathbf{z} \sim \mathcal{N}(\mathbf{0}, \mathbf{I}_d) and set \mathbf{x} = \boldsymbol{\mu} + \mathbf{L}\mathbf{z}, where \mathbf{L} is lower triangular (\mathbf{L}\mathbf{I}\mathbf{L}^\top = \boldsymbol{\Sigma}). For \boldsymbol{\Sigma} = \begin{pmatrix}2&1\\1&2\end{pmatrix}, \mathbf{L} = \begin{pmatrix}\sqrt{2} & 0 \\ 1/\sqrt{2} & \sqrt{3/2}\end{pmatrix}.
The VAE reparameterization trick: Because \mathbf{x} = \boldsymbol{\mu} + \mathbf{L}\mathbf{z} is differentiable with respect to \boldsymbol{\mu} and \mathbf{L} for fixed \mathbf{z}, gradients backpropagate cleanly through stochastic Gaussian layers.
L = [[1.414, 0.0], [0.707, 1.225]]
sample covariance = [[1.99, 0.99], [0.99, 1.99]]
its eigenvalues = [1. 2.99]
Conditioning a Gaussian Is Linear Regression
The Orthogonal Residual Trick & Schur Complement
Partition \mathbf{x} = (\mathbf{x}_1, \mathbf{x}_2) with mean (\boldsymbol{\mu}_1, \boldsymbol{\mu}_2) and block covariance \boldsymbol{\Sigma} = \begin{pmatrix}\boldsymbol{\Sigma}_{11} & \boldsymbol{\Sigma}_{12} \\ \boldsymbol{\Sigma}_{21} & \boldsymbol{\Sigma}_{22}\end{pmatrix}. Choose the regression matrix \mathbf{B} = \boldsymbol{\Sigma}_{12}\boldsymbol{\Sigma}_{22}^{-1} so the residual \mathbf{r} = \mathbf{x}_1 - \mathbf{B}\mathbf{x}_2 is uncorrelated with \mathbf{x}_2:
Cov(r, x2) = -0.003, Var(r) = 1.499
4091 samples with x2 near 2: mean of x1 0.97, variance 1.52
Concept Check: Poisson Waits, CLT & Conditioning
Check Your Understanding
Test your intuition on three calculations from the distribution catalog:
Poisson counts vs. exponential waits: Requests arrive at a Poisson rate of \lambda = 4 per minute. What is the probability of a silent minute (0 requests), and what is the probability of waiting more than 30 seconds (t = 0.5\text{ min}) for the next request?
Bivariate Gaussian conditioning: Let (X_1, X_2) be jointly Gaussian with mean \mathbf{0}, unit variances \Sigma_{11} = \Sigma_{22} = 1, and correlation \rho \in (-1, 1). What is the conditional distribution X_1 \mid X_2 = x_2?
Why joint Gaussianity matters: If Z \sim \mathcal{N}(0, 1) and S \in \{\pm 1\} is a fair random sign, both Z and Y = SZ are marginally \mathcal{N}(0, 1) with \mathrm{Cov}(Y, Z) = 0. Why isn’t Y \mid Z = 2 distributed as \mathcal{N}(0, 1)?
Answers:
P(N(1) = 0) = \mathbf{e^{-4} \approx 0.0183}. Waiting more than t = 0.5\text{ min} is the event N(0.5) = 0, which has probability e^{-4(0.5)} = \mathbf{e^{-2} \approx 0.1353}.
Here B = \Sigma_{12}\Sigma_{22}^{-1} = \rho, so X_1 \mid X_2 = x_2 \sim \mathcal{N}(\rho x_2,\ 1 - \rho^2). Notice that the conditional variance 1 - \rho^2 never depends on the observed value x_2.
(Y, Z) is not jointly Gaussian (all mass sits on the two lines y = \pm z). Given Z = 2, Y can only take values +2 or -2 with probability 1/2 each.