Simple Algorithm
Machine Learning · Convergence · 28 min

Exponential Families

Sufficient statistics, conjugacy and moment matching.

The Bernoulli, Poisson, Gaussian, Gamma, Beta, Dirichlet and categorical distributions look unrelated, yet they are one formula with different ingredients. That formula explains why their maximum likelihood estimates match averages, why a few summary numbers capture a dataset of any size, why they have conjugate priors, and why they appear whenever you maximize entropy.

What you’ll learn

  • Write common distributions in the canonical form h(x)exp⁡(η⊤T(x)−A(η))h(x)\exp(\boldsymbol\eta^\top T(x) - A(\boldsymbol\eta)), and identify natural parameters, sufficient statistics and the log-partition function.
  • Prove that ∇A=E[T]\nabla A = \E[T] and ∇2A=Cov⁡[T]\nabla^2 A = \Cov[T], and deduce that the log-likelihood is concave and the MLE matches moments.
  • State and prove the factorization theorem, and state the Pitman–Koopman–Darmois theorem with its conditions.
  • Derive the conjugate prior of an exponential family, and prove that exponential families maximize entropy under moment constraints.

One form, many distributions

DistributionT(x)T(x)η\boldsymbol\etaA(η)A(\boldsymbol\eta)
Bernoulli(p)(p)xxlog⁡p1−p\log\frac{p}{1-p}log⁡(1+eη)\log(1 + e^{\eta})
Poisson(λ)(\lambda), h=1/x!h = 1/x!xxlog⁡λ\log\lambdaeηe^{\eta}
Exponential (rate λ\lambda)xx−λ-\lambda−log⁡(−η)-\log(-\eta)
N(μ,σ2)\mathcal N(\mu, \sigma^2), h=1/2πh = 1/\sqrt{2\pi}(x, x2)(x,\ x^2)(μσ2, −12σ2)\big(\frac{\mu}{\sigma^2},\ -\frac{1}{2\sigma^2}\big)−η124η2−12log⁡(−2η2)-\frac{\eta_1^2}{4\eta_2} - \frac12\log(-2\eta_2)
Gamma (shape α\alpha, rate β\beta)(log⁡x, x)(\log x,\ x)(α−1, −β)(\alpha - 1,\ -\beta)log⁡Γ(η1+1)−(η1+1)log⁡(−η2)\log\Gamma(\eta_1 + 1) - (\eta_1 + 1)\log(-\eta_2)
Beta(α,β)(\alpha, \beta)(log⁡x, log⁡(1−x))(\log x,\ \log(1-x))(α−1, β−1)(\alpha - 1,\ \beta - 1)log⁡B(η1+1, η2+1)\log B(\eta_1 + 1,\ \eta_2 + 1)
Categorical over KK classesone-hot ey\mathbf e_y (first K−1K-1 entries)ηk=log⁡πkπK\eta_k = \log\frac{\pi_k}{\pi_K}log⁡(1+∑k<Keηk)\log\big(1 + \sum_{k<K} e^{\eta_k}\big)
Writing the categorical with all KK entries of the one-hot vector gives the softmax, but that representation is not minimal: adding a constant to every ηk\eta_k changes nothing. Not exponential families: Uniform(0,θ)\mathrm{Uniform}(0, \theta) (its support moves with θ\theta), the Cauchy and Student-tt location families, the Laplace with unknown location, and mixtures such as Gaussian mixtures.
Check your understanding

Which of these families, with all the listed parameters unknown, is not an exponential family?

  1. Gamma with unknown shape and rate
  2. Uniform(0,θ)\mathrm{Uniform}(0, \theta) with unknown θ>0\theta > 0
  3. Beta with unknown α\alpha and β\beta
  4. Multivariate Gaussian with unknown mean and covariance
Show the answer

B. Uniform(0,θ)\mathrm{Uniform}(0, \theta) with unknown θ>0\theta > 0

The density θ−11{0≤x≤θ}\theta^{-1}\mathbf 1\{0 \le x \le \theta\} has a support that depends on θ\theta. In an exponential family p(x∣η)>0p(x \mid \boldsymbol\eta) > 0 exactly where h(x)>0h(x) > 0, for every η\boldsymbol\eta, so the support cannot move.

The log-partition function generates moments

DerivationGradient and Hessian of A
  1. ∇A(η)=∫T(x) h(x) eη⊤T(x) dx∫h(x) eη⊤T(x) dx=Eη[T(x)]\nabla A(\boldsymbol\eta) = \frac{\int T(x)\,h(x)\,e^{\boldsymbol\eta^\top T(x)}\,dx}{\int h(x)\,e^{\boldsymbol\eta^\top T(x)}\,dx} = \E_{\boldsymbol\eta}\big[T(x)\big]

    Differentiate A(η)=log⁡∫h eη⊤TA(\boldsymbol\eta) = \log\int h\,e^{\boldsymbol\eta^\top T} under the integral sign (allowed on the interior of N\mathcal N). The ratio is exactly an expectation under p(⋅∣η)p(\cdot \mid \boldsymbol\eta):

  2. ∇2A(η)=Eη[TT⊤]−Eη[T] Eη[T]⊤=Cov⁡η[T(x)]⪰0\nabla^2 A(\boldsymbol\eta) = \E_{\boldsymbol\eta}\big[T T^\top\big] - \E_{\boldsymbol\eta}[T]\,\E_{\boldsymbol\eta}[T]^\top = \Cov_{\boldsymbol\eta}\big[T(x)\big] \succeq 0

    Differentiate again: the quotient rule produces the second moment minus the outer product of the first:

  3. I(η)=Cov⁡η[T(x)−∇A(η)]=∇2A(η)I(\boldsymbol\eta) = \Cov_{\boldsymbol\eta}\big[T(x) - \nabla A(\boldsymbol\eta)\big] = \nabla^2 A(\boldsymbol\eta)

    So AA is convex, and strictly convex in a minimal family, where a⊤Cov⁡[T] a=Var⁡[a⊤T]>0\mathbf a^\top\Cov[T]\,\mathbf a = \Var[\mathbf a^\top T] > 0 for every a≠0\mathbf a \ne \mathbf 0. The score of one observation is T(x)−∇A(η)T(x) - \nabla A(\boldsymbol\eta), so the Fisher information in natural parameters is simply the Hessian of AA:

Check it on the Gaussian. With A=−η12/(4η2)−12log⁡(−2η2)A = -\eta_1^2/(4\eta_2) - \frac12\log(-2\eta_2), the derivative with respect to η1\eta_1 is −η1/(2η2)=μ-\eta_1/(2\eta_2) = \mu, and with respect to η2\eta_2 it is η12/(4η22)−1/(2η2)=μ2+σ2=E[x2]\eta_1^2/(4\eta_2^2) - 1/(2\eta_2) = \mu^2 + \sigma^2 = \E[x^2]. For the Bernoulli, A′=eη/(1+eη)A' = e^\eta/(1 + e^\eta) is the sigmoid and A′′=p(1−p)A'' = p(1-p) the variance.

The mean parameters μ=∇A(η)=Eη[T]\boldsymbol\mu = \nabla A(\boldsymbol\eta) = \E_{\boldsymbol\eta}[T] give a second coordinate system. In a regular minimal family the map η↦μ\boldsymbol\eta \mapsto \boldsymbol\mu is one-to-one, since the gradient of a strictly convex function is, and it maps N\mathcal N onto the interior of the convex hull of the possible values of TT (Wainwright & Jordan, 2008, chapter 3). Every expected value strictly inside that hull is achieved by exactly one member of the family.

Maximum likelihood is moment matching

DerivationThe likelihood equations
  1. ℓ(η)=∑i=1nlog⁡h(xi)+η⊤∑i=1nT(xi)−n A(η)\ell(\boldsymbol\eta) = \sum_{i=1}^n \log h(x_i) + \boldsymbol\eta^\top\sum_{i=1}^n T(x_i) - n\,A(\boldsymbol\eta)

    For i.i.d. data the log-likelihood depends on the sample only through ∑iT(xi)\sum_i T(x_i):

  2. ∇ℓ(η)=∑i=1nT(xi)−n ∇A(η)=0⟺Eη^[T(x)]=Tˉ=1n∑i=1nT(xi)\nabla\ell(\boldsymbol\eta) = \sum_{i=1}^n T(x_i) - n\,\nabla A(\boldsymbol\eta) = \mathbf 0 \quad\Longleftrightarrow\quad \E_{\hat{\boldsymbol\eta}}\big[T(x)\big] = \bar T = \frac1n\sum_{i=1}^n T(x_i)

    It is concave, because AA is convex. Setting the gradient to zero gives the likelihood equations: the model's expected sufficient statistics must equal their sample averages.

  3. η^=(∇A)−1(Tˉ)exists  ⟺  Tˉ∈int⁡ conv⁡ T(X)\hat{\boldsymbol\eta} = (\nabla A)^{-1}(\bar T)\quad\text{exists}\iff \bar T \in \operatorname{int}\,\operatorname{conv}\,T(\mathcal X)

    In a regular minimal family a solution is unique, and it exists exactly when Tˉ\bar T lies in the interior of the convex hull of the possible values of TT (Brown, 1986). On the boundary the supremum is approached only as ∥η∥→∞\norm{\boldsymbol\eta} \to \infty: after 20 heads in 20 flips, Tˉ=1\bar T = 1 and the log-odds MLE is +∞+\infty.

Every closed form you know is an instance: the Gaussian MLE matches xˉ\bar x and x2‾\overline{x^2}; the Poisson matches xˉ\bar x; the Gamma matches log⁡x‾\overline{\log x} and xˉ\bar x, which is why the scale equation of the numerical fit in Maximum Likelihood & MAP reduced to αθ=xˉ\alpha\theta = \bar x. Conditional models inherit the property. A generalized linear model with canonical link has natural parameter ηi=w⊤xi\eta_i = \mathbf w^\top\mathbf x_i, so its likelihood equations read X⊤(y−μ(w))=0X^\top(\mathbf y - \boldsymbol\mu(\mathbf w)) = \mathbf 0: for logistic regression the fitted probabilities must reproduce the observed sums ∑ixijyi\sum_i x_{ij}y_i for every feature jj, and with an intercept the average fitted probability equals the observed fraction of ones. And when the data are linearly separable, Tˉ\bar T sits on the boundary and the weights diverge, the same failure as the 20 heads (Generalized Linear Models).

Predict before you look

You observe 1,000 waiting times and model them as Gamma with unknown shape and rate. To compute the MLE, how many numbers do you need to keep from the data?

Show the answer

2 numbers

The likelihood depends on the data only through ∑ilog⁡xi\sum_i \log x_i and ∑ixi\sum_i x_i (and nn, which you know). The other 998 degrees of freedom of the sample are irrelevant to the parameters: two numbers are sufficient, whatever the sample size. That fixed dimension is what characterizes exponential families, as the next step shows.

Sufficiency and the Pitman–Koopman–Darmois theorem

DerivationProof for discrete data
  1. Pr⁡θ(x∣S=s)=gθ(s) k(x)∑x′:S(x′)=sgθ(s) k(x′)=k(x)∑x′:S(x′)=sk(x′)\Pr_{\boldsymbol\theta}\big(\mathbf x \mid S = s\big) = \frac{g_{\boldsymbol\theta}(s)\,k(\mathbf x)}{\sum_{\mathbf x' : S(\mathbf x') = s} g_{\boldsymbol\theta}(s)\,k(\mathbf x')} = \frac{k(\mathbf x)}{\sum_{\mathbf x' : S(\mathbf x') = s} k(\mathbf x')}

    If the density factors, then for any x\mathbf x with S(x)=sS(\mathbf x) = s the factor gθ(s)g_{\boldsymbol\theta}(s) cancels from the conditional probability:

  2. p(x∣θ)=Pr⁡θ(S=S(x))⏟gθ(S(x)) Pr⁡(x∣S=S(x))⏟k(x)p(\mathbf x \mid \boldsymbol\theta) = \underbrace{\Pr_{\boldsymbol\theta}\big(S = S(\mathbf x)\big)}_{g_{\boldsymbol\theta}(S(\mathbf x))}\ \underbrace{\Pr\big(\mathbf x \mid S = S(\mathbf x)\big)}_{k(\mathbf x)}

    Conversely, if SS is sufficient, write the probability of x\mathbf x as that of its statistic times the parameter-free conditional, and read off the factors:

  3. ∏i=1np(xi∣η)=exp⁡(η⊤∑i=1nT(xi)−n A(η))⏟gη ∏i=1nh(xi)⏟k\prod_{i=1}^n p(x_i \mid \boldsymbol\eta) = \underbrace{\exp\Big(\boldsymbol\eta^\top\sum_{i=1}^n T(x_i) - n\,A(\boldsymbol\eta)\Big)}_{g_{\boldsymbol\eta}}\ \underbrace{\prod_{i=1}^n h(x_i)}_{k}

    For an exponential family the factorization is visible at a glance: ∑iT(xi)\sum_i T(x_i) is sufficient for every nn, and its dimension kk never grows. By the Rao–Blackwell theorem, conditioning any estimator on a sufficient statistic never increases its mean squared error, so good estimators can always be taken to be functions of ∑iT(xi)\sum_i T(x_i).

Each condition is needed. Fixed support: Uniform(0,θ)\mathrm{Uniform}(0, \theta) has the one-dimensional sufficient statistic max⁡ixi\max_i x_i for every nn, yet it is not an exponential family. Continuity: there are one-to-one maps from Rn\R^n into R\R (interleave the decimal digits of the coordinates), so without a regularity requirement the whole sample is trivially a "one-dimensional" sufficient statistic.

For machine learning the message is practical. Fixed-size summaries are what make streaming updates, distributed fitting and conjugate Bayesian updating cheap, and outside exponential families they are not available: a Gaussian mixture needs the whole sample, which is one reason it is fitted iteratively by EM (Latent Variables & EM).

Conjugacy, maximum entropy and duality

DerivationThe conjugate prior
  1. π(η∣χ,ν)∝exp⁡(η⊤χ−ν A(η))\pi(\boldsymbol\eta \mid \boldsymbol\chi, \nu) \propto \exp\big(\boldsymbol\eta^\top\boldsymbol\chi - \nu\,A(\boldsymbol\eta)\big)

    Choose a prior with the same functional form in η\boldsymbol\eta as the likelihood, with hyperparameters χ∈Rk\boldsymbol\chi \in \R^k (prior "sum of statistics") and ν>0\nu > 0 (prior "sample size"):

  2. π(η∣D)∝exp⁡(η⊤(χ+∑iT(xi))−(ν+n) A(η))\pi(\boldsymbol\eta \mid \data) \propto \exp\Big(\boldsymbol\eta^\top\big(\boldsymbol\chi + \textstyle\sum_i T(x_i)\big) - (\nu + n)\,A(\boldsymbol\eta)\Big)

    Multiplying by the likelihood just adds the data's statistics and count, so the posterior stays in the family:

  3. E[∇A(η)∣D]=χ+∑iT(xi)ν+n=νν+n χν+nν+n Tˉ\E\big[\nabla A(\boldsymbol\eta) \mid \data\big] = \frac{\boldsymbol\chi + \sum_i T(x_i)}{\nu + n} = \frac{\nu}{\nu + n}\,\frac{\boldsymbol\chi}{\nu} + \frac{n}{\nu + n}\,\bar T

    Under mild conditions the prior mean of the mean parameter is E[∇A(η)]=χ/ν\E[\nabla A(\boldsymbol\eta)] = \boldsymbol\chi/\nu (Diaconis & Ylvisaker, 1979). The posterior mean is therefore a weighted average of the prior guess and the data, with weight n/(ν+n)n/(\nu + n) on the data, and those authors also showed that, under conditions on the family, this linearity holds only for conjugate priors. The Beta–Bernoulli rule (a+h)/(a+b+n)(a + h)/(a + b + n) is the simplest case (Conjugate Priors & Exact Posteriors).

DerivationProof in one line of KL
  1. 0≤DKL(q ∥ pη)=Eq[log⁡qh]−η⊤μ+A(η)=−Hh(q)−η⊤μ+A(η)0 \le \KL(q \,\|\, p_{\boldsymbol\eta}) = \E_q\Big[\log\frac{q}{h}\Big] - \boldsymbol\eta^\top\boldsymbol\mu + A(\boldsymbol\eta) = -H_h(q) - \boldsymbol\eta^\top\boldsymbol\mu + A(\boldsymbol\eta)

    Expand the KL divergence from any feasible qq to pηp_{\boldsymbol\eta}, using Eq[T]=μ\E_q[T] = \boldsymbol\mu:

  2. Hh(q)≤A(η)−η⊤μ=Hh(pη)H_h(q) \le A(\boldsymbol\eta) - \boldsymbol\eta^\top\boldsymbol\mu = H_h(p_{\boldsymbol\eta})

    The same computation with q=pηq = p_{\boldsymbol\eta} gives zero. So every feasible qq has entropy at most that of pηp_{\boldsymbol\eta}, with equality only when DKL(q ∥ pη)=0\KL(q \,\|\, p_{\boldsymbol\eta}) = 0, that is, q=pηq = p_{\boldsymbol\eta}:

  3. A(η)=sup⁡μ {η⊤μ−A∗(μ)}A(\boldsymbol\eta) = \sup_{\boldsymbol\mu}\ \big\{\boldsymbol\eta^\top\boldsymbol\mu - A^*(\boldsymbol\mu)\big\}

    The right side, as a function of μ\boldsymbol\mu, is minus the convex conjugate of AA: A∗(μ)=sup⁡η{η⊤μ−A(η)}=−Hh(pη(μ))A^*(\boldsymbol\mu) = \sup_{\boldsymbol\eta}\{\boldsymbol\eta^\top\boldsymbol\mu - A(\boldsymbol\eta)\} = -H_h(p_{\boldsymbol\eta(\boldsymbol\mu)}). Conjugate duality then writes the log-partition function as an optimization over mean parameters, the starting point of variational inference (Wainwright & Jordan, 2008; Variational Inference).

Key takeaways

  • An exponential family has densities h(x)exp⁡(η⊤T(x)−A(η))h(x)\exp(\boldsymbol\eta^\top T(x) - A(\boldsymbol\eta)). Bernoulli, categorical, Poisson, Gaussian, Gamma, Beta and Dirichlet all fit; families whose support depends on the parameter, and mixtures, do not.
  • The log-partition function generates moments: ∇A=E[T]\nabla A = \E[T], ∇2A=Cov⁡[T]=I(η)\nabla^2 A = \Cov[T] = I(\boldsymbol\eta). So AA is convex, the log-likelihood concave, and mean and natural parameters are in one-to-one correspondence in a minimal family.
  • The MLE matches moments, Eη^[T]=Tˉ\E_{\hat{\boldsymbol\eta}}[T] = \bar T, and exists exactly when Tˉ\bar T lies inside the convex hull of the possible values of TT. GLMs with canonical links inherit both facts.
  • ∑iT(xi)\sum_i T(x_i) is sufficient by the factorization theorem, with a dimension that never grows; by Pitman–Koopman–Darmois, smooth families with fixed support have such summaries only if they are exponential families.
  • The conjugate prior ∝exp⁡(η⊤χ−νA(η))\propto \exp(\boldsymbol\eta^\top\boldsymbol\chi - \nu A(\boldsymbol\eta)) updates by adding statistics and counts, and its posterior mean of ∇A\nabla A is linear in Tˉ\bar T. Exponential families maximize entropy under moment constraints, and A∗A^* is the negative entropy.

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

For the Poisson family, A(η)=eηA(\eta) = e^{\eta} with η=log⁡λ\eta = \log\lambda. What do A′(η)A'(\eta) and A′′(η)A''(\eta) tell you?

  1. A′=λA' = \lambda is the mean and A′′=λA'' = \lambda is the variance: they are equal
  2. A′A' is the variance and A′′A'' the skewness
  3. A′=λA' = \lambda is the mean, and A′′A'' has no probabilistic meaning
  4. A′=log⁡λA' = \log\lambda is the natural parameter itself
Show the answer

A. A′=λA' = \lambda is the mean and A′′=λA'' = \lambda is the variance: they are equal

∇A=E[T]\nabla A = \E[T] and ∇2A=Var⁡[T]\nabla^2 A = \Var[T] with T(x)=xT(x) = x. Both equal eη=λe^{\eta} = \lambda: the Poisson's mean equals its variance, which is why overdispersed counts break it (When the Model Is Wrong).

Question 2

You fit a Bernoulli model in its natural parameter (the log-odds) to 15 flips that all came up heads. What happens?

  1. The MLE is η^=log⁡15\hat\eta = \log 15
  2. The log-likelihood is not concave, so there are several maxima
  3. No finite MLE exists: Tˉ=1\bar T = 1 is on the boundary, and the log-likelihood keeps increasing as η→∞\eta \to \infty
  4. The MLE is η^=0\hat\eta = 0, the fair coin
Show the answer

C. No finite MLE exists: Tˉ=1\bar T = 1 is on the boundary, and the log-likelihood keeps increasing as η→∞\eta \to \infty

The likelihood equation σ(η^)=Tˉ=1\sigma(\hat\eta) = \bar T = 1 has no solution, since the sigmoid never reaches 1. The likelihood is maximized only in the limit. In probability coordinates p^=1\hat p = 1 exists on the closed interval, but the natural parameter diverges, as do logistic-regression weights on separable data.

Question 3

Uniform(0,θ)\mathrm{Uniform}(0, \theta) has the one-dimensional sufficient statistic max⁡ixi\max_i x_i for every sample size, yet it is not an exponential family. Why doesn't this contradict the Pitman–Koopman–Darmois theorem?

  1. Because max⁡ixi\max_i x_i is not really sufficient
  2. Because the theorem assumes the support does not depend on the parameter, and here it does
  3. Because the theorem only applies to discrete distributions
  4. Because max⁡ixi\max_i x_i is not a continuous function of the sample
Show the answer

B. Because the theorem assumes the support does not depend on the parameter, and here it does

The density θ−n1{max⁡ixi≤θ}\theta^{-n}\mathbf 1\{\max_i x_i \le \theta\} factors through max⁡ixi\max_i x_i, so it is sufficient. The theorem's hypothesis of a parameter-free support fails, and parameter-dependent supports are exactly where non-exponential families with small sufficient statistics live.

Question 4

Among all densities on [0,∞)[0, \infty) with mean 2, which has the largest entropy?

  1. The uniform density on [0,4][0, 4]
  2. The half-normal density with mean 2
  3. The exponential density with mean 2
  4. A point mass at 2
Show the answer

C. The exponential density with mean 2

The constraint is on T(x)=xT(x) = x, so the maximizer has the form eηx−A(η)e^{\eta x - A(\eta)} on [0,∞)[0, \infty): an exponential distribution, here with rate 12\tfrac12 and entropy 1+log⁡2≈1.691 + \log 2 \approx 1.69 nats. The half-normal with the same mean has entropy about 1.641.64, and the uniform on [0,4][0, 4] has log⁡4≈1.39\log 4 \approx 1.39.

Further reading

  • M. J. Wainwright & M. I. Jordan, "Graphical models, exponential families, and variational inference," Foundations and Trends in Machine Learning 1(1–2), 1–305 (2008), chapter 3.
  • L. D. Brown, Fundamentals of Statistical Exponential Families (Institute of Mathematical Statistics, Lecture Notes–Monograph Series 9, 1986).
  • B. O. Koopman, "On distributions admitting a sufficient statistic," Transactions of the American Mathematical Society 39(3), 399–409 (1936).
  • E. T. Jaynes, "Information theory and statistical mechanics," Physical Review 106(4), 620–630 (1957).
  • P. Diaconis & D. Ylvisaker, "Conjugate priors for exponential families," Annals of Statistics 7(2), 269–281 (1979).