Skip to content
mlmentorship

Advantage estimation and GAE

Policy gradients need a low-variance estimate of how much better an action was than average. GAE is the standard answer: an exponentially weighted blend of n-step returns.

Published · 6 min read ·Specialist ·Advanced

Summary

The advantage measures how much better action is than the policy’s average. Generalized Advantage Estimation (GAE, Schulman et al., 2016) estimates it as an exponentially weighted average of -step TD residuals, controlled by a single parameter .

Policy gradient methods optimize . The choice of controls the bias-variance tradeoff:

  • (full return): unbiased, high variance.
  • : lower variance but needs an action-value estimator.
  • : same expectation as but with the baseline subtracted, lower variance.

Substituting an estimator for introduces bias. GAE makes this tradeoff explicit and tunable. It is the default advantage estimator in PPO, the most widely deployed RL algorithm.

The mechanism

Define the TD residual at step :

The -step advantage estimate is

GAE blends all -step estimates with exponential weight :

In code this collapses to a backward recursion:

A single backward pass over the trajectory.

Temporal credit assignment

One backward scan adds the same decaying residuals

A backward recurrence equals a weighted residual sumWith gamma times lambda equal to 0.8, residuals (1,2,-1) give advantage 1.96. The backward scan gives the same answer.Walk backward: decay the future, addtoday-1-1-1 + 0.8 x 0x .821.22 + 0.8 x -1x .811.961 + 0.8 x 1.2Future residuals cross more decayboundaries.
Derivation
GAE as a weighted residual trace and reverse scan In a four-step finite rollout, delta t contributes to advantage t with weight one, delta t plus one with gamma lambda, delta t plus two with gamma lambda squared, and delta t plus three with gamma lambda cubed. Below, dashed arrows run from the rollout boundary toward time t, showing the equivalent backward recursion: at each step, add the local delta to gamma lambda times the accumulated value from the right. UNROLLED VIEW: CONTRIBUTIONS TO Ât δt δt+1 δt+2 δt+3 weight 1 weight γλ weight (γλ)² weight (γλ)³ Ât = δt + γλ δt+1 + (γλ)² δt+2 + (γλ)³ δt+3 COMPUTATION VIEW: SCAN FROM THE ROLLOUT BOUNDARY TOWARD t at each step: accumulated value ← local δ + γλ × value from the right Ât final estimate Ât+1 carry left Ât+2 carry left Ât+3 = δt+3 start at boundary dashed arrows: recursion direction
start at the right edge of the rollout and scan left. Each step keeps its own TD residual at full strength, then adds γλ times the value already accumulated from later steps. Unrolling that recursion gives weights 1, γλ, (γλ)2, ... for δt, δt+1, δt+2, ... .
Check: How much does the residual three steps later contribute? Why can one reverse scan compute the total?
Read it this way: With gamma times lambda equal to 0.8, residuals (1,2,-1) give advantage 1.96. The backward scan gives the same answer.
Which residual crosses two decay boundaries before reaching the first time step?

The two knobs

  • (discount): how much future reward matters. Part of the problem definition; usually 0.99 for episodic, 0.95 to 0.999 for continuing tasks.
  • (GAE): bias-variance dial.
    • recovers the 1-step TD residual: low variance, biased by errors.
    • recovers the full Monte Carlo return minus : unbiased, high variance.
    • to is the standard for PPO.

Why subtracting a baseline reduces variance

For any function depending only on state, . So the gradient estimator

has the same expectation but lower variance, when correlates with . The optimal baseline is exactly , hence the advantage formulation.

How it is used in PPO

PPO trains an actor and a value critic jointly. At each rollout:

  1. Run the policy for steps in parallel environments. Collect transitions.
  2. Run the value network on every observed state to get .
  3. Compute and then via the GAE recursion.
  4. Compute returns as for the value-function regression target.
  5. Normalize advantages (subtract mean, divide by std) per batch. Important for training stability.
  6. Train policy with the clipped objective using , train value network on .

Common pitfalls

  • Forgetting to bootstrap on truncation. When an episode is cut off mid-trajectory (not because of termination), should use as the bootstrap. Conflating truncation with termination is a frequent bug.
  • Not normalizing advantages. PPO almost always benefits from per-batch advantage normalization.
  • Using with a large on long horizons. Variance explodes.
  • Applying GAE in off-policy settings without correction. GAE assumes on-policy data. With a replay buffer and importance sampling, V-trace or Retrace is the corrected version.