-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot.py
More file actions
136 lines (112 loc) · 4.22 KB
/
Copy pathplot.py
File metadata and controls
136 lines (112 loc) · 4.22 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
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
import os, glob, yaml, pprint, numpy as np, pandas as pd
from webbrowser import get
from collections import defaultdict
import matplotlib.pyplot as plt
from tensorboard.backend.event_processing import event_accumulator
# from pylab import rcParams, axes
SIZE_GUIDANCE = {
'compressedHistograms': 500,
'images': 4,
'audio': 4,
'scalars': 10000,
'histograms': 1,
}
STORE_EVERYTHING_SIZE_GUIDANCE = {
'compressedHistograms': 0,
'images': 0,
'audio': 0,
'scalars': 0,
'histograms': 0,
}
# params = {
# 'axes.labelsize': 28,
# 'axes.titlesize': 32,
# 'legend.fontsize': 14,
# 'xtick.labelsize': 'x-large',
# 'ytick.labelsize': 'x-large',
# 'text.usetex': True,
# 'figure.figsize': [14, 12]
# }
SMOOTH = 3000
CUT = 52_000
def get_values(filename, scalar="Episodic_Reward"):
ea = event_accumulator.EventAccumulator(filename, size_guidance=STORE_EVERYTHING_SIZE_GUIDANCE)
ea.Reload()
ea_scalar = ea.Scalars(tag=scalar)
ea_scalar = pd.DataFrame(ea_scalar)
return ea_scalar
def smooth(y, box_pts):
box = np.ones(box_pts)/box_pts
y_smooth = np.convolve(y, box, mode='same')
return y_smooth
def preprocess(log_dir):
params = {
'axes.labelsize': 28,
'axes.titlesize': 32,
'legend.fontsize': 14,
'xtick.labelsize': 'x-large',
'ytick.labelsize': 'x-large',
'text.usetex': True,
'figure.figsize': [10, 8]
}
from pylab import plot, rcParams, legend, axes, grid
rcParams.update(params)
logs = glob.glob(os.path.join(log_dir, "*/logs/*"), recursive=True)
# pprint.pprint(logs)
l = []
for event in logs:
l.append(event.split('/')[2].split('--'))
# pprint.pprint(l)
merged = defaultdict(lambda: [])
for i in l: merged['--'.join(i[:-1])].append('--'.join(i))
# pprint.pprint(merged)
# pprint.pprint(list(merged.keys()))
count = -1
colors = ['#006BB2', '#B22400']
labels = ['HAMMER', 'IL']
for exp in merged:
if ('meslen_0' in exp) or ('dru_1--meslen_3' in exp):
print("================================\n"+exp+"\n================================\n")
vals = []
count+=1
for i in merged[exp]:
# if ('randomseed_5327' in i):
# if any(n in i for n in ['5327', '8651', '14712', '186',
# '9538', '106', '90300', '4973', '310', '530', '606']):
if any(n in i for n in ['5327', '8651', '14712', '186',
'9538', '106']):
print(i)
logs = glob.glob(os.path.join('./save', i, "logs/*.npy"), recursive=True)[0]
## save numpy arrays
# logs_dir = glob.glob(os.path.join('./save', i, "logs"), recursive=True)[0]
# with open(logs_dir+'/arr.npy', 'wb') as f:
# np.save(f, get_values(logs)['value'].to_numpy())
arr = np.load(logs)
print(arr.shape)
vals.append(smooth(
arr[:CUT],
box_pts=SMOOTH
)[2000:CUT-2000])
# break
val_means = np.array(vals).mean(axis=0)
val_stds = np.array(vals).std(axis=0)
plt.plot(val_means, label=labels[count], color=colors[count])
plt.fill_between(np.arange(1, len(val_means)+1),
val_means - val_stds,
val_means + val_stds,
alpha=0.2)
# break
rcParams.update(params)
legend = plt.legend(loc="upper left")
# legend = legend(loc='upper center', bbox_to_anchor=(0.5, 1.05), ncol=3, fancybox=True, shadow=True)
frame = legend.get_frame()
frame.set_facecolor('0.9')
frame.set_edgecolor('0.9')
plt.title('HAMMER on Multi-Agent Walker')
plt.xlabel("Number of Episodes")
plt.ylabel("Average Returns per Agent")
plt.xlim((100, CUT-2000))
plt.grid()
plt.show()
if __name__ == '__main__':
preprocess('./save')