Chapter 6
Temporal-Difference Learning
Monte Carlo waits for the end of the episode, because only then is the return known; dynamic programming does not wait for anything, but it needs a model. Temporal-difference (TD) learning takes the sampling of the first and the bootstrapping of the second: after a single transition it moves the estimate of the state it has left toward the reward just received plus the estimated value of the state it has reached.Richard S. Sutton. Learning to Predict by the Methods of Temporal Differences. Machine Learning, 3(1):9–44, 1988. doi: 10.1007/BF00115009; and Richard S. Sutton and Andrew G. Barto. Reinforcement Learning: An Introduction. Adaptive Computation and Machine Learning. MIT Press, Cambridge, MA, second edition, 2018. ISBN 978-0-262-03924-6. URL http://incompleteideas.net/book/the-book-2nd.html Sutton and Barto call it the idea that is “central and novel to reinforcement learning”, and this chapter shows why. TD learning converges to the right answer, it is faster than Monte Carlo on Markov problems for a reason that can be stated precisely (it computes the maximum-likelihood model’s values without building the model), and its control versions, Sarsa and Q-learning, are the two most widely used algorithms of the field. They also bring a new pathology, maximization bias, with a remedy whose descendants run in today’s deep reinforcement learning.
6.1TD Prediction#
Both Monte Carlo and TD methods update an estimate of from experience under . A simple every-visit Monte Carlo rule with a constant step size, constant- MC, is
usable only at the end of the episode. The simplest TD method, **TD(0)**, replaces the return by a one-step estimate of it and updates as soon as and are observed:
(6.1)Algorithm 6.1 (Tabular TD(0)). Input: the policy . Parameter: step size . Initialize: arbitrary for , except .
Loop for each episode:
- Initialize .
- Loop for each step of the episode, until is terminal:
- action given by for ; take , observe ;
- ;
- .
The two targets estimate two different expressions of the same value. By definition and by the Bellman equation ((3.9)),
Monte Carlo estimates the first expression: its target is a sample, so the expectation is replaced by one draw, but nothing else is approximated. Dynamic programming uses the second expression with the expectation computed exactly from the model, but with replaced by the current estimate. The TD target does both: it samples the expectation and bootstraps on . The TD backup diagram is correspondingly a single sampled transition, a sample update as opposed to the expected updates of dynamic programming.
The bracket in (6.1) is the TD error,
(6.2)the error in the estimate , available only at time . If is held fixed during an episode, as it is in Monte Carlo methods, the Monte Carlo error is the discounted sum of TD errors:
(6.3)Indeed, , and unrolling to telescopes. This identity, and its versions for changing (Exercise 6.10), -step returns and -returns, will tie Monte Carlo and TD together in Chapter 7 and Chapter 12.
6.1.1In Wolfram Language#
The identity (6.3) for a three-step episode , with and for the terminal state.
Sum the discounted TD errors : the intermediate values cancel and what remains is .const tdSum = await show`Module[{v = {Subscript[V, 0], Subscript[V, 1], Subscript[V, 2], 0}, r = {Subscript[R, 1], Subscript[R, 2], Subscript[R, 3]}}, Expand[Sum[\[Gamma]^k (r[[k + 1]] + \[Gamma] v[[k + 2]] - v[[k + 1]]), {k, 0, 2}]]]`6.2Why TD Learning Works#
TD(0) needs no model, unlike dynamic programming, and it learns online, from incomplete episodes and in continuing tasks, unlike Monte Carlo. But it learns a guess from a guess; does it converge to the right answer?
Take the conditional expectation of the TD error given the current state, for a fixed :
(6.4)where is the Bellman expectation operator of Chapter 4. In expectation, then, TD(0) performs a damped step of iterative policy evaluation, , at the visited state; the noise is the difference between the sampled and the expected target. That is exactly the setting of stochastic approximation: a noisy, asynchronous iteration toward the fixed point of an operator that is a -contraction in the max norm (Theorem A.3), or, in undiscounted episodic tasks, a contraction in a weighted max norm when all policies terminate.
Theorem 6.2 (Convergence of tabular TD(0)). Let the policy be fixed, the rewards have bounded variance, and every state be visited infinitely often. If the step sizes used at the visits to each state satisfy and , then with probability one. With a constant, sufficiently small , the estimates converge in the mean but keep fluctuating around .
Proof. (Sketch.) Write the update at a visit to as , where has conditional mean zero by (6.4) and conditional variance bounded by . The general theorem on asynchronous stochastic approximation of a max-norm contraction (Jaakkola, Jordan and Singh; Tsitsiklis; see Section 6.9.1 and Theorem A.7) then gives convergence to the unique fixed point . For a constant step the noise never averages out. Heuristically, averaging over the visited state, the mean of follows the deterministic iteration , with the diagonal matrix of visit probabilities, which converges for small because its iteration matrix has spectral radius below one; Sutton’s 1988 proof of convergence in the mean makes this precise. □
Sutton proved convergence in the mean in 1988 and Dayan with probability one in 1992; the theorem above is the form obtained a few years later from stochastic approximation.Richard S. Sutton. Learning to Predict by the Methods of Temporal Differences. Machine Learning, 3(1):9–44, 1988. doi: 10.1007/BF00115009; Peter Dayan. The Convergence of TD() for General . Machine Learning, 8(3–4):341–362, 1992. doi: 10.1007/BF00992701; Tommi Jaakkola, Michael I. Jordan, and Satinder P. Singh. On the Convergence of Stochastic Iterative Dynamic Programming Algorithms. Neural Computation, 6(6):1185–1201, 1994. doi: 10.1162/neco.1994.6.6.1185; and John N. Tsitsiklis. Asynchronous Stochastic Approximation and Q-Learning. Machine Learning, 16(3):185–202, 1994. doi: 10.1007/BF00993306 It says nothing about speed, and no general theorem says that TD beats Monte Carlo; but the examples and the batch analysis below explain why it usually does.
Example 6.3 (Random walk). A Markov reward process (an MDP without actions) with states in a row: every episode starts in and moves left or right with equal probability, terminating beyond either end; the reward is on termination at the right and otherwise, and . Then is the probability of leaving on the right: . Starting from and comparing root-mean-squared errors over the first 100 episodes, Sutton and Barto find TD(0) consistently better than constant- MC for all the step sizes they try.
For states the Bellman equation is the discrete Laplace equation with and for the terminal “states” on the two sides, so is linear.
Solve the boundary-value recurrence of the random walk with states: the value of the -th state is the probability of exiting on the right.const rwValues = await show`RSolve[{v[k + 1] - 2 v[k] + v[k - 1] == 0, v[0] == 0, v[n + 1] == 1}, v[k], k]`const rwEig = await show`Module[{P = {{0, 1/2, 0, 0, 0}, {1/2, 0, 1/2, 0, 0}, {0, 1/2, 0, 1/2, 0}, {0, 0, 1/2, 0, 1/2}, {0, 0, 0, 1/2, 0}}}, Simplify[Eigenvalues[IdentityMatrix[5] - P]]]`const rwFixed = await show`Module[{P = {{0, 1/2, 0, 0, 0}, {1/2, 0, 1/2, 0, 0}, {0, 1/2, 0, 1/2, 0}, {0, 0, 1/2, 0, 1/2}, {0, 0, 0, 1/2, 0}}}, LinearSolve[IdentityMatrix[5] - P, {0, 0, 0, 0, 1/2}]]`Every lies in , so the eigenvalues of the iteration matrix lie in for , and the expected iteration converges; the slowest mode, , is the smooth one, in which information about the right-hand reward must diffuse across the whole chain one bootstrapping step at a time.
6.3Batch Updating and Certainty Equivalence#
Suppose the experience is finite, say ten episodes, and it is presented over and over. In batch updating the increments (6.1) (or the Monte Carlo ones) are computed for every time step of the batch with fixed, and is changed once by their sum; this is repeated until stops changing. On the random walk, batch TD(0) is consistently better than batch Monte Carlo. Both have a precise meaning.
Let the batch contain visits to each nonterminal state , let count the transitions from to (terminal included), and define the maximum-likelihood model
The value of this model, , is the certainty-equivalence estimate: the right answer if the estimated model were exactly right.
Theorem 6.4 (What batch MC and batch TD(0) compute). With a sufficiently small constant step size, and episodic data:
- batch constant- MC converges to the sample averages of the observed returns, the minimizer of over the batch;
- batch TD(0) converges to the certainty-equivalence estimate .
Proof. (1) The summed increment at is , which vanishes exactly at the sample mean of those returns, the minimizer of the squared error; each sweep moves a fraction of the way there, so it converges when .
(2) The summed TD increment at is
so a fixed point satisfies , and in vector form the sweep is with . Every state of the data leads to termination in the empirical model, so (restricted to nonterminal states) has spectral radius below one even for , and is a nonsingular M-matrix. Multiplying it on the left by the positive diagonal keeps it a nonsingular M-matrix, whose eigenvalues have positive real parts. For small enough all eigenvalues of lie inside the unit circle, and the sweep converges to the unique solution . □
Example 6.5 (You are the predictor). Eight episodes of an unknown Markov reward process: one is (from to with reward , then termination with reward ); six are ; one is . Everyone agrees that . But ? Batch Monte Carlo answers , the only return ever observed from , with zero error on the training data. Batch TD answers : in the data always leads to , so is worth what is worth.
const predictor = await show`Module[{va = Subscript[V, A], vb = Subscript[V, B]}, {Solve[{0 + vb - va == 0, 6 (1 - vb) + 2 (0 - vb) == 0}, {va, vb}], Solve[D[(0 - va)^2 + 2 (0 - vb)^2 + 6 (1 - vb)^2, {{va, vb}}] == {0, 0}, {va, vb}]}]`If the process really is Markov, the TD answer will have lower error on future data; Monte Carlo minimizes error on the past. That is the sense in which TD is “optimal”, and it explains the batch results: certainty equivalence uses every transition to inform every state upstream of it. Online TD(0) does not reach , but it moves toward it, which is the best available explanation of its speed on Markov tasks. It is also remarkable computationally: building needs memory and solving for time, whereas TD approaches the same answer with memory.The converse matters too. When the state signal is not Markov, the certainty-equivalence model is wrong, and Monte Carlo’s minimization of error on the observed returns can be the better choice; this is one reason why Monte Carlo methods are said to be less harmed by violations of the Markov property.
6.4Sarsa: On-Policy TD Control#
For control we follow generalized policy iteration (Section 4.7) with TD prediction of action values. The sequence is a Markov chain on state–action pairs with rewards, so TD(0) applies to it verbatim:
(6.5)with . The quintuple names the algorithm, Sarsa.Gavin A. Rummery and Mahesan Niranjan. On-Line Q-Learning Using Connectionist Systems. Technical Report CUED/F-INFENG/TR 166, Cambridge University Engineering Department, 1994
Algorithm 6.6 (Sarsa (on-policy TD control)). Parameters: , . Initialize: arbitrary for , , except .
Loop for each episode:
- Initialize ; choose from with the policy derived from (e.g. -greedy).
- Loop for each step, until is terminal:
- take , observe ;
- choose from with the policy derived from ;
- ;
- , .
Sarsa evaluates the policy it follows, which keeps changing toward greediness. It converges with probability one to and an optimal policy if every pair is visited infinitely often, the step sizes satisfy the usual conditions, and the policy is greedy in the limit with infinite exploration (GLIE), for example -greedy with .Satinder Singh, Tommi Jaakkola, Michael L. Littman, and Csaba Szepesvári. Convergence Results for Single-Step On-Policy Reinforcement-Learning Algorithms. Machine Learning, 38(3):287–308, 2000. doi: 10.1023/A:1007678930559 With a fixed the best it can aim for is the best -soft policy, the target of on-policy Monte Carlo control in Theorem 5.5. Being online is a real advantage over Monte Carlo control: in the windy gridworld, where a crosswind pushes the agent upward, a policy can trap the agent forever, so an episode-by-episode method may never get to learn; Sarsa learns during the episode that the trap is bad and leaves it.
6.5Q-learning: Off-Policy TD Control#
Q-learning bootstraps on the best next action instead of the one actually taken:Christopher John Cornish Hellaby Watkins. Learning from Delayed Rewards. PhD thesis, King’s College, University of Cambridge, Cambridge, UK, May 1989. doi: 10.17863/CAM.132164. URL https://www.repository.cam.ac.uk/handle/1810/406035; and Christopher J. C. H. Watkins and Peter Dayan. Technical Note: Q-Learning. Machine Learning, 8(3–4):279–292, 1992. doi: 10.1007/BF00992698
(6.6)Algorithm 6.7 (Q-learning (off-policy TD control)). Parameters: , . Initialize: arbitrary for , , except .
Loop for each episode:
- Initialize .
- Loop for each step, until is terminal:
- choose from with a policy derived from (e.g. -greedy);
- take , observe ;
- ;
- .
Q-learning is off-policy, yet it uses no importance sampling. The reason is visible in the expected update. Conditioned on , the target’s mean is
the Bellman optimality operator of (3.18): the next action of the behavior policy does not enter at all. The behavior policy only decides which pairs get updated and how often, so all that convergence needs is that every pair keeps being updated. Under that condition and the usual step-size conditions, Q-learning converges to with probability one; Watkins and Dayan gave the first proof, and the stochastic-approximation proofs of 1994 cover it as the case of a contraction in the max norm (Section 6.9.1). If the behavior policy is greedy too, Q-learning and Sarsa nearly coincide, but not exactly (Exercise 6.12).
6.5.1On-Policy versus Off-Policy: Cliff Walking#
In a gridworld the agent goes from the bottom-left corner to the bottom-right one, with reward per step; the cells between them are a cliff, and stepping in costs and sends the agent back to the start. Both methods behave -greedily with . Q-learning learns , whose greedy policy walks along the edge of the cliff in steps, and while doing so it occasionally falls off because of the random actions. Sarsa learns the values of the -greedy policy it actually follows, prefers the -step route along the top, and earns more reward online. The difference is not that one method is wrong: they answer different questions. Q-learning asks “what is the best I could do if I stopped exploring?”; Sarsa asks “what will I get, given that I keep exploring?”
A caricature makes the trade-off computable. On the edge route, of the decisions are next to the cliff, and at each of them the exploratory action that falls (one of four) is taken with probability ; ignore all other exploratory moves. The value of the edge route under -greedy behavior satisfies a renewal equation, since a fall restarts the same route.
Solve for : the value of the edge route when each of risky steps falls with probability .const cliffU = await show`Assuming[0 < f < 1 && k > 0, FullSimplify[u /. First[Solve[u == Sum[(1 - f)^j (f (-100 + u) - (1 - f)), {j, 0, k - 1}] + (1 - f)^k (-2), u]]]]`const cliffEps = await show`\[Epsilon] /. FindRoot[(${cliffU} /. {k -> 11, f -> \[Epsilon]/4}) == -17, {\[Epsilon], 0.02}]`To first order in , for : each unit of exploration costs far more than the four steps saved. So for any above about , Sarsa’s values make the safe route look better, while Q-learning’s values never depend on (Figure 6.1). If is decreased to zero, both converge to the edge route.
Figure 6.1: Value of the edge route in the cliff-walking caricature: on-policy, under -greedy behavior (black), and as learned by Q-learning (blue, for every ). The dashed line is the safe route’s .
6.6Expected Sarsa#
Replace the sampled next action of Sarsa by its expectation under the target policy:
(6.7)Given , Expected Sarsa moves deterministically in the direction in which Sarsa moves on average, so it removes the variance due to the random choice of at the cost of a sum over actions.Harm van Seijen, Hado van Hasselt, Shimon Whiteson, and Marco Wiering. A Theoretical and Empirical Analysis of Expected Sarsa. In 2009 IEEE Symposium on Adaptive Dynamic Programming and Reinforcement Learning (ADPRL), pages 177–184, 2009. doi: 10.1109/ADPRL.2009.4927542 In cliff walking, where all randomness comes from the policy, it can use without losing asymptotic performance, whereas Sarsa needs a small . Its target policy need not be the behavior policy: with greedy, (6.7) is Q-learning, so Expected Sarsa contains both of the previous algorithms.
Conditional variances of the two targets given , with two actions of values taken with probabilities (same reward in both): Sarsa’s target varies with , Expected Sarsa’s does not.const esVar = await show`Module[{w = {x, 1 - x}, t = \[Gamma] {Subscript[q, 1], Subscript[q, 2]}}, Factor[{w . t^2 - (w . t)^2, (w . t)^2 - (w . t)^2}]]`6.7Maximization Bias and Double Learning#
Every control method so far builds its target policy with a maximum over estimated values, and the maximum of estimates is a biased estimate of the maximum. Suppose the true values of all actions in a state are zero but the estimates are noisy: their maximum is positive. This maximization bias can mislead control. In Sutton and Barto’s example, from state action right terminates with reward , and left leads with reward to a state in which many actions all terminate with a reward drawn from . Left is a mistake, but the maximum over the noisy estimates in makes look positive, and -greedy Q-learning initially chooses left far more often than the forced by exploration.
Proposition 6.8 (Maximization bias and the double estimator). Let , , be unbiased estimates of , and let be unbiased estimates independent of them. Then
(6.8)If all are equal, the second estimate is exactly unbiased.
Proof. The maximum is convex, so Jensen’s inequality gives . For the second, condition on : the selected action is then fixed and independent of , so , and , a weighted average of the true values, which is at most their maximum and equals it when they are all equal. □
The bias comes from using the same samples to select the maximizing action and to evaluate it. For two independent estimates the excess is , and it keeps growing with the number of actions (Figure 6.2).
The expected maximum of two independent estimates of two true values .const emax2 = await show`Expectation[Max[Subscript[X, 1], Subscript[X, 2]], {Subscript[X, 1] \[Distributed] NormalDistribution[0, \[Sigma]], Subscript[X, 2] \[Distributed] NormalDistribution[0, \[Sigma]]}, Assumptions -> \[Sigma] > 0]`const dbl = await show`Module[{pr = Probability[Subscript[X, 1] > Subscript[X, 2], {Subscript[X, 1] \[Distributed] NormalDistribution[Subscript[\[Mu], 1], \[Sigma]], Subscript[X, 2] \[Distributed] NormalDistribution[Subscript[\[Mu], 1] - \[CapitalDelta], \[Sigma]]}]}, Simplify[Subscript[\[Mu], 1] pr + (Subscript[\[Mu], 1] - \[CapitalDelta]) (1 - pr) - Subscript[\[Mu], 1], \[Sigma] > 0]]`const emax3 = await show`Integrate[3 x PDF[NormalDistribution[], x] CDF[NormalDistribution[], x]^2, {x, -Infinity, Infinity}]`Double learning splits the experience in two, learns two independent estimates , and uses one to choose and the other to evaluate. For Q-learning this gives Double Q-learning:Hado van Hasselt. Double Q-learning. In Advances in Neural Information Processing Systems 23 (NIPS 2010), pages 2613–2621, 2010 on each step a coin decides which estimate to update, and the update of is
(6.9)with the roles exchanged for . Memory doubles; computation per step does not.
Algorithm 6.9 (Double Q-learning). Parameters: , . Initialize: , arbitrary, with .
Loop for each episode: initialize , and for each step until is terminal,
- choose -greedily with respect to ; take , observe ;
- with probability apply (6.9) to ; otherwise apply it with and exchanged;
- .
On the example of this section Double Q-learning is essentially unaffected by maximization bias. By Proposition 6.8 its estimates can err on the low side when the true values differ, a much milder fault in control, because an underestimated action is simply tried less rather than chased. Double versions of Sarsa and Expected Sarsa are built the same way (Exercise 6.13).
6.8Afterstates#
Sometimes the immediate effect of an action is known and only what follows is uncertain. In tic-tac-toe (Chapter 1) or chess the board after our move is determined by the move; the opponent’s reply is not. Values of these afterstates (post-decision states) are more economical than action values: different position–move pairs that produce the same board share one value, so learning about one transfers immediately to the others. Queueing problems, where actions assign or reject customers, have the same structure. Nothing else changes: afterstate methods are still generalized policy iteration, and they still face the on-policy/off-policy choice.
6.9Beyond the Book: Convergence Theory and Double Estimators Today#
6.9.1Asymptotic Convergence of Q-learning and TD#
Sutton and Barto state the convergence of TD(0), Sarsa and Q-learning but prove none of them. The proofs of the early 1990s share one template.Beyond Sutton and Barto (2018). The book cites these results without proof. Watkins and Dayan (1992) proved Q-learning’s convergence by an “action replay” construction; Jaakkola, Jordan and Singh (1994) and Tsitsiklis (1994) independently proved a general theorem on asynchronous stochastic approximation of max-norm contractions, which covers Q-learning and TD() at once.Christopher J. C. H. Watkins and Peter Dayan. Technical Note: Q-Learning. Machine Learning, 8(3–4):279–292, 1992. doi: 10.1007/BF00992698; Tommi Jaakkola, Michael I. Jordan, and Satinder P. Singh. On the Convergence of Stochastic Iterative Dynamic Programming Algorithms. Neural Computation, 6(6):1185–1201, 1994. doi: 10.1162/neco.1994.6.6.1185; and John N. Tsitsiklis. Asynchronous Stochastic Approximation and Q-Learning. Machine Learning, 16(3):185–202, 1994. doi: 10.1007/BF00993306 Write any of the updates, at the pair (or state) visited at time , as
(6.10)with for the components not updated. If (a) is a contraction in a weighted max norm with fixed point , (b) the noise has and , and (c) and for every with probability one, then with probability one. For Q-learning, , is a -contraction in the max norm, and ; condition (c) contains the requirement that every pair be visited infinitely often. The key step is to compare with a deterministic sequence of shrinking boxes around : the contraction pulls the iterates into the next box, and the weighted average of the noise, a martingale with summable variance, eventually stays smaller than the gap.
6.9.2Finite-Time Analysis of TD Learning#
Asymptotic convergence says nothing about how many samples are needed. Since 2018 finite-time bounds have been proved by treating TD with linear features (the tabular case is the one-hot special case) as a linear stochastic approximation whose mean matrix is negative definite in the sense of Chapter 9, so that the associated ODE has the TD fixed point (9.5) as a globally stable equilibrium.Beyond Sutton and Barto (2018). Bhandari, Russo and Singal (COLT 2018; Operations Research 2021) gave a short finite-time analysis that mirrors stochastic gradient descent; Srikant and Ying (COLT 2019) removed the projection step and the i.i.d. assumption for constant step sizes with a Lyapunov drift argument. The ODE method itself goes back to Borkar and Meyn (2000).Jalaj Bhandari, Daniel Russo, and Raghav Singal. A Finite Time Analysis of Temporal Difference Learning with Linear Function Approximation. Operations Research, 69(3):950–973, 2021. doi: 10.1287/opre.2020.2024. Extended abstract in Proceedings of the 31st Conference on Learning Theory (COLT 2018), PMLR 75; arXiv:1806.02450; R. Srikant and Lei Ying. Finite-Time Error Bounds for Linear Stochastic Approximation and TD Learning. In Proceedings of the Thirty-Second Conference on Learning Theory, volume 99 of Proceedings of Machine Learning Research, pages 2803–2830. PMLR, 2019; and Vivek S. Borkar and Sean P. Meyn. The O.D.E. Method for Convergence of Stochastic Approximation and Reinforcement Learning. SIAM Journal on Control and Optimization, 38(2):447–469, SIAM, 2000. doi: 10.1137/S0363012997331639 Bhandari, Russo and Singal show that with i.i.d. transitions, step size and averaged iterate ,
where weights states by the stationary distribution and is the variance of the update at the fixed point; for Markovian data a projected variant obtains the same rate with an extra factor of the mixing time, and decaying step sizes improve the rate to roughly . Srikant and Ying prove that with a constant step and Markovian data, the mean squared error decays geometrically, at rate , down to a floor of order . The lesson for the tabular algorithms of this chapter is quantitative: the in the denominator is the price of bootstrapping, the slow mode of the random walk in Section 6.2 made concrete.
6.9.3Heirs of Double Q-learning#
Maximization bias became a practical problem with deep Q-networks (Section 15.5), where function-approximation error plays the role of the noise in Proposition 6.8.Beyond Sutton and Barto (2018). Double DQN (van Hasselt, Guez and Silver, AAAI 2016) and the clipped double Q-learning of TD3 (Fujimoto, van Hoof and Meger, ICML 2018) are the two most influential descendants of Double Q-learning; the overestimation analysis goes back to Thrun and Schwartz (1993).Hado van Hasselt, Arthur Guez, and David Silver. Deep Reinforcement Learning with Double Q-Learning. In Proceedings of the Thirtieth AAAI Conference on Artificial Intelligence, volume 30, pages 2094–2100. AAAI Press, 2016. doi: 10.1609/aaai.v30i1.10295; Scott Fujimoto, Herke van Hoof, and David Meger. Addressing Function Approximation Error in Actor-Critic Methods. In Jennifer Dy and Andreas Krause, editors, Proceedings of the 35th International Conference on Machine Learning, volume 80 of Proceedings of Machine Learning Research, pages 1587–1596, Stockholm, Sweden, 2018. PMLR; and Sebastian Thrun and Anton Schwartz. Issues in Using Function Approximation for Reinforcement Learning. In Michael C. Mozer, Paul Smolensky, David S. Touretzky, Jeffrey L. Elman, and Andreas S. Weigend, editors, Proceedings of the 1993 Connectionist Models Summer School, pages 255–263, Hillsdale, NJ, 1993. Lawrence Erlbaum Van Hasselt, Guez and Silver prove that if the true values of actions are all and the estimates are unbiased on average, , but not all correct, , then , whatever the source of the errors, and the bound is tight. Their Double DQN keeps the online network for selection and lets the slowly updated target network evaluate:
In continuous control, where an actor maximizes the critic, the overestimation is worse and the two estimates are not independent enough. TD3 trains two critics and takes the minimum of their target networks at a smoothed target action,
deliberately trading overestimation for underestimation, which, as noted after Proposition 6.8, is the safer error because it is not propagated by the policy update. Actor–critic methods themselves are the subject of Chapter 13, and TD3 as a whole is described in Section 13.8.4.
Back in the tabular setting, the one-step methods of this chapter and the Monte Carlo methods of Chapter 5 are two ends of a spectrum. Chapter 7 fills the space between them by bootstrapping after steps instead of one.
6.10Exercises#
Exercise 6.10. (Sutton and Barto, Exercise 6.1.) Let be the value array used at time in the TD error and in the update (6.1). Find the correction that must be added to to obtain exactly.
Solution
Add and subtract :
and unroll:
with at the terminal state. TD(0) changes only at time , so the correction term equals if and otherwise: the identity is exact unless the episode revisits a state on consecutive steps, and otherwise off by terms of order .
A three-step check, with standing for : the difference between and the two sums vanishes identically.const exChanging = await show`Module[{v = Function[{k, j}, If[j == 3, 0, Subscript[V, k, j]]], r = {Subscript[R, 1], Subscript[R, 2], Subscript[R, 3]}}, Simplify[(r[[1]] + \[Gamma] r[[2]] + \[Gamma]^2 r[[3]] - v[0, 0]) - Sum[\[Gamma]^k (r[[k + 1]] + \[Gamma] v[k, k + 1] - v[k, k]), {k, 0, 2}] - Sum[\[Gamma]^(k + 1) (v[k + 1, k + 1] - v[k, k + 1]), {k, 0, 2}]]]`Exercise 6.11. (Sutton and Barto, Exercise 6.3.) In the random walk of Example 6.3, with initially and , only changes during the first episode. What happened in that episode, and by how much did change?
Solution
Every transition between nonterminal states has reward and, as long as both values are still , TD error : nothing changes. The only nonzero TD errors occur on termination. Termination on the right would have changed , so the episode ended on the left, from , with . Hence decreased by , to . (If the walk visited before, those transitions also had zero error.)
Exercise 6.12. (Sutton and Barto, Exercise 6.12.) Suppose action selection is greedy. Is Q-learning then exactly the same algorithm as Sarsa? Do they make the same action selections and the same updates?
Solution
Almost, but not exactly. With greedy selection Sarsa’s is , so its target coincides with Q-learning’s, evaluated with before the update. But Sarsa chooses before updating and then executes that , while Q-learning chooses its next action after the update. When the update can change which action is greedy in : Q-learning then acts on the new values, Sarsa on the old choice, and from then on the trajectories, and hence the updates, can differ. (Ties broken at random are a second source of divergence.)
Exercise 6.13. (Sutton and Barto, Exercise 6.13.) Write the update equations of Double Expected Sarsa with an -greedy target policy.
Solution
Keep two estimates. With probability update , using to define the target policy and to evaluate it:
where ; otherwise apply the same update with and exchanged. Behavior can be -greedy in . The selection, the only place where a maximum enters, uses one estimate and the evaluation the other, which is what removes the maximization bias of Proposition 6.8; for this is Double Q-learning.