Conditional Independence and d-Separation
A Bayes net's arrows encode a lot of independence assumptions. Being able to read independencies off the graph without computing anything is a core exam skill. It is also how you check whether a model makes sense.
Two basic independence properties
- Local Markov property: each node is conditionally independent of its non-descendants, given its parents. (JohnCalls is independent of Burglary and Earthquake given Alarm.)
- Markov blanket: each node is conditionally independent of every other node given its Markov blanket: its parents, its children and its children's other parents.
Why are the children's other parents included? Because of explaining away, the phenomenon described just below.
The three building blocks
Every path through a Bayes net is built from three kinds of three-node connections. Understand these three and you understand d-separation.
| Structure | Picture | A and C independent? | Given B? |
|---|---|---|---|
| Causal chain | A → B → C | No (rain makes slipping likely, slipping makes lateness likely) | Yes: once you know Bolt slipped, rain adds nothing about lateness |
| Common cause (fork) | A ← B → C | No (John's call is evidence for Mary's call) | Yes: given the alarm, John and Mary are independent |
| Common effect (collider / v-structure) | A → B ← C | Yes: burglaries and earthquakes are unrelated | No! Given the alarm, they become dependent |
Chains and forks behave the way you'd expect: observing the middle node blocks the flow of information. Colliders are the opposite: the path is blocked until you observe the middle node (or any of its descendants). Then it opens.
Explaining away
Burglaries and earthquakes are independent: knowing there was an earthquake tells you nothing about burglars. But suppose the alarm went off. Now if you learn there was an earthquake, the earthquake explains the alarm, and a burglary becomes much less likely. The two causes compete to explain the shared effect. The numbers (computed in §7.3):
| Evidence | P(Burglary | evidence) |
|---|---|
| none | 0.001 |
| John and Mary both call | 0.284 |
| John and Mary call and there was an earthquake | 0.003 |
Learning about the earthquake drops the burglary probability by a factor of almost 100. Bolt's own version: Bolt is late (effect). If you learn its battery was low (one cause), the probability that the path was wet (another cause) drops. This is everyday reasoning, and Bayes nets get it automatically.
d-separation: the general rule
A path between X and Y is blocked by evidence set Z if it contains a node N such that either
- N is a chain or fork node (→N→, ←N←, or ←N→) and N is in Z, or
- N is a collider (→N←) and neither N nor any descendant of N is in Z.
X and Y are d-separated given Z if every path between them is blocked. Then \(X \perp Y \mid Z\) is guaranteed for any CPT values.
Here is an algorithm that is easier to apply by hand than checking every path, the ancestral moral graph method:
- Keep only X, Y, Z and their ancestors.
- Moralize: connect ("marry") every pair of parents that share a child, then drop the arrow directions.
- Delete the nodes in Z.
- If X and Y are disconnected, they are d-separated given Z.
Here it is on a bigger Bolt network: Rain and Sprinkler both cause a WetPath, a wet path causes Slips, slips and a low Battery cause Lateness, and lateness causes a Complaint.
# d-separation via the "ancestral moral graph" method
PARENTS = { # a bigger campus network for Bolt
"Rain": [], "Sprinkler": [], "Battery": [],
"WetPath": ["Rain", "Sprinkler"],
"Slip": ["WetPath"],
"Late": ["Slip", "Battery"],
"Complaint": ["Late"],
}
def ancestors(nodes):
result, stack = set(nodes), list(nodes)
while stack:
for par in PARENTS[stack.pop()]:
if par not in result:
result.add(par); stack.append(par)
return result
def d_separated(X, Y, Z):
"""True if every path between X and Y is blocked given evidence Z."""
keep = ancestors(set(X) | set(Y) | set(Z)) # 1. keep only ancestors
edges = {n: set() for n in keep}
for child in keep: # 2. moralize: link each node to its parents
ps = PARENTS[child] # and "marry" co-parents
for a in ps:
edges[a].add(child); edges[child].add(a)
for b in ps:
if a != b: edges[a].add(b)
seen, stack = set(X), list(X) # 3. delete Z, check if X still reaches Y
while stack:
for nb in edges[stack.pop()]:
if nb not in seen and nb not in Z:
if nb in Y: return False
seen.add(nb); stack.append(nb)
return True
tests = [
(["Rain"], ["Sprinkler"], []), # common effect, nothing observed
(["Rain"], ["Sprinkler"], ["WetPath"]), # observe the common effect
(["Rain"], ["Sprinkler"], ["Complaint"]), # observe a DESCENDANT of the common effect
(["Rain"], ["Late"], []), # causal chain
(["Rain"], ["Late"], ["Slip"]), # chain, middle observed
(["Battery"], ["Rain"], []),
(["Battery"], ["Rain"], ["Late"]), # explaining away
]
for X, Y, Z in tests:
verdict = "independent" if d_separated(X, Y, Z) else "DEPENDENT"
print(f"{X[0]:9s} vs {Y[0]:9s} given {str(Z):15s}: {verdict}")Rain vs Sprinkler given [] : independent
Rain vs Sprinkler given ['WetPath'] : DEPENDENT
Rain vs Sprinkler given ['Complaint'] : DEPENDENT
Rain vs Late given [] : DEPENDENT
Rain vs Late given ['Slip'] : independent
Battery vs Rain given [] : independent
Battery vs Rain given ['Late'] : DEPENDENT
Line 3 is the subtle one. Observing a complaint (a descendant of the WetPath collider) opens the path between Rain and Sprinkler: a complaint is evidence that the path was wet, and the two possible causes start competing again. The last line is explaining away across a longer distance. If Bolt is late, learning that it rained makes "low battery" a less necessary explanation.
- List every undirected path between X and Y.
- For each path, label every intermediate node as chain, fork or collider for that path.
- A path is blocked if any chain/fork node is observed, or any collider is unobserved with no observed descendants.
- Independent only if all paths are blocked.
The usual mistake is forgetting that observing a collider's descendant also opens it.