← back to EEE 485
Week 12125 min full read
7 concepts24 worked examples32 exercises5 exam-level7 figures
What are you here for?

12 Probabilistic graphical models: directed graphs, d-separation, naive Bayes, undirected graphs and image denoising

Start with this

One question before you read anything. Getting it wrong is the point: it shows you what this section is for.

§12.2 — two coins behind one lamp

Two fair coins are tossed separately, so their results are independent. A lamp lights whenever at least one coin shows heads. You cannot see the coins, only the lamp, and the lamp is lit.

Find(a) What is the probability that coin 2 shows heads?
Given
  • $p(\text{heads})=\tfrac12$ for each coin, tossed independently

  • the lamp lights if and only if at least one coin shows heads

  • observed: the lamp is lit

Hint 1/4

Ask which outcomes of the two coins are still possible once you know the lamp is lit.

Hint 2/4

$$p(H_2\mid\text{lit})=\frac{p(H_2,\text{lit})}{p(\text{lit})}$$

Hint 3/4

The outcomes $HH, HT, TH, TT$ each have probability $1/4$; the lamp is lit for $HH, HT, TH$, and coin 2 shows heads in $HH$ and $TH$.

Hint 4/4

Two of the three lit outcomes have coin 2 heads, so the answer is $2/3$.

Show solution

List the four equally likely outcomes and keep the ones that light the lamp: faster than Bayes' rule with symbols, and it shows the answer directly.

The outcomes that light the lamp

$$\begin{aligned}&HH,\ HT,\ TH\ \text{light it}\\ &TT\ \text{does not}\end{aligned}$$

Each of the four outcomes has probability $1/4$ because the coins are fair and independent.

Condition on the lamp

$$p(H_2\mid\text{lit})=\frac{p(HH)+p(TH)}{p(\text{lit})}=\frac{1/2}{3/4}=\frac23$$

Of the three lit outcomes, two have coin 2 showing heads.

Answer $$\boxed{p(H_2\mid\text{lit})=\tfrac23}$$
Check

Bayes' rule: $p(\text{lit}\mid H_2)\,p(H_2)/p(\text{lit})=1\cdot\frac12\big/\frac34=\frac23$.

Seeing a common effect of two independent causes changes what we believe about each: the lamp alone moves coin 2 from $1/2$ to $2/3$.

A solar-powered sensor at a field station sends one packet every night, and tonight none arrived. A low battery or radio interference can each stop a packet, and on a normal night each happens $1$ time in $10$. Then a storm report says the radio band was jammed all night: should the technician worry more or less about the battery?

By the end you can put numbers on it: out of $1000$ nights with a lost packet the battery is low on about $597$, and out of $1000$ such nights with a storm, on only about $174$.

In 60 seconds

A graphical model writes a joint distribution as a product that a graph dictates: one factor $p(x_j\mid\mathrm{pa}_j)$ per node of a directed graph, one potential per maximal clique of an undirected one. The same graph tells which variables are independent given which.

Directed
$$p(x_1,\dots,x_D)=\prod_{j=1}^{D}p(x_j\mid\mathrm{pa}_j)$$

writing the joint of a , counting its numbers, or sampling parents first

Blocked path
$$\begin{aligned}&v\in C\text{ and head-to-tail}\\ &\qquad\text{or tail-to-tail, or}\\ &v\text{ head-to-head, }v\notin C,\\ &\qquad\mathrm{de}(v)\cap C=\varnothing\end{aligned}$$

deciding $A\perp\!\!\!\perp B\mid C$: every path from $A$ to $B$ must contain such a node

Naive Bayes, Bernoulli features
$$\begin{aligned}\hat c&=\arg\max_c\ \hat\pi_c\prod_{j}\big[\hat\theta_{jc}^{\,I(x_j=1)}\\ &\qquad\qquad\times(1-\hat\theta_{jc})^{I(x_j=0)}\big]\\ \hat\pi_c&=\frac{n_c}{n},\qquad \hat\theta_{jc}=\frac{n_{jc}}{n_c}\end{aligned}$$

classifying from binary features after counting the training data

Undirected factorization
$$\begin{aligned}&p(x)=\frac1Z\prod_{c\in M}\psi_c(x_c)\\ &Z=\sum_x\prod_{c\in M}\psi_c(x_c)\end{aligned}$$

an undirected graph with non-negative potentials; $\psi_c=e^{-E(x_c)}$ gives the

Three most common mistakes
  1. Treating an observed head-to-head node as a blocker. Observing $c$ in $a\to c\leftarrow b$, or any of $c$, makes $a$ and $b$ dependent: a lost packet couples the battery and the interference.

  2. Dividing $n_{jc}$ by $n$ instead of $n_c$. $\hat\theta_{jc}=n_{jc}/n_c$ is a rate inside class $c$; only the class share $\hat\pi_c=n_c/n$ uses $n$.

  3. Leaving the co-parents out of a directed Markov blanket, or adding them to an undirected one. Directed: parents, children and the children's other parents. Undirected: the neighbours only.

Two course documents give different weights:

  • Chapter 1 slides, undergraduate line: midterm 25, final 25, four quizzes 20, two-phase project 30.
  • STARS syllabus page printed on 21 September 2026: midterm 30, final 30, problem sets and quizzes 20, project 20. It is the later document; confirm which split applies.
  • The STARS weekly list has graphical models as its tenth item and names naive Bayes in its eleventh; the lecture slides teach both in chapter 12.
How much time do you have?
10 minutes

The three procedures of the section: write a factorization, decide independence by d-separation, train and use naive Bayes.

The 60-second card · Directed graphs: one factor per node · D-separation: when every path is blocked · Naive Bayes · Formula card
45 minutes

Every block once with its first worked example, then naive Bayes from fully worked to bare.

The 60-second card · Directed graphs: one factor per node · Three ways two arrows meet · D-separation: when every path is blocked · Naive Bayes · The Markov blanket · Markov random fields · Image denoising · Scaffolding comes off · Formula card
full read

Adds the proofs, the look-alike pairs, a full exam-style question and mixed practice where you pick the method yourself.

The opening pages · Recall first · Directed graphs: one factor per node · Three ways two arrows meet · D-separation: when every path is blocked · Naive Bayes · The Markov blanket · Markov random fields · Image denoising · Look-alike pairs · Method boxes · Scaffolding comes off · Full exam-style question · Practice set · Check yourself
By the end of this section
  1. Write the joint distribution of a directed acyclic graph as a product of parent conditionals, count its free numbers, and draw a sample by .

  2. Decide what observing the middle node does in the tail-to-tail, head-to-tail and head-to-head graphs, and compute an explaining-away posterior by enumeration.

  3. Apply d-separation to decide whether $A\perp\!\!\!\perp B\mid C$ in a directed graph, checking every path.

  4. Train a by maximum likelihood, with counts for Bernoulli features and class means and variances for Gaussian ones, and classify a new point.

  5. Find the Markov blanket of a node in a directed graph and compute $p(x_i\mid x_{j\ne i})$ from the blanket's factors alone.

  6. List the cliques and maximal cliques of an undirected graph, write its factorization with potentials and $Z$, and read by separation.

  7. Write the energy of the image-denoising model and run coordinate-wise updates until a full sweep changes nothing.

Syllabus coverage

Probabilistic graphical models — covered

  • Directed acyclic graphs and the factorization of the joint
  • the chain rule as the complete graph
  • parameter counts
  • ancestral sampling
  • undirected graphs, cliques and potentials

The lecturer's chapter title. The chapter moves from directed to undirected models, and so does this section.

Inference in graphical models — covered

Conditional independence read off the graph: the three-node rules, d-separation, Markov blankets and separation in undirected graphs. Posteriors by enumeration and explaining away, the naive Bayes posterior, and the most probable image by coordinate-wise energy descent.

Several blocks share this token; the explaining-away example is where it first appears.

Learning in graphical models — covered

Maximum likelihood for a naive Bayes classifier: counts for Bernoulli features, class means and variances for Gaussian ones, and the Lagrange multiplier behind the class shares.

The STARS weekly list names naive Bayes in its eleventh item, beside restricted Boltzmann machines; the chapter 12 slides teach it here, so this section covers it.

Pseudo-counts against zero counts — off syllabus

Adding one imaginary success and one imaginary failure to every naive Bayes count, so that no estimate is exactly $0$ or $1$.

Further reading, not on the slides. It appears in one interleaved question, where it links naive Bayes with the Beta prior of the Bayesian estimation section.

Gaussian naive Bayes and logistic regression — off syllabus

With one variance shared by both classes, the naive Bayes log-odds is linear in $x$.

Further reading, used in one interleaved question only.

Recall first
Conditional probability and Bayes' rule

$p(a\mid b)=\dfrac{p(a,b)}{p(b)}$ for $p(b)>0$, and $p(a\mid b)=\dfrac{p(b\mid a)\,p(a)}{\sum_{a'}p(b\mid a')\,p(a')}$.

Every posterior on this page, from explaining away to naive Bayes, is this formula.

Summing out

$p(a)=\sum_b p(a,b)$, and $p(a\mid e)=\sum_b p(a,b\mid e)$; for a continuous $b$ the sum is an integral.

Inference by enumeration sums the joint over every variable that was not observed.

Independence

$a$ and $b$ are independent when $p(a,b)=p(a)\,p(b)$ for every pair of values.

Conditional independence is the same test inside the distribution given $c$.

Maximum likelihood estimates

$\hat\theta=\arg\max_\theta\sum_i\log p(x_i\mid\theta)$. Bernoulli: successes over trials. Gaussian: $\hat\mu=\frac1n\sum_ix_i$ and $\hat\sigma^2=\frac1n\sum_i(x_i-\hat\mu)^2$.

Naive Bayes is trained with exactly these estimates, one class at a time.

Lagrange multipliers

To maximize $f(\pi)$ subject to $g(\pi)=0$, solve $\nabla f=\lambda\nabla g$ together with $g(\pi)=0$.

The class shares must add up to $1$, and the multiplier enforces it.

The Gaussian density

$\mathcal N(x\mid\mu,\sigma^2)=\dfrac{1}{\sqrt{2\pi\sigma^2}}\,e^{-(x-\mu)^2/(2\sigma^2)}$.

Gaussian naive Bayes multiplies one such density per feature.

Try it yourself first (2 questions)
1§12.1 — the size of a full joint table

A lab stores the joint distribution of $10$ binary sensor readings as one full table, with a probability for every combination of values.

Find(a) How many numbers in the table can be chosen freely?
Given
  • $10$ sensors, each reading $0$ or $1$

  • the table lists every combination

Hint 1/4

First count the combinations of values, then ask whether all of them are free.

Hint 2/4

$D$ binary variables have $2^D$ combinations; the probabilities add up to $1$.

Hint 3/4

With $D=10$: $2^{10}=1024$ cells, one of them fixed by the other $1023$.

Hint 4/4

The table has $1023$ free numbers.

Show solution

Count the cells, then subtract the one cell that the sum-to-one rule fixes.

Cells

$$2^{10}=1024$$

Each variable doubles the number of value combinations.

Free cells

$$1024-1=1023$$

The cells add up to $1$, so the last one follows from the others.

Answer $$\boxed{1023}$$
Check

Check on $2$ variables: $2^2-1=3$ free numbers, for example $p(00)$, $p(01)$, $p(10)$, with $p(11)$ fixed by the rest.

A full joint table doubles with every new variable; that growth is what graphs are for.

2§12.2 — Bayes' rule for a fire alarm

A building's alarm rings on $90$ of every $100$ days with a fire and, falsely, on $5$ of every $100$ days without one. Fires happen on $1$ day in $100$.

Find(a) The alarm rings. What is the probability of a fire?
Given
  • $p(\text{fire})=0.01$

  • $p(\text{alarm}\mid\text{fire})=0.9$

  • $p(\text{alarm}\mid\text{no fire})=0.05$

Hint 1/4

You need the share of ringing alarms that come from real fires.

Hint 2/4

With $F$ = fire and $A$ = alarm: $$p(F\mid A)=\frac{p(A\mid F)\,p(F)}{p(A\mid F)\,p(F)+p(A\mid\bar F)\,p(\bar F)}$$

Hint 3/4

Numerator $0.9\times0.01=0.009$; the other term is $0.05\times0.99=0.0495$.

Hint 4/4

$0.009/0.0585\approx0.154$.

Show solution

Bayes' rule with the law of total probability in the denominator; the question gives exactly the pieces it needs.

Joint probabilities

$$\begin{aligned}&0.01\times0.9=0.009\\ &0.99\times0.05=0.0495\end{aligned}$$

Prior times likelihood for fire and for no fire.

Normalize

$$\frac{0.009}{0.009+0.0495}=\frac{0.009}{0.0585}=0.154$$

The alarm rings in both situations; fire is the share of alarms that come from fires.

Answer $$\boxed{p(\text{fire}\mid\text{alarm})\approx0.154}$$
Check

Odds route: prior odds $0.01/0.99=0.0101$, times the likelihood ratio $0.9/0.05=18$, gives $0.182$, and $0.182/1.182=0.154$.

A rare cause stays fairly unlikely even after a reliable signal, because false alarms from the common case add up.

Notation
symbolreads asmeanswatch out
$x=(x_1,\dots,x_D)$

x one to x D

the $D$ random variables of the model, one per node

In denoising, $x_i$ is a clean pixel, $+1$ or $-1$.

$\mathrm{pa}_j$

parents of j

the nodes with an arrow into $x_j$

Empty for a root; its factor is then $p(x_j)$.

$a\perp\!\!\!\perp b\mid c$

a independent of b given c

$p(a,b\mid c)=p(a\mid c)\,p(b\mid c)$ for all values

$a\perp\!\!\!\perp b$ with nothing after the bar is plain independence.

$A,\ B,\ C$

sets A, B, C

disjoint sets of nodes; $C$ is the observed set in d-separation

In naive Bayes, $C$ is the number of classes; the context tells which.

$\mathrm{de}(v)$

descendants of v

the children of $v$, their children, and so on

$v$ itself is not one of its descendants.

$y\in\{1,\dots,C\},\ \ \pi_c,\ \ \theta_{jc}$

y; pi c; theta j c

the class label, the share of class $c$, and the parameter of feature $j$ in class $c$

Bernoulli: $\theta_{jc}=p(x_j=1\mid y=c)$. Gaussian: $\theta_{jc}=(\mu_{jc},\sigma^2_{jc})$.

$n,\ \ n_c,\ \ n_{jc}$

n; n c; n j c

training size; points of class $c$; points of class $c$ with $x_j=1$

$n_{jc}$ is counted inside class $c$ only.

$I(\cdot)$

indicator

$1$ if the statement inside is true, else $0$

$\theta^{I(x=1)}(1-\theta)^{I(x=0)}$ picks $\theta$ or $1-\theta$.

$M,\ \ x_c,\ \ \psi_c$

M; x c; psi c

the set of maximal cliques; the variables of clique $c$; its potential

$\psi_c\ge0$, but it is not a probability.

$Z$

Z

$\sum_x\prod_{c\in M}\psi_c(x_c)$, the normalizing constant

A sum over every configuration: $2^D$ terms for $D$ binary nodes.

$E(\cdot),\ \ \beta,\ \ \eta,\ \ h$

E; beta; eta; h

energy with $\psi=e^{-E}$; neighbour, data and bias weights in denoising

Lower energy means higher probability.

Conventions used here
Binary coding.

$1$ means the event happens and $0$ that it does not. In denoising, pixels take $+1$ (white) and $-1$ (black).

The factors and counts are written for these codes.

What 'dependent' means.

When a rule says two variables are dependent, it means: dependent for some choice of the tables, not necessarily for every choice. Independence read off the graph holds for every choice.

The graph knows which factors exist, not their numbers; special numbers can hide a dependence.

Paths ignore direction.

A path is a chain of edges walked either way along an arrow. Directions matter only when we check how the two arrows meet at each node of the path.

Information flows against arrows too, as explaining away shows.

Descendants.

$\mathrm{de}(v)$ holds the children of $v$, their children, and so on, but not $v$ itself.

The head-to-head rule asks about $v$ and $\mathrm{de}(v)$ separately.

Cliques have at least two nodes.

As in the lecture, a clique lists two or more nodes. A single node is trivially fully connected, and some books count it too.

Counts of cliques differ between books for this reason only.

Sampling from a uniform number.

To draw $x$ with $p(x=1)=q$ from $u$ uniform on $[0,1)$, set $x=1$ if $u<q$. With more than two values, cut $[0,1)$ into consecutive pieces in the listed order.

Fixing the rule makes every sampling example checkable.

Sweeps in denoising.

A sweep visits pixels row by row, left to right, and uses each new value at once. If both values give the same energy, the pixel keeps its value.

The order changes intermediate images, and the tie rule keeps the energy strictly falling.

Logs and decimals.

$\log$ is the natural logarithm, except $\log_2$ in the one mutual information question, which follows the feature selection section and counts bits. Numbers are computed from unrounded values and shown to three or four decimals.

Posteriors near $0$ or $1$ need the digits.

12.1Directed graphs: one factor per node

Draw the arrows, and the joint distribution becomes one small factor per node: fewer numbers to store, estimate and sample from.

The probability review handles any joint table; the trouble is its size, which doubles with every new variable.

Solvable with what we have
  • compute $p(L=1\mid F=1)$ once someone hands us the full table of the five sensor variables

  • reverse a conditional with Bayes' rule

  • get a marginal by summing the table

Not solvable yet
  • store that table cheaply: $31$ numbers for five binary variables, $1\,048\,575$ for twenty

  • estimate $31$ numbers from a few weeks of nights, when most combinations never occur

  • say which variables are irrelevant to a question without doing the sums

  • draw a random night without listing all $32$ cells

Keep only the marginal rates, $p(L=1)=0.1$, $p(F=1)=0.1517$, $p(S=1)=0.1526$, and multiply them as if the variables were independent: $p(L=1,F=1,S=1)\approx0.0023$, about $23$ nights in $10\,000$.

Why it fails

A low battery almost always loses the packet, and a lost packet almost always sends the SMS, so the three come together far more often than chance. The linked model below gives about $860$ nights in $10\,000$.

TheoremFactorization of a directed acyclic graph
Conditions
  • the graph is directed and acyclic: no path that follows the arrows returns to its start

  • $\mathrm{pa}_j$ is the set of parents of $x_j$; a root has none and contributes $p(x_j)$

  • each factor is a conditional distribution: for every value of $\mathrm{pa}_j$ it sums to $1$ over $x_j$ (integrates, for a continuous $x_j$)

$$\boxed{p(x_1,\dots,x_D)=\prod_{j=1}^{D}p(x_j\mid\mathrm{pa}_j)}$$

The joint probability of all $D$ variables is a product with one factor per node: the probability of that node's value given the values of its parents. Arrows decide what each factor is conditioned on, and a missing arrow is a condition that was dropped.

Where the product comes from, and why cycles are forbidden

Order the nodes so that parents come before children; acyclicity guarantees such an order. The chain rule in that order is exact for any joint: $p(x_1, \allowbreak \dots, \allowbreak x_D)=\prod_jp(x_j\mid x_1, \allowbreak \dots, \allowbreak x_{j-1})$.

The graph states which earlier variables each $x_j$ still depends on: its parents. Dropping the others from each condition turns the chain rule into the product in the box.

The chain rule itself is the complete graph: node $j$ has every earlier node as a parent, $D(D-1)/2$ arrows in all. Every arrow removed from it is one conditional independence added.

The product is a valid distribution: sum first over a node with no children, whose factor adds up to $1$ and disappears, then repeat. A directed cycle has no such node to start from.

Looks like this, but is not

Any directed graph gives a valid factorization, cycles included: for $a\to b\to a$, take $p(a\mid b)\,p(b\mid a)$.

Let each variable copy the other with probability $0.9$. The four products are $0.81$, $0.01$, $0.01$ and $0.81$, which add up to $1.64$, not $1$. Without a parents-first order there is no node to sum out first.

A low battery, a lost packet and an SMS on the same night

The sensor's graph is $W\to L\to F\leftarrow R$ and $F\to S$, with the tables below. Find $p(L=1,F=1,S=1)$, and compare it with the product of the three marginal rates, $0.1\times0.1517\times0.1526$.

Find$p(L=1,F=1,S=1)$ and its ratio to the independence guess.
Given
  • $p(W=1)=0.5$ (cloudy day), $p(R=1)=0.1$ (interference)

  • $p(L=1\mid W=1)=0.15$, $p(L=1\mid W=0)=0.05$ (low battery)

  • $p(F=1\mid L,R)=0.02,\ \allowbreak 0.5,\ \allowbreak 0.9,\ \allowbreak 0.95$ for $(L,R)=(0,0), \allowbreak (0,1), \allowbreak (1,0), \allowbreak (1,1)$ (lost packet)

  • $p(S=1\mid F=1)=0.95$, $p(S=1\mid F=0)=0.01$ (SMS alert)

Solution

Sum the factored joint over the two variables nobody asked about, $W$ and $R$; each sum then acts only on the factors that contain its variable, so we never write the $32$-cell table.

Write the joint

$$\begin{aligned}&p(W,L,R,F,S)\\ &=p(W)\,p(L\mid W)\,p(R)\\ &\quad\times p(F\mid L,R)\,p(S\mid F)\end{aligned}$$

One factor per node, conditioned on the arrows into it.

Sum out the weather

$$p(L=1)=0.5(0.15)+0.5(0.05)=0.1$$

$W$ appears only in $p(W)$ and $p(L\mid W)$, so its sum touches nothing else.

Sum out the interference

$$p(F=1\mid L=1)=0.9(0.9)+0.1(0.95)=0.905$$

$R$ appears only in $p(R)$ and $p(F\mid L,R)$; with $L=1$ fixed we average over $R$.

Multiply along the chain

$$p(L=1,F=1,S=1)=0.1\times0.905\times0.95=0.0860$$

What is left is $L\to F\to S$ with all three values fixed.

Compare with the independence guess

$$\frac{0.0860}{0.1\times0.1517\times0.1526}=\frac{0.0860}{0.00231}=37$$

The product of marginals ignores both links, $L\to F$ and $F\to S$.

Answer $$\boxed{\begin{aligned}&p(L=1,F=1,S=1)\\ &=0.0860\\ &\text{about }37\times\text{ the guess}\end{aligned}}$$
Check

Bayes-reversal route: $p(L=1\mid F=1)=0.597$ and $p(F=1,S=1)=0.1517\times0.95=0.1441$, so $0.597\times0.1441=0.0860$.

This closes the opening problem: $10$ numbers give $0.086$, while multiplying the marginals gave $0.0023$.

The factorization and the count for a six-node graph

Graph $G$ has the arrows $x_1\to x_2$, $x_1\to x_3$, $x_6\to x_3$, $x_2\to x_4$, $x_3\to x_4$ and $x_4\to x_5$. Write $p(x_1,\dots,x_6)$ and count its free numbers when all six variables are binary, and again when $x_1$ takes three values.

FindThe factorization and the two counts.
Given
  • arrows $x_1\to x_2$, $x_1\to x_3$, $x_6\to x_3$, $x_2\to x_4$, $x_3\to x_4$, $x_4\to x_5$

  • case 1: all binary; case 2: $x_1\in\{1,2,3\}$, the rest binary

Solution

Read the parents node by node from the arrows that point in; the count then follows factor by factor, which is far less error-prone than counting cells of the full table.

Parents of each node

$$\begin{aligned}&\mathrm{pa}_1=\mathrm{pa}_6=\varnothing,\ \ \mathrm{pa}_2=\{x_1\}\\ &\mathrm{pa}_3=\{x_1,x_6\},\ \ \mathrm{pa}_4=\{x_2,x_3\}\\ &\mathrm{pa}_5=\{x_4\}\end{aligned}$$

$x_1$ and $x_6$ have no incoming arrow, so they are roots.

One factor per node

$$\begin{aligned}p(x)&=p(x_1)\,p(x_6)\\ &\quad\times p(x_2\mid x_1)\\ &\quad\times p(x_3\mid x_1,x_6)\\ &\quad\times p(x_4\mid x_2,x_3)\\ &\quad\times p(x_5\mid x_4)\end{aligned}$$

The order of the factors does not matter; each appears once.

Count, all binary

$$1+1+2+4+4+2=14\ \ \text{against}\ \ 2^6-1=63$$

A binary node needs one number per configuration of its parents, $2^{\#\text{parents}}$.

Count, three-valued root

$$2+1+3+6+4+2=18\ \ \text{against}\ \ 3\cdot2^5-1=95$$

$p(x_1)$ now has $2$ free numbers; $p(x_2\mid x_1)$ gets $3$ rows and $p(x_3\mid x_1,x_6)$ gets $3\times2=6$.

Answer $$\boxed{\begin{aligned}&14\ \text{numbers (all binary)}\\ &18\ \text{numbers (}x_1\text{ ternary)}\end{aligned}}$$
Check

Test the rule on the complete graph over $3$ binary nodes, which is the chain rule: $1+2+4=7=2^3-1$, exactly the full table, as it must be.

Count parent configurations, not parents: a factor's size is the product of its parents' numbers of values, times one less than its own.

Drawing one night from the sensor model

Use the sensor tables and the uniform numbers $u_W=0.62$, $u_R=0.07$, $u_L=0.30$, $u_F=0.41$, $u_S=0.97$ to draw one night $(\hat W, \allowbreak \hat R, \allowbreak \hat L, \allowbreak \hat F, \allowbreak \hat S)$ by ancestral sampling.

FindThe sampled night.
Given
  • $p(W=1)=0.5$ (cloudy day), $p(R=1)=0.1$ (interference)

  • $p(L=1\mid W=1)=0.15$, $p(L=1\mid W=0)=0.05$ (low battery)

  • $p(F=1\mid L,R)=0.02,\ \allowbreak 0.5,\ \allowbreak 0.9,\ \allowbreak 0.95$ for $(L,R)=(0,0), \allowbreak (0,1), \allowbreak (1,0), \allowbreak (1,1)$ (lost packet)

  • $p(S=1\mid F=1)=0.95$, $p(S=1\mid F=0)=0.01$ (SMS alert)

  • uniform numbers $u_W=0.62$, $u_R=0.07$, $u_L=0.30$, $u_F=0.41$, $u_S=0.97$

  • rule: $x=1$ if $u<p(x=1\mid\text{parents})$

Solution

Parents first: $W$ and $R$ are roots, $L$ needs $W$, $F$ needs $L$ and $R$, and $S$ needs $F$. Any order with parents before children works; this one is $W,R,L,F,S$.

The roots

$$\begin{aligned}&u_W=0.62\ge0.5\Rightarrow\hat W=0\\ &u_R=0.07<0.1\Rightarrow\hat R=1\end{aligned}$$

A root is drawn from its own table; $x=1$ exactly when $u$ falls below $p(x=1)$.

The battery

$$u_L=0.30\ge p(L=1\mid W=0)=0.05\Rightarrow\hat L=0$$

The parent value just drawn, $\hat W=0$, picks the row of the table.

The packet

$$u_F=0.41<p(F=1\mid L=0,R=1)=0.5\Rightarrow\hat F=1$$

Both parents are known now, so the row $(0,1)$ applies.

The SMS

$$u_S=0.97\ge p(S=1\mid F=1)=0.95\Rightarrow\hat S=0$$

The rare branch: the packet is lost but no SMS goes out.

Answer $$\boxed{(\hat W,\hat R,\hat L,\hat F,\hat S)=(0,1,0,1,0)}$$
Check

The factorization gives this night the probability $0.5\times0.1\times0.95\times0.5\times0.05=0.0012$: rare, as it needs interference ($1$ night in $10$) and a failed SMS ($1$ in $20$).

Ancestral sampling needs only the factors and a parents-first order; it never builds the joint table.

Checkpoint
§12.1 — reading the joint off a graph

A directed graph $G$ on six variables has exactly six arrows: $x_1\to x_2$, $x_1\to x_3$, $x_6\to x_3$, $x_2\to x_4$, $x_3\to x_4$ and $x_4\to x_5$.

Find(a) Which product is $p(x_1,\dots,x_6)$ for this graph?
Givenarrows $x_1\to x_2$, $x_1\to x_3$, $x_6\to x_3$, $x_2\to x_4$, $x_3\to x_4$, $x_4\to x_5$
Hint 1/4

Each node contributes one factor; decide what each factor is conditioned on.

Hint 2/4

$$p(x_1,\dots,x_D)=\prod_{j}p(x_j\mid\mathrm{pa}_j)$$

Hint 3/4

Arrows into $x_3$ come from $x_1$ and $x_6$; into $x_4$ from $x_2$ and $x_3$; into $x_5$ from $x_4$ only.

Hint 4/4

The joint is ${p(x_1)}{p(x_6)}{p(x_2\mid x_1)}$ ${p(x_3\mid x_1,x_6)}$ ${p(x_4\mid x_2,x_3)}{p(x_5\mid x_4)}$.

Show solution

List the arrows into each node; nothing else enters a factor.

Parents

$$\mathrm{pa}_3=\{x_1,x_6\},\ \ \mathrm{pa}_4=\{x_2,x_3\},\ \ \mathrm{pa}_5=\{x_4\}$$

The nodes that need care: $x_3$ has two parents, and $x_5$ has only $x_4$.

Product

$$\begin{aligned}&p(x_1)p(x_6)p(x_2\mid x_1)\\ &\quad\times p(x_3\mid x_1,x_6)\\ &\quad\times p(x_4\mid x_2,x_3)p(x_5\mid x_4)\end{aligned}$$

One factor per node.

Answer $$\boxed{\begin{aligned}p(x)&=p(x_1)\,p(x_6)\\ &\quad\times p(x_2\mid x_1)\\ &\quad\times p(x_3\mid x_1,x_6)\\ &\quad\times p(x_4\mid x_2,x_3)\\ &\quad\times p(x_5\mid x_4)\end{aligned}}$$
Check

Six factors for six nodes, and the parents listed add up to the six arrows: $0+0+1+2+2+1=6$.

Count the arrows into each node before writing; the total must match the number of arrows.

⚠ Conditioning on ancestors instead of parents

everything upstream seems to matter

wrong$$p(x_5\mid x_1,x_2,x_3,x_4)$$
right$$p(x_5\mid x_4)$$
⚠ Dropping a parent

one of two incoming arrows is easy to miss

wrong$$p(x_3\mid x_1)$$
right$$p(x_3\mid x_1,x_6)$$
⚠ Counting both rows of a binary table

the table has two columns, $x=0$ and $x=1$

wrong$$p(F\mid L,R):\ 4\times2=8\ \text{numbers}$$
right$$\begin{aligned}&p(F\mid L,R):\ 4\ \text{numbers, since}\\ &p(F=0\mid\cdot)=1-p(F=1\mid\cdot)\end{aligned}$$

12.2Three ways two arrows meet: blocked, blocked, opened

Observing the middle node blocks tail-to-tail and head-to-tail connections but opens a head-to-head one: that is explaining away.

A missing arrow drops a condition from a factor; to see what that means for independence, we start with three nodes and two arrows.

TheoremConditional independence in the three three-node graphs
Conditions
  • $a\perp\!\!\!\perp b\mid c$ means $p(a,b\mid c)=p(a\mid c)\,p(b\mid c)$ for all values of $a$ and $b$ and every $c$ with $p(c)>0$

  • 'dependent' means dependent for some choice of the tables (see the conventions)

$$\boxed{\begin{aligned}&a\leftarrow c\rightarrow b:\ a\perp\!\!\!\perp b\mid c\\ &\qquad\text{dependent without }c\\ &a\rightarrow c\rightarrow b:\ a\perp\!\!\!\perp b\mid c\\ &\qquad\text{dependent without }c\\ &a\rightarrow c\leftarrow b:\ a\perp\!\!\!\perp b\\ &\qquad\text{dependent given }c\end{aligned}}$$

When $c$ is a common parent or a link in a chain, $a$ and $b$ share information through $c$, and knowing $c$ cuts that channel. When $c$ is a common child, often called a , $a$ and $b$ have nothing in common until $c$ is observed; then each becomes evidence about the other.

Three short computations

Tail-to-tail, $p(a,b,c)=p(c)p(a\mid c)p(b\mid c)$. Dividing by $p(c)$ leaves $p(a\mid c)p(b\mid c)$. Without $c$, $p(a,b)=\sum_cp(c)p(a\mid c)p(b\mid c)$ is a mixture, which does not factor in general.

Head-to-tail, $p(a,b,c)=p(a)p(c\mid a)p(b\mid c)$. Bayes' rule turns $p(a)p(c\mid a)/p(c)$ into $p(a\mid c)$, so $p(a,b\mid c)=p(a\mid c)p(b\mid c)$. Without $c$, $p(a,b)=p(a)\sum_cp(c\mid a)p(b\mid c)$ still depends on $a$ through the sum.

Head-to-head, $p(a,b,c)=p(a)p(b)p(c\mid a,b)$. Summing over $c$ removes the last factor, so $p(a,b)=p(a)p(b)$. Given $c$, $p(a,b\mid c)=p(a)p(b)p(c\mid a,b)/p(c)$ keeps $a$ and $b$ together inside $p(c\mid a,b)$.

Looks like this, but is not

No arrow joins $W$ and $F$ in $W\to L\to F$, so a cloudy day tells nothing about the packet.

An arrow is a direct dependence only; information also travels along paths. Clouds raise the chance of a low battery and so of a lost packet: $p(F=1\mid W=1)=0.194$ against $p(F=1\mid W=0)=0.110$. Only once $L$ is known does $W$ stop mattering.

evidencep(L = 1)per 1000

nothing

$0.100$

$100$

$F=1$

$0.597$

$597$

$F=1$, $R=1$

$0.174$

$174$

$F=1$, $R=0$

$0.833$

$833$

$F=1$ is a lost packet, $R=1$ a storm, $R=0$ a night without interference. The lost packet raises both causes; learning that one cause happened takes most of the suspicion off the other, and ruling it out puts the suspicion back.

Two thermometers and one heater: dependent, until the heater is known

A heater is on ($c=1$) or off with probability $0.5$ each. Two thermometers $a$ and $b$ each read 'warm' with probability $0.9$ when the heater is on and $0.2$ when it is off, independently given $c$. Show that $a$ and $b$ are dependent, and independent given $c$.

Find$p(a=1,b=1)$ against $p(a=1)p(b=1)$, then the same test given $c=1$.
Given
  • $c\to a$, $c\to b$ (tail-to-tail at $c$)

  • $p(c=1)=0.5$

  • $p(a=1\mid c=1)=p(b=1\mid c=1)=0.9$, $p(a=1\mid c=0)=p(b=1\mid c=0)=0.2$

Solution

Compute the two sides of the independence test with numbers; a single unequal pair of values is enough to show dependence.

Marginals

$$p(a=1)=p(b=1)=0.5(0.9)+0.5(0.2)=0.55$$

Sum out the heater.

Joint without the heater

$$\begin{aligned}&p(a=1,b=1)\\ &=0.5(0.9)^2+0.5(0.2)^2=0.425\\ &\ne0.55^2=0.3025\end{aligned}$$

The joint is a mixture over $c$, and a mixture of products is not a product.

What one warm reading says

$$p(b=1\mid a=1)=\frac{0.425}{0.55}=0.773>0.55$$

A warm $a$ makes 'heater on' likelier, and that raises the chance that $b$ reads warm.

Given the heater

$$\begin{aligned}&p(a=1,b=1\mid c=1)\\ &=0.9\times0.9\\ &=p(a=1\mid c=1)\\ &\quad\times p(b=1\mid c=1)\end{aligned}$$

Once $c$ is known, the only link between the thermometers is gone.

Answer $$\boxed{\begin{aligned}&a\not\perp\!\!\!\perp b\\ &a\perp\!\!\!\perp b\mid c\end{aligned}}$$
Check

Check $c=0$ as well: $p(a=1,b=1\mid c=0)=0.04=0.2\times0.2$. Both values of $c$ pass, which is what independence given $c$ requires.

A common parent makes its children look related; conditioning on the parent removes the resemblance.

Is the battery low? A lost packet, then a storm report

In the sensor model, $L$ (low battery) and $R$ (interference) are the two parents of $F$ (lost packet): $L\to F\leftarrow R$. Find $p(L=1)$, then $p(L=1\mid F=1)$, then $p(L=1\mid F=1,R=1)$.

FindThe three beliefs in a low battery.
Given
  • $p(L=1)=0.1$ (after summing out the weather), $p(R=1)=0.1$

  • $p(F=1\mid L,R)=0.02,\ \allowbreak 0.5,\ \allowbreak 0.9,\ \allowbreak 0.95$ for $(L,R)=(0,0), \allowbreak (0,1), \allowbreak (1,0), \allowbreak (1,1)$

Solution

Enumerate: fix the observed values, sum the factored joint over the rest, and divide. With two binary parents there are only four cells to add.

Before any evidence

$$p(L=1)=0.1$$

Summed out of the weather in the first worked example.

The lost packet: four cells

$$\begin{aligned}p(F=1)&=0.0162+0.045\\ &\quad+0.081+0.0095\\ &=0.1517\end{aligned}$$

The cells $p(L)p(R)p(F=1\mid L,R)$ are $0.9(0.9)(0.02)$, $0.9(0.1)(0.5)$, $0.1(0.9)(0.9)$ and $0.1(0.1)(0.95)$, for $(L,R)=(0,0), \allowbreak (0,1), \allowbreak (1,0), \allowbreak (1,1)$.

Belief after the lost packet

$$p(L=1\mid F=1)=\frac{0.081+0.0095}{0.1517}=0.597$$

Keep the two cells with $L=1$ and divide by all four.

Belief after the storm report

$$\begin{aligned}&p(L=1\mid F=1,R=1)\\ &=\frac{0.1(0.95)}{0.1(0.95)+0.9(0.5)}\\ &=\frac{0.095}{0.545}=0.174\end{aligned}$$

Only the two cells with $R=1$ survive; the common factor $p(R=1)=0.1$ cancels.

Answer $$\boxed{\begin{aligned}\text{no evidence}&:\ 0.100\\ F=1&:\ 0.597\\ F=1,\ R=1&:\ 0.174\end{aligned}}$$
Check

Average check: $p(R=1\mid F=1)=0.0545/0.1517=0.359$, and $0.3593(0.1743)+0.6407(0.8333)=0.597$, back to $p(L=1\mid F=1)$.

Four cells for $p(F=1)$, then two for each conditional.

This answers the opening question: the storm explains the lost packet away, and the battery drops from about $597$ in $1000$ back to $174$.

Checkpoint
§12.2 — a chain with its middle node observed

In the sensor model the weather $W$ affects the packet $F$ only through the battery: $W\to L\to F$ (the interference $R$ is the other parent of $F$). A technician already knows the battery is low, $L=1$.

Find(a) The technician then learns whether the day was cloudy. What happens to $p(F=1\mid L=1,W)$?
Given
  • $W\to L\to F\leftarrow R$

  • $p(F=1\mid L=1)=0.9(0.9)+0.1(0.95)=0.905$

  • observed: $L=1$

Hint 1/4

Ask through which nodes the weather can reach the packet.

Hint 2/4

Head-to-tail at $L$: $W\perp\!\!\!\perp F\mid L$.

Hint 3/4

With $L=1$ fixed, $p(F=1\mid L=1,W)=\sum_Rp(R)p(F=1\mid L=1,R)=0.9(0.9)+0.1(0.95)$ for either $W$.

Hint 4/4

It stays $0.905$ whatever the weather.

Show solution

Use the head-to-tail rule rather than enumerating: $W$ reaches $F$ only through $L$.

Where W enters

$$p(F\mid L,W)=\sum_Rp(R)\,p(F\mid L,R)$$

No factor of $F$ contains $W$; only $L$ and $R$ do.

Both values of W

$$p(F=1\mid L=1,W=1)=p(F=1\mid L=1,W=0)=0.905$$

The weather has nowhere else to act.

Answer $$\boxed{0.905\ \text{in both cases}}$$
Check

Without $L$ the weather does matter: $p(F=1\mid W=1)=0.194$ and $p(F=1\mid W=0)=0.110$.

Once the middle of a chain is known, the far end tells nothing new.

⚠ Treating an observed head-to-head node as a blocker

in two of the three graphs, observing the middle node does block

wrong$$a\to c\leftarrow b:\ \ a\perp\!\!\!\perp b\mid c$$
right$$a\to c\leftarrow b:\ \ a\perp\!\!\!\perp b,\ \text{but dependent given }c$$
⚠ Reading a missing arrow as independence

the arrows are the only thing drawn between the two nodes

wrong$$\text{no arrow }W\text{ to }F\ \Rightarrow\ W\perp\!\!\!\perp F$$
right$$W\perp\!\!\!\perp F\mid L\ \text{only; the path }W\to L\to F\text{ is open}$$
⚠ Turning conditional independence into plain independence

the two statements differ by one symbol after the bar

wrong$$a\perp\!\!\!\perp b\mid c\ \Rightarrow\ a\perp\!\!\!\perp b$$
right$$a\perp\!\!\!\perp b\mid c\ \text{does not imply }a\perp\!\!\!\perp b\ \text{(two thermometers)}$$

12.3D-separation: when every path is blocked

Check every path between two sets; if the observed set blocks each one, the sets are conditionally independent.

A longer path is a string of three-node pieces, so the three rules of the previous block, applied node by node, decide any graph.

DefinitionBlocked paths and d-separation
Conditions
  • $A$, $B$, $C$ are disjoint sets of nodes; $C$ is observed

  • a path is any chain of edges from a node of $A$ to a node of $B$, walked either way along the arrows

  • $\mathrm{de}(v)$ is the set of descendants of $v$

$$\boxed{\begin{aligned}&\text{a path is blocked at }v\text{ if}\\ &\text{(1) }v\text{ is head-to-tail or}\\ &\qquad\text{tail-to-tail, and }v\in C\\ &\text{(2) }v\text{ is head-to-head, }v\notin C,\\ &\qquad\mathrm{de}(v)\cap C=\varnothing\\ &\text{all paths blocked}\\ &\qquad\Rightarrow\ A\perp\!\!\!\perp B\mid C\end{aligned}}$$

A path carries dependence unless one node on it stops the flow. A head-to-tail or tail-to-tail node stops it when the node is observed; a head-to-head node stops it unless the node or something below it is observed. If every path from $A$ to $B$ is stopped, $C$ d-separates $A$ from $B$, and $A$ and $B$ are independent given $C$.

Why the rules are the three-node rules, node by node (sketch)

Each interior node of a path sees two arrows, so it is one of the three graphs of the previous block. Rule (1) is the tail-to-tail and head-to-tail result; rule (2) is the head-to-head one.

A descendant of a collider carries information about it: if $c\to d$ and $d$ is observed, then $d$ acts as a noisy reading of $c$, and a reading of the common child couples its parents.

One blocking node is enough for a path, but every path must be blocked, because dependence can travel along any open one. The full proof that d-separation implies conditional independence for every choice of tables is longer and is not needed here.

Looks like this, but is not

Observing more variables can only make things more independent, so if $x_2\perp\!\!\!\perp x_3\mid x_1$ then also $x_2\perp\!\!\!\perp x_3\mid\{x_1,x_5\}$.

Observing $x_5$ opens the collider $x_4$ above it, and the lower path starts to carry dependence. Adding a node to $C$ can block a chain and open a collider at the same time.

Two paths between x2 and x3, and what observing x5 does

In graph $G$, decide whether $x_2\perp\!\!\!\perp x_3\mid x_1$, and whether $x_2\perp\!\!\!\perp x_3\mid\{x_1,x_5\}$.

FindBoth verdicts, with the blocking node of each path.
Given
  • arrows $x_1\to x_2$, $x_1\to x_3$, $x_6\to x_3$, $x_2\to x_4$, $x_3\to x_4$, $x_4\to x_5$

  • first $C=\{x_1\}$, then $C=\{x_1,x_5\}$

Solution

List the paths once, then check each path against each observed set; the paths do not change when $C$ does.

All paths from x2 to x3

$$\begin{aligned}&x_2\leftarrow x_1\rightarrow x_3\\ &x_2\rightarrow x_4\leftarrow x_3\end{aligned}$$

Walk the edges in either direction; $x_5$ and $x_6$ hang off $x_4$ and $x_3$ and lead back to no other route.

C = {x1}

$$\begin{aligned}&\text{path 1: tail-to-tail at }x_1\\ &x_1\in C\Rightarrow\text{blocked}\end{aligned}$$

Rule 1: an observed tail-to-tail node blocks.

$$\begin{aligned}&\text{path 2: head-to-head at }x_4\\ &x_4,x_5\notin C\Rightarrow\text{blocked}\end{aligned}$$

Rule 2: an unobserved collider with no observed descendant blocks.

$$\Rightarrow\ x_2\perp\!\!\!\perp x_3\mid x_1$$

Every path is blocked.

C = {x1, x5}

$$\text{path 1: still blocked at }x_1$$

Adding nodes to $C$ never unblocks an observed tail-to-tail node.

$$\begin{aligned}&\text{path 2: }x_5\in\mathrm{de}(x_4)\cap C\\ &\Rightarrow\text{open}\end{aligned}$$

Rule 2 fails: a descendant of the collider is observed.

$$\Rightarrow\ x_2\not\perp\!\!\!\perp x_3\mid\{x_1,x_5\}$$

One open path is enough.

Answer $$\boxed{\begin{aligned}&x_2\perp\!\!\!\perp x_3\mid x_1\\ &x_2\not\perp\!\!\!\perp x_3\mid\{x_1,x_5\}\end{aligned}}$$
Check

Exact check on a model with random tables for $G$: $p(x_2,x_3\mid x_1)$ factors for both values of $x_1$, and $p(x_2,x_3\mid x_1,x_5)$ does not.

Observing more can create dependence: a descendant of a collider acts like a partial view of the collider itself.

A root that becomes connected: x6 and x1

In graph $G$, $x_1$ and $x_6$ are both roots. Decide whether $x_6\perp\!\!\!\perp x_1$, and whether $x_6\perp\!\!\!\perp x_1\mid x_4$.

FindBoth verdicts.
Given
  • arrows $x_1\to x_2$, $x_1\to x_3$, $x_6\to x_3$, $x_2\to x_4$, $x_3\to x_4$, $x_4\to x_5$

  • first $C=\varnothing$, then $C=\{x_4\}$

Solution

Two roots are independent unless something opens a collider between them, so we look for colliders on each path.

All paths from x6 to x1

$$\begin{aligned}&x_6\to x_3\leftarrow x_1\\ &x_6\to x_3\to x_4\leftarrow x_2\leftarrow x_1\end{aligned}$$

The second path goes down through $x_3$ and back up through $x_2$.

Nothing observed

$$\begin{aligned}&\text{path 1: head-to-head at }x_3\\ &\text{nothing observed}\Rightarrow\text{blocked}\end{aligned}$$

An unobserved collider blocks.

$$\begin{aligned}&\text{path 2: head-to-head at }x_4\\ &\Rightarrow\text{blocked}\end{aligned}$$

$x_3$ passes (head-to-tail, unobserved), but $x_4$ is an unobserved collider.

$$\Rightarrow\ x_6\perp\!\!\!\perp x_1$$

Both paths are blocked.

C = {x4}

$$\begin{aligned}&\text{path 1: }x_4\in\mathrm{de}(x_3)\cap C\\ &\Rightarrow\text{open}\end{aligned}$$

$x_4$ is a child of the collider $x_3$.

$$\Rightarrow\ x_6\not\perp\!\!\!\perp x_1\mid x_4$$

One open path decides it; path 2, open at $x_4$ as well, is not needed.

Answer $$\boxed{\begin{aligned}&x_6\perp\!\!\!\perp x_1\\ &x_6\not\perp\!\!\!\perp x_1\mid x_4\end{aligned}}$$
Check

Same pattern as the sensor: $L$ and $R$ are independent, but not given $F$ or given $F$'s child $S$.

For two roots, look for colliders: each is closed until it or one of its descendants is observed.

Checkpoint
§12.3 — one true statement about graph G

Graph $G$ has the arrows $x_1\to x_2$, $x_1\to x_3$, $x_6\to x_3$, $x_2\to x_4$, $x_3\to x_4$ and $x_4\to x_5$. Exactly one of the statements below follows from d-separation.

Find(a) Which statement is true?
Givenarrows $x_1\to x_2$, $x_1\to x_3$, $x_6\to x_3$, $x_2\to x_4$, $x_3\to x_4$, $x_4\to x_5$
Hint 1/4

For each statement, look for a single open path; a statement is true only if none exists.

Hint 2/4

A path is blocked by a node that is head-to-tail or tail-to-tail and observed, or head-to-head with neither it nor a descendant observed.

Hint 3/4

Paths: $x_2$ to $x_3$ via $x_1$ or $x_4$; $x_6$ to $x_1$ via $x_3$ or $x_3,x_4,x_2$; the collider $x_3$ has descendants $x_4$ and $x_5$.

Hint 4/4

Only $x_6\perp\!\!\!\perp x_2\mid x_1$ survives: both of its paths are blocked.

Show solution

Test each statement by its most suspicious path first: a collider with an observed descendant, or an unobserved chain.

x2 and x3, nothing observed

$$x_2\leftarrow x_1\rightarrow x_3\ \text{open}$$

Tail-to-tail at the unobserved $x_1$.

x6 and x1 given x4

$$x_6\to x_3\leftarrow x_1\ \text{open}$$

$x_4$ is a descendant of the collider $x_3$.

x6 and x2 given x1

$$x_6\to x_3\leftarrow x_1\to x_2:\ \text{blocked at }x_3\text{ and at }x_1$$

Unobserved collider $x_3$ without observed descendants, and observed tail-to-tail $x_1$.

$$x_6\to x_3\to x_4\leftarrow x_2:\ \text{blocked at }x_4$$

Unobserved collider.

x2 and x6 given x5

$$x_2\to x_4\leftarrow x_3\leftarrow x_6\ \text{open}$$

$x_5$ is a child of the collider $x_4$.

Answer $$\boxed{x_6\perp\!\!\!\perp x_2\mid x_1}$$
Check

The exact check on a model with random tables agrees: only $x_6$ and $x_2$ given $x_1$ factor.

Check the suspicious path first; one open path settles a 'dependent' verdict.

⚠ Checking only one path

the first path found is often the obvious one

wrong$$\begin{aligned}&x_2\leftarrow x_1\rightarrow x_3\ \text{blocked}\\ &\Rightarrow x_2\perp\!\!\!\perp x_3\mid\{x_1,x_5\}\end{aligned}$$
right$$\begin{aligned}&\text{also }x_2\rightarrow x_4\leftarrow x_3\text{: open,}\\ &\text{so not independent}\end{aligned}$$
⚠ Forgetting the descendants of a collider

rule (2) looks only at the collider when read quickly

wrong$$x_3\notin C\ \Rightarrow\ x_6\to x_3\leftarrow x_1\ \text{blocked given }x_4$$
right$$x_4\in\mathrm{de}(x_3)\cap C\ \Rightarrow\ \text{open}$$
⚠ Treating an unobserved collider as open

an unobserved node usually lets information through

wrong$$x_6\to x_3\leftarrow x_1,\ C=\varnothing:\ \text{open}$$
right$$x_6\to x_3\leftarrow x_1,\ C=\varnothing:\ \text{blocked, so }x_6\perp\!\!\!\perp x_1$$

12.4Naive Bayes: a star-shaped graph that learns by counting

A classifier whose graph is a star: the label is each feature's only parent, so training is counting and prediction is one product per class.

So far the graph was given; now we choose one on purpose, a star around the class label, and the independences it states make learning a matter of counting.

TheoremNaive Bayes: model, decision and maximum likelihood estimates
Conditions
  • features $x=(x_1,\dots,x_D)$, label $y\in\{1,\dots,C\}$ with $p(y=c)=\pi_c$

  • the features are conditionally independent given $y$: arrows $y\to x_j$ only, none between features

  • Bernoulli features: $p(x_j\mid y=c)=\theta_{jc}^{I(x_j=1)}(1-\theta_{jc})^{I(x_j=0)}$; Gaussian: $p(x_j\mid y=c)=\mathcal N(x_j\mid\mu_{jc},\sigma^2_{jc})$

  • data $D=\{(x_i,y_i)\}_{i=1}^n$, $n_c=\sum_iI(y_i=c)$, $n_{jc}=\sum_iI(x_{ij}=1,\,y_i=c)$

$$\boxed{\begin{aligned}&p(y=c\mid x)\\ &\propto\pi_c\prod_{j=1}^{D}p(x_j\mid y=c)\\ &\hat\pi_c=\frac{n_c}{n}\\ &\hat\theta_{jc}=\frac{n_{jc}}{n_c}\end{aligned}}$$

The posterior of a class is its share times the probability of each observed feature under that class, rescaled so the classes add up to $1$. Trained by maximum likelihood, a share is the fraction of training points in the class, and a feature rate is the fraction of that class's points that show the feature.

The likelihood splits along the graph

By the factorization, $L(\theta,\pi)=\prod_ip(y_i\mid\pi)\prod_jp(x_{ij}\mid y_i,\theta_j)$, so $l=\sum_cn_c\log\pi_c+\sum_{i,j,c}I(y_i=c)\log p(x_{ij}\mid y_i=c,\theta_{jc})$: one sum for the shares and one term per feature and class.

Shares: maximize $\sum_cn_c\log\pi_c$ subject to $\sum_c\pi_c=1$. The Lagrange condition $n_c/\pi_c=\lambda$ gives $\pi_c=n_c/\lambda$, and adding over $c$ gives $\lambda=n$.

Bernoulli rates: the $\theta_{jc}$ term is $n_{jc}\log\theta_{jc}+(n_c-n_{jc})\log(1-\theta_{jc})$. Its derivative vanishes at $\hat\theta_{jc}=n_{jc}/n_c$.

Gaussian features split the same way, class by class: $\hat\mu_{jc}$ is the class mean of feature $j$, and $\hat\sigma^2_{jc}$ its average squared deviation, divided by $n_c$.

Looks like this, but is not

Naive Bayes assumes that the features are independent of each other.

It assumes independence given $y$. Without $y$ the star is tail-to-tail at $y$, so the features are dependent: in the trained e-mail model 'prize' and 'outside sender' each appear in $40$ e-mails out of $100$, but together in about $24$, not $16$.

Training on ten e-mails: maximum likelihood is counting

Ten labelled e-mails are described by three binary features. Fit a Bernoulli naive Bayes classifier by maximum likelihood.

Find$\hat\pi_c$ and $\hat\theta_{jc}$ for $c=1,2$ and $j=1,2,3$.
Given
  • features: $x_1$ = the word 'prize' appears, $x_2$ = a link, $x_3$ = sender outside the university

  • spam, $y=1$: $(1,1,1)$, $(1,0,1)$, $(0,1,1)$, $(1,1,0)$

  • not spam, $y=2$: $(0,1,0)$, $(0,0,0)$, $(0,1,1)$, $(0,0,0)$, $(1,0,0)$, $(0,1,0)$

Solution

The estimates in the box are ratios of counts, so we count once per class and per feature and divide; no optimization is left to do.

Class counts

$$\begin{aligned}&n_1=4,\quad n_2=6\\ &\hat\pi_1=\frac{4}{10}=0.4,\quad \hat\pi_2=0.6\end{aligned}$$

The class share divides by all $n=10$ e-mails.

Feature counts inside each class

$$\begin{aligned}&n_{11}=3,\ n_{21}=3,\ n_{31}=3\\ &n_{12}=1,\ n_{22}=3,\ n_{32}=1\end{aligned}$$

Down each column, counting $1$s among the spam rows, then among the others.

Feature rates

$$\begin{aligned}&\hat\theta_{\cdot1}=\Big(\frac34,\ \frac34,\ \frac34\Big)\\ &\hat\theta_{\cdot2}=\Big(\frac16,\ \frac36,\ \frac16\Big)\end{aligned}$$

Each count is divided by its own class size, $4$ or $6$, not by $10$.

Answer $$\boxed{\begin{aligned}\hat\pi&=(0.4,\ 0.6)\\ \hat\theta_{\cdot1}&=(0.75,\ 0.75,\ 0.75)\\ \hat\theta_{\cdot2}&=(0.167,\ 0.5,\ 0.167)\end{aligned}}$$
Check

Moving any estimate away from its count ratio lowers the log-likelihood: at the estimates it is $-23.04$, and with $\theta_{11}=0.5$ instead of $0.75$ it drops to $-23.57$.

Training naive Bayes is one pass of counting; the Lagrange multiplier in the proof only explains why the shares divide by $n$.

Classifying two new e-mails with the trained model

With the estimates of the previous example, find $p(y=1\mid x)$ for $x=(1,0,1)$ and for $x=(0,1,0)$.

FindThe two posteriors of spam.
Given
  • $\hat\pi=(0.4,\ 0.6)$

  • $\hat\theta_{\cdot1}=(0.75,\ 0.75,\ 0.75)$

  • $\hat\theta_{\cdot2}=(1/6,\ 1/2,\ 1/6)$

Solution

Score each class with $\hat\pi_c\prod_j$ ($\hat\theta_{jc}$ or $1-\hat\theta_{jc}$), then divide by the sum of the scores; this is Bayes' rule with the factored likelihood.

x = (1, 0, 1)

$$\text{spam: }0.4\times0.75\times0.25\times0.75=0.05625$$

$x_2=0$, so the middle factor is $1-\hat\theta_{21}=0.25$.

$$\text{not spam: }0.6\times\tfrac16\times\tfrac12\times\tfrac16=0.00833$$

Same pattern with class 2 rates; $1-\hat\theta_{22}=\tfrac12$.

$$p(y=1\mid x)=\frac{0.05625}{0.05625+0.00833}=0.871$$

Normalize the two scores.

x = (0, 1, 0)

$$\text{spam: }0.4\times0.25\times0.75\times0.25=0.01875$$

Two features absent: two factors $1-0.75$.

$$\text{not spam: }0.6\times\tfrac56\times\tfrac12\times\tfrac56=0.2083$$

Absent 'prize' and inside sender are typical of class 2.

$$p(y=1\mid x)=\frac{0.01875}{0.01875+0.2083}=0.083$$

Normalize.

Answer $$\boxed{\begin{aligned}&p(y=1\mid(1,0,1))=0.871\\ &p(y=1\mid(0,1,0))=0.083\end{aligned}}$$
Check

Log-odds route for the first e-mail: $\log\frac{0.05625}{0.00833}=\log6.75=1.910$, and $1/(1+e^{-1.910})=0.871$.

Absent features vote too, through $1-\hat\theta_{jc}$; dropping them changes the answer.

Gaussian naive Bayes: temperature says healthy, vibration says worn

Four healthy motors had (temperature, vibration) readings $(40,2)$, $(42,3)$, $(44,3)$, $(46,4)$; four worn ones had $(48,5)$, $(50,6)$, $(52,7)$, $(54,6)$, in degrees Celsius and mm/s. Fit a Gaussian naive Bayes model with equal shares and classify a motor at $(46,5)$.

Find$p(\text{worn}\mid x)$.
Given
  • healthy, $c=1$: $(40,2)$, $(42,3)$, $(44,3)$, $(46,4)$

  • worn, $c=2$: $(48,5)$, $(50,6)$, $(52,7)$, $(54,6)$

  • $\pi_1=\pi_2=0.5$; new motor $x=(46,5)$

Solution

Estimate a mean and a variance per class and feature, then compare log-densities: equal shares cancel, and logs turn the product into a sum of per-feature votes.

Estimates per class

$$\begin{aligned}&\hat\mu_{\cdot1}=(43,\ 3),\ \ \hat\sigma^2_{\cdot1}=(5,\ 0.5)\\ &\hat\mu_{\cdot2}=(51,\ 6),\ \ \hat\sigma^2_{\cdot2}=(5,\ 0.5)\end{aligned}$$

Maximum likelihood divides the squared deviations by $n_c=4$: for healthy temperature $(9+1+1+9)/4=5$.

Temperature's vote

$$\log\frac{\mathcal N(46\mid51,5)}{\mathcal N(46\mid43,5)}=\frac{9-25}{2\cdot5}=-1.6$$

Equal variances cancel the constants; $46$ is closer to the healthy mean.

Vibration's vote

$$\log\frac{\mathcal N(5\mid6,0.5)}{\mathcal N(5\mid3,0.5)}=\frac{4-1}{2\cdot0.5}=3$$

$5$ is two units above the healthy mean but only one below the worn one, and the variance is small.

Combine

$$p(\text{worn}\mid x)=\frac{1}{1+e^{-(3-1.6)}}=\frac{1}{1+e^{-1.4}}=0.802$$

Conditional independence makes the votes add in the log-odds.

Answer $$\boxed{p(\text{worn}\mid x)=0.802}$$
Check

Direct densities: healthy $0.07254\times0.01033=0.000750$, worn $0.01464\times0.2076=0.00304$, and $0.00304/(0.00304+0.00075)=0.802$.

Each Gaussian feature votes with the difference of squared distances divided by twice its variance, so a precise feature outvotes a vague one.

Checkpoint
§12.4 — one Bernoulli rate from counts

A mail filter is trained on $40$ e-mails. $10$ of them are spam, and $8$ of those spam e-mails contain a link; $6$ of the $30$ other e-mails contain a link too.

Find(a) What is the maximum likelihood estimate of $\theta_{\text{link},1}=p(\text{link}\mid\text{spam})$?
Given
  • $n=40$; spam $n_1=10$, not spam $n_2=30$

  • link in spam: $8$; link in not spam: $6$

Hint 1/4

Decide which e-mails the rate is a fraction of.

Hint 2/4

$\hat\theta_{jc}=n_{jc}/n_c$.

Hint 3/4

$n_{jc}=8$ spam e-mails with a link, out of $n_c=10$ spam e-mails.

Hint 4/4

$\hat\theta=8/10=0.8$.

Show solution

The rate is counted inside the class, so only the $10$ spam e-mails matter.

Count inside the class

$$\hat\theta=\frac{n_{jc}}{n_c}=\frac{8}{10}=0.8$$

Maximum likelihood for a Bernoulli rate: successes over trials, within class $c$.

Answer $$\boxed{\hat\theta=0.8}$$
Check

Consistency: the other class gives $6/30=0.2$, and $0.25(0.8)+0.75(0.2)=0.35=14/40$, the link rate over all $40$ e-mails.

Before dividing, ask whose count this is a fraction of.

⚠ Dividing a feature count by n

$n$ is the number in plain sight

wrong$$\hat\theta_{jc}=\frac{n_{jc}}{n}$$
right$$\hat\theta_{jc}=\frac{n_{jc}}{n_c}$$
⚠ Dropping the absent features

a feature that is $0$ looks like it says nothing

wrong$$\hat\pi_c\prod_{j:\,x_j=1}\hat\theta_{jc}$$
right$$\hat\pi_c\prod_{j:\,x_j=1}\hat\theta_{jc}\prod_{j:\,x_j=0}(1-\hat\theta_{jc})$$
⚠ Forgetting the class share

the likelihood looks like the whole score

wrong$$\hat c=\arg\max_c\prod_jp(x_j\mid y=c)$$
right$$\hat c=\arg\max_c\hat\pi_c\prod_jp(x_j\mid y=c)$$

12.5The Markov blanket: parents, children and co-parents

Parents, children and co-parents: once they are known, the rest of a directed graph tells a node nothing more.

D-separation answers questions about any sets; one question comes up so often that it has its own answer: which nodes make the rest of the graph irrelevant to one node?

TheoremThe Markov blanket in a directed graph
Conditions
  • the joint factorizes as $\prod_kp(x_k\mid\mathrm{pa}_k)$

  • the co-parents of $x_i$ are the other parents of $x_i$'s children

  • for a continuous $x_i$ the sum is an integral

$$\boxed{\begin{aligned}&p(x_i\mid x_{j\ne i})\\ &\propto p(x_i\mid\mathrm{pa}_i)\\ &\quad\times\prod_{k:\,x_i\in\mathrm{pa}_k}p(x_k\mid\mathrm{pa}_k)\\ &\mathrm{MB}(x_i)=\text{parents}\cup\text{children}\\ &\qquad\cup\text{co-parents}\end{aligned}}$$

To predict one node from all the others, keep only its own factor and the factors of its children; every other factor cancels. Those factors mention the parents, the children and the children's other parents, so this set, the blanket, is all we need to know.

Cancel every factor that does not contain the node

Write $p(x_i\mid x_{j\ne i})=p(x)\big/\sum_{x_i}p(x)$ and substitute the factorization on top and below.

A factor $p(x_k\mid\mathrm{pa}_k)$ with $x_i$ neither equal to $x_k$ nor in $\mathrm{pa}_k$ does not change with $x_i$: it comes out of the sum below and cancels with its copy on top.

What survives is $p(x_i\mid\mathrm{pa}_i)$ and one factor for each child $x_k$; a child's factor also contains the child's other parents. Those variables form the blanket.

Looks like this, but is not

The Markov blanket of a node is the set of nodes joined to it by an arrow.

Co-parents have no arrow to the node, yet they matter: in $L\to F\leftarrow R$, once $F$ is known, learning $R$ moves the belief in $L$ from $0.597$ to $0.174$. The blanket of $L$ is $\{W,F,R\}$, not $\{W,F\}$.

The battery given everything else: which factors survive

In the sensor model, find $p(L=1\mid W=1,R=0,F=1,S)$ for $S=1$ and for $S=0$.

FindThe two conditionals.
Given
  • $W\to L\to F\leftarrow R$, $F\to S$

  • $p(L=1\mid W=1)=0.15$; $p(F=1\mid L,R=0)=0.9$ if $L=1$ and $0.02$ if $L=0$

  • $p(S=1\mid F=1)=0.95$

Solution

Use the blanket formula: only the factors that contain $L$ survive, so the tables of $W$, $R$ and $S$ are never needed.

Factors that contain L

$$p(L\mid W)\ \text{and}\ p(F\mid L,R)$$

$L$'s own factor and the factor of its only child $F$.

Unnormalized values

$$\begin{aligned}&L=1:\ 0.15\times0.9=0.135\\ &L=0:\ 0.85\times0.02=0.017\end{aligned}$$

Plug in $W=1$, $R=0$, $F=1$.

Normalize

$$p(L=1\mid\cdot)=\frac{0.135}{0.135+0.017}=0.888\ \ \text{for }S=1\text{ and for }S=0$$

$p(S\mid F)$ has no $L$ in it, so it cancels; the value of $S$ cannot matter.

Answer $$\boxed{\begin{aligned}&p(L=1\mid\text{the rest})=0.888\\ &\text{for }S=0\text{ and for }S=1\end{aligned}}$$
Check

Keep $S$ in: with $S=1$, $\frac{0.15(0.9)(0.95)}{0.15(0.9)(0.95)+0.85(0.02)(0.95)}=0.12825/0.1444=0.888$; the factor $0.95$ cancels, as the blanket says.

$S$ lies below $L$, but once $F$ is known it has nothing left to say about $L$.

Three blankets in graph G

Find the Markov blankets of $x_3$, $x_4$ and $x_1$ in graph $G$.

Find$\mathrm{MB}(x_3)$, $\mathrm{MB}(x_4)$, $\mathrm{MB}(x_1)$.
Givenarrows $x_1\to x_2$, $x_1\to x_3$, $x_6\to x_3$, $x_2\to x_4$, $x_3\to x_4$, $x_4\to x_5$
Solution

Collect parents, then children, then the other parents of those children; a table per node keeps the co-parents from being forgotten.

x3

$$\begin{aligned}&\text{parents }x_1,x_6;\ \text{child }x_4\\ &\text{co-parent }x_2\end{aligned}$$

$x_4$ has the parents $x_2$ and $x_3$, so $x_2$ comes in through $x_4$.

$$\mathrm{MB}(x_3)=\{x_1,x_2,x_4,x_6\}$$

$x_5$ is a grandchild and stays out.

x4

$$\begin{aligned}&\text{parents }x_2,x_3;\ \text{child }x_5\\ &\text{no co-parent}\end{aligned}$$

$x_5$ has only $x_4$ as a parent.

$$\mathrm{MB}(x_4)=\{x_2,x_3,x_5\}$$

Two parents and one child; no other node shares a factor with $x_4$.

x1

$$\begin{aligned}&\text{no parent; children }x_2,x_3\\ &\text{co-parent }x_6\end{aligned}$$

$x_6$ is the other parent of the child $x_3$.

$$\mathrm{MB}(x_1)=\{x_2,x_3,x_6\}$$

A root's blanket is its children and their other parents.

Answer $$\boxed{\begin{aligned}\mathrm{MB}(x_3)&=\{x_1,x_2,x_4,x_6\}\\ \mathrm{MB}(x_4)&=\{x_2,x_3,x_5\}\\ \mathrm{MB}(x_1)&=\{x_2,x_3,x_6\}\end{aligned}}$$
Check

Symmetry check: $x_2\in\mathrm{MB}(x_3)$ and $x_3\in\mathrm{MB}(x_2)$; blanket membership always goes both ways, and here it does.

Read a blanket off the factors: every node that shares a factor with $x_i$ is in it, and no other node is.

Checkpoint
§12.5 — the Markov blanket of one node

Graph $G$ has the arrows $x_1\to x_2$, $x_1\to x_3$, $x_6\to x_3$, $x_2\to x_4$, $x_3\to x_4$ and $x_4\to x_5$.

Find(a) What is the Markov blanket of $x_2$?
Givenarrows $x_1\to x_2$, $x_1\to x_3$, $x_6\to x_3$, $x_2\to x_4$, $x_3\to x_4$, $x_4\to x_5$
Hint 1/4

The blanket is everything that shares a factor with $x_2$.

Hint 2/4

Directed blanket = parents $\cup$ children $\cup$ co-parents.

Hint 3/4

$x_2$ has parent $x_1$ and child $x_4$; the child $x_4$ has the other parent $x_3$.

Hint 4/4

$\mathrm{MB}(x_2)=\{x_1,x_3,x_4\}$.

Show solution

Parents, children, co-parents, in that order.

Collect

$$\begin{aligned}&\text{parent }x_1,\ \text{child }x_4\\ &\text{co-parent }x_3\end{aligned}$$

$x_4$ has the parents $x_2$ and $x_3$.

Answer $$\boxed{\mathrm{MB}(x_2)=\{x_1,x_3,x_4\}}$$
Check

The factors containing $x_2$ are $p(x_2\mid x_1)$ and $p(x_4\mid x_2,x_3)$; their other variables are exactly $x_1$, $x_3$, $x_4$.

A co-parent is found by walking to a child and back up another arrow.

⚠ Leaving out the co-parents

they are not adjacent to the node

wrong$$\mathrm{MB}(x_3)=\{x_1,x_4,x_6\}$$
right$$\mathrm{MB}(x_3)=\{x_1,x_2,x_4,x_6\}$$
⚠ Adding grandchildren

everything downstream seems to carry evidence

wrong$$\mathrm{MB}(x_3)\ni x_5$$
right$$x_5\notin\mathrm{MB}(x_3):\ p(x_5\mid x_4)\ \text{has no }x_3$$
⚠ Keeping only the parents

in a chain, the parent looks like the only source of information

wrong$$p(x_i\mid x_{j\ne i})=p(x_i\mid\mathrm{pa}_i)$$
right$$p(x_i\mid x_{j\ne i})\propto p(x_i\mid\mathrm{pa}_i)\prod_{k:\,x_i\in\mathrm{pa}_k}p(x_k\mid\mathrm{pa}_k)$$

12.6Markov random fields: undirected graphs, cliques and potentials

Without arrows, the joint is a product of non-negative potentials on maximal cliques, divided by a normalizing sum $Z$.

Directed graphs need a direction for every link; between neighbouring pixels of an image there is no natural direction, so we drop the arrows.

TheoremUndirected graphical model: separation and factorization
Conditions
  • $M$ is the set of maximal cliques and $x_c$ the variables of clique $c$

  • each satisfies $\psi_c(x_c)\ge0$; $Z$, the , sums over every configuration of $x$ (an integral for continuous variables)

  • separation: $A\perp\!\!\!\perp B\mid C$ when every path from $A$ to $B$ passes through a node of $C$

$$\boxed{\begin{aligned}p(x)&=\frac1Z\prod_{c\in M}\psi_c(x_c)\\ Z&=\sum_x\prod_{c\in M}\psi_c(x_c)\\ \psi_c(x_c)&=e^{-E(x_c)}\ \text{(Boltzmann)}\end{aligned}}$$

The probability of a configuration is proportional to a product of non-negative scores, one per maximal clique, and $Z$ rescales the products into probabilities; with $\psi_c=e^{-E(x_c)}$ this is a Boltzmann distribution. Independence is plain separation: observed nodes cut every path through them, so a node given its neighbours is independent of the rest.

Separation from the factorization, and the cost of Z

If $x_i$ and $x_j$ are not neighbours, no clique contains both, so each potential holds at most one of them. Given all other nodes, $p(x)$ splits into a factor with $x_i$ times a factor with $x_j$, and $p(x_i,x_j\mid\text{rest})=p(x_i\mid\text{rest})\,p(x_j\mid\text{rest})$.

The potentials that contain $x_i$ contain only $x_i$ and its neighbours, so given the neighbours all other factors cancel from $p(x_i\mid\text{rest})$: the blanket is the neighbours.

A potential on a smaller clique can be multiplied into any maximal clique that contains it without changing $p(x)$; that is why maximal cliques are enough.

For $D$ binary nodes, $Z$ has $2^D$ terms: $64$ for six nodes, about $10^{3010}$ for a $100\times100$ binary image.

Looks like this, but is not

A maximal clique is a clique of the largest size in the graph.

Maximal means no node can be added, not biggest. In $H$, $\{x_5,x_6\}$ is maximal: adding $x_3$ or $x_4$ breaks full connection. It has two nodes while the triangles have three.

x1 x2 x3productprobability

$000$, $111$

$3\cdot3=9$

$9/32$ each

$001$, $110$

$3\cdot1=3$

$3/32$ each

$011$, $100$

$1\cdot3=3$

$3/32$ each

$010$, $101$

$1\cdot1=1$

$1/32$ each

Rows are grouped by how many neighbour pairs agree: two, one, one, none. The products add up to $Z=32$, and a configuration where both pairs agree is $9$ times as probable as one where neither does.

Cliques, blanket and factorization of a bow-tie graph

The undirected graph $H$ has the edges $x_1x_2$, $x_1x_3$, $x_2x_3$, $x_3x_4$, $x_3x_5$, $x_4x_5$ and $x_5x_6$. List its cliques and maximal cliques, write the factorization, give the Markov blanket of $x_3$, and decide whether $x_1\perp\!\!\!\perp x_6\mid x_3$.

FindCliques, maximal cliques, $p(x)$, $\mathrm{MB}(x_3)$ and one independence verdict.
Givenedges $x_1x_2$, $x_1x_3$, $x_2x_3$, $x_3x_4$, $x_3x_5$, $x_4x_5$, $x_5x_6$
Solution

Find the triangles first, since every larger clique would contain them; the edges not inside a triangle are then maximal on their own.

Cliques

$$\begin{aligned}&\text{pairs: }12,\ 13,\ 23,\ 34,\\ &\qquad 35,\ 45,\ 56\\ &\text{triangles: }123,\ 345\end{aligned}$$

Every edge is a clique of two; $\{x_1,x_2,x_3\}$ and $\{x_3,x_4,x_5\}$ are fully connected. No four nodes are, so there are $9$ cliques.

Maximal cliques

$$\begin{aligned}M=\big\{&\{x_1,x_2,x_3\},\ \{x_3,x_4,x_5\},\\ &\{x_5,x_6\}\big\}\end{aligned}$$

The edge $x_5x_6$ cannot grow: $x_6$ has no other neighbour.

Factorization

$$\begin{aligned}p(x)&=\frac1Z\,\psi_{123}(x_1,x_2,x_3)\\ &\quad\times\psi_{345}(x_3,x_4,x_5)\\ &\quad\times\psi_{56}(x_5,x_6)\end{aligned}$$

One potential per maximal clique, then the normalizing constant.

Blanket and separation

$$\mathrm{MB}(x_3)=\{x_1,x_2,x_4,x_5\}$$

In an undirected graph the blanket is the neighbours.

$$x_1\perp\!\!\!\perp x_6\mid x_3$$

Every path from $x_1$ to $x_6$ passes through $x_3$, which is observed.

Answer $$\boxed{\begin{aligned}&9\ \text{cliques},\ 3\ \text{maximal}\\ &\mathrm{MB}(x_3)=\{x_1,x_2,x_4,x_5\}\\ &x_1\perp\!\!\!\perp x_6\mid x_3\end{aligned}}$$
Check

Count check on the maximal cliques: every edge must lie in at least one of them, and the triangles hold $3+3=6$ edges plus the edge $x_5x_6$, all $7$.

In an undirected graph, independence is plain separation: remove the observed nodes and see whether the two sets are still connected.

Normalizing a three-node chain, and checking separation with numbers

Three binary nodes form the chain $x_1 - x_2 - x_3$. Both potentials give $3$ to agreeing neighbours and $1$ to disagreeing ones. Find $Z$, $p(1,1,1)$, and check $x_1\perp\!\!\!\perp x_3\mid x_2$ numerically.

Find$Z$, $p(1,1,1)$, and the separation check at $x_2=1$.
Given
  • $\psi_{12}(a,b)=\psi_{23}(a,b)=3$ if $a=b$, $1$ if $a\ne b$

  • $x_1,x_2,x_3\in\{0,1\}$

Solution

With only $8$ configurations we list them all; the products fall into four groups by how many neighbours agree.

The sum Z

$$\begin{aligned}Z&=\underbrace{2\times9}_{000,\,111}+\underbrace{2\times3}_{001,\,110}\\ &\quad+\underbrace{2\times3}_{011,\,100}+\underbrace{2\times1}_{010,\,101}\\ &=18+6+6+2=32\end{aligned}$$

Two agreements give $3\times3$, one gives $3\times1$, none gives $1\times1$.

One probability

$$p(1,1,1)=\frac{\psi_{12}(1,1)\,\psi_{23}(1,1)}{Z}=\frac{9}{32}=0.281$$

A potential product becomes a probability only after dividing by $Z$.

Separation given x2 = 1

$$p(x_1=1,x_3=1\mid x_2=1)=\frac{9}{(3+1)(1+3)}=\frac{9}{16}=\frac34\cdot\frac34$$

With $x_2$ fixed, the sum over $(x_1,x_3)$ splits into a sum over $x_1$ times a sum over $x_3$.

$$p(x_1=1\mid x_2=1)=\frac{3}{3+1}=\frac34$$

The same for $x_3$; the product of the two is $9/16$, so independence given $x_2$ holds here.

Without x2

$$\begin{aligned}&p(x_3=1\mid x_1=1)\\ &=\frac{9+1}{9+3+3+1}=\frac58\\ &\ne p(x_3=1)=\frac12\end{aligned}$$

Summing over $x_2$ couples the ends: $x_1$ and $x_3$ are dependent until $x_2$ is known.

Answer $$\boxed{\begin{aligned}&Z=32\\ &p(1,1,1)=\tfrac{9}{32}\\ &p(x_1,x_3\mid x_2)\ \text{factors}\end{aligned}}$$
Check

Sum $x_2$ last: $Z=\sum_{x_2}\big(\sum_{x_1}\psi_{12}\big)\big(\sum_{x_3}\psi_{23}\big)=2\times(3+1)\times(3+1)=32$.

All $2^3=8$ configurations; a $100\times100$ binary image would need about $10^{3010}$.

$Z$ is a sum over every configuration: $8$ terms here, but $2^D$ in general, which is why it is the expensive part.

Checkpoint
§12.6 — maximal cliques of a square

An undirected graph on four nodes is a square: $x_1 - x_2 - x_3 - x_4 - x_1$, with no diagonal edges.

Find(a) How many maximal cliques does it have?
Givenedges $x_1x_2$, $x_2x_3$, $x_3x_4$, $x_4x_1$
Hint 1/4

Decide first whether any three nodes are fully connected.

Hint 2/4

A maximal clique is fully connected and cannot take one more node.

Hint 3/4

Each triple, such as $\{x_1,x_2,x_3\}$, misses a diagonal edge; each edge is fully connected.

Hint 4/4

The four edges are the maximal cliques: $4$.

Show solution

Look for triangles first; if there are none, every edge is maximal.

Triangles

$$\{x_1,x_2,x_3\}:\ x_1x_3\ \text{missing}$$

Every triple of the cycle misses a diagonal.

Edges

$$\begin{aligned}M=\{&\{x_1,x_2\},\{x_2,x_3\},\\ &\{x_3,x_4\},\{x_4,x_1\}\}\end{aligned}$$

No edge can be extended, so each is maximal.

Answer $$\boxed{\begin{aligned}&4\ \text{maximal cliques:}\\ &\text{the four edges}\end{aligned}}$$
Check

Every edge lies in exactly one maximal clique here, $4$ edges for $4$ cliques.

A cycle of four with no diagonal has no clique bigger than an edge.

⚠ Reading a potential as a probability

in a directed graph the factors are probabilities

wrong$$p(1,1,1)=\psi_{12}(1,1)\,\psi_{23}(1,1)=9$$
right$$p(1,1,1)=\frac{9}{Z}=\frac{9}{32}$$
⚠ Keeping only the biggest cliques

'maximal' sounds like 'largest'

wrong$$M=\{\{x_1,x_2,x_3\},\{x_3,x_4,x_5\}\}$$
right$$\begin{aligned}M=\{&\{x_1,x_2,x_3\},\{x_3,x_4,x_5\},\\ &\{x_5,x_6\}\}\end{aligned}$$
⚠ Adding co-parents to an undirected blanket

the directed rule is still fresh

wrong$$\mathrm{MB}(x_2)=\{x_1,x_3,x_4,x_5\}\ \text{in }H$$
right$$\mathrm{MB}(x_2)=\{x_1,x_3\}\ \text{in }H\text{: its neighbours}$$

12.7Image denoising: lower the energy one pixel at a time

An undirected grid cleans a noisy black-and-white image: lower the energy one pixel at a time until a full sweep changes nothing.

Neighbouring pixels of an image are the natural undirected graph, and a potential that rewards agreement turns 'clean images are smooth' into a probability.

MethodThe denoising and the coordinate-wise update
Conditions
  • $y_i\in\{-1,+1\}$: pixel $i$ of the noisy image, observed; $x_i\in\{-1,+1\}$: pixel $i$ of the clean image, unknown

  • $i\sim j$ runs over neighbouring pairs (up, down, left, right), each pair once

  • $\beta>0$ rewards agreeing neighbours, $\eta>0$ rewards agreeing with the reading, $h$ biases toward one colour

  • $a_j$ is the vote of pixel $j$; if $a_j=0$ the pixel keeps its value

$$\boxed{\begin{aligned}E(x,y)&=h\sum_ix_i\\ &\quad-\beta\sum_{i\sim j}x_ix_j\\ &\quad-\eta\sum_ix_iy_i\\ p(x,y)&=\frac{1}{Z}e^{-E(x,y)}\\ a_j&=\beta\sum_{k\sim j}x_k+\eta y_j-h\\ x_j&\leftarrow\begin{cases}+1,&a_j>0\\ -1,&a_j<0\end{cases}\end{aligned}}$$

The energy is low when neighbouring pixels agree and when each pixel agrees with its reading, so the most probable clean image has the lowest energy. One pixel at a time takes the value with the lower energy; the energy never rises, and a sweep with no change marks a local maximum of the probability.

Only one pixel's terms change, so the rule is a sign

The maximal cliques are the neighbour pairs $\{x_i,x_j\}$ and the pairs $\{x_i,y_i\}$; the energy has one term per clique, and the bias $hx_i$ can be merged into the pair with $y_i$.

Collect the terms with $x_j$: $E=x_j\big(h-\beta\sum_{k\sim j}x_k-\eta y_j\big)+\text{(rest)}$. So $E(x_j=+1)-E(x_j=-1)=2\big(h-\beta\sum_kx_k-\eta y_j\big)$, negative exactly when the vote $\beta\sum_kx_k+\eta y_j-h$ is positive.

Each update keeps or lowers $E$, and $E$ takes finitely many values, so the sweeps stop. The final image cannot be improved by changing one pixel, but a better image that needs several changes at once may exist.

This is the lecture's coordinate-wise descent on the energy; many books call it .

Looks like this, but is not

Every pixel ends up with the colour of the majority of its neighbours.

The reading votes too, with weight $\eta$. With $\beta=1$ and $\eta=1.5$, an edge pixel with two white neighbours and one black keeps its black reading: $1\cdot(2-1)+1.5\cdot(-1)=-0.5<0$.

Which of two 2 by 2 images is more probable?

A noisy $2\times2$ image has three white pixels and a black one in the bottom right: $y=\begin{smallmatrix}+1&+1\\+1&-1\end{smallmatrix}$. With $\beta=1$, $\eta=1.5$, $h=0$, compare the energy of $x=y$ with that of the all-white $x$, and say how much more probable the better one is.

Find$E(x,y)$ for both candidates and the ratio of their probabilities.
Given
  • $y$: rows $(+1,+1)$ and $(+1,-1)$

  • $\beta=1$, $\eta=1.5$, $h=0$

  • neighbour pairs: the two rows and the two columns, $4$ pairs

Solution

Evaluate the two sums of the energy separately, neighbour pairs and pixel-reading pairs, because each candidate wins one of them.

x = y

$$\begin{aligned}&\sum_{i\sim j}x_ix_j=1-1+1-1=0\\ &\sum_ix_iy_i=4\end{aligned}$$

The black pixel disagrees with both of its neighbours; every pixel agrees with its reading.

$$E=-1(0)-1.5(4)=-6$$

$E=h\sum x_i-\beta\sum x_ix_j-\eta\sum x_iy_i$ with $h=0$.

All white

$$\begin{aligned}&\sum_{i\sim j}x_ix_j=4\\ &\sum_ix_iy_i=1+1+1-1=2\end{aligned}$$

All pairs agree now, but the corner pixel contradicts its reading.

$$E=-1(4)-1.5(2)=-7$$

Lower energy than $x=y$.

Probability ratio

$$\frac{p(\text{white}\mid y)}{p(x=y\mid y)}=\frac{e^{7}}{e^{6}}=e\approx2.72$$

$p(x\mid y)\propto e^{-E(x,y)}$; $Z$ cancels in a ratio.

Answer $$\boxed{\begin{aligned}E(y)&=-6\\ E(\text{white})&=-7\\ \text{ratio}&=e\approx2.72\end{aligned}}$$
Check

Pixel rule for the corner: its two neighbours say $+1$ with weight $\beta\cdot2=2$, its reading says $-1$ with weight $1.5$; $2-1.5>0$, so white wins, as the energies say.

A lone pixel that disagrees with its neighbours is cheaper to flip than to keep, once $\beta\times(\text{agreeing neighbours})$ exceeds $\eta$.

A full sweep on a 4 by 4 image

The noisy image $y$ below should be two black columns and two white ones, but two pixels were flipped. Starting from $x=y$, run coordinate-wise updates with $\beta=1$, $\eta=1.5$, $h=0$, row by row, until a sweep changes nothing. Track the energy.

FindThe final image, the pixels that changed, and the energies.
Given
  • noisy image, $\blacksquare=-1$ (black), $\square=+1$ (white): $$y=\begin{array}{cccc}\blacksquare&\blacksquare&\square&\square\\ \blacksquare&\blacksquare&\blacksquare&\square\\ \square&\blacksquare&\square&\square\\ \blacksquare&\blacksquare&\square&\square\end{array}$$

  • $\beta=1$, $\eta=1.5$, $h=0$

  • update: $x_j=+1$ if $\beta\sum_{k\sim j}x_k+\eta y_j>0$, $-1$ if $<0$

Solution

Only pixels whose neighbours disagree with them can change, so we check those first; the others keep their value because $\beta\sum x_k$ and $\eta y_j$ point the same way.

Start

$$E(y,y)=-\beta(6)-\eta(16)=-6-24=-30$$

Of the $24$ neighbour pairs, $15$ agree and $9$ disagree, so $\sum x_ix_j=6$; every pixel matches its reading, so $\sum x_iy_i=16$.

Sweep 1, pixel (2, 3)

$$\begin{aligned}&\beta(+1-1+1+1)+1.5(-1)\\ &=0.5>0\ \Rightarrow\ x_{23}=+1\end{aligned}$$

Three of its four neighbours are white, which outvotes its black reading.

$$E:\ -30\to-31$$

$\Delta E=(x_{\text{new}}-x_{\text{old}})(h-\beta\sum x_k-\eta y_j)=2(-0.5)=-1$.

Sweep 1, pixel (3, 1)

$$\begin{aligned}&\beta(-1-1-1)+1.5(+1)\\ &=-1.5<0\ \Rightarrow\ x_{31}=-1\end{aligned}$$

An edge pixel with three black neighbours: they outvote its white reading.

$$E:\ -31\to-34$$

$\Delta E=(-2)(0-(-3)-1.5)=-3$.

Sweep 2

$$\text{no pixel changes}\ \Rightarrow\ \text{stop}$$

Every pixel's vote now has the sign of its current value, so no update changes anything.

Answer $$\boxed{\begin{aligned}x&=\begin{array}{cccc}\blacksquare&\blacksquare&\square&\square\\ \blacksquare&\blacksquare&\square&\square\\ \blacksquare&\blacksquare&\square&\square\\ \blacksquare&\blacksquare&\square&\square\end{array}\\ E&=-34\end{aligned}}$$
Check

Direct energy of the final image: $20$ neighbour pairs agree and $4$ disagree across the middle, so $\sum x_ix_j=16$; $14$ pixels match their readings and $2$ do not, so $\sum x_iy_i=12$; $E=-16-1.5(12)=-34$.

$16$ pixel checks per sweep, two sweeps.

Coordinate-wise updates fix isolated flips in one sweep; a second sweep is needed only to confirm that nothing else moves.

Checkpoint
§12.7 — one pixel's update

In the denoising model with $\beta=1$, $\eta=1.5$ and $h=0$, an interior pixel currently equals its black reading, $x_j=y_j=-1$. Its four neighbours are white, white, white and black.

Find(a) What does one coordinate-wise update do to this pixel, and to the energy?
Given
  • neighbours $+1,\ +1,\ +1,\ -1$

  • $x_j=y_j=-1$

  • $\beta=1$, $\eta=1.5$, $h=0$

Hint 1/4

Compare the energy with $x_j=+1$ and with $x_j=-1$, everything else fixed.

Hint 2/4

$x_j=+1$ exactly when $\beta\sum_{k\sim j}x_k+\eta y_j-h>0$.

Hint 3/4

$\sum_kx_k=+1+1+1-1=2$ and $\eta y_j=1.5\times(-1)$, so the vote is $2-1.5$.

Hint 4/4

The vote is $0.5>0$: the pixel turns white and $E$ drops by $1$.

Show solution

Use the pixel rule instead of recomputing the whole energy: only the terms with $x_j$ change.

The vote

$$\beta\sum_kx_k+\eta y_j=1\cdot2+1.5(-1)=0.5>0$$

The neighbour sum is $3-1=2$.

The energy change

$$\Delta E=(+1-(-1))\,(h-2-1.5\cdot(-1))=2(-0.5)=-1$$

Only the terms containing $x_j$ change.

Answer $$\boxed{\begin{aligned}&x_j=+1\\ &\Delta E=-1\end{aligned}}$$
Check

Sign check: the energy must go down when the rule changes a pixel, and $-1<0$.

Compute the vote $\beta\sum x_k+\eta y_j-h$ and read off its sign; the energy change is minus twice the vote when the pixel flips from $-1$ to $+1$.

⚠ Choosing the value with the higher energy

a larger product $x_ix_j$ feels like a larger energy

wrong$$x_j=+1\ \text{if}\ \beta\sum_kx_k+\eta y_j-h<0$$
right$$x_j=+1\ \text{if}\ \beta\sum_kx_k+\eta y_j-h>0$$
⚠ Forgetting the reading

smoothing is the visible goal

wrong$$x_j\leftarrow\operatorname{sign}\Big(\sum_{k\sim j}x_k\Big)$$
right$$x_j\leftarrow\operatorname{sign}\Big(\beta\sum_{k\sim j}x_k+\eta y_j-h\Big)$$
⚠ Counting each neighbour pair twice

a double sum over pixels and their neighbours visits every pair from both ends

wrong$$-\beta\sum_i\sum_{k\sim i}x_ix_k$$
right$$-\beta\sum_{i\sim j}x_ix_j\ \ \text{(each pair once)}$$
observed y1122334455current x1122334455energy E = −45.5start from x = ydots on y: flipped by noise

Step through coordinate-wise denoising of a $5\times5$ image with $\beta=1$, $\eta=1.5$, $h=0$. Dots on the $\textcolor{#d1690a}{\text{observed }y}$ mark the four pixels flipped by noise; the $\textcolor{#8250df}{\text{outlined}}$ pixel is the one just updated, and each frame prints the energy.

At the edges
sweep 1, pixel (2, 3) a wrong move

Two noisy neighbours outvote the pixel's correct white reading, so it turns black. Sweep 2 undoes it once the neighbours are fixed: a greedy step can go wrong and still end well.

sweep 3 no change

The energy is $-55.5$, the energy of the clean image; here the local minimum is the clean image, which is not guaranteed in general.

Deciding A independent of B given C in a directed graph

A question gives a directed graph and asks whether $A\perp\!\!\!\perp B\mid C$.

  1. List the paths

    Every chain of edges from a node of $A$ to a node of $B$, walked either way, never visiting a node twice.

  2. Classify the nodes

    At each interior node, the two arrows of the path meet head-to-tail, tail-to-tail or head-to-head.

  3. Mark blocked paths

    Blocked if some node is head-to-tail or tail-to-tail and in $C$, or head-to-head with neither it nor a descendant in $C$.

  4. Conclude

    All paths blocked: $A\perp\!\!\!\perp B\mid C$. One open path: dependent in general.

Where it goes wrong
  • Stopping after the first blocked path.

  • Checking the head-to-head node but not its descendants.

  • Treating an unobserved head-to-head node as open.

A posterior by enumeration in a small network

A few binary nodes with tables, some observed, and one query such as $p(L=1\mid F=1)$.

  1. Factor

    Write the joint as the product of parent conditionals.

  2. Fix the evidence

    Put the observed values into every factor.

  3. Sum out

    For each value of the query, add the product over the unobserved variables; a factor without a summed variable moves outside that sum.

  4. Normalize

    Divide each result by their total.

Where it goes wrong
  • Summing over an observed variable instead of fixing it.

  • Dropping a prior factor, such as $p(R)$, from some terms but not from others.

  • Stopping before the division, which leaves the joint $p(\text{query},\text{evidence})$.

Training and using Bernoulli naive Bayes

Binary features, labelled training rows, and a new row to classify.

  1. Count

    $n_c$ per class and $n_{jc}$ per feature inside each class.

  2. Estimate

    $\hat\pi_c=n_c/n$ and $\hat\theta_{jc}=n_{jc}/n_c$.

  3. Score

    $\hat\pi_c$ times, for each feature, $\hat\theta_{jc}$ if $x_j=1$ and $1-\hat\theta_{jc}$ if $x_j=0$.

  4. Normalize and decide

    Divide the scores by their sum and predict the largest.

Where it goes wrong
  • Dividing $n_{jc}$ by $n$.

  • Leaving out the factors of absent features.

  • A zero count makes $\hat\theta_{jc}$ exactly $0$ or $1$ and can force a posterior of $0$.

Coordinate-wise denoising by hand

A small $\pm1$ image, the weights $\beta$, $\eta$, $h$, and a request to clean it.

  1. Start

    Set $x=y$.

  2. Vote

    For pixel $j$, compute $\beta\sum_{k\sim j}x_k+\eta y_j-h$ with the current neighbours.

  3. Set

    $x_j=+1$ if the vote is positive, $-1$ if negative, unchanged at $0$; use the new value at once.

  4. Sweep and stop

    Visit every pixel in order; stop after a sweep with no change.

Where it goes wrong
  • Using the old neighbour values for a whole sweep.

  • Moving toward the higher energy.

  • Leaving out the reading $y_j$.

Chain: the observed middle node silences the far end

In $W\to L\to F$ (sensor tables), compare $p(F=1\mid L=1,W=1)$ with $p(F=1\mid L=1,W=0)$.

FindThe two conditionals.
Given$p(F=1\mid L=1)=0.9(0.9)+0.1(0.95)=0.905$ after summing out $R$
Solution

Find where $W$ enters the factors of $F$.

Both values of W

$$\begin{aligned}&p(F=1\mid L=1,W)\\ &=\sum_Rp(R)\,p(F=1\mid L=1,R)\\ &=0.905\end{aligned}$$

No factor of $F$ contains $W$; with $L$ known, $W$ has no way through.

Answer $$\boxed{0.905\ \text{for both values of }W}$$
Check

Without $L$ the weather matters: $0.194$ on cloudy days, $0.110$ otherwise.

Head-to-tail at an observed node: blocked.

Collider: the observed middle node connects its parents

In $L\to F\leftarrow R$ (sensor tables), with $F=1$ observed, compare $p(L=1\mid F=1,R=1)$ with $p(L=1\mid F=1,R=0)$.

FindThe two conditionals.
Given
  • $p(L=1)=0.1$, $p(R=1)=0.1$

  • $p(F=1\mid L,R)=0.02,\ \allowbreak 0.5,\ \allowbreak 0.9,\ \allowbreak 0.95$

Solution

Enumerate over $L$ with $F$ and $R$ fixed; $p(R)$ cancels.

R = 1

$$\frac{0.1(0.95)}{0.1(0.95)+0.9(0.5)}=0.174$$

Interference explains the lost packet.

R = 0

$$\frac{0.1(0.9)}{0.1(0.9)+0.9(0.02)}=0.833$$

Without interference, the battery is the suspect.

Answer $$\boxed{0.174\ \text{against}\ 0.833}$$
Check

The two values bracket $p(L=1\mid F=1)=0.597$, which is their average weighted by $p(R\mid F=1)$.

Head-to-head at an observed node: opened.

Both examples observe the middle node of three; the chain goes silent and the collider starts to carry information.

How to tell them apart

Look at the arrowheads at the observed node: two heads meeting there open the path; any other pattern blocks it.

Directed blanket of x3 in G

Graph $G$: $x_1\to x_2$, $x_1\to x_3$, $x_6\to x_3$, $x_2\to x_4$, $x_3\to x_4$, $x_4\to x_5$. Find $\mathrm{MB}(x_3)$.

Find$\mathrm{MB}(x_3)$.
Giventhe arrows of $G$
Solution

Parents, children, co-parents.

Collect

$$\{x_1,x_6\}\cup\{x_4\}\cup\{x_2\}$$

$x_2$ is the other parent of the child $x_4$.

Answer $$\boxed{\{x_1,x_2,x_4,x_6\}}$$
Check

The factors with $x_3$ are $p(x_3\mid x_1,x_6)$ and $p(x_4\mid x_2,x_3)$; their other variables are these four.

Head-to-head at the child $x_4$ pulls $x_2$ in.

Undirected blanket of x3 on the same links

Drop the arrows of $G$ and read the same six links as an undirected graph. Find $\mathrm{MB}(x_3)$.

Find$\mathrm{MB}(x_3)$.
Givenedges $x_1x_2$, $x_1x_3$, $x_3x_6$, $x_2x_4$, $x_3x_4$, $x_4x_5$
Solution

In an undirected graph the blanket is the set of neighbours.

Neighbours

$$\{x_1,x_4,x_6\}$$

$x_2$ is two steps away, through $x_1$ or $x_4$.

Answer $$\boxed{\{x_1,x_4,x_6\}}$$
Check

Separation check: removing $x_1$, $x_4$, $x_6$ leaves $x_3$ with no edge at all.

Without arrows, nothing is head-to-head, so there are no co-parents.

The same six links give two blankets: arrows meeting head-to-head at $x_4$ bring the co-parent $x_2$ into the directed one.

How to tell them apart

Directed: parents, children and co-parents. Undirected: neighbours only.

Two nodes with an arrow: the product is already a probability

$a\to b$ with $p(a=1)=0.3$ and $p(b=1\mid a=1)=0.8$. Find $p(a=1,b=1)$.

Find$p(a=1,b=1)$.
Given
  • $p(a=1)=0.3$

  • $p(b=1\mid a=1)=0.8$

Solution

Multiply the two factors of the directed factorization.

Multiply

$$p(a=1,b=1)=0.3\times0.8=0.24$$

Each factor is a probability, so no rescaling is needed.

Answer $$\boxed{0.24}$$
Check

The four products $0.24, \allowbreak 0.06, \allowbreak 0.7p(b=1\mid a=0), \allowbreak 0.7p(b=0\mid a=0)$ add to $1$ for any table.

Directed factors are normalized one by one.

Two nodes with an edge: the product needs Z

$a - b$ with $\psi(a,b)=3$ if $a=b$ and $1$ otherwise. Find $p(a=1,b=1)$.

Find$p(a=1,b=1)$.
Given$\psi(0,0)=\psi(1,1)=3$, $\psi(0,1)=\psi(1,0)=1$
Solution

Divide the potential by the sum over all four configurations.

Normalize

$$\begin{aligned}&Z=3+1+1+3=8\\ &p(a=1,b=1)=\frac38\end{aligned}$$

The potential $3$ is a score, not a probability.

Answer $$\boxed{\tfrac38=0.375}$$
Check

The four probabilities $3/8, \allowbreak 1/8, \allowbreak 1/8, \allowbreak 3/8$ add to $1$.

Undirected potentials are normalized once, globally, by $Z$.

A directed factor is already a probability; an undirected potential is a score until the whole product is divided by $Z$.

How to tell them apart

Arrows: multiply the conditionals. No arrows: multiply the potentials, then divide by their sum over every configuration.

Scaffolding comes off
The common skeleton
  1. Count $n_c$ for each class and $n_{jc}$ for each feature inside each class.

  2. Estimate $\hat\pi_c=n_c/n$ and $\hat\theta_{jc}=n_{jc}/n_c$.

  3. Score each class: $\hat\pi_c$ times $\hat\theta_{jc}$ for every $x_j=1$ and $1-\hat\theta_{jc}$ for every $x_j=0$.

  4. Divide the scores by their sum and predict the largest.

1 · fully worked

Two alarms, eight checks: train, then classify one machine

Eight past checks recorded two alarms, $x_1$ (over-temperature) and $x_2$ (over-current), and the finding $y=1$ (fault) or $y=2$ (no fault). Fault: $(1,1)$, $(1,0)$, $(0,1)$. No fault: $(0,0)$, $(1,0)$, $(0,0)$, $(0,1)$, $(0,0)$. Classify a machine with $x=(1,0)$.

Find$p(y=1\mid x)$ and the decision.
Given
  • fault, $y=1$: $(1,1)$, $(1,0)$, $(0,1)$

  • no fault, $y=2$: $(0,0)$, $(1,0)$, $(0,0)$, $(0,1)$, $(0,0)$

  • new machine $x=(1,0)$

Solution

Count, estimate, score, normalize: the four lines of the method box, in order.

Count

$$\begin{aligned}&n_1=3,\ n_2=5\\ &n_{11}=2,\ n_{21}=2\\ &n_{12}=1,\ n_{22}=1\end{aligned}$$

Class sizes, then the $1$s of each alarm inside each class.

Estimate

$$\hat\pi=\Big(\tfrac38,\ \tfrac58\Big),\quad \hat\theta_{\cdot1}=\Big(\tfrac23,\ \tfrac23\Big),\quad \hat\theta_{\cdot2}=\Big(\tfrac15,\ \tfrac15\Big)$$

Shares over $n=8$; rates over the class sizes $3$ and $5$.

Score

$$\begin{aligned}&\tfrac38\cdot\tfrac23\cdot\tfrac13=\tfrac1{12}\\ &\tfrac58\cdot\tfrac15\cdot\tfrac45=\tfrac1{10}\end{aligned}$$

$x_2=0$, so each class uses $1-\hat\theta_{2c}$: $\tfrac13$ and $\tfrac45$.

Normalize and decide

$$p(y=1\mid x)=\frac{1/12}{1/12+1/10}=\frac{5}{11}=0.455\ \Rightarrow\ \hat c=2$$

The over-temperature alarm points to a fault, but the silent over-current alarm and the larger share of healthy machines point the other way.

Answer $$\boxed{\begin{aligned}&p(\text{fault}\mid x)=\tfrac{5}{11}\approx0.455\\ &\text{predict no fault}\end{aligned}}$$
Check

Log-odds route: $\log(3/5)+\log\frac{2/3}{1/5}+\log\frac{1/3}{4/5}=-0.511+1.204-0.875=-0.182$, and $1/(1+e^{0.182})=0.455=5/11$.

One feature pointing to a class is not enough; the prior and the absent features vote as well.

2 · you write the reasoning

Easier: the estimates are given, so only scoring is left. Two classes with $\hat\pi=(0.5,0.5)$, $\hat\theta_{\cdot1}=(0.8,\ 0.3)$, $\hat\theta_{\cdot2}=(0.2,\ 0.6)$, and a new point $x=(1,1)$. For each line, write why it is allowed.

  1. $$\text{score}_1=0.5\times0.8\times0.3=0.12$$

    reasoning

    Class 1: its share times $\hat\theta_{11}$ for $x_1=1$ times $\hat\theta_{21}$ for $x_2=1$.

  2. $$\text{score}_2=0.5\times0.2\times0.6=0.06$$

    reasoning

    The same product with the class 2 estimates.

  3. $$p(y=1\mid x)=\frac{0.12}{0.12+0.06}=\frac23$$

    reasoning

    The scores are proportional to the posteriors, so dividing by their sum gives probabilities.

  4. $$\hat c=1$$

    reasoning

    The larger posterior wins; equal shares mean only the feature rates decided.

3 · find the buried error

Harder, and the solution below hides two errors. Twelve past checks with three alarms: fault ($y=1$): $(1,1,0)$, $(1,1,0)$, $(1,0,1)$, $(1,1,0)$, $(0,0,0)$; no fault ($y=2$): $(0,0,1)$, $(0,1,1)$, $(1,0,1)$, $(0,0,1)$, $(0,1,0)$, $(0,0,1)$, $(0,0,0)$. A student classifies $x=(1,1,0)$.

  1. Step 1. Class counts and shares.

    $$\begin{aligned}&n_1=5,\ n_2=7\\ &\hat\pi=\Big(\tfrac5{12},\ \tfrac7{12}\Big)\end{aligned}$$

  2. Step 2. Rates of the three alarms in class 1.

    $$\hat\theta_{\cdot1}=\Big(\tfrac45,\ \tfrac3{12},\ \tfrac15\Big)$$

  3. Step 3. Rates of the three alarms in class 2.

    $$\hat\theta_{\cdot2}=\Big(\tfrac17,\ \tfrac27,\ \tfrac57\Big)$$

  4. Step 4. Scores of the two classes for $x=(1,1,0)$.

    $$\begin{aligned}&\tfrac5{12}\cdot\tfrac45\cdot\tfrac3{12}\cdot\tfrac15=0.0167\\ &\tfrac7{12}\cdot\tfrac17\cdot\tfrac27\cdot\tfrac57=0.0170\end{aligned}$$

  5. Step 5. Normalize.

    $$p(y=1\mid x)=\frac{0.0167}{0.0167+0.0170}=0.495$$

  6. Step 6. Class 2, by a hair.

    $$\hat c=2$$

the two buried errors (2)
⚠ step 2

The rate of the second alarm in class 1 is divided by all $12$ checks: $\hat\theta_{21}=3/12$. Three of the $5$ fault rows have $x_2=1$, so $\hat\theta_{21}=3/5$.

$n$ is the number printed at the top of the data, and the class shares in step 1 did divide by it.

right

$\hat\theta_{\cdot1}=(4/5,\ 3/5,\ 1/5)$.

⚠ step 4

For $x_3=0$ both scores multiply by $\hat\theta_{3c}$ instead of $1-\hat\theta_{3c}$: $1/5$ and $5/7$ should be $4/5$ and $2/7$.

Writing the product as $\prod_j\hat\theta_{jc}$ for every feature is the habit from features that are all $1$.

right

Scores $\tfrac5{12}\cdot\tfrac45\cdot\tfrac35\cdot\tfrac45=0.16$ and $\tfrac7{12}\cdot\tfrac17\cdot\tfrac27\cdot\tfrac27=0.0068$, so $p(y=1\mid x)=0.959$ and the decision flips to class 1.

4 · the bare problem
§12.4 — naive Bayes from data to decision

A pipe monitor logs three binary signals: $x_1$ humidity alarm, $x_2$ pressure drop, $x_3$ night-time reading. Ten past readings were labelled leak ($y=1$) or no leak ($y=2$).

Find
  1. (a) Estimate $\hat\pi_c$ and $\hat\theta_{jc}$ by maximum likelihood.

  2. (b) Find $p(y=1\mid x)$ and the predicted class.

Given
  • leak ($y=1$): $(1,1,1)$, $(1,1,0)$, $(1,0,1)$, $(0,1,0)$

  • no leak ($y=2$): $(1,0,1)$, $(0,1,0)$, $(0,0,1)$, $(0,0,0)$, $(0,0,1)$, $(0,0,0)$

  • new reading $x=(0,1,1)$

Hint 1/4

Train first (shares and rates from counts), then score the two classes for the new reading.

Hint 2/4

$\hat\pi_c=n_c/n$, $\hat\theta_{jc}=n_{jc}/n_c$; score $=\hat\pi_c\prod_j$ ($\hat\theta_{jc}$ or $1-\hat\theta_{jc}$).

Hint 3/4

Leak rows: $4$, with $x_1,x_2,x_3$ equal to $1$ in $3$, $3$, $2$ of them; no-leak rows: $6$, with $1$, $1$, $3$. The new reading is $x=(0,1,1)$.

Hint 4/4

Scores $0.0375$ and $0.0417$ give $p(y=1\mid x)=9/19\approx0.474$: predict no leak.

Show solution

The same four lines as the fully worked rung.

Count and estimate

$$\hat\pi=(0.4,\ 0.6),\quad \hat\theta_{\cdot1}=\Big(\tfrac34,\ \tfrac34,\ \tfrac12\Big),\quad \hat\theta_{\cdot2}=\Big(\tfrac16,\ \tfrac16,\ \tfrac12\Big)$$

$n_1=4$ with $3$, $3$, $2$ ones; $n_2=6$ with $1$, $1$, $3$ ones.

Score

$$\begin{aligned}&0.4\cdot\tfrac14\cdot\tfrac34\cdot\tfrac12=0.0375\\ &0.6\cdot\tfrac56\cdot\tfrac16\cdot\tfrac12=0.0417\end{aligned}$$

$x_1=0$ uses $1-\hat\theta_{1c}$; the night-time factor $\tfrac12$ is the same in both classes.

Normalize and decide

$$\begin{aligned}&p(y=1\mid x)=\frac{0.0375}{0.0375+0.0417}\\ &=\frac{9}{19}=0.474\ \Rightarrow\ \hat c=2\end{aligned}$$

A close call; the pressure drop alone is not enough against the silent humidity alarm and the larger no-leak share.

Answer $$\boxed{\begin{aligned}&p(\text{leak}\mid x)=\tfrac{9}{19}\approx0.474\\ &\text{predict no leak}\end{aligned}}$$
Check

Log-odds check: $\log\frac{0.4}{0.6}+\log\frac{1/4}{5/6}+\log\frac{3/4}{1/6}+\log1=-0.405-1.204+1.504=-0.105$, and $1/(1+e^{0.105})=0.474$.

A feature with the same rate in every class cancels from the decision; check for it before multiplying.

Full exam-style question

A server room: factorization, independence, blanket and explaining awayexam format

A server can lose power ($P=1$) because of a grid outage ($G=1$) or a worn UPS battery ($U=1$). A power loss can cause a disk error ($K=1$) and triggers a monitoring alert ($M=1$). The graph is $G\to P\leftarrow U$, $P\to K$, $P\to M$.

  • (a) Write the joint and count its free numbers against a full table.
  • (b) Decide $G\perp\!\!\!\perp U$, $G\perp\!\!\!\perp U\mid M$ and $K\perp\!\!\!\perp M\mid P$.
  • (c) Give the Markov blanket of $U$.
  • (d) Find $p(G=1\mid P=1)$.
  • (e) A technician finds the UPS healthy, $U=0$. Find $p(G=1\mid P=1,U=0)$.
Find(a) the factorization and the counts; (b) three verdicts; (c) $\mathrm{MB}(U)$; (d) and (e) two posteriors.
Given
  • $p(G=1)=0.1$, $p(U=1)=0.1$

  • $p(P=1\mid G,U)=0.001,\ \allowbreak 0.3,\ \allowbreak 0.05,\ \allowbreak 0.95$ for $(G,U)=(0,0), \allowbreak (0,1), \allowbreak (1,0), \allowbreak (1,1)$

  • $p(K=1\mid P=1)=0.3$, $p(K=1\mid P=0)=0.01$; $p(M=1\mid P=1)=0.99$, $p(M=1\mid P=0)=0.001$

Solution

Structure first, numbers last: (a) to (c) need only the graph, and (d) and (e) need only the four cells of $p(G)p(U)p(P=1\mid G,U)$, because $K$ and $M$ sum to $1$ when unobserved.

(a) Factorization

$$\begin{aligned}&p(G,U,P,K,M)\\ &=p(G)\,p(U)\,p(P\mid G,U)\\ &\quad\times p(K\mid P)\,p(M\mid P)\end{aligned}$$

One factor per node.

$$1+1+4+2+2=10\ \ \text{against}\ \ 2^5-1=31$$

One number per parent configuration of each binary node.

(b) Three verdicts

$$G\perp\!\!\!\perp U$$

The only path $G\to P\leftarrow U$ is head-to-head at the unobserved $P$, whose descendants $K$, $M$ are unobserved.

$$G\not\perp\!\!\!\perp U\mid M$$

$M$ is a descendant of the collider $P$, so observing it opens the path.

$$K\perp\!\!\!\perp M\mid P$$

The only path $K\leftarrow P\to M$ is tail-to-tail at the observed $P$.

(c) Blanket of U

$$\mathrm{MB}(U)=\{P,G\}$$

No parents, the child $P$, and $P$'s other parent $G$.

(d) Belief in an outage after a power loss

$$\begin{aligned}p(P=1)&=0.00081+0.027\\ &\quad+0.0045+0.0095\\ &=0.04181\end{aligned}$$

The cells $p(G)p(U)p(P=1\mid G,U)$ are $0.9(0.9)(0.001)$, $0.9(0.1)(0.3)$, $0.1(0.9)(0.05)$ and $0.1(0.1)(0.95)$; $K$ and $M$ are summed out and vanish.

$$p(G=1\mid P=1)=\frac{0.0045+0.0095}{0.04181}=0.335$$

Keep the cells with $G=1$.

(e) After the UPS is found healthy

$$\begin{aligned}&p(G=1\mid P=1,U=0)\\ &=\frac{0.1(0.05)}{0.1(0.05)+0.9(0.001)}\\ &=\frac{0.005}{0.0059}=0.847\end{aligned}$$

Only the cells with $U=0$ remain; $p(U=0)$ cancels. Ruling out one cause makes the other the explanation.

Answer $$\boxed{\begin{aligned}&\text{(a) }10\text{ vs }31\\ &\text{(b) }G\perp\!\!\!\perp U;\ \text{not given }M;\\ &\qquad K\perp\!\!\!\perp M\mid P\\ &\text{(c) }\{P,G\}\\ &\text{(d) }0.335\qquad\text{(e) }0.847\end{aligned}}$$
Check

(e) the other way: with $U=1$ the outage becomes less likely, $0.1(0.95)/(0.1(0.95)+0.9(0.3))=0.260$. The answer to (d), $0.335$, lies between $0.260$ and $0.847$ because it is their average weighted by $p(U\mid P=1)$.

Four products for (d), two for (e).

In an exam, settle the graph questions before any arithmetic: they decide which factors the numbers even need.

Practice

A · concept 4 questions
1§12.4 — what naive Bayes really assumes

A classmate's summary sheet says: 'Naive Bayes assumes that the features are independent of each other.'

Find(a) Is the statement true or false?
Given
  • naive Bayes graph: $y\to x_j$ for every $j$, no edges between features

  • e-mail model: $\hat\pi=(0.4,\ 0.6)$; $\hat\theta_{1c}=\hat\theta_{3c}=(3/4,\ 1/6)$ for $c=1,2$

Hint 1/4

Separate two claims: independence once the label is known, and independence with the label unknown.

Hint 2/4

Tail-to-tail at $y$: $x_j\perp\!\!\!\perp x_k\mid y$, but dependent in general without $y$.

Hint 3/4

In the e-mail model $p(x_1=1)=p(x_3=1)=0.4(0.75)+0.6(1/6)=0.4$ and $p(x_1=1,x_3=1)=0.4(0.75)^2+0.6(1/6)^2=0.242$.

Hint 4/4

$0.242\ne0.4\times0.4=0.16$, so the statement is false.

Show solution

One pair of values that breaks the product settles it, so we compute a single cell.

Marginals

$$p(x_1=1)=0.4(0.75)+0.6\big(\tfrac16\big)=0.4$$

Sum over the label; the same for $x_3$.

Joint

$$p(x_1=1,x_3=1)=0.4(0.75)^2+0.6\big(\tfrac16\big)^2=0.2417$$

Given $y$ the features multiply; then sum over $y$.

Compare

$$0.2417\ne0.4^2=0.16$$

A mixture of products is not a product.

Answer $$\boxed{\text{False}}$$
Check

Given $y=1$ the product does hold: $0.75\times0.75=0.5625=p(x_1=1,x_3=1\mid y=1)$.

'Naive' is about the features given the class, never about the features alone.

2§12.2 — can observing a node create dependence?

In the sensor model the battery $L$ and the interference $R$ are independent before anything is observed. A student claims that observing a third variable can never make two independent variables dependent.

Find(a) Is the student's claim true or false?
Given
  • $W\to L\to F\leftarrow R$, $F\to S$

  • $p(W=1)=0.5$, $p(R=1)=0.1$; $p(L=1\mid W)=0.15$ if $W=1$, $0.05$ if $W=0$

  • $p(F=1\mid L,R)=0.02,\ \allowbreak 0.5,\ \allowbreak 0.9,\ \allowbreak 0.95$ for $(L,R)=(0,0), \allowbreak (0,1), \allowbreak (1,0), \allowbreak (1,1)$

  • $p(S=1\mid F=1)=0.95$, $p(S=1\mid F=0)=0.01$

Hint 1/4

Look for a node that both $L$ and $R$ point into.

Hint 2/4

Head-to-head at $c$: $a\perp\!\!\!\perp b$, but dependent given $c$.

Hint 3/4

$L\to F\leftarrow R$ with $F=1$: $p(L=1\mid F=1,R=1)=0.174$ against $p(L=1\mid F=1,R=0)=0.833$.

Hint 4/4

The two differ, so observing $F$ makes $L$ and $R$ dependent: the claim is false.

Show solution

If $L\perp\!\!\!\perp R\mid F$, the belief in $L$ could not change with $R$; we check whether it does.

R = 1

$$\frac{0.1(0.95)}{0.1(0.95)+0.9(0.5)}=0.174$$

Enumerate over $L$ with $F=1$, $R=1$.

R = 0

$$\frac{0.1(0.9)}{0.1(0.9)+0.9(0.02)}=0.833$$

The same with $R=0$.

Answer $$\boxed{\text{False}}$$
Check

Without $F$: $p(L=1\mid R)=0.1$ for both values of $R$, so they really were independent before.

Observing a collider, or anything below it, can create dependence.

3§12.3 — which observation connects two roots

In the sensor model the weather $W$ and the interference $R$ are independent. Which set of observed variables makes them dependent?

Find(a) Choose the observed set $C$ for which $W$ and $R$ are not d-separated.
Given
  • $W\to L\to F\leftarrow R$, $F\to S$

  • $p(W=1)=0.5$, $p(R=1)=0.1$; $p(L=1\mid W)=0.15$ if $W=1$, $0.05$ if $W=0$

  • $p(F=1\mid L,R)=0.02,\ \allowbreak 0.5,\ \allowbreak 0.9,\ \allowbreak 0.95$ for $(L,R)=(0,0), \allowbreak (0,1), \allowbreak (1,0), \allowbreak (1,1)$

  • $p(S=1\mid F=1)=0.95$, $p(S=1\mid F=0)=0.01$

Hint 1/4

The only path is $W\to L\to F\leftarrow R$; ask what each observed set does at $L$ and at $F$.

Hint 2/4

$L$ is head-to-tail (blocks if observed); $F$ is head-to-head (blocks unless $F$ or $S$ is observed).

Hint 3/4

$C=\{L\}$ blocks at $L$ and at $F$; $\varnothing$ blocks at $F$; $\{L,F\}$ blocks at $L$; $\{S\}$ leaves $L$ open and opens $F$ through its child.

Hint 4/4

Only $C=\{S\}$ leaves the path open.

Show solution

There is a single path, so each set needs only two checks: the gate at $L$ and the gate at $F$.

Gate at L

$$L\in C\Rightarrow\text{blocked}$$

Head-to-tail: observed blocks.

Gate at F

$$F,S\notin C\Rightarrow\text{blocked}$$

Head-to-head: open only if $F$ or its descendant $S$ is observed.

The candidates

$$\{S\}:\ L\ \text{passes},\ F\ \text{open}\ \Rightarrow\ \text{dependent}$$

The others each close one of the gates.

Answer $$\boxed{C=\{S\}}$$
Check

Numerically, $p(W=1\mid S=1)=0.629$ but $p(W=1\mid S=1,R=1)=0.520$, while given $L=1$ and $F=1$ the belief in clouds stays at $0.75$ whatever $R$ is.

A far-away observation can matter: $S$ reaches back through the collider.

4§12.6 — do potentials have to sum to one?

A student writes the potentials of an undirected model as tables and insists that each table must add up to $1$, like a probability table.

Find(a) Is the student right?
Given
  • $p(x)=\frac1Z\prod_{c\in M}\psi_c(x_c)$ with $\psi_c\ge0$

  • example: chain $x_1-x_2-x_3$ with $\psi=3$ for agreeing and $1$ for disagreeing neighbours

Hint 1/4

Ask what job $Z$ does in the factorization.

Hint 2/4

Only $\psi_c\ge0$ is required; $Z=\sum_x\prod_c\psi_c(x_c)$ makes the product a distribution.

Hint 3/4

In the chain, each table holds $3,1,1,3$, which adds to $8$; with $Z=32$ the probabilities still add to $1$.

Hint 4/4

No: potentials need only be non-negative.

Show solution

A valid model needs its probabilities to add to $1$; see whether $Z$ already ensures that.

Table sums

$$3+1+1+3=8\ne1$$

Neither table adds to $1$.

Normalized model

$$\sum_x\frac{\psi_{12}\psi_{23}}{Z}=\frac{32}{32}=1$$

Division by $Z=32$ repairs the total.

Answer $$\boxed{\text{False}}$$
Check

Multiplying every potential by $10$ multiplies $Z$ by $100$ and leaves every probability unchanged, so the scale of a table carries no meaning.

Directed factors are normalized locally; undirected potentials only globally, through $Z$.

B · computation 8 questions
1§12.1 — counting the numbers of a greenhouse model

A greenhouse model has a three-valued season, which affects rain and whether the pump runs; rain and the pump decide whether the soil is moist, and the soil decides whether the plants show stress.

Find
  1. (a) Write the factorization.

  2. (b) Count the free numbers, and compare with a full table.

Given
  • season $Q\in\{$dry, mild, wet$\}$, rain $R$, pump running $P$, moist soil $M$, plant stress $T$

  • arrows $Q\to R$, $Q\to P$, $R\to M$, $P\to M$, $M\to T$; all but $Q$ are binary

Hint 1/4

One factor per node; its size depends on how many configurations its parents have.

Hint 2/4

A node with $k$ values and $m$ parent configurations needs $(k-1)m$ numbers.

Hint 3/4

$Q$: $(3-1)\cdot1$; $R$ and $P$: $1\cdot3$ each; $M$: $1\cdot4$; $T$: $1\cdot2$. Full table: $3\cdot2^4$ cells.

Hint 4/4

$2+3+3+4+2=14$ numbers against $3\cdot2^4-1=47$.

Show solution

Count factor by factor with $(k-1)m$; counting cells of the joint and subtracting one is the check.

Factorization

$$p(Q)\,p(R\mid Q)\,p(P\mid Q)\,p(M\mid R,P)\,p(T\mid M)$$

The season has no parent; the others follow the arrows.

Count

$$2+3+3+4+2=14$$

$Q$ needs $2$; $R$ and $P$ one number per season; $M$ one per $(R,P)$ pair; $T$ one per value of $M$.

Full table

$$3\cdot2^4-1=47$$

All combinations, minus one for the sum to one.

Answer $$\boxed{14\ \text{numbers, against }47}$$
Check

If Season were binary, the rule would give $1+2+2+4+2=11$ against $2^5-1=31$: the three-valued root adds $1+1+1=3$, one per factor it enters.

A many-valued parent multiplies the size of every child's table.

2§12.1 — one ancestral sample from the greenhouse model

Draw one day from the greenhouse model by ancestral sampling, using the uniform numbers in the order $Q$, $R$, $P$, $M$, $T$.

Find
  1. (a) Find the sampled day.

  2. (b) Find its probability under the model.

Given
  • season $Q\in\{$dry, mild, wet$\}$, rain $R$, pump running $P$, moist soil $M$, plant stress $T$

  • arrows $Q\to R$, $Q\to P$, $R\to M$, $P\to M$, $M\to T$; all but $Q$ are binary

  • $p(Q)$: dry $0.3$, mild $0.5$, wet $0.2$ (in this order)

  • $p(R=1\mid Q)$: $0.05$, $0.3$, $0.7$; $p(P=1\mid Q)$: $0.9$, $0.5$, $0.1$ for dry, mild, wet

  • $p(M=1\mid R,P)=0.1,\ \allowbreak 0.8,\ \allowbreak 0.85,\ \allowbreak 0.95$ for $(R,P)=(0,0), \allowbreak (0,1), \allowbreak (1,0), \allowbreak (1,1)$

  • $p(T=1\mid M=1)=0.05$, $p(T=1\mid M=0)=0.6$

  • uniforms $0.72,\ \allowbreak 0.41,\ \allowbreak 0.18,\ \allowbreak 0.66,\ \allowbreak 0.33$; rule: value $1$ if $u<p$

Hint 1/4

Draw each variable after its parents, using the table row the parents pick.

Hint 2/4

Binary: $x=1$ if $u<p(x=1\mid\text{parents})$. Season: cut $[0,1)$ into $[0,0.3)$, $[0.3,0.8)$, $[0.8,1)$.

Hint 3/4

$0.72\to$ mild; $R$: $0.41$ vs $0.3$; $P$: $0.18$ vs $0.5$; $M$: $0.66$ vs $p(M=1\mid R=0,P=1)=0.8$; $T$: $0.33$ vs $0.05$.

Hint 4/4

(mild, no rain, pump on, moist soil, no stress), with probability $0.133$.

Show solution

The listed order already puts parents first, so each uniform meets a fully known row.

The season

$$0.72\in[0.3,0.8)\Rightarrow Q=\text{mild}$$

Consecutive intervals in the listed order.

Rain and pump

$$\begin{aligned}&0.41\ge0.3\Rightarrow R=0\\ &0.18<0.5\Rightarrow P=1\end{aligned}$$

The mild rows of both tables.

Soil and stress

$$\begin{aligned}&0.66<0.8\Rightarrow M=1\\ &0.33\ge0.05\Rightarrow T=0\end{aligned}$$

Rows picked by $(R,P)=(0,1)$ and by $M=1$.

Probability

$$0.5\times0.7\times0.5\times0.8\times0.95=0.133$$

One factor per node at the sampled values.

Answer $$\boxed{\begin{aligned}&(Q,R,P,M,T)\\ &=(\text{mild},0,1,1,0)\\ &p=0.133\end{aligned}}$$
Check

Plausibility: every draw took a common branch (mild $0.5$, no rain $0.7$, moist soil $0.8$, no stress $0.95$) except the pump's even split, so a fairly large probability for a five-variable day is expected.

A sample never needs the joint table, only the right row of each factor.

3§12.2 — a flat cake: explaining away in numbers

A cake does not rise ($N=1$). Two independent causes are possible: old yeast ($Y=1$) and a cold oven ($O=1$).

Find
  1. (a) Find $p(Y=1\mid N=1)$.

  2. (b) Find $p(Y=1\mid N=1,O=1)$ and $p(Y=1\mid N=1,O=0)$.

Given
  • $p(Y=1)=0.2$, $p(O=1)=0.1$, $Y\to N\leftarrow O$

  • $p(N=1\mid Y,O)=0.05,\ \allowbreak 0.7,\ \allowbreak 0.8,\ \allowbreak 0.95$ for $(Y,O)=(0,0), \allowbreak (0,1), \allowbreak (1,0), \allowbreak (1,1)$

Hint 1/4

Fix $N=1$, list the four $(Y,O)$ cells, and decide which cells each question keeps.

Hint 2/4

$p(Y=1\mid e)=\sum_{\text{cells with }Y=1}p(Y)p(O)p(N=1\mid Y,O)\big/\sum_{\text{all cells}}$.

Hint 3/4

Cells: $0.8(0.9)(0.05)=0.036$, $0.8(0.1)(0.7)=0.056$, $0.2(0.9)(0.8)=0.144$, $0.2(0.1)(0.95)=0.019$.

Hint 4/4

(a) $0.163/0.255=0.639$; (b) $0.019/0.075=0.253$ and $0.144/0.18=0.8$.

Show solution

All three questions use the same four cells; only the cells kept in the numerator and denominator change.

The four cells

$$\begin{aligned}&(0,0){:}\ 0.036,\quad (0,1){:}\ 0.056\\ &(1,0){:}\ 0.144,\quad (1,1){:}\ 0.019\end{aligned}$$

Prior of $Y$ times prior of $O$ times the chance of a flat cake.

(a)

$$\frac{0.144+0.019}{0.255}=0.639$$

$p(N=1)=0.255$ is the sum of all four.

(b)

$$\begin{aligned}&\frac{0.019}{0.056+0.019}=0.253\\ &\frac{0.144}{0.036+0.144}=0.8\end{aligned}$$

Keep the cells with the observed $O$.

Answer $$\boxed{0.639;\ \ 0.253\ \text{and}\ 0.8}$$
Check

Average check: $p(O=1\mid N=1)=0.075/0.255=0.294$, and $0.294(0.253)+0.706(0.8)=0.639$, the answer to (a).

The answer to (a) is always between the two answers to (b), weighted by the belief in the other cause.

4§12.3 — three verdicts on graph G

Graph $G$ has the arrows $x_1\to x_2$, $x_1\to x_3$, $x_6\to x_3$, $x_2\to x_4$, $x_3\to x_4$, $x_4\to x_5$.

Find
  1. (a) Is $x_1\perp\!\!\!\perp x_5\mid x_4$?

  2. (b) Is $x_2\perp\!\!\!\perp x_6$?

  3. (c) Is $x_2\perp\!\!\!\perp x_6\mid x_5$?

Givenarrows $x_1\to x_2$, $x_1\to x_3$, $x_6\to x_3$, $x_2\to x_4$, $x_3\to x_4$, $x_4\to x_5$
Hint 1/4

For each question list the paths, then look for one blocking node per path.

Hint 2/4

Blocked: head-to-tail or tail-to-tail and observed, or head-to-head with neither it nor a descendant observed.

Hint 3/4

(a) paths through $x_2,x_4$ and $x_3,x_4$; (b) and (c) paths $x_2,x_1,x_3,x_6$ and $x_2,x_4,x_3,x_6$; $x_5$ is a descendant of $x_4$ and of $x_3$.

Hint 4/4

(a) yes; (b) yes; (c) no.

Show solution

The paths are listed once per pair; the observed set then decides each node.

(a) x1 and x5 given x4

$$\begin{aligned}&x_1\to x_2\to x_4\to x_5\\ &x_1\to x_3\to x_4\to x_5\\ &\text{both blocked at }x_4\end{aligned}$$

Head-to-tail at the observed $x_4$.

(b) x2 and x6, nothing observed

$$x_2\leftarrow x_1\to x_3\leftarrow x_6:\ \text{collider }x_3$$

Unobserved, and its descendants $x_4$, $x_5$ are unobserved.

$$x_2\to x_4\leftarrow x_3\leftarrow x_6:\ \text{collider }x_4$$

Unobserved, as is $x_5$.

(c) x2 and x6 given x5

$$x_5\in\mathrm{de}(x_3)\cap\mathrm{de}(x_4)\ \Rightarrow\ \text{both paths open}$$

The colliders are $x_3$ on the first path and $x_4$ on the second; the other nodes, $x_1$ and $x_3$ respectively, are unobserved and not head-to-head, so they pass.

Answer $$\boxed{\text{(a) yes},\ \ \text{(b) yes},\ \ \text{(c) no}}$$
Check

An exact check with random tables for $G$ confirms all three: the first two joint tables factor, the third does not.

One observed descendant can open several colliders at once.

5§12.5 — the packet given its blanket

In the sensor model the technician knows it was a sunny day ($W=0$), the battery was fine ($L=0$), there was interference ($R=1$), and no SMS arrived ($S=0$).

Find
  1. (a) Find $p(F=1\mid W=0,L=0,R=1,S=0)$.

  2. (b) Would the answer change on a cloudy day?

Given
  • $W\to L\to F\leftarrow R$, $F\to S$

  • $p(W=1)=0.5$, $p(R=1)=0.1$; $p(L=1\mid W)=0.15$ if $W=1$, $0.05$ if $W=0$

  • $p(F=1\mid L,R)=0.02,\ \allowbreak 0.5,\ \allowbreak 0.9,\ \allowbreak 0.95$ for $(L,R)=(0,0), \allowbreak (0,1), \allowbreak (1,0), \allowbreak (1,1)$

  • $p(S=1\mid F=1)=0.95$, $p(S=1\mid F=0)=0.01$

Hint 1/4

Decide which variables $F$'s own factor and its child's factor mention.

Hint 2/4

$p(F\mid\text{rest})\propto p(F\mid L,R)\,p(S\mid F)$; the blanket of $F$ is $\{L,R,S\}$.

Hint 3/4

$F=1$: $p(F=1\mid0,1)p(S=0\mid F=1)=0.5\times0.05$; $F=0$: $0.5\times0.99$.

Hint 4/4

(a) $0.025/0.52=0.048$; (b) no, $W$ is outside the blanket.

Show solution

Only the factors containing $F$ survive, so we never touch $p(W)$ or $p(L\mid W)$.

Unnormalized

$$\begin{aligned}&F=1:\ 0.5\times0.05=0.025\\ &F=0:\ 0.5\times0.99=0.495\end{aligned}$$

$p(F\mid L=0,R=1)$ times $p(S=0\mid F)$.

Normalize

$$\frac{0.025}{0.025+0.495}=0.048$$

Divide by the sum over the two values of $F$.

Answer $$\boxed{\begin{aligned}&p(F=1\mid\cdot)=0.048\\ &\text{unchanged by }W\end{aligned}}$$
Check

Contrast: had the SMS arrived, $p(F=1\mid L=0,R=1,S=1)=0.475/0.48=0.990$.

A missing alert is strong evidence that the packet arrived, even on an interference night.

6§12.4 — the Lagrange multiplier behind the class shares

Twenty drone flights are labelled with one of three modes: $10$ survey, $6$ delivery, $4$ test. A GPS dropout occurred in $1$, $3$ and $3$ flights of these modes.

Find
  1. (a) Maximize $\sum_cn_c\log\pi_c$ subject to $\sum_c\pi_c=1$ with a Lagrange multiplier.

  2. (b) Give $\hat\pi$ and $\hat\theta_{1c}$ for the dropout feature.

Given
  • $n=20$; $n_1=10$, $n_2=6$, $n_3=4$

  • flights with a dropout: $n_{11}=1$, $n_{12}=3$, $n_{13}=3$

Hint 1/4

Only the class-share part of the log-likelihood depends on $\pi$; handle the constraint with a multiplier.

Hint 2/4

Set $\partial/\partial\pi_c$ of $\sum_cn_c\log\pi_c-\lambda(\sum_c\pi_c-1)$ to zero: $n_c/\pi_c=\lambda$.

Hint 3/4

$\pi_c=n_c/\lambda$ and $\sum_c\pi_c=1$ give $\lambda=n=20$; the counts are $10,6,4$ and $1,3,3$.

Hint 4/4

$\hat\pi=(0.5,\ 0.3,\ 0.2)$ and $\hat\theta_{1c}=(0.1,\ 0.5,\ 0.75)$.

Show solution

The constraint couples the shares, so they need a multiplier; each rate has no constraint and just a derivative.

Lagrangian

$$\mathcal L=\sum_cn_c\log\pi_c-\lambda\Big(\sum_c\pi_c-1\Big)$$

The multiplier term is zero whenever the constraint holds.

Stationary point

$$\frac{n_c}{\pi_c}-\lambda=0\ \Rightarrow\ \pi_c=\frac{n_c}{\lambda}$$

Differentiate in $\pi_c$.

$$\sum_c\frac{n_c}{\lambda}=1\ \Rightarrow\ \lambda=n=20$$

Put the solution into the constraint.

Estimates

$$\begin{aligned}&\hat\pi=\Big(\tfrac{10}{20},\tfrac6{20},\tfrac4{20}\Big)\\ &\hat\theta_{1c}=\Big(\tfrac1{10},\tfrac36,\tfrac34\Big)\end{aligned}$$

Rates divide by the class sizes $10$, $6$, $4$.

Answer $$\boxed{\begin{aligned}&\hat\pi=(0.5,\,0.3,\,0.2)\\ &\hat\theta_{1c}=(0.1,\,0.5,\,0.75)\end{aligned}}$$
Check

Moving the shares to $(1/3,1/3,1/3)$ lowers the share part of $l$ from $-20.59$ to $-21.97$, as a maximum requires.

Whenever parameters must add up to one, the maximum likelihood answer is 'count over total'.

7§12.4 — Gaussian naive Bayes with unequal spreads

A one-feature Gaussian naive Bayes classifier has two equally likely classes: class 1 with $\mathcal N(10,4)$ and class 2 with $\mathcal N(16,1)$.

Find
  1. (a) Find $p(y=1\mid x=13)$.

  2. (b) Find $p(y=1\mid x=14)$.

Given
  • $\pi_1=\pi_2=0.5$

  • $x\mid y=1\sim\mathcal N(10,4)$, $x\mid y=2\sim\mathcal N(16,1)$ (variances)

Hint 1/4

Compare the two log-densities; equal shares cancel.

Hint 2/4

$\log\mathcal N(x\mid\mu,\sigma^2)=-\frac{(x-\mu)^2}{2\sigma^2}-\frac12\log(2\pi\sigma^2)$; the posterior is $1/(1+e^{-d})$ with $d$ the log-ratio.

Hint 3/4

$x=13$: $-9/8-\frac12\log8\pi$ against $-9/2-\frac12\log2\pi$; $x=14$: $-2-\frac12\log8\pi$ against $-2-\frac12\log2\pi$.

Hint 4/4

(a) $d=2.682$, $p=0.936$; (b) $d=-\log2$, $p=1/3$.

Show solution

Work with log-densities: the constants differ only by $\frac12\log4=\log2$, which is easy to keep.

x = 13

$$d=\Big(-\frac98+\frac92\Big)-\frac12\log\frac{8\pi}{2\pi}=3.375-0.693=2.682$$

$13$ is $1.5$ standard deviations from class 1 and $3$ from class 2.

$$p(y=1\mid13)=\frac1{1+e^{-2.682}}=0.936$$

Logistic form of a two-class posterior.

x = 14

$$\begin{aligned}&d=(-2+2)-\log2=-0.693\\ &p(y=1\mid14)=\frac1{1+2}=\frac13\end{aligned}$$

Equal exponents; only the wider density's lower peak is left.

Answer $$\boxed{\begin{aligned}&p(y=1\mid13)=0.936\\ &p(y=1\mid14)=\tfrac13\end{aligned}}$$
Check

At $x=14$ the densities are $\mathcal N(14\mid10,4)=0.0270$ and $\mathcal N(14\mid16,1)=0.0540$, a ratio of exactly $1:2$.

Equal distance from two means does not mean a tie: the narrower class falls off faster.

8§12.6 — Z for a square of four binary nodes

Four binary nodes sit on a square $x_1-x_2-x_3-x_4-x_1$. Each of the four edge potentials gives $2$ to agreeing neighbours and $1$ to disagreeing ones.

Find
  1. (a) Find $Z$ and $p(1,1,1,1)$.

  2. (b) Check $x_1\perp\!\!\!\perp x_3\mid\{x_2,x_4\}$ at $x_2=x_4=1$ with numbers.

Given
  • $\psi(a,b)=2$ if $a=b$, $1$ if $a\ne b$, on each of the four edges

  • $x_j\in\{0,1\}$

Hint 1/4

Group the $16$ configurations by how many of the four edges disagree.

Hint 2/4

$Z=\sum_x\prod_{\text{edges}}\psi$; a configuration with $k$ disagreeing edges scores $2^{4-k}$.

Hint 3/4

Around a square the value changes an even number of times: $2$ configurations have $k=0$, $12$ have $k=2$, and $2$ have $k=4$.

Hint 4/4

$Z=2(16)+12(4)+2(1)=82$; $p(1,1,1,1)=16/82$; given $x_2=x_4=1$, $p(x_1=1,x_3=1)=16/25=(4/5)^2$.

Show solution

Going around a square, the colour changes an even number of times, so only $k=0,2,4$ disagreements occur.

Z

$$Z=2\cdot2^4+12\cdot2^2+2\cdot2^0=32+48+2=82$$

$2$ constant colourings, $2$ alternating ones, and the other $12$ have two disagreeing edges.

One configuration

$$p(1,1,1,1)=\frac{16}{82}=0.195$$

All four edges agree: $2^4=16$.

Separation given x2 = x4 = 1

$$p(x_1=1,x_3=1\mid\cdot)=\frac{16}{(4+1)(4+1)}=\frac{16}{25}$$

Given $x_2,x_4$, $x_1$ touches only its two edges, as does $x_3$: the sum factorizes.

$$\begin{aligned}&p(x_1=1\mid\cdot)=\frac{2\cdot2}{2\cdot2+1\cdot1}=\frac45\\ &\Big(\frac45\Big)^2=\frac{16}{25}\end{aligned}$$

The product of the two conditionals equals the joint conditional.

Answer $$\boxed{\begin{aligned}Z&=82\\ p(1,1,1,1)&=\tfrac{8}{41}\\ \tfrac{16}{25}&=\big(\tfrac45\big)^2\end{aligned}}$$
Check

Condition on $(x_2,x_4)$: equal values give $(4+1)(4+1)=25$, unequal give $(2+2)(2+2)=16$, so $Z=2(25)+2(16)=82$.

Separation in the graph shows up in the numbers as a sum that splits into a product.

C · exam level 5 questions
1§12.7 — the first sweep on a 3 by 3 image

A noisy $3\times3$ image is cleaned with $\beta=1$, $\eta=1.5$, $h=0$, starting from $x=y$ and sweeping row by row, left to right, with each new value used at once.

Find(a) Which pixels change during the first sweep?
Given
  • noisy image, $\blacksquare=-1$, $\square=+1$: $$y=\begin{array}{ccc}\square&\square&\square\\ \square&\blacksquare&\square\\ \blacksquare&\blacksquare&\square\end{array}$$

  • $\beta=1$, $\eta=1.5$, $h=0$

Hint 1/4

A pixel changes only if its neighbours outvote its reading; check the three black pixels.

Hint 2/4

$x_j=+1$ if $\beta\sum_{k\sim j}x_k+\eta y_j>0$.

Hint 3/4

Centre: neighbours sum $+2$, vote $2-1.5$. Bottom left: sum $0$. Bottom middle, after the centre turned white: sum $+1$, vote $1-1.5$.

Hint 4/4

Only the centre changes; the two bottom pixels support each other and stay black.

Show solution

White pixels have mostly white neighbours and a white reading, so only the black ones can move.

Centre (2, 2)

$$\sum x_k=+1+1+1-1=2,\quad 2-1.5=0.5>0\ \Rightarrow\ +1$$

Three white neighbours outvote the reading.

Bottom left (3, 1)

$$\sum x_k=+1-1=0,\quad 0-1.5<0\ \Rightarrow\ -1$$

A corner pixel with split neighbours keeps its reading.

Bottom middle (3, 2)

$$\sum x_k=+1-1+1=1,\quad 1-1.5<0\ \Rightarrow\ -1$$

The centre is already white here, and it still is not enough.

Second sweep

$$\text{no change}$$

No pixel's vote changes sign, so the run stops.

Answer $$\boxed{\begin{aligned}&\text{only the centre pixel}\\ &\text{turns white}\end{aligned}}$$
Check

Energy check: the only change lowers $E$ from $-15.5$ to $-16.5$, and the pixel rule predicts $\Delta E=-2\times0.5=-1$ for a vote of $0.5$.

Two adjacent black pixels shield each other; a lone one does not survive.

2§12.6 — the factorization of a square with a diagonal

An undirected graph on four nodes has the edges $x_1x_2$, $x_2x_3$, $x_3x_4$, $x_4x_1$ and the diagonal $x_1x_3$, but not $x_2x_4$.

Find(a) Which expression is the joint distribution in the lecture's form, one potential per maximal clique?
Given
  • edges $x_1x_2$, $x_2x_3$, $x_3x_4$, $x_4x_1$, $x_1x_3$

  • no edge between $x_2$ and $x_4$

Hint 1/4

Find the maximal cliques first; the expression follows from them.

Hint 2/4

$p(x)=\frac1Z\prod_{c\in M}\psi_c(x_c)$ over the maximal cliques $M$.

Hint 3/4

$\{x_1,x_2,x_3\}$ and $\{x_1,x_3,x_4\}$ are triangles; $\{x_1,x_2,x_3,x_4\}$ is not a clique because $x_2x_4$ is missing.

Hint 4/4

$p(x)=\frac1Z\psi_{123}(x_1, \allowbreak x_2, \allowbreak x_3)\,\psi_{134}(x_1, \allowbreak x_3, \allowbreak x_4)$.

Show solution

The diagonal creates triangles, and triangles are the largest cliques available without $x_2x_4$.

Maximal cliques

$$M=\{\{x_1,x_2,x_3\},\ \{x_1,x_3,x_4\}\}$$

Each triangle uses the diagonal; no four nodes are fully connected.

Factorization

$$\begin{aligned}p(x)&=\frac1Z\,\psi_{123}(x_1,x_2,x_3)\\ &\quad\times\psi_{134}(x_1,x_3,x_4)\end{aligned}$$

One potential per maximal clique, then $Z$.

Answer $$\boxed{p(x)=\tfrac1Z\,\psi_{123}\,\psi_{134}}$$
Check

Consequence check: $x_2$ and $x_4$ share no potential, and every path between them passes $x_1$ or $x_3$, so $x_2\perp\!\!\!\perp x_4\mid\{x_1,x_3\}$, as separation says.

The missing edge is what the factorization encodes: no potential ever holds both $x_2$ and $x_4$.

3§12.4 — a posterior where the prior matters

A bank's naive Bayes filter sorts card payments into routine ($y=1$) and suspicious ($y=2$) using two binary features: $x_1$ = paid abroad, $x_2$ = new device. The trained estimates are below.

Find(a) What is $p(y=2\mid x)$?
Given
  • $\hat\pi=(0.7,\ 0.3)$

  • $\hat\theta_{\cdot1}=(0.1,\ 0.2)$, $\hat\theta_{\cdot2}=(0.6,\ 0.7)$

  • new payment: $x=(1,1)$

Hint 1/4

Score each class with its share and the two feature rates, then normalize.

Hint 2/4

$p(y=c\mid x)\propto\hat\pi_c\,\hat\theta_{1c}\,\hat\theta_{2c}$ for $x=(1,1)$.

Hint 3/4

Routine: $0.7\times0.1\times0.2=0.014$. Suspicious: $0.3\times0.6\times0.7=0.126$.

Hint 4/4

$0.126/(0.014+0.126)=0.9$.

Show solution

Both features are $1$, so each score is the share times the two rates.

Scores

$$\begin{aligned}&0.7(0.1)(0.2)=0.014\\ &0.3(0.6)(0.7)=0.126\end{aligned}$$

The share enters once per class.

Normalize

$$\frac{0.126}{0.140}=0.9$$

Divide by the sum of the scores.

Answer $$\boxed{p(y=2\mid x)=0.9}$$
Check

Odds check: prior odds $0.3/0.7=0.429$, times likelihood ratio $0.42/0.02=21$, gives $9$, and $9/(1+9)=0.9$.

Posterior odds are prior odds times the likelihood ratio; naive Bayes multiplies one ratio per feature.

4§12.2 — explaining away through a descendant

In the sensor model the technician receives the SMS ($S=1$) but does not see $F$ directly. Later a storm report confirms interference ($R=1$).

Find(a) What are $p(L=1\mid S=1)$ and then $p(L=1\mid S=1,R=1)$?
Given
  • $W\to L\to F\leftarrow R$, $F\to S$

  • $p(W=1)=0.5$, $p(R=1)=0.1$; $p(L=1\mid W)=0.15$ if $W=1$, $0.05$ if $W=0$

  • $p(F=1\mid L,R)=0.02,\ \allowbreak 0.5,\ \allowbreak 0.9,\ \allowbreak 0.95$ for $(L,R)=(0,0), \allowbreak (0,1), \allowbreak (1,0), \allowbreak (1,1)$

  • $p(S=1\mid F=1)=0.95$, $p(S=1\mid F=0)=0.01$

Hint 1/4

The SMS is a noisy view of $F$, so both computations sum over $F$.

Hint 2/4

$p(L=1\mid e)=\sum_Fp(L=1, \allowbreak F, \allowbreak e)\big/\sum_{L,F}p(L, \allowbreak F, \allowbreak e)$, with every factor of the sensor model.

Hint 3/4

$p(L=1,S=1)=0.1\,(0.905\cdot0.95+0.095\cdot0.01)=0.0861$ and $p(S=1)=0.1526$; with $R=1$: $0.01(0.95\cdot0.95+0.05\cdot0.01)=0.00903$ against $0.09(0.5\cdot0.95+0.5\cdot0.01)=0.0432$.

Hint 4/4

$0.564$, then $0.173$.

Show solution

$S$ is a descendant of the collider $F$, so it behaves like a weaker observation of $F$; enumeration over $F$ handles it.

Given the SMS

$$\begin{aligned}&p(L=1,S=1)\\ &=0.1(0.85975+0.00095)\\ &=0.0861\end{aligned}$$

Sum over the unseen $F$: $0.905\cdot0.95=0.85975$ (packet lost, SMS sent) plus $0.095\cdot0.01=0.00095$ (packet arrived, false SMS).

$$p(L=1\mid S=1)=\frac{0.0861}{0.1526}=0.564$$

$p(S=1)=0.1517\cdot0.95+0.8483\cdot0.01=0.1526$.

Given the SMS and the storm

$$\begin{aligned}&p(L=1,R=1,S=1)\\ &=0.1(0.1)(0.95\cdot0.95\\ &\qquad+0.05\cdot0.01)\\ &=0.00903\end{aligned}$$

Both parents fixed; sum over $F$ with $p(F=1\mid1,1)=0.95$.

$$\begin{aligned}&p(L=0,R=1,S=1)\\ &=0.9(0.1)(0.5\cdot0.95\\ &\qquad+0.5\cdot0.01)\\ &=0.0432\end{aligned}$$

The same with $L=0$, where $p(F=1\mid0,1)=0.5$.

$$p(L=1\mid S=1,R=1)=\frac{0.00903}{0.00903+0.0432}=0.173$$

Normalize over $L$.

Answer $$\boxed{0.564\ \to\ 0.173}$$
Check

Both are a little below their $F$-observed versions, $0.597$ and $0.174$, because an SMS is slightly weaker evidence than a lost packet.

Observing a descendant of a collider opens it too, just less strongly.

5§12.3 — another true statement about graph G

Graph $G$ has the arrows $x_1\to x_2$, $x_1\to x_3$, $x_6\to x_3$, $x_2\to x_4$, $x_3\to x_4$ and $x_4\to x_5$. Exactly one statement below follows from d-separation.

Find(a) Which statement is true?
Givenarrows $x_1\to x_2$, $x_1\to x_3$, $x_6\to x_3$, $x_2\to x_4$, $x_3\to x_4$, $x_4\to x_5$
Hint 1/4

For each statement, try to find one open path.

Hint 2/4

Blocked: head-to-tail or tail-to-tail and observed, or head-to-head with neither it nor a descendant observed.

Hint 3/4

The collider $x_3$ lies on every path that leaves $x_6$; the collider $x_4$ has the descendant $x_5$; $x_1$ is tail-to-tail between $x_2$ and $x_3$.

Hint 4/4

Only $x_1\perp\!\!\!\perp x_6\mid x_2$ has all paths blocked.

Show solution

Look for an open path in each; the first one found settles a false statement.

x1 and x6 given x2

$$\begin{aligned}&x_1\to x_3\leftarrow x_6:\ \text{blocked}\\ &x_1\to x_2\to x_4\leftarrow x_3\leftarrow x_6\\ &\quad\text{blocked at }x_2\end{aligned}$$

Unobserved collider $x_3$ with unobserved descendants; observed head-to-tail $x_2$.

x5 and x6 given x3

$$x_6\to x_3\leftarrow x_1\to x_2\to x_4\to x_5\ \text{open}$$

Observing the collider $x_3$ opens it; the other nodes pass.

x2 and x6 given x3

$$x_2\leftarrow x_1\to x_3\leftarrow x_6\ \text{open}$$

The same observed collider $x_3$.

x2 and x3 given x1 and x4

$$x_2\to x_4\leftarrow x_3\ \text{open}$$

$x_4$ is an observed collider.

Answer $$\boxed{x_1\perp\!\!\!\perp x_6\mid x_2}$$
Check

The exact check on a model with random tables agrees with all four verdicts.

Observing a collider or its descendant is the usual way a 'false' statement fails.

D · interleaved 4 questions
1§12.1 — a hidden label behind one reading

A two-component Gaussian mixture has a hidden label $z$ and a reading $x$: first $z$ is drawn, then $x$ from the component $z$ picks. The components are $\mathcal N(0,1)$ and $\mathcal N(4,1)$ with shares $0.3$ and $0.7$.

Find
  1. (a) Draw the graph, write $p(z,x)$, and draw one sample $(z,x)$.

  2. (b) Find $p(z=1\mid x=1)$.

  3. (c) Find $p(z=1\mid x=2)$ and explain the value.

Given
  • $p(z=1)=0.3$, $p(z=2)=0.7$

  • $x\mid z=1\sim\mathcal N(0,1)$, $x\mid z=2\sim\mathcal N(4,1)$

  • uniform $u=0.62$ for $z$ ($z=1$ if $u<0.3$); standard normal draw $e=-0.5$, and $x=\mu_z+\sigma_ze$

Hint 1/4

The mixture is a directed graph with one arrow; sampling and the posterior both follow from it.

Hint 2/4

$p(z,x)=p(z)\,p(x\mid z)$; ancestral sampling draws $z$ first; $p(z=1\mid x)=\frac{0.3\,\mathcal N(x\mid0,1)}{0.3\,\mathcal N(x\mid0,1)+0.7\,\mathcal N(x\mid4,1)}$.

Hint 3/4

$u=0.62\ge0.3$ gives $z=2$, so $x=4-0.5$. At $x=1$ the log-odds is $\log\frac{0.3}{0.7}+\frac{9-1}{2}$; at $x=2$ the two squared distances are equal.

Hint 4/4

(a) $(2,\ 3.5)$; (b) $0.959$; (c) $0.3$, the prior share.

Show solution

Treat the mixture as a two-node : ancestral sampling for (a), Bayes' rule for (b) and (c).

Graph and sample

$$\begin{aligned}&p(z,x)=p(z)\,p(x\mid z)\\ &u=0.62\ge0.3\Rightarrow z=2\\ &x=4+1\cdot(-0.5)=3.5\end{aligned}$$

Parent first, then the child from the row the parent picks.

Posterior at x = 1

$$\begin{aligned}&\log\frac{p(z=1\mid x)}{p(z=2\mid x)}\\ &=\log\frac{0.3}{0.7}+\frac{9-1}{2}\\ &=-0.847+4=3.153\end{aligned}$$

Equal variances cancel the constants; the squared distances are $(1-4)^2=9$ and $(1-0)^2=1$.

$$p(z=1\mid x=1)=\frac{1}{1+e^{-3.153}}=0.959$$

The logistic form of a two-class posterior.

Posterior at x = 2

$$\frac{(2-4)^2-{(2-0)}^2}{2}=0\ \Rightarrow\ p(z=1\mid x=2)=0.3$$

Equal densities; only the shares remain.

Answer $$\boxed{\begin{aligned}&\text{(a) }(z,x)=(2,\,3.5)\\ &\text{(b) }0.959\\ &\text{(c) }0.3\end{aligned}}$$
Check

Direct values at $x=1$: $0.3\,\mathcal N(1\mid0,1)=0.0726$ and $0.7\,\mathcal N(1\mid4,1)=0.0031$, and $0.0726/0.0757=0.959$.

A mixture is a graphical model with a hidden parent; its responsibility is inference in that graph.

2§12.4 — one feature, two classes with equal spread

One feature, two classes: $x\mid y=1\sim\mathcal N(0,1)$ and $x\mid y=2\sim\mathcal N(2,1)$, with the same variance in both classes.

Find
  1. (a) With $\pi_1=\pi_2=0.5$, write $p(y=2\mid x)$ in the logistic form: find $\beta_0$, $\beta_1$ and the decision boundary.

  2. (b) Repeat with $\pi_2=0.75$.

Given
  • $x\mid y=1\sim\mathcal N(0,1)$, $x\mid y=2\sim\mathcal N(2,1)$

  • logistic form: $p(y=2\mid x)=1/(1+e^{-(\beta_0+\beta_1x)})$

Hint 1/4

Write the log-odds $\log\frac{p(y=2\mid x)}{p(y=1\mid x)}$ and see what kind of function of $x$ it is.

Hint 2/4

Log-odds $=\log\frac{\pi_2}{\pi_1}+\log\frac{\mathcal N(x\mid2,1)}{\mathcal N(x\mid0,1)}$; equal variances cancel the constants.

Hint 3/4

$\log\frac{\mathcal N(x\mid2,1)}{\mathcal N(x\mid0,1)}=\frac{x^2-(x-2)^2}{2}=2x-2$.

Hint 4/4

(a) $\beta_0=-2$, $\beta_1=2$, boundary $x=1$; (b) $\beta_0=-2+\log3=-0.901$, boundary $x=0.451$.

Show solution

Compute the log-odds directly; the shared variance makes the $x^2$ terms cancel, which is the point.

Log-odds

$$\log\frac{p(y=2\mid x)}{p(y=1\mid x)}=\log\frac{\pi_2}{\pi_1}-\frac{(x-2)^2}{2}+\frac{x^2}{2}=\log\frac{\pi_2}{\pi_1}+2x-2$$

Same variance, so the constants and the $x^2$ terms cancel.

(a) Equal shares

$$\beta_0=-2,\ \ \beta_1=2,\ \ \beta_0+\beta_1x=0\iff x=1$$

The boundary is the midpoint of the means.

(b) Shares 0.25 and 0.75

$$\beta_0=-2+\log3=-0.901,\ \ x=\frac{0.901}{2}=0.451$$

A larger prior share moves the boundary toward the other class.

Answer $$\boxed{\begin{aligned}&\text{(a) }\beta=(-2,\,2),\ x=1\\ &\text{(b) }\beta=(-0.901,\,2)\\ &\qquad x=0.451\end{aligned}}$$
Check

At $x=1$ in (a), both densities equal $e^{-1/2}/\sqrt{2\pi}$, so the posterior is $0.5$, as a boundary requires.

With one shared variance, Gaussian naive Bayes and logistic regression have the same form; they differ in how the coefficients are fitted.

3§12.4 — an inside sender the spam class never showed

In a new sample, all $4$ spam e-mails came from outside the university, so $\hat\theta_{31}=1$. A new e-mail with 'prize' and a link comes from inside: $x=(1,1,0)$.

Find
  1. (a) Find $p(\text{spam}\mid x)$ with maximum likelihood estimates.

  2. (b) Replace every $\hat\theta_{jc}$ by its posterior mean under $\mathrm{Beta}(1,1)$ and recompute.

Given
  • spam ($y=1$): $(1,1,1)$, $(1,0,1)$, $(0,1,1)$, $(1,1,1)$

  • not spam ($y=2$): $(0,1,0)$, $(0,0,0)$, $(0,1,1)$, $(0,0,0)$, $(1,0,0)$, $(0,1,0)$

  • Beta prior $\mathrm{Beta}(a,b)$: posterior mean of a rate $=(a+N_1)/(a+b+N)$

Hint 1/4

Look for a factor that is exactly $0$ before multiplying anything.

Hint 2/4

Maximum likelihood: $\hat\theta_{jc}=n_{jc}/n_c$. Beta$(1,1)$ posterior mean: $(n_{jc}+1)/(n_c+2)$.

Hint 3/4

Spam counts $(3,3,4)$ of $4$; not-spam counts $(1,3,1)$ of $6$; shares $0.4$ and $0.6$.

Hint 4/4

(a) $0$, because $1-\hat\theta_{31}=0$; (b) $0.345$.

Show solution

A product with a zero factor is zero whatever the other factors say, so check for zeros first.

(a) Maximum likelihood

$$0.4\cdot\tfrac34\cdot\tfrac34\cdot(1-1)=0\ \Rightarrow\ p(\text{spam}\mid x)=0$$

'Inside sender' never appeared among $4$ spam e-mails, so the model calls it impossible.

(b) Posterior means

$$\begin{aligned}&\tilde\theta_{\cdot1}=\Big(\tfrac46,\tfrac46,\tfrac56\Big)\\ &\tilde\theta_{\cdot2}=\Big(\tfrac28,\tfrac48,\tfrac28\Big)\end{aligned}$$

One imaginary success and one failure per count: the $\mathrm{Beta}(1,1)$ prior.

$$\begin{aligned}&0.4\cdot\tfrac23\cdot\tfrac23\cdot\tfrac16=0.0296\\ &0.6\cdot\tfrac14\cdot\tfrac12\cdot\tfrac34=0.0563\end{aligned}$$

The spam score is small but no longer zero.

$$p(\text{spam}\mid x)=\frac{0.0296}{0.0296+0.0563}=0.345$$

Normalize.

Answer $$\boxed{\begin{aligned}&\text{(a) }0\\ &\text{(b) }0.345\end{aligned}}$$
Check

Log-odds route: $\log\frac{0.4}{0.6}+\log\frac{2/3}{1/4}+\log\frac{2/3}{1/2}+\log\frac{1/6}{3/4}=-0.405+0.981+0.288-1.504=-0.641$, and $1/(1+e^{0.641})=0.345$.

Pseudo-counts are the Beta prior at work: they keep a small sample from ruling anything out.

4§12.4 — are naive Bayes features redundant?

Feature selection by maximum relevance and minimum redundancy penalizes the mutual information between selected features. Take the trained e-mail model and the features $x_1$ ('prize') and $x_3$ (outside sender).

Find
  1. (a) Find the joint table of $(x_1,x_3)$ under the model.

  2. (b) Find $I(x_1;x_3)$.

  3. (c) Since naive Bayes assumes conditional independence, is the redundancy term zero?

Given
  • $\hat\pi=(0.4,\ 0.6)$; $\hat\theta_{1c}=\hat\theta_{3c}=(3/4,\ 1/6)$

  • $I(X;X')=\sum_{x,x'}p(x,x')\log_2\frac{p(x,x')}{p(x)p(x')}$, in bits as in the feature selection section

Hint 1/4

The joint of two features comes from summing the label out of the naive Bayes factorization.

Hint 2/4

$p(x_1,x_3)=\sum_c\hat\pi_c\,p(x_1\mid c)\,p(x_3\mid c)$, then the mutual information formula.

Hint 3/4

$p(1,1)=0.4(0.75)^2+0.6(1/6)^2$; the marginals are $p(x_1=1)=p(x_3=1)=0.4$.

Hint 4/4

(a) $29/120$, $19/120$, $19/120$, $53/120$; (b) $0.084$ bits; (c) no.

Show solution

Build the table from the factorization; the four cells then feed the definition of $I$ directly.

Joint table

$$p(1,1)=0.4\big(\tfrac34\big)^2+0.6\big(\tfrac16\big)^2=\tfrac{29}{120}=0.242$$

Given $y$ the features multiply; the label is summed out.

$$\begin{aligned}p(1,0)&=p(0,1)\\ &=0.4-0.242=0.158\\ p(0,0)&=1-0.242-2(0.158)\\ &=0.442\end{aligned}$$

Rows and columns must add to the marginals $0.4$ and $0.6$.

Mutual information

$$\begin{aligned}I&=0.242\log_2\tfrac{0.242}{0.16}\\ &\quad+2(0.158)\log_2\tfrac{0.158}{0.24}\\ &\quad+0.442\log_2\tfrac{0.442}{0.36}\\ &=0.1438-0.1900+0.1303\\ &=0.084\end{aligned}$$

Each cell against the product of its marginals.

Redundancy

$$I(x_1;x_3)=0.084>0$$

Conditional independence given $y$ is not independence: the star is tail-to-tail at $y$.

Answer $$\boxed{I(x_1;x_3)\approx0.084\ \text{bits}>0}$$
Check

Entropy route: $I=H(x_1)-H(x_1\mid x_3)$; $p(x_1=1\mid x_3=1)=0.604$, $p(x_1=1\mid x_3=0)=0.264$, $H(x_1)=0.971$, $H(x_1\mid x_3)=0.4(0.968)+0.6(0.833)=0.887$, so $I=0.084$ bits.

Features that share a cause carry overlapping information even when a model treats them as independent given the label.

Mistake ledger (21 entries)
⚠ Conditioning on ancestors instead of parents

Everything upstream seems to matter.

wrong$$p(x_5\mid x_1,x_2,x_3,x_4)$$
right$$p(x_5\mid x_4)$$
⚠ Dropping a parent

One of two incoming arrows is easy to miss.

wrong$$p(x_3\mid x_1)$$
right$$p(x_3\mid x_1,x_6)$$
⚠ Counting both rows of a binary table

The table has two columns, $x=0$ and $x=1$.

wrong$$p(F\mid L,R):\ 4\times2=8\ \text{numbers}$$
right$$\begin{aligned}&p(F\mid L,R):\ 4\ \text{numbers, since}\\ &p(F=0\mid\cdot)=1-p(F=1\mid\cdot)\end{aligned}$$
⚠ Treating an observed head-to-head node as a blocker

In two of the three graphs, observing the middle node does block.

wrong$$a\to c\leftarrow b:\ \ a\perp\!\!\!\perp b\mid c$$
right$$a\to c\leftarrow b:\ \ a\perp\!\!\!\perp b,\ \text{but dependent given }c$$
⚠ Reading a missing arrow as independence

The arrows are the only thing drawn between the two nodes.

wrong$$\text{no arrow }W\text{ to }F\ \Rightarrow\ W\perp\!\!\!\perp F$$
right$$W\perp\!\!\!\perp F\mid L\ \text{only; the path }W\to L\to F\text{ is open}$$
⚠ Turning conditional independence into plain independence

The two statements differ by one symbol after the bar.

wrong$$a\perp\!\!\!\perp b\mid c\ \Rightarrow\ a\perp\!\!\!\perp b$$
right$$a\perp\!\!\!\perp b\mid c\ \text{does not imply }a\perp\!\!\!\perp b\ \text{(two thermometers)}$$
⚠ Checking only one path

The first path found is often the obvious one.

wrong$$\begin{aligned}&x_2\leftarrow x_1\rightarrow x_3\ \text{blocked}\\ &\Rightarrow x_2\perp\!\!\!\perp x_3\mid\{x_1,x_5\}\end{aligned}$$
right$$\begin{aligned}&\text{also }x_2\rightarrow x_4\leftarrow x_3\text{: open,}\\ &\text{so not independent}\end{aligned}$$
⚠ Forgetting the descendants of a collider

Rule (2) looks only at the collider when read quickly.

wrong$$x_3\notin C\ \Rightarrow\ x_6\to x_3\leftarrow x_1\ \text{blocked given }x_4$$
right$$x_4\in\mathrm{de}(x_3)\cap C\ \Rightarrow\ \text{open}$$
⚠ Treating an unobserved collider as open

An unobserved node usually lets information through.

wrong$$x_6\to x_3\leftarrow x_1,\ C=\varnothing:\ \text{open}$$
right$$x_6\to x_3\leftarrow x_1,\ C=\varnothing:\ \text{blocked, so }x_6\perp\!\!\!\perp x_1$$
⚠ Dividing a feature count by n

$n$ is the number in plain sight.

wrong$$\hat\theta_{jc}=\frac{n_{jc}}{n}$$
right$$\hat\theta_{jc}=\frac{n_{jc}}{n_c}$$
⚠ Dropping the absent features

A feature that is $0$ looks like it says nothing.

wrong$$\hat\pi_c\prod_{j:\,x_j=1}\hat\theta_{jc}$$
right$$\hat\pi_c\prod_{j:\,x_j=1}\hat\theta_{jc}\prod_{j:\,x_j=0}(1-\hat\theta_{jc})$$
⚠ Forgetting the class share

The likelihood looks like the whole score.

wrong$$\hat c=\arg\max_c\prod_jp(x_j\mid y=c)$$
right$$\hat c=\arg\max_c\hat\pi_c\prod_jp(x_j\mid y=c)$$
⚠ Leaving out the co-parents

They are not adjacent to the node.

wrong$$\mathrm{MB}(x_3)=\{x_1,x_4,x_6\}$$
right$$\mathrm{MB}(x_3)=\{x_1,x_2,x_4,x_6\}$$
⚠ Adding grandchildren

Everything downstream seems to carry evidence.

wrong$$\mathrm{MB}(x_3)\ni x_5$$
right$$x_5\notin\mathrm{MB}(x_3):\ p(x_5\mid x_4)\ \text{has no }x_3$$
⚠ Keeping only the parents

In a chain, the parent looks like the only source of information.

wrong$$p(x_i\mid x_{j\ne i})=p(x_i\mid\mathrm{pa}_i)$$
right$$p(x_i\mid x_{j\ne i})\propto p(x_i\mid\mathrm{pa}_i)\prod_{k:\,x_i\in\mathrm{pa}_k}p(x_k\mid\mathrm{pa}_k)$$
⚠ Reading a potential as a probability

In a directed graph the factors are probabilities.

wrong$$p(1,1,1)=\psi_{12}(1,1)\,\psi_{23}(1,1)=9$$
right$$p(1,1,1)=\frac{9}{Z}=\frac{9}{32}$$
⚠ Keeping only the biggest cliques

'maximal' sounds like 'largest'.

wrong$$M=\{\{x_1,x_2,x_3\},\{x_3,x_4,x_5\}\}$$
right$$\begin{aligned}M=\{&\{x_1,x_2,x_3\},\{x_3,x_4,x_5\},\\ &\{x_5,x_6\}\}\end{aligned}$$
⚠ Adding co-parents to an undirected blanket

The directed rule is still fresh.

wrong$$\mathrm{MB}(x_2)=\{x_1,x_3,x_4,x_5\}\ \text{in }H$$
right$$\mathrm{MB}(x_2)=\{x_1,x_3\}\ \text{in }H\text{: its neighbours}$$
⚠ Choosing the value with the higher energy

A larger product $x_ix_j$ feels like a larger energy.

wrong$$x_j=+1\ \text{if}\ \beta\sum_kx_k+\eta y_j-h<0$$
right$$x_j=+1\ \text{if}\ \beta\sum_kx_k+\eta y_j-h>0$$
⚠ Forgetting the reading

Smoothing is the visible goal.

wrong$$x_j\leftarrow\operatorname{sign}\Big(\sum_{k\sim j}x_k\Big)$$
right$$x_j\leftarrow\operatorname{sign}\Big(\beta\sum_{k\sim j}x_k+\eta y_j-h\Big)$$
⚠ Counting each neighbour pair twice

A double sum over pixels and their neighbours visits every pair from both ends.

wrong$$-\beta\sum_i\sum_{k\sim i}x_ix_k$$
right$$-\beta\sum_{i\sim j}x_ix_j\ \ \text{(each pair once)}$$
Formula card
Directed factorization
$$p(x_1,\dots,x_D)=\prod_{j=1}^{D}p(x_j\mid\mathrm{pa}_j)$$

directed acyclic graph; a root contributes $p(x_j)$

Free numbers of one factor
$$(k-1)\times\prod_{u\in\mathrm{pa}_j}(\text{values of }u)$$

$x_j$ takes $k$ values; the product is $1$ for a root

Three-node rules
$$\begin{aligned}&a\leftarrow c\rightarrow b:\ a\perp\!\!\!\perp b\mid c\\ &a\rightarrow c\rightarrow b:\ a\perp\!\!\!\perp b\mid c\\ &a\rightarrow c\leftarrow b:\ a\perp\!\!\!\perp b,\\ &\qquad\text{dependent given }c\end{aligned}$$

'dependent' means for some choice of the tables

Posterior by enumeration
$$p(q\mid e)=\frac{\sum_{h}p(q,h,e)}{\sum_{q',h}p(q',h,e)}$$

$q$ query, $e$ evidence, $h$ every other variable; $p$ written as the factorization

Blocked path, d-separation
$$\begin{aligned}&v\in C\text{ and head-to-tail}\\ &\qquad\text{or tail-to-tail, or}\\ &v\text{ head-to-head, }v\notin C,\\ &\qquad\mathrm{de}(v)\cap C=\varnothing\end{aligned}$$

every path from $A$ to $B$ blocked $\Rightarrow A\perp\!\!\!\perp B\mid C$

Naive Bayes
$$\begin{aligned}&p(y=c\mid x)\\ &\propto\pi_c\prod_jp(x_j\mid y=c)\\ &\hat\pi_c=\frac{n_c}{n}\\ &\hat\theta_{jc}=\frac{n_{jc}}{n_c}\end{aligned}$$

features independent given $y$; Bernoulli rates shown, Gaussian: class means and variances over $n_c$

Gaussian feature's vote
$$\log\frac{\mathcal N(x_j\mid\mu_{j2},\sigma^2_{j})}{\mathcal N(x_j\mid\mu_{j1},\sigma^2_{j})}=\frac{(x_j-\mu_{j1})^2-{(x_j-\mu_{j2})}^2}{2\sigma^2_{j}}$$

same variance in both classes; with different variances, divide each square by twice its own variance and add $\frac12\log(\sigma^2_{j1}/\sigma^2_{j2})$

Markov blanket, directed
$$p(x_i\mid x_{j\ne i})\propto p(x_i\mid\mathrm{pa}_i)\prod_{k:\,x_i\in\mathrm{pa}_k}p(x_k\mid\mathrm{pa}_k)$$

blanket = parents, children, co-parents; undirected: the neighbours

Undirected factorization
$$\begin{aligned}&p(x)=\frac1Z\prod_{c\in M}\psi_c(x_c)\\ &Z=\sum_x\prod_{c\in M}\psi_c(x_c)\end{aligned}$$

$\psi_c\ge0$ on maximal cliques; Boltzmann form $\psi_c=e^{-E(x_c)}$

Denoising energy and update
$$\begin{aligned}E&=h\sum_ix_i-\beta\sum_{i\sim j}x_ix_j\\ &\quad-\eta\sum_ix_iy_i\\ a_j&=\beta\sum_{k\sim j}x_k+\eta y_j-h\\ x_j&=+1\iff a_j>0\end{aligned}$$

$x_i,y_i\in\{-1,+1\}$; each neighbour pair once; stop after a sweep with no change

Check yourself

Close the page and write down from memory:

  • the factorization of a directed graph and how to count its numbers;
  • the three three-node graphs and what observing the middle node does in each;
  • the two blocking rules of d-separation;
  • the naive Bayes posterior and its two maximum likelihood estimates;
  • the directed and the undirected Markov blanket;
  • the undirected factorization with Z;
  • the denoising energy and the pixel update rule.

Then reopen the page and compare; whatever is missing is your reread list.

  • Write the joint of a given directed graph, count its free numbers, and draw one sample from given uniforms?

    c-factorization

  • Say what observing the middle node does in each three-node graph, and compute an explaining-away posterior?

    c-three-graphs

  • List every path between two sets and decide each by the two blocking rules?

    c-d-separation

  • Train Bernoulli or Gaussian naive Bayes from a table and classify a new point?

    c-naive-bayes

  • Name a node's Markov blanket and compute its conditional from the blanket's factors alone?

    c-markov-blanket

  • List cliques and maximal cliques, write the factorization with Z, and normalize a tiny model?

    c-mrf

  • Evaluate the denoising energy and run the pixel updates to a stop?

    c-denoising

Glossary (26 terms)
olasılıksal grafik model

A joint distribution described by a graph whose nodes are random variables and whose missing links state conditional independences.

directed acyclic graphyönlü döngüsüz çizge

A graph with arrows in which no path that follows the arrows comes back to where it started.

Bayesian networkBayes ağı

A directed graphical model: a directed acyclic graph with one factor $p(x_j\mid\mathrm{pa}_j)$ per node.

parentebeveyn

A node with an arrow into $x_j$; the parents form $\mathrm{pa}_j$.

descendant

A child of a node, a child of that child, and so on down the arrows.

factorizationçarpanlara ayırma

Writing a joint distribution as a product of smaller factors dictated by a graph.

ancestral sampling

Drawing a sample from a directed model by sampling every node after its parents, from the row of its table that the parents' values pick.

conditional independencekoşullu bağımsızlık

$a\perp\!\!\!\perp b\mid c$: once $c$ is known, $a$ tells nothing more about $b$; $p(a,b\mid c)=p(a\mid c)p(b\mid c)$.

tail-to-tail

A node on a path with both arrows leaving it, as $c$ in $a\leftarrow c\rightarrow b$.

head-to-tail

A node on a path with one arrow in and one arrow out, as $c$ in $a\rightarrow c\rightarrow b$.

head-to-head

A node on a path where both arrows point in, as $c$ in $a\rightarrow c\leftarrow b$; often called a collider.

collider

A head-to-head node on a path; it blocks the path unless it or one of its descendants is observed.

explaining away

Two independent causes of an observed effect become dependent: confirming one cause makes the other less likely.

d-separation

$C$ d-separates $A$ from $B$ when every path between them is blocked by $C$; it implies $A\perp\!\!\!\perp B\mid C$.

Markov blanket

The smallest set of nodes that, once known, makes a node independent of all others: parents, children and co-parents in a directed graph, neighbours in an undirected one.

co-parent

Another parent of one of a node's children.

naive Bayes classifiernaif Bayes sınıflandırıcısı

A classifier that treats the features as independent once the class is known, and predicts the class with the largest posterior.

Markov random fieldMarkov rastgele alanı

An undirected graphical model: the joint is a product of potentials on the maximal cliques, divided by $Z$.

cliqueklik

A set of nodes in which every pair is joined by an edge; here, of at least two nodes.

maximal cliquemaksimal klik

A clique that no further node can join while staying fully connected.

potential functionpotansiyel fonksiyonu

A non-negative function of a clique's variables; it scores configurations but is not a probability.

partition functionbölüşüm fonksiyonu

The normalizing constant $Z$, the sum of the product of potentials over every configuration.

Boltzmann distributionBoltzmann dağılımı

A distribution of the form $e^{-E(x)}/Z$: lower energy, higher probability.

energy functionenerji fonksiyonu

The function $E$ with $\psi=e^{-E}$; a sum of one term per clique.

image denoisinggörüntü gürültü giderme

Recovering a clean image from a noisy one, here as the most probable image under an undirected grid model.

iterated conditional modes

The common name of the lecture's coordinate-wise descent: set one variable at a time to its best value given the others.

What comes next
§13 · Restricted Boltzmann machines and deep learning

Here every potential was given, and every unknown was either summed out or set one pixel at a time. Next, an undirected graph gets a layer of hidden units, and its potentials are learned from data.

Sources
  • textbookT. Hastie, R. Tibshirani, J. Friedman, The Elements of Statistical Learning, Springer (course textbook) The weekly line names no chapter of the book, so no section numbers are cited here.
  • course materialEEE 485 lecture slides and lecture notes, chapter 12: Probabilistic graphical models Scope, order of topics and notation (pa_j, the three-node graphs, the sets A, B, C, x_j, y, C, pi_c, theta_jc, n_c, n_jc, I, M, x_c, psi_c, Z, E, x_i, y_i) follow these materials; all explanations, data, figures and exercises here are original.
  • course materialEEE 485 syllabus page on STARS, Fall 2026-27, printed 21 September 2026 Assessment weights, the weekly topic list and the recommended books.
  • textbookD. Koller and N. Friedman, Probabilistic Graphical Models: Principles and Techniques, MIT Press, 2009 Recommended in the syllabus; the lecture's overview figure comes from it.
  • textbookC. M. Bishop, Pattern Recognition and Machine Learning, Springer Recommended in the syllabus; the lecture's image denoising figures come from it, and the energy of the denoising model on this page has the same form.
  • standard resultBayes' rule, maximum likelihood, Lagrange multipliers and the Gaussian density Standard results used in the derivations. Every number and figure on this page was computed for it.

Spotted something missing or wrong? tell us · share your own notes or an old exam.

Last updated .