WARNING : The content of this repository has been split and transferred to :
Miscellaneous metrics and algorithms around community detection to be used with graphology
.
npm install graphology-communities
Metrics
Algorithms
Compute the modularity, given the graph and a partitioning
import {modularity} from 'graphology-communities';
// Alternatively, to load only the relevant code:
import modularity from 'graphology-communities/modularity';
const Q = modularity(graph, {'1': 0, '2': 0, '3': 1, '4': 1, '5': 1});
Arguments
- graph Graph: target graph.
- partitioning Object: object mapping a community index to a object.
- options ?object: options:
- attributes ?object: attributes' names:
- weight ?string [
weight
]: name of the edges' weight attribute.
- weight ?string [
- attributes ?object: attributes' names:
Execute the Louvain algorithm to detect a good partitioning of the graph in several communities. The original publication of the algorithm can be found there.
import {louvain} from 'graphology-communities';
// Alternatively, to load only the relevant code:
import louvain from 'graphology-communities/louvain';
const partitioning = louvain(graph); // Return a mapping object like {'1': 0, '2': 0, ..., 5: '1'}
// To directly map the result to nodes' attributes
louvain.assign(graph); // By default, assigned to the `community` attribute
lovuain.assign(graph, {attributes: {community: 'foo'}}); // Assigned to the `foo` attribute
Arguments
- graph Graph: graph to which you want to get the best partitioning.
- options ?object: options:
- attributes ?object: attributes' names:
- weight ?string [
weight
]: name of the edges' weight attribute. - community ?string [
community
]: name of the node attribute holding community information
- weight ?string [
- attributes ?object: attributes' names: