02 / 15 · Bayesian Modelling
Conjugate priors and the exponential family
Priors that keep the posterior in their own family, so that learning adds counts: the standard pairs, the exponential family that explains them, closed-form evidence and predictives, and what a light-tailed prior gets wrong.
The Bayesian approach · Bayesian inference · The multivariate Gaussian
On this page 12
A coin is flipped seven times: . Before the flips you believed it was probably close to fair, a prior on its probability of heads . After them, your belief is : two pseudo-counts went up by the five heads and the two tails. Two numbers carry the whole posterior, and the next flip is heads with probability , the posterior mean.
Most posteriors are not like that. The previous note answered every question by a sum over eleven urns. With a continuous parameter the sum becomes an integral, and the normalizing integral of Bayes’ formula, the evidence, usually has no closed form.
Without a formula, the posterior can still be computed on a grid: evaluate likelihood × prior at points per parameter and normalize. The cost is evaluations for parameters. The Code section computes the posterior of a normal mean and precision on a grid, about two million evaluations for two parameters. Ten parameters with a coarse 100 points each would need . Exact Bayesian inference in higher dimensions needs integrals done on paper, and the coin is the simplest case in which paper suffices.
Conjugacy: the posterior stays in the family#
A family of priors , indexed by hyperparameters , is conjugate to a likelihood if for every prior in the family and every dataset the posterior is again in the family:
A primed hyperparameter, , is the value after the update. Learning is the map on a few numbers. Because the posterior is again a prior of the family, the map can be applied one observation at a time, and by the sequential updating argument the result does not depend on the order or the batching of the data.
How do we find a conjugate prior before any theory? We read the likelihood of one observation as a function of the parameter and look for densities of the same functional form, since multiplying two such functions keeps the form. Take a normal with mean zero and an unknown precision :
As a function of it is a power of times the exponential of a linear function of . The gamma density , up to its constant, has the same form. Their product adds to and to , so the gamma prior is conjugate. The exponential family turns this reading into a rule.
Two more quantities come free. Write the prior as , with unnormalized and its normalizing constant. Conjugacy means that the likelihood times equals for a factor that does not depend on . The evidence is the sum rule over followed by the product rule; substituting this identity and integrating,
The evidence is a ratio of normalizing constants. The predictive of a new point is the evidence of one more observation divided by the evidence of the data, by the definition of a conditional distribution, and so again a ratio of normalizing constants.
Beta–Bernoulli and the evidence#
The density on is , with the normalizing constant , where and for integers. The beta section derives this constant by a change of variables in ; the same substitution with variables gives the Dirichlet constant below.
For flips with probability of heads , the posterior after heads in flips is . The Bayesian inference note derived this update and read and as pseudo-counts.
The new ingredient is the evidence. The likelihood of the sequence is , so and
For the seven flips of the opening, and the prior is ; with ,
The same number is the product of the seven one-step predictives, each the current posterior mean or its complement, with or raised by one after each flip:
By the product rule, : the evidence is the probability with which the model predicted each observation from the ones before it. The next note builds model comparison on this reading.
Dirichlet–categorical#
A categorical variable takes one of values with probabilities . The Dirichlet distribution on such probability vectors has density proportional to ; write . With counts in observations, the likelihood is , and
so . The Dirichlet is the beta distribution for categories. Its normalizing constant is . Both quantities below are ratios of such constants. The mean of multiplies the density by one more , so it is by , with the -th unit vector. The posterior mean is the predictive probability of category , as for the coin, and the evidence is with :
Take four categories, a uniform prior and counts . The posterior is , and the predictive probabilities are . The category never seen keeps probability instead of the maximum likelihood value 0. The evidence, with , and , is
Adding to every count is the add- smoothing of n-gram language models, seen as a posterior mean. The total is the strength of the prior in pseudo-counts. Values make the exponents negative, so the density grows without bound as any : the prior mass sits near the edges and corners of the simplex and favours sparse probability vectors, which is how latent Dirichlet allocation makes each document use few topics.
Normal–normal: an unknown mean#
For observations from with known and a prior , the Bayesian inference note derived the posterior with
To see where they come from, take the logarithm of prior × likelihood and collect the powers of ; every term free of goes into the constant:
The log-density of is . Matching the coefficients of and of gives the two updates; completing the square does the same for vectors.
The inverse of a variance is a precision. Written this way, both updates are additions: the precision grows by per observation, and precision × mean grows by . The data enter only through and , a first example of the sufficient statistics below.
The predictive of a new point adds the noise to the posterior uncertainty of the mean. Given , the mean and the new noise are independent, and the sum of two independent Gaussians is Gaussian with the means and the variances added (linear-Gaussian marginal):
With the prior , noise variance and four observations with mean , the posterior precision is . So and, with , , and the predictive is . For vectors, the same update with precision matrices is the conditional of a joint Gaussian, and Bayesian linear regression is this update for the weights of a linear model.
Normal with known mean: a gamma prior on the precision#
Now the mean is known and the precision is not. The opening of the note read one observation of as a function of and found the gamma form. The gamma distribution with shape and rate is defined on by the density
Its mean is and its variance , both derived in the gamma section from .
As a function of , the likelihood of observations is a power of times an exponential:
Multiplying by the prior adds the powers of and the coefficients of , so the posterior is with
Each observation adds to the shape and half its squared deviation to the rate. The more the data spread around , the larger and the smaller the posterior mean of the precision. Setting the derivative of the log-likelihood to zero gives the maximum likelihood value . The posterior mean is the mediant of the prior mean and this value, so it lies between them.
Take , the prior , with mean 1 and variance 1, and the five points of the next section:
| Quantity | Value |
|---|---|
| , | , |
| posterior mean | |
| posterior standard deviation | |
| maximum likelihood |
Doubling every deviation from multiplies the sum of squares by 4, to , and the posterior mean of the precision drops to .
Normal–gamma: unknown mean and precision#
When the noise level is unknown too, both and the precision need a prior. The likelihood of observations is
Why not take independent priors, a normal for and a gamma for ? Expand the square: the exponent contains and , products of the two unknowns, so the likelihood does not factorize into a function of times a function of . A conjugate prior must have the same shape, so it cannot factorize either. With independent priors the posterior leaves every standard family; the variational inference note starts from exactly that case.
The conjugate prior ties the two together. With the gamma distribution in shape and rate, the normal–gamma prior is
in which, given , the mean has the precision of observations: the more precise the data, the more precisely the mean is pinned down.
Two identities do the update. With the sample mean and , the sum of squares splits as : write and expand; the cross term vanishes because . Completing the square in ,
where and . To check it, compare the two sides: the coefficients of are both , those of both , and the constants agree because .
Now multiply the prior by the likelihood and keep only what depends on or . The prior contributes , the likelihood . By the two identities the product is
The first line is a normal density in with precision , up to its constant; the second is a gamma density in . The posterior is normal–gamma with
The rate collects three sources of squared deviation: the prior’s, the spread of the data around their mean, and the disagreement between the data mean and the prior mean. Writing instead gives the same model as the normal–inverse-gamma prior.
The marginal posterior of the mean integrates out the precision. For a normal with precision and a precision, using ,
The second line takes out of the bracket. The Student-t density with location , squared scale and degrees of freedom is, by definition, . Matching the last line gives and . So
Take the prior , , and the data :
| Quantity | Value |
|---|---|
| , , | , , |
| , , | , , |
| squared scale of , |
The mean has a Student-t posterior with 7 degrees of freedom, centre and squared scale . The Code section checks this marginal against the two-million-point grid of the opening: the two densities agree to .
The exponential family#
Every pair so far had the same structure. The likelihood depended on the data through a few sums: and ; the counts ; , and . And the prior had the form of that likelihood. The exponential family is the class of distributions for which this always happens.
Natural parameters and sufficient statistics#
A distribution belongs to the exponential family if its density, or probability mass function, can be written as
where are the natural parameters, the sufficient statistics, a base measure, and the log-partition function, which makes the density integrate to 1. The usual parameters are a reparametrization of :
| Distribution | ||||
|---|---|---|---|---|
| Bernoulli | ||||
| Poisson | ||||
| Categorical | , | one-hot, first entries | ||
For the Bernoulli, and . For the normal, expanding gives the terms and , and the rest, , is written in . The beta, Dirichlet, multivariate normal and Wishart distributions belong to the family too: the beta density is , and the others expand the same way. The uniform distribution on with unknown does not: its support moves with , while is positive wherever is, whatever . The Student-t and mixtures do not either: their log-densities, or a log of a sum, do not split into a sum of products of a function of the parameters and a function of .
For i.i.d. data the log-likelihood is
The data enter only through and , a vector whose size does not grow with . Two datasets with the same sums have proportional likelihoods and therefore, under any prior, the same posterior.
A statistic is sufficient for , by definition, when the conditional distribution of the data given does not depend on . The Fisher–Neyman factorization criterion says that this holds exactly when the likelihood factorizes as . The log-likelihood above has this form with and . The whole sample is always sufficient, with and . So when a model such as the Student-t is said to have no sufficient statistic, the claim is that none has a size that stays fixed as grows.
Proof of the factorization criterion for discrete data
Fix a dataset and write . If the likelihood factorizes, the probability of is the sum over all datasets with , so by the definition of a conditional probability
which is free of . Conversely, if does not depend on , the product rule gives , a factorization with and . For densities the sums become integrals over the sets , and making that rigorous needs measure theory (Halmos and Savage, 1949).
Derivatives of the log-partition function#
Differentiating the normalization under the integral sign gives the moments of . The exchange of derivative and integral is valid for in the interior of the set where is finite; Murphy (2023, Section 2.4.3) derives the same identities. The first derivative:
Differentiating once more, the exponent contributes :
Moments therefore come from derivatives. For the Bernoulli, and . For the normal, and . For the gamma, , with the digamma function, a moment that is hard to get any other way and that every variational update with a gamma factor needs.
A covariance matrix is positive semidefinite, so is convex, by the second-order condition for convexity. The log-likelihood above is then concave in . It is strictly concave when no linear combination of the statistics is constant, because is then positive for every ; a strictly concave function has at most one maximum. Setting its gradient to zero gives the maximum likelihood equation
This is moment matching: the fitted model reproduces the sample averages of the sufficient statistics. The Gaussian fit by sample mean and sample second moment is an instance, and so is the logistic regression gradient, predicted minus observed.
Concavity gives uniqueness, not existence. Ten flips that all come up heads make the Bernoulli log-likelihood . It increases with towards 0 and never reaches it: at , at . The equation has no solution, because is below 1 for every finite ; the supremum sits at , on the boundary. When the natural parameters range over an open set, a maximum exists exactly when the sample average of is a value of , a mean that some finite produces: a stationary point of a concave function is its maximum, and a maximum in an open set is a stationary point.
Concavity also belongs to the natural parametrization and can be lost in another one. For a normal with known mean , write . In the variance the log-likelihood is, up to a constant,
which is positive for . The maximum is still unique, but a Newton step started beyond moves away from it: there the first derivative is negative and the second positive, so . In the same function is concave.
Why the exponential family has conjugate priors#
Look at the likelihood as a function of : it is times a factor free of . A prior of the same shape,
multiplies with it into the same shape again:
The prior is the likelihood of imaginary observations whose sufficient statistics sum to , and the update adds the real ones (Bishop, 2006, Section 2.4.2). It is a proper prior only when is finite; for the Bernoulli below this means . With , the general formulas of the conjugacy section become
The beta prior is an instance. For the Bernoulli, with , so and . The prior density in is proportional to . As a density in it gains the Jacobian :
So and , and the update , is , . The Jacobian is why the beta exponents are rather than , the offset between the two pseudo-count conventions of the Bayesian inference note. For the seven flips, is four imaginary flips with two heads; adding the real and gives , :
A conjugate update: add the sufficient statistics
Conjugacy is not limited to the exponential family. The uniform distribution on has the likelihood for and 0 otherwise; the Pareto prior for multiplies with it into a Pareto with and . For families with a support that does not depend on the parameter, though, a sufficient statistic of fixed size for every , and with it this kind of conjugate prior, exists only in the exponential family. This is the Pitman–Koopman–Darmois theorem, which also needs smooth densities; its proof is in Koopman (1936), and Murphy (2023, Section 3.4.5) discusses it.
Mixtures of conjugate priors#
Optional depth: how to keep conjugacy with a more flexible prior. The last section uses it once.
A single conjugate prior can be too rigid: “the coin is probably fair, but it might be anything” is not a beta distribution. A mixture of conjugate priors, , is conjugate too. Bayes’ formula for one component, rearranged, says . Summing over the components,
so each component updates as before, and the weights are reweighted by each component’s evidence and normalized to sum to 1:
Take the prior and 9 heads in 10 flips. The components have the evidences and , and the weights become and : the data have moved belief from “fair” to “anything”. The posterior mean is
With 5 heads in 10, the weights are and instead. The weight update is already a comparison of two models by their evidence, the subject of the next note.
Posterior predictive distributions#
The predictive averages the likelihood over the posterior. For conjugate pairs it has a closed form, and it is wider than the plug-in prediction at the posterior mean, because it adds the uncertainty about the parameter to the noise of the data.
The beta–binomial#
The number of heads in future flips, under a posterior, has probabilities
the beta–binomial distribution. The first line is the predictive integral, with flips independent given ; the second collects the powers of and and uses the definition of . Its mean, , is that of a binomial with the posterior mean plugged in. Its variance is larger by the factor :
Derivation of the mean and variance
Write . Ratios of beta constants give the moments of : and , so . Given , is binomial with mean and variance . The tower property gives , and the law of total variance gives
where the second line uses .
After the seven flips, , the predictive for more flips has variance , against for the binomial with . The probability of 3 heads or fewer is under the predictive and under the plug-in.
The Student-t#
Under the normal–gamma posterior, a new observation is . Given , the mean has variance and the independent noise , so by the sum of independent Gaussians , a normal with precision , . Integrating out as for the marginal of ,
In the example of five points this is a Student-t with 7 degrees of freedom, centre and squared scale . Plugging in the posterior means, and , gives instead:
| Predictive Student-t | Plug-in | |
|---|---|---|
| central 95% interval | ||
The predictive gives almost four times the probability to an observation above 3, because it keeps the possibility that the noise is larger than its estimate. Plugging in the maximum likelihood fit, mean and variance , would give .
The predictive is wider than the plug-in
A table of conjugate pairs#
Each row follows by the reading of the conjugacy section: write the likelihood as a function of the parameter, multiply by the prior and add the exponents. For the Poisson, times gives and . The predictive of each row is the ratio of normalizers of the conjugacy section; the names follow Wikipedia’s table and Murphy (2023, Section 3.4).
| Likelihood | Conjugate prior | Posterior hyperparameters | Predictive |
|---|---|---|---|
| Bernoulli, binomial | beta–binomial | ||
| Categorical, multinomial | Dirichlet–multinomial | ||
| Poisson | negative binomial | ||
| Exponential | Lomax (Pareto II) | ||
| , known | precisions add | normal | |
| , known | Student-t | ||
| , both unknown | normal–gamma | above | Student-t |
| , both unknown | normal–Wishart | the same with matrices | multivariate Student-t |
| Uniform | Pareto | — |
Where it breaks: a prior with light tails#
A conjugate prior is chosen for its algebra, and its shape comes with the algebra. The normal prior has light tails, and they decide what happens when the data disagree with it. The example follows Murphy (2023, Section 3.4.6.2), after Berger.
One observation comes from . The prior belief is that has median 0 and quartiles and . The normal prior with these quartiles has standard deviation , variance . The Cauchy prior, a Student-t with one degree of freedom, has the same quartiles but heavy tails. Both state the same belief about the middle of the distribution, and they give different answers:
| Prior | Posterior mean of |
|---|---|
| normal, variance | |
| Cauchy | |
| normal, variance , |
The normal posterior is the precision-weighted average, . It sits where neither the prior nor the likelihood puts much belief: the likelihood says is within about 2 of 5, and the prior gives a probability of 1%. Under a normal prior, a datum is always pulled towards the prior mean by the same fraction, however surprising it is. A heavy-tailed prior gives up when the data are far away; the Cauchy posterior stays near the observation. The posterior mode shows why. It solves , so the prior pulls the estimate back by the slope of its log-density. For the normal prior the slope grows with , and the pull is . For the Cauchy, the slope fades for large : the mode is , a pull of only .
The Cauchy prior is not conjugate, and its posterior needs numerical integration. A mixture of conjugate priors is a conjugate compromise: a broad component with a small weight absorbs a surprising observation. In the third row, each component’s evidence is the linear-Gaussian marginal with or ; reweighting by them moves the weight of the broad component from to , and the posterior mean to .
Two other limits follow from the same algebra. Models built from blocks rarely have a usable conjugate prior as a whole: for a logistic regression, a mixture or a neural network, no prior family with a known normalizer stays closed under the update. Conjugacy then survives inside the blocks, conditional on the other variables, which is what variational inference and Gibbs sampling exploit. And the normal–gamma prior ties the uncertainty of the mean to the noise variance. When prior knowledge about the mean is independent of the noise level, the conjugate prior cannot express it.
What you should remember#
- Conjugate: the posterior stays in the prior’s family, and learning updates a few hyperparameters, in any order and batching.
- Beta–Bernoulli: , ; the evidence is the product of the one-step predictives. Dirichlet: is add- smoothing.
- Unknown mean and precision need the normal–gamma prior, which ties them; the mean and the predictive are Student-t.
- Exponential family: , with and ; maximum likelihood matches the sample means of .
- Its conjugate prior is : add to and to .
- Predictives are wider than plug-ins. A normal prior shrinks every datum by the same fraction, however far it lies.
Code#
Sequential updates checked against the batch formulas, the evidence as a product of predictives, the Dirichlet example, the normal–gamma posterior against the grid and its predictive against Monte Carlo, the derivatives of the log-partition function, the beta–binomial predictive, a mixture prior, and the normal against the Cauchy prior. Seeds are fixed; the script runs in about a second, and exact numbers can differ in the last digit across platforms and library versions.
import numpy as np
from scipy import stats, special, integrate, optimize
rng = np.random.default_rng(0)
lbeta = special.betaln
# beta-Bernoulli: one flip at a time gives the batch posterior, and the product of the
# one-step predictives is the evidence B(a + k, b + n - k) / B(a, b)
x = np.array([1, 0, 1, 1, 0, 1, 1]) # 5 heads in 7 flips
a, b, log_ev = 2.0, 2.0, 0.0 # prior Beta(2, 2)
for xi in x:
p_head = a / (a + b) # predictive of the next flip
log_ev += np.log(p_head if xi else 1 - p_head)
a, b = a + xi, b + 1 - xi # conjugate update
print(a, b, round(a / (a + b), 3)) # 7.0 4.0 0.636
print(round(np.exp(log_ev), 6), round(np.exp(lbeta(7, 4) - lbeta(2, 2)), 6)) # 0.007143 0.007143: 1/140 both ways
# Dirichlet-categorical: counts (5, 2, 0, 1) with a uniform Dir(1, 1, 1, 1) prior
alpha, counts = np.ones(4), np.array([5, 2, 0, 1])
post = alpha + counts
print((post / post.sum()).round(3)) # [0.5 0.25 0.083 0.167]: the unseen category keeps 1/12
log_ev = (special.gammaln(alpha.sum()) - special.gammaln(post.sum())
+ (special.gammaln(post) - special.gammaln(alpha)).sum())
print(round(1 / np.exp(log_ev))) # 27720: the evidence of the sequence is 1/27720
# normal-gamma: unknown mean and precision, prior mu | lam ~ N(m0, 1/(k0 lam)), lam ~ Gamma(a0, rate b0)
def ng_update(m, k, a, b, xs):
n, xbar = len(xs), np.mean(xs)
S = ((xs - xbar) ** 2).sum()
return ((k * m + n * xbar) / (k + n), k + n, a + n / 2,
b + S / 2 + k * n * (xbar - m) ** 2 / (2 * (k + n)))
xs = np.array([1.2, 0.4, 2.1, 1.5, 0.8])
batch = ng_update(0.0, 1.0, 1.0, 1.0, xs)
seq = (0.0, 1.0, 1.0, 1.0)
for xi in xs:
seq = ng_update(*seq, np.array([xi]))
print(np.round(batch, 4), np.allclose(batch, seq)) # [1. 6. 3.5 2.45] True
# check against brute force: the posterior on a grid of (mu, lam), marginalized over lam
mn, kn, an, bn = batch
mu, lam = np.linspace(-2, 4, 1201), np.linspace(1e-4, 8, 1600)
M, L = np.meshgrid(mu, lam, indexing='ij')
log_joint = (stats.norm.logpdf(M, 0, 1 / np.sqrt(L)) + stats.gamma.logpdf(L, 1, scale=1)
+ stats.norm.logpdf(xs[:, None, None], M, 1 / np.sqrt(L)).sum(axis=0))
grid = np.exp(log_joint - log_joint.max()).sum(axis=1)
grid /= grid.sum() * (mu[1] - mu[0]) # the marginal posterior density of mu on the grid
exact = stats.t(2 * an, loc=mn, scale=np.sqrt(bn / (an * kn))).pdf(mu)
print(round(float(np.abs(grid - exact).max()), 4)) # 0.0001: the closed-form Student-t marginal matches
# the posterior predictive is a Student-t; a Monte Carlo check by sampling lam, mu, then x
scale2 = bn * (kn + 1) / (an * kn) # the predictive scale squared
pred = stats.t(2 * an, loc=mn, scale=np.sqrt(scale2))
lam_s = rng.gamma(an, 1 / bn, size=400_000)
x_s = rng.normal(rng.normal(mn, 1 / np.sqrt(kn * lam_s)), 1 / np.sqrt(lam_s))
print(round(scale2, 4), round(pred.sf(3), 4), round((x_s > 3).mean(), 4)) # 0.8167 0.0313 0.0312
plug = stats.norm(mn, np.sqrt(bn / an)) # plug in the posterior means of mu and of lam
print(pred.ppf([0.025, 0.975]).round(2), plug.ppf([0.025, 0.975]).round(2), round(plug.sf(3), 4))
# [-1.14 3.14] [-0.64 2.64] 0.0084
print(round(stats.norm(1.2, np.sqrt(0.34)).sf(3), 4)) # 0.001: the plug-in maximum likelihood fit, variance S/n
# the log-partition function: its gradient is E[u(x)], its second derivative Var[u(x)]
A = lambda eta: np.log1p(np.exp(eta)) # Bernoulli, eta = log(p / (1 - p))
eta, h = np.log(0.3 / 0.7), 1e-4
print(round((A(eta + h) - A(eta - h)) / (2 * h), 4), round((A(eta + h) - 2 * A(eta) + A(eta - h)) / h ** 2, 4)) # 0.3 0.21
# beta-binomial predictive for the next 10 flips after Beta(7, 4), against the plug-in binomial
bb, bi = stats.betabinom(10, 7, 4), stats.binom(10, 7 / 11)
print(round(bb.var(), 3), round(bi.var(), 3), round(bb.cdf(3), 3), round(bi.cdf(3), 3)) # 4.05 2.314 0.089 0.032
# a mixture of conjugate priors is conjugate: 0.5 Beta(20, 20) + 0.5 Beta(1, 1), then 9 heads in 10
w = np.array([0.5 * np.exp(lbeta(29, 21) - lbeta(20, 20)), 0.5 * np.exp(lbeta(10, 2) - lbeta(1, 1))])
w /= w.sum()
print(w.round(3), round(w @ [29 / 50, 10 / 12], 3)) # [0.156 0.844] 0.794
w5 = np.array([np.exp(lbeta(25, 25) - lbeta(20, 20)), np.exp(lbeta(6, 6) - lbeta(1, 1))])
print((w5 / w5.sum()).round(3)) # [0.707 0.293]: with 5 heads in 10, "fair" gains
# a light-tailed prior: x = 5 from N(theta, 1), priors with median 0 and quartiles -1 and 1
x, v = 5.0, (1 / stats.norm.ppf(0.75)) ** 2 # the normal prior's variance, 2.198
lik = lambda th: stats.norm.pdf(x, th, 1)
Z = integrate.quad(lambda th: stats.cauchy.pdf(th) * lik(th), -60, 60, points=[0, 5])[0]
m_cauchy = integrate.quad(lambda th: th * stats.cauchy.pdf(th) * lik(th), -60, 60, points=[0, 5])[0] / Z
ev = np.array([0.8 * stats.norm.pdf(x, 0, np.sqrt(v + 1)), 0.2 * stats.norm.pdf(x, 0, np.sqrt(101))])
w = ev / ev.sum() # posterior weights of the two normal components
print(round(v, 2), round(v / (v + 1) * x, 2), round(m_cauchy, 2), w.round(2), round(w @ [v / (v + 1) * x, 100 / 101 * x], 2))
# 2.2 3.44 4.56 [0.34 0.66] 4.44
mode = lambda logprior: optimize.minimize_scalar(lambda th: -(stats.norm.logpdf(x, th, 1) + logprior(th)),
bounds=(0, 6), method='bounded').x
print(round(stats.norm(0, np.sqrt(v)).sf(3.4), 2), round(mode(stats.cauchy.logpdf), 2)) # 0.01 4.58
Next#
The evidence appeared in every section as a by-product: the normalizer of the posterior, a ratio of two constants, the product of one-step predictions, the weight of a mixture component. The next note makes it the main object. Comparing the evidence of two models compares how well each predicted the data before seeing them, and this comparison prefers the simplest model that explains the data without any penalty added by hand.
References#
- D. P. Vetrov, D. A. Kropotov. Bayesian Methods in Machine Learning (in Russian). Lecture course, Moscow State University, 2015. Lecture 2 (conjugate distributions, the exponential family) and its seminar problems.
- Bayesian Methods in Machine Learning (in Russian). Lecture course, HSE University, 2021. Lecture notes, lecture 2 (conjugate families, why the normal–gamma prior cannot factorize, the exponential family).
- Конспект курса «Байесовские методы в анализе данных», 2026, github.com/bmml-team/bmml_ftda, лекция 1.
- C. M. Bishop. Pattern Recognition and Machine Learning. Springer, 2006. Section 2.3.6 (Bayesian inference for the Gaussian, the normal–gamma prior), Section 2.4 (the exponential family; 2.4.2, conjugate priors).
- K. P. Murphy. Probabilistic Machine Learning: Advanced Topics. MIT Press, 2023. Section 3.4 (conjugate priors; 3.4.5, the exponential family; 3.4.6, mixtures of conjugate priors and robust heavy-tailed priors).
- B. O. Koopman. On distributions admitting a sufficient statistic. Transactions of the American Mathematical Society 39, 399–409, 1936.
- P. R. Halmos, L. J. Savage. Application of the Radon–Nikodym theorem to the theory of sufficient statistics. Annals of Mathematical Statistics 20(2), 225–241, 1949 (the factorization criterion for dominated families of distributions).
- Cambridge 4F13 Probabilistic Machine Learning, 2025/26. Lectures on discrete binary and categorical distributions (the beta and Dirichlet priors, pseudo-counts).