Files
pytorch-soft-actor-critic/normalized_actions.py
T
2019-05-20 12:37:41 +05:30

20 lines
547 B
Python

import gym
class NormalizedActions(gym.ActionWrapper):
def action(self, action):
action = (action + 1) / 2 # [-1, 1] => [0, 1]
action *= (self.action_space.high - self.action_space.low)
action += self.action_space.low
return action
def _reverse_action(self, action):
action -= self.action_space.low
action /= (self.action_space.high - self.action_space.low)
action = action * 2 - 1
return action
def _max_episode_steps(self):
return self._max_epsidoe_steps