-
Notifications
You must be signed in to change notification settings - Fork 2
/
auxFunctions.js
267 lines (188 loc) · 6.48 KB
/
auxFunctions.js
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
// ---------------------------------------------- Auxiliary Functions ----------------------------------------------
function nodeDetection(nodes_obj, state) {
let result = [];
for (let i = 0; i < nodes_obj.length; i++) {
if(state) {
result.push(nodes_obj[i].id)
} else {
result.push(nodes_obj[i].data.id)
}
}
return result
}
// Converting array of arrays data to string representation. To be used to generate .txt docs for benchmark.
function arrayToString(multi_array, str, title) {
for (let ij = 0; ij < title.length; ij++) {
str += (title[ij]);
if (ij < title.length-1) str += ",";
}
str += "\n";
for (let j = 0; j < multi_array[0].length; j++) {
for (let i = 0; i < multi_array.length; i++) {
str += multi_array[i][j];
if (i < multi_array.length-1) str += ",";
}
if (j < multi_array[0].length-1) str += "\n";
}
return str;
}
// Converting array of arrays data to string representation. To be used to generate .txt docs for benchmark.
function arrayToString_plot(obj, str, titles) {
let result = {};
let all_titles = Object.keys(obj);
let repeat = 10;
for (let i = 0; i < titles.length; i++) {
for (let j = 0; j < all_titles.length; j++) {
if (all_titles[j].includes(titles[i])) {
result[titles[i]] = result[titles[i]] || 0;
result[titles[i]] = result[titles[i]] + Math.log10(obj[all_titles[j]])/repeat;
}
}
}
let std_dev = {};
for (let i = 0; i < titles.length; i++) {
for (let j = 0; j < all_titles.length; j++) {
if (all_titles[j].includes(titles[i])) {
std_dev[titles[i]] = std_dev[titles[i]] || 0;
std_dev[titles[i]] = std_dev[titles[i]] + Math.pow(obj[all_titles[j]] - Math.pow(10,result[titles[i]]), 2)/repeat;
}
}
std_dev[titles[i]] = Math.log10(1.96 * Math.pow(std_dev[titles[i]], 0.5) / Math.pow(repeat, 0.5)); // 95% Confidence Interval
}
console.log(std_dev);
console.log(result);
let result_values = Object.values(result);
let std_dev_values = Object.values(std_dev);
str += ("time");
str += ",";
// ---------------------------- NMI x Mix Parameter [BENCH]
/*
str += ("Label Propagation");
str += ",";
str += ("SD1");
str += ",";
str += ("Layered Label Propagation");
str += ",";
str += ("SD2");
str += ",";
str += ("Louvain");
str += ",";
str += ("SD3");
str += ",";
str += ("Infomap");
str += ",";
str += ("SD4");
*/
// ---------------------------- LP/LLP/Louvain/Infomap NMI x Mix Parameter [BENCH]
str += ("k = 15");
str += ",";
str += ("SD1");
str += ",";
str += ("k = 20");
str += ",";
str += ("SD2");
str += ",";
str += ("k = 25");
str += ",";
str += ("SD3");
// ---------------------------- NMI Layered Label Propagation x Gamma Parameter [BENCH]
/*
for (let i = 0; i < 11; i++) {
str += ("Mix Param. = " + i/10);
str += ",";
str += ("SD" + (i + 1));
if (i < 10) str += ",";
}
*/
// ---------------------------- GN Generating Time x Mix Parameter [BENCH]
/*
str += ("Generating Time");
str += ",";
str += ("SD1");
*/
str += "\n";
for (let j = 0; j < 11; j++) {
str += j/10;
str += ",";
for (let i = j; i < result_values.length; i = i + 11) {
str += Math.round(result_values[i]*1000)/1000;
str += ",";
str += Math.round(std_dev_values[i]*1000)/1000;
if (i < result_values.length-11) str += ",";
}
if(j !== 11-1) str += "\n";
}
return str;
}
// Converting array of arrays data to string representation. To be used to generate .txt docs for benchmark.
function printMeta(obj, length_var) {
let str = "";
let new_obj = {};
let keys = Object.keys(obj);
let values = Object.values(obj);
str += ("ST");
str += "\t";
str += ("Community");
str += "\n";
for (let i = 1; i < length_var; i++) { // Generating 127 nodes, distributed in 4 groups, from GN benchmark network.
new_obj[i.toString()] = length_var;
}
for (let i = 0; i < keys.length; i++) { // Generating 127 nodes, distributed in 4 groups, from GN benchmark network.
new_obj[keys[i]] = values[i];
}
keys = Object.keys(new_obj);
values = Object.values(new_obj);
for (let j = 0; j < keys.length; j++) {
for (let i = 0; i < 2; i++) {
if (i === 0) {
str += keys[j];
str += "\t";
} else {
str += values[j];
}
}
if(j !== keys.length-1) {
str += "\n";
}
}
return str;
}
// Upon input of source and target nodes, it returns an edge with the right format.
function edge (source, target) { // Used in fs.readFile in order to push each edge in Input.txt to an empty array.
return {source: source, target: target, value: 1}; // Previously, I used parseInt to convert source and target strings to an integer.
}
// Upon input of a set of nodes, it returns an array with different format accordingly to a state value. It pretends to adjust to the type of visualization scheme and reset/run state.
function nodify (final_node_data, state) { // Used in fs.readFile in order to push each node in Input.txt to an empty array.
let result_aux = [];
let keys = Object.keys(final_node_data);
switch(state) {
case 0:
keys.forEach(function (key) {
result_aux.push({id: key, group: final_node_data[key]})
});
break;
case 1:
keys.forEach(function (key) {
result_aux.push({id: key, group: 1})
});
break;
case 2:
keys.forEach(function (key) {
result_aux.push({data: {id: key, weight: 5}})
});
break;
case 3:
keys.forEach(function (key) {
result_aux.push({data: {id: key, weight: final_node_data[key]}});
});
}
return result_aux; // Previously, I used parseInt to convert the key string to an integer.
}
module.exports = {
nodeDetection: nodeDetection,
arrayToString: arrayToString,
printMeta: printMeta,
edge: edge,
nodify: nodify,
arrayToString_plot: arrayToString_plot
};