Skip to content

Instantly share code, notes, and snippets.

@w8r
Created January 6, 2017 12:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save w8r/5085008918b4e0f08fd12a7b3c19659b to your computer and use it in GitHub Desktop.
Save w8r/5085008918b4e0f08fd12a7b3c19659b to your computer and use it in GitHub Desktop.
Graph Laplacian
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