ML Study Hub

Home / MLF / Week 11

Week 11 · The exponential family

Official syllabus line: Exponential Family of distributions
About 60 minEnd Term material (see exam radar)BSCS2004 · Harish Guruprasad Ramaswamy, Arun Rajkumar, Prashanth LA
Before you start: Week 8 (convex functions) and week 10 (distributions, expectation, variance). Logarithms and exponentials.
Watch first: the animated story of this weekAbout 1-2 minutes of real 3D animation with a friendly voice. Pause any time.
Read the words of the video
  1. Just like baking, many probability distributions share a secret "recipe card." You change the ingredients, but the basic layout stays the same. This means learning how to handle one distribution's recipe helps you understand many others, saving you lots of time and effort!
  2. This shared recipe card is called the 'exponential family'. It lets us write many distributions like coin flips or bell curves in one special form. The magic is, if you learn how to find the mean or fit one of these models using this recipe, you've learned it for all of them!
  3. Take the Poisson distribution, for counting things like buses. We can write its formula in our special recipe card form. Here, our natural parameter, 'eta', becomes 'log lambda', where 'lambda' is the average count. The 'T of x' part just becomes 'x', our actual count.
  4. While the name 'exponential family' might not appear on exams, its core ideas are super important for other topics like MLE and regression! Remember the recipe card, how 'A prime of eta' gives the mean, and how to find the best parameter by matching model mean to sample mean. Keep practicing!

The one-minute story

Think of it like this

Bake cakes, bread and biscuits and you will notice they all start from the same kind of recipe card: flour, a sweetener, something to make it rise, a little oven time. The card has a fixed layout and you only change the amounts.

Many of the probability distributions you already know (coin flips, waiting times, counts of buses, the bell curve) secretly share one recipe card too. It is called the exponential family. The beauty: if you learn how to do something once on the recipe card (find the mean, find the best parameter from data, fit a model), you have learned it for all of them at once.

That is the reason logistic regression, linear regression and many other models look so alike: they are all the same recipe with different ingredients.

Tip

How much to invest in this week. Looking at every MLF paper on the practice site, the exponential family is not asked by name in any of them, but the ideas here (natural parameter, log-partition function, "model mean = sample mean") are the foundation of the MLE questions that are asked, and of logistic regression in MLT and MLP. Learn the recipe, practise the Bernoulli and Poisson conversions, and move on.

By the end of this week you can:

  • write a distribution in the exponential-family form and name its parts;
  • show that Bernoulli, Poisson, exponential and Gaussian (known variance) belong to the family;
  • get the mean and variance from the log-partition function;
  • find the maximum-likelihood estimate by matching the model mean to the sample mean.

Words you need

Words you need
  • Exponential family - distributions that can be written as p(x∣η)=h(x)exp⁡(η T(x)−A(η))p(x\mid\eta)=h(x)\exp\big(\eta\,T(x)-A(\eta)\big).
  • Natural parameter η\eta - the "dial" of the family, in its most convenient form.
  • Sufficient statistic T(x)T(x) - the one summary of each data point that matters. For many data points you only need ∑T(xi)\sum T(x_i).
  • Log-partition function A(η)A(\eta) - the "normaliser" that makes the total probability equal 1.
  • Base measure h(x)h(x) - a background factor that does not depend on the parameter.

Idea 1: The recipe card

p(x∣η)=h(x) exp⁡ ⁣(η T(x)−A(η))\boxed{p(x\mid\eta)=h(x)\,\exp\!\big(\eta\,T(x)-A(\eta)\big)}

(One parameter for simplicity; with several, ηT(x)\eta T(x) becomes a dot product ηTT(x)\boldsymbol\eta^T\mathbf T(x).)

  • T(x)T(x): what you record from a data point.
  • η\eta: the parameter that multiplies it inside the exponent.
  • A(η)A(\eta): whatever you must subtract so the probabilities add up to 1: A(η)=ln⁡∑xh(x)eηT(x)A(\eta)=\ln\sum_xh(x)e^{\eta T(x)}.
  • h(x)h(x): leftover factor that does not involve η\eta.

To show a distribution is in the family: take its formula, write it as exp⁡(ln⁡…)\exp(\ln\ldots), and sort the terms into "involves both xx and the parameter" (ηT(x)\eta T(x)), "involves only the parameter" (−A-A), and "involves only xx" (hh).

Solved example: 1. Bernoulli (a coin with heads-probability pp)
p(x)=px(1−p)1−x=exp⁡ ⁣(xln⁡p1−p+ln⁡(1−p)),x∈{0,1}p(x)=p^x(1-p)^{1-x}=\exp\!\Big(x\ln\tfrac p{1-p}+\ln(1-p)\Big),\qquad x\in\{0,1\}

Sorting: T(x)=xT(x)=x, η=ln⁡p1−p\eta=\ln\dfrac p{1-p} (the log-odds, or logit), h(x)=1h(x)=1, and since p=eη1+eηp=\dfrac{e^\eta}{1+e^\eta} we get ln⁡(1−p)=−ln⁡(1+eη)\ln(1-p)=-\ln(1+e^\eta), so A(η)=ln⁡(1+eη)A(\eta)=\ln(1+e^\eta).

Now invert η=ln⁡p1−p\eta=\ln\frac p{1-p}: p=11+e−ηp=\dfrac1{1+e^{-\eta}}. That is the sigmoid from week 9! Logistic regression is just "set η=wTx\eta=\mathbf w^T\mathbf x for a Bernoulli".

Solved example: 2. Poisson (counts of events in a fixed time, mean λ\lambda)
p(x)=λxe−λx!=1x!exp⁡(xln⁡λ−λ),x=0,1,2,…p(x)=\frac{\lambda^xe^{-\lambda}}{x!}=\frac1{x!}\exp\big(x\ln\lambda-\lambda\big),\qquad x=0,1,2,\dots

T(x)=xT(x)=x, η=ln⁡λ\eta=\ln\lambda, h(x)=1x!h(x)=\frac1{x!}, A(η)=λ=eηA(\eta)=\lambda=e^\eta.

Solved example: 3. Exponential distribution and Gaussian with known variance

Exponential (λe−λx\lambda e^{-\lambda x} for x≥0x\ge0): write it as exp⁡(−λx+ln⁡λ)\exp(-\lambda x+\ln\lambda). So T(x)=xT(x)=x, η=−λ\eta=-\lambda (negative!), h=1h=1, A(η)=−ln⁡(−η)A(\eta)=-\ln(-\eta).

Gaussian with variance 1 (μ\mu unknown): 12πe−(x−μ)2/2=12πe−x2/2⏟h(x)exp⁡ ⁣(μx−μ22)\frac1{\sqrt{2\pi}}e^{-(x-\mu)^2/2}=\underbrace{\tfrac1{\sqrt{2\pi}}e^{-x^2/2}}_{h(x)}\exp\!\big(\mu x-\tfrac{\mu^2}2\big). So T(x)=xT(x)=x, η=μ\eta=\mu, A(η)=η22A(\eta)=\frac{\eta^2}2.

Distributions not in the family: the uniform on [0,θ][0,\theta] (its range depends on the parameter), the Cauchy, and the Student-tt.

Idea 2: The log-partition function knows the mean and variance

Differentiate AA:

A′(η)=E[T(X)],A′′(η)=Var⁡[T(X)]\boxed{A'(\eta)=E[T(X)],\qquad A''(\eta)=\operatorname{Var}[T(X)]}

One function holds the whole story. Check with what we found:

DistributionA(η)A(\eta)A′(η)=E[X]A'(\eta)=E[X]A′′(η)=Var⁡[X]A''(\eta)=\operatorname{Var}[X]
Bernoulliln⁡(1+eη)\ln(1+e^\eta)eη1+eη=p\frac{e^\eta}{1+e^\eta}=pp(1−p)p(1-p)
Poissoneηe^\etaeη=λe^\eta=\lambdaeη=λe^\eta=\lambda
Exponential−ln⁡(−η)-\ln(-\eta)−1η=1λ-\frac1\eta=\frac1\lambda1η2=1λ2\frac1{\eta^2}=\frac1{\lambda^2}
Gaussian (var 1)η2/2\eta^2/2η=μ\eta=\mu11

Every row reproduces a mean and variance you already knew from week 10. And because a variance is never negative, A′′≥0A''\ge0, which means AA is a convex function (week 8). That convexity is exactly what makes fitting these models a nice optimisation problem.

Idea 3: Fitting the family by maximum likelihood

Suppose you observe nn independent data points x1,…,xnx_1,\dots,x_n. The log-likelihood of η\eta is

ℓ(η)=η∑iT(xi)−nA(η)+(terms not involving η)\ell(\eta)=\eta\sum_iT(x_i)-nA(\eta)+\text{(terms not involving }\eta)

Differentiate and set to zero: ∑iT(xi)−nA′(η)=0\sum_iT(x_i)-nA'(\eta)=0, i.e.

A′(η^)=1n∑i=1nT(xi)"model mean = sample mean"\boxed{A'(\hat\eta)=\frac1n\sum_{i=1}^nT(x_i)}\qquad\text{"model mean = sample mean"}

Since A′′≥0A''\ge0, the log-likelihood is concave in η\eta, so this equation gives the global maximum. This is called moment matching.

Solved example: 4. MLE in one line each

Bernoulli. A′(η)=pA'(\eta)=p, so p^=1n∑xi=xˉ\hat p=\frac1n\sum x_i=\bar x (the fraction of heads).

Poisson. A′(η)=λA'(\eta)=\lambda, so λ^=xˉ\hat\lambda=\bar x. For the counts (2, 0, 3, 1, 4)(2,\,0,\,3,\,1,\,4): xˉ=105=2\bar x=\frac{10}5=\mathbf2.

Exponential. A′(η)=1λ=xˉA'(\eta)=\frac1\lambda=\bar x, so λ^=1xˉ\hat\lambda=\frac1{\bar x}. For waiting times (2,4,6)(2,4,6): xˉ=4\bar x=4, so λ^=0.25\hat\lambda=\mathbf{0.25}.

Gaussian, variance 1. μ^=xˉ\hat\mu=\bar x.

Notice the sufficient statistic at work: to estimate pp, λ\lambda or μ\mu you only needed the total ∑xi\sum x_i. The individual values were not needed.

Idea 4: Why this matters for the other courses

The idea

In a generalised linear model you choose a member of the family for the thing you are predicting, and set its natural parameter to a linear function of the inputs: η=wTx\eta=\mathbf w^T\mathbf x.

You predictFamilyModel
a real number with bell-shaped noiseGaussianlinear regression (MLT week 5)
yes / noBernoullilogistic regression (MLT week 9)
a count (0, 1, 2, ...)PoissonPoisson regression
one of KK categoriescategoricalsoftmax (neural nets, MLT week 12)

Your turn

Your turn: 1. Identify the parts

Write the Poisson(λ\lambda) distribution in exponential-family form and name TT, η\eta, hh and AA.

Need a hint?

Take exp⁡(ln⁡…)\exp(\ln\ldots) of the formula λxe−λx!\frac{\lambda^xe^{-\lambda}}{x!}.

Show the full solution

1x!exp⁡(xln⁡λ−λ)\frac1{x!}\exp(x\ln\lambda-\lambda). So T(x)=xT(x)=x, η=ln⁡λ\eta=\ln\lambda, h(x)=1x!h(x)=\frac1{x!}, A(η)=eηA(\eta)=e^\eta.

Your turn: 2. Mean from the log-partition

For the Bernoulli, A(η)=ln⁡(1+eη)A(\eta)=\ln(1+e^\eta). Compute A′(η)A'(\eta) and check it is the mean.

Need a hint?

Differentiate ln⁡(1+eη)\ln(1+e^\eta) with the chain rule.

Show the full solution

A′(η)=eη1+eηA'(\eta)=\frac{e^\eta}{1+e^\eta}. With η=ln⁡p1−p\eta=\ln\frac p{1-p}, eη=p1−pe^\eta=\frac p{1-p}, so A′=p/(1−p)1+p/(1−p)=pA'=\frac{p/(1-p)}{1+p/(1-p)}=p. ✓

Your turn: 3. Maximum likelihood by moment matching

Defects per batch of a product are modelled as Poisson. Five batches show 3, 5, 4, 6, 23,\,5,\,4,\,6,\,2 defects. What is the MLE of λ\lambda?

Need a hint?

Poisson: model mean =λ=\lambda.

Show the full solution

λ^=xˉ=205=4\hat\lambda=\bar x=\frac{20}5=\mathbf4.

Your turn: 4. Exponential MLE

Five service times (minutes) are 1, 2, 2, 3, 21,\,2,\,2,\,3,\,2. Estimate the rate λ\lambda of an exponential model, and the probability that a service takes over 3 minutes.

Need a hint?

λ^=1/xˉ\hat\lambda=1/\bar x and P(X>t)=e−λtP(X>t)=e^{-\lambda t}.

Show the full solution

xˉ=2\bar x=2, so λ^=0.5\hat\lambda=0.5. P(X>3)=e−1.5≈0.223P(X>3)=e^{-1.5}\approx0.223.

Your turn: 5. Is it in the family?

Is the uniform distribution on [0,θ][0,\theta] in the exponential family?

Need a hint?

Look at where θ\theta appears.

Show the full solution

No. Its density is 1θ\frac1\theta only on 0≤x≤θ0\le x\le\theta, so the support (where the density is non-zero) depends on θ\theta. In the family the support cannot depend on the parameter.

Exam radar

Exam radar

Be honest about priorities. Across all MLF papers on the practice site, none of the concept summaries mention the exponential family, natural parameter or sufficient statistic. What is examined near this week: MLE (in 16 of the 42 End Term summaries), Poisson and Bernoulli facts (16 and 11), and the exponential distribution story problems (waiting times). So treat this week as the foundation behind those, and for logistic regression in MLT and MLP.

If your term's paper does ask about it, the likely question is "write this distribution in exponential-family form" or "find A′(η)A'(\eta)" (Examples 1 to 3).

Watch out - real exam trap
  • For the exponential distribution, η=−λ\eta=-\lambda is negative, and A(η)=−ln⁡(−η)A(\eta)=-\ln(-\eta) needs η<0\eta<0.
  • T(x)T(x) is not always xx (for the Gaussian with unknown variance it is (x,x2)(x,x^2)).
  • "Moment matching" means model mean A′(η)A'(\eta) = sample mean of T(x)T(x), not of xx in general.
  • A distribution whose range depends on the parameter is not in the family.

Quick quiz

Quick quiz

For the Poisson distribution written in exponential-family form, the natural parameter eta is...

  • lambda
  • ln lambda
  • 1 / lambda
  • e to the lambda
Poisson(x) is (1/x!) exp(x ln(lambda) - lambda), so eta = ln(lambda) and A(eta) = e^eta.

For an exponential-family distribution, A prime of eta equals...

  • the variance
  • the expected value of T(X)
  • the likelihood
  • zero
The first derivative of the log-partition function is the mean of the sufficient statistic; the second derivative is its variance.

The MLE of the Poisson rate from counts 1, 3, 2 is...

  • 1
  • 2
  • 3
  • 6
The MLE is the sample mean: (1+3+2)/3 = 2.

Select all TRUE. (select all that apply)

  • The Bernoulli natural parameter is the log-odds.
  • The log-partition function A is convex.
  • The uniform distribution on [0, theta] is in the exponential family.
  • The sufficient statistic is always a constant.
The uniform's support depends on theta, so it is not in the family. A'' is a variance and hence non-negative, so A is convex.

Recap

Remember this
  • Recipe card: p(x∣η)=h(x)exp⁡(ηT(x)−A(η))p(x\mid\eta)=h(x)\exp(\eta T(x)-A(\eta)).
  • Bernoulli: η=ln⁡p1−p\eta=\ln\frac p{1-p} (logit; inverse is the sigmoid). Poisson: η=ln⁡λ\eta=\ln\lambda. Exponential: η=−λ\eta=-\lambda. Gaussian (var 1): η=μ\eta=\mu.
  • A′(η)=E[T]A'(\eta)=E[T], A′′(η)=Var⁡[T]≥0A''(\eta)=\operatorname{Var}[T]\ge0 so AA is convex.
  • MLE: A′(η^)=1n∑T(xi)A'(\hat\eta)=\frac1n\sum T(x_i), "model mean = sample mean". Log-likelihood is concave.
  • Setting η=wTx\eta=\mathbf w^T\mathbf x gives linear regression, logistic regression, Poisson regression, softmax.
Formulas to keep
  • p(x∣η)=h(x)exp⁡(ηT(x)−A(η))p(x\mid\eta)=h(x)\exp(\eta T(x)-A(\eta))
  • E[T]=A′(η)E[T]=A'(\eta), Var⁡[T]=A′′(η)\operatorname{Var}[T]=A''(\eta)
  • MLE: A′(η^)=1n∑iT(xi)A'(\hat\eta)=\frac1n\sum_iT(x_i)
  • Bernoulli p^=xˉ\hat p=\bar x; Poisson λ^=xˉ\hat\lambda=\bar x; Exponential λ^=1/xˉ\hat\lambda=1/\bar x
  • Logit: η=ln⁡p1−p\eta=\ln\frac p{1-p}; inverse: p=11+e−ηp=\frac1{1+e^{-\eta}}
Connected weeks (learn them together)

Practise with real exam questions

These come straight from past papers (with the real figures and the official answer key). Open 2 real questions on this week   All End Term papers