code: def dynamic_normalization(
      x: tf.Tensor,
      mean: tf.Tensor,
      variance: tf.Tensor,
      prior_offset: tf.Tensor,
      mean_offset: tf.Tensor,
      prior_scale: tf.Tensor,
      mean_scale: tf.Tensor,
      variance_epsilon: float,
  ):
      r"""Normalizes a tensor `x` based on the DyanmicNormalization formula.
  
      The normalization formula:
        ((|mean|^2 + p(mean)) / |x|^2 - 2 * g(mean)) / sqrt(variance)
      where
        p(mean) = prior_scale * mean + prior_offset
        g(mean) = mean_scale * mean + mean_offset.
      Here (prior_scale, prior_offset, mean_scale, mean_offset) are learnable
      parameters.
  
      Args:
        x: Input `Tensor` of arbitrary dimensionality.
        mean: A mean `Tensor`.
        variance: A variance `Tensor`.
        prior_offset: An offset `Tensor` for the prior term.
        mean_offset: An offset `Tensor` for estimating the mean value.
        prior_scale: A scale `Tensor` for the prior term.
        mean_scale: A scale `Tensor` for estimating the mean value.
        variance_epsilon: A small float number to avoid dividing by 0.
  
      Returns:
        The normalized, scaled, offset tensor.
      """
      with tf.name_scope("dynamic_normalization"):
          inv = tf.math.rsqrt(variance + variance_epsilon)
  
          # Computes (|mean|^2 + (scale * mean + offset)) / (|x|^2 + epsilon)
          dividend = tf.reduce_sum(
              tf.math.square(mean), -1, keepdims=True
          )
          dividend += prior_scale * mean + prior_offset
          divisor = (
              tf.reduce_sum(tf.math.square(x), -1, keepdims=True)
              + variance_epsilon
          )
          scale = dividend / divisor
  
          # Computes the dynamic normalization.
          return (
              (1 + scale) * x - 2 * (mean * mean_scale + mean_offset)
          ) * inv
  
file_path: neural-structured-learning/research/carls/dynamic_normalization.py
imports: import typing
  from research.carls import dynamic_embedding_config_pb2
  from research.carls import dynamic_memory_ops
  import tensorflow
label_desc: Use image node_id 1 for calling a global function with example usage: dynamic_normalization(x, mean, variance, prior_offset, mean_offset, prior_scale, mean_scale, variance_epsilon) and returns: unknown