Learning path / Bayesian reasoning

Update beliefs.


Turn uncertainty into action.

Bayesian inference is a loop, not a one-time formula: begin with uncertainty, observe evidence, update the posterior, then use that posterior to predict, decide, or choose what to measure next.

01 / Foundation

Flip the conditional.


Weigh it by the prior.

Bayes’ theorem converts the question a model can answer — how likely is this data under each hypothesis? — into the question you actually have: how likely is each hypothesis, given the data? Every instrument on this page is this one identity, applied over and over.

p(H | D) = p(D | H) · p(H) / p(D)
Fundamentals

Prior p(H)plausibility of the hypothesis before this data

Likelihood p(D | H)how well the hypothesis predicts what you saw

Evidence p(D)the same data, summed over every hypothesis

Worked example · one datum

The positive test

A condition affects 1 person in 100. A test catches 95% of true cases and false-alarms on 5% of healthy people. Your result comes back positive. How worried should you be?

Only 16%. The 5% false-alarm rate applies to the 99 healthy people, so false positives outnumber true ones five to one. The prior is not a technicality — it carries the base rate that intuition drops.

Priorp(sick) = 0.01
Likelihoodp(+ | sick) = 0.95, p(+ | healthy) = 0.05
Evidencep(+) = 0.95 · 0.01 + 0.05 · 0.99 = 0.059
Posteriorp(sick | +) = 0.0095 / 0.059 ≈ 0.16
Worked example · i.i.d. data

Five flips of a suspect coin

A drawer holds two coins: one fair (heads 50%) and one loaded (heads 80%). You grab one at random — a 50/50 prior — and flip it five times: H, H, T, H, H. The flips are independent and identically distributed given the coin, so the likelihood of the whole sequence is the product of the per-flip probabilities.

Batch or one flip at a time — identical. Multiply all five likelihoods at once, or update after every flip and let each posterior serve as the next prior: both roads end at 72%. That equivalence is why the rest of this page can feed observations in one at a time.

Fair coinp(HHTHH | fair) = 0.5⁵ ≈ 0.031
Loaded coinp(HHTHH | loaded) = 0.8⁴ · 0.2 ≈ 0.082
Posteriorp(loaded | D) = 0.082 / (0.082 + 0.031) ≈ 0.72
The same update, one flip at a time
FlipLikelihood ratiop(loaded) so far
start50.0%
H× 0.8 / 0.5 = 1.661.5%
H× 1.671.9%
T× 0.2 / 0.5 = 0.450.6%
H× 1.662.1%
H× 1.672.4%
From two hypotheses to infinitely many

The next section replaces the pair {fair, loaded} with every success rate between 0 and 1 at once. The prior becomes a curve, the product-of-likelihoods trick is unchanged, and the posterior becomes a curve you can watch move.

02 / Inference

Posterior = prior × evidence,


renormalized.

For a Bernoulli outcome, the unknown success probability p has a Beta prior. Multiplying by each likelihood adds one count to a shape parameter.

p(p | y₁:ₙ) ∝ p(p) ∏ p(yᵢ | p)
Fundamentals

Priorbelief before this dataset

Likelihoodhow the model explains observations

Posteriorupdated belief after evidence

Beta–Bernoulli

Belief becomes posterior

Beta(α, β) + data → Beta(α+s, β+f)
p = 0p = 1posterior mean 0.50
prior Beta(2, 2)posterior Beta(2, 2)
Prior

p(p) ∝ pα−1(1−p)β−1

×
Likelihood

p(data|p) ∝ ps(1−p)f

=
Posterior

p(p|data) ∝ pα+s−1(1−p)β+f−1

03 / Classification

Every labeled example


moves the prediction.

Multinomial Naive Bayes learns a class prior and one token distribution per class. Step through the inbox to see exactly which counts change and how a test email’s spam probability responds.

P(spam | words) ∝ P(spam) ∏ P(word | spam)
Fundamentals

Class priorbaseline frequency of spam vs ham

Conditional likelihoodword frequency within each class

Naive assumptionwords factor independently given class

Step 0 of 8
Model is at its prior
Training stream0 spam · 0 ham
What changedNo data yet
prior
Equal, smoothed starting belief

Before seeing mail, both classes and every vocabulary word receive one pseudocount.

Class prior P(spam)50.0%
(spam documents + 1) / (all documents + 2)
WordP(word | spam)P(word | ham)
free0.1000.100
win0.1000.100
offer0.1000.100
click0.1000.100
urgent0.1000.100
money0.1000.100
meeting0.1000.100
project0.1000.100
report0.1000.100
lunch0.1000.100
Class prior

P(c) = (Nc+1)/(N+2)

×
Word likelihoods

w (count(w,c)+1)/(tokensc+|V|)

Normalize scores

P(spam|words) = scores/(scores+scoreh)

Why “naive”?

The model assumes words are conditionally independent once the class is known. That is rarely literally true—“free” and “offer” co-occur—but the factorization makes learning transparent, fast, and surprisingly effective.

04 / Decisions

A posterior is useful


because you can act with it.

Thompson sampling draws one plausible reward rate for every option, chooses the largest, observes the reward, and updates only that option’s posterior.

sample → choose → observe → update
Fundamentals

Banditrepeated choice with partial feedback

Rewardobserved value from the chosen arm

Regretvalue lost versus the best arm

Three-armed bandit

Sample beliefs to make decisions

armₜ = arg maxᵢ θᵢ, θᵢ ~ posteriorᵢ
Arm A0 pulls
posterior mean50.0%
unknown truth: 32%
Arm B0 pulls
posterior mean50.0%
unknown truth: 48%
Arm C0 pulls
posterior mean50.0%
unknown truth: 56%
Run a round to draw one plausible value from every posterior.
The connection

The Beta posterior from chapter 01 becomes the sampling distribution here. Uncertain arms get explored because their posterior samples vary widely; strong arms get exploited because they win most samples.

05 / Optimization

The same decision loop,


over a continuous space.

Bayesian optimization replaces one posterior per arm with a probabilistic surrogate over a function. An acquisition rule combines predicted value with uncertainty to choose the next expensive evaluation.

surrogate → acquire → evaluate → update
Fundamentals

Black-box objectiveexpensive function without useful gradients

Surrogatecheap probabilistic approximation

Acquisitionrule for choosing the next evaluation

Gaussian process

Spend the next experiment wisely

acquisition(x) = μ(x) + κσ(x)
suggested next x−1search space+1
surrogate meancredible regionacquisition maximum
One pattern, four uses

Bayes updates a parameter belief. Naive Bayes updates a predictive classifier. Thompson sampling samples posteriors to choose discrete actions. Bayesian optimization searches a continuous domain through a surrogate posterior.

Continue the learning path

From probabilistic models to neural networks.

Objective functions turn likelihood assumptions into trainable losses; activation functions shape how gradients and representations move through a network.

Open deep learning