JSFiddle - React, Tailwind, and code Playground
by flek
HTML
<script src="https://unpkg.com/@aidanconnelly/[email protected]/dist/bundle.min.js"></script>
JavaScript
/**
* Created by krause on 2014-10-25.
*/
function Mdsjs() {
var thatMDS = this;
this.DEBUG = false;
this.noNaNs = function(arr) {
for(var ix = 0;ix < arr.length;ix += 1) {
if(Number.isNaN(arr[ix])) {
throw new Error("NaN in array");
}
}
};
this.noZeros = function(arr) {
for(var ix = 0;ix < arr.length;ix += 1) {
if(Number.isNaN(arr[ix]) || arr[ix] === 0) {
throw new Error(arr[ix] === 0 ? "0 in array" : "NaN in array");
}
}
};
this.onlyPositive = function(arr) {
for(var ix = 0;ix < arr.length;ix += 1) {
if(Number.isNaN(arr[ix]) || !(arr[ix] > 0)) {
throw new Error(!(arr[ix] > 0) ? arr[ix] + " in array" : "NaN in array");
}
}
};
this.CALL_ASYNC = function(f) {
setTimeout(f, 0);
};
this.getCallDirect = function() {
var depth = 0;
return function(f) {
if(depth > 20) { // prevent stack-overflows
throw {
__continuation: f
};
}
if(!depth) {
var cc = f;
while(cc) {
try {
depth += 1;
cc();
cc = null;
} catch(e) {
if(!e.__continuation) {
throw e;
}
cc = e.__continuation;
}
depth = 0;
}
} else {
depth += 1;
f();
}
};
};
this.pca = function(positions) {
var res;
thatMDS.pcaAsync(positions, function(mat) {
res = mat;
}, thatMDS.getCallDirect());
return res;
};
this.pcaAsync = function(positions, cb, argCall) {
var call = arguments.length > 2 ? argCall : thatMDS.CALL_ASYNC;
var centered = positions.colCenter();
var rows = centered.rows();
var cols = centered.cols();
centered.powerIterAsync(function(pca0) {
var mat = thatMDS.removeComponent(centered, pca0);
mat.powerIterAsync(function(pca1) {
var res = centered.createArray(cols, 2);
for(var ix = 0;ix <...