Probability

Bayesian Networks

A Bayesian network turns a DAG into a compact joint distribution by storing local conditionals and reading independence from blocked or active trails.

status: reviewimportance: importantdifficulty 4/5math: graduateread: 22mlive demo

Concept Structure

Bayesian Networks

01Intuition

Start with the picture, metaphor, or geometric mechanism.

02Math

Make the objects explicit and connect them with notation.

03Code

Mirror the equations with runnable implementation details.

04Interactive Demo

Manipulate the mechanism and watch the idea respond.

2prerequisites
5next concepts
4related links

Learner Contract

What this page should let you do.

You are here becauseA Bayesian network turns a DAG into a compact joint distribution by storing local conditionals and reading independence from blocked or active trails.

This Probability concept is the current idea: keep the same invariant visible across Intuition, Math, Code, Interactive Demo.

By the end4/4 sections ready | runnable code expected | live demo

Explain the mechanism, trace the main notation, and test one prediction in the live demo.

Do this firstIntuition

Read the intuition before the notation; the math should name a mechanism you already felt.

Then go nextd-Separation (review)

Follow this edge after making one prediction here; the next page should reuse the result, not restart the route.

Test the linkManipulate one control and predict the visible change.Then continue to d-Separation (review)

Claim/source review status

Substantive review recorded

1/1 claims have bounded review metadata; still check caveats and source scope.Metadata-derived; review may be AI-assisted. Not a human certification.
Claims1/1 reviewed
Sources4 cited
Codeattached
Demolive
Reviewed2026-07-02
Updatedpage 2026-07-02

Learning item flow

4/4 sections readyAsk about thisResearch room
ConceptBayesian NetworksProbability
4 sources attachedLocal snapshot ready
concept:probability/bayesian-networks
01

01

Intuition

Build the mental picture first so the rest of the page has something to attach to.

Section prompt

A Bayesian network is a directed graph that carries probability.

Each node is a random variable. Each arrow says that one variable is allowed to appear in another variable's local conditional distribution. If the graph is a directed acyclic graph, or DAG, we can order the variables so every arrow points forward and write the joint distribution as a product of small local pieces.

That is the first reason Bayesian networks matter. A full joint table over six binary variables needs

261=632^6-1=63

independent probabilities. A Bayesian network can need far fewer if each node has only a few parents. The graph is a compression of assumptions.

The second reason is conceptual. The graph tells us which dependencies are supposed to be direct and which ones are only induced through paths. A fork such as

SCRS \leftarrow C \rightarrow R

says Sprinkler and Rain can be associated because both depend on Cloudy. Once Cloudy is known, that path is blocked.

A collider such as

SWRS \rightarrow W \leftarrow R

behaves the other way around. If Wet Grass is unobserved, that path is closed. If Wet Grass is observed, Sprinkler and Rain can become coupled by explaining the same evidence. This is the small idea behind "explaining away."

The graph does not choose the actual numbers. You still need conditional probability tables, conditional densities, or learned conditional models. But the graph chooses the local questions:

  • How likely is Sprinkler given Cloudy?
  • How likely is Wet Grass given Sprinkler and Rain?
  • How likely is Late given Wet Grass and Traffic?

Those questions are small enough to inspect, learn, update, and later pass to inference algorithms.

02

02

Math

Translate the story into symbols, assumptions, and a derivation you can inspect.

Section prompt

Let

X=(X1,,Xd)X=(X_1,\ldots,X_d)

be random variables. A Bayesian network consists of:

  1. a DAG GG whose nodes are X1,,XdX_1,\ldots,X_d;
  2. one local conditional distribution for each node:
P(Xipa(Xi)),P(X_i \mid \mathrm{pa}(X_i)),

where pa(Xi)\mathrm{pa}(X_i) is the parent set of XiX_i in the DAG.

The joint distribution factorizes as

P(X1,,Xd)=i=1dP(Xipa(Xi)).P(X_1,\ldots,X_d) = \prod_{i=1}^{d}P(X_i\mid \mathrm{pa}(X_i)).

For the lab graph, define six binary variables:

C=Cloudy,S=Sprinkler,R=Rain,W=Wet Grass,T=Traffic,L=Late.C=\text{Cloudy},\quad S=\text{Sprinkler},\quad R=\text{Rain},\quad W=\text{Wet Grass},\quad T=\text{Traffic},\quad L=\text{Late}.

The arrows are

CS,CR,SW,RW,RT,WL,TL.C\to S,\quad C\to R,\quad S\to W,\quad R\to W,\quad R\to T,\quad W\to L,\quad T\to L.

The factorization is therefore

P(C,S,R,W,T,L)=P(C)P(SC)P(RC)P(WS,R)P(TR)P(LW,T).P(C,S,R,W,T,L) = P(C)\,P(S\mid C)\,P(R\mid C)\,P(W\mid S,R)\,P(T\mid R)\,P(L\mid W,T).

For binary variables, a node with kk binary parents needs one independent probability for each parent assignment:

2k.2^k.

So the number of independent conditional-table parameters is

1+2+2+4+2+4=15.1 + 2 + 2 + 4 + 2 + 4 = 15.

This is much smaller than the 6363 parameters in an unconstrained six-variable binary joint table.

The graph also gives conditional-independence claims. A useful local version is:

Xinon-descendants of Xipa(Xi).X_i \perp \text{non-descendants of }X_i \mid \mathrm{pa}(X_i).

For example, Traffic has parent Rain. Once Rain is known, Traffic is separated from upstream variables such as Cloudy and Sprinkler, and from Wet Grass unless we condition on their common child Late.

Global independence claims are read through paths. A path is active or blocked depending on which variables are observed:

  • A chain ABCA\to B\to C is blocked when BB is observed.
  • A fork ABCA\leftarrow B\to C is blocked when BB is observed.
  • A collider ABCA\to B\leftarrow C is closed by default, but opens when BB or one of its descendants is observed.

That last rule is the one many learners miss. Evidence can create dependence. If Cloudy is already known, Sprinkler and Rain are independent through their common cause. But observing Wet Grass opens the collider

SWR,S\to W\leftarrow R,

so evidence for Sprinkler can reduce the need to explain Wet Grass by Rain, and vice versa.

03

03

Code

Keep the implementation aligned with the notation so the algorithm is legible.

Section prompt
from itertools import product

nodes = ["C", "S", "R", "W", "T", "L"]
parents = {
    "C": (),
    "S": ("C",),
    "R": ("C",),
    "W": ("S", "R"),
    "T": ("R",),
    "L": ("W", "T"),
}

def binary_bn_parameter_count(parent_map):
    return sum(2 ** len(parent_map[node]) for node in nodes)

def joint_probability(assignment, cpts):
    prob = 1.0
    for node in nodes:
        parent_values = tuple(assignment[parent] for parent in parents[node])
        prob *= cpts[node][parent_values][assignment[node]]
    return prob

print("full joint parameters:", 2 ** len(nodes) - 1)
print("BN parameters:", binary_bn_parameter_count(parents))
print("factorization:")
for node in nodes:
    ps = parents[node]
    print(f"P({node}" + (f" | {','.join(ps)})" if ps else ")"))

The code is intentionally small: it does not run inference. It pins the object that inference algorithms later manipulate. A query algorithm such as variable elimination takes the local factors in this product, multiplies and sums them in a careful order, and avoids constructing the full 262^6 joint table when the graph is sparse enough.

04

04

Interactive Demo

Use direct manipulation to connect the explanation to a moving system.

Section prompt

The lab below asks you to predict what the graph encodes before it reveals the factor ledger or active trail. The same six-node DAG will be reused later for d-separation and variable elimination.

Live Concept Demo

Explore Bayesian Networks

The stage is code-native and interactive. Use it to test the explanation against the mechanism.

difficulty 4/5graduatecode-aligned
Demo Prediction Checkpoint

Manipulate one control and predict the visible change.

Commit to what Bayesian Networks should make visible before reading the result.

After The First Pass

Turn the concept into an inspected object.

Once the invariant is visible in the intuition, math, code, and demo, use these panels to inspect the mechanism visually, check source support, practice the idea, and attach a grounded research question.

Mechanism Storyboard

See the idea move before the page explains it

A Bayesian network turns a DAG into a compact joint distribution by storing local conditionals and reading independence from blocked or active trails.

Prediction open01 / Intuition
Prediction lens

Start with the picture, metaphor, or geometric mechanism.

Commit first

Before reading further, choose the kind of change Bayesian Networks should make visible.

Visual Inquiry

Make the image answer a mathematical question

A Bayesian network turns a DAG into a compact joint distribution by storing local conditionals and reading independence from blocked or active trails.

4/4 stages readyLive demo connected
Prediction

Which visible object should carry the first intuition?

Commit first

Pick the cue that should make Bayesian Networks easier to reason about before the page gives the answer.

Source Grounding

Canonical references for the mechanism on this page.

course-notes · 2026Stanford CS228 Notes: Bayesian NetworksStanford CS228

Grounds Bayesian networks as DAGs whose joint distributions factor into local conditionals over parent sets, plus local conditional-independence semantics.

Open source
course-notes · 2026Stanford CS228 Notes: Variable EliminationStanford CS228

Supports exact inference as factor manipulation and motivates keeping the factorization visible before later inference algorithms.

Open source
book · 2022Probabilistic Machine Learning: An IntroductionKevin P. Murphy

Probabilistic-ML reference for directed graphical models, Bayesian-network structure, conditional independence, and inference context.

Open source
book · 2009Probabilistic Graphical Models: Principles and TechniquesDaphne Koller and Nir Friedman

Canonical PGM reference for the semantics of Bayesian networks, local Markov assumptions, and d-separation.

Open source

Claim Review

A Bayesian network turns a DAG into a compact joint distribution by storing local conditionals and reading independence from blocked or active trails.

Status1 substantive review recorded

Claims without a substantive review badge still need exact source-support review.

Sources4 references

cs228-directed-graphical-models, cs228-variable-elimination, murphy-2022-probabilistic-ml, koller-friedman-2009-pgm

Local checks4 local checks

Use equations, runnable code, and demos to check whether the source support is operational.

Substantively reviewedA Bayesian network is a DAG plus local conditional probability models; the DAG licenses the factorization P(x1,...,xd)=prod_i P(x_i | pa_i) and conditional-independence claims read from active or blocked trails.Claim metadata: source checked

The sources support the page's finite-DAG factorization, parent-set CPT parameter accounting for binary variables, local Markov reading, and the fork/chain/collider active-trail cases used by the lab.

Sources: Stanford CS228 Notes: Bayesian Networks, Stanford CS228 Notes: Variable Elimination, Probabilistic Machine Learning: An Introduction, Probabilistic Graphical Models: Principles and TechniquesFinite binary teaching graph only; excludes continuous conditional densities, structure learning, parameter learning beyond CPT counting, approximate inference details, decision networks, dynamic Bayesian networks, and a GPT Pro publication pass.A bounded review summary is present; still check caveats and exact reference scope.

Checked Stanford CS228 directed-model notes for the DAG factorization and local independence semantics, CS228 variable-elimination notes for exact inference as factor manipulation, Murphy's ProbML for directed graphical-model context, and Koller/Friedman as the canonical PGM reference for local Markov/d-separation semantics. GPT Pro publication critique remains pending.

Reviewer: codex-local-source-review; reviewed 2026-07-02

Practice Loop

Try the idea before it explains itself

A Bayesian network turns a DAG into a compact joint distribution by storing local conditionals and reading independence from blocked or active trails.

Readiness0/3 checks ready
Predict

Before touching the demo, predict one visible change that should happen in Bayesian Networks.

Hint 1

Reveal when your model needs a nudge.

Hint 2

Reveal when your model needs a nudge.

Hint 3

Reveal when your model needs a nudge.

Grounded research drawerClose
ConceptBayesian NetworksProbability

Research Room

Attach the question to a claim, equation, code, or demo

Pick the concept, equation, source, runnable code, claim, misconception, or demo state before asking for help. The handoff keeps that page item in context.
Next local actionNo local draft saved yet

Open the draft below to save one note and next action in this browser.

conceptProbability

Bayesian Networks

Attached question

What is the smallest example that makes Bayesian Networks click without losing the math?

Local action draftNo local draft saved yetExpand only when ready to capture one local next action
Local action draft

This draft stays in this browser, attached to the selected learning item.

No local draft saved.
Evidence to inspect
  • References to inspect: attached references on this page.
  • Definition, prerequisite, and contrast concept links
  • The equation or runnable code that makes the concept operational
  • One demo state that shows the invariant instead of a slogan
What would resolve this
  • The learner can state the mechanism in their own words
  • The learner can name the prerequisite that would repair confusion
  • The learner can predict how the mechanism changes under one perturbation
Grounded AI handoff

I am working in Continuous Function's research reading room. Object: concept - Bayesian Networks Selected item key: recorded for copy. Context: Probability Page anchor: recorded for copy. Open question: What is the smallest example that makes Bayesian Networks click without losing the math? Evidence to inspect: - References to inspect: attached references on this page. - Definition, prerequisite, and contrast concept links - The equation or runnable code that makes the concept operational - One demo state that shows the invariant instead of a slogan What would resolve this: - The learner can state the mechanism in their own words - The learner can name the prerequisite that would repair confusion - The learner can predict how the mechanism changes under one perturbation Answer as a careful research tutor: stay source-grounded, separate verified evidence from assumptions, name the relevant math objects, and end with one next action.

View it in context
concept/concept-notebook/probability/bayesian-networks concept:probability/bayesian-networks