Type at least 2 letters. Enter opens the first result, Esc closes.

    Probability and Statistics · Lesson 3 · Chance, random variables and distributions

    Common distributions, the Poisson process and moment generating functions

    Beginner 75 min 5 interactive figures 3 videos Colab notebook

    Before this lesson: lesson 01 (independence, counting with (nk)\binom{n}{k}) and lesson 02 (PMF, PDF, CDF, expectation, variance). The gamma integral uses integration by parts (calculus, lesson 10). Time: about 75 minutes, plus the notebook.


    Why this matters #

    When you choose a loss or a prior, you choose a distribution. Binary cross-entropy is the negative log-likelihood of a Bernoulli; softmax cross-entropy is the categorical; the squared error is the Gaussian; the Poisson loss is for count targets such as clicks or photon counts. A beta prior on a click rate and a Dirichlet prior on topic proportions (LDA) are the standard Bayesian choices (lesson 10).

    The relations between the distributions are how samplers are built: a gamma sampler gives beta and Dirichlet samplers. Queues, server logs, website traffic, radioactive decay and earthquake catalogues are first modelled as Poisson processes. The moment generating function leads to the central limit theorem (lesson 06) and to Chernoff bounds (lesson 07).

    1. Predict first #

    2. The picture #

    A family tree #

    Start with one trial with success probability pp: a Bernoulli variable, 1 for success and 0 for failure. Everything in the discrete half of the family comes from repeating it independently.

    • Count the successes in nn trials: binomial Bin(n,p)\text{Bin}(n, p).
    • Count the trials up to the first success: geometric Geom(p)\text{Geom}(p).
    • Let nn be large and pp small, with np=λnp = \lambda fixed (many chances, each one rare): Poisson Poisson(λ)\text{Poisson}(\lambda).
    • Replace "success or failure" by "one of KK classes": categorical.

    Now let time be continuous. Events happen at rate λ\lambda per unit of time: on average λ\lambda events per unit.

    • The waiting time to the first event: exponential Exp(λ)\text{Exp}(\lambda), the continuous version of the geometric.
    • The waiting time to the kk-th event: gamma Gamma(k,λ)\text{Gamma}(k, \lambda), a sum of kk exponential gaps.

    Two distributions describe probabilities themselves. A beta variable is a number in (0,1)(0, 1), for example an unknown click rate. A Dirichlet variable is a probability vector, for example the shares of KK classes. Both come from normalising independent gamma variables. Finally, the Gaussian N(μ,σ2)\mathcal N(\mu, \sigma^2) appears when many small independent effects add up (lesson 06).

    Interactive figure: loading…

    Choose a family and move its parameters, then press "Sample 1000". The orange bars or curve are the formula (PMF or PDF). The dark vertical line marks the mean, and the bar at the top spans mean ± one standard deviation. The blue histogram shows 1000 samples; compare the sample mean and variance with the formulas in the side panel. Try the gamma with k=1k = 1 (it is the exponential), and the beta with a=b=1a = b = 1 (it is the uniform distribution).

    From binomial to Poisson #

    A shop's website gets many visitors per hour. Each visitor buys with a small probability. The number of orders in an hour is binomial with a large nn and a small pp. In practice, nobody knows nn and pp separately; only the average λ=np\lambda = np is easy to measure. The Poisson distribution needs only λ\lambda:

    P(N=k)=e−λλkk!,k=0,1,2,…P(N = k) = e^{-\lambda} \frac{\lambda^k}{k!}, \qquad k = 0, 1, 2, \dots
    Interactive figure: loading…

    Increase the number of trials nn, with the mean λ=np\lambda = np fixed. The blue bars are Bin(n,λ/n)\text{Bin}(n, \lambda/n); the orange bars are Poisson(λ)\text{Poisson}(\lambda). With n=10n = 10 the binomial is visibly narrower. As nn grows, the bars agree. The side panel shows the total variation distance (the largest possible difference between the probabilities of any event) and Le Cam's bound np2=λ2/nnp^2 = \lambda^2/n: both shrink like 1/n1/n.

    Quick check

    A factory makes 5,000 chips per day. Each chip is defective with probability 0.0004, independently. Which statement about the number of defective chips in a day is correct?

    Events in continuous time #

    Now spread the events over time. A Poisson process with rate λ\lambda is a random set of time points with two properties: the numbers of events in disjoint time windows are independent, and the number in a window of length tt is Poisson(λt)\text{Poisson}(\lambda t). Equivalently, the gaps between consecutive events are independent Exp(λ)\text{Exp}(\lambda) waiting times. Section 3 proves that the two descriptions agree.

    Interactive figure: loading…

    Press "New run", then make the run longer. Blue ticks on the timeline are events at rate λ\lambda. The left histogram collects the gaps between events, the right one the counts in windows of length 1. The orange curves are the formulas Exp(λ)\text{Exp}(\lambda) and Poisson(λ)\text{Poisson}(\lambda). Then lower the keep probability qq: each event is kept (aqua) or removed (magenta) by an independent coin. The kept events again form a Poisson process, with rate qλq\lambda (thinning).

    Quick check

    In the figure, λ=2\lambda = 2 and q=1q = 1. About what share of the windows of length 1 are empty?

    3. Definitions and main results #

    The table #

    Notation. We use the rate for the exponential and the gamma: Exp(λ)\text{Exp}(\lambda) has mean 1/λ1/\lambda, and Gamma(k,β)\text{Gamma}(k, \beta) has mean k/βk/\beta (here β\beta is a rate; it has nothing to do with the second parameter bb of the beta). N(μ,σ2)\mathcal N(\mu, \sigma^2) is given by its variance. The gamma function is Γ(a)=∫0∞xa−1e−x dx\Gamma(a) = \int_0^\infty x^{a-1} e^{-x}\,dx for a>0a > 0. Integration by parts gives Γ(a+1)=a Γ(a)\Gamma(a + 1) = a\,\Gamma(a), so Γ(n)=(n−1)!\Gamma(n) = (n-1)! for integers n≥1n \ge 1. The beta function is B(a,b)=Γ(a)Γ(b)/Γ(a+b)B(a, b) = \Gamma(a)\Gamma(b)/\Gamma(a + b).

    Distribution Support PMF / PDF Mean Variance Models
    Bernoulli(p)\text{Bernoulli}(p) {0,1}\{0, 1\} px(1−p)1−xp^x (1-p)^{1-x} pp p(1−p)p(1-p) one yes/no outcome (a click, a correct label)
    Bin(n,p)\text{Bin}(n, p) {0,…,n}\{0, \dots, n\} (nx)px(1−p)n−x\binom{n}{x} p^x (1-p)^{n-x} npnp np(1−p)np(1-p) successes in nn independent trials
    Geom(p)\text{Geom}(p), trials {1,2,… }\{1, 2, \dots\} (1−p)x−1p(1-p)^{x-1} p 1/p1/p (1−p)/p2(1-p)/p^2 trials up to and including the first success
    Poisson(λ)\text{Poisson}(\lambda) {0,1,… }\{0, 1, \dots\} e−λλx/x!e^{-\lambda} \lambda^x / x! λ\lambda λ\lambda counts of rare independent events in a window
    Cat(p1,…,pK)\text{Cat}(p_1, \dots, p_K) {1,…,K}\{1, \dots, K\} pxp_x one-hot: pp one-hot: diag⁡(p)−pp⊤\operatorname{diag}(p) - pp^\top one class label
    Exp(λ)\text{Exp}(\lambda) [0,∞)[0, \infty) λe−λx\lambda e^{-\lambda x} 1/λ1/\lambda 1/λ21/\lambda^2 waiting time to the next event
    Gamma(k,β)\text{Gamma}(k, \beta) (0,∞)(0, \infty) βkxk−1e−βxΓ(k)\dfrac{\beta^k x^{k-1} e^{-\beta x}}{\Gamma(k)} k/βk/\beta k/β2k/\beta^2 waiting time to the kk-th event; positive, skewed amounts
    Beta(a,b)\text{Beta}(a, b) (0,1)(0, 1) xa−1(1−x)b−1B(a,b)\dfrac{x^{a-1}(1-x)^{b-1}}{B(a, b)} aa+b\dfrac{a}{a+b} ab(a+b)2(a+b+1)\dfrac{ab}{(a+b)^2(a+b+1)} an unknown probability or proportion
    N(μ,σ2)\mathcal N(\mu, \sigma^2) R\mathbb{R} 12πσ2e−(x−μ)2/(2σ2)\dfrac{1}{\sqrt{2\pi\sigma^2}} e^{-(x-\mu)^2/(2\sigma^2)} μ\mu σ2\sigma^2 a sum of many small effects; measurement noise
    Dir(α1,…,αK)\text{Dir}(\alpha_1, \dots, \alpha_K) simplex Γ(α0)∏iΓ(αi)∏ixiαi−1\dfrac{\Gamma(\alpha_0)}{\prod_i \Gamma(\alpha_i)} \prod_i x_i^{\alpha_i - 1} αi/α0\alpha_i / \alpha_0 αi(α0−αi)α02(α0+1)\dfrac{\alpha_i(\alpha_0 - \alpha_i)}{\alpha_0^2(\alpha_0 + 1)} a probability vector (class shares, mixture weights)

    All parameters are positive, and p∈(0,1)p \in (0, 1). For the Dirichlet, α0=∑iαi\alpha_0 = \sum_i \alpha_i, and the simplex is the set of vectors with xi>0x_i > 0 and ∑ixi=1\sum_i x_i = 1. For the categorical, the mean and covariance are those of the one-hot vector eXe_X (a 1 in position XX, 0 elsewhere).

    Special cases. Exp(λ)=Gamma(1,λ)\text{Exp}(\lambda) = \text{Gamma}(1, \lambda). Bernoulli(p)=Bin(1,p)\text{Bernoulli}(p) = \text{Bin}(1, p). Beta(1,1)\text{Beta}(1, 1) is the uniform distribution on (0,1)(0, 1). Beta(a,b)\text{Beta}(a, b) is the Dirichlet with K=2K = 2 (the first component). Each mean and variance in the table follows from the definitions of lesson 02; the MGF below gives most of them in two lines.

    Two Dirichlet facts. The components compete for a fixed total of 1, so they are negatively correlated: Cov⁡(Xi,Xj)=−αiαj/(α02(α0+1))\operatorname{Cov}(X_i, X_j) = -\alpha_i\alpha_j / (\alpha_0^2(\alpha_0 + 1)) for i≠ji \ne j. A large α0\alpha_0 means little spread around the mean α/α0\alpha/\alpha_0.

    Relation 1: from binomial to Poisson #

    Theorem. Fix λ>0\lambda > 0 and k≥0k \ge 0. Then P(Bin(n,λ/n)=k)→e−λλk/k!P(\text{Bin}(n, \lambda/n) = k) \to e^{-\lambda}\lambda^k/k! as n→∞n \to \infty.

    Proof.

    1. Write the PMF with p=λ/np = \lambda/n and regroup the factors:
    (nk)(λn)k(1−λn)n−k=n(n−1)⋯(n−k+1)nk⋅λkk!⋅(1−λn)n⋅(1−λn)−k.\begin{aligned} &\binom{n}{k}\Big(\frac{\lambda}{n}\Big)^k \Big(1 - \frac{\lambda}{n}\Big)^{n-k} \\ &= \frac{n(n-1)\cdots(n-k+1)}{n^k} \cdot \frac{\lambda^k}{k!} \cdot \Big(1 - \frac{\lambda}{n}\Big)^n \cdot \Big(1 - \frac{\lambda}{n}\Big)^{-k}. \end{aligned}
    1. The first factor is a product of kk terms (n−j)/n(n - j)/n, and each one tends to 1 (kk is fixed).
    2. (1−λ/n)n→e−λ(1 - \lambda/n)^n \to e^{-\lambda} (the definition of exe^x as a limit), and (1−λ/n)−k→1(1 - \lambda/n)^{-k} \to 1.
    3. So the product tends to 1⋅λkk!⋅e−λ⋅11 \cdot \frac{\lambda^k}{k!} \cdot e^{-\lambda} \cdot 1. ■\blacksquare

    How good is it for a finite nn? The total variation distance between two distributions PP and QQ on the integers is dTV=12∑k∣P(k)−Q(k)∣d_{TV} = \frac12 \sum_k |P(k) - Q(k)|. It is the largest difference ∣P(A)−Q(A)∣|P(A) - Q(A)| over all events AA. Le Cam's inequality says that a sum of independent Bernoulli(pi)\text{Bernoulli}(p_i) variables is within total variation distance ∑ipi2\sum_i p_i^2 of Poisson(∑ipi)\text{Poisson}(\sum_i p_i). For Bin(n,p)\text{Bin}(n, p), the bound is np2np^2. It is small when pp is small, even if npnp is not. The trials may even have different pip_i.

    Why the bound is ∑ipi2\sum_i p_i^2: coupling

    Le Cam's inequality is proved by a coupling: build the Bernoulli BiB_i and a Poisson(pi)\text{Poisson}(p_i) variable QiQ_i on the same probability space so that they are equal most of the time. One can do it with P(Bi≠Qi)≤pi2P(B_i \ne Q_i) \le p_i^2. Then ∑iQi∼Poisson(∑ipi)\sum_i Q_i \sim \text{Poisson}(\sum_i p_i) (sums of independent Poissons are Poisson, below), and the two sums differ only if some pair differs. By the union bound of lesson 01, P(∑Bi≠∑Qi)≤∑ipi2P(\sum B_i \ne \sum Q_i) \le \sum_i p_i^2, and dTVd_{TV} is at most this probability.

    Relation 2: memorylessness #

    Theorem. If X∼Exp(λ)X \sim \text{Exp}(\lambda), then for all s,t≥0s, t \ge 0,

    P(X>s+t∣X>s)=P(X>t).P(X > s + t \mid X > s) = P(X > t) .

    Proof.

    1. The survival function is P(X>x)=∫x∞λe−λu du=e−λxP(X > x) = \int_x^\infty \lambda e^{-\lambda u}\,du = e^{-\lambda x} for x≥0x \ge 0.
    2. The event {X>s+t}\{X > s + t\} is a subset of {X>s}\{X > s\}, so their intersection is {X>s+t}\{X > s + t\}.
    3. By the definition of conditional probability, P(X>s+t∣X>s)=e−λ(s+t)/e−λs=e−λt=P(X>t)P(X > s + t \mid X > s) = e^{-\lambda(s+t)} / e^{-\lambda s} = e^{-\lambda t} = P(X > t). ■\blacksquare

    In words: if you have already waited ss, the remaining wait has the same distribution as a fresh wait. For a lifetime, it means the item does not age. The geometric distribution has the discrete version: P(X>n)=(1−p)nP(X > n) = (1-p)^n (the first nn trials fail), so P(X>m+n∣X>m)=(1−p)nP(X > m + n \mid X > m) = (1-p)^n.

    These are the only memoryless distributions on (0,∞)(0, \infty) and on {1,2,… }\{1, 2, \dots\}. Memorylessness says that the survival function G(x)=P(X>x)G(x) = P(X > x) satisfies G(s+t)=G(s) G(t)G(s + t) = G(s)\,G(t). The only non-increasing solutions with 0<G<10 < G < 1 are G(t)=e−λtG(t) = e^{-\lambda t} on (0,∞)(0, \infty) and G(n)=(1−p)nG(n) = (1-p)^n on the integers.

    Interactive figure: loading…

    Drag "already waited ss", then change the lifetime family. The orange curve is the survival curve P(X>t)P(X > t) of a new item, with mean lifetime 10 years. The yellow part is the curve beyond ss. Rescaled by 1/P(X>s)1/P(X > s) and moved back to time 0, it becomes the aqua curve: the survival curve of an item that has already lasted ss. For the exponential, aqua and orange are the same curve. For a gamma with k=3k = 3 (wear-out), an item that lasted 10 years survives 10 more with probability 0.146 instead of 0.423 for a new one. Press "Simulate" to count 10,000 simulated lifetimes (blue).

    The minimum of exponentials. Let X1,…,XmX_1, \dots, X_m be independent, Xi∼Exp(λi)X_i \sim \text{Exp}(\lambda_i). The minimum is larger than tt only if every XiX_i is, so P(min⁡iXi>t)=∏ie−λit=e−(∑iλi)tP(\min_i X_i > t) = \prod_i e^{-\lambda_i t} = e^{-(\sum_i \lambda_i) t}. Hence

    min⁡iXi∼Exp(∑iλi),P(X1 is the smallest)=λ1∑iλi.\min_i X_i \sim \text{Exp}\Big(\sum_i \lambda_i\Big), \qquad P(X_1 \text{ is the smallest}) = \frac{\lambda_1}{\sum_i \lambda_i} .

    Competing exponential clocks: the first one rings at the total rate, and clock ii wins with a probability proportional to its rate. (The second formula is ∫0∞λ1e−λ1t e−(∑i≥2λi)t dt\int_0^\infty \lambda_1 e^{-\lambda_1 t}\, e^{-(\sum_{i \ge 2} \lambda_i) t}\,dt.)

    Quick check

    A web server fails after an Exp(λ)\text{Exp}(\lambda) time with mean 200 days. It has run without failure for 300 days. What is its expected remaining time until failure?

    Moment generating functions #

    Definition. The moment generating function (MGF) of XX is MX(t)=E[etX]M_X(t) = \mathbb{E}[e^{tX}]. We use it when it is finite for all tt in an open interval (−h,h)(-h, h) around 0, with h>0h > 0.

    Theorem (three MGF facts). Assume MXM_X is finite on (−h,h)(-h, h).

    • (a) Moments: E[Xn]=MX(n)(0)\mathbb{E}[X^n] = M_X^{(n)}(0), the nn-th derivative at 0.
    • (b) Sums: if XX and YY are independent, MX+Y(t)=MX(t) MY(t)M_{X+Y}(t) = M_X(t)\,M_Y(t).
    • (c) Uniqueness: if MX=MYM_X = M_Y on some interval (−h,h)(-h, h), then XX and YY have the same distribution.

    Proof of (a) and (b). (c) is a deep result; we use it without proof.

    1. (a) Expand etX=∑n≥0tnXn/n!e^{tX} = \sum_{n \ge 0} t^n X^n / n!. When MXM_X is finite near 0, you may take the expectation term by term: MX(t)=∑n≥0E[Xn] tn/n!M_X(t) = \sum_{n \ge 0} \mathbb{E}[X^n]\, t^n / n!.
    2. A power series is the Taylor series of its sum, so the coefficient of tn/n!t^n/n! is MX(n)(0)M_X^{(n)}(0). Hence E[Xn]=MX(n)(0)\mathbb{E}[X^n] = M_X^{(n)}(0).
    3. (b) et(X+Y)=etXetYe^{t(X+Y)} = e^{tX} e^{tY}. For independent XX and YY, the mean of a product of a function of XX and a function of YY is the product of the means (lesson 04). ■\blacksquare

    It is often easier to use the cumulant generating function KX(t)=log⁡MX(t)K_X(t) = \log M_X(t). Since M(0)=1M(0) = 1, differentiating twice gives KX′(0)=E[X]K_X'(0) = \mathbb{E}[X] and KX′′(0)=Var⁡(X)K_X''(0) = \operatorname{Var}(X).

    Distribution MGF M(t)M(t) Valid for
    Bernoulli(p)\text{Bernoulli}(p) 1−p+pet1 - p + pe^t all tt
    Bin(n,p)\text{Bin}(n, p) (1−p+pet)n(1 - p + pe^t)^n all tt
    Poisson(λ)\text{Poisson}(\lambda) exp⁡(λ(et−1))\exp(\lambda(e^t - 1)) all tt
    Geom(p)\text{Geom}(p), trials pet/(1−(1−p)et)pe^t / (1 - (1-p)e^t) t<−ln⁡(1−p)t < -\ln(1-p)
    Exp(λ)\text{Exp}(\lambda) λ/(λ−t)\lambda / (\lambda - t) t<λt < \lambda
    Gamma(k,β)\text{Gamma}(k, \beta) (β/(β−t))k(\beta / (\beta - t))^k t<βt < \beta
    N(μ,σ2)\mathcal N(\mu, \sigma^2) exp⁡(μt+σ2t2/2)\exp(\mu t + \sigma^2 t^2 / 2) all tt

    Example (moments of the gamma). K(t)=−klog⁡(1−t/β)K(t) = -k \log(1 - t/\beta), so K′(t)=k/(β−t)K'(t) = k/(\beta - t) and K′′(t)=k/(β−t)2K''(t) = k/(\beta - t)^2. At t=0t = 0: mean k/βk/\beta and variance k/β2k/\beta^2. For the Poisson, K(t)=λ(et−1)K(t) = \lambda(e^t - 1), so K′(0)=K′′(0)=λK'(0) = K''(0) = \lambda: the mean equals the variance.

    Example (sums). Products of MGFs give at once, for independent summands:

    • Bin(n,p)\text{Bin}(n, p) is a sum of nn independent Bernoullis: (1−p+pet)n(1 - p + pe^t)^n;
    • Poisson(λ1)+Poisson(λ2)=Poisson(λ1+λ2)\text{Poisson}(\lambda_1) + \text{Poisson}(\lambda_2) = \text{Poisson}(\lambda_1 + \lambda_2);
    • N(μ1,σ12)+N(μ2,σ22)=N(μ1+μ2,σ12+σ22)\mathcal N(\mu_1, \sigma_1^2) + \mathcal N(\mu_2, \sigma_2^2) = \mathcal N(\mu_1 + \mu_2, \sigma_1^2 + \sigma_2^2);
    • Gamma(a,β)+Gamma(b,β)=Gamma(a+b,β)\text{Gamma}(a, \beta) + \text{Gamma}(b, \beta) = \text{Gamma}(a + b, \beta), with the same rate β\beta.
    Not every distribution has an MGF

    The Cauchy, the Student-tt and the log-normal distributions have E[etX]=∞\mathbb{E}[e^{tX}] = \infty for every t>0t > 0: their right tails are too heavy. The log-normal even has all moments E[Xn]\mathbb{E}[X^n], but they do not determine its distribution. The characteristic function φX(t)=E[eitX]\varphi_X(t) = \mathbb{E}[e^{itX}] always exists, because ∣eitX∣=1|e^{itX}| = 1, and it has the same product rule for sums and the same uniqueness property. Proofs of the central limit theorem often use it for this reason.

    Relation 3: a sum of exponentials is gamma #

    Theorem. If X1,…,XnX_1, \dots, X_n are i.i.d. Exp(λ)\text{Exp}(\lambda), then S=X1+⋯+Xn∼Gamma(n,λ)S = X_1 + \dots + X_n \sim \text{Gamma}(n, \lambda).

    Proof.

    1. For t<λt < \lambda: MXi(t)=∫0∞etxλe−λx dx=λ∫0∞e−(λ−t)x dx=λλ−tM_{X_i}(t) = \int_0^\infty e^{tx} \lambda e^{-\lambda x}\,dx = \lambda \int_0^\infty e^{-(\lambda - t)x}\,dx = \dfrac{\lambda}{\lambda - t}.
    2. By independence and fact (b), MS(t)=(λλ−t)nM_S(t) = \left(\dfrac{\lambda}{\lambda - t}\right)^n.
    3. The MGF of Gamma(n,λ)\text{Gamma}(n, \lambda) is ∫0∞etxλnxn−1e−λxΓ(n) dx=λnΓ(n)⋅Γ(n)(λ−t)n\displaystyle\int_0^\infty e^{tx} \frac{\lambda^n x^{n-1} e^{-\lambda x}}{\Gamma(n)}\,dx = \frac{\lambda^n}{\Gamma(n)} \cdot \frac{\Gamma(n)}{(\lambda - t)^n}, using ∫0∞xn−1e−cx dx=Γ(n)/cn\int_0^\infty x^{n-1} e^{-cx}\,dx = \Gamma(n)/c^n for c>0c > 0 (substitute u=cxu = cx).
    4. The two MGFs agree on (−λ,λ)(-\lambda, \lambda), so by uniqueness (c), S∼Gamma(n,λ)S \sim \text{Gamma}(n, \lambda). ■\blacksquare

    So the time of the kk-th event, when gaps are Exp(λ)\text{Exp}(\lambda), is Gamma(k,λ)\text{Gamma}(k, \lambda), with mean k/λk/\lambda. With integer kk the gamma is also called the Erlang distribution.

    Quick check

    X∼Gamma(2,3)X \sim \text{Gamma}(2, 3) and Y∼Gamma(4,3)Y \sim \text{Gamma}(4, 3) are independent (shape, rate). What is the distribution of X+YX + Y, and its mean?

    Relation 4: gamma ratios give the beta and the Dirichlet #

    Theorem. Let X∼Gamma(a,1)X \sim \text{Gamma}(a, 1) and Y∼Gamma(b,1)Y \sim \text{Gamma}(b, 1) be independent. Then

    T=XX+Y∼Beta(a,b),S=X+Y∼Gamma(a+b,1),T = \frac{X}{X + Y} \sim \text{Beta}(a, b), \qquad S = X + Y \sim \text{Gamma}(a + b, 1),

    and TT and SS are independent.

    Proof with a two-dimensional change of variables

    We use the change of variables for a pair: the density of the new pair is the old density times ∣det⁡J∣|\det J|, where JJ is the Jacobian of the inverse map. This is the 2-D version of the rule in lesson 02; lesson 05 treats it fully.

    1. The inverse map is x=stx = st, y=s(1−t)y = s(1 - t), for s>0s > 0 and t∈(0,1)t \in (0, 1).
    2. J=(∂x/∂s∂x/∂t∂y/∂s∂y/∂t)=(ts1−t−s)J = \begin{pmatrix} \partial x/\partial s & \partial x/\partial t \\ \partial y/\partial s & \partial y/\partial t \end{pmatrix} = \begin{pmatrix} t & s \\ 1 - t & -s \end{pmatrix}, so det⁡J=−st−s(1−t)=−s\det J = -st - s(1 - t) = -s and ∣det⁡J∣=s|\det J| = s.
    3. The joint density of (X,Y)(X, Y) is the product xa−1e−xΓ(a)⋅yb−1e−yΓ(b)\frac{x^{a-1}e^{-x}}{\Gamma(a)} \cdot \frac{y^{b-1}e^{-y}}{\Gamma(b)} (independence). Substitute and multiply by ss:
    p(s,t)=(st)a−1(s(1−t))b−1e−sΓ(a)Γ(b) s=sa+b−1e−sΓ(a+b)⏟Gamma(a+b, 1)⋅Γ(a+b)Γ(a)Γ(b)ta−1(1−t)b−1⏟Beta(a, b).p(s, t) = \frac{(st)^{a-1} (s(1-t))^{b-1} e^{-s}}{\Gamma(a)\Gamma(b)}\, s = \underbrace{\frac{s^{a+b-1} e^{-s}}{\Gamma(a+b)}}_{\text{Gamma}(a+b,\,1)} \cdot \underbrace{\frac{\Gamma(a+b)}{\Gamma(a)\Gamma(b)} t^{a-1}(1-t)^{b-1}}_{\text{Beta}(a,\,b)}.
    1. The joint density is a density of ss times a density of tt. So SS and TT are independent, with the stated distributions. ■\blacksquare

    Both factors integrate to 1, so the proof also shows B(a,b)=Γ(a)Γ(b)/Γ(a+b)B(a, b) = \Gamma(a)\Gamma(b)/\Gamma(a+b).

    The rate does not matter: with a common rate β\beta, every gamma is scaled by 1/β1/\beta, and the scale cancels in X/(X+Y)X/(X + Y).

    Dirichlet. In the same way (with a KK-dimensional Jacobian): if Gi∼Gamma(αi,1)G_i \sim \text{Gamma}(\alpha_i, 1) are independent and S=∑iGiS = \sum_i G_i, then

    (G1S,…,GKS)∼Dir(α1,…,αK).\Big(\frac{G_1}{S}, \dots, \frac{G_K}{S}\Big) \sim \text{Dir}(\alpha_1, \dots, \alpha_K) .

    This is how Dirichlet samples are made in practice (NumPy's rng.dirichlet does it).

    Interactive figure: loading…

    Move the three α\alpha sliders, or try the presets. Each point is one probability vector (x1,x2,x3)(x_1, x_2, x_3), drawn by normalising three independent gammas; each corner is one class with probability 1. Blue points are samples, and the orange dot is the mean α/α0\alpha/\alpha_0. With all α=1\alpha = 1 the points fill the triangle evenly. With all α=0.2\alpha = 0.2 they crowd into the corners and edges (sparse vectors: most mass on one or two classes). With all α=5\alpha = 5 they gather near the centre. The side panel compares the variance and covariance with the formulas.

    Relation 5: Dirichlet marginals are beta #

    Theorem. If X∼Dir(α1,…,αK)X \sim \text{Dir}(\alpha_1, \dots, \alpha_K), then Xi∼Beta(αi,α0−αi)X_i \sim \text{Beta}(\alpha_i, \alpha_0 - \alpha_i).

    Proof.

    1. Build XX from independent gammas: Xi=Gi/(Gi+R)X_i = G_i / (G_i + R), with R=∑j≠iGjR = \sum_{j \ne i} G_j.
    2. RR is a sum of independent Gamma(αj,1)\text{Gamma}(\alpha_j, 1) variables with the same rate, so R∼Gamma(α0−αi,1)R \sim \text{Gamma}(\alpha_0 - \alpha_i, 1) (MGF sums). RR is independent of GiG_i.
    3. Relation 4 with a=αia = \alpha_i and b=α0−αib = \alpha_0 - \alpha_i gives Xi∼Beta(αi,α0−αi)X_i \sim \text{Beta}(\alpha_i, \alpha_0 - \alpha_i). ■\blacksquare

    The beta mean and variance then give the Dirichlet mean αi/α0\alpha_i/\alpha_0 and the variance in the table. The same argument shows that merging components adds their α\alpha's: (X1+X2,X3,… )∼Dir(α1+α2,α3,… )(X_1 + X_2, X_3, \dots) \sim \text{Dir}(\alpha_1 + \alpha_2, \alpha_3, \dots).

    The Poisson process #

    Definition A (gaps). Let G1,G2,…G_1, G_2, \dots be i.i.d. Exp(λ)\text{Exp}(\lambda). The event times are Tk=G1+⋯+GkT_k = G_1 + \dots + G_k, and N(t)N(t) is the number of events in [0,t][0, t].

    Definition B (counts). N(0)=0N(0) = 0; the counts in disjoint intervals are independent; and N(t)−N(s)∼Poisson(λ(t−s))N(t) - N(s) \sim \text{Poisson}(\lambda(t - s)) for s<ts < t.

    Why the two definitions agree (sketch).

    1. By relation 3, Tk∼Gamma(k,λ)T_k \sim \text{Gamma}(k, \lambda).
    2. There are at least kk events by time tt exactly when the kk-th event happens by time tt: {N(t)≥k}={Tk≤t}\{N(t) \ge k\} = \{T_k \le t\}.
    3. Integration by parts (k−1k - 1 times) shows that the Gamma(k,λ)\text{Gamma}(k, \lambda) CDF is P(Tk≤t)=1−∑j<ke−λt(λt)j/j!P(T_k \le t) = 1 - \sum_{j < k} e^{-\lambda t}(\lambda t)^j/j!. That is P(N(t)≥k)P(N(t) \ge k) for N(t)∼Poisson(λt)N(t) \sim \text{Poisson}(\lambda t).
    4. Independence of disjoint intervals comes from memorylessness: at any time ss, the wait for the next event is again Exp(λ)\text{Exp}(\lambda) and does not depend on what happened before ss.

    Thinning. Keep each event independently with probability qq. Then the kept events form a Poisson process with rate qλq\lambda, the removed events form one with rate (1−q)λ(1 - q)\lambda, and the two are independent.

    Proof (counts in one window of length tt).

    1. Given N(t)=nN(t) = n, the kept count CC is Bin(n,q)\text{Bin}(n, q), and the removed count is R=n−CR = n - C.
    2. So P(C=k,R=r)=P(N(t)=k+r) (k+rk)qk(1−q)rP(C = k, R = r) = P(N(t) = k + r)\,\binom{k + r}{k} q^k (1 - q)^r =e−λt(λt)k+r(k+r)!⋅(k+r)!k! r! qk(1−q)r= e^{-\lambda t}\dfrac{(\lambda t)^{k + r}}{(k + r)!} \cdot \dfrac{(k + r)!}{k!\,r!}\, q^k (1 - q)^r.
    3. Split e−λt=e−qλte−(1−q)λte^{-\lambda t} = e^{-q\lambda t} e^{-(1-q)\lambda t} and (λt)k+r=(λt)k(λt)r(\lambda t)^{k+r} = (\lambda t)^k (\lambda t)^r: P(C=k,R=r)=e−qλt(qλt)kk!⋅e−(1−q)λt((1−q)λt)rr!P(C = k, R = r) = e^{-q\lambda t}\dfrac{(q\lambda t)^k}{k!} \cdot e^{-(1 - q)\lambda t}\dfrac{((1 - q)\lambda t)^r}{r!}.
    4. The joint PMF is a Poisson(qλt)\text{Poisson}(q\lambda t) PMF times a Poisson((1−q)λt)\text{Poisson}((1-q)\lambda t) PMF, so CC and RR are independent Poissons. Disjoint windows stay independent, because the coins are independent. ■\blacksquare

    Superposition. The union of two independent Poisson processes with rates λ1\lambda_1 and λ2\lambda_2 is a Poisson process with rate λ1+λ2\lambda_1 + \lambda_2: a sum of independent Poisson counts is Poisson (MGFs). Each event comes from process 1 with probability λ1/(λ1+λ2)\lambda_1/(\lambda_1 + \lambda_2), the probability that its exponential clock rings first.

    Conditional uniformity. Given N(T)=nN(T) = n, the nn event times are distributed like nn i.i.d. U(0,T)U(0, T) points, sorted. So, given 4 events in an hour, the number in the first 15 minutes is Bin(4,1/4)\text{Bin}(4, 1/4).

    The inspection paradox: why your bus is late

    Buses arrive as a Poisson process with on average one bus every 10 minutes. You arrive at a random time. By memorylessness, your expected wait is 10 minutes, not 5. And the time since the last bus is also about 10 minutes on average (for a process that has run for a long time). So the gap you land in has mean 20 minutes, twice the average gap. This is not a contradiction: a random arrival time is more likely to fall into a long gap than into a short one. The same length-biased sampling appears when you sample "a random user's session" by picking a random time point.

    Answers to section 1. (1) The count is Poisson(2)\text{Poisson}(2), so P(N=0)=e−2≈0.135P(N = 0) = e^{-2} \approx 0.135. (2) P(X>20∣X>10)=P(X>10)=e−10/10=e−1≈0.368P(X > 20 \mid X > 10) = P(X > 10) = e^{-10/10} = e^{-1} \approx 0.368, exactly the same as for a new disk. The exponential model says that the disk does not age; if real disks wear out, the exponential is the wrong model. (3) Poisson(2)\text{Poisson}(2), because np=1000⋅0.002=2np = 1000 \cdot 0.002 = 2 and pp is small (Le Cam's bound np2=0.004np^2 = 0.004).

    4. Worked example #

    A website gets support tickets as a Poisson process with rate λ=2\lambda = 2 per day.

    Counts. NN = tickets in one day, N∼Poisson(2)N \sim \text{Poisson}(2).

    1. P(N=0)=e−2≈0.1353P(N = 0) = e^{-2} \approx 0.1353.
    2. P(N≥3)=1−P(N≤2)=1−e−2(1+2+222)=1−5e−2≈0.3233P(N \ge 3) = 1 - P(N \le 2) = 1 - e^{-2}\big(1 + 2 + \tfrac{2^2}{2}\big) = 1 - 5e^{-2} \approx 0.3233.

    The binomial view. Split the day into 1440 minutes. In each minute a ticket arrives with probability 2/14402/1440, independently (ignore two tickets in the same minute). Then N∼Bin(1440,2/1440)N \sim \text{Bin}(1440, 2/1440), with P(N=0)=(1−2/1440)1440≈0.13515P(N = 0) = (1 - 2/1440)^{1440} \approx 0.13515 and P(N≥3)≈0.32332P(N \ge 3) \approx 0.32332. Le Cam's bound is np2=1440⋅(2/1440)2=4/1440≈0.0028np^2 = 1440 \cdot (2/1440)^2 = 4/1440 \approx 0.0028; the true total variation distance is about 0.0003.

    Waiting times.

    1. The wait for the first ticket is Exp(2)\text{Exp}(2): P(wait>1 day)=e−2P(\text{wait} > 1 \text{ day}) = e^{-2}. It is the same number as P(N=0)P(N = 0), because it is the same event.
    2. After 12 quiet hours, the remaining wait is again Exp(2)\text{Exp}(2), with mean 1/21/2 day (memorylessness).
    3. The time of the third ticket is T3∼Gamma(3,2)T_3 \sim \text{Gamma}(3, 2): mean 3/2=1.53/2 = 1.5 days, variance 3/22=0.753/2^2 = 0.75, standard deviation ≈0.866\approx 0.866 days.
    4. Check of the link: P(T3≤1)=P(N≥3)≈0.3233P(T_3 \le 1) = P(N \ge 3) \approx 0.3233.

    Thinning. Each ticket is urgent with probability 1/41/4, independently.

    1. Urgent tickets form a Poisson process with rate 2⋅1/4=0.52 \cdot 1/4 = 0.5 per day.
    2. P(no urgent ticket in a week)=e−0.5⋅7=e−3.5≈0.030P(\text{no urgent ticket in a week}) = e^{-0.5 \cdot 7} = e^{-3.5} \approx 0.030.
    3. Given 4 tickets in one day, the expected number in its first 6 hours is 4⋅6/24=14 \cdot 6/24 = 1 (conditional uniformity: Bin(4,1/4)\text{Bin}(4, 1/4)).

    A Dirichlet. A classifier is trained on data whose class shares are uncertain, modelled as X∼Dir(2,3,5)X \sim \text{Dir}(2, 3, 5), so α0=10\alpha_0 = 10.

    1. Mean (0.2,0.3,0.5)(0.2, 0.3, 0.5).
    2. X3∼Beta(5,5)X_3 \sim \text{Beta}(5, 5), with variance 5⋅5102⋅11=251100≈0.0227\dfrac{5 \cdot 5}{10^2 \cdot 11} = \dfrac{25}{1100} \approx 0.0227.
    3. Cov⁡(X1,X2)=−2⋅3102⋅11=−61100≈−0.0055\operatorname{Cov}(X_1, X_2) = -\dfrac{2 \cdot 3}{10^2 \cdot 11} = -\dfrac{6}{1100} \approx -0.0055.
    Quick check

    In the worked example (tickets at rate 2 per day), what is the probability that the first ticket of the day arrives in the first 6 hours?

    5. In code #

    SciPy checks the numbers of the worked example and the relations. Mind SciPy's parametrisation: scale is 1/rate1/\text{rate}, and the first positional argument of stats.expon is a shift (loc), not a rate.

    import numpy as np
    from scipy import stats, integrate
    
    # worked example: 2 tickets per day
    N = stats.poisson(2)
    print(round(N.pmf(0), 4), round(N.sf(2), 4))      # 0.1353 0.3233
    print(round(stats.binom(1440, 2 / 1440).sf(2), 4))   # 0.3233 (1440 minutes)
    T3 = stats.gamma(a=3, scale=1 / 2)                # shape 3, SCALE = 1/rate
    print(T3.mean(), T3.var(), round(T3.cdf(1), 4))   # 1.5 0.75 0.3233 = P(N >= 3)
    print(stats.expon(2).mean(), stats.expon(scale=1 / 2).mean())
    # 3.0 0.5  (the first one is loc=2, a shift!)
    print(round(np.exp(-0.5 * 7), 4))                 # 0.0302: no urgent ticket in a week
    
    # Binomial(n, 2/n) -> Poisson(2): total variation distance and Le Cam's bound
    for n in (10, 100, 1000):
        k = np.arange(n + 1)
        tv = 0.5 * (np.abs(stats.binom(n, 2 / n).pmf(k) - N.pmf(k)).sum() + N.sf(n))
        print(n, f"{tv:.2g}", f"{n * (2 / n) ** 2:.2g}")
    # 10 0.052 0.4 | 100 0.0046 0.04 | 1000 0.00045 0.004
    
    # Dirichlet(2, 3, 5): moments, and the marginal X_3 ~ Beta(5, 5)
    alpha = np.array([2.0, 3.0, 5.0])
    D = stats.dirichlet(alpha)
    print(D.mean(), np.round(D.var(), 4), round(stats.beta(5, 5).var(), 4))
    # [0.2 0.3 0.5] [0.0145 0.0191 0.0227] 0.0227
    rng = np.random.default_rng(0)
    G = rng.gamma(shape=alpha, size=(50_000, 3))      # independent Gamma(alpha_i, 1)
    X = G / G.sum(axis=1, keepdims=True)              # normalise: Dirichlet samples
    print(stats.kstest(X[:, 2], stats.beta(5, 5).cdf).pvalue > 0.01,
          round(np.cov(X[:, 0], X[:, 1])[0, 1], 4))   # True -0.0055
    
    # MGF of Gamma(3, rate 2) by numerical integration: e^{tx} times the
    # density 2^3 x^2 e^{-2x} / Gamma(3), written as one exponential (no overflow)
    f = lambda x, t: 2**3 / 2 * x**2 * np.exp((t - 2) * x)
    M = lambda t: integrate.quad(f, 0, np.inf, args=(t,))[0]
    print(round(M(0.5), 6), round((2 / (2 - 0.5)) ** 3, 6))   # 2.37037 2.37037
    
    # moments by finite differences
    h = 1e-3
    m1 = (M(h) - M(-h)) / (2 * h)
    m2 = (M(h) - 2 * M(0) + M(-h)) / h**2
    print(round(m1, 4), round(m2 - m1**2, 4))         # 1.5 0.75 (k/beta, k/beta^2)
    

    6. Where it shows up #

    • Losses are log-likelihoods. Bernoulli gives binary cross-entropy, categorical gives softmax cross-entropy (information theory, lesson 4), Gaussian with fixed variance gives the squared error, and Poisson gives the Poisson loss for count targets (torch.nn.PoissonNLLLoss). Lesson 08 derives these from maximum likelihood.
    • Priors. Beta for a probability (a click rate, the success rate of an arm in Thompson sampling), Dirichlet for mixture weights and topic proportions (LDA), gamma for a precision 1/σ21/\sigma^2. Lesson 10 shows why these are conjugate.
    • Traffic and queues. Requests to a web server, calls to a help desk and jobs on a cluster are first modelled as Poisson processes. Thinning gives the rate of a subset (errors, urgent calls); superposition merges sources.
    • Overdispersion. Real counts (orders per day, earthquakes per month) often have variance much larger than the mean, because the rate itself varies. A gamma mixture of Poissons, the negative binomial, is the standard fix. Earthquake catalogues cluster in time (aftershocks) and need self-exciting models.
    • Simulation. The Gillespie algorithm for chemical reactions uses the minimum of exponentials: the next reaction comes after an Exp(total rate)\text{Exp}(\text{total rate}) wait, and it is reaction ii with probability λi/∑jλj\lambda_i / \sum_j \lambda_j.
    • Diffusion models. A sum of independent Gaussians is Gaussian (MGF product). This is why the forward noising process has the closed form q(xt∣x0)=N(αˉt x0,(1−αˉt)I)q(x_t \mid x_0) = \mathcal N(\sqrt{\bar\alpha_t}\, x_0, (1 - \bar\alpha_t) I) (generative models, lesson 7).

    7. Common mistakes #

    • Rate versus scale. NumPy and SciPy use the scale 1/λ1/\lambda: rng.exponential(scale), rng.gamma(shape, scale), stats.expon(scale=1/lam). PyTorch's Exponential and Gamma use the rate. stats.expon(2) is a shift by 2, not a rate of 2.
    • Two geometric conventions. "Trials up to the first success" (support 1,2,…1, 2, \dots, mean 1/p1/p; SciPy and NumPy) or "failures before the first success" (support 0,1,…0, 1, \dots, mean (1−p)/p(1-p)/p). The variance (1−p)/p2(1-p)/p^2 is the same. Always check which one a book or a library uses.
    • Adding gammas with different rates. Gamma(a,β1)+Gamma(b,β2)\text{Gamma}(a, \beta_1) + \text{Gamma}(b, \beta_2) is not gamma when β1≠β2\beta_1 \ne \beta_2.
    • The Poisson parameter is a mean, not a probability. For 5,000 trials with p=0.0004p = 0.0004, use Poisson(2)\text{Poisson}(2), not Poisson(0.0004)\text{Poisson}(0.0004).
    • Forcing a Poisson on overdispersed counts. Compare the sample variance with the sample mean; for a Poisson their ratio is close to 1.
    • Assuming every variable has an MGF. The Cauchy, Student-tt and log-normal do not.
    • Treating Dirichlet components as independent betas. Each one is beta, but they sum to 1 and are negatively correlated.
    • Reading memorylessness as "nothing ever changes". It is a property of the waiting times: the past waiting gives no information about the remaining wait. Items that wear out are not memoryless.

    8. Check yourself #

    1. X∼Bin(20,0.1)X \sim \text{Bin}(20, 0.1). Give E[X]\mathbb{E}[X], Var⁡(X)\operatorname{Var}(X), P(X=0)P(X = 0) and the Poisson approximation of P(X=0)P(X = 0). Is the approximation as good as in section 4?
      AnswerMean 20⋅0.1=220 \cdot 0.1 = 2, variance 2⋅0.9=1.82 \cdot 0.9 = 1.8, P(0)=0.920≈0.1216P(0) = 0.9^{20} \approx 0.1216. Poisson(2)\text{Poisson}(2) gives e−2≈0.1353e^{-2} \approx 0.1353. It is worse: p=0.1p = 0.1 is not small, and Le Cam's bound np2=0.2np^2 = 0.2 is much larger than 0.00280.0028 (the true total variation distance is about 0.024).
    2. Show that the geometric distribution (trials) is memoryless.
      AnswerP(X>n)=P(the first n trials fail)=(1−p)nP(X > n) = P(\text{the first } n \text{ trials fail}) = (1-p)^n. So P(X>m+n∣X>m)=(1−p)m+n/(1−p)m=(1−p)n=P(X>n)P(X > m + n \mid X > m) = (1-p)^{m+n}/(1-p)^m = (1-p)^n = P(X > n).
    3. Use MGFs to show that the sum of independent Poisson(λ1)\text{Poisson}(\lambda_1) and Poisson(λ2)\text{Poisson}(\lambda_2) variables is Poisson(λ1+λ2)\text{Poisson}(\lambda_1 + \lambda_2).
      AnswerM(t)=eλ1(et−1) eλ2(et−1)=e(λ1+λ2)(et−1)M(t) = e^{\lambda_1(e^t - 1)}\, e^{\lambda_2(e^t - 1)} = e^{(\lambda_1 + \lambda_2)(e^t - 1)}. This is the MGF of Poisson(λ1+λ2)\text{Poisson}(\lambda_1 + \lambda_2), finite for all tt; uniqueness finishes the proof.
    4. Get the mean and the variance of Exp(λ)\text{Exp}(\lambda) from its MGF.
      AnswerK(t)=log⁡λ−log⁡(λ−t)K(t) = \log\lambda - \log(\lambda - t), so K′(t)=1/(λ−t)K'(t) = 1/(\lambda - t) and K′′(t)=1/(λ−t)2K''(t) = 1/(\lambda - t)^2. At t=0t = 0: mean 1/λ1/\lambda, variance 1/λ21/\lambda^2. (Or M′(0)=1/λM'(0) = 1/\lambda and M′′(0)=2/λ2M''(0) = 2/\lambda^2, so the variance is 2/λ2−1/λ22/\lambda^2 - 1/\lambda^2.)
    5. X∼Dir(2,3,5)X \sim \text{Dir}(2, 3, 5). What is the distribution of X1+X2X_1 + X_2?
      AnswerMerging components adds the α\alpha's: (X1+X2,X3)∼Dir(5,5)(X_1 + X_2, X_3) \sim \text{Dir}(5, 5), so X1+X2∼Beta(5,5)X_1 + X_2 \sim \text{Beta}(5, 5), with mean 0.5. (It is also 1−X31 - X_3, and X3∼Beta(5,5)X_3 \sim \text{Beta}(5, 5).)
    6. You have a sampler for Gamma(a,1)\text{Gamma}(a, 1) only. How do you sample Beta(3,7)\text{Beta}(3, 7), and what are its mean and variance?
      AnswerX/(X+Y)X/(X + Y) with independent X∼Gamma(3,1)X \sim \text{Gamma}(3, 1) and Y∼Gamma(7,1)Y \sim \text{Gamma}(7, 1). Mean 3/10=0.33/10 = 0.3, variance 3⋅7102⋅11=21/1100≈0.0191\dfrac{3 \cdot 7}{10^2 \cdot 11} = 21/1100 \approx 0.0191.
    Recall cardsAnswer in your head first, then reveal. Add the cards to your review deck to see them again just before you would forget.
    1. Give the Poisson PMF, its mean and its variance.

    2. When is Bin(n,p)\text{Bin}(n, p) close to Poisson(np)\text{Poisson}(np), and how close?

    3. State memorylessness of the exponential distribution.

    4. What is the distribution of the minimum of independent Exp(λ1)\text{Exp}(\lambda_1) and Exp(λ2)\text{Exp}(\lambda_2)?

    5. How does the MGF of a sum of independent variables relate to their MGFs?

    6. What is the distribution of a sum of kk i.i.d. Exp(λ)\text{Exp}(\lambda) variables?

    7. Give the mean of Beta(a,b)\text{Beta}(a, b), and compute it for Beta(2,8)\text{Beta}(2, 8).

    8. How do you sample a Dirichlet from gamma variables?

    9. Give the two equivalent definitions of a Poisson process with rate λ\lambda.

    10. What is thinning of a Poisson process?

    Open the review →

    9. Interview angle #

    • "Calls arrive as a Poisson process with 10 per hour. What is the probability of no call in 15 minutes?" — The count in 15 minutes is Poisson(2.5)\text{Poisson}(2.5), so e−2.5≈0.082e^{-2.5} \approx 0.082.
    • "What is the distribution of the minimum of two independent exponentials?" — Exp(λ1+λ2)\text{Exp}(\lambda_1 + \lambda_2); X1X_1 is the minimum with probability λ1/(λ1+λ2)\lambda_1/(\lambda_1 + \lambda_2).
    • "Expected number of die rolls until the first 6?" — Geom(1/6)\text{Geom}(1/6) (trials): mean 6, variance (5/6)/(1/36)=30(5/6)/(1/36) = 30.
    • "Your count data have variance much larger than the mean. What do you do?" — The Poisson model is wrong (overdispersion). Use a negative binomial, or model the extra variation (covariates, random effects).
    • "Buses come as a Poisson process every 10 minutes on average. How long do you wait?" — 10 minutes on average, by memorylessness. The gap you land in has mean 20 minutes (inspection paradox).
    • "How do you sample a Beta or a Dirichlet if you only have a gamma sampler?" — Normalise independent gammas with the same rate.

    10. Practice #

    The notebook for this lesson runs in Colab or in your browser. It has five exercises, each with a check cell and a folded solution:

    1. sample_gamma_int(k, lam, n, rng) as a sum of exponentials, and sample_dirichlet(alpha, n, rng) by normalising gammas; check the means and variances.
    2. poisson_process(lam, T, rng): event times on [0,T][0, T] from running sums of exponential gaps; a chi-square test of the counts per window.
    3. tv_binom_poisson(n, lam): the total variation distance between Bin(n,λ/n)\text{Bin}(n, \lambda/n) and Poisson(λ)\text{Poisson}(\lambda), compared with Le Cam's bound.
    4. conditional_survival(samples, s, t): estimate P(X>s+t∣X>s)P(X > s + t \mid X > s) by simulation, for exponential and gamma lifetimes.
    5. mgf_moments(M, h): the mean and the variance from an MGF by finite differences, checked on the gamma and the Poisson.

    11. Watch and read #

    The Poisson distribution, its link to the binomial and the "Poisson paradigm" for many rare, weakly dependent events.
    Open on YouTube · the player loads from youtube-nocookie.com when you press play
    Memorylessness and why the exponential is the only continuous memoryless distribution (relation 2).
    Open on YouTube · the player loads from youtube-nocookie.com when you press play
    Merging and splitting Poisson processes (superposition and thinning) and the inspection paradox.
    Open on YouTube · the player loads from youtube-nocookie.com when you press play
    • Joseph Blitzstein and Jessica Hwang, Introduction to Probability, 2nd edition, free PDF: §3.3 (Bernoulli, binomial), §4.3 (geometric), §4.7–4.8 (Poisson and the binomial limit), §5.4–5.5 (normal, exponential), §6.4–6.6 (MGFs and sums), §8.3–8.5 (beta, gamma and their connections), ch. 13 (Poisson processes).
    • Kevin Murphy, Probabilistic Machine Learning: An Introduction, free PDF: §2.4–2.7 (common univariate distributions and their use in ML).
    • The Statistics 110 course page has all lecture videos, including lecture 17 (moment generating functions) and lecture 23 (beta distribution).
    • Art Owen, Monte Carlo theory, methods and examples, ch. 4: how gamma, beta and Dirichlet variables are sampled in practice.