Graphviz 12.0.1~dev.20240716.0800
Loading...
Searching...
No Matches
mq.c
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (c) 2011 AT&T Intellectual Property
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * https://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors: Details at https://graphviz.org
9 *************************************************************************/
10
11/* Modularity Quality definition:
12
13 We assume undirected graph. Directed graph should be converted by summing edge weights.
14
15 Given a partition P of V into k clusters.
16
17 Let E(i,j) be the set of edges between cluster i and j.
18 Let |E(i,j)| be the sum of edge weights of edges in E(i,j).
19
20 Let E(i,i) be the set of edges within cluster i, but excluding self-edges.
21 Let |E(i,i)| be the sum of edge weights of edges in E(i,i).
22
23 Let V(i) be the sets of vertices in i
24
25 The intra-cluster edges concentration for a cluster i is
26 (the denominator could be |V(i)|*(|V(i)-1)/2 strictly speaking as we exclude self-edges):
27
28 |E(i,i)|
29 -----------
30 (|V(i)|^2/2)
31
32 The inter-cluster edges concentration between cluster i and j is
33
34 |E(i,j)|
35 ------------
36 |V(i)|*|V(j)|
37
38 So the cluster index is defined as the average intra cluster edge concentration, minus
39 the inter-cluster edge concentration:
40
41 . |E(i,i)| |E(i,j)|
42 MQ(P) = (1/k) * \sum_{i=1...k} ------------ - (1/(k*(k-1)/2)) * \sum_{i<j} ------------------- = mq_in/k - mq_out/(k*(k-1)/2)
43 . (|V(i)|^2/2) |V(i)|*|V(j)|
44
45 or
46
47 . |E(i,i)| |E(i,j)|
48 MQ(P)/2 = (1/k) * \sum_{i=1...k} ------------ - (1/(k*(k-1))) * \sum_{i<j} ------------------ = mq_in/k - mq_out/(k*(k-1))
49 . |V(i)|^2 |V(i)|*|V(j)|
50
51 Notice that if we assume the graph is unweights (edge weights = 1), then 0<= MQ <= 1.
52 For weighted graph, MQ may not be within 0 to 1. We could normalized it, but
53 for comparing clustering quality of the same graph but different partitioning, this
54 unnormalized quantity is not a problem.
55
56*/
57
58#define STANDALONE
59#include <cgraph/alloc.h>
60#include <cgraph/list.h>
61#include <limits.h>
62#include <sparse/general.h>
63#include <sparse/SparseMatrix.h>
64#include <sparse/mq.h>
65#include <stdbool.h>
66#include <string.h>
67
68static double get_mq(SparseMatrix A, int *assignment, int *ncluster0, double *mq_in0, double *mq_out0, double **dout0){
69 /* given a symmetric matrix representation of a graph and an assignment of nodes into clusters, calculate the modularity quality.
70 assignment: assignment[i] gives the cluster assignment of node i. 0 <= assignment[i] < ncluster.
71 ncluster: number of clusters
72 mq_in: the part of MQ to do with intra-cluster edges, before divide by 1/k
73 mq_out: the part of MQ to do with inter-cluster edges, before divide by 1/(k*(k-1))
74 mq = 2*(mq_in/k - mq_out/(k*(k-1)));
75 */
76 int ncluster = 0;
77 int n = A->m;
78 bool test_pattern_symmetry_only = false;
79 int *counts, *ia = A->ia, *ja = A->ja, k, i, j, jj;
80 double mq_in = 0, mq_out = 0, *a = NULL, Vi, Vj;
81 int c;
82 double *dout;
83
84
85 assert(SparseMatrix_is_symmetric(A, test_pattern_symmetry_only));
86 (void)test_pattern_symmetry_only;
87 assert(A->n == n);
88 if (A->type == MATRIX_TYPE_REAL) a = A->a;
89
90 counts = gv_calloc(n, sizeof(int));
91
92 for (i = 0; i < n; i++){
93 assert(assignment[i] >= 0 && assignment[i] < n);
94 if (counts[assignment[i]] == 0) ncluster++;
95 counts[assignment[i]]++;
96 }
97 k = ncluster;
98 assert(ncluster <= n);
99
100 for (i = 0; i < n; i++){
101 assert(assignment[i] < ncluster);
102 c = assignment[i];
103 Vi = counts[c];
104 for (j = ia[i] ; j < ia[i+1]; j++){
105 /* ASSUME UNDIRECTED */
106 jj = ja[j];
107 if (jj >= i) continue;
108 assert(assignment[jj] < ncluster);
109 Vj = counts[assignment[jj]];
110 if (assignment[jj] == c){
111 if (a) {
112 mq_in += a[j]/(Vi*Vi);
113 } else {
114 mq_in += 1./(Vi*Vi);
115 }
116 } else {
117 if (a) {
118 mq_out += a[j]/(Vi*Vj);
119 } else {
120 mq_out += 1./(Vi*Vj);
121 }
122 }
123
124 }
125 }
126
127 /* calculate scaled out degree */
128 dout = gv_calloc(n, sizeof(double));
129 for (i = 0; i < n; i++){
130 for (j = ia[i]; j < ia[i+1]; j++){
131 jj = ja[j];
132 if (jj == i) continue;
133 if (a){
134 dout[i] += a[j]/(double) counts[assignment[jj]];
135 } else {
136 dout[i] += 1./(double) counts[assignment[jj]];
137 }
138 }
139 }
140
141 *ncluster0 = k;
142 *mq_in0 = mq_in;
143 *mq_out0 = mq_out;
144 *dout0 = dout;
145 free(counts);
146
147 if (k > 1){
148 return 2*(mq_in/k - mq_out/(k*(k-1)));
149 } else {
150 return 2*mq_in;
151 }
152}
153
156 int n = A->n, i;
157 int *matching;
158
159 assert(A->type == MATRIX_TYPE_REAL);
160 assert(SparseMatrix_is_symmetric(A, false));
161
162 if (!A) return NULL;
163 assert(A->m == n);
165 grid->level = level;
166 grid->n = n;
167 grid->A = A;
168 grid->P = NULL;
169 grid->next = NULL;
170 grid->prev = NULL;
171 grid->delete_top_level_A = false;
172 matching = grid->matching = gv_calloc(n, sizeof(double));
173 grid->deg_intra = NULL;
174 grid->dout = NULL;
175 grid->wgt = NULL;
176
177 if (level == 0){
178 double mq = 0, mq_in, mq_out;
179 int ncluster;
180 double *deg_intra, *wgt, *dout;
181
182 grid->deg_intra = gv_calloc(n, sizeof(double));
183 deg_intra = grid->deg_intra;
184
185 grid->wgt = gv_calloc(n, sizeof(double));
186 wgt = grid->wgt;
187
188 for (i = 0; i < n; i++){
189 deg_intra[i] = 0;
190 wgt[i] = 1.;
191 }
192 for (i = 0; i < n; i++) matching[i] = i;
193 mq = get_mq(A, matching, &ncluster, &mq_in, &mq_out, &dout);
194 fprintf(stderr,"ncluster = %d, mq = %f\n", ncluster, mq);
195 grid->mq = mq;
196 grid->mq_in = mq_in;
197 grid->mq_out = mq_out;
198 grid->dout = dout;
199 grid->ncluster = ncluster;
200
201 }
202
203
204 return grid;
205}
206
208 if (!grid) return;
209 if (grid->A){
210 if (grid->level == 0) {
211 if (grid->delete_top_level_A) SparseMatrix_delete(grid->A);
212 } else {
214 }
215 }
217 free(grid->matching);
218 free(grid->deg_intra);
219 free(grid->dout);
220 free(grid->wgt);
222 free(grid);
223}
224
225DEFINE_LIST(ints, int)
226
228 int *matching = grid->matching;
229 SparseMatrix A = grid->A;
230 int n = grid->n, level = grid->level, nc = 0, nclusters = n;
231 double mq = 0, mq_in = 0, mq_out = 0, mq_new, mq_in_new, mq_out_new, mq_max = 0, mq_in_max = 0, mq_out_max = 0;
232 int *ia = A->ia, *ja = A->ja;
233 double amax = 0;
234 double *deg_intra = grid->deg_intra, *wgt = grid->wgt;
235 int i, j, k, jj, jc, jmax;
236 double gain = 0, *dout = grid->dout, deg_in_i, deg_in_j, wgt_i, wgt_j, a_ij, dout_i, dout_j, dout_max = 0, wgt_jmax = 0;
237 double maxgain = 0;
238 double total_gain = 0;
239
240 ints_t *neighbors = gv_calloc(n, sizeof(ints_t));
241
242 mq = grid->mq;
243 mq_in = grid->mq_in;
244 mq_out = grid->mq_out;
245
246 double *deg_intra_new = gv_calloc(n, sizeof(double));
247 double *wgt_new = gv_calloc(n, sizeof(double));
248 double *deg_inter = gv_calloc(n, sizeof(double));
249 int *mask = gv_calloc(n, sizeof(int));
250 double *dout_new = gv_calloc(n, sizeof(double));
251 for (i = 0; i < n; i++) mask[i] = -1;
252
253 assert(n == A->n);
254 for (i = 0; i < n; i++) matching[i] = UNMATCHED;
255
256 /* gain in merging node A into cluster B is
257 mq_in_new = mq_in - |E(A,A)|/(V(A))^2 - |E(B,B)|/(V(B))^2 + (|E(A,A)|+|E(B,B)|+|E(A,B)|)/(|V(A)|+|V(B)|)^2
258 . = mq_in - deg_intra(A)/|A|^2 - deg_intra(B)/|B|^2 + (deg_intra(A)+deg_intra(B)+a(A,B))/(|A|+|B|)^2
259
260 mq_out_new = mq_out - |E(A,B)|/(|V(A)|*V(B)|)-\sum_{C and A connected, C!=B} |E(A,C)|/(|V(A)|*|V(C)|)-\sum_{C and B connected,C!=B} |E(B,C)|/(|V(B)|*|V(C)|)
261 . + \sum_{C connected to A or B, C!=A, C!=B} (|E(A,C)|+|E(B,C)|)/(|V(C)|*(|V(A)|+|V(B)|)
262 . = mq_out + a(A,B)/(|A|*|B|)-\sum_{C and A connected} a(A,C)/(|A|*|C|)-\sum_{C and B connected} a(B,C)/(|B|*|C|)
263 . + \sum_{C connected to A or B, C!=A, C!=B} (a(A,C)+a(B,C))/(|C|*(|A|+|B|))
264 Denote:
265 dout(i) = \sum_{j -- i} a(i,j)/|j|
266 then
267
268 mq_out_new = mq_out - |E(A,B)|/(|V(A)|*V(B)|)-\sum_{C and A connected, C!=B} |E(A,C)|/(|V(A)|*|V(C)|)-\sum_{C and B connected,C!=B} |E(B,C)|/(|V(B)|*|V(C)|)
269 . + \sum_{C connected to A or B, C!=A, C!=B} (|E(A,C)|+|E(B,C)|)/(|V(C)|*(|V(A)|+|V(B)|)
270 . = mq_out + a(A,B)/(|A|*|B|)-dout(A)/|A| - dout(B)/|B|
271 . + (dout(A)+dout(B))/(|A|+|B|) - (a(A,B)/|A|+a(A,B)/|B|)/(|A|+|B|)
272 . = mq_out -dout(A)/|A| - dout(B)/|B| + (dout(A)+dout(B))/(|A|+|B|)
273 after merging A and B into cluster AB,
274 dout(AB) = dout(A) + dout(B);
275 dout(C) := dout(C) - a(A,C)/|A| - a(B,C)/|B| + a(A,C)/(|A|+|B|) + a(B, C)/(|A|+|B|)
276
277 mq_new = mq_in_new/(k-1) - mq_out_new/((k-1)*(k-2))
278 gain = mq_new - mq
279 */
280 double *a = A->a;
281 for (i = 0; i < n; i++){
282 if (matching[i] != UNMATCHED) continue;
283 /* accumulate connections between i and clusters */
284 for (j = ia[i]; j < ia[i+1]; j++){
285 jj = ja[j];
286 if (jj == i) continue;
287 if ((jc=matching[jj]) != UNMATCHED){
288 if (mask[jc] != i) {
289 mask[jc] = i;
290 deg_inter[jc] = a[j];
291 } else {
292 deg_inter[jc] += a[j];
293 }
294 }
295 }
296 deg_in_i = deg_intra[i];
297 wgt_i = wgt[i];
298 dout_i = dout[i];
299
300 maxgain = 0;
301 jmax = -1;
302 for (j = ia[i]; j < ia[i+1]; j++){
303 jj = ja[j];
304 if (jj == i) continue;
305 jc = matching[jj];
306 if (jc == UNMATCHED){
307 a_ij = a[j];
308 wgt_j = wgt[jj];
309 deg_in_j = deg_intra[jj];
310 dout_j = dout[jj];
311 } else if (deg_inter[jc] < 0){
312 continue;
313 } else {
314 a_ij = deg_inter[jc];
315 wgt_j = wgt_new[jc];
316 deg_inter[jc] = -1; // so that we do not redo the calculation when we hit another neighbor in cluster jc
317 deg_in_j = deg_intra_new[jc];
318 dout_j = dout_new[jc];
319 }
320
321 mq_in_new = mq_in - deg_in_i/pow(wgt_i, 2) - deg_in_j/pow(wgt_j,2)
322 + (deg_in_i + deg_in_j + a_ij)/pow(wgt_i + wgt_j,2);
323
324 mq_out_new = mq_out - dout_i/wgt_i - dout_j/wgt_j + (dout_i + dout_j)/(wgt_i + wgt_j);
325
326 if (nclusters > 2){
327 mq_new = 2*(mq_in_new/(nclusters - 1) - mq_out_new/((nclusters - 1)*(nclusters - 2)));
328 } else {
329 mq_new = 2*mq_in_new/(nclusters - 1);
330 }
331
332#ifdef DEBUG
333 {int ncluster;
334 double mq2, mq_in2, mq_out2, *dout2;
335 int nc2 = nc;
336 int *matching2 = gv_calloc(A->m, sizeof(int));
337 memcpy(matching2, matching, sizeof(double)*A->m);
338 if (jc != UNMATCHED) {
339 matching2[i] = jc;
340 } else {
341 matching2[i] = nc2;
342 matching2[jj] = nc2;
343 nc2++;
344 }
345 for (k = 0; k < n; k++) if (matching2[k] == UNMATCHED) matching2[k] =nc2++;
346 mq2 = get_mq(A, matching2, &ncluster, &mq_in2, &mq_out2, &dout2);
347 fprintf(stderr," {dout_i, dout_j}={%f,%f}, {predicted, calculated}: mq = {%f, %f}, mq_in ={%f,%f}, mq_out = {%f,%f}\n",dout_i, dout_j, mq_new, mq2, mq_in_new, mq_in2, mq_out_new, mq_out2);
348
349 mq_new = mq2;
350
351 }
352#endif
353
354 gain = mq_new - mq;
355 if (Verbose) fprintf(stderr,"gain in merging node %d with node %d = %f-%f = %f\n", i, jj, mq, mq_new, gain);
356 if (j == ia[i] || gain > maxgain){
357 maxgain = gain;
358 jmax = jj;
359 amax = a_ij;
360 dout_max = dout_j;
361 wgt_jmax = wgt_j;
362 mq_max = mq_new;
363 mq_in_max = mq_in_new;
364 mq_out_max = mq_out_new;
365 }
366
367 }
368
369 /* now merge i and jmax */
370 if (maxgain > 0 || (nc >= 1 && nc > maxcluster)){
371 total_gain += maxgain;
372 jc = matching[jmax];
373 if (jc == UNMATCHED){
374 fprintf(stderr, "maxgain=%f, merge %d, %d\n",maxgain, i, jmax);
375 ints_append(&neighbors[nc], jmax);
376 ints_append(&neighbors[nc], i);
377 dout_new[nc] = dout_i + dout_max;
378 matching[i] = matching[jmax] = nc;
379 wgt_new[nc] = wgt[i] + wgt[jmax];
380 deg_intra_new[nc] = deg_intra[i] + deg_intra[jmax] + amax;
381 nc++;
382 } else {
383 fprintf(stderr,"maxgain=%f, merge with existing cluster %d, %d\n",maxgain, i, jc);
384 ints_append(&neighbors[jc], i);
385 dout_new[jc] = dout_i + dout_max;
386 wgt_new[jc] += wgt[i];
387 matching[i] = jc;
388 deg_intra_new[jc] += deg_intra[i] + amax;
389 }
390 mq = mq_max;
391 mq_in = mq_in_max;
392 mq_out = mq_out_max;
393 nclusters--;
394 } else {
395 fprintf(stderr,"gain: %f -- no gain, skip merging node %d\n", maxgain, i);
396 assert(maxgain <= 0);
397 ints_append(&neighbors[nc], i);
398 matching[i] = nc;
399 deg_intra_new[nc] = deg_intra[i];
400 wgt_new[nc] = wgt[i];
401 nc++;
402 }
403
404
405 /* update scaled outdegree of neighbors of i and its merged node/cluster jmax */
406 jc = matching[i];
407 for (size_t l = ints_size(&neighbors[jc]) - 1; l != SIZE_MAX; --l) {
408 mask[ints_get(&neighbors[jc], l)] = n + i;
409 }
410
411 for (size_t l = ints_size(&neighbors[jc]) - 1; l != SIZE_MAX; --l) {
412 k = ints_get(&neighbors[jc], l);
413 for (j = ia[k]; j < ia[k+1]; j++){
414 jj = ja[j];
415 if (mask[jj] == n+i) continue;/* link to within cluster */
416 if ((jc = matching[jj]) == UNMATCHED){
417 if (k == i){
418 dout[jj] += -a[j]/wgt_i + a[j]/(wgt_i + wgt_jmax);
419 } else {
420 dout[jj] += -a[j]/wgt_jmax + a[j]/(wgt_i + wgt_jmax);
421 }
422 } else {
423 if (k == i){
424 dout_new[jc] += -a[j]/wgt_i + a[j]/(wgt_i + wgt_jmax);
425 } else {
426 dout_new[jc] += -a[j]/wgt_jmax + a[j]/(wgt_i + wgt_jmax);
427 }
428 }
429 }
430 }
431
432 }
433
434 fprintf(stderr,"verbose=%d\n",Verbose);
435 if (Verbose) fprintf(stderr,"mq = %f new mq = %f level = %d, n = %d, nc = %d, gain = %g, mq_in = %f, mq_out = %f\n", mq, mq + total_gain,
436 level, n, nc, total_gain, mq_in, mq_out);
437
438#ifdef DEBUG
439 {int ncluster;
440
441 mq = get_mq(A, matching, &ncluster, &mq_in, &mq_out, &dout);
442 fprintf(stderr," mq = %f\n",mq);
443
444 }
445#endif
446
447 if (nc >= 1 && (total_gain > 0 || nc < n)){
448 /* now set up restriction and prolongation operator */
449 SparseMatrix P, R, R0, B, cA;
450 double one = 1.;
452
454 for (i = 0; i < n; i++){
455 jj = matching[i];
457 }
463 if (!B) {
464 free(deg_intra_new);
465 free(wgt_new);
466 free(dout_new);
467 goto RETURN;
468 }
469 cA = SparseMatrix_multiply(B, P);
471 if (!cA) {
472 free(deg_intra_new);
473 free(wgt_new);
474 free(dout_new);
475 goto RETURN;
476 }
477 grid->P = P;
478 level++;
479 cgrid = Multilevel_MQ_Clustering_init(cA, level);
480 deg_intra_new = gv_recalloc(deg_intra_new, n, nc, sizeof(double));
481 wgt_new = gv_recalloc(wgt_new, n, nc, sizeof(double));
482 cgrid->deg_intra = deg_intra_new;
483 cgrid->mq = grid->mq + total_gain;
484 cgrid->wgt = wgt_new;
485 dout_new = gv_recalloc(dout_new, n, nc, sizeof(double));
486 cgrid->dout = dout_new;
487
488 cgrid = Multilevel_MQ_Clustering_establish(cgrid, maxcluster);
489
490 grid->next = cgrid;
491 cgrid->prev = grid;
492 } else {
493 /* no more improvement, stop and final clustering found */
494 for (i = 0; i < n; i++) matching[i] = i;
495
496 free(deg_intra_new);
497 free(wgt_new);
498 free(dout_new);
499 }
500
501 RETURN:
502 for (i = 0; i < n; i++) ints_free(&neighbors[i]);
503 free(neighbors);
504
505 free(deg_inter);
506 free(mask);
507 return grid;
508}
509
511 /* maxcluster is used to specify the maximum number of cluster desired, e.g., maxcluster=10 means that a maximum of 10 clusters
512 is desired. this may not always be realized, and mq may be low when this is specified. Default: maxcluster = 0 */
514 SparseMatrix A = A0;
515
516 if (maxcluster <= 0) maxcluster = A->m;
517 if (!SparseMatrix_is_symmetric(A, false) || A->type != MATRIX_TYPE_REAL){
519 }
521
523
524 if (A != A0) grid->delete_top_level_A = true; // be sure to clean up later
525 return grid;
526}
527
528
529static void hierachical_mq_clustering(SparseMatrix A, int maxcluster,
530 int *nclusters, int **assignment, double *mq){
531 /* find a clustering of vertices by maximize mq
532 A: symmetric square matrix n x n. If real value, value will be used as edges weights, otherwise edge weights are considered as 1.
533 maxcluster: used to specify the maximum number of cluster desired, e.g., maxcluster=10 means that a maximum of 10 clusters
534 . is desired. this may not always be realized, and mq may be low when this is specified. Default: maxcluster = 0
535 nclusters: on output the number of clusters
536 assignment: dimension n. Node i is assigned to cluster "assignment[i]". 0 <= assignment < nclusters
537 */
538
540 int *matching, i;
541 SparseMatrix P;
542 assert(A->m == A->n);
543
544 *mq = 0.;
545
546 grid = Multilevel_MQ_Clustering_new(A, maxcluster);
547
548 /* find coarsest */
549 cgrid = grid;
550 while (cgrid->next){
551 cgrid = cgrid->next;
552 }
553
554 /* project clustering up */
555 double *u = gv_calloc(cgrid->n, sizeof(double));
556 for (i = 0; i < cgrid->n; i++) u[i] = (double) (cgrid->matching)[i];
557 *nclusters = cgrid->n;
558 *mq = cgrid->mq;
559
560 while (cgrid->prev){
561 double *v = NULL;
562 P = cgrid->prev->P;
564 free(u);
565 u = v;
566 cgrid = cgrid->prev;
567 }
568
569 if (*assignment){
570 matching = *assignment;
571 } else {
572 matching = gv_calloc(grid->n, sizeof(int));
573 *assignment = matching;
574 }
575 for (i = 0; i < grid->n; i++) (matching)[i] = (int) u[i];
576 free(u);
577
579}
580
581
582
583void mq_clustering(SparseMatrix A, int maxcluster,
584 int *nclusters, int **assignment, double *mq){
585 /* find a clustering of vertices by maximize mq
586 A: symmetric square matrix n x n. If real value, value will be used as edges weights, otherwise edge weights are considered as 1.
587 maxcluster: used to specify the maximum number of cluster desired, e.g., maxcluster=10 means that a maximum of 10 clusters
588 . is desired. this may not always be realized, and mq may be low when this is specified. Default: maxcluster = 0
589 nclusters: on output the number of clusters
590 assignment: dimension n. Node i is assigned to cluster "assignment[i]". 0 <= assignment < nclusters
591 */
593
594 assert(A->m == A->n);
595
596 B = SparseMatrix_symmetrize(A, false);
597
598 if (B == A) {
600 }
601
603
605
606 hierachical_mq_clustering(B, maxcluster, nclusters, assignment, mq);
607
608 if (B != A) SparseMatrix_delete(B);
609
610}
SparseMatrix SparseMatrix_from_coordinate_format(SparseMatrix A)
SparseMatrix SparseMatrix_transpose(SparseMatrix A)
SparseMatrix SparseMatrix_symmetrize(SparseMatrix A, bool pattern_symmetric_only)
SparseMatrix SparseMatrix_coordinate_form_add_entry(SparseMatrix A, int irn, int jcn, const void *val)
bool SparseMatrix_is_symmetric(SparseMatrix A, bool test_pattern_symmetry_only)
void SparseMatrix_multiply_vector(SparseMatrix A, double *v, double **res)
SparseMatrix SparseMatrix_multiply(SparseMatrix A, SparseMatrix B)
void SparseMatrix_delete(SparseMatrix A)
SparseMatrix SparseMatrix_copy(SparseMatrix A)
SparseMatrix SparseMatrix_set_entries_to_real_one(SparseMatrix A)
SparseMatrix SparseMatrix_get_real_adjacency_matrix_symmetrized(SparseMatrix A)
SparseMatrix SparseMatrix_remove_diagonal(SparseMatrix A)
SparseMatrix SparseMatrix_new(int m, int n, int nz, int type, int format)
@ FORMAT_COORD
@ MATRIX_TYPE_REAL
Memory allocation wrappers that exit on failure.
static void * gv_recalloc(void *ptr, size_t old_nmemb, size_t new_nmemb, size_t size)
Definition alloc.h:73
static void * gv_calloc(size_t nmemb, size_t size)
Definition alloc.h:26
static void * gv_alloc(size_t size)
Definition alloc.h:47
#define A(n, t)
Definition expr.h:76
@ UNMATCHED
Definition general.h:85
static int Verbose
Definition gml2gv.c:22
void free(void *)
#define SIZE_MAX
Definition gmlscan.c:347
node NULL
Definition grammar.y:149
@ grid
Definition gvgen.c:32
#define B
Definition hierarchy.c:117
#define DEFINE_LIST(name, type)
Definition list.h:26
void mq_clustering(SparseMatrix A, int maxcluster, int *nclusters, int **assignment, double *mq)
Definition mq.c:583
static Multilevel_MQ_Clustering Multilevel_MQ_Clustering_init(SparseMatrix A, int level)
Definition mq.c:154
static void hierachical_mq_clustering(SparseMatrix A, int maxcluster, int *nclusters, int **assignment, double *mq)
Definition mq.c:529
static Multilevel_MQ_Clustering Multilevel_MQ_Clustering_new(SparseMatrix A0, int maxcluster)
Definition mq.c:510
static void Multilevel_MQ_Clustering_delete(Multilevel_MQ_Clustering grid)
Definition mq.c:207
static double get_mq(SparseMatrix A, int *assignment, int *ncluster0, double *mq_in0, double *mq_out0, double **dout0)
Definition mq.c:68
static Multilevel_MQ_Clustering Multilevel_MQ_Clustering_establish(Multilevel_MQ_Clustering grid, int maxcluster)
Definition mq.c:227
#define RETURN(v)
Definition strmatch.c:144
Multilevel_MQ_Clustering prev
Definition mq.h:27
Multilevel_MQ_Clustering next
Definition mq.h:26