Search

Search papers and lessons

Off-Policy Deep Reinforcement Learning without Exploration

Scott Fujimoto, David Meger, Doina Precup · 2018

Fujimoto and colleagues show that standard deep RL fails when learning from a fixed batch of data, and propose BCQ, which picks only actions the data supports.

On this page

  • Colour = topic mix
  • Reinforcement learning
  • Probability
  • Calculus
  • Discrete math
  • Inference
  • Linear algebra
  • ReadReady to readNot yet

TL;DR

Off-policy reinforcement learning is supposed to learn from data gathered by other policies, but this paper shows that standard deep methods fail when they must learn from a fixed batch of logged transitions with no further interaction. The cause is extrapolation error: the value estimates for state-action pairs missing from the batch are arbitrary, and the policy then chases them. The authors propose batch-constrained Q-learning and its deep form, BCQ, which restricts the policy to actions that look like the ones in the batch. BCQ learns from fixed data on continuous control tasks where the baselines do not.

Builds on: Offline Reinforcement Learning, DDPG, Double Q-Learning, Variational Autoencoder · Leads to: later batch methods such as CQL and IQL, which tackle the same failure in other ways.

Why it mattered

Many useful settings give reinforcement learning a fixed log and no way to try new things. A carefully monitored program or a human operator produces the data, and running an exploring agent on a real system is often costly, risky or slow. The paper argues that learning from such a batch has to be a first-class problem, because it is the setting where data collection is the bottleneck.

The authors claim BCQ is the first continuous control deep RL algorithm that learns effectively from arbitrary fixed batch data. The surprising experimental result is that an off-policy agent trained on exactly the same data as its behavioural agent does far worse than that agent, in every trial of the concurrent experiment. The paper names the cause extrapolation error. Plain imitation of the logged behaviour is the obvious shortcut, as in behavioural cloning, and it is strong when the data is expert. The paper argues that imitation methods struggle when the data is suboptimal.

The problem

In the batch setting the agent sees a set of transitions (s,a,r,s′)(s, a, r, s') and cannot collect more. Deep Q-learning and actor-critic methods such as DDPG were designed for agents that gather their own data, and they were labelled off-policy because the update does not depend on which policy produced a transition. The paper's point is that this label hides a dependence on coverage.

When the agent updates a value estimate, it backs up the value of the next action it would choose. If that action is not in the batch, the value of that pair was never trained. The network's output there is an extrapolation from neighbouring data, and it can be arbitrarily wrong. The authors identify three ways this happens: absent data, a biased estimate of the dynamics from a finite batch, and a training mismatch, because transitions are sampled from the batch rather than from the policy's own distribution. Extrapolation error is not always positive, but the maximisation step in Q-learning turns it into a persistent overestimation bias, and nothing collects new data to correct it.

The experiments use the Hopper-v1 environment with three batches. In the final buffer batch, a DDPG agent is trained for a million steps with large exploration noise and its whole buffer is then used. In the concurrent batch, a behavioural agent and an off-policy agent learn from the same buffer. In the imitation batch, an expert policy supplies the data. The off-policy agent is far worse than its behavioural agent in every setting, even when the data is identical, and its value estimates are unstable or divergent. In the imitation batch, the agent quickly learns non-expert actions, which the paper attributes to optimistic extrapolation.

How it works

The input is a fixed batch B\mathcal{B} of transitions from some behaviour policy. Nothing else is available. The output is a policy that stays close to the data and improves on it where the data supports improvement.

flowchart LR
  B["Fixed batch of transitions"] --> V["VAE learns actions the batch takes in each state"]
  V --> C["Sample candidate actions at the next state"]
  C --> P["Small perturbation of each candidate"]
  P --> T["Target: weighted min and max over two Q-networks"]
  T --> Q["Update Q-networks and perturbation"]
  Q --> A["Pick the best candidate by Q at each state"]
  1. Start from the batch alone. Check: every action the agent will ever take must be justified by a transition in B\mathcal{B}, or it is an extrapolation.
  2. Learn which actions the data contains. A state-conditioned variational autoencoder Gω(s)G_\omega(s) is trained to reproduce the batch's actions given their states. Check: a sample from Gω(s)G_\omega(s) is an action similar to those the batch took in similar states.
  3. Sample candidates at the next state. For each sampled transition's next state s′s', draw nn candidate actions from the generator. The paper uses n=10n = 10 during training. Check: the candidates come from the data's distribution, not from the whole action range.
  4. Perturb each candidate a little. A perturbation network ξϕ\xi_\phi adds an adjustment in the range [−Φ,Φ][-\Phi, \Phi]. This reaches actions just outside the batch without sampling the generator a huge number of times. Check: no candidate moves by more than Φ\Phi.
  5. Build a pessimistic target. A pair of Q-networks gives two values for each perturbed candidate. The target takes a weighted mix of the smaller and the larger value, with more weight on the smaller one, and then the maximum over candidates. Check: when the two networks disagree about a candidate, the target leans on the lower estimate.
  6. Update the networks. The Q-networks regress to the target. The perturbation network is trained by the deterministic policy gradient to raise Qθ1Q_{\theta_1}, and the target networks follow the online networks slowly. Check: a candidate the Q-networks rate highly and the batch supports is favoured.
  7. Act. At a state, the policy draws nn candidates from the generator, perturbs them, and takes the one with the highest Qθ1Q_{\theta_1}. Check: the chosen action is close to the data and has high estimated value.

The paper notes that the choice of nn and Φ\Phi sets a trade-off. With Φ=0\Phi = 0 and n=1n = 1, the policy is simply behavioural cloning of the generator. As Φ\Phi grows to the full action range and nn grows large, the policy becomes ordinary Q-learning, with all its extrapolation.

A tiny trace of step 5 uses three candidates for clarity, where the paper uses ten. Suppose the two target networks give Q1=(4.0, 2.5, 3.0)Q_1 = (4.0,\ 2.5,\ 3.0) and Q2=(3.6, 2.8, 3.4)Q_2 = (3.6,\ 2.8,\ 3.4) for candidates a1,a2,a3a_1, a_2, a_3. With λ=0.75\lambda = 0.75 the per-candidate values are 0.75⋅3.6+0.25⋅4.0=3.700.75 \cdot 3.6 + 0.25 \cdot 4.0 = 3.70, 0.75⋅2.5+0.25⋅2.8=2.5750.75 \cdot 2.5 + 0.25 \cdot 2.8 = 2.575 and 0.75⋅3.0+0.25⋅3.4=3.100.75 \cdot 3.0 + 0.25 \cdot 3.4 = 3.10. The best is a1a_1 at 3.70. With reward r=1r = 1 and discount γ=0.99\gamma = 0.99 the target is 1+0.99⋅3.70=4.6631 + 0.99 \cdot 3.70 = 4.663. The lower estimate pulls the target down from what the larger network alone would give.

The math

The batch as an MDP

The Bellman operator for a policy π\pi is TπQ(s,a)=Es′[r+γQ(s′,π(s′))]\mathcal{T}^{\pi}Q(s,a) = \mathbb{E}_{s'}[r + \gamma Q(s', \pi(s'))], and Q-learning updates Q(s,a)←(1−α)Q(s,a)+α(r+γmax⁡a′Q(s′,a′))Q(s,a) \leftarrow (1-\alpha)Q(s,a) + \alpha(r + \gamma \max_{a'} Q(s',a')) from sampled transitions. In the batch setting the samples come from B\mathcal{B} rather than from the true dynamics. The paper builds an alternative MDP MBM_{\mathcal{B}} with the same states and actions. Its transition probabilities are the empirical frequencies in the batch,

pB(s′∣s,a)=N(s,a,s′)∑s~N(s,a,s~),p_{\mathcal{B}}(s' \mid s,a) = \frac{N(s,a,s')}{\sum_{\tilde s} N(s,a,\tilde s)},

where N(s,a,s′)N(s,a,s') counts how often the tuple occurs in B\mathcal{B}. A pair (s,a)(s,a) that never occurs in the batch leads to a terminal state whose reward is the initial value of Q(s,a)Q(s,a). Theorem 1 says that Q-learning on the batch converges to the optimal value of MBM_{\mathcal{B}}, not of the true MDP MM.

Extrapolation error, exactly

The error of a policy evaluated on the batch is the gap between its true value and its batch value,

ϵMDP(s,a)=Qπ(s,a)−QBπ(s,a).\epsilon_{\text{MDP}}(s,a) = Q^{\pi}(s,a) - Q^{\pi}_{\mathcal{B}}(s,a).

Lemma 1 says that the weighted size of this error over the states and actions the policy actually visits, written ϵMDPπ=∑sμπ(s)∑aπ(a∣s) ∣ϵMDP(s,a)∣\epsilon^{\pi}_{\text{MDP}} = \sum_s \mu_\pi(s) \sum_a \pi(a \mid s)\,|\epsilon_{\text{MDP}}(s,a)|, is zero exactly when the batch's transition probabilities match the true ones wherever μπ(s)>0\mu_\pi(s) > 0 and π(a∣s)>0\pi(a \mid s) > 0. For a deterministic MDP, one observed transition is enough to match the true dynamics. That gives the key definition. A policy is batch-constrained if every state-action pair it can visit, with positive probability, is in B\mathcal{B}. Theorem 2 then says that for a deterministic MDP, the error is zero if and only if the policy is batch-constrained. A batch is coherent if every transition in it leads to a state that is also in the batch, unless that state is terminal. A coherent batch guarantees that such a policy exists when the start state is in the batch.

Batch-constrained Q-learning

The tabular algorithm restricts the maximum in the update to actions that are in the batch,

Q(s,a)←(1−α) Q(s,a)+α(r+γmax⁡a′ : (s′,a′)∈BQ(s′,a′)).Q(s,a) \leftarrow (1-\alpha)\,Q(s,a) + \alpha\Big(r + \gamma \max_{a' \,:\, (s',a') \in \mathcal{B}} Q(s',a')\Big).

Theorem 4 states that, for a deterministic MDP and a coherent batch, this converges to the optimal batch-constrained policy. The paper's consequence is that such a policy is guaranteed to do at least as well as the behavioural policy from any state in the batch.

The deep version

The deep policy takes nn candidates from the generator and perturbs them,

π(s)=arg⁡max⁡ai+ξϕ(s,ai,Φ)Qθ(s, ai+ξϕ(s,ai,Φ)),ai∼Gω(s), i=1,…,n.\pi(s) = \arg\max_{a_i + \xi_\phi(s, a_i, \Phi)} Q_\theta\big(s,\ a_i + \xi_\phi(s, a_i, \Phi)\big), \qquad a_i \sim G_\omega(s),\ i = 1, \dots, n.

The perturbation ξϕ\xi_\phi is limited to [−Φ,Φ][-\Phi, \Phi], which the paper implements with a tanh output scaled by Φ\Phi. The value target for the Q-networks uses the pessimism weight λ\lambda, which the paper sets to 0.75,

y=r+γmax⁡a~i[λmin⁡j=1,2Qθj′(s′,a~i)+(1−λ)max⁡j=1,2Qθj′(s′,a~i)],a~i=ai+ξϕ′(s′,ai,Φ),y = r + \gamma \max_{\tilde a_i}\Big[\lambda \min_{j=1,2} Q_{\theta'_j}(s', \tilde a_i) + (1-\lambda)\max_{j=1,2} Q_{\theta'_j}(s', \tilde a_i)\Big], \qquad \tilde a_i = a_i + \xi_{\phi'}(s', a_i, \Phi),

where ai∼Gω(s′)a_i \sim G_\omega(s') and θj′\theta'_j, ϕ′\phi' are target parameters. With λ=1\lambda = 1 this is the clipped double Q-learning target of Fujimoto and colleagues, which takes the minimum of two networks to reduce overestimation. Lowering λ\lambda below 1 blends in the larger estimate. The paper says λ\lambda controls how heavily uncertainty at future steps is penalised, and it uses 0.75 throughout.

The generator is a conditional variational autoencoder. Its encoder outputs a mean μ\mu and standard deviation σ\sigma for a latent vector z=μ+σϵz = \mu + \sigma\epsilon with ϵ∼N(0,I)\epsilon \sim \mathcal{N}(0, I), and its decoder reconstructs the action from the state and zz. The training loss is a reconstruction term ∑(D(s,z)−a)2\sum (D(s,z) - a)^2 plus a Kullback-Leibler term that keeps the latent distribution near a standard normal. The paper reuses the letter for the KL weight in the VAE loss, where λ=12J\lambda = \frac{1}{2J} and JJ is the size of the latent vector. That is a different quantity from the target weighting above. The perturbation network is trained to maximise the first Q-network along sampled candidates,

ϕ←arg⁡max⁡ϕ∑(s,a)∈BQθ1(s, a+ξϕ(s,a,Φ)),a∼Gω(s).\phi \leftarrow \arg\max_\phi \sum_{(s,a)\in\mathcal{B}} Q_{\theta_1}\big(s,\ a + \xi_\phi(s,a,\Phi)\big), \quad a \sim G_\omega(s).

Results

The paper reports its main comparison as learning curves rather than a table of scores, so this lesson states the claims and the experimental settings without quoting curve values.

Batch tasks. The paper compares BCQ with DDPG, DQN with a discretised action space, behavioural cloning, and a VAE-only cloning variant. It states that BCQ is the only algorithm that succeeds at all tasks, matching or outperforming the behavioural policy in each one. Behavioural cloning is best on the pure imitation task, which the paper says is expected because that task contains only expert data. Its value estimates for BCQ are stable, while the DDPG and DQN value estimates are unstable or divergent in the same tasks.

Imperfect demonstrations. A batch of 100,000 transitions from an expert with random actions on 30 percent of steps and extra Gaussian noise on the rest is a harder test. The paper reports that the deep RL and imitation baselines both perform poorly there, and that BCQ strongly outperforms the noisy demonstrator. It also reports that BCQ reaches high performance in far fewer iterations than deep RL methods typically need.

Ablation. Increasing the perturbation range Φ\Phi lowers performance on the imitation task and makes the value function less stable, which fits the account of extrapolation error. The appendix also tries ensembles of 4 and 10 value networks as an uncertainty signal. The ensembles stabilise the value function but do not restrict the actions to the expert's, and they cost more computation.

Random data. On two small tasks, Pendulum and a two-joint Reacher, a batch of 5,000 steps from a random behavioural policy is enough for both BCQ and DDPG to learn. The paper notes that imitation methods need expert data, so they cannot use a batch like this one.

Limits.

  • All the continuous control experiments are simulated, on OpenAI Gym tasks with MuJoCo physics (Hopper, HalfCheetah, Walker2d and others).
  • Results are averaged over 5 random seeds for the behavioural policy, simulator and networks, so spread across seeds is not characterised in the text.
  • The theory covers deterministic MDPs. For a stochastic MDP the paper notes that the batch may need infinitely many samples to match the true transitions.
  • The paper says BCQ is only one way to approach batch-constrained learning in a deep setting, and it does not claim the method is the final answer.

Reading guide

Read the paper in this order. The right column names the lessons on this site that cover what each section assumes.

SectionWhat it coversLessons to have in hand
1 IntroductionWhy batch learning matters, and why imitation and off-policy learning both fall shortOffline Reinforcement Learning, Behavior Cloning
2 BackgroundMDPs, the return, the Bellman operator, DQN targets, DDPG and the deterministic policy gradientMarkov Decision Process, Bellman Equation, Deep Q-Network, Deterministic Policy Gradient
3 Extrapolation errorThe three causes, and DDPG on the Hopper batchesTarget Network, Experience Replay, Overestimation Bias
4.1 Finite MDPsThe batch MDP, Lemma 1, batch-constrained policies, BCQLTemporal-Difference Learning, Q-Learning
4.2 Deep BCQThe generator, perturbation, pessimistic target and Algorithm 1Variational Autoencoder, Double Q-Learning, Actor-Critic Methods
5 ExperimentsBaselines, batch comparisons and imperfect demonstrationsDeep Deterministic Policy Gradient (DDPG)
6 Related workBatch RL, imitation, uncertainty, conservative updatesOffline Reinforcement Learning
Appendix AProofs for the finite MDP resultsBellman Equation
Appendices D to GAblations, the random behavioural study, and implementation detailsVariational Autoencoder, Target Network

Check yourself

QuestionWhat is extrapolation error, and why does a maximising Q-learning update make it harmful?Show answer
Extrapolation error is the error in a value estimate for a state-action pair that is missing from the batch, where the network has no data and its output is an arbitrary extension of nearby data. A Q-learning update backs up the largest value at the next state, so an unseen action whose value is overestimated gets chosen, and its inflated value is copied backwards. The error then feeds back into the values that follow, and because nothing collects new data, it is never corrected.
QuestionUsing the candidate values from the tiny trace, Q1 = (4.0, 2.5, 3.0) and Q2 = (3.6, 2.8, 3.4), with reward r = 1 and discount 0.99, what is the target if lambda is 0.5 instead of 0.75?Show answer
With λ=0.5\lambda = 0.5 the per-candidate values are 0.5⋅3.6+0.5⋅4.0=3.800.5 \cdot 3.6 + 0.5 \cdot 4.0 = 3.80, 0.5⋅2.5+0.5⋅2.8=2.650.5 \cdot 2.5 + 0.5 \cdot 2.8 = 2.65, and 0.5⋅3.0+0.5⋅3.4=3.200.5 \cdot 3.0 + 0.5 \cdot 3.4 = 3.20. The maximum is 3.80, so the target is 1+0.99⋅3.80=4.7621 + 0.99 \cdot 3.80 = 4.762. This is higher than the 4.663 at λ=0.75\lambda = 0.75, because a lower weight on the minimum gives more weight to the larger of the two estimates.
QuestionWhy does BCQ restrict the policy to actions the generator proposes near the batch, rather than letting the Q-network choose the best action over the full action range?Show answer
The Q-network's values for actions far from the batch are extrapolations, so the policy would select exactly the actions where the values are least reliable. Restricting the choice to candidates near the data means the policy only chooses actions whose values are backed by transitions in the batch. The restriction is what the theory in Section 4.1 calls batch-constrained, and it is the mechanism that removes extrapolation error for deterministic MDPs.
QuestionA logistics company has a year of logs from a human dispatcher, with no ability to run new experiments, and wants a policy that improves on the dispatcher. What would you check before using BCQ, and what would you expect to happen with a noisy dispatcher?Show answer
I would check that the logged state-action pairs cover the decisions the new policy would make, since the batch-constrained guarantee only holds for pairs in the data, and that the environment is close to deterministic, since the theory is for that case. I would also check whether the dispatcher's errors are noisy. The paper's imperfect-demonstrations results suggest that BCQ can outperform a noisy demonstrator, while plain imitation has no way to separate the expert's good actions from its mistakes, but this is evidence from simulation and does not guarantee the same result on dispatch logs.

Sources

Read the full paper

Scott Fujimoto, David Meger, Doina Precup, 2018. arXiv:1812.02900