Q($λ$) with Off-Policy Corrections
Anna Harutyunyan, Marc G. Bellemare, Tom Stepleton, Remi Munos
Introduction
In reinforcement learning (RL), learning is off-policy when samples generated by a behavior policy are used to learn about a distinct target policy. The usual approach to off-policy learning is to disregard, or altogether discard transitions whose target policy probabilities are low. For example, Watkins’s Q() cuts the trajectory backup as soon as a non-greedy action is encountered. Similarly, in policy evaluation, importance sampling methods weight the returns according to the mismatch in the target and behavior probabilities of the corresponding actions. This approach treats transitions conservatively, and hence may unnecessarily terminate backups, or introduce a large amount of variance.
Many off-policy methods, in particular of the Monte Carlo kind, have no other option than to judge off-policy actions in the probability sense. However, temporal difference methods in RL maintain an approximation of the value function along the way, with eligiblity traces providing a continuous link between one-step and Monte Carlo approaches. The value function assesses actions in terms of the following expected cumulative reward, and thus provides a way to directly correct immediate rewards, rather than transitions. We show in this paper that such approximate corrections can be sufficient for off-policy convergence, subject to a tradeoff condition between the eligibility trace parameter and the distance between the target and behavior policies. The two extremes of this tradeoff are one-step Q-learning, and on-policy learning. Formalizing the continuum of the tradeoff is one of the main insights of this paper.
In particular, we propose an off-policy return operator that augments the return with a correction term, based on the current approximation of the Q-function. We then formalize three algorithms stemming from this operator: (1) off-policy Qπ(), and its special case (2) on-policy Qπ(), for policy evaluation, and (3) Q∗() for off-policy control.
In policy evaluation, both on- and off-policy Qπ() are novel, but closely related to several existing algorithms of the TD() family. Section 7 discusses this in detail. We prove convergence of Qπ(), subject to the tradeoff where is a measure of dissimilarity between the behavior and target policies. More precisely, we prove that for any amount of “off-policy-ness” there is an inherent maximum allowed backup length value , and taking below this value guarantees convergence to without involving policy probabilities. This is desirable due to the instabilities and variance introduced by the likelihood ratio products in the importance sampling approach .
In control, Q∗() is in fact identical to Watkins’s Q(), except it does not cut the eligiblity trace at off-policy actions. Sutton and Barto 1998 mention such a variation, which they call naive Q(). We analyze this algorithm for the first time and prove its convergence for small values of . Although we were not able to prove a tradeoff similar to the policy evaluation case, we provide empirical evidence for the existence of such a tradeoff, confirming the intuition that naive Q() is “not as naive as one might at first suppose” .
We first give the technical background, and define our operators. We then specify the incremental versions of our algorithms based on these operators, and state their convergence. We follow by proving convergence: subject to the tradeoff in policy evaluation, and more conservatively, for small values of in control. We illustrate the tradeoff emerge empirically in the Bicycle domain in the control setting. Finally, we conclude by placing our algorithms in context within existing work in TD().
Preliminaries
To each policy corresponds a unique Q-function which describes the expected discounted sum of rewards achieved when following :
where for any operator , denotes successive applications of , and where we commonly treat as one particular Q-function. We write the Bellman operator , and the Bellman equation for :
The Bellman optimality operator is defined as and it is well known [1, 10, e.g.] that the optimal Q-function is the unique solution to the Bellman optimality equation
We write to denote the set of greedy policies w.r.t. . Thus for any .
Temporal difference (TD) learning rests on the fact that iterates of both operators and are guaranteed to converge to their respective fixed points and . Given a sample experience , SARSA(0) updates its Q-function estimate at iteration as follows:
Naturally, remains the fixed point of . Taking yields the usual Bellman operator , and removes the recursion on the approximate Q-function, and restores in the Monte Carlo sense. It is well-known that trades off the bias from bootstrapping with an approximate Q-function, with the variance from using a sampled multi-step return , with intermediate values of usually performing best in practice . The above -operator can be efficiently implemented in the online setting via a mechanism called eligibility traces. As we will see in Section 7, it in fact corresponds to a number of online algorithms, each subtly different, of which SARSA() is the canonical instance.
Off-Policy Return Operators
We will now describe the Monte Carlo off-policy corrected return operator that is at the heart of our contribution. Given a target , and a return generated by the behavior , the operator attempts to approximate a return that would have been generated by , by utilizing a correction built from a current approximation of . Its application to at a state-action pair is defined as follows:
That is, gives the usual expected discounted sum of future rewards, but each reward in the trajectory is augmented with an off-policy correction, which we define as the difference between the expected (with respect to the target policy) Q-value and the Q-value for the taken action. Thus, how much a reward is corrected is determined by both the approximation , and the target policy probabilities. Notice that if actions are similarly valued, the correction will have little effect, and learning will be roughly on-policy, but if the Q-function has converged to the correct estimates , the correction takes the immediate reward to the expected reward with respect to exactly. Indeed, as we will see later, is the fixed point of for any behavior policy .
We define the -step and -versions of in the usual way:
Note that the parameter here takes us from TD() to the Monte Carlo version of our operator , rather than the traditional Monte Carlo form (1).
Algorithm
where is the interim target policy. We distinguish between three algorithms:
is the fixed target policy. We write the corresponding operator .
for the special case of .
We wish to write the update (6) in terms of a simulated trajectory drawn according to . First, notice that (5) can be rewritten:
where is the expected TD-error. The offline forward view The true online version can be derived as given by van Seijen and Sutton 2014 is then
While (7) resembles many existing TD() algorithms, it subtly differs from all of them, due to (rather than ) being at its basis. Section 7 discusses the distinctions in detail. The practical every-visit form of (7) is written
and the corresponding online backward view of all three algorithms is summarized in Algorithm 1.
The following theorem states that when and are sufficiently close, the off-policy Qπ() algorithm converges to its fixed point .
Consider the sequence of Q-functions computed according to Algorithm 1 with fixed policies and . Let . If , then under the same conditions required for the convergence of (1–3 in Section 5.3) we have, almost surely:
We state a similar, albeit weaker result for Q∗().
Consider the sequence of Q-functions computed according to Algorithm 1 with the greedy policy with respect to . If , then under the same conditions required for the convergence of TD() (1–3 in Section 5.3) we have, almost surely:
The proofs of these theorems rely on showing that and are contractions (under the stated conditions), and invoking classical stochastic approximation convergence to their fixed point (such as Proposition 4.5 from ). We will focus on the contraction lemmas, which are the crux of the proofs, then outline the sketch of the online convergence argument.
Theorem 4.1 states that for any there exists some degree of “off-policy-ness” under which converges to . This is the tradeoff for the off-policy learning algorithm for policy evaluation. In the control case, the result of Theorem 4.2 is weaker as it only holds for values of smaller than . Notice that this threshold corresponds to the policy evaluation case for (arbitrary off-policy-ness). We were not able to prove convergence to for any and some . This is left as an open problem for now.
The main technical difficulty lies in the fact that in control, the greedy policy with respect to the current may change drastically from one step to the next, while itself changes incrementally (under small learning steps ). So the current may not offer a good off-policy correction to evaluate the new greedy policy. In order to circumvent this problem we may want to use slowly changing target policies . For example we could keep fixed for slowly increasing periods of time. This can be seen as a form of optimistic policy iteration where policy improvement steps alternate with approximate policy evaluation steps (and when the policy is fixed, Theorem 4.1 guarantees convergence to the value function of that policy). Another option would be to define as the empirical average of the previous greedy policies . We conjecture that defining such that (1) changes slowly with , and (2) becomes increasingly greedy, then we could extend the tradeoff of Theorem 4.1 to the control case. This is left for future work.
Analysis
We begin by verifying that the fixed points of in the policy evaluation and control settings are and , respectively. We then prove the contractive properties of these operators: is always a contraction and will converge to its fixed point, is a contraction for particular choices of (given in terms of ). The contraction coefficients depend on , , and : the distance between policies. Finally, we give a proof sketch for online convergence of Algorithm 1.
Before we begin, it will be convenient to rewrite (4) for all state-action pairs:
We can then write and from (5) as follows:
It is not surprising that the above along with the Bellman equations (2) and (3) directly yields that and are the fixed points of and :
It then remains to analyze the behavior of as it gets iterated.
Consider the policy evaluation algorithm . Assume the behavior policy is -away from the target policy , in the sense that . Then for , the sequence converges to exponentially fast: , where .
Let be the resolvent matrix. From (9) we have
Taking the sup norm, since is -away from :
for . Thus .
2 λ\lambda-return for control: Q∗(λ\lambda)
We next consider the case where the target policy is greedy with respect to the value estimate . The following Lemma states that is possible to select a small, but nonzero and still guarantee convergence.
Consider the off-policy control algorithm . Then
and for the sequence converges to exponentially fast.
Fix and let . Using (10), we write
Taking the sup-norm, since , we deduce the result:
3 Online Convergence
We are now ready to prove the online convergence of Algorithm 1. Let the following hold for every sample trajectory and all :
Bounded stepsizes: , .
Assumption 2 requires trajectories to be finite w.p. 1, which is satisfied by proper behavior policies. Equivalently, we may require from the MDP that all trajectories eventually reach a zero-value absorbing state. The proof closely follows that of Proposition 5.2 from , and requires rewriting the update in the suitable form, and verifying Assumptions (a) through (d) from their Proposition 4.5.
Experimental Results
Although we do not have a proof of the tradeoff (see Section 4) in the control case, we wished to investigate whether such a tradeoff can be observed experimentally. To this end, we applied Q∗() to the Bicycle domain . Here, the agent must simultaneously balance a bicycle and drive it to a goal position. Six real-valued variables describe the state – angle, velocity, etc. – of the bicycle. The reward function is proportional to the angle to the goal, and gives -1 for falling and +1 for reaching the goal. The discount factor is 0.99. The Q-function was approximated using multilinear interpolation over a uniform grid of size , and the stepsize was tuned to 0.1. We are chiefly interested in the interplay between the parameter in Q∗() and an -greedy exploration policy. Our main performance indicator is the frequency at which the goal is reached by the greedy policy after 500,000 episodes of training. We report three findings:
Higher values of lead to improved learning;
Very low values of exhibit lower performance; and
The Q-function diverges when is high relative to .
Together, these findings suggest that there is indeed a tradeoff in the control case as well, and lead us to conclude that with proper care it can be beneficial to do off-policy control with Q∗().
Learning speed and performance. Figure 1 (left) depicts the performance of Q∗(), in terms of the goal-reaching frequency, for three values of . The agent performs best () for and high (w.r.t. ) values of . Recall that Randløv and Alstrøm’s agent was trained using SARSA( with .
Divergence. For each value of , we determined the highest safe choice of which did not result in divergence. As Figure 1 (right) illustrates, there is a marked decrease in what is a safe value of as increases. Note the left-hand shaded region corresponding to the policy evaluation bound . Supporting our hypothesis on the true bound on (Section 5), it appears clear that the maximum safe value of depends on . In particular, notice how stops diverging exactly where predicted by this bound.
Related Work
In this section, we place the presented algorithms in context of the existing work in TD() , focusing in particular on action-value methods. As usual, let be a trajectory generated by following a behavior policy , i.e. . At time , SARSA() updates its -function as follows:
where denotes the update made at time , and can be rewritten in terms of one-step TD-errors:
SARSA() is an on-policy algorithm and converges to the value function of the behavior policy. Different algorithms arise by instantiating or from (11) differently. Table 1 provides the full details, while in text we will specify the most revealing components of the update.
This is the one-step update for General Q-Learning , which is a generalization of Expected SARSA to arbitrary policies. We refer to the direct eligibility trace extensions of these algorithms formed via Equations (11)-(13) by General Q() and Expected SARSA() (first mentioned by Sutton et al. 2014) Unfortunately, in an off-policy setting, General Q() will not converge to the value function of the target policy, as stated by the following proposition.
The stable point of General Q() is which is the fixed point of the operator .
Writing the algorithm in operator form, we get
Thus the fixed point of satisfies the following:
Solving for yields the result.
This is exactly our policy evaluation algorithm Qπ(). Specifically, when , we get the on-policy Qπ(). The induced on-policy correction may serve as a variance reduction term for Expected SARSA() (it may be helpful to refer to the -step return in Table 1 to observe this), but we leave variance analysis of this algorithm for future work. When , we recover off-policy Qπ(), which (under the stated conditions) converges to .
The algorithms above directly descend from basic SARSA(), but often learning off-policy requires special treatment. For example, a typical off-policy technique is importance sampling (IS) . It is a classical Monte Carlo method that allows one to sample from the available distribution, but obtain (unbiased or consistent) samples of the desired one, by reweighing the samples with their likelihood ratio according to the two distributions. That is, the updates for the ordinary per-decision IS algorithm for policy evaluation are made as follows:
This family of algorithms converges to with probability , under any soft, stationary behavior . There are several (recent) off-policy algorithms that reduce the variance of IS methods, at the cost of added bias .
However, off-policy Qπ() is perhaps related closest to the Tree-Backup (TB) algorithm, also discussed by Precup et al. 2000. Its one-step TD-error is the same as (15), the algorithms back up the same tree, and neither requires knowledge of the behavior policy . The important difference is in the weighting of the updates. As an off-policy precaution, TB() weighs updates along a trajectory with the cumulative target probability of that trajectory up until that point:
The weighting simplifies the convergence argument, allowing TB() to converge to without further restrictions on the distance between and . The drawback of TB() is that in the case of near on-policy-ness (when is close to ) the product of the probabilities cuts the traces unnecessarily (especially when the policies are stochastic). What we show in this paper, is that plain TD-learning can converge off-policy with no special treatment, subject to a tradeoff condition on and . Under that condition, Qπ() applies both on- and off-policy, without modifications. An ideal algorithm should be able to automatically cut the traces (like TB()) in case of extreme off-policy-ness while reverting to Qπ() when being near on-policy.
2 Control
Perhaps the most popular version of Q() is due to Watkins and Dayan 1992. Off-policy, it truncates the return and bootstraps as soon as the behavior policy takes a non-greedy action, as described by the following update:
Q() of Peng and Williams 1996 is meant to remedy this, by being a hybrid between SARSA() and Watkins’s Q(). Its -step return requires the following form for the TD-error:
This is, in fact, the same update rule as the General Q() defined in (14), where is the greedy policy. Following the same steps as in the proof of Proposition 1, the limit of this algorithm (if it converges) will be the fixed point of the operator which is different from unless the behavior is always greedy.
Sutton and Barto 1998 mention another, naive version of Watkins’s Q() that does not cut the trace on non-greedy actions. That is exactly the Q∗() algorithm described in this paper. Notice that despite the similarity to Watkins’s Q(), the equivalence representation for Q∗() is different from the one that would be derived by setting in (17), since the -step return uses the corrected immediate reward instead of the immediate reward alone. This correction is invisible in Watkins’s Q(), since the behavior policy is assumed to be greedy, before the return is cut off.
Conclusion
We formulated new algorithms of the TD family for off-policy policy evaluation and control. Unlike traditional off-policy learning algorithms, these methods do not involve weighting returns by their policy probabilities, yet under the right conditions converge to the correct TD fixed points. In policy evaluation, convergence is subject to a tradeoff between the degree of bootstrapping , distance between policies , and the discount factor . In control, determining the existence of a non-trivial -dependent bound for remains an open problem. Supported by telling empirical results in the Bicycle domain, we hypothesize that such a bound exists, and closely resembles the bound from the policy evaluation case.
Acknowledgements
The authors thank Hado van Hasselt and others at Google DeepMind, as well as the anonymous reviewers for their thoughtful feedback on the paper.