class_docstr: Encoding stage computing Kashin's representation from Hadamard transform.
  
  This class is inspired by the work "Uncertainty Principle and Vector
  Quantization" (https://arxiv.org/pdf/math/0611343.pdf), and the algorithm
  presented therein.
  
  The encoding stage builds upon the `HadamardEncodingStage` and uses the
  overcomplete base to compute representation with a smaller dynamic range of
  coefficients. One of the benefits is that it incurrs a smaller error in
  subsequent uniform quantization, smaller even compared to using the
  `HadamardEncodingStage`.
  
  The idea is that certain overcomplete bases, or tight frames, admit what is
  called "Kashin's representation" for every vector. Kashin's representation is
  such that the dynamic range of coefficients is as small as (asymptotically)
  possible. In this case, the overcomplete base consists of subsampled Hadamard
  matrix.
  
  The algorithm iteratively computes coefficients of input vector in rotated
  space (or projected space), projects onto a L-infinity ball, computes the
  residual error incurred by the projection, and repeats the same procedure with
  the residual and a smaller ball.
  
  For the meaning of the parameters `eta` and `delta`, see Section III.A in the
  referenced paper. The main pseudocode presented there is as follows:
    Input:
      projection, parameters eta, delta (should be derived from the projection).
      vector x of which representation needs to be computed.
    Initialize:
      kashin_coefficients <- [0, 0, ..., 0]
      M <- norm(x) / sqrt(delta * output_dim)  # [initial clipping level]
    Repeat num_iter times:
      b <- frame representation of x
      b <- clip b at level M
      kashin_coefficients <- kashin_coefficients + b
      x' <- recover from frame representation b
      x <- x - x'
      M <- M * eta
    Output:
      kashin_coefficients
  
  The actual implementation of the encoding works as follows:
  The shape of the input `x` to the `encode` method must be either `(dim)` or
  `(b, dim)`, where `dim` is the dimenion of the vector to which the transform
  is to be applied, and must be statically known. `b` represents an optional
  batch dimension, and does not need to be statically known.
  
  If the shape of the input is `(dim)`, it is first expanded to `(1, dim)`. The
  input of shape `(b, dim)` is then padded with zeros to dimension `(b, dim_2)`,
  where `dim_2` is the smallest power of 2 larger than or equal to `dim`. In the
  case of `dim / dim_2 > pad_extra_level_threshold`, an extra factor of 2 is
  added to `dim_2`. Otherwise, the algorithm does not have enough leeway to
  realize benefits over only applying the randomized Hadamard transform.
  
  The Kashin's representation is then computed for each of the `b` vectors of
  shape `dim_2`. The encoded value thus has shape `(b, dim_2)`.
docstr: Initializer for the `KashinHadamardEncodingStage`.
  
  Args:
    num_iters: An integer number of iterations to run to compute the
      representation. Cannot be a TensorFlow value.
    eta: A scalar parameter of the encoding algorithm. Determines the
      shrinkage of the clipping level in each iteration. Must be between 0 and
      1. Can be either a TensorFlow or a Python value.
    delta: A scalar parameter of the encoding algorithm. Determines the
      initial clipping level. Must be greater than 0. Can be either a
      TensorFlow or a Python value.
    last_iter_clip: A boolean, determining whether to apply clipping in last
      iteration of the encoding algorithm. If set to False, the encoded
      representation is always lossless. If set to True, the resulting
      representation can be lossy, although not necessarily. Cannot be a
      TensorFlow value.
    pad_extra_level_threshold: A scalar parameter determining the threshold,
      at which padding with zeros is to be expanded by an additional power of
      2. See class documentation for why this is needed. Cannot be a
      TensorFlow value.
  
  Raises:
    ValueError: The inputs do not satisfy the above constraints.
docstr_tok: ["Initializer","for","the","`","KashinHadamardEncodingStage","`",".","Args",":","num_iters",":","An","integer","number","of","iterations","to","run","to","compute","the","representation",".","Can","not","be","a","TensorFlow","value",".","eta",":","A","scalar","parameter","of","the","encoding","algorithm",".","Determines","the","shrinkage","of","the","clipping","level","in","each","iteration",".","Must","be","between","0","and","1",".","Can","be","either","a","TensorFlow","or","a","Python","value",".","delta",":","A","scalar","parameter","of","the","encoding","algorithm",".","Determines","the","initial","clipping","level",".","Must","be","greater","than","0",".","Can","be","either","a","TensorFlow","or","a","Python","value",".","last_iter_clip",":","A","boolean",",","determining","whether","to","apply","clipping","in","last","iteration","of","the","encoding","algorithm",".","If","set","to","False",",","the","encoded","representation","is","always","lossless",".","If","set","to","True",",","the","resulting","representation","can","be","lossy",",","although","not","necessarily",".","Can","not","be","a","TensorFlow","value",".","pad_extra_level_threshold",":","A","scalar","parameter","determining","the","threshold",",","at","which","padding","with","zeros","is","to","be","expanded","by","an","additional","power","of","2",".","See","class","documentation","for","why","this","is","needed",".","Can","not","be","a","TensorFlow","value",".","Raises",":","ValueError",":","The","inputs","do","not","satisfy","the","above","constraints","."]
code: def __init__(
      self,
      num_iters=3,
      eta=0.9,
      delta=1.0,
      last_iter_clip=False,
      pad_extra_level_threshold=0.85,
  ):
      """Initializer for the `KashinHadamardEncodingStage`.
  
      Args:
        num_iters: An integer number of iterations to run to compute the
          representation. Cannot be a TensorFlow value.
        eta: A scalar parameter of the encoding algorithm. Determines the
          shrinkage of the clipping level in each iteration. Must be between 0 and
          1. Can be either a TensorFlow or a Python value.
        delta: A scalar parameter of the encoding algorithm. Determines the
          initial clipping level. Must be greater than 0. Can be either a
          TensorFlow or a Python value.
        last_iter_clip: A boolean, determining whether to apply clipping in last
          iteration of the encoding algorithm. If set to False, the encoded
          representation is always lossless. If set to True, the resulting
          representation can be lossy, although not necessarily. Cannot be a
          TensorFlow value.
        pad_extra_level_threshold: A scalar parameter determining the threshold,
          at which padding with zeros is to be expanded by an additional power of
          2. See class documentation for why this is needed. Cannot be a
          TensorFlow value.
  
      Raises:
        ValueError: The inputs do not satisfy the above constraints.
      """
      if tf.is_tensor(num_iters):
          raise ValueError(
              "Parameter num_iters cannot be a TensorFlow value."
          )
      if not isinstance(num_iters, int) or num_iters <= 0:
          raise ValueError(
              "Number of iterations must be a positive integer."
              "num_iters provided: %s" % num_iters
          )
      self._num_iters = num_iters
  
      if not tf.is_tensor(eta) and not 0.0 < eta < 1.0:
          raise ValueError(
              "Parameter eta must be between 0 and 1. "
              "Provided eta: %s" % eta
          )
      self._eta = eta
  
      if not tf.is_tensor(delta) and delta <= 0.0:
          raise ValueError(
              "Parameter delta must be greater than 0. "
              "Provided delta: %s" % delta
          )
      self._delta = delta
  
      if tf.is_tensor(last_iter_clip):
          raise ValueError(
              "Parameter last_iter_clip cannot be a TensorFlow value."
          )
      if not isinstance(last_iter_clip, bool):
          raise ValueError("Parameter last_iter_clip must be a bool.")
      self._last_iter_clip = last_iter_clip
  
      if tf.is_tensor(pad_extra_level_threshold):
          raise ValueError(
              "Parameter pad_extra_level_threshold cannot be a TensorFlow value."
          )
      self._pad_extra_level_threshold = pad_extra_level_threshold
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import collections
  import numpy
  import tensorflow
  from tensorflow_model_optimization.python.core.internal.tensor_encoding.core import encoding_stage
  from tensorflow_model_optimization.python.core.internal.tensor_encoding.utils import tf_utils
label_desc: Use image node_id 1 to create a new KashinHadamardEncodingStage object from inherited base classes: encoding_stage with example: obj = KashinHadamardEncodingStage(num_iters, eta, delta, last_iter_clip, pad_extra_level_threshold)