Bayesian Networks and Probabilistic DAG Inference in AI

A full joint probability distribution table over ( n ) boolean random variables requires ( 2^n - 1 ) independent probability values — an exponential storage and computational nightmare for real-world problems with hundreds of variables. Bayesian Networks (also known as Belief Networks or Causal Networks, pioneered by Judea Pearl) solve this by exploiting conditional independence relationships to represent full joint distributions compactly in polynomial space.

Formal Definition of a Bayesian Network

A Bayesian Network is a structured probabilistic representation composed of two parts:

  1. A Directed Acyclic Graph (DAG): Nodes represent random variables (discrete or continuous), and directed edges represent direct causal or probabilistic dependencies.
  2. Conditional Probability Tables (CPTs): For every node ( X_i ) in the graph, a local conditional distribution specifying the probability of ( X_i ) given each combination of values for its immediate parents: ( P(X_i | ext{Parents}(X_i)) ).

The Master Joint Distribution Factorization

The fundamental theorem of Bayesian networks states that the complete joint probability distribution over all variables ( X_1, dots, X_n ) is equal to the product of local conditional distributions:

( P(X_1, X_2, dots, X_n) = prod_{i=1}^n P(X_i | ext{Parents}(X_i)) )

If each variable has at most ( k ) parents, the entire network requires only ( O(n cdot 2^k) ) numbers, shrinking exponential complexity into compact linear storage!

The Classic Alarm Network (Judea Pearl)

Consider Pearl's famous burglar alarm scenario:

  • A burglar (( B )) or an earthquake (( E )) can set off your home alarm (( A )).
  • If the alarm sounds, your neighbors John (( J )) and Mary (( M )) may call you at work.
Node / Variable Parents Conditional Probability Table (CPT) Entries
Burglary (( B )) None (Root) ( P(B = ext{True}) = 0.001 )
Earthquake (( E )) None (Root) ( P(E = ext{True}) = 0.002 )
Alarm (( A )) ( B, E ) ( P(A | B, E) = 0.95 )
( P(A | B, eg E) = 0.94 )
( P(A | eg B, E) = 0.29 )
( P(A | eg B, eg E) = 0.001 )
JohnCalls (( J )) ( A ) ( P(J | A) = 0.90 ),   ( P(J | eg A) = 0.05 )
MaryCalls (( M )) ( A ) ( P(M | A) = 0.70 ),   ( P(M | eg A) = 0.01 )

Calculating a Joint Probability: What is the probability that both John and Mary call, the alarm went off, but there was neither burglary nor earthquake?

( P(J wedge M wedge A wedge eg B wedge eg E) = P( eg B) cdot P( eg E) cdot P(A | eg B, eg E) cdot P(J | A) cdot P(M | A) )
( = (0.999) imes (0.998) imes (0.001) imes (0.90) imes (0.70) = 0.000628 )

D-Separation (Directional Separation)

D-Separation is a formal graph-theoretic criterion determining whether a set of variables ( X ) is conditionally independent of another set ( Y ) given observed evidence ( Z ). A path between ( X ) and ( Y ) is blocked if it contains:

  1. Causal Chain (( X ightarrow Z ightarrow Y )): Blocked if ( Z ) is observed.
  2. Common Cause / Fork (( X leftarrow Z ightarrow Y )): Blocked if ( Z ) is observed.
  3. Common Effect / Collider / V-Structure (( X ightarrow Z leftarrow Y )): The path is blocked if neither ( Z ) nor any of ( Z )'s descendants are observed. Observing the collider ( Z ) activates the path, inducing dependence (an effect known as "explaining away").

The Markov Blanket

In a Bayesian network, a node ( X ) is conditionally independent of all other nodes in the entire network, given its Markov Blanket. The Markov Blanket of node ( X ) consists of:

  • Its parents
  • Its children
  • All other parents of its children (co-parents)

Python Implementation: Computing Joint Probabilities in a Bayesian Network

The following script evaluates exact joint probabilities using Pearl's Alarm network parameters:

def compute_joint_prob(burglary, earthquake, alarm, john, mary):
    # CPT Definitions
    p_b = 0.001 if burglary else 0.999
    p_e = 0.002 if earthquake else 0.998

    # Alarm CPT lookup
    alarm_table = {
        (True, True): 0.95,
        (True, False): 0.94,
        (False, True): 0.29,
        (False, False): 0.001
    }
    prob_a_true = alarm_table[(burglary, earthquake)]
    p_a = prob_a_true if alarm else (1.0 - prob_a_true)

    # JohnCalls CPT
    p_j = (0.90 if alarm else 0.05) if john else (0.10 if alarm else 0.95)
    # MaryCalls CPT
    p_m = (0.70 if alarm else 0.01) if mary else (0.30 if alarm else 0.99)

    # Master Chain Factorization Product
    joint_probability = p_b * p_e * p_a * p_j * p_m
    return joint_probability

# Case 1: Alarm triggers without burglary or earthquake, both neighbors call
prob_false_alarm = compute_joint_prob(False, False, True, True, True)
print(f"P(J, M, A, ~B, ~E) = {prob_false_alarm:.8f}")

# Case 2: Real Burglary occurs, alarm fires, both call
prob_true_burglary = compute_joint_prob(True, False, True, True, True)
print(f"P(J, M, A, B, ~E)  = {prob_true_burglary:.8f}")

Frequently Asked Questions (FAQ) - Student & Interview Review

Q1. Why are directed cycles forbidden in Bayesian Networks?

Cycles are forbidden because a Bayesian Network represents a joint probability distribution factorized via the chain rule of probability. A directed cycle (A -> B -> A) would introduce circular definitions (A depends on B, which depends on A), making it impossible to compute a consistent joint probability.

Q2. What is 'explaining away' in a Bayesian collider?

Explaining away occurs in v-structures (X -> Z <- Y). Initially, independent causes X and Y are uncorrelated. But if we observe the common effect Z (e.g., the grass is wet), learning that it rained (X) explains away the wet grass, drastically reducing the probability that the sprinkler (Y) was on.

Q3. What are the common algorithms used for Bayesian Network inference?

Exact inference algorithms include Enumeration, Variable Elimination (dynamic programming that sums out irrelevant variables), and the Junction Tree algorithm. For large networks where exact inference is NP-hard, approximate inference algorithms are used: Rejection Sampling, Likelihood Weighting, and Markov Chain Monte Carlo (MCMC / Gibbs Sampling).

Q4. What is the relationship between Bayesian Networks and modern Deep Learning?

Bayesian Networks provide explicit causal semantics and probabilistic interpretability. In modern AI, they form the basis of Variational Autoencoders (VAEs), Bayesian Neural Networks (which output uncertainty bounds rather than point predictions), and causal AI frameworks.

Explore Related Artificial Intelligence Tutorials & Next Steps

Broaden your foundational and advanced AI knowledge across our curriculum:

Probability & Bayes' Theorem

Conditional probability, prior, likelihood, and posterior distributions.

Machine Learning Paradigms

Transition from Bayesian probabilistic graphs to statistical learning.

Evaluation Metrics & ROC-AUC

Measuring classification performance and probabilistic calibration.

BCA & University Viva-Voce Guide

Exam questions on D-separation, Markov blanket, and joint probability.

Share Share on Facebook Share on Twitter Share on LinkedIn Pin on Pinterest Share on Reddit

You may also like this!