-
Notifications
You must be signed in to change notification settings - Fork 1
/
mod_5epoch_.py
124 lines (77 loc) · 4.01 KB
/
mod_5epoch_.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
import os
import matplotlib.pyplot as plt
#source_dir = "experiment/test/WeatherIconView"
source_dir = "experiment/test"
folders = ["epoch_1","epoch_2","epoch_3","epoch_4","epoch_5"]
full_set = []
for folder in folders:
clus_2 = []
clus_5 = []
clus_10 = []
clus_15 = []
print(folder)
for r, d, f in os.walk("../"+folder+"/"+"AutoEncoder_Research/experiment/test"):
#First get the edgelist to process louvain and clustering
if r.split("/")[-1]+".embedding" in f:
for a_file in f:
if ".clustering" in a_file :
edge_list = r+'/'+r.split("/")[-1]+".txt"
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
m_norm = 0
with open(edge_list ) as f:
for edge in f:
m_norm += 1
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Modularity Q Calculation
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
modQ = 0
for partition in partion_node_counting.keys():
internal = 0
incident = 0
with open(edge_list) as f:
for edge in f:
source_dest = edge.split()
if source_dest[0] in node_partition_mapping and source_dest[1] in node_partition_mapping:
if node_partition_mapping[source_dest[0]] == str(partition) and \
node_partition_mapping[source_dest[1]] == str(partition):
internal += 1
incident += 1
elif node_partition_mapping[source_dest[0]] == str(partition) or \
node_partition_mapping[source_dest[1]] == str(partition):
incident += 1
modQ += ( (internal/(2.0*m_norm)) - (incident/(2.0*m_norm))**2)
#print("Modularity Q Value")
#print(modQ)
#output this qvalue to file
if "_2.clustering" in a_file:
clus_2.append(modQ)
elif "_5.clustering" in a_file:
clus_5.append(modQ)
elif "10.clustering" in a_file:
clus_10.append(modQ)
elif "15.clustering" in a_file:
clus_15.append(modQ)
full_set.append(clus_2)
full_set.append(clus_5)
full_set.append(clus_10)
full_set.append(clus_15)
fig = plt.figure()
ax = fig.add_subplot(111)
ax.boxplot(full_set[0:])
plt.xticks([1,2, 3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20], [ '2C-100E', '5C-100E', '10C-100E ', '15C-100E','2C-200E','5C-200E','10C-200E','15C-200E ','2C-300E','5C-300E','10C-300E','15C-300E','2C-400E','5C-400E','10C-400E','15C-400E','2C-500E','5C-500TD','10C-500E','15C-500E'], rotation='vertical')
ax.set_title('AutoEncoder Epochs Vs. Q-Value Analysis [150 Dataset] ')
ax.set_xlabel('[X] Cluster Model -Trained on- [Y] Epochos')
ax.set_ylabel('Q-Value')
#plt.ylim(0, 20)
plt.show()