Probability

Bayesian Updating and Conjugacy

Conjugacy makes Bayesian updating algebraic: compatible likelihood sufficient statistics add to prior hyperparameters, yielding a same-family posterior.

status: reviewimportance: importantdifficulty 4/5math: graduateread: 21mlive demo

Concept Structure

Bayesian Updating and Conjugacy

01Intuition

Start with the picture, metaphor, or geometric mechanism.

02Math

Make the objects explicit and connect them with notation.

03Code

Mirror the equations with runnable implementation details.

04Interactive Demo

Manipulate the mechanism and watch the idea respond.

3prerequisites
4next concepts
2related links

Learner Contract

What this page should let you do.

You are here becauseConjugacy makes Bayesian updating algebraic: compatible likelihood sufficient statistics add to prior hyperparameters, yielding a same-family posterior.

This Probability concept is the current idea: keep the same invariant visible across Intuition, Math, Code, Interactive Demo.

By the end4/4 sections ready | runnable code expected | live demo

Explain the mechanism, trace the main notation, and test one prediction in the live demo.

Do this firstIntuition

Read the intuition before the notation; the math should name a mechanism you already felt.

Then go nextBayesian Networks (review)

Follow this edge after making one prediction here; the next page should reuse the result, not restart the route.

Test the linkManipulate one control and predict the visible change.Then continue to Bayesian Networks (review)

Claim/source review status

Substantive review recorded

1/1 claims have bounded review metadata; still check caveats and source scope.Metadata-derived; review may be AI-assisted. Not a human certification.
Claims1/1 reviewed
Sources4 cited
Codeattached
Demolive
Reviewed2026-07-02
Updatedpage 2026-07-02

Learning item flow

4/4 sections readyAsk about thisResearch room
ConceptBayesian Updating and ConjugacyProbability
4 sources attachedLocal snapshot ready
concept:probability/bayesian-updating-conjugacy
01

01

Intuition

Build the mental picture first so the rest of the page has something to attach to.

Section prompt

Bayesian updating has one basic move:

posteriorlikelihood×prior.\text{posterior} \propto \text{likelihood}\times\text{prior}.

Conjugacy is what happens when that multiplication is kind. The prior and posterior stay in the same distribution family, and the data changes only a small set of hyperparameters.

For a Bernoulli coin, a beta prior keeps two numbers: how much mass leans toward heads and how much mass leans toward tails. After seeing hh heads and tt tails, the posterior is another beta distribution. The update is not a new optimization problem:

(α,β)(α+h,β+t).(\alpha,\beta)\quad\longrightarrow\quad(\alpha+h,\beta+t).

That is the first mental model. A conjugate prior is a ledger that knows which sufficient statistics the likelihood will contribute.

The deeper pattern is not "memorize the beta table." In exponential-family models, likelihood terms contain sufficient statistics such as counts, sums, or squared sums. A conjugate prior stores compatible natural parameters. Bayesian updating adds the data's sufficient statistics into that ledger and then renormalizes.

This is why conjugacy is so useful in probabilistic modeling. It gives exact posterior updates, exact posterior predictive probabilities, and often analytic marginal likelihoods. It is also why conjugacy is limited. If the model or prior no longer matches this algebra, Bayesian inference does not disappear; it usually becomes approximate inference, such as Monte Carlo or variational inference.

02

02

Math

Translate the story into symbols, assumptions, and a derivation you can inspect.

Section prompt

Let θ\theta be an unknown parameter and D={x1,,xn}D=\{x_1,\ldots,x_n\} be observed data. Bayes' rule gives

p(θD)=p(Dθ)p(θ)p(D).p(\theta\mid D) = \frac{p(D\mid\theta)p(\theta)}{p(D)}.

A prior family P\mathcal P is conjugate to a likelihood family when the posterior stays in P\mathcal P for every dataset in the model:

p(θ)Pp(θD)P.p(\theta)\in\mathcal P \quad\Rightarrow\quad p(\theta\mid D)\in\mathcal P.

The easiest exact example is the beta-Bernoulli model. Let θ[0,1]\theta\in[0,1] be the probability of success. The prior is

θBeta(α,β),p(θ)θα1(1θ)β1.\theta \sim \operatorname{Beta}(\alpha,\beta), \qquad p(\theta)\propto \theta^{\alpha-1}(1-\theta)^{\beta-1}.

If the data has hh successes and tt failures, the Bernoulli likelihood has shape

p(Dθ)θh(1θ)t.p(D\mid\theta)\propto \theta^h(1-\theta)^t.

Multiplying likelihood and prior gives

p(θD)θα+h1(1θ)β+t1,p(\theta\mid D) \propto \theta^{\alpha+h-1}(1-\theta)^{\beta+t-1},

so

θDBeta(α+h,β+t).\theta\mid D \sim \operatorname{Beta}(\alpha+h,\beta+t).

The posterior predictive probability of the next success is the posterior mean:

p(xn+1=1D)=E[θD]=α+hα+β+h+t.p(x_{n+1}=1\mid D) = \mathbb E[\theta\mid D] = \frac{\alpha+h}{\alpha+\beta+h+t}.

For a KK-class categorical model, let π=(π1,,πK)\pi=(\pi_1,\ldots,\pi_K) be class probabilities and let the prior be

πDirichlet(α1,,αK).\pi \sim \operatorname{Dirichlet}(\alpha_1,\ldots,\alpha_K).

If ckc_k is the count of class kk, the likelihood contributes

k=1Kπkck.\prod_{k=1}^{K}\pi_k^{c_k}.

The posterior is

πDDirichlet(α1+c1,,αK+cK),\pi\mid D \sim \operatorname{Dirichlet}(\alpha_1+c_1,\ldots,\alpha_K+c_K),

and the posterior predictive probability for class kk is

p(xn+1=kD)=αk+ckj=1Kαj+n.p(x_{n+1}=k\mid D) = \frac{\alpha_k+c_k}{\sum_{j=1}^{K}\alpha_j+n}.

For a normal mean with known observation variance, the sufficient statistic is different. Let

xiμN(μ,σ2)x_i\mid \mu \sim \mathcal N(\mu,\sigma^2)

with known σ2\sigma^2, and let the prior be

μN(μ0,τ01),\mu \sim \mathcal N(\mu_0,\tau_0^{-1}),

where τ0\tau_0 is prior precision. If xˉ\bar x is the sample mean, the data precision is

τD=nσ2.\tau_D=\frac{n}{\sigma^2}.

The posterior is another normal distribution,

μDN(μn,τn1),\mu\mid D\sim \mathcal N(\mu_n,\tau_n^{-1}),

with

τn=τ0+τD\tau_n=\tau_0+\tau_D

and

μn=τ0μ0+τDxˉτ0+τD.\mu_n = \frac{\tau_0\mu_0+\tau_D\bar x}{\tau_0+\tau_D}.

So the update is still ledger arithmetic, but the ledger is precision-weighted rather than count-only.

The general exponential-family version explains why this keeps happening. Suppose the likelihood can be written as

p(xη)=h(x)exp(ηT(x)A(η)),p(x\mid \eta) = h(x)\exp\left(\eta^\top T(x)-A(\eta)\right),

where η\eta is a natural parameter, T(x)T(x) is a sufficient statistic, and A(η)A(\eta) is the log normalizer. A conjugate prior often has the form

p(ηχ,ν)exp(ηχνA(η)).p(\eta\mid \chi,\nu) \propto \exp\left(\eta^\top\chi-\nu A(\eta)\right).

For iid data, the likelihood contributes iT(xi)\sum_i T(x_i) and nA(η)nA(\eta). The posterior hyperparameters become

χ=χ+i=1nT(xi),ν=ν+n.\chi'=\chi+\sum_{i=1}^{n}T(x_i), \qquad \nu'=\nu+n.

This is the reusable invariant: conjugacy works when the prior is shaped to receive the likelihood's sufficient statistics.

03

03

Code

Keep the implementation aligned with the notation so the algorithm is legible.

Section prompt
import numpy as np

def beta_bernoulli(alpha, beta, heads, tails):
    post = np.array([alpha + heads, beta + tails], dtype=float)
    return post, post[0] / post.sum()

def dirichlet_categorical(alpha, counts):
    post = np.asarray(alpha, dtype=float) + np.asarray(counts, dtype=float)
    return post, post / post.sum()

def normal_known_variance(mu0, prior_var, xbar, n, obs_var):
    prior_precision = 1.0 / prior_var
    data_precision = n / obs_var
    post_precision = prior_precision + data_precision
    post_mean = (prior_precision * mu0 + data_precision * xbar) / post_precision
    return post_mean, 1.0 / post_precision

print("Beta posterior:", beta_bernoulli(2, 3, heads=5, tails=3))
print("Dirichlet posterior:", dirichlet_categorical([1, 1, 1], [3, 4, 1]))
print("Normal posterior:", normal_known_variance(-1.0, 1.0, 0.625, 8, 1.0))

Each function mirrors the same idea. The posterior is not found by maximizing the likelihood. It is found by adding the likelihood's sufficient statistics to prior hyperparameters and then reading the updated distribution.

04

04

Interactive Demo

Use direct manipulation to connect the explanation to a moving system.

Section prompt

The Conjugacy Ledger Lab hides the posterior ledger until you commit to an update rule.

Switch among three conjugate pairs:

  1. Beta-Bernoulli: prior shape parameters plus success/failure counts.
  2. Dirichlet-categorical: prior class mass plus category counts.
  3. Normal-normal with known variance: prior precision plus data precision.

Before revealing, decide whether the posterior should add sufficient statistics, replace the prior with the MLE, directly average parameters, or remain unchanged. Then reveal the exact posterior and the posterior predictive summary.

Live Concept Demo

Explore Bayesian Updating and Conjugacy

The stage is code-native and interactive. Use it to test the explanation against the mechanism.

difficulty 4/5graduatecode-aligned
Demo Prediction Checkpoint

Manipulate one control and predict the visible change.

Commit to what Bayesian Updating and Conjugacy should make visible before reading the result.

After The First Pass

Turn the concept into an inspected object.

Once the invariant is visible in the intuition, math, code, and demo, use these panels to inspect the mechanism visually, check source support, practice the idea, and attach a grounded research question.

Mechanism Storyboard

See the idea move before the page explains it

Conjugacy makes Bayesian updating algebraic: compatible likelihood sufficient statistics add to prior hyperparameters, yielding a same-family posterior.

Prediction open01 / Intuition
Prediction lens

Start with the picture, metaphor, or geometric mechanism.

Commit first

Before reading further, choose the kind of change Bayesian Updating and Conjugacy should make visible.

Visual Inquiry

Make the image answer a mathematical question

Conjugacy makes Bayesian updating algebraic: compatible likelihood sufficient statistics add to prior hyperparameters, yielding a same-family posterior.

4/4 stages readyLive demo connected
Prediction

Which visible object should carry the first intuition?

Commit first

Pick the cue that should make Bayesian Updating and Conjugacy easier to reason about before the page gives the answer.

Source Grounding

Canonical references for the mechanism on this page.

course-notes · 2022MIT 18.05 Lecture 15: Bayesian Updating with Discrete PriorsMIT OpenCourseWare

Grounds the conjugate-prior definition, beta-binomial/Beta-Bernoulli update, normal-normal known-variance update, and the warning that nonconjugate cases may require computational methods.

Open source
book · 2020Mathematics for Machine LearningDeisenroth, Faisal, and Ong

Grounds Bayes' rule, conditional probability, distributions, and the probability notation used by the update algebra.

Open source
book · 2022Probabilistic Machine Learning: An IntroductionKevin P. Murphy

Probabilistic-ML reference for Bayesian parameter learning, conjugate examples, posterior predictive reasoning, and the bridge to approximate inference.

Open source
course-notes · 2010Berkeley CS 281B / Stat 241B Lecture 4: Exponential Families and Conjugate PriorsMichael I. Jordan

Supports the exponential-family conjugacy pattern: prior natural parameters update by adding sufficient statistics and sample count terms.

Open source

Claim Review

Conjugacy makes Bayesian updating algebraic: compatible likelihood sufficient statistics add to prior hyperparameters, yielding a same-family posterior.

Status1 substantive review recorded

Claims without a substantive review badge still need exact source-support review.

Sources4 references

mit-18-05-conjugate-priors, deisenroth-2020-mml, murphy-2022-probabilistic-ml, jordan-2010-conjugate-priors

Local checks4 local checks

Use equations, runnable code, and demos to check whether the source support is operational.

Substantively reviewedA conjugate prior is a prior family that stays in the same family after multiplying by a compatible likelihood, and in common exponential-family cases the update can be read as prior hyperparameters plus data sufficient statistics.Claim metadata: source checked

The sources support conjugacy as posterior-family closure, the Beta-Bernoulli/count-addition witness, the Dirichlet-categorical count-addition pattern through exponential-family sufficient statistics, the normal-normal known-variance precision update, and the caveat that conjugacy is a convenience rather than a universal Bayesian method.

Sources: MIT 18.05 Lecture 15: Bayesian Updating with Discrete Priors, Mathematics for Machine Learning, Probabilistic Machine Learning: An Introduction, Berkeley CS 281B / Stat 241B Lecture 4: Exponential Families and Conjugate PriorsFinite and known-variance witnesses only; excludes hierarchical priors, unknown-variance normal-inverse-gamma updates, nonparametric Bayes, improper-prior edge cases, and a GPT Pro publication pass.A bounded review summary is present; still check caveats and exact reference scope.

Checked MIT 18.05 for the conjugate-prior definition, beta-binomial/Beta-Bernoulli and normal-normal known-variance updates, and the nonconjugate warning; checked MML for Bayes-rule and distribution notation; checked Murphy's ProbML context for Bayesian parameter learning and posterior predictive use; checked Jordan's exponential-family lecture for the natural-parameter plus sufficient-statistics conjugacy form. GPT Pro publication critique remains pending.

Reviewer: codex-local-source-review; reviewed 2026-07-02

Practice Loop

Try the idea before it explains itself

Conjugacy makes Bayesian updating algebraic: compatible likelihood sufficient statistics add to prior hyperparameters, yielding a same-family posterior.

Readiness0/3 checks ready
Predict

Before touching the demo, predict one visible change that should happen in Bayesian Updating and Conjugacy.

Hint 1

Reveal when your model needs a nudge.

Hint 2

Reveal when your model needs a nudge.

Hint 3

Reveal when your model needs a nudge.

Grounded research drawerClose
ConceptBayesian Updating and ConjugacyProbability

Research Room

Attach the question to a claim, equation, code, or demo

Pick the concept, equation, source, runnable code, claim, misconception, or demo state before asking for help. The handoff keeps that page item in context.
Next local actionNo local draft saved yet

Open the draft below to save one note and next action in this browser.

conceptProbability

Bayesian Updating and Conjugacy

Attached question

What is the smallest example that makes Bayesian Updating and Conjugacy click without losing the math?

Local action draftNo local draft saved yetExpand only when ready to capture one local next action
Local action draft

This draft stays in this browser, attached to the selected learning item.

No local draft saved.
Evidence to inspect
  • References to inspect: attached references on this page.
  • Definition, prerequisite, and contrast concept links
  • The equation or runnable code that makes the concept operational
  • One demo state that shows the invariant instead of a slogan
What would resolve this
  • The learner can state the mechanism in their own words
  • The learner can name the prerequisite that would repair confusion
  • The learner can predict how the mechanism changes under one perturbation
Grounded AI handoff

I am working in Continuous Function's research reading room. Object: concept - Bayesian Updating and Conjugacy Selected item key: recorded for copy. Context: Probability Page anchor: recorded for copy. Open question: What is the smallest example that makes Bayesian Updating and Conjugacy click without losing the math? Evidence to inspect: - References to inspect: attached references on this page. - Definition, prerequisite, and contrast concept links - The equation or runnable code that makes the concept operational - One demo state that shows the invariant instead of a slogan What would resolve this: - The learner can state the mechanism in their own words - The learner can name the prerequisite that would repair confusion - The learner can predict how the mechanism changes under one perturbation Answer as a careful research tutor: stay source-grounded, separate verified evidence from assumptions, name the relevant math objects, and end with one next action.

View it in context
concept/concept-notebook/probability/bayesian-updating-conjugacy concept:probability/bayesian-updating-conjugacy