Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
graphology-metrics
Advanced tools
Miscellaneous metrics to be used with graphology
.
npm install graphology-metrics
Graph metrics
Node metrics
Computes the density of the given graph.
import {density} from 'graphology-metrics';
import density from 'graphology-metrics/density';
// Passing a graph instance
const d = density(graph);
// Passing the graph's order & size
const d = density(order, size);
// Or to force the kind of density being computed
import {
mixedDensity,
directedDensity,
undirectedDensity,
multiMixedDensity,
multiDirectedDensity,
multiUndirectedDensity
} from 'graphology-metric/density';
const d = undirectedDensity(mixedGraph);
Arguments
Either:
Or:
Computes the extent - min, max - of a node or edge's attribute.
import extent from 'graphology-metrics/extent';
// Retrieving a single node attribute's extent
extent(graph, 'size');
>>> [1, 34]
// Retrieving multiple node attributes' extents
extent(graph, ['x', 'y']);
>>> {x: [-4, 3], y: [-34, 56]}
// For edges
extent.edgeExtent(graph, 'weight');
>>> [0, 5.7]
Arguments
Computes the modularity, given the graph and a partitioning
import {modularity} from 'graphology-metrics';
// Alternatively, to load only the relevant code:
import modularity from 'graphology-metrics/modularity';
// Simplest way
const Q = modularity(graph);
// If community mapping is external to the graph
const Q = modularity(graph, {
communities: {'1': 0, '2': 0, '3': 1, '4': 1, '5': 1}
});
Arguments
community
]: name of the nodes' community attribute in case we need to read them from the graph itself.weight
]: name of the edges' weight attribute.Computes the betweenness centrality for every node.
import betweennessCentrality from 'graphology-metrics/centrality/betweenness';
// To compute centrality for every node:
const centrality = betweennessCentrality(graph);
// To compute weighted betweenness centrality
const centrality = betweennessCentrality(graph, {weighted: true});
// To directly map the result onto nodes' attributes (`beetweennessCentrality`):
betweennessCentrality.assign(graph);
// To directly map the result onto a custom attribute:
betweennessCentrality.assign(graph, {attributes: 'myCentrality'});
Arguments
betweennessCentrality
]: Name of the centrality attribute to assign.true
]: should the result be normalized?false
]: should we compute the weighted betweenness centrality?Computes the degree centrality for every node.
import degreeCentrality from 'graphology-metrics/centrality/degree';
// Or to load more specific functions:
import {
degreeCentrality,
inDegreeCentrality,
outDegreeCentrality
} from 'graphology-metrics/centrality/degree';
// To compute degree centrality for every node:
const centrality = degreeCentrality(graph);
// To directly map the result onto nodes' attributes (`degreeCentrality`):
degreeCentrality.assign(graph);
// To directly map the result onto a custom attribute:
degreeCentrality.assign(graph, {attribute: 'myCentrality'});
Arguments
FAQs
Miscellaneous graph metrics for graphology.
The npm package graphology-metrics receives a total of 24,855 weekly downloads. As such, graphology-metrics popularity was classified as popular.
We found that graphology-metrics demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.