class_docstr: Wrapped DqnAgent that supports recycled training.
class_docstr_tok: ["Wrapped","DqnAgent","that","supports","recycled","training","."]
code: def calculate_neuron_score_all_layers(
      self, model, intermediate_act, intermediate_act_grad
  ):
      all_layers_score = {}
      if self.neuron_score_algo == "activation":
          for act_key, act_value in intermediate_act.items():
              self.log_batch_size = min(
                  self.log_batch_size, act_value.shape[0]
              )
              neurons_score = tf.reduce_mean(
                  tf.math.abs(act_value[: self.log_batch_size, :]),
                  axis=0,
              )
              neurons_score = neurons_score / (
                  tf.reduce_mean(neurons_score) + 1e-9
              )
              all_layers_score[act_key] = neurons_score
      elif self.neuron_score_algo == "activation_grad":
          for act, act_grad in zip(
              intermediate_act.items(), intermediate_act_grad.items()
          ):
              act_k, act_v = act
              _, act_grad_v = act_grad
              self.log_batch_size = min(
                  self.log_batch_size, act_v.shape[0]
              )
              act_multi_grad = tf.math.abs(
                  tf.multiply(
                      act_v[: self.log_batch_size, :],
                      act_grad_v[: self.log_batch_size, :],
                  )
              )
              neurons_score = tf.reduce_mean(act_multi_grad, axis=0)
              neurons_score = neurons_score / (
                  tf.reduce_mean(neurons_score) + 1e-9
              )
              all_layers_score[act_k] = neurons_score
      elif self.neuron_score_algo == "connected_weights":
          model_layers = get_all_layers(model, filter_fn=is_dense_layer)
          for layer, next_layer in zip(
              model_layers[:-1], model_layers[1:]
          ):
              incoming_var = layer.kernel
              outgoing_var = next_layer.kernel
              # incoming_var is KxN, outgoing_var is NxM.
              # neurons_score is N dimensional
              neurons_score = tf.reduce_sum(
                  tf.math.abs(incoming_var), axis=0
              )
              neurons_score *= tf.reduce_sum(
                  tf.math.abs(outgoing_var), axis=1
              )
              neurons_score = neurons_score / (
                  tf.reduce_mean(neurons_score) + 1e-9
              )
              all_layers_score[layer.name] = neurons_score
      else:
          raise ValueError(
              "neuron_score_algo:%s  is not valid."
              % self.neuron_score_algo
          )
      return all_layers_score
  
imports: import functools
  import os
  from absl import app
  from absl import flags
  from absl import logging
  import gin
  import numpy
  import reverb
  from rigl.rl.tfagents import sparse_tanh_normal_projection_network
  import tensorflow
  from tf_agents.agents import tf_agent
  from tf_agents.agents.sac import sac_agent
  from tf_agents.environments import suite_mujoco
  from tf_agents.keras_layers import inner_reshape
  from tf_agents.metrics import py_metrics
  from tf_agents.networks import nest_map
  from tf_agents.networks import sequential
  from tf_agents.policies import greedy_policy
  from tf_agents.policies import py_tf_eager_policy
  from tf_agents.policies import random_py_policy
  from tf_agents.replay_buffers import reverb_replay_buffer
  from tf_agents.replay_buffers import reverb_utils
  from tf_agents.train import actor
  from tf_agents.train import learner
  from tf_agents.train import triggers
  from tf_agents.train.utils import spec_utils
  from tf_agents.train.utils import strategy_utils
  from tf_agents.train.utils import train_utils
  from tf_agents.utils import common
  from tf_agents.utils import object_identity
label_desc: Use image node_id 6 for calling the RecycledSacAgent obj's underlying member method code with example usage: obj.calculate_neuron_score_all_layers(model, intermediate_act, intermediate_act_grad) and returns: all_layers_score