class_docstr: A Worker object is created for each training thread.
class_docstr_tok: ["A","Worker","object","is","created","for","each","training","thread","."]
docstr: Construct the arrays needed for training.
docstr_tok: ["Construct","the","arrays","needed","for","training","."]
code: def process_rollout(
      self,
      states,
      actions,
      action_prob,
      rewards,
      values,
      initial_rnn_states,
  ):
      """Construct the arrays needed for training."""
  
      # Compute the discounted rewards and advantages.
  
      discounted_rewards = rewards.copy()
      discounted_rewards[-1] += values[-1]
      advantages = (
          rewards
          - values[:-1]
          + self.ppo.discount_factor * np.array(values[1:])
      )
      for j in range(len(rewards) - 1, 0, -1):
          discounted_rewards[j - 1] += (
              self.ppo.discount_factor * discounted_rewards[j]
          )
          advantages[j - 1] += (
              self.ppo.discount_factor
              * self.ppo.advantage_lambda
              * advantages[j]
          )
  
      # Convert the actions to one-hot.
  
      n_actions = self.env.n_actions
      actions_matrix = []
      for action in actions:
          a = np.zeros(n_actions, np.float32)
          a[action] = 1.0
          actions_matrix.append(a)
      actions_matrix = np.array(actions_matrix, dtype=np.float32)
  
      # Rearrange the states into the proper set of arrays.
  
      if self.ppo._state_is_list:
          state_arrays = [[] for i in range(len(self.env.state_shape))]
          for state in states:
              for j in range(len(state)):
                  state_arrays[j].append(state[j])
      else:
          state_arrays = [states]
  
      # Return the processed arrays.
  
      return (
          initial_rnn_states,
          state_arrays,
          discounted_rewards,
          actions_matrix,
          action_prob,
          advantages,
      )
  
imports: import copy
  import time
  from collections.abc import Sequence
  from multiprocessing.dummy import Pool
  import numpy
  import tensorflow
  from deepchem.models import KerasModel
  from deepchem.models.optimizers import Adam
label_desc: Use image node_id 4 for calling the _Worker obj's underlying member method code with example usage: obj.process_rollout(states, actions, action_prob, rewards, values, initial_rnn_states) and returns: initial_rnn_states,  state_arrays,  discounted_rewards,  actions_matrix,  action_prob,  advantages