code: def compute_advantages(
      discount,
      gae_lambda,
      max_len,
      baselines,
      rewards,
      name="compute_advantages",
  ):
      """Calculate advantages.
  
      Advantages are a discounted cumulative sum.
  
      The discount cumulative sum can be represented as an IIR
      filter ob the reversed input vectors, i.e.
  
      y[t] - discount*y[t+1] = x[t], or
      rev(y)[t] - discount*rev(y)[t-1] = rev(x)[t]
  
      Given the time-domain IIR filter step response, we can
      calculate the filter response to our signal by convolving the
      signal with the filter response function. The time-domain IIR
      step response is calculated below as discount_filter:
  
      discount_filter = [1, discount, discount^2, ..., discount^N-1]
      where the epsiode length is N.
  
      We convolve discount_filter with the reversed time-domain
      signal deltas to calculate the reversed advantages:
  
      rev(advantages) = discount_filter (X) rev(deltas)
  
      TensorFlow's tf.nn.conv1d op is not a true convolution, but
      actually a cross-correlation, so its input and output are
      already implicitly reversed for us.
  
      advantages = discount_filter (tf.nn.conv1d) deltas
  
      Args:
          discount (float): Discount factor.
          gae_lambda (float): Lambda, as used for Generalized Advantage
              Estimation (GAE).
          max_len (int): Maximum length of a single episode.
          baselines (tf.Tensor): A 2D vector of value function estimates with
              shape :math:`(N, T)`, where :math:`N` is the batch dimension
              (number of episodes) and :math:`T` is the maximum episode length
              experienced by the agent.
          rewards (tf.Tensor): A 2D vector of per-step rewards with shape
              :math:`(N, T)`, where :math:`N` is the batch dimension (number of
              episodes) and :math:`T` is the maximum episode length experienced
              by the agent.
          name (string): Name of the operation.
  
      Returns:
          tf.Tensor: A 2D vector of calculated advantage values with shape
              :math:`(N, T)`, where :math:`N` is the batch dimension (number of
              episodes) and :math:`T` is the maximum episode length experienced
              by the agent.
      """
      with tf.name_scope(name):
          # Prepare convolutional IIR filter to calculate advantages
          gamma_lambda = tf.constant(
              float(discount) * float(gae_lambda),
              dtype=tf.float32,
              shape=[max_len, 1, 1],
          )
          advantage_filter = tf.compat.v1.cumprod(
              gamma_lambda, axis=0, exclusive=True
          )
  
          # Calculate deltas
          pad = tf.zeros_like(baselines[:, :1])
          baseline_shift = tf.concat([baselines[:, 1:], pad], 1)
          deltas = rewards + discount * baseline_shift - baselines
  
          # Convolve deltas with the discount filter to get advantages
          deltas_pad = tf.expand_dims(
              tf.concat([deltas, tf.zeros_like(deltas[:, :-1])], 1),
              axis=2,
          )
          adv = tf.nn.conv1d(
              deltas_pad, advantage_filter, stride=1, padding="VALID"
          )
          advantages = tf.reshape(adv, [-1])
  
      return advantages
  
imports: import collections
  import numpy
  import tensorflow
label_desc: Use image node_id 19 for calling a global function with example usage: compute_advantages(discount, gae_lambda, max_len, baselines, rewards, name) and returns: advantages