code: def _ground_truth_calculation(
      discounts,
      log_rhos,
      rewards,
      values,
      bootstrap_value,
      clip_rho_threshold,
      clip_pg_rho_threshold,
  ):
      """Calculates the ground truth for V-trace in Python/Numpy."""
      vs = []
      seq_len = len(discounts)
      rhos = np.exp(log_rhos)
      cs = np.minimum(rhos, 1.0)
      clipped_rhos = rhos
      if clip_rho_threshold:
          clipped_rhos = np.minimum(rhos, clip_rho_threshold)
      clipped_pg_rhos = rhos
      if clip_pg_rho_threshold:
          clipped_pg_rhos = np.minimum(rhos, clip_pg_rho_threshold)
  
      # This is a very inefficient way to calculate the V-trace ground truth.
      # We calculate it this way because it is close to the mathematical notation of
      # V-trace.
      # v_s = V(x_s)
      #       + \sum^{T-1}_{t=s} \gamma^{t-s}
      #         * \prod_{i=s}^{t-1} c_i
      #         * \rho_t (r_t + \gamma V(x_{t+1}) - V(x_t))
      # Note that when we take the product over c_i, we write `s:t` as the notation
      # of the paper is inclusive of the `t-1`, but Python is exclusive.
      # Also note that np.prod([]) == 1.
      values_t_plus_1 = np.concatenate(
          [values, bootstrap_value[None, :]], axis=0
      )
      for s in range(seq_len):
          v_s = np.copy(values[s])  # Very important copy.
          for t in range(s, seq_len):
              v_s += (
                  np.prod(discounts[s:t], axis=0)
                  * np.prod(cs[s:t], axis=0)
                  * clipped_rhos[t]
                  * (
                      rewards[t]
                      + discounts[t] * values_t_plus_1[t + 1]
                      - values[t]
                  )
              )
          vs.append(v_s)
      vs = np.stack(vs, axis=0)
      pg_advantages = clipped_pg_rhos * (
          rewards
          + discounts
          * np.concatenate([vs[1:], bootstrap_value[None, :]], axis=0)
          - values
      )
  
      return impala_vtrace.VTraceReturns(
          vs=vs, pg_advantages=pg_advantages
      )
  
file_path: maze/maze/test/train/impala/test_vtrace.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import gym
  import numpy
  from maze.distributions.distribution_mapper import DistributionMapper
  from maze.perception.perception_utils import convert_to_torch
  from maze.train.trainers.impala import impala_vtrace
label_desc: Use image node_id 3 for calling a global function with example usage: _ground_truth_calculation(discounts, log_rhos, rewards, values, bootstrap_value, clip_rho_threshold, clip_pg_rho_threshold) and returns: impala_vtrace