-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
49 lines (39 loc) · 1.64 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
import gym
import matplotlib.pyplot as plt
from gym_minigrid.wrappers import *
from functions import main_plot, savepdf, train, defaultdict2
from policies import EpsilonGreedy, EpsilonMaxOpportunity, EpsilonMaxVariance
from networks import EnsambleNetwork, DeepQNetwork
from agents import SarsaLambdaAgent, SarsaAgent, DeepQAgent
from wrappers import OneHotWrapper
if __name__ == "__main__":
envn = "MiniGrid-Empty-8x8-v0"
env = gym.make(envn)
env = OneHotWrapper(env)
methods = []
deepQAgentArgs = {
"gamma": 0.95,
"replay_buffer_minreplay": 300,
"replay_buffer_size": 500000
}
policy = EpsilonGreedy(epsilon=0.1)
network = DeepQNetwork
DQNAgent = lambda: DeepQAgent(env, policy, network=network, **deepQAgentArgs)
methods.append(("DQN", DQNAgent))
policy = EpsilonMaxOpportunity(epsilon=0.1, c=1)
network = lambda *args, **kwargs: EnsambleNetwork([DeepQNetwork] * 10, *args, **kwargs)
DQNAgentMO = lambda: DeepQAgent(env, policy, network=network, **deepQAgentArgs)
methods.append(("DQN-MO", DQNAgentMO))
policy = EpsilonMaxVariance(epsilon=0.1)
network = lambda *args, **kwargs: EnsambleNetwork([DeepQNetwork] * 10, *args, **kwargs)
DQNAgentMV = lambda: DeepQAgent(env, policy, network=network, **deepQAgentArgs)
methods.append(("DQN-MV", DQNAgentMV))
experiments = []
for k, (name, agent) in enumerate(methods):
expn = f"experiments/{envn}_{name}"
#for i in range(10):
#train(env, agent(), expn, num_episodes=200)
experiments.append(expn)
main_plot(experiments, smoothing_window=10)
savepdf("./results")
plt.show()