W HERE O FF -P OLICY D EEP R EINFORCEMENT L EARNING F AILS
Anonymous authors
Paper under double-blind review
A BSTRACT
This work examines batch reinforcement learning–the task of maximally exploiting a given batch of off-policy data, without further data collection.
We demonstrate that due to errors introduced by extrapolation, standard off-policy deep reinforcement learning algorithms, such as DQN and DDPG, are only capable of learning with data correlated to their current policy, making them ineffective for most off-policy applications.
We introduce a novel class of off-policy algorithms, batch-constrained reinforcement learning, which restricts the action space to force the agent towards behaving on-policy with respect to a subset of the given data.
We extend this notion to deep reinforcement learning, and to the best of our knowledge, present the ﬁrst continuous control deep reinforcement learning algorithm which can learn effectively from uncorrelated off-policy data
I NTRODUCTION
Learning from only a batch of data without requiring further interactions with the environment is a crucial requirement for scaling reinforcement learning to tasks where the data collection procedure is costly, risky, or time-consuming.
Off-policy batch reinforcement learning has important implications in many areas, such as robotics, imitation learning and exploration.
In practical applications, it is often preferable for data collection to be performed by some secondary controlled process, such as a human operator or a carefully monitored program.
If assumptions on the quality of the behavioral policy can be made, imitation learning can be used to produce good policies.
However, imitation learning algorithms, such as behavioral cloning, are known to fail when exposed to noisy or suboptimal trajectories (Ross et al., 2011), and more sophisticated approaches are generally unable to surpass the performance of the demonstrator without further interactions with the environment (Ziebart et al., 2008; Ho & Ermon, 2016; Hester et al., 2017).
In most deep reinforcement learning algorithms, a single policy, or variations of a single policy, are used for both exploration and exploitation.
This paradigm creates a trade-off between future learning and current performance, and limits the agent to suboptimal policies, unless careful annealing of the exploratory behavior is performed.
In contrast, batch reinforcement learning offers a mechanism for learning from a decoupled exploratory process without suffering from degradation in current performance.
Most modern off-policy deep reinforcement learning algorithms fall into the category of growing batch learning (Lange et al., 2012), in which data is collected and stored into an experience replay dataset (Lin, 1992), which is used to train the agent before further data collection occurs.
However, we ﬁnd that these off-policy algorithms are generally unsuccessful, unless the available dataset is correlated to the current policy.
We demonstrate that this inability to truly learn off-policy is largely due to extrapolation error , a phenomenon in which unseen state-action pairs in the learning target are erroneously estimated to have unrealistic values, which may make them more attractive than observed actions.
In other words, the uncertainty of unseen state-action pairs and generalization from function approximation, can cause poor value estimates and suboptimal action selection.
To overcome extrapolation error in off-policy learning, we introduce batch-constrained reinforcement learning, in which agents are trained to maximize reward by only selecting previously seen actions .
We prove that this paradigm induces desirable properties in the discrete MDP setting, such as converging to the optimal policy without needing to experience all possible transitions.
We generalize this notion to continuous control with neural networks by training a state-conditioned generative model to produce only previously seen actions.
This generative model is combined with a network which aims to optimally perturb the generated actions in a small range, resulting in the agent using only actions similar to those previously seen.
We test our algorithm on several MuJoCo (Todorov et al., 2012) environments, where extrapolation error is particularly problematic due to the high dimensional continuous action space, which makes it impossible to sample the action space exhaustively.
Unlike any previous continuous control reinforcement learning algorithm, our approach is able to learn successfully in a variety of batch reinforcement learning settings.
Our algorithm offers a uniﬁed view on imitation and off-policy learning, and is capable of learning from purely expert demonstrations, as well as from ﬁnite batches of suboptimal data.
To ensure reproducibility, we provide precise experimental and implementation details and our code will be made available.
B ACKGROUND
In reinforcement learning, an agent interacts with its environment, typically assumed to be a Markov decision process (MDP) ( S , A , p, r, γ ) , with state space S , action space
A transition dynamics p ( s (cid:48) | s, a ) , for each s (cid:48) , s ∈ S and a ∈ A .
At each discrete time step, the agent receives a reward r ( s, a ) ∈ R for performing action a in state s .
The goal of the agent is to maximize the expectation of the sum of discounted rewards, known as the return R t = (cid:80) ∞
i =
t +1 γ
i r
( s i , a i ) , which weighs future rewards with respect to the discount factor γ ∈ [0 , 1) .
The agent selects actions with respect to a policy π : S → A , which has a corresponding value function Q π ( s, a ) =
E π
[ R t | s, a ] , estimating the expected return when following the policy π after taking action a in state s .
Given Q π , a new policy π (cid:48) of equal or better performance can be derived by greedy maximization π (cid:48)
= argmax a Q π ( s, a ) (Sutton & Barto, 1998).
For a given policy π , the value function can be estimated using sampled versions of the Bellman operator T
[Equation] [Equation]
The Bellman operator is a contraction for γ ∈ [0 , 1) with unique ﬁxed point Q π ( s, a ) (Bertsekas & Tsitsiklis, 1996).
Q ∗ ( s, a ) = max π Q π ( s, a ) is known as the optimal value function, which has a corresponding optimal policy obtained through greedy action choices.
For large or continuous state and action spaces, the value can be approximated with neural networks, e.g. using the DQN algorithm (Mnih et al., 2015).
In DQN, the value function Q θ is updated using the target:
[Equation]
Q-learning is an off-policy algorithm (Sutton & Barto, 1998), meaning the target can be computed without consideration of how the experience was generated.
As a result, off-policy reinforcement learning algorithms are able to learn from data collected by any behavioral policy.
Typically, the loss is minimized over mini-batches of tuples of the agent’s past data, ( s, a, r, s (cid:48) )
∈ B , sampled from an experience replay dataset B (Lin, 1992).
For shorthand, we often write s ∈ B if there exists a transition tuple containing s in the batch B , and similarly for ( s, a ) ∈ B .
To further stabilize learning, a target network with frozen parameters Q θ (cid:48) , is used in the learning target.
The parameters of the target network θ (cid:48) are updated to the current network parameters θ after a ﬁxed number of time steps, or by averaging θ (cid:48)
← τθ + (1 − τ ) θ (cid:48) for some small τ (Lillicrap et al., 2015).
In a continuous action space, the analytic maximum of Equation 2 is intractable.
In this case, actor-critic methods are commonly used, where action selection is performed through a separate policy network π φ , known as the actor, and updated with respect to a value estimate, known as the critic (Sutton & Barto, 1998; Konda & Tsitsiklis, 2003).
This policy can be updated following the deterministic policy gradient theorem (Silver et al., 2014):
[Equation]
which corresponds to learning an approximation to the maximum of Q θ , by propagating the gradient through both π φ and Q θ .
When combined with off-policy deep Q-learning to learn Q θ , this algorithm is referred to as Deep Deterministic Policy Gradients (DDPG) (Lillicrap et al., 2015).
[Equation]
E XTRAPOLATION E RROR
Off-policy algorithms commonly assume inﬁnite state-action visitation for convergence or optimality guarantees (Watkins, 1989; Precup et al., 2001), which is generally impossible to satisfy in any practical problem.
In this section, we analyze how breaking this assumption can introduce large amounts of error into the value function by a phenomenon we call extrapolation error .
We show how this error can lead to degenerate policies for even provably convergent batch algorithms, such as kernel-based reinforcement learning (Ormoneit & Sen, 2002).
Furthermore, we ﬁnd that state of the art deep reinforcement learning algorithms, such as DDPG (Lillicrap et al., 2015) and DQN (Mnih et al., 2015), are generally incapable of learning from data uncorrelated to the current policy.
Consequently, current deep reinforcement learning algorithms are unsatisfactory solutions for the batch setting, where no assumptions can be made on the data collection process.
In Q-learning, an off-policy target r + γQ ( s (cid:48) , a (cid:48) ) is used to train the current value estimate, where a (cid:48) is selected by a policy π ( s (cid:48) ) .
However, if the state-action pair ( s (cid:48) , a (cid:48) ) is not contained in the training set, the value Q ( s (cid:48) , a (cid:48) ) can be unpredictable due to extrapolation from other state-action pairs by function approximation.
This means Q ( s (cid:48) , a (cid:48) ) can take on implausible values due to the lack of data near the state-action pair.
Informally, extrapolation error comes from training the value estimate with state-action pairs that are not present in the training data.
When combined with maximization in reinforcement learning algorithms, extrapolation error provides a source of noise that can induce a persistent overestimation bias (Thrun & Schwartz, 1993; Van Hasselt et al., 2016; Fujimoto et al., 2018).
In an off-policy or batch setting, this extrapolation error may never be corrected, due to the inability to collect new data, resulting in disastrous value estimation and degenerate policies.
3. A S IMPLE E XAMPLE
This problem of extrapolation persists in traditional batch reinforcement learning algorithms, such as kernel-based reinforcement learning (KBRL)
(Ormoneit & Sen, 2002).
For a given batch B of transitions ( s, a, r, s (cid:48) ) , non-negative density function φ : R + → R + , hyper-parameter τ ∈ R , and norm || · || , KBRL evaluates the value of a state-action pair (s,a) as follows:
[Equation]
where states s a B ∈
S corresponding to the action a ( s B , a ) ∈
B , and V ( s (cid:48)B ) = max a s.t.
( s (cid:48)B ,a ) ∈B Q ( s (cid:48)B , a ) .
At each iteration, KBRL updates the estimates of Q ( s B , a B ) for all ( s B , a B ) ∈ B following Equation (4), then updates V ( s (cid:48)B ) by evaluating Q ( s (cid:48)B , a ) for all s B ∈ B and a ∈ A .
Given access to the entire deterministic MDP, KBRL will provable converge to the optimal value, however when limited to only a subset, we ﬁnd the value estimation susceptible to extrapolation.
In Figure 1, we provide a deterministic two state, two action MDP in which KBRL fails to learn the optimal policy when provided with state-action pairs from the optimal policy.
Given the batch { ( s 0 , a 1 , r = 1 , s 1 ) , ( s 1 , a 0 , r = 0 , s 0 ) } , corresponding to the optimal behavior, and noting that there is only one example of each action, Equation (4) provides the following:
[Equation]
[Figure]
After sufﬁcient iterations KBRL will converge correctly to Q ( s
[Equation]
However, when evaluating actions, KBRL erroneously extrapolates the values of each action
Q ( · , a 1 ) = 1 1 − γ 2 , Q ( · , a 0 )
= γ 1 − γ 2 , and its behavior, argmax a Q ( s, a ) , will result in the degenerate policy of continually selecting a 1 .
KBRL fails this example by estimating the values of unseen state-action pairs.
In methods where the extrapolated estimates can be included into the learning update, such ﬁtted Q-iteration or DQN (Ernst et al., 2005; Mnih et al., 2015), this can cause an increasing sequence of value estimates.
3. E XTRAPOLATION ERROR IN D EEP R EINFORCEMENT L EARNING
While Section 3.1 examined a speciﬁc counterexample, this raises a key question– what is the role of extrapolation error in a practical setting?
In this section, we examine the behavior of a state of the art deep actor-critic algorithm, DDPG (Lillicrap et al., 2015), when learned with off-policy data.
We ﬁnd that extrapolation error, combined with the maximization via gradient updates in the policy updates of DDPG, results in large amounts of overestimation bias and reduced performance.
To examine the bias induced from off-policy learning, we examine three different batch settings in the MuJoCo environments of OpenAI gym (Todorov et al., 2012; Brockman et al., 2016), which we use to train an off-policy DDPG agent with no interaction with the environment:
Batch 1 (Fixed buffer).
We train a DDPG (Lillicrap et al., 2015) agent for 1 million time steps, adding large amounts of Gaussian noise, N (0 , 0 . 5) , for exploration, and store all experienced transitions.
This collection procedure creates a dataset with a diverse set of states and actions.
Batch 2 (Concurrent learning).
We simultaneously train the off-policy DDPG agent with the behavioral DDPG agent, for 1 million time steps.
The behavioral policy performs data collection with N (0 , 0 . 1) Gaussian noise added for exploration.
Each transition experienced by the behavioral policy is stored in a buffer replay which both agents learn from.
Batch 2 differs from Batch 1 as the agent learns as the buffer replay grows.
Batch 3 (Imitation).
A trained DDPG agent acts as an expert, and is used to collect a dataset of 1 million transitions, without added noise.
For each experiment we graph the performance of the agents as they train (left), as well as their value estimates (right), in Figure 2.
Straight lines represent the average return of episodes contained in the batch.
For better comparison, we additionally graph the learning performance of the behavioral agent for the ﬁxed buffer experiment.
Na¨ıvely, we might expect the off-policy agent trained with Batch 1 to perform well, given the large amounts of exploration, and size of the buffer, however, we ﬁnd that the agent performs far worse than the behavioral agent.
Furthermore, we ﬁnd the value function overestimates the true value.
In experiments with Batch 2, both agents sees the same buffer, we might expect the performance to be very similar.
However, due to small differences in the initial policies, the impact of extrapolation error on the off-policy agent is observed.
There is a notable difference in performance, and the value estimates of the off-policy agent is consistently higher than the behavioral value estimates.
Results of the agent trained with Batch 3 demonstrates the failure of off-policy deep reinforcement learning algorithms when the state-action coverage is limited, as exploration is hampered due to the unchanging expert policy.
In this experiment the off-policy agent fails to learn any meaningful behavior and the value function demonstrates divergent behavior.
These experiments show extrapolation error can be highly detrimental to learning off-policy in a batch reinforcement learning setting.
While the continuous state space and multi-dimensional action spaces in MuJoCo environments are contributing factors to extrapolation error, the scale of these tasks is small compared to real world settings.
However, even if a sufﬁcient amount of data collection occurs, the concerns of catastrophic forgetting (McCloskey & Cohen, 1989; Goodfellow et al., 2013) may still result in extrapolation error.
Consequently, off-policy reinforcement learning algorithms used in the real-world will require practical guarantees without inﬁnite data.
O FF -P OLICY R EINFORCEMENT L EARNING WITHOUT I NFINITE D ATA
Extrapolation error is introduced when we evaluate a learning target with an unseen state-action pair, during off-policy learning without inﬁnite data.
To address this concern, in this section we propose a learning agent which aims to act optimally while selecting actions from corresponding seen stateaction pairs.
In other words, for a given batch, we aim to learn the optimal agent which is on-policy with respect to a subset of the provided data.
We begin by deriving the batch-constrained policy iteration algorithm in a discrete MDP setting in Section 4.1 and then extend the algorithm to a deep reinforcement learning setting in Section 4.2.
4. B ATCH -C ONSTRAINED R EINFORCEMENT L EARNING FOR D ISCRETE MDP S
While extrapolation error is induced by function approximation, this section aims to introduce theoretical concepts and explain why a constrained action-space approach is a desirable strategy, even in a discrete MDP setting without function approximation.
To begin formalizing the notion of only learning with seen data, we deﬁne a batch B as a set of tuples ( s, a, r, s (cid:48) ) , where we further assume if ( s, a ) ∈ B then s (cid:48)
∈ B if p ( s (cid:48) | s, a ) > 0 unless s (cid:48) is a terminal state.
For a given batch B , we deﬁne the set of batch-constrained policies Π B , where π ∈ Π B : S → A , maps states to actions with the condition that if s ∈ B then the policy must select previously seen actions such that ( s, π ( s )) ∈ B .
In a practical reinforcement learning setup, the policy can only be trained with previously collected state-action pairs, thus we deﬁne the batch Bellman operator T π B , which will produce ∞ if a stateaction pair is not contained in the batch:
[Equation]
The batch Bellman operator serves as a representation for extrapolation error, as it will produce ∞ in regions that are uncertain due to unseen data points.
For a given batch B and policy π , we can use the batch Bellman operator to compute the value of a batch-constrained policy π ∈ Π B .
Lemma 1 (Batch Bellman Policy Evaluation).
For a given batch B , MDP M , and batchconstrained policy π ∈ Π B , the batch Bellman operator T π B repeatedly applied to an initial Q 0 :
S ×
A → R , where Q k +1 =
T π B Q k converges to a ﬁxed point Q π B ( s, a ) where Q π B ( s, a ) =
Q π ( s, a ) for ( s, a ) ∈ B , as k → ∞ .
The proof follows naturally by constructing a new MDP with transitions deﬁned by the batch.
Lemma 1 states if π ∈ Π B , the resulting value function Q π B ( s, a ) will be accurate, i.e. Q π B ( s, a ) =
Q π ( s, a ) , at any state-action pair ( s, a ) contained in the batch B .
This Lemma leads us to a key result concerning batch-constrained policies, which states only batch-constrained policies can produce accurate value functions with respect to the batch Bellman operator.
Theorem 1 (Batch Bellman Necessary and Sufﬁcient Condition).
Let Q π B ( s, a ) be the ﬁxed point of the batch Bellman operator T π B , then Q π B ( s, a ) =
Q π ( s, a ) for all ( s, a ) ∈ B
if and only if π ∈ Π B .
The batch Bellman operator overestimates the value for unseen states, analogous to the worst-case of extrapolation error in a function approximation setting.
Theorem 1 implies with access to only a subset of state-action pairs in the MDP, the value function Q π B learned with the batch Bellman operator will be inaccurate unless π is batch-constrained.
Given the batch Bellman operator is a representation of an extreme case of extrapolation error, Theorem 1 suggests batch-constrained policies are a potential solution to limiting incorrect extrapolation in the standard setting.
Next, we demonstrate batch-constrained policies can be used to learn the optimal policy.
We ﬁrst generalize the policy improvement theorem to a batch-constrained setting.
Given the value function of any batch-constrained policy, a policy of equal or higher value can be computed by greedily selecting actions a of highest value that satisfy the batch constraint ( s, a ) ∈ B .
Lemma 2 (Batch-Constrained Policy Improvement).
Let π ∈ Π B be any deterministic batchconstrained policy and π (cid:48)
( s ) = argmax a s.t.
( s,a ) ∈B Q π ( s, a ) , then for all s ∈ B , Q π (cid:48)
( s, π (cid:48) ( s )) ≥
Q π ( s, π ( s )) .
The previous Lemma, along with the standard policy evaluation result (Sutton & Barto, 1998) can be brought together to provide a policy iteration result.
By repeatedly evaluating an initial batchconstrained policy, and greedily maximizing with respect to value function and batch constraints, the policy converges to the optimal batch-constrained policy.
Theorem 2 (Batch-Constrained Policy Iteration).
Given a batch B and MDP M , then the repeated application of policy evaluation and batch-constrained policy improvement converges to a policy π ∗B , such that Q π ∗B ( s, π ∗B ( s )) ≥ Q π B ( s, π B ( s )) for all π B ∈ Π B and s ∈ B .
Optimality is a direct result from Theorem 1, namely, if the batch contains all possible state-action pairs from an optimal policy π ∗ , batch-constrained policy iteration converges to the optimal policy.
Corollary 1 (Batch-Constrained Optimality).
Given a batch B , and MDP M if for all s ∈ S , ( s, a ∗ , r, s (cid:48) )
∈ B where a ∗ = argmax a Q ∗ ( s, a ) and Q ∗ ( s, a ) = max π Q π ( s, a ) , then batchconstrained policy iteration converges to a policy π ∗ = argmax a Q ∗ ( s, a ) for all s ∈ S .
This result can be extended to show the direct connection from batch-constrained policy iteration and imitation learning.
Given an optimal trajectory, batch-constrained policy iteration converges to a policy which imitates the optimal trajectory over the state space it covers.
This result demonstrates that batch-constrained policy iteration is able to learn meaningful policies in certain regions of the state space, without access to the entire MDP.
Corollary 2 (Batch-Constrained Imitation).
Given a deterministic MDP, and trajectory T =
( s 0 , a ∗ 0 , r 0 , ...,
s i +1 , a ∗ i +1 , r i +1 , ... )
where a ∗ i = argmax a Q ∗ ( s i , a ) and Q ∗ ( s, a )
=
max π Q π ( s, a ) , then batch-constrained policy iteration converges to π ∗ ( s i )
=
argmax a Q ∗ ( s i , a ) for all s i ∈ T .
4. B ETWEEN I MITATION AND R EINFORCEMENT L EARNING FOR C ONTINUOUS C ONTROL
In this section we use the theoretical concepts introduced in the previous section as inspiration for a deep reinforcement learning algorithm in the continuous control setting, which minimizes extrapolation error through an approximation to the batch-constraint.
By nature, moving away from the discrete MDP setting brings a different set of challenges.
For a given continuous state s ∈ B , it is unlikely that there is more than one corresponding action a such that ( s, a ) ∈ B .
This is problematic as a batch-constrained policy will learn to simply imitate previously taken actions, which may be undesirable if the batch contains any suboptimal actions.
To address this, we deﬁne a similarity metric by modelling a learned distribution over actions contained in the batch.
This enables our deep batch reinforcement learning algorithm, Batch-Constrained deep Q-learning (BCQ), to approximate the batch-constraint by selecting actions which are similar to previously seen actions.
The batch-constraint was introduced as a tool to reduce extrapolation error by selecting only actions from previously seen state-action pairs.
We deﬁne a similarity metric by making the assumption that the similarity between ( s, a ) and the state-action pairs in the batch B can be modelled using a learned state-conditioned marginal likelihood P B ( a | s ) .
In this case, it follows that that the policy maximizing E a ∼ π [ P B ( a | s )] would minimize the error induced by extrapolation from distant, or unseen, state-action pairs, by only selecting the most likely actions in the batch, with respect to a given state.
Given the difﬁculty of directly maximizing P B ( a | s ) due to its intractable nature, we instead train a parametric generative model of the batch G ω ( s ) , which we can sample actions from as a reasonable approximation to argmax π E a ∼ π [ P B ( a | s )] .
For our generative model we use a conditional variational auto-encoder (VAE) (Kingma & Welling, 2013; Sohn et al., 2015), which models the distribution by transforming an underlying latent space 1 .
The encoder-decoder generative model G ω =
{ E ω 1 , D ω 2 } is trained to maximize the marginal likelihood of the batch B by optimizing the variational lowerbound:
[Equation]
where E ˜ ω 1 ( s, a )
= µ, σ and z ∼ N ( µ, σ ) .
To reduce extrapolation error in the value estimate
Q θ , actions which are similar to previously seen actions need to be selected in the learning target r + γQ θ (cid:48) ( s (cid:48) , π ( s (cid:48) )) .
The generative model G ω provides this mechanism, as for a given state, actions similar to the actions in the batch can sampled with high probability.
The generative model G ω , alongside the value function Q θ , can be used as a policy by sampling n actions from G ω and selecting the highest valued action according to the value estimate Q θ .
To increase the diversity of seen actions, we introduce a perturbation model ξ φ ( s, a, Φ) , which outputs an adjustment to an action a in the range [ − Φ , Φ] .
This enables access to actions in a constrained region, without having to sample from the generative model a prohibitive number of times.
This results in a policy π which is deﬁned by the hyper-parameters n and Φ , the value function Q θ and the perturbation model ξ φ :
[Equation]
The choice of n and Φ creates a trade-off between an imitation learning and reinforcement learning algorithm.
If Φ = 0 , and the number of sampled actions n = 1 , then the policy resembles behavioral cloning and as Φ → a max − a min and n → ∞ , then π = argmax a Q θ ( s (cid:48) , a ) , approaching Q-learning as the policy becomes closer to greedy maximization of the value function.
The perturbation model ξ φ can be trained to maximize Q
θ ( s, a ) through the deterministic policy gradient algorithm
(Silver et al., 2014):
[Equation]
As π includes a random sampling process, the variance of the value estimate update can be reduced by including a value network V ψ ( s ) , which changes the learning target of Q θ to r + γV ψ (cid:48)
( s (cid:48) ) .
This value network can be updated with learning target:
[Equation]
This forms Batch-Constrained deep Q-learning (BCQ), which maintains four parametrized networks, a perturbation model ξ φ ( s, a ) , a critic Q θ
( s, a ) , a value network V ψ ( s ) , and a generative model G ω ( s ) .
We summarize BCQ in Algorithm 1.
While BCQ is an approximation to batchconstrained reinforcement learning, in the following section we demonstrate that this approximation results in stable value learning and a strong performance in the batch setting.
Furthermore, we ﬁnd that only a single setting of n and Φ is necessary for a wide range of tasks.
Input: Batch B , horizon T , target network update rate τ , mini-batch size N , max perturbation Φ
Initialize network
Sample mini batch of N transitions ( s a r s (cid:48) ) from B
Sample VAE: µ, σ = E ω 1 ( s, a ) , ˜ a = D ω 2 ( s, z ) , z ∼ N ( µ, σ )
Update VAE: ω ← argmin ω (cid:80) ( a − ˜ a ) 2 + D KL ( N ( µ, σ ) ||N (0 , 1))
Update critic: θ ← argmin θ (cid:80) ( r + γV ψ (cid:48)
( s (cid:48) )
− Q θ ( s, a ))
Update perturbation model: φ ← argmax φ (cid:80) Q ( s, a + ξ φ ( s, a, Φ)) , a ∼ G ω ( s )
Sample n actions: { a i ∼ G ω ( s (cid:48) ) }
i =1 ,...,n
Perturb each action: { a i = a i + ξ φ ( s (cid:48) , a i , Φ) } i =1 ,...,n
Update value: ψ ← argmin ψ (cid:80) (max a i Q θ ( s, a i ) − V ψ ( s ))
Update target network: ψ (cid:48) ← τψ + (1 − τ ) ψ (cid:48) end for
[Figure]
E XPERIMENTS
To evaluate the effectiveness of Batch-Constrained deep Q-learning (BCQ) in a high-dimensional setting, we focus on MuJoCo environments in OpenAI gym
(Todorov et al., 2012; Brockman et al., 2016).
For reproducibility, we make no modiﬁcations to the original environments or reward functions.
We compare our method with DDPG (Lillicrap et al., 2015), DQN (Mnih et al., 2015) using an independently discretized action space with 10 bins per dimension, a feed-forward behavioral cloning method (BC), and a variant with a VAE (VAE-BC), mimicking G ω ( s ) used by BCQ.
For
BCQ, we use Φ = 0 .
05 , sample n = 10 actions from the VAE G ω and set the latent space to have twice the number of dimensions as the action space.
Exact network, hyper-parameter and training details of each method, along with experimental details are provided in the Supplementary Material.
[Figure]
We evaluate each method following the three experiments deﬁned in Section 3.2: ﬁxed buffer , learning from the ﬁnal experience replay of a trained DDPG agent, concurrent learning , learning simultaneously with the behavioral DDPG policy, and imitation , learning from a dataset collected by an expert.
The results of these experiments, along with the estimated values of BCQ, DDPG and DQN, and the true value of BCQ are displayed in Figure 3.
Our approach, BCQ, is the only algorithm which succeeds at all three tasks, matching or outperforming the behavioral policy in each instance, and outperforming all other agents, besides in imitation learning where behavioral cloning unsurprisingly performs the best.
These result demonstrate our approach is capable of both performing imitation learning and off-policy learning with ﬁxed hyper-parameters.
Furthermore, unlike DDPG and DQN, BCQ exhibits a highly stable value function in the presence of off-policy samples, suggesting extrapolation error has been successfully mitigated.
Given the action space of DQN is discretized independently, it is foreseeable that it would perform poorly on these environments with multi-dimensional actions.
However, this discretization reduces the action space to a more manageable scale, allowing for greater coverage of the action space, and potentially reducing the impact of extrapolation error.
Unfortunately, it is clear that this hypothesis is false, and the greedy maximization of DQN produces a highly overestimated value function.
Alongside extrapolation error, a likely cause is the error introduced by the independent discretization.
These results suggest that na ¨ ıvely reducing the size of the action space of the environment is an inadequate solution to extrapolation error.
To study the robustness of BCQ to imperfect transitions and multi-modal data, we examine its performance with a batch of 100k transitions collected by an expert policy, with two sources of noise.
The behavioral policy selects actions randomly with probability 0 . 3 and with high exploratory noise
N (0 , 0 . 3) added to the remaining actions.
We report the results in Figure 4.
We ﬁnd that both deep reinforcement learning and imitation learning algorithms preform poorly at this task.
BCQ, however, is able to strongly outperform the performance of the noisy demonstrator, disentangling poor and expert actions.
Furthermore, compared to current deep reinforcement learning algorithms, such as the DDPG demonstrator in Figure 3.c, BCQ attains a high performance in remarkably few iterations.
As DDPG is known to be data-efﬁcient compared to other state of the art algorithms (Henderson et al., 2017), this suggests our approach effectively leverages expert transitions.
R ELATED W ORK
Batch Reinforcement Learning.
While batch reinforcement learning algorithms have been shown to be convergent with non-parametric function approximators such as averagers (Gordon, 1995) and kernel methods (Ormoneit & Sen, 2002), they make no guarantees on the quality of the policy without inﬁnite data.
Other batch algorithms, such as ﬁtted Q-iteration, have used other function approximators, including decision trees (Ernst et al., 2005) and neural networks (Riedmiller, 2005), but come without convergence guarantees.
Decoupling exploration and exploitation has been previously attempted by achieving sufﬁcient diversity in data in an exploratory phase (Colas et al., 2018).
Due to fewer assumptions on the data collection, off-policy algorithms which rely on importance sampling (Precup et al., 2001; Munos et al., 2016) may not be applicable in a batch setting, and scale poorly to multi-dimensional action spaces.
Reinforcement learning with the experience replay (Lin, 1992) can be considered a form of batch reinforcement learning, and is a standard tool for off- policy deep reinforcement learning algorithms (Mnih et al., 2015).
It has been observed that large experience replay (Lin, 1992) can be detrimental to performance (de Bruin et al., 2015; Zhang &
Sutton, 2017) and the diversity of states in the buffer is an important factor for performance (de Bruin et al., 2016).
Isele & Cosgun (2018) observed the performance of agent was strongest when the distribution of data in the replay buffer matches the test distribution.
These results defend the notion that extrapolation error is an important factor in the performance off-policy reinforcement learning.
Imitation Learning.
Imitation learning and its variants are well studied problems (Schaal, 1999;
Argall et al., 2009).
In recent years, combining imitation with reinforcement learning, via learning from demonstrations (Kim et al., 2013; Piot et al., 2014; Chemali & Lazaric, 2015) has grown in popularity with extensions to deep reinforcement learning (Hester et al., 2017; Veˇcer´ık et al., 2017).
While effective, these methods require either explicit labeling of expert data, or further on-policy data collection to surpass the performance of the demonstrator.
Research in imitation and inverse reinforcement learning, with robustness to noise is an emerging area (Evans, 2016; Nair et al., 2017), but require expert data.
Gao et al.
(2018) introduced an imitation learning algorithm which learned from highly imperfect demonstrations, by favoring seen actions, but is limited to discrete actions.
Uncertainty in Reinforcement Learning.
Uncertainty estimates in deep reinforcement learning have generally been used to encourage exploration (Dearden et al., 1998;
Strehl & Littman, 2008;
O’Donoghue et al., 2018; Azizzadenesheli et al., 2018).
Other methods have examined approximating the Bayesian posterior of the value function (Osband et al., 2016; 2018; Touati et al., 2018), again using the variance to encourage exploration to unseen regions of the state space.
It has been previously noted that non-linear function approximation itself induces an implicit exploration without an explicit exploration policy (Dauparas et al., 2018).
Our results suggest that this exploration may be the result of an extrapolation error due to unseen state-action pairs.
In model-based reinforcement learning, uncertainty has been used for exploration, but also for the opposite effect–to push the policy towards regions of certainty in the model.
This is used to combat the well-known problems with compounding model errors, and is present in policy search methods (Deisenroth & Rasmussen, 2011; Gal et al., 2016; Higuera et al., 2018), combined with trajectory optimization (Chua et al., 2018) or value-based methods (Buckman et al., 2018).
Our work connects to policy methods with conservative updates (Kakade & Langford, 2002), such as trust region (Schulman et al., 2015;
Achiam et al., 2017) and information-theoretic methods (Peters & M ¨ ulling, 2010; Van Hoof et al., 2017) which aim to keep an updated policy similar to the previous policy.
These methods avoid explicit uncertainty estimates, and rather force policy updates into a constrained range before collecting new data, limiting errors introduced by large changes in the policy.
Similarly, our approach can be thought of an off-policy variant, where the policy aims to be kept close, in output space, to any combination of the previous policies which performed the data collection.
C ONCLUSION
In this work we demonstrate a critical problem in off-policy reinforcement learning with ﬁnite data and function approximation, where the value target introduces error by including an estimate of unseen data.
This phenomenon, which we denote extrapolation error , has important implications for batch and off-policy reinforcement learning, as it is generally implausible to have complete stateaction coverage in any practical setting.
We derive batch-constrained reinforcement learning–acting on-policy with respect to the available data, as an answer to extrapolation error.
When extended to a deep reinforcement learning setting, our algorithm, Batch-Constrained deep Q-learning (BCQ), is capable of learning from arbitrary batch data, without assumptions on the collection procedure.
A M ISSING P ROOFS
Lemma 1 (Batch Bellman Policy Evaluation).
For a given batch B , MDP M , and batchconstrained policy π ∈ Π B , the batch Bellman operator T π B repeatedly applied to an initial Q 0 :
S ×
A → R , where Q k +1 =
T π B Q k converges to a ﬁxed point Q π B ( s, a ) where Q π B ( s, a ) =
Q π ( s, a ) for ( s, a ) ∈ B , as k → ∞ .
Proof.
Deﬁne a new MDP M B by restricting the full MDP M to a sub-MDP with a set of states and actions with respect to B , then the lemma follows naturally from the contraction proof of the
Bellman operator (Bertsekas & Tsitsiklis, 1996).
Theorem 1 (Batch Bellman Necessary and Sufﬁcient Condition).
Let Q π B ( s, a ) be the ﬁxed point of the batch Bellman operator T π B , then Q π B ( s, a ) =
Q π ( s, a ) for all ( s, a ) ∈ B
if and only if π ∈ Π B .
Proof.
( ⇒ ) Follows from the deﬁnition of T π B , as if π / ∈ Π B then for some s we have ( s, π ( s )) / ∈ B and it follows that Q π B ( s, π ( s ))
= ∞ .
( ⇐ ) Follows directly from Lemma 1.
Lemma 2 (Batch-Constrained Policy Improvement).
Let π ∈ Π B be any deterministic batchconstrained policy and π (cid:48)
( s ) = argmax a s.t.
( s,a ) ∈B Q π ( s, a ) , then for all s ∈ B , Q π
[Table]
( s, π (cid:48) ( s )) ≥
Q π ( s, π ( s )) .
Proof.
Follows from policy improvement theorem (Sutton & Barto, 1998) by restricting the MDP to a sub-MDP with the set of states and actions contained in B and noting Q π ( s, π ∗B ( s )) ≥ Q π ( s, π ( s )) for all s ∈ B .
Theorem 2 (Batch-Constrained Policy Iteration).
Given a batch B and MDP M , then the repeated application of policy evaluation and batch-constrained policy improvement converges to a policy π ∗B , such that Q π ∗B ( s, π ∗B ( s )) ≥ Q π B ( s, π B ( s )) for all π B ∈ Π B and s ∈ B .
Proof.
Denote π i the policy at iteration i .
By Lemma 2, we have the monotonically increasing sequence Q π i +1 ≥
Q π i .
Noting that Q is bounded above as r is bounded, then policy iteration must converge to some maximum Q π (cid:48) , with corresponding policy π (cid:48)
∈ Π B , such that π (cid:48)
( s ) = argmax a s.t.
( s,a ) ∈B Q π (cid:48)
( s, a ) for all s ∈ B .
It follows that for all π ∈ Π B we have T π B Q π (cid:48)
≤ Q π (cid:48) , otherwise contradicting the deﬁnition of π (cid:48) .
Then from a repeated application of Lemma 1 we have that Q π ≤ Q π (cid:48) , and π (cid:48) must be the optimal batch-constrained policy.
Corollary 1 (Batch-Constrained Optimality).
Given a batch B , and MDP M if for all s ∈ S , ( s, a ∗ , r, s (cid:48) )
∈ B where a ∗ = argmax a Q ∗ ( s, a ) and Q ∗ ( s, a ) = max π Q π ( s, a ) , then batchconstrained policy iteration converges to a policy π ∗ = argmax a Q ∗ ( s, a ) for all s ∈ S .
Proof.
Follows directly from Theorem 1 as π ∗ ∈ Π B .
Corollary 2 (Batch-Constrained Imitation).
Given a deterministic MDP, and trajectory T =
( s 0 , a ∗ 0 , r 0 , ...,
s i +1 , a ∗ i +1 , r i +1 , ... )
where a ∗ i = argmax a Q ∗ ( s i , a ) and Q ∗ ( s, a )
=
max π Q π ( s, a ) , then batch-constrained policy iteration converges to π ∗ ( s i )
=
argmax a Q ∗ ( s i , a ) for all s i ∈ T .
Proof.
Follows directly from Theorem 1 by setting B = T .
B R ANDOM B EHAVIORAL P OLICY S TUDY
The experiments in Section 5 use a learned, or partially learned, behavioral policy for data collection.
This is a necessary requirement for learning meaningful behavior, as a random policy generally fails to provide sufﬁcient coverage over the state space.
However, in simple toy problems, such as the pendulum swing-up task and the reaching task with a two-joint arm from OpenAI gym
(Brockman et al., 2016), a random policy can sufﬁciently explore the environment, enabling us to examine the properties of algorithms with entirely non-expert data.
In Figure 5, we examine the performance of our algorithm, BCQ, as well as DDPG (Lillicrap et al., 2015), these two toy problems, when learning off-policy from a small batch of 5000 time steps, col- lected entirely by a random policy.
We ﬁnd that both BCQ and DDPG are able to learn successfully in this off-policy task.
These results suggests BCQ is less restrictive than imitation learning algorithms, which require expert data to learn.
We also ﬁnd that unlike previous environments, given the small scale of the environments, the random policy is able to provide sufﬁcient coverage of the action space for DDPG to learn successfully.
[Figure]
C E XPERIMENTAL D ETAILS
Each environment is run for 1 million time steps, unless stated otherwise, with evaluations every 5000 time steps, where an evaluation measures the average reward from 10 episodes with no exploration noise.
Our results are reported over 5 random seeds of the behavioral policy, OpenAI Gym simulator and network initialization.
Value estimates are averaged over mini-batches of 100 and sampled every 2500 iterations.
The true value is estimated by sampling 100 state-action pairs from the buffer replay and computing the discounted return by running the episode until completion while following the current policy.
Each agent is trained after episode by applying one training iteration per each time step in the episode.
The agent is trained with transition tuples ( s, a, r, s (cid:48) ) sampled from an experience replay that is deﬁned by each experiment.
We deﬁne four possible experiments.
Unless stated otherwise, default settings as deﬁned in Supplementary Material D are used.
Batch 1 (Fixed buffer).
We train a DDPG (Lillicrap et al., 2015) agent for 1 million time steps, adding large amounts of Gaussian noise ( N (0 , 0 . 5)) to induce exploration, and store all experienced transitions in a buffer replay.
This training procedure creates a buffer replay with a diverse set of states and actions.
A second, randomly initialized agent is trained using the 1 million stored transitions.
Batch 2 (Concurrent learning).
We simultaneously train two agents for 1 million time steps, the ﬁrst DDPG agent, performs data collection and each transition is stored in a buffer replay which both agents learn from.
This means the behavioral agent learns from the standard training regime for most off-policy deep reinforcement learning algorithms, and the second agent is learning offpolicy, as the data is collected without direct relationship to its current policy.
Batch 2 differs from
Batch 1 as the agents are trained with the same version of the buffer, while in Batch 1 the agent learns from the ﬁnal buffer replay after the behavioral agent has ﬁnished training.
Batch 3 (Imitation).
A DDPG agent is trained for 1 million time steps.
The trained agent then acts as an expert policy, and is used to collect a dataset of 1 million transitions.
This dataset is used to train a second, randomly initialized agent.
In particular, we train DDPG across 15 seeds, and select the 5 top performing seeds as the expert policies.
Batch 4 (Robust Imitation).
The expert policies from Batch 3 are used to collect a dataset of 100k transitions, while selecting actions randomly with probability 0 .
3 and adding Gaussian noise
N (0 , 0 . 3) to the remaining actions.
This dataset is used to train a second, randomly initialized agent.
D I MPLEMENTATION D ETAILS
Across all methods and experiments, for fair comparison, each network generally uses the same hyper-parameters and architectures, which are deﬁned in Table 1 and Figure 6 respectively.
Critics and value functions follow the standard practice (Mnih et al., 2015) in which the Bellman update differs for terminal transitions.
When the episode ends by reaching some terminal state, the value is set to 0 in the learning target y :
y
[Equation]
Where the termination signal from time-limited environments is ignored, thus we only consider a state s t terminal if t < max horizon .
[Table]
[Table]
[Figure]
BCQ. BCQ uses four networks: a perturbation model ξ φ ( s, a ) , a critic Q θ ( s, a ) , a value network
V ψ ( s ) , and a state-conditioned VAE G ω ( s ) , along with a target value network V ψ (cid:48) ( s ) .
Each network in BCQ follows the default architecture (Figure 6) and the default hyper-parameters (Table 1).
For ξ φ ( s, a, Φ) , the constraint Φ is implemented through a tanh activation multiplied by I · Φ following the ﬁnal layer.
The VAE G ω is deﬁned by two networks, an encoder E ω 1 ( s, a ) and decoder D ω 2 ( s, z ) , where ω = { ω 1 , ω 2 } .
The encoder takes a state-action pair and outputs the mean µ and standard deviation σ of a Gaussian distribution N ( µ, σ ) .
The state s , along with a latent vector z is sampled from the Gaussian, is passed to the decoder D ω 2 ( s, z ) which outputs an action.
The VAE is trained with respect to the mean squared error of the reconstruction along with a KL regularization term:
[Equation]
[Equation]
Noting the Gaussian form of both distributions, the KL divergence term can be simpliﬁed (Kingma & Welling, 2013):
[Equation]
where J denotes the dimensionality of z .
For each experiment, J is set to twice the dimensionality of the action space.
The KL divergence term in L VAE is normalized across experiments by setting λ = 1 J .
During inference with the VAE, the latent vector z is clipped to a range of [ − 0 . 5] to limit generalization beyond previously seen actions.
For the small scale experiments in Supplementary
Material B, L 2 regularization with weight 10 − 3 was used for the VAE to compensate for the small number of samples.
The other networks remain unchanged.
In the value network update, Equation (11), the VAE is sampled multiple times and passed to both the actor and critic.
For each state in the mini-batch the VAE is sampled n = 10 times.
This can be implemented efﬁciently by passing a latent vector with batch size 10 · batch size , effectively 1000 , to the VAE and treating the output as a new mini-batch for the actor and critic.
When running the agent in the environment, we sample from the VAE 100 times.
DDPG.
Our DDPG implementation deviates from some of the default architecture and hyperparameters to mimic the original implementation more closely (Lillicrap et al., 2015).
In particular, the action is only passed to the critic network at the second layer, (Figure 7), the critic uses Lregularization with weight 10 − 2 , and the actor uses a reduced learning rate of 10 − 4 . (state dimension, 400) ReLU
[Equation]
RelU
[Equation]
As done in Fujimoto et al.
(2018), our DDPG agent randomly selects actions for the ﬁrst 10k time steps for HalfCheetah-v1, and 1k time steps for Hopper-v1 and Walker2d-v1.
This was found to improve performance and reduce the likelihood of local minima in the policy during early iterations.
DQN.
Given the high dimensional nature of the action space of the experimental environments, our
DQN implementation selects actions over an independently discretized action space.
Each action dimension is discretized separately into 10 possible actions, giving 10 J possible actions, where J is the dimensionality of the action-space.
A given state-action pair ( s, a ) then corresponds to a set of state-sub-action pairs ( s, a i ) for i = { 1 , ..., J } .
In each DQN update, all state-sub-action pairs ( s, a i ) are updated with respect to the average value of the target state-sub-action pairs ( s (cid:48) , a (cid:48) j ) .
The learning update of the discretized DQN is as follows:
[Equation]
For clarity we provide the exact DQN network architecture in Figure 8.
(state dimension, 400)
ReLU (400, 300)
RelU (300, 10 action dimension)
[Figure]
Behavioral Cloning.
We use two behavioral cloning methods, VAE-BC and BC.
VAE-BC is implemented and trained exactly as G ω ( s ) deﬁned for BCQ.
BC uses a feed-forward network with the default architecture and hyper-parameters, and trained with a mean-squared error reconstruction loss.
E V ARIATIONAL A UTO -E NCODER B ACKGROUND
A variational auto-encoder (VAE) (Kingma & Welling, 2013) is a generative model which aims to maximize the marginal log-likelihood log p ( X )
=
(cid:80)
Ni =1 log p ( x i )
where X = { x 1 , ..., x N } , the dataset.
While computing the marginal likelihood is intractable in nature, we can instead optimize the variational lower-bound:
[Equation]
where p ( z ) is chosen a prior, generally the multivariate normal distribution N (0 , I ) .
We deﬁne the posterior q ( z | X ) =
N ( z | µ ( X ) , σ 2 ( X ) I ) as the encoder and p ( X | z ) as the decoder.
Simply put, this means a VAE is an auto-encoder, where the a given sample x is passed through the encoder to produce a random latent vector z , which is given to the decoder to reconstruct the original sample x .
The VAE is trained on a reconstruction loss, and a KL-divergence term according to the distribution of the latent vectors.
To perform gradient descent on the variational lower bound we can use the re-parametrization trick (Kingma & Welling, 2013;
Rezende et al., 2014):
[Equation]
[Equation]
This formulation allows for back-propagation through stochastic nodes, by noting µ and σ can be represented by deterministic functions.
During inference, random values of z are sampled from the multivariate normal and passed through the decoder to produce samples x .