class_docstr: A PPO Agent.
class_docstr_tok: ["A","PPO","Agent","."]
docstr: Compute advantages, optionally using GAE.
  
  Based on baselines ppo1 implementation. Removes final timestep, as it needs
  to use this timestep for next-step value prediction for TD error
  computation.
  
  Args:
    rewards: Tensor of per-timestep rewards.
    returns: Tensor of per-timestep returns.
    discounts: Tensor of per-timestep discounts. Zero for terminal timesteps.
    value_preds: Cached value estimates from the data-collection policy.
  
  Returns:
    advantages: Tensor of length (len(rewards) - 1), because the final
      timestep is just used for next-step value prediction.
docstr_tok: ["Compute","advantages",",","optionally","using","GAE",".","Based","on","baselines","ppo1","implementation",".","Removes","final","timestep",",","as","it","needs","to","use","this","timestep","for","next-step","value","prediction","for","TD","error","computation",".","Args",":","rewards",":","Tensor","of","per-timestep","rewards",".","returns",":","Tensor","of","per-timestep","returns",".","discounts",":","Tensor","of","per-timestep","discounts",".","Zero","for","terminal","timesteps",".","value_preds",":","Cached","value","estimates","from","the","data-collection","policy",".","Returns",":","advantages",":","Tensor","of","length","(","len","(","rewards",")","-","1",")",",","because","the","final","timestep","is","just","used","for","next-step","value","prediction","."]
code: def compute_advantages(
      self,
      rewards: types.NestedTensor,
      returns: types.Tensor,
      discounts: types.Tensor,
      value_preds: types.Tensor,
  ) -> types.Tensor:
      """Compute advantages, optionally using GAE.
  
      Based on baselines ppo1 implementation. Removes final timestep, as it needs
      to use this timestep for next-step value prediction for TD error
      computation.
  
      Args:
        rewards: Tensor of per-timestep rewards.
        returns: Tensor of per-timestep returns.
        discounts: Tensor of per-timestep discounts. Zero for terminal timesteps.
        value_preds: Cached value estimates from the data-collection policy.
  
      Returns:
        advantages: Tensor of length (len(rewards) - 1), because the final
          timestep is just used for next-step value prediction.
      """
      # Arg value_preds was appended with final next_step value. Make tensors
      #   next_value_preds by stripping first and last elements respectively.
      value_preds = value_preds[:, :-1]
      if self._use_gae:
          advantages = value_ops.generalized_advantage_estimation(
              values=value_preds,
              final_value=value_preds[:, -1],
              rewards=rewards,
              discounts=discounts,
              td_lambda=self._lambda,
              time_major=False,
          )
      else:
          with tf.name_scope("empirical_advantage"):
              advantages = returns - value_preds
  
      return advantages
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import collections
  from typing import Optional, Text, Tuple
  from absl import logging
  import gin
  from six.moves import range
  from six.moves import zip
  import tensorflow
  from tf_agents.agents import data_converter
  from tf_agents.agents import tf_agent
  from tf_agents.agents.ppo import ppo_policy
  from tf_agents.agents.ppo import ppo_utils
  from tf_agents.networks import network
  from tf_agents.policies import greedy_policy
  from tf_agents.specs import tensor_spec
  from tf_agents.trajectories import time_step
  from tf_agents.trajectories import trajectory
  from tf_agents.typing import types
  from tf_agents.utils import common
  from tf_agents.utils import eager_utils
  from tf_agents.utils import nest_utils
  from tf_agents.utils import object_identity
  from tf_agents.utils import tensor_normalizer
  from tf_agents.utils import value_ops
label_desc: Use image node_id 4 for calling the PPOAgent obj's underlying member method code with example usage: obj.compute_advantages(rewards, returns, discounts, value_preds) and returns: advantages