def gae_returns(rollout: StepSequence, gamma: float=0.99, lamb: float=0.95):
    "\n    Compute returns using generalized advantage estimation.\n\n    .. seealso::\n        [1] J. Schulmann, P. Moritz, S. Levine, M. Jordan, P. Abbeel, 'High-Dimensional Continuous Control Using\n        Generalized Advantage Estimation', ICLR 2016\n\n    :param rollout: sequence of steps\n    :param gamma: temporal discount factor\n    :param lamb: discount factor\n    :return: estimated advantage\n    "

    def _next_value(step: Step) -> float:
        ' Helper to return `next_value = 0` for last step '
        if step.done:
            return 0.0
        return step.next_value
    deltas = [((step.reward + (gamma * _next_value(step))) - step.value) for step in rollout]
    cumsum = discounted_reverse_cumsum(deltas, (gamma * lamb))
    return cumsum
Compute returns using generalized advantage estimation.

.. seealso::
    [1] J. Schulmann, P. Moritz, S. Levine, M. Jordan, P. Abbeel, 'High-Dimensional Continuous Control Using
    Generalized Advantage Estimation', ICLR 2016

:param rollout: sequence of steps
:param gamma: temporal discount factor
:param lamb: discount factor
:return: estimated advantage
def gae_returns(rollout: StepSequence, gamma: float=0.99, lamb: float=0.95):
    "\n    Compute returns using generalized advantage estimation.\n\n    .. seealso::\n        [1] J. Schulmann, P. Moritz, S. Levine, M. Jordan, P. Abbeel, 'High-Dimensional Continuous Control Using\n        Generalized Advantage Estimation', ICLR 2016\n\n    :param rollout: sequence of steps\n    :param gamma: temporal discount factor\n    :param lamb: discount factor\n    :return: estimated advantage\n    "

    def _next_value(step: Step) -> float:
        ' Helper to return `next_value = 0` for last step '
        if step.done:
            return 0.0
        return step.next_value
    deltas = [((step.reward + (gamma * _next_value(step))) - step.value) for step in rollout]
    cumsum = discounted_reverse_cumsum(deltas, (gamma * lamb))
    return cumsum