DDPG Pendulum

This commit is contained in:
Shangtong Zhang
2017-08-01 10:52:14 -06:00
parent 1be3b44999
commit 5116733f22
5 changed files with 69 additions and 97 deletions
+4 -20
View File
@@ -80,22 +80,6 @@ class Pendulum(BasicTask):
name = 'Pendulum-v0'
success_threshold = -10
def __init__(self):
BasicTask.__init__(self)
self.env = gym.make(self.name)
self.env._max_episode_steps = sys.maxsize
self.action_dim = self.env.action_space.shape[0]
self.state_dim = self.env.observation_space.shape[0]
def step(self, action):
action = np.clip(action, -2, 2)
next_state, reward, done, info = self.env.step(action)
return next_state, reward, done, info
class MountainCarContinuous(BasicTask):
name = 'MountainCarContinuous-v0'
success_threshold = 90
def __init__(self):
BasicTask.__init__(self)
self.env = gym.make(self.name)
@@ -104,15 +88,15 @@ class MountainCarContinuous(BasicTask):
self.state_dim = self.env.observation_space.shape[0]
def normalize_state(self, state):
state = (state - self.env.unwrapped.low_state) / \
(self.env.unwrapped.high_state - self.env.unwrapped.low_state)
state = (state - self.env.observation_space.low) / \
(self.env.observation_space.high - self.env.observation_space.low)
state = state * 2 - 1
return state
def step(self, action):
action = np.clip(action, -1, 1)
action = np.clip(action, -2, 2)
next_state, reward, done, info = self.env.step(action)
return next_state, reward, done, info
return self.normalize_state(next_state), reward, done, info
class BipedalWalker(BasicTask):
name = 'BipedalWalker-v2'