code: def calc_indicators(mem):
      START_STEPS = 15
      n = len(mem)
      episode_shaping_reward = np.sum(
          [exp.info["shaping_reward"] for exp in mem]
      )
      episode_r2_reward = np.sum(
          [
              exp.info["r2_reward"]
              for exp in mem
              if exp.info["frame_count"] <= 1000
          ]
      )
      x_offset_reward = np.sum(
          exp.info["x_offset_reward"] for exp in mem
      )
  
      episode_length = mem[-1].info["frame_count"]
  
      scalar_vel = np.mean([exp.info["scalar_vel"] for exp in mem])
      action_l2_penalty = np.mean(
          [exp.info["mean_action_l2_penalty"] for exp in mem]
      )
  
      start_loss = 10 * START_STEPS * 4 - np.sum(
          [exp.reward for exp in mem][:START_STEPS]
      )
      all_start_loss = 0
      for i in range(n):
          if not mem[i].info["target_changed"]:
              frame_count = 4
              if i - 1 >= 0:
                  frame_count = (
                      mem[i].info["frame_count"]
                      - mem[i - 1].info["frame_count"]
                  )
              all_start_loss += 10.0 * frame_count - mem[i].reward
          else:
              break
      start_other_loss = all_start_loss - start_loss
      first_change_loss = 0
      second_change_loss = 0
      third_change_loss = 0
      first_change_other_loss = 0
      second_change_other_loss = 0
      third_change_other_loss = 0
      first_stage_vel = 0.0
      second_stage_vel = 0.0
      third_stage_vel = 0.0
      other_loss = 0
  
      change_loss = []
      all_change_loss = []
      change_vel = []
  
      for i in range(n - 1):
          if mem[i].info["target_changed"]:
              change_loss.append(0.0)
              all_change_loss.append(0.0)
              change_vel.append([])
              for j in range(START_STEPS):
                  idx = i + 1 + j
                  if idx >= n or mem[idx].info["target_changed"]:
                      break
                  frame_count = 4
                  if idx - 1 >= 0:
                      frame_count = (
                          mem[idx].info["frame_count"]
                          - mem[idx - 1].info["frame_count"]
                      )
                  change_loss[-1] += (
                      10.0 * frame_count - mem[idx].reward
                  )
              for j in range(n - i - 1):
                  idx = i + 1 + j
                  if idx >= n or mem[idx].info["target_changed"]:
                      break
                  if idx - 1 >= 0:
                      frame_count = (
                          mem[idx].info["frame_count"]
                          - mem[idx - 1].info["frame_count"]
                      )
                  all_change_loss[-1] += (
                      10.0 * frame_count - mem[idx].reward
                  )
                  change_vel[-1].append(mem[idx].info["scalar_vel"])
  
      if len(change_loss) >= 1:
          first_change_loss = change_loss[0]
          first_change_other_loss = all_change_loss[0] - change_loss[0]
      if len(change_loss) >= 2:
          second_change_loss = change_loss[1]
          second_change_other_loss = all_change_loss[1] - change_loss[1]
      if len(change_loss) >= 3:
          third_change_loss = change_loss[2]
          third_change_other_loss = all_change_loss[2] - change_loss[2]
      other_loss = (
          10 * mem[-1].info["frame_count"]
          - start_loss
          - first_change_loss
          - second_change_loss
          - third_change_loss
          - episode_r2_reward
      )
      if len(change_vel) >= 1:
          first_stage_vel = np.mean(change_vel[0])
      if len(change_vel) >= 2:
          second_stage_vel = np.mean(change_vel[1])
      if len(change_vel) >= 3:
          third_stage_vel = np.mean(change_vel[2])
  
      indicators_dict = {
          "episode_shaping_reward": episode_shaping_reward,
          "episode_r2_reward": episode_r2_reward,
          "x_offset_reward": x_offset_reward,
          "episode_length": episode_length,
          "scalar_vel": scalar_vel,
          "mean_action_l2_penalty": action_l2_penalty,
          "start_loss": start_loss,
          "first_change_loss": first_change_loss,
          "second_change_loss": second_change_loss,
          "third_change_loss": third_change_loss,
          "start_other_loss": start_other_loss,
          "first_change_other_loss": first_change_other_loss,
          "second_change_other_loss": second_change_other_loss,
          "third_change_other_loss": third_change_other_loss,
          "other_loss": other_loss,
          "first_stage_vel": first_stage_vel,
          "second_stage_vel": second_stage_vel,
          "third_stage_vel": third_stage_vel,
      }
      return indicators_dict
  
imports: import csv
  import numpy
  import tensorflow
  import os
  import six
label_desc: Use image node_id 1 for calling a global function with example usage: calc_indicators(mem) and returns: indicators_dict