Skip to content

Commit

Permalink
Migrate all remaining imports
Browse files Browse the repository at this point in the history
  • Loading branch information
curran committed Dec 30, 2020
1 parent 6b27627 commit 1334113
Show file tree
Hide file tree
Showing 14 changed files with 62 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/covariance.js
Expand Up @@ -22,7 +22,7 @@ export function variancecovariance(v) {
}
for (i = 0; i < o; i++) {
for (j = i; j < o; j++)
cov[i][j] = cov[j][i] = reorder.covariancetranspose(v, i, j);
cov[i][j] = cov[j][i] = covariancetranspose(v, i, j);
}
return cov;
};
6 changes: 3 additions & 3 deletions src/cuthill_mckee_order.js
Expand Up @@ -42,7 +42,7 @@ export function cuthill_mckee(graph, comp) {
};

export function reverse_cuthill_mckee(graph, comp) {
return reorder.cuthill_mckee(graph, comp).reverse();
return cuthill_mckee(graph, comp).reverse();
};

export function cuthill_mckee_order(graph, comps) {
Expand All @@ -53,7 +53,7 @@ export function cuthill_mckee_order(graph, comps) {
for (i = 0; i < comps.length; i++) {
comp = comps[i];
order = order.concat(
reorder.cuthill_mckee(graph, comp));
cuthill_mckee(graph, comp));
}
return order;
};
Expand All @@ -66,7 +66,7 @@ export function reverse_cuthill_mckee_order(graph, comps) {
for (i = 0; i < comps.length; i++) {
comp = comps[i];
order = order.concat(
reorder.reverse_cuthill_mckee(graph, comp));
reverse_cuthill_mckee(graph, comp));
}
return order;
};
Expand Down
8 changes: 4 additions & 4 deletions src/debug.js
Expand Up @@ -12,7 +12,7 @@ export function displaymat(mat, rowperm, colperm) {
}
};

export function printve(row, prec, colperm, line) {
export function printvec(row, prec, colperm, line) {
var j;
if (! line)
line = "";
Expand All @@ -32,7 +32,7 @@ export function printmat(m, prec, rowperm, colperm) {
if (! prec) prec=4;
for (i = 0; i < m.length; i++) {
row = rowperm ? m[rowperm[i]] : m[i];
reorder.printvec(row, prec, colperm, i+": ");
printvec(row, prec, colperm, i+": ");
}
};

Expand All @@ -49,6 +49,6 @@ export function printhcluster(cluster,indent) {

return Array(indent+1).join(' ')
+"id: "+cluster.id+", dist: "+cluster.dist+"\n"
+reorder.printhcluster(cluster.left, indent+1)+"\n"
+reorder.printhcluster(cluster.right, indent+1);
+printhcluster(cluster.left, indent+1)+"\n"
+printhcluster(cluster.right, indent+1);
};
4 changes: 3 additions & 1 deletion src/dist.js
@@ -1,5 +1,7 @@
import { distance } from './distance';

export function dist() {
var distance = reorder.distance.euclidean;
var distance = distance.euclidean;

function dist(vectors) {
var n = vectors.length,
Expand Down
4 changes: 3 additions & 1 deletion src/edgesum.js
@@ -1,6 +1,8 @@
import { range } from './range';

export function edgesum(graph, order) {
if (! order)
order = reorder.range(graph.nodes().length);
order = range(graph.nodes().length);

var inv = inverse_permutation(order),
links = graph.links(),
Expand Down
13 changes: 9 additions & 4 deletions src/fiedler.js
@@ -1,4 +1,9 @@
// Compute te Fiedler vector, the smallest non-null eigenvector of a matrix.
import { debug } from './core';
import { poweriteration, poweriteration_n } from './poweriteration';
import { array1d } from './utils';
import { random_array } from './random';

// Compute the Fiedler vector, the smallest non-null eigenvector of a matrix.
// See:
// Yehuda Koren, Liran Carmel, David Harel
// ACE: A Fast Multiscale Eigenvector Computation for Drawing Huge Graphs
Expand All @@ -21,7 +26,7 @@ function gershgorin_bound(B) {
if (t > max)
max = t;
}
if (reorder.debug) {
if (debug) {
console.log('gershgorin_bound=%d', max);
}
return max;
Expand All @@ -42,7 +47,7 @@ export function fiedler_vector(B, eps) {
row[j] = - row[j];
}
}
var init = [ reorder.array1d(n, 1), reorder.random_array(n) ],
eig = reorder.poweriteration_n(Bhat, 2, init, eps, 1);
var init = [ array1d(n, 1), random_array(n) ],
eig = poweriteration_n(Bhat, 2, init, eps, 1);
return eig[0][1];
}
7 changes: 5 additions & 2 deletions src/graph.js
@@ -1,3 +1,6 @@
import { debug } from './core';
import { cmp_number } from './utils';

export function graph(nodes, links, directed) {
var graph = {},
linkDistance = 1,
Expand Down Expand Up @@ -108,7 +111,7 @@ export function graph(nodes, links, directed) {
graph.edges = function(node) {
if (typeof node != "number") {
node = node.index;
if (reorder.debug) {
if (debug) {
console.log('received node %d', node);
}
}
Expand Down Expand Up @@ -229,7 +232,7 @@ export function graph(nodes, links, directed) {
}
}
if (ccomp.length) {
ccomp.sort(reorder.cmp_number);
ccomp.sort(cmp_number);
comps.push(ccomp);
}
}
Expand Down
16 changes: 11 additions & 5 deletions src/graph2distmat.js
@@ -1,11 +1,17 @@
import { zeroes } from './aliases';
import { distmax } from './dist';
import { all_pairs_distance } from './all_pairs_distance';
import { permute } from './permute';
import { flatten } from './utils';

// Converts a graph with weighted edges (weight in l.value)
// into a distance matrix suitable for reordering with e.g.
// Optimal Leaf Ordering.

export function distmat2valuemat(distmat) {
var n = distmat.length,
valuemat = reorder.zeroes(n, n),
max_dist = reorder.distmax(distmat),
valuemat = zeroes(n, n),
max_dist = distmax(distmat),
i, j;

for (i = 0; i < n; i++) {
Expand All @@ -20,7 +26,7 @@ export function graph2valuemats(graph, comps) {
if (! comps)
comps = graph.components();

var dists = reorder.all_pairs_distance(graph, comps);
var dists = all_pairs_distance(graph, comps);
return dists.map(distmat2valuemat);
};

Expand All @@ -29,8 +35,8 @@ export function valuemats_reorder(valuemats, leaforder, comps) {

if (comps) {
orders = orders.map(function(d, i) {
return reorder.permute(comps[i], d);
return permute(comps[i], d);
});
}
return orders.reduce(reorder.flatten);
return orders.reduce(flatten);
};
6 changes: 4 additions & 2 deletions src/graph2mat.js
@@ -1,3 +1,5 @@
import { zeroes } from './aliases';

export function graph2mat(graph, directed) {
var nodes = graph.nodes(),
links = graph.links(),
Expand All @@ -23,15 +25,15 @@ export function graph2mat(graph, directed) {
cols--;
}
//console.log("Rows: "+rows+" Cols: "+cols);
mat = reorder.zeroes(rows, cols);
mat = zeroes(rows, cols);

for (i = 0; i < links.length; i++) {
l = links[i];
mat[l.source.index][l.target.index] = l.value ? l.value : 1;
}
}
else {
mat = reorder.zeroes(n, n);
mat = zeroes(n, n);

for (i = 0; i < links.length; i++) {
l = links[i];
Expand Down
4 changes: 3 additions & 1 deletion src/graph_complete.js
@@ -1,3 +1,5 @@
import { graph } from './graph';

export function complete_graph(n, directed) {
var nodes = graph_empty_nodes(n),
links = [],
Expand All @@ -17,5 +19,5 @@ export function complete_graph(n, directed) {
links.push({source: i, target: j });
}
}
return reorder.graph(nodes, links, directed).init();
return graph(nodes, links, directed).init();
};
10 changes: 7 additions & 3 deletions src/graph_random.js
@@ -1,8 +1,12 @@
import { graph_empty } from './graph_empty';
import { complete_graph } from './graph_complete';
import { graph } from './graph';

export function graph_random_erdos_renyi(n, p, directed) {
if (p <= 0)
return reorder.graph_empty(n, directed);
return graph_empty(n, directed);
else if (p >= 1)
return reorder.graph_complete(n, directed);
return complete_graph(n, directed);

var nodes = graph_empty_nodes(n),
links = [],
Expand Down Expand Up @@ -39,7 +43,7 @@ export function graph_random_erdos_renyi(n, p, directed) {
links.push({source: v, target: w});
}
}
return reorder.graph(nodes, links, directed).init();
return graph(nodes, links, directed).init();
};

export const graph_random = graph_random_erdos_renyi;
4 changes: 3 additions & 1 deletion src/hcluster.js
@@ -1,7 +1,9 @@
import { distance } from './distance';

// This is a modified implementation of hcluster derived from:
// https://github.com/jasondavies/science.js/blob/master/src/stats/hcluster.js
export function hcluster() {
var distance = reorder.distance.euclidean,
var distance = distance.euclidean,
linkage = "single", // single, complete or average
distMatrix = null;

Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Expand Up @@ -27,7 +27,7 @@ export {
} from './cuthill_mckee_order';
export {
displaymat,
printve,
printvec,
printmat,
assert,
printhcluster
Expand Down
7 changes: 5 additions & 2 deletions src/random.js
@@ -1,3 +1,6 @@
import { permutation } from './permutation';
import { zeroes } from './aliases';

/* Fisher-Yates shuffle.
See http://bost.ocks.org/mike/shuffle/
*/
Expand All @@ -19,7 +22,7 @@ export function randomPermute(array, i, j) {
};

export function randomPermutation(n) {
return reorder.randomPermute(reorder.permutation(n));
return randomPermute(permutation(n));
};

export function random_array(n, min, max) {
Expand All @@ -43,7 +46,7 @@ export function random_matrix(p, n, m, sym) {
sym = false;
else if (! sym)
sym = true;
var mat = reorder.zeroes(n, m), i, j, cnt;
var mat = zeroes(n, m), i, j, cnt;

if (sym) {
for (i = 0; i < n; i++) {
Expand Down

0 comments on commit 1334113

Please sign in to comment.