code: def _adaptive_max_norm(
      norm, std_factor, decay, global_step, epsilon, name
  ):
      """Find max_norm given norm and previous average."""
      with vs.variable_scope(name, "AdaptiveMaxNorm", [norm]):
          log_norm = math_ops.log(norm + epsilon)
  
          def moving_average(name, value, decay):
              moving_average_variable = vs.get_variable(
                  name,
                  shape=value.get_shape(),
                  dtype=value.dtype,
                  initializer=init_ops.zeros_initializer(),
                  trainable=False,
              )
              return moving_averages.assign_moving_average(
                  moving_average_variable,
                  value,
                  decay,
                  zero_debias=False,
              )
  
          # quicker adaptation at the beginning
          if global_step is not None:
              n = math_ops.cast(global_step, dtypes.float32)
              decay = math_ops.minimum(decay, n / (n + 1.0))
  
          # update averages
          mean = moving_average("mean", log_norm, decay)
          sq_mean = moving_average(
              "sq_mean", math_ops.square(log_norm), decay
          )
  
          variance = sq_mean - math_ops.square(mean)
          std = math_ops.sqrt(math_ops.maximum(epsilon, variance))
          max_norms = math_ops.exp(mean + std_factor * std)
          return max_norms, mean
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import six
  from ..None import contrib_framework
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import ops
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import clip_ops
  from tensorflow.python.ops import control_flow_ops
  from tensorflow.python.ops import init_ops
  from tensorflow.python.ops import math_ops
  from tensorflow.python.ops import random_ops
  from tensorflow.python.ops import variable_scope
  from tensorflow.python.ops import variables
  from tensorflow.python.summary import summary
  from tensorflow.python.training import moving_averages
  from tensorflow.python.training import optimizer
  from tensorflow.python.training import training
label_desc: Use image node_id 3 for calling a global function with example usage: _adaptive_max_norm(norm, std_factor, decay, global_step, epsilon, name) and returns: max_norms,  mean, moving_averages