Concept notebookChecking saved investigationReading browser-local route memory before showing a continuation.

Bayesian Inference

Bayesian inference updates a prior distribution over unknowns into a posterior by multiplying by the likelihood and normalizing.

published · difficulty 3/5 · 17 min read

01

01

Intuition

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

PredictName the object in plain language, then predict what should change.Leave with one reusable mental picture before notation appears.

Maximum likelihood asks: which parameter makes the data look most probable?

Bayesian inference asks a different question: after seeing the data, what should we believe about each possible parameter?

That difference matters when data is scarce or uncertainty matters. The likelihood is a score of parameters by data fit. A prior is what you believed before the data. A posterior is the updated distribution after both forces are combined.

For a coin with unknown head probability θ\thetaθ, maximum likelihood might pick one number such as θ^=0.8\hat\theta=0.8θ^=0.8. Bayesian inference keeps a whole distribution over plausible θ\thetaθ values. With little data, the prior can still matter. With lots of data, and with a prior that gives nonzero density near the data-favored values, the likelihood usually concentrates the posterior near the parameters that explain the observations.

The mental model is not "Bayes is MLE plus vibes." It is a different object: MLE returns an estimate, while Bayesian inference returns a distribution over the unknown quantity.

Section prompt

Copy-only prompts — each action copies a page-grounded prompt to your clipboard. Nothing is sent by this site.

02

02

Math

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

InspectTrack the same object through the notation and check each symbol.Leave with the invariant the equations preserve.

Let θΘ\theta\in\ThetaθΘ be an unknown parameter and let DDD be observed data. Bayesian inference starts with a prior distribution or density p(θ)p(\theta)p(θ) and a likelihood p(Dθ)p(D\mid\theta)p(Dθ). Bayes' rule gives the posterior:

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

For a continuous parameter, the denominator

p(D)=p(Dθ)p(θ)dθp(D)=\int p(D\mid\theta)p(\theta)\,d\thetap(D)=p(Dθ)p(θ)dθ

is the evidence or marginal likelihood. Its job is to normalize the posterior so it integrates to 111.

If θ\thetaθ lives in a discrete set, replace the integral with a sum. The job is the same: add up prior-weighted likelihood over all possible parameter values.

For parameter comparison, the key proportional form is

p(θD)p(Dθ)p(θ).p(\theta\mid D)\propto p(D\mid\theta)p(\theta).p(θD)p(Dθ)p(θ).

This is the central contrast with maximum likelihood. The likelihood p(Dθ)p(D\mid\theta)p(Dθ) is a function of θ\thetaθ, but it is not automatically a probability distribution over θ\thetaθ. Multiplying by a prior and normalizing turns it into the posterior distribution.

For a coin with unknown head probability θ[0,1]\theta\in[0,1]θ[0,1], suppose the data has hhh heads and ttt tails, with n=h+tn=h+tn=h+t. The likelihood shape is

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

If DDD records only the count of heads, the full binomial likelihood also has a factor (nh)\binom{n}{h}(hn). That factor does not depend on θ\thetaθ, so it disappears in proportional calculations.

If the prior is a beta distribution with α,β>0\alpha,\beta>0α,β>0,

θBeta(α,β),\theta\sim\operatorname{Beta}(\alpha,\beta),θBeta(α,β),

then

p(θ)θα1(1θ)β1.p(\theta)\propto \theta^{\alpha-1}(1-\theta)^{\beta-1}.p(θ)θα1(1θ)β1.

Multiplying prior and likelihood gives

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

so the posterior is

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

The maximum-likelihood estimate is

θ^MLE=hh+t\hat\theta_{\mathrm{MLE}}=\frac{h}{h+t}θ^MLE=h+th

when h+t>0h+t>0h+t>0. The posterior mean is

E[θD]=α+hα+β+h+t.\mathbb E[\theta\mid D]=\frac{\alpha+h}{\alpha+\beta+h+t}.E[θD]=α+β+h+tα+h.

When n>0n>0n>0, the posterior mean can also be written as

E[θD]=α+βα+β+nαα+β+nα+β+nhn.\mathbb E[\theta\mid D]=\frac{\alpha+\beta}{\alpha+\beta+n}\cdot\frac{\alpha}{\alpha+\beta}+\frac{n}{\alpha+\beta+n}\cdot\frac{h}{n}.E[θD]=α+β+nα+βα+βα+α+β+nnnh.

This is the clean bridge to maximum likelihood: the posterior mean is a weighted compromise between the prior mean and the MLE. The posterior distribution is the richer object; the mean is only one summary of it.

It is safe to think of α+β\alpha+\betaα+β as prior strength for this averaging formula. The density exponents are α1\alpha-1α1 and β1\beta-1β1, so pseudo-count language is only a mnemonic. The exact conjugate update is the parameter update Beta(α,β)Beta(α+h,β+t)\operatorname{Beta}(\alpha,\beta)\to\operatorname{Beta}(\alpha+h,\beta+t)Beta(α,β)Beta(α+h,β+t).

Section prompt

Copy-only prompts — each action copies a page-grounded prompt to your clipboard. Nothing is sent by this site.

03

03

Code

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

TraceMatch variables to symbols before reading the implementation.Leave with a runnable witness for the math.
import math
import numpy as np

def log_beta_fn(a, b):
    return math.lgamma(a) + math.lgamma(b) - math.lgamma(a + b)

def log_beta_pdf(theta, a, b):
    if theta <= 0 or theta >= 1:
        return -math.inf
    return (a - 1) * math.log(theta) + (b - 1) * math.log(1 - theta) - log_beta_fn(a, b)

alpha, beta = 2.0, 2.0
heads, tails = 8, 2

post_alpha = alpha + heads
post_beta = beta + tails
n = heads + tails

mle = None if n == 0 else heads / n
prior_mean = alpha / (alpha + beta)
posterior_mean = post_alpha / (post_alpha + post_beta)

print("MLE:", "undefined" if mle is None else round(mle, 3))
print("prior mean:", round(prior_mean, 3))
print("posterior mean:", round(posterior_mean, 3))
print("posterior:", f"Beta({post_alpha:.1f}, {post_beta:.1f})")

# Grid approximation to show prior * likelihood -> posterior shape.
grid = np.linspace(0.01, 0.99, 99)
log_prior = np.array([log_beta_pdf(theta, alpha, beta) for theta in grid])
log_likelihood = heads * np.log(grid) + tails * np.log(1 - grid)
log_unnormalized_posterior = log_prior + log_likelihood

# Normalize on the grid for inspection.
weights = np.exp(log_unnormalized_posterior - log_unnormalized_posterior.max())
weights = weights / weights.sum()
grid_mean = float(np.sum(grid * weights))

print("grid posterior mean approx:", round(grid_mean, 3))

The code mirrors the math: the prior is a density over θ\thetaθ, the likelihood scores the observed heads and tails for each θ\thetaθ, and the posterior beta parameters add the observed counts to the prior parameters.

Section prompt

Copy-only prompts — each action copies a page-grounded prompt to your clipboard. Nothing is sent by this site.

04

04

Interactive Demo

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

ManipulateChange one control and predict the visible response before reveal.Leave with the observed invariant or a repaired model.

Live Concept Demo

Explore Bayesian Inference

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

difficulty 3/5undergraduatecode-aligned
Demo inquiry checkpoint

Manipulate one control and predict the visible change.

01Choose lensTrace a quantity
02ObserveDemo state pending
03GroundName the equation, invariant, or control that explains it.
04CarryNext: Variational Autoencoders

Choose what to inspect in Bayesian Inference. This shared fallback is an observation guide, not evidence of learning.

Loading interactive demo...

Use the sliders and presets to compare prior strength against observed data. The prior and posterior curves are densities over θ\thetaθ. The likelihood curve is normalized only for display so its shape can be compared on the same plot.

Try the "strong prior, little data" preset, then the "data wins" preset. The MLE only follows the observed fraction. The posterior mean moves between prior belief and data fit, and the full posterior curve shows how much uncertainty remains.

Section prompt

Copy-only prompts — each action copies a page-grounded prompt to your clipboard. Nothing is sent by this site.

4/4 sections ready

Concept: Bayesian Inference

What is the smallest example that makes Bayesian Inference click without losing the math?

BeforeDistributionsNow4/4 sections readyTryManipulate one control and predict the visible change.NextVariational Autoencoders
Object contextProbability
ConceptLearner lens

Bayesian Inference

What is the smallest example that makes Bayesian Inference click without losing the math?

Mode questionCan I say the mechanism back in one sentence before I reveal anything?

Start with the prediction checkpoint, then compare the reveal to the mental model.

Take this move

Study modes

Keep the object fixed; change the lens.

Route back through the notebook

Carry the same object through intuition, math, code, and demo.

4/4 sections ready
Carry inDistributions

Bring the mental model from Distributions; this page will reuse it instead of restarting from zero.

Work hereBayesian Inference

Bayesian inference updates a prior distribution over unknowns into a posterior by multiplying by the likelihood and normalizing.

Carry outVariational Autoencoders

The next edge should feel earned: use the demo prediction here before following Variational Autoencoders.

After The First Pass

Turn the concept into an inspected object.

The lower panels are one second act: keep the object fixed, inspect it visually, check source boundaries, practice transfer, then attach the research question.
ConceptBayesian InferenceProbability

Mechanism Storyboard

See the idea move before the page explains it

Bayesian inference updates a prior distribution over unknowns into a posterior by multiplying by the likelihood and normalizing.

Demo notes open01 / Intuition
Editorial probability illustration of prior and likelihood curves combining into a sharper posterior belief.
Prediction lens

Start with the picture, metaphor, or geometric mechanism.

Commit first

Before reading further, choose the kind of change Bayesian Inference should make visible.

Visual Inquiry

Make the image answer a mathematical question

Bayesian inference updates a prior distribution over unknowns into a posterior by multiplying by the likelihood and normalizing.

4/4 stages readyDemo notes connected
Prediction

Which visible object should carry the first intuition?

Commit first

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

Source Grounding

Canonical references for the mechanism on this page.

Object - ConceptBayesian InferenceQuestion

What is the smallest example that makes Bayesian Inference click without losing the math?

concept:probability/bayesian-inference
Boundary

sources: deisenroth-2020-mml, murphy-2022-probabilistic-ml

Check

Open the closest source note before trusting the local explanation.

Evidence

2 selected-object sources shown first; 2 references total.

Next move

Audit the claim boundary, then ask from the same selected object.

selected object source · book · 2020Mathematics for Machine LearningDeisenroth, Faisal, and Ong
Located CF editorial boundary

Grounds the probability notation and Bayes-rule prerequisites needed for the page.

Used here as

Deisenroth et al. ground Bayes' rule as posterior = likelihood times prior divided by evidence and define evidence as the posterior normalizer; Murphy grounds Bayesian parameter inference...

Caveat

Checks posterior updating and MLE contrast only; not approximate inference, hierarchy, asymptotics, posterior predictive decisions, or universal prior-strength advice. Code/demo are beta-...

Open source
selected object source · book · 2022Probabilistic Machine Learning: An IntroductionMurphy
Located CF editorial boundary

Grounds Bayesian inference as posterior updating under probabilistic models.

Used here as

Deisenroth et al. ground Bayes' rule as posterior = likelihood times prior divided by evidence and define evidence as the posterior normalizer; Murphy grounds Bayesian parameter inference...

Caveat

Checks posterior updating and MLE contrast only; not approximate inference, hierarchy, asymptotics, posterior predictive decisions, or universal prior-strength advice. Code/demo are beta-...

Open source

Claim Review

Bayesian inference updates a prior distribution over unknowns into a posterior by multiplying by the likelihood and normalizing.

Object - ConceptBayesian InferenceQuestion

What is the smallest example that makes Bayesian Inference click without losing the math?

concept:probability/bayesian-inference
Boundary

sources: deisenroth-2020-mml, murphy-2022-probabilistic-ml

Check

Treat every claim as provisional until source support and a local witness agree.

Evidence

1 structured claim check on this concept.

Next move

Run the prediction or practice transfer before asking for a grounded review.

1 CF editorial source-scope review recorded

Publisher-side editorial review is not independent replication. Claims without it still need exact source-support review. 2 references and 3 local witnesses are available for inspection.

Bayesian inference updates a prior distribution over unknown parameters by multiplying it with the likelihood of observed data and normalizing by evidence, producing a posterior distribution rather than a single maximum-likelihood estimate.
Used here as

Deisenroth et al. ground Bayes' rule as posterior = likelihood times prior divided by evidence and define evidence as the posterior normalizer; Murphy grounds Bayesian parameter inference as updating p(theta...

Local witness
Equation 1
p(θD)=p(Dθ)p(θ)p(D).p(\theta\mid D)=\frac{p(D\mid\theta)p(\theta)}{p(D)}.
Equation 2
p(D)=p(Dθ)p(θ)dθp(D)=\int p(D\mid\theta)p(\theta)\,d\theta
Caveat

Checks posterior updating and MLE contrast only; not approximate inference, hierarchy, asymptotics, posterior predictive decisions, or universal prior-strength advice. Code/demo are beta-Bernoulli witnesses;...

Review stateCF editorial source-scope reviewClaim metadata: source checkedPublisher-side editorial review only; not independent replication. Check caveats and exact source scope.

MML supports Bayes-rule notation with prior, likelihood, evidence, and posterior labels, defines evidence/marginal likelihood as the normalizer, and notes that the full posterior retains more information than focusing on a maximum/statistic. Murphy directly supports parameter-level Bayesian updating as p(theta|D) proportional to p(theta)p(D|theta) normalized by p(D), contrasts this with MLE as a single likelihood-maximizing parameter estimate, and gives the beta-Bernoulli/binomial posterior update used by the page.

Reviewer: codex+oracle; reviewed 2026-05-07

Practice notebook

Use the idea, then test it somewhere new

Bayesian inference updates a prior distribution over unknowns into a posterior by multiplying by the likelihood and normalizing.

AttemptNo learning claim inferred
Object - ConceptBayesian InferenceQuestion

What is the smallest example that makes Bayesian Inference click without losing the math?

concept:probability/bayesian-inference
Boundary

sources: deisenroth-2020-mml, murphy-2022-probabilistic-ml

Check

Use one state from Bayesian Inference to explain what changes, why it changes, and which assumption the explanation needs.

Evidence

No learner move yet; no learning state is inferred.

Next move

Write first, use only the help you need, then try a new case without it.

Explain

Use one state from Bayesian Inference to explain what changes, why it changes, and which assumption the explanation needs.

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 object roomClose
Selected object routeAsk from this object; carry one invariant back.sources: deisenroth-2020-mml, murphy-2022-probabilistic-ml
  1. ObjectConceptBayesian Inference
  2. PredictBefore revealBayesian Inference prediction
  3. WitnessCompare codeBayesian Inference code witness 1
  4. RoomAsk groundedChecking local snapshot
ConceptBayesian InferenceProbability
Code witness comparisonBayesian Inference code witness 1if theta <= 0 or theta >= 1:Prediction before revealBayesian Inference predictionManipulate one control and predict the visible change.
Grounded room questionWhat is the smallest example that makes Bayesian Inference click without losing the math?Checking local snapshot

Research Room

Attach the question to an exact object

Pick the concept, equation, source, code witness, claim, misconception, or demo state before asking for help. The handoff stays grounded to that object.
Next local actionNo local draft saved yet

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

conceptProbability

Bayesian Inference

Anchored question

What is the smallest example that makes Bayesian Inference click without losing the math?

Source boundaryInspect source ids: deisenroth-2020-mml, murphy-2022-probabilistic-mlStable content-object key attached
Role lenses for this object

These are fixed, deterministic perspectives derived from the selected object. They do not represent people, community contributions, or independent review.

Learner evidence requestAsk what would make "Bayesian Inference" feel predictable rather than familiar.
Assumption

Source ids deisenroth-2020-mml, murphy-2022-probabilistic-ml must support the exact object, not just the surrounding topic.

Source-checking summary

Treat this as a mechanism object: connect the definition to one equation, code witness, or demo before broadening the discussion.

Proposed experiment

Ask the learner to perturb one representation, then check whether the same invariant survives in math, code, and demo.

Next action

The learner can state the mechanism in their own words

Evidence4 checks
PredictionChecking carried observation
ActionReady for one action
AILearner handoff ready
Open source object
01PredictionChecking browser-local route memory
02EvidenceChecking for a carried observation
03BoundaryInspect source ids: deisenroth-2020-mml, murphy-2022-probabilistic-ml
04Next moveSave one next action
Local action draftNo local draft saved yetExpand only when ready to capture one local next action
Local action draft

This draft stays locally in this browser for concept:probability/bayesian-inference.

No local draft saved.
Evidence to inspect
  • Source ids to inspect: deisenroth-2020-mml, murphy-2022-probabilistic-ml
  • Definition, prerequisite, and contrast concept links
  • The equation or code witness 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
Object-attached AI handoff

I am working in Continuous Function's research reading room. Object: concept - Bayesian Inference Object key: concept:probability/bayesian-inference Context: Probability Anchor id: concept/concept-notebook/probability/bayesian-inference Open question: What is the smallest example that makes Bayesian Inference click without losing the math? Evidence to inspect: - Source ids to inspect: deisenroth-2020-mml, murphy-2022-probabilistic-ml - Definition, prerequisite, and contrast concept links - The equation or code witness that makes the concept operational - One demo state that shows the invariant instead of a slogan Deterministic role lenses for this object: - Boundary: fixed perspectives, not people, community contributions, or independent review - Source-checking summary: Treat this as a mechanism object: connect the definition to one equation, code witness, or demo before broadening the discussion. - Proposed experiment: Ask the learner to perturb one representation, then check whether the same invariant survives in math, code, and demo. - Teach/transfer move: Turn the mechanism into one sentence that predicts a neighboring concept. - Assumptions: - Source ids deisenroth-2020-mml, murphy-2022-probabilistic-ml must support the exact object, not just the surrounding topic. - The stable content-object key lets local drafts, prompts, and route memory attach without changing the source page. - The concept explanation is local atlas prose until checked against its math, code, and source support. - Prerequisite gaps should become a repair route, not a reason to leave the object vague. - Role-lens requests: - Learner: ask for "Ask what would make "Bayesian Inference" feel predictable rather than familiar." | assumption: Source ids deisenroth-2020-mml, murphy-2022-probabilistic-ml must support the exact object, not just the surrounding topic. | next action: The learner can state the mechanism in their own words - Researcher: ask for "Source ids to inspect: deisenroth-2020-mml, murphy-2022-probabilistic-ml" | assumption: The stable content-object key lets local drafts, prompts, and route memory attach without changing the source page. | next action: The learner can name the prerequisite that would repair confusion - Experimenter: ask for "Choose one variable or condition to perturb before asking for an explanation." | assumption: The concept explanation is local atlas prose until checked against its math, code, and source support. | next action: The learner can predict how the mechanism changes under one perturbation - Professor: ask for "Find the smallest transferable rule a learner could reuse without the AI." | assumption: Prerequisite gaps should become a repair route, not a reason to leave the object vague. | next action: Teach or transfer: Turn the mechanism into one sentence that predicts a neighboring concept. 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. Current deterministic role lens for this object: - Role lens: Learner - Evidence request: Ask what would make "Bayesian Inference" feel predictable rather than familiar. - Assumption to keep visible: Source ids deisenroth-2020-mml, murphy-2022-probabilistic-ml must support the exact object, not just the surrounding topic. - Proposed experiment: Ask the learner to perturb one representation, then check whether the same invariant survives in math, code, and demo. - Next action: The learner can state the mechanism in their own words

concept/concept-notebook/probability/bayesian-inference concept:probability/bayesian-inference