6 Probabilistic Graphical Models
A joint distribution over binary variables requires free parameters, a number that grows astronomically with . For just 30 variables this is already over a billion. Clearly, writing down or learning such a table is hopeless without further structure.
Probabilistic graphical models (PGMs) solve this problem by encoding conditional independence assumptions in the language of graphs. Every node is a random variable; edges (or their absence) declare which variables directly influence one another. The graph structure implies a factorisation of the joint distribution into a product of small, local terms, each involving only a variable and its immediate neighbours.
Key Idea.
A graphical model uses a graph to compactly represent a high-dimensional joint distribution.
Nodes = random variables.
Edges = direct statistical dependencies.
Missing edges = conditional independences that enable factorisation.
The graph is not merely a visualisation aid: it is a precise mathematical object that determines which factorisations are valid and which inference algorithms are tractable.
Why should we care about PGMs in a book on generative modelling? Because every major generative model family can be expressed as a graphical model:
VAEs are directed latent-variable models (section PGMs as the Language of Generative Models).
Autoregressive models are Bayesian networks with a chain factorisation.
Diffusion models are hierarchical directed models with a fixed forward process.
Energy-based models are undirected graphical models.
Understanding PGMs gives us a unified language for reasoning about the structure, training, and inference of all these models.
Historical Note.
The idea of using graphs to represent statistical relationships dates back to the geneticist Sewall Wright, who introduced path diagrams in 1921 to study causal relationships in genetics [1]. The modern theory of Bayesian networks was developed by Judea Pearl in the 1980s [2], culminating in his 2011 Turing Award “for fundamental contributions to artificial intelligence through the development of a calculus for probabilistic and causal reasoning.” The parallel theory of undirected models traces to statistical physics (the Ising model, 1925) and was formalised in statistics by Hammersley and Clifford in 1971 [3]. The comprehensive treatment by Koller and Friedman [4] unified both traditions.
Directed Graphical Models: Bayesian Networks
A Bayesian network1 is a directed acyclic graph (DAG) in which each node has a conditional probability distribution (CPD) given its parents.
Definition 1 (Bayesian Network).
A Bayesian network is a pair where:
is a directed acyclic graph (DAG) with nodes .
is a collection of conditional distributions, one per node, where denotes the parents of in .
The joint distribution factorises as (Factorisation)
Example 1 (A Simple Weather Chain).
Consider three binary variables: (cloudy), (rain), (wet grass), with the DAG . The joint factorises as A full joint table for three binary variables needs parameters. The factorised model needs only parameters (one for , two for , two for ). The saving grows dramatically with the number of variables.
Example 2 (Parameter Savings at Scale).
Suppose we have a chain of binary variables: . The full joint needs parameters. The Bayesian network factorisation gives parameters, an exponential-to-linear reduction. For , this is versus .
A Larger Example: Medical Diagnosis
Consider a medical diagnosis scenario with five variables: Smoking (), Pollution (), Cancer (), X-ray (), and Breathing difficulty ().
The factorisation implied by Figure fig:medical:bn is: (Factor)
Example 3 (Counting Parameters).
If all five variables are binary, the full joint needs free parameters. The Bayesian network needs: This is a reduction for just 5 variables; the savings grow exponentially with the number of variables.
Plate Notation
When a graphical model contains repeated structure ( data points drawn independently from the same model) drawing copies of the subgraph is impractical. Plate notation uses a rectangle (“plate”) to indicate replication.
Remark 1 (Reading Plate Diagrams).
Shaded nodes are observed; unshaded are latent.
Nodes outside a plate are shared across all copies.
Nodes inside a plate are replicated.
Arrows crossing a plate boundary mean every copy of the inner node receives the same parent.
The plate diagram in Figure fig:plate:gmm encodes: .
Conditional Independence and d-Separation
The power of a graphical model lies not just in the factorisation it implies, but in the conditional independence (CI) statements we can read directly from the graph. The criterion for reading CI from a DAG is called d-separation.
Three Canonical Structures
Every path in a DAG is built from three atomic motifs. Understanding these three cases is the key to understanding d-separation.
Definition 2 (The Three Canonical Structures).
Let , , be three nodes connected by a path in a DAG.
Chain: . Conditioning on blocks the flow of information from to : .
Fork: (equivalently and ). is a common cause. Conditioning on blocks the path: .
Collider (v-structure): . The path is blocked by default: . Conditioning on (or any descendant of ) opens the path: .
Example 4 (Explaining Away).
Suppose = “earthquake” and = “burglar alarm malfunction”, both of which can cause = “alarm sounds”. Marginally, and are independent (earthquakes have nothing to do with alarm malfunctions). But if you observe that the alarm sounded (), learning that an earthquake occurred () makes a malfunction () less likely, since the earthquake already “explains away” the alarm. This is the collider effect: conditioning on induces a dependence between its parents.
The d-Separation Criterion
Definition 3 (d-Separation).
Let be a DAG and let , , be disjoint sets of nodes. A path between a node in and a node in is blocked by if it contains a node such that either:
and is not a collider on the path (chain or fork), or
is a collider on the path and neither nor any descendant of is in .
and are d-separated given , written , if every path between and is blocked by .
Theorem 1 (Soundness and Completeness of d-Separation).
Let be a distribution that factorises according to DAG . Then for all disjoint sets , , : Moreover, if is a faithful distribution for (i.e. the only CIs in are those implied by ), then the converse also holds.
Example 5 (Applying d-Separation).
In the medical diagnosis network (Figure fig:medical:bn):
Is ? Yes, there is no path between and that does not go through collider , so the path is blocked. Smoking and pollution are a priori independent.
Is ? No, is a collider between and , and conditioning on it opens the path. If you know someone has cancer, learning they smoke makes pollution a less likely cause (explaining away).
Is ? Yes, both paths from to go through , and conditioning on blocks the chains . Once we know the cancer status, the X-ray result tells us nothing extra about breathing difficulty.
Markov Blanket
Definition 4 (Markov Blanket).
The Markov blanket of a node in a Bayesian network is the set: where are the children of and are the other parents of 's children.
Proposition 1 (Markov Blanket Property).
A node is conditionally independent of all other variables in the network given its Markov blanket:
Proof.
By the factorisation , depends only on the factors that involve : its own CPD and the CPDs of its children for . These factors involve exactly the parents, children, and co-parents of .
Insight.
The Markov blanket defines the minimal sufficient context for a variable; everything outside the blanket is irrelevant once the blanket is known. In Gibbs sampling (Chapter 6), we sample each variable from its conditional given its Markov blanket, which is efficient because the blanket is typically small relative to the full network.
Undirected Graphical Models: Markov Random Fields
Not all dependencies are naturally directional. In an image, nearby pixels influence each other symmetrically. In a protein, amino acids interact via symmetric physical forces. Undirected graphical models capture such symmetric relationships.
Definition 5 (Markov Random Field).
A Markov random field (MRF), also called an undirected graphical model, consists of an undirected graph and a set of non-negative potential functions , one per maximal clique of . The joint distribution is (MRF) where is the partition function ensuring normalisation, and denotes the variables in clique .
Remark 2 (Potentials Are Not Probabilities).
Unlike CPDs in Bayesian networks, potential functions are not probability distributions; they are arbitrary non-negative functions. This extra flexibility comes at a cost: computing the partition function is generally intractable (it sums over all configurations).
Example 6 (The Ising Model).
The Ising model, introduced by physicist Ernst Ising in 1925 [5], is perhaps the most famous MRF. Each node on a lattice takes a spin , and neighbouring spins prefer to align: (Ising) where controls the coupling strength and is an external field. The pairwise potential is , which is large when (spins aligned) and small when .
At high temperature () the spins are nearly independent; at low temperature () they strongly align. The transition between these regimes is a phase transition, a phenomenon of deep importance in both physics and generative modelling (where it manifests as “mode collapse” or sharp transitions in sample quality).
The Hammersley–Clifford Theorem
The following theorem provides the theoretical foundation for MRFs, establishing the equivalence between the graph structure and the factorisation.
Theorem 2 (Hammersley–Clifford).
Remark 3 (Energy-Based Interpretation).
Writing , the MRF becomes a Gibbs distribution with energy . Low-energy configurations have high probability. This is exactly the framework of energy-based models (EBMs), a family of generative models where a neural network parameterises the energy function .
Directed vs. Undirected Models
| Property | Bayesian Network (Directed) | MRF (Undirected) |
| Edge meaning | Causal / generative direction | Symmetric association |
| Factorisation | ||
| Normalisation | Automatic (CPDs normalise) | Requires partition function |
| CI criterion | d-separation | Graph separation |
| Typical use | Causal modelling, VAEs, autoregressive | Physics, images, EBMs |
Factor Graphs
Both directed and undirected models can be represented in a unified framework called a factor graph.
Definition 6 (Factor Graph).
A factor graph is a bipartite graph with:
Variable nodes (drawn as circles).
Factor nodes (drawn as small squares).
An edge between and iff appears in factor .
The joint distribution is (Graph) where is the set of variable nodes neighbouring factor .
Example 7 (Converting a Bayesian Network to a Factor Graph).
Given the medical diagnosis Bayesian network , we create one factor node for each CPD: , , , , . Each factor connects to its argument variables. The partition function since the factors are proper conditional distributions.
Insight.
Factor graphs are the natural framework for message-passing algorithms. On a tree-structured factor graph, the sum-product algorithm (belief propagation) computes exact marginals in time linear in the number of nodes. This is the algorithmic engine behind many inference procedures in generative models.
Inference in Graphical Models
Given a graphical model, inference means computing quantities of interest from the joint distribution, typically marginal probabilities or the most likely configuration.
Definition 7 (Marginal and MAP Inference).
Given a joint and a partition of variables into query and evidence :
Marginal inference: compute , where are the remaining (hidden) variables.
MAP inference: find .
Variable Elimination
The brute-force approach sums over all configurations, exponential in the number of variables. Variable elimination exploits the factorisation to sum out variables one at a time, dramatically reducing the cost.
Algorithm 1 (Variable Elimination).
Input: Factors , query variable , elimination ordering . Output: Marginal (unnormalised).
for each variable in the elimination ordering:
Collect all factors that mention .
Compute the product .
Replace by the new factor in the factor set.
return the product of all remaining factors (which involve only ).
Example 8 (Variable Elimination Walkthrough).
Consider the chain with . To compute , we eliminate , , in order: Each step sums over one variable in a small factor, avoiding exponential blowup. If each variable takes values, the cost is instead of .
Caution.
The cost of variable elimination depends critically on the elimination ordering. A bad ordering can create intermediate factors that are exponentially large. Finding the optimal ordering is NP-hard in general. In practice, heuristics like minimum degree or minimum fill work well for sparse graphs.
Belief Propagation
On tree-structured graphs, variable elimination can be organised as a message-passing algorithm: each node sends a “message,” a function summarising its local information, to its neighbours.
Definition 8 (Sum-Product Messages on a Factor Tree).
On a factor graph that is a tree, the message from variable node to factor node is: (Factor) and the message from factor to variable is: (VAR) The marginal of is proportional to the product of all incoming messages: .
Theorem 3 (Exactness on Trees).
On a tree-structured factor graph, belief propagation computes exact marginals for every variable in time, where is the number of variables, is the domain size, and is the maximum factor size.
Remark 4 (Loopy Belief Propagation).
On graphs with cycles, belief propagation can still be run by iterating messages until convergence, a heuristic known as loopy belief propagation. It has no convergence guarantees in general, but works surprisingly well in practice and forms the basis of algorithms for error-correcting codes (turbo codes, LDPC codes) and computer vision [6].
When Exact Inference Is Intractable
Key Idea.
For general graphs, exact inference is NP-hard. This fundamental intractability is what motivates the two major families of approximate inference:
Variational inference: approximate the posterior with a tractable family, optimising a bound (Chapter 8).
Sampling methods (MCMC): draw correlated samples from the posterior, with convergence guarantees in the limit.
Understanding why exact inference is hard provides the motivation for the variational methods that power modern generative models like VAEs.
Learning in Graphical Models
Learning a graphical model from data involves estimating the parameters (and potentially the structure ) given a dataset .
Maximum Likelihood with Complete Data
When all variables are observed (“complete data”), MLE in a Bayesian network decomposes into independent subproblems.
Proposition 2 (MLE Decomposes over CPDs).
For a Bayesian network with complete data, the log-likelihood is which decomposes into independent terms, one per node. Each CPD can be estimated separately.
Example 9 (MLE for a Discrete CPD).
In the medical diagnosis network, suppose we observe data points and want to estimate for each configuration of parents. The MLE is simply the empirical frequency: This is just counting, no optimisation needed!
Learning with Latent Variables: The EM Algorithm
When some variables are latent (unobserved), the log-likelihood no longer decomposes, and MLE becomes much harder.
Definition 9 (The EM Algorithm).
Given observed data and latent variables , the Expectation-Maximisation (EM) algorithm iterates:
E-step: Compute the posterior over latent variables using current parameters:
M-step: Maximise the expected complete-data log-likelihood:
Proposition 3 (EM Monotonically Increases Likelihood).
Each iteration of EM is guaranteed to increase (or leave unchanged) the observed-data log-likelihood: .
Proof sketch.
By Jensen's inequality, the E-step constructs a lower bound on that is tight at . The M-step maximises this bound, which can only increase the objective. See Chapter 8 for the detailed connection to variational inference.
Insight.
The EM algorithm is the bridge between graphical models and generative modelling:
For Gaussian mixture models (Chapter 7), EM alternates between computing cluster responsibilities (E-step) and updating means/covariances (M-step).
For VAEs, the E-step is intractable, so we replace it with an amortised encoder , the “variational” in VAE.
For diffusion models, the forward process defines the latent structure, and training optimises a variational bound similar to the EM objective.
PGMs as the Language of Generative Models
Every generative model we will study in this book has a natural PGM representation. Recognising this structure helps us understand what independence assumptions each model makes, what inference challenges it faces, and why particular training objectives are used.
| Model Family | Graph Type | Key Challenge | Solution Strategy |
| Autoregressive | Directed (chain) | Sequential generation | Parallel training, caching |
| VAE | Directed (latent) | Intractable posterior | Amortised variational inference |
| GAN | Implicit (no explicit ) | Adversarial training | Discriminator as density ratio |
| Normalising Flow | Directed (bijective) | Jacobian cost | Triangular / coupling layers |
| Diffusion | Directed (Markov chain) | Long chain | Score matching, DDPM bound |
| Energy-Based | Undirected | Partition function | Contrastive divergence, score matching |
Remark 5 (The Implicit Model Exception).
GANs are sometimes called implicit generative models because they define a sampling procedure without specifying explicitly. They do not naturally fit the PGM framework, since there is no tractable density. This is both a strength (no normalisation constant) and a weakness (no likelihood for evaluation).
Independence Maps and Perfect Maps
A natural question arises: can we always find a graph that exactly captures all the conditional independences in a given distribution?
Definition 10 (I-map, D-map, Perfect Map).
Let be a distribution and a graph.
is an independence map (I-map) for if every CI implied by holds in . (The graph may “miss” some independences.)
is a dependence map (D-map) for if every CI in is captured by . (The graph may assert too many independences.)
is a perfect map for if it is both an I-map and a D-map, meaning the graph captures exactly the CIs in .
Example 10 (No Perfect Directed Map).
Consider four binary variables with the CI structure: and , but no other CIs. It can be shown that no DAG is a perfect map for this distribution, but an undirected graph (a 4-cycle ) is. This illustrates why we need both directed and undirected models.
Caution.
The existence of a perfect map is a strong assumption. In practice, we choose a graph family (directed or undirected) that captures the most important dependencies, accepting that some independences may be missed or incorrectly asserted. The choice of graph family is a modelling decision with practical consequences for inference and learning.
Chapter Summary
This chapter introduced the language of probabilistic graphical models, the formal backbone of generative modelling.
Bayesian networks (directed models) represent joint distributions via CPDs and DAGs; d-separation reads off conditional independences.
Markov random fields (undirected models) use clique potentials and partition functions; the Hammersley–Clifford theorem connects graph structure to factorisation.
Factor graphs unify both representations and enable message-passing inference.
Inference (variable elimination, belief propagation) is exact on trees but NP-hard in general, motivating the variational methods of Chapter 8.
Learning with complete data is straightforward (MLE decomposes); with latent variables, EM provides an iterative solution.
Every major generative model family has a natural PGM interpretation, making graphical models the lingua franca of the field.
In the next chapter, we study Gaussian mixture models, the simplest and most instructive latent-variable model, where the EM algorithm can be derived in closed form.
Exercises
Exercise 1 (Factorisation and Parameter Counting).
Consider a DAG with four binary random variables , , , and edges , , , .
- (a)
Write down the factorisation of .
- (b)
How many free parameters does this model need?
- (c)
Compare to the parameters for the full joint.
Exercise 2 (Collider and Explaining Away).
Let , , be random variables in a DAG with edges and (a v-structure).
- (a)
Show that marginally.
- (b)
Show that .
- (c)
Explain intuitively why observing creates a dependence (the “explaining away” effect).
Exercise 3 (d-Separation Practice).
Consider a DAG with nodes and edges , , , . Determine which hold:
- (a)
- (b)
- (c)
- (d)
- (e)
Justify each answer by identifying paths and their blocking status.
Exercise 4 (Markov Blanket Computation).
For the graph with edges , , , , :
- (a)
Prove that is conditionally independent of all other variables given its Markov blanket.
- (b)
Compute for every node .
Exercise 5 (Constructing a Medical Bayesian Network).
Variables: Smoking (), Pollution (), Cancer (), X-ray (), Breathing difficulty (). Domain knowledge:
and are independent risk factors.
depends on both and .
and each depend on .
- (a)
Draw the Bayesian network.
- (b)
Write the factorisation of the joint.
- (c)
Count parameters (binary variables) and compare to the full joint.
- (d)
Does hold? Interpret medically.
Exercise 6 (Hidden Markov Model).
An HMM has latent states and observations , where depends only on and depends only on .
- (a)
Draw the DAG and write the joint factorisation.
- (b)
Show that for .
- (c)
Show that marginally when .
- (d)
What is the Markov blanket of (for )?
Exercise 7 (GMM Plate Diagram).
A Gaussian mixture model has data points, components, mixing weights , means , and covariances .
- (a)
Draw the plate diagram.
- (b)
Identify observed, latent, and parameter nodes.
- (c)
Write the complete joint with appropriate priors.
Exercise 8 (Ising Model Computation).
Consider a Ising model (4 spins on a grid) with and .
- (a)
List all configurations and compute the unnormalised probability for each.
- (b)
Compute the partition function .
- (c)
What is the probability that all four spins are aligned ( or )?
- (d)
What is the marginal probability ?
Exercise 9 (Variable Elimination Ordering).
Consider a “diamond” DAG: , , , , all binary. You want to compute .
- (a)
Perform variable elimination with ordering . What is the size of the largest intermediate factor?
- (b)
Repeat with ordering .
- (c)
Which ordering is more efficient and why?
Exercise 10 (MRF Factorisation).
An undirected graph has nodes and edges , , , (a 4-cycle).
- (a)
List the maximal cliques.
- (b)
Write the MRF factorisation.
- (c)
What conditional independences does this graph encode?
- (d)
Can this CI structure be represented by any DAG? (Hint: see Example Example 10.)
Exercise 11 (EM for a Simple Latent Variable Model).
Consider a mixture of two coins: coin 1 has and coin 2 has , with mixing weight . You observe flips but don't know which coin was used for each flip.
- (a)
Write the complete-data log-likelihood .
- (b)
Derive the E-step: compute .
- (c)
Derive the M-step updates for , , .
- (d)
Implement EM and test on simulated data with , , , .
Exercise 12 (Belief Propagation on a Chain).
Consider a 3-node chain: with pairwise potentials and , and unary potentials for each node. All variables are binary.
- (a)
Write out the messages , , and the belief .
- (b)
Verify that (the true marginal).
- (c)
If and , compute and .
Exercise 13 (VAE as a Graphical Model).
A variational autoencoder has the generative model , .
- (a)
Draw the directed graphical model (with plate notation for data points).
- (b)
Why is the posterior intractable?
- (c)
The encoder is not part of the generative model. Where does it appear in the PGM, and what role does it play?
- (d)
Connect this to the EM algorithm: what plays the role of the E-step? The M-step?
Exercise 14 (Directed vs. Undirected Expressiveness).
- (a)
Give an example of a CI structure that can be represented by a DAG but not by any undirected graph. (Hint: consider a v-structure.)
- (b)
Give an example that can be represented by an undirected graph but not by any DAG. (Hint: consider a 4-cycle.)
- (c)
What does this tell us about the relative expressiveness of directed and undirected models?
Notes
- The name is historical; a Bayesian network does not require Bayesian (as opposed to frequentist) statistical methods.
References
-
Correlation and Causation
BibTeX
@article{wright1921correlation, title={Correlation and Causation}, author={Wright, Sewall}, journal={Journal of Agricultural Research}, volume={20}, number={7}, pages={557--585}, year={1921} }Journal article
-
Probabilistic Reasoning in Intelligent Systems: Networks of Plausible Inference
BibTeX
@book{pearl1988probabilistic, title={Probabilistic Reasoning in Intelligent Systems: Networks of Plausible Inference}, author={Pearl, Judea}, publisher={Morgan Kaufmann}, year={1988} }Book
-
Markov Fields on Finite Graphs and Lattices
BibTeX
@unpublished{hammersley1971markov, title={Markov Fields on Finite Graphs and Lattices}, author={Hammersley, John M and Clifford, Peter}, year={1971}, note={Unpublished manuscript} }Reference
-
Probabilistic Graphical Models: Principles and Techniques
BibTeX
@book{koller2009probabilistic, title={Probabilistic Graphical Models: Principles and Techniques}, author={Koller, Daphne and Friedman, Nir}, publisher={MIT Press}, address={Cambridge, MA}, year={2009} }Book
-
Beitrag zur Theorie des Ferromagnetismus
BibTeX
@article{ising1925beitrag, title={{Beitrag zur Theorie des Ferromagnetismus}}, author={Ising, Ernst}, journal={Zeitschrift f{\"u}r Physik}, volume={31}, number={1}, pages={253--258}, year={1925} }Journal article
-
Understanding Belief Propagation and Its Generalizations
BibTeX
@article{yedidia2003understanding, title={Understanding Belief Propagation and Its Generalizations}, author={Yedidia, Jonathan S and Freeman, William T and Weiss, Yair}, journal={Exploring Artificial Intelligence in the New Millennium}, volume={8}, pages={236--239}, year={2003} }Journal article