code: def calc_gae(rewards, values, next_value, gamma, lam):
      """Calculate generalized advantage estimator (GAE).
      See: https://arxiv.org/pdf/1506.02438.pdf
  
      Args:
          rewards (List/Tuple/np.array): rewards of (s_t, s_{t+1}, ..., s_T)
          values (List/Tuple/np.array): values of (s_t, s_{t+1}, ..., s_T)
          next_value (Scalar): value of s_{T+1}
          gamma (Scalar): gamma coefficient
          lam (Scalar): lambda coefficient
  
      Returns:
          advantages (np.array): advantages of (s_t, s_{t+1}, ..., s_T)
      """
      # temporal differences
      tds = rewards + gamma * np.append(values[1:], next_value) - values
      advantages = calc_discount_sum_rewards(tds, gamma * lam)
      return advantages
  
imports: import numpy
  import scipy.signal
label_desc: Use image node_id 2 for calling a global function with example usage: calc_gae(rewards, values, next_value, gamma, lam) and returns: advantages