Discretize continuous actions to tokens. action: np.ndarray, (n, 3), continuous actions in Cartesian or Spherical coordinates. return: np.ndarray, (n,), tokens.
(self, action: np.ndarray)
| 175 | self.yaw_bins = np.array(bin_policy["yaw_bins"]) |
| 176 | |
| 177 | def __call__(self, action: np.ndarray) -> List[str]: |
| 178 | """Discretize continuous actions to tokens. |
| 179 | action: np.ndarray, (n, 3), continuous actions in Cartesian or Spherical coordinates. |
| 180 | return: np.ndarray, (n,), tokens. |
| 181 | """ |
| 182 | roll, pitch, yaw = action[:, 0], action[:, 1], action[:, 2] |
| 183 | disc_roll = np.clip(np.digitize(roll, self.roll_bins) - 1, 0, self.num_roll_bins - 1) |
| 184 | disc_pitch = np.clip(np.digitize(pitch, self.pitch_bins) - 1, 0, self.num_pitch_bins - 1) |
| 185 | disc_yaw = np.clip(np.digitize(yaw, self.yaw_bins) - 1, 0, self.num_yaw_bins - 1) |
| 186 | |
| 187 | ids = disc_roll * self.NP + disc_pitch * self.num_yaw_bins + disc_yaw |
| 188 | return self.token_array[ids] |
| 189 | |
| 190 | def decode_token_ids_to_actions(self, action_token_id: Union[np.int64, np.ndarray]) -> np.ndarray: |
| 191 | """decode token ids to continuous actions. |
nothing calls this directly
no outgoing calls
no test coverage detected