-
Notifications
You must be signed in to change notification settings - Fork 1
/
lv_coupling.py
127 lines (87 loc) · 3.83 KB
/
lv_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
import os
import matplotlib.pyplot as plt
#source_dir = "experiment/test/WeatherIconView"
source_dir = "experiment/test"
#Analyis meaning number of microservices generated
louvain = []
autoencoder = []
data = [louvain, autoencoder]
coupling = []
for r, d, f in os.walk(source_dir):
qvalue_file = r+"/"+r.split("/")[-1] +".qvalues"
if os.path.exists(qvalue_file):
highest_ae_qvalue_line = "0 -9999"
all_lines = []
with open(qvalue_file) as fi:
all_lines = fi.read().splitlines()
for line in all_lines:
splt_line = line.split()
if splt_line[0] !="louvain":
if float(splt_line[1]) > float(highest_ae_qvalue_line.split()[1]):
highest_ae_qvalue_line = line
edge_list_file = r+"/"+r.split("/")[-1] +".txt"
edge_list = []
with open(edge_list_file) as fi:
edge_list = fi.read().splitlines()
#louvain coup
with open(r+"/"+r.split("/")[-1] +".isolated_louvain") 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) )
louvain.append(score)
#louvain
#High score ae coup
highest_qvalue_file = r+"/"+r.split("/")[-1] +"_"+ highest_ae_qvalue_line.split()[0] +".clustering"
with open(highest_qvalue_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) )
autoencoder.append(score)
full_set_minus_zeros = []
for item in data:
full_set_minus_zeros.append([i for i in item if float(i) != 0.0])
fig = plt.figure()
ax = fig.add_subplot(111)
ax.boxplot(full_set_minus_zeros[0:])
plt.xticks([1,2], ['Louvain Clusters', 'AutoEncoder Clusters'])
ax.set_title('AutoEncoder Coupling Analysis ~ 750 Repository Dataset')
ax.set_xlabel('Generation Method')
ax.set_ylabel('Coupling Value')
#plt.ylim(0, 20)
plt.show()