Bayesian Networks
A Bayesian network is a directed acyclic graph of random variables in which each node carries a conditional probability table for itself given its parents. That structure factors the full joint distribution into a product of local terms, turning an exponential table into a linear one, and it makes the conditional independences of the domain explicit.
╌╌╌╌
The full joint distribution answers every question you can ask about a domain — but its size grows exponentially. A joint over Boolean variables has entries; thirty variables already demand a billion numbers, none of which a human could estimate or a machine store. The previous lesson addressed this with independence: knowing that has nothing to do with a toothache lets you factor its probability out and stop enumerating combinations that never mattered. A Bayesian network is the data structure that makes that factoring systematic. It is a graph whose edges record exactly which variables depend on which, and whose local tables reconstruct the entire joint from a linear number of numbers instead of an exponential one.1
The network
The edges are meant to be read causally. An arrow says exerts a direct influence on , and the intuition that causes should be parents of effects is what makes networks easy to build: a domain expert can usually name the direct influences long before they could write down a single probability. Once the topology is fixed, the only remaining work is to fill each node's conditional probability table — the local rule for that variable given its immediate causes.2
Return to the dental world of the previous lesson: , , (a probe catching in the tooth), and . We argued that is independent of the rest, and that and are conditionally independent given — a cavity is the common cause of both, and once you know whether it is present, the probe tells you nothing further about the ache. The network encodes this directly.
The burglary network
The example that carries the rest of the chapter is a little richer.3 You have a burglar alarm at home. It is fairly reliable at detecting a break-in, but it also trips occasionally on a minor earthquake. Two neighbors, John and Mary, have promised to call you at work when they hear it. John nearly always calls when the alarm sounds, but sometimes confuses the ringing telephone for the alarm and calls anyway; Mary likes loud music and often misses the alarm altogether. Given who has and has not called, you want the probability of a burglary.
Five Boolean variables — , , , , — carry the domain. The causal structure is plain: a burglary or an earthquake can set off the alarm, and the alarm is the only thing John or Mary react to. Neither neighbor perceives burglaries or earthquakes directly, and they do not confer before calling, so each call depends on the alarm and nothing else.
Each row of a conditional probability table (CPT) is a conditioning case — a possible combination of parent values, a miniature possible world. The alarm's table has four rows because it has two Boolean parents; each row gives the probability the alarm fires in that case, and its complement is minus that, so we list only one number. A root node with no parents, like , has a single row: its prior. In general a Boolean node with Boolean parents needs numbers.4
The tables absorb a great deal of the world's untidiness. There is no node for
Mary is listening to loud music
or the phone is ringing
; those factors are
folded into the uncertainty on the links — the reason John's call probability
given the alarm is rather than . A small agent copes with a large,
messy world by summarizing an unbounded set of unmentioned circumstances into a
few conditional probabilities.
Semantics: the network is the joint
The network above is syntax — a graph with numbers. Its meaning is a specific full joint distribution, recovered by one formula. A generic joint entry is the probability of an assignment to every variable, , and a Bayesian network defines it as the product of the local tables:5
Each joint entry is a product of one entry from each node's CPT, picking the row that matches the parents' values in that assignment. This is the whole content of a Bayesian network: the graph plus the local tables is the joint distribution, factored. To find the probability that the alarm sounds but neither a burglary nor an earthquake occurs and both neighbors call, read off five numbers and multiply:
Since the network reconstructs the joint, it can answer any query the joint could — by summing the relevant entries. The rest of the lesson is about doing that summation without ever writing the joint out in full.
Constructing a network
Where does the factorization come from? Apply the chain rule to the joint — it holds for any distribution — decomposing it into a product of conditionals in some fixed variable order :
Compare this with the network's product. The two agree exactly when, for every variable,
provided .6 In words: a node must be conditionally independent of its other predecessors, given its parents. This gives a procedure. Order the variables so that causes precede effects; then for each in turn, choose as its parents the minimal set of already-placed nodes it directly depends on, add the edges, and write the CPT.
Because each node links only to earlier ones, the graph is automatically acyclic, and because no probability is stored twice there is no way to make the tables mutually inconsistent — a domain expert literally cannot build a network that violates the axioms of probability.
Order matters
The procedure works for any ordering, but a bad one is costly. Add the burglary variables in the anti-causal order , , , , and you are forced into tenuous links: if Mary called, John is more likely to have called too (both point to the alarm), so needs as a parent; assessing demands an unnatural judgment about how a burglary explains away the alarm.
Both networks represent exactly the same joint distribution. The diagnostic
one simply fails to expose the conditional independences, so it stores redundant
numbers to compensate. The lesson is that causal models are the compact ones:
arrows from causes to effects require the fewest, most natural probabilities,
which is why expert physicians reliably give better numbers for causal rules
(what does this disease cause?
) than for diagnostic ones.
Compactness
Compactness is the reason the whole apparatus exists. A Bayesian network is a locally structured (or sparse) system: each variable is directly influenced by only a bounded number of others, no matter how large the domain. Suppose each of Boolean variables has at most parents. Each CPT holds at most numbers, so the entire network needs at most — linear in . The full joint needs — exponential.7
Concretely, with nodes and parents each, the network needs numbers and the joint over a billion. The saving is not free: it holds only when the domain really is sparse. If every variable influences every other, the graph is fully connected and the network stores as much as the joint. But most real domains are sparse, and when a dependence is genuine but weak — whether an earthquake, having tripped the alarm, should also make John more likely to call — you may drop the link, trading a little accuracy for a much smaller model.
Conditional independence and d-separation
The graph does more than compress numbers; it declares which independences hold. The topological semantics states them directly: a node is conditionally independent of its non-descendants, given its parents.8 In the burglary network, is independent of , , and once you know — the alarm screens off everything upstream. A second, stronger statement uses the Markov blanket of a node — its parents, its children, and its children's other parents. A node is independent of all other nodes in the network given its Markov blanket. To isolate a node, these are the variables you must condition on, and they will reappear when we sample.
To decide independence for any two sets of nodes given a third, there is a graphical criterion called d-separation. It rests on three ways a path can run through an intermediate node , and whether evidence at blocks the path or opens it.9
The chain passes influence from to through ; observing cuts the flow, so . A burglary influences John's call only through the alarm, and once you know the alarm's state the burglary adds nothing. The common cause behaves the same way: and are correlated because drives both, but fix the cavity and the correlation vanishes.
The common effect , also called a collider, is the subtle case, and it runs backward. Two independent causes of the same effect are marginally independent — and have nothing to do with each other a priori — but observing their shared effect makes them dependent. If the alarm is sounding and you learn it was an earthquake, the probability of a burglary drops: the earthquake explains away the alarm. A path through a collider is blocked until the collider (or one of its descendants) is observed, at which point it opens. Explaining away is the signature of probabilistic reasoning that pure logic cannot capture.
Exact inference by variable elimination
We can now store a joint compactly; the next question is how to query it. The naive way — write out the whole sum over hidden variables — throws away the compactness we just gained and costs again. The fix is an accounting trick: factor out the terms that do not depend on the variable being summed, so each partial sum is computed once and reused. That is variable elimination, and it is the same dynamic-programming idea that turns an exponential recursion into a polynomial one.
The basic query asks for the posterior of a query variable given observed evidence , with the remaining variables hidden. Because the network is the joint, any such query is a sum of products of CPT entries. Written out for , marginalizing the hidden variables and :10
where normalizes the result to sum to . Evaluated naively, summing over all hidden variables costs : a network of Booleans forces terms. But the sum has structure — does not depend on or and can sit outside both sums; sits outside the sum over . Pushing each factor out as far as it goes gives
Variable elimination evaluates this right to left, computing each inner sum once and reusing it. Enumeration, by contrast, recomputes the shared subexpression separately for each value of ; eliminating that repetition is where the dynamic-programming saving comes from.
The bookkeeping is done with factors — matrices indexed by the variables they mention. Each CPT is a factor; the two operations that combine them are pointwise product (a factor over the union of the operands' variables, multiplying matching entries) and summing out a variable (adding the submatrices for each of its values). To eliminate from the burglary query, take the pointwise product of every factor mentioning — the factors for , , — and sum over , producing a new factor over and . Then eliminate the same way. The order in which variables are eliminated does not change the answer, but it changes the size of the intermediate factors, and hence the cost. Finding the optimal ordering is itself intractable, so a greedy rule — eliminate whichever variable yields the smallest next factor — is the usual heuristic.11
- 1input: , the query variable; , observed evidence
- 2input: , a Bayesian network over variables
- 3
- 4for each in do
- 5
- 6if is a hidden variable then
- 7
- 8return
One further economy: any variable that is not an ancestor of the query or the evidence is irrelevant and can be deleted before the sum begins. Querying , the term equals — is a leaf that is neither queried nor observed — so drops out entirely.
The burglary query, carried through
Run variable elimination on with the tables from the network figure. Five factors enter, one per CPT with the evidence substituted in: , , the three-way , and the two evidence factors and (ordered ).
Eliminate . Multiply the three factors that mention and sum out, producing a factor over . The product is at and at . For each of the four cases, weight these by and add:
Eliminate . Multiply by and sum out, giving a factor over :
Multiply by the prior and normalize. Scale by : for and for . These are and ; dividing by their sum normalizes:
A burglary is about likely given both calls. The intermediate factors never exceeded two variables, which is why this polytree query is cheap; the same right-to-left evaluation on a densely connected network would build factors over many variables at once, and that is where the cost hides.
The complexity of inference
For polytrees — singly connected networks, where at most one undirected path joins any two nodes — variable elimination runs in time and space linear in the size of the network. The burglary network is a polytree, and this is the best case.12
For multiply connected networks, where nodes are joined by more than one path, the intermediate factors can grow exponentially even when every node has few parents. In the worst case exact inference is intractable, and unavoidably so: the problem is NP-hard. Propositional logical inference is a special case of Bayesian network inference, so the network problem inherits its hardness — and in fact it is #P-hard, as hard as counting the satisfying assignments of a logical formula, strictly harder than deciding satisfiability.
When exact inference is out of reach, the alternative is to estimate the answer rather than compute it — and the whole framework generalizes far beyond the fixed, finite variable sets we have assumed so far.
This continues in Bayesian Networks: Inference and Relational Models, which estimates intractable posteriors by sampling and then lifts the network from a fixed set of variables to whole populations of objects.
Footnotes
- Russell & Norvig, AIMA, §14.1 — Representing Knowledge in an Uncertain Domain: the full joint grows intractably with the number of variables, and independence and conditional independence relationships are what a Bayesian network encodes to represent essentially any joint distribution concisely. ↩
- Russell & Norvig, AIMA, §14.1 — the full specification of a Bayesian network: nodes as random variables, directed links marking parents in a DAG, a CPT per node, and the causal reading of arrows as direct influence that makes topology easy for an expert to supply. ↩
- Russell & Norvig, AIMA, §14.1, Figure 14.2 — the burglary/alarm/earthquake network due to Judea Pearl, its topology, and the conditional probability tables for , , , , and . ↩
- Russell & Norvig, AIMA, §14.1 — conditional probability tables and conditioning cases: each row a combination of parent values summing to 1, the entry omitted for Boolean variables, and a Boolean node with Boolean parents requiring numbers; laziness and ignorance folded into the link uncertainties. ↩
- Russell & Norvig, AIMA, §14.2.1, Equations (14.1)–(14.2) — the semantics of a Bayesian network as the full joint distribution, , and the worked . ↩
- Russell & Norvig, AIMA, §14.2.1 —
A method for constructing Bayesian networks
: the chain rule, Equation (14.3) , ordering causes before effects, choosing minimal parent sets, and the guarantee of acyclicity and consistency. ↩ - Russell & Norvig, AIMA, §14.2.1 —
Compactness and node ordering
: locally structured (sparse) systems, the versus count with the , example (960 numbers versus over a billion), and the tradeoff of dropping tenuous links. ↩ - Russell & Norvig, AIMA, §14.2.2, Figure 14.4 — the topological semantics: a node is conditionally independent of its non-descendants given its parents, and independent of all other nodes given its Markov blanket (parents, children, children's parents). ↩
- Russell & Norvig, AIMA, §14.2.2, footnote — d-separation as the general topological criterion for conditional independence of node sets, decided by whether paths are blocked; the chain, common-cause, and common-effect (collider / explaining-away) connection types and how observing the middle node blocks or opens each. ↩
- Russell & Norvig, AIMA, §14.4.1, Equation (14.4) — inference by enumeration: a query as a sum of products of CPT entries, , the answer , and its cost with repeated subexpressions. ↩
- Russell & Norvig, AIMA, §14.4.2, Figure 14.11 — the variable elimination algorithm: factors, pointwise product and summing out, right-to-left evaluation with stored intermediates, , variable-ordering heuristics, and removal of variables irrelevant to the query. ↩
- Russell & Norvig, AIMA, §14.4.3 — the complexity of exact inference: linear time and space for singly connected networks (polytrees), exponential worst case for multiply connected networks, and the #P-hardness (NP-hard) of the general problem, with propositional inference as a special case. ↩
╌╌ END ╌╌