Simple Algorithm
Reinforcement Learning · Bootstrapping · 22 min

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 nn-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 v^(s,w)\hat v(s,\mathbf w). But it uses the value only as a baseline, compared with the full return GtG_t. 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, VV stands for the critic v^(⋅,w)\hat v(\cdot,\mathbf w).

DerivationThe TD error estimates the advantage
  1. δt=Rt+1+γ V(St+1)−V(St)(V(St+1)=0 if St+1 is terminal)\delta_t=R_{t+1}+\gamma\,V(S_{t+1})-V(S_t)\qquad\big(V(S_{t+1})=0\ \text{if }S_{t+1}\text{ is terminal}\big)

    Define the critic's TD error:

  2. E[δt∣St=s,At=a]=r(s,a)+γ∑s′P(s′∣s,a) Vπ(s′)−Vπ(s)=Qπ(s,a)−Vπ(s)=Aπ(s,a)\E\big[\delta_t\mid S_t=s,A_t=a\big]=r(s,a)+\gamma\sum_{s'}P(s'\mid s,a)\,V^\pi(s')-V^\pi(s)=Q^\pi(s,a)-V^\pi(s)=A^\pi(s,a)

    If the critic is exact, V=VπV=V^\pi, then conditioning on the state and action gives exactly the advantage:

  3. E[δt∣St,At]=Aπ(St,At)+γ E[e(St+1)∣St,At]⏟depends on At: biases the gradient−e(St)⏟acts as a baseline\E\big[\delta_t\mid S_t,A_t\big]=A^\pi(S_t,A_t)+\underbrace{\gamma\,\E\big[e(S_{t+1})\mid S_t,A_t\big]}_{\text{depends on }A_t:\ \text{biases the gradient}}-\underbrace{e(S_t)}_{\text{acts as a baseline}}

    So δt ∇log⁡π(At∣St)\delta_t\,\nabla\log\pi(A_t\mid S_t) is then an unbiased sample of the policy-gradient term at StS_t, with far less variance than Gt−V(St)G_t-V(S_t): one random transition instead of a whole random future. With an inexact critic, write e=V−Vπe=V-V^\pi; the error splits into a harmful and a harmless part:

One-step actor–critic

text
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 I=γtI=\gamma^t; 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, αθ/αw→0\alpha_\theta/\alpha_w\to0 (Compatible Features & Two-Timescale Actor–Critic).
  • What the critic learns. A state-value critic is enough, since δt\delta_t supplies the advantage. A critic of Q(s,a)Q(s,a) lets the actor use Q^(St,At)−V^(St)\hat Q(S_t,A_t)-\hat V(S_t) or, with continuous actions, the slope ∇aQ\nabla_aQ, 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.
Check your understanding

In a continuing task, the critic overestimates every state's value by the same constant c>0c>0, so V=Vπ+cV=V^\pi+c. What happens to the one-step actor–critic's expected update?

  1. Nothing changes in expectation: every TD error is shifted by −(1−γ)c-(1-\gamma)c, which does not depend on the action and acts like a baseline
  2. It becomes biased toward actions with large immediate rewards
  3. It points in the opposite direction
  4. Its bias is the critic's error amplified by 11−γ\frac{1}{1-\gamma}
Show the answer

A. Nothing changes in expectation: every TD error is shifted by −(1−γ)c-(1-\gamma)c, which does not depend on the action and acts like a baseline

E[δt∣s,a]=Aπ(s,a)+γc−c\E[\delta_t\mid s,a]=A^\pi(s,a)+\gamma c-c. 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 nn-step advantage estimates, built from the nn-step returns of n-Step Returns & Eligibility Traces:

A^t(n)=Rt+1+γRt+2+⋯+γn−1Rt+n+γnV(St+n)⏟Gt:t+n−V(St)=∑l=0n−1γl δt+l\hat A^{(n)}_t=\underbrace{R_{t+1}+\gamma R_{t+2}+\dots+\gamma^{n-1}R_{t+n}+\gamma^nV(S_{t+n})}_{G_{t:t+n}}-V(S_t)=\sum_{l=0}^{n-1}\gamma^l\,\delta_{t+l}
The sum of TD errors telescopes into the nn-step return minus the baseline. n=1n=1 gives the one-step actor–critic; running to the end of the episode gives REINFORCE with a baseline. The critic's error enters only through γnV(St+n)\gamma^nV(S_{t+n}).

Averaging all nn with weights (1−λ)λn−1(1-\lambda)\lambda^{n-1} gives the λ-return minus the baseline, ∑l≥0(γλ)lδt+l\sum_{l\ge0}(\gamma\lambda)^l\delta_{t+l}: generalized advantage estimation, the default advantage estimator of PPO. The dial works as in TD(λ) prediction: λ\lambda near 0 trusts the critic, λ\lambda near 1 trusts the samples, and the best setting usually lies in between.

Check your understanding

Which statement about the nn-step advantage estimate A^t(n)\hat A^{(n)}_t is correct?

  1. Larger nn always reduces its variance
  2. With n=1n=1 it is unbiased whatever the critic
  3. Larger nn makes it lean less on the critic: less bias, more variance
  4. Once the critic is exact, the choice of nn no longer matters at all
Show the answer

C. Larger nn makes it lean less on the critic: less bias, more variance

The critic's error is discounted by γn\gamma^n in A^t(n)\hat A^{(n)}_t, while the estimate sums nn random rewards. With an exact critic every nn is unbiased, but the variances still differ, typically growing with nn.

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 tmax⁡=5t_{\max}=5 steps, computes nn-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: NN environments step together, then one batched update.

python
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 out

The 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 β H(π(⋅∣St))\beta\,\mathcal H\big(\pi(\cdot\mid S_t)\big) to the objective, with β=0.01\beta=0.01 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 mθ(s)∈Rd\mathbf m_{\boldsymbol\theta}(s)\in\R^d, 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:

log⁡πθ(a∣s)=−∑i=1d[(ai−mi(s))22σi2+log⁡σi]−d2log⁡(2π),H(π(⋅∣s))=∑i=1dlog⁡σi+d2log⁡(2πe)\log\pi_{\boldsymbol\theta}(\mathbf a\mid s)=-\sum_{i=1}^{d}\Big[\frac{\big(a_i-m_i(s)\big)^2}{2\sigma_i^2}+\log\sigma_i\Big]-\frac d2\log(2\pi),\qquad\mathcal H\big(\pi(\cdot\mid s)\big)=\sum_{i=1}^{d}\log\sigma_i+\frac d2\log(2\pi e)
Here π\pi inside log⁡(2π)\log(2\pi) is the number, not the policy. A Gaussian's entropy depends only on its standard deviations, so an entropy bonus simply pushes the log⁡σi\log\sigma_i up.

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 tanh⁡\tanh, 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 E[δt∣St,At]=Aπ(St,At)\E[\delta_t\mid S_t,A_t]=A^\pi(S_t,A_t); an inexact critic biases the gradient only through its action-dependent expected error at the next state.
  • nn-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.

Question 1

With an inexact critic V=Vπ+eV=V^\pi+e, through which part does the one-step actor–critic's policy gradient become biased?

  1. Through −e(St)-e(S_t), the error at the current state
  2. Through γ E[e(St+1)∣St,At]\gamma\,\E\big[e(S_{t+1})\mid S_t,A_t\big], the expected error at the next state, which depends on the action
  3. Through both parts equally
  4. Through neither: the TD error is always unbiased
Show the answer

B. Through γ E[e(St+1)∣St,At]\gamma\,\E\big[e(S_{t+1})\mid S_t,A_t\big], the expected error at the next state, which depends on the action

E[δt∣St,At]=Aπ(St,At)+γE[e(St+1)∣St,At]−e(St)\E[\delta_t\mid S_t,A_t]=A^\pi(S_t,A_t)+\gamma\E[e(S_{t+1})\mid S_t,A_t]-e(S_t). 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.

Question 2

Why does the critic usually learn with the larger step size in an actor–critic method?

  1. Because the critic's network is smaller
  2. Because larger critic steps reduce the bias of the policy gradient to zero
  3. 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
  4. 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 VV is close to the current policy's values. Letting the critic adapt on a faster timescale keeps it near VπθV^{\pi_{\boldsymbol\theta}} while θ\boldsymbol\theta drifts slowly, the structure that two-timescale convergence proofs formalize.

Question 3

What distinguishes A2C from A3C?

  1. A2C uses a replay buffer and A3C does not
  2. A2C has no critic
  3. A2C runs a single environment
  4. 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 nn-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.

Question 4

Why does A3C add an entropy bonus to its policy loss?

  1. To discourage premature collapse to a nearly deterministic policy, which would end exploration and stall softmax gradients
  2. To help the critic converge faster
  3. To make the policy gradient unbiased
  4. 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 β H(π(⋅∣s))\beta\,\mathcal H(\pi(\cdot\mid s)) 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

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).