Sums of Continuous Variables
For continuous variables the convolution sum becomes an integral. If and are independent with densities and , then has density
Two uniforms make a triangle
For uniform on , the integrand is 1 when both and . The overlap has length for and for :
a triangle. Adding a third uniform gives a piecewise quadratic, already quite bell-shaped (the Irwin–Hall densities).
import random
rng = random.Random(1)
n = 200_000
for k in [1, 2, 3, 12]:
sums = [sum(rng.random() for _ in range(k)) for _ in range(n)]
hist = [0] * 10
for s in sums:
hist[min(int(s / k * 10), 9)] += 1
print(f"k={k:2d}: " + " ".join(f"{h / n:.3f}" for h in hist))k= 1: 0.099 0.101 0.100 0.099 0.101 0.101 0.099 0.100 0.100 0.101
k= 2: 0.020 0.060 0.100 0.141 0.178 0.179 0.140 0.100 0.060 0.020
k= 3: 0.004 0.031 0.086 0.162 0.217 0.215 0.163 0.086 0.031 0.005
k=12: 0.000 0.000 0.007 0.109 0.384 0.383 0.109 0.008 0.000 0.000
The rows show the distribution of the sum rescaled to , in 10 bins. One uniform is flat; two make a triangle; twelve are already very close to a normal curve. The sum of 12 uniforms minus 6 has mean 0 and variance , an old trick for generating approximately standard normal numbers.
Exponentials sum to gamma
The sum of independent exponentials with rate has the gamma density (Gamma, Beta and Chi-Squared). For two exponentials the convolution integral is short:
from sympy import symbols, integrate, exp, simplify
x, z = symbols("x z", positive=True)
lam = symbols("lambda", positive=True)
f = lam * exp(-lam * x)
h2 = simplify(integrate(f * lam * exp(-lam * (z - x)), (x, 0, z)))
print("two exponentials:", h2)
h3 = simplify(integrate(h2.subs(z, x) * lam * exp(-lam * (z - x)), (x, 0, z)))
print("three exponentials:", h3)two exponentials: lambda**2*z*exp(-lambda*z)
three exponentials: lambda**3*z**2*exp(-lambda*z)/2
Normals sum to normals
If and are independent, then . Completing the square in the convolution integral proves it; moment generating functions prove it in one line. This stability is special: the normal is the fixed point that sums of many independent variables converge to.
The Cauchy surprise
The average of independent Cauchy variables has the same Cauchy distribution as one of them. Averaging does not help at all, because the Cauchy has no mean (Expectation for Densities). Convolution confirms what the running averages showed: heavy tails do not average out.
import math
import random
rng = random.Random(2)
cauchy = lambda: math.tan(math.pi * (rng.random() - 0.5))
for n in [1, 10, 100]:
avgs = [sum(cauchy() for _ in range(n)) / n for _ in range(20_000)]
inside = sum(abs(a) < 1 for a in avgs) / len(avgs)
print(f"average of {n:3d} Cauchy samples: P(|avg| < 1) = {inside:.3f}")
print("for a single Cauchy: P(|X| < 1) = 0.5")average of 1 Cauchy samples: P(|avg| < 1) = 0.499
average of 10 Cauchy samples: P(|avg| < 1) = 0.505
average of 100 Cauchy samples: P(|avg| < 1) = 0.500
for a single Cauchy: P(|X| < 1) = 0.5
In software
Sums of continuous variables model total delays in a pipeline, total measurement error, and aggregated risk. Noise added in differential privacy is often Laplace or Gaussian, and the privacy analysis of many noisy queries is a statement about sums of these. Kernel density estimates are themselves convolutions of the data with a smoothing kernel.
Exercises
Exercise 1: Triangle probability
For the sum of two uniforms on , find and .
Answer
and .
Solution
. By symmetry about 1, .
Exercise 2: Variance of the sum
What are the mean and variance of the sum of 12 independent uniforms on ?
Answer
Mean 6, variance 1.
Solution
Each has mean and variance ; both add over independent terms.
Exercise 3: Sum of uniforms on different ranges (code)
Simulate with uniform on and uniform on , and compare and with the exact values and .
Answer
Simulated values near 0.25 and 0.75; the density is a trapezoid.
Solution
The joint density is on the rectangle . is a triangle of area times ; is area times .
import random
rng = random.Random(3)
n = 200_000
s = [rng.random() + rng.uniform(0, 2) for _ in range(n)]
print(round(sum(v <= 1 for v in s) / n, 4), round(sum(v <= 2 for v in s) / n, 4))0.2487 0.7498
Test yourself
The sum of two independent uniforms on has which density?
- Uniform on
- Triangular on
- Exponential
- Normal
The average of 100 independent Cauchy variables has…
- a normal distribution
- the same Cauchy distribution as one variable
- variance 1/100
- a point mass at 0