Probabilistic and Graphical Models
A map of which variables directly influence which. The graph draws the independencies, and the independencies decide what is cheap to compute.
Why Does This Exist?
A joint distribution over binary variables needs numbers. At that is a billion: unwritable, unfittable, uninheritable. Yet real domains are full of structure: a symptom depends on its disease, not on a distant author's breakfast. Graphical models turn that structure into savings by factorizing the joint along a graph, so you store and learn small local tables instead of one giant one.
The graph is also a reasoning engine. Read conditional independencies off it (parents screen off non-descendants given the full parent set), and every inference algorithm, from belief propagation to Gibbs sampling in MCMC, exploits exactly those independencies. This page is the overview; factor graphs give the unifying representation, and the directed and undirected carriers are Bayesian networks and Markov random fields.
The one idea you need first
Conditional independence means that once is known, learning tells you nothing new about . Factorization follows: . Every saving below is this identity applied along the graph's edges. Bayes background is in Bayes theorem.
Think of It Like This
A company org chart for gossip
Rumors flow along reporting lines. If you want to know whether the rumor reaches the intern, you only need the intern's manager's state, not the CEO's breakfast: the manager screens off the rest. The org chart says who screens off whom, and the whole company gossip dynamics factor into one small forwarding rule per person.
Change the org chart and you change the computation. A flat company where everyone talks to everyone needs one giant rulebook. A hierarchy needs small ones. Graphical models are this observation made exact: the graph is the org chart, each node's table is its forwarding rule, and independence is the screening.
Where the analogy stops: gossip can loop back and amplify, while directed models must be acyclic or the factorization breaks. Loops need the undirected treatment.
How It Actually Works
A directed model (Bayesian network) on a DAG factors as . An undirected model (Markov random field) factors over cliques as with partition function normalizing. A factor graph makes both explicit by drawing variable nodes and factor nodes, which is why inference code targets factor graphs rather than either carrier.
Worked example
Three binary variables in a chain : alarm, guard checks, guard calls. Full joint: free numbers. Factored: needs 1, needs 2 (one per value of ), needs 2, for numbers versus 7. Modest here; at chain length 30 it is versus a billion.
Set , , , , . Then with : . And given the call (), the alarm probability updates to where : . The call more than doubles the alarm suspicion, from 0.1 to 0.25, computed with three small tables and no joint.
Code
Elimination on the chain: two small sums replace the joint, exactly as the numbers above.
import numpy as np
pA = np.array([0.9, 0.1]) # P(A=0), P(A=1)pB_given_A = np.array([[0.8, 0.2], [0.1, 0.9]]) # rows: A valuepC_given_B = np.array([[0.9, 0.1], [0.2, 0.8]]) # rows: B valuepB = pA @ pB_given_A # eliminate ApC = pB @ pC_given_B # eliminate Bprint(np.round(pB, 3)) # -> [0.73 0.27]print(round(float(pC[1]), 3)) # -> 0.289Each @ is one variable eliminated by summing it out locally. On a 30-chain this loop replaces a billion-entry table; on a tree it is exact, and on loopy graphs it becomes loopy belief propagation, which is approximate.
Watch Out For
Cycles in a directed model
A directed cycle has no valid factorization: the product of conditionals is unnormalized or contradictory, and every sampler built on it produces confident nonsense. Direction must be acyclic, always. When the domain genuinely feeds back, switch to an undirected model or unroll time explicitly.
Treating the undirected normalizer as 1
Markov random field factors are not probabilities and their product does not sum to 1. Forgetting corrupts every probability the model quotes, while leaving the argmax intact, which is why the bug survives testing on predictions and detonates on calibration. Learn with contrastive or likelihood methods that account for .
The Quick Version
- Graphical models factor a joint along a graph: one small table per node or clique.
- A 3-chain needs 5 numbers instead of 7; a 30-chain needs 59 instead of a billion.
- Directed models multiply conditionals on a DAG; undirected models multiply clique potentials over .
- Independence read from the graph is what makes inference algorithms fast.
- The worked chain lifts alarm suspicion from 0.10 to 0.25 on observing the call.
- Cycles break directed models; forgotten normalizers break undirected probabilities.