Statistics
| Branch: | Revision:

root / fiddle / simulation_analysis / utility.py @ e066fa74

History | View | Annotate | Download (2.19 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(bc_result, hbc_result):
37
    output_data = list()
38

    
39
    for key in bc_result.keys():
40
        tmp_list = []
41

    
42
        tmp_index = key.find('_')
43
        typo_code = key
44
        if tmp_index != -1:
45
            typo_code = key[:tmp_index]
46

    
47
        graph_type = typo_code[:2]
48
        num_of_nodes = typo_code[2:]
49

    
50
        bc_values = bc_result[key]
51
        hbc_values = hbc_result[key]
52

    
53
        tmp_list.append(key)
54
        tmp_list.append(typo_code)
55
        # print typo_code
56
        tmp_list.append(graph_type)
57
        tmp_list.append(num_of_nodes)
58

    
59
        tmp_list.append(bc_values[2])
60
        tmp_list.append(hbc_values[2])
61

    
62
        tmp_list.append(bc_values[3])
63
        tmp_list.append(hbc_values[3])
64

    
65
        output_data.append(tmp_list)
66

    
67
    return output_data
68

    
69
def read_out2(input_filepath):
70
    result = np.loadtxt(input_filepath,
71
        dtype={
72
            'names': ('filename', 'typotype', 'graphtype', 'numofnodes', 'avg_bc', 'avg_hbc', 'std_bc', 'std_hbc'),
73
            'formats': ('a40', 'a6', 'a2', 'i4', 'f8', 'f8', 'f8', 'f8'),
74
        },
75
        delimiter=',',
76
    )
77
    return result