class_docstr: A Worker object is created for each training thread.
class_docstr_tok: ["A","Worker","object","is","created","for","each","training","thread","."]
docstr: Create a new rollout by applying hindsight to an existing one, then process it.
docstr_tok: ["Create","a","new","rollout","by","applying","hindsight","to","an","existing","one",",","then","process","it","."]
code: def process_rollout_with_hindsight(
      self, states, actions, initial_rnn_states
  ):
      """Create a new rollout by applying hindsight to an existing one, then process it."""
      hindsight_states, rewards = self.env.apply_hindsight(
          states, actions, states[-1]
      )
      if self.ppo._state_is_list:
          state_arrays = [[] for i in range(len(self.env.state_shape))]
          for state in hindsight_states:
              for j in range(len(state)):
                  state_arrays[j].append(state[j])
      else:
          state_arrays = [hindsight_states]
      state_arrays += initial_rnn_states
      state_arrays = [np.stack(s) for s in state_arrays]
      inputs = state_arrays + [
          np.expand_dims(s, axis=0) for s in initial_rnn_states
      ]
      outputs = self._compute_model(inputs)
      values = outputs[self.ppo._value_index].numpy()
      values = np.append(values.flatten(), 0.0)
      probabilities = outputs[self.ppo._action_prob_index].numpy()
      actions = actions[: len(rewards)]
      action_prob = probabilities[np.arange(len(actions)), actions]
      return self.process_rollout(
          hindsight_states,
          actions,
          action_prob,
          np.array(rewards, dtype=np.float32),
          np.array(values, dtype=np.float32),
          initial_rnn_states,
      )
  
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 5 for calling the _Worker obj's underlying member method code with example usage: obj.process_rollout_with_hindsight(states, actions, initial_rnn_states) and returns: self