VerifiedarXiv:1506.0243826 min
Reinforcement learning · Policy gradients

GAE: High-Dimensional Continuous Control Using Generalized Advantage Estimation

Score each action by a decaying sum of a learned value function's one-step prediction errors, and policy gradients get far less noisy for a small, tunable bias.

A policy gradient makes actions that turned out better than expected more likely. Generalized advantage estimation measures "better than expected" as a weighted sum of the value function's errors after each action, with weights that shrink by a factor γλ\gamma\lambda per step. The parameter λ\lambda moves the estimate between a one-step version, low in noise but biased by every error in the value function, and the full observed return, unbiased but noisy.

Explaining the paperHigh-Dimensional Continuous Control Using Generalized Advantage EstimationSchulman, Moritz, Levine, Jordan, Abbeel · ICLR 2016 · arXiv:1506.02438 ↗

A 2015 Berkeley paper that trained 3D simulated robots to run and to stand up from raw joint states. Its estimator became the advantage computation in PPO and in most on-policy RL code written since.

The paper has two parts. The first is an estimator: given one sampled trajectory and an imperfect value function, how to score each action so that a policy gradient built from those scores has low variance and little bias. The second is an algorithm: TRPO for the policy, a similar trust region for the value network, and the estimator between them, which together learned bipedal and quadrupedal running gaits and a getting-up motion in the MuJoCo simulator. The networks map the robot's 33 (or 29) state numbers straight to 10 (or 8) joint torques, with no hand-designed gait structure.

The page follows the paper's order. It starts with the policy gradient and why its raw form is noisy, defines the advantage function and the discount, builds the estimator from one-step prediction errors, and then spends two sections on its bias: where it comes from, and how the two parameters γ\gamma and λ\lambda trade it against variance. The value-function fit, the full algorithm, the experiments and the released code follow.

Why policy gradients are noisy

A stochastic policy πθ(a∣s)\pi_\theta(a \mid s) is a network that outputs a probability distribution over actions; for the robots, as in TRPO, the network outputs the mean of a Gaussian over the 10 joint torques. A trajectory is the sequence (s0,a0,s1,a1,… )(s_0, a_0, s_1, a_1, \dots) produced by sampling an action, stepping the simulator, and repeating, with a reward rtr_t after every step. The goal is to maximize the expected total reward. Policy gradient methods estimate the gradient of that expectation with respect to θ\theta from sampled trajectories, and every estimator the paper considers has the form

g=E[∑t=0∞Ψt ∇θlog⁡πθ(at∣st)]g = \mathbb{E}\Big[\sum_{t=0}^{\infty} \Psi_t\, \nabla_\theta \log \pi_\theta(a_t \mid s_t)\Big]
(1)

∇θlog⁡πθ(at∣st)\nabla_\theta \log \pi_\theta(a_t \mid s_t) is the direction in parameter space that makes the action actually taken at step tt more probable. Ψt\Psi_t is a scalar that says how much, and with what sign, to move along it. The simplest choice sets Ψt\Psi_t to the trajectory's total reward (REINFORCE, Williams 1992): every action in a good episode becomes more likely and every action in a bad episode less likely. The estimate is unbiased and, on long episodes, very noisy.

Take one of the paper's biped episodes: up to 2,000 steps of 0.01 seconds each. If the robot stumbles at step 1,500, the total reward drops, and that drop multiplies the gradient term of the action at step 10 as much as the action at step 1,499. Over many episodes, the actions that had nothing to do with the stumble average out, but only slowly, because each action's effect is mixed with the effects of thousands of other random actions. The paper puts it as the variance of the estimator scaling unfavorably with the time horizon. The usual fixes are to drop rewards that came before ata_t (they cannot depend on it) and to subtract a baseline. The paper lists six choices of Ψt\Psi_t:

  1. the total reward of the trajectory, ∑t=0∞rt\textstyle\sum_{t=0}^{\infty} r_t;
  2. the reward following the action, ∑t′=t∞rt′\textstyle\sum_{t'=t}^{\infty} r_{t'};
  3. the same minus a baseline b(st)b(s_t);
  4. the state-action value Qπ(st,at)Q^\pi(s_t, a_t);
  5. the advantage Aπ(st,at)A^\pi(s_t, a_t);
  6. the TD residual rt+Vπ(st+1)−Vπ(st)r_t + V^\pi(s_{t+1}) - V^\pi(s_t).

The last three use value functions, defined in the next section. The paper argues for the advantage: a gradient step should raise the probability of better-than-average actions and lower that of worse-than-average ones, and Ψt=Aπ(st,at)\Psi_t = A^\pi(s_t, a_t) points the term toward a more probable ata_t exactly when the action beat the policy's average. The paper says this choice gives "almost the lowest possible variance" and refers to Greensmith et al. (2004) for the formal analysis. The advantage is unknown and has to be estimated from the same samples, and the rest of the paper is about how.

The advantage and the discount

The value function Vπ(st)V^\pi(s_t) is the expected sum of future rewards from state sts_t if the policy chooses every action. The state-action value Qπ(st,at)Q^\pi(s_t, a_t) is the same expectation with the first action fixed to ata_t. The advantage is their difference:

Vπ(st)=Est+1:∞at:∞[∑l=0∞rt+l]Qπ(st,at)=Est+1:∞at+1:∞[∑l=0∞rt+l]V^{\pi}(s_t) = \mathbb{E}_{\substack{s_{t+1:\infty}\\ a_{t:\infty}}}\Big[\sum_{l=0}^{\infty} r_{t+l}\Big] \qquad Q^{\pi}(s_t,a_t) = \mathbb{E}_{\substack{s_{t+1:\infty}\\ a_{t+1:\infty}}}\Big[\sum_{l=0}^{\infty} r_{t+l}\Big]Vπ(st)=Est+1:∞at:∞[∑l=0∞rt+l]Qπ(st,at)=Est+1:∞at+1:∞[∑l=0∞rt+l]\begin{gathered} V^{\pi}(s_t) = \mathbb{E}_{\substack{s_{t+1:\infty}\\ a_{t:\infty}}}\Big[\sum_{l=0}^{\infty} r_{t+l}\Big] \\ Q^{\pi}(s_t,a_t) = \mathbb{E}_{\substack{s_{t+1:\infty}\\ a_{t+1:\infty}}}\Big[\sum_{l=0}^{\infty} r_{t+l}\Big] \end{gathered}
(2)
Aπ(st,at)=Qπ(st,at)−Vπ(st)A^{\pi}(s_t, a_t) = Q^{\pi}(s_t, a_t) - V^{\pi}(s_t)
(3)

The subscripts on E\mathbb{E} list what is averaged over: future states drawn from the simulator and future actions drawn from the policy. VπV^\pi averages over ata_t as well; QπQ^\pi does not. A positive Aπ(st,at)A^\pi(s_t, a_t) means that taking ata_t and then following the policy is better, in expectation, than following the policy from sts_t directly.

The problem the paper solves is undiscounted: maximize the plain sum of rewards. It then introduces a discount γ∈[0,1]\gamma \in [0, 1] anyway, as a knob on the estimator rather than part of the goal. Rewards ll steps after an action are multiplied by γl\gamma^l, which shrinks the contribution of delayed, mostly unrelated rewards to each action's score. The discounted value functions Vπ,γV^{\pi,\gamma}, Qπ,γQ^{\pi,\gamma}, Aπ,γA^{\pi,\gamma} (equations 4 and 5) are (2) and (3) with γlrt+l\gamma^l r_{t+l} in place of rt+lr_{t+l}, and the gradient they define is

gγ=Es0:∞a0:∞[∑t=0∞Aπ,γ(st,at) ∇θlog⁡πθ(at∣st)]g^{\gamma} = \mathbb{E}_{\substack{s_{0:\infty}\\ a_{0:\infty}}}\Big[\sum_{t=0}^{\infty} A^{\pi,\gamma}(s_t, a_t)\, \nabla_\theta \log \pi_\theta(a_t \mid s_t)\Big]gγ=Es0:∞a0:∞[∑t=0∞Aπ,γ(st,at)∇θlog⁡πθ(at∣st)]\begin{aligned} g^{\gamma} = \mathbb{E}_{\substack{s_{0:\infty}\\ a_{0:\infty}}}\Big[&\sum_{t=0}^{\infty} A^{\pi,\gamma}(s_t, a_t) \\ &\quad \nabla_\theta \log \pi_\theta(a_t \mid s_t)\Big] \end{aligned}
(6)

gγg^\gamma is already a biased version of the true gradient gg whenever γ<1\gamma < 1, because it ignores the tail of each action's effect. With the weights γl\gamma^l, rewards more than about 1/(1−γ)1/(1-\gamma) steps out barely count: 100 steps at γ=0.99\gamma = 0.99, 200 steps at γ=0.995\gamma = 0.995. At the robots' 0.01-second timestep that is 1 or 2 seconds of simulated time, and any consequence of an action that arrives later is mostly invisible to the gradient.

From here on, the target is gγg^\gamma, and the question is which estimates of Aπ,γA^{\pi,\gamma} leave it unbiased. The paper calls an estimator A^t\hat A_t, which may depend on the whole trajectory, γ-just if substituting it for Aπ,γA^{\pi,\gamma} in (6) gives the same expectation:

E[A^t ∇θlog⁡πθ(at∣st)]=E[Aπ,γ(st,at) ∇θlog⁡πθ(at∣st)]\mathbb{E}\big[\hat A_t\, \nabla_\theta \log \pi_\theta(a_t \mid s_t)\big] = \mathbb{E}\big[A^{\pi,\gamma}(s_t,a_t)\, \nabla_\theta \log \pi_\theta(a_t \mid s_t)\big]E[A^t ∇θlog⁡πθ(at∣st)]=E[Aπ,γ(st,at) ∇θlog⁡πθ(at∣st)]\begin{aligned} &\mathbb{E}\big[\hat A_t\, \nabla_\theta \log \pi_\theta(a_t \mid s_t)\big] \\ &= \mathbb{E}\big[A^{\pi,\gamma}(s_t,a_t)\, \nabla_\theta \log \pi_\theta(a_t \mid s_t)\big] \end{aligned}
(7)

Proposition 1 gives a sufficient condition. If A^t=Qt−bt\hat A_t = Q_t - b_t, where QtQ_t may depend on anything from step tt on but averages to Qπ,γ(st,at)Q^{\pi,\gamma}(s_t, a_t), and btb_t depends only on states and actions before ata_t, then A^t\hat A_t is γ-just. The proof rests on one identity. For any fixed state,

Ea∼π[∇θlog⁡πθ(a∣s)]=∑aπθ(a∣s) ∇θπθ(a∣s)πθ(a∣s)=∇θ∑aπθ(a∣s)=∇θ1=0\mathbb{E}_{a \sim \pi}\big[\nabla_\theta \log \pi_\theta(a \mid s)\big] = \sum_a \pi_\theta(a \mid s)\,\frac{\nabla_\theta \pi_\theta(a \mid s)}{\pi_\theta(a \mid s)} = \nabla_\theta \sum_a \pi_\theta(a \mid s) = \nabla_\theta 1 = 0Ea∼π[∇θlog⁡πθ(a∣s)]=∑aπθ(a∣s) ∇θπθ(a∣s)πθ(a∣s)=∇θ∑aπθ(a∣s)=∇θ1=0\begin{aligned} &\mathbb{E}_{a \sim \pi}\big[\nabla_\theta \log \pi_\theta(a \mid s)\big] \\ &= \sum_a \pi_\theta(a \mid s)\,\frac{\nabla_\theta \pi_\theta(a \mid s)}{\pi_\theta(a \mid s)} \\ &= \nabla_\theta \sum_a \pi_\theta(a \mid s) = \nabla_\theta 1 = 0 \end{aligned}

so a baseline btb_t that does not change with ata_t multiplies a quantity that is zero on average and adds nothing to the expected gradient. It can still change the variance a great deal. Four examples are γ-just: the discounted return ∑lγlrt+l\sum_l \gamma^l r_{t+l}, Qπ,γQ^{\pi,\gamma}, Aπ,γA^{\pi,\gamma} itself, and the one-step residual built from the exact value function:

rt+γVπ,γ(st+1)−Vπ,γ(st)r_t + \gamma V^{\pi,\gamma}(s_{t+1}) - V^{\pi,\gamma}(s_t)

One-step errors and k-step estimates

Let VV be an approximate value function, in practice a neural network. Its TD residual at step tt is

δtV=rt+γV(st+1)−V(st)\delta^V_t = r_t + \gamma V(s_{t+1}) - V(s_t)

It compares two predictions of the same discounted return: V(st)V(s_t), made before the step, and rt+γV(st+1)r_t + \gamma V(s_{t+1}), made after seeing the reward and the next state. If the step went better than the network expected, δtV>0\delta^V_t > 0. With the exact V=Vπ,γV = V^{\pi,\gamma}, the expected residual is exactly the advantage, because averaging rt+γVπ,γ(st+1)r_t + \gamma V^{\pi,\gamma}(s_{t+1}) over the next state gives Qπ,γ(st,at)Q^{\pi,\gamma}(s_t, a_t):

Est+1[δtVπ,γ]=Est+1[Qπ,γ(st,at)−Vπ,γ(st)]=Aπ,γ(st,at)\mathbb{E}_{s_{t+1}}\big[\delta^{V^{\pi,\gamma}}_t\big] = \mathbb{E}_{s_{t+1}}\big[Q^{\pi,\gamma}(s_t,a_t) - V^{\pi,\gamma}(s_t)\big] = A^{\pi,\gamma}(s_t,a_t)Est+1[δtVπ,γ]=Est+1[Qπ,γ(st,at)−Vπ,γ(st)]=Aπ,γ(st,at)\begin{aligned} \mathbb{E}_{s_{t+1}}\big[\delta^{V^{\pi,\gamma}}_t\big] &= \mathbb{E}_{s_{t+1}}\big[Q^{\pi,\gamma}(s_t,a_t) - V^{\pi,\gamma}(s_t)\big] \\ &= A^{\pi,\gamma}(s_t,a_t) \end{aligned}
(10)

With any other VV, the residual is biased, and the bias is the error of VV at st+1s_{t+1} (scaled by γ\gamma) that does not cancel. The paper's next step is to sum kk consecutive residuals. The intermediate values cancel in pairs, the +γV(st+1)+\gamma V(s_{t+1}) of one residual against the −V(st+1)-V(s_{t+1}) of the next once it is multiplied by γ\gamma, leaving a kk-step return with the value function at both ends:

A^t(k)=∑l=0k−1γlδt+lV=−V(st)+rt+γrt+1+⋯+γk−1rt+k−1+γkV(st+k)\hat A^{(k)}_t = \sum_{l=0}^{k-1} \gamma^l \delta^V_{t+l} = -V(s_t) + r_t + \gamma r_{t+1} + \dots + \gamma^{k-1} r_{t+k-1} + \gamma^k V(s_{t+k})A^t(k)=∑l=0k−1γlδt+lV=−V(st)+rt+γrt+1+…+γk−1rt+k−1+γkV(st+k)\begin{aligned} \hat A^{(k)}_t &= \sum_{l=0}^{k-1} \gamma^l \delta^V_{t+l} \\ &= -V(s_t) + r_t + \gamma r_{t+1} + \dots \\ &\quad + \gamma^{k-1} r_{t+k-1} + \gamma^k V(s_{t+k}) \end{aligned}
(14)

A three-step example with γ=0.99\gamma = 0.99: rewards 0, 0, 1, value predictions V(s0)=0.5V(s_0) = 0.5, V(s1)=0.6V(s_1) = 0.6, V(s2)=0.8V(s_2) = 0.8, and a terminal s3s_3 with value 0. The residuals and the three estimates are

δ0=0+0.99×0.6−0.5=0.094δ1=0+0.99×0.8−0.6=0.192δ2=1+0−0.8=0.2\begin{aligned} \delta_0 &= 0 + 0.99 \times 0.6 - 0.5 = 0.094 \\ \delta_1 &= 0 + 0.99 \times 0.8 - 0.6 = 0.192 \\ \delta_2 &= 1 + 0 - 0.8 = 0.2 \end{aligned}
A^0(1)=0.094A^0(2)=0.094+0.99×0.192=0.284A^0(3)=0.284+0.9801×0.2=0.480\begin{aligned} \hat A^{(1)}_0 &= 0.094 \\ \hat A^{(2)}_0 &= 0.094 + 0.99 \times 0.192 = 0.284 \\ \hat A^{(3)}_0 &= 0.284 + 0.9801 \times 0.2 = 0.480 \end{aligned}

The first is the one-step estimate. The second equals −0.5+0.992×0.8-0.5 + 0.99^2 \times 0.8, and the third equals −0.5+0.992×1-0.5 + 0.99^2 \times 1, the observed discounted return minus the baseline.

In (14) the term −V(st)-V(s_t) is a baseline: it does not depend on ata_t, so it adds no bias. All of the bias sits in the bootstrap term γkV(st+k)\gamma^k V(s_{t+k}), and its weight γk\gamma^k shrinks as kk grows. Variance moves the other way, because each extra step adds one more random reward to the sum. As k→∞k \to \infty the bootstrap vanishes and

A^t(∞)=∑l=0∞γlδt+lV=−V(st)+∑l=0∞γlrt+l\hat A^{(\infty)}_t = \sum_{l=0}^{\infty} \gamma^l \delta^V_{t+l} = -V(s_t) + \sum_{l=0}^{\infty} \gamma^l r_{t+l}A^t(∞)=∑l=0∞γlδt+lV=−V(st)+∑l=0∞γlrt+l\begin{aligned} \hat A^{(\infty)}_t &= \sum_{l=0}^{\infty} \gamma^l \delta^V_{t+l} \\ &= -V(s_t) + \sum_{l=0}^{\infty} \gamma^l r_{t+l} \end{aligned}
(15)

the empirical return minus a value-function baseline, choice 3 in the list above. A3C, published the next year, picks one kk per state (up to 5 steps on Atari), where GAE averages over all of them.

How GAE works

The generalized advantage estimator takes an exponentially weighted average of the kk-step estimators, with weight (1−λ)λk−1(1-\lambda)\lambda^{k-1} on A^t(k)\hat A^{(k)}_t. The weights sum to 1 for any λ∈[0,1)\lambda \in [0, 1). Written in terms of the residuals, residual δt+lV\delta^V_{t+l} appears in every estimator with k>lk > l, multiplied by γl\gamma^l, so its total weight is γl\gamma^l times the sum of those estimators' weights, a geometric tail that sums to λl\lambda^l:

A^tGAE(γ,λ)=(1−λ)(A^t(1)+λA^t(2)+λ2A^t(3)+…)=∑l=0∞(γλ)lδt+lV\hat A^{\mathrm{GAE}(\gamma,\lambda)}_t = (1-\lambda)\big(\hat A^{(1)}_t + \lambda \hat A^{(2)}_t + \lambda^2 \hat A^{(3)}_t + \dots\big) = \sum_{l=0}^{\infty} (\gamma\lambda)^l \delta^V_{t+l}A^tGAE(γ,λ)=(1−λ)(A^t(1)+λA^t(2)+λ2A^t(3)+…)=∑l=0∞(γλ)lδt+lV\begin{aligned} \hat A^{\mathrm{GAE}(\gamma,\lambda)}_t &= (1-\lambda)\big(\hat A^{(1)}_t + \lambda \hat A^{(2)}_t + \lambda^2 \hat A^{(3)}_t + \dots\big) \\ &= \sum_{l=0}^{\infty} (\gamma\lambda)^l \delta^V_{t+l} \end{aligned}
(16)

Figure 1 lays the regrouping out as a grid. Each row is one kk-step estimator and the residuals it contains, shaded by the row's weight; the bars underneath are the column sums times γl\gamma^l. Pick a column and compare the readout with λl\lambda^l.

Figure 1 · k-step estimators averaged into GAE
λ = 0.70
l = 2

column 2: row weights sum to 0.490 = λ2 = 0.490 · times γ2 → weight on δt+2 = 0.480

Row k holds the residuals δt … δt+k−1 that make up the k-step estimator, shaded by its weight (1 − λ)λk−1; the last row lumps every longer estimator (weight λ8). The bars are the resulting weight on each residual, (γλ)l, with γ = 0.99. Drag λ to 0 (only the first row survives) and to 1 (all weight moves to the longest estimators). Click a column or use the column slider.

At λ=0.7\lambda = 0.7, the default in the figure, column 2 collects 0.7² = 0.49 of the row weight, and the weight on δt+2\delta_{t+2} is 0.992×0.49=0.4800.99^2 \times 0.49 = 0.480. The two ends of the slider are the estimators from the previous section:

GAE(γ,0):A^t=δt=rt+γV(st+1)−V(st)\mathrm{GAE}(\gamma, 0):\quad \hat A_t = \delta_t = r_t + \gamma V(s_{t+1}) - V(s_t)GAE(γ,0):A^t=δt=rt+γV(st+1)−V(st)\begin{aligned} \mathrm{GAE}(\gamma, 0):\quad \hat A_t &= \delta_t \\ &= r_t + \gamma V(s_{t+1}) - V(s_t) \end{aligned}
(17)
GAE(γ,1):A^t=∑l=0∞γlδt+l=∑l=0∞γlrt+l−V(st)\mathrm{GAE}(\gamma, 1):\quad \hat A_t = \sum_{l=0}^{\infty} \gamma^l \delta_{t+l} = \sum_{l=0}^{\infty} \gamma^l r_{t+l} - V(s_t)GAE(γ,1):A^t=∑l=0∞γlδt+l=∑l=0∞γlrt+l−V(st)\begin{aligned} \mathrm{GAE}(\gamma, 1):\quad \hat A_t &= \sum_{l=0}^{\infty} \gamma^l \delta_{t+l} \\ &= \sum_{l=0}^{\infty} \gamma^l r_{t+l} - V(s_t) \end{aligned}
(18)

GAE(γ,1)\mathrm{GAE}(\gamma, 1) is γ-just whatever the accuracy of VV, since VV appears only as a baseline, and it has high variance from the long sum of rewards. GAE(γ,0)\mathrm{GAE}(\gamma, 0) is γ-just only when V=Vπ,γV = V^{\pi,\gamma} and otherwise biased, and it typically has much lower variance. Values in between trade one for the other. The construction is the one behind TD(λ), with a different target: TD(λ) averages kk-step returns to train a value function, while (16) averages kk-step advantages. Since each kk-step advantage is the kk-step return minus V(st)V(s_t), GAE is the λ-return minus V(st)V(s_t).

Equation (16) also gives a cheap way to compute it. Splitting off the first term gives the recursion

A^t=δt+γλ A^t+1\hat A_t = \delta_t + \gamma\lambda\, \hat A_{t+1}

so one backward pass over a trajectory produces every advantage in O(T)O(T) time. Figure 2 runs that computation on an 8-step segment that ends without terminating, so the last residual uses the value of the state after the cut (the hollow dot). A reward of +1 arrives at step 5, which the value network underpredicted.

Figure 2 · GAE on one trajectory segment
λ = 0.95
t = 0

Â0 = 0.384 · λ=0 (one step): 0.044 · λ=1 (Monte Carlo): 0.482
weight halves every 11.3 steps

Top: rewards and the value prediction for each state; the hollow dot is the bootstrap V(sT). Bottom: each residual δ (faint) and, for the selected step, its weighted contribution (γλ)lδ (bright). The bright bars sum to Ât. Drag λ from 0 (one step) to 1 (Monte Carlo); click a column or use the step slider to move t. Toy numbers, γ = 0.99.

At step 0, λ=0\lambda = 0 gives A^0=0.044\hat A_0 = 0.044: the first step looks barely better than expected, because the value network's prediction rose only from 0.55 to 0.60. λ=1\lambda = 1 gives 0.482, which includes the full surprise at step 5. The figure starts at λ=0.95\lambda = 0.95, which gives 0.384; at the paper's robot setting γ=0.995,λ=0.96\gamma = 0.995, \lambda = 0.96, the product γλ=0.955\gamma\lambda = 0.955 halves the weight every 15 steps.

Where the bias comes from

The previous section said that λ<1\lambda < 1 adds bias only when VV is wrong. Expanding (16) shows which values of VV enter the estimate. Collecting the terms of each residual,

A^tGAE(γ,λ)=∑l=0∞(γλ)lrt+l  −  V(st)  +  (1−λ)∑l=1∞γlλl−1 V(st+l)\hat A^{\mathrm{GAE}(\gamma,\lambda)}_t = \sum_{l=0}^{\infty} (\gamma\lambda)^l r_{t+l} \;-\; V(s_t) \;+\; (1-\lambda)\sum_{l=1}^{\infty} \gamma^l \lambda^{l-1}\, V(s_{t+l})A^tGAE(γ,λ)=∑l=0∞(γλ)lrt+l−V(st)+(1−λ)∑l=1∞γlλl−1 V(st+l)\begin{aligned} \hat A^{\mathrm{GAE}(\gamma,\lambda)}_t &= \sum_{l=0}^{\infty} (\gamma\lambda)^l r_{t+l} - V(s_t) \\ &\quad + (1-\lambda)\sum_{l=1}^{\infty} \gamma^l \lambda^{l-1}\, V(s_{t+l}) \end{aligned}

which follows because V(st+l)V(s_{t+l}) appears as +γV+\gamma V in residual l−1l-1 (weight (γλ)l−1(\gamma\lambda)^{l-1}) and as −V-V in residual ll (weight (γλ)l(\gamma\lambda)^l). The first sum is a return discounted by γλ\gamma\lambda instead of γ\gamma. −V(st)-V(s_t) is a baseline. The last sum puts the value network's predictions at later states into the score, and those states depend on ata_t, so an error in VV there becomes an error in the gradient. At λ=1\lambda = 1 the last sum vanishes and the first becomes the ordinary discounted return. When V=Vπ,γV = V^{\pi,\gamma}, the later-state values supply exactly the expected return that the steeper discount cut away.

Section 4 of the paper reads the same algebra as reward shaping. Ng, Harada and Russell (1999) showed that adding γΦ(s′)−Φ(s)\gamma\Phi(s') - \Phi(s) to every reward, for any function Φ\Phi of the state, leaves the optimal policy of a discounted problem unchanged:

r~(s,a,s′)=r(s,a,s′)+γΦ(s′)−Φ(s)\tilde r(s, a, s') = r(s, a, s') + \gamma \Phi(s') - \Phi(s)
(20)

Summed along a trajectory with discount γ\gamma, the added terms cancel in pairs and leave only −Φ(st)-\Phi(s_t), so the shaped problem has Q~=Q−Φ\tilde Q = Q - \Phi, V~=V−Φ\tilde V = V - \Phi and the same advantage A~π,γ=Aπ,γ\tilde A^{\pi,\gamma} = A^{\pi,\gamma} (equations 22 to 24). Choose Φ=V\Phi = V and the shaped reward is the TD residual, r~t=δtV\tilde r_t = \delta^V_t. GAE is then the sum of shaped rewards under the steeper discount γλ\gamma\lambda:

∑l=0∞(γλ)l r~(st+l,at+l,st+l+1)=∑l=0∞(γλ)lδt+lV=A^tGAE(γ,λ)\sum_{l=0}^{\infty} (\gamma\lambda)^l\, \tilde r(s_{t+l}, a_{t+l}, s_{t+l+1}) = \sum_{l=0}^{\infty} (\gamma\lambda)^l \delta^V_{t+l} = \hat A^{\mathrm{GAE}(\gamma,\lambda)}_t∑l=0∞(γλ)l r~(st+l,at+l,st+l+1)=∑l=0∞(γλ)lδt+lV=A^tGAE(γ,λ)\begin{aligned} &\sum_{l=0}^{\infty} (\gamma\lambda)^l\, \tilde r(s_{t+l}, a_{t+l}, s_{t+l+1}) \\ &= \sum_{l=0}^{\infty} (\gamma\lambda)^l \delta^V_{t+l} = \hat A^{\mathrm{GAE}(\gamma,\lambda)}_t \end{aligned}
(25)

To say how much a steeper discount loses, the paper defines the response function: how much the expected reward ll steps later changes when the action is fixed to ata_t, compared with the policy's average,

χ(l;st,at)=E[rt+l∣st,at]−E[rt+l∣st]\chi(l; s_t, a_t) = \mathbb{E}\big[r_{t+l} \mid s_t, a_t\big] - \mathbb{E}\big[r_{t+l} \mid s_t\big]
(26)

The advantage is the discounted sum of the responses,

Aπ,γ(s,a)=∑l=0∞γlχ(l;s,a)A^{\pi,\gamma}(s, a) = \sum_{l=0}^{\infty} \gamma^l \chi(l; s, a)

so the response function spreads the advantage across timesteps. A delayed consequence is a response at a large lag ll. Any discount weights the response by its envelope, and the part at lags well beyond 1/(1−γλ)1/(1-\gamma\lambda) is lost. Shaping with the exact Vπ,γV^{\pi,\gamma} moves the entire response to lag 0: once st+1s_{t+1} is known, the expected future shaped reward is zero, so only δt\delta_t carries information about ata_t, and no discount can lose anything. A good but imperfect VV moves part of it. In the paper's words, GAE reshapes the rewards with VV to shrink the temporal extent of the response, then uses the steeper discount to cut off the noise from long delays.

Consider a small example. At step 0 a policy chooses between two actions with probability 0.5 each. The good action pays +1 exactly 20 steps later and the other pays nothing; no other reward depends on the choice. The value network is a blend V=(1−κ) Vπ,γV = (1-\kappa)\,V^{\pi,\gamma}, where κ=0\kappa = 0 is the exact value function and κ=1\kappa = 1 assigns no value to the pending reward. Working through the residuals, the difference between the two actions shows up as (1−κ)γ20(1-\kappa)\gamma^{20} in δ0\delta_0 and as κ\kappa in δ20\delta_{20}, and zero at every other lag. GAE weights the second by (γλ)20(\gamma\lambda)^{20}, so the credit the estimator gives the good action is

(1−κ)γ20+κ(γλ)20=γ20[1−κ(1−λ20)](1-\kappa)\gamma^{20} + \kappa(\gamma\lambda)^{20} = \gamma^{20}\big[1 - \kappa(1-\lambda^{20})\big](1−κ)γ20+κ(γλ)20=γ20[1−κ(1−λ20)]\begin{aligned} &(1-\kappa)\gamma^{20} + \kappa(\gamma\lambda)^{20} \\ &= \gamma^{20}\big[1 - \kappa(1-\lambda^{20})\big] \end{aligned}

against a true, undiscounted value of 1. The factor γ20\gamma^{20} is the bias from γ\gamma (0.818 at γ=0.99\gamma = 0.99). The bracket is the bias from λ\lambda, and it equals 1 when κ=0\kappa = 0 or λ=1\lambda = 1. Figure 3 draws the two responses; move κ to 0 and the teal mass jumps to lag 0, where no discount touches it.

Figure 3 · where the credit for a delayed reward lands
κ = 0.50
λ = 0.96

credited to the good action: 0.590 = 0.409 at lag 0 + 0.50 × (γλ)20 · γ-ceiling γ20 = 0.818 · truth = 1

Per lag, the difference in expected signal between the good and bad action. Amber outline: the raw reward, a spike of 1 at lag 20. Teal: the shaped reward δ for a value function with error κ; the filled part is what survives the GAE weight (γλ)l (solid curve). The dashed curve is γl. γ = 0.99.

At the default κ=0.5\kappa = 0.5, λ=0.96\lambda = 0.96: 0.409 lands at lag 0 and survives intact, and 0.5 lands at lag 20, of which 0.950420=0.3620.9504^{20} = 0.362 survives, for a total of 0.590. With κ=1\kappa = 1 (no useful value function) the credit is (γλ)20=0.362(\gamma\lambda)^{20} = 0.362, and at λ=0\lambda = 0 it is zero: the one-step estimate uses only δ0\delta_0, which contains none of a reward that the value function did not predict.

Choosing γ and λ

Both parameters lower variance by shortening the sum, and both can add bias, but the paper separates their roles. γ\gamma sets the scale of the value function the network has to learn, Vπ,γV^{\pi,\gamma}, which does not depend on λ\lambda. γ<1\gamma < 1 biases the gradient regardless of how accurate the value function is. λ<1\lambda < 1 biases it only when the value function is inaccurate. The paper reports that the best λ\lambda is much lower than the best γ\gamma, likely because λ\lambda adds far less bias for a reasonably accurate value function.

Figure 4, a toy of this page's rather than the paper's, adds noise to the example above and measures the policy gradient itself. The episode runs 200 steps and every reward carries independent Gaussian noise with standard deviation 0.3. With a two-action policy at p=0.5p = 0.5, write a=1a = 1 for the good action and a=0a = 0 for the other; the gradient with respect to the policy's logit from one episode is A^0×(a−0.5)\hat A_0 \times (a - 0.5), and its true undiscounted value is 0.25. The curves show, as fractions of 0.25, the bias, the noise of an average over N=50N = 50 episodes, and the root-mean-square error that combines them. All three are exact formulas, checked against a 4,000-episode simulation.

Figure 4 · bias and noise of the gradient as λ varies
λ = 0.96
κ = 0.50
γ = 0.990

at λ = 0.96: bias 0.410 · noise 0.274 · total 0.493
lowest total at λ = 0.98 (0.474) · signal kept = γ20·[1 − κ(1 − λ20)] = 0.590

Total error = √(bias² + noise²), with the bias and the noise of a 50-episode average, all relative to the true gradient. The bright dot marks the λ with the lowest total. Set the value error κ and γ with the sliders; click or drag on the plot (or use the λ slider) to read off a λ.

At κ=0.5\kappa = 0.5 and γ=0.99\gamma = 0.99, λ=0\lambda = 0 has a total error of 0.597, almost all bias; λ=1\lambda = 1 has 0.626, mostly noise (its bias, 0.182, is the γ\gamma part alone); the minimum is 0.474 at λ=0.98\lambda = 0.98. Three settings show the paper's claims. Set κ=0\kappa = 0 and the best λ\lambda is 0, because an exact value function makes the one-step estimate unbiased. Set γ=1\gamma = 1 and λ=1\lambda = 1 becomes the worst choice (1.202) while the minimum moves to 0.413 at λ=0.96\lambda = 0.96, since nothing then limits the 200 noisy rewards in the sum. Lower γ\gamma to 0.9 and every curve is dominated by the γ20=0.12\gamma^{20} = 0.12 factor, a bias no value function can remove.

The noise in Figure 4 has one source, the reward noise, and it grows with the effective length of the sum: the standard deviation of A^0\hat A_0 at λ=1\lambda = 1 is 2.18 times its value at λ=0.96\lambda = 0.96. In the robot tasks much of the noise comes from the randomness of later actions and their effect on the dynamics, and it grows with the length of the sum in the same way.

Fitting the value function

Every estimate above uses a value network VϕV_\phi. The simplest way to fit it is regression onto the discounted returns observed in the batch:

min⁡ϕ∑n=1N∥Vϕ(sn)−V^n∥2V^t=∑l=0∞γlrt+l\min_{\phi} \sum_{n=1}^{N} \big\|V_\phi(s_n) - \hat V_n\big\|^2 \qquad \hat V_t = \sum_{l=0}^{\infty} \gamma^l r_{t+l}min⁡ϕ∑n=1N∥Vϕ(sn)−V^n∥2V^t=∑l=0∞γlrt+l\begin{gathered} \min_{\phi} \sum_{n=1}^{N} \big\|V_\phi(s_n) - \hat V_n\big\|^2 \\ \hat V_t = \sum_{l=0}^{\infty} \gamma^l r_{t+l} \end{gathered}
(28)

where nn runs over all NN timesteps of the batch (50,000 for the biped). The targets are Monte Carlo returns, sometimes called TD(1) targets. The paper also tried TD(λ) targets and saw no difference.

The returns from one batch are noisy, and a large network fitted to convergence on them would chase that noise. The paper constrains each fit with a trust region instead. It first measures how well the old network fits the new targets,

σ2=1N∑n=1N∥Vϕold(sn)−V^n∥2\sigma^2 = \frac{1}{N}\sum_{n=1}^{N} \big\|V_{\phi_{\text{old}}}(s_n) - \hat V_n\big\|^2

and then solves

min⁡ϕ∑n=1N∥Vϕ(sn)−V^n∥2s.t.1N∑n=1N∥Vϕ(sn)−Vϕold(sn)∥22σ2≤ϵ\min_{\phi} \sum_{n=1}^{N} \big\|V_\phi(s_n) - \hat V_n\big\|^2 \quad \text{s.t.} \quad \frac{1}{N}\sum_{n=1}^{N} \frac{\|V_\phi(s_n) - V_{\phi_{\text{old}}}(s_n)\|^2}{2\sigma^2} \le \epsilonmin⁡ϕ∑n=1N∥Vϕ(sn)−V^n∥2s.t.    1N∑n=1N∥Vϕ(sn)−Vϕold(sn)∥22σ2≤ϵ\begin{gathered} \min_{\phi} \sum_{n=1}^{N} \big\|V_\phi(s_n) - \hat V_n\big\|^2 \\ \text{s.t.}\;\; \frac{1}{N}\sum_{n=1}^{N} \frac{\|V_\phi(s_n) - V_{\phi_{\text{old}}}(s_n)\|^2}{2\sigma^2} \le \epsilon \end{gathered}
(29)

In words: the mean squared change in predictions over the batch may be at most 2σ2ϵ2\sigma^2\epsilon, so the root-mean-square change is capped at σ2ϵ\sigma\sqrt{2\epsilon}. If Vϕ(s)V_\phi(s) is read as the mean of a Gaussian with variance σ2\sigma^2, the left side is the average KL divergence between the old and new Gaussians, since the KL divergence between two Gaussians with equal variance is (μ1−μ2)2/2σ2(\mu_1 - \mu_2)^2 / 2\sigma^2, the same form as the KL constraint on the policy step.

To solve it, the paper linearizes the objective and approximates the constraint with the Gauss-Newton matrix H=1N∑njnjn⊤H = \tfrac{1}{N}\sum_n j_n j_n^{\top}, where jn=∇ϕVϕ(sn)j_n = \nabla_\phi V_\phi(s_n). The conjugate gradient method, using only products v↦Hvv \mapsto Hv, approximately solves the resulting quadratic program (equation 30): it finds the direction s≈−H−1gs \approx -H^{-1} g, with gg the gradient of the objective, and rescales the step to the boundary of the constraint. HH is, up to a factor of σ2\sigma^2, the Fisher information matrix of that Gaussian, so this is a natural-gradient step for the value network, the same procedure TRPO uses for the policy.

Figure 5 runs one such step on a one-dimensional problem small enough to solve exactly: 30 noisy return targets, a value function that is linear in 8 parameters, and an old fit that is close to the truth but not equal to it. Watch the two error curves at the bottom as ε grows.

Figure 5 · one trust-region step on the value function
ε = 0.10

step = 84% of the way to the batch least-squares fit · RMS change in V = 0.285 (cap σ√(2ε) = 0.285, σ = 0.637)
error on batch 0.542 · vs true V 0.229 · lowest vs true V at ε ≈ 0.025

Top: the true value (dashed, unknown to the learner), the old fit, the 30 return targets and the new fit after one step of (29). Bottom: RMS error on the batch (amber) and against the true value (teal) across ε, with the current ε marked. Drag ε; "new batch" draws fresh targets.

At ϵ=0\epsilon = 0 the fit does not move. As ϵ\epsilon grows, the step moves the parameters along the natural-gradient direction toward the batch's least-squares fit; for a linear model with squared error, that straight line is the exact solution path of (29). The error on the batch falls all the way. The error against the true value function falls, bottoms out, and rises again once the step starts fitting this batch's noise, the overfitting to the most recent batch that the paper names as the reason for the trust region. The paper does not report the ϵ\epsilon it used.

The full algorithm

The policy update is TRPO. Each iteration it approximately solves

max⁡θ  1N∑n=1Nπθ(an∣sn)πθold(an∣sn) A^ns.t.D‾KL(πθold,πθ)≤ϵ\max_{\theta}\; \frac{1}{N}\sum_{n=1}^{N} \frac{\pi_\theta(a_n \mid s_n)}{\pi_{\theta_{\text{old}}}(a_n \mid s_n)}\, \hat A_n \quad \text{s.t.} \quad \overline{D}_{\mathrm{KL}}(\pi_{\theta_{\text{old}}}, \pi_\theta) \le \epsilonmax⁡θ  1N∑n=1Nπθ(an∣sn)πθold(an∣sn) A^ns.t.    D‾KL(πθold,πθ)≤ϵ\begin{gathered} \max_{\theta}\; \frac{1}{N}\sum_{n=1}^{N} \frac{\pi_\theta(a_n \mid s_n)}{\pi_{\theta_{\text{old}}}(a_n \mid s_n)}\, \hat A_n \\ \text{s.t.}\;\; \overline{D}_{\mathrm{KL}}(\pi_{\theta_{\text{old}}}, \pi_\theta) \le \epsilon \end{gathered}
(31)

where D‾KL\overline{D}_{\mathrm{KL}} is the KL divergence between the old and new action distributions, averaged over the batch's states, and A^n\hat A_n is the GAE estimate at timestep nn of the batch. Linearizing the objective and taking a quadratic approximation of the constraint gives a step along F−1gF^{-1} g, where FF is the average Fisher information matrix of the policy and gg the policy gradient estimate: the natural policy gradient direction, with TRPO's own rule for the step length.

One iteration of the algorithm simulates the current policy for NN timesteps, computes δtV\delta^V_t at every step with the current value network VϕiV_{\phi_i}, computes A^t=∑l(γλ)lδt+lV\hat A_t = \sum_l (\gamma\lambda)^l \delta^V_{t+l}, takes the TRPO step to θi+1\theta_{i+1}, and then takes the value step (30) to ϕi+1\phi_{i+1}. In code, with the shapes of a biped batch:

for i in range(n_iters):
    paths = simulate(policy_theta, n_steps=50_000)  # biped batch: 50,000 steps
    for p in paths:                                 # obs (T, 33), act (T, 10)
        p.adv, p.vtarg = gae(p.rew, V_phi(p.obs), v_last(p))
    # Policy step, eq. (31). adv is a constant: no gradient reaches phi here.
    theta = trpo_step(theta, paths)                 # grad flows via log pi only
    # Value step, eq. (30), AFTER the policy step, on the same batch.
    phi = vf_trust_region_step(phi, paths)          # regress V_phi on vtarg

The advantages are computed once from the network outputs and then treated as constants. The policy loss differentiates through log⁡πθ\log \pi_\theta only, and the value network's parameters receive gradient only from the regression loss. If the value network were updated first, on the same batch, it would partly absorb that batch's returns, and the residuals that score the policy would shrink toward zero. In the extreme case of a value network that fits every return exactly, every δtV\delta^V_t is zero and so is the policy gradient.

The per-trajectory advantage and value-target computation, written out:

import numpy as np

def gae(rewards, values, v_last, gamma=0.99, lam=0.96):
    """One trajectory of T steps. values[t] = V(s_t) from the value net
    BEFORE this iteration's update; v_last = V(s_T), or 0.0 if s_T is
    terminal. Returns advantages and value targets, both of shape (T,)."""
    T = len(rewards)
    v_next = np.append(values[1:], v_last)
    deltas = rewards + gamma * v_next - values      # TD residuals
    adv = np.zeros(T)
    run = 0.0
    for t in reversed(range(T)):                    # A_t = d_t + g*l*A_{t+1}
        run = deltas[t] + gamma * lam * run
        adv[t] = run
    ret = np.zeros(T)                               # targets for eq. (28)
    run = 0.0
    for t in reversed(range(T)):
        run = rewards[t] + gamma * run
        ret[t] = run
    return adv, ret

What the experiments show

The experiments ask two questions: how γ\gamma and λ\lambda affect learning when the optimizer is held fixed, and whether GAE with the two trust regions can train large neural network policies on hard control problems. All results are reported as cost, the negative reward, so lower is better. "No VF" in the plots is a baseline that depends only on the timestep: the average return at that timestep across the batch.

Cart-pole. A linear policy and a value network with one 20-unit hidden layer, 20 trajectories per batch of at most 1,000 steps, averaged over 21 random seeds. At γ=0.99\gamma = 0.99, the paper compares λ\lambda = 0, 0.36, 0.68, 0.84, 0.92, 0.96, 0.98, 0.99 and 1, plus no value function; the fastest improvement comes from λ\lambda in [0.92, 0.98]. A heat map of cost after 20 iterations over a grid of γ\gamma and λ\lambda puts the best region at γ∈[0.96,0.99]\gamma \in [0.96, 0.99] and λ∈[0.92,0.99]\lambda \in [0.92, 0.99].

3D robots. The policy and value networks share an architecture: three tanh hidden layers of 100, 50 and 25 units with a linear output layer. The simulated humanoid has 33 state dimensions and 10 actuated joints, the quadruped 29 and 8. Episodes end after 2,000 steps of 0.01 s, and the walking episodes end earlier if the center of mass falls below 0.8 m (biped) or 0.2 m (quadruped). The rewards for biped walking, quadruped walking and biped getting up are

rbiped=vfwd−10−5∥u∥2−10−5∥fimpact∥2+0.2rquad=vfwd−10−6∥u∥2−10−3∥fimpact∥2+0.05rup=−(hhead−1.5)2−10−5∥u∥2\begin{aligned} r_{\text{biped}} &= v_{\mathrm{fwd}} - 10^{-5}\|u\|^2 - 10^{-5}\|f_{\mathrm{impact}}\|^2 + 0.2 \\ r_{\text{quad}} &= v_{\mathrm{fwd}} - 10^{-6}\|u\|^2 - 10^{-3}\|f_{\mathrm{impact}}\|^2 + 0.05 \\ r_{\text{up}} &= -(h_{\mathrm{head}} - 1.5)^2 - 10^{-5}\|u\|^2 \end{aligned}

with vfwdv_{\mathrm{fwd}} the forward velocity, uu the joint torques, fimpactf_{\mathrm{impact}} the impact forces and hheadh_{\mathrm{head}} the head height. The constant offset pays the walkers for staying up; without it, the quadratic penalties could make ending the episode early the best policy.

Biped locomotion. 50,000 timesteps per batch, nine seeds, about 2 hours per run on a 16-core machine. The plotted conditions vary γ\gamma from 0.96 to 1 at λ=0.96\lambda = 0.96, and λ\lambda from 0.92 to 1 at γ=0.995\gamma = 0.995, plus γ=1\gamma = 1 without a value function. The best curves come from γ∈[0.99,0.995]\gamma \in [0.99, 0.995] and λ∈[0.96,0.99]\lambda \in [0.96, 0.99]. After 1,000 iterations the gait is fast, smooth and stable. The paper converts this to robot time: 0.01×50,000×1,0000.01 \times 50{,}000 \times 1{,}000 seconds is 5.8 days of simulated experience, short enough that the authors call training on a real robot plausible if it could be reset safely.

Quadruped and standing up. 200,000 timesteps per batch, five seeds, about 4 hours per run on a 32-core machine, and a smaller comparison: λ=0.96\lambda = 0.96, λ=1\lambda = 1, and no value function (the Provenance panel below covers a mismatch between the text and the plots here). For the quadruped, λ=0.96\lambda = 0.96 is best. For standing up, a value function always helps, and λ=0.96\lambda = 0.96 and λ=1\lambda = 1 end up about the same. The standing-up curves run 500 iterations; at 200,000 steps each that is 11.6 days of simulated time. With the 5.8 days of the walking run, that roughly matches the abstract's "1-2 weeks" for the biped tasks.

The discussion summarizes the sweep as: an intermediate λ\lambda in [0.9, 0.99] usually works best. It also reports that λ=0\lambda = 0, the one-step estimate, was too biased to perform well on these tasks, and contrasts this with DDPG and related concurrent work, which differentiate a learned Q-function with respect to the action and made one-step methods work on lower-dimensional problems with careful tuning. The paper compares no other algorithms; it relies on the TRPO paper for those comparisons.

The paper leaves several questions open. Its analysis is, in its own words, "intuitive but informal": there is no bound relating the value function's error to the gradient's error, so the choice of regression loss for VV is not matched to what the policy gradient needs. γ\gamma and λ\lambda are fixed by hand. And the policy and value networks are separate; sharing features between them is listed as future work.

Implementation notes

John Schulman's modular_rl repository has the reference implementation, released after the paper. Its compute_advantage function is equation (16) with three practical additions. A trajectory that ended in a terminal state bootstraps the last residual with 0; one cut off by the time limit bootstraps it with the last predicted value of the path, an approximation to V(sT)V(s_T). The discounted sum is computed with a backward linear filter (scipy.signal.lfilter), which evaluates the backward recursion from the GAE section in vectorized form. And the advantages are standardized to mean 0 and standard deviation 1 across the whole batch before the policy step.

The released value fit differs from Section 5. It runs 25 iterations of L-BFGS with a small L2 penalty, and instead of a trust region it regresses onto targets mixed 10% new return and 90% old prediction, which also limits how far one batch can move the network. The value network gets the normalized timestep t / timestep_limit as an extra input, which lets it represent the shrinking return near a time limit. The command-line defaults are γ=0.99\gamma = 0.99 and λ=1.0\lambda = 1.0.

PPO (2017) kept GAE and replaced the TRPO step with a clipped objective. Its MuJoCo runs use γ=0.99\gamma = 0.99 and λ=0.95\lambda = 0.95 on segments of 2,048 steps, with the sum in (16) truncated at the segment end and bootstrapped there. Its value target is A^t+V(st)\hat A_t + V(s_t), which by the identity in the GAE section is the λ-return, the TD(λ) target the paper's footnote describes.

Provenance Verified against primary literatureHow we verify
Kimura & Kobayashi (1998); Wawrzyński (2009)Earlier online actor-critic methods with the same exponentially weighted estimator. The paper credits them for the formula and claims novelty for the analysis and for using it in a batch trust-region algorithm.
Sutton & Barto (1998), TD(lambda)The lambda-return is (1 - lambda) times the sum over n of lambda^(n-1) times the n-step return. GAE is the same average applied to the k-step advantage estimators, so GAE(gamma, lambda) equals the lambda-return minus V(s_t). Footnote 2 of the paper uses the lambda-return as an alternative value target and reports no difference from the Monte Carlo target.
Ng, Harada & Russell (1999)Potential-based reward shaping, r + gamma Phi(s') - Phi(s), leaves optimal policies of the discounted problem unchanged. Equation (20) is this transformation; with Phi = V the shaped reward is the TD residual.
Schulman et al. (2015), TRPOThe policy update of equation (31): maximize the importance-weighted surrogate subject to an average KL constraint, solved with conjugate gradient and a line search. The GAE paper holds this optimizer fixed and varies only gamma and lambda.
modular_rl, core.py L49-62 (official code, J. Schulman)compute_advantage: deltas = r + gamma*b[t+1] - b[t], where a path cut off by the time limit is bootstrapped with its last baseline value b[-1] and a terminated path with 0; advantage = discount(deltas, gamma*lam); then advantages are standardized to mean 0 and standard deviation 1 across the batch, a step the paper does not mention.
modular_rl, core.py L392-414, L427-439; agentzoo.py L49The released value fit is L-BFGS (25 iterations, L2 penalty 1e-3) on targets mixed as 0.1 x new Monte Carlo return + 0.9 x old prediction (mixfrac = 0.1), not the conjugate-gradient trust region of equations (29)-(30). The value network also receives t / timestep_limit as an extra input. Defaults (core.py L71-72): gamma = 0.99, lam = 1.0. The code was released after the paper, so these may not be the settings behind its plots.
Paper, Section 5 constantsThe constraint is written three ways: (29) as mean squared change / (2 sigma^2) <= epsilon, (30) as the quadratic form with H and no factor, and the step rescaling as 1/2 (alpha s)^T H (alpha s) = epsilon. They differ by constant factors (2 sigma^2, 1, 1/2) that only change what a given epsilon means. The paper reports no value of epsilon for either trust region. The figure on this page implements (29).
Paper, Section 6.2.1 parameter countWith 33 inputs and 100-50-25 tanh layers, the policy mean network has 9,985 weights and biases (10 outputs) and the value network 9,751 (1 output). The text says "each with over 10^4 parameters"; that holds if the policy has extra parameters (for example a learned log standard deviation per action, 10 more) or inputs the paper does not list.
Paper, Appendix B and equations (21), (23), (25), (31)Small slips with no effect on the results. Equation (31) is printed as a minimization of the advantage-weighted surrogate with the step along -F^{-1} g; for an advantage measured in reward, as Section 3 defines it, the surrogate is maximized and the step is along +F^{-1} g, which is how this page writes it.The proof of Proposition 1 ends the Q-term with A^pi and an expectation over a_{0:t-1}; it should be Q^{pi,gamma} over a_{0:t}, and the advantage form follows by subtracting V^{pi,gamma}(s_t) as a baseline. Equations (21) and (25) write the shaped reward with a_t where a_{t+l} is meant, and (23) writes V-tilde(s, a) for V-tilde(s).
correctionSection 6.3.3 says the quadruped and standing-up runs fixed γ = 0.995 and varied λ ∈ {0, 0.96}, plus a run with no value function. The legends of the plotted curves show λ = 0.96 and λ = 1 (plus no value function), and the standing-up legend uses γ = 0.99, not 0.995. The paragraph's own last sentence compares λ = 0.96 with λ = 1, which matches the plots, so {0, 0.96} is a slip. Relatedly, the paragraph cites the quadruped result to "Section 6.3.2" (PDF) or "Figure 3" (HTML), and Figure 4's caption lists the quadruped as panel (a) while the quadruped curves are drawn in Figure 3's right panel. This page reports the conditions as the legends show them.

Questions you might still have

?

Is GAE the same thing as TD(λ)?
It uses the same construction for a different quantity. TD(λ) averages n-step returns with weights (1 − λ)λ^(n−1) to get a target for the value function. GAE averages k-step advantage estimates with the same weights. Each k-step advantage is the k-step return minus V(s_t), so GAE(γ, λ) is exactly the λ-return minus V(s_t). PPO uses that identity in reverse: its value target is the GAE advantage plus the old value prediction.

?

Why not learn a Q-function and use Q(s, a) − V(s) as the advantage?
Appendix A.2 gives two reasons. A state-value function has a smaller input (no action), so it is easier to learn, and GAE can move smoothly from the high-bias one-step estimate (λ = 0) to the low-bias Monte Carlo one (λ = 1). A learned Q-function gives only a high-bias estimate, and the authors found the one-step estimate too biased on their tasks. DDPG, published the same year, made the Q-function approach work on lower-dimensional problems.

?

Why does the policy update use the old value function?
Because the value step regresses V toward returns from the same batch. If V were fitted first and fitted perfectly, every residual r + γV(s') − V(s) on that batch would be zero, and so would the advantages and the policy gradient. Fitting V afterwards keeps the batch out of the baseline that scores it. The paper calls the opposite order a source of additional bias.

?

Which γ and λ should I use?
The paper's best results sit at γ between 0.96 and 0.995 and λ between 0.92 and 0.99, with λ well below γ, and its discussion recommends λ in [0.9, 0.99]. PPO later used γ = 0.99 and λ = 0.95 on MuJoCo. A useful check is the effective horizon 1/(1 − γλ): at 0.99 and 0.95 it is about 17 steps, so residuals more than a few dozen steps after an action contribute almost nothing.

?

Does GAE work with data from an older policy, such as a replay buffer?
Not without corrections. The analysis assumes the trajectory was sampled from the policy being updated: the residuals after step t reflect what the current policy would do next. With off-policy data the sum mixes in another policy's behavior. PPO stays close to this assumption by reusing each batch for only a few epochs with a clipped objective that limits how far the policy moves; fully off-policy methods use importance-weighted corrections instead.

?

How are episodes that hit the time limit handled?
The sum in GAE is infinite, and a trajectory cut off by a time limit did not end, so the last residual needs a value for the state after the cut. The authors' released code bootstraps with the last predicted value of the path; a terminal state gets 0. Treating a time-limit cut as a true termination would tell the value function the episode ends there, which biases V near the limit.

?

Does it matter that the code standardizes the advantages?
Rescaling every advantage by the same positive factor does not change a TRPO step: the natural-gradient direction scales by that factor and the KL-constrained step length divides it back out. Subtracting the batch mean acts like an extra constant baseline, which mainly changes the variance of the gradient rather than its expected direction. With a fixed learning rate, as in plain policy gradient, the scale matters and standardization sets it.

Footnotes & further reading

  1. The paper: Schulman, Moritz, Levine, Jordan & Abbeel, High-Dimensional Continuous Control Using Generalized Advantage Estimation (ICLR 2016; arXiv v6, October 2018). Videos of the learned gaits are linked from the paper.
  2. Reference code: joschu/modular_rl, modular_rl/core.py (compute_advantage, NnRegression, NnVf) and modular_rl/agentzoo.py.
  3. The policy optimizer: Schulman et al., Trust Region Policy Optimization (ICML 2015), covered in the TRPO explainer. Its successor, Schulman et al., Proximal Policy Optimization Algorithms (2017), uses GAE; see the PPO explainer.
  4. Reward shaping: Ng, Harada & Russell, Policy Invariance Under Reward Transformations: Theory and Application to Reward Shaping (ICML 1999).
  5. TD(λ) and the λ-return: Sutton & Barto, Reinforcement Learning: An Introduction, chapter 12 of the second edition. The policy-gradient baseline argument goes back to Williams, Simple statistical gradient-following algorithms for connectionist reinforcement learning (1992); its variance is analyzed in Greensmith, Bartlett & Baxter, Variance Reduction Techniques for Gradient Estimates in Reinforcement Learning (JMLR 2004).
  6. The one-step, Q-function route the paper contrasts itself with: Lillicrap et al., Continuous control with deep reinforcement learning (2015), in the DDPG explainer. The single-k bootstrapped advantage is in the A3C explainer.