🕸️ Bayesian Networks — Live DAG Inference & MCMC
Interactive Bayesian network in 3D: click nodes to set evidence and watch exact enumeration and live Gibbs-sampling MCMC recompute posterior beliefs across a directed acyclic graph of conditional probability tables.
About Bayesian Networks
A Bayesian network compactly represents a joint probability distribution as a directed acyclic graph (DAG): nodes are random variables, edges point from each parent to the children it directly influences, and every node stores a conditional probability table (CPT) of P(node | parents(node)). The graph's Markov property — a node is conditionally independent of its non-descendants given only its parents — lets the joint distribution factorise as a product of small local CPTs instead of one exponentially large table, which is what makes both exact and approximate inference tractable on realistically sized networks.
This simulator implements two independent inference engines side by side on the same graph. Exact inference enumerates every assignment of the hidden variables consistent with the evidence you've set by clicking nodes, sums their joint probabilities (each a product of CPT lookups along the DAG), and normalises — the same principle behind variable elimination and belief propagation, just without their computational shortcuts. Gibbs sampling, a Markov Chain Monte Carlo (MCMC) method, instead repeatedly resamples one variable at a time from its exact conditional distribution given its Markov blanket, and the running fraction of sweeps where the query variable was true converges toward the exact posterior as more samples accumulate.
Frequently Asked Questions
What is a Bayesian network?
A Bayesian network is a directed acyclic graph (DAG) whose nodes are random variables and whose edges point from each variable to the ones it directly influences. Every node stores a conditional probability table (CPT) giving P(node | its parents). Because of the graph's Markov property, a node is conditionally independent of its non-descendants given its parents, so the full joint distribution factorises as the product of every node's CPT entry instead of one exponentially large table.
What does clicking a node do in this simulation?
Clicking a sphere cycles that variable through Unknown, True and False, fixing it as observed evidence. Every other node's colour is then its exact posterior marginal P(node = True | evidence), recomputed instantly by enumerating every consistent assignment of the remaining hidden variables and summing their joint probabilities.
How does the exact enumeration inference work here?
With five or fewer binary variables there are at most 32 possible full assignments. For each one consistent with the fixed evidence, the simulator multiplies every node's CPT entry together to get that assignment's joint probability, then sums those probabilities grouped by whether each variable is true, and divides by the total evidence-consistent mass — the textbook enumeration algorithm behind variable elimination and belief propagation.
What is Gibbs sampling / MCMC and why does its estimate wobble?
Gibbs sampling repeatedly resamples one non-evidence variable at a time from its exact conditional distribution given its Markov blanket (its parents, its children, and its children's other parents), leaving every other variable fixed. Averaging the fraction of sweeps where the query variable was true estimates its posterior probability. Because each sample is random, the running estimate wobbles early on and only settles near the exact value after enough sweeps.
What is a Markov blanket?
A variable's Markov blanket is the set of nodes that fully determine its conditional distribution: its parents, its children, and any other parents of those children. Given its Markov blanket, a variable is conditionally independent of every other node in the network.
Why do the two example networks matter?
The Alarm network (Burglary, Earthquake to Alarm to JohnCalls, MaryCalls) shows how two independent causes can compete to explain one observed effect — explaining away. The Sprinkler network (Cloudy to Sprinkler and Rain to WetGrass) shows a common cause creating a spurious correlation between two effects that vanishes once the cause is observed.
Is this simulation using real probability numbers?
Yes. The conditional probability tables are the standard published values for the Alarm and Sprinkler networks from Pearl's and Russell & Norvig's textbook presentations. Both the exact enumeration and the Gibbs-sampling MCMC operate on those real CPTs.
Interactive Bayesian network in 3D: click nodes to set evidence and watch exact enumeration and live Gibbs-sampling MCMC recompute posterior beliefs across a directed acyclic graph of conditional probability tables.
3D · Three.js / WebGL renderer · 60 FPS target · runs fully client-side, no install