Probability Generating Functions
A distribution on is a sequence of probabilities, and sequences can be packed into power series, as in Generating Functions. The resulting probability generating function (PGF) turns convolution into multiplication and moments into derivatives.
Definition
For a random variable with values in :
The coefficients are the probabilities. Key properties:
- ;
- and , so ;
- sums: if and are independent, .
The last property is the main point: the messy convolution of Sums of Discrete Variables becomes a product.
| Distribution | PGF |
|---|---|
| Bernoulli() | |
| Binomial(, ) | |
| Poisson() | |
| Geometric() on | |
| Fair die |
Moments by differentiation
from sympy import symbols, exp, diff, simplify, Rational, expand
s, lam, p = symbols("s lambda p", positive=True)
q = 1 - p
for name, G in [("Poisson", exp(lam * (s - 1))), ("Geometric", p * s / (1 - q * s))]:
m1 = simplify(diff(G, s).subs(s, 1))
m2 = simplify(diff(G, s, 2).subs(s, 1))
print(f"{name}: mean = {m1}, variance = {simplify(m2 + m1 - m1 ** 2)}")
die = sum(s ** k for k in range(1, 7)) / 6
two = expand(die ** 2)
print("two dice PGF coefficients (x36):", [two.coeff(s, k) * 36 for k in range(2, 13)])Poisson: mean = lambda, variance = lambda
Geometric: mean = 1/p, variance = (1 - p)/p**2
two dice PGF coefficients (x36): [1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1]
Squaring the die's PGF lists the familiar counts 1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1 for sums 2 to 12.
Sums of Poissons, in one line
For independent Poissons, : the sum is Poisson(). And since a PGF determines its distribution, nothing more needs checking.
Sicherman dice
Can two dice with different labels give the same distribution of sums as two ordinary dice? Factor the PGF: . Regrouping the factors of the square differently gives dice labelled and , the Sicherman dice.
from sympy import symbols, factor, expand
from itertools import product
from collections import Counter
s = symbols("s")
print(factor(sum(s ** k for k in range(1, 7))))
a = [1, 2, 2, 3, 3, 4]
b = [1, 3, 4, 5, 6, 8]
normal = Counter(x + y for x, y in product(range(1, 7), repeat=2))
sicherman = Counter(x + y for x, y in product(a, b))
print("same sum distribution:", normal == sicherman)s*(s + 1)*(s**2 - s + 1)*(s**2 + s + 1)
same sum distribution: True
Random sums
If is independent of the i.i.d. , the random sum has PGF
Composition of PGFs. Differentiating at gives Wald's identity (Conditional Expectation). This composition rule is the key to branching processes.
In software
PGFs give exact distributions for sums in dice and board games, error counts in coding theory, and the number of collisions in hashing. Computer algebra systems (SymPy, Mathematica) extract coefficients exactly; numerically, polynomial multiplication via FFT computes the same thing quickly.
Exercises
Exercise 1: Identify the distribution
A random variable has PGF . What is its distribution, mean and variance?
Answer
Binomial(5, 2/3): mean , variance .
Solution
It matches with , ; , .
Exercise 2: Coin until heads, twice
What is the PGF of the number of tosses of a fair coin needed for two heads?
Answer
.
Solution
It is a sum of two independent geometric(1/2) waiting times, so the PGF is the square of .
Exercise 3: Three dice (code)
Use the PGF to find the probability that three dice sum to 10, and the full list of counts.
Answer
.
Solution
from sympy import symbols, expand
s = symbols("s")
G3 = expand(sum(s ** k for k in range(1, 7)) ** 3)
counts = [G3.coeff(s, k) for k in range(3, 19)]
print(counts)
print(G3.coeff(s, 10), "of", sum(counts))[1, 3, 6, 10, 15, 21, 25, 27, 27, 25, 21, 15, 10, 6, 3, 1]
27 of 216
Test yourself
If and are independent, the PGF of is…
How do you get from the PGF?