root / fiddle / simulation_analysis / utility.py @ 072a5b5a
History | View | Annotate | Download (2.46 KB)
1 |
import numpy as np |
---|---|
2 |
|
3 |
def get_statistical_for_column(col): |
4 |
"""Returns the min, max, avg, std
|
5 |
"""
|
6 |
stats = [np.amin(col), np.amax(col), np.average(col), np.std(col)] |
7 |
return stats
|
8 |
|
9 |
def get_statistical_data(input_data, index_column_name, value_column_name): |
10 |
categories = np.unique(input_data[index_column_name]) |
11 |
|
12 |
result_dict = dict()
|
13 |
for cat in categories: |
14 |
values = input_data[input_data[index_column_name] == cat][value_column_name] |
15 |
stats = get_statistical_for_column(values) |
16 |
result_dict[cat] = stats |
17 |
|
18 |
return result_dict
|
19 |
|
20 |
def write_to_file(output_filepath, output_data, dtype={}): |
21 |
np.savetxt(output_filepath, output_data, fmt='%s', delimiter=',') |
22 |
|
23 |
|
24 |
def read_out1(input_filepath): |
25 |
result = np.loadtxt(input_filepath, |
26 |
dtype={ |
27 |
'names': ('filename', 'graphtype', 'numberofnodes', 'runindex', 'bc_time', 'hbc_time', |
28 |
'start_bc_clock', 'end_bc_clock', 'start_hbc_clock', 'end_hbc_clock'), |
29 |
'formats': ('a40', 'a2', 'i4', 'i4', 'f8', 'f8', 'f8', 'f8', 'f8', 'f8'), |
30 |
}, |
31 |
delimiter=',',
|
32 |
) |
33 |
return result
|
34 |
|
35 |
|
36 |
def format_output_data_out1(bc_result, hbc_result): |
37 |
output_data = list()
|
38 |
|
39 |
for key in bc_result.keys(): |
40 |
tmp_list = [key] |
41 |
|
42 |
tmp_index = key.find('_')
|
43 |
typo_code = key[:tmp_index] |
44 |
tmp_list.append(typo_code) |
45 |
|
46 |
bc_values = bc_result[key] |
47 |
hbc_values = hbc_result[key] |
48 |
|
49 |
tmp_list.append(bc_values[2])
|
50 |
tmp_list.append(hbc_values[2])
|
51 |
|
52 |
tmp_list.append(bc_values[3])
|
53 |
tmp_list.append(hbc_values[3])
|
54 |
|
55 |
output_data.append(tmp_list) |
56 |
|
57 |
return output_data
|
58 |
|
59 |
def read_out2(input_filepath): |
60 |
result = np.loadtxt(input_filepath, |
61 |
dtype={ |
62 |
'names': ('filename', 'typotype', 'avg_bc', 'avg_hbc', 'std_bc', 'std_hbc'), |
63 |
'formats': ('a40', 'a6', 'f8', 'f8', 'f8', 'f8'), |
64 |
}, |
65 |
delimiter=',',
|
66 |
) |
67 |
return result
|
68 |
|
69 |
|
70 |
def format_output_data_out2(bc_result, hbc_result): |
71 |
output_data = list()
|
72 |
|
73 |
for key in bc_result.keys(): |
74 |
tmp_list = [key] |
75 |
|
76 |
graph_type = key[0:2] |
77 |
tmp_list.append(graph_type) |
78 |
|
79 |
num_of_nodes = key[2:]
|
80 |
tmp_list.append(num_of_nodes) |
81 |
|
82 |
bc_values = bc_result[key] |
83 |
hbc_values = hbc_result[key] |
84 |
|
85 |
tmp_list.append(bc_values[2])
|
86 |
tmp_list.append(hbc_values[2])
|
87 |
|
88 |
tmp_list.append(bc_values[3])
|
89 |
tmp_list.append(hbc_values[3])
|
90 |
|
91 |
output_data.append(tmp_list) |
92 |
|
93 |
return output_data
|