graphology-metrics
Advanced tools
Comparing version 1.8.0-alpha1 to 1.8.0-alpha2
@@ -8,6 +8,8 @@ /** | ||
var isGraph = require('graphology-utils/is-graph'), | ||
unweightedShortestPath = require('graphology-shortest-path/unweighted'), | ||
dijkstraShotestPath = require('graphology-shortest-path/dijkstra'), | ||
lib = require('graphology-shortest-path/indexed-brandes'), | ||
defaults = require('lodash/defaults'); | ||
var createUnweightedIndexedBrandes = lib.createUnweightedIndexedBrandes, | ||
createDijkstraIndexedBrandes = lib.createDijkstraIndexedBrandes; | ||
/** | ||
@@ -42,4 +44,2 @@ * Defaults. | ||
var centralities = {}; | ||
// Solving options | ||
@@ -53,8 +53,9 @@ options = defaults({}, options, DEFAULTS); | ||
/* eslint no-unused-vars: 0 */ | ||
var shortestPath = unweightedShortestPath.createIndexedBrandes(graph); | ||
var brandes = weighted ? | ||
createDijkstraIndexedBrandes(graph, weightAttribute) : | ||
createUnweightedIndexedBrandes(graph); | ||
var nodes = graph.nodes(), | ||
node, | ||
result, | ||
var N = graph.order; | ||
var result, | ||
S, | ||
@@ -66,3 +67,2 @@ P, | ||
j, | ||
l, | ||
m, | ||
@@ -72,14 +72,9 @@ v, | ||
var delta = {}; | ||
var delta = new Float64Array(N), | ||
centralities = new Float64Array(N); | ||
// Initializing centralities | ||
for (i = 0, l = nodes.length; i < l; i++) | ||
centralities[nodes[i]] = 0; | ||
// Iterating over each node | ||
for (i = 0, l = nodes.length; i < l; i++) { | ||
node = nodes[i]; | ||
for (i = 0; i < N; i++) { | ||
result = brandes(i); | ||
result = shortestPath(node); | ||
S = result[0]; | ||
@@ -104,3 +99,3 @@ P = result[1]; | ||
if (w !== node) | ||
if (w !== i) | ||
centralities[w] += delta[w]; | ||
@@ -111,7 +106,6 @@ } | ||
// Rescaling | ||
var n = graph.order, | ||
scale = null; | ||
var scale = null; | ||
if (normalized) | ||
scale = n <= 2 ? null : (1 / ((n - 1) * (n - 2))); | ||
scale = N <= 2 ? null : (1 / ((N - 1) * (N - 2))); | ||
else | ||
@@ -121,12 +115,10 @@ scale = graph.type === 'undirected' ? 0.5 : null; | ||
if (scale !== null) { | ||
for (node in centralities) | ||
centralities[node] *= scale; | ||
for (i = 0; i < N; i++) | ||
centralities[i] *= scale; | ||
} | ||
if (assign) { | ||
for (node in centralities) | ||
graph.setNodeAttribute(node, centralityAttribute, centralities[node]); | ||
} | ||
if (assign) | ||
return brandes.index.assign(centralityAttribute, centralities); | ||
return centralities; | ||
return brandes.index.collect(centralities); | ||
} | ||
@@ -133,0 +125,0 @@ |
{ | ||
"name": "graphology-metrics", | ||
"version": "1.8.0-alpha1", | ||
"version": "1.8.0-alpha2", | ||
"description": "Miscellaneous graph metrics for graphology.", | ||
@@ -21,2 +21,3 @@ "main": "index.js", | ||
"keywords": [ | ||
"betweenness", | ||
"centrality", | ||
@@ -60,6 +61,9 @@ "density", | ||
] | ||
}, | ||
"globals": { | ||
"Float64Array": true | ||
} | ||
}, | ||
"dependencies": { | ||
"graphology-shortest-path": "1.1.0-alpha1", | ||
"graphology-shortest-path": "^1.1.1", | ||
"graphology-types": "^0.15.4", | ||
@@ -66,0 +70,0 @@ "graphology-utils": "^1.6.1", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
47151
1055
+ Added@yomguithereal/helpers@1.1.1(transitive)
+ Addedgraphology-indices@0.16.6(transitive)
+ Addedgraphology-shortest-path@1.5.2(transitive)
+ Addedgraphology-types@0.24.8(transitive)
+ Addedgraphology-utils@2.5.2(transitive)
+ Addedmnemonist@0.38.50.39.8(transitive)
+ Addedobliterator@2.0.4(transitive)
- Removedgraphology-shortest-path@1.1.0-alpha1(transitive)
- Removedgraphology-types@0.16.00.24.7(transitive)
- Removedmnemonist@0.32.0(transitive)
- Removedobliterator@1.6.1(transitive)