-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.py
53 lines (45 loc) · 1.42 KB
/
main.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import gym
import os
import mujoco_py
from agent import Agent
from train import Train
from play import Play
ENV_NAME = "Swimmer"
TRAIN_FLAG = False
test_env = gym.make(ENV_NAME + "-v2")
n_states = test_env.observation_space.shape[0]
action_bounds = [test_env.action_space.low[0], test_env.action_space.high[0]]
n_actions = test_env.action_space.shape[0]
n_iterations = 500
lr = 3e-4
epochs = 10
clip_range = 0.2
mini_batch_size = 64
T = 2048
if __name__ == "__main__":
print(f"number of states:{n_states}\n"
f"action bounds:{action_bounds}\n"
f"number of actions:{n_actions}")
if not os.path.exists(ENV_NAME):
os.mkdir(ENV_NAME)
os.mkdir(ENV_NAME + "/logs")
env = gym.make(ENV_NAME + "-v2")
agent = Agent(n_states=n_states,
n_iter=n_iterations,
env_name=ENV_NAME,
action_bounds=action_bounds,
n_actions=n_actions,
lr=lr)
if TRAIN_FLAG:
trainer = Train(env=env,
test_env=test_env,
env_name=ENV_NAME,
agent=agent,
horizon=T,
n_iterations=n_iterations,
epochs=epochs,
mini_batch_size=mini_batch_size,
epsilon=clip_range)
trainer.step()
player = Play(env, agent, ENV_NAME)
player.evaluate()