diff --git a/lib/numbers/matrix.js b/lib/numbers/matrix.js index d9374fd..017fa4b 100644 --- a/lib/numbers/matrix.js +++ b/lib/numbers/matrix.js @@ -779,7 +779,7 @@ matrix.reverseCols = function(M) { * @return {Array} matrix */ matrix.zeros = function(n,m) { - var M = []; + var M = new Array(n); if (n < 1 || m < 1) { throw new Error('The matrix dimensions must be positive integers.'); } @@ -790,7 +790,7 @@ matrix.zeros = function(n,m) { for (var j=0; j 0) return arr[n][k]; if (!arr[n]) arr[n] = []; - return arr[n][k] = _binomial(n - 1, k - 1) + _binomial(n - 1, k); + arr[n][k] = _binomial(n - 1, k - 1) + _binomial(n - 1, k); + return arr[n][k]; } return _binomial(n, k); @@ -1146,10 +1147,11 @@ var matrix = exports; * @return {Array} copied matrix. */ matrix.deepCopy = function(arr) { - if (arr[0][0] === undefined) { + if (!Array.isArray(arr)) { + throw new Error('Input must be a matrix.'); + } else if (arr[0][0] === undefined) { throw new Error('Input cannot be a vector.'); } - var result = new Array(arr.length); for (var i = 0; i < arr.length; i++) { @@ -1165,10 +1167,15 @@ matrix.deepCopy = function(arr) { * @param {Array} arr */ matrix.isSquare = function(arr) { + if (!Array.isArray(arr)) { + throw new Error('Input must be a matrix.'); + } else if (arr[0][0] === undefined) { + throw new Error('Input cannot be a vector.'); + } var rows = arr.length; - for (var i = 0, row; row = arr[i]; i++) { - if (row.length != rows) return false; + for (var i = 0; i < rows; i++) { + if (arr[i].length != rows) return false; } return true; @@ -1892,7 +1899,7 @@ matrix.reverseCols = function(M) { * @return {Array} matrix */ matrix.zeros = function(n,m) { - var M = []; + var M = new Array(n); if (n < 1 || m < 1) { throw new Error('The matrix dimensions must be positive integers.'); } @@ -1903,7 +1910,7 @@ matrix.zeros = function(n,m) { for (var j=0; je;e++){if("number"!=typeof r[e])throw new Error("All elements in array must be numbers");t-=r[e]}return t}throw new Error("Input must be of type Array")},n.product=function(r){if("[object Array]"===Object.prototype.toString.call(r)){var t=r[0];if("number"!=typeof t)throw new Error("All elements in array must be numbers");for(var e=1,n=r.length;n>e;e++){if("number"!=typeof r[e])throw new Error("All elements in array must be numbers");t*=r[e]}return t}throw new Error("Input must be of type Array")},n.square=function(r){return r*r},n.binomial=function(r,t){function e(r,t){return r>=0&&0===t?1:0===r&&t>0?0:n[r]&&n[r][t]>0?n[r][t]:(n[r]||(n[r]=[]),n[r][t]=e(r-1,t-1)+e(r-1,t))}var n=[];return e(r,t)},n.factorial=function(r){for(var t=2,e=1;r>=t;)e*=t++;return e},n.gcd=function(r,t){var e;if(r=+r,t=+t,r!==r||t!==t)return 0/0;if(1/0===r||r===-1/0||1/0===t||t===-1/0)return 1/0;if(r%1!==0||t%1!==0)throw new Error("Can only operate on integers");for(;t;)e=r%t,r=t,t=e;return r>0?r:-r},n.lcm=function(r,t){return Math.abs(r*t)/n.gcd(r,t)},n.random=function(r,t,e){if(0===r.length)throw new Error("Empty array");if(t>r.length&&!e)throw new Error("Quantity requested exceeds size of array");if(e===!0){var o,a=[];for(o=0;t>o;o++)a[o]=r[Math.floor(Math.random()*r.length)];return a}return n.shuffle(r).slice(0,t)},n.shuffle=function(r){for(var t,e,n=r.length;n;)e=Math.floor(Math.random()*n--),t=r[n],r[n]=r[e],r[e]=t;return r},n.max=function(r){if(!Array.isArray(r))throw new Error("Input must be of type Array");for(var t,e=-1/0,n=0,o=r.length;o>n;n++)if(t=+r[n],t>e&&(e=t),t!==t)return 0/0;return e},n.min=function(r){if(!Array.isArray(r))throw new Error("Input must be of type Array");for(var t,e=+1/0,n=0,o=r.length;o>n;n++)if(t=+r[n],e>t&&(e=t),t!==t)return 0/0;return e},n.range=function(r,t,e){var n,o,a=0;for(arguments.length<=1&&(t=r||0,r=0),e=e||1,r>t&&(e=0-Math.abs(e)),o=Math.max(Math.ceil((t-r)/e)+1,0),n=new Array(o);o>a;)n[a++]=r,r+=e;return n},n.isInt=function(r){return r%1===0},n.divMod=function(r,t){return n.isInt(r)&&n.isInt(t)?[Math.floor(r/t),r%t]:!1},n.powerMod=function(r,t,e){if(-1>t)return Math.pow(r,t)%e;if(0===t)return 1%e;if(t>=1){for(var o=1;t>0;)t%2===1&&(o=o*r%e),r=r*r%e,t>>=1;return o}return-1===t?n.modInverse(r,e):1>t?n.powerMod(r,Math.pow(t,-1),e):void 0},n.egcd=function(r,t){if(r=+r,t=+t,r!==r||t!==t)return[0/0,0/0,0/0];if(1/0===r||r===-1/0||1/0===t||t===-1/0)return[1/0,1/0,1/0];if(r%1!==0||t%1!==0)throw new Error("Can only operate on integers");var e,n,o,a,i=0>r?-1:1,u=0>t?-1:1,f=0,s=1,h=1,l=0;for(r=Math.abs(r),t=Math.abs(t);0!==r;)e=Math.floor(t/r),n=t%r,o=f-h*e,a=s-l*e,t=r,r=n,f=h,s=l,h=o,l=a;return[t,i*f,u*s]},n.modInverse=function(r,t){var e=n.egcd(r,t);if(1!=e[0])throw new Error("No modular inverse exists");return e[1]%t},n.numbersEqual=function(r,t,e){return e>r-t&&r-t>-e},n.fallingFactorial=function(r,t){var e=r-t+1,n=1;if(0>r)throw new Error("n cannot be negative");if(t>r)return 0;for(;r>=e;)n*=e++;return n}},{}],4:[function(r,t,e){function n(r,t,e){var n=(t+e)/2,o=Math.abs(e-t)/6;return o*(r(t)+4*r(n)+r(e))}function o(r,t,e,a,i){var u=t+e,f=n(r,t,u),s=n(r,u,e);return Math.abs(f+s-a)<=15*i?f+s+(f+s-a)/15:o(r,t,u,i/2,f)+o(r,u,e,i/2,s)}var a=r("../numbers"),i=e;i.pointDiff=function(r,t){var e=r(t-.001),n=r(t+.001);return(n-e)/.002},i.Riemann=function(r,t,e,n,o){var a,i=(e-t)/n,u=0;if("function"==typeof o)for(a=t;e>a;a+=i)u+=r(o(a,a+i));else for(a=t;e>a;a+=i)u+=r(a);return u*i},i.adaptiveSimpson=function(r,t,e,i){return i="undefined"==typeof i?a.EPSILON:i,o(r,t,e,n(r,t,e),i)},i.limit=function(r,t,e){if("left"===e)return r(t-1e-15);if("right"===e)return r(t+1e-15);if("middle"===e)return(i.limit(r,t,"left")+i.limit(r,t,"right"))/2;throw new Error("Approach not provided")},i.StirlingGamma=function(r){return Math.sqrt(2*Math.PI/r)*Math.pow(r/Math.E,r)},i.LanczosGamma=function(r){var t,e=[.9999999999998099,676.5203681218851,-1259.1392167224028,771.3234287776531,-176.6150291621406,12.507343278686905,-.13857109526572012,9984369578019572e-21,1.5056327351493116e-7],n=7;if(.5>r)return Math.PI/(Math.sin(Math.PI*r)*i.LanczosGamma(1-r));r-=1;var o=e[0],a=r+n+.5;for(t=1;t=t)throw new Error("Please use a positive integer for N.");var e=[];t=Math.ceil(t);for(var n=2;ne;e++){var n=(this.phase()+2*Math.PI*e)/r,a=Math.pow(this.magnitude(),1/r);t[e]=new o(a*Math.cos(n),a*Math.sin(n))}return t},o.prototype.sin=function(){var r=new o(Math.E,0),t=new o(0,1),e=new o(0,-1),n=r.complexPow(t.multiply(this)).subtract(r.complexPow(e.multiply(this)));return n.divide(new o(0,2))},o.prototype.cos=function(){var r=new o(Math.E,0),t=new o(0,1),e=new o(0,-1),n=r.complexPow(t.multiply(this)).add(r.complexPow(e.multiply(this)));return n.divide(new o(2,0))},o.prototype.tan=function(){return this.sin().divide(this.cos())},o.prototype.equals=function(r,t){return n.numbersEqual(this.re,r.re,t)&&n.numbersEqual(this.im,r.im,t)},t.exports=o},{"../numbers":2}],6:[function(r,t,e){var n=r("../numbers"),o=n.complex,a=e;a.segment=function(r,t,e){for(var n=[],o=t;o=t)return[new o(r[0],0)];if(Math.log(t)/Math.LN2%1!==0)throw new Error("Array length must be integer power of 2");for(var e=a.fft(a.segment(r,0,2)),n=a.fft(a.segment(r,1,2)),i=[],u=t/2,f=0;t>f;f++){var s=-2*Math.PI*f/t,h=new o(Math.cos(s),Math.sin(s));i[f]=u>f?e[f].add(h.multiply(n[f])):e[f-u].subtract(h.multiply(n[f-u]))}return i}},{"../numbers":2}],7:[function(r,t,e){var n=e;n.fibonacci=function(r){for(var t,e=function(r){for(var t,e=[];r>0;)t=2>r?r:r%2,r=Math.floor(r/2),e.push(t);return e.reverse()},n=1,o=0,a=1,i=e(r),u=0;ue;e++){t[e]=new Array(r);for(var n=0;r>n;n++)t[e][n]=e===n?1:0}return t},n.dotproduct=function(r,t){if(r.length===t.length){for(var e=0,n=0;ne;e++){for(n=r[0][e],o=r[0][e],t=1;a>t;t++)o*=r[t][((e+t)%i+i)%i],n*=r[t][((e-t)%i+i)%i];u+=o-n}return u},n.lupDecomposition=function(r){if(!n.isSquare(r))throw new Error("Matrix must be square.");var t,e=r.length,o=n.deepCopy(r),a=n.transpose(n.identity(e)),i=new Array(e);this.getL=function(r){for(var t=r[0].length,e=n.identity(t),o=0;t>o;o++)for(var a=0;t>a;a++)o>a&&(e[o][a]=r[o][a]);return e},this.getU=function(r){for(var t=r[0].length,e=n.identity(t),o=0;t>o;o++)for(var a=0;t>a;a++)a>=o&&(e[o][a]=r[o][a]);return e};for(var u=0;e>u;u++){var f;for(f=0;e>f;f++)i[f]=o[f][u];for(f=0;e>f;f++){t=o[f];for(var s=Math.min(f,u),h=0,l=0;s>l;l++)h+=t[l]*i[l];t[u]=i[f]-=h}var m=u;for(f=u+1;e>f;f++)Math.abs(i[f])>Math.abs(i[m])&&(m=f);if(m!=u&&(o=n.rowSwitch(o,m,u),a=n.rowSwitch(a,m,u)),e>u&&0!==o[u][u])for(f=u+1;e>f;f++)o[f][u]/=o[u][u]}return[this.getL(o),this.getU(o),a]},n.rotate=function(r,t,e){if(2===r.length){var o="clockwise"===e?-1:1,a=t*(Math.PI/180),i=[[Math.cos(a),-1*o*Math.sin(a)],[o*Math.sin(a),Math.cos(a)]];return n.multiply(i,r)}throw new Error("Only two dimensional operations are supported at this time")},n.scale=function(r,t,e){if(2===r.length){var o=[[t,0],[0,e]];return n.multiply(o,r)}throw new Error("Only two dimensional operations are supported at this time")},n.shear=function(r,t,e){if(2===r.length){var o="xaxis"===e?t:0,a="yaxis"===e?t:0,i=[[1,o],[a,1]];return n.multiply(i,r)}throw new Error("Only two dimensional operations are supported at this time")},n.affine=function(r,t,e){if(2===r.length){var o=[[1,0,t],[0,1,e],[0,0,1]],a=[[r[0][0]],[r[1][0]],[1]],i=n.multiply(o,a);return[[i[0][0]],[i[1][0]]]}throw new Error("Only two dimensional operations are supported at this time")},n.rowScale=function(r,t,e){for(var n=new Array(r.length),o=0;oMath.abs(r[s][f])&&(s=e);var h=r[f];if(r[f]=r[s],r[s]=h,Math.abs(r[f][f])<=a)return r;for(e=f;++e=0;){for(o=r[f][f],e=-1;++e=f;)r[e][n]-=r[f][n]*r[e][f]/o;for(r[f][f]/=o,n=i-1;++nt;t++)r[t]=r[t].concat(o[t]);for(r=n.GaussJordanEliminate(r),t=0;e>t;t++)r[t]=r[t].slice(e);return r}throw new Error("The given matrix must be square")},n.getCol=function(r,t){var e=[];if(0>t)throw new Error("The specified column must be a positive integer.");if(t>=r[0].length)throw new Error("The specified column must be between 0 and the number of columns - 1.");for(var n=0;n=t.length)throw new Error("The desired order of the rows must start at 0 and end at the number of rows - 1.");e.push(r[t[n]])}return e},n.reorderCols=function(r,t){var e=[];if(void 0===t)throw new Error("Please enter a desired reordering array.");if(t.length!==r[0].length)throw new Error("The reordered matrix must have the same number of columns as the original matrix.");for(var o=0;o=t.length)throw new Error("The desired order of the rows must start at 0 and end at the number of rows - 1.");e.push(n.getCol(r,t[o]))}return n.transpose(e)},n.reverseRows=function(r){for(var t=[],e=r.length-1;e>-1;e--)t.push(e);return n.reorderRows(r,t)},n.reverseCols=function(r){for(var t=[],e=r.length-1;e>-1;e--)t.push(e);return n.reorderCols(r,t)},n.zeros=function(r,t){var e=[];if(1>r||1>t)throw new Error("The matrix dimensions must be positive integers.");r=Math.ceil(r),t=Math.ceil(t);for(var n=0;r>n;n++){for(var o=new Array(t),a=0;t>a;a++)o[a]=0;e.push(o)}return e},n.zigzag=function(r,t,e){if(1>=r)throw new Error("Matrix size must be at least 2x2.");r=Math.ceil(r);var o=n.zeros(r,r),a=function(t){var e,n,o,a,i,u=!1,f=r*r,s=1,h=1;for(t[0][0]=f,t[r-1][r-1]=s,a=1;r>a;a++)u?(f-=4*h,s+=4*h,h++):(f--,s++),t[0][a]=f,t[r-1][r-1-a]=s,u=!u;var l=!0;for(a=1;r>a;a++){for(e=0,n=a,o=t[e][n],i=1;a+1>i;i++)l?o-=1:o+=1,e++,n--,t[e][n]=o;l=!l}for(l=r%2===0?!0:!1,a=1;r-1>a;a++){for(e=r-1,n=a,o=t[e][n],i=1;r-a>i;i++)l?o--:o++,e--,n++,t[e][n]=o;l=!l}return t},i=function(r){return n.transpose(a(r))},u=function(r){return n.reverseCols(a(r))},f=function(r){return n.reverseRows(m(u(r)))},s=function(r){return n.reverseRows(a(r))},h=function(r){return n.reverseRows(i(r))},l=function(r){return n.reverseCols(n.reverseRows(a(r)))},m=function(r){return n.transpose(l(r))};if("BR"===t&&"H"===e)return a(o);if("BR"===t&&"V"===e)return i(o);if("BL"===t&&"H"===e)return u(o);if("BL"===t&&"V"===e)return f(o);if("TR"===t&&"H"===e)return s(o);if("TR"===t&&"V"===e)return h(o);if("TL"===t&&"H"===e)return l(o);if("TL"===t&&"V"===e)return m(o);throw new Error("Enter the direction (V,H) and corner (BR,BL,TR,TL) correctly.")},n.vectorNorm=function(r,t){if(!Array.isArray(r)||0===r.length)throw new Error("Vector must be an array of at least length 1.");if("undefined"!=typeof t&&"number"!=typeof t)throw new Error("Norm order must be a number.");t="undefined"==typeof t?2:t;var e,n,o=r.length,a=0;switch(t){case 1/0:for(n=0;o>n;n++)e=Math.abs(r[n]),e>a&&(a=e);break;case-1/0:for(a=1/0,n=0;o>n;n++)e=Math.abs(r[n]),a>e&&(a=e);break;default:for(n=0;o>n;n++)a+=Math.pow(Math.abs(r[n]),t);a=Math.pow(a,1/t)}return a},n.matrixNorm=function(r,t){if(!Array.isArray(r)||0===r.length||!Array.isArray(r[0]))throw new Error("Matrix must be an array of at least length 1.");if("undefined"!=typeof t&&"number"!=typeof t&&null!==t)throw new Error("Norm order must be a number or null.");t="undefined"==typeof t?null:t;var e,n,o,a=r.length,i=r[0].length,u=0;switch(t){case 1/0:for(n=0;a>n;n++){for(e=0,o=0;i>o;o++)e+=Math.abs(r[n][o]);e>u&&(u=e)}break;case-1/0:for(u=1/0,n=0;a>n;n++){for(e=0,o=0;i>o;o++)e+=Math.abs(r[n][o]);u>e&&(u=e)}break;case 1:for(n=0;i>n;n++){for(e=0,o=0;a>o;o++)e+=Math.abs(r[o][n]);e>u&&(u=e)}break;case-1:for(u=1/0,n=0;i>n;n++){for(e=0,o=0;a>o;o++)e+=Math.abs(r[o][n]);u>e&&(u=e)}break;case null:for(n=0;a>n;n++)for(o=0;i>o;o++)u+=Math.pow(r[n][o],2);u=Math.pow(u,.5);break;case 2:throw new Error("Singular values are not yet supported in numbers.js.");case-2:throw new Error("Singular values are not yet supported in numbers.js.");default:for(n=0;a>n;n++)for(o=0;i>o;o++)u+=Math.pow(Math.abs(r[n][o]),t);u=Math.pow(u,1/t)}return u},n.isUpperBand=function(r,t){if(!Array.isArray(r)||!Array.isArray(r[0])||r.length<2)throw new Error("Matrix must be an array of at least dimension 2.");if("number"!=typeof t||0>t||t%1!==0)throw new Error("Upper bandwidth must be a nonzero integer.");for(var e=!0,n=r[0].length,o=0,a=t+1;n>a;a++){if(0!==r[o][a]){e=!1;break}o++}return e},n.isLowerBand=function(r,t){if(!Array.isArray(r)||!Array.isArray(r[0])||r.length<2)throw new Error("Matrix must be an array of at least dimension 2.");if("number"!=typeof t||0>t||t%1!==0)throw new Error("Lower bandwidth must be a nonzero integer.");for(var e=!0,n=r.length,o=0,a=t+1;n>a;a++){if(0!==r[a][o]){e=!1;break}o++}return e}},{}],9:[function(r,t,e){var n=r("./basic"),o=e;o.simple=function(r){if(1===r)return!1;if(2===r)return!0;if(void 0!==r){for(var t=1,e=Math.ceil(Math.sqrt(r));++t<=e;)if(r%t===0)return!1;return!0}},o.factorization=function(r){r=Math.floor(r);for(var t,e,n=[],o=Math.sqrt,a=r>1&&isFinite(r);a;){if(t=o(r),e=2,r%e)for(e=3;r%e&&(e+=2)t?r:e,n.push(e),a=e!==r,r/=e}return n},o.millerRabin=function(r,t){if(1===arguments.length&&(t=20),2===r)return!0;if(!n.isInt(r)||1>=r||r%2===0)return!1;for(var e=0,o=r-1;;){var a=n.divMod(o,2),i=a[0],u=a[1];if(1===u)break;e+=1,o=i}for(var f=function(t){if(1===n.powerMod(t,o,r))return!1;for(var a=0;e>a;a++)if(n.powerMod(t,Math.pow(2,a)*o,r)===r-1)return!1;return!0},s=0;t>s;s++){var h=2+Math.floor(Math.random()*(r-2-2));if(f(h))return!1}return!0},o.sieve=function(r){if(2>r)return[];for(var t=[2],e=3;r>=e;e++){var n=!1;for(var o in t)n=n||0===e%t[o];n||t.push(e)}return t},o.coprime=function(r,t){return 1===n.gcd(r,t)},o.getPerfectPower=function(r){var t=o.getPrimePower(r);return t&&t[1]>1?t:!1},o.getPrimePower=function(r){if(2>r)return!1;if(o.millerRabin(r))return[r,1];if(r%2===0)return[2,r.toString(2).length-1];var t=o.factorization(r);if(!t)return!1;for(var e=t.length,n=0;e>n;n++)for(var a=0,i=0;r>=a;){if(a=Math.pow(t[n],i),a/r===1)return[t[n],i];i++}return!1}},{"./basic":3}],10:[function(r,t,e){var n=(r("./basic"),e),o=Math.random;n.setGenerator=function(r){if("function"!=typeof r)throw new Error("Must pass a function");o=r},n.sample=function(r,t,e){var n=[];n.length=e;for(var a=0;e>a;a++)n[a]=r+(t-r)*o();return n},n.boxMullerTransform=function(r,t){arguments.length<=1&&(t=1),0===arguments.length&&(r=0);var e,n=0,a=0;do n=2*o()-1,a=2*o()-1,e=n*n+a*a;while(0===e||e>1);var i=Math.sqrt(-2*Math.log(e)/e),u=n*i,f=a*i;return u=r+u*t,f=r+f*t,[u,f]},n.irwinHall=function(r,t){1===arguments.length&&(t=0);for(var e=0,n=0;r>n;n++)e+=o();return e-t},n.bates=function(r,t,e){arguments.length<=2&&(e=0),1===arguments.length&&(t=1);for(var n=0,a=0;r>a;a++)n+=(t-e)*o()+e;return n/r},n.distribution={},n.distribution.normal=function(r,t,e){return arguments.length<=2&&(e=1),1===arguments.length&&(t=0),n.distribution.boxMuller(r,t,e)},n.distribution.logNormal=function(r,t,e){arguments.length<=2&&(e=1),1===arguments.length&&(t=0);var o=function(r){return Math.exp(r)};return n.distribution.boxMuller(r,t,e).map(o)},n.distribution.boxMuller=function(r,t,e,o){arguments.length<=3&&(o=!1),arguments.length<=2&&(e=1),1===arguments.length&&(t=0);for(var a=[],i=0;r>i;i++){var u=n.boxMullerTransform(t,e);a.push(o?u:u[0])}return a},n.distribution.irwinHall=function(r,t,e){arguments.length<=2&&(e=0),1===arguments.length&&(t=r);for(var o=new Array(r),a=0;r>a;a++)o[a]=n.irwinHall(t,e);return o},n.distribution.irwinHallNormal=function(r){return n.distribution.irwinHall(r,12,6)},n.distribution.bates=function(r,t,e){arguments.length<=2&&(e=0),1===arguments.length&&(t=r);for(var o=new Array(r),a=0;r>a;a++)o[a]=n.bates(r,t,e);return o}},{"./basic":3}],11:[function(r,t,e){var n=r("./basic"),o=e;o.mean=function(r){var t=r.length,e=n.sum(r);return e/t},o.median=function(r){return o.quantile(r,1,2)},o.mode=function(r){for(var t={},e=0,n=r.length;n>e;e++)void 0===t[r[e]]?t[r[e]]=0:t[r[e]]++;var o;for(var a in t)t.hasOwnProperty(a)&&(void 0===o||t[a]>t[o])&&(o=a);return Number(o)},o.quantile=function(r,t,e){var n,o,a;return 0===t?Math.min.apply(null,r):t===e?Math.max.apply(null,r):(n=r.slice(0),n.sort(function(r,t){return r-t}),o=n.length,a=o*t/e,a%1===0?.5*n[a-1]+.5*n[a]:n[Math.floor(a)])},o.report=function(r){return{mean:o.mean(r),firstQuartile:o.quantile(r,1,4),median:o.median(r),thirdQuartile:o.quantile(r,3,4),standardDev:o.standardDev(r)}},o.standardDev=function(r){for(var t=r.length,e=o.mean(r),a=[],i=0;iu;u++)o+=r[u]*t[u];return(o-a*i/e)/e}throw new Error("Array mismatch")}},{"./basic":3}]},{},[1])(1)}); \ No newline at end of file +!function(r){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=r();else if("function"==typeof define&&define.amd)define([],r);else{var t;"undefined"!=typeof window?t=window:"undefined"!=typeof global?t=global:"undefined"!=typeof self&&(t=self),t.numbers=r()}}(function(){return function r(t,e,n){function o(i,u){if(!e[i]){if(!t[i]){var f="function"==typeof require&&require;if(!u&&f)return f(i,!0);if(a)return a(i,!0);var s=new Error("Cannot find module '"+i+"'");throw s.code="MODULE_NOT_FOUND",s}var h=e[i]={exports:{}};t[i][0].call(h.exports,function(r){var e=t[i][1][r];return o(e?e:r)},h,h.exports,r,t,e,n)}return e[i].exports}for(var a="function"==typeof require&&require,i=0;ie;e++){if("number"!=typeof r[e])throw new Error("All elements in array must be numbers");t-=r[e]}return t}throw new Error("Input must be of type Array")},n.product=function(r){if("[object Array]"===Object.prototype.toString.call(r)){var t=r[0];if("number"!=typeof t)throw new Error("All elements in array must be numbers");for(var e=1,n=r.length;n>e;e++){if("number"!=typeof r[e])throw new Error("All elements in array must be numbers");t*=r[e]}return t}throw new Error("Input must be of type Array")},n.square=function(r){return r*r},n.binomial=function(r,t){function e(r,t){return r>=0&&0===t?1:0===r&&t>0?0:n[r]&&n[r][t]>0?n[r][t]:(n[r]||(n[r]=[]),n[r][t]=e(r-1,t-1)+e(r-1,t),n[r][t])}var n=[];return e(r,t)},n.factorial=function(r){for(var t=2,e=1;r>=t;)e*=t++;return e},n.gcd=function(r,t){var e;if(r=+r,t=+t,r!==r||t!==t)return 0/0;if(1/0===r||r===-1/0||1/0===t||t===-1/0)return 1/0;if(r%1!==0||t%1!==0)throw new Error("Can only operate on integers");for(;t;)e=r%t,r=t,t=e;return r>0?r:-r},n.lcm=function(r,t){return Math.abs(r*t)/n.gcd(r,t)},n.random=function(r,t,e){if(0===r.length)throw new Error("Empty array");if(t>r.length&&!e)throw new Error("Quantity requested exceeds size of array");if(e===!0){var o,a=[];for(o=0;t>o;o++)a[o]=r[Math.floor(Math.random()*r.length)];return a}return n.shuffle(r).slice(0,t)},n.shuffle=function(r){for(var t,e,n=r.length;n;)e=Math.floor(Math.random()*n--),t=r[n],r[n]=r[e],r[e]=t;return r},n.max=function(r){if(!Array.isArray(r))throw new Error("Input must be of type Array");for(var t,e=-1/0,n=0,o=r.length;o>n;n++)if(t=+r[n],t>e&&(e=t),t!==t)return 0/0;return e},n.min=function(r){if(!Array.isArray(r))throw new Error("Input must be of type Array");for(var t,e=+1/0,n=0,o=r.length;o>n;n++)if(t=+r[n],e>t&&(e=t),t!==t)return 0/0;return e},n.range=function(r,t,e){var n,o,a=0;for(arguments.length<=1&&(t=r||0,r=0),e=e||1,r>t&&(e=0-Math.abs(e)),o=Math.max(Math.ceil((t-r)/e)+1,0),n=new Array(o);o>a;)n[a++]=r,r+=e;return n},n.isInt=function(r){return r%1===0},n.divMod=function(r,t){return n.isInt(r)&&n.isInt(t)?[Math.floor(r/t),r%t]:!1},n.powerMod=function(r,t,e){if(-1>t)return Math.pow(r,t)%e;if(0===t)return 1%e;if(t>=1){for(var o=1;t>0;)t%2===1&&(o=o*r%e),r=r*r%e,t>>=1;return o}return-1===t?n.modInverse(r,e):1>t?n.powerMod(r,Math.pow(t,-1),e):void 0},n.egcd=function(r,t){if(r=+r,t=+t,r!==r||t!==t)return[0/0,0/0,0/0];if(1/0===r||r===-1/0||1/0===t||t===-1/0)return[1/0,1/0,1/0];if(r%1!==0||t%1!==0)throw new Error("Can only operate on integers");var e,n,o,a,i=0>r?-1:1,u=0>t?-1:1,f=0,s=1,h=1,l=0;for(r=Math.abs(r),t=Math.abs(t);0!==r;)e=Math.floor(t/r),n=t%r,o=f-h*e,a=s-l*e,t=r,r=n,f=h,s=l,h=o,l=a;return[t,i*f,u*s]},n.modInverse=function(r,t){var e=n.egcd(r,t);if(1!=e[0])throw new Error("No modular inverse exists");return e[1]%t},n.numbersEqual=function(r,t,e){return e>r-t&&r-t>-e},n.fallingFactorial=function(r,t){var e=r-t+1,n=1;if(0>r)throw new Error("n cannot be negative");if(t>r)return 0;for(;r>=e;)n*=e++;return n}},{}],4:[function(r,t,e){function n(r,t,e){var n=(t+e)/2,o=Math.abs(e-t)/6;return o*(r(t)+4*r(n)+r(e))}function o(r,t,e,a,i){var u=t+e,f=n(r,t,u),s=n(r,u,e);return Math.abs(f+s-a)<=15*i?f+s+(f+s-a)/15:o(r,t,u,i/2,f)+o(r,u,e,i/2,s)}var a=r("../numbers"),i=e;i.pointDiff=function(r,t){var e=r(t-.001),n=r(t+.001);return(n-e)/.002},i.Riemann=function(r,t,e,n,o){var a,i=(e-t)/n,u=0;if("function"==typeof o)for(a=t;e>a;a+=i)u+=r(o(a,a+i));else for(a=t;e>a;a+=i)u+=r(a);return u*i},i.adaptiveSimpson=function(r,t,e,i){return i="undefined"==typeof i?a.EPSILON:i,o(r,t,e,n(r,t,e),i)},i.limit=function(r,t,e){if("left"===e)return r(t-1e-15);if("right"===e)return r(t+1e-15);if("middle"===e)return(i.limit(r,t,"left")+i.limit(r,t,"right"))/2;throw new Error("Approach not provided")},i.StirlingGamma=function(r){return Math.sqrt(2*Math.PI/r)*Math.pow(r/Math.E,r)},i.LanczosGamma=function(r){var t,e=[.9999999999998099,676.5203681218851,-1259.1392167224028,771.3234287776531,-176.6150291621406,12.507343278686905,-.13857109526572012,9984369578019572e-21,1.5056327351493116e-7],n=7;if(.5>r)return Math.PI/(Math.sin(Math.PI*r)*i.LanczosGamma(1-r));r-=1;var o=e[0],a=r+n+.5;for(t=1;t=t)throw new Error("Please use a positive integer for N.");var e=[];t=Math.ceil(t);for(var n=2;ne;e++){var n=(this.phase()+2*Math.PI*e)/r,a=Math.pow(this.magnitude(),1/r);t[e]=new o(a*Math.cos(n),a*Math.sin(n))}return t},o.prototype.sin=function(){var r=new o(Math.E,0),t=new o(0,1),e=new o(0,-1),n=r.complexPow(t.multiply(this)).subtract(r.complexPow(e.multiply(this)));return n.divide(new o(0,2))},o.prototype.cos=function(){var r=new o(Math.E,0),t=new o(0,1),e=new o(0,-1),n=r.complexPow(t.multiply(this)).add(r.complexPow(e.multiply(this)));return n.divide(new o(2,0))},o.prototype.tan=function(){return this.sin().divide(this.cos())},o.prototype.equals=function(r,t){return n.numbersEqual(this.re,r.re,t)&&n.numbersEqual(this.im,r.im,t)},t.exports=o},{"../numbers":2}],6:[function(r,t,e){var n=r("../numbers"),o=n.complex,a=e;a.segment=function(r,t,e){for(var n=[],o=t;o=t)return[new o(r[0],0)];if(Math.log(t)/Math.LN2%1!==0)throw new Error("Array length must be integer power of 2");for(var e=a.fft(a.segment(r,0,2)),n=a.fft(a.segment(r,1,2)),i=[],u=t/2,f=0;t>f;f++){var s=-2*Math.PI*f/t,h=new o(Math.cos(s),Math.sin(s));i[f]=u>f?e[f].add(h.multiply(n[f])):e[f-u].subtract(h.multiply(n[f-u]))}return i}},{"../numbers":2}],7:[function(r,t,e){var n=e;n.fibonacci=function(r){for(var t,e=function(r){for(var t,e=[];r>0;)t=2>r?r:r%2,r=Math.floor(r/2),e.push(t);return e.reverse()},n=1,o=0,a=1,i=e(r),u=0;ue;e++)if(r[e].length!=t)return!1;return!0},n.addition=function(r,t){if(r.length===t.length&&r[0].length===t[0].length){var e,n=new Array(r.length);if(r[0].length)for(e=0;ee;e++){t[e]=new Array(r);for(var n=0;r>n;n++)t[e][n]=e===n?1:0}return t},n.dotproduct=function(r,t){if(r.length===t.length){for(var e=0,n=0;ne;e++){for(n=r[0][e],o=r[0][e],t=1;a>t;t++)o*=r[t][((e+t)%i+i)%i],n*=r[t][((e-t)%i+i)%i];u+=o-n}return u},n.lupDecomposition=function(r){if(!n.isSquare(r))throw new Error("Matrix must be square.");var t,e=r.length,o=n.deepCopy(r),a=n.transpose(n.identity(e)),i=new Array(e);this.getL=function(r){for(var t=r[0].length,e=n.identity(t),o=0;t>o;o++)for(var a=0;t>a;a++)o>a&&(e[o][a]=r[o][a]);return e},this.getU=function(r){for(var t=r[0].length,e=n.identity(t),o=0;t>o;o++)for(var a=0;t>a;a++)a>=o&&(e[o][a]=r[o][a]);return e};for(var u=0;e>u;u++){var f;for(f=0;e>f;f++)i[f]=o[f][u];for(f=0;e>f;f++){t=o[f];for(var s=Math.min(f,u),h=0,l=0;s>l;l++)h+=t[l]*i[l];t[u]=i[f]-=h}var m=u;for(f=u+1;e>f;f++)Math.abs(i[f])>Math.abs(i[m])&&(m=f);if(m!=u&&(o=n.rowSwitch(o,m,u),a=n.rowSwitch(a,m,u)),e>u&&0!==o[u][u])for(f=u+1;e>f;f++)o[f][u]/=o[u][u]}return[this.getL(o),this.getU(o),a]},n.rotate=function(r,t,e){if(2===r.length){var o="clockwise"===e?-1:1,a=t*(Math.PI/180),i=[[Math.cos(a),-1*o*Math.sin(a)],[o*Math.sin(a),Math.cos(a)]];return n.multiply(i,r)}throw new Error("Only two dimensional operations are supported at this time")},n.scale=function(r,t,e){if(2===r.length){var o=[[t,0],[0,e]];return n.multiply(o,r)}throw new Error("Only two dimensional operations are supported at this time")},n.shear=function(r,t,e){if(2===r.length){var o="xaxis"===e?t:0,a="yaxis"===e?t:0,i=[[1,o],[a,1]];return n.multiply(i,r)}throw new Error("Only two dimensional operations are supported at this time")},n.affine=function(r,t,e){if(2===r.length){var o=[[1,0,t],[0,1,e],[0,0,1]],a=[[r[0][0]],[r[1][0]],[1]],i=n.multiply(o,a);return[[i[0][0]],[i[1][0]]]}throw new Error("Only two dimensional operations are supported at this time")},n.rowScale=function(r,t,e){for(var n=new Array(r.length),o=0;oMath.abs(r[s][f])&&(s=e);var h=r[f];if(r[f]=r[s],r[s]=h,Math.abs(r[f][f])<=a)return r;for(e=f;++e=0;){for(o=r[f][f],e=-1;++e=f;)r[e][n]-=r[f][n]*r[e][f]/o;for(r[f][f]/=o,n=i-1;++nt;t++)r[t]=r[t].concat(o[t]);for(r=n.GaussJordanEliminate(r),t=0;e>t;t++)r[t]=r[t].slice(e);return r}throw new Error("The given matrix must be square")},n.getCol=function(r,t){var e=[];if(0>t)throw new Error("The specified column must be a positive integer.");if(t>=r[0].length)throw new Error("The specified column must be between 0 and the number of columns - 1.");for(var n=0;n=t.length)throw new Error("The desired order of the rows must start at 0 and end at the number of rows - 1.");e.push(r[t[n]])}return e},n.reorderCols=function(r,t){var e=[];if(void 0===t)throw new Error("Please enter a desired reordering array.");if(t.length!==r[0].length)throw new Error("The reordered matrix must have the same number of columns as the original matrix.");for(var o=0;o=t.length)throw new Error("The desired order of the rows must start at 0 and end at the number of rows - 1.");e.push(n.getCol(r,t[o]))}return n.transpose(e)},n.reverseRows=function(r){for(var t=[],e=r.length-1;e>-1;e--)t.push(e);return n.reorderRows(r,t)},n.reverseCols=function(r){for(var t=[],e=r.length-1;e>-1;e--)t.push(e);return n.reorderCols(r,t)},n.zeros=function(r,t){var e=new Array(r);if(1>r||1>t)throw new Error("The matrix dimensions must be positive integers.");r=Math.ceil(r),t=Math.ceil(t);for(var n=0;r>n;n++){for(var o=new Array(t),a=0;t>a;a++)o[a]=0;e[n]=o}return e},n.zigzag=function(r,t,e){if(1>=r)throw new Error("Matrix size must be at least 2x2.");r=Math.ceil(r);var o=n.zeros(r,r),a=function(t){var e,n,o,a,i,u=!1,f=r*r,s=1,h=1;for(t[0][0]=f,t[r-1][r-1]=s,a=1;r>a;a++)u?(f-=4*h,s+=4*h,h++):(f--,s++),t[0][a]=f,t[r-1][r-1-a]=s,u=!u;var l=!0;for(a=1;r>a;a++){for(e=0,n=a,o=t[e][n],i=1;a+1>i;i++)l?o-=1:o+=1,e++,n--,t[e][n]=o;l=!l}for(l=r%2===0?!0:!1,a=1;r-1>a;a++){for(e=r-1,n=a,o=t[e][n],i=1;r-a>i;i++)l?o--:o++,e--,n++,t[e][n]=o;l=!l}return t},i=function(r){return n.transpose(a(r))},u=function(r){return n.reverseCols(a(r))},f=function(r){return n.reverseRows(m(u(r)))},s=function(r){return n.reverseRows(a(r))},h=function(r){return n.reverseRows(i(r))},l=function(r){return n.reverseCols(n.reverseRows(a(r)))},m=function(r){return n.transpose(l(r))};if("BR"===t&&"H"===e)return a(o);if("BR"===t&&"V"===e)return i(o);if("BL"===t&&"H"===e)return u(o);if("BL"===t&&"V"===e)return f(o);if("TR"===t&&"H"===e)return s(o);if("TR"===t&&"V"===e)return h(o);if("TL"===t&&"H"===e)return l(o);if("TL"===t&&"V"===e)return m(o);throw new Error("Enter the direction (V,H) and corner (BR,BL,TR,TL) correctly.")},n.vectorNorm=function(r,t){if(!Array.isArray(r)||0===r.length)throw new Error("Vector must be an array of at least length 1.");if("undefined"!=typeof t&&"number"!=typeof t)throw new Error("Norm order must be a number.");t="undefined"==typeof t?2:t;var e,n,o=r.length,a=0;switch(t){case 1/0:for(n=0;o>n;n++)e=Math.abs(r[n]),e>a&&(a=e);break;case-1/0:for(a=1/0,n=0;o>n;n++)e=Math.abs(r[n]),a>e&&(a=e);break;default:for(n=0;o>n;n++)a+=Math.pow(Math.abs(r[n]),t);a=Math.pow(a,1/t)}return a},n.matrixNorm=function(r,t){if(!Array.isArray(r)||0===r.length||!Array.isArray(r[0]))throw new Error("Matrix must be an array of at least length 1.");if("undefined"!=typeof t&&"number"!=typeof t&&null!==t)throw new Error("Norm order must be a number or null.");t="undefined"==typeof t?null:t;var e,n,o,a=r.length,i=r[0].length,u=0;switch(t){case 1/0:for(n=0;a>n;n++){for(e=0,o=0;i>o;o++)e+=Math.abs(r[n][o]);e>u&&(u=e)}break;case-1/0:for(u=1/0,n=0;a>n;n++){for(e=0,o=0;i>o;o++)e+=Math.abs(r[n][o]);u>e&&(u=e)}break;case 1:for(n=0;i>n;n++){for(e=0,o=0;a>o;o++)e+=Math.abs(r[o][n]);e>u&&(u=e)}break;case-1:for(u=1/0,n=0;i>n;n++){for(e=0,o=0;a>o;o++)e+=Math.abs(r[o][n]);u>e&&(u=e)}break;case null:for(n=0;a>n;n++)for(o=0;i>o;o++)u+=Math.pow(r[n][o],2);u=Math.pow(u,.5);break;case 2:throw new Error("Singular values are not yet supported in numbers.js.");case-2:throw new Error("Singular values are not yet supported in numbers.js.");default:for(n=0;a>n;n++)for(o=0;i>o;o++)u+=Math.pow(Math.abs(r[n][o]),t);u=Math.pow(u,1/t)}return u},n.isUpperBand=function(r,t){if(!Array.isArray(r)||!Array.isArray(r[0])||r.length<2)throw new Error("Matrix must be an array of at least dimension 2.");if("number"!=typeof t||0>t||t%1!==0)throw new Error("Upper bandwidth must be a nonzero integer.");for(var e=!0,n=r[0].length,o=0,a=t+1;n>a;a++){if(0!==r[o][a]){e=!1;break}o++}return e},n.isLowerBand=function(r,t){if(!Array.isArray(r)||!Array.isArray(r[0])||r.length<2)throw new Error("Matrix must be an array of at least dimension 2.");if("number"!=typeof t||0>t||t%1!==0)throw new Error("Lower bandwidth must be a nonzero integer.");for(var e=!0,n=r.length,o=0,a=t+1;n>a;a++){if(0!==r[a][o]){e=!1;break}o++}return e},n.isRowDD=function(r){var t=r.length;if(t!==r[0].length)throw new Error("The given matrix must be square.");if(void 0===r[0][0])throw new Error("Input must be a matrix.");for(var e=0;t>e;e++){var n,o=r[e],a=o[e],i=0;for(n=0;e>n;n++)i+=Math.abs(o[n]);for(n=e+1;t>n;n++)i+=Math.abs(o[n]);if(Math.abs(a)e;e++){var n,o=r[e],a=o[e],i=0;for(n=0;e>n;n++)i+=Math.abs(o[n]);for(n=e+1;t>n;n++)i+=Math.abs(o[n]);if(Math.abs(a)<=i)return!1}return!0},n.isColumnDD=function(r){var t=r.length;if(t!==r[0].length)throw new Error("The given matrix must be square.");if(void 0===r[0][0])throw new Error("Input must be a matrix.");for(var e=0;t>e;e++){var o,a=n.getCol(r,e),i=a[e],u=0;for(o=0;e>o;o++)u+=Math.abs(a[o]);for(o=e+1;t>o;o++)u+=Math.abs(a[o]);if(Math.abs(i)e;e++){var o,a=n.getCol(r,e),i=a[e],u=0;for(o=0;e>o;o++)u+=Math.abs(a[o]);for(o=e+1;t>o;o++)u+=Math.abs(a[o]);if(Math.abs(i)<=u)return!1}return!0}},{}],9:[function(r,t,e){var n=r("./basic"),o=e;o.simple=function(r){if(isNaN(r)||!isFinite(r)||r%1||2>r)return!1;if(r%2===0)return 2===r;if(r%3===0)return 3===r;for(var t=5,e=Math.sqrt(r);e>=t;t+=6)if(r%t===0||r%(t+2)===0)return!1;return!0},o.factorization=function(r){r=Math.floor(r);for(var t,e,n=[],o=Math.sqrt,a=r>1&&isFinite(r);a;){if(t=o(r),e=2,r%e)for(e=3;r%e&&(e+=2)t?r:e,n.push(e),a=e!==r,r/=e}return n},o.millerRabin=function(r,t){if(1===arguments.length&&(t=20),2===r)return!0;if(!n.isInt(r)||1>=r||r%2===0)return!1;for(var e=0,o=r-1;;){var a=n.divMod(o,2),i=a[0],u=a[1];if(1===u)break;e+=1,o=i}for(var f=function(t){if(1===n.powerMod(t,o,r))return!1;for(var a=0;e>a;a++)if(n.powerMod(t,Math.pow(2,a)*o,r)===r-1)return!1;return!0},s=0;t>s;s++){var h=2+Math.floor(Math.random()*(r-2-2));if(f(h))return!1}return!0},o.sieve=function(r){if(2>r)return[];for(var t=[2],e=3;r>=e;e++){var n=!1;for(var o in t)n=n||0===e%t[o];n||t.push(e)}return t},o.coprime=function(r,t){return 1===n.gcd(r,t)},o.getPerfectPower=function(r){var t=o.getPrimePower(r);return t&&t[1]>1?t:!1},o.getPrimePower=function(r){if(2>r)return!1;if(o.millerRabin(r))return[r,1];if(r%2===0)return[2,r.toString(2).length-1];var t=o.factorization(r);if(!t)return!1;for(var e=t.length,n=0;e>n;n++)for(var a=0,i=0;r>=a;){if(a=Math.pow(t[n],i),a/r===1)return[t[n],i];i++}return!1}},{"./basic":3}],10:[function(r,t,e){var n=(r("./basic"),e),o=Math.random;n.setGenerator=function(r){if("function"!=typeof r)throw new Error("Must pass a function");o=r},n.sample=function(r,t,e){var n=[];n.length=e;for(var a=0;e>a;a++)n[a]=r+(t-r)*o();return n},n.boxMullerTransform=function(r,t){arguments.length<=1&&(t=1),0===arguments.length&&(r=0);var e,n=0,a=0;do n=2*o()-1,a=2*o()-1,e=n*n+a*a;while(0===e||e>1);var i=Math.sqrt(-2*Math.log(e)/e),u=n*i,f=a*i;return u=r+u*t,f=r+f*t,[u,f]},n.irwinHall=function(r,t){1===arguments.length&&(t=0);for(var e=0,n=0;r>n;n++)e+=o();return e-t},n.bates=function(r,t,e){arguments.length<=2&&(e=0),1===arguments.length&&(t=1);for(var n=0,a=0;r>a;a++)n+=(t-e)*o()+e;return n/r},n.distribution={},n.distribution.normal=function(r,t,e){return arguments.length<=2&&(e=1),1===arguments.length&&(t=0),n.distribution.boxMuller(r,t,e)},n.distribution.logNormal=function(r,t,e){arguments.length<=2&&(e=1),1===arguments.length&&(t=0);var o=function(r){return Math.exp(r)};return n.distribution.boxMuller(r,t,e).map(o)},n.distribution.boxMuller=function(r,t,e,o){arguments.length<=3&&(o=!1),arguments.length<=2&&(e=1),1===arguments.length&&(t=0);for(var a=[],i=0;r>i;i++){var u=n.boxMullerTransform(t,e);a.push(o?u:u[0])}return a},n.distribution.irwinHall=function(r,t,e){arguments.length<=2&&(e=0),1===arguments.length&&(t=r);for(var o=new Array(r),a=0;r>a;a++)o[a]=n.irwinHall(t,e);return o},n.distribution.irwinHallNormal=function(r){return n.distribution.irwinHall(r,12,6)},n.distribution.bates=function(r,t,e){arguments.length<=2&&(e=0),1===arguments.length&&(t=r);for(var o=new Array(r),a=0;r>a;a++)o[a]=n.bates(r,t,e);return o}},{"./basic":3}],11:[function(r,t,e){var n=r("./basic"),o=e;o.mean=function(r){var t=r.length,e=n.sum(r);return e/t},o.median=function(r){return o.quantile(r,1,2)},o.mode=function(r){for(var t={},e=0,n=r.length;n>e;e++)void 0===t[r[e]]?t[r[e]]=0:t[r[e]]++;var o;for(var a in t)t.hasOwnProperty(a)&&(void 0===o||t[a]>t[o])&&(o=a);return Number(o)},o.quantile=function(r,t,e){var n,o,a;return 0===t?Math.min.apply(null,r):t===e?Math.max.apply(null,r):(n=r.slice(0),n.sort(function(r,t){return r-t}),o=n.length,a=o*t/e,a%1===0?.5*n[a-1]+.5*n[a]:n[Math.floor(a)])},o.report=function(r){return{mean:o.mean(r),firstQuartile:o.quantile(r,1,4),median:o.median(r),thirdQuartile:o.quantile(r,3,4),standardDev:o.standardDev(r)}},o.standardDev=function(r){for(var t=r.length,e=o.mean(r),a=[],i=0;iu;u++)o+=r[u]*t[u];return(o-a*i/e)/e}throw new Error("Array mismatch")}},{"./basic":3}]},{},[1])(1)}); \ No newline at end of file diff --git a/test/matrix.test.js b/test/matrix.test.js index bbb65c6..bb7354a 100644 --- a/test/matrix.test.js +++ b/test/matrix.test.js @@ -686,4 +686,80 @@ suite('numbers', function() { done(); }); + test('should test for weak row diagonal dominance', function(done) { + var m1 = [[3,-2,1], + [1,-3,2], + [-1,2,4]]; + var m2 = [[-2,2,1], + [1,3,2], + [1,-2,0]]; + + var expected1 = true; + var expected2 = false; + + var res1 = matrix.isRowDD(m1); + var res2 = matrix.isRowDD(m2); + + assert.deepEqual(res1,expected1); + assert.deepEqual(res2,expected2); + done(); + }); + + test('should test for strict row diagonal dominance', function(done) { + var m1 = [[3,-2,1], + [1,-3,2], + [-1,2,4]]; + var m2 = [[-4,2,1], + [1,6,2], + [1,-2,5]]; + + var expected1 = false; + var expected2 = true; + + var res1 = matrix.isStrictlyRowDD(m1); + var res2 = matrix.isStrictlyRowDD(m2); + + assert.deepEqual(res1,expected1); + assert.deepEqual(res2,expected2); + done(); + }); + + test('should test for weak column diagonal dominance', function(done) { + var m1 = [[3,-2,1], + [1,-3,2], + [-1,2,4]]; + var m2 = [[-4,1,1], + [2,3,2], + [2,-1,5]]; + + var expected1 = false; + var expected2 = true; + + var res1 = matrix.isColumnDD(m1); + var res2 = matrix.isColumnDD(m2); + + assert.deepEqual(res1,expected1); + assert.deepEqual(res2,expected2); + done(); + }); + + test('should test for strict column diagonal dominance', function(done) { + var m1 = [[-4,2,1], + [1,6,2], + [1,-2,5]]; + var m2 = [[-4,1,1], + [2,3,2], + [2,-1,5]]; + + var expected1 = true; + var expected2 = false; + + var res1 = matrix.isStrictlyColumnDD(m1); + var res2 = matrix.isStrictlyColumnDD(m2); + + assert.deepEqual(res1,expected1); + assert.deepEqual(res2,expected2); + done(); + }); + });