-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.py
45 lines (35 loc) · 948 Bytes
/
script.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
import os
import sys
import matplotlib.pyplot as plt
import numpy as np
import gym
from dqn import DQN
orgDQN, multistep = False, False
if len(sys.argv) == 1:
print("There is no argument, please input")
for i in range(1,len(sys.argv)):
if sys.argv[i] == "orgDQN":
orgDQN = True
elif sys.argv[i] == "multistep":
multistep = True
env = gym.make('CartPole-v1')
if orgDQN:
env.reset()
dqn = DQN(env, multistep=False)
orgDQN_record = dqn.learn(1500)
del dqn
if multistep:
env.reset()
dqn = DQN(env, multistep=True)
multistep_record = dqn.learn(500)
del dqn
print("Reinforcement Learning Finish")
print("Draw graph ... ")
if orgDQN:
plt.plot(np.arange((len(orgDQN_record))), orgDQN_record, label='Original DQN')
if multistep:
plt.plot(np.arange((len(multistep_record))), multistep_record, label='Multistep DQN')
plt.legend()
fig =plt.gcf()
plt.savefig("result.png")
plt.show()