-
Notifications
You must be signed in to change notification settings - Fork 1
/
ae_coupling.py
159 lines (117 loc) · 4.99 KB
/
ae_coupling.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
import os
import matplotlib.pyplot as plt
import matplotlib
font = {'family' : 'sans-serif',
'weight' : 'bold',
'size' : 35}
matplotlib.rc('font', **font)
#source_dir = "experiment/test/WeatherIconView"
source_dir = "experiment/test"
#Analyis meaning number of microservices generated
louvain = []
clus_2 = []
clus_3 = []
clus_4 = []
clus_5 = []
clus_6 = []
clus_7 = []
clus_8 = []
clus_9 = []
clus_10 = []
clus_11 = []
clus_12 = []
clus_13 = []
clus_14 = []
clus_15 = []
clus_16 = []
clus_17 = []
clus_18 = []
clus_19 = []
full_set = [louvain, clus_2,clus_3,clus_4,clus_5,clus_6,clus_7,clus_8,clus_9,clus_10,clus_11,clus_12,clus_13,clus_14,clus_15, clus_16,clus_17,clus_18,clus_19]
coupling = []
count = 0
for r, d, f in os.walk(source_dir):
count+= 1
print("Progress: "+ str(count/753.0))
if r.split("/")[-1]+".embedding" in f:
edge_list_file = r+"/"+r.split("/")[-1] +".txt"
edge_list = []
with open(edge_list_file) as fi:
edge_list = fi.read().splitlines()
for a_file in f:
if "louvain" in a_file or "clustering" in a_file:
with open(r+'/'+ a_file) as fi:
clusters = fi.read().splitlines()
node_partition_mapping = {}
partion_node_counting = {}
for pair in clusters:
node_partion = pair.split()
node_partition_mapping[node_partion[0]] = node_partion[1]
for a in set(node_partition_mapping.values()):
partion_node_counting[a] = 0
for b in node_partition_mapping.items():
if str(b[1]) == str(a) :
partion_node_counting[a] += 1
#print(node_partition_mapping)
#print(partion_node_counting)
score = 0
for parition in partion_node_counting.keys():
cnt = 0.00
for edge in edge_list:
if node_partition_mapping[edge.split()[0]] == parition and node_partition_mapping[edge.split()[1]] == parition:
cnt += 1
if int (partion_node_counting[parition] *(partion_node_counting[parition] - 1) ) != 0:
score = cnt/ float(partion_node_counting[parition] *(partion_node_counting[parition] - 1) )
if "_2.clustering" in a_file:
clus_2.append(score)
elif "_3.clustering" in a_file:
clus_3.append(score)
elif "_4.clustering" in a_file:
clus_4.append(score)
elif "_5.clustering" in a_file:
clus_5.append(score)
elif "_6.clustering" in a_file:
clus_6.append(score)
elif "_7.clustering" in a_file:
clus_7.append(score)
elif "_8.clustering" in a_file:
clus_8.append(score)
elif "_9.clustering" in a_file:
clus_9.append(score)
elif "10.clustering" in a_file:
clus_10.append(score)
elif "11.clustering" in a_file:
clus_11.append(score)
elif "12.clustering" in a_file:
clus_12.append(score)
elif "13.clustering" in a_file:
clus_13.append(score)
elif "14.clustering" in a_file:
clus_14.append(score)
elif "15.clustering" in a_file:
clus_15.append(score)
elif "16.clustering" in a_file:
clus_16.append(score)
elif "17.clustering" in a_file:
clus_17.append(score)
elif "18.clustering" in a_file:
clus_18.append(score)
elif "19.clustering" in a_file:
clus_19.append(score)
elif "isolated_louvain" in a_file:
louvain.append(score)
full_set_minus_zeros = []
for item in full_set:
full_set_minus_zeros.append([i for i in item if float(i) != 0.0])
print(full_set_minus_zeros[2])
fig = plt.figure()
ax = fig.add_subplot(111)
bp = ax.boxplot(full_set)
for box in bp['boxes']:
box.set(linewidth=10)
plt.xticks([1,2, 3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19], [ 'Louvain', '2-AE', '3-AE ', '4-AE','5-AE','6-AE','7-AE','8-AE ','9-AE','10-AE','11-AE','12-AE','13-AE','14-AE','15-AE','16-AE','17-AE','18-AE','19-AE'], rotation='vertical')
#ax.set_title('Internal Cluster Coupling Analysis with Dropped Zeroes ~ 753 Repository Dataset')
ax.set_xlabel('Model Type (Louvain / X-Class AutoEncoder)',fontsize = 50)
ax.set_ylabel('Cohesion Value',fontsize = 50)
#plt.ylim(0, .6)
plt.show()