class_docstr: A2C: Advantage Actor-Critic.
  
  A2C is a synchronous, deterministic variant of Asynchronous Advantage
      Actor Critic (A3C).
  
  See https://arxiv.org/abs/1708.05144
  
  Args:
      model (A2CModel): Model to train
      optimizer (chainer.Optimizer): optimizer used to train the model
      gamma (float): Discount factor [0,1]
      num_processes (int): The number of processes
      gpu (int): GPU device id if not None nor negative.
      update_steps (int): The number of update steps
      phi (callable): Feature extractor function
      pi_loss_coef (float): Weight coefficient for the loss of the policy
      v_loss_coef (float): Weight coefficient for the loss of the value
          function
      entropy_coeff (float): Weight coefficient for the loss of the entropy
      use_gae (bool): use generalized advantage estimation(GAE)
      tau (float): gae parameter
      average_actor_loss_decay (float): Decay rate of average actor loss.
          Used only to record statistics.
      average_entropy_decay (float): Decay rate of average entropy. Used only
          to record statistics.
      average_value_decay (float): Decay rate of average value. Used only
          to record statistics.
      act_deterministically (bool): If set true, choose most probable actions
          in act method.
      batch_states (callable): method which makes a batch of observations.
          default is `chainerrl.misc.batch_states.batch_states`
class_docstr_tok: ["A2C",":","Advantage","Actor-Critic",".","A2C","is","a","synchronous",",","deterministic","variant","of","Asynchronous","Advantage","Actor","Critic","(","A3C",")",".","See","https",":","\/\/arxiv.org\/abs\/1708.05144","Args",":","model","(","A2CModel",")",":","Model","to","train","optimizer","(","chainer.Optimizer",")",":","optimizer","used","to","train","the","model","gamma","(","float",")",":","Discount","factor","[","0,1","]","num_processes","(","int",")",":","The","number","of","processes","gpu","(","int",")",":","GPU","device","id","if","not","None","nor","negative",".","update_steps","(","int",")",":","The","number","of","update","steps","phi","(","callable",")",":","Feature","extractor","function","pi_loss_coef","(","float",")",":","Weight","coefficient","for","the","loss","of","the","policy","v_loss_coef","(","float",")",":","Weight","coefficient","for","the","loss","of","the","value","function","entropy_coeff","(","float",")",":","Weight","coefficient","for","the","loss","of","the","entropy","use_gae","(","bool",")",":","use","generalized","advantage","estimation","(","GAE",")","tau","(","float",")",":","gae","parameter","average_actor_loss_decay","(","float",")",":","Decay","rate","of","average","actor","loss",".","Used","only","to","record","statistics",".","average_entropy_decay","(","float",")",":","Decay","rate","of","average","entropy",".","Used","only","to","record","statistics",".","average_value_decay","(","float",")",":","Decay","rate","of","average","value",".","Used","only","to","record","statistics",".","act_deterministically","(","bool",")",":","If","set","true",",","choose","most","probable","actions","in","act","method",".","batch_states","(","callable",")",":","method","which","makes","a","batch","of","observations",".","default","is","`","chainerrl.misc.batch_states.batch_states","`"]
code: def update(self):
      with chainer.no_backprop_mode():
          _, next_value = self.model.pi_and_v(self.states[-1])
          next_value = next_value.array[:, 0]
  
      self._compute_returns(next_value)
      pout, values = self.model.pi_and_v(
          chainer.Variable(
              self.states[:-1].reshape([-1] + list(self.obs_shape))
          )
      )
  
      actions = chainer.Variable(
          self.actions.reshape([-1] + list(self.action_shape))
      )
      dist_entropy = F.mean(pout.entropy)
      action_log_probs = pout.log_prob(actions)
  
      values = values.reshape((self.update_steps, self.num_processes))
      action_log_probs = action_log_probs.reshape(
          (self.update_steps, self.num_processes)
      )
      advantages = self.returns[:-1] - values
      value_loss = F.mean(advantages * advantages)
      action_loss = -F.mean(advantages.array * action_log_probs)
  
      self.model.cleargrads()
  
      (
          value_loss * self.v_loss_coef
          + action_loss * self.pi_loss_coef
          - dist_entropy * self.entropy_coeff
      ).backward()
  
      self.optimizer.update()
      self.states[0] = self.states[-1]
  
      self.t_start = self.t
  
      # Update stats
      self.average_actor_loss += (1 - self.average_actor_loss_decay) * (
          float(action_loss.array) - self.average_actor_loss
      )
      self.average_value += (1 - self.average_value_decay) * (
          float(value_loss.array) - self.average_value
      )
      self.average_entropy += (1 - self.average_entropy_decay) * (
          float(dist_entropy.array) - self.average_entropy
      )
  
imports: from logging import getLogger
  import warnings
  import chainer
  from chainer import functions
  from chainerrl import agent
  from chainerrl.misc.batch_states import batch_states
  from chainerrl.recurrent import RecurrentChainMixin
label_desc: Use image node_id 4 for calling the A2C obj's underlying member method code with example usage: obj.update() without return types