Safe and Efficient Off-Policy Reinforcement Learning
Rémi Munos, Tom Stepleton, Anna Harutyunyan, Marc G. Bellemare
Notation
The value function for a policy , , describes the expected discounted sum of rewards associated with following from a given state-action pair. Using operator notation, we write this as
The Bellman operator for a policy is defined as and its fixed point is , i.e. . The Bellman optimality operator introduces a maximization over the set of policies:
Its fixed point is , the unique optimal value function (Puterman,, 1994). It is this quantity that we will seek to obtain when we talk about the “control setting”.
The -return extension (Sutton,, 1988) of the Bellman operators considers exponentially weighted sums of -steps returns:
where is the Bellman residual of for policy . Examination of the above shows that is also the fixed point of . At one extreme () we have the Bellman operator , while at the other () we have the policy evaluation operator which can be estimated using Monte Carlo methods (Sutton and Barto,, 1998). Intermediate values of trade off estimation bias with sample variance (Kearns and Singh,, 2000).
We seek to evaluate a target policy using trajectories drawn from a behaviour policy . If , we are on-policy; otherwise, we are off-policy. We will consider trajectories of the form:
Off-Policy Algorithms
We are interested in two related off-policy learning problems. In the policy evaluation setting, we are given a fixed policy whose value we wish to estimate from sample trajectories drawn from a behaviour policy . In the control setting, we consider a sequence of policies that depend on our own sequence of Q-functions (such as -greedy policies), and seek to approximate .
The general operator that we consider for comparing several return-based off-policy algorithms is:
Importance sampling is the simplest way to correct for the discrepancy between and when learning from off-policy returns (Precup et al.,, 2000, 2001; Geist and Scherrer,, 2014). The off-policy correction uses the product of the likelihood ratios between and . Notice that defined in (3) with this choice of yields for any . For we recover the basic IS estimate \sum_{t\geq 0}\gamma^{t}\big{(}\prod_{s=1}^{t}c_{s}\big{)}r_{t}, thus (3) can be seen as a variance reduction technique (with a baseline ). It is well known that IS estimates can suffer from large – even possibly infinite – variance (mainly due to the variance of the product ), which has motivated further variance reduction techniques such as in (Mahmood and Sutton,, 2015; Mahmood et al.,, 2015; Hallak et al.,, 2015).
A recent alternative proposed by Harutyunyan et al., (2016) introduces an off-policy correction based on a -baseline (instead of correcting the probability of the sample path like in IS). This approach, called Qπ() and Q∗() for policy evaluation and control, respectively, corresponds to the choice . It offers the advantage of avoiding the blow-up of the variance of the product of ratios encountered with IS. Interestingly, this operator contracts around provided that and are sufficiently close to each other. Defining the level of “off-policyness”, the authors prove that the operator defined by (3) with is a contraction mapping around for , and around for the worst case of . Unfortunately, Qπ() requires knowledge of , and the condition for Q∗() is very conservative. Neither Qπ(), nor Q∗() are safe as they do not guarantee convergence for arbitrary and .
The TB() algorithm of Precup et al., (2000) corrects for the target/behaviour discrepancy by multiplying each term of the sum by the product of target policy probabilities. The corresponding operator defines a contraction mapping for any policies and , which makes it a safe algorithm. However, this algorithm is not efficient in the near on-policy case (where and are similar) as it unnecessarily cuts the traces, preventing it to make use of full returns: indeed we need not discount stochastic on-policy transitions (as shown by Harutyunyan et al.,’s results about Qπ).
Our contribution is an algorithm – Retrace – that takes the best of the three previous algorithms. Retrace uses an importance sampling ratio truncated at . Compared to IS, it does not suffer from the variance explosion of the product of IS ratios. Now, similarly to and unlike TB(), it does not cut the traces in the on-policy case, making it possible to benefit from the full returns. In the off-policy case, the traces are safely cut, similarly to TB(). In particular, \min\big{(}1,\frac{\pi(a_{s}|x_{s})}{\mu(a_{s}|x_{s})}\big{)}\geq\pi(a_{s}|x_{s}): Retrace() does not cut the traces as much as TB(). In the subsequent sections, we will show the following:
For any traces (thus including the Retrace() operator), the return-based operator (3) is a -contraction around , for arbitrary policies and
In the control case (where is replaced by a sequence of increasingly greedy policies) the online Retrace() algorithm converges a.s. to , without requiring the GLIE assumption.
As a corollary, Watkins’s Q converges a.s. to .
Analysis of Retrace(λ𝜆\lambda)
We will in turn analyze both off-policy policy evaluation and control settings. We will show that is a contraction mapping in both settings (under a mild additional assumption for the control case).
Our first result states the -contraction of the operator (3) defined by any set of non-negative coefficients (in order to emphasize that can be a function of the whole history ) under the assumption that .
The operator defined by (3) has a unique fixed point . Furthermore, if for each and each history we have c_{s}=c_{s}(a_{s},\mathcal{F}_{s})\in\big{[}0,\frac{\pi(a_{s}|x_{s})}{\mu(a_{s}|x_{s})}\big{]}, then for any Q-function
The following lemma will be useful in proving Theorem 1 (proof in the appendix).
The difference between and its fixed point is
Now since , we have that , i.e. a linear combination of weighted by non-negative coefficients:
Thus is a -specific contraction coefficient, which is when (the trace is cut immediately) and can be close to zero when learning from full returns ( for all ).
2 Control
In the control setting, the single target policy is replaced by a sequence of policies which depend on . While most prior work has focused on strictly greedy policies, here we consider the larger class of increasingly greedy sequences. We now make this notion precise.
Intuitively, this means that each is at least as greedy as the previous policy for . Many natural sequences of policies are increasingly greedy, including -greedy policies (with non-increasing ) and softmax policies (with non-increasing temperature). See proofs in the appendix.
We will assume that is Markovian, in the sense that it depends on (as well as the policies and ) only but not on the full past history. This allows us to define the (sub)-probability transition operator
Finally, an additional requirement to the convergence in the control case, we assume that satisfies (this can be achieved by a pessimistic initialization ).
Consider an arbitrary sequence of behaviour policies (which may depend on ) and a sequence of target policies that are increasingly greedy w.r.t. the sequence :
where the return operator is defined by (3) for and and a Markovian . Assume the target policies are -away from the greedy policies w.r.t. , in the sense that , where is the vector with 1-components. Further suppose that . Then for any ,
In consequence, if then .
Using , the Retrace operator rewrites
We now lower- and upper-bound the term .
Upper bound on . We prove that with A_{k}:=\gamma(I-\gamma P^{c\mu_{k}})^{-1}\big{[}P^{\pi_{k}}-P^{c\mu_{k}}\big{]}. Since we deduce that has non-negative elements, whose sum over each row, is at most . Thus
Lower bound on . Using the fact that we have
Lower bound on . Since the sequence is increasingly greedy w.r.t. , we have
where . Since and are non-negative matrices, so is . Thus since we assumed . Thus, (5) implies that
Combining the above with (4) we deduce . When , we further deduce that are bounded, thus . ∎
3 Online algorithms
So far we have analyzed the contraction properties of the expected operators. We now describe online algorithms which can learn from sample trajectories. We analyze the algorithms in the every visit form (Sutton and Barto,, 1998), which is the more practical generalization of the first-visit form. In this section, we will only consider the Retrace() algorithm defined with the coefficient . For that , let us rewrite the operator as , where , and write the Retrace operator . We focus on the control case, noting that a similar (and simpler) result can be derived for policy evaluation.
Consider a sequence of sample trajectories, with the trajectory generated by following : . For each along this trajectory, with being the time of first occurrence of , update
The proof extends similar convergence proofs of TD() by Bertsekas and Tsitsiklis, (1996) and of optimistic policy iteration by Tsitsiklis, (2003), and is provided in the appendix. Notice that compared to Theorem 2 we do not assume that here. However, we make the additional (rather technical) assumption that and commute at the limit. This is satisfied for example when the probability assigned by the behavior policy to the greedy action is independent of . Examples include -greedy policies, or more generally mixtures between the greedy policy and an arbitrary distribution (see Lemma 5 in the appendix for the proof):
Notice that the mixture coefficient needs not go to .
Discussion of the results
Theorems 1 and 2 ensure convergence to and for any trace coefficient . However, to make the best choice of , we need to consider the speed of convergence, which depends on both (1) the variance of the online estimate, which indicates how many online updates are required in a single iteration of , and (2) the contraction coefficient of .
Contraction speed: The contraction coefficient of (see Remark 1) depends on how much the traces have been cut, and should be as small as possible (since it takes iterations of to obtain an -approximation). It is smallest when the traces are not cut at all (i.e. if for all , is the policy evaluation operator which produces in a single iteration). Indeed, when the traces are cut, we do not benefit from learning from full returns (in the extreme, and reduces to the (one step) Bellman operator with ).
A reasonable trade-off between low variance (when are small) and high contraction speed (when are large) is given by Retrace(), for which we provide the convergence of the online algorithm.
If we relax the assumption that the trace is Markovian (in which case only the result for policy evaluation has been proven so far) we could trade off a low trace at some time for a possibly larger-than- trace at another time, as long as their product is less than . A possible choice could be
2 Other topics of discussion
The crucial point of Theorem 2 is that convergence to occurs for arbitrary behaviour policies. Thus the online result in Theorem 3 does not require the behaviour policies to become greedy in the limit with infinite exploration (i.e. GLIE assumption, Singh et al.,, 2000). We believe Theorem 3 provides the first convergence result to for a -return (with ) algorithm that does not require this (hard to satisfy) assumption.
Proof of Watkins’ Q(λ𝜆\lambda).
As a corollary of Theorem 3 when selecting our target policies to be greedy w.r.t. (i.e. ), we deduce that Watkins’ Q() ( e.g., Watkins,, 1989; Sutton and Barto,, 1998) converges a.s. to (under the assumption that commutes asymptotically with the greedy policies, which is satisfied for e.g. defined by (8)). We believe this is the first such proof.
Increasingly greedy policies
The assumption that the sequence of target policies is increasingly greedy w.r.t. the sequence of is more general that just considering greedy policies w.r.t. (which is Watkins’s Q()), and leads to more efficient algorithms. Indeed, using non-greedy target policies may speed up convergence as the traces are not cut as frequently. Of course, in order to converge to , we eventually need the target policies (and not the behaviour policies, as mentioned above) to become greedy in the limit (i.e. as defined in Theorem 2).
Unlike Retrace(), does not need to know the behaviour policy . However, it fails to converge when is far from . Retrace() uses its knowledge of (for the chosen actions) to cut the traces and safely handle arbitrary policies and .
Comparison to TB(λ𝜆\lambda).
Similarly to , TB() does not need the knowledge of the behaviour policy . But as a consequence, TB() is not able to benefit from possible near on-policy situations, cutting traces unnecessarily when and are close.
Estimating the behavior policy.
In the case is unknown, it is reasonable to build an estimate from observed samples and use instead of in the definition of the trace coefficients . This may actually even lead to a better estimate, as analyzed by LiAistats2015.
Continuous action space.
Let us mention that Theorems 1 and 2 extend to the case of (measurable) continuous or infinite action spaces. The trace coefficients will make use of the densities instead of the probabilities . This is not possible with TB().
Open questions include:
(1) Removing the technical assumption that and asymptotically commute, (2) Relaxing the Markov assumption in the control case in order to allow trace coefficients of the form (9).
Experimental Results
To validate our theoretical results, we employ Retrace in an experience replay (Lin,, 1993) setting, where sample transitions are stored within a large but bounded replay memory and subsequently replayed as if they were new experience. Naturally, older data in the memory is usually drawn from a policy which differs from the current policy, offering an excellent point of comparison for the algorithms presented in Section 2.
Our agent adapts the DQN architecture of Mnih et al., (2015) to replay short sequences from the memory (details in the appendix) instead of single transitions. The Q-function target update for a sample sequence is
We compare our algorithms’ performance on 60 different Atari 2600 games in the Arcade Learning Environment (Bellemare et al.,, 2013) using Bellemare et al.,’s inter-algorithm score distribution. Inter-algorithm scores are normalized so that 0 and 1 respectively correspond to the worst and best score for a particular game, within the set of algorithms under comparison. If is a game and the inter-algorithm score on for algorithm , then the score distribution function is . Roughly, a strictly higher curve corresponds to a better algorithm.
Across values of , performs best, save for where obtains slightly superior performance. However, is highly sensitive to the choice of (see Figure 1, left, and Table 2 in the appendix). Both Retrace() and TB achieve dramatically higher performance than Q-Learning early on and maintain their advantage throughout. Compared to TB(), Retrace() offers a narrower but still marked advantage, being the best performer on 30 games; TB() claims 15 of the remainder. Per-game details are given in the appendix.
Retrace() can be seen as an algorithm that automatically adjusts – efficiently and safely – the length of the return to the degree of ”off-policyness” of any available data.
Acknowledgments.
The authors thank Daan Wierstra, Nicolas Heess, Hado van Hasselt, Ziyu Wang, David Silver, Audrunas Grūslys, Georg Ostrovski, Hubert Soyer, and others at Google DeepMind for their very useful feedback on this work.
References
Appendix A Proof of Lemma 1
Let . We begin by rewriting (3):
Since is the fixed point of , we have
Appendix B Increasingly greedy policies
Recall the definition of an increasingly greedy sequence of policies.
We say that a sequence of policies is increasingly greedy w.r.t. a sequence of functions if the following property holds for all :
It is obvious to see that this property holds if all policies are greedy w.r.t. . Indeed in such case, for any .
We now prove that this property holds for -greedy policies (with non-increasing ) as well as soft-max policies (with non-decreasing ), as stated in the two lemmas below.
Of course not all policies satisfy this property (a counter-example being ).
Let be a non-increasing sequence. Then the sequence of policies which are -greedy w.r.t. the sequence of functions is increasingly greedy w.r.t. that sequence.
From the definition of an -greedy policy we have:
where we used the fact that . ∎
Let be a non-decreasing sequence of soft-max parameters. Then the sequence of policies which are soft-max (with parameter ) w.r.t. the sequence of functions is increasingly greedy w.r.t. that sequence.
For any and , define and Then we have
Thus is a non-decreasing function, and since , we have
Appendix C Proof of Theorem 2
As mentioned in the main text, since is Markovian, we can define the (sub)-probability transition operator
The Retrace operator then writes
We now lower- and upper-bound the term .
where A_{k}:=\gamma(I-\gamma P^{c\mu_{k}})^{-1}\big{[}P^{\pi_{k}}-P^{c\mu_{k}}\big{]}.
Now let us prove that has non-negative elements, whose sum over each row is at most . Let be the vector with 1-components. By rewriting as and noticing that
it is clear that all elements of are non-negative. We have
(since ). Thus has non-negative elements, whose sum over each row, is at most . We deduce from (10) that is upper-bounded by a sub-convex combination of components of ; the sum of their coefficients is at most . Thus
Now, from the definition of we have thus
By hypothesis, is increasingly greedy w.r.t. , thus
where . Since has non-negative elements (as proven in (11)) as well as , then has non-negative elements as well. Thus
since we assumed . Thus (15) implies that
and combining the above with (13) we deduce
Now assume that . We first deduce that is bounded. Indeed as soon as , we have
Thus . Since is bounded, we deduce that . ∎
Appendix D Proof of Theorem 3
We first prove convergence of the general online algorithm.
and assume that (1) is a centered, -measurable noise term of bounded variance, and (2) is bounded from above by , where is a random sequence that converges to 0 a.s. Then, under the same assumptions as in Theorem 3, we have that almost surely.
We write for . Let us prove the result in three steps.
Upper bound on . The first part of the proof is similar to the proof of (13), so we have
Lower bound on . Again, similarly to (15) we have
Lower-bound on . Since the sequence of policies is increasingly greedy w.r.t. , we have
where and . It is easy to see that both and continue to satisfy the assumptions on , and . Now, from the definition of the operator, we have
Using this equality into (20) and writing , we have
where . The matrix is non-negative but may not be a contraction mapping (the sum of its components per row may be larger than ). Thus we cannot directly apply Proposition 4.5 of Bertsekas and Tsitsiklis, (1996). However, as we have seen in the proof of Theorem 2, the matrix is a -contraction mapping. So now we relate to using our assumption that and commute asymptotically, i.e. with . For any (sub)-transition matrices and , we have
Replacing by and by , we deduce
where continues to satisfy the assumptions on (since ).
Now, let us define another sequence as follows: and
We can now apply Proposition 4.5 of Bertsekas and Tsitsiklis, (1996) to the sequence . The matrices are non-negative, and the sum of their coefficients per row is bounded by , see (12), thus are -contraction mappings and have the same fixed point which is . The noise is centered and -measurable and satisfies the bounded variance assumption, and is bounded above by for some . Thus almost surely.
Now, it is straightforward to see that for all . Indeed by induction, let us assume that . Then
since all elements of the matrix are non-negative. Thus we deduce that
Conclusion. Using (23) in (19) we deduce the lower bound:
almost surely. Now combining with the upper bound (18) we deduce that
The last two terms can be incorporated to the and terms, respectively; we thus again apply Proposition 4.5 of Bertsekas and Tsitsiklis, (1996) to the sequence defined by (17) and deduce that almost surely. ∎
It remains to rewrite the update (7) in the form of (17), in order to apply Theorem 4.
Let denote the accumulating trace (Sutton and Barto,, 1998):
Let us write to emphasize the online setting. Then (7) can be written as
Using our assumptions on finite trajectories, and , we can show that:
Finally, using the above, and writing , (25) can be rewritten in the desired form:
We can thus apply Theorem 4 to (27), and conclude that the iterates as , w.p. 1.
Let and two sequences of policies. If there exists such that for all ,
then the transition matrices and asymptotically commute: .
Let a sequence of (deterministic) greedy policies w.r.t. a sequence . Let a sequence of policies that are away from , in the sense that, for all ,
Let a sequence of policies defined by:
for some arbitrary policy and . Assume . Then the transition matrices and asymptotically commute.
The intuition is that asymptotically gets very close to the deterministic policy . In that case, the minimum distribution puts a mass close to on the greedy action , and no mass on other actions, thus gets very close to , and Lemma 4 applies (with multiplicative constant ).
Indeed, from our assumption that is -away from we have:
Thus Lemma 4 applies (with a multiplicative constant ) and and asymptotically commute. ∎
Appendix F Experimental Methods
Although our experiments’ learning problem closely matches the DQN setting used by Mnih et al., (2015) (i.e. single-thread off-policy learning with large replay memory), we conducted our trials in the multi-threaded, CPU-based framework of Mnih et al., (2016), obtaining ample result data from affordable CPU resources. Key differences from the DQN are as follows. Sixteen threads with private environment instances train simultaneously; each infers with and finds gradients w.r.t. a local copy of the network parameters; gradients then update a “master” parameter set and local copies are refreshed. Target network parameters are simply shared globally. Each thread has private replay memory holding 62,500 transitions (1/16th of DQN’s total replay capacity). The optimizer is unchanged from (Mnih et al.,, 2016): “Shared RMSprop” with step size annealing to 0 over environment frames (summed over threads). Exploration parameter () behaviour differs slightly: every 50,000 frames, threads switch randomly (probability 0.3, 0.4, and 0.3 respectively) between three schedules (anneal from 1 to 0.5, 0.1, or 0.01 over 250,000 frames), starting new schedules at the intermediate positions where they left old ones.We evaluated a DQN-style single schedule for , but our multi-schedule method, similar to the one used by Mnih et al.,, yielded improved performance in our multi-threaded setting.
Our experiments comprise 60 Atari 2600 games in ALE (Bellemare et al.,, 2013), with “life” loss treated as episode termination. The control, minibatched (64 transitions/minibatch) one-step Q-learning as in (Mnih et al.,, 2015), shows performance comparable to DQN in our multi-threaded setup. Retrace, TB, and Q* runs use minibatches of four 16-step sequences (again 64 transitions/minibatch) and the current exploration policy as the target policy . All trials clamp rewards into prior to gradient calculation; analogous quantities in the multi-step algorithms are clamped into $$, then scaled (divided by) the sequence length. Coarse, then fine logarithmic parameter sweeps on the games Asterix, Breakout, Enduro, Freeway, H.E.R.O, Pong, Q*bert, and Seaquest yielded step sizes of 0.0000439 and 0.0000912, and RMSprop regularization parameters of 0.001 and 0.0000368, for control and multi-step algorithms respectively. Reported performance averages over four trials with different random seeds for each experimental configuration.
We compared our algorithms for different values of , using the DQN score as a baseline. As before, for each we compute the inter-algorithm scores on a per-game basis. We then averaged the inter-algorithm scores across games to produce Table 2 (see also Figure 2 for a visual depiction). We first remark that Retrace always achieve a score higher than TB, demonstrating that it is efficient in the sense of Section 2. Next, we note that performs best for small values of , but begins to fail for values above . In this sense, it is also not safe. This is particularly problematic as the safe threshold of is likely to be problem-dependent. Finally, there is no setting of for which Retrace performs particularly poorly; for high values of , it achieves close to the top score in most games. For Retrace() it makes sense to use a values (at least in deterministic environments) as the trace cutting effect required in off-policy learning is taken care of by the use of the coefficient. On the contrary, only relies on a value to take care of cutting traces for off-policy data.