class_docstr: Applies Spectral Normalization to all parameters in a tree.
  
  This is isomorphic to EMAParamsTree in moving_averages.py.
class_docstr_tok: ["Applies","Spectral","Normalization","to","all","parameters","in","a","tree",".","This","is","isomorphic","to","EMAParamsTree","in","moving_averages.py","."]
code: def __call__(self, tree, update_stats=True):
      def maybe_sn(k, v):
          if self.ignore_regex and re.match(self.ignore_regex, k):
              return v
          else:
              sn_name = k.replace("/", "__").replace("~", "_tilde")
              return SpectralNorm(self.eps, self.n_steps, name=sn_name)(
                  v, update_stats=update_stats
              )
  
      # We want to potentially replace params with Spectral Normalized versions.
      new_values = {}
      for module_name, param_dict in tree.items():
          new_values[module_name] = {
              k: maybe_sn("/".join([module_name, k]), v)
              for k, v in param_dict.items()
          }
      return hk.data_structures.to_haiku_dict(new_values)
  
imports: import re
  from typing import Optional
  from haiku._src import base
  from haiku._src import data_structures
  from haiku._src import initializers
  from haiku._src import module
  import jax
  import jax.lax
  import jax.numpy
label_desc: Use image node_id 2 for calling the SNParamsTree obj's underlying member method code with example usage: obj.__call__(tree, update_stats) and returns: hk, v, SpectralNorm