14 Reinforcement Learning
Every model in this book so far was trained on a dataset that sat still: nothing the model predicted changed which example came next. Now consider a language model working through a mathematics problem. It writes a thousand tokens of reasoning, and only at the end does a checker say whether the answer is right. No token has a label of its own, and each one changes what the model can write next. A controller balancing a pole on a moving cart is in the same position: each push changes the angle it must correct next, and the only reward is the time the pole stays up. Figure 14.1 draws this loop between the decision maker, the agent, and the world it acts on, the environment.
Two questions follow: which decisions deserve credit for a reward that arrives late, and how can a learner find good decisions when nobody shows it what they are? Richard Bellman answered the first in the 1950s when the rules are known: score each state by the reward still to come, turning a long horizon into a chain of one-step lookaheads (Bellman 1957). In the 1980s Andrew Barto, Richard Sutton, and Chris Watkins learned those scores by trial and error (Barto et al. 1983; Sutton 1988; Watkins 1989), and Ronald Williams showed how to improve the decision rule—the policy—directly from the rewards its attempts earn (Williams 1992). Because the learner collects its own data, its mistakes change what it learns from next, which also explains why imitation alone falls short when a model never practices recovering from its own errors.
The chapter moves in three stages. First, we formalize Markov decision processes (Section 14.1), compute exact optimal policies when the rules are known (Section 14.2), learn action values from sampled transitions (Section 14.3), and quantify exploration regret (Section 14.4). Next, we study what expert demonstrations miss over long horizons (Section 14.5) and what continuous dynamic programming becomes under known physics via the Linear-Quadratic Regulator (LQR), iterative LQR (iLQR), and receding-horizon Model Predictive Control (MPC) (Section 14.6). Finally, we optimize policies directly via score-function gradients (Section 14.7), cut their variance with baselines and group-relative weights (Section 14.8), and replace lookup tables with neural networks before mapping out the methods of this chapter and the next (Section 14.9).
All examples run in PyTorch and JAX, and most are small enough to check every estimate against an exact solution. Chapter 15 continues with bootstrapped critics, experience replay, learned dynamics models, and fixed offline datasets, while the Language Models part treats preference-based post-training in greater depth.
Resources and Further Reading
The following freely available resources provide theoretical treatments, courses, implementations, and empirical guidance.
Textbooks
- Sutton and Barto, Reinforcement Learning: An Introduction (Sutton and Barto 2018) provides a comprehensive introduction to value methods, policy methods, planning, and function approximation. Sutton and Barto received the 2024 Turing Award for their foundational contributions to reinforcement learning.
- Szepesvári, Algorithms for Reinforcement Learning (Szepesvári 2010) states this chapter’s algorithms and their guarantees in under a hundred pages.
- Bertsekas, A Course in Reinforcement Learning (Bertsekas 2025) develops reinforcement learning from the perspective of optimal control and dynamic programming.
- Agarwal, Jiang, Kakade, and Sun, Reinforcement Learning: Theory and Algorithms (Agarwal et al. 2019) supplies the sample-complexity rates this chapter states qualitatively.
- Lattimore and Szepesvári, Bandit Algorithms (Lattimore and Szepesvári 2020) is the full theory behind Section 14.4.
- For Section 14.6, Kalman (1960) and Anderson and Moore (2007) develop the Linear-Quadratic Regulator (LQR), Differential Dynamic Programming (Mayne 1966) and iterative LQR (Li and Todorov 2004) extend backward Riccati passes to nonlinear trajectory optimization, Rawlings et al. (2017) covers constrained receding-horizon Model Predictive Control, and Tedrake (2023) treats underactuated robotics and trajectory optimization.
Courses
- Berkeley CS285: Deep Reinforcement Learning covers policy gradients, value methods, model-based learning, and offline reinforcement learning at the graduate level.
- Stanford CS234: Reinforcement Learning is the course closest in scope to this chapter: foundations, exploration, and policy gradients with their guarantees.
- Stanford CS224R: Deep Reinforcement Learning covers the practice, imitation and offline methods included.
- CMU 10-703: Deep Reinforcement Learning and Control pairs the algorithms with control and physical embodiment.
- MIT 6.7920: Reinforcement Learning: Foundations and Methods develops the dynamic-programming theory introduced in Section 14.2.
Annotated implementations
- CleanRL (Huang, Rousslan F. J. Dossa, et al. 2022) provides single-file, benchmarked implementations of the major deep reinforcement learning algorithms discussed after Section 14.9.
- Stable-Baselines3 (Raffin et al. 2021) provides library implementations of the same algorithms, with tuned hyperparameters in its accompanying zoo.
- Gymnasium (Towers et al. 2024) documents the environment interface used throughout these chapters.
Empirical practice
- Spinning Up in Deep RL (Achiam 2018) is a short curriculum from the score function to SAC, written to be read beside running code.
- The 37 Implementation Details of Proximal Policy Optimization (Huang, Rousslan Fernand Julien Dossa, et al. 2022) documents how implementation choices omitted from algorithm descriptions affect PPO performance and reproducibility.