-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_all.py
154 lines (121 loc) · 4.3 KB
/
run_all.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
"""
Train all agents with different parameters and save their weights and
escape latencies during training to visualize results with plotter.py
The data are saved in different folders for each set of parameters
Lazare Girardin - URLNN Mini-project 2
"""
import sys
import pylab as plb
import matplotlib.pyplot as plt
import numpy as np
import mountaincar
import sarsa
if __name__ == "__main__":
trial_number = 300
agents = 10
# ******************** WEIGHTS ***********
# --- Tau decay --- weights zero ----
print(" Testing weights: ZEROS")
for i in range(agents):
d = sarsa.SarsaAgent(decay=True, tau=1., w_init='zero')
print("AGENT ", i+1)
w, latencies = d.learn(epochs=trial_number)
w_id = 'ALLdata/zeroWeights/weights_%.2d' % i +'.npy'
lat_id = 'ALLdata/zeroWeights/latencies_%.2d' %i + '.npy'
np.save(w_id, w)
np.save(lat_id, latencies)
# --- Tau decay --- weights ones ----
print(" Testing weights: ONES")
for i in range(agents):
d = sarsa.SarsaAgent(decay=True, tau=1., w_init='one')
print("AGENT ", i+1)
w, latencies = d.learn(epochs=trial_number)
w_id = 'ALLdata/oneWeights/weights_%.2d' % i +'.npy'
lat_id = 'ALLdata/oneWeights/latencies_%.2d' %i + '.npy'
np.save(w_id, w)
np.save(lat_id, latencies)
print(" Testing weights: RANDOM")
# --- Tau decay --- weights random ----
for i in range(agents):
d = sarsa.SarsaAgent(decay=True, tau=1., w_init='rand')
print("AGENT ", i+1)
w, latencies = d.learn(epochs=trial_number)
w_id = 'ALLdata/randWeights/weights_%.2d' % i +'.npy'
lat_id = 'ALLdata/randWeights/latencies_%.2d' %i + '.npy'
np.save(w_id, w)
np.save(lat_id, latencies)
# ******************** TAU *******************
# decay tau -> any other from above
# --- Tau 0.01 ---
print(" Testing tau: 0.01")
for i in range(agents):
d = sarsa.SarsaAgent(decay=False, tau=0.01, w_init='variance')
print("AGENT ", i+1)
w, latencies = d.learn(epochs=trial_number)
w_id = 'ALLdata/Tau001/weights_%.2d' % i +'.npy'
lat_id = 'ALLdata/Tau001/latencies_%.2d' %i + '.npy'
np.save(w_id, w)
np.save(lat_id, latencies)
# --- Tau 0.4 ---
print(" Testing tau: 0.4")
for i in range(agents):
d = sarsa.SarsaAgent(decay=False, tau=0.4, w_init='variance')
print("AGENT ", i+1)
w, latencies = d.learn(epochs=trial_number)
w_id = 'ALLdata/Tau04/weights_%.2d' % i +'.npy'
lat_id = 'ALLdata/Tau04/latencies_%.2d' %i + '.npy'
np.save(w_id, w)
np.save(lat_id, latencies)
# --- Tau 1 ---
print(" Testing tau: 1")
for i in range(agents):
d = sarsa.SarsaAgent(decay=False, tau=1., w_init='variance')
print("AGENT ", i+1)
w, latencies = d.learn(epochs=trial_number)
w_id = 'ALLdata/Tau1/weights_%.2d' % i +'.npy'
lat_id = 'ALLdata/Tau1/latencies_%.2d' %i + '.npy'
np.save(w_id, w)
np.save(lat_id, latencies)
# ********* ELIGIBILITY ***********************
# --- lambda 0.95
print(" Testing lambda: 0.95")
for i in range(agents):
d = sarsa.SarsaAgent(decay=True, tau=1., w_init='variance', lambda_=0.95)
print("AGENT ", i+1)
w, latencies = d.learn(epochs=trial_number)
w_id = 'ALLdata/l095/weights_%.2d' % i +'.npy'
lat_id = 'ALLdata/l095/latencies_%.2d' %i + '.npy'
np.save(w_id, w)
np.save(lat_id, latencies)
# --- lambda 0
print(" Testing lambda: 0")
for i in range(agents):
d = sarsa.SarsaAgent(decay=True, tau=1., w_init='variance', lambda_=0.)
print("AGENT ", i+1)
w, latencies = d.learn(epochs=trial_number)
w_id = 'ALLdata/l0/weights_%.2d' % i +'.npy'
lat_id = 'ALLdata/l0/latencies_%.2d' 100%i + '.npy'
np.save(w_id, w)
np.save(lat_id, latencies)
# ******* ETA ***************
# eta=0.05 -> any other data from above
# --- eta 0.5
print("Testing eta: 0.5")
for i in range(agents):
d = sarsa.SarsaAgent(decay=True, tau=1., w_init='variance', eta=0.5)
print("AGENT ", i+1)
w, latencies = d.learn(epochs=trial_number)
w_id = 'ALLdata/eta05/weights_%.2d' % i +'.npy'
lat_id = 'ALLdata/eta05/latencies_%.2d' %i + '.npy'
np.save(w_id, w)
np.save(lat_id, latencies)
# --- eta 0.9
print(" Testing eta: 0.9")
for i in range(agents):
d = sarsa.SarsaAgent(decay=True, tau=1., w_init='variance', eta=0.9)
print("AGENT ", i+1)
w, latencies = d.learn(epochs=trial_number)
w_id = 'ALLdata/eta09/weights_%.2d' % i +'.npy'
lat_id = 'ALLdata/eta09/latencies_%.2d' %i + '.npy'
np.save(w_id, w)
np.save(lat_id, latencies)