All Projects → anvaka → ngraph.louvain

anvaka / ngraph.louvain

Licence: MIT License
Given a graph instance detects communities using the Louvain Method

Programming Languages

javascript
184084 projects - #8 most used programming language

ngraph.louvain

Given a graph instance detects clusters using the Louvain Method. Demo

usage

// Let's say you have an ngraph instance:
var graph = createAGraph();

// To detect clusters:
var detectClusters = require('ngraph.louvain');
var clusters = detectClusters(graph);

// now you can iterate over each node and get it's community (aka class):
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);
  // this will give you next level in the hierarchy
}

install

npm install ngraph.louvain

see also

license

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].