-
Notifications
You must be signed in to change notification settings - Fork 2
/
runtime_analysis.py
125 lines (114 loc) · 4.33 KB
/
runtime_analysis.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
"""
Runtime analysis for testing and training of movement detection networks
Author: Petrut A. Bogdan
"""
# Imports
from zipfile import BadZipfile
from common_analysis_imports import *
from os import listdir
from os.path import isfile, join
start_time = plt.datetime.datetime.now()
save_dir = "runtime_analysis_meta"
if not os.path.isdir(save_dir):
os.mkdir(save_dir)
synaptogenesis_folder_relative_location = "../synaptogenesis/"
onlyfiles = [f for f in listdir(synaptogenesis_folder_relative_location) if
isfile(join(synaptogenesis_folder_relative_location, f))]
only_delay_npz_files = [f for f in onlyfiles if ".npz" in f and "delay" in f]
print(only_delay_npz_files)
testing_random_delay_files = []
testing_constant_delay_files = []
training_random_delay_files = []
training_constant_delay_files = []
exceptions = []
ke_count = 0
io_count = 0
bzf_count = 0
exception_strings = []
for f in only_delay_npz_files:
print(f)
try:
is_constant_delay = False
pathed_file = join(synaptogenesis_folder_relative_location, f)
data = np.load(pathed_file)
if (data['exception'] and
not data['exception'].ravel()[0] == "None") \
or "error_" in f:
# Broken
exceptions.append((f, data['exception']))
elif data['testing']:
# Testing
sim_params = np.array(data['sim_params']).ravel()[0]
if 'delay_interval' in sim_params.keys():
is_constant_delay = sim_params['delay_interval'] == [1, 1]
else:
is_constant_delay = "constant" in f
if is_constant_delay:
testing_constant_delay_files.append((
f, sim_params['simtime'],
np.array(data['total_time']).ravel()[
0].total_seconds() * 1000,
sim_params,
os.stat(pathed_file)))
else:
testing_random_delay_files.append((
f, sim_params['simtime'],
np.array(data['total_time']).ravel()[
0].total_seconds() * 1000,
sim_params,
os.stat(pathed_file)))
elif not data['testing']:
# Training
sim_params = np.array(data['sim_params']).ravel()[0]
if 'delay_interval' in sim_params.keys():
is_constant_delay = sim_params['delay_interval'] == [1, 1]
else:
is_constant_delay = "constant" in f
if is_constant_delay:
training_constant_delay_files.append((
f, sim_params['simtime'],
np.array(data['total_time']).ravel()[
0].total_seconds() * 1000,
sim_params,
os.stat(pathed_file)))
else:
training_random_delay_files.append((
f, sim_params['simtime'],
np.array(data['total_time']).ravel()[
0].total_seconds() * 1000,
sim_params,
os.stat(pathed_file)))
else:
sim_params = np.array(data['sim_params']).ravel()[0]
print("Something went wrong with", f, sim_params)
except KeyError as ke:
ke_count += 1
except IOError as io:
io_count += 1
except BadZipfile as bzf:
bzf_count += 1
except TypeError as te:
print(te)
except Exception as e:
exception_strings.append(str(e))
traceback.print_exc()
end_time = plt.datetime.datetime.now()
total_time = end_time - start_time
suffix = end_time.strftime("_%H%M%S_%d%m%Y")
if args.filename:
filename = args.filename
else:
filename = join(save_dir, "runtime_analysis_drifting_grating" + str(
suffix))
np.savez(filename,
testing_random_delay_files = testing_random_delay_files,
testing_constant_delay_files=testing_constant_delay_files,
training_random_delay_files=training_random_delay_files,
training_constant_delay_files=training_constant_delay_files,
exceptions=exceptions,
keyerror_count=ke_count,
ioerror_count=io_count,
badzipfileerror_count=bzf_count,
exception_strings=exception_strings)
print("Results in", filename)
print("Total time elapsed -- " + str(total_time))