Skip to content
StackDecode
AI & ML Atlas
Artificial IntelligencealgorithmInteractive simulation

Bayesian Inference

Updates beliefs in light of evidence using Bayes' rule.

The idea

Start with a prior belief about a hypothesis, multiply by how likely the observed evidence would be if the hypothesis were true (the likelihood), and renormalise to get the posterior. Rare conditions stay unlikely even after a positive test, which is why the prior matters so much.

P(H | E) = P(E | H) · P(H) / P(E)

Watch it run

This is a real computation, not a drawing. Pause, step, change the settings, or try new random data.

01chance of heads →
  • belief about the bias
  • true bias

Before any evidence: a flat belief, "any bias from 0 to 1 is equally likely". The dashed green line is the true bias, hidden from us.

heads:
0
tails:
0
best guess:
0.5
1/15

The curve is the posterior: Beta(1 + heads, 1 + tails).

Step by step

  1. 1State the prior probability of each hypothesis.
  2. 2Observe the evidence.
  3. 3Multiply each prior by the likelihood of that evidence.
  4. 4Divide by the total so the numbers sum to 1.
  5. 5Use the posterior as the new prior when more evidence arrives.

Where it is used

Medical tests, spam filters, A/B testing, probabilistic programming.

Watch out for

A poor prior or a wrong likelihood model gives confidently wrong answers.

Related