class_docstr: Proximal Policy Optimization
  
  See https://arxiv.org/abs/1707.06347
  
  Args:
      model (A3CModel): Model to train.  Recurrent models are not supported.
          state s  |->  (pi(s, _), v(s))
      optimizer (chainer.Optimizer): Optimizer used to train the model
      gpu (int): GPU device id if not None nor negative
      gamma (float): Discount factor [0, 1]
      lambd (float): Lambda-return factor [0, 1]
      phi (callable): Feature extractor function
      value_func_coef (float): Weight coefficient for loss of
          value function (0, inf)
      entropy_coef (float): Weight coefficient for entropy bonus [0, inf)
      update_interval (int): Model update interval in step
      minibatch_size (int): Minibatch size
      epochs (int): Training epochs in an update
      clip_eps (float): Epsilon for pessimistic clipping of likelihood ratio
          to update policy
      clip_eps_vf (float): Epsilon for pessimistic clipping of value
          to update value function. If it is ``None``, value function is not
          clipped on updates.
      standardize_advantages (bool): Use standardized advantages on updates
      recurrent (bool): If set to True, `model` is assumed to implement
          `chainerrl.links.StatelessRecurrent` and update in a recurrent
          manner.
      max_recurrent_sequence_len (int): Maximum length of consecutive
          sequences of transitions in a minibatch for updatig the model.
          This value is used only when `recurrent` is True. A smaller value
          will encourage a minibatch to contain more and shorter sequences.
      act_deterministically (bool): If set to True, choose most probable
          actions in the act method instead of sampling from distributions.
      value_stats_window (int): Window size used to compute statistics
          of value predictions.
      entropy_stats_window (int): Window size used to compute statistics
          of entropy of action distributions.
      value_loss_stats_window (int): Window size used to compute statistics
          of loss values regarding the value function.
      policy_loss_stats_window (int): Window size used to compute statistics
          of loss values regarding the policy.
  
  Statistics:
      average_value: Average of value predictions on non-terminal states.
          It's updated on (batch_)act_and_train.
      average_entropy: Average of entropy of action distributions on
          non-terminal states. It's updated on (batch_)act_and_train.
      average_value_loss: Average of losses regarding the value function.
          It's updated after the model is updated.
      average_policy_loss: Average of losses regarding the policy.
          It's updated after the model is updated.
      n_updates: Number of model updates so far.
      explained_variance: Explained variance computed from the last batch.
class_docstr_tok: ["Proximal","Policy","Optimization","See","https",":","\/\/arxiv.org\/abs\/1707.06347","Args",":","model","(","A3CModel",")",":","Model","to","train",".","Recurrent","models","are","not","supported",".","state","s","|-",">","(","pi","(","s",",","_",")",",","v","(","s",")",")","optimizer","(","chainer.Optimizer",")",":","Optimizer","used","to","train","the","model","gpu","(","int",")",":","GPU","device","id","if","not","None","nor","negative","gamma","(","float",")",":","Discount","factor","[","0",",","1","]","lambd","(","float",")",":","Lambda-return","factor","[","0",",","1","]","phi","(","callable",")",":","Feature","extractor","function","value_func_coef","(","float",")",":","Weight","coefficient","for","loss","of","value","function","(","0",",","inf",")","entropy_coef","(","float",")",":","Weight","coefficient","for","entropy","bonus","[","0",",","inf",")","update_interval","(","int",")",":","Model","update","interval","in","step","minibatch_size","(","int",")",":","Minibatch","size","epochs","(","int",")",":","Training","epochs","in","an","update","clip_eps","(","float",")",":","Epsilon","for","pessimistic","clipping","of","likelihood","ratio","to","update","policy","clip_eps_vf","(","float",")",":","Epsilon","for","pessimistic","clipping","of","value","to","update","value","function",".","If","it","is","``","None","``",",","value","function","is","not","clipped","on","updates",".","standardize_advantages","(","bool",")",":","Use","standardized","advantages","on","updates","recurrent","(","bool",")",":","If","set","to","True",",","`","model","`","is","assumed","to","implement","`","chainerrl.links.StatelessRecurrent","`","and","update","in","a","recurrent","manner",".","max_recurrent_sequence_len","(","int",")",":","Maximum","length","of","consecutive","sequences","of","transitions","in","a","minibatch","for","updatig","the","model",".","This","value","is","used","only","when","`","recurrent","`","is","True",".","A","smaller","value","will","encourage","a","minibatch","to","contain","more","and","shorter","sequences",".","act_deterministically","(","bool",")",":","If","set","to","True",",","choose","most","probable","actions","in","the","act","method","instead","of","sampling","from","distributions",".","value_stats_window","(","int",")",":","Window","size","used","to","compute","statistics","of","value","predictions",".","entropy_stats_window","(","int",")",":","Window","size","used","to","compute","statistics","of","entropy","of","action","distributions",".","value_loss_stats_window","(","int",")",":","Window","size","used","to","compute","statistics","of","loss","values","regarding","the","value","function",".","policy_loss_stats_window","(","int",")",":","Window","size","used","to","compute","statistics","of","loss","values","regarding","the","policy",".","Statistics",":","average_value",":","Average","of","value","predictions","on","non-terminal","states",".","It","'s","updated","on","(","batch_",")","act_and_train",".","average_entropy",":","Average","of","entropy","of","action","distributions","on","non-terminal","states",".","It","'s","updated","on","(","batch_",")","act_and_train",".","average_value_loss",":","Average","of","losses","regarding","the","value","function",".","It","'s","updated","after","the","model","is","updated",".","average_policy_loss",":","Average","of","losses","regarding","the","policy",".","It","'s","updated","after","the","model","is","updated",".","n_updates",":","Number","of","model","updates","so","far",".","explained_variance",":","Explained","variance","computed","from","the","last","batch","."]
code: def _update_if_dataset_is_ready(self):
      dataset_size = (
          sum(len(episode) for episode in self.memory)
          + len(self.last_episode)
          + (
              0
              if self.batch_last_episode is None
              else sum(
                  len(episode) for episode in self.batch_last_episode
              )
          )
      )
      if dataset_size >= self.update_interval:
          self._flush_last_episode()
          if self.recurrent:
              dataset = _make_dataset_recurrent(
                  episodes=self.memory,
                  model=self.model,
                  phi=self.phi,
                  batch_states=self.batch_states,
                  obs_normalizer=self.obs_normalizer,
                  gamma=self.gamma,
                  lambd=self.lambd,
                  max_recurrent_sequence_len=self.max_recurrent_sequence_len,
              )
              self._update_recurrent(dataset)
          else:
              dataset = _make_dataset(
                  episodes=self.memory,
                  model=self.model,
                  phi=self.phi,
                  batch_states=self.batch_states,
                  obs_normalizer=self.obs_normalizer,
                  gamma=self.gamma,
                  lambd=self.lambd,
              )
              assert len(dataset) == dataset_size
              self._update(dataset)
          self.explained_variance = _compute_explained_variance(
              list(itertools.chain.from_iterable(self.memory))
          )
          self.memory = []
  
imports: import collections
  import itertools
  import random
  import chainer
  from chainer import cuda
  import chainer.functions
  import numpy
  from chainerrl import agent
  from chainerrl.misc.batch_states import batch_states
label_desc: Use image node_id 3 for calling the PPO obj's underlying member method code with example usage: obj._update_if_dataset_is_ready() without return types