Stanford CS221 | Autumn 2025 | Lecture 12: Bayesian Networks I
TL;DR
This lecture transitions from model-free and model-based reinforcement learning to probabilistic reasoning, introducing Bayesian networks as a framework for representing uncertain world states. It establishes probability fundamentals—joint distributions, marginalization, and conditioning—using tensor operations (einops) to provide the mathematical foundation for efficient inference in complex domains.
🧠 Model-Based vs. Model-Free Intelligence 3 insights
Model-free methods are direct but inflexible
Approaches like Q-learning compile rewards and transitions into direct predictions, making it impossible to adapt if the reward function changes without completely retraining the model.
Model-based reasoning enables flexible planning
Understanding how the world works allows agents to recompute optimal policies on the fly when objectives change, whereas Q-values permanently bake in the original reward structure.
Bayesian networks model uncertain world states
The lecture shifts from deterministic search and MDPs to representing the world probabilistically, addressing how agents reason under uncertainty about multiple interrelated state variables.
📊 Probability as Tensor Operations 3 insights
Joint distributions represent complete world states
A joint distribution over random variables assigns probabilities to every possible assignment of values, serving as a comprehensive 'source of truth' for all possible world configurations.
Probability tables are multi-dimensional tensors
Joint distributions map directly to tensors where each axis corresponds to a random variable, enabling efficient computation using linear algebra rather than manual table lookups.
Einops notation expresses all probability laws
Marginalization and other operations can be written compactly using einops (einsum) notation, where summing over axes not present in the output label corresponds to marginalizing out variables.
🔍 Core Inference Operations 3 insights
Marginalization collapses uncertain variables
To ignore a variable, sum probabilities over all assignments that differ only in that variable, effectively collapsing the probability table by removing the corresponding dimension.
Conditioning selects and renormalizes evidence
Observing evidence selects compatible assignments from the joint distribution, then divides by the evidence probability to renormalize, yielding a valid probability distribution over remaining variables.
Inference queries act like SQL on databases
Probabilistic inference treats the joint distribution as a database, allowing queries that specify evidence variables and request probabilities for query variables while automatically marginalizing all unmentioned variables.
Bottom Line
To reason under uncertainty, represent the world as a joint probability distribution over random variables and use marginalization to ignore unknowns and conditioning to incorporate evidence—foundations that Bayesian networks will make computationally tractable for complex domains.
More from Stanford Online
View all
Stanford CS221 | Autumn 2025 | Lecture 20: Fireside Chat, Conclusion
Percy Liang reflects on AI's transformation from academic curiosity to global infrastructure, debunking sci-fi misconceptions about capabilities while arguing that academia's role in long-term research and critical evaluation remains essential as the job market shifts away from traditional entry-level software engineering.
Stanford CS221 | Autumn 2025 | Lecture 19: AI Supply Chains
This lecture examines AI's economic impact through the lens of supply chains and organizational strategy, demonstrating why understanding compute monopolies, labor market shifts, and corporate decision-making is as critical as tracking algorithmic capabilities.
Stanford CS221 | Autumn 2025 | Lecture 18: AI & Society
This lecture argues that AI developers bear unique ethical responsibility for societal outcomes, framing AI as a dual-use technology that requires active steering toward beneficial applications while preventing misuse and accidental harms through rigorous auditing and an ecosystem-aware approach.
Stanford CS221 | Autumn 2025 | Lecture 17: Language Models
This lecture introduces modern language models as industrial-scale systems requiring millions of dollars and trillions of tokens to train, explaining their fundamental operation as auto-regressive next-token predictors that encode language structure through massive statistical modeling.