-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestingLab.py
33 lines (24 loc) · 866 Bytes
/
TestingLab.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from rllab.envs.base import Env
from rllab.envs.base import Step
from rllab.spaces import Box
import numpy as np
class PointEnv(Env):
@property
def observation_space(self):
return Box(low=-np.inf, high=-np.inf, shape=(2,))
@property
def action_space(self):
return Box(low=-0.1, high=0.1, shape=(2,))
def reset(self):
self._state = np.random.uniform(-1,1, size=(2,))
observation = np.copy(self._state)
return observation
def step(self, action):
self._state = self._state + action
x, y = self._state
reward = - (x**2 + y**2)**0.5
done = abs(x)<0.01 and abs(y) < 0.01
next_observation = np.copy(self._state)
return Step(observation=next_observation, reward=reward, done=done)
def render(self):
print("Current State: ", self._state)