(self, trajectory, temperature=1.0)
return result
Chooses an action to play after a trajectory.
Chooses an action to play after a trajectory.
Chooses an action to play after a trajectory .
def policy(self, trajectory, temperature=1.0):
    """Chooses an action to play after a trajectory."""
    model = self._policy_collect_model
    if temperature != 1.0:  # When evaluating (t != 1.0), don't collect stats
      model = self._policy_eval_model
      model.state = self._policy_collect_model.state
    model.replicate_weights(self._policy_trainer.model_weights)
    tr_slice = trajectory.suffix(self._max_slice_length)
    trajectory_np = tr_slice.to_np(timestep_to_np=self.task.timestep_to_np)
    # Add batch dimension to trajectory_np and run the model.
    pred = model(trajectory_np.observation[None, ...])
    # Pick element 0 from the batch (the only one), last (current) timestep.
    pred = pred[0, -1, :]
    sample = self._policy_dist.sample(pred, temperature=temperature)
    result = (sample, pred)
    if fastmath.is_backend(fastmath.Backend.JAX):
      result = fastmath.nested_map(lambda x: x.copy(), result)
    return result
def policy ( self , trajectory , temperature = 1.0 ) : model = self . _policy_collect_model if temperature != 1.0 : # When evaluating (t != 1.0), don't collect stats model = self . _policy_eval_model model . state = self . _policy_collect_model . state model . replicate_weights ( self . _policy_trainer . model_weights ) tr_slice = trajectory . suffix ( self . _max_slice_length ) trajectory_np = tr_slice . to_np ( timestep_to_np = self . task . timestep_to_np ) # Add batch dimension to trajectory_np and run the model. pred = model ( trajectory_np . observation [ None , ... ] ) # Pick element 0 from the batch (the only one), last (current) timestep. pred = pred [ 0 , - 1 , : ] sample = self . _policy_dist . sample ( pred , temperature = temperature ) result = ( sample , pred ) if fastmath . is_backend ( fastmath . Backend . JAX ) : result = fastmath . nested_map ( lambda x : x . copy ( ) , result ) return result