Conjugate priors and the exponential family
When the posterior has a closed form: the conjugate pairs Beta–Bernoulli, Gamma–Poisson, the Normal mean and precision, the Normal–Gamma; the exponential family, sufficient statistics and the general conjugate prior; the eight standard distributions and their moments.
When the integral takes care of itself
In the topic The Bayesian approach a coin with a uniform prior on came up heads three times, the posterior became , and the next flip was predicted to be heads with probability . Everything there had a closed form. That was luck, not the rule. Bayes' formula
has an integral in the denominator, and for most pairs of prior and likelihood nobody can take it by hand. A grid is no escape either: with points per axis and parameters it costs evaluations, and points for parameters is already .
This topic is about the pairs where the integral takes care of itself.
Definition. A family of priors with hyperparameters is conjugate to a likelihood if, for any admissible data , the posterior stays in the family:
where the new hyperparameters are computed from and .
Three remarks keep the definition honest.
- The family is shared by the prior and the posterior only. The likelihood is a distribution over the data, often on a different space. As a function of it just has to look like the prior, so that the product keeps the form.
- Bayesian updating turns into arithmetic on a few numbers. The normalizer of the family is known, so the evidence and the predictive often come out in closed form too.
- If the observations are independent given , then . Yesterday's posterior is today's prior, , and neither the order nor the batching of the data changes the result.
How do you find a conjugate prior? Write the likelihood as a function of , drop the factors that do not depend on , and take a prior of the same shape. The next blocks do exactly this four times.
Beta–Bernoulli: the coin continues
A coin with flips and heads has the likelihood
The binomial model, which records only the number of heads, adds the factor ; it does not depend on and cancels in the posterior. As a function of the likelihood is a power of times a power of . The Beta density has the same shape:
Multiplying, the exponents add up to , so
Heads go to , tails go to . That is why and are read as pseudo-counts: the prior behaves as if we had already seen about heads and tails. The data enter only through and .
The moments of the Beta, needed all the time:
Back to our coin at . Six more flips give heads and tails, and the coin moves to . Over all nine flips there were heads, so:
- the MAP estimate is the mode, ; with a uniform prior it coincides with the MLE ;
- the posterior mean is , slightly pulled towards the prior mean ;
- the probability that the next flip is heads is .
The posterior mean always lies between the prior mean and the observed frequency , and the more flips there are, the closer it gets to the frequency.
Gamma–Poisson: counting events
Now counts: the number of bug reports per day, of calls per hour. A count is modelled as with . For intervals with total count the likelihood as a function of is
A power of times an exponential of : this is the shape of the Gamma distribution. Throughout the course it is written in shape–rate form,
with shape and rate . Multiplying adds the powers and the coefficients in the exponent:
The pseudo-count reading carries over: the prior is worth about events seen over intervals.
Example. A team logs bug reports per day. The prior says "about bugs over days", mean . The next five days bring reports, so and . The posterior is with mean , between the prior mean and the sample mean .
The predictive for tomorrow's count is no longer Poisson but negative binomial: it is wider, because itself is uncertain. The Gamma is a natural candidate wherever the likelihood in a positive parameter is a power times an exponential, and the Poisson is not the only such case.
The Normal mean: precisions add
Measurements with a known noise variance and an unknown mean . The prior is . The log of the posterior, up to a constant, is
It is a quadratic in , so the posterior is Gaussian, . Collect the coefficient of and of and complete the square:
Read it in terms of precision, the inverse variance. The precisions of the prior and of the data add up. The posterior mean is an average of the prior mean and the data, weighted by their precisions.
Example. Prior , noise , four measurements with . The precision is , so , and .
What about the next measurement? Write it as , where follows the posterior and is fresh noise, independent of . A sum of independent Gaussians is Gaussian, with means and variances adding:
The first term is uncertainty about the parameter, the second is noise. The topic Bayesian linear regression repeats this whole block with a weight vector instead of a single .
Unknown precision and the Normal–Gamma
Now the opposite case: the mean is known and the spread is not. Work with the precision , so . Each density carries in front, so the likelihood as a function of is
Again a power times an exponential, so the prior is and
Example. , prior , data . The squared deviations sum to , the posterior is , and . The MLE is ; the prior with mean pulls the estimate down. Larger deviations mean a larger rate and a smaller precision.
Both unknown. The likelihood contains : a cross term between and . It does not split into a factor for and a factor for , so a product of independent Normal and Gamma priors is not conjugate. The conjugate prior is joint, the Normal–Gamma:
The variance of depends on , and says how many observations the prior guess is worth. With the updates are
The rate collects the scatter of the data around their own mean plus the disagreement between that mean and the prior guess. On the same five points with and : , , , , . Integrating out , the marginal posterior of is a Student t-distribution with degrees of freedom: heavier tails than a Gaussian, because the noise level itself is uncertain.
The exponential family
Four conjugate pairs, four lucky coincidences? No. All four likelihoods belong to one family. A distribution is in the exponential family if its density can be written as
Here is the natural parameter, the sufficient statistics, the base measure, and the log-partition function, the log of the normalizing constant. The natural parameter is often not the usual one:
| Distribution | ||||
|---|---|---|---|---|
Two things are required: the support of must not depend on the parameter, and must be linear in the statistics, with all the dependence on the parameter collected in and .
Sufficient statistics of fixed size. For an independent sample
The data reach the parameter only through and : the number of heads for the coin, and for the Gaussian. By the Fisher–Neyman factorization criterion, is sufficient, and its size does not grow with .
Derivatives of give moments. Differentiate under the integral:
For the Poisson, , and both derivatives equal : the mean and the variance of a Poisson are both .
Concavity. The log-likelihood has Hessian , so it is concave in . At a maximum : the model's expected statistics match the sample ones (moment matching). Three caveats. Concavity holds in the natural parameter, not in an arbitrary one such as . Strict concavity needs statistics without affine dependence. And concavity does not promise a finite maximum: after heads in flips, .
The general conjugate prior
As a function of , the likelihood of a sample is . Take a prior of the same form, with hyperparameters and :
Multiplying adds the exponents:
This is the general conjugate prior of the exponential family. The reading is the same as before: the prior acts like imaginary observations whose statistics add up to , and every update simply adds the real statistics to the imaginary ones. The hyperparameters must keep the prior normalizable; that is the only constraint.
The Beta as an instance. For the Bernoulli and , so
This is a density over . To get a density over , multiply by the Jacobian :
So is the number of prior heads and the number of prior tails, and the update , is exactly . The "" in the Beta exponents is the Jacobian. Our coin has walked .
A side note. Conjugate priors exist outside the family too: the uniform on has the Pareto as a conjugate prior. But among models with a fixed support, only the exponential family has sufficient statistics of fixed size, under mild regularity conditions (the Pitman–Koopman–Darmois theorem), so this is where conjugacy lives systematically.
Eight standard distributions, and what comes next
The eight distributions that every topic of the course takes for granted. Outside the listed support the density or probability is zero; for continuous ones is a density, not the probability of a point.
| Distribution | Support | |||
|---|---|---|---|---|
They are linked: , , . In the Gamma, is a rate, not a scale; libraries such as numpy and scipy take the scale .
And the map of conjugate pairs from this topic:
| Likelihood | Prior | Posterior |
|---|---|---|
| Bernoulli / binomial, successes in | ||
| Poisson, total count over intervals | ||
| Exponential, total time of waits | ||
| Normal, known | , precisions add | |
| Normal, known mean | on | |
| Normal, both unknown | Normal–Gamma | above |
One more gift of conjugacy. The evidence is a ratio of normalizers: for a sequence of flips . Our nine flips under the uniform prior give . A rival model, "the coin is exactly fair", has no free parameter and gives , two and a half times more. Both models fit five heads in nine flips; the simpler one predicted them better. Which one should we believe, and why does simplicity win here? That is the topic Bayesian model selection.
Check your understanding
The same questions as in Pulse. Answers are shared between modes.
Answers are saved on the server and tied to this browser until you sign in.