Skip to main content

05. Bayesian Inference and Conjugate Priors — How Distributions Learn

Background 5/5. So far, distributions have been treated as "given." This page covers the procedure for updating beliefs about a distribution after observing data (Bayesian inference) and the special structure that gives this update a closed form (conjugacy). This is where the Beta distribution takes the stage as a "probability distribution over probabilities."

Bayes' theorem

It follows directly from the definition of conditional probability.

P(θD)=P(Dθ)P(θ)P(D)P(\theta \mid D) = \frac{P(D \mid \theta)\, P(\theta)}{P(D)}

The role of each term:

TermNameMeaning
P(θ)P(\theta)PriorBelief about the parameter before observing data
P(Dθ)P(D \mid \theta)LikelihoodPlausibility of observing this data when the parameter is θ\theta
P(θD)P(\theta \mid D)PosteriorBelief updated after observing data
P(D)P(D)EvidenceNormalization constant P(Dθ)P(θ)dθ\int P(D \mid \theta) P(\theta)\, d\theta

The key shift in perspective: in frequentist statistics, θ\theta is an unknown constant, while in Bayesian statistics, θ\theta itself is a random variable. The notion of a "distribution over parameters" therefore makes sense, and inference is the process of tightening that distribution with data.

In practice, it is written as a proportionality that omits the normalization constant.

P(θD)posterior  P(Dθ)likelihood×P(θ)prior\underbrace{P(\theta \mid D)}_{\text{posterior}} \ \propto\ \underbrace{P(D \mid \theta)}_{\text{likelihood}} \times \underbrace{P(\theta)}_{\text{prior}}

The problem: the posterior is generally intractable

P(D)=P(Dθ)P(θ)dθP(D) = \int P(D \mid \theta) P(\theta) d\theta has no closed form for most combinations of likelihood and prior. Major branches of modern Bayesian statistics—MCMC and variational inference—are devoted to approximating this integral. But for certain combinations, this integral is solved for free. That is conjugacy.

Conjugate priors

A prior family P\mathcal{P} is conjugate to a likelihood P(Dθ)P(D \mid \theta) if

priorP    posteriorP\text{prior} \in \mathcal{P} \implies \text{posterior} \in \mathcal{P}

The posterior remains in the same family as the prior, and updating ends with arithmetic on the parameters.

Representative example: Beta–Bernoulli

Suppose we estimate the probability θ[0,1]\theta \in [0,1] that a coin comes up heads. If kk heads are observed in nn tosses, the likelihood is

P(Dθ)=θk(1θ)nkP(D \mid \theta) = \theta^{k} (1-\theta)^{n-k}

Choose Beta(α,β)\mathrm{Beta}(\alpha, \beta) as the prior, so P(θ)θα1(1θ)β1P(\theta) \propto \theta^{\alpha-1}(1-\theta)^{\beta-1}. Then

P(θD)  θk(1θ)nkθα1(1θ)β1=θα+k1(1θ)β+nk1P(\theta \mid D) \ \propto\ \theta^{k}(1-\theta)^{n-k} \cdot \theta^{\alpha-1}(1-\theta)^{\beta-1} = \theta^{\alpha+k-1}(1-\theta)^{\beta+n-k-1}

The right-hand side is exactly the kernel of Beta(α+k, β+nk)\mathrm{Beta}(\alpha+k,\ \beta+n-k). Without performing a single integral,

θD  Beta(α+k, β+nk)\theta \mid D \ \sim\ \mathrm{Beta}(\alpha + k,\ \beta + n - k)

The update rule is "add the counts." α\alpha can be read as the number of successes observed so far plus the prior success count, while β\beta is the failure count. This is why α,β\alpha, \beta are called pseudo-counts. Starting from Beta(1,1)\mathrm{Beta}(1,1) (= Uniform) makes an "observer with no bias," while starting from Beta(50,50)\mathrm{Beta}(50,50) gives a "strong prior belief that the coin is fair."

Why those combinations fit — the exponential family

This is no coincidence. If the likelihood belongs to the exponential family,

p(xθ)=h(x)exp(η(θ)T(x)A(θ))p(x \mid \theta) = h(x) \exp\big( \eta(\theta)^{\top} T(x) - A(\theta) \big)

a conjugate prior always exists, and updating reduces to accumulating the sufficient statistic T(x)T(x). Frequently used conjugate pairs include:

LikelihoodConjugate priorPosterior update
Bernoulli / binomialBetaAdd success and failure counts
PoissonGammaAdd event counts and observation counts
Normal (known variance)NormalPrecision-weighted mean
Normal (unknown mean and variance)Normal-Inverse-GammaUpdate four parameters
Categorical / multinomialDirichletAdd counts for each category

The third row is important: the Gaussian is conjugate to itself for its mean. From the perspective of conjugacy, Gaussian and Beta distributions play the same role on their respective stages (continuous location parameters versus probability parameters).

Posterior predictive distribution

The distribution of the next observation xnewx_{\text{new}} is obtained by integrating out parameter uncertainty.

P(xnewD)=P(xnewθ)P(θD)dθP(x_{\text{new}} \mid D) = \int P(x_{\text{new}} \mid \theta)\, P(\theta \mid D)\, d\theta

For Beta–Bernoulli, the Beta function identity gives this integral in closed form:

P(xnew=1D)=E[θD]=α+kα+β+nP(x_{\text{new}} = 1 \mid D) = \mathbb{E}[\theta \mid D] = \frac{\alpha + k}{\alpha + \beta + n}

This formula contains Laplace's rule of succession as a special case (with α=β=1\alpha = \beta = 1, it becomes k+1n+2\frac{k+1}{n+2}). Smoothing that "does not conclude the probability is zero even after zero observations" emerges automatically.

Sequential updating — the online nature of Bayesian inference

Thanks to conjugacy, even when data arrives as a stream, only a few parameters are needed as state.

Beta(α,β) 1 success Beta(α+1,β) 1 failure Beta(α+1,β+1)\mathrm{Beta}(\alpha,\beta) \xrightarrow{\ \text{1 success}\ } \mathrm{Beta}(\alpha+1,\beta) \xrightarrow{\ \text{1 failure}\ } \mathrm{Beta}(\alpha+1,\beta+1) \to \cdots
  • The final posterior is identical whether all data is inserted at once or one item at a time (exchangeability).
  • This structure enables Thompson sampling in multi-armed bandits (see the Beta distribution page) and real-time monitoring of A/B tests.

Limitations of conjugacy

  • Restricted expressiveness: real prior knowledge may not have a Beta shape. Conjugacy is a computational convenience, not an epistemological justification.
  • In complex models (hierarchical models and neural networks), the conjugate structure breaks and MCMC or variational inference becomes necessary. Even within those algorithms, however, conjugate blocks remain useful performance levers (for example, full conditional distributions in Gibbs sampling).

What to remember from this page

  1. Bayesian inference = prior × likelihood ∝ posterior. Its essence is the shift in perspective that promotes the parameter to a random variable.
  2. Conjugacy = the property that the posterior remains in the prior's family. Updating reduces to arithmetic on sufficient statistics.
  3. Beta–Bernoulli is the archetypal conjugate pair: Beta(α,β)Beta(α+k,β+nk)\mathrm{Beta}(\alpha,\beta) \to \mathrm{Beta}(\alpha+k, \beta+n-k), and its parameters are pseudo-counts.
  4. The posterior predictive mean α+kα+β+n\frac{\alpha+k}{\alpha+\beta+n} has automatic smoothing built in.

Next step

The background theory is complete. We now confront the three distributions directly.