diff options
Diffstat (limited to 'Metrics/Metrics-Calculation/metrics_plot/type_analysis/src/plot_violation.py')
-rw-r--r-- | Metrics/Metrics-Calculation/metrics_plot/type_analysis/src/plot_violation.py | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/Metrics/Metrics-Calculation/metrics_plot/type_analysis/src/plot_violation.py b/Metrics/Metrics-Calculation/metrics_plot/type_analysis/src/plot_violation.py new file mode 100644 index 00000000..e5e12f42 --- /dev/null +++ b/Metrics/Metrics-Calculation/metrics_plot/type_analysis/src/plot_violation.py | |||
@@ -0,0 +1,77 @@ | |||
1 | import matplotlib.pyplot as plt | ||
2 | import numpy as np | ||
3 | import cdf_histogram as cdf | ||
4 | import readCSV as reader | ||
5 | import constants | ||
6 | import csv | ||
7 | from shutil import copy | ||
8 | |||
9 | |||
10 | # viatra_controlled = np.genfromtxt('../statistics/violations/viatra_controlled.csv', delimiter='\n') | ||
11 | # viatra_controlled_mean = np.mean(viatra_controlled) | ||
12 | # viatra_nocons = np.genfromtxt('../statistics/violations/viatra_no_cons_violation.csv', delimiter='\n') | ||
13 | # viatra_nocons_mean = np.mean(viatra_nocons) | ||
14 | # human = np.genfromtxt('../statistics/violations/human_violation.csv', delimiter='\n') | ||
15 | # human_mean = np.mean(human) | ||
16 | # print('viatra controlled violation mean: ' + str(viatra_controlled_mean)) | ||
17 | # print('viatra no cons violation mean: ' + str(viatra_nocons_mean)) | ||
18 | # print('human output violation mean: ' + str(human_mean)) | ||
19 | |||
20 | |||
21 | def read_violation_file(file_name): | ||
22 | violation = {} | ||
23 | with open(file_name) as f: | ||
24 | for i, line in enumerate(f): | ||
25 | line = int(line.rstrip()) | ||
26 | if line in violation: | ||
27 | violation[line] += 1 | ||
28 | else: | ||
29 | violation[line] = 1 | ||
30 | f.close() | ||
31 | return violation | ||
32 | |||
33 | # violation = read_violation_file('../statistics/violations/viatra_controlled.csv') | ||
34 | # print(violation) | ||
35 | # fig, ax = plt.subplots() | ||
36 | # rects = ax.bar(violation.keys(), violation.values()) | ||
37 | # cdf.autolabel(rects, ax) | ||
38 | # ax.set_title('viatra controlled violation distribution') | ||
39 | # ax.set_xlabel('number of violations') | ||
40 | # ax.set_ylabel('number of occurrence') | ||
41 | # plt.show() | ||
42 | # fig.savefig('../statistics/violations/viatra_controlled_violation_distribution.png') | ||
43 | |||
44 | |||
45 | def plot_violation(): | ||
46 | v = np.array([0,1,1,0,0]) | ||
47 | print(v) | ||
48 | (n, bins) = np.histogram(v, bins=v.size, density=True) # NumPy version (no plot) | ||
49 | # plt.plot(.5 * (bins[1:] + bins[:-1]), n) | ||
50 | plt.hist(v, bins=50, density=1) | ||
51 | plt.show() | ||
52 | |||
53 | |||
54 | def human_output_size(): | ||
55 | list_of_files = reader.readmultiplefiles('../statistics/humanOutput/', 5000) | ||
56 | num_nodes_list =[] | ||
57 | human_size_dic = {} | ||
58 | for file in list_of_files: | ||
59 | contents = reader.readcsvfile(file) | ||
60 | num_of_node = contents[constants.NUMBER_NODES] | ||
61 | # human_size_dic[file] = int(num_of_node[0]) | ||
62 | # num_nodes_list.append(int(num_of_node[0])) | ||
63 | if 90 <= num_of_node[0] <= 110: | ||
64 | copy(file, '../statistics/human_output_100/') | ||
65 | |||
66 | # mean = np.mean(num_nodes_list) | ||
67 | # std = np.std(num_nodes_list) | ||
68 | # with open('../statistics/human_output_size.csv', 'w', newline='') as csvfile: | ||
69 | # spamwriter = csv.writer(csvfile, delimiter=',', | ||
70 | # quotechar='|', quoting=csv.QUOTE_MINIMAL) | ||
71 | # spamwriter.writerow(['mean', mean]) | ||
72 | # spamwriter.writerow(['standard deviation', std]) | ||
73 | # for key, value in human_size_dic.items(): | ||
74 | # spamwriter.writerow([key, value]) | ||
75 | |||
76 | |||
77 | |||