AI Course · Week 14

Probabilistic Reasoning

The real world is uncertain, so AI must reason with probability. Bayes' theorem and Bayesian networks let a machine update its beliefs as evidence arrives.

By Arj Uncertainty Est. reading time: 16 minutes

The ontologies of last week dealt in certainties: a dog definitely is a mammal. But most of the real world is uncertain. Will it rain? Does this patient have the disease? Is this email spam? An intelligent agent cannot wait for certainty; it must weigh the odds and act. Probabilistic reasoning is how AI handles uncertainty, and at its centre is one of the most useful and most misunderstood ideas in all of science: Bayes' theorem. This page builds it up, and then hands you a calculator that reveals a result almost nobody guesses correctly.

1

Reasoning under uncertainty

Classic logic deals in true and false. But an agent in the real world rarely has that luxury. Sensors are noisy, the future is unknown, and evidence is incomplete. Rather than pretend to be certain, a rational agent represents its uncertainty with probability: a number from 0 (impossible) to 1 (certain) for how likely something is.

Probability lets an agent do something logic cannot: update its beliefs as evidence arrives. Before a test, you have some belief a patient is ill. After a positive result, that belief should change, but by exactly how much? Getting that update right is the whole game, and it is where human intuition famously fails.

Belief as a number
Treating belief as a probability turns vague hunches into something a machine can calculate with. The rules of probability then tell the agent precisely how much a new piece of evidence should shift its confidence.
2

Conditional probability

The key concept is conditional probability: the probability of one thing given that we know another. It is written P(A | B), read "the probability of A given B".

  • P(rain) is the plain chance of rain.
  • P(rain | dark clouds) is the chance of rain given that we can see dark clouds, which is higher.

Evidence changes probabilities, and conditional probability is how we express that. The crucial and slippery point is that the order matters: P(A | B) is generally not the same as P(B | A). The probability of a positive test given disease is not the probability of disease given a positive test. Confusing those two is the single most common mistake in reasoning about evidence, and Bayes' theorem is the tool that correctly connects them.

The flipping trap
"Ninety-nine percent of sick people test positive" does not mean "ninety-nine percent of people who test positive are sick". Those are two different conditional probabilities, and mixing them up leads to badly wrong conclusions, as the calculator below will show.
3

Bayes' theorem

Bayes' theorem is the rule for flipping a conditional probability, for turning "the chance of the evidence given the cause" into "the chance of the cause given the evidence", which is usually what we actually want to know.

P(B | A) * P(A) P(A | B) = ------------------- P(B) P(A) the prior: belief in A before the evidence P(B | A) the likelihood: chance of the evidence if A is true P(A | B) the posterior: updated belief in A after seeing B

Read it as a story of updating. You start with a prior belief. Evidence arrives. Bayes' theorem multiplies your prior by how well A explains the evidence (the likelihood) and rescales, giving your new, updated posterior belief. It is the mathematically correct way to change your mind, and it is used everywhere from spam filters to medical diagnosis to robot navigation.

The one-line meaning
New belief equals old belief adjusted by how well the hypothesis explains the new evidence. Bayes' theorem is just the precise formula for common-sense updating.
4

The test that fools everyone

Here is the famous example. A disease affects 1 percent of people. A test correctly flags 99 percent of sick people, and wrongly flags only 5 percent of healthy people. You test positive. What is the chance you are actually sick? Most people, including many doctors, say around 95 percent. The real answer is far lower. Move the sliders and see for yourself.

Interactive Bayes calculator: a medical test

Set the numbers, and the bars show, out of 10,000 people, who tests positive and who is truly sick.

1.0%
99%
5.0%
P(sick | positive test)
0%
of people who test positive are actually sick
With the default numbers, a positive test means only about a 1-in-6 chance of being sick. The reason: the disease is so rare that false alarms from the huge healthy majority outnumber the true positives. That is Bayes' theorem, and it is why a single test is rarely the whole story.
5

Bayesian networks

Real problems involve many uncertain variables that influence each other. A Bayesian network is a graph that captures these relationships compactly: each node is a variable, and an arrow from one node to another means the first directly influences the second.

The classic example: Rain makes the Grass wet, but so does the Sprinkler. Each node carries a small table (a conditional probability table) giving its probability for each combination of its parents' values. From this compact structure, the network can answer questions like "given the grass is wet, how likely is it that it rained?" by propagating probabilities through the graph.

  • Nodes are random variables (Rain, Sprinkler, Wet grass).
  • Arrows show direct influence (Rain points to Wet grass).
  • Conditional probability tables quantify each influence.
Why the structure helps
Writing out the probability of every combination of variables directly would be impossibly large. A Bayesian network exploits the fact that most variables only depend on a few others, shrinking the problem to something a machine can actually compute with.
6

Naive Bayes and beyond

One of the simplest and most successful uses of Bayes' theorem is the Naive Bayes classifier. To decide whether an email is spam, it uses Bayes' theorem to compute the probability of spam given the words in the email. The "naive" part is a simplifying assumption that all the words are independent of each other, which is not really true but works remarkably well in practice, and made early spam filters possible.

Probabilistic reasoning runs quietly through modern AI: in speech recognition weighing likely word sequences, in robot localisation tracking where a robot probably is, in recommendation and diagnosis, and in the uncertainty estimates that make systems trustworthy. Wherever an agent must act without certainty, it reasons with probability.

Where the course has taken you
You started with search in a certain world and end with reasoning in an uncertain one. Together, search, optimisation, learning, knowledge, and probability are the core ideas that let machines act intelligently. Every modern AI system, including the large language models everyone is talking about, is built from these foundations.
7

Key points and practice

  • AI handles uncertainty with probability, updating beliefs as evidence arrives.
  • Conditional probability P(A | B) is the chance of A given B; order matters, P(A | B) is not P(B | A).
  • Bayes' theorem flips a conditional using the prior, likelihood, and evidence to give the posterior.
  • With a rare condition, a positive test can still mean a low chance of having it, because false alarms dominate.
  • A Bayesian network is a graph of variables and influences with conditional probability tables.
  • Naive Bayes classifies (for example, spam) by assuming features are independent.
4 marks
Q1. State Bayes' theorem and explain what the prior, likelihood, and posterior mean.
Model answer

Bayes' theorem states that P(A | B) = P(B | A) * P(A) / P(B). The prior P(A) is the belief in hypothesis A before seeing the evidence. The likelihood P(B | A) is how probable the evidence B is if A is true. The posterior P(A | B) is the updated belief in A after observing B. The theorem combines the prior belief with how well the hypothesis explains the new evidence to produce the revised belief.

4 marks
Q2. A disease affects 1 percent of people. A test detects 99 percent of sick people but also gives a positive result for 5 percent of healthy people. Explain why a positive test does not mean a 99 percent chance of being sick.
Model answer

Because the disease is rare, most people are healthy, so even a small false positive rate produces many false alarms. Out of 10,000 people, about 100 are sick and roughly 99 of them test positive, but of the 9,900 healthy people about 5 percent, nearly 495, also test positive. So around 594 test positive in total, of whom only about 99 are truly sick, giving a probability of being sick of roughly 99 / 594, about 17 percent. The 99 percent figure is the probability of testing positive given illness, not the probability of illness given a positive test.

3 marks
Q3. What is a Bayesian network, and what do its nodes and arrows represent?
Model answer

A Bayesian network is a graphical model that represents a set of uncertain variables and the influences between them. Each node is a random variable, and an arrow from one node to another indicates that the first variable directly influences the second. Each node also has a conditional probability table giving its probability for each combination of its parents' values, and together these let the network compute the probability of any variable given evidence about others.

That is the whole course
You have gone from search to learning to uncertainty. To go further, into how transformers and generative AI actually work and how to build with them, our deep-dive handbook is the next step.
Explore the handbook
Scroll to Top