The algorithms of the previous chapter assumed something that is never true in most real applications: the transition kernel is known. Every sweep of iterative policy evaluation computes — an expectation that requires knowing the probability of landing in each next state. In a board game with explicit rules, this can be computed analytically. In robotics, financial markets, protein folding, or language generation, the dynamics are either too complex to model or simply unobservable. The agent must learn the value function from experience — from sequences of observed states, actions, and rewards — without ever accessing directly.
Two approaches suggest themselves. The first is Monte Carlo estimation: run complete episodes, compute the actual return , and average over many episodes. No model, no bootstrap, just the empirical average of observed returns. The second approach is less obvious and more powerful: do not wait for the episode to end. After observing a single transition , use the current estimate of as a proxy for the future return, and update immediately. This is temporal difference learning — the bootstrapping insight identified by Sutton in 1988 in a paper titled “Learning to Predict by the Methods of Temporal Differences.”
The difference between these two approaches is not merely algorithmic. It reflects two different views of what a value estimate represents and what evidence should update it.
Monte Carlo: The Unbiased Baseline
Before developing temporal difference methods, it helps to understand precisely what they improve upon. The Monte Carlo prediction algorithm is the simplest model-free approach to policy evaluation: run the policy for complete episodes, record the actual return from each visited state, and update:
Since is an unbiased sample of , the empirical average converges to the true value function by the law of large numbers. No Bellman equation, no transition kernel, and no approximation are involved. The estimate is statistically correct in a clean and verifiable sense.
The limitations follow directly from this cleanliness. First, Monte Carlo requires complete episodes: cannot be computed until the episode terminates, because it depends on all future rewards. Many environments have no natural termination — continuous control tasks, real-time systems, and most physical processes operate indefinitely. Second, Monte Carlo estimates have high variance: is a sum of many random rewards, and each contributes independent noise. The variance of an -step return grows with , and for long episodes in stochastic environments, the variance of a single-episode return can be large enough to require thousands of samples for reliable estimation.
Both limitations have the same root cause: Monte Carlo refuses to use any information about the relationship between state values. It treats each state’s value as an independent quantity to be estimated from scratch. The Bellman equations say that state values are not independent — they are related by the recursive identity — and this relationship can be exploited.
The Bootstrapping Idea and TD(0)
The Bellman expectation equation for a fixed policy is:
This says that is an unbiased estimator of — exactly as is, but requiring only one step of observed reward rather than an entire trajectory. If we had the true , we could use this one-step target directly and achieve lower variance than Monte Carlo, since it depends on only a single random reward rather than a sum of many.
We do not have the true . But we have an estimate , and we can substitute it:
This is the TD(0) update. The quantity is the TD error: the difference between what the Bellman equation predicts the value of should be, given the observed transition, and what the current estimate says it is. A positive TD error means was better than expected; a negative error means it was worse. The update nudges toward consistency with the observed transition.
Bootstrapping refers to the circularity in this update: we are using the current estimate to improve the current estimate . A value estimate is being used to generate a target for updating another value estimate. This is not, in general, a sound inference procedure — and indeed it introduces a bias that Monte Carlo avoids — but it works because the Bellman equations constrain what a self-consistent set of value estimates must look like. The contraction property of ensures that the fixed point of bootstrapped iteration is the unique true value function .
The practical advantage is significant. TD(0) updates after every single transition, without waiting for an episode to end. It is fully online: estimates improve continuously as experience arrives, rather than in batch at the end of episodes.
Stochastic Approximation and Convergence
TD(0) is a special case of stochastic approximation: a general framework for finding the fixed point of an operator using noisy estimates of its output. The target is a single-sample estimate of the Bellman expectation . The TD(0) update moves toward this noisy target with step size .
The classical convergence result — due to Sutton (1988) and formalized using the ODE method by Tsitsiklis (1994) — states that under the Robbins-Monro conditions on step sizes,
and assuming every state is visited infinitely often, TD(0) converges with probability 1 to . The first condition ensures enough total learning to reach the fixed point; the second ensures the noise diminishes fast enough for the estimates to stabilize. The Banach contraction property of provides the key analytical ingredient: it guarantees that the expected update at each step points toward , so the stochastic iterates cannot wander arbitrarily far.
In practice, a constant step size is often preferred over a decaying schedule: it converges not to a fixed point but to a neighborhood of one, tracking non-stationarity if the environment or policy changes over time. This is often the desired behavior in continuing (non-episodic) tasks.
The -Step Spectrum
TD(0) and Monte Carlo are the extremes of a continuous spectrum of algorithms, parameterized by how many steps of observed reward are used before bootstrapping. The -step return is:
For , this is the TD(0) target . As , this approaches the Monte Carlo return . The corresponding -step TD update replaces the one-step target with :
The tradeoff is explicit. Larger reduces the bias introduced by bootstrapping — the target depends less on the potentially inaccurate current estimates — at the cost of higher variance from summing more observed rewards. Early in training, when is far from , larger is often better: the bootstrapped value introduces substantial bias, and longer observed returns are more informative. Late in training, when , smaller is often better: the bias is small, and shorter returns have lower variance and propagate information faster.
TD() and Eligibility Traces
Rather than committing to a single , TD() averages across all -step returns with geometrically decaying weights parameterized by :
The factor normalizes the weights to sum to one. When , only the one-step return receives weight: TD() reduces to TD(0). When , the geometric series assigns all weight to the infinite-horizon return and TD(1) is equivalent to Monte Carlo. For , the -return is dominated by short returns when is small, and by longer returns when is large — a smooth interpolation that avoids the binary choice between the two extremes.
The forward view of TD() updates using as the target, but requires knowing all future rewards before computing the weighted sum — not online. The backward view provides an equivalent online algorithm using eligibility traces: a per-state memory vector that accumulates recent visits, decaying geometrically:
At each step, the TD error is propagated backward through all recently visited states in proportion to their eligibility:
States visited recently and frequently have high eligibility and receive large updates; states visited long ago have low eligibility and receive small ones. The trace vector encodes a decaying memory of which states were responsible for the current TD error — hence the name. Sutton’s original paper proved that the forward and backward views are equivalent in expectation: they produce the same expected parameter updates, step by step, even though they compute them in opposite temporal directions.
Eligibility traces are the first mechanism in this progression that explicitly connects past states to present errors. This is relevant beyond the algorithmic efficiency argument: in neuroscience, the TD error has been identified with dopaminergic prediction error signals, and eligibility traces correspond to synaptic eligibility — the biological mechanism by which neurons that fired recently remain eligible for Hebbian potentiation. The mathematical structure and the biological mechanism converge on the same solution to the credit assignment problem.
From Prediction to Control: SARSA
TD(0) solves the prediction problem. For the control problem — finding the optimal policy — we need to not only evaluate but also improve. The complication is that alone is not sufficient for improvement without the model: selecting the greedy action requires , which requires knowing .
The model-free resolution is to estimate action-value functions directly. With in hand, policy improvement requires no model: . Applying TD prediction to functions yields the control algorithm.
SARSA — named for the quintuple used in each update — is the on-policy version:
The target uses the action that was actually selected by the current policy. This makes SARSA on-policy: the Q-function estimate is consistent with the policy generating the experience, including its exploratory deviations. Interleaving SARSA updates with -greedy action selection — act greedily with probability and uniformly at random with probability — produces an online generalized policy iteration that converges to the optimal policy as .
The exploration parameter resolves the exploration-exploitation tension: an agent that always acts greedily can trap itself in a locally good policy, never visiting states where the current estimates are wrong. Occasional random actions ensure all relevant regions of state-action space are eventually visited. This is the simplest instantiation of a problem that pervades reinforcement learning and does not have a clean general solution.
Q-Learning: Off-Policy Control
Sutton’s 1988 paper established TD prediction; Watkins’ 1989 PhD thesis introduced the model-free control algorithm that would ultimately prove most influential. The modification is deceptively small: replace the action-value of the next selected action in the SARSA target with the maximum action-value over all next actions.
The Q-learning update is:
The target is a sample estimate of the right-hand side of the Bellman optimality equation:
Q-learning is therefore stochastic approximation of value iteration applied to action-value functions. Because the target uses — the greedy action, not the action actually taken — Q-learning is off-policy: the target policy (greedy with respect to ) differs from the behavior policy generating experience (e.g., -greedy). The behavior policy needs only to ensure sufficient exploration; the target policy is always implicitly greedy.
This off-policy character is both Q-learning’s strength and, eventually, its source of instability. The strength: experience from any exploratory policy can be used to learn about the greedy policy, making Q-learning flexible about data collection. The behavior policy could be -greedy, uniformly random, or even replayed from a buffer of old transitions. The instability: the asymmetry between the behavior policy generating bootstrapped targets and the target policy being evaluated can, with function approximation, cause the Q-estimates to diverge — a problem the next chapter will confront directly.
SARSA vs. Q-Learning: A Concrete Distinction
The difference between SARSA and Q-learning is not merely technical. In environments where exploration is costly or dangerous, it produces qualitatively different behavior.
The standard example is a grid world with a cliff along one edge. The globally optimal path runs close to the cliff — direct and fast. A conservative path runs far from it. SARSA, which evaluates the -greedy policy including its random deviations, learns the conservative path: with small probability, a random step near the cliff leads to falling, and this risk is incorporated into the Q-values. Q-learning learns the optimal path: its target is always the greedy policy, which never deliberately steps toward the cliff, so the Q-values reflect the optimal cost rather than the -greedy cost.
At the limit , both converge to the same optimal policy. But at any finite — which is always the case during learning — Q-learning is more aggressive than SARSA. This is not always the right tradeoff, particularly in systems with real-world consequences for exploration failures. The choice between on-policy and off-policy estimation is one of the first genuinely practical design decisions in reinforcement learning.
The Frontier of the Tabular Era
By the mid-1990s, the tabular TD landscape was fully mapped. TD(0) converged to . SARSA converged to with an appropriately decaying . Q-learning converged to regardless of the behavior policy, provided all state-action pairs were visited infinitely often. These convergence results were clean and complete. Given enough experience, all three algorithms produced the correct answer — the same answer as the exact DP algorithms of Chapter 02, without ever requiring the transition kernel.
The remaining limitation was the same one that constrained dynamic programming: the state space must be small enough to represent explicitly. Every state-action pair needs an entry in the Q-table; every convergence proof relies on visiting every entry infinitely often. For the problems that motivated reinforcement learning — controlling physical systems, playing complex games, making decisions in language — the state space is too large to enumerate, and a lookup table cannot generalize across unseen states.
Applying Q-learning to a game of Atari with raw pixel inputs, for instance, requires a Q-value for every possible pixel configuration — a table with entries, of which any single game will visit an infinitesimal fraction. The Q-table cannot be stored; even if it could, no individual state would be visited enough times for a reliable estimate.
The solution was proposed by Mnih et al. in 2013: replace the Q-table with a neural network that takes a state as input and outputs Q-values for each action. The resulting algorithm — the Deep Q-Network — achieved superhuman performance on dozens of Atari games. But the convergence guarantees of tabular Q-learning did not carry over automatically, and new engineering innovations were required to make neural Q-learning stable. Those innovations, and the reasons they were necessary, are the subject of the next chapter.
Temporal difference learning was introduced in Sutton (1988), Learning to Predict by the Methods of Temporal Differences. Q-learning was developed by Watkins in his 1989 PhD thesis and published as Watkins and Dayan (1992), Q-learning. Rigorous convergence proofs for TD(0) using the ODE method are in Tsitsiklis (1994), Asynchronous Stochastic Approximation and Q-Learning. SARSA was described by Rummery and Niranjan (1994) and named by Sutton (1996). TD() and the forward-backward equivalence of eligibility traces are developed in Sutton and Barto (2018), chapters 6, 7, and 12. The connection between TD errors and dopaminergic prediction error signals was established by Schultz, Dayan, and Montague (1997), A Neural Substrate of Prediction and Reward.