Skip to main content

Probability Distributions

The distribution of a random variable describes how probability is spread over its possible values. Two random variables with the same distribution behave identically from a probabilistic point of view, even if they come from different experiments. A crit indicator on a d20 and a biased coin that lands heads 5% of the time have the same distribution.

Most distributions used in practice belong to a few families, each indexed by a small number of parameters. We write X∼Normal(μ,σ2)X \sim \text{Normal}(\mu, \sigma^2) to say that XX follows the normal distribution with parameters μ\mu and σ2\sigma^2.

info

This chapter covers

  • probability mass functions for discrete random variables and probability density functions for continuous ones,
  • the discrete families Bernoulli, binomial, categorical and Poisson,
  • the continuous families uniform, normal, beta and Student's t,
  • the multivariate normal distribution, and
  • a summary table of where each family appears in the ML and RL notes.

Probability Mass Functions​

A discrete random variable XX is described by its probability mass function (PMF), p(x)=Pr⁡(X=x)p(x) = \Pr(X = x). A function is a valid PMF exactly when its values are non-negative and add up to one over all possible values,

p(x)≥0for all x,∑xp(x)=1.p(x) \ge 0 \quad \text{for all } x, \qquad \sum_{x} p(x) = 1.

The probability of any event is the sum of the PMF over the values in it, Pr⁡(X∈A)=∑x∈Ap(x)\Pr(X \in A) = \sum_{x \in A} p(x), and the CDF from chapter 1 is the running sum F(x)=∑x′≤xp(x′)F(x) = \sum_{x' \le x} p(x').

Probability Density Functions​

A continuous random variable XX is described by a probability density function (PDF) ff, whose area over an interval gives the probability that XX falls in it,

Pr⁡(a≤X≤b)=∫abf(x) dx.\Pr(a \le X \le b) = \int_a^b f(x) \, dx.

A function is a valid PDF exactly when it is non-negative and its total area is one,

f(x)≥0for all x,∫−∞∞f(x) dx=1.f(x) \ge 0 \quad \text{for all } x, \qquad \int_{-\infty}^{\infty} f(x) \, dx = 1.

The density is the derivative of the CDF, f(x)=F′(x)f(x) = F'(x), and for a small width Δx\Delta x the probability of landing near xx is approximately f(x) Δxf(x) \, \Delta x. A density is therefore not a probability, and it can be larger than one. The uniform distribution on [0,0.5][0, 0.5] has density 22 everywhere on that interval, and its total area is still 0.5×2=10.5 \times 2 = 1.

Discrete Distributions​

Bernoulli​

The Bernoulli distribution describes a single trial with two outcomes, success (X=1X = 1) with probability pp and failure (X=0X = 0) with probability 1−p1 - p. Its PMF is

Pr⁡(X=k)=pk(1−p)1−k,k∈{0,1}.\Pr(X = k) = p^k (1-p)^{1-k}, \qquad k \in \{0, 1\}.

The crit indicator CC from chapter 1 is Bernoulli(0.05)\text{Bernoulli}(0.05). In machine learning, logistic regression models a binary label as a Bernoulli random variable whose pp depends on the input.

Binomial​

The binomial distribution counts the successes in nn independent Bernoulli trials with the same success probability pp. Independent means that the result of one trial doesn't change the probabilities of the others. There are (nk)\binom{n}{k} ways to place kk successes among nn trials, each with probability pk(1−p)n−kp^k (1-p)^{n-k}, so

Pr⁡(X=k)=(nk)pk(1−p)n−k,k=0,1,…,n.\Pr(X = k) = \binom{n}{k} p^k (1-p)^{n-k}, \qquad k = 0, 1, \dots, n.

The number of critical hits in 20 attack rolls is Binomial(20,0.05)\text{Binomial}(20, 0.05). The probability of at least one crit is 1−Pr⁡(X=0)=1−0.9520≈0.641 - \Pr(X = 0) = 1 - 0.95^{20} \approx 0.64, so a full evening of combat without a single crit isn't that unusual.

Categorical​

The categorical distribution generalizes the Bernoulli to KK outcomes. The random variable XX takes a value in {1,…,K}\{1, \dots, K\}, and a vector of probabilities π=(π1,…,πK)\boldsymbol{\pi} = (\pi_1, \dots, \pi_K) gives

Pr⁡(X=k)=πk,πk≥0,∑k=1Kπk=1.\Pr(X = k) = \pi_k, \qquad \pi_k \ge 0, \quad \sum_{k=1}^K \pi_k = 1.

A fair d20 is categorical with πk=1/20\pi_k = 1/20 for every face. Softmax regression outputs a categorical distribution over classes, and in RL a stochastic policy π(a∣s)\pi(a \mid s) over a finite set of actions is a categorical distribution for each state (see Markov Decision Processes). Counting how often each outcome occurs in nn categorical trials gives the multinomial distribution, which relates to the categorical the way the binomial relates to the Bernoulli.

Poisson​

The Poisson distribution counts events in a fixed interval of time or space, when events occur independently of each other at a constant average rate λ\lambda. Its PMF is

Pr⁡(X=k)=λke−λk!,k=0,1,2,…\Pr(X = k) = \frac{\lambda^k e^{-\lambda}}{k!}, \qquad k = 0, 1, 2, \dots

The number of random encounters during a day of travel, or of emails you receive in an hour, are classic examples. The Poisson is also the limit of the binomial for rare events. If nn is large and p=λ/np = \lambda / n is small, Binomial(n,p)\text{Binomial}(n, p) is close to Poisson(λ)\text{Poisson}(\lambda). Poisson regression uses it to model counts.

Continuous Distributions​

Uniform​

The uniform distribution on [a,b][a, b] spreads probability evenly over the interval,

f(x)={1b−aif a≤x≤b,0otherwise.f(x) = \begin{cases} \frac{1}{b-a} & \text{if } a \leq x \leq b, \\ 0 & \text{otherwise.} \end{cases}

Random number generators produce Uniform(0,1)\text{Uniform}(0, 1) values, and samplers for every other distribution, including the ones in these interactives, start from them. Shrink the interval below a width of one to see the density rise above one.

Normal​

The normal (or Gaussian) distribution is the bell curve,

f(x)=1σ2πexp⁡(−(x−μ)22σ2),f(x) = \frac{1}{\sigma \sqrt{2\pi}} \exp\left(-\frac{(x-\mu)^2}{2\sigma^2}\right),

where μ\mu sets the center and σ>0\sigma > 0 sets the spread. About 68% of the probability lies within one σ\sigma of μ\mu, 95% within two and 99.7% within three. The standard normal has μ=0\mu = 0 and σ=1\sigma = 1, and any normal random variable can be standardized to it with Z=(X−μ)/σZ = (X - \mu)/\sigma.

The normal shows up so often because averages of many independent quantities are approximately normal, which is the central limit theorem. The ML notes use it to model the noise in linear regression, and the RL notes use it for policies over continuous actions in policy gradient methods.

Beta​

The beta distribution lives on [0,1][0, 1], which makes it a natural way to describe uncertainty about an unknown probability. With shape parameters α,β>0\alpha, \beta > 0,

f(x)=xα−1(1−x)β−1B(α,β),0≤x≤1,f(x) = \frac{x^{\alpha - 1} (1 - x)^{\beta - 1}}{B(\alpha, \beta)}, \qquad 0 \le x \le 1,

where B(α,β)=Γ(α)Γ(β)/Γ(α+β)B(\alpha, \beta) = \Gamma(\alpha)\Gamma(\beta)/\Gamma(\alpha + \beta) makes the area equal to one. With α=β=1\alpha = \beta = 1 it is the uniform distribution. The mean is α/(α+β)\alpha / (\alpha + \beta), and the larger α+β\alpha + \beta is, the more concentrated the distribution becomes.

If you suspect that a d20 is loaded but don't know by how much, a beta distribution can describe your belief about its crit chance. A later chapter on Bayesian inference updates that belief with each roll, and the same idea drives Thompson sampling for bandits.

Student's t​

The Student's t distribution with ν\nu degrees of freedom has density

f(x)=Γ(ν+12)νπ Γ(ν2)(1+x2ν)−ν+12.f(x) = \frac{\Gamma \left(\frac{\nu+1}{2}\right)}{\sqrt{\nu \pi} \, \Gamma \left(\frac{\nu}{2}\right)} \left(1 + \frac{x^2}{\nu}\right)^{-\frac{\nu+1}{2}}.

It is bell-shaped and centered at zero like the standard normal, but with heavier tails, and it approaches the standard normal as ν\nu grows. It appears when a sample mean is standardized with the sample's own standard deviation instead of the true one, which is the basis of confidence intervals and t-tests in the planned inference chapters.

Multivariate Normal​

Many quantities in ML are vectors, such as the weights of a model or the coordinates of a data point. A random vector X∈Rd\mathbf{X} \in \mathbb{R}^d follows the multivariate normal distribution N(μ,Σ)\mathcal{N}(\boldsymbol{\mu}, \boldsymbol{\Sigma}) when its density is

f(x)=1(2π)d/2det⁡(Σ)1/2exp⁡(−12(x−μ)⊤Σ−1(x−μ)).f(\mathbf{x}) = \frac{1}{(2\pi)^{d/2} \det(\boldsymbol{\Sigma})^{1/2}} \exp\left(-\frac{1}{2} (\mathbf{x} - \boldsymbol{\mu})^\top \boldsymbol{\Sigma}^{-1} (\mathbf{x} - \boldsymbol{\mu})\right).

The mean vector μ\boldsymbol{\mu} sets the center, and the covariance matrix Σ\boldsymbol{\Sigma}, which must be symmetric and positive definite, sets the spread along each direction and how the coordinates move together. Points of equal density form ellipses (ellipsoids in higher dimensions). When Σ\boldsymbol{\Sigma} is diagonal the ellipses line up with the axes and the coordinates are independent, and when Σ=σ2I\boldsymbol{\Sigma} = \sigma^2 \mathbf{I} they are circles. The probabilistic interpretation of linear regression uses this distribution for the vector of targets.

Summary​

The mean and variance columns are defined in the next chapter.

DistributionValuesParametersMeanVarianceWhere it appears
Bernoulli{0,1}\{0, 1\}ppppp(1−p)p(1-p)Binary labels, logistic regression
Binomial{0,…,n}\{0, \dots, n\}n,pn, pnpnpnp(1−p)np(1-p)Counting successes
Categorical{1,…,K}\{1, \dots, K\}π1,…,πK\pi_1, \dots, \pi_KSoftmax regression, stochastic policies
Poisson{0,1,2,… }\{0, 1, 2, \dots\}λ\lambdaλ\lambdaλ\lambdaCount data, Poisson regression
Uniform[a,b][a, b]a,ba, ba+b2\frac{a+b}{2}(b−a)212\frac{(b-a)^2}{12}Random number generation
NormalR\mathbb{R}μ,σ2\mu, \sigma^2μ\muσ2\sigma^2Regression noise, Gaussian policies, the CLT
Beta[0,1][0, 1]α,β\alpha, \betaαα+β\frac{\alpha}{\alpha+\beta}αβ(α+β)2(α+β+1)\frac{\alpha\beta}{(\alpha+\beta)^2(\alpha+\beta+1)}Beliefs about probabilities, Thompson sampling
Student's tR\mathbb{R}ν\nu00 for ν>1\nu > 1νν−2\frac{\nu}{\nu-2} for ν>2\nu > 2Confidence intervals, t-tests

The categorical's outcomes are labels rather than quantities, so its mean and variance are usually not used.

1. A player makes 20 attack rolls with a fair d20. Which distribution describes the number of critical hits?

2. Which statement about a probability density function ff is true?

3. What happens to Student's t distribution as the degrees of freedom ν\nu grow?

What's Next​

The summary table lists a mean and a variance for each family. Expectation, Variance, and Covariance defines these quantities and the rules for computing them.