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.

Figure 14.1: The loop between an agent and its environment. At step \(t\) the agent, following its policy \(\pi\), chooses an action \(a_t\) (blue); the environment, governed by its transition probabilities \(P\) and reward \(r\), returns a reward \(r_t\) and the next state \(s_{t+1}\) (orange). Repeating the exchange produces the trajectory \(\tau = (s_0, a_0, r_0, s_1, a_1, r_1, \ldots)\).

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

Annotated implementations

Empirical practice