Foundations to Frontier
Tests

Probabilistic graphical models: Bayesian networks and Markov random fields

A joint distribution over many variables is too big to write down: 30 binary variables need over a billion numbers. Probabilistic graphical models factorize it using conditional independence. A Bayesian network (a directed acyclic graph) writes p(x) as a product of local conditionals P(x_i | parents). A Markov random field (an undirected graph) writes it as a normalized product of clique potentials, with a partition function Z. This page covers both factorizations, how to read independences from the graph (d-separation, separation and Markov blankets), moralization, factor graphs, what each family can and cannot express, and learning parameters and structure from data (counting, Chow–Liu trees). In the exercise a satellite fault model with 8 binary variables is learned from samples, and the exact KL divergence to the truth is computed for four model classes. The correct sparse structure (21 parameters) won at every sample size, reaching 0.001 nats at n = 10000. A full table (255 parameters) was worst at n = 30 (1.22 nats) but consistent (0.014 at 10000). The best tree beat the full table up to n = 300 and then stalled at 0.186, the price of v-structures a tree cannot represent.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Drawing a joint distribution

A satellite’s battery runs low because of an eclipse or a panel fault; a low battery causes temperature drops and attitude errors; those trip an alarm. Writing the probability of every combination of these eight events needs 255 numbers. Drawing the arrows of cause and effect lets you write it with 21: each variable only needs a small table given its direct causes. That is a Bayesian network. When influences have no natural direction, such as neighbouring pixels in an image, you use an undirected graph instead: a Markov random field. In the demo, pick two variables and click others to condition on them: the graph tells you whether they become independent.

Which paths carry association? A d-separation explorer
X Y Click other nodes to condition on them (shaded).
TerrainCmdSpeedSlipOdomErrBlur
Paths between Terrain and Cmd given Z = {}: all blocked → d-separated (independent)
  • Terrain → Speed ← Cmd: blocked at Speed (collider, not conditioned)
  • Terrain → Slip ← Speed ← Cmd: blocked at Slip (collider, not conditioned)
Rules: a chain (→ M →) or fork (← M →) is blocked if you condition on M. A collider (→ M ←) is blocked unless you condition on M or one of its descendants. Try Terrain and Cmd: independent, but conditioning on Speed (or on its descendant Blur) makes them dependent.
Why engineers care

Graphical models are the language of fault diagnosis, sensor fusion and state estimation: Kalman filters, HMMs, SLAM factor graphs (GTSAM) and image denoising MRFs are all special cases. The graph is also how you explain a model to a safety reviewer.

📝 Quick check (Level 0)
0/3 answered
  1. 1. A Bayesian network uses…
  2. 2. A Markov random field uses…
  3. 3. Graphical models save parameters by using…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

Two factorizations

  • Bayesian network (BN): p(x₁, …, x_n) = Π_i P(x_i | x_pa(i)) for a DAG. Each factor is a conditional probability table (CPT) or a conditional density.
    • Example (A → C ← B): P(A=1) = 0.3, P(B=1) = 0.6, P(C=1 | A=1, B=0) = 0.7. Then P(A=1, B=0, C=1) = 0.3 × 0.4 × 0.7 = 0.084.
    • Parameters for binary variables: Σ_i 2^|pa(i)|. The 8-variable satellite model needs 1+1+1+4+4+4+2+4 = 21; a full table needs 2⁸ − 1 = 255.
  • Markov random field (MRF): p(x) = (1/Z) Π_C ψ_C(x_C) over cliques C, with Z = Σ_x Π_C ψ_C(x_C).
    • Ising model with spins ±1: p(s) ∝ exp(Σ_edges J s_i s_j + Σ_i h_i s_i). Two spins, J = 1, h = 0: P(both up) = e / (2e + 2/e) = 0.440.
    • Potentials are not probabilities; only the normalized product is. Computing Z is the hard part.
  • Reading independences:
    • BN: d-separation. Chains and forks are blocked by conditioning on the middle node; a collider (A → C ← B) is blocked unless C or a descendant is observed (“explaining away”).
    • MRF: plain graph separation. X ⫫ Y | Z if every path from X to Y passes through Z.
    • Markov blanket: in a BN, parents + children + children’s other parents; in an MRF, the neighbours. Given its blanket a node is independent of everything else.
  • Moralization: BN → MRF by connecting (“marrying”) co-parents and dropping arrows. The moral graph may lose independences (the marginal independence of A and B in a v-structure).
  • Factor graphs: a bipartite graph of variables and factors; the common format for message passing (Kschischang, Frey and Loeliger, 2001).
  • Explaining away: with A, B ~ Bernoulli(0.5) and C = A OR B: P(A) = 0.5, P(A | C) = 0.667, P(A | C, B) = 0.5.
📝 Quick check (Level 1)
0/3 answered
  1. 1. In a v-structure A → C ← B, observing C makes A and B…
  2. 2. The Markov blanket of a BN node includes…
  3. 3. Moralization…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.

Building and learning graphical models

Exercise 1.

  • Evaluate a BN joint probability by the chain rule over the DAG.
  • Count parameters, moralize a DAG and find Markov blankets.
  • Normalize a tiny MRF by enumerating its partition function.

Practice.

  • Start from domain structure: causes point to effects; time points forward. Check every arrow with an expert.
  • Learn CPTs by counting with a Dirichlet/Beta prior (add-α smoothing); with missing data use EM.
  • Learn structure only when you must: score-based search (BIC, BDeu) with hill climbing, constraint-based tests (PC algorithm), or Chow–Liu trees as a fast baseline. Structure learning is hard: equivalent DAGs give the same distribution.
  • Libraries: pgmpy (Python BNs and MRFs), pomegranate, bnlearn (R), GTSAM and Ceres for robotics factor graphs, PyMC/NumPyro for continuous models.
  • Validate by held-out log-likelihood and by checking independences the graph claims against data.
from pgmpy.models import DiscreteBayesianNetwork
from pgmpy.estimators import BayesianEstimator, HillClimbSearch, BIC
from pgmpy.inference import VariableElimination
model = DiscreteBayesianNetwork([("Eclipse", "PowerLow"), ("PanelFault", "PowerLow"), ("PowerLow", "BatteryLow"),
                                 ("BatteryOld", "BatteryLow"), ("BatteryLow", "TempLow"), ("Eclipse", "TempLow"),
                                 ("BatteryLow", "AttitudeErr"), ("TempLow", "Alarm"), ("AttitudeErr", "Alarm")])
model.fit(df, estimator=BayesianEstimator, prior_type="BDeu", equivalent_sample_size=5)   # df: telemetry flags
print(VariableElimination(model).query(["PanelFault"], evidence={"Alarm": 1, "Eclipse": 0}))
learned = HillClimbSearch(df).estimate(scoring_method=BIC(df))                             # structure search
🐍 Exercise 1: factorize, count and moralize
Evaluate a BN joint, count parameters, moralize, find Markov blankets and normalize a tiny Ising MRF.
📝 Quick check (Level 2)
0/3 answered
  1. 1. CPTs are usually learned by…
  2. 2. A fast structure-learning baseline is…
  3. 3. Robotics SLAM back-ends use…

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

Equivalence of the two views. For a positive distribution, the Hammersley–Clifford theorem says p factorizes over the cliques of an undirected graph G exactly when it satisfies the Markov properties of G. For DAGs, p factorizes as Π P(x_i | pa) exactly when every node is independent of its non-descendants given its parents (the local Markov property), equivalently when every d-separation in the DAG holds in p (Pearl, 1988; Lauritzen, 1996).

Expressiveness. Neither family contains the other. A v-structure (A ⫫ B but not A ⫫ B | C) has no perfect undirected map; a 4-cycle MRF (A ⫫ C | B, D and B ⫫ D | A, C) has no perfect DAG. Trees and chordal graphs are representable both ways. Markov equivalent DAGs share their skeleton and v-structures, which is why data alone cannot orient every edge.

Learning. With complete data the BN log-likelihood decomposes into one term per family, so CPTs are fitted independently by counting. Chow and Liu (1968) showed that the maximum-likelihood tree is the maximum spanning tree on pairwise mutual information. The KL from the truth to the best tree equals Σ_i H(x_i) − H(x) − Σ_edges I(x_i; x_j): the multi-information the tree fails to capture. MRF learning is harder because Z depends on all parameters: the gradient of the log-likelihood is (data moments − model moments), and model moments need inference (contrastive divergence, pseudo-likelihood).

Bias–variance of structure. A richer structure has lower approximation error but more parameters to estimate; with k parameters the expected excess KL from estimation is about k/(2n) nats. The full table (255 parameters) at n = 1000 would pay about 0.13 nats; Exercise 2 measured 0.142.

📝 Quick check (Level 3)
0/3 answered
  1. 1. Hammersley–Clifford links an MRF factorization to…
  2. 2. The maximum-likelihood tree is…
  3. 3. Learning MRF parameters is hard because…

Level 4: Expert

★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.

How much does the right graph structure help when learning a distribution from limited data?

History.

  • C. Chow and C. Liu, “Approximating discrete probability distributions with dependence trees” (1968).
  • J. Besag, “Spatial interaction and the statistical analysis of lattice systems” (1974): MRFs and pseudo-likelihood.
  • J. Pearl, Probabilistic Reasoning in Intelligent Systems (1988): Bayesian networks and d-separation.
  • S. Lauritzen and D. Spiegelhalter, “Local computations with probabilities on graphical structures” (1988).
  • D. Koller and N. Friedman, Probabilistic Graphical Models (2009).

Exercise 2. A satellite fault model with 8 binary variables: Eclipse, PanelFault, BatteryOld → PowerLow (from Eclipse, PanelFault) → BatteryLow (from PowerLow, BatteryOld) → TempLow (also from Eclipse) and AttitudeErr → Alarm (from TempLow, AttitudeErr). True entropy 3.337 nats.

  • Data: n ancestral samples, n = 30 … 10000.
  • Models (all with a Beta(1, 1) prior on every table entry): the true structure (21 parameters), a Chow–Liu tree learned from the same data (15), a full joint table (255) and independent variables (8).
  • Measure: exact KL(truth ‖ model) in nats, by enumerating all 256 states. Zero is perfect.
n true structure (21) Chow–Liu tree (15) full table (255) independent (8)
30 0.197 0.357 1.219 1.243
100 0.110 0.275 0.766 1.223
300 0.042 0.258 0.403 1.222
1000 0.009 0.202 0.142 1.195
3000 0.005 0.188 0.048 1.194
10000 0.001 0.186 0.014 1.192
  • The right sparse structure wins everywhere, needing about 300 samples to reach the accuracy the full table reaches with about 3000–10000.
  • Trees vs tables cross over: Chow–Liu beat the full table up to n = 300 and lost from n = 1000. The tree’s floor is the best possible tree, KL 0.185 (computed from the exact distribution), because the two v-structures (PowerLow and Alarm each have two parents) need three-way tables.
  • Independence costs 1.19 nats: the multi-information of the model, the information carried only by dependencies.
  • Seeds 1 and 2: the same ordering at every n; KL of the true structure at n = 30 was 0.111 and 0.198; Chow–Liu at 10000 was 0.186 in both; the crossover again fell between 300 and 1000.
🐍 Exercise 2 (research): how much does the right graph structure help when learning a distribution from limited data?
Learn a satellite fault model from samples with the true structure, a Chow–Liu tree, a full table and an independence model, and compare their exact KL to the truth.

Graphical models in AI, robotics and aerospace

  • Diagnosis: Bayesian networks for spacecraft and aircraft health management (e.g. NASA’s ADAPT electrical power testbed diagnostic challenges) and for fault trees with uncertain evidence.
  • SLAM and state estimation: factor graphs with iSAM2 and GTSAM (Kaess et al., 2012; Dellaert and Kaess, 2017) are the standard robotics back-end.
  • Vision: MRFs and CRFs for denoising, stereo and segmentation (graph cuts, Boykov et al., 2001); dense CRFs refined early deep segmentation outputs.
  • Earth observation: spatial MRF priors smooth land-cover maps so neighbouring pixels agree.

References

  1. C. K. Chow and C. N. Liu (1968). “Approximating discrete probability distributions with dependence trees.” IEEE Trans. Information Theory, 14(3).
  2. J. Besag (1974). “Spatial interaction and the statistical analysis of lattice systems.” JRSS B, 36.
  3. J. Pearl (1988). Probabilistic Reasoning in Intelligent Systems. Morgan Kaufmann.
  4. S. L. Lauritzen and D. J. Spiegelhalter (1988). “Local computations with probabilities on graphical structures and their application to expert systems.” JRSS B, 50.
  5. S. L. Lauritzen (1996). Graphical Models. Oxford University Press.
  6. F. R. Kschischang, B. J. Frey and H.-A. Loeliger (2001). “Factor graphs and the sum-product algorithm.” IEEE Trans. Information Theory, 47(2).
  7. D. Koller and N. Friedman (2009). Probabilistic Graphical Models: Principles and Techniques. MIT Press.
  8. F. Dellaert and M. Kaess (2017). “Factor graphs for robot perception.” Foundations and Trends in Robotics, 6.
  9. A. Ankan and J. Textor (2024). “pgmpy: a Python toolkit for Bayesian networks.” JMLR, 25.