A1126 of 55
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

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 n independent exponential variables, each with mean 1, against the Gaussian with the same mean n and variance n.
  • For n=1 the two look nothing alike. By n = 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?

Name it

The moment generating function

MX(s)=E[esX]

defined for the real s where the expectation is finite. Expanding esX=1+sX+s2X2/2!+⋯ shows where the name comes from:

MX(0)=1MX′(0)=E[X]MX′′(0)=E[X2]

so Var(X)=M′′(0)−M′(0)2. (With s=jω it's the characteristic function, essentially the Fourier transform of the density, which always exists.)

Sums become products

If X and Y are independent, E[es(X+Y)]=E[esX]E[esY], so

MX+Y(s)=MX(s)MY(s)

and a generating function determines its distribution, so recognizing the product identifies the sum.

A short table

DistributionM(s)
Gaussian, mean μ, variance σ2eμs+σ2s2/2
Poisson, mean λeλ(es−1)
Exponential, rate λλλ−s for s<λ
Bernoulli, P(1)=p1−p+pes

So sums of independent Gaussians are Gaussian (means and variances add), sums of independent Poissons are Poisson, and a sum of n independent exponentials with rate λ has M=(λ/(λ−s))n: the Erlang distribution, the waiting time for the nth arrival of a Poisson process (lesson 13), with tail

P(T>t)=e−λt∑k=0n−1(λt)kk!

Why sums turn Gaussian

For a variable with mean 0 and variance 1, ln⁡M(s)=s2/2+O(s3). The sum of n independent copies, scaled by 1/n, has ln⁡M=nln⁡M(s/n)=s2/2+O(1/n), which approaches s2/2, 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
  1. Differentiate the generating function. M(s)=λλ−s M′(s)=λ(λ−s)2 M′′(s)=2λ(λ−s)3
  2. Set s=0. E[X]=1λ E[X2]=2λ2
  3. Variance. Var(X)=2λ2−1λ2=1λ2
  4. What it means. The standard deviation equals the mean, the exponential's signature spread.

Answer the mean is 1/λ and the variance 1/λ2.

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
  1. The total's distribution. Each stage has λ = 0.5 per ms, so the total's generating function is (0.50.5−s)3 an Erlang with n=3.
  2. Mean and spread. The mean is 6 ms and the variance 3×4=12ms2 so the standard deviation is 3.46 ms.
  3. Tail beyond 10 ms. With λt = 5, P(T>10)=e−5(1+5+252)=18.5e−5=0.125
  4. 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
  1. Multiply the generating functions. e2(es−1)e3(es−1)=e5(es−1) so the total is Poisson with mean 5.
  2. Exactly 5 photons. P(5)=55e−55!=0.175
  3. 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 M(s)=e1s+0.5s2/2. What is E[X2], from M′′(0)?

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 M(s)=λ/(λ−s).

(a)

What is its mean, M′(0)?

(b)

What is its variance, M′′(0)−M′(0)2?

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 esT at s = 0.5 (below the rate), M_exact to (λ/(λ−s))n, and var_est to the sample variance of the sums, to compare with n/λ2.

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, M(s)=∫0∞esxλe−λxdx, for s<λ.

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°.

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.

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.