Bayesian Network
A Bayesian network models variables and their conditional dependencies as a directed acyclic graph, so evidence can update probabilities of causes.
A Bayesian network, also called a belief network, is a probabilistic graphical model that represents a set of random variables and their conditional dependencies with a directed acyclic graph (DAG). Each node is a variable, such as a disease, a symptom, or a sensor reading, and each arrow points from a direct influence to the variable it affects. Every node stores a conditional probability table giving its distribution for each combination of its parents' values, and together these tables define the full joint distribution of all the variables. Given evidence about some variables, the network computes updated probabilities for the rest, which makes it a tool for diagnosis, risk assessment, and decision support under uncertainty. Judea Pearl developed much of the theory in the 1980s, and his work on probabilistic and causal reasoning earned him the 2011 Turing Award.
Structure and Conditional Probability Tables#
The graph encodes conditional independence: each variable is independent of the variables that are not its descendants once its parents are known. This lets the joint distribution factor into small local pieces, P(X1, ..., Xn) = P(X1 | parents(X1)) × ... × P(Xn | parents(Xn)). The classic burglary-alarm network from Pearl's work, used throughout Russell and Norvig's textbook Artificial Intelligence: A Modern Approach, has five yes-or-no variables. A burglary or an earthquake can set off a home alarm, and the alarm prompts two neighbors, John and Mary, to call the owner.
A full joint table over five binary variables needs 31 independent probabilities. The network needs 10: one each for burglary and earthquake, four for the alarm given each combination of its two parents, and two for each neighbor given the alarm. The savings grow quickly with more variables, because the size of each table depends only on how many parents its node has.
Inference: Updating Beliefs from Evidence#
Inference fixes the observed variables and computes the posterior distribution of a query variable by applying Bayes' theorem across the graph. It runs in any direction: from causes to effects (prediction), from effects to causes (diagnosis), and between causes of a shared effect. That last pattern, called explaining away, means that once the alarm is known to have sounded, learning that an earthquake happened lowers the probability of a burglary. Exact inference by enumeration or variable elimination is tractable on small or tree-like networks, but it is NP-hard in general, so large networks use approximate methods such as likelihood weighting, Gibbs sampling, or loopy belief propagation.
This example answers the textbook query P(Burglary | John calls, Mary calls) by enumeration, summing the factored joint over the unobserved earthquake and alarm variables:
from itertools import product
# Conditional probability tables of the burglary-alarm network
p_burglary, p_earthquake = 0.001, 0.002
p_alarm = {(True, True): 0.95, (True, False): 0.94, (False, True): 0.29, (False, False): 0.001}
p_john = {True: 0.90, False: 0.05} # P(John calls | alarm)
p_mary = {True: 0.70, False: 0.01} # P(Mary calls | alarm)
def bern(p, value):
"""Return the probability of a binary outcome with success probability p."""
return p if value else 1 - p
# Evidence: both neighbors called. Sum the factored joint over the hidden variables.
joint = {True: 0.0, False: 0.0}
for b, e, a in product([True, False], repeat=3):
joint[b] += bern(p_burglary, b) * bern(p_earthquake, e) * bern(p_alarm[b, e], a) * p_john[a] * p_mary[a]
print(f"P(burglary | John and Mary call) = {joint[True] / sum(joint.values()):.3f}")The script prints 0.284, the same answer the textbook gives. Two calls raise the probability of a burglary from 1 in 1,000 to about 28%, and the other 72% goes to explanations without a burglary, such as an alarm triggered by an earthquake or by a fault, because burglaries are so rare.
Learning Bayesian Networks from Data#
A network can be built by hand from expert knowledge, learned from data, or both. Parameter learning fills the conditional probability tables from observed frequencies, with priors to smooth rare combinations and the expectation-maximization algorithm when some values are missing. Structure learning searches for the graph itself, either by scoring candidate graphs with a criterion such as the Bayesian information criterion or by running conditional independence tests, as the PC algorithm does. Learned arrows show statistical dependence, and reading them as causes takes the extra assumptions studied in causal discovery. Python libraries such as pgmpy implement both kinds of learning along with exact and approximate inference.
Real-World Applications#
- Medical diagnosis: Networks link diseases to the symptoms and test results they cause, so a clinician's observations update the probability of each condition, and every conclusion can be traced through the graph, a form of explainable AI.
- Fault diagnosis: Industrial and IT systems model how component failures propagate to alarms and readings. In visual inspection, defect classes found by a YOLO26 detector can enter the network as observed evidence that updates the probability of each upstream root cause, such as a worn tool or a miscalibrated machine.
- Risk assessment: Ecologists, insurers, and safety engineers combine sparse data with expert judgment in networks that estimate the likelihood of rare events.
Bayesian Networks vs. Related Models#
- Naive Bayes: A Bayesian network with one class node as the only parent of every feature, which assumes the features are independent given the class.
- Markov random fields: Graphical models with undirected edges, suited to symmetric relationships such as neighboring pixels in an image.
- Markov decision processes: Models of sequential decisions, with actions that change the state and rewards to maximize, and the standard framework of reinforcement learning. A Bayesian network gains decisions and payoffs only when extended with decision and utility nodes into an influence diagram.
- Hidden Markov models: A dynamic Bayesian network, one that repeats the same structure at every time step, with a hidden state that emits one observation per step. Kalman filters have the same structure with continuous states and linear-Gaussian transitions and observations.










