diff options
Diffstat (limited to 'Metrics/Metrics-Calculation/metrics_plot/src/average_ks_plot.py')
-rw-r--r-- | Metrics/Metrics-Calculation/metrics_plot/src/average_ks_plot.py | 62 |
1 files changed, 0 insertions, 62 deletions
diff --git a/Metrics/Metrics-Calculation/metrics_plot/src/average_ks_plot.py b/Metrics/Metrics-Calculation/metrics_plot/src/average_ks_plot.py deleted file mode 100644 index e949a729..00000000 --- a/Metrics/Metrics-Calculation/metrics_plot/src/average_ks_plot.py +++ /dev/null | |||
@@ -1,62 +0,0 @@ | |||
1 | from GraphType import GraphStat | ||
2 | from GraphType import GraphCollection | ||
3 | from scipy import stats | ||
4 | import readCSV as reader | ||
5 | import matplotlib.pyplot as plt | ||
6 | |||
7 | class GraphDistance: | ||
8 | #init with a graph stat and a collection of graph stats | ||
9 | def __init__(self, graphStat, collection): | ||
10 | self.graph = graphStat | ||
11 | self.collection = collection | ||
12 | print('calculating for %d' %(self.graph.id)) | ||
13 | self.out_d_distance = average_ks_distance(collection.out_ds, graphStat.out_d) | ||
14 | self.na_distance = average_ks_distance(collection.nas, graphStat.na) | ||
15 | self.mpc_distance = average_ks_distance(collection.mpcs, graphStat.mpc) | ||
16 | |||
17 | def average_ks_distance(targets, sample): | ||
18 | distance = 0.0 | ||
19 | for target in targets: | ||
20 | value, p = stats.ks_2samp(target, sample) | ||
21 | distance += value | ||
22 | |||
23 | distance = distance / len(targets) | ||
24 | return distance | ||
25 | |||
26 | # metric_selector: GraphDistance -> float | ||
27 | def plot(infos, lines, id, metric_selector, title): | ||
28 | metric_distances = retrive_info_from_list(metric_selector, list(infos.values())) | ||
29 | x = retrive_info_from_list(lambda a : a.graph.num_nodes, list(infos.values)) | ||
30 | graph = plt.figure(id) | ||
31 | plt.title(title) | ||
32 | |||
33 | for line in lines: | ||
34 | line_infos = retrive_info_from_list(lambda a: infos[a], line) | ||
35 | line_y = retrive_info_from_list(metric_selector, line_infos) | ||
36 | line_x = retrive_info_from_list(lambda a : a.graph.num_nodes, list(infos.values)) | ||
37 | plt.plot(line_x, line_y, color='blue') | ||
38 | plt.plot(x, metric_distances, color='red', linestyle='', marker='o',alpha=0.7) | ||
39 | graph.show() | ||
40 | |||
41 | def retrive_info_from_list(selector, distances): | ||
42 | return list(map(selector, list(infos.values))) | ||
43 | |||
44 | human = GraphCollection('../statistics/humanOutput/', 300, 'Human') | ||
45 | file_names = reader.readmultiplefiles('../statistics/viatraEvolve/', 500, False) | ||
46 | |||
47 | infos = [] | ||
48 | # read all files | ||
49 | for name in file_names: | ||
50 | infos.append(GraphStat(name)) | ||
51 | |||
52 | infos = list(map(lambda s: GraphDistance(s, human), infos)) | ||
53 | |||
54 | info_dic = {} | ||
55 | for info in infos: | ||
56 | info_dic[info.graph.id] = info | ||
57 | |||
58 | plot(info_dic, [[1,2,3,4,5,6,7,8,9,10]], 0, lambda a: a.out_d_distance, 'out degree') | ||
59 | # plot(info_dic, 1, lambda a: a.na_distance, 'node activity') | ||
60 | # plot(info_dic, 2, lambda a: a.mpc_distance, 'mpc') | ||
61 | |||
62 | input() \ No newline at end of file | ||