Generating functions, cumulants and the characteristic function
Sums of independent variables are convolutions; transforms turn them into products. Study probability, moment and cumulant generating functions, including the convexity behind Chernoff bounds, and the characteristic function, which always exists, determines the law and proves the central limit theorem.
After this lesson you can
Calculate PGFs, MGFs, cumulants and characteristic functions for the catalogued distributions.
Find laws of independent and random sums using products of transforms.
Prove convexity of the cumulant generating function and relate its derivatives to mean and variance.
State uniqueness and inversion for characteristic functions and apply inversion numerically using FFT.
Explain when an MGF does not exist and when moments do not determine the law.
Adding independent random variables is the most frequent operation in applied probability: the total error of an ensemble, the aggregate loss of a portfolio, the tokens spent in a multi-turn conversation, or the noise accumulated step by step by a diffusion model (each step of the forward process adds an independent Gaussian to the image). It is also an awkward operation. The law of S=X1+X2 is not obtained pointwise: it is a convolution,
and with n summands it must be repeated n−1 times. The probability that ten dice sum to 35 comes from nine chained convolutions (it is 0.0727, which we will calculate in two ways). If n is a parameter, random, or enormous, what you want is a formula rather than an algorithm.
You already know a school-level trick. When two polynomials are multiplied, their coefficients are convolved. If GA(s)=∑kpksk is the polynomial whose coefficients are the probabilities of A, and GB the one for B, then the coefficient of sm in GA(s)GB(s) is ∑kpkqm−k, exactly P(A+B=m) when A and B are independent. The law of a sum is a product of polynomials. Evaluating the polynomial at s=eit keeps the product valid, and each G(eit) is a complex number: multiplying complex numbers multiplies their moduli and adds their angles. The figure makes this visible. Edit the two laws and check that the product of the blue and aqua curves is, for each t, the magenta curve of the sum.
InteractiveConvolution on the left, product on the right
Law: convolution
Transform: product, with t∈[0,2π]
φA(t)
φB(t)
φA+B (from the sum pmf); arrow: φAφB
Examples
∣φA∣∣φB∣ = ∣φA+B∣0.435 × 0.838 = 0.365
argφA+argφB97.5° + −6.2° ≡ 91.4°
maximum ∣φA+B−φAφB∣ on [0,2π]6.8e−16
E of A, B and A + B1.70 + 2.00 = 3.70
Var of A, B and A + B1.21 + 5.20 = 6.41
A and B are laws on {0,…,5} that can be edited by dragging the bars (remaining or missing mass is distributed among the others). Below is the law of A+B, calculated by convolution. On the right, for t∈[0,2π], are the curves φA(t)=∑kpkeitk and φB(t) in the complex plane, and the curve of φA+B, calculated only from the pmf of the sum. The arrows show the three values at the selected t: the magenta arrow is the product of the other two, with modulus ∣φA∣∣φB∣ and angle argφA+argφB. The error readout compares φA+B, calculated from the sum's pmf, with φAφB at 49 values of t: what remains is floating-point rounding. With “Atom + law”, multiplication by φ=e3it rotates the curve.
This lesson turns the trick into a theory. There are four transforms of a law, each with its own strength, and all four send convolution to multiplication:
For X taking values in {0,1,2,…}, the series ∑kpksk with pk=P(X=k) is a power series whose coefficients sum to 1, and its value at s is the expectation of sX (which exists without assumptions on X, since sX≤1 when ∣s∣≤1).
It converges absolutely for ∣s∣≤1 because ∑kpk=1, so its radius of convergence is at least 1.
Proof
(1) follows from ∑pk=1 and uniform convergence on [0,1] of a power series with nonnegative coefficients. (2) A power series with positive radius of convergence can be differentiated term by term, and its coefficients are its derivatives at 0 divided by k! (the Taylor polynomial of a power series is the series itself). (3) For s∈[0,1), G(r)(s)=∑k≥rk(k−1)⋯(k−r+1)pksk−r, with all terms nonnegative and increasing in s; by monotone convergence, the limit as s↑1 is ∑kk(k−1)⋯(k−r+1)pk. Taking r=2 and E[X2]=G′′(1)+G′(1) gives the variance. (4) If X⊥⊥Y, then sX⊥⊥sY for each fixed s (measurable functions of independent variables), and the expectation of a product of independent variables is the product of their expectations: E[sX+Y]=E[sX]E[sY].
∎
Uniqueness is proved here in one line using the coefficients of a power series, whereas uniqueness for the characteristic function will require a Fourier analysis argument. This is the advantage of working with coefficients.
Examples that calculate themselves. A Bernoulli variable with parameter p has G(s)=1−p+ps; by property 4, a sum of n independent Bernoulli variables has G(s)=(1−p+ps)n, whose coefficients are binomial by the binomial theorem: the binomial is the law of that sum without calculating a single convolution. For the Poisson,
G(s)=k∑e−μk!μksk=eμ(s−1),
and hence, if independent X∼Poisson(μ1) and Y∼Poisson(μ2), then GX+Y(s)=e(μ1+μ2)(s−1): X+Y∼Poisson(μ1+μ2). Differentiation gives G′(1)=μ and G′′(1)=μ2, so Var(X)=μ2+μ−μ2=μ.
Random sums
In the conditional expectation lesson you calculated the mean and variance of S=ξ1+⋯+ξN with random N. The PGF gives the entire law.
Proof
Condition on N, as in the previous lesson: E[sS]=∑nP(N=n)E[sξ1+⋯+ξn]=∑nP(N=n)H(s)n=GN(H(s)), where the second equality uses property 4 n times.
∎
The chain rule recovers what you already knew: E[S]=GN′(1)H′(1)=E[N]E[ξ] and, differentiating twice, Var(S)=E[N]Var(ξ)+Var(N)E[ξ]2. But there is more. If N∼Poisson(λ), then GS(s)=exp(λ(H(s)−1)): this is the compound Poisson, the law of aggregate loss from a Poisson number of claims, which reappears as a compound Poisson process. And if each ξi is Bernoulli(p) (each Poisson event is retained with probability p), H(s)=1−p+ps and GS(s)=exp(λp(s−1)): thinning a Poisson(λ) with probability p produces a Poisson(λp), the key result of superposition and thinning, in two lines.
Branching processes and extinction
A Galton-Watson process starts with one individual, Z0=1, and each individual in generation n has a number of offspring with law (pk)k≥0, independent of one another and of previous generations. It describes surnames becoming extinct, chains of infection, particle cascades and the growth of search trees, measured by the effective branching factor. The natural question is: what is the probability of extinction?
The next generation’s size is a random sum, Zn+1=ξ1+⋯+ξZn, so if G is the PGF of the number of offspring and Gn that of Zn, the previous theorem gives Gn+1=Gn∘G, that is, Gn=G∘G∘⋯∘G (n times). The probability of extinction by generation n is P(Zn=0)=Gn(0), and the probability of eventual extinction is q=limnGn(0), the limit of an increasing sequence of events.
Proof
Let sn=Gn(0)=P(Zn=0). Then sn+1=G(sn), the sequence is increasing (the events {Zn=0} increase) and has limit q. Because G is continuous on [0,1], q=G(q): it is a root. If r∈[0,1] is another root, since G is increasing and s0=0≤r, induction gives sn≤r for every n (from sn≤r follows sn+1=G(sn)≤G(r)=r), so q≤r: it is the smallest.
For the second part, G is convex on [0,1] (a sum of convex functions pksk), and strictly convex if pk>0 for some k≥2. If m≤1, the tangent at s=1, 1+m(s−1), lies below G and above the diagonal (m≤1 and s−1≤0), so G(s)>s for every s<1 (equality would require G to be affine, i.e. pk=0 for k≥2, and then m=p1<1 gives G(s)−s=p0(1−s)>0): 1 is the only root. If m>1, G(1−h)=1−mh+o(h)<1−h for small h, so G(s)−s<0 near 1, while G(0)−0=p0≥0: continuity gives a root in [0,1), and q<1.
∎
The figure animates the proof. The sequence sn is the staircase between the curve y=G(s) and the diagonal; it converges to their first intersection. The tangent at (1,1) has slope m: when m crosses 1, a second intersection appears (the critical value m=1 is the phase transition).
InteractiveExtinction probability: iterating the PGF
y=G(s)
y=s
tangent at (1,1), slope m
staircase Gn(0)
smallest root q of G(s)=s
Probability of extinction by generation n
Number of offspring
n = 25
regimesupercritical, m = 1.50
extinction probability q0.4172
P(Zn=0)=Gn(0) at current n0.4172
survival probability 1−q0.5828
p0,p1,p2,p30.22, 0.33, 0.25, 0.13
With m>1, curve G meets the diagonal at q<1: the process never becomes extinct with probability 1−q.
The blue curve is y=G(s) for an offspring law with mean m; the dashed line is the diagonal, and the tangent at (1,1) has slope m. The magenta staircase starts at s0=0 and applies sn+1=G(sn): sn is P(Zn=0), the probability of extinction by generation n. On the right, sn rises with n toward the smallest root q of G(s)=s (red circle on the left, dashed red line on the right). Move m across 1: below it, the curve is above the diagonal and q=1; above it a root smaller than 1 appears and the population never dies out with probability 1−q. Near m=1 the staircase barely advances: critical extinction is extremely slow. Change the family while keeping m fixed: q depends on the entire shape of G on [0,1], but whether q<1 or q=1 is decided by m alone.
This idea goes further than it may seem. The threshold m=1 separates a cascade that dies out from one that spreads, and the same structure governs gradient propagation in a very deep network with critical initialization, the R0 of an epidemic, or the branching structure of a Hawkes process.
Moment generating function
The PGF only works for integer-valued variables. For a real variable X, replace sX with eλX, which is the same when s=eλ, and evaluate at every real λ.
Since eλX>0, the expectation is always defined, although it may be +∞. Always 0∈DX with MX(0)=1. If λ1<λ<λ2 belong to the domain, eλx≤eλ1x+eλ2x implies λ∈DX: the domain is an interval containing 0. Nearly all the useful properties occur when 0 is an interior point, that is, when M is finite on (−a,b) for a,b>0.
Proof
Fix λ0∈(−a,b) and δ>0 with [λ0−2δ,λ0+2δ]⊂(−a,b). For each k there is a C such that ∣x∣k≤Ceδ∣x∣, and so, for ∣λ−λ0∣≤δ,
∣x∣keλx≤Ceδ∣x∣+λx≤C(e(λ0+2δ)x+e(λ0−2δ)x),
a function with finite expectation that does not depend on λ. Taking λ0=0 proves (1). The same bound is the dominating function required by the theorem on differentiation under the integral sign (applied with ∂λeλx=xeλx and repeated k times), proving (2). For (3), ∑k∣λx∣k/k!=e∣λx∣≤eλx+e−λx is integrable for ∣λ∣<min(a,b), so the dominated convergence theorem (or Fubini) allows exchanging sum and expectation in E[eλX]=E[∑k(λX)k/k!].
∎
That is why it is called the moment generating function: it is the exponential series of the sequence of moments. To see the mechanism, the exponential X∼Exp(θ) has M(λ)=∫0∞θe−(θ−λ)xdx=θ−λθ for λ<θ, and the geometric expansion 1−λ/θ1=∑k(λ/θ)k identifies, by property 3, E[Xk]/k!=θ−k, that is, E[Xk]=k!/θk, without a single integration by parts.
For the normal, completing the square gives M(λ)=eμλ+σ2λ2/2 for every λ∈R (the domain is R), and again the moments can be read from the power series of an exponential. For the Poisson, M(λ)=eμ(eλ−1), the PGF evaluated at s=eλ.
When the MGF exists and when it does not
Having 0 in the interior of the domain is a statement about the tails.
Proof
(⇒) If M is finite on (−a,b), Markov’s inequality applied to eλX with λ=b/2 gives P(X>x)≤e−λxM(λ), and similarly with −a/2 for P(X<−x). (⇐) If P(∣X∣>x)≤Ce−cx and ∣λ∣<c, the tail formula, E[e∣λ∣∣X∣]=1+∫0∞∣λ∣e∣λ∣xP(∣X∣>x)dx≤1+C∣λ∣∫0∞e−(c−∣λ∣)xdx<∞, bounds M(λ)≤E[e∣λ∣∣X∣].
∎
The laws in this catalogue fall into these groups. With tails decaying faster than any exponential (normal, binomial, Poisson, bounded support), the domain is all of R; the Poisson, with a tail of order e−xlogx, is in this group even though its tail is heavier than the Gaussian. With exponential tails (exponential, gamma, Laplace), the domain is an interval bounded by the rate: λ<θ for the exponential with rate θ. For heavy tails (Pareto, Cauchy, Student’s t, log-normal), the domain is only (−∞,0] or only {0}: for Pareto with index 3, ∫1∞eλx3x−4dx=∞ for every λ>0, because the exponential beats any power.
This is information rather than a failure of the tool: M being finite near 0 means exactly that the tail decays exponentially. This is the definition of a sub-exponential variable that we will see in the Bernstein lesson, and of a sub-Gaussian one if, in addition, with centered X, M(λ)≤eσ2λ2/2 for all λ∈R.
Cumulant generating function
The MGF turns sums into products, MX+Y=MXMY, but products are awkward to differentiate. A logarithm turns them back into sums.
Convexity follows from Hölder’s inequality, and that proof (which holds on the whole domain, including its boundary, where ψ is not differentiable) is the first exercise. Property 3 follows by taking logarithms of the product of MGFs. Property 2 needs an idea useful throughout the lesson: exponential tilting.
Tilting a law
If λ∈DX, the formula
Pλ(dx)=eλx−ψ(λ)PX(dx)
defines a probability (its total mass is M(λ)/M(λ)=1), the exponentially tilted law of X. It multiplies the density by an increasing exponential (when λ>0) and renormalizes it, moving mass to the right. Notice P0=PX. All the information about derivatives of ψ is in it: for interior λ, differentiating under the integral,
The derivative of ψ at λ is the mean of the tilted law, and the second derivative is its variance. At λ=0 the tilted law is the original one, giving property 2, and since variance is nonnegative, ψ′′≥0: convexity (strict if X is nonconstant, because then Varλ(X)>0). The slope ψ′(λ) increases with λ because tilting pushes the mean to the right, faster when there is more variance to move.
InteractiveThe shape of the cumulant generating function
Cumulant function ψ(λ)=logE[eλX]
ψ(λ)
tangent at λ0
tangent at 0, slope E[X]
curvature parabola
Original and tilted laws pλ0(x)=p(x)eλ0x−ψ(λ0)
p(x) and its mean E[X]
pλ0(x) y su media ψ′(λ0)
With a=ψ′(λ0)=2.00, the Chernoff bound on the right tail P(X≥a) is e−I=0.736. On the graph of ψ, the tangent intersects the axis λ=0 at −I=−0.31.
Law of X
ψ(λ0)0.693
ψ′(λ0), tilted mean2.000
ψ′′(λ0), tilted variance4.000
ψ′(0)=E[X], ψ′′(0)=Var(X)1.000, 1.000
κ1,…,κ41, 1, 2, 6
I=λ0ψ′(λ0)−ψ(λ0)0.307
For X∼Exp(1), ψ(λ)=−log(1−λ) has a vertical asymptote at rate λ=1: M(λ)=∞ for λ≥1. The tilted law is another exponential, with rate 1−λ.
On the left, ψ(λ)=logE[eλX] in blue, with its tangent at λ0 (dashed, slope ψ′(λ0)), the parabola with curvature ψ′′(λ0) (magenta), and the tangent at 0 in dotted gray, with slope E[X]. On the right, the original and tilted laws pλ0(x)=p(x)eλ0x−ψ(λ0), with their means: the tilted mean is exactly the slope, and the tilted variance the curvature. The tangent intersects the λ=0 axis at −I, with I=λ0ψ′(λ0)−ψ(λ0), the exponent of the Chernoff bound (below). For the exponential, ψ has a vertical asymptote at rate λ=1 and the tilted mean shoots up as you approach it. For the Pareto and log-normal, ψ=+∞ for every λ>0: tilting is possible only toward the origin, and the domain ends at a wall.
Cumulants versus moments
The first cumulants have names of their own. Expanding logM with M(λ)=1+m1λ+m2λ2/2+⋯ (where mk=E[Xk]) and log(1+u)=u−u2/2+⋯ gives
Through order 3, cumulants and central moments coincide. From order four onward they do not: κ4 is the central moment of order 4 minus 3σ4, so κ4/σ4 is the excess kurtosis, which is 0 for the normal (whose central moment of order 4 is 3σ4). The advantage of cumulants over moments is additivity. If Sn is the sum of n independent copies of X, then κr(Sn)=nκr(X), whereas the central moment of order 4 of the sum is nκ4+3n2σ4, mixing n with n2.
Law
ψ(λ)
κn
N(μ,σ2)
μλ+σ2λ2/2
μ,σ2,0,0,…
Poisson(μ)
μ(eλ−1)
μ for every n
Exp(θ)
−log(1−λ/θ)
(n−1)!/θn
Gamma(k,θ)
−klog(1−λ/θ)
k(n−1)!/θn
Unif(−1,1)
log(sinhλ/λ)
0,31,0,−152,0,…
Three observations from the table. The normal is the law with zero cumulants from order 3 onward, and the only one: by a theorem of Marcinkiewicz, if ψ is a polynomial it has degree at most 2. The Poisson has all cumulants equal, so its mean and variance coincide. And the gamma has κn=k(n−1)!/θn, the cumulant of k independent exponentials: its excess kurtosis is κ4/κ22=6/k, decreasing like 1/k when variables are added, and here the central limit theorem emerges in cumulant form. Standardize Sn by σn: the cumulant of order r≥3 of (Sn−nμ)/(σn) is nκr/(σn)r=κrσ−rn1−r/2→0, while κ1=0 and κ2=1 stay fixed: the cumulants approach those of the normal, one by one.
The Chernoff bound
Convexity and tilting meet in the most useful bound in applied probability. For λ≥0 and a∈R, Markov’s inequality applied to eλX gives
P(X≥a)=P(eλX≥eλa)≤e−λaM(λ)=e−(λa−ψ(λ)).
We can choose the best λ: P(X≥a)≤exp(−supλ≥0{λa−ψ(λ)}), the Legendre transform of ψ at a. For a>E[X] (the interesting tail; if a≤E[X] the supremum is 0 and the bound is trivial), the optimum, when interior to the domain, satisfies ψ′(λ)=a: tilt the law until its mean is exactly a. The figure shows this: with λ0 and a=ψ′(λ0), the exponent is I=λ0a−ψ(λ0), visible on the graph of ψ as the negative of the tangent’s vertical-axis intercept. For N(0,σ2), ψ(λ)=σ2λ2/2 and λa−ψ is maximized at λ=a/σ2, with I=a2/(2σ2): the Gaussian tail P(X≥a)≤e−a2/(2σ2). For Poisson(μ), I=alog(a/μ)−a+μ, the Kullback-Leibler divergence between Poisson(a) and Poisson(μ): the exponent of a tail is a distance between the original and tilted laws. This is developed in the lessons on Chernoff and Cramér; here it suffices to know where it comes from.
Characteristic function
The MGF fails for heavy tails because eλx grows without bound. The solution is to replace the real exponential with an imaginary exponential, which rotates rather than explodes: eitx has modulus 1 for every x and t, so its expectation always exists.
A center of mass
Think of φ(t) geometrically. Each possible value x of X becomes, for fixed t, a point eitx on the unit circle, and φ(t) is the center of mass of those points, each weighted by its probability. As t rises, the point for atom x rotates at angular speed x. At t=0 all are at 1 and φ(0)=1.
InteractiveThe characteristic function as a center of mass
atom x at eitx, size by weight
center of mass φ(t)
path of φ from 0 to t
Modulus ∣φ(t)∣ for t∈[0,4π]. The dashed line is the edge of the circle.
φ(t)−0.046 − 0.017 i
∣φ(t)∣0.0491
argφ(t)−2.783 rad
Lattice with spacing 1: at t=2π all points return together, ∣φ∣=1.
The blue points are eitx for each atom x of the law, sized by probability; the magenta point is their center of mass φ(t), and the magenta curve its path from 0 to t. On the right, ∣φ(t)∣ versus t. Play the animation. With the die (integer atoms) all points return to 1 together at t=2π and ∣φ∣=1: this is a lattice law and its characteristic function is periodic. With atoms0,1,2, which are incommensurable, the t window extends to [0,26π]: the modulus returns near 1 (0.99 at t≈31.2, 0.998 at t≈75.5, where t/2π and t2/2π are nearly integers simultaneously) but never reaches it. With the coin±1 it returns to the edge already at t=π. With the normal, uniform, or Cauchy, speeds form a continuum, points spread around the circle and the center sinks toward 0. For continuous laws, 160 equally weighted atoms at quantiles are drawn only to visualize the cloud; the center of mass uses the exact formula for φ.
The figure suggests three facts, proved below: ∣φ∣≤1 (the center of mass of points on a circle lies in the disk); if all points coincide at some t=0, the law is lattice; and the modulus tends to zero when the law has a density, by the Riemann-Lebesgue lemma.
Proof
(1) E[eitX]≤EeitX=1 by the triangle inequality for expectation, and eitX=e−itX. (2) ∣φ(t+h)−φ(t)∣=E[eitX(eihX−1)]≤EeihX−1, independent of t and tending to 0 as h→0 by dominated convergence (the bound is 2). (3) E[eit(aX+b)]=eitbE[ei(at)X]. (4) As for the PGF, eitX and eitY are independent and bounded.
(5) Apply differentiation under the integral with dominating function ∣x∣k∈L1(PX): φ(k)(t)=E[(iX)keitX], continuous by dominated convergence. The expansion uses the elementary bound eiy−∑k≤n(iy)k/k!≤min(∣y∣n+1/(n+1)!,2∣y∣n/n!). With y=tX,
and the expectation tends to 0 as t→0 by dominated convergence (the bound 2∣X∣n/n! is integrable and the first argument of the minimum tends to 0 pointwise). This is the remainder o(∣t∣n).
∎
Properties 3 and 4 use the same mechanism as the PGF and MGF, now without any condition. Property 5 implies that if X has mean 0 and variance 1, φ(t)=1−t2/2+o(t2).
Examples. For Bernoulli, φ(t)=1−p+peit, and for the exponential with rate θ, φ(t)=∫0∞θe−(θ−it)xdx=θ/(θ−it): the MGF formula with λ=it. For the uniform on (−1,1), φ(t)=sint/t. For the standard normal there is a short proof without complex variables. Since xp(x)=−p′(x) for the Gaussian density, differentiating under the integral and integrating by parts gives
and φ(0)=1 gives φ(t)=e−t2/2. By property 3, for N(μ,σ2) it is eiμt−σ2t2/2. Note the elegance: up to constants, the normal density is its own Fourier transform. This self-duality makes the inversion proof tractable. (The normal appearing as a limit of sums has another cause, seen in cumulants: it is the only law with quadratic ψ, and when a sum is standardized cumulants of order ≥3 vanish.)
The standard Cauchy has φ(t)=e−∣t∣, calculated by residues or inversion in the second exercise. It is striking because e−∣t∣is not differentiable at 0, consistent with the Cauchy having no mean (E∣X∣=∞).
Lattice laws and the behavior of ∣φ∣
The figure suggested that ∣φ(t0)∣=1 for some t0=0 is very special. It is.
Proof
(⇐) If X=a+hN with integer N, eit0X=eit0aei2πNsgn(t0)=eit0a almost surely and ∣φ(t0)∣=1. (⇒) Let φ(t0)=eiα. Then 1=e−iαφ(t0)=E[ei(t0X−α)], and taking real parts, E[1−cos(t0X−α)]=0. Since 1−cos≥0, it is 0 almost surely: t0X−α∈2πZ, i.e. X∈α/t0+(2π/t0)Z. Periodicity of ∣φ∣ follows from φ(t+2π/h)=eia2π/hφ(t).
∎
Thus for an integer variable not concentrated on a coarser progression, ∣φ(t)∣=1 exactly at t∈2πZ; the coin ±1 has spacing 2 and returns at t=π, as shown. At the opposite extreme, the Riemann-Lebesgue lemma (the analogue of Fourier coefficients of an integrable function tending to zero) says that if X has a density, φ(t)→0 as ∣t∣→∞. The converse is false (a singular law may have φ→0), but the smoother the density, the faster φ decays: the infinitely smooth normal has Gaussian decay; the exponential, with a jump at 0, only 1/t. This correspondence between smoothness of f and decay of φ determines numerical inversion accuracy.
Preview: the central limit theorem in four lines
Let Xi be iid with mean 0 and variance 1, Sn=X1+⋯+Xn, and φ the characteristic function of X1. By properties 3 and 4, the characteristic function of Sn/n is φ(t/n)n, and by property 5, φ(u)=1−u2/2+o(u2):
φSn/n(t)=(1−2nt2+o(n1))n⟶e−t2/2(n→∞).
The limit is the characteristic function of the standard normal. One link is missing: Lévy’s continuity theorem, which states that if characteristic functions of a sequence of laws converge pointwise to a function continuous at 0, the sequence converges in distribution. It turns the convergence of φSn/n into Sn/n⇒N(0,1); the complete proof, with the tail bound, is in the central limit theorem lesson.
Uniqueness and inversion
Everything above is useful only if the characteristic function identifies the law. It does, with a constructive formula.
Proof
The idea is to smooth with a Gaussian, making the integral tractable, and then remove the smoothing.
Step 1: the smoothed law. Let Z∼N(0,1) be independent of X and ε>0. The density of εZ is gε(u)=(2πε2)−1/2e−u2/(2ε2), and by Gaussian self-duality, gε(u)=2π1∫e−itue−ε2t2/2dt. The sum X+εZ has density fε(x)=E[gε(x−X)], and by Fubini (the integrand is bounded by integrable e−ε2t2/2),
Step 2: uniqueness. For every bounded continuous h, E[h(X+εZ)]→E[h(X)] as ε→0 (dominated convergence: X+εZ→X and h is bounded). If φX=φY, the preceding steps give E[h(X+εZ)]=E[h(Y+εZ)] for every ε, and taking ε→0, E[h(X)]=E[h(Y)] for every bounded continuous h. Such functions determine the law (indicators of closed intervals are decreasing limits of bounded continuous functions, and intervals form a π-system generating the Borel sets: π-λ theorem).
Step 3: inversion. If φX∈L1, dominated convergence gives fε(x)→f(x):=2π1∫e−itxφX(t)dt uniformly in x (the difference is bounded by 2π1∫∣φX∣(1−e−ε2t2/2)dt→0). Thus f is continuous (uniform limit of continuous functions), bounded and ≥0 (limit of densities). For h∈Cc, E[h(X+εZ)]=∫hfε→∫hf, and the limit is also E[h(X)]: the law of X has density f.
∎
This argument is also an algorithm. A program inverting a characteristic function with Gaussian smoothing does just this: it produces a valid density, at the cost of bias controlled by ε. Without integrability (for example, an atomic law has a nondecaying φ), Lévy’s formula still holds in an integrated form: for a<b continuity points of the distribution function,
F(b)−F(a)=T→∞lim2π1∫−TTite−ita−e−itbφ(t)dt.
Takeaways. Three constantly used consequences. (i) Recognizing laws: if φS(t)=eiμt−σ2t2/2, then S is normal. A sum of independent normals N(μi,σi2) has φ=∏jeiμjt−σj2t2/2=ei(∑μj)t−(∑σj2)t2/2, so it is N(∑μj,∑σj2), and uniqueness justifies that conclusion. (ii) Symmetry: φ−X=φX, so φX is real if and only if X=d−X. (iii) Multivariate: the characteristic function of a vector, φX(t)=E[eit⊤X], determines its law and equals ∏jφXj(tj) if and only if the coordinates are independent. The multivariate Gaussian lesson defines the Gaussian vector this way.
One consequence for MGFs: if MX=MY in a neighborhood of 0, then X and Y have the same law. Both characteristic functions arise by analytically continuing λ↦M(λ) to λ=it and agree in the strip; the final section gives the argument.
Inverting with the FFT
The inversion formula is an integral, and integrals can be discretized. With step Δt and cutoff T, the trapezoid rule is
f^(x)=2πΔt∣tk∣≤T∑φ(tk)e−itkx,tk=kΔt,
and evaluated on the grid xj=jΔx with ΔxΔt=2π/N it is exactly a discrete Fourier transform of N terms: the one computed by np.fft.fft in O(NlogN) (with a small alternating sign change for centered grids, as the code shows). This is the Carr-Madan method for option prices, and the method used by libraries to calculate densities of laws defined by their characteristic function (stable laws, Lévy processes, compound Poisson mixtures). It has three dangers, each with a precise mathematical cause:
Aliasing.f^ is periodic in x with period L=2π/Δt: by the Poisson summation formula, f^(x)=∑j∈ZfT(x+jL), the (truncated) density summed with all its shifted copies. If the law has mass outside [−L/2,L/2] (heavy tails), that mass wraps around to the other side. Remedy: small Δt, i.e. a large window L.
Resolution. Cutting off at ∣t∣≤T amounts to smoothing f with a kernel of width ∼π/T, which is also the grid spacing Δx. Remedy: large T.
Gibbs ringing. If f has a jump (the exponential at 0, the uniform at its endpoints), φ decays only as 1/t and the abrupt cutoff at T produces waves around the jump, including negative densities and overshoot near 9% of the jump. Remedy: multiply φ by e−ε2t2/2 (adding N(0,ε2) noise, as in the inversion proof) or another smooth window, at the cost of bias of order ε at the jump.
InteractiveInverting a characteristic function on a grid
Exact density versus f^(x)=2πΔt∑∣tk∣≤Tφ(tk)e−itkx
exact density f
grid reconstruction f^
window edge ±L/2
What remains of ∣φ(t)∣
Gray: ∣φ∣. Aqua: after multiplication by e−ε2t2/2. Red: discarded region. If ∣φ∣ has not fallen nearly to zero at T, the cutoff leaves a trace.
Scenarios
Law to recover
error ∫f^−fdx in view0.209
window L=2π/Δt25.13
resolution in x, π/T0.314
terms in the sum, 2T/Δt81
∣φ(T)∣, what is discarded1.0e−1
minimum of f^−0.085
There is negative mass: this is Gibbs ringing from the cutoff at T. A density cannot be negative; the ringing is an artifact, not data.
Reconstruction f^ (magenta) against exact density (gray, dashed). In Gibbs ringing (exponential, with a jump at 0), cutoff T leaves waves and negative values; increase T and the waves narrow but do not disappear (the jump overshoot is always near 9%). In Gaussian smoothing, multiplying φ by e−ε2t2/2 removes the ringing but rounds the jump. In Aliasing, a Cauchy is inverted with too short a window (the red line marks ±L/2): heavy tails decaying as 1/x2 wrap around and raise the density. In Well chosen (normal) error is practically zero. On the right, the modulus ∣φ(t)∣: red shows the discarded region, aqua after smoothing. Adjust Δt, T and ε by hand and see which readout changes: the window depends only on Δt and resolution only on T.
The moment problem
One last question: do moments determine the law? If E[Xk]=E[Yk] for all k≥1, do X and Y have the same law? If the MGF exists, yes.
Proof
Let MX be finite on (−a,a). For any t0∈R, differentiating under the integral gives φX(k)(t0)=E[(iX)keit0X], so φX(k)(t0)≤E∣X∣k, and the MGF theorem gives E∣X∣k≤Crk!r−k for any r<a (from er∣x∣≥rk∣x∣k/k! and E[er∣X∣]≤M(r)+M(−r)<∞). Thus the Taylor series of φXat any point t0 converges to φX for ∣t−t0∣<r: the bound eiy−∑k≤n(iy)k/k!≤∣y∣n+1/(n+1)! with y=(t−t0)X bounds the order-n remainder by ∣t−t0∣n+1E∣X∣n+1/(n+1)!≤Cr(∣t−t0∣/r)n+1→0. Thus φX is analytic on R. The same holds for Y, whose even absolute moments are equal and whose odd absolute moments are bounded by the even ones (Cauchy-Schwarz), so it has the same bound. At t0=0, derivatives φ(k)(0)=ikE[Xk] agree, hence φX=φY on (−r,r). Two analytic functions agreeing on an interval agree on all R (identity principle), and by uniqueness X=dY.
∎
The theorem says “if the MGF exists, moments suffice.” It does not say the converse, which is false: there are laws without an MGF whose moments do not determine the law. The classic example, due to Stieltjes (1894), is the log-normal.
Proof
It is a density: 1+asin(⋅)≥0 for ∣a∣≤1. With u=logx, ∫0∞xkf(x)sin(2πlogx)dx=∫Rekuϕ(u)sin(2πu)du, where ϕ is the standard normal density. Completing the square, ekuϕ(u)=ek2/2ϕ(u−k), and with v=u−k the integral is ek2/2∫ϕ(v)sin(2π(v+k))dv=ek2/2∫ϕ(v)sin(2πv)dv=0, because k is integer (the sine has period 2π in v) and ϕ(v)sin(2πv) is odd. Taking k=0 shows fa integrates to 1 and, for k≥1, that moments agree. The laws differ for a=0 because their densities differ on a set of positive Lebesgue measure (for example, where sin(2πlogx)>0).
∎
The figure makes this tangible. With u=logX, the two densities are a Gaussian and a Gaussian multiplied by a sinusoid; the moments of X are the values of the Laplace transform of that density at integers, E[ekU], and the sinusoid is orthogonal to all exponentials with integer k against the Gaussian. With ω=2π, total variation distance between f and f1 is 21E∣sin2πZ∣≈0.318: the laws are not close, yet the table’s six moments agree up to rounding.
InteractiveSame moments, different law
Density of X on the x scale
Density of U=logX: a Gaussian with a sinusoid
The characteristic function does distinguish them: ∣φfa(t)−φf(t)∣
Moments E[Xk]: log-normal and perturbed
k
e^(k²/2)
with a
rel. diff.
1
1.649
1.649
0
2
7.389
7.389
0
3
90.017
90.017
0
4
2980.958
2980.958
0
5
2.683e+5
2.683e+5
0
6
6.566e+7
6.566e+7
0
log-normal f
perturbed fa=f(1+asin(ωlogx))
total variation distance TV(f,fa)0.286
maximum ∣φfa(t)−φf(t)∣, t∈[0,15]0.180
ω is a multiple of π: sin(ωk)=0 for every integer k, and all six moments agree with the log-normal up to quadrature error. Different laws, same moments.
The log-normal density f (gray, dashed) and the perturbed fa=f(1+asin(ωlogx)), on the x scale and the u=logx scale (where the perturbation is a sinusoid of frequency ω on a Gaussian). The table calculates moments E[Xk] of fa by quadrature and compares them with exact values ek2/2: with ω a multiple of π (slider value 2, giving the classic sin(2πlogx)) relative difference is zero or order 10−16, floating-point noise, for any amplitude a. Move ω/π off the integers and moments separate by relative difference ae−ω2/2sin(ωk): substantially at ω/π=0.5, around 10−5 at 1.5 (the factor e−ω2/2 suppresses it). Below, the characteristic function does distinguish the two laws: ∣φfa−φf∣ reaches 0.2 with ω=2π and a=1.
This phenomenon teaches two lessons. First: agreement of all moments does not identify a law, so a moment-matching method can confuse laws with different tails. A sufficient condition, finer than the MGF, is Carleman’s condition: ∑nm2n−1/(2n)=∞ guarantees determinacy, with mk=E[Xk]. For the log-normal m2n=e2n2, m2n−1/(2n)=e−n and the series converges: the condition fails, as expected. Second: the characteristic function always distinguishes laws, because it determines the law without assumptions. Of the four transforms, only it gives complete identification.
Implementation from scratch
All of the above can be calculated in a few lines of NumPy. Start with the simplest point: convolution is a product of PGFs evaluated at roots of unity. The fast Fourier transform evaluates G(s)=∑kpksk at s=e−2πij/M, j=0,…,M−1: it is the PGF at M points of the circle; multiplying and applying the inverse yields the pmf of the sum. Choose M larger than the sum’s support to avoid circular overlap.
[ ]Convolución como producto de PGFBrowser
import numpy as np
dado = np.array([0] + [1 / 6] * 6) # pmf de un dado sobre {0, ..., 6}
M = 64 # mayor que el soporte de la suma de 10 dados (0 a 60)
conv = np.array([1.0])
for _ in range(10): # diez convoluciones directas
conv = np.convolve(conv, dado)
G = np.fft.fft(dado, M) # G(w^j): la PGF en las raíces M-ésimas de la unidad
via_pgf = np.fft.ifft(G ** 10).real[:61] # producto de diez PGF y transformada inversa
s = np.arange(61)
print(f"P(S = 35): convolución {conv[35]:.6f} PGF {via_pgf[35]:.6f}")
print(f"mayor diferencia entre las dos pmf: {np.max(np.abs(conv - via_pgf)):.1e}")
print(f"E[S] = {np.sum(s * conv):.4f}, Var(S) = {np.sum((s - 35.0) ** 2 * conv):.4f} (teoría 35 y {10 * 35 / 12:.4f})")
The two columns agree in every printed digit and the largest difference across the pmf is around 10−17: rounding. We get P(S=35)=0.0727, the number in the motivation. PGF composition calculates the compound Poisson without enumerating convolutions: N∼Poisson(3) turns and one die per turn, S=ξ1+⋯+ξN with GS(s)=exp(3(H(s)−1)).
[ ]Suma aleatoria: G_N(H(s)) en la circunferenciaBrowser
lam, M = 3.0, 256
cara = np.array([0] + [1 / 6] * 6) # un dado con caras 1..6, y probabilidad 0 en 0
H = np.fft.fft(cara, M) # H(s) en las raíces de la unidad
pmf_S = np.fft.ifft(np.exp(lam * (H - 1))).real # G_N(H(s)) = exp(lam (H(s) - 1)) y vuelta a la pmf
k = np.arange(M)
print(f"suma de masas {pmf_S.sum():.6f}, mínimo {pmf_S.min():.1e}")
print(f"E[S] = {np.sum(k * pmf_S):.4f} (teoría {lam * 3.5}) Var(S) = {np.sum((k - 10.5) ** 2 * pmf_S):.4f} "
f"(teoría {lam * 35 / 12 + lam * 3.5 ** 2})")
rng = np.random.default_rng(0) # comprobación por simulación
N = rng.poisson(lam, 200_000).astype(np.intp) # intp: en Pyodide (32 bits) np.repeat exige índices de ese tipo
tiradas = rng.integers(1, 7, int(N.sum()))
S = np.bincount(np.repeat(np.arange(N.size), N), weights=tiradas, minlength=N.size)
print(f"P(S=0): PGF {pmf_S[0]:.5f}, e^-3 = {np.exp(-lam):.5f}, simulación {np.mean(S == 0):.5f}")
print(f"P(S=10): PGF {pmf_S[10]:.5f}, simulación {np.mean(S == 10):.5f}")
The variance 45.5=E[N]Var(ξ)+Var(N)E[ξ]2=3⋅1235+3⋅3.52 is the previous lesson’s formula, reproduced by the PGF without conditioning. The simulation of 200000 replicates agrees with the exact pmf to the third digit, as Monte Carlo error permits. (And P(S=0)=GN(H(0))=GN(0)=e−3 agrees with the probability of no turns.)
Now invert a characteristic function. With grids tk=(k−N/2)Δt, xj=(j−N/2)Δx and ΔtΔx=2π/N, the exponent e−itkxj equals e−2πijk/N up to a factor (−1)j+k (because N/2 is even), giving the wrapper around np.fft.fft. The code recovers the density of a sum of three independent exponentials with rates 1,2,3 (whose characteristic function is the product ∏iλi/(λi−it)) and of a sum of three uniforms, comparing them with the exact solution, simulation and direct convolution.
[ ]Inversión de una función característica con la FFTBrowser
def densidad_desde_cf(phi, x_max, N=4096, eps=0.0):
"""f(x_j) en la malla x_j = (j - N/2) dx de [-x_max, x_max), por inversión de Fourier discreta de phi."""
dx = 2 * x_max / N
dt = 2 * np.pi / (N * dx) # dt * dx = 2 pi / N: es la relación malla-malla de la FFT
k = np.arange(N)
t = (k - N // 2) * dt
vals = phi(t) * np.exp(-0.5 * (eps * t) ** 2) * (-1.0) ** k # suavizado gaussiano opcional y signo alterno
f = (dt / (2 * np.pi)) * (-1.0) ** k * np.fft.fft(vals)
return (k - N // 2) * dx, f.real
tasas = np.array([1.0, 2.0, 3.0])
phi_hipo = lambda t: np.prod([r / (r - 1j * t) for r in tasas], axis=0)
x, f = densidad_desde_cf(phi_hipo, x_max=20)
# solución exacta (fracciones simples) y convolución directa de las tres densidades
c = [np.prod([tasas[j] / (tasas[j] - tasas[i]) for j in range(3) if j != i]) for i in range(3)]
exacta = (x >= 0) * sum(c[i] * tasas[i] * np.exp(-tasas[i] * np.maximum(x, 0)) for i in range(3))
dx = 0.005
g = np.arange(0, 30, dx)
conv = np.convolve(np.convolve(np.exp(-g), 2 * np.exp(-2 * g)) * dx, 3 * np.exp(-3 * g))[: g.size] * dx
rng = np.random.default_rng(1)
S = sum(rng.exponential(1 / r, 300_000) for r in tasas)
h, e = np.histogram(S, bins=60, range=(0, 6), density=True)
centros = (e[:-1] + e[1:]) / 2
print(f"suma de tres exponenciales (tasas 1, 2, 3), {x.size} puntos")
print(f" FFT frente a exacta: {np.max(np.abs(f - exacta)):.1e}")
print(f" convolución directa: {np.max(np.abs(conv - np.interp(g, x, f))):.1e} (error de la malla de paso {dx})")
print(f" simulación (300 000): {np.max(np.abs(h - np.interp(centros, x, f))):.1e} (ruido de Monte Carlo)")
def phi_unif01(t):
t = np.where(t == 0, 1e-300, t)
return (np.exp(1j * t) - 1) / (1j * t)
xu, fu = densidad_desde_cf(lambda t: phi_unif01(t) ** 3, x_max=6)
irwin = np.where((xu >= 0) & (xu < 1), xu**2 / 2, np.where((xu >= 1) & (xu < 2), (-2 * xu**2 + 6 * xu - 3) / 2, np.where((xu >= 2) & (xu <= 3), (3 - xu) ** 2 / 2, 0.0)))
print(f"suma de tres uniformes (Irwin-Hall), FFT frente a exacta: {np.max(np.abs(fu - irwin)):.1e}")
The FFT wins by several orders of magnitude: direct convolution has discretization error of order Δx (here 10−3 to 10−2), and simulation has Monte Carlo noise 1/n. For a smooth density and cutoff T=NΔt/2≈320 where ∣φ∣ is already around 10−7, the FFT reaches 10−6. When it breaks, it does so for the three reasons above, as the same function shows:
[ ]Aliasing y rizado de GibbsBrowser
cauchy = lambda x: 1 / (np.pi * (1 + x**2))
phi_cauchy = lambda t: np.exp(-np.abs(t))
for x_max in [5, 200]:
xc, fc = densidad_desde_cf(phi_cauchy, x_max)
print(f"Cauchy con ventana [-{x_max}, {x_max}): error máximo {np.max(np.abs(fc - cauchy(xc))):.1e}")
print("\nuniforme (0, 1), con un salto en cada extremo, N = 512:")
for eps in [0.0, 0.02, 0.05]:
xg, fg = densidad_desde_cf(phi_unif01, x_max=4, N=512, eps=eps)
exacta_u = ((xg >= 0) & (xg <= 1)) * 1.0
print(f" eps = {eps:4.2f}: mínimo {fg.min():+.4f} máximo {fg.max():.4f} error L1 {np.sum(np.abs(fg - exacta_u)) * (xg[1] - xg[0]):.3f}")
The Cauchy with a short window has error ∼10−2 (aliasing: its heavy tails wrap around), and with the long window 10−5. The uniform shows the smoothing tradeoff: without smoothing the minimum is negative, −0.088, and the maximum exceeds 1 by 9%; with ε=0.02 both anomalies almost disappear and error falls; with ε=0.05 the jumps are overly rounded and error rises again. This trades off truncating φ at T (ringing) against smoothing bias (rounded jumps), with an intermediate ε minimizing their sum.
Finally, the symbolic part. SymPy differentiates the exact generating functions: each cumulant is a derivative at 0, and the relation κ4=μ4−3σ4 is checked against moments.
[ ]Cumulantes con SymPyBrowser
import sympy as sp
lam = sp.symbols("lambda")
th, mu, sg, k, lm = sp.symbols("theta mu sigma k lm", positive=True)
def cumulantes(psi, n=6):
return [sp.simplify(sp.diff(psi, lam, j).subs(lam, 0)) for j in range(1, n + 1)]
casos = {
"normal": mu * lam + sg**2 * lam**2 / 2,
"exponencial": -sp.log(1 - lam / th),
"gamma": -k * sp.log(1 - lam / th),
"Poisson": lm * (sp.exp(lam) - 1),
}
for nombre, psi in casos.items():
print(f"{nombre:12s} kappa_1..6 =", cumulantes(psi))
# uniforme (-1, 1): psi = log(sinh(lam)/lam) no se evalúa en 0 directamente, pero sí su serie
serie = sp.series(sp.log(sp.sinh(lam) / lam), lam, 0, 7).removeO()
print("uniforme ", [sp.nsimplify(serie.coeff(lam, j) * sp.factorial(j)) for j in range(1, 7)])
# momentos de la exponencial desde la MGF y la relación kappa_4 = mu_4 - 3 sigma^4
M = sp.exp(casos["exponencial"])
m = [sp.simplify(sp.diff(M, lam, j).subs(lam, 0)) for j in range(1, 5)]
mu4 = sp.simplify(m[3] - 4 * m[2] * m[0] + 6 * m[1] * m[0] ** 2 - 3 * m[0] ** 4)
print("momentos E[X^k], k=1..4:", m)
print("mu_4 central =", mu4, " kappa_4 - (mu_4 - 3 kappa_2^2) =", sp.simplify(cumulantes(casos["exponencial"])[3] - (mu4 - 3 * cumulantes(casos["exponencial"])[1] ** 2)))
The preceding cumulant table is verified symbol by symbol: the exponential yields κn=(n−1)!/θn, the gamma multiplies it by k, and the Poisson yields μ at every order. The last line confirms that κ4=6/θ4 equals μ4−3σ4=9/θ4−3/θ4.
Estimating cumulants from data
With samples, the natural estimator of κn replaces central moments by those of the empirical law: κ^1=xˉ, κ^2=m2, κ^3=m3, κ^4=m4−3m22, with mr=n1∑(xi−xˉ)r. An exact, not merely asymptotic, property demonstrates additivity: if you take all sumsxi+yj of two samples, each weighted 1/(nm) (the image under (x,y)↦x+y of the product of the two empirical laws), that law is the convolution of the empirical laws and the cumulants of the sum are exactly the sum of their cumulants.
[ ]Cumulantes muestrales y aditividad exactaBrowser
def cumulantes_muestrales(x):
x = np.asarray(x, dtype=float)
d = x - x.mean()
m2, m3, m4 = np.mean(d**2), np.mean(d**3), np.mean(d**4)
return np.array([x.mean(), m2, m3, m4 - 3 * m2**2])
rng = np.random.default_rng(0)
x = rng.exponential(1.0, 200_000)
print("Exp(1): ", np.round(cumulantes_muestrales(x), 3), " teoría [1, 1, 2, 6]")
u = rng.uniform(-1, 1, 200_000)
print("Unif(-1, 1): ", np.round(cumulantes_muestrales(u), 3), " teoría [0, 0.333, 0, -0.133]")
g = rng.gamma(10, 0.5, 400_000) # suma de diez exponenciales de tasa 2
kg = cumulantes_muestrales(g)
print(f"Gamma(10, tasa 2): curtosis en exceso {kg[3] / kg[1]**2:.3f} (teoría 6/10 = 0.6)")
a, b = rng.exponential(1.0, 300), rng.uniform(-1, 1, 300)
suma = (a[:, None] + b[None, :]).ravel() # las 90 000 sumas x_i + y_j: la ley empírica de la suma
dif = cumulantes_muestrales(suma) - (cumulantes_muestrales(a) + cumulantes_muestrales(b))
print("kappa_n(suma) - kappa_n(a) - kappa_n(b):", dif)
The first two lines agree with theory up to sampling error (the exponential’s κ^4 is the noisiest, using a fourth-order moment of an exponential tail), and the last line is zero up to floating-point rounding, ∼10−15: this is not an approximation but an algebraic identity for empirical laws.
The library version
Tool
What it provides
Notes
scipy.stats.<ley>.stats(moments="mvsk")
exact mean, variance, skewness and excess kurtosis
these are κ1,κ2,κ3/κ23/2,κ4/κ22
scipy.stats.kstat(x, n)
k-statistics (unbiased estimators of κn)
up to n=4; not the plug-in estimators above
scipy.stats.<ley>.moment(n)
raw moment of order n
exact
scipy.fft.ifft, np.fft.ifft
numerical inversion
used above; scipy.fft also supports workers for parallelism
scipy.optimize.brentq
smallest root of G(s)=s
extinction probability
sympy
symbolic generating functions and cumulants
sp.diff, sp.series
[ ]scipy: cumulantes, k-estadísticos y extinciónBrowser
from scipy import stats, optimize
print("Gamma(3, escala 0.5) exacto, mvsk:", np.round(np.array(stats.gamma(3, scale=0.5).stats(moments="mvsk"), dtype=float), 4))
x = np.random.default_rng(0).exponential(1.0, 200_000)
print("k-estadísticos de una Exp(1):", [round(float(stats.kstat(x, n)), 3) for n in (1, 2, 3, 4)], " (teoría 1, 1, 2, 6)")
# probabilidad de extinción con descendencia Poisson(1.5): la menor raíz de G(s) = s en [0, 1)
G = lambda s: np.exp(1.5 * (s - 1))
q = optimize.brentq(lambda s: G(s) - s, 0.0, 0.99)
print(f"q = {q:.6f} (probabilidad de extinción; supervivencia {1 - q:.4f})")
s_n = 0.0
for n in range(1, 6):
s_n = G(s_n)
print(f" Pr(Z_{n} = 0) = {s_n:.4f}")
kstat agrees with the preceding cell’s estimator to the third digit because with n=200000 the bias correction, of order 1/n, is invisible; for small samples (n≲30) it matters. Brent’s root finder, however, would not work on all of [0,1]: G(1)−1=0, the interval contains two roots (the one sought and the trivial root), and brentq would return 1 as soon as it sees the right endpoint is a root. The right endpoint must instead satisfy G(s)−s<0, which for m>1 is any s∈(q,1) such as 0.99; alternatively use fixed-point iteration, which converges monotonically from 0 to the smallest root by the extinction theorem.
Common mistakes
Exercises
ProofThe cumulant generating function is convex
Prove: Let X be a real variable with domain D={λ:M(λ)<∞}, M(λ)=E[eλX]. Prove that ψ=logM is convex on D and that, if 0 is an interior point of D, ψ′(0)=E[X] and ψ′′(0)=Var(X).
0
Use Hölder's inequality E[UV]≤E[Up]1/pE[Vq]1/q for U,V≥0, with 1/p+1/q=1, p,q>1.
Step 1 of 4. Let λ1,λ2∈D and θ∈(0,1). How do you rewrite e(θλ1+(1−θ)λ2)X to apply Hölder?
ProofThe mean of Cauchy variables is Cauchy
Prove: Prove that the characteristic function of the standard Cauchy, with density p(x)=1/(π(1+x2)), is φ(t)=e−∣t∣, and deduce that the mean Xˉn=(X1+⋯+Xn)/n of n iid standard Cauchy variables is again standard Cauchy.
0
Use the inversion formula: first compute the characteristic function of the Laplace density 21e−∣x∣ and apply inversion to it.
Step 1 of 4. What is the characteristic function of the Laplace density q(x)=21e−∣x∣?
NumericExtinction with Poisson(1.5) offspring
A branching process has a Poisson number of offspring per individual with mean 1.5. Use the PGF to calculate the probability q that the lineage eventually dies out.
QuizThe domain of the MGF
Which distribution has a moment generating function finite only for λ<1?
NumericExcess kurtosis of a sum of exponentials
Let X1,…,X10 be independent exponentials with rate 2 and S=X1+⋯+X10. Calculate the excess kurtosis of S, κ4(S)/κ2(S)2.
QuizWhich cannot be a characteristic function?
Which of these functions is not the characteristic function of any real random variable?
QuizMoments and laws
Which statement is true?
NumericThe t cutoff for FFT inversion
You want a density on x∈[−20,20) on a grid of N=4096 points by characteristic-function inversion with np.fft. The grids satisfy ΔtΔx=2π/N, with tk=(k−N/2)Δt. What cutoff T=NΔt/2 does the characteristic function reach?
CodeSample cumulants and additivity
Implement sample_cumulants(x), returning a length-4 array of sample cumulants [k1, k2, k3, k4] for sample x, calculated using central moments of the empirical law: k1 is the mean, k2 and k3 are the central moments of orders 2 and 3 (with divisor n), and k4 = m4 - 3 * m2**2. Tests check values for an exponential and a uniform, translation invariance (for k2,k3,k4), scaling κn(cX)=cnκn(X) and exact additivity of cumulants of the empirical law of sums xi+yj.
import numpy as np
def sample_cumulants(x):
"""Cumulantes k1, k2, k3, k4 de la ley empirica de la muestra x."""
x = np.asarray(x, dtype=float)
# tu codigo: momentos centrales m2, m3, m4 y combinacion para k4
return np.zeros(4)
Shift+Enter to run
Summary
Key idea
Adding independent variables convolves their laws, and a suitable transform turns this into multiplication. The probability generating function applies to integers, the moment generating function to light tails, the cumulant generating function (ψ=logM) is convex and additive, and the characteristic function φ(t)=E[eitX] always exists, determines the law and has an inversion formula (computed by FFT). The MGF may not exist for heavy tails, and matching moments does not guarantee matching laws.
PGF: G(s)=E[sX] for integers; GX+Y=GXGY, GS=GN∘H for random sums; a branching process extinction probability is the smallest root of G(s)=s and equals 1 if and only if mean offspring is ≤1.
MGF: M(λ)=E[eλX], finite near 0 if and only if the tail decays exponentially; then M(k)(0)=E[Xk] and moments determine the law. For heavy tails it is +∞ for every λ>0.
CGF: ψ=logM is convex; ψ′(λ) and ψ′′(λ) are the mean and variance of the tilted law eλx−ψ(λ)P(dx); cumulants are additive, κ3 is the central moment of order 3 and κ4=μ4−3σ4; the Chernoff bound is exp(−supλ{λa−ψ(λ)}).
Characteristic function: always exists, ∣φ∣≤1, uniformly continuous, φX+Y=φXφY, and with E∣X∣n<∞ it has a moment expansion. A law is lattice if and only if ∣φ(t0)∣=1 for some t0=0; with a density, φ→0 (Riemann-Lebesgue). For the normal it is eiμt−σ2t2/2; for the Cauchy, e−∣t∣.
Uniqueness and inversion: φ determines the law and, if φ∈L1, f(x)=2π1∫e−itxφ(t)dt. FFT inversion requires controlling aliasing (L=2π/Δt), resolution (π/T) and Gibbs ringing at jumps.
Moment problem: an MGF finite near 0 implies determinacy; the log-normal and f(1+asin(2πlogx)) have the same moments and different laws, distinguished by φ.