-
Notifications
You must be signed in to change notification settings - Fork 2
/
aggregate_nums.py
61 lines (45 loc) · 1.44 KB
/
aggregate_nums.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
import numpy as np
import sys
from glob import glob
dataset = sys.argv[1]
alg = sys.argv[2]
if len(sys.argv) > 3:
keep_last = int(sys.argv[3])
else:
keep_last = 1
seed_list = [42, 1234, 2011]
# seed_list = [42]
filename = f"outputs/{dataset}/{alg}_*_28_%d_log.txt"
aggregate_results = []
for seed in seed_list:
seed_results = []
curr_filename = filename % seed
print(curr_filename)
curr_files = glob(curr_filename)
# curr_files = [curr_filename]
if len(curr_files) == 0:
print("No files found")
exit()
elif len(curr_files) == 1:
for curr_file in curr_files:
with open(curr_file, 'r') as f:
lines = f.readlines()
for line in lines:
line.rstrip()
temp_arr =[]
arr = line.split(',')
for val in arr:
if val.strip() != "NA":
temp_arr.append(float(val))
else:
temp_arr.append(0)
seed_results.append(temp_arr)
seed_results = np.array(seed_results)
else:
print("More than one file found! ")
print(curr_files)
exit()
for i in range(keep_last):
aggregate_results.append(seed_results[-i-1])
aggregate_results = np.array(aggregate_results)
print(np.mean(aggregate_results, axis=0))