ddpg with a dynamics model

I'm trying a dynamics model to provide additional supervision. I'm using
this repo because it's performance tested on a competition and is in
pytorch. I'm intially testing with pendulum. Code is messy as it's a one
time experiment.
This commit is contained in:
wassname
2018-01-18 16:41:20 +08:00
parent 814607dc94
commit 0de68133cf
5 changed files with 608 additions and 35 deletions
+54 -6
View File
@@ -1,7 +1,8 @@
import numpy as np
import gym
from gym.spaces import Box
from osim.env import RunEnv
import sys
# from osim.env import RunEnv
from common.state_transform import StateVelCentr
@@ -59,12 +60,59 @@ class DdpgWrapper(gym.Wrapper):
return observation
# def create_env_old(args):
# env = RunEnv(visualize=False, max_obstacles=args.max_obstacles)
#
# if hasattr(args, "baseline_wrapper") or hasattr(args, "ddpg_wrapper"):
# env = DdpgWrapper(env, args)
#
# return env
# class BasicTask:
# def __init__(self):
# self.normalized_state = True
#
# def normalize_state(self, state):
# return state
#
# def reset(self):
# state = self.env.reset()
# if self.normalized_state:
# return self.normalize_state(state)
# return state
#
# def step(self, action):
# next_state, reward, done, info = self.env.step(action)
# if self.normalized_state:
# next_state = self.normalize_state(next_state)
# return next_state, np.sign(reward), done, info
#
# def random_action(self):
# return self.env.action_space.sample()
#
#
# class Pendulum(BasicTask):
# name = 'Pendulum-v0'
# success_threshold = -10
#
# def __init__(self):
# BasicTask.__init__(self)
# self.env = gym.make(self.name)
# self.max_episode_steps = self.env._max_episode_steps
# 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
def create_env(args):
env = RunEnv(visualize=False, max_obstacles=args.max_obstacles)
if hasattr(args, "baseline_wrapper") or hasattr(args, "ddpg_wrapper"):
env = DdpgWrapper(env, args)
# env = Pendulum()
env = gym.make('Pendulum-v0')
return env