DDPG: adjust continuous actions through a critic
DDPG
Derive a deterministic actor update for a bounded control, keeping replay distributions and target networks distinct.
ddpgReplace three buttons with a dial
Suppose a teaching device accepts a control between −1 and 1. DQN can estimate separate values for left, stop and right buttons, but cannot allocate an output to every real number in an interval. Discretizing the control into a thousand settings also becomes expensive as action dimensions multiply. DDPG trains an additional actor that maps a state directly to an action. A critic estimates the action’s value, and the actor adjusts the dial using the critic’s derivative with respect to that action.
The critic supplies a learned estimate. If it creates a spurious peak, the actor can climb that peak. DDPG turns continuous action search into differentiable optimization; it does not give the critic access to a true value table. Original paper
DPG provides the deterministic policy-gradient theory. DDPG combines it with neural networks, experience replay and target networks. The DDPG preprint first appeared in 2015 and its paper identifies ICLR 2016; the version read here is the 2019 v6 revision. The revision year is not the algorithm’s origin date. DPG DDPG version
Deterministic actions still visit a distribution of states
Write the actor as and the critic as . Their parameters are and respectively; an action is not an actor parameter. With a fixed starting distribution, an environment independent of the parameters, differentiability and regularity conditions permitting interchange of integration and differentiation, define the discounted objective and unnormalized state occupancy:
For finite states, replace the integral by a sum. Here the actor Jacobian is arranged as parameter count by action dimension, so multiplying by the action gradient yields a parameter gradient. A deterministic policy removes integration over policy action randomness, not the state distribution. The theorem uses the true policy value and corresponding occupancy. A generic neural critic and uniform replay do not automatically satisfy those conditions. Theorem and off-policy discussion
The practical algorithm samples a replay minibatch containing states, actions, rewards, next states and true termination flags . Bars denote slowly changing target parameters. Compute a fixed backup and fit the online critic:
Stopping the gradient means this step fits the backup without differentiating through it. A true terminal state has no future return. An external collection timeout can still require bootstrapping, using the final observation before reset. If the task itself has a fixed horizon, include remaining time in the state and terminate at the task endpoint. An old interface that compresses timeout and termination into one Boolean needs careful interpretation. Implementation and termination conventions
After updating the critic, maximize its current score over replay states:
With critic parameters held fixed, this is the gradient of that minibatch surrogate. It is generally an approximate update direction for the original start-state return objective. Freeze critic weights during actor learning but retain the derivative from action input to Q output. Detaching the entire output removes the actor’s learning signal too. Actor implementation
Finally update both target parameter sets. Here multiplies the online parameters, whereas some implementations use to multiply the old targets:
Initialize targets by copying online weights. The order is critic, actor, then targets. Replay reuses a wider set of past observations and targets slow changes in backups; neither gives a general convergence guarantee. The original paper uses OU exploration noise and batch normalization. Those are implementation choices; the pinned Spinning Up implementation uses Gaussian exploration noise. Original algorithm Code conventions
Actually train a two-step controller
This original task lasts two steps. Actions and uniformly sampled starting positions lie in . The first action changes the second-step position; the second step truly terminates. State contains phase and position . Each phase has a two-parameter actor and six quadratic critic features:
Choosing at the second step earns 1. Doing the same at the first step reaches the return upper bound . The critic’s action derivative is , and the actor derivative contains . Independent central finite differences check both analytic derivatives.
The program uses only the Python standard library. It collects 6000 steps, beginning with 200 uniform exploration steps. Afterwards it adds Gaussian noise with standard deviation 0.3 to actor actions and clips them. A circular buffer of capacity 2000 samples 32 transitions uniformly with replacement. Critic and actor learning rates are 0.04 and 0.02; the target coefficient is 0.01. Evaluation uses 101 fixed starting positions with exploration disabled. At most one minibatch update follows each environment step, giving 5800 critic and actor updates by default.
"""Original two-step control lesson; quadratic critics, not deep RL benchmark."""
import json
import math
import random
def clip(x, low=-1.0, high=1.0):
return min(high, max(low, x))
def features(x, a):
return [1.0, x, a, x*x, x*a, a*a]
def value(w, x, a):
return sum(u*v for u, v in zip(w, features(x, a)))
def action_gradient(w, x, a):
return w[2] + w[4]*x + 2*w[5]*a
def policy(w, x):
return math.tanh(w[0]*x + w[1])
def transition(phase, x, a):
if phase not in (0, 1) or not -1 <= a <= 1:
raise ValueError('phase must be 0/1 and action in [-1,1]')
return 1.0-(a-0.5*x)**2, 0.5*(x+a), phase == 1
def bootstrap(reward, future, terminated, truncated=False, gamma=0.9):
# External collection limits do not erase the continuation value.
# A real terminal state takes precedence even if both flags are true.
return reward if terminated else reward + gamma*future
def evaluate(actor):
returns = []
for i in range(101):
x = -1.0 + 2.0*i/100
total = 0.0
for h in (0, 1):
a = policy(actor[h], x)
r, x, _ = transition(h, x, a)
total += (0.9**h)*r
returns.append(total)
return sum(returns)/len(returns)
def train(seed=0, steps=6000):
explore, replay_rng = random.Random(seed), random.Random(seed+10000)
init = random.Random(seed+20000)
actor = [[0.0, 0.0] for _ in range(2)]
critic = [[init.uniform(-0.05, 0.05) for _ in range(6)] for _ in range(2)]
target_actor = [w[:] for w in actor]
target_critic = [w[:] for w in critic]
replay, capacity, tau = [], 2000, 0.01
initial = evaluate(actor)
phase, x, updates = 0, explore.uniform(-1, 1), 0
for t in range(steps):
a = explore.uniform(-1, 1) if t < 200 else clip(policy(actor[phase], x)+explore.gauss(0, 0.3))
r, nx, terminal = transition(phase, x, a)
item = (phase, x, a, r, nx, terminal)
if len(replay) < capacity:
replay.append(item)
else:
replay[t % capacity] = item
phase, x = (0, explore.uniform(-1, 1)) if terminal else (1, nx)
if t < 200:
continue
batch = [replay_rng.choice(replay) for _ in range(32)]
cg = [[0.0]*6 for _ in range(2)]
for h, sx, act, reward, next_x, done in batch:
future = 0.0 if done else value(target_critic[1], next_x, policy(target_actor[1], next_x))
y = bootstrap(reward, future, done)
error = value(critic[h], sx, act) - y
for j, f in enumerate(features(sx, act)):
cg[h][j] += 2*error*f/len(batch)
for h in (0, 1):
critic[h] = [w-0.04*g for w, g in zip(critic[h], cg[h])]
ag = [[0.0]*2 for _ in range(2)]
for h, sx, *_ in batch:
act = policy(actor[h], sx)
dz = action_gradient(critic[h], sx, act)*(1-act*act)
ag[h][0] += dz*sx/len(batch)
ag[h][1] += dz/len(batch)
for h in (0, 1):
actor[h] = [w+0.02*g for w, g in zip(actor[h], ag[h])]
target_actor[h] = [(1-tau)*v+tau*w for v, w in zip(target_actor[h], actor[h])]
target_critic[h] = [(1-tau)*v+tau*w for v, w in zip(target_critic[h], critic[h])]
updates += 1
return {'seed':seed, 'initial':initial, 'final':evaluate(actor), 'optimum':1.9,
'critic_updates':updates, 'actor_updates':updates,
'actor':actor, 'critic':critic, 'target_actor':target_actor}
if __name__ == '__main__':
print(json.dumps(train(), sort_keys=True))
Inspect the complete recorded output
{"actor": [[0.5236871225973071, -0.0004731742740617796], [0.5082939848174745, -0.000855987285543454]], "actor_updates": 5800, "critic": [[1.8944227220576786, 0.00012196580991579371, -0.0001989443020707362, -0.24013855916949278, 0.971614469550044, -0.9762872866311275], [0.9965772810361748, 0.000509452200296677, -0.0014117889767140943, -0.2327207238172958, 0.9523348881341847, -0.9684061089724543]], "critic_updates": 5800, "final": 1.8999391982975766, "initial": 1.795875, "optimum": 1.9, "seed": 0, "target_actor": [[0.5234214940786861, -0.000345302207106862], [0.5082226444811255, -0.0007721067317969688]]}This trains low-dimensional parameter models so each multiplication can be inspected. It is not deep-network DDPG or a MuJoCo reproduction. With fixed feature dimensions, update time is linear in batch size and replay storage is linear in capacity. Neural versions additionally depend on parameter count and forward/backward computation.
All seeds 0–7 were run and retained. The untrained fixed-grid return is 1.795875; the trained mean is 1.899931, with an approximate range of 1.899904–1.899941. The analytic bound of 1.9 belongs only to this task. Approaching it shows useful learned actions here, not stability on a real robot.
Small value errors can hide bad derivatives
The actor needs derivatives, whereas critic training usually penalizes value errors. Let the true value be zero and construct this counterexample:
Value error is uniformly small, yet the action derivative can be badly wrong. DPG’s compatible approximation argument adds conditions on action gradients and feature structure; low value MSE alone does not replace them. Compatibility conditions
Also distinguish reusing past actions to train a critic from correcting state weights. A separate two-state probe in this batch has start-objective gradient (0.63, 0.36), but its local actor direction weighted by behavior occupancy is (0.63, 0.18). The state distribution causes the difference. Off-policy sampling does not automatically remove distribution bias.
High-dimensional actions, insufficient exploration, critic extrapolation and tanh saturation can all hurt learning. TD3 addresses some estimation and update instabilities; SAC instead trains a stochastic actor with an entropy objective. A choice between them still needs evaluation on the intended data, environment, budget and multiple seeds.
Inspect the updates separately
- What must remain differentiable after critic parameters are frozen during actor learning?
Answer: The action input must remain differentiable, followed by the actor’s parameter Jacobian. Freezing critic weights avoids unnecessary weight gradients; detaching the entire Q output also cuts the actor path.
- Reward is 1, discount is 0.9 and the target critic gives 2. What is the nonterminal backup? What if the transition truly terminates?
Answer: The nonterminal backup is 2.8; the terminal backup is 1. A pure collection timeout belongs to the first case, a real task endpoint to the second. If both flags are true, actual termination takes precedence.
- A target weight is 0 and its online weight is 10. What does the paper’s produce? What value should an implementation using receive?
Answer: The new target is 0.1 and . Mistaking 0.01 for the coefficient on the old target gives 9.9, making the target almost immediately track the online value.
- Does lower critic validation error guarantee better actor actions?
Answer: No. The oscillating counterexample has small value error and a large derivative error. Inspect nearby value geometry, actual policy returns, coverage and multiple seeds as well. Validation value error is one piece of evidence, not an action-quality guarantee.
Reading the derivation and implementation
Start with the distinction between DPG’s true policy gradient and off-policy approximation, retaining occupancy and compatibility conditions. DPG derivation Then read DDPG’s target networks and Algorithm 1 while separating preprint, conference and revision dates. DDPG methods The pinned Spinning Up code locates detached targets, actor backpropagation, exploration and Polyak coefficients. No upstream code was executed and no original benchmark was reproduced for this article. Implementation reading
Make a prediction, then check
How should the critic be handled during actor training?
Learning objectives
- Write actor, critic and target updates and check the action derivative.
- Explain why uniform replay does not automatically give the exact start-state objective gradient.
Prerequisites & connections
Explore related knowledge →References
- Deterministic Policy Gradient Algorithms — scoped derivation
David Silver; Guy Lever; Nicolas Heess; Thomas Degris; Daan Wierstra; Martin Riedmiller · 2014 - Continuous control with deep reinforcement learning — arXiv v6 methods
Timothy P. Lillicrap; Jonathan J. Hunt; Alexander Pritzel; Nicolas Heess; Tom Erez; Yuval Tassa; David Silver; Daan Wierstra · 2019 - Spinning Up — DDPG fixed-commit methods
OpenAI; Joshua Achiam and contributors · 2020
Version1 · Editorial status: Recorded technical checks completed
View technical check record (AI)
Codex · 2026-09-23 · Single AI author. Scoped reading: Read PDF2–5, viewed4/5; supplement web lines0–266. Unnormalized occupancy, off-policy approximation and compatible action-gradient conditions; no full experiment or appendix audit. First2015-09-09, ICLR2016; selected v6 dated2019-07-05. Read PDF2–5, viewed5: replay, deterministic chain-rule updates, targets and exploration. No benchmark replication or later-table audit. Docs1–258, main PyTorch file162–284, all61 core lines; rho convention, detached targets, actor gradients through Q and old Gym timeout handling. Fixed commit; reference only, no upstream execution or copying. 6 paired equations and four explained exercises. Deterministic chain-rule/action derivatives checked by finite differences; replay surrogate distinguished from start-state gradient. Critic/actor/target order, true termination versus collection limits and target interpolation tested. Eight actual low-dimensional two-step runs retained, not deep-network or robot reproduction.
- Deterministic chain-rule/action derivatives checked by finite differences; replay surrogate distinguished from start-state gradient. Critic/actor/target order, true termination versus collection limits and target interpolation tested. Eight actual low-dimensional two-step runs retained, not deep-network or robot reproduction.
- Four computed SVG variants per topic;10 numeric/geometry tests and24 current responsive cases passed. All eight selected current captures directly viewed; all four groups use the checked initial captures. Actual assets and manuscripts are SHA bound. Full article acceptance recorded separately.
Source locations checked:
- Deterministic Policy Gradient Algorithms — scoped derivation · Read PDF2–5, viewed4/5; supplement web lines0–266. Unnormalized occupancy, off-policy approximation and compatible action-gradient conditions; no full experiment or appendix audit.
- Continuous control with deep reinforcement learning — arXiv v6 methods · First2015-09-09, ICLR2016; selected v6 dated2019-07-05. Read PDF2–5, viewed5: replay, deterministic chain-rule updates, targets and exploration. No benchmark replication or later-table audit.
- Spinning Up — DDPG fixed-commit methods · Docs1–258, main PyTorch file162–284, all61 core lines; rho convention, detached targets, actor gradients through Q and old Gym timeout handling. Fixed commit; reference only, no upstream execution or copying.
Related topics