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 setup_model(self):
      with SetVerbosity(self.verbose):
          assert issubclass(self.policy, ActorCriticPolicy), (
              "Error: the input policy for the ACKTR model must be "
              "an instance of common.policies.ActorCriticPolicy."
          )
  
          # Enable continuous actions tricks (normalized advantage)
          self.continuous_actions = isinstance(self.action_space, Box)
  
          self.graph = tf.Graph()
          with self.graph.as_default():
              self.set_random_seed(self.seed)
              self.sess = tf_util.make_session(
                  num_cpu=self.n_cpu_tf_sess, graph=self.graph
              )
  
              n_batch_step = None
              n_batch_train = None
              if issubclass(self.policy, RecurrentActorCriticPolicy):
                  n_batch_step = self.n_envs
                  n_batch_train = self.n_envs * self.n_steps
  
              step_model = self.policy(
                  self.sess,
                  self.observation_space,
                  self.action_space,
                  self.n_envs,
                  1,
                  n_batch_step,
                  reuse=False,
                  **self.policy_kwargs,
              )
  
              self.params = params = tf_util.get_trainable_vars("model")
  
              with tf.variable_scope(
                  "train_model",
                  reuse=True,
                  custom_getter=tf_util.outer_scope_getter(
                      "train_model"
                  ),
              ):
                  train_model = self.policy(
                      self.sess,
                      self.observation_space,
                      self.action_space,
                      self.n_envs,
                      self.n_steps,
                      n_batch_train,
                      reuse=True,
                      **self.policy_kwargs,
                  )
  
              with tf.variable_scope(
                  "loss",
                  reuse=False,
                  custom_getter=tf_util.outer_scope_getter("loss"),
              ):
                  self.advs_ph = advs_ph = tf.placeholder(
                      tf.float32, [None]
                  )
                  self.rewards_ph = rewards_ph = tf.placeholder(
                      tf.float32, [None]
                  )
                  self.learning_rate_ph = (
                      learning_rate_ph
                  ) = tf.placeholder(tf.float32, [])
                  self.actions_ph = (
                      train_model.pdtype.sample_placeholder([None])
                  )
  
                  neg_log_prob = train_model.proba_distribution.neglogp(
                      self.actions_ph
                  )
  
                  # training loss
                  pg_loss = tf.reduce_mean(advs_ph * neg_log_prob)
                  self.entropy = entropy = tf.reduce_mean(
                      train_model.proba_distribution.entropy()
                  )
                  self.pg_loss = pg_loss = (
                      pg_loss - self.ent_coef * entropy
                  )
                  self.vf_loss = vf_loss = mse(
                      tf.squeeze(train_model.value_fn), rewards_ph
                  )
                  train_loss = pg_loss + self.vf_coef * vf_loss
  
                  # Fisher loss construction
                  self.pg_fisher = pg_fisher_loss = -tf.reduce_mean(
                      neg_log_prob
                  )
                  sample_net = train_model.value_fn + tf.random_normal(
                      tf.shape(train_model.value_fn)
                  )
                  self.vf_fisher = (
                      vf_fisher_loss
                  ) = -self.vf_fisher_coef * tf.reduce_mean(
                      tf.pow(
                          train_model.value_fn
                          - tf.stop_gradient(sample_net),
                          2,
                      )
                  )
                  self.joint_fisher = pg_fisher_loss + vf_fisher_loss
  
                  tf.summary.scalar("entropy_loss", self.entropy)
                  tf.summary.scalar("policy_gradient_loss", pg_loss)
                  tf.summary.scalar(
                      "policy_gradient_fisher_loss", pg_fisher_loss
                  )
                  tf.summary.scalar("value_function_loss", self.vf_loss)
                  tf.summary.scalar(
                      "value_function_fisher_loss", vf_fisher_loss
                  )
                  tf.summary.scalar("loss", train_loss)
  
                  self.grads_check = tf.gradients(train_loss, params)
  
              with tf.variable_scope("input_info", reuse=False):
                  tf.summary.scalar(
                      "discounted_rewards",
                      tf.reduce_mean(self.rewards_ph),
                  )
                  tf.summary.scalar(
                      "learning_rate",
                      tf.reduce_mean(self.learning_rate_ph),
                  )
                  tf.summary.scalar(
                      "advantage", tf.reduce_mean(self.advs_ph)
                  )
  
                  if self.full_tensorboard_log:
                      tf.summary.histogram(
                          "discounted_rewards", self.rewards_ph
                      )
                      tf.summary.histogram(
                          "learning_rate", self.learning_rate_ph
                      )
                      tf.summary.histogram("advantage", self.advs_ph)
                      if tf_util.is_image(self.observation_space):
                          tf.summary.image(
                              "observation", train_model.obs_ph
                          )
                      else:
                          tf.summary.histogram(
                              "observation", train_model.obs_ph
                          )
  
              with tf.variable_scope(
                  "kfac",
                  reuse=False,
                  custom_getter=tf_util.outer_scope_getter("kfac"),
              ):
                  with tf.device("/gpu:0"):
                      self.optim = optim = kfac.KfacOptimizer(
                          learning_rate=learning_rate_ph,
                          clip_kl=self.kfac_clip,
                          momentum=0.9,
                          kfac_update=self.kfac_update,
                          epsilon=0.01,
                          stats_decay=0.99,
                          async_eigen_decomp=self.async_eigen_decomp,
                          cold_iter=10,
                          max_grad_norm=self.max_grad_norm,
                          verbose=self.verbose,
                      )
  
                      optim.compute_and_apply_stats(
                          self.joint_fisher, var_list=params
                      )
  
              self.train_model = train_model
              self.step_model = step_model
              self.step = step_model.step
              self.proba_step = step_model.proba_step
              self.value = step_model.value
              self.initial_state = step_model.initial_state
              tf.global_variables_initializer().run(session=self.sess)
  
              self.summary = tf.summary.merge_all()
  
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 4 for calling the ACKTR obj's underlying member method code with example usage: obj.setup_model() without return types