I4 · Problem Solving and Reasoning: Classical AI

Probabilistic Reasoning

Probabilistic reasoning lets an agent draw conclusions when facts are uncertain, by representing beliefs as probabilities and updating them with evidence. A Bayesian network does this compactly: it is a directed graph whose nodes are random variables and whose arrows show direct influences, with a table at each node giving its probabilities for each combination of its parents' values. Inference computes the probability of unknown variables given observed ones.

12 min Intermediate · Sublevel Intermediate Jump to the activity

What you need: The earlier topics of this module.

Definition

Your burglar alarm rings. It might be a burglar, or it might be a small earthquake. Then your neighbour calls to say she heard it. How worried should you be? Logic cannot say; probability can.

Probabilistic reasoning lets an agent draw conclusions when facts are uncertain, by representing beliefs as probabilities and updating them with evidence. A Bayesian network does this compactly: it is a directed graph whose nodes are random variables and whose arrows show direct influences, with a table at each node giving its probabilities for each combination of its parents' values. Inference computes the probability of unknown variables given observed ones.

In simple words

Instead of "if alarm then burglar", you reason in chances: alarms usually mean burglars, but earthquakes can set them off too, and neighbours sometimes call for no reason. A Bayesian network is a map of what causes what, with a number on each link, so the computer can work out how likely a burglary really is.

Overview

  • Probabilistic reasoning lets an AI system draw conclusions when information is uncertain or incomplete.
  • Beliefs are probabilities, updated with evidence using Bayes' theorem.
  • Full joint distributions grow exponentially, so models exploit independence to stay small.
  • Bayesian networks, championed by Judea Pearl in the 1980s, made this practical.
  • Inference answers questions like "what is the probability of disease given these symptoms?".
  • Temporal models track beliefs that change over time, as in speech recognition and robot localisation.

Why it matters

Real knowledge is uncertain: symptoms do not prove a disease, sensors are noisy, and witnesses can be wrong. Probabilistic reasoning is how medical decision support, spam filters, robot localisation and fault diagnosis handle that uncertainty in a principled way.

Key terms

Random variable
A quantity whose value is uncertain, such as Burglary (true or false).
Bayesian network
A directed graph of variables with conditional probability tables showing how each depends on its parents.
Conditional probability table (CPT)
For each node, its probabilities given every combination of its parents' values.
Evidence
Variables whose values have been observed.
Conditional independence
Two variables become unrelated once a third is known, which keeps networks small.
Explaining away
When one cause is confirmed, the probability of other causes of the same effect drops.

Types

Probabilistic reasoning uses several types of model and inference. These are the main ones.

1. Bayesian networks

Directed acyclic graphs where each node is a variable with a table of probabilities given its parents.

  • How it works: The joint probability factorises as the product of each variable given its parents, so far fewer numbers are needed.
  • Example: A network linking Burglary and Earthquake to Alarm, and Alarm to calls from two neighbours.
  • When to use it: Use them for diagnosis, risk assessment and any domain with known cause-and-effect structure.

2. Exact inference

Computing posterior probabilities precisely, by enumeration or variable elimination.

  • How it works: Enumeration sums over all hidden variables; variable elimination reorders the sums and caches intermediate results to save work.
  • Example: Computing P(burglary | both neighbours called) ≈ 0.28 in the classic alarm network.
  • When to use it: Use it for small or tree-shaped networks, where it is fast enough.

3. Approximate inference (sampling)

Estimating probabilities by generating many random samples from the model.

  • How it works: Rejection sampling, likelihood weighting and Markov chain Monte Carlo (such as Gibbs sampling) give answers that improve with more samples.
  • Example: Estimating disease probabilities in a large medical network by simulating 100,000 patients.
  • When to use it: Use it for large networks where exact inference is too slow.

4. Hidden Markov models and temporal models

Models of a hidden state that changes over time and produces observations.

  • How it works: Filtering estimates the current state, smoothing past states and the Viterbi algorithm the most likely sequence of hidden states.
  • Example: Inferring whether it is raining outside from whether people bring umbrellas each day; older speech recognisers used HMMs.
  • When to use it: Use them for sequences such as speech, gestures, weather states and part-of-speech tagging.

5. Kalman and particle filters

Algorithms that track continuous hidden quantities, such as position, from noisy measurements.

  • How it works: The Kalman filter assumes linear dynamics and normal noise; particle filters represent beliefs with many weighted samples and handle non-linear cases.
  • Example: GPS navigation smoothing jumpy position readings; Apollo spacecraft navigation used Kalman filters.
  • When to use it: Use them for tracking, navigation and sensor fusion in robots, vehicles and phones.

Explained in detail

The alarm network

Judea Pearl's classic example has five variables: Burglary and Earthquake both influence Alarm, and Alarm influences whether neighbours John and Mary call. Arrows go from causes to effects. Each node has a small table: the chance of a burglary on a given day might be 0.001; of an earthquake 0.002; the alarm rings with probability 0.95 if both happen, 0.94 if only a burglary, 0.29 if only an earthquake and 0.001 if neither. Writing out every combination of five variables would need 31 numbers; the network needs only 10, because each variable depends directly on just a few others. Pearl's work on Bayesian networks in the 1980s earned him the Turing Award in 2011.

Reasoning in different directions

TypeQuestionDirection
DiagnosticJohn called; how likely is a burglary?From effect to cause
PredictiveThere was a burglary; how likely is it that Mary calls?From cause to effect
Intercausal (explaining away)The alarm rang and an earthquake is confirmed; how likely is a burglary now?Between causes of a shared effect

Explaining away is a pattern people use naturally but simple rule systems cannot. If the alarm rang, a burglary becomes more likely. If you then learn there was an earthquake, the burglary becomes less likely again, because the earthquake already explains the alarm. Bayesian networks capture this automatically through the laws of probability.

Where probabilistic reasoning is used

  • Medical decision support: networks linking diseases, risk factors, symptoms and test results.
  • Fault diagnosis: telling which component most likely failed in a printer, power grid or aircraft from observed symptoms.
  • Robot localisation: combining noisy sensor readings and motion over time to estimate where a robot is.
  • Speech recognition and language: hidden Markov models, a special kind of network, were the standard before neural networks.
  • Exact inference can be slow in large networks, so systems often use approximate methods such as sampling.

The numbers in the example below show how dramatic these updates can be. Before any evidence, a burglary has a one-in-a-thousand chance. After the alarm rings, it rises to well over a third, because the alarm almost never rings without a cause. Learning that an earthquake happened then pulls it back down to a fraction of one per cent. Networks also make it easy to ask "what if" questions and to see which piece of evidence matters most, which is valuable when a doctor or engineer must decide what to check next.

How it works

  1. Identify the variables, including causes, effects and observations.
  2. Draw arrows from each cause to its direct effects.
  3. Fill in each node's table from data or expert estimates.
  4. Enter the evidence you observe.
  5. Compute the probabilities of the variables you care about, exactly or by sampling.

In code

bayes_net.py
from itertools import product

P_B, P_E = 0.001, 0.002
P_A = {(True, True): 0.95, (True, False): 0.94, (False, True): 0.29, (False, False): 0.001}
P_J = {True: 0.90, False: 0.05}  # John calls given alarm
P_M = {True: 0.70, False: 0.01}  # Mary calls given alarm

def joint(b, e, a, j, m):
    p = (P_B if b else 1 - P_B) * (P_E if e else 1 - P_E)
    p *= P_A[(b, e)] if a else 1 - P_A[(b, e)]
    p *= P_J[a] if j else 1 - P_J[a]
    p *= P_M[a] if m else 1 - P_M[a]
    return p

def prob_burglary(**evidence):
    num = den = 0.0
    for b, e, a, j, m in product([True, False], repeat=5):
        world = dict(b=b, e=e, a=a, j=j, m=m)
        if any(world[k] != v for k, v in evidence.items()):
            continue
        p = joint(b, e, a, j, m)
        den += p
        num += p if b else 0
    return num / den

print(f"Prior P(burglary):                    {P_B:.4f}")
print(f"After John and Mary both call:         {prob_burglary(j=True, m=True):.4f}")
print(f"After the alarm rings:                 {prob_burglary(a=True):.4f}")
print(f"Alarm rings and earthquake confirmed:  {prob_burglary(a=True, e=True):.4f}  (explaining away)")

Output

Prior P(burglary):                    0.0010
After John and Mary both call:         0.2842
After the alarm rings:                 0.3736
Alarm rings and earthquake confirmed:  0.0033  (explaining away)

Try it yourself

The alarm and the earthquake

Ravi is at work when his phone shows a home-alarm alert.

Which kind of reasoning?

Classify each question about the alarm network.

  • John called. How likely is a burglary?

  • The alarm rang and an earthquake happened. How likely is a burglary?

  • There is an earthquake. Will Mary call?

  • A patient has a cough. How likely is pneumonia?

Common mistakes

  • Treating an effect as proof of a cause, ignoring other causes and base rates.
  • Drawing arrows from effects to causes, making the network bigger and harder to check.
  • Filling tables with guesses and never checking them against data.

Check yourself

Question 1

1. What does an arrow in a Bayesian network show?

Question 2

2. The alarm rang and an earthquake is confirmed. The probability of a burglary…

Question 3

3. Why are Bayesian networks compact?

Summary

  • Probabilistic reasoning handles uncertainty by representing and updating beliefs as probabilities.
  • Bayesian networks represent causes and effects compactly with conditional probability tables.
  • They support diagnostic, predictive and explaining-away reasoning, in medicine, diagnosis and robotics.

Read it. Now try it yourself.

Open the interactive activity

Finished reading?

Sources: Russell and Norvig, Artificial Intelligence: A Modern Approach (4th edition) · ACM Turing Award: Judea Pearl (2011)