-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconsecutive_pairs_stats.py
178 lines (141 loc) · 8.94 KB
/
consecutive_pairs_stats.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import csv
def read_csv(filename):
data_list = []
with open(filename, 'r') as csvfile:
reader = csv.reader(csvfile)
headers = next(reader) # 跳过表头
for row in reader:
data_list.append(row)
return data_list
def pair_stats(all_superspreader_list):
all_pair_type_dict = {"s1":0,"s2":0,"s3":0}
for node_idx, superspreader_list in enumerate(all_superspreader_list):
checked_list = [superspreader_list[0]]
pair_type_dict={"s1":0,"s2":0,"s3":0}
for i in range(len(superspreader_list)-1):
if superspreader_list[i+1] == superspreader_list[i]:
pair_type_dict["s1"]+=1
elif superspreader_list[i+1] != superspreader_list[i] and superspreader_list[i+1] not in checked_list:
pair_type_dict["s2"]+=1
elif superspreader_list[i+1] != superspreader_list[i] and superspreader_list[i+1] in checked_list:
pair_type_dict["s3"] += 1
checked_list.append(superspreader_list[i+1])
all_pair_type_dict["s1"] += pair_type_dict["s1"]
all_pair_type_dict["s2"] += pair_type_dict["s2"]
all_pair_type_dict["s3"] += pair_type_dict["s3"]
print("====")
all = all_pair_type_dict["s1"]+all_pair_type_dict["s2"]+all_pair_type_dict["s3"]
all_pair_type_dict_pro = {"s1":all_pair_type_dict["s1"]/all,"s2":all_pair_type_dict["s2"]/all,"s3":all_pair_type_dict["s3"]/all}
return all_pair_type_dict_pro
def pair_stats_v2(all_superspreader_list):
all_pair_type_dict = {"s1":0,"s2":0,"s3":0}
for node_idx, superspreader_list in enumerate(all_superspreader_list):
checked_list = [superspreader_list[0]]
pair_type_dict={"s1":0,"s2":0,"s3":0}
for i in range(len(superspreader_list)-1):
if superspreader_list[i+1] == superspreader_list[i]:
pair_type_dict["s1"]+=1
elif superspreader_list[i+1] != superspreader_list[i] and superspreader_list[i+1] not in checked_list:
pair_type_dict["s2"]+=1
elif superspreader_list[i+1] != superspreader_list[i] and superspreader_list[i+1] in checked_list:
pair_type_dict["s3"] += 1
checked_list.append(superspreader_list[i+1])
# print("pair_type_dict:",pair_type_dict)
all_pair_type_dict["s1"] += pair_type_dict["s1"]
all_pair_type_dict["s2"] += pair_type_dict["s2"]
all_pair_type_dict["s3"] += pair_type_dict["s3"]
print("====")
all = all_pair_type_dict["s1"]+all_pair_type_dict["s2"]+all_pair_type_dict["s3"]
all_pair_type_dict_pro = {"s1":all_pair_type_dict["s1"]/all,"s2":all_pair_type_dict["s2"]/all,"s3":all_pair_type_dict["s3"]/all}
return all_pair_type_dict_pro
regular_tree_BFS_sqrt = read_csv('./data_moreG_small/2debug_regular_tree_BFS_sqrt.csv')
regular_tree_BFS_rand_BFS = read_csv('./data_moreG_small/2debug_regular_tree_BFS_rand_BFS.csv')
regular_tree_BFS_stc = read_csv('./data_moreG_small/2debug_regular_tree_BFS_stc.csv')
regular_tree_DFS_sqrt = read_csv('./data_moreG_small/2debug_regular_tree_DFS_sqrt.csv')
regular_tree_DFS_rand_BFS = read_csv('./data_moreG_small/2debug_regular_tree_DFS_rand_BFS.csv')
regular_tree_DFS_stc = read_csv('./data_moreG_small/2debug_regular_tree_DFS_stc.csv')
print("regular_tree_BFS_sqrt:",pair_stats_v2(regular_tree_BFS_sqrt))
print("regular_tree_BFS_rand_BFS:",pair_stats_v2(regular_tree_BFS_rand_BFS))
print("regular_tree_BFS_stc:",pair_stats_v2(regular_tree_BFS_stc))
print("regular_tree_DFS_sqrt:",pair_stats_v2(regular_tree_DFS_sqrt))
print("regular_tree_DFS_rand_BFS:",pair_stats_v2(regular_tree_DFS_rand_BFS))
print("regular_tree_DFS_stc:",pair_stats_v2(regular_tree_DFS_stc))
print("-------------------------")
sensor_BFS_sqrt = read_csv('./data_moreG_small/2debug_sensor_BFS_sqrt.csv')
sensor_BFS_rand_BFS = read_csv('./data_moreG_small/2debug_sensor_BFS_rand_BFS.csv')
sensor_BFS_stc = read_csv('./data_moreG_small/2debug_sensor_BFS_stc.csv')
sensor_DFS_sqrt = read_csv('./data_moreG_small/2debug_sensor_DFS_sqrt.csv')
sensor_DFS_rand_BFS = read_csv('./data_moreG_small/2debug_sensor_DFS_rand_BFS.csv')
sensor_DFS_stc = read_csv('./data_moreG_small/2debug_sensor_DFS_stc.csv')
print("sensor_BFS_sqrt:",pair_stats_v2(sensor_BFS_sqrt))
print("sensor_BFS_rand_BFS:",pair_stats_v2(sensor_BFS_rand_BFS))
print("sensor_BFS_stc:",pair_stats_v2(sensor_BFS_stc))
print("sensor_DFS_sqrt:",pair_stats_v2(sensor_DFS_sqrt))
print("sensor_DFS_rand_BFS:",pair_stats_v2(sensor_DFS_rand_BFS))
print("sensor_DFS_stc:",pair_stats_v2(sensor_DFS_stc))
print("-------------------------")
complete_nary_BFS_sqrt = read_csv('./data_moreG_small/2debug_complete_nary_BFS_sqrt.csv')
complete_nary_BFS_rand_BFS = read_csv('./data_moreG_small/2debug_complete_nary_BFS_rand_BFS.csv')
complete_nary_BFS_stc = read_csv('./data_moreG_small/2debug_complete_nary_BFS_stc.csv')
complete_nary_DFS_sqrt = read_csv('./data_moreG_small/2debug_complete_nary_DFS_sqrt.csv')
complete_nary_DFS_rand_BFS = read_csv('./data_moreG_small/2debug_complete_nary_DFS_rand_BFS.csv')
complete_nary_DFS_stc = read_csv('./data_moreG_small/2debug_complete_nary_DFS_stc.csv')
print("complete_nary_BFS_sqrt:",pair_stats_v2(complete_nary_BFS_sqrt))
print("complete_nary_BFS_rand_BFS:",pair_stats_v2(complete_nary_BFS_rand_BFS))
print("complete_nary_BFS_stc:",pair_stats_v2(complete_nary_BFS_stc))
print("complete_nary_DFS_sqrt:",pair_stats_v2(complete_nary_DFS_sqrt))
print("complete_nary_DFS_rand_BFS:",pair_stats_v2(complete_nary_DFS_rand_BFS))
print("complete_nary_DFS_stc:",pair_stats_v2(complete_nary_DFS_stc))
print("-------------------------")
ER_random_BFS_sqrt = read_csv('./data_moreG_small/2debug_ER_random_BFS_sqrt.csv')
ER_random_BFS_rand_BFS = read_csv('./data_moreG_small/2debug_ER_random_BFS_rand_BFS.csv')
ER_random_BFS_stc = read_csv('./data_moreG_small/2debug_ER_random_BFS_stc.csv')
ER_random_DFS_sqrt = read_csv('./data_moreG_small/2debug_ER_random_DFS_sqrt.csv')
ER_random_DFS_rand_BFS = read_csv('./data_moreG_small/2debug_ER_random_DFS_rand_BFS.csv')
ER_random_DFS_stc = read_csv('./data_moreG_small/2debug_ER_random_DFS_stc.csv')
print("ER_random_BFS_sqrt:",pair_stats_v2(ER_random_BFS_sqrt))
print("ER_random_BFS_rand_BFS:",pair_stats_v2(ER_random_BFS_rand_BFS))
print("ER_random_BFS_stc:",pair_stats_v2(ER_random_BFS_stc))
print("ER_random_DFS_sqrt:",pair_stats_v2(ER_random_DFS_sqrt))
print("ER_random_DFS_rand_BFS:",pair_stats_v2(ER_random_DFS_rand_BFS))
print("ER_random_DFS_stc:",pair_stats_v2(ER_random_DFS_stc))
print("-------------------------")
SBM_BFS_sqrt = read_csv('./data_moreG_small/2debug_SBM_BFS_sqrt.csv')
SBM_BFS_rand_BFS = read_csv('./data_moreG_small/2debug_SBM_BFS_rand_BFS.csv')
SBM_BFS_stc = read_csv('./data_moreG_small/2debug_SBM_BFS_stc.csv')
SBM_DFS_sqrt = read_csv('./data_moreG_small/2debug_SBM_DFS_sqrt.csv')
SBM_DFS_rand_BFS = read_csv('./data_moreG_small/2debug_SBM_DFS_rand_BFS.csv')
SBM_DFS_stc = read_csv('./data_moreG_small/2debug_SBM_DFS_stc.csv')
print("SBM_BFS_sqrt:",pair_stats_v2(SBM_BFS_sqrt))
print("SBM_BFS_rand_BFS:",pair_stats_v2(SBM_BFS_rand_BFS))
print("SBM_BFS_stc:",pair_stats_v2(SBM_BFS_stc))
print("SBM_DFS_sqrt:",pair_stats_v2(SBM_DFS_sqrt))
print("SBM_DFS_rand_BFS:",pair_stats_v2(SBM_DFS_rand_BFS))
print("SBM_DFS_stc:",pair_stats_v2(SBM_DFS_stc))
print("-------------------------")
sensor_BFS_sqrt = read_csv('./data_moreG_small/2debug_sensor_BFS_sqrt.csv')
sensor_BFS_rand_BFS = read_csv('./data_moreG_small/2debug_sensor_BFS_rand_BFS.csv')
sensor_BFS_stc = read_csv('./data_moreG_small/2debug_sensor_BFS_stc.csv')
sensor_DFS_sqrt = read_csv('./data_moreG_small/2debug_sensor_DFS_sqrt.csv')
sensor_DFS_rand_BFS = read_csv('./data_moreG_small/2debug_sensor_DFS_rand_BFS.csv')
sensor_DFS_stc = read_csv('./data_moreG_small/2debug_sensor_DFS_stc.csv')
print("sensor_BFS_sqrt:",pair_stats_v2(sensor_BFS_sqrt))
print("sensor_BFS_rand_BFS:",pair_stats_v2(sensor_BFS_rand_BFS))
print("sensor_BFS_stc:",pair_stats_v2(sensor_BFS_stc))
print("sensor_DFS_sqrt:",pair_stats_v2(sensor_DFS_sqrt))
print("sensor_DFS_rand_BFS:",pair_stats_v2(sensor_DFS_rand_BFS))
print("sensor_DFS_stc:",pair_stats_v2(sensor_DFS_stc))
print("-------------------------")
real_world_BFS_sqrt = read_csv('./data_moreG/2debug_real_world_BFS_sqrt.csv')
real_world_BFS_rand_BFS = read_csv('./data_moreG/2debug_real_world_BFS_rand_BFS.csv')
real_world_BFS_stc = read_csv('./data_moreG/2debug_real_world_BFS_stc.csv')
real_world_DFS_sqrt = read_csv('./data_moreG/2debug_real_world_DFS_sqrt.csv')
real_world_DFS_rand_BFS = read_csv('./data_moreG/2debug_real_world_DFS_rand_BFS.csv')
real_world_DFS_stc = read_csv('./data_moreG/2debug_real_world_DFS_stc.csv')
print("real_world_BFS_sqrt:",pair_stats_v2(real_world_BFS_sqrt))
print("real_world_BFS_rand_BFS:",pair_stats_v2(real_world_BFS_rand_BFS))
print("real_world_BFS_stc:",pair_stats_v2(real_world_BFS_stc))
print("real_world_DFS_sqrt:",pair_stats_v2(real_world_DFS_sqrt))
print("real_world_DFS_rand_BFS:",pair_stats_v2(real_world_DFS_rand_BFS))
print("real_world_DFS_stc:",pair_stats_v2(real_world_DFS_stc))
print("-------------------------")