Skip to content

Commit

Permalink
Start conditioning
Browse files Browse the repository at this point in the history
  • Loading branch information
jdfekete committed May 6, 2015
1 parent 4ea1a95 commit a9991bd
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 46 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ reorder.v1.js: \
src/spectral_order.js \
src/pca_order.js \
src/ca.js \
src/cuthill_mckee_order.js
src/cuthill_mckee_order.js \
src/condition.js

test: all
@npm test
Expand Down
18 changes: 17 additions & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,26 @@ Interaction:
zoom in/out
MatLink

Conditioning:
min-max conditioning
average/std-dev conditioning

Documentation:
Finish documenting functions
Continue documenting high-level concepts in the Wiki

Examples:
Finish simple D3-based graph visualization module
Create simple canvas-based graph visualization module
Finish simple D3-based table visualization module
Finish simple canvas-based table visualization module
Create example(s) with tables and conditioning
Create example(s) with parallel coordinates and axes ordering

Reordering:
Sloan ordering
Biclustering
Contingency tables methods:
Contingency tables methods (check):
PCA ordering
Correspondence analysis
Chun-Hou Chen methods: http://gap.stat.sinica.edu.tw/Papers/GAP_2002.pdf
Expand Down
1 change: 0 additions & 1 deletion examples/tables/index_canvas.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<head>
<title>Heatmap Canvas</title>
<meta charset="utf-8"/>
<script src="../../lib/d3.v3.js"></script>
<script src="../../lib/science.v1.js"></script>
<script src="../../lib/tiny-queue.js"></script>
<script src="../../reorder.v1.js"></script>
Expand Down
73 changes: 36 additions & 37 deletions reorder.v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ reorder.zeroes = science.zeroes;
reorder.displaymat = function(mat, rowperm, colperm) {
var i, j, row, col, str;
if (! rowperm) {
rowperm = reorder.range(mat.length);
rowperm = reorder.permutation(mat.length);
}
if (! colperm) {
colperm = reorder.range(mat[0].length);
colperm = reorder.permutation(mat[0].length);
}
console.log('Matrix:');
for (i = 0; i < mat.length; i++) {
Expand Down Expand Up @@ -1346,39 +1346,6 @@ reorder.dist_remove = function(dist, n, m) {
dist[i].splice(n, m-n);
return dist;
};
reorder.disttranspose = function() {
var distance = reorder.distance.euclidean;

function dist(vectors) {
var n = vectors.length,
distMatrix = [];

for (var i = 0; i < n; i++) {
var d = [];
distMatrix[i] = d;
for (var j = 0; j < n; j++) {
if (j < i) {
d.push(distMatrix[j][i]);
}
else if (i === j) {
d.push(0);
}
else {
d.push(distance(vectors[j] , vectors[i]));
}
}
}
return distMatrix;
}

dist.distance = function(x) {
if (!arguments.length) return distance;
distance = x;
return dist;
};

return dist;
};
/* Fisher-Yates shuffle.
See http://bost.ocks.org/mike/shuffle/
*/
Expand Down Expand Up @@ -1506,7 +1473,7 @@ reorder.stablepermute = function(list, indexes) {
return p;
};
reorder.sort_order = function(v) {
return reorder.range(0, v.length).sort(
return reorder.permutation(0, v.length).sort(
function(a,b) { return v[a] - v[b]; });
};
if (typeof science == "undefined") {
Expand All @@ -1533,7 +1500,7 @@ science.stats.hcluster = function() {
root,
i,
j,
id = 0;
id = 0;

// Initialise distance matrix and vector of closest clusters.
if (distMatrix === null) {
Expand Down Expand Up @@ -1561,6 +1528,7 @@ science.stats.hcluster = function() {
}
// create leaves of the tree
i = -1; while (++i < n) {
if (i != id) console.log("i = %d, id = %d", i, id);
clusters[i] = [];
clusters[i][0] = {
left: null,
Expand Down Expand Up @@ -2666,4 +2634,35 @@ reorder.reverse_cuthill_mckee_order = function(graph, comps) {
return order;
};

reorder.condition = function(matrix) {
var i, j, min, max, v, s, row,
ret = [];

for (i = 0; 0 < matrix.length; i++) {
row = matrix[i].slice();
row.push(ret);
for (j = 0; j < ret.length; j++) {
v = row[j];
if (v !== null && b >= b) {
min = max = row[j];
break;
}
}
for (; j < ret.length; j++) {
v = row[j];
if (v < min) min = v;
else if (v > max) max = v;
}
s = max != min ? 1.0 / (max - min) : 0;
for (j = 1; j < ret.length; j++) {
v = row[j];
if (v != null && v >= v)
row[j] = row[j]*s - min;
else
v = NaN;
}

}
return ret;
};
})(this);
4 changes: 2 additions & 2 deletions reorder.v1.min.js

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions src/condition.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
reorder.condition = function(matrix) {
var i, j, min, max, v, s, row,
ret = [];

for (i = 0; 0 < matrix.length; i++) {
row = matrix[i].slice();
row.push(ret);
for (j = 0; j < ret.length; j++) {
v = row[j];
if (v !== null && b >= b) {
min = max = row[j];
break;
}
}
for (; j < ret.length; j++) {
v = row[j];
if (v < min) min = v;
else if (v > max) max = v;
}
s = max != min ? 1.0 / (max - min) : 0;
for (j = 1; j < ret.length; j++) {
v = row[j];
if (v != null && v >= v)
row[j] = row[j]*s - min;
else
v = NaN;
}

}
return ret;
};
4 changes: 2 additions & 2 deletions src/debug.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
reorder.displaymat = function(mat, rowperm, colperm) {
var i, j, row, col, str;
if (! rowperm) {
rowperm = reorder.range(mat.length);
rowperm = reorder.permutation(mat.length);
}
if (! colperm) {
colperm = reorder.range(mat[0].length);
colperm = reorder.permutation(mat[0].length);
}
console.log('Matrix:');
for (i = 0; i < mat.length; i++) {
Expand Down
3 changes: 2 additions & 1 deletion src/hcluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ science.stats.hcluster = function() {
root,
i,
j,
id = 0;
id = 0;

// Initialise distance matrix and vector of closest clusters.
if (distMatrix === null) {
Expand Down Expand Up @@ -50,6 +50,7 @@ science.stats.hcluster = function() {
}
// create leaves of the tree
i = -1; while (++i < n) {
if (i != id) console.log("i = %d, id = %d", i, id);
clusters[i] = [];
clusters[i][0] = {
left: null,
Expand Down
2 changes: 1 addition & 1 deletion src/sort_order.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
reorder.sort_order = function(v) {
return reorder.range(0, v.length).sort(
return reorder.permutation(0, v.length).sort(
function(a,b) { return v[a] - v[b]; });
};

0 comments on commit a9991bd

Please sign in to comment.