Consistent On-Line Off-Policy Evaluation
Assaf Hallak, Shie Mannor
Introduction
Reinforcement Learning (RL) techniques were successfully applied in fields such as robotics, games, marketing and more (Kober et al., 2013; Al-Rawi et al., 2015; Barrett et al., 2013). We consider the problem of off-policy evaluation (OPE) – assessing the performance of a complex strategy without applying it. An OPE formulation is often considered in domains with limited sampling capability. For example, marketing and recommender systems (Theocharous & Hallak, 2013; Theocharous et al., 2015) directly relate policies to revenue. A more extreme example is drug administration, as there are only few patients in the testing population, and sub-optimal policies can have life threatening effects (Hochberg et al., 2016). OPE can also be useful as a module for policy optimization in a policy improvement scheme (Thomas et al., 2015a).
In this paper, we consider the OPE problem in an on-line setup where each new sample is immediately used to update our current value estimate of some previously unseen policy. We propose and analyze a new algorithm called COP-TD(,) for estimating the value of the target policy; COP-TD(,) has the following properties:
Easy to understand and implement on-line.
Allows closing the gap to consistency such that the limit point is the same that would have been obtained by on-policy learning with the target policy.
Empirically comparable to state-of-the art algorithms.
Our algorithm resembles (Sutton et al., 2015)’s Emphatic TD that was extended by (Hallak et al., 2015) to the general parametric form ETD(,). We clarify the connection between the algorithms and compare them empirically. Finally, we introduce an additional related heuristic called Log-COP-TD(,) and motivate it.
Notations and Background
We consider the standard discounted Markov Decision Process (MDP) formulation (Bertsekas & Tsitsiklis, 1996) with a single long trajectory. Let be an MDP where is the finite state space and is the finite action space. The parameter sets the transition probabilities given the previous state and action , where the first state is determined by the distribution . The parameter sets the reward distribution obtained by taking action in state and is the discount factor specifying the exponential reduction in reward with time.
The process advances as follows: A state is sampled according to the distribution . Then, at each time step starting from the agent draws an action according to the stochastic behavior policy , a reward is accumulated by the agent, and the next state is sampled using the transition probability .
The expected discounted accumulated reward starting from a specific state and choosing an action by some policy is called the value function, which is also known to satisfy the Bellman equation in a vector form:
where is the step size. The value is an estimate of the current state’s , looking forward steps, and is an exponentially weighted average of all of these estimates going forward till infinity. Notice that Equation 1 does not specify an on-line implementation since depends on future observations, however there exists a compact on-line implementation using eligibility traces (Bertsekas & Tsitsiklis (1996) for on-line TD(), and Sutton et al. (2014), Sutton et al. (2015) for off-policy TD()). The underlying operator of TD() is given by:
and is a -contraction (Bertsekas, 2012).
We denote by the stationary distribution over states induced by taking the policy and mark . Since we are concerned with the behavior at infinite horizon, we assume . In addition, we assume that the MDP is ergodic for the two specified policies so and that the OPE problem is proper – .
TD() can be adjusted to find the fixed point of where is the projection to the subspace spanned by the features with respect to the -weighted norm (Sutton & Barto, 1998):
Finally, we define OPE-related quantities:
we call the covariate shift ratio (as denoted under different settings by (Hachiya et al., 2012)).
We summarize the assumptions used in the proofs:
Under both policies the induced Markov chain is ergodic.
The first state is distributed according to the stationary distribution of the behavior policy .
The problem is proper: .
The feature matrix has full rank .
Assumption 1 is commonly used for convergence theorems as it verifies the value function is well defined on all states regardless of the initial sampled state. Assumption 2 can be relaxed since we are concerned with the long-term properties of the algorithm past its mixing time – we require it for clarity of the proofs. Assumption 3 is required so the importance sampling ratios will be well defined. Assumption 4 guarantees the optimal is unique which greatly simplifies the proofs.
Previous Work
We can roughly categorize previous OPE algorithms to two main families. Gradient based methods that perform stochastic gradient descent on error terms they want to minimize. These include GTD (Sutton et al., 2009a), GTD-2, TDC (Sutton et al., 2009b) and HTD (White & White, 2016). The main disadvantages of gradient based methods are (A) they usually update an additional error correcting term, which means another time-step parameter needs to be controlled; and (B) they rely on estimating non-trivial terms, an estimate that tends to converge slowly. The other family uses importance sampling (IS) methods that correct the gains between on-policy and off-policy updates using the IS-ratios ’s. Among these are full IS (Precup et al., 2001) and ETD(,) (Sutton et al., 2015). These methods are characterized by the bias-variance trade-off they resort to – navigating between biased convergent values (or even divergent), and very slow convergence stemming from the high variance of IS correcting factors (the products). There are also a few algorithms that fall between the two, for example TO-GTD (van Hasselt et al., 2014) and WIS-TD() (Mahmood & Sutton, 2015).
A comparison of these algorithms in terms of convergence rate, synergy with function approximation and more is available in (White & White, 2016; Geist & Scherrer, 2014). We focus in this paper on the limit point of the convergence. For most of the aforementioned algorithms, the process was shown to converge almost surely to the fixed point of the projected Bellman operator where is some stationary distribution (usually ), however the in question was neverExcept full IS, however its variance is too high to be applicable in practice. as we would have obtained from running on-policy TD with the target policy. The algorithm achieving the closest result is ETD(,) which replaced with , where trades-off some of the process’ variance with the bias in the limit point. Hence, our main contribution is a consistent algorithm which can converge to the same value that would have been obtained by running an on-policy scheme with the same policy.
Motivation
Here we provide a motivating example showing that even in simple cases with “close” behavior and target policies, the two induced stationary distributions can differ greatly. Choosing a specific linear parameterization further emphasizes the difference between applying on-policy TD with the target policy, and applying inconsistent off-policy TD.
Assume a chain MDP with numbered states , where from each state you can either move left to state , or right to state . If you’ve reached the beginning or the end of the chain (states or ) then taking a step further does not affect your location. Assume the behavior policy moves left with probability , while the target policy moves right with probability . It is easy to see that the stationary distributions are given by:
For instance, if we have a length chain with , for the rightmost state we have . Let’s set the reward to be for the right half of the chain, so the target policy is better since it spends more time in the right half. The value of the target policy in the edges of the chain for is .
Now what happens if we try to approximate the value function using one constant feature ? The fixed point of is , while the fixed point of is – a substantial difference. The reason for this difference lies in the emphasis each projection puts on the states: according to , the important states are in the left half of the chain – these with low value function, and therefore the value estimation of all states is low. However, according to the important states are concentrated on the right part of the chain since the target policy will visit these more often. Hence, the estimation error is emphasized on the right part of the chain and the value estimation is higher. When we wish to estimate the value of the target policy, we want to know what will happen if we deploy it instead of the behavior policy, thus taking the fixed point of better represents the off-policy evaluation solution.
COP-TD(λ𝜆\lambda, β𝛽\beta)
Most off-policy algorithms multiply the TD summand of TD() with some value that depends on the history and the current state. For example, full IS-TD by (Precup et al., 2001) examines the ratio between the probabilities of the trajectory under both policies:
In problems with a long horizon, or these that start from the stationary distribution, we suggest using the time-invariant covariate shift multiplied by the current . The intuition is the following: We would prefer using the probabilities ratio given in Equation 3, but it has very high variance, and after many time steps we might as well look at the stationary distribution ratio instead. This direction leads us to the following update equations:
If the satisfy then the process described by Eq. (4) converges almost surely to the fixed point of .
The proof follows the ODE method (Kushner & Yin, 2003) similarly to Tsitsiklis & Van Roy (1997) (see the appendix for more details).
Since is generally unknown, it is estimated using an additional stochastic approximation process. In order to do so, we note the following Lemma:
Note that , unlike , is restricted to a close set since its -weighted linear combination is equal to and all of its entries are non-negative; We denote this -weighted simplex by , and let be the (non-linear) projection to this set with respect to the Euclidean norm ( can be calculated efficiently, (Chen & Ye, 2011)). Now, we can devise a TD algorithm which estimates and uses it to find , which we call COP-TD(, ) (Consistent Off-Policy TD).
Similarly to the Bellman operator for TD-learning, we define the underlying COP-operator and its extension:
The following Lemma may give some intuition on the convergence of the estimation process:
Under the ergodicity assumption, denote the eigenvalues of by . Then is a -contraction in the -norm on the orthogonal subspace to , and is a fixed point of .
The technical proof is given in the appendix.
The proof is given in the appendix and also follows the ODE method. Notice that a theorem is only given for , convergence results for general should follow the work by Yu (2015).
A possible criticism on COP-TD(,) is that it is not actually consistent, since in order to be consistent the original state space has to be small, in which case every off-policy algorithm is consistent as well. Still, the dependence on another set of features allows to trade-off accuracy with computational power in estimating and subsequently . Moreover, smart feature selection may further reduce this gap, and COP-TD(, ) is still the first algorithm addressing this issue. We conclude with linking the error in ’s estimate with the difference in the resulting , which suggests that a well estimated results in consistency:
Let . If , then the fixed point of COP-TD(,) with function approximation satisfies the following, where is the induced norm:
where , and sets the fixed point of the operator .
Recently, Sutton et al. (2015) had suggested an algorithm for off-policy evaluation called Emphatic TD. Their algorithm was later on extended by Hallak et al. (2015) and renamed ETD(, ), which was shown to perform extremely well empirically by White & White (2016). ETD(, ) can be represented as:
When comparing ETD(,)’s form to COP-TD(,)’s, instead of spending memory and time resources on a state/feature-dependent , ETD(,) uses a one-variable approximation. The resulting is in fact a one-step estimate of , starting from (see Equations 15, 8), up to a minor difference: (which following our logic adds bias to the estimate We have conducted several experiments with an altered ETD and indeed obtained better results compared with the original, these experiments are outside the scope of the paper.).
Unlike ETD(, ), COP-TD(,)’s effectiveness depends on the available resources. The number of features can be adjusted accordingly to provide the most affordable approximation. The added cost is fine-tuning another step-size, though ’s effect is less prominent.
The Logarithm Approach for Handling Long Products
We now present a heuristic algorithm which works similarly to COP-TD(, ). Before presenting the algorithm, we explain the motivation behind it.
Konidaris et al. (2011) suggested a statistical interpretation of TD(). They show that under several assumptions the TD() estimate is the maximum likelihood estimator of given : (1) Each is an unbiased estimator of ; (2) The random variables are independent and specifically uncorrelated; (3) The random variables are jointly normally distributed; and (4) The variance of each is proportional to .
Under Assumptions 1-3 the maximum likelihood estimator of given its previous estimate can be represented as a linear convex combination of with weights:
Subsequently, in Konidaris et al. (2011) Assumption was relaxed and instead a closed form approximation of the variance was proposed. In a follow-up paper by Thomas et al. (2015b), the second assumption was also removed and the weights were instead given as: , where the covariance matrix can be estimated from the data, or otherwise learned through some parametric form.
While both the approximated variance and learned covariance matrix solutions improve performance on several benchmarks, the first uses a rather crude approximation, and the second solution is both state-dependent and based on noisy estimates of the covariance matrix. In addition, there aren’t efficient on-line implementations since all past weights should be recalculated to match a new sample. Still, the suggested statistical justification is a valuable tool in assessing the similar role of in ETD(, ).
3 Log-COP-TD(λ𝜆\lambda, β𝛽\beta)
This approximation is crude – we could add terms reducing the error through Taylor expansion, but these would be complicated to deal with. Hence, we can relate to this method mainly as a well-motivated heuristic.
Notice that this formulation resembles the standard MDP formulation, only with the corresponding ”reward” terms going backward instead of forward, and no discount factor. Unfortunately, without a discount factor we cannot expect the estimated value to converge, so we propose using an artificial one . We can incorporate function approximation for this formulation as well. Unlike COP-TD(, ), we can choose the features and weights as we wish with no restriction, besides the linear constraint on the resulting through the weight vector . This can be approximately enforced by normalizing using (which should equal if we were exactly correct). We call the resulting algorithm Log-COP-TD(,).
4 Using the Original Features
An interesting phenomenon occurs when the behavior and target policies employ a feature based Boltzmann distribution for choosing the actions: , and , where a constant feature is added to remove the (possibly different) normalizing constant. Thus, , and Log-COP-TD(,) obtains a parametric form that depends on the original features instead of a different set.
5 Approximation Hardness
As we propose to use linear function approximation for and one cannot help but wonder how hard it is to approximate these quantities, especially compared to the value function. The comparison between and is problematic for several reasons:
The ultimate goal is estimating , approximation errors in are second order terms.
The value function depends on the policy-induced reward function and transition probability matrix, while depends on the stationary distributions induced by both policies. Since each depends on at least one distinct factor - we can expect different setups to result in varied approximation hardness. For example, if the reward function has a poor approximation then so will , while extremely different behavior and target policies can cause to behave erratically.
Subsequently, the choice of features for approximating and can differ significantly depending on the problem at hand.
If we would still like to compare and , we could think of extreme examples:
When , , when then .
In the chain MDP example in Section 4 we saw that is an exponential function of the location in the chain. Setting reward in one end to will result in an exponential form for as well. Subsequently, in the chain MDP example approximating is easier than as we obtain a linear function of the position; This is not the general case.
Experiments
We have performed 3 types of experiments. Our first batch of experiments (Figure 1) demonstrates the accuracy of predicting by both COP-TD(, ) and Log-COP-TD(, ). We show two types of setups in which visualization of is relatively clear - the chain MDP example mentioned in Section 4 and the mountain car domain (Sutton & Barto, 1998) in which the state is determined by only two continuous variables - the car’s position and speed. The parameters and exhibited low sensitivity in these tasks so they were simply set to , we show the estimated after iterations. For the chain MDP (top two plots, notice the logarithmic scale) we first approximate without any function approximation (top-left) and we can see COP-TD manages to converge to the correct value while Log-COP-TD is much less exact. When we use linear feature space (constant parameter and position) Log-COP-TD captures the true behavior of much better as expected. The two lower plots show the error (in color) in estimated for the mountain car with a pure exploration behavior policy vs. a target policy oriented at moving right. The z-axis is the same for both plots and it describes a much more accurate estimate of obtained through simulations. The features used were local state aggregation. We can see that both algorithms succeed similarly on the position-speed pairs which are sampled often due to the behavior policy and the mountain. When looking at more rarely observed states, the estimate becomes worse for both algorithms, though Log-COP-TD seems to be better performing on the spike at position .
Next we test the sensitivity of COP-TD(, ) and Log-COP-TD(,) to the parameters and (Figure 2) on two distinct toy examples - the chain MDP introduced before but with only 30 states with the position-linear features, and a random MDP with 32 states, 2 actions and a -bit binary feature vector along with a free parameter (this compact representation was suggested by White & White (2016) to approximate real world problems). The policies on the chain MDP were taken as described before, and on the random MDP a state independent / probability to choose an action by the behavior/target policy. As we can see, larger values of cause noisier estimations in the random MDP for COP-TD(, ), but has little effect in other venues. As for - we can see that if it is too large or too small the error behaves sub-optimally, as expected for the crude approximation of Equation 10. In conclusion, unlike ETD(, ), Log/COP-TD(, ) are much less effected by , though should be tuned to improve results.
Our final experiment (Figure 3) compares our algorithms to ETD(, ) and GTD(, ) over 4 setups: chain MDP with 100 states with right half rewards with linear features, a 2 action random MDP with 256 states and binary features, acrobot (3 actions) and cart-pole balancing (21 actions) (Sutton & Barto, 1998) with reset at success and state aggregation to states. In all problems we used the same features for and estimation, , constant step size for the TD process and results were averaged over 10 trajectories, other parameters (, , other step sizes, ) were swiped over to find the best ones. To reduce figure clutter we have not included standard deviations though the noisy averages still reflect the variance in the process. Our method of comparison on the first 2 setups estimates the value function using the suggested algorithm, and finds the weighted average of the error between and the on-policy fixed point :
where is the optimal obtained by on-policy TD using the target policy. On the latter continuous state problems we applied on-line TD on a different trajectory following the target policy, used the resulting value as ground truth and taken the sum of squared errors with respect to it. The behavior and target policies for the chain MDP and random MDP are as specified before. For the acrobot problem the behavior policy is uniform over the 3 actions and the target policy chooses between these with probabilities . For the cart-pole the action space is divided to 21 actions from -1 to 1 equally, the behavior policy chooses among these uniformly while the target policy is 1.5 times more prone to choosing a positive action than a negative one.
The experiments show that COP-TD(, ) and Log-COP-TD(, ) have comparable performance to ETD(, ) where at least one is better in every setup. The advantage in the new algorithms is especially seen in the chain MDP corresponding to a large discrepancy between the stationary distribution of the behavior and target policy. GTD() is consistently worse on the tested setups, this might be due to the large difference between the chosen behavior and target policies which affects GTD() the most.
Conclusion
Research on off-policy evaluation has flourished in the last decade. While a plethora of algorithms were suggested so far, ETD(, ) by Hallak et al. (2015) has perhaps the simplest formulation and theoretical properties. Unfortunately, ETD(, ) does not converge to the same point achieved by on-line TD when linear function approximation is applied.
We address this issue with COP-TD(,) and proved it can achieve consistency when used with a correct set of features, or at least allow trading-off some of the bias by adding or removing features. Despite requiring a new set of features and calibrating an additional update function, COP-TD(,)’s performance does not depend as much on as ETD(,), and shows promising empirical results.
We offer a connection to the statistical interpretation of TD() that motivates our entire formulation. This interpretation leads to two additional approaches: (a) weight the using estimated variances instead of exponents and (b) approximating instead of ; both approaches deserve consideration when facing a real application.
References
Appendix
Under both policies the induced Markov chain is ergodic.
The first state is distributed according to the behavior policy .
The support of contains the support of , i.e. .
The feature matrix has full rank.
If the step sizes hold then the process described by Equation 4 converges almost surely to the fixed point of .
Similarly to on-policy TD, we define and , the fixed point is the solution to . First we find and show stability:
This is exactly the same we would have obtained from TD() and it is negative definite (see (Sutton et al., 2015)). Similarly we can find :
and we obtained the same as on-policy TD() with .
Now we consider the noise of this off-policy TD, which is exactly the same noise as the on-policy TD only multiplied by - as long as the noise term of the ODE formulation (Kushner & Yin, 2003) is still bounded, the proof is exactly the same. According to Assumption 1, we know that is lower and upper bounded. By Assumption 3 we also know that is lower and upper bounded. Therefore the noise of the new process is bounded and the same a.s. convergence applies as on-policy TD() (Tsitsiklis & Van Roy, 1997). Since are the same as on-policy TD() for the target policy , the convergence is to the same fixed point. ∎
2 Proof of Lemma 2
For any function on the state space :
where is the unit vector of state . So, for an unbiased estimate of denoted we can define and derive:
3 Proof of Lemma 3
Under the ergodicity assumption, denote the eigenvalues of by . Then is a -contraction in the -norm on the orthogonal subspace to , and is a fixed point of .
We first show that is a fixed point of :
Due to similarity, the eigenvalues of are the same as these of which is a stochastic matrix with eigenvalues , where for we obtain the eigenvalue . Now for every vector orthogonal to denoted , the first eigenvalue has no effect on its spectral decomposition, which means that . ∎
4 Proof of Theorem 1
We use a three timescales stochastic approximation analysis. The fastest process is which converges naturally with time-step :
The process converges almost surely to by the strong law of large numbers. Our next process is , which we will show converges a.s. to with :
We follow the notation from (Schuss & Borkar, 2009). We first specify the stochastic approximation using and :
Now there are several conditions that must follow - condition on the step sizes, conditions on the Martingale and conditions on the projection. If all of these are met than the process converegs to the fixed point of the projected operator .
The step size conditions follow by the theorem’s assumption. Now we move on to the Martingale conditions.
Now let’s consider the projection where we follow the discussion in (Schuss & Borkar, 2009), Section 5.4. Notice that is Lipschitz and the eigenvalues around the fixed point are non-negative, therefore there’s a stable invariant solution set. In addition, the projection is to a closed convex set , so is bounded. Hence, our goal is to show that the projection is Lipschitz and that we can ignore its non-smooth boundary.
The projection to the simplex zeros some coordinates and decreases a constant from the other coordinates. If indeed it zeros some coordinates - we are at a problematic area of the space since the projection is not Frechet differentiable there (we are on the boundary of the set). However, because (Assumption 1), the unprojected ODE repels from these problematic boundaries, and we can assume that after enough the steps the projection is simply a projection to the affine subspace . In that case the projection is given by: and its Frechet derivative is . This derivative is Lipschitz continuous which means that its composition with is also Lipschitz .
Hence, the process converges to the solution set of for . Under these constraints the only fixed point can be (intersection of the line with the weighted simplex set .
Finally, treating the process assuming already converged to , leaves us with Lemma 1. Since each process depends only on the previous ones, it is enough to show they converge independently as long as the step sizes satisfy the rate constraints. ∎
5 Proof of Theorem 2
Similarly to the proof of Theorem , we can analyze the system on 3-time scales. The fastest process is which converges naturally with time-step :
First we represent the corresponding and of the projected ODE as follows (we assume , but the results are similar for general ):
We can now verify that a solution to also holds the Projected COP equation: by multiplying it from the left by :
Moving on to the last process, we get the following equations:
leading us to the known convergence solution (if indeed the process converge, which is not necessarily true) which is the fixed point of .
6 Proof of Corollary 1
Let . If , then the fixed point of COP-TD(,) with function approximation satisfies the following, where is the induced norm:
where , and sets the fixed point of the operator .
If , then we know that the weights of the projection hold:
We write the solution equations for both weight vectors
Now we subtract both equations and add and subtract :
Now we take norm on both sides, and use induced matrix sub-multiplicative property:
7 More details on the experiments
Experiments for Figure 1: 100 states chain MDP, with probability to move left / right for the behavior / target policy. Results were taken after iterations. For COP-TD we used and a constant step size . For Log-COP-TD we used and constant step size . The experiment was conducted 10 times and the standard deviation is given as shading in the graph.
For the mountain car experiment we used the simulator given by https://jamh-web.appspot.com/download.htm. The state aggregation was obtained by running kmeans with clusters and taking the centers as representative states. The behavior policy was taken to be uniform over the 3 possible actions (-1, 0, 1), and the target policy chose these actions with probabilities (1/6,1/3,1/2) regardless of the state. COP-TD was applied with and constant step size , and Log-COP-TD was applied with and constant step size . Both algorithms ran for iterations before the estimated was taken.
Experiments for Figure 2: 100 states chain MDP, with probability to move left / right for the behavior / target policy. For both algorithms constant step size . For Log-COP-TD we used when sweeping on the other parameter. All experiments were conducted 10 times and we show the average result.
In the randomized MDP with 32 states we used uniform distribution over transition probabilities for two possible actions, and the target policy had to choose one action where the behavior policy had to choose the other action. All experiments were conducted 10 times and we show the average result.
Experiments for Figure 3 were obtained by running COP-TD, Log-COP-TD, ETD and GTD over 4 setups. The distinct parameters of each algorithm were swiped over to find the best value: COP-TD’s step size and , Log-COP-TD’s steps size, and , ETD’s and GTD’s step size. The step size of the main process and were taken to be the same for all algorithms: step size = 0.05 and (obtained also by sweeping over possible values). The simulators for acrobot and pole-balancing were taken from https://jamh-web.appspot.com/download.htm.