Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.A player and a coach
An actor-critic agent has two parts. The actor chooses the moves. The critic watches and, after every move, says whether things now look better or worse than it expected. The actor makes moves that pleasantly surprised the critic more likely. Because the critic judges each move right away instead of waiting for the end of the game, learning is much less noisy, as long as the critic itself is a good judge.
Actor-critic methods such as A2C, A3C and PPO trained agents for Atari, StarCraft II and Dota 2, and robot controllers in simulation.
- 1. In actor-critic, the actor…
- 2. The critic tells the actor…
- 3. Actor-critic learning depends on…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.By hand
- Critic: an estimate V_w(s) of the state value of the current policy, trained by TD learning (topic L2-2).
- TD error: δ_t = r_(t+1) + γV(S_(t+1)) − V(S_t), with V(S_(t+1)) = 0 if the episode really ended. If V = V^π, E[δ_t | S_t, A_t] = A^π(S_t, A_t), the advantage.
- Actor update: θ ← θ + α Â_t ∇log π_θ(A_t|S_t), with Â_t an advantage estimate.
- n-step advantage: Â^(n)t = r(t+1) + … + γ^(n−1) r_(t+n) + γ^n V(S_(t+n)) − V(S_t).
- GAE(λ): Â_t = Σ_k (γλ)^k δ_(t+k). λ = 0 gives the one-step TD error (low variance, biased by the critic); λ = 1 gives the Monte Carlo return minus V (unbiased, high variance).
- A3C and A2C: A3C (Mnih et al. 2016) runs many asynchronous workers that each push gradients to shared parameters; A2C waits for all workers and makes one synchronous batched update, which is simpler and uses GPUs better.
- Truncation vs termination: an episode cut by a time limit has not ended; bootstrap from V(S_(t+1)) as usual.
- 1. The TD error δ is an estimate of…
- 2. GAE with λ = 0 is…
- 3. A2C differs from A3C in that its workers…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.A2C on cart-pole
Exercise 1.
- 16 cart-poles per learner (reward 1 per step, 200-step limit), run for 20 steps per update.
- Actor: π(right|s) = sigmoid(w·(s, 1)). Critic: linear in 15 features, 1, the scaled state and all pairwise products.
- GAE(0.95), γ = 0.99, one Adam step for each per update (actor 0.03, critic 1.0); the critic moves toward V + Â.
- Time-outs are cuts: the next state’s value is still used.
Practice.
- Start from λ = 0.95, γ = 0.99, a few dozen parallel environments, and rollouts of 5 to 128 steps.
- The critic must keep up: give it a larger step size or several updates per batch; a lagging critic poisons every advantage.
- Normalise advantages per batch, and add a small entropy bonus to keep the policy exploring.
- Separate terminated from truncated: Gymnasium returns both flags for this reason.
- Share or split the network: a shared body with policy and value heads saves computation; separate networks are easier to tune.
- Tools: Stable-Baselines3 A2C and PPO, CleanRL single-file implementations, and vectorised environments (Gymnasium’s SyncVectorEnv, EnvPool).
def gae(rewards, values, next_values, fails, dones, gamma, lam):
adv = np.zeros_like(values); run = np.zeros(values.shape[1:])
for k in range(len(values) - 1, -1, -1):
delta = rewards[k] + gamma * next_values[k] * ~fails[k] - values[k]
run = delta + gamma * lam * ~dones[k] * run
adv[k] = run
return adv- 1. A common default for GAE is…
- 2. A time-limit cut should…
- 3. If the critic lags behind the policy…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
Advantage form. Subtracting V^π(s) from Q^π(s, a) is a state-dependent baseline, so E[(Q − V)∇log π] = E[Q∇log π] (topic L4-2).
TD error as advantage. E[δ_t | S_t, A_t] = E[r_(t+1) + γV^π(S_(t+1)) | S_t, A_t] − V^π(S_t) = Q^π(S_t, A_t) − V^π(S_t). With an approximate V the estimate is biased by the critic’s error.
Telescoping. With no episode end inside the segment, Σ_(k=0)^(n−1) γ^k δ_(t+k) = Σ_k γ^k r_(t+k+1) + γ^n V(S_(t+n)) − V(S_t): the intermediate values cancel. So the n-step advantage is a discounted sum of TD errors, and λ = 1 gives the return minus V.
GAE as an average. Σ_k (γλ)^k δ_(t+k) = (1 − λ)Σ_(n≥1) λ^(n−1) Â^(n)_t: GAE is an exponentially weighted average of all n-step advantages, just as TD(λ) averages n-step returns. Its effective horizon is about 1/(1 − γλ) steps (about 17 for γ = 0.99, λ = 0.95).
Bias and variance. Small λ leans on the critic: less noise, but every error in V enters the gradient. Large λ leans on sampled rewards: unbiased if the segment ends at a true terminal, noisier.
- 1. If V = V^π, the expected TD error given (s, a) equals…
- 2. The sum of discounted TD errors over n steps equals…
- 3. GAE's effective horizon is about…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.On cart-pole, how does A2C’s learning depend on λ, on how fast the critic learns, and on handling the time limit correctly?
History.
- A. Barto, R. Sutton and C. Anderson (1983) introduced the actor-critic architecture, on the cart-pole task itself.
- V. Konda and J. Tsitsiklis (2000) proved convergence of actor-critic algorithms with two time scales.
- V. Mnih and colleagues (2016) introduced A3C, asynchronous advantage actor-critic; the synchronous A2C variant followed in OpenAI Baselines (2017).
- J. Schulman, P. Moritz, S. Levine, M. Jordan and P. Abbeel (2016) introduced generalised advantage estimation.
- F. Pardo, A. Tavakoli, V. Levdik and P. Kormushev (2018) analysed time limits in reinforcement learning.
Exercise 2.
- A2C as in Exercise 1, 600 updates of 16 × 20 environment steps; four learners per setting, trained at once.
- GAE with λ = 0, 0.5, 0.9, 0.95 and 1 (critic step 1.0); then λ = 0.95 with a slow critic (step 0.05), and with the time limit treated as failure.
- Measured: environment steps until the last 20 finished episodes average 195; the mean of the last 20 episodes; the critic’s value of the upright state.
Seed 0:
| setting | thousands of steps to reach 195 (4 learners) | mean of last 20 episodes | critic value, upright state |
|---|---|---|---|
| λ = 0 | 93.4, 68.7, 51.1, 69.9 | 172.3 | 88.8 |
| λ = 0.5 | 50.6, 62.2, 63.3, 89.6 | 191.2 | 90.9 |
| λ = 0.9 | 75.1, 55.2, 59.9, 62.5 | 200.0 | 100.3 |
| λ = 0.95 | 55.0, 57.5, 59.4, 54.8 | 197.9 | 99.0 |
| λ = 1 | 61.3, 57.7, 53.2, 65.1 | 197.5 | 99.5 |
| λ = 0.95, slow critic | never, never, never, never | 88.3 | 23.3 |
| λ = 0.95, time limit as failure | 71.0, 60.1, 66.6, 63.6 | 199.3 | 72.8 |
- λ = 0 was the weakest: every learner reached 195 at some point, but the one-step advantages inherit the critic’s errors, and the final mean was 172.3 (164.2 and 144.7 on seeds 1 and 2) against 197.5 to 200.0 for λ ≥ 0.9.
- λ from 0.9 to 1 behaved alike here. Each 20-step rollout is cut and bootstrapped from the critic, so even λ = 1 is not a full Monte Carlo return, and these short-horizon advantages are not very noisy.
- A slow critic broke everything: with critic step 0.05 the upright value was still 23 when it should be near 100, no learner ever reached 195, and the final means were 88.3, 79.8 and 85.3 on the three seeds.
- The time-limit bug taught the critic that balancing ends in a crash: its upright value was 72.8 (70.5 and 71.5 on seeds 1 and 2) instead of about 100. On this task the policy still learned, because the fake failure comes only after 200 good steps; on tasks where the end of time matters it misleads the actor.
- Exercise 1: four learners with λ = 0.95 ended with last-20 means of 199.2, 195.8, 197.8 and 200.0; their critics valued the upright state at 97.7 to 101.3, close to 1/(1 − γ) = 100.
- Seeds 1 and 2 (final means for λ = 0, 0.5, 0.9, 0.95, 1): 164.2, 191.0, 199.8, 197.7, 198.7 and 144.7, 199.2, 199.0, 198.8, 199.2.
Actor-critic in practice
- PPO (next topic) keeps the A2C structure but takes several clipped steps per batch.
- Off-policy actor-critics (DDPG, TD3, SAC; topic L4-5) learn Q instead of V and reuse old data from a replay buffer.
- IMPALA and V-trace scale actor-critic to thousands of actors, correcting for the lag between acting and learning policies.
- Language models: PPO-based RLHF is an actor-critic with a value head on the language model.
References
- A. G. Barto, R. S. Sutton and C. W. Anderson (1983). “Neuronlike adaptive elements that can solve difficult learning control problems.” IEEE Transactions on Systems, Man, and Cybernetics.
- V. R. Konda and J. N. Tsitsiklis (2000). “Actor-critic algorithms.” NeurIPS.
- V. Mnih, A. P. Badia, M. Mirza, A. Graves, T. Lillicrap, T. Harley, D. Silver and K. Kavukcuoglu (2016). “Asynchronous methods for deep reinforcement learning.” ICML.
- J. Schulman, P. Moritz, S. Levine, M. Jordan and P. Abbeel (2016). “High-dimensional continuous control using generalized advantage estimation.” ICLR.
- F. Pardo, A. Tavakoli, V. Levdik and P. Kormushev (2018). “Time limits in reinforcement learning.” ICML.