-
Notifications
You must be signed in to change notification settings - Fork 0
/
live.py
executable file
·54 lines (44 loc) · 1.33 KB
/
live.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
#!/usr/bin/python3
import os
import argparse
import multiprocessing
from matplotlib import pyplot as plt
from scipy.io import savemat
from numpy import array
parser = argparse.ArgumentParser()
parser.add_argument("dir", metavar='dir', help="model dirs")
args = parser.parse_args()
result = []
def getResult(path):
sub = path[0]
i = path[1]
with open(os.path.join(args.dir, sub, i, 'cell.lua')) as fd:
performance = fd.readline().split()[1].strip()
try:
performance = float(performance)
if performance < 0:
return
return ((int(i), performance, sub))
except:
pass
dirs = [('live', i) for i in os.listdir(os.path.join(args.dir, 'live'))] + \
[('dead', i) for i in os.listdir(os.path.join(args.dir, 'dead'))]
c = {'live': 'b.', 'dead': 'r.'}
pool = multiprocessing.Pool(16)
result = [i for i in pool.imap_unordered(getResult, dirs) if i]
pool.close()
pool.join()
result = sorted(result, key=lambda x: x[0])
# print(max([i[1] for i in result]))
print(sorted(result, key=lambda x: x[1])[-1])
matdata = []
for ix, data in enumerate(result):
plt.plot(ix, data[1], c[data[2]])
matdata.append(data[1])
# savemat('a.mat',{'a':array(matdata)})
plt.grid()
plt.show()
for data in result:
plt.plot(data[0], data[1], c[data[2]])
plt.grid()
plt.show()