![Build Status](https://travis-ci.org/graphology/graphology-metrics.svg)
Graphology metrics
Miscellaneous metrics to be used with graphology
.
Installation
npm install graphology-metrics
Usage
Graph metrics
Node metrics
Density
Computes the density of the given graph.
import {density} from 'graphology-metrics';
import density from 'graphology-metrics/density';
const d = density(graph);
const d = density(order, size);
import {
mixedDensity,
directedDensity,
undirectedDensity,
multiMixedDensity,
multiDirectedDensity,
multiUndirectedDensity
} from 'graphology-metric/density';
const d = undirectedDensity(mixedGraph);
Arguments
Either:
- graph Graph: target graph.
Or:
- order number: number of nodes in the graph.
- size number: number of edges in the graph.
Modularity
Computes the modularity, given the graph and a partitioning
import {modularity} from 'graphology-metrics';
import modularity from 'graphology-metrics/modularity';
const Q = modularity(graph);
const Q = modularity(graph, {
communities: {'1': 0, '2': 0, '3': 1, '4': 1, '5': 1}
});
Arguments
- graph Graph: target graph.
- options ?object: options:
- communities ?object: object mapping nodes to their respective communities.
- attributes ?object: attributes' names:
- community ?string [
community
]: name of the nodes' community attribute in case we need to read them from the graph itself. - weight ?string [
weight
]: name of the edges' weight attribute.
Centrality
Degree centrality
Computes the degree centrality for every node.
import degreeCentrality from 'graphology-metrics/centrality/degree';
import {
degreeCentrality,
inDegreeCentrality,
outDegreeCentrality
} from 'graphology-metrics/centrality/degree';
const centralities = degreeCentrality(graph);
degreeCentrality.assign(graph);
degreeCentrality.assign(graph, {attribute: 'myCentrality'});
Arguments
- graph Graph: target graph.
- options ?object: options:
- attribute ?string: name of the centrality attribute.