Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

graphology-metrics

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphology-metrics - npm Package Compare versions

Comparing version 1.10.1 to 1.11.0

55

modularity.js

@@ -14,6 +14,2 @@ /**

*
* Note that the current implementation choses to ignore self-loops. It would
* be easy to consider them in the computations but I don't think they were
* intended to be taken into account by the metric.
*
* Regarding the directed version, one has to understand that the undirected

@@ -23,2 +19,15 @@ * version's is basically considering the graph as a directed one where all

*
* There is one exception to this, though: self loops. To conform with density's
* definition, as used in modularity's one, and to keep true to the matrix
* formulation of modularity, one has to note that self-loops only count once
* in both the undirected and directed cases. This means that a k-clique with
* one node having a self-loop will not have the same modularity in the
* undirected and mutual case. Indeed, in both cases the modularity of a
* k-clique with one loop and minus one internal edge should be equal.
*
* This also means that, as with the naive density formula regarding loops,
* one should increment M when considering a loop. Also, to remain coherent
* in this regard, degree should not be multiplied by two because of the loop
* else it will have too much importance regarding the considered proportions.
*
* Hence, here are the retained formulas:

@@ -133,2 +142,3 @@ *

* https://github.com/gephi/gephi/blob/master/modules/StatisticsPlugin/src/main/java/org/gephi/statistics/plugin/Modularity.java
* https://github.com/igraph/igraph/blob/eca5e809aab1aa5d4eca1e381389bcde9cf10490/src/community.c#L906
*/

@@ -185,5 +195,2 @@ var defaults = require('lodash/defaultsDeep'),

graph.forEachUndirectedEdge(function(edge, attr, source, target) {
if (source === target)
return;
var weight = getWeight(attr);

@@ -194,3 +201,6 @@

weightedDegrees[ids[source]] += weight;
weightedDegrees[ids[target]] += weight;
// NOTE: we double degree only if we don't have a loop
if (source !== target)
weightedDegrees[ids[target]] += weight;
});

@@ -227,5 +237,2 @@

graph.forEachDirectedEdge(function(edge, attr, source, target) {
if (source === target)
return;
var weight = getWeight(attr);

@@ -266,10 +273,6 @@

// Diagonal
// NOTE: could change something here to handle self loops
S += 0 - (Math.pow(weightedDegrees[i], 2) / M2);
// NOTE: it is important to parse the whole matrix here, diagonal and
// lower part included. A lot of implementation differ here because
// they process only a part of the matrix
for (j = i + 1; j < l; j++) {
for (j = 0; j < l; j++) {

@@ -286,4 +289,7 @@ // NOTE: Kronecker's delta

// Here we multiply by two to simulate iteration through lower part
S += (Aij - (didj / M2)) * 2;
// We add twice if we have a self loop
if (i === j && typeof edgeAttributes !== 'undefined')
S += (Aij - (didj / M2)) * 2;
else
S += (Aij - (didj / M2));
}

@@ -312,6 +318,2 @@ }

// Diagonal
// NOTE: could change something here to handle self loops
S += 0 - ((weightedInDegrees[i] * weightedOutDegrees[i]) / M);
// NOTE: it is important to parse the whole matrix here, diagonal and

@@ -322,5 +324,2 @@ // lower part included. A lot of implementation differ here because

if (i === j)
continue;
// NOTE: Kronecker's delta

@@ -425,5 +424,2 @@ // NOTE: we could go from O(n^2) to O(avg.C^2)

graph.forEachUndirectedEdge(function(edge, edgeAttr, source, target, sourceAttr, targetAttr) {
if (source === target)
return;
var weight = getWeight(edgeAttr);

@@ -467,5 +463,2 @@

graph.forEachDirectedEdge(function(edge, edgeAttr, source, target, sourceAttr, targetAttr) {
if (source === target)
return;
var weight = getWeight(edgeAttr);

@@ -472,0 +465,0 @@

{
"name": "graphology-metrics",
"version": "1.10.1",
"version": "1.11.0",
"description": "Miscellaneous graph metrics for graphology.",

@@ -53,2 +53,3 @@ "main": "index.js",

"graphology-layout": "^0.2.0",
"graphology-operators": "^1.1.0",
"mocha": "^7.0.1"

@@ -55,0 +56,0 @@ },

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc