TL;DR
Generalized advantage estimation (GAE) estimates how much better each action was than expected, using the rewards and value estimates seen along a trajectory. It is a weighted sum of one-step TD errors, where the weights shrink geometrically with distance into the future. A single parameter, , slides the estimate between a low-variance, biased version at one end and a high-variance, unbiased version at the other.
GAE is the advantage estimator used inside most modern policy-gradient training, so the choice of directly shapes how fast and how stably a policy learns.
Where you'll see it: as the advantage signal in PPO and other actor-critic methods that train robots, game agents and language-model policies.
Intuition
Looking a few steps ahead
A policy-gradient update needs to know whether an action helped. The advantage answers that, but it is defined through expectations the agent cannot compute directly. It has to be estimated from one trajectory, and there are two obvious ways to do that, each with a flaw.
The first is to use one step. Take the reward you just got, add the discounted value of where you landed, and subtract the value you expected before acting. This is a single TD error. It depends on only one random reward, so it is steady from run to run. But it relies entirely on the value estimate, and if that estimate is wrong, the error is wrong too.
The second is the Monte Carlo way: follow the trajectory to its end. Add up all the rewards you actually received, discount them, and subtract the baseline. This uses no value estimate beyond the baseline, so it has no bias from a wrong value function. But the total depends on every random event along the way, so it swings a lot between trajectories.
GAE sits between these. It looks ahead a few steps, uses the real rewards for those steps, and leans on the value estimates further out. The further ahead it looks, the more it trusts the rewards and the less it trusts the value function. The parameter sets how quickly that trust fades.
A weighted vote over the future
Each one-step TD error is a vote on whether the action was good, cast with a different amount of evidence. GAE takes a weighted average of these votes, with the votes for distant steps counting less. The decay of the weights is what keeps the estimate from being dominated by the long, noisy tail of a trajectory. The geometric weights are the same shape as those of an exponential moving average, applied here to future TD errors instead of past observations.
- λ = 0.95
- λ = 0.5
- λ = 0
The math
Setting
Let be the current estimate of the state-value function and the discount factor. For each time step the TD error is
It is a one-sample estimate of the advantage , as the advantage-function lesson shows. At the end of an episode the value of the terminal state is taken to be zero.
The k-step estimates
Use real rewards and then bootstrap, meaning replace the rest of the future with the value estimate. Define
The sum telescopes. Expand each and collect terms:
- Each term contributes , and .
- The terms cancel in pairs: the from step is cancelled by the that step contributes.
- What remains is
This is "discounted real rewards for steps, then the value estimate, minus the baseline." Two extremes matter:
- gives , the one-step TD error. It has low variance and high bias, because it trusts a lot.
- (or the end of the episode) gives , where is the full discounted return. It is unbiased but has high variance.
Generalized advantage estimation
GAE is the average of the -step estimates, weighted by a geometric distribution:
The weights sum to one, so this is a proper average. Substitute the definition of and swap the order of summation. The weight that multiplies is
because . So
This is the form used in practice. It can be computed in a single backwards pass over a trajectory with the recursion
so the cost is a handful of arithmetic operations per step.
What the two knobs do
The parameter controls the mix of the two extremes. At only survives, which is the one-step TD estimate. At the weights are , which gives the full Monte Carlo advantage .
The discount also shrinks the weights, so the product sets an effective horizon. Weights fall geometrically, so the estimate looks roughly steps ahead. Concretely, a sensible default such as and gives and a horizon of about 17 steps.
A useful way to read the bias-variance trade is this. The value estimate is wrong by some amount. Every carries 's error at its two ends. With small , the estimate is dominated by the nearby s, so it inherits 's error. With large , the estimate is dominated by real rewards, which are unbiased but noisy, and the noise grows with the number of terms included.
Worked examples
Take an episode with three steps, , rewards , , , and the episode ends after step 2. The current value estimates are , , , and .
- TD errors. . . .
- Take , so . Start from the end: .
- .
- .
Now compare the extremes for the first step. With , the advantage is . With , it is . This matches the Monte Carlo advantage: the full return from step 0 is , and .
Interpretation: moves the estimate from to . Here gives , which sits between them but closer to the one-step end, because the weights on distant errors fall fast.
The same recursion in Python, with the output from running it:
def gae(rewards, values, gamma, lam):
adv = [0.0] * len(rewards)
running = 0.0
for t in reversed(range(len(rewards))):
delta = rewards[t] + gamma * values[t + 1] - values[t]
running = delta + gamma * lam * running
adv[t] = running
return adv
rewards = [1.0, 0.0, 2.0]
values = [1.0, 1.5, 1.0, 0.0] # one extra entry: the value after the last step
for lam in (0.0, 0.5, 1.0):
print(lam, [round(a, 4) for a in gae(rewards, values, 0.9, lam)])0.0 [1.35, -0.6, 1.0]
0.5 [1.2825, -0.15, 1.0]
1.0 [1.62, 0.3, 1.0]The first column reproduces the hand calculation. The values list has one more entry than rewards because the last transition bootstraps from the value of the state after the final step. Here that is zero because the episode ended.
Use a typical setting, and , so .
- Weight on the TD error 10 steps ahead: .
- Weight on the TD error 50 steps ahead: .
- Effective horizon: steps.
Interpretation: an error 10 steps away still counts for about half as much as the one-step error. By 50 steps it counts for less than 5 percent. A policy trained on a task with rewards a hundred steps apart needs either a larger or a better value function, because the estimate will not reach that far.
Tradeoffs and failure modes
| Situation | What goes wrong | Better choice |
|---|---|---|
| Value function is poor | Small inherits its error, so the advantage is biased | Increase , or improve the value network before tuning anything else |
| Long, noisy episodes | Large sums many random rewards, so the estimate has high variance | Decrease , or use more parallel rollouts to average the noise |
| Rewards far apart in time | Effective horizon is shorter than the reward delay, so credit does not reach the early actions | Raise and together, or add reward shaping |
| Advantages on wildly different scales across batches | Gradient steps change size unpredictably | Normalise advantages within each batch, as most implementations do |
| Episodes cut off by a time limit | Bootstrapping from a terminal value of zero is wrong for a truncated episode | Bootstrap from the value of the last real state |
In practice a value near 0.95 for with near 0.99 has worked across many continuous-control benchmarks, which is why it is a common default. Treat it as a starting point, not a law. GAE also does not fix a bad value function, and it needs a policy that visits the states being evaluated.
History
Richard Sutton introduced temporal-difference learning in the 1980s, and his TD(λ) family of methods used the same weighting idea over multi-step returns. The mixed-horizon weighting that GAE uses is a direct descendant of that work.
GAE was introduced by John Schulman, Philipp Moritz, Sergey Levine, Michael Jordan and Pieter Abbeel in 2015, and published at ICLR in 2016 as a way to reduce the variance of policy-gradient estimates for continuous control. It caught on because it was simple to add to existing policy-gradient code and gave a clean knob for the bias-variance trade. When Schulman and colleagues introduced PPO in 2017, GAE became part of the standard training recipe, and it is still widely used in actor-critic methods.
Check yourself
QuestionRecall: what is the TD error , and what does it estimate?Show answer
. It is one step of reward plus the discounted value of the next state, minus the value of the current state. It is a single-sample estimate of the advantage , and it is the quantity TD learning computes at each step.
QuestionComputation: with , , and TD errors , , and nothing after step 2, what is the GAE advantage at step 0?Show answer
Use the recursion from the end. . Then . Then . Check with the direct sum: .
QuestionWhy: why does setting make the advantage estimate biased but low in variance?Show answer
At the estimate is only the one-step TD error. It uses one real reward, so the randomness comes from a single transition and stays small. But it also depends on the value estimates and directly. If those are wrong, the error passes straight into the advantage, and nothing in the estimate corrects it.
QuestionApplied: a team trains a robot policy on episodes of 2000 steps with . Their advantages are very noisy, and training is unstable. They try , and training gets worse. What should they consider?Show answer
With the estimate is the full Monte Carlo advantage over a 2000-step episode. Summing that many random rewards produces high variance, which is the likely cause of the instability. They should lower , for example to around 0.9 to 0.95, so the estimate depends mostly on nearby steps. They should also check that the value function is reasonable, since a lower will then inherit its error, and consider normalising advantages within each batch.
Sources
- Schulman, Moritz, Levine, Jordan, Abbeel, "High-Dimensional Continuous Control Using Generalized Advantage Estimation" (2015): https://arxiv.org/abs/1506.02438
- Schulman et al., "Proximal Policy Optimization Algorithms" (2017): https://arxiv.org/abs/1707.06347
- Sutton and Barto, "Reinforcement Learning: An Introduction", 2nd edition: http://incompleteideas.net/book/the-book-2nd.html
- Reinforcement learning (Wikipedia): https://en.wikipedia.org/wiki/Reinforcement_learning