TD3: twin critics and a delayed actor
TD3
Separate minimum twin-Q targets, action smoothing and delayed updates, then measure the computations they change.
td3Why two critics still cannot certify a value
Consider a fictional control task with true action value 1. Two critics predict 1.1 and 1.2; their minimum still overestimates. If they predict 0.7 and 1.2 instead, the minimum underestimates. TD3’s twin critics do not form a certified confidence interval. They supply a more conservative training target to reduce opportunities for the actor to chase false peaks.
TD3 modifies DDPG in three places: use the smaller target-critic value in backups, perturb target actions with small noise, and update the actor and target networks less frequently than the critics. These changes address value estimates, local action smoothing and update timing. Adding a second Q-network alone does not implement the full algorithm. Original paper
The paper appeared at ICML 2018. Its reported results belong to the authors’ experimental conditions. Here we compare against DDPG on the same two-step teaching task, without calling the local experiment a paper reproduction. Publication and methods
Follow one transition through the three changes
Sample from replay, where marks true termination. Evaluate the target actor at the next state and apply two distinct clips: one limits the noise, the other enforces action bounds. For multidimensional actions, clipping is componentwise:
For a target action of 0.95, raw noise 0.8, noise cap 0.2 and action upper bound 1, the intermediate result is 0.95+0.2=1.15, then 1 after action clipping. Clipping only noise still permits invalid actions; clipping only the final action can permit excessive local perturbations. This noise computes a backup, rather than an exploratory environment action. The two noise scales can differ. Smoothing and implementation Both clips
Both target critics evaluate the same next state and the same perturbed action. Their minimum supplies one shared target for fitting the two online critics:
Do not backpropagate through the target. A truly terminal transition leaves only reward. The networks have separate parameters but share data and targets, which does not make them independent. A minimum cannot exceed either input; this establishes conservatism relative to those inputs, not a lower bound on true Q. Correlated errors and underestimation
The classic TD3 actor maximizes the first online critic, without taking a minimum:
This is a concrete difference from SAC’s actor formula. Hold critic parameters fixed during the actor step while retaining action derivatives. The actor uses the critic after its current update. Actor update
Let count completed critic minibatch updates and let be a positive integer. Update both critics every time, but update the actor and all target copies only when the clock triggers:
Our first trigger is critic update , with the counter retained across collection blocks. The pinned upstream implementation instead uses a local counter starting at zero in each update loop. Its default configuration is compatible with regular spacing, but arbitrary block lengths need not match a persistent clock. State which clock an implementation uses. Pinned implementation
Why might smoothing help? Consider one critic away from action bounds, with small, unclipped, zero-mean noise. A second-order Taylor approximation gives:
At a sharp peak the second derivative is negative, so the neighborhood average falls below the peak. Actual TD3 includes clipping, boundaries, finite sampling and a twin-Q minimum; this local approximation is not its exact backup. It explains a smoothing mechanism rather than proving improvement in every environment. Target smoothing
Put all three changes into a training loop
Reuse the original two-step environment from the DDPG article. Starting is uniform on , reward is , the next position is , and the second step terminates. Each phase has a tanh linear actor and two critics with six quadratic features each. These are small teaching models, not a deep-network benchmark.
Defaults are 6000 environment steps, 200 initial uniform exploration steps, replay capacity 2000, batch size 32 and discount 0.9. Exploration noise has standard deviation 0.3; target smoothing uses standard deviation 0.1, noise cap 0.2 and action bounds . Critic and actor learning rates are 0.04 and 0.02, target coefficient 0.01, and delay 2. Initialization, exploration, replay and target smoothing use separate seeded random streams.
"""Original TD3 control lesson; same environment as DDPG, quadratic critics."""
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 smooth_action(action, noise, noise_clip=0.2):
if noise_clip < 0:
raise ValueError('noise clip must be nonnegative')
return clip(action + clip(noise, -noise_clip, noise_clip))
def actor_due(critic_updates, delay):
if not isinstance(delay, int) or isinstance(delay, bool) or delay < 1:
raise ValueError('delay must be a positive integer')
return critic_updates > 0 and critic_updates % delay == 0
def train(seed=0, steps=6000, delay=2):
actor_due(0, delay)
explore, replay_rng = random.Random(seed), random.Random(seed+10000)
init = random.Random(seed+20000)
smoothing = random.Random(seed+30000)
actor = [[0.0, 0.0] for _ in range(2)]
critic = [[init.uniform(-0.05, 0.05) for _ in range(6)] for _ in range(2)]
critic2 = [[init.uniform(-0.05, 0.05) for _ in range(6)] for _ in range(2)]
target2 = [w[:] for w in critic2]
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
actor_updates = 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)]
gradients = [[[0.0]*6 for _ in range(2)] for _ in range(2)]
for h, sx, act, reward, next_x, done in batch:
future = 0.0
if not done:
na = smooth_action(policy(target_actor[1], next_x), smoothing.gauss(0, 0.1))
future = min(value(target_critic[1], next_x, na), value(target2[1], next_x, na))
y = bootstrap(reward, future, done)
for k, q in enumerate((critic, critic2)):
error = value(q[h], sx, act)-y
for j, f in enumerate(features(sx, act)):
gradients[k][h][j] += 2*error*f/len(batch)
for k, q in enumerate((critic, critic2)):
for h in (0, 1):
q[h] = [w-0.04*g for w, g in zip(q[h], gradients[k][h])]
updates += 1
if actor_due(updates, delay):
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])]
for qt, q in ((target_critic, critic), (target2, critic2)):
qt[h] = [(1-tau)*v+tau*w for v, w in zip(qt[h], q[h])]
actor_updates += 1
return {'seed':seed, 'initial':initial, 'final':evaluate(actor), 'optimum':1.9,
'critic_updates':updates, 'actor_updates':actor_updates,
'actor':actor, 'critic':critic, 'critic2':critic2, 'target_actor':target_actor}
if __name__ == '__main__':
print(json.dumps(train(), sort_keys=True))
Inspect the complete recorded output
{"actor": [[0.5232718313788149, -0.0007796796527325128], [0.5086183652401205, -0.0009166998126641008]], "actor_updates": 2900, "critic": [[1.8869688017392403, -0.00039767402824984684, -0.0009110872288137134, -0.24113535516044643, 0.9729107049799418, -0.9779522879107702], [0.9969185013450774, 0.00045395050038467554, -0.001278276659474881, -0.23464326958515813, 0.957136870694855, -0.9713519620899428]], "critic2": [[1.8869708033014703, -0.0003977828419043931, -0.0009108852585462347, -0.24114390620903162, 0.9729361013395702, -0.9779720127070964], [0.996997855431188, 0.0004404197732804965, -0.001246455632007738, -0.23507418502130198, 0.9582090541959876, -0.9720174064417539]], "critic_updates": 5800, "final": 1.8999386953554782, "initial": 1.795875, "optimum": 1.9, "seed": 0, "target_actor": [[0.523085656155751, -0.0006567184456597295], [0.5082779866306146, -0.0007494336540563322]]}5800 critic minibatch updates produce 2900 actor updates. Each actor trigger also soft-updates the target actor and both target critics. Checks cover unchanged targets before the first trigger, the first target interpolation coefficient, both action clips, true termination precedence, and analytic action gradients against finite differences. Replay samples uniformly with replacement; this is not a claim that observations are independent.
Across seeds 0–7, TD3’s fixed-grid evaluation without exploration averages 1.899931, with an approximate range of 1.899908–1.899942. DDPG averages 1.899931 on the same task. Both approach the analytic bound of 1.9; this experiment does not show a meaningful TD3 return advantage. Delay reduces actor updates but adds a second trained critic, so actor counts alone cannot establish half the total runtime. For fixed model sizes, update cost remains linear in batch size. Another critic adds model and gradient computation; replay capacity need not double.
Correlated errors, underestimation and a changed target
Take two zero-mean errors, each equally likely to be ±0.2. With independence, their four possible pairs have mean minimum −0.1. With identical errors, the mean minimum is zero:
Network count alone therefore does not determine the bias reduction, and underestimation is not a free benefit. The paper discusses correlation from shared replay. Its finite-setting argument is not presented here as a theorem for arbitrary neural networks. Error discussion
Target noise also changes the subsequent action distribution evaluated by a backup. Clipping at boundaries makes perturbations asymmetric; excessive smoothing can erase a genuinely useful narrow action region. Slower actor updates can delay adaptation. DDPG’s coverage problems, erroneous critic action derivatives and off-policy approximation remain.
The algorithm box on PDF page 6 uses for the target action, while Eqs. 14/15 on that page use . The condition is abbreviated as “if t mod d,” and Eq. 13 omits the discount. We use the next state, divisibility test and discount consistently with the Bellman relation, Eqs. 14/15 and pinned implementation, rather than copying the inconsistent notation. Original page Code comparison
Predict an update
- Target action is 0.95, noise is −0.8, the noise cap is 0.2 and actions lie in . What is the final target action?
Answer: Clip noise to −0.2, giving action 0.75, which needs no further clipping. The noise cap and action bounds constrain different quantities.
- Reward is 1, discount is 0.9, the transition is nonterminal and target Q-values are 3 and 2. What backup is used?
Answer: The smaller Q is 2, so the backup is 2.8. Both online critics fit this same target. True termination would instead give target 1.
- After seven critic updates with delay 3, how many actor updates should this example perform? What if the counter resets after every two critic updates?
Answer: Updates 3 and 6 trigger, for two actor updates. A counter starting at 1 and resetting every two updates never reaches 3; one restarting at 0 and triggering there updates too frequently. Define a persistent update clock explicitly.
- If both critics predict 10, is true Q at least 10? How should equal TD3 and DDPG teaching scores be reported?
Answer: No; both critics can share an overestimation error. Report comparable conditions, seed ranges and computational differences. The algorithm’s reputation does not turn equal scores into a demonstrated improvement.
Separate mechanism, implementation and results
Pages 4–6 of the original paper connect correlated errors, delay and target smoothing. This article reads the method sections without claiming a complete benchmark or supplementary-proof audit. Original methods The pinned Spinning Up commit supplies both clips, the Q1 actor and actual update timing. Comparing it with pseudocode exposes operational conventions; upstream code was neither executed nor copied. Pinned code
Make a prediction, then check
What does the classic TD3 actor maximize?
Learning objectives
- Distinguish exploration from target smoothing and apply both noise and action clipping.
- Implement delay with a persistent counter and explain why minimum twin Q is not a certified lower bound.
Prerequisites & connections
Explore related knowledge →References
- Addressing Function Approximation Error in Actor-Critic Methods — scoped methods
Scott Fujimoto; Herke van Hoof; David Meger · 2018 - Spinning Up — TD3 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: PMLR80:1587–1596. Read PDF2–6, viewed6: correlated critics, underestimation, delay and smoothing. Eqs14/15 and code resolve Algorithm1 state/divisibility notation and missing gamma in Eq13; no complete benchmark or supplement audit. Docs1–28 and32–140, main file181–325, all62 core lines; two clips, twin Q, Q1 actor and local update clock. Fixed commit; reference only, no upstream execution or copying. 6 paired equations and four explained exercises. Separate noise/action clips, twin target minimum, Q1 actor and persistent delayed clock tested. Independent versus correlated error counterexample and all eight runs retained. No certified lower bound or meaningful return advantage over DDPG demonstrated in this teaching task.
- Separate noise/action clips, twin target minimum, Q1 actor and persistent delayed clock tested. Independent versus correlated error counterexample and all eight runs retained. No certified lower bound or meaningful return advantage over DDPG demonstrated in this teaching task.
- 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:
- Addressing Function Approximation Error in Actor-Critic Methods — scoped methods · PMLR80:1587–1596. Read PDF2–6, viewed6: correlated critics, underestimation, delay and smoothing. Eqs14/15 and code resolve Algorithm1 state/divisibility notation and missing gamma in Eq13; no complete benchmark or supplement audit.
- Spinning Up — TD3 fixed-commit methods · Docs1–28 and32–140, main file181–325, all62 core lines; two clips, twin Q, Q1 actor and local update clock. Fixed commit; reference only, no upstream execution or copying.
Related topics