Continuous Distributions

Every shape in this lesson can start from one flat random number between 0 and 1. Read a curve backwards, and the number 0.975 becomes 1.96 under the bell curve and 3.69 under a waiting time with mean 1.

Pick a shape and press play. Watch each pink uniform number hit the curve and drop into the pile (blue), which settles onto the density (warm). Then drag u. Then we build, piece by piece, fourteen distributions from area, sums, waits and bent axes.

You need what a probability is, basic Python and the idea of area under a curve. We build the rest from zero.

Turn flat numbers into shapes

0.975

Simulated in your browser with a fixed seed, illustrative. The curves are exact. The Cauchy panel shows only the middle of the line; its outputs far outside land in the end bars.

Chapter 0

Probability Is Area

Shade an interval under the curve to get its chance, and see that a single point gets none

A lidar measures the distance to a wall 1,000 times. The readings scatter around the truth by a few centimetres. The error can be 0.031 m, 0.0312 m, or anything between. Outcomes that fill a whole interval are continuous.

What is the chance that the error is exactly 0.03 m? It is 0. No single value out of infinitely many can hold probability. So a continuous distribution gives probability to intervals, not to points.

It does this with a probability density function, or PDF, written f(x). It is a curve over the number line. The chance of landing between two numbers is the area under the curve between them. The whole area is 1.

Call the random error X, and the ends of the interval a and b.

Say it aloud

P of a at most X at most b equals the integral from a to b of f of x, d x.

P(a ≤ X ≤ b)
P of a at most X at most b the chance that the error lands between a and b, a number from 0 to 1.
∫ab
the integral from a to b the area under the curve between a and b: cut it into thin strips and add them.
f(x)
f of x the density at x: probability per metre of error. It can be larger than 1.
dx
d x the width of one thin strip. Height f(x) times width dx is the chance of that strip.
In plain words

Cut the stretch from a to b into thin strips. Each strip has height f(x) and width dx, so its chance is f(x) times dx. Add the strips. The total is the chance that X lands between a and b.

With numbers

With made-up numbers: the lidar error is Gaussian with a spread of 0.1 m. Its density at 0 is 3.99 per metre. The strip from −0.005 to 0.005 m has width 0.01 m, so its chance is about 3.99 × 0.01 = 0.0399. The exact area is 0.0399 too.

Shade an interval

Top: the density of the lidar error (warm) with your interval in teal. Bottom: the CDF. Shrink the width and watch the area go to 0 while the height stays put.

0.00 m
0.10 m

Exact areas of a Gaussian with mean 0 and spread 0.1 m. The lidar is a made-up example. No simulation.

The running area from the far left up to x is the cumulative distribution function, or CDF, written F(x) = P(X ≤ x). Any interval is the difference of two CDF heights: P(a ≤ X ≤ b) = F(b) − F(a). A point has no area, so ≤ and < give the same answer here. In the discrete lesson they did not.

Failure: reading a density as a chance.

Symptom: a model reports a log-likelihood of +1.38 per reading. Someone files a bug, because the log of a probability cannot be positive.

Measure: the density at 0 is 3.99 per metre, and ln 3.99 = 1.38. Measured in centimetres, the same density is 0.0399 per cm, and its log is −3.22.

Fix: densities carry units. Compare likelihoods only in the same units. To get a chance, multiply by a width or take an area.

  1. Quantiles: read the CDF backwards, and turn flat numbers into any shape (the hero).
  2. Gaussian: many small pushes add up to a bell.
  3. Exponential: a wait with no memory, and the Weibull for parts that wear.
  4. Gamma: add several waits; the chi-squared and the inverse-Gamma come with it.
  5. Beta: a distribution over a chance, updated by counting.
  6. Transforms: bend the axis and keep the area: log-normal and Rayleigh.
  7. Heavy tails: Student-t, Laplace, and a Cauchy whose average never settles.
  8. Showcase: name the distribution behind six data sets, including compass headings.
  9. The field guide: every formula, convention and link in one place.
A density f equals 2.5 at x = 0.4. What is P(X = 0.4)?

Chapter 1

Read the CDF Backwards

Turn a chance into a value with the quantile function, and turn flat numbers into any shape

A motor fails at a random time. Its maker says the mean life is 500 hours. You want the age by which half the motors have failed, and the age by which 5% have. Both questions give a chance and ask for a value. That is the CDF read backwards.

The quantile function F−1(u) takes a chance u between 0 and 1. It returns the value x where the CDF reaches u. The median is F−1(0.5). The 95th percentile is F−1(0.95).

The simplest continuous shape is the uniform distribution on an interval from a to b, written Uniform(a, b). Its density is flat at 1/(b − a), so the area is 1. Its mean is the midpoint (a + b)/2 and its variance is (b − a)2/12. Glorot initialisation draws the weights of a layer with 256 inputs and 128 outputs from Uniform(−0.125, 0.125). Their variance is 0.252/12 = 0.0052.

Uniform(0, 1) is the raw material of every sampler. Call one draw from it U. Call the CDF you want F.

Say it aloud

X equals F inverse of U.

X
X the output: a random value with the shape you want.
F−1
F inverse the quantile function: give it a chance, it returns the value where the CDF F reaches that chance.
U
U a uniform random number between 0 and 1, the input.
In plain words

Draw U. Find the height U on the CDF F. Read off the x below that point. That x is one draw of X. It works because F only goes up, so P(X ≤ x) = P(U ≤ F(x)) = F(x).

With numbers

The motor's CDF is F(x) = 1 − e−x/500. Solve U = F(x) for x: X = −500 ln(1 − U). U = 0.5 gives 346.6 hours. U = 0.05 gives 25.6 hours.

Read it backwards

The warm curve is the CDF. Drag u (pink) and follow the path to the value below. The 40 evenly spaced chances on the left land in blue ticks: they crowd where the density is high.

0.50

Exact quantiles. We made up the motor and the lidar.

The motor's median, 347 hours, sits well below its mean of 500. A few motors that run for thousands of hours pull the mean up. The hero uses this same move: each pink number is a U, and the curve it hits is F.

Failure: the scale went in as the shift.

Symptom: the median motor life prints as 500.7 hours.

Measure: stats.expon(500).mean() returns 501.0. SciPy read 500 as loc, a shift, and kept the scale at 1.

Fix: name it: stats.expon(scale=500). Its median is 346.6 and its mean 500.

Motor life is exponential with mean 500 hours. By what age have 5% of motors failed?

Chapter 2

Many Small Pushes Make a Bell

Add many small independent effects and watch any shape turn into the Gaussian

Many small effects push each lidar reading: heat in the diode, jitter in the clock, dust on the lens. No single push dominates. Add many small, independent pushes, and the total takes one shape, whatever each push looks like. That is the central limit theorem, or CLT.

Add more pushes

Each blue bar counts sums of n draws, shifted and scaled to mean 0 and spread 1. The yellow outline is the Gaussian. Raise n, then switch to the skewed source.

1

8,000 seeded sums per setting, illustrative. The outline is the exact standard Gaussian.

The shape is the Gaussian, or normal, distribution. Two numbers set it. Call its centre the mean μ, said "mu". Call its spread the standard deviation σ, said "sigma"; its square σ2 is the variance. We write N(μ, σ2).

Say it aloud

f of x equals one over sigma root two pi, times e to the minus, x minus mu squared, over two sigma squared.

f(x)
f of x the density of the Gaussian at the value x.
1/(σ√(2π))
one over sigma root two pi the height at the peak. It makes the total area 1, so a narrow bell is tall.
e−(x − μ)2/(2σ2)
e to the minus distance squared over two sigma squared the bell. It is 1 at the mean μ and falls fast as x moves away in steps of σ.
In plain words

Measure how far x is from the mean μ, in units of σ. Square it, halve it, and take e to the minus that. Multiply by the peak height 1/(σ√(2π)).

With numbers

With made-up numbers: lidar error with μ = 0 and σ = 0.1 m. At x = 0 the bell factor is 1, so f(0) = 1/(0.1 × 2.507) = 3.99 per metre. At x = 0.2 m, two σ away, the factor is e−2 = 0.135, so f = 0.54.

Some shares are worth knowing. 68.3% of a Gaussian lies within one σ of the mean, 95.4% within two, and 99.73% within three. For the lidar, an error larger than 0.3 m has chance 0.0027: about 1 reading in 370.

Why this formula? Among all distributions with a given mean and variance, the Gaussian has the largest entropy: it assumes nothing more. Kalman filters assume Gaussian noise for this reason, and VAEs (variational autoencoders) use it as their prior.

Failure: trusting the bell in the tail.

Symptom: sums of 10 exponential waits land more than 2 standard deviations above their mean 3.7% of the time. The Gaussian says 2.3%.

Measure: pick the skewed source with n = 10 and read the tail share. The exact share, from the Gamma of Chapter 4, is 3.69%. At 3 standard deviations it is 0.67% against 0.13%.

Fix: for skewed parts, ask tail questions of the exact distribution of the sum, not of the bell.

Lidar error is N(0, 0.12) in metres. About what share of errors lie between −0.2 m and 0.2 m?

Chapter 3

Waiting With No Memory

Fail at a steady rate, and the past stops mattering; let parts wear, and it matters again

A motor fails at random, at a steady rate, with no wear. Call the failure rate λ, said "lambda": failures per hour. A mean life of 500 hours means λ = 1/500. The time X until it fails has an exponential distribution. Its density is λe−λx for x ≥ 0, and its mean is 1/λ.

The chance it is still running after t hours is the survival function S(t) = P(X > t) = e−λt. P(X > 700) = e−1.4 = 0.247.

Now take a motor that has already run s hours. What is the chance it runs t more?

Say it aloud

P of X greater than s plus t, given X greater than s, equals e to the minus lambda times s plus t, over e to the minus lambda s. That equals e to the minus lambda t.

P(X > s + t | X > s)
P of X greater than s plus t, given X greater than s the chance of t more hours for a motor aged s hours. The bar "|" reads "given".
e−λ(s + t) / e−λs
S of s plus t over S of s survive to s + t, as a share of those that survived to s.
e−λt
e to the minus lambda t the survival chance of a new motor over t hours. The age s has cancelled.
In plain words

Of the motors alive at age s, count the share still alive at s + t. Divide the two survival chances. The powers subtract, s drops out, and the answer depends on t alone.

With numbers

With made-up numbers: λ = 1/500 per hour, s = 500, t = 700. e−2.4 / e−1 = 0.0907 / 0.368 = 0.247. A new motor gets the same 0.247.

Age the motor

The warm curve is the chance of lasting t more hours for a motor that has run s hours. The yellow outline is a new motor. All three shapes have a mean life of 500 hours. Drag the age.

500 h

Exact survival curves, made-up motors. We set each Weibull scale so every shape has a mean life of 500 hours.

The exponential is the only continuous distribution with no memory (Blitzstein and Hwang, Theorem 5.5.3). It is the continuous partner of the geometric. It is also the gap between events in a Poisson stream: requests at 5 a minute arrive with exponential gaps of mean 0.2 minutes.

Real parts wear. The Weibull distribution adds a shape number k: S(t) = e−(t/η)k, with a scale η ("eta"). k = 1 is the exponential. Take k = 2 and a mean of 500 hours. A motor aged 500 hours then has a 2.4% chance of 700 more; a new one has 21%. With k below 1, early failures dominate and survivors get safer.

Failure: no memory for parts that wear.

Symptom: a fleet plans on 500 more hours from every motor, at every age. After 500 hours, motors fail in bunches.

Measure: with a Weibull k = 2 and mean 500 hours, a 500-hour-old motor has 230 hours left on average, not 500.

Fix: fit a Weibull to the lifetimes and check k against 1 before you use the exponential.

An exponential motor with mean life 500 hours has run 1,000 hours. How many more hours does it expect?

Chapter 4

Add the Waits

Add k exponential waits to get the Gamma, then find the chi-squared inside it

Requests reach a server at 5 a minute, at random. The wait for the first one is exponential with mean 0.2 minutes. How long until the third? The third arrival comes after three independent waits, added.

Call the number of waits k, the shape. Call the mean of one wait θ, said "theta", the scale. The sum of k exponential waits has a Gamma distribution, Gamma(k, θ).

Say it aloud

f of x equals x to the k minus one, times e to the minus x over theta. Divide all that by gamma of k times theta to the k.

f(x)
f of x the density of the total wait x, for x > 0.
xk − 1
x to the k minus one the rise: k − 1 arrivals must fit before x, and there is more room for them as x grows.
e−x/θ
e to the minus x over theta the fall: a long total wait is unlikely, as for one wait.
Γ(k)
gamma of k the gamma function: (k − 1)! for a whole number k, and smooth between. It makes the area 1.
θk
theta to the k fixes the units of x, so the area stays 1.
In plain words

The density rises like x to the k minus 1, because there must be room for k − 1 earlier arrivals. It falls like e to the minus x over θ, because long waits are rare. Γ(k) θk scales the curve to area 1.

With numbers

k = 3, θ = 0.2 min, x = 0.4 min: 0.42 = 0.16, e−2 = 0.135, Γ(3) = 2, 0.23 = 0.008. So f(0.4) = 0.16 × 0.135 / 0.016 = 1.35 per minute, the peak of the curve.

Wait for the k-th request

Top: one stream of requests (teal), with the k-th ringed. Bottom: the time to the k-th request over 3,000 streams (blue) and the Gamma density (warm). The pink line is 1 minute.

3

Seeded streams at 5 requests a minute, illustrative. The density and the tail chance are exact.

Mean and variance come from adding the waits: mean kθ and variance kθ2. For the third request the mean is 0.6 minutes and the standard deviation 0.35. The chance of waiting more than a minute is 0.125. Check it another way: the third request is late exactly when at most 2 arrive in the first minute. That Poisson(5) chance is e−5(1 + 5 + 12.5) = 0.125.

Two famous members. The chi-squared distribution χ2(n) is the sum of n squared standard Gaussians, and equals Gamma(n/2, 2), with mean n. Sums of squared standardised residuals follow it: with 10 of them, values above 18.31 happen 5% of the time. If X is Gamma, then 1/X is inverse-Gamma, the usual prior on a variance; Bayesian Distributions uses it.

Failure: the rate went in as the scale.

Symptom: the wait for the third request comes out at 15 minutes on average.

Measure: stats.gamma(3, scale=5).mean() returns 15.0. The rate, 5 a minute, went in where the scale belongs.

Fix: scale = 1/rate: stats.gamma(3, scale=0.2) has mean 0.6. Write the form next to every Gamma.

What is Gamma(1, θ)?

Chapter 5

A Distribution Over a Chance

Put a density on a success rate between 0 and 1, and update it by counting hits and misses

A robot gripper works 14 times in 20 tries. Its true success rate p is unknown, somewhere between 0 and 1. You want a distribution for p itself: how likely is 0.6, or 0.9? That needs a density that lives on 0 to 1.

The Beta distribution has two shape numbers, α ("alpha") and β ("beta"). Think of α − 1 as hits you have seen and β − 1 as misses. Beta(1, 1) is flat: it is Uniform(0, 1). The mean is α/(α + β).

Say it aloud

f of p equals p to the alpha minus one, times one minus p to the beta minus one, over B of alpha and beta.

f(p)
f of p the density of the unknown success rate at the value p, for p from 0 to 1.
pα − 1
p to the alpha minus one one factor of p per hit counted: high rates explain many hits.
(1 − p)β − 1
one minus p to the beta minus one one factor of 1 − p per miss counted: low rates explain many misses.
B(α, β)
B of alpha and beta the beta function, a constant that makes the area 1.
In plain words

Each hit pulls the curve toward 1 through p, and each miss pulls it toward 0 through 1 − p. Where the pulls balance, at (α − 1)/(α + β − 2), the curve peaks. B(α, β) scales it to area 1.

With numbers

Beta(15, 7): the peak is at 14/20 = 0.70. The mean is 15/22 = 0.682. The area above p = 0.8 is 0.109.

Now the update. The prior is your belief before data: Beta(α, β). You then see s hits and m misses. By the binomial, the chance of that data is proportional to ps(1 − p)m. Multiply the prior by it:

pα − 1(1 − p)β − 1 × ps(1 − p)m = pα + s − 1(1 − p)β + m − 1 that is Beta(α + s, β + m)

The posterior, the belief after data, is Beta again. A prior whose posterior stays in its family is conjugate.

Count the grasps

Warm: the flat prior. Purple: the posterior after your grasps. The shaded area is the chance that the rate is above 0.8. Add grasps one at a time, or load 14 of 20.

Exact Beta curves and areas. The gripper is a made-up example.

With 14 of 20, 95% of the posterior lies between 0.48 and 0.85: twenty tries pin down little. Bandits use these curves. Thompson sampling draws one rate from each arm's Beta and plays the arm with the largest draw. The Dirichlet extends the Beta to K categories, in Multivariate Distributions.

Failure: a bell for a rate near 0.

Symptom: 2 of 20 grasps work. The usual estimate, plus or minus 1.96 standard errors, gives −0.03 to 0.23: negative rates are inside.

Measure: a Gaussian with mean 0.1 and standard error 0.067 puts 6.8% of its area below 0.

Fix: use the Beta posterior, Beta(3, 19). 95% of it lies between 0.030 and 0.304, all inside 0 to 1.

The prior is Beta(2, 2). You see 3 hits and 1 miss. What is the posterior?

Chapter 6

Bend the Axis, Keep the Area

Push a known shape through a function, and correct the density by how much the axis stretches

Request latencies are positive and skewed: most are near 100 ms, a few take 600. Their logarithm, though, looks like a bell. If X is Gaussian, then Y = eX is log-normal. Products of many positive factors become log-normal, because the log turns a product into a sum, and the CLT takes over.

To get Y's density, follow one thin strip. Call the input value x and its density fX. A function bends the axis and sends x to y. A strip of width dx at x lands as a strip of width dy at y, and it holds the same probability. So fY(y) dy = fX(x) dx.

Say it aloud

f Y of y equals f X of x, times the absolute value of d x over d y.

fY(y)
f Y of y the density of the output, at the value y.
fX(x)
f X of x the density of the input, at the x that maps to y.
|dx/dy|
the absolute value of d x over d y the Jacobian: how much input width fits in one unit of output width. Where the axis stretches, the density thins.
In plain words

Find the input x that lands on y. Take its density fX(x). Multiply by how many units of x fit into one unit of y. The probability in the strip stays the same; only its width changes.

With numbers

With made-up numbers: ln of latency is N(ln 100, 0.82). For y = 100 ms, x = ln 100 = 4.61 and fX(x) = 1/(0.8 × 2.507) = 0.499. Here dx/dy = 1/y = 0.01. So fY(100) = 0.0050 per ms.

Push a bell through a function

Left: the input. Right: the outputs (blue) and the density from the rule above (warm). Turn on "Forget the Jacobian" to see the curve you get without |dx/dy|.

0.8

4,000 seeded inputs, illustrative. We made up the latency and GPS numbers; the curves are exact.

For the log-normal with μ = ln 100 and σ = 0.8, the median is eμ = 100 ms, because the log keeps the order. The mean is eμ + σ2/2 = 137.7 ms: the long right tail pulls it up. 8.5% of requests take over 300 ms.

The same rule gives the Rayleigh distribution. A GPS fix has independent Gaussian errors east and north, each with σ = 3 m. The miss distance R has density (r/σ2) e−r2/(2σ2). The factor r comes from the circle: a ring at radius r has length 2πr, so tiny misses are rare. P(R < 5 m) = 1 − e−25/18 = 0.751, and the mean miss is 3.76 m.

Failure: forgetting the Jacobian.

Symptom: a latency model built as fX(ln y) has a total area of 137.7, not 1.

Measure: the area of fX(ln y) over all y equals the average of eX, which is eμ + σ2/2 = 137.7.

Fix: multiply by |dx/dy| = 1/y. The toggle in the device draws the bad curve in red.

ln of a latency is N(ln 100, 0.82). What is the median latency?

Chapter 7

When the Average Never Settles

Give big values real probability, and watch the mean stop working

A lidar usually errs by a few centimetres. Sometimes a beam bounces off glass and reads 3 m long. In our simulation, one such glitch among 21 readings moves the average by 14 cm and the median by 1 cm. A Gaussian calls a 3 m error impossible. Data with glitches need a heavy-tailed distribution, whose density falls slowly, so big values keep real probability.

The standard one is Student's t. Take a standard Gaussian Z, with mean 0 and σ = 1. Take an independent chi-squared V with ν degrees of freedom, said "nu".

Say it aloud

T equals Z over the square root of V over nu.

T
T a Student-t variable with ν degrees of freedom.
Z
Z a standard Gaussian draw: the signal.
√(V/ν)
root V over nu a noisy estimate of the spread. V is chi-squared with ν degrees of freedom, so V/ν averages 1 but wobbles. When it comes out small, T gets big.
In plain words

Divide a Gaussian draw Z by a spread that you only estimate. Sometimes the estimate is too small, and the ratio T shoots out. Those shots are the heavy tails. Larger ν means a steadier estimate and lighter tails.

With numbers

ν = 3: suppose Z = 1.0 and V comes out 0.3. Then V/ν = 0.1, its root is 0.316, and T = 3.16. A Gaussian lands beyond 5 with chance 0.00006%; the t with ν = 3 does it 1.5% of the time.

Watch the running mean

Top: each draw as a blue dot; triangles mark draws off the scale. Bottom: the running mean (purple) and the centre 0 (yellow). Draw 1,000 from each shape.

Seeded draws, illustrative. Tail chances are exact.

At ν = 1 the t is the Cauchy, whose mean does not exist: the integral for it diverges. The average of n Cauchy draws is again Cauchy, with the same spread. No number of samples settles it. As ν grows, the t becomes the Gaussian.

The t also handles small samples. Five lap times, 12.1, 11.8, 12.4, 12.0 and 11.9 s, have mean 12.04 s and sample standard deviation 0.230 s. The spread comes from only 5 values, so the 95% interval uses t with 4 degrees of freedom. It is 12.04 ± 2.776 × 0.230/√5: from 11.75 to 12.33 s. The Gaussian's 1.96 would claim more certainty than the data holds.

A middle case is the Laplace, with density e−|x − μ|/b/(2b). Its log is minus an absolute value, so fitting it is L1 regression, and its best centre is the median. A Laplace prior on weights gives the lasso.

Failure: a Gaussian likelihood with glitches.

Symptom: one 3 m glitch moves a 21-reading average by 14 cm.

Measure: compare the mean with the median. At 15 standard units, the Gaussian density is 5.5 × 10−50 and the Cauchy density 0.0014.

Fix: use the median, or fit a Student-t likelihood, which treats glitches as rare but possible.

You average 1,000 Cauchy draws. How does the spread of that average compare with one draw?

Chapter 8

Name the Distribution Behind the Data

Read the story, check where the values can live, fit, and compare the curves

Real data comes without a label. You get 400 numbers and a story. Three questions narrow the choice:

  1. Where can the values live? The whole line points to the Gaussian, the t or the Laplace. Positive amounts point to the exponential, Weibull, Gamma or log-normal. Rates between 0 and 1 point to the Beta. Angles point to the von Mises.
  2. What made them? Many small pushes give a bell. A wait at a steady rate gives the exponential; wear gives the Weibull. A sum of waits gives the Gamma, and a product of factors the log-normal.
  3. Does the fit match? Fit each candidate by maximum likelihood: choose the parameters that make the data most probable. Then compare the average log density and look at the tails.

Angles need care. Compass headings live on a circle, so 359° and 1° are 2° apart. A Gaussian on raw degrees splits a cluster near north into two piles. The von Mises distribution wraps around: its density is proportional to eκ cos(θ − μ), with a mean direction μ and a concentration κ ("kappa"). With κ = 5, 74% of headings fall within 30° of the mean.

Fit the data

Pick a data set and read its story. Then pick a candidate. Blue bars are the data; the purple curve is the fitted candidate.

Each data set is 400 values we simulated with a fixed seed from a known distribution, so the right answer is known. The fits are maximum likelihood with scipy.stats, computed ahead of time.

Two cases need a second look. For the third request, the Gamma beats the Weibull by only 0.003 per value. The data alone barely decide, but the story says "a sum of three waits". For clean lidar noise, the t fit picks ν = 26, which is a Gaussian in all but name.

Failure: fitting a line to a circle.

Symptom: a Gaussian fit to headings clustered around north gives a mean of 177°, almost due south, where there is no data.

Measure: its spread is 158°, and its average log density is −6.48 against −4.75 for the von Mises.

Fix: treat angles as points on a circle. Fit a von Mises, or average the sines and cosines, not the degrees.

Your data are wind directions, clustered around 350° to 10°. Which candidate do you try first?

Chapter 9

The Field Guide

Keep the stories, the formulas and the library conventions in one place

Every shape here comes from a story: area, a sum, a wait, a count of hits, a bent axis, or a noisy spread. Find the story and the support first. Then fit and look at the tails.

DistributionStorySupportMeanVariance
Uniform(a, b)No preference in a range[a, b](a + b)/2(b − a)2/12
Gaussian N(μ, σ2)Many small pushes addedall realsμσ2
Exponential(λ)Wait at a steady ratex ≥ 01/λ1/λ2
Weibull(k, η)Life with wear (k > 1) or early failures (k < 1)x ≥ 0ηΓ(1 + 1/k)η2[Γ(1 + 2/k) − Γ(1 + 1/k)2]
Gamma(k, θ)Sum of k waitsx > 0kθkθ2
Chi-squared χ2(n)Sum of n squared standard Gaussiansx > 0n2n
Inverse-Gamma(α, β)1 over a Gamma; prior on a variancex > 0β/(α − 1), α > 1β2/((α − 1)2(α − 2)), α > 2
Beta(α, β)Belief about a rate[0, 1]α/(α + β)αβ/((α + β)2(α + β + 1))
Log-normal(μ, σ)Product of many factorsx > 0eμ + σ2/2(eσ2 − 1)e2μ + σ2
Rayleigh(σ)Length of a 2-D Gaussian errorr ≥ 0σ√(π/2)(4 − π)σ2/2
Student-t(ν)Gaussian over an estimated spreadall reals0, ν > 1ν/(ν − 2), ν > 2
Cauchy(x0, γ)t with ν = 1; ratio of two Gaussiansall realsnonenone
Laplace(μ, b)Sharp peak, L1 errorsall realsμ2b2
Von Mises(μ, κ)Bell on a circleanglesdirection μcircular: 1 − I1(κ)/I0(κ)

How they connect

Corrections to the old version of this page

The core as code

pythonimport numpy as np
from scipy import stats

# SciPy: every family takes loc (shift) and scale; name them.
# expon(scale=1/rate); gamma(a=k, scale=theta); weibull_min(c=k, scale=eta);
# lognorm(s=sigma, scale=exp(mu)); t(df=nu); vonmises(kappa) works in radians.
stats.norm(0, 0.1).pdf(0)                       # 3.99 per metre: a density, not a chance
2 * stats.norm(0, 0.1).sf(0.3)                   # 0.0027
stats.expon(scale=500).median()                  # 346.6 hours
stats.gamma(3, scale=0.2).sf(1)                  # 0.125
stats.beta(15, 7).sf(0.8)                       # 0.109
stats.lognorm(0.8, scale=100).mean()              # 137.7 ms
stats.rayleigh(scale=3).cdf(5)                   # 0.751
stats.t.ppf(0.975, df=4)                          # 2.776

def sample(ppf, n, rng=np.random.default_rng(0)):
    """Inverse transform: push uniform numbers through the quantile function."""
    return ppf(rng.random(n))

x = sample(lambda u: -500 * np.log1p(-u), 100_000)    # motor lives, mean about 500

def best_fit(x, names=("norm", "t", "expon", "weibull_min", "gamma", "lognorm")):
    """Maximum likelihood fit of each candidate; higher average log density is better."""
    out = {}
    for name in names:
        d = getattr(stats, name)
        if name in ("norm", "t"):
            p = d.fit(x)
        elif x.min() > 0:
            p = d.fit(x, floc=0)                       # positive families start at 0
        else:
            continue
        out[name] = np.mean(d(*p).logpdf(x))
    return sorted(out.items(), key=lambda kv: -kv[1])

Keep going

The takeaway. Probability is area. Find the story (a sum, a wait, a rate, a product, a noisy spread, an angle) and where the values can live. Then fit, and check the tails before you trust the mean.

Now press Present or Teach and explain four things from memory. Explain why a density of 3.99 is not a chance. Explain why X = F−1(U) has CDF F. Explain why the exponential forgets the past. Explain why the Jacobian keeps the area at 1. Then go back to the hero, pick the Cauchy, and watch where the pink numbers near 0 and 1 land.

Continuous Distributions
Next: Multivariate Distributions · Back to Gleams