Simple Algorithm
Reinforcement Learning · Fixed Point · 28 min

Deterministic Policy Gradients: DDPG & TD3

The DPG theorem, its deep version, and three fixes for overestimation.

A policy that never randomizes has no score function, so the likelihood-ratio machinery of policy gradients seems not to apply. Silver et al. (2014) showed that it is not needed: a deterministic policy's return has a gradient, given by the chain rule through the critic; it is the zero-noise limit of the stochastic policy gradient; and it can be estimated off-policy without importance sampling. This lesson proves the theorem, builds compatible critics for deterministic actors, then follows the deep version from DDPG's overestimation to TD3's three fixes and their successors.

What you’ll learn

  • State and prove the deterministic policy gradient theorem, and explain its relation to stochastic policy gradients as the noise vanishes, including what happens to the variance of the two estimators.
  • Derive the off-policy deterministic actor–critic and the compatible critic Qw(s,a)=(a−μθ(s))⊤∇θμθ(s)⊤w+V(s)Q^{\mathbf w}(s,a)=\big(a-\mu_{\boldsymbol\theta}(s)\big)^\top\nabla_{\boldsymbol\theta}\mu_{\boldsymbol\theta}(s)^\top\mathbf w+V(s), whose weights are the natural deterministic policy gradient.
  • Reproduce the argument that an actor trained on an approximate critic overestimates, and explain how each of TD3's fixes responds, including the underestimation that clipped double Q-learning introduces.
  • Summarize what is known about the brittleness of deep deterministic actor–critics, and the ensemble and distributional critics that followed TD3.

The deterministic policy gradient theorem

Take continuous actions A⊆Rd\mathcal A\subseteq\R^d and a deterministic policy μθ:S→A\mu_{\boldsymbol\theta}:\mathcal S\to\mathcal A (Silver et al.'s notation; the start distribution is written ν\nu in this lesson). The return is J(θ)=ES0∼ν[Vμθ(S0)]=11−γES∼dνμθ[r(S,μθ(S))]J(\boldsymbol\theta)=\E_{S_0\sim\nu}\big[V^{\mu_{\boldsymbol\theta}}(S_0)\big]=\frac{1}{1-\gamma}\E_{S\sim d^{\mu_{\boldsymbol\theta}}_\nu}\big[r(S,\mu_{\boldsymbol\theta}(S))\big]. The parameters move the action in every state and, through it, every later state, so a gradient seems to need the derivative of the state distribution. It does not.

DerivationProof sketch: differentiate the Bellman equation, then unroll
  1. Vμ(s)=Qμ(s,μ(s))=r(s,μ(s))+γ∫P(s′∣s,μ(s)) Vμ(s′) ds′V^\mu(s)=Q^\mu\big(s,\mu(s)\big)=r\big(s,\mu(s)\big)+\gamma\int P\big(s'\mid s,\mu(s)\big)\,V^\mu(s')\,ds'

    Write μ=μθ\mu=\mu_{\boldsymbol\theta}. The value of a deterministic policy is its action value at its own action:

  2. ∇θVμ(s)=∇θμ(s) ∇aQμ(s,a)∣a=μ(s)⏟h(s)+γ∫P(s′∣s,μ(s)) ∇θVμ(s′) ds′\nabla_{\boldsymbol\theta}V^\mu(s)=\underbrace{\nabla_{\boldsymbol\theta}\mu(s)\,\nabla_aQ^\mu(s,a)\big|_{a=\mu(s)}}_{h(s)}+\gamma\int P\big(s'\mid s,\mu(s)\big)\,\nabla_{\boldsymbol\theta}V^\mu(s')\,ds'

    The parameters enter through the action in the first two places and through Vμ(s′)V^\mu(s') in the third. The chain rule collects the first two into ∇aQμ\nabla_aQ^\mu, since Qμ(s,a)=r(s,a)+γ∫P(s′∣s,a)Vμ(s′) ds′Q^\mu(s,a)=r(s,a)+\gamma\int P(s'\mid s,a)V^\mu(s')\,ds':

  3. ∇θVμ(s)=∑t≥0γt E[h(St) ∣ S0=s]\nabla_{\boldsymbol\theta}V^\mu(s)=\sum_{t\ge0}\gamma^t\,\E\big[h(S_t)\,\big|\,S_0=s\big]

    This is a Bellman equation for ∇θVμ\nabla_{\boldsymbol\theta}V^\mu with "reward" hh. Unrolling it, which the regularity conditions justify, sums hh along the policy's own trajectory:

  4. Average over S0∼νS_0\sim\nu; by definition of the normalized discounted distribution, ∑tγtE[h(St)]=11−γEdνμ[h]\sum_t\gamma^t\E[h(S_t)]=\frac{1}{1-\gamma}\E_{d^\mu_\nu}[h]. ■\blacksquare The derivative of the state distribution never appears because it is absorbed into the recursion, exactly as in the stochastic theorem.

Silver et al. (Theorem 2) also show the two theorems are one. Let πθ,σ(⋅∣s)=qσ(⋅ ;μθ(s))\pi_{\boldsymbol\theta,\sigma}(\cdot\mid s)=q_\sigma\big(\cdot\,;\mu_{\boldsymbol\theta}(s)\big) be stochastic policies whose densities concentrate on μθ(s)\mu_{\boldsymbol\theta}(s) as σ↓0\sigma\downarrow0, Gaussians among them. Under further regularity conditions, lim⁡σ↓0∇J(πθ,σ)=∇J(μθ)\lim_{\sigma\downarrow0}\nabla J(\pi_{\boldsymbol\theta,\sigma})=\nabla J(\mu_{\boldsymbol\theta}). The gradients agree in the limit. Their estimators do not.

Predict before you look

For a one-dimensional Gaussian policy with mean mm and standard deviation σ=0.1\sigma=0.1, what is the variance of the score ∂log⁡π(a∣s)/∂m=(a−m)/σ2\partial\log\pi(a\mid s)/\partial m=(a-m)/\sigma^2 under the policy?

Show the answer

100

Var⁡[(a−m)/σ2]=σ2/σ4=1/σ2=100\Var\big[(a-m)/\sigma^2\big]=\sigma^2/\sigma^4=1/\sigma^2=100. A likelihood-ratio estimator multiplies returns by this score, so its variance grows without bound as exploration shrinks, even though its expectation converges to the deterministic gradient. The deterministic estimator has no score at all. On a continuous bandit with a quadratic cost, Silver et al. found the deterministic actor–critic's advantage over a stochastic one growing with the action dimension (10, 25 and 50).

Off-policy learning and compatible critics

Let a stochastic behavior policy bb generate the data, with discounted state distribution dνbd^b_\nu, and evaluate the deterministic target policy on those states, Jb(θ)=ES∼dνb[Vμθ(S)]J_b(\boldsymbol\theta)=\E_{S\sim d^b_\nu}\big[V^{\mu_{\boldsymbol\theta}}(S)\big]. Dropping the term that differentiates QμθQ^{\mu_{\boldsymbol\theta}} itself, as Degris, White and Sutton's off-policy actor–critic does for stochastic policies, gives the off-policy deterministic policy gradient:

∇Jb(θ) ≈ ES∼dνb[∇θμθ(S)  ∇aQμθ(S,a)∣a=μθ(S)]\nabla J_b(\boldsymbol\theta)\ \approx\ \E_{S\sim d^b_\nu}\Big[\nabla_{\boldsymbol\theta}\mu_{\boldsymbol\theta}(S)\;\nabla_aQ^{\mu_{\boldsymbol\theta}}(S,a)\big|_{a=\mu_{\boldsymbol\theta}(S)}\Big]
No integral over actions, so no importance weight on the actor. With a Q-learning critic, whose target r+γQ(s′,μθ(s′))r+\gamma Q(s',\mu_{\boldsymbol\theta}(s')) needs no weight either, this is the off-policy deterministic actor–critic (OPDAC).
DerivationProof
  1. E[∇θμθ(S) ϵ(S)]=0,ϵ(s)=∇aQw(s,a)∣a=μθ(s)−∇aQμ(s,a)∣a=μθ(s)\E\Big[\nabla_{\boldsymbol\theta}\mu_{\boldsymbol\theta}(S)\,\boldsymbol\epsilon(S)\Big]=\mathbf 0,\qquad\boldsymbol\epsilon(s)=\nabla_aQ^{\mathbf w}(s,a)\big|_{a=\mu_{\boldsymbol\theta}(s)}-\nabla_aQ^{\mu}(s,a)\big|_{a=\mu_{\boldsymbol\theta}(s)}

    Let ϵ(s)\boldsymbol\epsilon(s) be the error in the action gradient. By condition 1, ∇wϵ(s)⊤=∇θμθ(s)\nabla_{\mathbf w}\boldsymbol\epsilon(s)^\top=\nabla_{\boldsymbol\theta}\mu_{\boldsymbol\theta}(s), so the least-squares optimality condition of (2) reads

  2. E[∇θμθ(S) ∇aQw(S,a)∣a=μθ(S)]=E[∇θμθ(S) ∇aQμ(S,a)∣a=μθ(S)]\E\Big[\nabla_{\boldsymbol\theta}\mu_{\boldsymbol\theta}(S)\,\nabla_aQ^{\mathbf w}(S,a)\big|_{a=\mu_{\boldsymbol\theta}(S)}\Big]=\E\Big[\nabla_{\boldsymbol\theta}\mu_{\boldsymbol\theta}(S)\,\nabla_aQ^{\mu}(S,a)\big|_{a=\mu_{\boldsymbol\theta}(S)}\Big]

    Rearranged, the critic's action gradient has the same projection onto the actor's Jacobian as the true one, which is all the gradient formula uses. ■\blacksquare

The compatible critic is linear in a−μθ(s)a-\mu_{\boldsymbol\theta}(s): a local model of the advantage of deviating from the policy's action, with features ∇θμθ(s)(a−μθ(s))\nabla_{\boldsymbol\theta}\mu_{\boldsymbol\theta}(s)(a-\mu_{\boldsymbol\theta}(s)). As a global model of QQ it is useless (it diverges for large deviations), but the gradient only looks at the slope at a=μθ(s)a=\mu_{\boldsymbol\theta}(s). It parallels the stochastic case (Compatible Features & Two-Timescale Actor–Critic), including the natural gradient: with the metric M(θ)=E[∇θμθ(S)∇θμθ(S)⊤]M(\boldsymbol\theta)=\E\big[\nabla_{\boldsymbol\theta}\mu_{\boldsymbol\theta}(S)\nabla_{\boldsymbol\theta}\mu_{\boldsymbol\theta}(S)^\top\big], the limit of the Fisher information as the policy's variance shrinks (up to scale), the compatible weights are the natural deterministic policy gradient: M−1∇J∝wM^{-1}\nabla J\propto\mathbf w, so the actor can simply step along w\mathbf w.

In practice the critic's weights are learned by TD methods, which do not minimize the error in condition 2, so the gradient is only approximately exact. Silver et al.'s COPDAC-GQ uses a gradient-TD critic (gradient Q-learning) on a faster timescale than the actor, which converges to the minimizer of the projected Bellman error under step-size conditions, where off-policy linear Q-learning may diverge.

Check your understanding

The compatible critic is linear in the action deviation a−μθ(s)a-\mu_{\boldsymbol\theta}(s), while true action values are far from linear in aa. Why does it still give the exact gradient?

  1. Because true action values become linear in aa once the policy is optimal
  2. Because the deterministic gradient uses the critic only through its action gradient at a=μθ(s)a=\mu_{\boldsymbol\theta}(s), and the least-squares fit matches that slope where the actor's Jacobian can see it
  3. Because the baseline V(s)V(s) absorbs all the nonlinearity
  4. It does not: compatibility only reduces the gradient's variance
Show the answer

B. Because the deterministic gradient uses the critic only through its action gradient at a=μθ(s)a=\mu_{\boldsymbol\theta}(s), and the least-squares fit matches that slope where the actor's Jacobian can see it

Only ∇aQ\nabla_aQ at the policy's own action enters ∇θμ ∇aQ\nabla_{\boldsymbol\theta}\mu\,\nabla_aQ, and only through its projection onto the columns of ∇θμ\nabla_{\boldsymbol\theta}\mu. A linear model in the deviation can match that slope exactly; its values far from μθ(s)\mu_{\boldsymbol\theta}(s) never matter.

Why an actor overestimates

DDPG (Lillicrap et al., 2016) is the off-policy deterministic actor–critic with deep networks and DQN's stabilizers: replay, slowly tracking target networks, batch normalization, and Ornstein–Uhlenbeck exploration noise. Its authors noted that nonlinear function approximation nullifies any convergence guarantee. Fujimoto, van Hoof and Meger (2018) isolated one specific failure, an actor-critic version of overestimation bias. Write QϕQ_\phi for the critic and QμQ^\mu for the true action values of the current actor μθ\mu_{\boldsymbol\theta}.

DerivationProof
  1. E[Qϕ(s,μapprox(s))]≥E[Qϕ(s,μtrue(s))],E[Qμ(s,μtrue(s))]≥E[Qμ(s,μapprox(s))]\E\big[Q_\phi(s,\mu_{\text{approx}}(s))\big]\ge\E\big[Q_\phi(s,\mu_{\text{true}}(s))\big],\qquad\E\big[Q^\mu(s,\mu_{\text{true}}(s))\big]\ge\E\big[Q^\mu(s,\mu_{\text{approx}}(s))\big]

    Each update is, to first order, the steepest ascent direction of its own objective. So for steps small enough, the approximate update is at least as good by the critic as the true one, and the true update is at least as good in truth as the approximate one:

  2. E[Qϕ(s,μapprox(s))]≥E[Qϕ(s,μtrue(s))]≥E[Qμ(s,μtrue(s))]≥E[Qμ(s,μapprox(s))]\E\big[Q_\phi(s,\mu_{\text{approx}}(s))\big]\ge\E\big[Q_\phi(s,\mu_{\text{true}}(s))\big]\ge\E\big[Q^\mu(s,\mu_{\text{true}}(s))\big]\ge\E\big[Q^\mu(s,\mu_{\text{approx}}(s))\big]

    Chain the two inequalities through the assumption. ■\blacksquare

The argument is local and per update, but its consequence compounds. A small overestimate in each update is copied into the critic's targets by bootstrapping, and a wrong critic produces poor policy updates, which make the targets worse: a feedback loop. On Hopper and Walker2d the authors measured DDPG's average value estimate climbing far above the true return. It is maximization bias again, with a gradient step on the critic playing the role of the max (Maximization Bias & Double Q-Learning). The widget shows the tabular version, and the price of the cure.

TD3, precisely

Double estimators need two independent estimates. Double DQN's recipe, choosing with the current actor and evaluating with the target critic, failed in actor–critic form: with a slowly changing policy the current and target networks were too similar. Two full actor–critic pairs, each critic evaluating the other's actor, reduced the bias but did not remove it, since the critics share a replay buffer and each other's targets. TD3 instead keeps one actor and caps the target at the smaller of two critics, clipped double Q-learning:

y=r+γ min⁡i=1,2Qϕi′(s′,a~),a~=μθ′(s′)+clip⁡(ε,−c,c),ε∼N(0,σ~2)y=r+\gamma\,\min_{i=1,2}Q_{\phi_i'}\big(s',\tilde a\big),\qquad\tilde a=\mu_{\boldsymbol\theta'}(s')+\operatorname{clip}\big(\varepsilon,-c,c\big),\quad\varepsilon\sim\mathcal N(0,\tilde\sigma^2)
Both critics regress on the same target; σ~=0.2\tilde\sigma=0.2 and c=0.5c=0.5 in the paper. The minimum can underestimate, which the authors accept: an underestimated action is simply not chosen by the actor, so the error is not reinforced, while an overestimated one is actively sought out.

Delayed policy updates. With target networks the critic's error shrinks over several updates, while actor updates taken on high-error estimates can make the values diverge. TD3 therefore updates the actor and the target networks once every d=2d=2 critic updates.

Target policy smoothing. A deterministic actor can overfit narrow peaks of the critic. The ideal target averages over a neighborhood of the target action, y=r+γEε[Qϕ′(s′,μθ′(s′)+ε)]y=r+\gamma\E_\varepsilon\big[Q_{\phi'}(s',\mu_{\boldsymbol\theta'}(s')+\varepsilon)\big], enforcing that similar actions have similar values; one clipped noise sample per target approximates it. The result resembles expected SARSA for a noisy version of the target policy, and, like SARSA, favors actions that are robust to perturbation.

Variant (TD3 paper, Table 2)HalfCheetahHopperWalker2dAnt
TD39533330545654185
without clipped double Q979318372579850
without delayed updates9591240746963754
without target smoothing8988239340344155
none of the three (TD3's architecture and settings)840110622362564
DDPG as published316317321521816
Average return over the last 10 evaluations of 10 trials of one million steps. Single fixes added to the tuned DDPG mostly helped little; combinations helped much more. Removing clipped double Q hurt most on Hopper, Walker2d and Ant, yet slightly raised the HalfCheetah score: the importance of each component varies by task. With 10 trials, read differences of a few hundred with caution.

Brittleness, and what came after

Deep deterministic actor–critics remain sensitive. Henderson et al. (2018) showed that results for DDPG and other continuous-control algorithms swing with hyperparameters, network architecture, reward scaling, codebase and random seeds: ten runs of one algorithm with one configuration (TRPO on HalfCheetah), split into two groups of five seeds, gave statistically different learning curves. A deterministic actor also explores only through noise added from outside, which TD3 keeps simple (Gaussian, standard deviation 0.1, after 1,000 to 10,000 purely random steps).

Later methods tuned the pessimism more finely. D4PG (Barth-Maron et al., 2018) gave DDPG a distributional critic, nn-step returns, prioritized replay and distributed actors. TQC (Kuznetsov, Shvechikov, Grishin & Vetrov, 2020) mixes several distributional critics and drops the highest quantiles of their pooled prediction, a dial for overestimation rather than TD3's all-or-nothing minimum. REDQ (Chen, Wang, Zhou & Ross, 2021) takes the minimum over a random subset of a large ensemble of critics, which allows many gradient updates per environment step, and reported sample efficiency matching a state-of-the-art model-based method on MuJoCo. SAC (Maximum-Entropy RL & Soft Actor–Critic) kept TD3's twin critics but replaced the deterministic actor by a stochastic one.

Key takeaways

  • ∇J=11−γEdμ[∇θμθ∇aQμ∣a=μθ]\nabla J=\frac{1}{1-\gamma}\E_{d^{\mu}}\big[\nabla_{\boldsymbol\theta}\mu_{\boldsymbol\theta}\nabla_aQ^{\mu}|_{a=\mu_{\boldsymbol\theta}}\big] follows by differentiating the Bellman equation and unrolling; it is the zero-noise limit of the stochastic policy gradient, whose likelihood-ratio estimator has variance growing like 1/σ21/\sigma^2.
  • Off-policy, the actor needs no importance weights; a compatible critic (a−μθ(s))⊤∇θμθ(s)⊤w+V(s)\big(a-\mu_{\boldsymbol\theta}(s)\big)^\top\nabla_{\boldsymbol\theta}\mu_{\boldsymbol\theta}(s)^\top\mathbf w+V(s) fitted by least squares on action gradients makes the gradient exact, and its weights are the natural deterministic gradient.
  • An actor climbing an approximate critic yields a policy its critic overestimates whenever the critic does not underestimate the true step (Fujimoto et al., 2018); bootstrapping compounds the bias.
  • TD3 caps targets at the minimum of two critics (convergent in the tabular case, biased low), delays actor updates and smooths target actions; the components interact and their value varies by task.
  • Successors tune the pessimism more finely (distributional critics with truncation, randomized ensembles), and deep deterministic actor–critics remain sensitive to seeds and hyperparameters.

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

A Gaussian policy's standard deviation σ\sigma is sent to zero. What happens to the stochastic policy gradient and to its likelihood-ratio estimator?

  1. Both converge to the deterministic policy gradient, with vanishing variance
  2. The gradient diverges, which is why deterministic policies need a separate theorem
  3. The gradient converges to the deterministic policy gradient, but the estimator's variance grows like 1/σ21/\sigma^2, because the score (a−m)/σ2(a-m)/\sigma^2 blows up
  4. The gradient converges to zero, because a deterministic policy cannot be improved
Show the answer

C. The gradient converges to the deterministic policy gradient, but the estimator's variance grows like 1/σ21/\sigma^2, because the score (a−m)/σ2(a-m)/\sigma^2 blows up

Silver et al.'s Theorem 2 gives the limit of the gradients. The estimator is a different matter: its score has variance 1/σ21/\sigma^2 per dimension, so sampling it becomes hopeless exactly where the deterministic estimator, which differentiates the critic instead, works best.

Question 2

Which two conditions make a critic QwQ^{\mathbf w} compatible with a deterministic actor μθ\mu_{\boldsymbol\theta}?

  1. QwQ^{\mathbf w} is a neural network, and it is trained by TD learning with target networks
  2. Qw=QμQ^{\mathbf w}=Q^{\mu} everywhere, and the actor is linear
  3. Its action gradient at the actor's action is linear in the actor's Jacobian, ∇aQw∣a=μθ(s)=∇θμθ(s)⊤w\nabla_aQ^{\mathbf w}|_{a=\mu_{\boldsymbol\theta}(s)}=\nabla_{\boldsymbol\theta}\mu_{\boldsymbol\theta}(s)^\top\mathbf w, and w\mathbf w minimizes the squared error of that action gradient
  4. Its features are the score functions ∇θlog⁡πθ(a∣s)\nabla_{\boldsymbol\theta}\log\pi_{\boldsymbol\theta}(a\mid s)
Show the answer

C. Its action gradient at the actor's action is linear in the actor's Jacobian, ∇aQw∣a=μθ(s)=∇θμθ(s)⊤w\nabla_aQ^{\mathbf w}|_{a=\mu_{\boldsymbol\theta}(s)}=\nabla_{\boldsymbol\theta}\mu_{\boldsymbol\theta}(s)^\top\mathbf w, and w\mathbf w minimizes the squared error of that action gradient

These are the conditions of Silver et al.'s Theorem 3. The least-squares condition makes the critic's slope match the true slope where the actor's Jacobian looks, which is all the gradient uses; QwQ^{\mathbf w} may be wrong everywhere else.

Question 3

Fujimoto et al.'s argument concludes that the policy an actor–critic produces is overestimated by its own critic. Which assumption does it need?

  1. That the critic's errors are zero-mean noise independent of the action
  2. That the critic does not underestimate, in expectation, the value of the policy the true gradient step would produce, and that the step size is small
  3. That the environment is deterministic
  4. That the actor is linear in its parameters
Show the answer

B. That the critic does not underestimate, in expectation, the value of the policy the true gradient step would produce, and that the step size is small

The proof chains three inequalities: the approximate step is best by the critic, the true step is best in truth (both for small steps), and the critic is at least the truth at the true step's policy. Nothing else is assumed, which is why the effect is so general.

Question 4

What did TD3's ablation study show about its three components?

  1. Target policy smoothing alone recovers most of TD3's performance on every task
  2. Each component alone improves every task substantially
  3. Delayed policy updates hurt performance, since the actor trains half as often
  4. Single components mostly helped little, combinations helped much more, and their importance varied by task; removing clipped double Q hurt Hopper, Walker2d and Ant badly but not HalfCheetah
Show the answer

D. Single components mostly helped little, combinations helped much more, and their importance varied by task; removing clipped double Q hurt Hopper, Walker2d and Ant badly but not HalfCheetah

The components interact. The ablation is a warning against attributing an algorithm's gains to one mechanism on the basis of a few tasks, and with 10 trials per entry, small differences are noise.

Further reading

  • D. Silver, G. Lever, N. Heess, T. Degris, D. Wierstra & M. Riedmiller, "Deterministic policy gradient algorithms," ICML (2014).
  • T. P. Lillicrap, J. J. Hunt, A. Pritzel, N. Heess, T. Erez, Y. Tassa, D. Silver & D. Wierstra, "Continuous control with deep reinforcement learning," ICLR (2016).
  • S. Fujimoto, H. van Hoof & D. Meger, "Addressing function approximation error in actor-critic methods," ICML (2018).
  • P. Henderson, R. Islam, P. Bachman, J. Pineau, D. Precup & D. Meger, "Deep reinforcement learning that matters," AAAI (2018).
  • X. Chen, C. Wang, Z. Zhou & K. Ross, "Randomized ensembled double Q-learning: Learning fast without a model," ICLR (2021).