Probability and Bayesian networks
This lecture builds the probability base for generative models: joint, marginal and conditional distributions, the chain rule and Bayesian network factorization. It works through the weather table and the loan and disease numericals. After this page you can factor a joint distribution from a DAG and apply Bayes rule by hand.
Joint, marginal and conditional probabilitySearch on YouTube
A random variable names an uncertain quantity. means sunshine and means rain. Uppercase is the variable. Lowercase is one value of that variable.
The slides define three probabilities. Marginal probability is the probability of one variable. Joint probability is the probability of several variables together. Conditional probability is the probability of one variable when another value is known.
is the full joint table. is one cell in that table. The joint table holds all the information. It is the central source of truth.
is the marginal of . is the marginal of . Each marginal sums the joint cells that share its value.
is the conditional of when is known. is the reverse. Each conditional selects matching rows and normalizes them to sum to 1.
Think of a full count table. Marginal adds along a row or column. Conditional zooms into one row or column and rescales it to 100 percent.
Weather tableSearch on YouTube
The slides use two Boolean variables and . Each pair is one possible state of the world. The joint table below matches all slide numbers. Its column holds and .
| \ | Marginal | ||
|---|---|---|---|
| Marginal |
Worked example. Marginalize the weather table.
Step 1. Marginal of . Add across each row.
Step 2. Marginal of . Add down each column.
Step 3. Check.
Recompute gives the same row sums and . Recompute gives the same column sums and .
Worked example. Condition on rain: .
Step 1. Select the matching column.
Step 2. Normalize by . Divide each cell by .
Step 3. Check.
Recompute gives . Recompute gives . The conditional sums to 1.
Chain rule and independenceSearch on YouTube
The chain rule rebuilds a joint value from marginal and conditional values. Independence removes the conditioning.
and are two random variables. is the marginal of . is the conditional of when is known.
This is the test for independence. Knowledge of does not change . Knowledge of does not change .
The joint becomes a plain product. No conditional table is needed.
Worked example. Ten Boolean variables need joint cells. A chain needs 19 values.
Step 1. Full joint table size.
The last value follows from the sum-to-1 rule. So the full table needs numbers.
Step 2. Chain .
Each dependent variable needs two numbers, one per parent state. Its complement follows by subtraction from 1. Recompute gives and .
Do not store the full joint table when variables show conditional independence. The table grows as . A Bayesian network stores far fewer values.
Bayesian networksSearch on YouTube
A Bayesian network is a directed acyclic graph. Nodes are random variables. Arrows show conditional dependence. The graph encodes the joint distribution through small local tables.
is node . are its direct parents in the graph. Each factor is one small conditional table. A root with no parents uses its marginal table.
A Bayesian network holds the full joint distribution in factorized form. It uses marginal tables at roots and conditional tables elsewhere. Conditional independence makes this saving possible.
In the exam write the factorization first, then substitute numbers. Examiners give credit for the parent structure even when one product term is wrong.
Loan default factorizationSearch on YouTube
The slides ask about one loan customer. The customer has high income (). The customer made a small deposit (). The customer gave no security (). The customer owns real estate (). Variable means default and means payback.
The network factorizes the five-variable joint into five small tables. Each variable conditions on its parents only.
is high income. is small deposit. is default. is no security. is real estate ownership.
Worked example. Probability of default with the given profile.
Step 1. Write the factorized form.
Step 2. Substitute the table values.
Step 3. Multiply in order.
Recompute gives . Recompute gives .
Worked example. Probability of payback for the same profile.
Step 1. Change to in the factorization.
Step 2. Substitute the table values.
Step 3. Multiply in order.
Recompute gives . Recompute gives . Default () is about four times more likely than payback () for this profile.
Disease diagnosis with Bayes ruleSearch on YouTube
A doctor sees fever and cough. The question is the probability of disease. The network has one parent (disease) and two symptoms (fever) and (cough).
The slide values are , , , and .
is the joint of disease with both symptoms. is the marginal of the symptoms. The symptom marginal is not given directly. The network computes it by summing both disease states.
is the root, so it uses its marginal. and each condition on only. Fever and cough are independent when is known.
Worked example. Posterior disease probability when fever and cough are present.
Step 1. Joint with disease.
Step 2. Joint without disease. Here .
Step 3. Symptom marginal. Add the two joints.
Step 4. Bayes rule. Divide.
Recompute gives . Recompute gives . The sum is and the ratio is .
Never divide by a guessed . Always compute it as the sum over and . That sum is the denominator of Bayes rule.
The lab repeats the three l11 numericals with clicks. Use it to check each sum and product before the exam.
| S \ R | R=0 | R=1 | P(S) |
| S=0 | 0.78 | ||
| S=1 | 0.22 | ||
| P(R) | 0.90 | 0.10 | 1.00 |
Click a cell to see its row sum. The row sum is the marginal.
P(S=0) = 0.70 + 0.08 = 0.78. Click a cell to marginalize its row.
Reviewer authorship and samplingSearch on YouTube
Joint distributions also model word sequences. The slides use six reviews by one reviewer. Each review has length 5. The vocabulary has 50 words.
A five-node graph models one review. Each node is one word position. Each node takes 50 values. The raw joint has possibilities.
has no parent. depends on . From onward each word has two parents. The slides show this structure at .
Authorship test runs in three steps. Compute the probability of each training review under the model. Pick a threshold weight from those values. Mark a new comment as this reviewer when its probability crosses the threshold.
Generation works in a related way. The model gives one distribution per position. The greedy choice picks the most likely word at each step. That choice repeats the same review on every run.
Do not generate text by always taking the most likely word. The output repeats the same review. Sample from the distribution instead, like rolling a biased dice.
Sampling picks each word with its probability. A word with probability wins about seven runs in ten. A word with probability still wins sometimes. Every run gives a different review. The reviews still match the style of the reviewer.
Pixel neighborhoods and latent variablesSearch on YouTube
The same idea extends to images. The value of a pixel depends on its neighbours. A simple model uses the horizontal and vertical neighbours. A richer model also uses diagonal neighbours.
The local group of dependent pixels is a clique. The model stores the joint distribution of the clique. Each pixel takes discrete values from 0 to 255. Markov random fields and conditional random fields express this spatial coherence. They help generate realistic image samples.
Pixels near each other tend to look alike. Sky pixels sit next to sky pixels. The neighbourhood model states this fact as a probability.
Blue sky and latent variablesSearch on YouTube
Many pixels in the slide image are blue. The cause is a daytime photo under a clear sky. That cause is absent from the pixel data. It is hidden information inside the data.
Such hidden information is a latent variable. The model sees pixel intensities. It does not see the sky condition. The latent variable links them: clear sky raises the probability of blue pixels.
Generative models learn this link. They model observed pixels and latent causes together. The learned latent features then support reconstruction, generation and feature extraction.
Marge Joins Cells, ChainsFactor
Marginal sums cells. Joint holds all cells. Conditional selects and normalizes cells. Chain builds the joint from conditionals. Factor each node on its parents only.
Quick self-testSearch on YouTube
1. Define marginal, joint and conditional probability in one line each.
Marginal is the probability of one variable. Joint is the probability of several variables together. Conditional is the probability of one variable when another value is known.
2. The weather table has P(S = 0, R = 1) = 0.08 and P(S = 1, R = 1) = 0.02. Find P(R = 1) and the conditional of S = 0.
. . The two conditionals and sum to 1.
3. State the chain rule for two variables and the independence test.
Chain rule: . Independence test: . Under independence .
4. Ten Boolean variables need a full joint table. How many values must be stored, and how many does a chain A to J need?
The full table has cells, so store values. The chain needs plus two values per link: values.
5. Write the loan factorization for default with the given profile and compute its value.
. The payback version with gives .
6. Fever and cough are present. The slide values are , , , and . Find the posterior.
and . . So .
7. Differentiate greedy word choice and sampling for review generation.
Greedy choice takes the most likely word at each step. It repeats the same review. Sampling draws words with their probabilities. It gives a different review on each run.
8. What is a latent variable? Use the blue-sky image.
A latent variable is hidden information inside the data. The pixels are blue because the photo shows daytime clear sky. The sky condition is the latent variable behind the blue pixels.
9. A pixel model uses only horizontal and vertical neighbours. What changes when diagonal neighbours join the clique?
The clique grows and captures richer spatial links. The joint table of the clique grows with it. The model represents spatial coherence better and needs more values.
- Marginal probability covers one variable. Joint probability covers several variables together. Conditional probability fixes one value and normalizes.
- Marginal sums joint cells. Conditional selects matching cells and divides by their sum. The weather table gives and .
- Chain rule states . Independence states , so .
- Ten Boolean variables need joint values but only values as a chain. Bayesian networks exploit this conditional independence.
- A Bayesian network factorizes the joint as . Roots use marginals and other nodes use small conditional tables.
- The loan profile gives for default and for payback.
- Disease Bayes rule gives , and .
- Review authorship thresholds the joint word probability. Text generation must sample from the distribution. Greedy maximum repeats one review.
- Pixel values depend on neighbour cliques with values 0 to 255. Markov random fields model this coherence.
- A latent variable is hidden cause in the data, like clear sky behind blue pixels.
Bayes Theorem Geometry
Bayes Theorem Clearly Explained
Conditional Probabilities