Probabilistic graphical models

A probabilistic graphical model (PGM) is a graph that represents a joint distribution p(x). The graph shows how the joint distribution factorizes and, equivalently, also shows the (conditional) independence relations between the variables. There are two main flavours of PGMs.

Directed PGMs (Bayesian networks)

A directed PGM uses a directed acyclic graph (DAG) to represent distributions. Each node is a variable. The joint distribution is the product of the conditional distribution of each node, given its parents:

p(x)=∏ip(xi∣pai)

The d-separation rules give the conditional and unconditional independence relations in the graph. The Markov blanket of a node contains its parents, its children and, because of explaining away, its co-parents.

PGM - directed example.png300
Example DAG: p(x)=p(x1)p(x2)p(x3∣x1,x2)p(x4∣x3)p(x5∣x2). x1 and x2 are co-parents of x3, so observing x3 couples them (explaining away).

PGM - d-separation cases.png500
The three d-separation cases for a path between a and b through c (top: c unobserved; bottom: c observed, shaded). Tail-to-tail and head-to-tail paths are open when c is unobserved and blocked when c is observed. The head-to-head path is the reverse: it is blocked when c and all its descendants are unobserved, and observing c (or a descendant) opens it.

Undirected PGMs (Markov random fields / Markov networks)

An undirected PGM uses an undirected graph. In this case, the joint distribution is written as the product of potential functions on the (maximal) cliques C of the graph:

p(x)=1Z∏CψC(xC)

Z is the partition function. Simple graph separation shows the independence relations. Thus, the Markov blanket of a node contains only its neighbours. If all potentials are strictly positive, each potential is an exponential of a negative energy function E:

ψC(xC)=exp⁡{−E(xC)}

The joint distribution is then a Gibbs-Boltzmann distribution. This is the form of energy-based models (EBMs).

PGM - undirected example.png300
Example MRF with maximal cliques {x1,x2,x3}, {x3,x4} and {x2,x5}: p(x)=1Zψ123(x1,x2,x3)ψ34(x3,x4)ψ25(x2,x5). This is the moral graph of the DAG above: linking the co-parents x1 and x2 and dropping the arrows.

Representational power

A PGM can show all the conditional independence relations of a distribution and no other relations. In this case, the PGM is said to be a perfect map of the distribution. Some distributions have a perfect map only as a directed graph and some have a perfect map only as an undirected graph. Some distributions have no perfect map of either type.

Also, a directed PGM and an undirected PGM can both represent the same distribution. Even then, the set of conditional independence relations that can be read out from each representation may be different. So these are incomplete representations of underlying distributions. Going even further, it's important to remember that distributions themselves are models of underlying phenomena, not the phenomena themselves.

Screenshot 2026-10-09 at 21.11.59.png

PGM - perfect map examples.png400
Examples outside the overlap. Left: the v-structure x1→x3←x2 has x1⊥x2 but x1⊥̸x2∣x3. No undirected graph on these variables shows both. Right: the 4-cycle has x1⊥x3∣{x2,x4} and x2⊥x4∣{x1,x3}. No DAG shows exactly these relations.

Factor graphs

A factor graph shows the factorization more explicitly. It is a bipartite graph with one node for each variable and one node for each factor. Each factor node connects to the variables that the factor uses:

p(x)=∏sfs(xs)

You can change each of the two flavours of PGM above into a factor graph. In a directed PGM, the factors are the conditional distributions p(xi∣pai). In an undirected PGM, the factors are the clique potentials ψC.

A factor graph gives more detail than the above two flavours. For example, two or more factors can use the same set of variables. A factor graph can also remove some ambiguities. For example, a fully connected triangle in an undirected graph can be one three-way potential or three pairwise potentials. The undirected graph does not show the difference, but the factor graph can.

PGM - factor graph triangle.png500
Left: an undirected triangle. Middle: a factor graph with one three-way factor f(x1,x2,x3). Right: a factor graph with three pairwise factors fa(x1,x2)fb(x1,x3)fc(x2,x3). Both factor graphs have the same undirected graph.

The main advantage of a factor graph is for inference. If the factor graph is a tree (i.e. it has no loops, so there is exactly one path between any two nodes), the sum-product algorithm (belief propagation) calculates the exact marginals. The algorithm sends local messages between variable nodes and factor nodes. The marginal of a node is the product of the messages that come into that node. If you replace each sum with a maximum, you get the max-sum algorithm. This algorithm finds the most probable configuration (the Viterbi algorithm is a special case). On a graph with loops, you can use the same message passing (loopy belief propagation). The result is only approximate, but it is often good in practice.

The messages are:

μfs→x(x)=∑x1,…,xMfs(x,x1,…,xM)∏m∈ne(fs)∖xμxm→fs(xm)μxm→fs(xm)=∏l∈ne(xm)∖fsμfl→xm(xm)p(x)∝∏s∈ne(x)μfs→x(x)

A factor multiplies in the messages from its other variables and sums them out. A variable multiplies the messages from its other factors. Leaf nodes start the recursion with μx→f(x)=1 and μf→x(x)=f(x). For max-sum, replace each ∑ with max and work with logs, so the products become sums.

PGM - sum-product messages.png400
Messages flowing towards x3 on a tree-structured factor graph. If messages are passed from the leaves to a root and then back out to the leaves, every node gets its exact marginal.


Links

Sources