clustering.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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_Modularity_Clustering_struct *Multilevel_Modularity_Clustering;
  16. struct Multilevel_Modularity_Clustering_struct {
  17. int level;/* 0, 1, ... */
  18. int n;
  19. SparseMatrix A; /* n x n matrix */
  20. SparseMatrix P;
  21. Multilevel_Modularity_Clustering next;
  22. Multilevel_Modularity_Clustering prev;
  23. bool delete_top_level_A;
  24. int *matching; /* dimension n. matching[i] is the clustering assignment of node i */
  25. double modularity;
  26. double deg_total; /* total edge weights, including self-edges */
  27. double *deg;/* dimension n. deg[i] equal to the sum of edge weights connected to vertex i. I.e., sum of row i */
  28. bool agglomerate_regardless; ///< whether to agglomerate nodes even if this
  29. ///< causes modularity reduction. This is used if
  30. ///< we want to force agglomeration so as to get
  31. ///< fewer clusters
  32. };
  33. enum {CLUSTERING_MODULARITY = 0, CLUSTERING_MQ};
  34. /* find a clustering of vertices by maximize modularity
  35. A: symmetric square matrix n x n. If real value, value will be used as edges weights, otherwise edge weights are considered as 1.
  36. inplace: whether A can e modified. If true, A will be modified by removing diagonal.
  37. maxcluster: used to specify the maximum number of cluster desired, e.g., maxcluster=10 means that a maximum of 10 clusters
  38. . is desired. this may not always be realized, and modularity may be low when this is specified. Default: maxcluster = 0 (no limit)
  39. nclusters: on output the number of clusters
  40. assignment: dimension n. Node i is assigned to cluster "assignment[i]". 0 <= assignment < nclusters.
  41. . If *assignment = NULL on entry, it will be allocated. Otherwise used.
  42. modularity: achieve modularity
  43. */
  44. void modularity_clustering(SparseMatrix A, bool inplace, int maxcluster,
  45. int *nclusters, int **assignment, double *modularity);
  46. #ifdef __cplusplus
  47. }
  48. #endif