class_docstr: Actor-Critic Policy Gradient.
  
  See https://arxiv.org/pdf/1602.01783.pdf for a description of algorithm.
docstr: Process accumulated trajectory to generate training data.
  
  Args:
      keep_last (bool): last state without action and reward will be kept
          if True.
docstr_tok: ["Process","accumulated","trajectory","to","generate","training","data",".","Args",":","keep_last","(","bool",")",":","last","state","without","action","and","reward","will","be","kept","if","True","."]
code: def _process_accumulated_trajectory(self, keep_last):
      """Process accumulated trajectory to generate training data.
  
      Args:
          keep_last (bool): last state without action and reward will be kept
              if True.
      """
      if not self._trajectory_states:
          return
  
      # If trajectory hasn't terminated, we have _trajectory_states
      # and sometimes _trajectory_actions having one more item than
      # _trajectory_rewards. Same length is expected if called from
      # start() or end(), where the trajectory has terminiated.
      if len(self._trajectory_states) == len(self._trajectory_rewards):
          bootstrap_r = 0
      else:
          # Bootstrap from last state
          bootstrap_r = np.asscalar(
              self._evaluate_model(
                  self._value_network, self._trajectory_states[-1]
              )
          )
          last_state = self._trajectory_states.pop()
          if len(self._trajectory_actions) != len(
              self._trajectory_rewards
          ):
              # This will only happen when agent calls start() to begin
              # a new episode without calling end() before to terminate the
              # prevous episode. The last action thus can be discarded.
              self._trajectory_actions.pop()
  
      if len(self._trajectory_states) != len(
          self._trajectory_rewards
      ) or len(self._trajectory_actions) != len(
          self._trajectory_rewards
      ):
          raise RuntimeError(
              "Can't pair (state, action, reward). "
              "state/action can only be one more step ahead "
              "of rewrad in trajectory."
          )
  
      for transition in zip(
          self._trajectory_states,
          self._trajectory_actions,
          self._discount_rewards(bootstrap_r),
      ):
          self._input_buffer.append(transition[0])
          self._value_network_output_buffer.append([transition[2]])
          # TODO: consider using cntk.ops.one_hot instead of _index_to_vector
          self._policy_network_output_buffer.append(
              self._index_to_vector(transition[1], self._num_actions)
          )
          self._policy_network_weight_buffer.append(
              [
                  transition[2]
                  - self._evaluate_model(
                      self._value_network, transition[0]
                  )
              ]
          )
  
      # Clear the trajectory history.
      self._trajectory_states = []
      self._trajectory_actions = []
      self._trajectory_rewards = []
      if keep_last:
          self._trajectory_states.append(last_state)
  
imports: import cntk
  import numpy
  import ast
  from .agent import AgentBaseClass
  from .shared.cntk_utils import negative_of_entropy_with_softmax
  from .shared.models import Models
  from .shared.policy_gradient_parameters import PolicyGradientParameters
label_desc: Use image node_id 12 for calling the ActorCritic obj's underlying member method code with example usage: obj._process_accumulated_trajectory(keep_last) without return types