Advantage Estimation & GAE
Was that action better than expected? Estimating that well is most of the job.
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 :
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 as the exponentially weighted average of all -step advantage estimators:
Where .
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 time:
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
- How does GAE interact with discount factor γ? determines the effective time horizon of returns ( steps). determines the effective horizon of bootstrapping trust in the Critic network ( steps).
- What happens if the Critic V(s) is inaccurate? If is poorly trained (high approximation error), low transfers Critic estimation error directly into the Advantage, corrupting Policy updates. Train Critic thoroughly.
Check yourself
Question 1 of 3
What fundamental trade-off in Advantage Estimation does GAE (Generalized Advantage Estimation) address?