* exported rl-algs * more stuff from rl-algs * run slow tests * re-exported rl_algs * re-exported rl_algs - fixed problems with serialization test and test_cartpole * replaced atari_arg_parser with common_arg_parser * run.py can run algos from both baselines and rl_algs * added approximate humanoid reward with ppo2 into the README for reference * dummy commit to RUN BENCHMARKS * dummy commit to RUN BENCHMARKS * dummy commit to RUN BENCHMARKS * dummy commit to RUN BENCHMARKS * very dummy commit to RUN BENCHMARKS * serialize variables as a dict, not as a list * running_mean_std uses tensorflow variables * fixed import in vec_normalize * dummy commit to RUN BENCHMARKS * dummy commit to RUN BENCHMARKS * flake8 complaints * save all variables to make sure we save the vec_normalize normalization * benchmarks on ppo2 only RUN BENCHMARKS * make_atari_env compatible with mpi * run ppo_mpi benchmarks only RUN BENCHMARKS * hardcode names of retro environments * add defaults * changed default ppo2 lr schedule to linear RUN BENCHMARKS * non-tf normalization benchmark RUN BENCHMARKS * use ncpu=1 for mujoco sessions - gives a bit of a performance speedup * reverted running_mean_std to user property decorators for mean, var, count * reverted VecNormalize to use RunningMeanStd (no tf) * reverted VecNormalize to use RunningMeanStd (no tf) * profiling wip * use VecNormalize with regular RunningMeanStd * added acer runner (missing import) * flake8 complaints * added a note in README about TfRunningMeanStd and serialization of VecNormalize * dummy commit to RUN BENCHMARKS * merged benchmarks branch
71 lines
1.6 KiB
Python
71 lines
1.6 KiB
Python
import numpy as np
|
|
from abc import abstractmethod
|
|
from gym import Env
|
|
from gym.spaces import Discrete, Box
|
|
|
|
|
|
class IdentityEnv(Env):
|
|
def __init__(
|
|
self,
|
|
episode_len=None
|
|
):
|
|
|
|
self.episode_len = episode_len
|
|
self.time = 0
|
|
self.reset()
|
|
|
|
def reset(self):
|
|
self._choose_next_state()
|
|
self.time = 0
|
|
self.observation_space = self.action_space
|
|
|
|
return self.state
|
|
|
|
def step(self, actions):
|
|
rew = self._get_reward(actions)
|
|
self._choose_next_state()
|
|
done = False
|
|
if self.episode_len and self.time >= self.episode_len:
|
|
rew = 0
|
|
done = True
|
|
|
|
return self.state, rew, done, {}
|
|
|
|
def _choose_next_state(self):
|
|
self.state = self.action_space.sample()
|
|
self.time += 1
|
|
|
|
@abstractmethod
|
|
def _get_reward(self, actions):
|
|
raise NotImplementedError
|
|
|
|
|
|
class DiscreteIdentityEnv(IdentityEnv):
|
|
def __init__(
|
|
self,
|
|
dim,
|
|
episode_len=None,
|
|
):
|
|
|
|
self.action_space = Discrete(dim)
|
|
super().__init__(episode_len=episode_len)
|
|
|
|
def _get_reward(self, actions):
|
|
return 1 if self.state == actions else 0
|
|
|
|
|
|
class BoxIdentityEnv(IdentityEnv):
|
|
def __init__(
|
|
self,
|
|
shape,
|
|
episode_len=None,
|
|
):
|
|
|
|
self.action_space = Box(low=-1.0, high=1.0, shape=shape)
|
|
super().__init__(episode_len=episode_len)
|
|
|
|
def _get_reward(self, actions):
|
|
diff = actions - self.state
|
|
diff = diff[:]
|
|
return -0.5 * np.dot(diff, diff)
|