mq.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. #pragma once
  11. #include <stdbool.h>
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. typedef struct Multilevel_MQ_Clustering_struct *Multilevel_MQ_Clustering;
  16. struct Multilevel_MQ_Clustering_struct {
  17. int level;/* 0, 1, ... */
  18. int n;
  19. SparseMatrix A; /* n x n matrix */
  20. SparseMatrix P;
  21. Multilevel_MQ_Clustering next;
  22. Multilevel_MQ_Clustering prev;
  23. bool delete_top_level_A;
  24. int *matching; /* dimension n. matching[i] is the clustering assignment of node i */
  25. /*
  26. . |E(i,i)| |E(i,j)|
  27. MQ/2 = (1/k) * \sum_{i=1...k} ------------ - (1/(k*(k-1))) * \sum_{i<j} -------------------
  28. . |V(i)|^2 |V(i)|*|V(j)|
  29. . = mq_in/k - mq_out/(k*(k-1))
  30. */
  31. double mq;
  32. double mq_in, mq_out;/* mqs(A) = deg_in(A)/|A|^2 - deg_out(A)/|A|/(|V|-|A|) */
  33. int ncluster; /* number of clusters */
  34. double *deg_intra;/* dimension n. deg[i] equal to the sum of edge weights within cluster i */
  35. double *dout;/* dimension n, dout[i] = \sum_{j -- i} a(i,j)/|j| is the scaled sum of outdegree */
  36. double *wgt; /* total vertex weight each coarse grid vertex represent */
  37. };
  38. /* find a clustering of vertices by maximize modularity quality
  39. A: symmetric square matrix n x n. If real value, value will be used as edges weights, otherwise edge weights are considered as 1.
  40. maxcluster: used to specify the maximum number of cluster desired, e.g., maxcluster=10 means that a maximum of 10 clusters
  41. . is desired. this may not always be realized, and modularity quality may be low when this is specified. Default: maxcluster = 0 (no limit)
  42. nclusters: on output the number of clusters
  43. assignment: dimension n. Node i is assigned to cluster "assignment[i]". 0 <= assignment < nclusters.
  44. . If *assignment = NULL on entry, it will be allocated. Otherwise used.
  45. mq: achieve modularity
  46. */
  47. void mq_clustering(SparseMatrix A, int maxcluster,
  48. int *nclusters, int **assignment, double *mq);
  49. #ifdef __cplusplus
  50. }
  51. #endif