Actor–Critic Methods
A learned critic to cut the variance of the policy gradient.
REINFORCE waits for the end of every episode and then judges each action by everything that happened afterwards. An actor–critic judges each action one step later, by how much better things went than a learned critic predicted. That trade of a little bias for much less variance, run on many copies of the environment at once, is the template behind A2C, PPO and much of modern deep RL.
What you’ll learn
- Show that the TD error is an unbiased advantage estimate exactly when the critic is correct, and identify which part of a critic's error biases the policy gradient.
- Write the one-step actor–critic algorithm with its two step sizes.
- Use -step and λ-weighted advantages to trade bias for variance.
- Describe A3C and A2C: parallel actors, entropy bonuses, and shared or separate networks.
- Build a Gaussian actor–critic for continuous actions.
From a baseline to a critic
REINFORCE with a learned baseline already trains two things: a policy and a state-value estimate . But it uses the value only as a baseline, compared with the full return . An actor–critic method also uses it to bootstrap: it replaces the return by a one-step target, the reward plus the discounted estimated value of the next state. Sutton and Barto reserve the name actor–critic for this second use, because only then does the critic pass judgment on the actor's action, with the bias and variance of a TD target. Below, stands for the critic .
Define the critic's TD error:
If the critic is exact, , then conditioning on the state and action gives exactly the advantage:
So is then an unbiased sample of the policy-gradient term at , with far less variance than : one random transition instead of a whole random future. With an inexact critic, write ; the error splits into a harmful and a harmless part:
One-step actor–critic
input: policy π(a | s, θ), state-value estimate v̂(s, w), step sizes α_θ > 0, α_w > 0
loop for each episode:
S ← first state of the episode; I ← 1
while S is not terminal:
A ~ π(· | S, θ)
take A, observe R and S′
δ ← R + γ · v̂(S′, w) − v̂(S, w) # v̂(S′, w) = 0 if S′ is terminal
w ← w + α_w · δ · ∇_w v̂(S, w) # critic: semi-gradient TD(0)
θ ← θ + α_θ · I · δ · ∇_θ log π(A | S, θ) # actor: I = γ^t, as the theorem asks
I ← γ · I
S ← S′Sutton and Barto's one-step actor–critic (§13.5): fully online, one update per step, no waiting for episodes to end. The critic is semi-gradient TD(0) (Temporal-Difference Learning). Most implementations drop the factor ; The Policy Gradient Theorem in Depth explains what that changes.
Three design questions recur in every actor–critic.
- Two step sizes. The critic must track the values of a policy that keeps changing, so it usually learns faster than the actor. Convergence proofs make this a separation of timescales, (Compatible Features & Two-Timescale Actor–Critic).
- What the critic learns. A state-value critic is enough, since supplies the advantage. A critic of lets the actor use or, with continuous actions, the slope , as the deterministic policy gradients of Continuous Control: DDPG, TD3 & SAC do.
- Whose data. The TD targets and the policy gradient both assume the actions came from the current policy. Reusing older data requires importance corrections (Distributed Actor–Critic: A3C & IMPALA) or an off-policy design with replay.
In a continuing task, the critic overestimates every state's value by the same constant , so . What happens to the one-step actor–critic's expected update?
- Nothing changes in expectation: every TD error is shifted by , which does not depend on the action and acts like a baseline
- It becomes biased toward actions with large immediate rewards
- It points in the opposite direction
- Its bias is the critic's error amplified by
Show the answer
A. Nothing changes in expectation: every TD error is shifted by , which does not depend on the action and acts like a baseline
. The shift does not depend on the action, so it averages out against the zero-mean score, exactly like a baseline. Only errors that differ across next states in a way that depends on the action bias the gradient. (In an episodic task the terminal value is pinned at 0, so actions that end the episode see a different shift, and a small bias appears.)
n-step and λ advantages
One-step TD errors have low variance but lean entirely on the critic; full returns lean on nothing but are noisy. In between lie -step advantage estimates, built from the -step returns of n-Step Returns & Eligibility Traces:
Averaging all with weights gives the λ-return minus the baseline, : generalized advantage estimation, the default advantage estimator of PPO. The dial works as in TD(λ) prediction: near 0 trusts the critic, near 1 trusts the samples, and the best setting usually lies in between.
Which statement about the -step advantage estimate is correct?
- Larger always reduces its variance
- With it is unbiased whatever the critic
- Larger makes it lean less on the critic: less bias, more variance
- Once the critic is exact, the choice of no longer matters at all
Show the answer
C. Larger makes it lean less on the critic: less bias, more variance
The critic's error is discounted by in , while the estimate sums random rewards. With an exact critic every is unbiased, but the variances still differ, typically growing with .
A3C and A2C: many actors at once
A deep network trained on one stream of experience sees highly correlated samples. DQN broke the correlation with a replay buffer; Mnih et al. (2016) broke it with parallelism. A3C, asynchronous advantage actor–critic, runs many actor-learner threads, 16 in their Atari experiments, each with its own copy of the environment. A thread acts for up to steps, computes -step advantages for that segment, and applies its gradients to shared parameters without locks. At any moment the threads are in different states, so their combined updates are far less correlated than one agent's, and no replay buffer is needed. The paper reported surpassing the previous state of the art on Atari while training for half the time, on a single multi-core CPU instead of a GPU.
A2C is the synchronous version: wait for all actors to finish their segments, then make one update from the whole batch. OpenAI's 2017 report on its baseline implementations found no evidence that the noise of asynchrony improves performance, and the synchronous version uses a GPU better because it processes one large batch. A2C, and PPO after it, set the standard pattern: environments step together, then one batched update.
import torch
import torch.nn.functional as F
from torch.distributions import Categorical
def a2c_loss(logits, values, actions, returns, value_coef=0.5, entropy_coef=0.01):
"""logits: (N, A); values: (N,) critic outputs V(S_t); returns: (N,) n-step targets."""
dist = Categorical(logits=logits)
advantages = returns - values.detach() # the critic's verdict, fixed for the actor
policy_loss = -(dist.log_prob(actions) * advantages).mean()
value_loss = F.mse_loss(values, returns) # regress V(S_t) toward the n-step return
entropy = dist.entropy().mean() # bonus that keeps the policy stochastic
return policy_loss + value_coef * value_loss - entropy_coef * entropy
def n_step_returns(rewards, dones, last_value, gamma=0.99):
"""One actor's segment. rewards, dones (floats): (n,); last_value = V(S_{t+n}), no grad."""
R, out = last_value, torch.zeros_like(rewards)
for t in reversed(range(len(rewards))):
R = rewards[t] + gamma * R * (1.0 - dones[t]) # stop bootstrapping at episode ends
out[t] = R
return outThe actor, critic and entropy terms share one optimizer step. Detaching values in the advantage keeps the actor's loss from training the critic. Treating every done as a true ending is a simplification: a time-limit cut should still bootstrap, as Generalized Advantage Estimation shows.
The entropy bonus. Adding to the objective, with in A3C's Atari experiments, discourages premature collapse to a nearly deterministic policy. Collapse would end exploration and, for softmax policies, stall the gradient toward abandoned actions, the plateaus analyzed in Global Convergence of Policy Gradients. Maximum-entropy RL takes the idea further and rewards entropy in every future state too (Maximum-Entropy RL & Soft Actor–Critic).
Shared or separate networks. A3C's Atari network shared all its non-output layers, convolutional and fully connected, between a softmax policy head and a linear value head. Sharing trains one representation with both losses, but then the value loss's weight must be balanced against the policy loss, and the two can interfere. For continuous control, the large study of Andrychowicz et al. (2020) recommends separate networks, with a wide value network that shares no layers with the policy.
Continuous actions
For continuous actions the actor outputs a Gaussian. A common design has a network produce the mean , while a state-independent vector of log standard deviations is learned as a free parameter. With independent coordinates, the log-probability and the entropy are sums over coordinates:
Two practical wrinkles. Environments bound their actions, so a sample is either clipped before it is sent, which keeps the log-probability of the unclipped sample in the gradient, or squashed through , which requires a change-of-variables term in the log-probability, as soft actor–critic does (Continuous Control: DDPG, TD3 & SAC). And the standard deviations are part of the policy: they shrink as the policy grows confident, which is how exploration fades unless an entropy bonus resists it.
Key takeaways
- An actor–critic judges each action by its critic's TD error. With an exact critic ; an inexact critic biases the gradient only through its action-dependent expected error at the next state.
- -step and λ-weighted advantages interpolate between the one-step TD error (low variance, critic-dependent) and the Monte Carlo return minus a baseline (unbiased, noisy).
- A3C decorrelates updates with many asynchronous actor-learners instead of replay; A2C's synchronous, batched version performs as well and uses GPUs better. The critic usually learns faster than the actor.
- An entropy bonus keeps the policy stochastic; for continuous actions the actor is usually a Gaussian with a learned mean and learned log standard deviations.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
With an inexact critic , through which part does the one-step actor–critic's policy gradient become biased?
- Through , the error at the current state
- Through , the expected error at the next state, which depends on the action
- Through both parts equally
- Through neither: the TD error is always unbiased
Show the answer
B. Through , the expected error at the next state, which depends on the action
. The last term depends only on the state, so like any baseline it averages out against the zero-mean score. The middle term varies with the action, so it changes the expected direction.
Why does the critic usually learn with the larger step size in an actor–critic method?
- Because the critic's network is smaller
- Because larger critic steps reduce the bias of the policy gradient to zero
- Because the critic's predictions must keep up with a policy that keeps changing; if the actor moves faster than the critic can follow, TD errors judge actions against stale values
- Because the actor's gradient has lower variance
Show the answer
C. Because the critic's predictions must keep up with a policy that keeps changing; if the actor moves faster than the critic can follow, TD errors judge actions against stale values
The TD error is a sound verdict only if is close to the current policy's values. Letting the critic adapt on a faster timescale keeps it near while drifts slowly, the structure that two-timescale convergence proofs formalize.
What distinguishes A2C from A3C?
- A2C uses a replay buffer and A3C does not
- A2C has no critic
- A2C runs a single environment
- A2C waits for all parallel actors and makes one synchronous, batched update; A3C's threads update shared parameters asynchronously
Show the answer
D. A2C waits for all parallel actors and makes one synchronous, batched update; A3C's threads update shared parameters asynchronously
Both run many environments in parallel and both use an -step advantage actor–critic. A3C applies each thread's gradients as soon as they are ready, so updates are computed from slightly stale parameters; A2C synchronizes, which is simpler, deterministic and better suited to GPUs, and it was reported to perform as well.
Why does A3C add an entropy bonus to its policy loss?
- To discourage premature collapse to a nearly deterministic policy, which would end exploration and stall softmax gradients
- To help the critic converge faster
- To make the policy gradient unbiased
- To keep the rewards bounded
Show the answer
A. To discourage premature collapse to a nearly deterministic policy, which would end exploration and stall softmax gradients
The bonus rewards keeping several actions in play. It changes the objective slightly, so it is a bias by design, traded for continued exploration and better-conditioned gradients.
Go deeper
- Generalized Advantage Estimation · λ-weighted advantages: the bias–variance dial of modern policy gradients.
- Compatible Features & Two-Timescale Actor–Critic · When a critic leaves the gradient unbiased, and why actor–critic converges.
- Distributed Actor–Critic: A3C & IMPALA · Parallel actors, policy lag and V-trace corrections.
Further reading
- R. S. Sutton & A. G. Barto, Reinforcement Learning: An Introduction, §13.5–13.7 (MIT Press, 2nd ed., 2018).
- A. G. Barto, R. S. Sutton & C. W. Anderson, "Neuronlike adaptive elements that can solve difficult learning control problems," IEEE Transactions on Systems, Man, and Cybernetics 13(5), 834–846 (1983).
- V. Mnih, A. P. Badia, M. Mirza, A. Graves, T. Lillicrap, T. Harley, D. Silver & K. Kavukcuoglu, "Asynchronous methods for deep reinforcement learning," ICML (2016).
- M. Andrychowicz et al., "What matters in on-policy reinforcement learning? A large-scale empirical study," arXiv:2006.05990 (2020).