Reinforcement Learning

Work in progress: this part of the notes is still being revised.

Reinforcement learning studies agents that learn to act from the consequences of their actions: an agent observes, acts, receives rewards, and must find behavior that maximizes the rewards it will collect, without being told what the right actions are. It builds on the probability, optimization, and linear algebra of Foundations, on the supervised learning and function approximation of Machine Learning and Deep Learning, on the decision theory, filtering, game trees, Monte Carlo tree search, and game theory of Artificial Intelligence, on the preference learning and reasoning of NLP and LLMs, and on the generative models of Generative AI. The module is about twice the size of the others: 31 chapters in two parts follow the topics of the reading plan, and 17 labs apply them to working agents.

Chapters

Part I — Classical reinforcement learning.

ChapterMain contentReading plan
1. Markov Decision ProcessesThe reward hypothesis; Markov chains and reward processes; returns and discounting; policies, value functions, and the Bellman equations; occupancy measures; optimal values and why deterministic Markov policies suffice; what discounts, rewards, and time limits specify; partial observability, previewed.Topic 1
2. Dynamic ProgrammingPolicy evaluation by iteration and by linear algebra; the policy improvement theorem; policy iteration as Newton’s method; value iteration, error bounds, and asynchronous updates; generalized policy iteration; linear programming; finite horizons and average reward; complexity and the curse of dimensionality.Topic 2
3. Multi-Armed BanditsRegret; ε-greedy, optimism, and explore-then-commit; UCB1, KL-UCB, and the Lai–Robbins bound; minimax regret; Thompson sampling and its regret; gradient bandits; nonstationarity; best-arm identification.Topic 3
4. Contextual, Bayesian, and Adversarial BanditsThe bandit as a belief MDP and the Gittins index; adversarial bandits and Exp3; contextual bandits, LinUCB, and linear Thompson sampling; off-policy evaluation and learning from logs.Topic 4
5. Monte Carlo MethodsFirst-visit and every-visit prediction; blackjack; exploring starts and ε-soft policies; importance sampling, ordinary and weighted, and its variance; the role of the Markov property.Topic 5
6. Temporal-Difference LearningThe TD error and bootstrapping; bias and variance of targets; why TD is often faster than Monte Carlo; stochastic approximation and step sizes; afterstates; TD-Gammon; TD errors and dopamine.Topic 6
7. Model-Free ControlSARSA, Q-learning, and Expected SARSA, with their convergence; cliff walking and on-policy caution; maximization bias and double Q-learning; exploration, step sizes, and time limits in practice.Topic 7
8. Multi-Step Bootstrapping and Eligibility Tracesn-step returns and how to choose n; λ-returns and the forward view; eligibility traces and the backward view; true online TD(λ); SARSA(λ) and Q(λ).Topic 8
9. Off-Policy LearningImportance sampling for returns and its products of ratios; control variates and doubly robust estimators; the curse of horizon; tree backup, Q(σ), and a general form of off-policy traces; Retrace and its descendants.Topic 9
10. Planning and Learning with Tabular ModelsModels and Dyna; wrong models and exploration bonuses; prioritized sweeping; trajectory sampling and real-time dynamic programming; rollout algorithms, sparse sampling, and Monte Carlo tree search.Topic 10
11. Value Function ApproximationThe prediction objective; gradient Monte Carlo and semi-gradient TD; linear methods and the TD fixed point; features, tile coding, and step sizes; least-squares TD and policy iteration; control with approximation and average reward.Topic 11
12. The Deadly Triad and Gradient-TD MethodsBaird’s counterexample and the deadly triad; the geometry of value functions; residual gradients and why the Bellman error is not learnable; gradient-TD methods and emphatic TD; fitted value iteration and its error bounds.Topic 12
13. Policy Gradient and Actor-Critic MethodsParameterized policies and the policy gradient theorem; REINFORCE and baselines; actor–critic methods with traces; compatible features and the natural policy gradient; Gaussian and deterministic policies.Topic 13
14. Partially Observable EnvironmentsAgent states and memory; POMDPs and value functions over beliefs; exact and point-based value iteration; online planning with POMCP; finite-state controllers; learned memory and beliefs; Bayes-adaptive MDPs; Gaussian beliefs, the Kalman filter, and the separation of estimation and control.Topic 14
15. Optimal Control and Trajectory OptimizationThe linear–quadratic regulator and the Riccati recursion; LQR as a laboratory for RL; shooting, collocation, DDP, and iLQR; the cross-entropy method and MPPI; model predictive control, stability, and constraints; where control and RL meet.Topic 15

Part II — Modern reinforcement learning.

ChapterMain contentReading plan
16. Deep Q-LearningDQN: fitted Q-iteration with networks, experience replay, and target networks; measuring progress on Atari; overestimation and double DQN; dueling networks; the deadly triad in practice and the pathologies of deep value learning.Topic 16
17. Distributional Reinforcement LearningThe distributional Bellman equation and its contraction; categorical and quantile representations; C51, QR-DQN, and IQN; why distributions help; risk-sensitive decisions and CVaR.Topic 17
18. Data-Efficient and Scalable Value-Based AgentsPrioritized replay, multi-step returns, noisy networks, and Rainbow; distributed replay, R2D2, and Agent57; Atari 100k and data efficiency; replay ratios, resets, plasticity, and scaling; evaluating agents.Topic 18
19. Deep Actor-Critic and Distributed RLA2C and A3C; generalized advantage estimation; rollouts, truncation, and termination; policy lag and V-trace; IMPALA and SEED; simulation on accelerators; OpenAI Five.Topic 19
20. Trust Regions and Proximal Policy OptimizationThe performance difference lemma and conservative policy iteration; TRPO and the natural gradient; PPO’s clipped objective and what it does; the implementation details that matter; MPO and regularized MDPs; PPO as the default.Topic 20
21. Continuous Control and Maximum-Entropy RLDeterministic policy gradients and DDPG; overestimation and TD3; the maximum-entropy objective and soft actor–critic; control as inference and linearly solvable MDPs; ensembles, high update-to-data ratios, and normalization; benchmarks and reproducibility.Topic 21
22. Exploration in Deep RLWhy dithering fails; counts, pseudo-counts, and random network distillation; curiosity and the noisy TV; episodic novelty; posterior sampling, bootstrapped DQN, and randomized priors; Go-Explore; exploration without rewards.Topic 22
23. Model-Based RL and World ModelsWhy model errors compound; probabilistic ensembles, PETS, and MBPO; latent world models and the Dreamer agents; value-equivalent models and TD-MPC; transformer, diffusion, and interactive world models; when models help.Topic 23
24. Planning with Learned ModelsAlphaGo, AlphaGo Zero, and AlphaZero; MuZero and its extensions; what visit counts approximate; Gumbel search and policy improvement with few simulations.Topic 24
25. Imitation Learning and Inverse RLBehavior cloning and compounding errors; DAgger; inverse RL, feature matching, and maximum-entropy IRL; GAIL, AIRL, and IQ-Learn; expressive policies and learning from video; rewards from human preferences.Topic 25
26. Offline Reinforcement LearningWhy off-policy algorithms fail offline; policy constraints, conservative Q-learning, and implicit Q-learning; model-based offline RL; pessimism and coverage; sequence models and expressive policies; evaluation and offline-to-online learning.Topic 26
27. Multi-Agent RL and Self-PlaySolution concepts and the dynamics of learning in games; counterfactual regret minimization and poker; self-play, populations, PSRO, and leagues; cooperative MARL and centralized training; conventions, social dilemmas, and negotiation; self-play for language models.Topic 27
28. Reinforcement Learning for Language Models and ReasoningGeneration as a decision problem and the KL-regularized objective; from PPO to critic-free methods such as GRPO; normalizations, importance ratios, and entropy; learned, verifiable, and process rewards; reasoning models, search, and multi-turn agents; reward hacking.Topic 28
29. Generalist Agents, Meta-RL, and Open-EndednessMeta-RL as Bayes-adaptive control; RL², MAML, and task inference; in-context RL and discovered algorithms; goal-conditioned and zero-shot RL; generalist and pretrained agents; robot foundation models; novelty, quality diversity, and environment generation.Topic 29
30. The Theory of Reinforcement LearningSample complexity with a generative model; regret and PAC bounds, optimism, and posterior sampling; linear MDPs and the limits of realizability; complexity measures; offline data and pessimism; convergence of policy optimization.Topic 30
31. Reinforcement Learning in the Real WorldReward design and potential-based shaping; reward hacking; goals and hindsight relabeling; options and hierarchies; constrained MDPs, safe exploration, and robustness; sim-to-real transfer, domain randomization, and adaptation; deployed systems and the challenges of real-world RL.Topic 31

Part I builds the subject from its foundations. Chapters 1–2 define the problem and solve it with a known model; chapters 3–4 isolate exploration in bandits; chapters 5–10 learn from experience without a model, by Monte Carlo, temporal differences, multi-step and off-policy methods, and planning with learned tabular models; chapters 11–13 add function approximation and policy gradients, with the instabilities that come with them; and chapters 14–15 treat hidden state and continuous control. Part II follows deep RL to the current frontier: value-based agents (chapters 16–18), actor-critic and policy optimization methods (19–21), exploration (22), models and planning (23–24), learning from demonstrations and fixed data (25–26), many agents (27), language models (28), and generalist agents (29), and it closes with the theory that explains what is possible (30) and the practice of deploying RL in the world (31). Proofs and longer derivations appear in collapsed appendices at the end of each chapter, and every chapter ends with exercises whose solutions are in collapsed callouts.

Labs

The labs are larger projects, each a page in the Labs folder with instructions, expected results, commentary on what the results show, and extensions, and a reference solution in Labs/code that prints the expected results on a laptop CPU.

LabWhat you buildChaptersTime
1. Dynamic Programming on FrozenLake and TaxiExact models from Gymnasium environments, solved by policy and value iteration and checked by simulation.1–2½ min
2. Bandit Algorithms in PracticeA library of bandit algorithms, stress tests, a contextual bandit from real data, and off-policy evaluation.3–41 min
3. Tabular Control with Monte Carlo and TD MethodsMonte Carlo, SARSA, Q-learning, and double Q-learning on four environments with known optimal policies.5–74 min
4. Planning with Learned and Given ModelsDyna, rollouts, Monte Carlo tree search, and real-time dynamic programming.101½ min
5. Tile Coding and Linear Control on Mountain CarTile coding, SARSA(λ), true online SARSA(λ), and least-squares policy iteration.8, 113 min
6. Policy Gradient and Actor-Critic Methods on CartPoleREINFORCE estimators, an online actor–critic, GAE, and the natural policy gradient.132½ min
7. System Identification, LQR, and Model Predictive ControlA learned linear model with LQR, and model predictive control of a pendulum with given and learned models.152 min
8. Deep Q-Networks on CartPole and MinAtarDQN from scratch, its ablations and overestimation, and double DQN on a miniature Atari game.1625 min
9. Advantage Actor-Critic with Parallel and Stale ActorsA2C, policy lag, V-trace, and clipping.194 min
10. Proximal Policy Optimization from ScratchPPO on LunarLander with ablations, and a Gaussian policy for HalfCheetah.2045 min
11. Off-Policy Actor-Critics for Continuous ControlDDPG, TD3, and SAC on a pendulum and on HalfCheetah.2140 min
12. Model-Based RL with Learned EnsemblesPETS with probabilistic ensembles, and MBPO.2315 min
13. AlphaZero and Gumbel Search from ScratchAlphaZero on tic-tac-toe and Connect Four, and Gumbel search with few simulations.2417 min
14. Imitation and Offline Reinforcement LearningBehavior cloning, DAgger, TD3+BC, and implicit Q-learning on datasets of different quality.25–2625 min
15. Regret Minimization and Self-Play in PokerLeduc poker with exact exploitability; CFR, CFR+, and Monte Carlo CFR; regularized self-play and PSRO.273 min
16. Reinforcement Learning for a Small Language ModelA small transformer fine-tuned with REINFORCE, RLOO, GRPO, and Dr. GRPO against a verifier.2825 min
17. Safe and Robust Reinforcement LearningLagrangian PPO, a model-based shield, and sim-to-real transfer with domain randomization and RMA.3116 min

Times are for the reference solutions; the labs from 8 on use two cores. Chapters without a lab of their own (9, 12, 14, 17, 18, 22, 29, and 30) have code blocks and experimental exercises that play the same role.

Shared conventions

Examples and supporting resources

The chapter text contains the definitions, derivations, and worked examples, and every figure is generated by a script in Sources/Figure code. The computing setup records the Python environment and how to run the code, the labs, and the figure scripts, and figure sources records the construction behind each figure.

The reading plan lists the lectures and readings for each topic. Course links collects the courses it draws on, video links the lecture recordings by chapter, books and documentation the reference texts, libraries, and tutorials, and papers the principal research behind each chapter. Beyond the module’s own labs, the CS285 homeworks and Spinning Up are the best further exercises, and CleanRL is the best reference for complete, benchmarked implementations.

Connections to later modules

Safety and frontier research starts from problems this module documents: rewards that are misspecified and proxies that are hacked (chapter 31, chapter 28), open-ended systems that generate their own objectives (chapter 29), agents that learn in the world and must stay within constraints while they do (chapter 31), and the language models trained with human feedback and verifiable rewards (chapter 28). It adds goal misgeneralization, the risks of agents that pursue goals in the world, and the oversight and evaluation of systems trained with reinforcement learning.

Labs

Reading plan and sources