-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot_avg_VLR_acc.py
142 lines (86 loc) · 3.46 KB
/
plot_avg_VLR_acc.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
import argparse
import h5py
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.pylab as pylab
params = {'axes.titlesize':'x-large',
'axes.labelsize': 'x-large'}
pylab.rcParams.update(params)
def plot_line_avg_acc(avg_accuracies, expansion_markers, threshold, labels, save):
plt.figure()
averaged_accs = np.zeros(31)
print(len(avg_accuracies))
for avg_acc in avg_accuracies:
for i, acc in enumerate(avg_acc):
averaged_accs[i] += acc
for i in range(len(averaged_accs)):
averaged_accs[i] /= 100
plt.plot(averaged_accs)
plt.ylabel('Average Accuracy on All Tasks')
plt.xlabel('Total Task Count')
plt.xlim(1, 30)
plt.ylim(0, 100)
markers = []
for marker in expansion_markers:
if marker not in markers:
plt.axvline(x=marker, color='r')
markers.append(marker)
else:
plt.axvline(x=marker, color='g')
# plt.axhline(y=threshold, linestyle='dashed')
# plt.legend(loc='upper center', bbox_to_anchor=(0.5, 1.05),
# ncol=3, fancybox=True, shadow=True)
plt.savefig('final/plots/{}.pdf'.format(save), dpi=300, format='pdf')
def parse_h5_file(filename):
f = h5py.File(filename, 'r')
avg_acc = []
task_acc = []
expansions = []
metadata = []
for data in f["avg_acc"]:
avg_acc.append(data)
for data in f["task_acc"]:
task_acc.append(data)
for data in f["expansions"]:
expansions.append(data)
for data in f["metadata"]:
metadata.append(data)
f.close()
expansion_indices = []
for i in range(len(expansions)):
if expansions[i] == 1:
expansion_indices.append(i)
elif expansions[i] > 1:
for exp in range(i):
expansion_indices.append(i)
print("You'd better take a look at {}, Captain...".format(filename))
return avg_acc, task_acc, expansion_indices, metadata
def main():
"""
NOTE: pass me the name of the file with expansion first...
"""
parser = argparse.ArgumentParser(description='Plotting Tool')
parser.add_argument('--filenames', nargs='+', type=str, default=['NONE'], metavar='FILENAMES',
help='names of .h5 files containing experimental result data')
parser.add_argument('--labels', nargs='+', type=str, default=['NONE'], metavar='LABELS',
help='figure legend labels in same order as respective filenames')
parser.add_argument('--line', type=str, default='NO_LINE', metavar='LINE',
help='filename for saved line graph (no extension)')
args = parser.parse_args()
avg_acc_list = []
task_acc_list = []
expansion_indices_list = []
metadata_list = []
for filename in args.filenames:
avg_acc, task_acc, expansion_indices, metadata = parse_h5_file(filename)
avg_acc_list.append(avg_acc)
task_acc_list.append(task_acc)
expansion_indices_list.append(expansion_indices)
metadata_list.append(metadata)
threshold = 0
for data in metadata_list[0]:
if data.startswith('accuracy_threshold'):
threshold = float(data[data.rfind(' '):])
plot_line_avg_acc(avg_acc_list, expansion_indices_list[0], threshold, args.labels, args.line)
if __name__ == "__main__":
main()