Skip to content

Instantly share code, notes, and snippets.

@mjbommar
Created August 11, 2009 22:02
Show Gist options
  • Save mjbommar/166149 to your computer and use it in GitHub Desktop.
Save mjbommar/166149 to your computer and use it in GitHub Desktop.
//Calculate merge matrix
igraph_community_edge_betweenness(&graph, &result, NULL, &M, NULL, IGRAPH_DIRECTED);
// Initialize max modularity
maxmod = 0.0;
// Determine max number of steps to merge
maxsteps = igraph_matrix_nrow(&M) < igraph_vcount(&graph) - 1) ? igraph_matrix_nrow(&M) : igraph_vcount(&graph) - 1;
// Compare merge modularities and keep only the best
for (steps=1; steps < maxsteps; steps++) {
igraph_community_to_membership(&M, igraph_vcount(&graph), steps, &membership, 0);
igraph_modularity(&graph, &membership, &modularity, 0);
if (modularity > maxmod) {
igraph_vector_update(&maxmembership, &membership);
maxmod = modularity;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment