mirror of
https://github.com/wassname/DeepRL.git
synced 2026-09-09 11:13:47 +08:00
DDPG Pendulum
This commit is contained in:
+4
-20
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user