Day 41 · 2026.08.02

Probabilistic Graphical Models

Drawing a graph is declaring a whole catalogue of what is irrelevant to what
"Probability is not really about numbers; it is about the structure of reasoning." — Judea Pearl

Bayesian Networks

Encoding independence in the edges you leave out
Directed Models
Intuition

A joint distribution over $n$ binary variables needs $2^n-1$ numbers; at 30 variables that already exceeds a billion. But the world is never fully connected. Draw direct dependencies as arrows, and the real information lives in the edges you did not draw—every missing edge asserts a conditional independence, and the joint collapses from exponential into a product of small tables.

Stranger still is explaining away. Wet grass may be caused by rain or by the sprinkler; the two causes start out unrelated. Yet once you see that the grass is wet, learning that it rained last night immediately lowers your belief that the sprinkler ran—the rain has already accounted for the wetness. Observing a common effect makes its two causes dependent out of thin air.

Cloudy Sprinkler Rain Wet grass opened by observing the collider red = observed
Formal definition
$$P(X_1,\dots,X_n)=\prod_{i=1}^{n} P\!\left(X_i \mid \mathrm{pa}(X_i)\right)$$

$\mathrm{pa}(X_i)$ is the set of parents of $X_i$ in the directed acyclic graph. The line says one thing: given its direct causes, a variable is independent of all its non-descendants. Storage drops from $2^n$ to $\sum_i 2^{|\mathrm{pa}(X_i)|}$. The graph is not an illustration of the distribution—the graph is half its definition; the other half is just the local conditional probability tables.

Why it is beautiful

There is a dictionary here between graph theory and probability. d-separation is a purely combinatorial test: trace the paths, note which nodes are observed, touch no integral. Its conclusion, however, is about the distribution—separation in the graph implies conditional independence in the distribution, and for almost all parameter values the converse holds too. A question you can answer by running a finger along arrows is equivalent to whether a family of high-dimensional integrals coincide. This syntax–semantics correspondence is not an isolated case (Day 19, Day 47): mathematics rewards, again and again, those who demote a semantic question to a syntactic one.

Applications

The QMR-DT diagnostic system links hundreds of diseases to thousands of symptoms through a two-layer network; genetic linkage analysis propagates genotype beliefs along pedigree graphs. The deepest step was Pearl's promotion of arrows from dependence to causation: with the intervention operator $do(x)$, the graph can decide whether a causal effect is identifiable from purely observational data (the back-door criterion)—"correlation is not causation" became a computable proposition.

The essential line · a question
A Bayesian network's information content lies not in the edges you drew but in the ones you did not—modelling is the act of responsibly declaring what is irrelevant to what.
Does the dependency graph you draw for a system also implicitly assert a set of irrelevancies? Would you notice when one is violated?

Markov Chains

A local rule that fixes a global invariant
Stochastic Processes
Intuition

The Markov property is a single sentence: the future depends on the past only through the present. The current state is a sufficient statistic for the entire history—remember it and you can throw the logs away.

Picture a crowd doing a random walk on a state graph, each person stepping by the same rule. However strange the starting distribution, after enough steps the crowd's overall distribution stops changing—inflow into each state exactly balances outflow. Individuals still jump about; the macroscopic shape has frozen.

A B C 0.7 0.6 0.9 the distribution converges to π t=0 t=5 t→∞
Formal definition
$$\pi P=\pi,\qquad \textstyle\sum_i \pi_i=1$$

$P$ is the transition matrix, $P_{ij}$ the probability of jumping from $i$ to $j$; the row vector $\pi$ is a distribution over states. The equation says $\pi$ is the left eigenvector of $P$ for eigenvalue 1—one step leaves the distribution untouched. If the chain is irreducible and aperiodic, $\pi$ is unique; error decays like $|\lambda_2|^t$, so the larger the spectral gap, the faster the mixing (Day 4, Day 48).

Why it is beautiful

The rule is entirely local—each state knows only where it jumps—yet the result is global and unique, and it is the most basic object in linear algebra: an eigenvector. PageRank is exactly this sentence cashed out: "an important page is one linked to by important pages" is a circular definition, and the eigenvector equation unwinds it.

Lovelier still is running the logic backwards: instead of taking a chain and finding its stationary distribution, take the distribution you want to sample and design a chain that has it as its stationary distribution. Detailed balance $\pi_i P_{ij}=\pi_j P_{ji}$ involves only ratios of $\pi$, so the intractable normalizing constant cancels—which is precisely why high-dimensional posteriors you cannot write down can still be sampled from.

Applications

PageRank and the random walks behind recommender systems; MCMC, which underpins modern Bayesian statistics and Ising-model simulation; queueing theory, where the stationary distribution gives waiting times. Shannon modelled English letter sequences as a Markov chain—the prehistory of language models (Day 13). The newest instance is diffusion models: the forward noising process is a Markov chain that grinds data into Gaussian noise, and the network learns its time reversal.

The essential line · a question
The single constraint "remembering the present is enough" compresses a stochastic process into one matrix and its long-run behaviour into one eigenvector.
Which "states" in your own systems are genuinely sufficient statistics? When the Markov assumption fails, which variable was usually left out?

Hidden Markov Models

Watching a chain through frosted glass
Latent Variables
Intuition

The real state evolves backstage as a Markov chain—the phoneme a speaker intends, a bull or bear regime, whether a stretch of genome is coding or not. You see only what it randomly "renders": a waveform, a day's return, a base pair. The chain walks in the dark; you guess from the light.

The difficulty: a length-$T$ observation admits $|S|^T$ hidden paths that all explain it. What saves you is the Markov property—two paths with different histories that sit in the same state right now have identical influence on the future, so they can be merged on the spot into a single number.

state trellis (red = the Viterbi path) s₁ s₂ s₃ x₁ x₂ x₃ x₄ observed
Formal definition

Two parameter sets: transitions $A_{ij}=P(z_t=j\mid z_{t-1}=i)$ and emissions $B_{jk}=P(x_t=k\mid z_t=j)$. The forward recursion is

$$\alpha_t(j)=\Big[\sum_i \alpha_{t-1}(i)\,A_{ij}\Big]\,B_{j\,x_t}$$

Read $\alpha_t(j)$ as the joint probability of "having produced every observation $x_{1:t}$ so far, and sitting in state $j$ right now". The sum inside the bracket is the whole secret: it merges every history leading into $j$ into one number, because the future depends on $j$ and not on how you reached $j$. Outside the bracket, the emission term absorbs the current observation's evidence. Cost falls from $O(|S|^T)$ to $O(|S|^2T)$.

Why it is beautiful

On the same trellis, replace $\sum$ with $\max$ and you no longer compute a marginal but the single most likely hidden path—that is Viterbi. The two algorithms looking identical is no coincidence: they are the same recursion instantiated over different semirings, with $(+,\times)$ giving a sum of probabilities and $(\max,\times)$ giving an optimal path. The skeleton of an algorithm has been cleanly separated from the algebra it computes over: change the semiring and you change the meaning; shortest paths and sequence alignment sit in the same table. You thought you were solving one problem and proved a whole family (Day 19).

Applications

Speech recognition was ruled by HMMs for thirty years before deep learning: hidden states were phonemes, emissions modelled acoustics. Bioinformatics uses them for gene prediction and sequence alignment; Viterbi decoding runs in the convolutional-code decoder of nearly every mobile phone (Day 33). Even today, the CTC loss in end-to-end speech models runs the same forward–backward recursion—only the emission probabilities now come from a neural network.

The essential line · a question
Dynamic programming beats exponential blow-up not through cleverness but through the model's own conditional-independence structure—the Markov property is the licence to merge.
If the hidden state still depended on older history, how would you enlarge the state to make it Markov again? What does that cost?

Inference as Message Passing

From graphical models to deep learning
Inference & ML
Intuition

The first three concepts are special cases of one algorithm. Read the graph as a communication network: each node knows only its relationships to its neighbours, summarizes "here is what I think you should look like" into a message, and updates its own belief once its neighbours have replied. Run this protocol once on a tree and every node ends up holding exactly the correct marginal—yet global inference was never executed as a whole by any node. It emerges out of local conversation. This is the worldview of distributed systems: no central coordinator, global consistency guaranteed by a local protocol.

Formal definition
$$m_{i\to j}(x_j)=\sum_{x_i}\psi_{ij}(x_i,x_j)\,\phi_i(x_i)\!\!\prod_{k\in N(i)\setminus j}\!\! m_{k\to i}(x_i)$$

$\phi_i$ is node $i$'s own evidence, $\psi_{ij}$ the edge compatibility (how plausible this pair of values is), and $N(i)\setminus j$ the neighbours other than $j$—what $j$ just told you must not be handed back to $j$, or belief reinforces itself into an echo chamber. The sum marginalizes out $i$'s possibilities, leaving only its opinion about $j$.

Why it is beautiful

Once the graph has cycles the protocol loses its guarantees, yet people run it anyway (loopy BP) and it often works absurdly well; only a decade later did it become clear that it optimizes the Bethe free energy from statistical physics. The same equation was discovered independently in three unrelated fields: the cavity method in statistical physics, LDPC decoding in coding theory, and belief propagation in AI.

When exact inference really is out of reach there is a second road: turn inference into optimization—search a family of simple distributions $q$ for the one closest to the true posterior by maximizing the lower bound

$$\log P(x)\;\ge\;\mathbb{E}_{q}\!\left[\log P(x,z)\right]-\mathbb{E}_{q}\!\left[\log q(z)\right]$$

The first term pushes $q$ onto high-probability regions; the second is $q$'s entropy, stopping it from collapsing to a point. The gap between the bound and $\log P(x)$ is exactly a KL divergence. "Compute an integral" has become "run gradient descent"—which is precisely the VAE objective.

Applications

LDPC and turbo codes decode with loopy BP and push rates close to the Shannon limit (Day 13, Day 33). The training objectives of VAEs and diffusion models are both variants of the ELBO. Every layer of a graph neural network is a learnable version of message passing—the hand-designed potentials replaced by neural networks; attention, too, can be read as one round of message passing on a fully connected graph. Deep learning did not abolish graphical models, it parameterized their inference step.

The essential line · a question
Structure is constraint and constraint is tractability: a graphical model's power comes from daring to declare "there is no edge here", and inference is only local belief propagating along that skeleton until it settles.
When a model learns potentials without ever declaring structure, has it truly learned those conditional independences—or merely memorized them with enough parameters?

Going deeper

Why is conditional independence more fundamental than independence?
Unconditional independence almost never holds in the real world, which makes it of little use. Conditional independence is everywhere: once the direct causes are given, distant things carry no extra information. More importantly it composes—an entire joint distribution can be assembled out of a pile of conditional-independence assertions. Graphical models are possible because the world's dependencies are sparse and local, which is probably the same reason physical laws can be written as differential equations that involve only a neighbourhood.
What does a causal graph have that a probabilistic one does not?
A commitment about interventions. Different directed graphs can induce exactly the same joint distribution (a Markov equivalence class), and observational data cannot tell them apart. A causal graph asserts something extra: after cutting all incoming edges to a node—that is, $do(x)$—the remaining mechanisms are unchanged. This "modularity" assumption is not verifiable from data; it is a stance taken by the modeller. Only with it can you ask "if I change $X$, what happens to $Y$"—the watershed between prediction and decision.
When is explicit structure still irreplaceable?
When data is scarce, when you must extrapolate to an intervention never observed, or when calibrated uncertainty is required. A purely fitted model can only interpolate within its training distribution; the moment the question becomes "what if I change $X$", there is nothing to answer with unless structure was declared. That is why clinical trial design, epidemic modelling, and failure attribution still hand-draw graphs—there, the cost of being wrong is too high to let parameters guess the structure.
Is the brain running approximate inference?
Predictive coding holds that cortex sends predictions downward and prediction errors upward, formally close to message passing on a hierarchical Gaussian graphical model; the free-energy principle goes further and unifies perception and action as optimization of one variational bound—perception changes $q$ to fit the world, action changes the world to fit $q$. The evidence remains contested, and critics note it can be framed so broadly as to be nearly unfalsifiable. Still, the analogy poses a sharp question: if intelligence is approximate inference over a structured model, which is the harder part—learning the structure, or inferring on it?