Generalized Advantage Estimation (GAE) provides a family of advantage estimators that trade off bias and variance using a parameter lambda. When lambda = 0 it reduces to the one-step TD error (low variance, high bias). When lambda = 1 it becomes equivalent to the full Monte Carlo advantage (high variance, low bias). In practice, lambda around 0.95 works well.
Given rewards, value estimates (including V(s_T) = 0 for the terminal state), gamma, and lambda, compute the GAE advantages for each timestep.
Return the advantages as a list of floats with the same length as rewards.
Input: rewards = [1, 1, 1], values = [0, 0, 0, 0], gamma = 1, lam = 1
Output: [3.0, 2.0, 1.0]
Explanation: With gamma and lambda equal to 1, future TD errors accumulate without decay.
Input: rewards = [1, 0, 5], values = [1, 2, 3, 0], gamma = 0.9, lam = 0.95
Output: [3.86055, 2.41, 2.0]
Traverse timesteps backward while carrying the next advantage.
At each step, add the TD error to gamma times lambda times the carried advantage.
Accepts: array
Accepts: array
Accepts: number
Accepts: number
Generalized Advantage Estimation (GAE) provides a family of advantage estimators that trade off bias and variance using a parameter lambda. When lambda = 0 it reduces to the one-step TD error (low variance, high bias). When lambda = 1 it becomes equivalent to the full Monte Carlo advantage (high variance, low bias). In practice, lambda around 0.95 works well.
Given rewards, value estimates (including V(s_T) = 0 for the terminal state), gamma, and lambda, compute the GAE advantages for each timestep.
Return the advantages as a list of floats with the same length as rewards.
Input: rewards = [1, 1, 1], values = [0, 0, 0, 0], gamma = 1, lam = 1
Output: [3.0, 2.0, 1.0]
Explanation: With gamma and lambda equal to 1, future TD errors accumulate without decay.
Input: rewards = [1, 0, 5], values = [1, 2, 3, 0], gamma = 0.9, lam = 0.95
Output: [3.86055, 2.41, 2.0]
Traverse timesteps backward while carrying the next advantage.
At each step, add the TD error to gamma times lambda times the carried advantage.
Accepts: array
Accepts: array
Accepts: number
Accepts: number