class_docstr: Base class for weight update methods.
  
  Attributes:
    all_layers_names: list of layer names in a model.
    recycle_type: neuron, layer based.
    dead_neurons_threshold: below this threshold a neuron is considered dead.
    reset_layers: list of layer names to be recycled.
    reset_start_layer_idx: index of the layer from which we start recycling.
    reset_period: int represents the period of weight update.
    reset_start_step: start recycle from start step
    reset_end_step:  end recycle from end step
    logging_period:  the period of statistics logging e.g., dead neurons.
    prev_neuron_score: score at last reset step or log step in case of no reset.
    sub_mean_score: if True the average activation will be subtracted
                    for each neuron when we calculate the score.
class_docstr_tok: ["Base","class","for","weight","update","methods",".","Attributes",":","all_layers_names",":","list","of","layer","names","in","a","model",".","recycle_type",":","neuron",",","layer","based",".","dead_neurons_threshold",":","below","this","threshold","a","neuron","is","considered","dead",".","reset_layers",":","list","of","layer","names","to","be","recycled",".","reset_start_layer_idx",":","index","of","the","layer","from","which","we","start","recycling",".","reset_period",":","int","represents","the","period","of","weight","update",".","reset_start_step",":","start","recycle","from","start","step","reset_end_step",":","end","recycle","from","end","step","logging_period",":","the","period","of","statistics","logging","e.g.",",","dead","neurons",".","prev_neuron_score",":","score","at","last","reset","step","or","log","step","in","case","of","no","reset",".","sub_mean_score",":","if","True","the","average","activation","will","be","subtracted","for","each","neuron","when","we","calculate","the","score","."]
docstr: Track intersected dead neurons with last logging/reset step.
  
  Args:
    intermediates: current intermediates
  
  Returns:
    log_dict: dict contains the percentage of intersection
docstr_tok: ["Track","intersected","dead","neurons","with","last","logging\/reset","step",".","Args",":","intermediates",":","current","intermediates","Returns",":","log_dict",":","dict","contains","the","percentage","of","intersection"]
code: def log_intersected_dead_neurons(self, intermediates):
      """Track intersected dead neurons with last logging/reset step.
  
      Args:
        intermediates: current intermediates
  
      Returns:
        log_dict: dict contains the percentage of intersection
      """
      score_tree = jax.tree_map(
          self.estimate_neuron_score, intermediates
      )
      neuron_score_dict = flax.traverse_util.flatten_dict(
          score_tree, sep="/"
      )
  
      if self.prev_neuron_score is None:
          self.prev_neuron_score = neuron_score_dict
          log_dict = None
      else:
          log_dict = {}
          for prev_k_score, current_k_score in zip(
              self.prev_neuron_score.items(), neuron_score_dict.items()
          ):
              _, prev_score = prev_k_score
              k, score = current_k_score
              prev_score, score = prev_score[0], score[0]
              prev_mask = prev_score <= self.dead_neurons_threshold
              # we count the dead neurons which remains dead in the current step.
              intersected_mask = (prev_mask) & (
                  score <= self.dead_neurons_threshold
              )
              prev_dead_count = jnp.count_nonzero(prev_mask)
              intersected_count = jnp.count_nonzero(intersected_mask)
  
              percent = (
                  (float(intersected_count) / prev_dead_count)
                  if prev_dead_count
                  else 0.0
              )
              log_dict[f"dead_intersected_percent/{k[:-9]}"] = (
                  float(percent) * 100.0
              )
  
              # track average score of recycled neurons from last step and
              # the average of non dead in the current step.
              nondead_mask = score > self.dead_neurons_threshold
              log_dict[f"mean_score_recycled/{k[:-9]}"] = float(
                  jnp.mean(score[prev_mask])
              )
              log_dict[f"mean_score_nondead/{k[:-9]}"] = float(
                  jnp.mean(score[nondead_mask])
              )
  
          self.prev_neuron_score = neuron_score_dict
      return log_dict
  
imports: import functools
  import logging
  import flax
  from flax import linen
  import gin
  import jax
  from jax import random
  import jax.numpy
  import optax
label_desc: Use image node_id 11 for calling the BaseRecycler obj's underlying member method code with example usage: obj.log_intersected_dead_neurons(intermediates) and returns: log_dict