Graphviz 15.1.1~dev.20260628.0906
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 v2.0
5 * which accompanies this distribution, and is available at
6 * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.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#include "config.h"
59
60#define STANDALONE
61#include <assert.h>
62#include <limits.h>
63#include <sparse/general.h>
64#include <sparse/SparseMatrix.h>
65#include <sparse/mq.h>
66#include <stdbool.h>
67#include <stddef.h>
68#include <string.h>
69#include <util/alloc.h>
70#include <util/list.h>
71
72static double get_mq(SparseMatrix A, int *assignment, int *ncluster0, double *mq_in0, double *mq_out0, double **dout0){
73 /* given a symmetric matrix representation of a graph and an assignment of nodes into clusters, calculate the modularity quality.
74 assignment: assignment[i] gives the cluster assignment of node i. 0 <= assignment[i] < ncluster.
75 ncluster: number of clusters
76 mq_in: the part of MQ to do with intra-cluster edges, before divide by 1/k
77 mq_out: the part of MQ to do with inter-cluster edges, before divide by 1/(k*(k-1))
78 mq = 2*(mq_in/k - mq_out/(k*(k-1)));
79 */
80 int ncluster = 0;
81 const size_t n = A->m;
82 bool test_pattern_symmetry_only = false;
83 int *counts, *ia = A->ia, *ja = A->ja, k, j, jj;
84 double mq_in = 0, mq_out = 0, *a = NULL, Vi, Vj;
85 int c;
86 double *dout;
87
88
89 assert(SparseMatrix_is_symmetric(A, test_pattern_symmetry_only));
90 (void)test_pattern_symmetry_only;
91 assert((size_t)A->n == n);
92 if (A->type == MATRIX_TYPE_REAL) a = A->a;
93
94 counts = gv_calloc(n, sizeof(int));
95
96 for (size_t i = 0; i < n; i++){
97 assert(assignment[i] >= 0 && (size_t)assignment[i] < n);
98 if (counts[assignment[i]] == 0) ncluster++;
99 counts[assignment[i]]++;
100 }
101 k = ncluster;
102 assert(ncluster <= (int)n);
103
104 for (size_t i = 0; i < n; i++){
105 assert(assignment[i] < ncluster);
106 c = assignment[i];
107 Vi = counts[c];
108 for (j = ia[i] ; j < ia[i+1]; j++){
109 /* ASSUME UNDIRECTED */
110 jj = ja[j];
111 if (jj >= (int)i) continue;
112 assert(assignment[jj] < ncluster);
113 Vj = counts[assignment[jj]];
114 if (assignment[jj] == c){
115 if (a) {
116 mq_in += a[j]/(Vi*Vi);
117 } else {
118 mq_in += 1./(Vi*Vi);
119 }
120 } else {
121 if (a) {
122 mq_out += a[j]/(Vi*Vj);
123 } else {
124 mq_out += 1./(Vi*Vj);
125 }
126 }
127
128 }
129 }
130
131 /* calculate scaled out degree */
132 dout = gv_calloc(n, sizeof(double));
133 for (size_t i = 0; i < n; i++){
134 for (j = ia[i]; j < ia[i+1]; j++){
135 jj = ja[j];
136 if (jj == (int)i) continue;
137 if (a){
138 dout[i] += a[j]/(double) counts[assignment[jj]];
139 } else {
140 dout[i] += 1./(double) counts[assignment[jj]];
141 }
142 }
143 }
144
145 *ncluster0 = k;
146 *mq_in0 = mq_in;
147 *mq_out0 = mq_out;
148 *dout0 = dout;
149 free(counts);
150
151 if (k > 1){
152 return 2*(mq_in/k - mq_out/(k*(k-1)));
153 } else {
154 return 2*mq_in;
155 }
156}
157
160 int n = A->n, i;
161 int *matching;
162
163 assert(A->type == MATRIX_TYPE_REAL);
164 assert(SparseMatrix_is_symmetric(A, false));
165
166 if (!A) return NULL;
167 assert(A->m == (size_t)n);
169 grid->level = level;
170 grid->n = n;
171 grid->A = A;
172 grid->P = NULL;
173 grid->next = NULL;
174 grid->prev = NULL;
175 grid->delete_top_level_A = false;
176 matching = grid->matching = gv_calloc(n, sizeof(double));
177 grid->deg_intra = NULL;
178 grid->dout = NULL;
179 grid->wgt = NULL;
180
181 if (level == 0){
182 double mq = 0, mq_in, mq_out;
183 int ncluster;
184 double *deg_intra, *wgt, *dout;
185
186 grid->deg_intra = gv_calloc(n, sizeof(double));
187 deg_intra = grid->deg_intra;
188
189 grid->wgt = gv_calloc(n, sizeof(double));
190 wgt = grid->wgt;
191
192 for (i = 0; i < n; i++){
193 deg_intra[i] = 0;
194 wgt[i] = 1.;
195 }
196 for (i = 0; i < n; i++) matching[i] = i;
197 mq = get_mq(A, matching, &ncluster, &mq_in, &mq_out, &dout);
198 fprintf(stderr,"ncluster = %d, mq = %f\n", ncluster, mq);
199 grid->mq = mq;
200 grid->mq_in = mq_in;
201 grid->mq_out = mq_out;
202 grid->dout = dout;
203 grid->ncluster = ncluster;
204
205 }
206
207
208 return grid;
209}
210
212 if (!grid) return;
213 if (grid->A){
214 if (grid->level == 0) {
215 if (grid->delete_top_level_A) SparseMatrix_delete(grid->A);
216 } else {
218 }
219 }
221 free(grid->matching);
222 free(grid->deg_intra);
223 free(grid->dout);
224 free(grid->wgt);
226 free(grid);
227}
228
230 int *matching = grid->matching;
231 SparseMatrix A = grid->A;
232 int n = grid->n, level = grid->level, nc = 0, nclusters = n;
233 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;
234 int *ia = A->ia, *ja = A->ja;
235 double amax = 0;
236 double *deg_intra = grid->deg_intra, *wgt = grid->wgt;
237 int i, j, k, jj, jc, jmax;
238 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;
239 double maxgain = 0;
240 double total_gain = 0;
241
242 LIST(int) *neighbors = gv_calloc(n, sizeof(neighbors[0]));
243
244 mq = grid->mq;
245 mq_in = grid->mq_in;
246 mq_out = grid->mq_out;
247
248 double *deg_intra_new = gv_calloc(n, sizeof(double));
249 double *wgt_new = gv_calloc(n, sizeof(double));
250 double *deg_inter = gv_calloc(n, sizeof(double));
251 int *mask = gv_calloc(n, sizeof(int));
252 double *dout_new = gv_calloc(n, sizeof(double));
253 for (i = 0; i < n; i++) mask[i] = -1;
254
255 assert(n == A->n);
256 for (i = 0; i < n; i++) matching[i] = UNMATCHED;
257
258 /* gain in merging node A into cluster B is
259 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
260 . = mq_in - deg_intra(A)/|A|^2 - deg_intra(B)/|B|^2 + (deg_intra(A)+deg_intra(B)+a(A,B))/(|A|+|B|)^2
261
262 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)|)
263 . + \sum_{C connected to A or B, C!=A, C!=B} (|E(A,C)|+|E(B,C)|)/(|V(C)|*(|V(A)|+|V(B)|)
264 . = 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|)
265 . + \sum_{C connected to A or B, C!=A, C!=B} (a(A,C)+a(B,C))/(|C|*(|A|+|B|))
266 Denote:
267 dout(i) = \sum_{j -- i} a(i,j)/|j|
268 then
269
270 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)|)
271 . + \sum_{C connected to A or B, C!=A, C!=B} (|E(A,C)|+|E(B,C)|)/(|V(C)|*(|V(A)|+|V(B)|)
272 . = mq_out + a(A,B)/(|A|*|B|)-dout(A)/|A| - dout(B)/|B|
273 . + (dout(A)+dout(B))/(|A|+|B|) - (a(A,B)/|A|+a(A,B)/|B|)/(|A|+|B|)
274 . = mq_out -dout(A)/|A| - dout(B)/|B| + (dout(A)+dout(B))/(|A|+|B|)
275 after merging A and B into cluster AB,
276 dout(AB) = dout(A) + dout(B);
277 dout(C) := dout(C) - a(A,C)/|A| - a(B,C)/|B| + a(A,C)/(|A|+|B|) + a(B, C)/(|A|+|B|)
278
279 mq_new = mq_in_new/(k-1) - mq_out_new/((k-1)*(k-2))
280 gain = mq_new - mq
281 */
282 double *a = A->a;
283 for (i = 0; i < n; i++){
284 if (matching[i] != UNMATCHED) continue;
285 /* accumulate connections between i and clusters */
286 for (j = ia[i]; j < ia[i+1]; j++){
287 jj = ja[j];
288 if (jj == i) continue;
289 if ((jc=matching[jj]) != UNMATCHED){
290 if (mask[jc] != i) {
291 mask[jc] = i;
292 deg_inter[jc] = a[j];
293 } else {
294 deg_inter[jc] += a[j];
295 }
296 }
297 }
298 deg_in_i = deg_intra[i];
299 wgt_i = wgt[i];
300 dout_i = dout[i];
301
302 maxgain = 0;
303 jmax = -1;
304 for (j = ia[i]; j < ia[i+1]; j++){
305 jj = ja[j];
306 if (jj == i) continue;
307 jc = matching[jj];
308 if (jc == UNMATCHED){
309 a_ij = a[j];
310 wgt_j = wgt[jj];
311 deg_in_j = deg_intra[jj];
312 dout_j = dout[jj];
313 } else if (deg_inter[jc] < 0){
314 continue;
315 } else {
316 a_ij = deg_inter[jc];
317 wgt_j = wgt_new[jc];
318 deg_inter[jc] = -1; // so that we do not redo the calculation when we hit another neighbor in cluster jc
319 deg_in_j = deg_intra_new[jc];
320 dout_j = dout_new[jc];
321 }
322
323 mq_in_new = mq_in - deg_in_i/pow(wgt_i, 2) - deg_in_j/pow(wgt_j,2)
324 + (deg_in_i + deg_in_j + a_ij)/pow(wgt_i + wgt_j,2);
325
326 mq_out_new = mq_out - dout_i/wgt_i - dout_j/wgt_j + (dout_i + dout_j)/(wgt_i + wgt_j);
327
328 if (nclusters > 2){
329 mq_new = 2*(mq_in_new/(nclusters - 1) - mq_out_new/((nclusters - 1)*(nclusters - 2)));
330 } else {
331 mq_new = 2*mq_in_new/(nclusters - 1);
332 }
333
334#ifdef DEBUG
335 {int ncluster;
336 double mq2, mq_in2, mq_out2, *dout2;
337 int nc2 = nc;
338 int *matching2 = gv_calloc(A->m, sizeof(int));
339 memcpy(matching2, matching, sizeof(double)*A->m);
340 if (jc != UNMATCHED) {
341 matching2[i] = jc;
342 } else {
343 matching2[i] = nc2;
344 matching2[jj] = nc2;
345 nc2++;
346 }
347 for (k = 0; k < n; k++) if (matching2[k] == UNMATCHED) matching2[k] =nc2++;
348 mq2 = get_mq(A, matching2, &ncluster, &mq_in2, &mq_out2, &dout2);
349 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);
350
351 mq_new = mq2;
352
353 }
354#endif
355
356 gain = mq_new - mq;
357 if (Verbose) fprintf(stderr,"gain in merging node %d with node %d = %f-%f = %f\n", i, jj, mq, mq_new, gain);
358 if (j == ia[i] || gain > maxgain){
359 maxgain = gain;
360 jmax = jj;
361 amax = a_ij;
362 dout_max = dout_j;
363 wgt_jmax = wgt_j;
364 mq_max = mq_new;
365 mq_in_max = mq_in_new;
366 mq_out_max = mq_out_new;
367 }
368
369 }
370
371 /* now merge i and jmax */
372 if (maxgain > 0 || (nc >= 1 && nc > maxcluster)){
373 total_gain += maxgain;
374 jc = matching[jmax];
375 if (jc == UNMATCHED){
376 fprintf(stderr, "maxgain=%f, merge %d, %d\n",maxgain, i, jmax);
377 LIST_APPEND(&neighbors[nc], jmax);
378 LIST_APPEND(&neighbors[nc], i);
379 dout_new[nc] = dout_i + dout_max;
380 matching[i] = matching[jmax] = nc;
381 wgt_new[nc] = wgt[i] + wgt[jmax];
382 deg_intra_new[nc] = deg_intra[i] + deg_intra[jmax] + amax;
383 nc++;
384 } else {
385 fprintf(stderr,"maxgain=%f, merge with existing cluster %d, %d\n",maxgain, i, jc);
386 LIST_APPEND(&neighbors[jc], i);
387 dout_new[jc] = dout_i + dout_max;
388 wgt_new[jc] += wgt[i];
389 matching[i] = jc;
390 deg_intra_new[jc] += deg_intra[i] + amax;
391 }
392 mq = mq_max;
393 mq_in = mq_in_max;
394 mq_out = mq_out_max;
395 nclusters--;
396 } else {
397 fprintf(stderr,"gain: %f -- no gain, skip merging node %d\n", maxgain, i);
398 assert(maxgain <= 0);
399 LIST_APPEND(&neighbors[nc], i);
400 matching[i] = nc;
401 deg_intra_new[nc] = deg_intra[i];
402 wgt_new[nc] = wgt[i];
403 nc++;
404 }
405
406
407 /* update scaled outdegree of neighbors of i and its merged node/cluster jmax */
408 jc = matching[i];
409 for (size_t l = LIST_SIZE(&neighbors[jc]) - 1; l != SIZE_MAX; --l) {
410 mask[LIST_GET(&neighbors[jc], l)] = n + i;
411 }
412
413 for (size_t l = LIST_SIZE(&neighbors[jc]) - 1; l != SIZE_MAX; --l) {
414 k = LIST_GET(&neighbors[jc], l);
415 for (j = ia[k]; j < ia[k+1]; j++){
416 jj = ja[j];
417 if (mask[jj] == n+i) continue;/* link to within cluster */
418 if ((jc = matching[jj]) == UNMATCHED){
419 if (k == i){
420 dout[jj] += -a[j]/wgt_i + a[j]/(wgt_i + wgt_jmax);
421 } else {
422 dout[jj] += -a[j]/wgt_jmax + a[j]/(wgt_i + wgt_jmax);
423 }
424 } else {
425 if (k == i){
426 dout_new[jc] += -a[j]/wgt_i + a[j]/(wgt_i + wgt_jmax);
427 } else {
428 dout_new[jc] += -a[j]/wgt_jmax + a[j]/(wgt_i + wgt_jmax);
429 }
430 }
431 }
432 }
433
434 }
435
436 fprintf(stderr,"verbose=%d\n",Verbose);
437 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,
438 level, n, nc, total_gain, mq_in, mq_out);
439
440#ifdef DEBUG
441 {int ncluster;
442
443 mq = get_mq(A, matching, &ncluster, &mq_in, &mq_out, &dout);
444 fprintf(stderr," mq = %f\n",mq);
445
446 }
447#endif
448
449 if (nc >= 1 && (total_gain > 0 || nc < n)){
450 /* now set up restriction and prolongation operator */
451 SparseMatrix P, R, R0, B, cA;
452 double one = 1.;
454
455 R0 = SparseMatrix_new((size_t)nc, n, 1, MATRIX_TYPE_REAL, FORMAT_COORD);
456 for (i = 0; i < n; i++){
457 jj = matching[i];
459 }
465 if (!B) {
466 free(deg_intra_new);
467 free(wgt_new);
468 free(dout_new);
469 goto RETURN;
470 }
471 cA = SparseMatrix_multiply(B, P);
473 if (!cA) {
474 free(deg_intra_new);
475 free(wgt_new);
476 free(dout_new);
477 goto RETURN;
478 }
479 grid->P = P;
480 level++;
481 cgrid = Multilevel_MQ_Clustering_init(cA, level);
482 deg_intra_new = gv_recalloc(deg_intra_new, n, nc, sizeof(double));
483 wgt_new = gv_recalloc(wgt_new, n, nc, sizeof(double));
484 cgrid->deg_intra = deg_intra_new;
485 cgrid->mq = grid->mq + total_gain;
486 cgrid->wgt = wgt_new;
487 dout_new = gv_recalloc(dout_new, n, nc, sizeof(double));
488 cgrid->dout = dout_new;
489
490 cgrid = Multilevel_MQ_Clustering_establish(cgrid, maxcluster);
491
492 grid->next = cgrid;
493 cgrid->prev = grid;
494 } else {
495 /* no more improvement, stop and final clustering found */
496 for (i = 0; i < n; i++) matching[i] = i;
497
498 free(deg_intra_new);
499 free(wgt_new);
500 free(dout_new);
501 }
502
503 RETURN:
504 for (i = 0; i < n; i++) LIST_FREE(&neighbors[i]);
505 free(neighbors);
506
507 free(deg_inter);
508 free(mask);
509 return grid;
510}
511
513 /* maxcluster is used to specify the maximum number of cluster desired, e.g., maxcluster=10 means that a maximum of 10 clusters
514 is desired. this may not always be realized, and mq may be low when this is specified. Default: maxcluster = 0 */
516 SparseMatrix A = A0;
517
518 if (maxcluster <= 0) maxcluster = (int)A->m;
519 if (!SparseMatrix_is_symmetric(A, false) || A->type != MATRIX_TYPE_REAL){
521 }
523
525
526 if (A != A0) grid->delete_top_level_A = true; // be sure to clean up later
527 return grid;
528}
529
530
531static void hierachical_mq_clustering(SparseMatrix A, int maxcluster,
532 int *nclusters, int **assignment, double *mq){
533 /* find a clustering of vertices by maximize mq
534 A: symmetric square matrix n x n. If real value, value will be used as edges weights, otherwise edge weights are considered as 1.
535 maxcluster: used to specify the maximum number of cluster desired, e.g., maxcluster=10 means that a maximum of 10 clusters
536 . is desired. this may not always be realized, and mq may be low when this is specified. Default: maxcluster = 0
537 nclusters: on output the number of clusters
538 assignment: dimension n. Node i is assigned to cluster "assignment[i]". 0 <= assignment < nclusters
539 */
540
542 int *matching, i;
543 SparseMatrix P;
544 assert(A->m == (size_t)A->n);
545
546 *mq = 0.;
547
548 grid = Multilevel_MQ_Clustering_new(A, maxcluster);
549
550 /* find coarsest */
551 cgrid = grid;
552 while (cgrid->next){
553 cgrid = cgrid->next;
554 }
555
556 /* project clustering up */
557 double *u = gv_calloc(cgrid->n, sizeof(double));
558 for (i = 0; i < cgrid->n; i++) u[i] = (double) (cgrid->matching)[i];
559 *nclusters = cgrid->n;
560 *mq = cgrid->mq;
561
562 while (cgrid->prev){
563 double *v = NULL;
564 P = cgrid->prev->P;
566 free(u);
567 u = v;
568 cgrid = cgrid->prev;
569 }
570
571 if (*assignment){
572 matching = *assignment;
573 } else {
574 matching = gv_calloc(grid->n, sizeof(int));
575 *assignment = matching;
576 }
577 for (i = 0; i < grid->n; i++) (matching)[i] = (int) u[i];
578 free(u);
579
581}
582
583
584
585void mq_clustering(SparseMatrix A, int maxcluster,
586 int *nclusters, int **assignment, double *mq){
587 /* find a clustering of vertices by maximize mq
588 A: symmetric square matrix n x n. If real value, value will be used as edges weights, otherwise edge weights are considered as 1.
589 maxcluster: used to specify the maximum number of cluster desired, e.g., maxcluster=10 means that a maximum of 10 clusters
590 . is desired. this may not always be realized, and mq may be low when this is specified. Default: maxcluster = 0
591 nclusters: on output the number of clusters
592 assignment: dimension n. Node i is assigned to cluster "assignment[i]". 0 <= assignment < nclusters
593 */
595
596 assert(A->m == (size_t)A->n);
597
598 B = SparseMatrix_symmetrize(A, false);
599
600 if (B == A) {
602 }
603
605
606 assert(B->type == MATRIX_TYPE_REAL);
607
608 hierachical_mq_clustering(B, maxcluster, nclusters, assignment, mq);
609
610 if (B != A) SparseMatrix_delete(B);
611
612}
SparseMatrix SparseMatrix_new(size_t m, int n, size_t nz, int type, int format)
SparseMatrix SparseMatrix_from_coordinate_format(SparseMatrix A)
SparseMatrix SparseMatrix_transpose(SparseMatrix A)
SparseMatrix SparseMatrix_symmetrize(SparseMatrix A, bool pattern_symmetric_only)
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_get_real_adjacency_matrix_symmetrized(SparseMatrix A)
SparseMatrix SparseMatrix_remove_diagonal(SparseMatrix A)
@ FORMAT_COORD
#define SparseMatrix_coordinate_form_add_entry(A, irn, jcn, val)
wrap SparseMatrix_coordinate_form_add_entry_ for type safety
@ 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:76
static bool Verbose
Definition gml2gv.c:26
void free(void *)
#define SIZE_MAX
Definition gmlscan.c:347
node NULL
Definition grammar.y:181
@ grid
Definition gvgen.c:34
#define B
Definition hierarchy.c:120
type-generic dynamically expanding list
#define LIST_APPEND(list,...)
Definition list.h:124
#define LIST(type)
Definition list.h:55
#define LIST_SIZE(list)
Definition list.h:80
#define LIST_FREE(list)
Definition list.h:373
#define LIST_GET(list, index)
Definition list.h:159
void mq_clustering(SparseMatrix A, int maxcluster, int *nclusters, int **assignment, double *mq)
Definition mq.c:585
static Multilevel_MQ_Clustering Multilevel_MQ_Clustering_init(SparseMatrix A, int level)
Definition mq.c:158
static void hierachical_mq_clustering(SparseMatrix A, int maxcluster, int *nclusters, int **assignment, double *mq)
Definition mq.c:531
static Multilevel_MQ_Clustering Multilevel_MQ_Clustering_new(SparseMatrix A0, int maxcluster)
Definition mq.c:512
static void Multilevel_MQ_Clustering_delete(Multilevel_MQ_Clustering grid)
Definition mq.c:211
static double get_mq(SparseMatrix A, int *assignment, int *ncluster0, double *mq_in0, double *mq_out0, double **dout0)
Definition mq.c:72
static Multilevel_MQ_Clustering Multilevel_MQ_Clustering_establish(Multilevel_MQ_Clustering grid, int maxcluster)
Definition mq.c:229
#define RETURN(v)
Definition strmatch.c:146
Multilevel_MQ_Clustering prev
Definition mq.h:27
Multilevel_MQ_Clustering next
Definition mq.h:26
size_t m
row dimension