1-eps)break;var t=tmp;tmp=b;b=t}return tmp};reorder.poweriteration_n=function(v,p,init,eps,start){if(!eps)eps=1e-9;var n=v.length,b=Array(p),i,j,k,l,bk,dot,row,tmp=Array(n),s=100;reorder.assert(n==v[0].length,"poweriteration needs a square matrix");if(!init){for(i=0;i0){for(l=0;l1-eps)break;bk=tmp;tmp=b[k];b[k]=bk}}return b};function gershgorin_bound(B){var i,j,max=0,n=B.length,t,row;for(i=0;imax)max=t}return max}function fiedler_vector(B,eps){var g=gershgorin_bound(B),n=B.length,Bhat=B.map(function(row){return row.slice()}),i,j,row;for(i=0;i=b)throw"Invalid list, indices not sorted";return a-b});return order};function _orderExcept(vector,i,j){var distanceMatrix=reorder.dist().distance(distance)(vector);var row,k,l,rev=false,args,pos=-1;distanceMatrix[i][i+1]=0;distanceMatrix[i+1][i]=0;var perm=ordering().distanceMatrix(distanceMatrix)(vector);pos=perm.indexOf(i);for(k=0;ki)perm[k]+=j-i-2}if(pos!==0&&perm[pos-1]===j-1)rev=true;if(rev){perm.reverse();pos=perm.length-pos-1}args=[pos+1,0].concat(reorder.range(i+1,j-1));Array.prototype.splice.apply(perm,args);return perm}order.orderrowsexcept=order.orderexcept;return order};reorder.covariance=reorder.dot;reorder.covariancetranspose=function(v,a,b){var n=v.length,cov=0,i;for(i=0;i0)v[i]/=norm;return v}reorder.poweriteration=function(v,eps,init){if(!eps)eps=1e-9;var n=v.length,b,i,j,tmp=Array(n),norm,s=100,e;reorder.assert(n==v[0].length,"poweriteration needs a square matrix");if(!init){b=reorder.random_array(n)}else b=init.slice();normalize(b);while(s-->0){for(i=0;i1-eps)break;var t=tmp;tmp=b;b=t}return tmp};reorder.poweriteration_n=function(v,p,init,eps,start){if(!eps)eps=1e-9;var n=v.length,b=Array(p),i,j,k,l,bk,dot,row,tmp=Array(n),s=100;reorder.assert(n==v[0].length,"poweriteration needs a square matrix");if(!init){for(i=0;i0){for(l=0;l1-eps)break;bk=tmp;tmp=b[k];b[k]=bk}}return b};function gershgorin_bound(B){var i,j,max=0,n=B.length,t,row;for(i=0;imax)max=t}return max}function fiedler_vector(B,eps){var g=gershgorin_bound(B),n=B.length,Bhat=B.map(function(row){return row.slice()}),i,j,row;for(i=0;i=b){min=max=row[j];break}}for(;jmax)max=v}s=max!=min?1/(max-min):0;for(j=1;j=v)row[j]=row[j]*s-min;else v=NaN}}return ret}})(this);
\ No newline at end of file
diff --git a/src/condition.js b/src/condition.js
new file mode 100644
index 0000000..2de8608
--- /dev/null
+++ b/src/condition.js
@@ -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;
+};
diff --git a/src/debug.js b/src/debug.js
index d971929..b64f6ae 100644
--- a/src/debug.js
+++ b/src/debug.js
@@ -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++) {
diff --git a/src/hcluster.js b/src/hcluster.js
index 1375126..c774c1b 100644
--- a/src/hcluster.js
+++ b/src/hcluster.js
@@ -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) {
@@ -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,
diff --git a/src/sort_order.js b/src/sort_order.js
index a65cadb..c39c556 100644
--- a/src/sort_order.js
+++ b/src/sort_order.js
@@ -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]; });
};