Advantage Estimation & GAE

Was that action better than expected? Estimating that well is most of the job.

🔴 advanced5 min readrl
The advantage measures how much better an action was than what the agent expected in that situation, and it drives most policy updates. Estimating it involves a trade-off. Looking only one step ahead gives a steady estimate that can be systematically wrong. Waiting for the whole episode gives an unbiased estimate that is very noisy. Generalised advantage estimation, used in PPO, blends estimates from every horizon in between, with a single setting that chooses where to sit between steady and unbiased.

The Bias-Variance Spectrum in Advantage Estimation

Given 1-step TD error δtV=rt+1+γV(st+1)−V(st)\delta_t^V = r_{t+1} + \gamma V(s_{t+1}) - V(s_t):

  1-Step Advantage (k=1):     A_t^{(1)} = δ_t^V                                 (High Bias, LOW VARIANCE)
  2-Step Advantage (k=2):     A_t^{(2)} = δ_t^V + γ δ_{t+1}^V
  k-Step Advantage:          A_t^{(k)} = ∑_{l=0}^{k-1} γ^l δ_{t+l}^V
  Monte Carlo (k=∞):         A_t^{(∞)} = ∑_{l=0}^∞ γ^l δ_{t+l}^V = G_t - V(s_t) (ZERO BIAS, High Variance)

The GAE Formulation

GAE defines the advantage estimator AtGAE(γ,λ)A_t^{\text{GAE}(\gamma, \lambda)} as the exponentially weighted average of all kk-step advantage estimators:

AtGAE(γ,λ)=(1−λ)∑k=1∞λk−1At(k)=∑l=0∞(γλ)lδt+lVA_t^{\text{GAE}(\gamma, \lambda)} = (1 - \lambda) \sum_{k=1}^\infty \lambda^{k-1} A_t^{(k)} = \sum_{l=0}^\infty (\gamma \lambda)^l \delta_{t+l}^V

Where δt+lV=rt+l+1+γV(st+l+1)−V(st+l)\delta_{t+l}^V = r_{t+l+1} + \gamma V(s_{t+l+1}) - V(s_{t+l}).

                    GAE Exponential Weighting (λ ∈ [0, 1])
  λ = 0 ───────────────► 1-Step TD (Fastest learning, low variance, high bias)
  λ = 0.95 ────────────► Standard PPO Setting (Optimal Bias-Variance Sweet Spot!)
  λ = 1.0 ────────────► Full Monte Carlo (Slow learning, high variance, zero bias)

Recursive Implementation

GAE can be computed backwards from the end of an episode in O(T)O(T) time:

AtGAE=δtV+(γλ)At+1GAEA_t^{\text{GAE}} = \delta_t^V + (\gamma \lambda) A_{t+1}^{\text{GAE}}
python
# Backward calculation of GAE in PyTorch
gae = 0
advantages = torch.zeros_like(rewards)
for t in reversed(range(len(rewards))):
    delta = rewards[t] + gamma * values[t+1] * (1 - dones[t]) - values[t]
    gae = delta + gamma * lam * (1 - dones[t]) * gae
    advantages[t] = gae

Say this out loud

"Generalized Advantage Estimation (GAE) calculates Advantage A_t by taking an exponentially weighted average of k-step TD errors using parameter λ ∈ [0, 1]. λ=0 gives 1-step TD (low variance, high bias); λ=1 gives full Monte Carlo (high variance, zero bias). PPO sets λ=0.95 as the optimal sweet spot for deep RL and alignment."

Follow-ups to expect

Check yourself

Question 1 of 3

What fundamental trade-off in Advantage Estimation does GAE (Generalized Advantage Estimation) address?

More in Reinforcement Learning

See all →
Value-Based vs Policy-Based Methods5 minMulti-Armed Bandits4 minProximal Policy Optimization5 min