docstr: Kfac Optimizer for ACKTR models
  link: https://arxiv.org/pdf/1708.05144.pdf
  
  :param learning_rate: (float) The learning rate
  :param momentum: (float) The momentum value for the TensorFlow momentum optimizer
  :param clip_kl: (float) gradient clipping for Kullback-Leibler
  :param kfac_update: (int) update kfac after kfac_update steps
  :param stats_accum_iter: (int) how may steps to accumulate stats
  :param full_stats_init: (bool) whether or not to fully initialize stats
  :param cold_iter: (int) Cold start learning rate for how many steps
  :param cold_lr: (float) Cold start learning rate
  :param async_eigen_decomp: (bool) Use async eigen decomposition
  :param async_stats: (bool) Asynchronous stats update
  :param epsilon: (float) epsilon value for small numbers
  :param stats_decay: (float) the stats decay rate
  :param blockdiag_bias: (bool)
  :param channel_fac: (bool) factorization along the channels
  :param factored_damping: (bool) use factored damping
  :param approx_t2: (bool) approximate T2 act and grad fisher
  :param use_float64: (bool) use 64-bit float
  :param weight_decay_dict: (dict) custom weight decay coeff for a given gradient
  :param max_grad_norm: (float) The maximum value for the gradient clipping
  :param verbose: (int) verbosity level
docstr_tok: ["Kfac","Optimizer","for","ACKTR","models","link",":","https",":","\/\/arxiv.org\/pdf\/1708.05144.pdf",":","param","learning_rate",":","(","float",")","The","learning","rate",":","param","momentum",":","(","float",")","The","momentum","value","for","the","TensorFlow","momentum","optimizer",":","param","clip_kl",":","(","float",")","gradient","clipping","for","Kullback-Leibler",":","param","kfac_update",":","(","int",")","update","kfac","after","kfac_update","steps",":","param","stats_accum_iter",":","(","int",")","how","may","steps","to","accumulate","stats",":","param","full_stats_init",":","(","bool",")","whether","or","not","to","fully","initialize","stats",":","param","cold_iter",":","(","int",")","Cold","start","learning","rate","for","how","many","steps",":","param","cold_lr",":","(","float",")","Cold","start","learning","rate",":","param","async_eigen_decomp",":","(","bool",")","Use","async","eigen","decomposition",":","param","async_stats",":","(","bool",")","Asynchronous","stats","update",":","param","epsilon",":","(","float",")","epsilon","value","for","small","numbers",":","param","stats_decay",":","(","float",")","the","stats","decay","rate",":","param","blockdiag_bias",":","(","bool",")",":","param","channel_fac",":","(","bool",")","factorization","along","the","channels",":","param","factored_damping",":","(","bool",")","use","factored","damping",":","param","approx_t2",":","(","bool",")","approximate","T2","act","and","grad","fisher",":","param","use_float64",":","(","bool",")","use","64-bit","float",":","param","weight_decay_dict",":","(","dict",")","custom","weight","decay","coeff","for","a","given","gradient",":","param","max_grad_norm",":","(","float",")","The","maximum","value","for","the","gradient","clipping",":","param","verbose",":","(","int",")","verbosity","level"]
code: def __init__(
      self,
      learning_rate=0.01,
      momentum=0.9,
      clip_kl=0.01,
      kfac_update=2,
      stats_accum_iter=60,
      full_stats_init=False,
      cold_iter=100,
      cold_lr=None,
      async_eigen_decomp=False,
      async_stats=False,
      epsilon=1e-2,
      stats_decay=0.95,
      blockdiag_bias=False,
      channel_fac=False,
      factored_damping=False,
      approx_t2=False,
      use_float64=False,
      weight_decay_dict=None,
      max_grad_norm=0.5,
      verbose=1,
  ):
      """
      Kfac Optimizer for ACKTR models
      link: https://arxiv.org/pdf/1708.05144.pdf
  
      :param learning_rate: (float) The learning rate
      :param momentum: (float) The momentum value for the TensorFlow momentum optimizer
      :param clip_kl: (float) gradient clipping for Kullback-Leibler
      :param kfac_update: (int) update kfac after kfac_update steps
      :param stats_accum_iter: (int) how may steps to accumulate stats
      :param full_stats_init: (bool) whether or not to fully initialize stats
      :param cold_iter: (int) Cold start learning rate for how many steps
      :param cold_lr: (float) Cold start learning rate
      :param async_eigen_decomp: (bool) Use async eigen decomposition
      :param async_stats: (bool) Asynchronous stats update
      :param epsilon: (float) epsilon value for small numbers
      :param stats_decay: (float) the stats decay rate
      :param blockdiag_bias: (bool)
      :param channel_fac: (bool) factorization along the channels
      :param factored_damping: (bool) use factored damping
      :param approx_t2: (bool) approximate T2 act and grad fisher
      :param use_float64: (bool) use 64-bit float
      :param weight_decay_dict: (dict) custom weight decay coeff for a given gradient
      :param max_grad_norm: (float) The maximum value for the gradient clipping
      :param verbose: (int) verbosity level
      """
      self.max_grad_norm = max_grad_norm
      self._lr = learning_rate
      self._momentum = momentum
      self._clip_kl = clip_kl
      self._channel_fac = channel_fac
      self._kfac_update = kfac_update
      self._async_eigen_decomp = async_eigen_decomp
      self._async_stats = async_stats
      self._epsilon = epsilon
      self._stats_decay = stats_decay
      self._blockdiag_bias = blockdiag_bias
      self._approx_t2 = approx_t2
      self._use_float64 = use_float64
      self._factored_damping = factored_damping
      self._cold_iter = cold_iter
      self.verbose = verbose
      if cold_lr is None:
          # good heuristics
          self._cold_lr = self._lr  # * 3.
      else:
          self._cold_lr = cold_lr
      self._stats_accum_iter = stats_accum_iter
      if weight_decay_dict is None:
          weight_decay_dict = {}
      self._weight_decay_dict = weight_decay_dict
      self._diag_init_coeff = 0.0
      self._full_stats_init = full_stats_init
      if not self._full_stats_init:
          self._stats_accum_iter = self._cold_iter
  
      self.sgd_step = tf.Variable(
          0, name="KFAC/sgd_step", trainable=False
      )
      self.global_step = tf.Variable(
          0, name="KFAC/global_step", trainable=False
      )
      self.cold_step = tf.Variable(
          0, name="KFAC/cold_step", trainable=False
      )
      self.factor_step = tf.Variable(
          0, name="KFAC/factor_step", trainable=False
      )
      self.stats_step = tf.Variable(
          0, name="KFAC/stats_step", trainable=False
      )
      self.v_f_v = tf.Variable(0.0, name="KFAC/vFv", trainable=False)
  
      self.factors = {}
      self.param_vars = []
      self.stats = {}
      self.stats_eigen = {}
  
      self._update_stats_op = None
  
imports: import re
  from functools import reduce
  import tensorflow
  import numpy
  from stable_baselines.acktr.kfac_utils import detect_min_val, factor_reshape, gmatmul
label_desc: Use image node_id 1 to create a new KfacOptimizer object  with example: obj = KfacOptimizer(learning_rate, momentum, clip_kl, kfac_update, stats_accum_iter, full_stats_init, cold_iter, cold_lr, async_eigen_decomp, async_stats, epsilon, stats_decay, blockdiag_bias, channel_fac, factored_damping, approx_t2, use_float64, weight_decay_dict, max_grad_norm, verbose)