class_docstr: The ACKTR (Actor Critic using Kronecker-Factored Trust Region) model class, https://arxiv.org/abs/1708.05144
  
  :param policy: (ActorCriticPolicy or str) The policy model to use (MlpPolicy, CnnPolicy, CnnLstmPolicy, ...)
  :param env: (Gym environment or str) The environment to learn from (if registered in Gym, can be str)
  :param gamma: (float) Discount factor
  :param nprocs: (int) The number of threads for TensorFlow operations
  
      .. deprecated:: 2.9.0
          Use `n_cpu_tf_sess` instead.
  
  :param n_steps: (int) The number of steps to run for each environment
  :param ent_coef: (float) The weight for the entropy loss
  :param vf_coef: (float) The weight for the loss on the value function
  :param vf_fisher_coef: (float) The weight for the fisher loss on the value function
  :param learning_rate: (float) The initial learning rate for the RMS prop optimizer
  :param max_grad_norm: (float) The clipping value for the maximum gradient
  :param kfac_clip: (float) gradient clipping for Kullback-Leibler
  :param lr_schedule: (str) The type of scheduler for the learning rate update ('linear', 'constant',
                      'double_linear_con', 'middle_drop' or 'double_middle_drop')
  :param verbose: (int) the verbosity level: 0 none, 1 training information, 2 tensorflow debug
  :param tensorboard_log: (str) the log location for tensorboard (if None, no logging)
  :param _init_setup_model: (bool) Whether or not to build the network at the creation of the instance
  :param async_eigen_decomp: (bool) Use async eigen decomposition
  :param kfac_update: (int) update kfac after kfac_update steps
  :param policy_kwargs: (dict) additional arguments to be passed to the policy on creation
  :param gae_lambda: (float) Factor for trade-off of bias vs variance for Generalized Advantage Estimator
      If None (default), then the classic advantage will be used instead of GAE
  :param full_tensorboard_log: (bool) enable additional logging when using tensorboard
      WARNING: this logging can take a lot of space quickly
  :param seed: (int) Seed for the pseudo-random generators (python, numpy, tensorflow).
      If None (default), use random seed. Note that if you want completely deterministic
      results, you must set `n_cpu_tf_sess` to 1.
  :param n_cpu_tf_sess: (int) The number of threads for TensorFlow operations
      If None, the number of cpu of the current machine will be used.
class_docstr_tok: ["The","ACKTR","(","Actor","Critic","using","Kronecker-Factored","Trust","Region",")","model","class",",","https",":","\/\/arxiv.org\/abs\/1708.05144",":","param","policy",":","(","ActorCriticPolicy","or","str",")","The","policy","model","to","use","(","MlpPolicy",",","CnnPolicy",",","CnnLstmPolicy",",","...",")",":","param","env",":","(","Gym","environment","or","str",")","The","environment","to","learn","from","(","if","registered","in","Gym",",","can","be","str",")",":","param","gamma",":","(","float",")","Discount","factor",":","param","nprocs",":","(","int",")","The","number","of","threads","for","TensorFlow","operations","..","deprecated",":",":","2.9.0","Use","`","n_cpu_tf_sess","`","instead",".",":","param","n_steps",":","(","int",")","The","number","of","steps","to","run","for","each","environment",":","param","ent_coef",":","(","float",")","The","weight","for","the","entropy","loss",":","param","vf_coef",":","(","float",")","The","weight","for","the","loss","on","the","value","function",":","param","vf_fisher_coef",":","(","float",")","The","weight","for","the","fisher","loss","on","the","value","function",":","param","learning_rate",":","(","float",")","The","initial","learning","rate","for","the","RMS","prop","optimizer",":","param","max_grad_norm",":","(","float",")","The","clipping","value","for","the","maximum","gradient",":","param","kfac_clip",":","(","float",")","gradient","clipping","for","Kullback-Leibler",":","param","lr_schedule",":","(","str",")","The","type","of","scheduler","for","the","learning","rate","update","(","'linear","'",",","'constant","'",",","'double_linear_con","'",",","'middle_drop","'","or","'double_middle_drop","'",")",":","param","verbose",":","(","int",")","the","verbosity","level",":","0","none",",","1","training","information",",","2","tensorflow","debug",":","param","tensorboard_log",":","(","str",")","the","log","location","for","tensorboard","(","if","None",",","no","logging",")",":","param","_init_setup_model",":","(","bool",")","Whether","or","not","to","build","the","network","at","the","creation","of","the","instance",":","param","async_eigen_decomp",":","(","bool",")","Use","async","eigen","decomposition",":","param","kfac_update",":","(","int",")","update","kfac","after","kfac_update","steps",":","param","policy_kwargs",":","(","dict",")","additional","arguments","to","be","passed","to","the","policy","on","creation",":","param","gae_lambda",":","(","float",")","Factor","for","trade-off","of","bias","vs","variance","for","Generalized","Advantage","Estimator","If","None","(","default",")",",","then","the","classic","advantage","will","be","used","instead","of","GAE",":","param","full_tensorboard_log",":","(","bool",")","enable","additional","logging","when","using","tensorboard","WARNING",":","this","logging","can","take","a","lot","of","space","quickly",":","param","seed",":","(","int",")","Seed","for","the","pseudo-random","generators","(","python",",","numpy",",","tensorflow",")",".","If","None","(","default",")",",","use","random","seed",".","Note","that","if","you","want","completely","deterministic","results",",","you","must","set","`","n_cpu_tf_sess","`","to","1.",":","param","n_cpu_tf_sess",":","(","int",")","The","number","of","threads","for","TensorFlow","operations","If","None",",","the","number","of","cpu","of","the","current","machine","will","be","used","."]
code: def learn(
      self,
      total_timesteps,
      callback=None,
      log_interval=100,
      tb_log_name="ACKTR",
      reset_num_timesteps=True,
  ):
      new_tb_log = self._init_num_timesteps(reset_num_timesteps)
      callback = self._init_callback(callback)
  
      with SetVerbosity(self.verbose), TensorboardWriter(
          self.graph, self.tensorboard_log, tb_log_name, new_tb_log
      ) as writer:
          self._setup_learn()
          self.n_batch = self.n_envs * self.n_steps
  
          self.learning_rate_schedule = Scheduler(
              initial_value=self.learning_rate,
              n_values=total_timesteps,
              schedule=self.lr_schedule,
          )
  
          # FIFO queue of the q_runner thread is closed at the end of the learn function.
          # As a result, it needs to be redefinied at every call
          with self.graph.as_default():
              with tf.variable_scope(
                  "kfac_apply",
                  reuse=self.trained,
                  custom_getter=tf_util.outer_scope_getter(
                      "kfac_apply"
                  ),
              ):
                  # Some of the variables are not in a scope when they are create
                  # so we make a note of any previously uninitialized variables
                  tf_vars = tf.global_variables()
                  is_uninitialized = self.sess.run(
                      [
                          tf.is_variable_initialized(var)
                          for var in tf_vars
                      ]
                  )
                  old_uninitialized_vars = [
                      v
                      for (v, f) in zip(tf_vars, is_uninitialized)
                      if not f
                  ]
  
                  (
                      self.train_op,
                      self.q_runner,
                  ) = self.optim.apply_gradients(
                      list(zip(self.grads_check, self.params))
                  )
  
                  # then we check for new uninitialized variables and initialize them
                  tf_vars = tf.global_variables()
                  is_uninitialized = self.sess.run(
                      [
                          tf.is_variable_initialized(var)
                          for var in tf_vars
                      ]
                  )
                  new_uninitialized_vars = [
                      v
                      for (v, f) in zip(tf_vars, is_uninitialized)
                      if not f and v not in old_uninitialized_vars
                  ]
  
                  if len(new_uninitialized_vars) != 0:
                      self.sess.run(
                          tf.variables_initializer(
                              new_uninitialized_vars
                          )
                      )
  
          self.trained = True
  
          t_start = time.time()
          coord = tf.train.Coordinator()
          if self.q_runner is not None:
              enqueue_threads = self.q_runner.create_threads(
                  self.sess, coord=coord, start=True
              )
          else:
              enqueue_threads = []
  
          callback.on_training_start(locals(), globals())
  
          for update in range(1, total_timesteps // self.n_batch + 1):
              callback.on_rollout_start()
  
              # pytype:disable=bad-unpacking
              # true_reward is the reward without discount
              if isinstance(self.runner, PPO2Runner):
                  # We are using GAE
                  rollout = self.runner.run(callback)
                  (
                      obs,
                      returns,
                      masks,
                      actions,
                      values,
                      _,
                      states,
                      ep_infos,
                      true_reward,
                  ) = rollout
              else:
                  rollout = self.runner.run(callback)
                  (
                      obs,
                      states,
                      returns,
                      masks,
                      actions,
                      values,
                      ep_infos,
                      true_reward,
                  ) = rollout
              # pytype:enable=bad-unpacking
              callback.update_locals(locals())
              callback.on_rollout_end()
  
              # Early stopping due to the callback
              if not self.runner.continue_training:
                  break
  
              self.ep_info_buf.extend(ep_infos)
              (
                  policy_loss,
                  value_loss,
                  policy_entropy,
              ) = self._train_step(
                  obs,
                  states,
                  returns,
                  masks,
                  actions,
                  values,
                  self.num_timesteps // (self.n_batch + 1),
                  writer,
              )
              n_seconds = time.time() - t_start
              fps = int((update * self.n_batch) / n_seconds)
  
              if writer is not None:
                  total_episode_reward_logger(
                      self.episode_reward,
                      true_reward.reshape((self.n_envs, self.n_steps)),
                      masks.reshape((self.n_envs, self.n_steps)),
                      writer,
                      self.num_timesteps,
                  )
  
              if self.verbose >= 1 and (
                  update % log_interval == 0 or update == 1
              ):
                  explained_var = explained_variance(values, returns)
                  logger.record_tabular("nupdates", update)
                  logger.record_tabular(
                      "total_timesteps", self.num_timesteps
                  )
                  logger.record_tabular("fps", fps)
                  logger.record_tabular(
                      "policy_entropy", float(policy_entropy)
                  )
                  logger.record_tabular(
                      "policy_loss", float(policy_loss)
                  )
                  logger.record_tabular("value_loss", float(value_loss))
                  logger.record_tabular(
                      "explained_variance", float(explained_var)
                  )
                  if (
                      len(self.ep_info_buf) > 0
                      and len(self.ep_info_buf[0]) > 0
                  ):
                      logger.logkv(
                          "ep_reward_mean",
                          safe_mean(
                              [
                                  ep_info["r"]
                                  for ep_info in self.ep_info_buf
                              ]
                          ),
                      )
                      logger.logkv(
                          "ep_len_mean",
                          safe_mean(
                              [
                                  ep_info["l"]
                                  for ep_info in self.ep_info_buf
                              ]
                          ),
                      )
                  logger.dump_tabular()
  
          coord.request_stop()
          coord.join(enqueue_threads)
  
      callback.on_training_end()
      return self
  
imports: import time
  import warnings
  import tensorflow
  from gym.spaces import Box, Discrete
  from stable_baselines import logger
  from stable_baselines.a2c.a2c import A2CRunner
  from stable_baselines.ppo2.ppo2 import Runner
  from stable_baselines.common.tf_util import mse, total_episode_reward_logger
  from stable_baselines.acktr import kfac
  from stable_baselines.common.schedules import Scheduler
  from stable_baselines.common import explained_variance, ActorCriticRLModel, tf_util, SetVerbosity, TensorboardWriter
  from stable_baselines.common.policies import ActorCriticPolicy, RecurrentActorCriticPolicy
  from stable_baselines.common.math_util import safe_mean
label_desc: Use image node_id 6 for calling the ACKTR obj's underlying member method code with example usage: obj.learn(total_timesteps, callback, log_interval, tb_log_name, reset_num_timesteps) and returns: self