ngraph.louvain
Given a graph instance detects clusters using the Louvain Method.
Demo
usage
var graph = createAGraph();
var detectClusters = require('ngraph.louvain');
var clusters = detectClusters(graph);
graph.forEachNode(function(node) {
console.log(node.id, clusters.getClass(node.id));
});
Note: Louvain method is hierarchical. I.e. you should be able to get coarser
graphs based on detected communities. By default ngraph.louvain
does not implement hierarchies, yet you can easily achieve it by following:
var coarsen = require('ngraph.coarsen');
var detectClusters = require('ngraph.louvain');
var clusters = detectClusters(graph);
while(clusters.canCoarse()) {
graph = coarsen(graph, clusters);
clusters = detectClusters(graph);
}
install
npm install ngraph.louvain
see also
license
MIT