Actor-Critic Methods: A2C, A3C, and Advantage Estimation
3162 words
16 min read
Visual companion
Python
Type and operator map
Python Week 1: the first filter for runtime behavior
View
Revision summary
What this note is really saying
Short form
# Actor-Critic Methods: A2C, A3C, and Advantage Estimation ## 🎯 Learning Objectives - Understand why combining policy gradients with value functions improves sample efficiency - Derive the advantage function and its role in reducing gradient variance - Implement Advantage Actor-Critic (A2C) - Understand A3C's async...

Actor-Critic Methods: A2C, A3C, and Advantage Estimation
🎯 Learning Objectives
- Understand why combining policy gradients with value functions improves sample efficiency
- Derive the advantage function and its role in reducing gradient variance
- Implement Advantage Actor-Critic (A2C)
- Understand A3C's asynchronous architecture
- Analyze the bias-variance tradeoff in advantage estimation
📋 Prerequisites
- Policy Gradients (Week 8): REINFORCE, score function, baseline
- TD Learning (Week 5): Value function estimation, TD error
- Deep Learning basics: Neural network optimization, sharing parameters
1. 📖 Core Content
1.1 Intuition: Why Combine Actor and Critic?
In REINFORCE (the basic policy gradient method), the agent uses the full Monte Carlo return Gt to evaluate its actions. This works but has high variance — you must complete many episodes before the signal averages out.
In TD learning, the agent learns a value function that estimates expected returns with low variance (but some bias).
Actor-Critic combines both:
- Actor: The policy πθ(a∣s) that decides which action to take
- Critic: The value function Vϕ(s) or Qϕ(s,a) that evaluates how good the state/action is The critic provides a low-variance baseline for the actor, reducing gradient variance. The actor improves the policy based on the critic's evaluation. This is the most widely used architecture in modern RL (PPO, SAC, TD3 are all actor-critic methods).
1.2 The Policy Gradient with a Critic
Recall the REINFORCE gradient:
The Actor-Critic gradient replaces Gt with an advantage estimate:
where A(s,a)=Q(s,a)−V(s) is the advantage function.
The advantage tells us: "How much better is taking action a compared to the average action in state s?"
1.2.1 Why Advantage?
The value function V(s) acts as a baseline. Subtracting it from Q(s,a) reduces variance without introducing bias:
Why? Because Eπ[∇θlogπ(a∣s)]=∇θEπ[1]=∇θ1=0.
The baseline can be any function of s (not a). The optimal baseline is V(s), giving us the advantage A(s,a)=Q(s,a)−V(s).
1.3 Estimating the Advantage
We rarely have Q(s,a) directly. Common advantage estimates (from simplest to most complex):
1.3.1 TD Error as Advantage
A(s,a)≈TD error δR+γV(s′)−V(s)This is the simplest advantage estimate. The TD error tells us how much better/worse the actual outcome was compared to the expected value.
Bias vs Variance: This has low variance (one-step TD) but can be biased if V is inaccurate.
1.3.2 Monte Carlo Advantage
A(s,a)≈Gt−V(s)Low bias (uses complete return) but very high variance.
1.3.3 Generalized Advantage Estimation (GAE)
GAE (Schulman et al., 2016) smoothly interpolates between TD and MC advantages:
where δt=Rt+1+γV(St+1)−V(St).
This is exactly TD(λ) applied to advantage estimation:
- λ=0: 1-step TD advantage (high bias, low variance)
- λ=1: Monte Carlo advantage (low bias, high variance)
- λ=0.95: typical in practice (balanced tradeoff)
1.4 A2C: Advantage Actor-Critic
A2C uses synchronous training with multiple parallel environments.
(Diagram)
1.4.1 A2C Loss Functions
Actor loss (policy gradient):
Critic loss (value function regression):
Entropy bonus (encourages exploration):
Total loss:
1.4.2 A2C Algorithm
textInitialize actor π_θ and critic V_φ networks loop for T steps: for each worker i in parallel: Run policy πθ for n steps Store (s_t, a_t, r_t, s_{t+1}) in trajectory buffer Compute advantages using GAE for each worker i: Compute actor loss, critic loss, entropy bonus Gradient step on combined loss Update θ, φ
Worked Example 1: A2C Advantage Computation
A3 steps for a single worker:
- Step 1: s₁ → a₁ → r₁=1, s₂
- Step 2: s₂ → a₂ → r₂=0, s₃
- Step 3: s₃ → a₃ → r₃=2, s₄ (terminal) Current critic values: V(s₁)=0.5, V(s₂)=0.3, V(s₃)=0.1, V(s₄)=0. γ=0.9. Compute TD errors: δ₁ = 1 + 0.9(0.3) - 0.5 = 1 + 0.27 - 0.5 = 0.77 δ₂ = 0 + 0.9(0.1) - 0.3 = 0 + 0.09 - 0.3 = -0.21 δ₃ = 2 + 0.9(0) - 0.1 = 1.9 Compute GAE(γ=0.9, λ=0.95): A₁ = δ₁ + 0.9(0.95)(-0.21) + (0.9·0.95)²(1.9) = 0.77 + 0.855(-0.21) + 0.731(1.9) = 0.77 - 0.180 + 1.389 = 1.979 A₂ = δ₂ + 0.9(0.95)(1.9) = -0.21 + 1.625 = 1.415 A₃ = δ₃ = 1.9 The advantages are highest for a₁ and a₃ because they led to high rewards. a₂ had negative TD error (the actual reward was worse than expected), but the GAE positive future advantage compensates.
1.5 A3C: Asynchronous Advantage Actor-Critic
A3C extends A2C with asynchronous training: multiple workers independently interact with their environments and update a shared global network asynchronously.
(Diagram)
Key Differences from A2C
| Aspect | A2C (Synchronous) | A3C (Asynchronous) |
|---|---|---|
| Workers | All workers sync before update | Workers update independently |
| Gradient | Sum over all workers | Each worker sends gradients when ready |
| Stability | More stable gradients | More diverse exploration |
| Wall-clock speed | Slower (sync wait) | Faster (no waiting) |
| Hardware utilization | Less efficient | More efficient |
1.6 A2C vs A3C vs DQN vs PPO
| Method | Actor-Critic? | Parallelism | Key Innovation |
|---|---|---|---|
| REINFORCE | No (no critic) | None | Basic policy gradient |
| A2C | Yes | Sync | Synchronous multi-worker |
| A3C | Yes | Async | Asynchronous multi-worker |
| DQN | No (value-only) | Replay buffer | Experience replay + target net |
| PPO | Yes | Sync | Clipped surrogate objective |
1.7 Edge Cases & Gotchas
- Shared vs separate networks: Actor and critic can share early layers (common in A2C/A3C). This speeds learning but may cause interference — fix by orthogonal initialization.
- GAE λ sensitivity: The choice of λ significantly affects performance. Too low λ (0-0.9): high bias, potentially too conservative. Too high λ (0.99-1): high variance, unstable learning.
- Entropy coefficient: If entropy bonus is too large, the policy never converges (stays random). If too small, it converges prematurely to a suboptimal policy.
- Value function as baseline only: The advantage should center at ~0. If advantages are consistently positive, the value function is underestimating; if consistently negative, it's overestimating.
- n-step returns: Instead of GAE, using n-step returns for advantage (∑k=0n−1γkrt+k+γnV(st+n)−V(st)) is simpler and works well.
1.8 Why This Matters
Actor-Critic methods are the foundation of almost all modern deep RL:
| Algorithm | Relationship to Actor-Critic |
|---|---|
| PPO | Actor-Critic + clipped surrogate |
| SAC | Actor-Critic + entropy regularization + double Q |
| TD3 | Actor-Critic + double Q + target policy smoothing |
| IMPALA | A3C-style async with V-trace off-policy correction |
| AlphaZero | MCTS as actor, neural network as critic |
If you understand A2C, you can understand all of these — they add specific modifications on top of the same core idea.
2. 📐 Key Formulas / Concepts
| Concept | Formula | Description |
|---|---|---|
| Actor gradient | $\nabla_\theta J = \mathbb{E}[\nabla_\theta \log \pi_\theta(a | s) \cdot A(s,a)]$ |
| Advantage | A(s,a)=Q(s,a)−V(s) | Action quality relative to baseline |
| TD advantage | A≈R+γV(s′)−V(s) | 1-step advantage estimate |
| GAE | AtGAE=∑l=0∞(γλ)lδt+l | λ-weighted advantage estimate |
| A2C loss | L=Lactor+c1Lcritic−c2Lentropy | Combined objective |
| Value function baseline | E[∇logπ⋅b(s)]=0 | Baseline doesn't bias gradient |
3. ⚠️ Common Pitfalls
Pitfall 1: Not Normalizing Advantages
Mistake: Using raw advantages without normalization.
Why: If advantages are all very large (e.g., range [-100, 100]), the policy gradient update can be huge, destabilizing training.
Correct approach: Normalize advantages across the batch (subtract mean, divide by standard deviation). This centers the advantages around 0 with unit variance, providing a stable gradient scale.
Pitfall 2: Sharing Too Many Parameters Between Actor and Critic
Mistake: Using a fully shared network for policy and value.
Why: The actor and critic have different objectives. The actor wants to maximize returns; the critic wants to predict returns accurately. Sharing all parameters forces one network to serve two masters, which can lead to feature interference.
Correct approach: Share early layers (feature extractors) but use separate output heads for policy and value. This balances sharing (efficient representation learning) with separation (avoiding interference).
Pitfall 3: Setting Entropy Coefficient Too High or Too Low
Mistake: Using a fixed entropy coefficient without tuning.
Why: Early training benefits from high entropy (exploration). Late training should have low entropy (exploitation). A fixed coefficient that's good for early training may prevent convergence; one good for late training may never explore enough.
Correct approach: Start with a moderate entropy coefficient (e.g., 0.01) and anneal it. Or use adaptive entropy tuning (SAC style).
Pitfall 4: Incorrect GAE Computation at Episode Boundaries
Mistake: Computing GAE across episode boundaries.
Why: The TD error formula assumes the value of the terminal state is 0. If the trajectory buffer includes states from two different episodes, the bootstrap value at the episode boundary is wrong.
Correct approach: Reset the GAE computation at episode boundaries. When s_{t+1} is terminal, set V(s_{t+1}) = 0 and don't continue the GAE sum beyond that point.
4. 📝 Practice Questions
Q1: Derive why any state-dependent baseline b(s) doesn't bias the policy gradient.The policy gradient with baseline:∇θJ=Es∼dπ,a∼π[∇θlogπθ(a∣s)⋅(Qπ(s,a)−b(s))]The bias introduced by b(s) is:Bias=Es,a[∇θlogπθ(a∣s)⋅b(s)]=Es∼dπ[b(s)⋅Ea∼π[∇θlogπθ(a∣s)]]Now, Ea∼π[∇θlogπθ(a∣s)]=∑aπθ(a∣s)∇θlogπθ(a∣s)=∑a∇θπθ(a∣s)=∇θ∑aπθ(a∣s)=∇θ1=0Therefore, the bias term = 0 for any b(s) that doesn't depend on a. The optimal baseline that minimizes variance is b(s)=Vπ(s), making A(s,a)=Qπ(s,a)−Vπ(s) the advantage function. Q2: For GAE with λ=0, show that AtGAE=δt (TD error). For λ=1, show that AtGAE=Gt−V(st) (MC advantage).λ=0: AtGAE=∑l=0∞(γ⋅0)lδt+l=δt+0+0+...=δtThis is exactly the 1-step TD error, giving highest bias/lowest variance.λ=1: AtGAE=∑l=0∞(γ⋅1)lδt+l=δt+γδt+1+γ2δt+2+...Expanding: δt=rt+γV(st+1)−V(st) γδt+1=γ(rt+1+γV(st+2)−V(st+1)) γ2δt+2=γ2(rt+2+γV(st+3)−V(st+2))Summing (telescoping): = rt+γrt+1+γ2rt+2+...−V(st)=Gt−V(st)This is the MC advantage, giving lowest bias/highest variance. Q3: In A2C with 8 parallel workers, each collecting n=5 steps per update, what's the effective batch size? How does this compare to a single-worker A2C with n=40 steps?With 8 workers × 5 steps = 40 (s, a, r) transitions per update. With 1 worker × 40 steps = 40 transitions per update.The batch size in terms of transitions is the same (40).However, the multi-worker approach has two advantages:
- Diverse exploration: Each worker experiences different states, reducing correlation between samples. This is like having a more diverse replay buffer.
- Wall-clock efficiency: With 8 workers, collecting 5 steps each takes ~5 step-times. Single worker needs 40 step-times (the environment step is often the bottleneck).
Multi-worker A2C gives better gradient estimates (lower variance) because the batch contains more diverse, less correlated samples. Q4: The entropy bonus in A2C is -c₂·H(π). Will this increase or decrease exploration? What happens if c₂ is too large?The entropy H(π)=−∑aπ(a∣s)logπ(a∣s) is maximized when the policy is uniform (max entropy) and minimized when it's deterministic (zero entropy).The loss includes -c₂·H(π), meaning we're subtracting entropy. Since we minimize the total loss, this encourages higher entropy (exploration).If c₂ is too large:
- The policy remains near-uniform (never specializes)
- The agent never learns to exploit good actions
- The policy gradient signal is overwhelmed by the entropy bonus
- The agent effectively acts randomly
If c₂ is too small:
- The policy converges quickly to a deterministic policy
- The agent may converge to a suboptimal deterministic policy without exploring enough
Typical values: c₂ = 0.01 to 0.1 for continuous control, c₂ = 0.001 to 0.01 for Atari. Q5: Explain why A3C's asynchronous updates can lead to "gradient staleness" and how it's mitigated.Gradient staleness: Worker A reads global parameters at time t, computes gradients for 5 steps, and sends updates at time t+5. Meanwhile, Workers B, C, D also computed and applied their gradients. Worker A's gradients were computed using stale parameters (from t) and are being applied to potentially very different parameters (at t+5).This is like using a map from last week to navigate today — the terrain may have changed.Mitigations:
n-step returns limit staleness: Each worker only collects n steps (e.g., 5-20) before updating, limiting the staleness window. RMSProp/Adam with global learning rate: Adaptive optimizers are more robust to stale gradients. Trust region methods (PPO): By clipping the surrogate objective, PPO limits how much each update can change the policy, making it more robust to stale gradients. IMPALA's V-trace: Corrects for the off-policyness introduced by stale parameters using importance sampling. Synchronous A2C avoids staleness entirely: all workers sync before each update, ensuring gradients are computed on the same parameters being updated.Q6: An A2C agent's advantages are all positive (range [0.5, 2.0]) for an entire training run. What does this indicate?Consistently positive advantages mean that the critic (value function) is underestimating the value of every state. For every state visited, the actual return is better than predicted.This indicates a systematic bias in the critic:
- The critic is too pessimistic: It consistently underestimates V(s)
- The actor is outperforming expectations: The actual returns are better than what the critic expects
Consequences:
- The policy gradient update is always positive (increase log probability of all actions)
- Relative differences between actions are preserved (since advantages scale differently per state-action)
- The learning signal is weaker than it should be (advantages should be centered around 0)
Fix: Normalize advantages to have zero mean across the batch. This is standard practice in A2C implementations. Q7: Compare A2C with a batch size of 32 (single worker, 32 steps per update) vs A2C with batch size 32 (4 workers, 8 steps each).
| Aspect | Single Worker (32 steps) | 4 Workers (8 steps each) |
|---|---|---|
| Data correlation | High (temporally adjacent states are similar) | Low (different env states) |
| Exploration diversity | Low (one trajectory) | High (4 trajectories) |
| Wall-clock per update | 32 environment steps | 8 environment steps + sync |
| Gradient variance | Higher (correlated data) | Lower (diverse data) |
| Experience diversity | Single sequence of 32 | 4 different sequences |
The multi-worker version generally gives better gradients (lower variance) and faster wall-clock training. This is why A2C/A3C are preferred over single-worker variants. Q8: Derive the actor loss gradient for a single (s,a) transition with advantage A.The actor loss for a single transition is:Lactor(s,a)=−logπθ(a∣s)⋅AThe gradient is:∇θLactor=−∇θlogπθ(a∣s)⋅AFor a Gaussian policy (continuous action space): πθ(a∣s)=N(μθ(s),σθ2(s))logπθ(a∣s)=−2σθ2(s)(a−μθ(s))2−log(2πσθ(s))∇θlogπθ=σθ2(s)a−μθ(s)⋅∇θμθ(s)−σθ3(s)(a−μθ(s))2−σθ2(s)⋅∇θσθ(s)For a categorical policy (discrete actions): πθ(a∣s)=softmax(hθ(s))a∇θlogπθ(a∣s)=∇θhθ(a∣s)−∑a′πθ(a′∣s)∇θhθ(a′∣s)where hθ(a∣s) is the logit for action a.The advantage A scales the gradient — actions with positive advantage are made more likely; actions with negative advantage are made less likely. Q9: In A2C, the critic loss Lcritic=(Gt−Vϕ(st))2 is the MSE between the return and the predicted value. Why use MSE rather than absolute error?MSE has a squared penalty (quadratic in error), while MAE has a linear penalty. For value estimation:
Gradient magnitude: MSE gradient is proportional to the error (Gt−Vϕ(st)), so large errors produce larger updates. This helps the critic quickly correct large mistakes. Sensitivity to outliers: MSE is more sensitive to outliers (returns far from the predicted value). This is actually desirable in RL because rare, high-return episodes are informative — we want the critic to learn from them quickly. Convergence properties: MSE corresponds to the variance-minimizing estimator (assuming Gaussian noise). The critic aims to estimate E[Gt∣St=s], and under MSE, the minimizer is the conditional expectation. Smoothness: MSE has smooth gradients everywhere, making optimization easier.The downside of MSE is that for very large errors (e.g., initial training), gradients can be too large, causing training instability. This is one reason advantage normalization is used — it keeps the critic targets and predictions in a reasonable range. Q10: Explain the "deadly triad" in actor-critic methods with function approximation.The "deadly triad" refers to the combination of three elements that can cause instability and divergence in RL:
- Function approximation: Representing V(s) or π(a|s) with a neural network (not a table)
- Bootstrapping: Updating based on current estimates (TD learning)
- Off-policy learning: Learning about one policy from data generated by another
Actor-critic methods with off-policy data (e.g., using a replay buffer) combine all three:
- Neural network parameterization (function approximation)
- TD error for the critic update (bootstrapping)
- Behavior policy differs from target policy when using stale data (off-policy)
Manifestations:
- Value function may diverge (grow without bound)
- Policy may oscillate between very different behaviors
- Learning may get stuck in poor local optima
Mitigations:
- A2C avoids off-policy learning: On-policy updates using fresh data from current policy
- PPO: Constrains policy changes to a trust region
- Target networks: Stabilize bootstrapping targets (used in DQN, SAC, TD3)
- Gradient clipping: Prevents huge updates from rare large errors
On-policy actor-critic (A2C, PPO) avoids the off-policy part of the triad, which is a key reason for their stability.
5. 🔗 Cross-References
- Previous: Policy Gradients (Week 8) — REINFORCE and baseline concept
- Next: PPO (Week 10) — Trust-region actor-critic
- Related: DQN (Week 7) — Value-based RL comparison
- External: Schulman et al., "Generalized Advantage Estimation" (ICLR 2016) Join Discord PreviousPolicy GradientsNextProximal Policy Optimization