Created
January 6, 2017 12:36
-
-
Save w8r/5085008918b4e0f08fd12a7b3c19659b to your computer and use it in GitHub Desktop.
Graph Laplacian
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function laplacian(G, N) { | |
var L = new Array(N); | |
for (var i = 0; i < N; i++) { | |
var row = new Array(N); | |
var node = G.nodes[i]; | |
for (var j = 0; j < N; j++) { | |
if (i === j) { | |
row[j] = node.edges.length; | |
} else { | |
row[j] = (node.edges.indexOf(j) === -1) ? -1 : 0; | |
} | |
} | |
L[i] = row; | |
} | |
return L; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment