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