Search

Search papers and lessons

Deep Deterministic Policy Gradient (DDPG)

Level 3 · 9 min read

DDPG trains a deterministic actor and a Q-critic together, using replay and slowly moving target networks, to control continuous actions.

On this page

  • Colour = topic mix
  • Reinforcement learning
  • Calculus
  • Probability
  • Linear algebra
  • Discrete math
  • Neural network basics
  • Sign in to see your progress

TL;DR

DDPG learns a policy that outputs one continuous action per state, along with a critic that scores state-action pairs. The actor is improved by following the critic's gradient with respect to the action. It uses the replay buffer and target networks from the deep Q-network, so it can learn from stored experience. It is the standard way to apply deep reinforcement learning to continuous control, such as torques on a robot arm.

Where you'll see it: simulated robot control, where the action is a vector of joint torques, and any continuous-action task where a discrete max over actions is impractical.

Intuition

Think of a driver and a coach. The driver (the actor) decides how hard to turn the wheel. The coach (the critic) watches the result and says how much better or worse the outcome was. The coach does not just score the outcome. The coach also says which direction to move the wheel to do better. The driver takes that advice and adjusts, and the coach keeps learning from the driver's new results.

Why is this needed? In Q-learning the policy is "take the action with the largest QQ". With a discrete set of actions that is a quick lookup. With continuous actions, such as a torque in the range from minus one to one, finding the largest QQ needs an optimisation at every step. DDPG avoids that search by learning an actor that outputs the best action directly, and it trains the actor using the critic's gradient.

The result is a deterministic policy: for a given state it always outputs the same action. That keeps the update cheap and low-variance. The cost is that exploration has to be added by hand, usually as noise on the action during training.

flowchart LR
  S["State s"] --> A["Actor mu(s) outputs action a"]
  A --> Q["Critic Q(s, a) scores it"]
  Q --> G["Gradient of Q with respect to a"]
  G --> A
  R["Replay buffer"] --> Q
  R --> A

The math

Setup

Write the actor as a deterministic map μθ:S→A\mu_\theta : \mathcal{S} \to \mathcal{A} from states to actions, with parameters θ\theta. Write the critic as Qw(s,a)Q_w(s, a) with parameters ww. A stored transition is (s,a,r,s′)(s, a, r, s'), meaning the agent took action aa in state ss, received reward rr and landed in s′s'. The discount factor is γ∈[0,1)\gamma \in [0, 1).

The actor is trained to maximise the expected return

J(θ)=Es[Qw(s,μθ(s))],J(\theta) = \mathbb{E}_{s}\big[ Q_w(s, \mu_\theta(s)) \big],

where the expectation is over states drawn from the replay buffer. The critic is trained to satisfy the Bellman equation (see Bellman Equation) with the actor's action as the next-state action.

The actor update

The deterministic policy gradient, from Deterministic Policy Gradient, says that the gradient of JJ with respect to the actor parameters is

Definition: DDPG actor gradient
∇θJ≈1N∑i=1N∇aQw(si,a)∣a=μθ(si) ∇θμθ(si),\nabla_\theta J \approx \frac{1}{N} \sum_{i=1}^{N} \nabla_a Q_w(s_i, a)\big|_{a = \mu_\theta(s_i)} \, \nabla_\theta \mu_\theta(s_i),

averaged over a minibatch of NN states from the replay buffer. The first factor is the gradient of the critic with respect to the action, a vector the size of the action. The second factor is the Jacobian of the actor's output with respect to its parameters.

This is the Chain Rule applied to the path from the parameters, through the action, into the critic. The actor parameters are then moved uphill with a gradient ascent step, or equivalently downhill on −J-J with Gradient Descent.

The critic update

The critic is a regression onto a Bellman target. The target uses the target actor μθ′\mu_{\theta'} and the target critic Qw′Q_{w'}:

y=r+γ Qw′(s′,μθ′(s′)).y = r + \gamma \, Q_{w'}\big(s', \mu_{\theta'}(s')\big).

The critic minimises the mean squared error between its prediction and this target,

L(w)=1N∑i=1N(yi−Qw(si,ai))2,L(w) = \frac{1}{N} \sum_{i=1}^{N} \big( y_i - Q_w(s_i, a_i) \big)^2,

where the targets yiy_i are treated as constants, so no gradient flows through them. Squared error is the usual mean squared error loss.

Target networks and soft updates

Both target networks follow the online networks slowly. After each update the target weights move a small step toward the online weights:

θ′←τθ+(1−τ)θ′,w′←τw+(1−τ)w′,\theta' \leftarrow \tau \theta + (1 - \tau)\theta', \qquad w' \leftarrow \tau w + (1 - \tau) w',

with τ≪1\tau \ll 1. This is the same idea as the periodic copy in the deep Q-network, but applied gradually at every step instead of every few thousand steps. A small τ\tau keeps the targets stable while the online networks learn.

Exploration

Because the actor is deterministic, DDPG adds noise to the action during training. If n\mathbf{n} is noise, the agent acts with a=μθ(s)+na = \mu_\theta(s) + \mathbf{n}, clipped to the allowed action range. The original paper used temporally correlated noise from an Ornstein-Uhlenbeck process (with θ=0.15\theta = 0.15 and σ=0.2\sigma = 0.2), so that consecutive actions drift smoothly. Plain independent Gaussian noise is also common in implementations. The noise is used only to collect data. The actor and critic are trained on the data, and the test policy is the deterministic μθ\mu_\theta without noise.

The full loop

Each environment step stores one transition in the replay buffer. Then the agent samples a minibatch, updates the critic toward yy, updates the actor with the gradient above, and soft-updates both target networks. Stored transitions can be reused many times, which is what gives DDPG its sample efficiency compared with purely on-policy methods.

Worked examples

Example
One actor step with a one-dimensional action

Use a linear actor μθ(s)=θs\mu_\theta(s) = \theta s with θ=0\theta = 0, a single state s=2s = 2, and a fixed critic Q(s,a)=−(a−1)2Q(s, a) = -(a - 1)^2. The critic prefers actions near 1, whatever the state. Use learning rate α=0.1\alpha = 0.1.

  1. The current action is μθ(2)=0⋅2=0\mu_\theta(2) = 0 \cdot 2 = 0.
  2. The action gradient of the critic is ∇aQ=−2(a−1)\nabla_a Q = -2(a - 1). At a=0a = 0 this is −2(0−1)=2-2(0 - 1) = 2.
  3. The Jacobian of the actor with respect to θ\theta is ∇θμθ(s)=s=2\nabla_\theta \mu_\theta(s) = s = 2.
  4. The actor gradient is 2⋅2=42 \cdot 2 = 4. Gradient ascent gives θ←0+0.1⋅4=0.4\theta \leftarrow 0 + 0.1 \cdot 4 = 0.4.
  5. The new action is μθ(2)=0.4⋅2=0.8\mu_\theta(2) = 0.4 \cdot 2 = 0.8, closer to the critic's preferred value of 1.

Interpretation: the actor moved its output toward the action the critic scores highest, using only the critic's slope at the current action. Repeating the step gives θ=0.48\theta = 0.48 and an action of 0.960.96, which is closer still.

Example
One critic target and a soft update

A robot arm produces a transition with reward r=1.0r = 1.0. The target actor's next-state action is scored by the target critic at Qw′(s′,μθ′(s′))=10.0Q_{w'}(s', \mu_{\theta'}(s')) = 10.0. Use discount γ=0.99\gamma = 0.99. The online critic currently predicts Qw(s,a)=9.5Q_w(s, a) = 9.5 for the stored action.

  1. Bellman target: y=1.0+0.99⋅10.0=1.0+9.9=10.9y = 1.0 + 0.99 \cdot 10.0 = 1.0 + 9.9 = 10.9.
  2. Temporal-difference error: y−Qw(s,a)=10.9−9.5=1.4y - Q_w(s, a) = 10.9 - 9.5 = 1.4.
  3. Squared loss for this sample: 1.42=1.961.4^2 = 1.96. The critic's update reduces this by moving Qw(s,a)Q_w(s, a) up toward 10.910.9.
  4. Suppose one target weight is 2.02.0 and the online weight is now 2.52.5. A soft update with τ=0.01\tau = 0.01 moves the target to 2.0+0.01⋅0.5=2.0052.0 + 0.01 \cdot 0.5 = 2.005.

Interpretation: the target is built from the target networks, so the regression goal does not move with every online update. The soft update changes the target by only a fraction of the online change, which is what keeps the critic's goal stable. The value τ=0.01\tau = 0.01 is an illustrative choice, not a value taken from the paper.

Tradeoffs and failure modes

SituationWhat goes wrongBetter choice
Discrete actionsThe actor's gradient needs a continuous action, and the max over a small set is easy[[deep-q-network
Critic overestimates valuesThe actor exploits the critic's errors and the policy drifts into bad actionsTwin critics, delayed actor updates and target smoothing (the TD3 changes)
Multi-modal best actionsA deterministic actor can commit to one mode and miss othersA stochastic actor trained with an entropy bonus
Sparse rewardsLittle signal reaches the critic, so the actor learns slowlyHindsight relabelling or reward shaping
Hyperparameter sensitivityLearning rates, noise scale and τ\tau all interact, and runs can divergeCareful tuning and several seeds; compare with a well-tuned baseline
Stale replay dataOld transitions came from an older policy and bias the criticSmaller buffer, or prioritise recent data

A common failure is divergence: the critic's values grow without bound, and the actor follows them. Lower learning rates, soft targets and gradient clipping are the first remedies. The critic error is also worth logging, because a rising critic loss often comes before a collapse in return.

History

Silver and colleagues introduced the deterministic policy gradient in 2014 and showed that the gradient can be written as an expectation over states, with no integral over actions. Lillicrap and colleagues combined it with the ideas that had made the deep Q-network work: a replay buffer, target networks and minibatch training. Their 2015 arXiv paper, Continuous control with deep reinforcement learning, applied the result to simulated physics tasks with continuous actions and gave the algorithm the name DDPG. The paper's algorithm box and experiments are the usual reference for the details above.

Check yourself

QuestionRecall: how does DDPG's actor differ from the policy in Q-learning, and why does that matter for continuous actions?Show answer
Q-learning picks the action with the largest QQ by searching over the action set. With continuous actions that search has to run at every step. DDPG's actor outputs the action directly, so the best action is produced in one forward pass, and the actor is trained with the critic's action gradient.
QuestionComputation: the reward is r=2r = 2, the discount is γ=0.9\gamma = 0.9, and the target critic scores the next state-action pair at 88. What is the Bellman target yy, and what is the squared error if the online critic predicts 77?Show answer
y=2+0.9⋅8=2+7.2=9.2y = 2 + 0.9 \cdot 8 = 2 + 7.2 = 9.2. The error is 9.2−7=2.29.2 - 7 = 2.2, and the squared error is 2.22=4.842.2^2 = 4.84.
QuestionWhy: why are target networks updated slowly, and what would happen if the critic used the online networks directly in its target?Show answer
The target is what the critic regresses toward. If the target moves with every critic update, the regression chases a moving goal and can oscillate or diverge. Soft updates keep the target nearly fixed over many steps, so the critic has time to fit it. Using the online networks in the target removes that stability and is a common cause of divergence.
QuestionApplied: a DDPG agent with a deterministic actor learns quickly, but in a task with two very different good motions it always converges to the same one. Why, and what would you change?Show answer
A deterministic actor outputs one action per state, so it can settle on one of two good modes and never represent the other. Exploration noise helps during data collection, but it does not change the actor's output form. A stochastic actor trained with an entropy bonus, or a mixture policy, can represent several modes. Another option is to seed training from demonstrations of each motion.

Sources