The distributions a practitioner needs from Bernoulli to the Gaussian, and the family they belong to.
A family, not a list
Motivation
Fourteen distributions cover almost everything in practice, and they connect: Bernoulli is the seed; construction and limit arrows grow the rest; conjugate priors close the tree, all inside one envelope.
One coin flip: P(X=1)=p, P(X=0)=1-p. Because X^2 = X, both moments collapse instantly: \mathbb E[X]=p, \operatorname{Var}(X)=p(1-p).
import numpy as onprng = onp.random.default_rng(0)p =0.3sample =1* (rng.random((3, 3)) < p) # 1 with prob p, else 0big =1* (rng.random(10000) < p) # large sample for the meanprint('pmf P(0), P(1) =', (1- p, p))print('mean of 10,000 draws =', float(big.mean()), ' (≈ p)')sample
pmf P(0), P(1) = (0.7, 0.3)
mean of 10,000 draws = 0.3006 (≈ p)
array([[0, 1, 1],
[1, 0, 0],
[0, 0, 0]])
Every binary classifier outputs a Bernoulli; its negative log-likelihood is binary cross-entropy.
Categorical: softmax in disguise
Discrete
K outcomes with P(X=k)=p_k. A network produces the p_k from logits through the softmax p_k = e^{z_k}/\sum_j e^{z_j}, and the NLL is exactly cross-entropy.
import numpy as onprng = onp.random.default_rng(0)z = onp.array([2.0, 1.0, 0.1, -1.0]) # logits over K = 4 classesp_cat = onp.exp(z) / onp.exp(z).sum() # softmax -> categoricaldraw =int(rng.choice(len(p_cat), p=p_cat))print('categorical p =', p_cat.round(3), ' sum =', float(p_cat.sum()))print('one sample -> class', draw)
categorical p = [0.638 0.235 0.095 0.032] sum = 1.0
one sample -> class 0
The Gumbel-max trick samples a categorical exactly; its soft version makes discrete choices differentiable.
The discrete gallery
Discrete
Four laws in one picture, mass on the integers:
Uniform spreads mass evenly (\mu=\tfrac{n+1}{2}); the others concentrate it where events are likely.
Binomial: moments for free
Discrete
A Binomial is a sum of n Bernoullis, X=\sum_i X_i, so linearity and independence hand us the moments with no algebra:
mean 1/lambda = 2.0 sample mean = 2.001
var 1/lambda^2 = 4.0 sample var = 3.984
The only memoryless continuous law (converse: Exercise 4); the continuous partner of the Poisson, and the source of X=-\log U/\lambda sampling.
Gaussian: the CLT limit
Continuous
Standardized sums of any iid finite-variance terms converge to the Gaussian. Watch universality happen, starting from the least Gaussian summand available, the flat, hard-edged uniform:
n=1 is a plateau, n=2 a triangle; by n=32 the sum is indistinguishable from \mathcal N(0,1) at this resolution. Nothing in the code knows about the Gaussian: summation manufactures it. (It is also the maximum-entropy law for fixed mean and variance.)
The normalizer: a polar trick
Continuous
Why \sqrt{2\pi}? Recall from the integral-calculus chapter: square the integral and switch to polar coordinates,
Contours are ellipsoids: axes along the eigenvectors of \boldsymbol\Sigma, half-lengths \propto\sqrt{\lambda_i}. Isotropy = spheres = independent coordinates. Sampling is the Cholesky recipe: \boldsymbol\Sigma=\mathbf L\mathbf L^\top, \mathbf x=\boldsymbol\mu+\mathbf L\mathbf z.
Conditional mean is linear in \mathbf x_2; the Schur-complement covariance is the entire engine of Gaussian-process regression.
In high dimension, the Gaussian is a thin shell
Continuous
\|\mathbf x\|^2 sums d independent mean-1 terms, so it concentrates near d: the mass lives in a shell of radius \approx\sqrt d, far from the origin where the density is pointwise largest; and two independent draws are nearly orthogonal, cosine \sim 1/\sqrt d:
d = 3: ||x||/sqrt(d) = 0.920 ± 0.378, mean |cos(x,y)| = 0.497
d = 30: ||x||/sqrt(d) = 0.992 ± 0.127, mean |cos(x,y)| = 0.145
d = 300: ||x||/sqrt(d) = 1.000 ± 0.039, mean |cos(x,y)| = 0.046
Load-bearing facts: 1/\sqrt dinitialization keeps \|\mathbf{Wx}\|\approx\|\mathbf x\|; cosine similarity is informative because unrelated vectors sit near 0; nearest-neighbor contrast fades. Exponential tail bounds arrive in the concentration-and-generalization section.
Base measure h, natural parameters\boldsymbol\eta, sufficient statistics T, log-partition A. Bernoulli (\eta=\operatorname{logit}p, A=\operatorname{softplus}), Poisson (\eta=\log\lambda), and Gaussian all fit.
Two exclusions, two reasons: the uniforms stay outside because their support moves with the parameters; Cauchy and Student-t do not admit a fixed finite-dimensional sufficient statistic for their usual unknown location-and-scale families. They therefore lack the standard finite-dimensional conjugate update, and their negative log-likelihoods are not generally convex.
Where the form comes from
Unification
Maximize entropy H_h[p] subject to fixed averages \mathbb E[T(\mathbf x)] = \boldsymbol\tau. The Lagrange multipliers are the natural parameters, and the maximizer is exactly p\propto h\,e^{\boldsymbol\eta^\top T}.
The exponential family is the least-committal family consistent with a chosen set of expected statistics.
The moment property
Unification
Differentiating the log-partition recovers the moments:
dA/deta = 0.668188
sigmoid(eta) = E[x] = p = 0.668188
04
Conjugate priors
Beta · Gamma · Dirichlet: updating is counting
Beta–Bernoulli: pseudo-counts
Priors
A \text{Beta}(\alpha,\beta) prior times a Bernoulli likelihood with x heads in n flips gives a \text{Beta}(\alpha+x,\beta+n-x) posterior; \alpha,\beta act as phantom heads and tails: