1. Home
  2. Explore
  3. Computer Science
  4. Bayesian Networks Overview

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Bayesian Networks Overview

Speaker 1Speaker 2

Bayesian Networks Overview

8:17
0:00-8:17
  1. Hope

    So today we're diving into Bayesian networks. In one sentence, they're factor graphs plus probability. That sounds simple, but it's actually a huge step forward in how we model uncertainty.

  2. Maria

    Okay, so we already know factor graphs from last week — variables and factors. Adding probability means the factors become probability distributions, right? But first, maybe a quick refresher on probability basics?

  3. Hope

    Definitely. Let's start with a joint distribution over two variables, say sunshine and rain. The joint distribution P(S,R) is a table with a probability for every combination. For example, P(S=1,R=0)=0.7 means a 70% chance it's sunny and not rainy.

  4. Maria

    And from that joint distribution we can get marginals — like the probability of sunshine regardless of rain — by summing over all values of the other variable. So P(S=1) would be the sum of P(S=1,R=0) and P(S=1,R=1).

  5. Hope

    Exactly. And then there's conditioning. If we observe that it's raining, we want P(S|R=1). We take only the rows where R=1, and normalize so they sum to 1. That gives us a new distribution. These two operations — marginalization and conditioning — are the core of probabilistic inference.

  6. Maria

    So probabilistic inference is just answering queries like "What's the probability it's raining given that there's traffic and it's autumn?" You combine conditioning on evidence with marginalizing out irrelevant variables.

  7. Hope

    Right. But the challenge is that the full joint distribution is exponential in the number of variables. If you have 100 binary variables, that's 2^100 entries — impossible to write down or compute with directly. Bayesian networks give us a compact way to represent that huge distribution.

  8. Maria

    And that's where the factor graph structure comes in. We specify local conditional distributions for each variable given its parents, and then the joint distribution is just the product of all those locals. That's a much smaller description.

  9. Hope

    Let's make it concrete with the classic alarm network. We have variables Burglary, Earthquake, and Alarm. Burglary and Earthquake are independent, both with a small prior probability. The alarm depends on both: it goes off if either a burglary or an earthquake happens. So we define P(B), P(E), and P(A|B,E).

  10. Maria

    And then the joint distribution is P(B,E,A) = P(B) P(E) P(A|B,E). That's a product of three small tables instead of one big three-variable table. I can see the savings already.

  11. Hope

    Now, suppose you hear the alarm. You'd think the probability of a burglary goes up, right? And it does — from a prior of, say, 0.05 to about 0.51. But then you hear on the radio that there was an earthquake. What happens to the probability of burglary then?

  12. Maria

    I'd guess it goes down, because the earthquake already explains the alarm. So even though burglary and earthquake are independent in the prior, conditioning on the alarm makes them dependent. That's explaining away.

  13. Hope

    Exactly! It's a really important reasoning pattern. The probability of burglary given alarm and earthquake drops back to the prior, 0.05. So the earthquake 'explains away' the alarm, so we don't suspect a burglary anymore. This shows why writing things down precisely matters — our intuitions can be tricky.

  14. Maria

    And this network is a directed acyclic graph. Generalizing, a Bayesian network over variables X1 to Xn defines the joint distribution as the product over i of P(Xi | parents of Xi). Each factor is a local conditional distribution.

  15. Hope

    And note: each local conditional distribution sums to 1 over the variable for any fixed parent values. That property gives us two nice consistencies. First, if you marginalize out a leaf node, you just drop it from the graph — the resulting distribution is exactly what you'd get from the sub-network. Second, the local conditionals are consistent with the conditionals derived from the full joint distribution.

  16. Maria

    That's powerful. So we can do graphical manipulations instead of heavy algebra. In the alarm network, marginalizing out Alarm would just leave B and E with their independent prior. In a plain factor graph, you'd have to keep the factor because it's not necessarily a conditional distribution — but here we know it sums to 1, so it disappears.

  17. Hope

    Let's look at another example: cold and allergies. You have variables Cold, Allergies, Coughing, and ItchyEyes. Cold causes both coughing and itchy eyes, allergies only cause itchy eyes. So you set edges from Cold to both, and from Allergies to ItchyEyes. Then you define local conditionals for each variable — like P(Cold), P(Allergies), P(Cough|Cold), P(Itchy|Cold,Allergies).

  18. Maria

    So if you observe coughing and itchy eyes, you can compute the probability of having a cold versus allergies. And because of explaining away again, the probability of cold might be lower than you'd think, because allergies are also possible. It's fascinating how the network captures these interactions.

  19. Hope

    Now, a different way to think about Bayesian networks is as probabilistic programs. Instead of writing tables, you write a program with random choices. For the alarm network: B ~ Bernoulli(ε), E ~ Bernoulli(ε), A = B OR E. Each run of the program generates a sample from the joint distribution.

  20. Maria

    So it's like a generative story. You start at the root nodes, sample their values, then move down, sampling each variable conditioned on its parents. The program defines the distribution exactly. And it scales to complex models with loops or functions.

  21. Hope

    Exactly. There are many classic probabilistic programs: Markov models where each word depends on the previous, hidden Markov models for time series, naive Bayes for classification, latent Dirichlet allocation for topics, and so on. They all share the structure of hidden causes generating observed effects.

  22. Maria

    So the mindset when designing a Bayesian network is generative: you imagine a story of how the data you observe might have been produced by some underlying, unobserved variables. Then you do inference to reverse that — given observations, infer the hidden causes.

  23. Hope

    Right. And inference is the key challenge. How do we compute P(query | evidence) efficiently? We can use the factor graph representation and algorithms like variable elimination. Let's go through the inference steps with a simple Markov chain: X1 → X2 → X3 → X4. Suppose we want P(X3 | X2=5).

  24. Maria

    First, remove non-ancestors of the query and evidence. Here, X4 is a descendant of X2? Actually, X4 is downstream of X2? Wait — ancestors are upstream. X4 is downstream, so it's not an ancestor of X2 or X3. So we can marginalize it out.

  25. Hope

    Exactly. Graphically, we delete X4. Then we convert the remaining subgraph to a factor graph: one factor per variable. For this chain, that's P(X1), P(X2|X1), P(X3|X2). Since we condition on X2=5, we remove X2 as a variable and plug its value into the factors that involve it.

  26. Maria

    So we get factors P(X1) and P(X2=5|X1) connected to X1, and P(X3|X2=5) connected to X3. Those two groups are disconnected because X1 doesn't connect to X3 directly. So we can drop the X1 side — it's just a constant factor for X3. And we're left with P(X3|X2=5), which is the answer.

  27. Hope

    Yes! And that matches the consistency property: the local conditional from the network is exactly the conditional we want. But if the graph is more tangled, we can't just drop things. For the alarm network query P(B|A=1), we have to marginalize out E explicitly.

  28. Maria

    So after conditioning on A=1, we have three factors: P(B), P(E), and P(A=1|B,E). To get the marginal over B, we sum over E. That creates a new factor f(B) = sum_E P(E) * P(A=1|B,E). Then P(B|A=1) is proportional to P(B) * f(B). That's variable elimination.

  29. Hope

    And that procedure — remove non-ancestors, convert to factor graph, condition on evidence, marginalize disconnected components, then do variable elimination on the remaining factors — is a general strategy for probabilistic inference in Bayesian networks. Next time we'll dive deeper into the algorithms that make this efficient.

  30. Maria

    So today we learned that Bayesian networks are factor graphs with a probabilistic interpretation. They give us a compact way to represent large joint distributions using local conditionals, and they come with useful consistency properties. The generative story helps us design models, and inference lets us answer queries about hidden variables. I'm starting to see why this is such a powerful framework.

  31. Hope

    Exactly. And as we'll see, the same algorithms we used for maximum weight assignments in factor graphs — like variable elimination and Gibbs sampling — have probabilistic counterparts. It all comes together. For now, practice with small networks and get comfortable with the inference steps. Next lecture we'll tackle more complex inference techniques.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent