-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathgraphicate_learning.py
70 lines (51 loc) · 1.59 KB
/
graphicate_learning.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
import matplotlib.pyplot as plt
import csv
import sys, getopt
def main(argv):
#Input learning history file
inputfile = ''
try:
opts, args = getopt.getopt(argv,"f:",["file="])
except getopt.GetoptError:
print("test.py -f --file <file>")
sys.exit(2)
for opt, arg in opts:
if opt in ("-f", "--file"):
inputfile = arg
reward = []
baseline = []
advantage = []
penalty = []
loss_agent = []
lagrangian = []
# Retrieve variables from csv
with open(inputfile) as csv_file:
csv_reader = csv.reader(csv_file, delimiter=',')
for row in csv_reader:
tmp = row[3].split()
reward.append(float(tmp[1]))
tmp = row[4].split()
lagrangian.append(float(tmp[1]))
tmp = row[5].split()
baseline.append(float(tmp[1]))
tmp = row[6].split()
advantage.append(float(tmp[1]))
tmp = row[7].split()
penalty.append(float(tmp[1]))
tmp = row[8].split()
loss_agent.append(float(tmp[1]))
# Plotting...
fig, ax = plt.subplots(2, 1)
ax[0].plot(reward, label='energy')
ax[0].plot(baseline, label='baseline')
ax[0].plot(penalty, label='penalty')
ax[0].plot(lagrangian, label='lagrangian')
ax[0].legend()
ax[0].set(ylabel='Cost', title='Learning history')
ax[0].grid()
ax[1].plot(loss_agent, label='loss agent')
ax[1].grid()
ax[1].set(xlabel='samples (x100)', ylabel='loss agent')
plt.show()
if __name__ == "__main__":
main(sys.argv[1:])