Exemplo n.º 1
0
 def batch_tensor(self, name):
     """ A buffer of a given value in a 'flat' (minibatch-indexed) format """
     if name in self.transition_tensors:
         return tensor_util.merge_first_two_dims(
             self.transition_tensors[name])
     else:
         return self.rollout_tensors[name]
Exemplo n.º 2
0
 def to_transitions(self) -> 'Transitions':
     """ Convert given rollout to Transitions """
     # No need to propagate 'rollout_tensors' as they won't mean anything
     return Transitions(
         size=self.num_steps * self.num_envs,
         environment_information=
             [ei for l in self.environment_information for ei in l]
             if self.environment_information is not None else None,
         transition_tensors={
             name: tensor_util.merge_first_two_dims(t) for name, t in self.transition_tensors.items()
         },
         extra_data=self.extra_data
     )
Exemplo n.º 3
0
 def to_transitions(self) -> 'Transitions':
     """ Convert given rollout to Transitions """
     # No need to propagate 'rollout_tensors' as they won't mean anything
     transition_tensor = {}
     for name, t in self.transition_tensors.items():
         if isinstance(t, dict):
             transition_tensor[name] = {
                 k: tensor_util.merge_first_two_dims(v)
                 for k, v in t.items()
             }
         else:
             transition_tensor[name] = tensor_util.merge_first_two_dims(t)
     return Transitions(
         size=self.num_steps * self.num_envs,
         environment_information=[
             ei for l in self.environment_information for ei in l
         ],
         transition_tensors=transition_tensor,
         # {
         #     name: tensor_util.merge_first_two_dims(t) for name, t in self.transition_tensors.items()
         # },
         extra_data=self.extra_data)
Exemplo n.º 4
0
 def flatten_tensor(self, tensor):
     """ Merge first two dims of a tensor """
     return tensor_util.merge_first_two_dims(tensor)