-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplot_learning_history.py
More file actions
78 lines (65 loc) · 2.05 KB
/
plot_learning_history.py
File metadata and controls
78 lines (65 loc) · 2.05 KB
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
import csv
import getopt
import sys
import matplotlib.pyplot as plt
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 = []
lambda_occupancy = []
lambda_bandwidth = []
lambda_latency = []
# 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]))
tmp = row[9].split()
lambda_occupancy.append(float(tmp[1]))
tmp = row[10].split()
lambda_bandwidth.append(float(tmp[1]))
tmp = row[11].split()
lambda_latency.append(float(tmp[1]))
# Plotting...
fig, ax = plt.subplots(2, 1)
ax[0].plot(reward, label='Cost')
ax[0].plot(baseline, label='Baseline')
ax[0].plot(lagrangian, label='Lagrangian')
ax[0].plot(penalty, label='Penalty')
ax[0].legend()
ax[0].set(ylabel='Cost', title='Learning history')
ax[0].grid()
ax[1].plot(lambda_occupancy, label='λ1')
ax[1].plot(lambda_bandwidth, label='λ2')
ax[1].plot(lambda_latency, label='λ3')
ax[1].grid()
# ax[1].legend(loc='upper left')
ax[1].legend()
ax[1].set(xlabel='samples (x1000)', ylabel='Lambda')
plt.show()
if __name__ == "__main__":
main(sys.argv[1:])