A11 · Lesson 26 · Moment generating functions
One function that holds every moment, and turns sums into products
Lesson 25 found the distribution of a sum of independent variables by convolving their densities, which is hard work beyond two or three terms. A total delay through three exponential queues, the count from two independent Poisson sources, the noise from many small contributions: each is a sum. There's a transform that turns convolution into multiplication, just as the Fourier and Laplace transforms do for signals: the moment generating function. It also produces a variable's mean, variance and every other moment by differentiation, and it's the cleanest way to see why sums tend toward the Gaussian.
- The curves are the density of the sum of independent exponential variables, each with mean 1, against the Gaussian with the same mean and variance .
- For the two look nothing alike. By = 20 they nearly coincide: the central limit theorem, which the generating function explains.
Predict
Two independent sources each emit a Poisson number of photons per millisecond, with means 2 and 3. What is the distribution of the total?
Poisson with mean 5. A Poisson variable's generating function is ; multiplying two of them gives , which is the generating function of a Poisson with mean 5. The convolution exists, but the generating functions answer the question without doing it.
Name it
The moment generating function
defined for the real where the expectation is finite. Expanding shows where the name comes from:
so . (With it's the characteristic function, essentially the Fourier transform of the density, which always exists.)
Sums become products
If and are independent, , so
and a generating function determines its distribution, so recognizing the product identifies the sum.
A short table
| Distribution | |
|---|---|
| Gaussian, mean , variance | |
| Poisson, mean | |
| Exponential, rate | for |
| Bernoulli, |
So sums of independent Gaussians are Gaussian (means and variances add), sums of independent Poissons are Poisson, and a sum of independent exponentials with rate has : the Erlang distribution, the waiting time for the th arrival of a Poisson process (lesson 13), with tail
Why sums turn Gaussian
For a variable with mean 0 and variance 1, . The sum of independent copies, scaled by , has , which approaches , the standard Gaussian's. Every distribution with a finite variance loses its other features under addition; that's lesson 16's central limit theorem.
Worked example
Find the mean and variance of an exponential variable with rate from its generating function.
Show the solution
- Differentiate the generating function.
- Set .
- Variance.
- What it means. The standard deviation equals the mean, the exponential's signature spread.
Answer the mean is and the variance .
Worked example
A packet passes three independent stages, each taking an exponential time with mean 2 ms. What's the mean and standard deviation of the total, and the chance it exceeds 10 ms?
Show the solution
- The total's distribution. Each stage has = 0.5 per ms, so the total's generating function is an Erlang with .
- Mean and spread. The mean is 6 ms and the variance so the standard deviation is 3.46 ms.
- Tail beyond 10 ms. With = 5,
- Compare with a Gaussian. One packet in eight takes more than 10 ms; a Gaussian with the same mean and spread would say 0.124, already close at only three stages.
Answer the total has a mean of 6 ms and a standard deviation of 3.46 ms, and exceeds 10 ms with chance 0.125.
Worked example
Two independent Poisson sources emit 2 and 3 photons per millisecond on average. What is the chance of exactly 5 photons in a millisecond?
Show the solution
- Multiply the generating functions. so the total is Poisson with mean 5.
- Exactly 5 photons.
- The long way. Without the generating function this would be a sum of six products of Poisson probabilities, which gives the same 0.175 with much more work.
Answer the chance of exactly 5 photons is 0.175.
Check
A Gaussian variable has . What is , from ?
Check
A task passes 2 independent exponential stages, each with mean 2 ms. What's the chance the total exceeds 20 ms?
Check
Independent Poisson counts have means 2 and 0.5. What's the chance their sum equals 6?
Check
An exponential variable has rate 2, so .
(a)
What is its mean, ?
(b)
What is its variance, ?
Check
Draw 400 000 sums of n = 2 independent exponentials with rate lam = 1, using rng = np.random.default_rng(1) and rng.exponential(1 / lam, (400000, n)).sum(axis=1). Set M_est to the sample mean of at s = 0.5 (below the rate), M_exact to , and var_est to the sample variance of the sums, to compare with .
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Derive the exponential's generating function, , for .
Step 1
Combine the exponentials. What is the integrand?
Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.
Step 2
Integrate from 0 to ∞. What is ?
Check
Why is the generating function of a sum of independent variables the product of their generating functions?
Explain why
A sum of many small independent noises looks Gaussian whatever the individual noises look like. Use generating functions to explain why.
Each noise, scaled to mean 0 and variance 1, has a log generating function that starts plus higher powers of that depend on its shape. Summing of them and dividing by multiplies their generating functions and scales by , so the log of the result is copies of plus higher terms that each shrink as or faster. The parts add to exactly , the Gaussian's, while everything that distinguished the individual shapes fades. Only the mean and variance survive the summing.
Practice
Keep practicing
7 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.