Level 3 In-Depth AI · Reinforcement Learning
Actor-Critic Methods
Combine a policy (the actor) with a learned value function (the critic). The critic tells the actor, after every step, whether things went better or worse than expected. Advantage, A2C and A3C, and generalised advantage estimation.
- Level
- ●●●●● Advanced
- Reading
- 14 min
- To learn it well
- 1.5 hours to read, an afternoon to practise
- Builds on
- 18 concepts →
- Quiz
- 4 questions ↓
This leads to
Proximal Policy OptimizationThe full path from zero — 18 concepts before this one
- What Is AI?
- Probability Basics
- Derivatives and Slopes
- Vectors
- How Machines Learn
- Partial Derivatives and Gradients
- Matrices and Matrix Multiplication
- Supervised, Unsupervised and Reinforcement Learning
- Gradient Descent
- Supervised Learning
- Reinforcement Learning: The Basics
- Linear Regression
- The Perceptron
- Markov Decision Processes
- Logistic Regression
- Value Functions and Bellman Equations
- Neural Networks
- Policy Gradients
- Actor-Critic Methods
Read them roughly in this order. See it on the concept map →
Why it matters
REINFORCE learns a policy directly, but it has two weaknesses. It must wait until an episode ends to compute each return, and that return is very noisy, so learning is slow and erratic. Value-based methods learn from every single step with low noise, but they struggle with continuous actions and can't represent random policies.
Actor-critic methods take the best of both. An actor (the policy) chooses actions. A critic (a value function) watches and, after every step, says whether the outcome was better or worse than expected. The actor follows a policy gradient, but it is weighted by the critic's low-noise judgment instead of a raw return.
Almost every modern deep-RL algorithm is an actor-critic: A2C and A3C, Proximal Policy Optimization (the workhorse behind RLHF and Preference Optimization), and SAC and TD3 for robotics. The critic idea also explains the "value model" that classic RLHF trains next to the language model. Once you understand this chapter, most RL papers become readable.
The intuition
Think of an apprentice chef (the actor) and an experienced taster (the critic). The apprentice cooks. The taster has eaten thousands of dishes and has a sense of how good a dish should be at each stage. After each step, the taster doesn't say "the final meal scored 7 out of 10". The taster says "that's better than I'd expect at this point" or "worse than I'd expect". The apprentice adjusts on the spot, without waiting for the meal to be finished.
Meanwhile the taster is learning too. Each time the actual outcome differs from the taster's expectation, the taster updates their sense of what to expect. The two improve together. The apprentice's cooking gets better, and the taster's judgments get more accurate. Each makes the other's job easier.
The key quantity is the surprise, the TD error from Q-Learning:
"What actually happened (one real reward plus the critic's estimate of where I landed) minus what the critic expected." If , the action was better than expected, so make it more likely. If , make it less likely. And in both cases, move the critic's estimate towards what happened.
Key idea Actor-critic = policy gradient with the noisy return replaced by the critic's advantage estimate, "how much better than expected was that?". The critic learns by TD, the actor by policy gradient, and they train together.
How it works
The advantage
Policy Gradients showed that subtracting a baseline from the return reduces noise without biasing the gradient, and that the ideal baseline is the state value . What remains is the advantage:
It answers: how much better is action than the policy's average behaviour in state ? A positive advantage means the action beats the policy's own average, so do it more. The policy gradient becomes
We don't know , but the TD error estimates it. Given and , the expected value of is exactly (that is the Bellman equation). So the TD error , computed with the true , is an unbiased sample of the advantage. With a learned critic it is a slightly biased but far less noisy estimate. This is the central bargain of actor-critic: accept a little bias to remove a lot of variance.
One-step actor-critic
With actor parameters and critic parameters ( for "weights"; for a table, one number per state), after every step:
- Compute the TD error: . Use for a terminal .
- Update the critic towards the TD target: .
- Update the actor along the policy gradient: .
For a table, is 1 for the entry of and 0 elsewhere, so step 2 is just the TD(0) rule from Q-Learning. For a softmax actor, with respect to the logits is "one-hot of the action taken minus the probabilities" (Policy Gradients).
Worked example. The critic believes . The agent takes "right" with probability 0.25 (all four actions equally likely), receives , and lands in with . With :
- TD error: . Better than expected.
- Critic, with : .
- Actor, with : the logit gradient is , so "right" gains in logit and the other three each lose about 0.003. "Right" becomes slightly more likely.
Deep actor-critic: A2C and A3C
With neural networks, actor and critic are usually one network with two heads: a shared body that reads the state, a policy head that outputs action logits, and a value head that outputs a single number . The training loss combines three parts:
Here is the advantage estimate, is the critic's regression target (for example an -step return), and is the entropy of the action distribution, a measure of how spread out it is (Entropy, Cross-Entropy and KL Divergence). Rewarding entropy stops the policy collapsing to a deterministic one too early. The constants (often 0.5) and (often 0.01) balance the terms.
Instead of one-step TD errors, these methods usually look a few real steps ahead. The n-step return adds actual rewards and then bootstraps:
A3C (Asynchronous Advantage Actor-Critic; Mnih et al., DeepMind, 2016) ran many copies of the agent in parallel on CPU threads. Each explored its own copy of the environment and sent gradient updates to a shared network. The parallel actors see different situations at the same moment, which decorrelates the data much as Deep Q-Networks's replay buffer does, but without storing anything. A2C is the synchronous version: wait for all the workers, then make one batched update. A2C turned out to be just as good and simpler to run on GPUs, so it became the standard.
Generalised advantage estimation
How far ahead should the advantage estimate look? One-step TD () has low variance but leans heavily on the critic, which may be wrong (bias). The full Monte Carlo return () is unbiased but noisy. Generalised advantage estimation (GAE) (Schulman et al., 2015) mixes all the -step estimates with exponentially decaying weights. Written in terms of TD errors, it is simply a discounted sum of future surprises:
The new parameter (between 0 and 1) slides between the two extremes. gives the one-step TD error . gives , the Monte Carlo advantage. Values around work well in practice and are the default in most Proximal Policy Optimization code.
Worked example (computed by the second code block below). A 4-step episode with rewards 0, 0, 0, 1, critic values 0.5, 0.6, 0.6, 0.7, and . The first TD error is . With the first step's advantage is just 0.04. With it is . With it is 0.198, in between and much closer to the Monte Carlo value, because the critic here underestimates the later states.
In code
A tabular one-step actor-critic on the icy gridworld from Value Functions and Bellman Equations. The actor is a table of softmax logits H, the critic a table of values V. Both learn from the same TD error, at every step.
import numpy as np
WALL, GOAL, PIT, START = (1, 1), (0, 3), (1, 3), (3, 0)
MOVES = [(-1, 0), (1, 0), (0, -1), (0, 1)] # up, down, left, right
SIDE = {0: (2, 3), 1: (2, 3), 2: (0, 1), 3: (0, 1)} # sideways slips
def step(s, a, rng): # the icy gridworld again
x = rng.random()
a = a if x < 0.8 else SIDE[a][0] if x < 0.9 else SIDE[a][1]
r, c = s[0] + MOVES[a][0], s[1] + MOVES[a][1]
if 0 <= r < 4 and 0 <= c < 4 and (r, c) != WALL: s = (r, c)
return s, (1.0 if s == GOAL else -1.0 if s == PIT else 0.0), s in (GOAL, PIT)
rng = np.random.default_rng(0)
H = np.zeros((4, 4, 4)) # actor: action preferences (logits) per square
V = np.zeros((4, 4)) # critic: state-value estimate per square
alpha_actor, alpha_critic, gamma = 0.1, 0.1, 0.9
returns = []
for episode in range(1, 3001):
s, G, disc, done = START, 0.0, 1.0, False
while not done:
pi = np.exp(H[s]) / np.exp(H[s]).sum() # softmax policy
a = rng.choice(4, p=pi)
s2, r, done = step(s, a, rng)
delta = r + (0 if done else gamma * V[s2]) - V[s] # TD error = advantage estimate
V[s] += alpha_critic * delta # critic: TD(0) update
grad_log_pi = -pi; grad_log_pi[a] += 1 # d log π(a|s) / d logits
H[s] += alpha_actor * delta * grad_log_pi # actor: policy-gradient step
G += disc * r; disc *= gamma; s = s2
returns.append(G)
if episode in (100, 500, 1000, 2000, 3000):
print(f"episodes {episode-99:4d}-{episode:4d}: average return {np.mean(returns[-100:]):+.3f}")
print(f"critic's V(start) = {V[START]:.3f} (optimal v*: 0.473)")
print("greedy actions:\n" + "\n".join(" ".join("■" if (r, c) in (WALL, GOAL, PIT) else "↑↓←→"[H[r, c].argmax()]
for c in range(4)) for r in range(4)))
# episodes 1- 100: average return -0.014
# episodes 401- 500: average return +0.413
# episodes 901-1000: average return +0.439
# episodes 1901-2000: average return +0.465
# episodes 2901-3000: average return +0.464
# critic's V(start) = 0.489 (optimal v*: 0.473)
# greedy actions:
# → → → ■
# ↑ ■ ↑ ■
# ↑ ← ← ←
# ↑ ← ← ←
Compare this with Q-Learning on the same gridworld. The return climbs above 0.4 within 500 episodes, against several thousand for ε-greedy Q-learning, and settles near 0.465, close to the optimal 0.473. There is no ε here. The actor explores because its policy is random, and it becomes more decisive by itself as the logits grow. The critic's estimate of the start square, 0.489, is close to the true optimal value.
The greedy actions read off the actor match the optimal policy along the route it actually uses. In the rarely visited squares on the right of the bottom two rows they differ: the actor still prefers ←, including just below the pit, where value iteration chose ↓. The actor has had little reason to refine squares it almost never visits.
Here is GAE on a single short trajectory, with the same backward loop that Proximal Policy Optimization implementations use:
import numpy as np
def gae(rewards, values, last_value, gamma=0.99, lam=0.95):
"""Generalised advantage estimates for one trajectory (last_value = 0 if it ended)."""
values = np.append(values, last_value)
adv, running = np.zeros(len(rewards)), 0.0
for t in reversed(range(len(rewards))):
delta = rewards[t] + gamma * values[t + 1] - values[t] # one-step TD error
running = delta + gamma * lam * running # discounted sum of TD errors
adv[t] = running
return adv
rewards = np.array([0.0, 0.0, 0.0, 1.0]) # reward only at the end
values = np.array([0.5, 0.6, 0.6, 0.7]) # the critic's current guesses V(S_t)
for lam in (0.0, 0.5, 0.95, 1.0):
print(f"lambda = {lam:<4} advantages: {np.round(gae(rewards, values, 0.0, gamma=0.9, lam=lam), 3)}")
# lambda = 0.0 advantages: [ 0.04 -0.06 0.03 0.3 ]
# lambda = 0.5 advantages: [0.046 0.014 0.165 0.3 ]
# lambda = 0.95 advantages: [0.198 0.185 0.287 0.3 ]
# lambda = 1.0 advantages: [0.229 0.21 0.3 0.3 ]
The loop runs backwards because each advantage is the current TD error plus times the next step's advantage, the same recursive trick as .
The next step: A2C on a real environment
Stable-Baselines3 ships a tested A2C (shared actor-critic network, n-step returns, entropy bonus, parallel environments). This needs pip install gymnasium stable-baselines3, so it isn't run here:
import gymnasium as gym
from stable_baselines3 import A2C
from stable_baselines3.common.env_util import make_vec_env
env = make_vec_env("CartPole-v1", n_envs=8) # 8 environments stepped in parallel
model = A2C("MlpPolicy", env, n_steps=5, gamma=0.99, gae_lambda=1.0,
ent_coef=0.01, vf_coef=0.5, verbose=1)
model.learn(total_timesteps=200_000)
Common pitfalls
- A bad critic misleads the actor. Early in training the critic is wrong, and its advantage estimates can push the actor the wrong way. Use a larger critic learning rate, or train the critic for a while first, and watch the critic's loss.
- Gradients through the target. The critic's target must be treated as a constant. In PyTorch, detach it, or the critic learns to move its targets instead of its predictions.
- Unscaled advantages. Advantages can vary by orders of magnitude between tasks. Normalising them per batch (subtract the mean, divide by the standard deviation) is a standard and very effective trick.
- Imbalanced loss terms. If the value loss is much larger than the policy loss in a shared network, it dominates the shared layers. Tune , or use separate networks.
- Entropy collapse. If the policy's entropy drops to nearly zero early, exploration stops. Log the entropy, and raise if it falls too fast.
Watch out Actor-critic is still on-policy (except for the off-policy variants below). Data collected by an old version of the actor gives biased gradients for the new one. A3C's asynchronous workers are already slightly stale, and taking many gradient steps on one batch makes it worse. Controlling exactly that staleness is what Proximal Policy Optimization adds.
Variations
- Proximal Policy Optimization: actor-critic with GAE, plus a clipped objective that allows several safe gradient epochs per batch of data. The most widely used deep-RL algorithm.
- TRPO (Schulman et al., 2015): limits each policy update with a constraint on the KL divergence. PPO is its simpler successor.
- DDPG and TD3 (2015, 2018): actor-critic for continuous actions with a deterministic actor and a Q-function critic, trained off-policy from a replay buffer like Deep Q-Networks.
- SAC (Soft Actor-Critic; Haarnoja et al., 2018): off-policy, with entropy maximisation built into the objective. A standard choice for robot learning.
- IMPALA (DeepMind, 2018): many actors feed one central learner, with an importance-weighting correction ("V-trace") for the lag between them.
- Critics in planning: AlphaGo's value network is a critic for board positions (Monte Carlo Tree Search and AlphaGo), and Dreamer trains an actor-critic inside a learned world model (Model-Based RL and World Models).
A bit of history
Actor-critic is one of the oldest ideas in RL. In 1983, Andrew Barto, Richard Sutton and Charles Anderson balanced a pole on a cart with two neuron-like elements, an "associative search element" (the actor) and an "adaptive critic element". The pole-balancing benchmark itself is the CartPole of Deep Q-Networks. The idea had roots in Ian Witten's 1977 work and in theories of how the brain's dopamine signal reports prediction errors. That link, made explicit by Schultz, Dayan and Montague in 1997, is one of neuroscience's best-known connections to RL. Theoretical foundations came from Konda and Tsitsiklis (1999–2000) and the policy gradient theorem. The deep era began with A3C in 2016, which trained faster on a multi-core CPU than DQN did on a GPU. GAE (2015) and then Proximal Policy Optimization (2017) made actor-critic the default family for deep RL.
Try it
- Set
alpha_critic = 0.0, so the critic stays at 0. The TD error is then just the reward, and the actor only learns on the final step of each episode. How much slower does learning become?- Make the critic learn ten times faster than the actor (
alpha_critic = 0.5, alpha_actor = 0.05) and the reverse. Which is more stable?- In the GAE code, change the critic values to the true returns
[0.729, 0.81, 0.9, 1.0]. What happens to the advantages for every λ, and why?Hint for 3: with a perfect critic every TD error is zero in this deterministic episode.
Learn more
Hand-picked courses, books, videos and tutorials for going deeper. See all resources →
Reinforcement Learning: An Introduction
The foundational RL textbook by the field's founders. Free PDF.
Spinning Up in Deep RL
OpenAI's short, precise introduction to deep RL: key concepts and notation, the policy-gradient derivation, and clean reference implementations of VPG, PPO, DDPG, TD3 and SAC.
Policy Gradient Algorithms
The policy-gradient family in one place, from REINFORCE and actor-critic to A3C, TRPO, PPO and SAC, with consistent notation and derivations.
Asynchronous Methods for Deep Reinforcement Learning
A3C: many actor-learners running in parallel on CPU threads, each computing advantage actor-critic updates. Its synchronous version became A2C.
High-Dimensional Continuous Control Using Generalized Advantage Estimation
Introduced GAE, an exponentially weighted mix of multi-step advantage estimates whose λ parameter trades bias against variance. Used by nearly every PPO implementation.
Hugging Face Deep RL Course
A hands-on deep reinforcement learning course from Q-learning to PPO. You train agents in games.
Stable-Baselines3 documentation
Reliable PyTorch implementations of PPO, A2C, DQN, SAC and more, with a one-line training API that works on any Gymnasium environment. The quickest way to train a real agent.
Facts checked as of 30 November 2026. Fast-moving details (products, prices, laws) change often. · Source: content/entries/rl/actor-critic.md