| 180 | return mu, sigma |
| 181 | |
| 182 | def scale_action(self, action: th.Tensor, eps=1e-7) -> th.Tensor: |
| 183 | # input action \in [a_low, a_high] |
| 184 | # output action \in [d_low+eps, d_high-eps] |
| 185 | d_low, d_high = self.action_dist.low, self.action_dist.high # scalar |
| 186 | |
| 187 | if d_low is not None and d_high is not None: |
| 188 | a_low = th.as_tensor(self.action_space.low.astype(np.float32)).to(action.device) |
| 189 | a_high = th.as_tensor(self.action_space.high.astype(np.float32)).to(action.device) |
| 190 | action = (action-a_low)/(a_high-a_low) * (d_high-d_low) + d_low |
| 191 | action = th.clamp(action, d_low+eps, d_high-eps) |
| 192 | return action |
| 193 | |
| 194 | def unscale_action(self, action: np.ndarray, eps=0.0) -> np.ndarray: |
| 195 | # input action \in [d_low, d_high] |