Comparing version 1.1.2 to 1.1.4
{ | ||
"name": "ml-gsd", | ||
"version": "1.1.0", | ||
"version": "1.1.4", | ||
"description": "Global Spectra Deconvolution", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -1,3 +0,3 @@ | ||
!function(r,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.GSD=t():r.GSD=t()}(this,function(){return function(r){function t(n){if(o[n])return o[n].exports;var e=o[n]={exports:{},id:n,loaded:!1};return r[n].call(e.exports,e,e.exports,t),e.loaded=!0,e.exports}var o={};return t.m=r,t.c=o,t.p="",t(0)}([function(r,t,o){r.exports.post=o(1),r.exports.gsd=o(15)},function(r,t,o){function n(r,t,o,n,e){var i=o.length,a=[],s=[],f=Math.sign(o[1]-o[0]);-1==f&&(e[0]=o.length-1);for(var u=Math.abs(t-r)/2,h=(r+t)/2,c=!1,l=e[0];!c&&i>l&&l>=0;)Math.abs(o[l]-h)<=u?(a.push(o[l]),s.push(n[l]),l+=f):1==Math.sign(h-o[l])?l+=f:c=!0;return e[0]=l,[a,s]}function e(r,t,o,e,a){var f,u,h=[0],c=i(r,e),l=[],m=1;for("gaussian"==a&&(m=1.17741),f=0;f<c.length;f++){var p=c[f].group;if(p.length>1){var w=n(c[f].limits[0]-c[f].limits[1],c[f].limits[0]+c[f].limits[1],t,o,h);if(w[0].length>5){var v=p[0].width/1e3,d=[3,100,v,v,v,10*v,10*v,11,9,1],y=[];for("gaussian"==a?y=s.optimizeGaussianSum(w,p,d):"lorentzian"==a&&(y=s.optimizeLorentzianSum(w,p,d)),u=0;u<y.length;u++)l.push({x:y[u][0][0],y:y[u][1][0],width:y[u][2][0]*m})}}else{p=p[0];var w=n(p.x-e*p.width,p.x+e*p.width,t,o,h);if(w[0].length>5){var v=p.width/1e3,d=[3,100,v,v,v,10*v,10*v,11,9,1],g=[];if("gaussian"==a)var g=s.optimizeSingleGaussian([w[0],w[1]],p,d);else if("lorentzian"==a)var g=s.optimizeSingleLorentzian([w[0],w[1]],p,d);l.push({x:g[0][0],y:g[1][0],width:g[2][0]*m})}}}return l}function i(r,t){var o,n,e,i,a=[],s=[],f=[r[0].x,t*r[0].width];for(o=0;o<r.length;o++)Math.abs(r[o].x-f[0])<t*r[o].width+f[1]?(a.push(r[o]),e=f[0]+f[1],r[o].x+t*r[o].width>e&&(e=r[o].x+t*r[o].width),i=f[0]-f[1],r[o].x-t*r[o].width<i&&(i=r[o].x-t*r[o].width),f=[(e+i)/2,Math.abs(e-i)/2]):(s.push({limits:f,group:a}),a=[r[o]],f=[r[o].x,t*r[o].width]);for(s.push({limits:f,group:a}),o=s.length-2;o>=0;o--)if(Math.abs(s[o].limits[0]-s[o+1].limits[0])<(s[o].limits[1]+s[o+1].limits[1])/2){for(n=0;n<s[o+1].group.length;n++)s[o].group.push(s[o+1].group[n]);e=s[o].limits[0]+s[o].limits[1],s[o+1].limits[0]+s[o+1].limits[1]>e&&(e=s[o+1].limits[0]+s[o+1].limits[1]),i=s[o].limits[0]-s[o].limits[1],s[o+1].limits[0]-s[o+1].limits[1]<i&&(i=s[o+1].limits[0]-s[o+1].limits[1]),s[o].limits=[(e+i)/2,Math.abs(e-i)/2],s.splice(o+1,1)}return s}function a(r,t){for(var o=t.width,n=[],e=0,i=0,a=1,f=r.length-1;f>=0;f--)r[f].soft&&n.push(r.splice(f,1)[0]);n.push({x:Number.MAX_VALUE});for(var u=[[n[0].x,n[0].y]],h=[0],f=1;f<n.length;f++)if(Math.abs(n[f-1].x-n[f].x)<o)u.push([n[f].x,n[f].y]),n[f].y>e&&(e=n[f].y,i=f),h.push(f),a++;else{if(a>2){var c=s.optimizeSingleLorentzian(u,{x:n[i].x,y:e,width:Math.abs(u[0][0]-u[u.length-1][0])});r.push({x:c[0][0],y:c[1][0],width:c[2][0],soft:!1})}else h.map(function(t){r.push(n[t])});u=[[n[f].x,n[f].y]],h=[f],e=n[f].y,i=f,a=1}return r.sort(function(r,t){return r.x-t.x}),r}var s=o(2);r.exports={optimizePeaks:e,joinBroadPeaks:a}},function(r,t,o){"use strict";function n(r,t,o){var n,e,i,a,s=t.length/3,f=r.rows,u=m.zeros(r.length,1);for(e=0;s>e;e++)for(a=Math.pow(t[e+2*s][0]/2,2),n=t[e+s][0]*a,i=0;f>i;i++)u[i][0]+=n/(Math.pow(r[i][0]-t[e][0],2)+a);return u}function e(r,t,o){for(var n=t[1][0]*Math.pow(t[2][0]/2,2),e=r.rows,i=new m(r.rows,r.columns),a=0;e>a;a++)i[a][0]=n/(Math.pow(r[a][0]-t[0][0],2)+Math.pow(t[2][0]/2,2));return i}function i(r,t,o){for(var n=t[2][0]*t[2][0]/2,e=r.rows,i=new m(r.rows,r.columns),a=0;e>a;a++)i[a][0]=t[1][0]*Math.exp(-(r[a][0]-t[0][0])*(r[a][0]-t[0][0])/n);return i}function a(r,t,o){var n=h(r),i=n[0],a=n[1],s=n[2],f=i.columns,u=[f/Math.sqrt(a.dot(a))],o=Object.create(o||[3,100,.001,.001,.001,.01,.01,11,9,1]),l=[],p=Math.abs(i[0][0]-i[1][0]),w=new m([[-p/1e4],[-.001],[-p/1e4]]),v=new m([[t.x],[1],[t.width]]),d=new m([[t.x-p],[.75],[t.width/4]]),y=new m([[t.x+p],[1.25],[4*t.width]]),g=c.optimize(e,v,i,a,u,w,d,y,l,o);return g=g.p,[g[0],[g[1][0]*s],g[2]]}function s(r,t,o){var n=h(r),e=n[0],a=n[1],s=n[2],f=e.columns,u=[f/Math.sqrt(a.dot(a))],o=Object.create(o||[3,100,.001,.001,.001,.01,.01,11,9,1]),l=[],p=Math.abs(e[0][0]-e[1][0]),w=new m([[-p/1e4],[-.001],[-p/1e4]]),w=new m([[-Math.abs(e[0][0]-e[1][0])/1e3],[-.001],[-t.width/1e3]]),v=new m([[t.x],[1],[t.width]]),d=new m([[t.x-p],[.75],[t.width/4]]),y=new m([[t.x+p],[1.25],[4*t.width]]),g=c.optimize(i,v,e,a,u,w,d,y,l,o);return g=g.p,[g[0],[g[1][0]*s],g[2]]}function f(r,t,o){var e,i=h(r),a=i[0],s=i[1],f=i[2],u=a.columns,p=[u/l.sqrt(s.dot(s))],o=Object.create(o||[3,100,.001,.001,.001,.01,.01,11,9,1]),w=[],v=t.length,d=new m(3*v,1),y=new m(3*v,1),g=new m(3*v,1),b=new m(3*v,1),M=Math.abs(a[0][0]-a[1][0]);for(e=0;v>e;e++)d[e][0]=t[e].x,d[e+v][0]=1,d[e+2*v][0]=t[e].width,y[e][0]=t[e].x-M,y[e+v][0]=0,y[e+2*v][0]=t[e].width/4,g[e][0]=t[e].x+M,g[e+v][0]=1.5,g[e+2*v][0]=4*t[e].width,b[e][0]=-M/1e3,b[e+v][0]=-.001,b[e+2*v][0]=-M/1e3;var b=-Math.abs(a[0][0]-a[1][0])/1e4,x=c.optimize(n,d,a,s,p,b,y,g,w,o);x=x.p;var A=new Array(v);for(e=0;v>e;e++)A[e]=[x[e],[x[e+v][0]*f],x[e+2*v]];return A}function u(r,t,o){var e,i=h(r),a=i[0],s=i[1],f=i[2],u=a.rows,p=new m(u,1),w=u/l.sqrt(s.dot(s));for(e=0;u>e;e++)p[e][0]=w;var o=Object.create(o||[3,100,.001,.001,.001,.01,.01,11,9,2]),v=[],d=t.length,y=new m(3*d,1),g=new m(3*d,1),b=new m(3*d,1),M=new m(3*d,1),x=Math.abs(a[0][0]-a[1][0]);for(e=0;d>e;e++)y[e][0]=t[e].x,y[e+d][0]=t[e].y/f,y[e+2*d][0]=t[e].width,g[e][0]=t[e].x-x,g[e+d][0]=.8*t[e].y/f,g[e+2*d][0]=t[e].width/2,b[e][0]=t[e].x+x,b[e+d][0]=1.2*t[e].y/f,b[e+2*d][0]=2*t[e].width,M[e][0]=-x/1e3,M[e+d][0]=-.001,M[e+2*d][0]=-x/1e3;var A=c.optimize(n,y,a,s,p,M,g,b,v,o);A=A.p;var R=new Array(d);for(e=0;d>e;e++)R[e]=[A[e],[A[e+d][0]*f],A[e+2*d]];return R}function h(r){var t,o,n,e=r.length,i=null,a=null,s=0;if(2==e){var f=r[0].length;if(3>f)throw new SizeException(f);if(i=new m(f,1),a=new m(f,1),t=r[0],o=r[1],"number"==typeof t[0])for(n=0;f>n;n++)i[n][0]=t[n],a[n][0]=o[n],o[n]>s&&(s=o[n]);else if("object"==typeof t[0])for(n=0;f>n;n++)i[n][0]=t[n][0],a[n][0]=o[n][0],o[n][0]>s&&(s=o[n][0])}else{var f=e;if(3>f)throw new SizeException(f);for(i=new m(f,1),a=new m(f,1),n=0;f>n;n++)i[n][0]=r[n][0],a[n][0]=r[n][1],a[n][0]>s&&(s=a[n][0])}for(n=0;f>n;n++)a[n][0]/=s;return[i,a,s]}var c=o(3),l=c.Matrix.algebra,m=o(5);r.exports.optimizeSingleLorentzian=a,r.exports.optimizeLorentzianSum=f,r.exports.optimizeSingleGaussian=s,r.exports.optimizeGaussianSum=u,r.exports.singleGaussian=i,r.exports.singleLorentzian=e},function(r,t,o){"use strict";r.exports=o(4),r.exports.Matrix=o(5),r.exports.Matrix.algebra=o(14)},function(r,t,o){var n=o(5),e=o(14),i={optimize:function(r,t,o,i,a,s,f,u,h,c){var l=0,m=0;if("object"!=typeof t[0])for(var p=0;p<t.length;p++)t[p]=[t[p]];var p,w,v=-50,d=t.length,y=i.length,g=n.zeros(d,1),b=n.zeros(y,1),M=.01/v,x=.01/v,A=n.zeros(y,d);if(o.length!=i.length){console.log("lm.m error: the length of t must equal the length of y_dat"),length_t=o.length,length_y_dat=i.length;var M=0;if(!l)return}a=a||Math.sqrt((y-d+1)/e.multiply(e.transpose(i),i)),s=s||.001,f=f||e.multiply(Math.abs(t),-100),u=u||e.multiply(Math.abs(t),100),h=h||1,c=c||[3,10*d,.001,.001,.001,.01,.01,11,9,1];var R=c[0],z=c[1],k=c[2],S=(c[3],c[4],c[5]),j=c[6],E=c[7],V=c[8],C=c[9];if(l&&3==R&&(R=2),!s.length||1==s.length){for(var q=new Array(d),p=0;d>p;p++)q[p]=[s];s=q}var D=[];for(p=0;p<s.length;p++)0!=s[p][0]&&D.push(p);var I=D.length,O=!1,_=null;if(!a.length||a.length<y){var L=e.multiply(n.ones(y,1),a[0]);_=e.dotMultiply(L,L)}else _=e.dotMultiply(a,a);var J=this.lm_matx(r,o,g,b,1,A,t,i,_,s,h),U=J.JtWJ,T=J.JtWdy,M=J.Chi_sq,P=J.y_hat,A=J.J;switch(Math.max(Math.abs(T))<k&&(console.log(" *** Your Initial Guess is Extremely Close to Optimal ***"),console.log(" *** epsilon_1 = ",k),O=!0),C){case 1:lambda=j;break;default:lambda=j*Math.max(e.diag(U)),nu=2}x=M;for(var W=null;!O&&z>=m;){switch(m+=1,C){case 1:W=e.solve(e.add(U,e.multiply(e.diag(e.diag(U)),lambda)),T);break;default:W=e.solve(e.add(U,e.multiply(n.eye(d),lambda)),T)}var N=new Array(D.length);for(w=0;w<D.length;w++)N[w]=W[D[w]];var G=e.add(t,N);for(w=0;w<G.length;w++)G[w][0]=Math.min(Math.max(f[w][0],G[w][0]),u[w][0]);var Q=e.subtract(i,r(o,G,h)),X=e.multiply(e.transpose(Q),e.dotMultiply(Q,_));if(2==C){var F=e.multiply(e.transpose(T),W),Y=e.multiply(F,e.inv(e.add(e.multiply(e.subtract(X-M),.5)),e.multiply(F,2)));W=e.multiply(Y,W);for(var w=0;w<D.length;w++)N[w]=W[D[w]];G=e.add(t,N),G=e.min(e.max(f,G),u),Q=e.subtract(i,r(o,G,h)),X=e.multiply(e.transpose(Q),mat.dotMultiply(Q,_))}var B=(M-X)/e.multiply(e.multiply(e.transpose(W),2),e.add(e.multiply(lambda,W),T));if(B>S)switch(dX2=M-x,x=M,g=t,b=P,t=G,J=this.lm_matx(r,o,g,b,dX2,A,t,i,_,s,h),U=J.JtWJ,T=J.JtWdy,M=J.Chi_sq,P=J.y_hat,A=J.J,C){case 1:lambda=Math.max(lambda/V,1e-7);break;case 2:lambda=Math.max(lambda/(1+Y),1e-7);break;case 3:lambda=e.multiply(Math.max(1/3,1-(2*B-1)^3),lambda),nu=2}else switch(M=x,m%(2*d)==0&&(J=this.lm_matx(r,o,g,b,-1,A,t,i,_,s,h),U=J.JtWJ,T=J.JtWdy,dX2=J.Chi_sq,P=J.y_hat,A=J.J),C){case 1:lambda=Math.min(lambda*E,1e7);break;case 2:lambda+=Math.abs((X-M)/2/Y);break;case 3:lambda*=nu,nu=2*nu}}return _=e.multiply(e.multiply(e.transpose(Q),Q),n.ones(y,1)),_.apply(function(r,t){_[r][t]=(y-I+1)/_[r][t]}),J=this.lm_matx(r,o,g,b,-1,A,t,i,_,s,h),U=J.JtWJ,T=J.JtWdy,M=J.Chi_sq,P=J.y_hat,A=J.J,{p:t,X2:M}},lm_FD_J:function(r,t,o,i,a,s){var f=i.length,u=o.length;a=a||e.multiply(n.ones(u,1),.001);for(var h=o.clone(),c=new n(f,u),l=new Array(u),m=0;u>m;m++){if(l[m]=a[m]*(1+Math.abs(o[m][0])),o[m]=[h[m][0]+l[m]],0!=l[m])if(y1=r(t,o,s),a[m][0]<0)for(var p=e.dotDivide(e.subtract(y1,i),l[m]),w=0;f>w;w++)c[w][m]=p[w][0];else{o[m][0]=h[m][0]-l[m];for(var p=e.dotDivide(e.subtract(y1,r(t,o,s)),2*l[m]),w=0;f>w;w++)c[w][m]=p[w][0]}o[m]=h[m]}return c},lm_Broyden_J:function(r,t,o,n,i){var a=e.subtract(n,r),s=e.transpose(a);return s.div(e.multiply(s,a)),o=e.add(o,e.multiply(e.subtract(i,e.add(t,e.multiply(o,a))),s))},lm_matx:function(r,t,o,i,a,s,f,u,h,c,l,m){var p=(u.length,f.length);c=c||.001;var w=r(t,f,l);s=m%(2*p)==0||a>0?this.lm_FD_J(r,t,f,w,c,l):this.lm_Broyden_J(o,i,s,f,w);var v=e.subtract(u,w),d=e.multiply(e.transpose(v),e.dotMultiply(v,h)),y=e.transpose(s),g=e.multiply(y,e.dotMultiply(s,e.multiply(h,n.ones(1,p)))),b=e.multiply(y,e.dotMultiply(h,v));return{JtWJ:g,JtWdy:b,Chi_sq:d,y_hat:w,J:s}}};r.exports=i},function(r,t,o){"use strict";r.exports=o(6),r.exports.Decompositions=r.exports.DC=o(7)},function(r,t){"use strict";function o(r){for(var t=0,o=r.length,n=new Array(o);o>t;t++)n[t]=r[t];return n}function n(r,t){var e,i,a=0;if(Array.isArray(r)){if(i=t,e=i?o(r):r,r=e.length,t=e[0].length,"undefined"==typeof t)throw new TypeError("Data must be a 2D array");if(!(r>0&&t>0))throw new RangeError("Invalid dimensions: "+r+"x"+t);for(;r>a;a++){if(e[a].length!==t)throw new RangeError("Inconsistent array dimensions");i&&(e[a]=o(e[a]))}}else{if("number"!=typeof r)throw new TypeError("Invalid arguments");if(!(r>0&&t>0))throw new RangeError("Invalid dimensions: "+r+"x"+t);for(e=new Array(r);r>a;a++)e[a]=new Array(t)}return Object.defineProperty(e,"rows",{writable:!0,value:r}),Object.defineProperty(e,"columns",{writable:!0,value:t}),e.__proto__=n.prototype,e}var e=Array.prototype.splice,i=Array.prototype.concat;n.from1DArray=function(r,t,o){var e,i,a=0;if(e=r*t,e!==o.length)throw new RangeError("Data length does not match given dimensions");for(i=new Array(r);r>a;a++)i[a]=o.slice(a*t,(a+1)*t);return new n(i)},n.rowVector=function(r){return new n([r])},n.columnVector=function(r){for(var t=r.length,o=new Array(t),e=0;t>e;e++)o[e]=[r[e]];return new n(o)},n.empty=function(r,t){return new n(r,t)},n.zeros=function(r,t){return n.empty(r,t).fill(0)},n.ones=function(r,t){return n.empty(r,t).fill(1)},n.rand=function(r,t){for(var o=n.empty(r,t),e=0,i=o.rows;i>e;e++)for(var a=0,s=o.columns;s>a;a++)o[e][a]=Math.random();return o},n.eye=function(r){for(var t=n.zeros(r,r),o=t.rows,e=0;o>e;e++)t[e][e]=1;return t},n.diag=function(r){for(var t=r.length,o=n.zeros(t,t),e=0;t>e;e++)o[e][e]=r[e];return o},n.indices=function(r,t){for(var o=new Array(t-r),n=0;n<o.length;n++)o[n]=r++;return o},n.stack=function(r){var t,o,e;if(n.isMatrix(r)){var i=0,a=0;for(t=0;t<arguments.length;t++)i+=arguments[t].rows,arguments[t].columns>a&&(a=arguments[t].columns);var s=n.zeros(i,a),f=0;for(t=0;t<arguments.length;t++){var u=arguments[t];for(o=0;o<u.rows;o++){for(e=0;e<u.columns;e++)s[f][e]=u[o][e];f++}}return s}if(Array.isArray(r)){var h=n.empty(arguments.length,r.length);for(t=0;t<arguments.length;t++)h.setRow(t,arguments[t]);return h}},n.expand=function(r,t){for(var o=[],e=0;e<t.length;e++)for(var i=0;i<t[e];i++)o.push(r[e]);return new n(o)},n.checkMatrix=function(r){if(!r)throw new TypeError("Argument has to be a matrix");return"Matrix"!==r.klass&&(r=new n(r)),r},n.isMatrix=function(r){return r?"Matrix"===r.klass:!1},Object.defineProperty(n.prototype,"klass",{get:function(){return"Matrix"}}),Object.defineProperty(n.prototype,"size",{get:function(){return this.rows*this.columns}}),n.prototype.checkRowIndex=function(r){if(0>r||r>this.rows-1)throw new RangeError("Row index out of range.")},n.prototype.checkColumnIndex=function(r){if(0>r||r>this.columns-1)throw new RangeError("Column index out of range.")},n.prototype.checkDimensions=function(r){if(this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal.")},n.prototype.apply=function(r){for(var t=this.rows,o=this.columns,n=0;t>n;n++)for(var e=0;o>e;e++)r.call(this,n,e);return this},n.prototype.clone=function(){return new n(this.to2DArray())},n.prototype.to1DArray=function(){return i.apply([],this)},n.prototype.to2DArray=function(){for(var r=this.rows,t=new Array(r),n=0;r>n;n++)t[n]=o(this[n]);return t},n.prototype.isRowVector=function(){return 1===this.rows},n.prototype.isColumnVector=function(){return 1===this.columns},n.prototype.isVector=function(){return 1===this.rows||1===this.columns},n.prototype.isSquare=function(){return this.rows===this.columns},n.prototype.isSymmetric=function(){if(this.isSquare()){for(var r=this.rows,t=0;r>t;t++)for(var o=0;t>=o;o++)if(this[t][o]!==this[o][t])return!1;return!0}return!1},n.prototype.set=function(r,t,o){return this[r][t]=o,this},n.prototype.get=function(r,t){return this[r][t]},n.prototype.fill=function(r){for(var t=this.rows,o=this.columns,n=0;t>n;n++)for(var e=0;o>e;e++)this[n][e]=r;return this},n.prototype.neg=function(){return this.mulS(-1)},n.prototype.add=function(r){return"number"==typeof r?this.addS(r):(r=n.checkMatrix(r),this.addM(r))},n.prototype.addS=function(r){for(var t=this.rows,o=this.columns,n=0;t>n;n++)for(var e=0;o>e;e++)this[n][e]+=r;return this},n.prototype.addM=function(r){this.checkDimensions(r);for(var t=this.rows,o=this.columns,n=0;t>n;n++)for(var e=0;o>e;e++)this[n][e]+=r[n][e];return this},n.prototype.sub=function(r){return"number"==typeof r?this.subS(r):(r=n.checkMatrix(r),this.subM(r))},n.prototype.subS=function(r){for(var t=this.rows,o=this.columns,n=0;t>n;n++)for(var e=0;o>e;e++)this[n][e]-=r;return this},n.prototype.subM=function(r){this.checkDimensions(r);for(var t=this.rows,o=this.columns,n=0;t>n;n++)for(var e=0;o>e;e++)this[n][e]-=r[n][e];return this},n.prototype.mul=function(r){return"number"==typeof r?this.mulS(r):(r=n.checkMatrix(r),this.mulM(r))},n.prototype.mulS=function(r){for(var t=this.rows,o=this.columns,n=0;t>n;n++)for(var e=0;o>e;e++)this[n][e]*=r;return this},n.prototype.mulM=function(r){this.checkDimensions(r);for(var t=this.rows,o=this.columns,n=0;t>n;n++)for(var e=0;o>e;e++)this[n][e]*=r[n][e];return this},n.prototype.div=function(r){return"number"==typeof r?this.divS(r):(r=n.checkMatrix(r),this.divM(r))},n.prototype.divS=function(r){for(var t=this.rows,o=this.columns,n=0;t>n;n++)for(var e=0;o>e;e++)this[n][e]/=r;return this},n.prototype.divM=function(r){this.checkDimensions(r);for(var t=this.rows,o=this.columns,n=0;t>n;n++)for(var e=0;o>e;e++)this[n][e]/=r[n][e];return this},n.prototype.getRow=function(r){return this.checkRowIndex(r),o(this[r])},n.prototype.getRowVector=function(r){return n.rowVector(this.getRow(r))},n.prototype.setRow=function(r,t){if(this.checkRowIndex(r),n.isMatrix(t)&&(t=t.to1DArray()),t.length!==this.columns)throw new RangeError("Invalid row size");return this[r]=o(t),this},n.prototype.removeRow=function(r){if(this.checkRowIndex(r),1===this.rows)throw new RangeError("A matrix cannot have less than one row");return e.call(this,r,1),this.rows-=1,this},n.prototype.addRow=function(r,t){if("undefined"==typeof t&&(t=r,r=this.rows),0>r||r>this.rows)throw new RangeError("Row index out of range.");if(n.isMatrix(t)&&(t=t.to1DArray()),t.length!==this.columns)throw new RangeError("Invalid row size");return e.call(this,r,0,o(t)),this.rows+=1,this},n.prototype.swapRows=function(r,t){this.checkRowIndex(r),this.checkRowIndex(t);var o=this[r];return this[r]=this[t],this[t]=o,this},n.prototype.getColumn=function(r){this.checkColumnIndex(r);for(var t=this.rows,o=new Array(t),n=0;t>n;n++)o[n]=this[n][r];return o},n.prototype.getColumnVector=function(r){return n.columnVector(this.getColumn(r))},n.prototype.setColumn=function(r,t){this.checkColumnIndex(r),n.isMatrix(t)&&(t=t.to1DArray());var o=this.rows;if(t.length!==o)throw new RangeError("Invalid column size");for(var e=0;o>e;e++)this[e][r]=t[e];return this},n.prototype.removeColumn=function(r){if(this.checkColumnIndex(r),1===this.columns)throw new RangeError("A matrix cannot have less than one column");for(var t=0,o=this.rows;o>t;t++)this[t].splice(r,1);return this.columns-=1,this},n.prototype.addColumn=function(r,t){if("undefined"==typeof t&&(t=r,r=this.columns),0>r||r>this.columns)throw new RangeError("Column index out of range.");n.isMatrix(t)&&(t=t.to1DArray());var o=this.rows;if(t.length!==o)throw new RangeError("Invalid column size");for(var e=0;o>e;e++)this[e].splice(r,0,t[e]);return this.columns+=1,this},n.prototype.swapColumns=function(r,t){this.checkRowIndex(r),this.checkRowIndex(t);for(var o,n,e=this.rows,i=0;e>i;i++)n=this[i],o=n[r],n[r]=n[t],n[t]=o;return this},n.prototype.checkRowVector=function(r){if(n.isMatrix(r)&&(r=r.to1DArray()),r.length!==this.columns)throw new RangeError("vector size must be the same as the number of columns");return r},n.prototype.checkColumnVector=function(r){if(n.isMatrix(r)&&(r=r.to1DArray()),r.length!==this.rows)throw new RangeError("vector size must be the same as the number of rows");return r},n.prototype.addRowVector=function(r){r=this.checkRowVector(r);for(var t=this.rows,o=this.columns,n=0;t>n;n++)for(var e=0;o>e;e++)this[n][e]+=r[e];return this},n.prototype.subRowVector=function(r){r=this.checkRowVector(r);for(var t=this.rows,o=this.columns,n=0;t>n;n++)for(var e=0;o>e;e++)this[n][e]-=r[e];return this},n.prototype.mulRowVector=function(r){r=this.checkRowVector(r);for(var t=this.rows,o=this.columns,n=0;t>n;n++)for(var e=0;o>e;e++)this[n][e]*=r[e];return this},n.prototype.divRowVector=function(r){r=this.checkRowVector(r);for(var t=this.rows,o=this.columns,n=0;t>n;n++)for(var e=0;o>e;e++)this[n][e]/=r[e];return this},n.prototype.addColumnVector=function(r){r=this.checkColumnVector(r);for(var t=this.rows,o=this.columns,n=0;t>n;n++)for(var e=0;o>e;e++)this[n][e]+=r[n];return this},n.prototype.subColumnVector=function(r){r=this.checkColumnVector(r);for(var t=this.rows,o=this.columns,n=0;t>n;n++)for(var e=0;o>e;e++)this[n][e]-=r[n];return this},n.prototype.mulColumnVector=function(r){r=this.checkColumnVector(r);for(var t=this.rows,o=this.columns,n=0;t>n;n++)for(var e=0;o>e;e++)this[n][e]*=r[n];return this},n.prototype.divColumnVector=function(r){r=this.checkColumnVector(r);for(var t=this.rows,o=this.columns,n=0;t>n;n++)for(var e=0;o>e;e++)this[n][e]/=r[n];return this},n.prototype.mulRow=function(r,t){this.checkRowIndex(r);for(var o=0,n=this.columns;n>o;o++)this[r][o]*=t;return this},n.prototype.mulColumn=function(r,t){this.checkColumnIndex(r);for(var o=0,n=this.rows;n>o;o++)this[o][r]*=t},n.prototype.max=function(){for(var r=-(1/0),t=this.rows,o=this.columns,n=0;t>n;n++)for(var e=0;o>e;e++)this[n][e]>r&&(r=this[n][e]);return r},n.prototype.maxIndex=function(){for(var r=-(1/0),t={},o=this.rows,n=this.columns,e=0;o>e;e++)for(var i=0;n>i;i++)this[e][i]>r&&(r=this[e][i],t.row=e,t.column=i);return t},n.prototype.min=function(){for(var r=1/0,t=this.rows,o=this.columns,n=0;t>n;n++)for(var e=0;o>e;e++)this[n][e]<r&&(r=this[n][e]);return r},n.prototype.minIndex=function(){for(var r=1/0,t={},o=this.rows,n=this.columns,e=0;o>e;e++)for(var i=0;n>i;i++)this[e][i]<r&&(r=this[e][i],t.row=e,t.column=i);return t},n.prototype.maxRow=function(r){this.checkRowIndex(r);for(var t=-(1/0),o=0,n=this.columns;n>o;o++)this[r][o]>t&&(t=this[r][o]);return t},n.prototype.maxRowIndex=function(r){this.checkRowIndex(r);for(var t=-(1/0),o={row:r},n=0,e=this.columns;e>n;n++)this[r][n]>t&&(t=this[r][n],o.column=n);return o},n.prototype.minRow=function(r){this.checkRowIndex(r);for(var t=1/0,o=0,n=this.columns;n>o;o++)this[r][o]<t&&(t=this[r][o]);return t},n.prototype.minRowIndex=function(r){this.checkRowIndex(r);for(var t=1/0,o={row:r,column:0},n=0,e=this.columns;e>n;n++)this[r][n]<t&&(t=this[r][n],o.column=n);return o},n.prototype.maxColumn=function(r){this.checkColumnIndex(r);for(var t=-(1/0),o=0,n=this.rows;n>o;o++)this[o][r]>t&&(t=this[o][r]);return t},n.prototype.maxColumnIndex=function(r){this.checkColumnIndex(r);for(var t=-(1/0),o={row:0,column:r},n=0,e=this.rows;e>n;n++)this[n][r]>t&&(t=this[n][r],o.row=n);return o},n.prototype.minColumn=function(r){this.checkColumnIndex(r);for(var t=1/0,o=0,n=this.rows;n>o;o++)this[o][r]<t&&(t=this[o][r]);return t},n.prototype.minColumnIndex=function(r){this.checkColumnIndex(r);for(var t=1/0,o={row:0,column:r},n=0,e=this.rows;e>n;n++)this[n][r]<t&&(t=this[n][r],o.row=n);return o},n.prototype.diag=function a(){if(!this.isSquare())throw new TypeError("Only square matrices have a diagonal.");for(var a=new Array(this.rows),r=0,t=this.rows;t>r;r++)a[r]=this[r][r];return a},n.prototype.sum=function(){for(var r=0,t=this.rows,o=this.columns,n=0;t>n;n++)for(var e=0;o>e;e++)r+=this[n][e];return r},n.prototype.mean=function(){return this.sum()/this.size},n.prototype.prod=function s(){for(var s=1,r=this.rows,t=this.columns,o=0;r>o;o++)for(var n=0;t>n;n++)s*=this[o][n];return s},n.prototype.cumulativeSum=function(){for(var r=0,t=this.rows,o=this.columns,n=0;t>n;n++)for(var e=0;o>e;e++)r+=this[n][e],this[n][e]=r;return this},n.prototype.dot=function f(r){if(this.size!==r.size)throw new RangeError("vectors do not have the same size");for(var t=this.to1DArray(),o=r.to1DArray(),f=0,n=t.length,e=0;n>e;e++)f+=t[e]*o[e];return f},n.prototype.mmul=function(r){if(!n.isMatrix(r))throw new TypeError('parameter "other" must be a matrix');this.columns!==r.rows&&console.warn("Number of columns of left matrix are not equal to number of rows of right matrix.");var t,o,e,i=this.rows,a=this.columns,s=r.columns,f=new n(i,s),u=new Array(a);for(o=0;s>o;o++){for(e=0;a>e;e++)u[e]=r[e][o];for(t=0;i>t;t++){var h=this[t],c=0;for(e=0;a>e;e++)c+=h[e]*u[e];f[t][o]=c}}return f},n.prototype.sortRows=function(r){for(var t=0,o=this.rows;o>t;t++)this[t].sort(r);return this},n.prototype.sortColumns=function(r){for(var t=0,o=this.columns;o>t;t++)this.setColumn(t,this.getColumn(t).sort(r));return this},n.prototype.transpose=function(){for(var r=new n(this.columns,this.rows),t=this.rows,o=this.columns,e=0;t>e;e++)for(var i=0;o>i;i++)r[i][e]=this[e][i];return r},n.prototype.subMatrix=function(r,t,o,e){if(r>t||o>e||0>r||r>=this.rows||0>t||t>=this.rows||0>o||o>=this.columns||0>e||e>=this.columns)throw new RangeError("Argument out of range");for(var i=new n(t-r+1,e-o+1),a=r;t>=a;a++)for(var s=o;e>=s;s++)i[a-r][s-o]=this[a][s];return i},n.prototype.subMatrixRow=function(r,t,o){if("undefined"==typeof t?(t=0,o=this.columns-1):"undefined"==typeof o&&(o=this.columns-1),t>o||0>t||t>=this.columns||0>o||o>=this.columns)throw new RangeError("Argument out of range.");for(var e=r.length,i=this.rows,a=new n(e,o-t+1),s=0;e>s;s++)for(var f=t;o>=f;f++){if(r[s]<0||r[s]>=i)throw new RangeError("Argument out of range.");a[s][f-t]=this[r[s]][f]}return a},n.prototype.subMatrixColumn=function(r,t,o){if("undefined"==typeof t?(t=0,o=this.rows-1):"undefined"==typeof o&&(o=this.rows-1),t>o||0>t||t>=this.rows||0>o||o>=this.rows)throw new RangeError("Argument out of range.");for(var e=r.length,i=this.columns,a=new n(o-t+1,e),s=0;e>s;s++)for(var f=t;o>=f;f++){if(r[s]<0||r[s]>=i)throw new RangeError("Argument out of range.");a[f-t][s]=this[f][r[s]]}return a},n.prototype.trace=function u(){if(!this.isSquare())throw new TypeError("The matrix is not square");for(var u=0,r=0,t=this.rows;t>r;r++)u+=this[r][r];return u},n.prototype.abs=function(){for(var r=this.rows,t=this.columns,o=0;r>o;o++)for(var n=0;t>n;n++)this[o][n]=Math.abs(this[o][n])},r.exports=n},function(r,t,o){"use strict";function n(r){return e(r,i.eye(r.rows))}function e(r,t){return r.isSquare()?new f(r).solve(t):new u(r).solve(t)}var i=o(6),a=o(8),s=o(10),f=o(11),u=o(12),h=o(13);i.prototype.inverse=function(){return n(this)},i.prototype.solve=function(r){return e(this,r)},r.exports={SingularValueDecomposition:a,SVD:a,EigenvalueDecomposition:s,EVD:s,LuDecomposition:f,LU:f,QrDecomposition:u,QR:u,CholeskyDecomposition:h,CHO:h,inverse:n,solve:e}},function(r,t,o){"use strict";function n(r,t){if(!(this instanceof n))return new n(r,t);r=e.checkMatrix(r),t=t||{};var o=r.clone(),a=r.rows,s=r.columns,f=Math.min(a,s),u=!0,h=!0;t.computeLeftSingularVectors===!1&&(u=!1),t.computeRightSingularVectors===!1&&(h=!1);var c=t.autoTranspose===!0,l=!1;if(s>a)if(c){o=o.transpose(),a=o.rows,s=o.columns,l=!0;var m=u;u=h,h=m}else console.warn("Computing SVD on a matrix with more columns than rows. Consider enabling autoTranspose");var p,w,v,d,y,g,b,M,x,A,R,z,k,S,j,E,V,C,q,D,I,O=new Array(Math.min(a+1,s)),_=e.zeros(a,f),L=e.zeros(s,s),J=new Array(s),U=new Array(a),T=Math.min(a-1,s),P=Math.max(0,Math.min(s-2,a));for(v=0,A=Math.max(T,P);A>v;v++){if(T>v){for(O[v]=0,p=v;a>p;p++)O[v]=i(O[v],o[p][v]);if(0!==O[v]){for(o[v][v]<0&&(O[v]=-O[v]),p=v;a>p;p++)o[p][v]/=O[v];o[v][v]+=1}O[v]=-O[v]}for(w=v+1;s>w;w++){if(T>v&&0!==O[v]){for(y=0,p=v;a>p;p++)y+=o[p][v]*o[p][w];for(y=-y/o[v][v],p=v;a>p;p++)o[p][w]+=y*o[p][v]}J[w]=o[v][w]}if(u&&T>v)for(p=v;a>p;p++)_[p][v]=o[p][v];if(P>v){for(J[v]=0,p=v+1;s>p;p++)J[v]=i(J[v],J[p]);if(0!==J[v]){for(J[v+1]<0&&(J[v]=-J[v]),p=v+1;s>p;p++)J[p]/=J[v];J[v+1]+=1}if(J[v]=-J[v],a>v+1&&0!==J[v]){for(p=v+1;a>p;p++)U[p]=0;for(w=v+1;s>w;w++)for(p=v+1;a>p;p++)U[p]+=J[w]*o[p][w];for(w=v+1;s>w;w++)for(y=-J[w]/J[v+1],p=v+1;a>p;p++)o[p][w]+=y*U[p]}if(h)for(p=v+1;s>p;p++)L[p][v]=J[p]}}if(d=Math.min(s,a+1),s>T&&(O[T]=o[T][T]),d>a&&(O[d-1]=0),d>P+1&&(J[P]=o[P][d-1]),J[d-1]=0,u){for(w=T;f>w;w++){for(p=0;a>p;p++)_[p][w]=0;_[w][w]=1}for(v=T-1;v>=0;v--)if(0!==O[v]){for(w=v+1;f>w;w++){for(y=0,p=v;a>p;p++)y+=_[p][v]*_[p][w];for(y=-y/_[v][v],p=v;a>p;p++)_[p][w]+=y*_[p][v]}for(p=v;a>p;p++)_[p][v]=-_[p][v];for(_[v][v]=1+_[v][v],p=0;v-1>p;p++)_[p][v]=0}else{for(p=0;a>p;p++)_[p][v]=0;_[v][v]=1}}if(h)for(v=s-1;v>=0;v--){if(P>v&&0!==J[v])for(w=v+1;s>w;w++){for(y=0,p=v+1;s>p;p++)y+=L[p][v]*L[p][w];for(y=-y/L[v+1][v],p=v+1;s>p;p++)L[p][w]+=y*L[p][v]}for(p=0;s>p;p++)L[p][v]=0;L[v][v]=1}for(var W=d-1,N=0,G=Math.pow(2,-52);d>0;){for(v=d-2;v>=-1&&-1!==v;v--)if(Math.abs(J[v])<=G*(Math.abs(O[v])+Math.abs(O[v+1]))){J[v]=0;break}if(v===d-2)R=4;else{for(g=d-1;g>=v&&g!==v;g--)if(y=(g!==d?Math.abs(J[g]):0)+(g!==v+1?Math.abs(J[g-1]):0),Math.abs(O[g])<=G*y){O[g]=0;break}g===v?R=3:g===d-1?R=1:(R=2,v=g)}switch(v++,R){case 1:for(b=J[d-2],J[d-2]=0,w=d-2;w>=v;w--)if(y=i(O[w],b),M=O[w]/y,x=b/y,O[w]=y,w!==v&&(b=-x*J[w-1],J[w-1]=M*J[w-1]),h)for(p=0;s>p;p++)y=M*L[p][w]+x*L[p][d-1],L[p][d-1]=-x*L[p][w]+M*L[p][d-1],L[p][w]=y;break;case 2:for(b=J[v-1],J[v-1]=0,w=v;d>w;w++)if(y=i(O[w],b),M=O[w]/y,x=b/y,O[w]=y,b=-x*J[w],J[w]=M*J[w],u)for(p=0;a>p;p++)y=M*_[p][w]+x*_[p][v-1],_[p][v-1]=-x*_[p][w]+M*_[p][v-1],_[p][w]=y;break;case 3:for(z=Math.max(Math.max(Math.max(Math.max(Math.abs(O[d-1]),Math.abs(O[d-2])),Math.abs(J[d-2])),Math.abs(O[v])),Math.abs(J[v])),k=O[d-1]/z,S=O[d-2]/z,j=J[d-2]/z,E=O[v]/z,V=J[v]/z,C=((S+k)*(S-k)+j*j)/2,q=k*j*(k*j),D=0,(0!==C||0!==q)&&(D=Math.sqrt(C*C+q),0>C&&(D=-D),D=q/(C+D)),b=(E+k)*(E-k)+D,I=E*V,w=v;d-1>w;w++){if(y=i(b,I),M=b/y,x=I/y,w!==v&&(J[w-1]=y),b=M*O[w]+x*J[w],J[w]=M*J[w]-x*O[w],I=x*O[w+1],O[w+1]=M*O[w+1],h)for(p=0;s>p;p++)y=M*L[p][w]+x*L[p][w+1],L[p][w+1]=-x*L[p][w]+M*L[p][w+1],L[p][w]=y;if(y=i(b,I),M=b/y,x=I/y,O[w]=y,b=M*J[w]+x*O[w+1],O[w+1]=-x*J[w]+M*O[w+1],I=x*J[w+1],J[w+1]=M*J[w+1],u&&a-1>w)for(p=0;a>p;p++)y=M*_[p][w]+x*_[p][w+1],_[p][w+1]=-x*_[p][w]+M*_[p][w+1],_[p][w]=y}J[d-2]=b,N+=1;break;case 4:if(O[v]<=0&&(O[v]=O[v]<0?-O[v]:0,h))for(p=0;W>=p;p++)L[p][v]=-L[p][v];for(;W>v&&!(O[v]>=O[v+1]);){if(y=O[v],O[v]=O[v+1],O[v+1]=y,h&&s-1>v)for(p=0;s>p;p++)y=L[p][v+1],L[p][v+1]=L[p][v],L[p][v]=y;if(u&&a-1>v)for(p=0;a>p;p++)y=_[p][v+1],_[p][v+1]=_[p][v],_[p][v]=y;v++}N=0,d--}}if(l){var Q=L;L=_,_=Q}this.m=a,this.n=s,this.s=O,this.U=_,this.V=L}var e=o(6),i=o(9).hypotenuse;n.prototype={get condition(){return this.s[0]/this.s[Math.min(this.m,this.n)-1]},get norm2(){return this.s[0]},get rank(){for(var r=Math.pow(2,-52),t=Math.max(this.m,this.n)*this.s[0]*r,o=0,n=this.s,e=0,i=n.length;i>e;e++)n[e]>t&&o++;return o},get diagonal(){return this.s},get threshold(){return Math.pow(2,-52)/2*Math.max(this.m,this.n)*this.s[0]},get leftSingularVectors(){return this.U},get rightSingularVectors(){return this.V},get diagonalMatrix(){return e.diag(this.s)},solve:function(r){var t,o=r,n=this.threshold,i=this.s.length,a=e.zeros(i,i);for(t=0;i>t;t++)Math.abs(this.s[t])<=n?a[t][t]=0:a[t][t]=1/this.s[t];var s,f,u,h=this.V.mmul(a),c=this.V.rows,l=this.U.rows,m=e.zeros(c,l);for(t=0;c>t;t++)for(s=0;l>s;s++){for(u=0,f=0;i>f;f++)u+=h[t][f]*this.U[s][f];m[t][s]=u}return m.mmul(o)},solveForDiagonal:function(r){return this.solve(e.diag(r))},inverse:function(){var r,t,o=this.threshold,n=this.V.rows,i=this.V.columns,a=new e(n,this.s.length);for(r=0;n>r;r++)for(t=0;i>t;t++)Math.abs(this.s[t])>o?a[r][t]=this.V[r][t]/this.s[t]:a[r][t]=0;var s,f,u=this.U.rows,h=this.U.columns,c=new e(n,u);for(r=0;n>r;r++)for(t=0;u>t;t++){for(f=0,s=0;h>s;s++)f+=a[r][s]*this.U[t][s];c[r][t]=f}return c}},r.exports=n},function(r,t){"use strict";t.hypotenuse=function(r,t){var o;return Math.abs(r)>Math.abs(t)?(o=t/r,Math.abs(r)*Math.sqrt(1+o*o)):0!==t?(o=r/t,Math.abs(t)*Math.sqrt(1+o*o)):0}},function(r,t,o){"use strict";function n(r){if(!(this instanceof n))return new n(r);if(r=u.checkMatrix(r),!r.isSquare())throw new Error("Matrix is not a square matrix");var t,o,f=r.columns,h=u.zeros(f,f),c=new Array(f),l=new Array(f),m=r;if(r.isSymmetric()){for(t=0;f>t;t++)for(o=0;f>o;o++)h[t][o]=m[t][o];e(f,l,c,h),i(f,l,c,h)}else{var p=u.zeros(f,f),w=new Array(f);for(o=0;f>o;o++)for(t=0;f>t;t++)p[t][o]=m[t][o];a(f,p,w,h),s(f,l,c,h,p)}this.n=f,this.e=l,this.d=c,this.V=h}function e(r,t,o,n){var e,i,a,s,f,u,h,c;for(f=0;r>f;f++)o[f]=n[r-1][f];for(s=r-1;s>0;s--){for(c=0,a=0,u=0;s>u;u++)c+=Math.abs(o[u]);if(0===c)for(t[s]=o[s-1],f=0;s>f;f++)o[f]=n[s-1][f],n[s][f]=0,n[f][s]=0;else{for(u=0;s>u;u++)o[u]/=c,a+=o[u]*o[u];for(e=o[s-1],i=Math.sqrt(a),e>0&&(i=-i),t[s]=c*i,a-=e*i,o[s-1]=e-i,f=0;s>f;f++)t[f]=0;for(f=0;s>f;f++){for(e=o[f],n[f][s]=e,i=t[f]+n[f][f]*e,u=f+1;s-1>=u;u++)i+=n[u][f]*o[u],t[u]+=n[u][f]*e;t[f]=i}for(e=0,f=0;s>f;f++)t[f]/=a,e+=t[f]*o[f];for(h=e/(a+a),f=0;s>f;f++)t[f]-=h*o[f];for(f=0;s>f;f++){for(e=o[f],i=t[f],u=f;s-1>=u;u++)n[u][f]-=e*t[u]+i*o[u];o[f]=n[s-1][f],n[s][f]=0}}o[s]=a}for(s=0;r-1>s;s++){if(n[r-1][s]=n[s][s],n[s][s]=1,a=o[s+1],0!==a){for(u=0;s>=u;u++)o[u]=n[u][s+1]/a;for(f=0;s>=f;f++){for(i=0,u=0;s>=u;u++)i+=n[u][s+1]*n[u][f];for(u=0;s>=u;u++)n[u][f]-=i*o[u]}}for(u=0;s>=u;u++)n[u][s+1]=0}for(f=0;r>f;f++)o[f]=n[r-1][f],n[r-1][f]=0;n[r-1][r-1]=1,t[0]=0}function i(r,t,o,n){var e,i,a,s,f,u,c,l,m,p,w,v,d,y,g,b,M;for(a=1;r>a;a++)t[a-1]=t[a];t[r-1]=0;var x=0,A=0,R=Math.pow(2,-52);for(u=0;r>u;u++){for(A=Math.max(A,Math.abs(o[u])+Math.abs(t[u])),c=u;r>c&&!(Math.abs(t[c])<=R*A);)c++; | ||
if(c>u){M=0;do{for(M+=1,e=o[u],l=(o[u+1]-e)/(2*t[u]),m=h(l,1),0>l&&(m=-m),o[u]=t[u]/(l+m),o[u+1]=t[u]*(l+m),p=o[u+1],i=e-o[u],a=u+2;r>a;a++)o[a]-=i;for(x+=i,l=o[c],w=1,v=w,d=w,y=t[u+1],g=0,b=0,a=c-1;a>=u;a--)for(d=v,v=w,b=g,e=w*t[a],i=w*l,m=h(l,t[a]),t[a+1]=g*m,g=t[a]/m,w=l/m,l=w*o[a]-g*e,o[a+1]=i+g*(w*e+g*o[a]),f=0;r>f;f++)i=n[f][a+1],n[f][a+1]=g*n[f][a]+w*i,n[f][a]=w*n[f][a]-g*i;l=-g*b*d*y*t[u]/p,t[u]=g*l,o[u]=w*l}while(Math.abs(t[u])>R*A)}o[u]=o[u]+x,t[u]=0}for(a=0;r-1>a;a++){for(f=a,l=o[a],s=a+1;r>s;s++)o[s]<l&&(f=s,l=o[s]);if(f!==a)for(o[f]=o[a],o[a]=l,s=0;r>s;s++)l=n[s][a],n[s][a]=n[s][f],n[s][f]=l}}function a(r,t,o,n){var e,i,a,s,f,u,h,c=0,l=r-1;for(u=c+1;l-1>=u;u++){for(h=0,s=u;l>=s;s++)h+=Math.abs(t[s][u-1]);if(0!==h){for(a=0,s=l;s>=u;s--)o[s]=t[s][u-1]/h,a+=o[s]*o[s];for(i=Math.sqrt(a),o[u]>0&&(i=-i),a-=o[u]*i,o[u]=o[u]-i,f=u;r>f;f++){for(e=0,s=l;s>=u;s--)e+=o[s]*t[s][f];for(e/=a,s=u;l>=s;s++)t[s][f]-=e*o[s]}for(s=0;l>=s;s++){for(e=0,f=l;f>=u;f--)e+=o[f]*t[s][f];for(e/=a,f=u;l>=f;f++)t[s][f]-=e*o[f]}o[u]=h*o[u],t[u][u-1]=h*i}}for(s=0;r>s;s++)for(f=0;r>f;f++)n[s][f]=s===f?1:0;for(u=l-1;u>=c+1;u--)if(0!==t[u][u-1]){for(s=u+1;l>=s;s++)o[s]=t[s][u-1];for(f=u;l>=f;f++){for(i=0,s=u;l>=s;s++)i+=o[s]*n[s][f];for(i=i/o[u]/t[u][u-1],s=u;l>=s;s++)n[s][f]+=i*o[s]}}}function s(r,t,o,n,e){var i,a,s,u,h,c,l,m,p,w,v,d,y,g,b,M=r-1,x=0,A=r-1,R=Math.pow(2,-52),z=0,k=0,S=0,j=0,E=0,V=0,C=0,q=0;for(i=0;r>i;i++)for((x>i||i>A)&&(o[i]=e[i][i],t[i]=0),a=Math.max(i-1,0);r>a;a++)k+=Math.abs(e[i][a]);for(;M>=x;){for(u=M;u>x&&(V=Math.abs(e[u-1][u-1])+Math.abs(e[u][u]),0===V&&(V=k),!(Math.abs(e[u][u-1])<R*V));)u--;if(u===M)e[M][M]=e[M][M]+z,o[M]=e[M][M],t[M]=0,M--,q=0;else if(u===M-1){if(l=e[M][M-1]*e[M-1][M],S=(e[M-1][M-1]-e[M][M])/2,j=S*S+l,C=Math.sqrt(Math.abs(j)),e[M][M]=e[M][M]+z,e[M-1][M-1]=e[M-1][M-1]+z,m=e[M][M],j>=0){for(C=S>=0?S+C:S-C,o[M-1]=m+C,o[M]=o[M-1],0!==C&&(o[M]=m-l/C),t[M-1]=0,t[M]=0,m=e[M][M-1],V=Math.abs(m)+Math.abs(C),S=m/V,j=C/V,E=Math.sqrt(S*S+j*j),S/=E,j/=E,a=M-1;r>a;a++)C=e[M-1][a],e[M-1][a]=j*C+S*e[M][a],e[M][a]=j*e[M][a]-S*C;for(i=0;M>=i;i++)C=e[i][M-1],e[i][M-1]=j*C+S*e[i][M],e[i][M]=j*e[i][M]-S*C;for(i=x;A>=i;i++)C=n[i][M-1],n[i][M-1]=j*C+S*n[i][M],n[i][M]=j*n[i][M]-S*C}else o[M-1]=m+S,o[M]=m+S,t[M-1]=C,t[M]=-C;M-=2,q=0}else{if(m=e[M][M],p=0,l=0,M>u&&(p=e[M-1][M-1],l=e[M][M-1]*e[M-1][M]),10===q){for(z+=m,i=x;M>=i;i++)e[i][i]-=m;V=Math.abs(e[M][M-1])+Math.abs(e[M-1][M-2]),m=p=.75*V,l=-.4375*V*V}if(30===q&&(V=(p-m)/2,V=V*V+l,V>0)){for(V=Math.sqrt(V),m>p&&(V=-V),V=m-l/((p-m)/2+V),i=x;M>=i;i++)e[i][i]-=V;z+=V,m=p=l=.964}for(q+=1,h=M-2;h>=u&&(C=e[h][h],E=m-C,V=p-C,S=(E*V-l)/e[h+1][h]+e[h][h+1],j=e[h+1][h+1]-C-E-V,E=e[h+2][h+1],V=Math.abs(S)+Math.abs(j)+Math.abs(E),S/=V,j/=V,E/=V,h!==u)&&!(Math.abs(e[h][h-1])*(Math.abs(j)+Math.abs(E))<R*(Math.abs(S)*(Math.abs(e[h-1][h-1])+Math.abs(C)+Math.abs(e[h+1][h+1]))));)h--;for(i=h+2;M>=i;i++)e[i][i-2]=0,i>h+2&&(e[i][i-3]=0);for(s=h;M-1>=s&&(g=s!==M-1,s!==h&&(S=e[s][s-1],j=e[s+1][s-1],E=g?e[s+2][s-1]:0,m=Math.abs(S)+Math.abs(j)+Math.abs(E),0!==m&&(S/=m,j/=m,E/=m)),0!==m);s++)if(V=Math.sqrt(S*S+j*j+E*E),0>S&&(V=-V),0!==V){for(s!==h?e[s][s-1]=-V*m:u!==h&&(e[s][s-1]=-e[s][s-1]),S+=V,m=S/V,p=j/V,C=E/V,j/=S,E/=S,a=s;r>a;a++)S=e[s][a]+j*e[s+1][a],g&&(S+=E*e[s+2][a],e[s+2][a]=e[s+2][a]-S*C),e[s][a]=e[s][a]-S*m,e[s+1][a]=e[s+1][a]-S*p;for(i=0;i<=Math.min(M,s+3);i++)S=m*e[i][s]+p*e[i][s+1],g&&(S+=C*e[i][s+2],e[i][s+2]=e[i][s+2]-S*E),e[i][s]=e[i][s]-S,e[i][s+1]=e[i][s+1]-S*j;for(i=x;A>=i;i++)S=m*n[i][s]+p*n[i][s+1],g&&(S+=C*n[i][s+2],n[i][s+2]=n[i][s+2]-S*E),n[i][s]=n[i][s]-S,n[i][s+1]=n[i][s+1]-S*j}}}if(0!==k){for(M=r-1;M>=0;M--)if(S=o[M],j=t[M],0===j)for(u=M,e[M][M]=1,i=M-1;i>=0;i--){for(l=e[i][i]-S,E=0,a=u;M>=a;a++)E+=e[i][a]*e[a][M];if(t[i]<0)C=l,V=E;else if(u=i,0===t[i]?e[i][M]=0!==l?-E/l:-E/(R*k):(m=e[i][i+1],p=e[i+1][i],j=(o[i]-S)*(o[i]-S)+t[i]*t[i],c=(m*V-C*E)/j,e[i][M]=c,e[i+1][M]=Math.abs(m)>Math.abs(C)?(-E-l*c)/m:(-V-p*c)/C),c=Math.abs(e[i][M]),R*c*c>1)for(a=i;M>=a;a++)e[a][M]=e[a][M]/c}else if(0>j)for(u=M-1,Math.abs(e[M][M-1])>Math.abs(e[M-1][M])?(e[M-1][M-1]=j/e[M][M-1],e[M-1][M]=-(e[M][M]-S)/e[M][M-1]):(b=f(0,-e[M-1][M],e[M-1][M-1]-S,j),e[M-1][M-1]=b[0],e[M-1][M]=b[1]),e[M][M-1]=0,e[M][M]=1,i=M-2;i>=0;i--){for(w=0,v=0,a=u;M>=a;a++)w+=e[i][a]*e[a][M-1],v+=e[i][a]*e[a][M];if(l=e[i][i]-S,t[i]<0)C=l,E=w,V=v;else if(u=i,0===t[i]?(b=f(-w,-v,l,j),e[i][M-1]=b[0],e[i][M]=b[1]):(m=e[i][i+1],p=e[i+1][i],d=(o[i]-S)*(o[i]-S)+t[i]*t[i]-j*j,y=2*(o[i]-S)*j,0===d&&0===y&&(d=R*k*(Math.abs(l)+Math.abs(j)+Math.abs(m)+Math.abs(p)+Math.abs(C))),b=f(m*E-C*w+j*v,m*V-C*v-j*w,d,y),e[i][M-1]=b[0],e[i][M]=b[1],Math.abs(m)>Math.abs(C)+Math.abs(j)?(e[i+1][M-1]=(-w-l*e[i][M-1]+j*e[i][M])/m,e[i+1][M]=(-v-l*e[i][M]-j*e[i][M-1])/m):(b=f(-E-p*e[i][M-1],-V-p*e[i][M],C,j),e[i+1][M-1]=b[0],e[i+1][M]=b[1])),c=Math.max(Math.abs(e[i][M-1]),Math.abs(e[i][M])),R*c*c>1)for(a=i;M>=a;a++)e[a][M-1]=e[a][M-1]/c,e[a][M]=e[a][M]/c}for(i=0;r>i;i++)if(x>i||i>A)for(a=i;r>a;a++)n[i][a]=e[i][a];for(a=r-1;a>=x;a--)for(i=x;A>=i;i++){for(C=0,s=x;s<=Math.min(a,A);s++)C+=n[i][s]*e[s][a];n[i][a]=C}}}function f(r,t,o,n){var e,i;return Math.abs(o)>Math.abs(n)?(e=n/o,i=o+e*n,[(r+e*t)/i,(t-e*r)/i]):(e=o/n,i=n+e*o,[(e*r+t)/i,(e*t-r)/i])}var u=o(6),h=o(9).hypotenuse;n.prototype={get realEigenvalues(){return this.d},get imaginaryEigenvalues(){return this.e},get eigenvectorMatrix(){return this.V},get diagonalMatrix(){var r,t,o=this.n,n=this.e,e=this.d,i=new u(o,o);for(r=0;o>r;r++){for(t=0;o>t;t++)i[r][t]=0;i[r][r]=e[r],n[r]>0?i[r][r+1]=n[r]:n[r]<0&&(i[r][r-1]=n[r])}return i}},r.exports=n},function(r,t,o){"use strict";function n(r){if(!(this instanceof n))return new n(r);r=e.checkMatrix(r);var t,o,i,a,s,f,u,h,c,l,m=r.clone(),p=m.rows,w=m.columns,v=new Array(p),d=1;for(t=0;p>t;t++)v[t]=t;for(c=new Array(p),o=0;w>o;o++){for(t=0;p>t;t++)c[t]=m[t][o];for(t=0;p>t;t++){for(h=m[t],l=Math.min(t,o),s=0,i=0;l>i;i++)s+=h[i]*c[i];h[o]=c[t]-=s}for(a=o,t=o+1;p>t;t++)Math.abs(c[t])>Math.abs(c[a])&&(a=t);if(a!==o){for(i=0;w>i;i++)f=m[a][i],m[a][i]=m[o][i],m[o][i]=f;u=v[a],v[a]=v[o],v[o]=u,d=-d}if(p>o&&0!==m[o][o])for(t=o+1;p>t;t++)m[t][o]/=m[o][o]}this.LU=m,this.pivotVector=v,this.pivotSign=d}var e=o(6);n.prototype={isSingular:function(){for(var r=this.LU,t=r.columns,o=0;t>o;o++)if(0===r[o][o])return!0;return!1},get determinant(){var r=this.LU;if(!r.isSquare())throw new Error("Matrix must be square");for(var t=this.pivotSign,o=r.columns,n=0;o>n;n++)t*=r[n][n];return t},get lowerTriangularFactor(){for(var r=this.LU,t=r.rows,o=r.columns,n=new e(t,o),i=0;t>i;i++)for(var a=0;o>a;a++)i>a?n[i][a]=r[i][a]:i===a?n[i][a]=1:n[i][a]=0;return n},get upperTriangularFactor(){for(var r=this.LU,t=r.rows,o=r.columns,n=new e(t,o),i=0;t>i;i++)for(var a=0;o>a;a++)a>=i?n[i][a]=r[i][a]:n[i][a]=0;return n},get pivotPermutationVector(){return this.pivotVector.slice()},solve:function(r){r=e.checkMatrix(r);var t=this.LU,o=t.rows;if(o!==r.rows)throw new Error("Invalid matrix dimensions");if(this.isSingular())throw new Error("LU matrix is singular");var n,i,a,s=r.columns,f=r.subMatrixRow(this.pivotVector,0,s-1),u=t.columns;for(a=0;u>a;a++)for(n=a+1;u>n;n++)for(i=0;s>i;i++)f[n][i]-=f[a][i]*t[n][a];for(a=u-1;a>=0;a--){for(i=0;s>i;i++)f[a][i]/=t[a][a];for(n=0;a>n;n++)for(i=0;s>i;i++)f[n][i]-=f[a][i]*t[n][a]}return f}},r.exports=n},function(r,t,o){"use strict";function n(r){if(!(this instanceof n))return new n(r);r=e.checkMatrix(r);var t,o,a,s,f=r.clone(),u=r.rows,h=r.columns,c=new Array(h);for(a=0;h>a;a++){var l=0;for(t=a;u>t;t++)l=i(l,f[t][a]);if(0!==l){for(f[a][a]<0&&(l=-l),t=a;u>t;t++)f[t][a]/=l;for(f[a][a]+=1,o=a+1;h>o;o++){for(s=0,t=a;u>t;t++)s+=f[t][a]*f[t][o];for(s=-s/f[a][a],t=a;u>t;t++)f[t][o]+=s*f[t][a]}}c[a]=-l}this.QR=f,this.Rdiag=c}var e=o(6),i=o(9).hypotenuse;n.prototype={solve:function(r){r=e.checkMatrix(r);var t=this.QR,o=t.rows;if(r.rows!==o)throw new Error("Matrix row dimensions must agree");if(!this.isFullRank())throw new Error("Matrix is rank deficient");var n,i,a,s,f=r.columns,u=r.clone(),h=t.columns;for(a=0;h>a;a++)for(i=0;f>i;i++){for(s=0,n=a;o>n;n++)s+=t[n][a]*u[n][i];for(s=-s/t[a][a],n=a;o>n;n++)u[n][i]+=s*t[n][a]}for(a=h-1;a>=0;a--){for(i=0;f>i;i++)u[a][i]/=this.Rdiag[a];for(n=0;a>n;n++)for(i=0;f>i;i++)u[n][i]-=u[a][i]*t[n][a]}return u.subMatrix(0,h-1,0,f-1)},isFullRank:function(){for(var r=this.QR.columns,t=0;r>t;t++)if(0===this.Rdiag[t])return!1;return!0},get upperTriangularFactor(){var r,t,o=this.QR,n=o.columns,i=new e(n,n);for(r=0;n>r;r++)for(t=0;n>t;t++)t>r?i[r][t]=o[r][t]:r===t?i[r][t]=this.Rdiag[r]:i[r][t]=0;return i},get orthogonalFactor(){var r,t,o,n,i=this.QR,a=i.rows,s=i.columns,f=new e(a,s);for(o=s-1;o>=0;o--){for(r=0;a>r;r++)f[r][o]=0;for(f[o][o]=1,t=o;s>t;t++)if(0!==i[o][o]){for(n=0,r=o;a>r;r++)n+=i[r][o]*f[r][t];for(n=-n/i[o][o],r=o;a>r;r++)f[r][t]+=n*i[r][o]}}return f}},r.exports=n},function(r,t,o){"use strict";function n(r){if(!(this instanceof n))return new n(r);if(r=e.checkMatrix(r),!r.isSymmetric())throw new Error("Matrix is not symmetric");var t,o,i,a=r,s=a.rows,f=new e(s,s),u=!0;for(o=0;s>o;o++){var h=f[o],c=0;for(i=0;o>i;i++){var l=f[i],m=0;for(t=0;i>t;t++)m+=l[t]*h[t];h[i]=m=(a[o][i]-m)/f[i][i],c+=m*m}for(c=a[o][o]-c,u&=c>0,f[o][o]=Math.sqrt(Math.max(c,0)),i=o+1;s>i;i++)f[o][i]=0}if(!u)throw new Error("Matrix is not positive definite");this.L=f}var e=o(6);n.prototype={get leftTriangularFactor(){return this.L},solve:function(r){r=e.checkMatrix(r);var t=this.L,o=t.rows;if(r.rows!==o)throw new Error("Matrix dimensions do not match");var n,i,a,s=r.columns,f=r.clone();for(a=0;o>a;a++)for(i=0;s>i;i++){for(n=0;a>n;n++)f[a][i]-=f[n][i]*t[a][n];f[a][i]/=t[a][a]}for(a=o-1;a>=0;a--)for(i=0;s>i;i++){for(n=a+1;o>n;n++)f[a][i]-=f[n][i]*t[n][a];f[a][i]/=t[a][a]}return f}},r.exports=n},function(r,t,o){"use strict";function n(r,t){return new A(r,t)}function e(r,t){return A.ones(r,t)}function i(r,t){return A.eye(r,t)}function a(r,t){return A.zeros(r,t)}function s(r,t){return A.rand(r,t)}function f(r){if("number"==typeof r)return r;var t=r.clone();return t.transpose()}function u(r,t){if("number"==typeof r&&"number"==typeof t)return r+t;if("number"==typeof r)return this.add(t,r);var o=r.clone();return o.add(t)}function h(r,t){if("number"==typeof r&&"number"==typeof t)return r-t;if("number"==typeof r)return this.subtract(t,r);var o=r.clone();return o.sub(t)}function c(r,t){if("number"==typeof r&&"number"==typeof t)return r*t;if("number"==typeof r)return this.multiply(t,r);var o=r.clone();return"number"==typeof t?o.mul(t):o=o.mmul(t),1==o.rows&&1==o.columns?o[0][0]:o}function l(r,t){var o=r.clone();return o.mul(t)}function m(r,t){var o=r.clone();return o.div(t)}function p(r){var t,o,n=null,e=r.rows,i=r.columns;if("undefined"==typeof i&&"object"==typeof r)if(r[0]&&r[0].length)for(e=r.length,i=r[0].length,o=Math.min(e,i),n=A.zeros(i,i),t=0;i>t;t++)n[t][t]=r[t][t];else for(i=r.length,n=A.zeros(i,i),t=0;i>t;t++)n[t][t]=r[t];if(1==e)for(n=A.zeros(i,i),t=0;i>t;t++)n[t][t]=r[0][t];else if(e>0&&i>0)for(o=Math.min(e,i),n=new Array(o),t=0;o>t;t++)n[t]=r[t][t];return n}function w(r,t){if("number"==typeof r&&"number"==typeof t)return Math.min(r,t);for(var o=r.rows,n=r.columns,e=new A(o,n),i=0;o>i;i++)for(var a=0;n>a;a++)r[i][a]<t[i][a]?e[i][a]=r[i][a]:e[i][a]=t[i][a];return e}function v(r,t){if("number"==typeof r&&"number"==typeof t)return Math.max(r,t);for(var o=r.rows,n=r.columns,e=new A(o,n),i=0;o>i;i++)for(var a=0;n>a;a++)r[i][a]>t[i][a]?e[i][a]=r[i][a]:e[i][a]=t[i][a];return e}function d(r){if("number"==typeof r)return Math.sqrt(r);for(var t=r.rows,o=r.columns,n=new A(t,o),e=0;t>e;e++)for(var i=0;o>i;i++)n[e][i]=Math.sqrt(r[e][i]);return n}function y(r){if("number"==typeof r)return Math.abs(r);for(var t=r.rows,o=r.columns,n=new A(t,o),e=0;t>e;e++)for(var i=0;o>i;i++)n[e][i]=Math.abs(r[e][i]);return n}function g(r){if("number"==typeof r)return Math.sqrt(r);for(var t=r.rows,o=r.columns,n=new A(t,o),e=0;t>e;e++)for(var i=0;o>i;i++)n[e][i]=Math.exp(r[e][i]);return n}function b(r,t){if("number"==typeof r)return Math.pow(r,t);for(var o=r.rows,n=r.columns,e=new A(o,n),i=0;o>i;i++)for(var a=0;n>a;a++)e[i][a]=Math.pow(r[i][a],t);return e}function M(r,t){return r.solve(t)}function x(r){return"number"==typeof r?1/r:r.inverse()}var A=o(5);r.exports={transpose:f,add:u,subtract:h,multiply:c,dotMultiply:l,dotDivide:m,diag:p,min:w,max:v,solve:M,inv:x,sqrt:d,exp:g,dotPow:b,abs:y,matrix:n,ones:e,zeros:a,random:s,eye:i}},function(r,t,o){function n(r,t,o){var o=Object.create(o||{});void 0===o.minMaxRatio&&(o.minMaxRatio=25e-5),void 0===o.broadRatio&&(o.broadRatio=0),void 0===o.noiseLevel&&(o.noiseLevel=0),void 0===o.maxCriteria&&(o.maxCriteria=!0),void 0===o.smoothY&&(o.smoothY=!0),void 0===o.realTopDetection&&(o.realTopDetection=!1);var n=a({},f,o.sgOptions),u={m:1,b:0};if(!o.maxCriteria||o.noiseLevel>0){if(t=[].concat(t),!o.maxCriteria){u={m:-1,b:i.array.max(t)};for(var h=0;h<t.length;h++)t[h]=-t[h]+u.b;o.noiseLevel=-o.noiseLevel+u.b}if(o.noiseLevel>0)for(var h=0;h<t.length;h++)Math.abs(t[h])<o.noiseLevel&&(t[h]=0)}for(var c,l=0,m=Number.MAX_VALUE,h=0;h<r.length-1;h++){var c=Math.abs(r[h+1]-r[h]);m>c&&(m=c),c>l&&(l=c)}if(.05>(l-m)/l)var p=s(t,r[1]-r[0],{windowSize:n.windowSize,polynomial:n.polynomial,derivative:0}),w=s(t,r[1]-r[0],{windowSize:n.windowSize,polynomial:n.polynomial,derivative:1}),v=s(t,r[1]-r[0],{windowSize:n.windowSize,polynomial:n.polynomial,derivative:2});else var p=s(t,r,{windowSize:n.windowSize,polynomial:n.polynomial,derivative:0}),w=s(t,r,{windowSize:n.windowSize,polynomial:n.polynomial,derivative:1}),v=s(t,r,{windowSize:n.windowSize,polynomial:n.polynomial,derivative:2});for(var d=r,y=r[1]-r[0],g=0,b=0,h=0;h<p.length;h++)Math.abs(v[h])>g&&(g=Math.abs(v[h])),Math.abs(p[h])>b&&(b=Math.abs(p[h]));for(var M=[],x=[],A=[],R=null,z=null,k=new Array,h=1;h<p.length-1;h++)(w[h]<w[h-1]&&w[h]<=w[h+1]||w[h]<=w[h-1]&&w[h]<w[h+1])&&(z=d[h],y>0&&null!=R&&(x.push(R),A.push(z))),(w[h]>=w[h-1]&&w[h]>w[h+1]||w[h]>w[h-1]&&w[h]>=w[h+1])&&(R=d[h],0>y&&null!=z&&(x.push(R),A.push(z))),v[h]<v[h-1]&&v[h]<v[h+1]&&(M.push(h),Math.abs(v[h])>o.broadRatio*g?k.push(!1):k.push(!0));o.realTopDetection&&e(M,d,p);for(var S,j,E,V,C,q,D=[],I=0,O=0;O<M.length;O++){for(E=d[M[O]],S=-1,j=I+1,C=Number.MAX_VALUE,V=0,q=!0;-1==S&&j<x.length&&q;)V=Math.abs(E-(x[j]+A[j])/2),C>V?C=V:q=!1,V<Math.abs(x[j]-A[j])/2&&(S=j,I=j),j++;-1!=S&&Math.abs(p[M[O]])>o.minMaxRatio*b&&D.push({x:E,y:(p[M[O]]-u.b)/u.m,width:Math.abs(A[S]-x[S]),soft:k[O]})}return D.sort(function(r,t){return r.x-t.x}),D}function e(r,t,o){for(var n,e,i,a,s,f=0;f<r.length;f++)s=r[f],o[s-1]>=o[s-2]&&o[s-1]>=o[s]?s--:o[s+1]>=o[s]&&o[s+1]>=o[s+2]?s++:o[s-2]>=o[s-3]&&o[s-2]>=o[s-1]?s-=2:o[s+2]>=o[s+1]&&o[s+2]>=o[s+3]&&(s+=2),o[s-1]>0&&o[s+1]>0&&o[s]>=o[s-1]&&o[s]>=o[s+1]&&(n=20*Math.log10(o[s-1]),e=20*Math.log10(o[s]),i=20*Math.log10(o[s+1]),a=.5*(n-i)/(n-2*e+i),t[r[f]]=t[s]+(t[s]-t[s-1])*a,o[r[f]]=o[s]-.25*(o[s-1]-[s+1])*a)}var i=(o(2),o(16)),a=o(19),s=o(20),f={windowSize:5,polynomial:3};r.exports=n},function(r,t,o){"use strict";t.array=o(17),t.matrix=o(18)},function(r,t){"use strict";function o(r,t){return r-t}t.sum=function n(r){for(var n=0,t=0;t<r.length;t++)n+=r[t];return n},t.max=function e(r){for(var e=-(1/0),t=r.length,o=0;t>o;o++)r[o]>e&&(e=r[o]);return e},t.min=function i(r){for(var i=1/0,t=r.length,o=0;t>o;o++)r[o]<i&&(i=r[o]);return i},t.minMax=function(r){for(var t=1/0,o=-(1/0),n=r.length,e=0;n>e;e++)r[e]<t&&(t=r[e]),r[e]>o&&(o=r[e]);return{min:t,max:o}},t.arithmeticMean=function(r){for(var t=0,o=r.length,n=0;o>n;n++)t+=r[n];return t/o},t.mean=t.arithmeticMean,t.geometricMean=function(r){for(var t=1,o=r.length,n=0;o>n;n++)t*=r[n];return Math.pow(t,1/o)},t.logMean=function(r){for(var t=0,o=r.length,n=0;o>n;n++)t+=Math.log(r[n]);return t/o},t.grandMean=function(r,t){for(var o=0,n=0,e=r.length,i=0;e>i;i++)o+=t[i]*r[i],n+=t[i];return o/n},t.truncatedMean=function(r,t,n){void 0===n&&(n=!1),n||(r=r.slice().sort(o));for(var e=r.length,i=Math.floor(e*t),a=0,s=i;e-i>s;s++)a+=r[s];return a/(e-2*i)},t.harmonicMean=function(r){for(var t=0,o=r.length,n=0;o>n;n++){if(0===r[n])throw new RangeError("value at index "+n+"is zero");t+=1/r[n]}return o/t},t.contraHarmonicMean=function(r){for(var t=0,o=0,n=r.length,e=0;n>e;e++)t+=r[e]*r[e],o+=r[e];if(0>o)throw new RangeError("sum of values is negative");return t/o},t.median=function(r,t){void 0===t&&(t=!1),t||(r=r.slice().sort(o));var n=r.length,e=Math.floor(n/2);return n%2===0?.5*(r[e-1]+r[e]):r[e]},t.variance=function(r,o){void 0===o&&(o=!0);for(var n=t.mean(r),e=0,i=r.length,a=0;i>a;a++){var s=r[a]-n;e+=s*s}return o?e/(i-1):e/i},t.standardDeviation=function(r,o){return Math.sqrt(t.variance(r,o))},t.standardError=function(r){return t.standardDeviation(r)/Math.sqrt(r.length)},t.quartiles=function(r,n){"undefined"==typeof n&&(n=!1),n||(r=r.slice(),r.sort(o));var e=r.length/4,i=r[Math.ceil(e)-1],a=t.median(r,!0),s=r[Math.ceil(3*e)-1];return{q1:i,q2:a,q3:s}},t.pooledStandardDeviation=function(r,o){return Math.sqrt(t.pooledVariance(r,o))},t.pooledVariance=function(r,o){"undefined"==typeof o&&(o=!0);for(var n=0,e=0,i=r.length,a=0;i>a;a++){var s=r[a],f=t.variance(s);n+=(s.length-1)*f,e+=o?s.length-1:s.length}return n/e},t.mode=function(r){var t,o=r.length,n=new Array(o);for(t=0;o>t;t++)n[t]=0;var e=new Array(o),i=0;for(t=0;o>t;t++){var a=e.indexOf(r[t]);a>=0?n[a]++:(e[i]=r[t],n[i]=1,i++)}var s=0,f=0;for(t=0;i>t;t++)n[t]>s&&(s=n[t],f=t);return e[f]},t.covariance=function(r,o,n){"undefined"==typeof n&&(n=!0);var e=t.mean(r),i=t.mean(o);if(r.length!==o.length)throw"Vectors do not have the same dimensions";for(var a=0,s=r.length,f=0;s>f;f++){var u=r[f]-e,h=o[f]-i;a+=u*h}return n?a/(s-1):a/s},t.skewness=function(r,o){"undefined"==typeof o&&(o=!0);for(var n=t.mean(r),e=0,i=0,a=r.length,s=0;a>s;s++){var f=r[s]-n;e+=f*f,i+=f*f*f}var u=e/a,h=i/a,c=h/Math.pow(u,1.5);if(o){var l=Math.sqrt(a*(a-1)),m=a-2;return l/m*c}return c},t.kurtosis=function(r,o){"undefined"==typeof o&&(o=!0);for(var n=t.mean(r),e=r.length,i=0,a=0,s=0;e>s;s++){var f=r[s]-n;i+=f*f,a+=f*f*f*f}var u=i/e,h=a/e;if(o){var c=i/(e-1),l=e*(e+1)/((e-1)*(e-2)*(e-3)),m=a/(c*c),p=(e-1)*(e-1)/((e-2)*(e-3));return l*m-3*p}return h/(u*u)-3},t.entropy=function(r,t){"undefined"==typeof t&&(t=0);for(var o=0,n=r.length,e=0;n>e;e++)o+=r[e]*Math.log(r[e]+t);return-o},t.weightedMean=function(r,t){for(var o=0,n=r.length,e=0;n>e;e++)o+=r[e]*t[e];return o},t.weightedStandardDeviation=function(r,o){return Math.sqrt(t.weightedVariance(r,o))},t.weightedVariance=function(r,o){for(var n=t.weightedMean(r,o),e=0,i=r.length,a=0,s=0,f=0;i>f;f++){var u=r[f]-n,h=o[f];e+=h*(u*u),s+=h,a+=h*h}return e*(s/(s*s-a))},t.center=function(r,o){"undefined"==typeof o&&(o=!1);var n=r;o||(n=r.slice());for(var e=t.mean(n),i=n.length,a=0;i>a;a++)n[a]-=e},t.standardize=function(r,o,n){"undefined"==typeof o&&(o=t.standardDeviation(r)),"undefined"==typeof n&&(n=!1);for(var e=r.length,i=n?r:new Array(e),a=0;e>a;a++)i[a]=r[a]/o;return i},t.cumulativeSum=function(r){var t=r.length,o=new Array(t);o[0]=r[0];for(var n=1;t>n;n++)o[n]=o[n-1]+r[n];return o}},function(r,t,o){"use strict";function n(r,t){"undefined"==typeof t&&(t=0);for(var o=0,n=r.length,e=r[0].length,i=0;n>i;i++)for(var a=0;e>a;a++)o+=r[i][a]*Math.log(r[i][a]+t);return-o}function e(r,t){"undefined"==typeof t&&(t=0);var o,n,e,i,a=r.length,s=r[0].length;if(-1===t){for(o=[0],n=a*s,e=0;a>e;e++)for(i=0;s>i;i++)o[0]+=r[e][i];o[0]/=n}else if(0===t)for(o=new Array(s),n=a,i=0;s>i;i++){for(o[i]=0,e=0;a>e;e++)o[i]+=r[e][i];o[i]/=n}else{if(1!==t)throw new Error("Invalid dimension");for(o=new Array(a),n=s,i=0;a>i;i++){for(o[i]=0,e=0;s>e;e++)o[i]+=r[i][e];o[i]/=n}}return o}function i(r,t,o){for(var n=a(r,t,o),e=n.length,i=0;e>i;i++)n[i]=Math.sqrt(n[i]);return n}function a(r,t,o){"undefined"==typeof o&&(o=!0),t=t||e(r);var n=r.length;if(0===n)return[];for(var i=r[0].length,a=new Array(i),s=0;i>s;s++){for(var f=0,u=0,h=0,c=0;n>c;c++)h=r[c][s]-t[s],f+=h,u+=h*h;o?a[s]=(u-f*f/n)/(n-1):a[s]=(u-f*f/n)/n}return a}function s(r){for(var t=r.length,o=r[0].length,n=new Array(o),e=0;o>e;e++){for(var i=new Array(t),a=0;t>a;a++)i[a]=r[a][e];i.sort();var s=i.length;s%2===0?n[e]=.5*(i[s/2]+i[s/2-1]):n[e]=i[Math.floor(s/2)]}return n}function f(r){var t,o,n=r.length,e=r[0].length,i=new Array(e);for(t=0;e>t;t++){for(var a=new Array(n),s=0;n>s;s++)a[s]=0;var f=new Array(n),u=0;for(o=0;n>o;o++){var h=f.indexOf(r[o][t]);h>=0?a[h]++:(f[u]=r[o][t],a[u]=1,u++)}var c=0,l=0;for(o=0;u>o;o++)a[o]>c&&(c=a[o],l=o);i[t]=f[l]}return i}function u(r,t){"undefined"==typeof t&&(t=!0);for(var o=e(r),n=r.length,i=o.length,a=new Array(i),s=0;i>s;s++){for(var f=0,u=0,h=0;n>h;h++){var c=r[h][s]-o[s];f+=c*c,u+=c*c*c}var l=f/n,m=u/n,p=m/Math.pow(l,1.5);if(t){var w=Math.sqrt(n*(n-1)),v=n-2;a[s]=w/v*p}else a[s]=p}return a}function h(r,t){"undefined"==typeof t&&(t=!0);for(var o=e(r),n=r.length,i=r[0].length,a=new Array(i),s=0;i>s;s++){for(var f=0,u=0,h=0;n>h;h++){var c=r[h][s]-o[s];f+=c*c,u+=c*c*c*c}var l=f/n,m=u/n;if(t){var p=f/(n-1),w=n*(n+1)/((n-1)*(n-2)*(n-3)),v=u/(p*p),d=(n-1)*(n-1)/((n-2)*(n-3));a[s]=w*v-3*d}else a[s]=m/(l*l)-3}return a}function c(r){for(var t=r.length,o=i(r),n=o.length,e=new Array(n),a=Math.sqrt(t),s=0;n>s;s++)e[s]=o[s]/a;return e}function l(r,t){return m(r,void 0,t)}function m(r,t,o){"undefined"==typeof o&&(o=0),"undefined"==typeof t&&(0===o?t=r.length-1:1===o&&(t=r[0].length-1));var n=e(r,o),i=r.length;if(0===i)return[[]];var a,s,f,u,h,c=r[0].length;if(0===o){for(a=new Array(c),s=0;c>s;s++)a[s]=new Array(c);for(s=0;c>s;s++)for(f=s;c>f;f++){for(u=0,h=0;i>h;h++)u+=(r[h][f]-n[f])*(r[h][s]-n[s]);u/=t,a[s][f]=u,a[f][s]=u}}else{if(1!==o)throw new Error("Invalid dimension");for(a=new Array(i),s=0;i>s;s++)a[s]=new Array(i);for(s=0;i>s;s++)for(f=s;i>f;f++){for(u=0,h=0;c>h;h++)u+=(r[f][h]-n[f])*(r[s][h]-n[s]);u/=t,a[s][f]=u,a[f][s]=u}}return a}function p(r){var t,o,n=e(r),a=i(r,!0,n),s=w(r,n,a),f=r.length,u=r[0].length,h=new Array(u);for(t=0;u>t;t++)h[t]=new Array(u);for(t=0;u>t;t++)for(o=t;u>o;o++){for(var c=0,l=0,m=s.length;m>l;l++)c+=s[l][o]*s[l][t];c/=f-1,h[t][o]=c,h[o][t]=c}return h}function w(r,t,o){return t=t||e(r),"undefined"==typeof o&&(o=i(r,!0,t)),d(v(r,t,!1),o,!0)}function v(r,t,o){t=t||e(r);var n,i,a,s=r,f=r.length;if(!o)for(s=new Array(f),n=0;f>n;n++)s[n]=new Array(r[n].length);for(n=0;f>n;n++){var u=s[n];for(i=0,a=u.length;a>i;i++)u[i]=r[n][i]-t[i]}return s}function d(r,t,o){"undefined"==typeof t&&(t=i(r));var n,e,a,s=r,f=r.length;if(!o)for(s=new Array(f),n=0;f>n;n++)s[n]=new Array(r[n].length);for(n=0;f>n;n++){var u=s[n],h=r[n];for(e=0,a=u.length;a>e;e++)0===t[e]||isNaN(t[e])||(u[e]=h[e]/t[e])}return s}function y(r,t){var o=e(r),n=r.length;if(0===n)return[];for(var i=r[0].length,a=new Array(i),s=0;i>s;s++){for(var f=0,u=0,h=0,c=0;n>c;c++){var l=r[c][s]-o[s],m=t[c];f+=m*(l*l),h+=m,u+=m*m}a[s]=f*(h/(h*h-u))}return a}function g(r,t,o){"undefined"==typeof o&&(o=0);var n=r.length;if(0===n)return[];var e,i,a,s,f,u,h=r[0].length;if(0===o){for(e=new Array(h),i=0;h>i;i++)e[i]=0;for(i=0;n>i;i++)for(u=r[i],f=t[i],s=0;h>s;s++)e[s]+=u[s]*f}else{if(1!==o)throw new Error("Invalid dimension");for(e=new Array(n),i=0;n>i;i++)e[i]=0;for(s=0;n>s;s++)for(u=r[s],f=t[s],i=0;h>i;i++)e[s]+=u[i]*f}var c=x.sum(t);if(0!==c)for(i=0,a=e.length;a>i;i++)e[i]/=c;return e}function b(r,t,o,n){n=n||0,o=o||g(r,t,n);for(var e=0,i=0,a=0,s=t.length;s>a;a++)e+=t[a],i+=t[a]*t[a];var f=e/(e*e-i);return M(r,t,o,f,n)}function M(r,t,o,n,e){e=e||0,o=o||g(r,t,e),"undefined"==typeof n&&(n=1);var i=r.length;if(0===i)return[[]];var a,s,f,u,h,c=r[0].length;if(0===e){for(a=new Array(c),s=0;c>s;s++)a[s]=new Array(c);for(s=0;c>s;s++)for(f=s;c>f;f++){for(h=0,u=0;i>u;u++)h+=t[u]*(r[u][f]-o[f])*(r[u][s]-o[s]);a[s][f]=h*n,a[f][s]=h*n}}else{if(1!==e)throw new Error("Invalid dimension");for(a=new Array(i),s=0;i>s;s++)a[s]=new Array(i);for(s=0;i>s;s++)for(f=s;i>f;f++){for(h=0,u=0;c>u;u++)h+=t[u]*(r[f][u]-o[f])*(r[s][u]-o[s]);a[s][f]=h*n,a[f][s]=h*n}}return a}var x=o(17);r.exports={entropy:n,mean:e,standardDeviation:i,variance:a,median:s,mode:f,skewness:u,kurtosis:h,standardError:c,covariance:l,scatter:m,correlation:p,zScores:w,center:v,standardize:d,weightedVariance:y,weightedMean:g,weightedCovariance:b,weightedScatter:M}},function(r,t){"use strict";var o=Object.prototype.hasOwnProperty,n=Object.prototype.toString,e=function(r){return"function"==typeof Array.isArray?Array.isArray(r):"[object Array]"===n.call(r)},i=function(r){if(!r||"[object Object]"!==n.call(r))return!1;var t=o.call(r,"constructor"),e=r.constructor&&r.constructor.prototype&&o.call(r.constructor.prototype,"isPrototypeOf");if(r.constructor&&!t&&!e)return!1;var i;for(i in r);return"undefined"==typeof i||o.call(r,i)};r.exports=function a(){var r,t,o,n,s,f,u=arguments[0],h=1,c=arguments.length,l=!1;for("boolean"==typeof u?(l=u,u=arguments[1]||{},h=2):("object"!=typeof u&&"function"!=typeof u||null==u)&&(u={});c>h;++h)if(r=arguments[h],null!=r)for(t in r)o=u[t],n=r[t],u!==n&&(l&&n&&(i(n)||(s=e(n)))?(s?(s=!1,f=o&&e(o)?o:[]):f=o&&i(o)?o:{},u[t]=a(l,f,n)):"undefined"!=typeof n&&(u[t]=n));return u}},function(r,t,o){function n(r,t,o){if(o=u({},h,o),o.windowSize%2===0||o.windowSize<5||!Number.isInteger(o.windowSize))throw new RangeError("Invalid window size (should be odd and at least 5 integer number)");if(o.windowSize>r.length)throw new RangeError("Window size is higher than the data length "+o.windowSize+">"+r.length);if(o.derivative<0||!Number.isInteger(o.derivative))throw new RangeError("Derivative should be a positive integer");if(o.polynomial<1||!Number.isInteger(o.polynomial))throw new RangeError("Polynomial should be a positive integer");o.polynomial>=6&&console.warn("You should not use polynomial grade higher than 5 if you are not sure that your data arises from such a model. Possible polynomial oscillation problems");var n=o.windowSize,i=Math.floor(n/2),a=r.length,s=new Array(a),c=f(n,o.polynomial,o.derivative),l=0,m=!0;"[object Array]"===Object.prototype.toString.call(t)?m=!1:l=Math.pow(t,o.derivative);for(var p=0;i>p;p++){for(var w=c[i-p-1],v=c[i+p+1],d=0,y=0,g=0;n>g;g++)d+=w[g]*r[g],y+=v[g]*r[a-n+g-1];m?(s[i-p-1]=d/l,s[a-i+p]=y/l):(l=e(t,i-p-1,i,o.derivative),s[i-p-1]=d/l,l=e(t,a-i+p,i,o.derivative),s[a-i+p]=y/l)}for(var b=c[i],p=n;a+1>p;p++){for(var M=0,g=0;n>g;g++)M+=b[g]*r[g+p-n];m||(l=e(t,p-i-1,i,o.derivative)),s[p-i-1]=M/l}return s}function e(r,t,o,n){for(var e=0,i=0,a=t-o;t+o>a;a++)a>=0&&a<r.length-1&&(e+=r[a+1]-r[a],i++);return Math.pow(e/i,n)}function i(r,t,o,n){var e=0;return e=o>0?(4*o-2)/(o*(2*t-o+1))*(r*i(r,t,o-1,n)+n*i(r,t,o-1,n-1))-(o-1)*(2*t+o)/(o*(2*t-o+1))*i(r,t,o-2,n):0==o&&0==n?1:0}function a(r,t){var o=1;if(r>=t)for(var n=r-t+1;r>=n;n++)o*=n;return o}function s(r,t,o,n,e){for(var s=0,f=0;n>=f;f++)s+=(2*f+1)*(a(2*o,f)/a(2*o+f+1,f+1))*i(r,o,f,0)*i(t,o,f,e);return s}function f(r,t,o){for(var n=new Array(r),e=Math.floor(r/2),i=-e;e>=i;i++){n[i+e]=new Array(r);for(var a=-e;e>=a;a++)n[i+e][a+e]=s(a,i,e,t,o)}return n}var u=o(19),h=(o(16),{windowSize:11,derivative:0,polynomial:2});r.exports=n}])}); | ||
!function(r,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.GSD=t():r.GSD=t()}(this,function(){return function(r){function t(n){if(o[n])return o[n].exports;var e=o[n]={exports:{},id:n,loaded:!1};return r[n].call(e.exports,e,e.exports,t),e.loaded=!0,e.exports}var o={};return t.m=r,t.c=o,t.p="",t(0)}([function(r,t,o){r.exports.post=o(1),r.exports.gsd=o(15)},function(r,t,o){function n(r,t,o,n,e){var i=o.length,a=[],s=[],f=Math.sign(o[1]-o[0]);-1==f&&(e[0]=o.length-1);for(var u=Math.abs(t-r)/2,h=(r+t)/2,c=!1,l=e[0];!c&&i>l&&l>=0;)Math.abs(o[l]-h)<=u?(a.push(o[l]),s.push(n[l]),l+=f):1==Math.sign(h-o[l])?l+=f:c=!0;return e[0]=l,[a,s]}function e(r,t,o,e,a){var f,u,h=[0],c=i(r,e),l=[],m=1;for("gaussian"==a&&(m=1.17741),f=0;f<c.length;f++){var p=c[f].group;if(p.length>1){var w=n(c[f].limits[0]-c[f].limits[1],c[f].limits[0]+c[f].limits[1],t,o,h);if(w[0].length>5){var v=p[0].width/1e3,d=[3,100,v,v,v,10*v,10*v,11,9,1],y=[];for("gaussian"==a?y=s.optimizeGaussianSum(w,p,d):"lorentzian"==a&&(y=s.optimizeLorentzianSum(w,p,d)),u=0;u<y.length;u++)l.push({x:y[u][0][0],y:y[u][1][0],width:y[u][2][0]*m})}}else{p=p[0];var w=n(p.x-e*p.width,p.x+e*p.width,t,o,h);if(w[0].length>5){var v=p.width/1e3,d=[3,100,v,v,v,10*v,10*v,11,9,1],g=[];if("gaussian"==a)var g=s.optimizeSingleGaussian([w[0],w[1]],p,d);else if("lorentzian"==a)var g=s.optimizeSingleLorentzian([w[0],w[1]],p,d);l.push({x:g[0][0],y:g[1][0],width:g[2][0]*m})}}}return l}function i(r,t){var o,n,e,i,a=[],s=[],f=[r[0].x,t*r[0].width];for(o=0;o<r.length;o++)Math.abs(r[o].x-f[0])<t*r[o].width+f[1]?(a.push(r[o]),e=f[0]+f[1],r[o].x+t*r[o].width>e&&(e=r[o].x+t*r[o].width),i=f[0]-f[1],r[o].x-t*r[o].width<i&&(i=r[o].x-t*r[o].width),f=[(e+i)/2,Math.abs(e-i)/2]):(s.push({limits:f,group:a}),a=[r[o]],f=[r[o].x,t*r[o].width]);for(s.push({limits:f,group:a}),o=s.length-2;o>=0;o--)if(Math.abs(s[o].limits[0]-s[o+1].limits[0])<(s[o].limits[1]+s[o+1].limits[1])/2){for(n=0;n<s[o+1].group.length;n++)s[o].group.push(s[o+1].group[n]);e=s[o].limits[0]+s[o].limits[1],s[o+1].limits[0]+s[o+1].limits[1]>e&&(e=s[o+1].limits[0]+s[o+1].limits[1]),i=s[o].limits[0]-s[o].limits[1],s[o+1].limits[0]-s[o+1].limits[1]<i&&(i=s[o+1].limits[0]-s[o+1].limits[1]),s[o].limits=[(e+i)/2,Math.abs(e-i)/2],s.splice(o+1,1)}return s}function a(r,t){for(var o=t.width,n=[],e=0,i=0,a=1,f=r.length-1;f>=0;f--)r[f].soft&&n.push(r.splice(f,1)[0]);n.push({x:Number.MAX_VALUE});for(var u=[[n[0].x,n[0].y]],h=[0],f=1;f<n.length;f++)if(Math.abs(n[f-1].x-n[f].x)<o)u.push([n[f].x,n[f].y]),n[f].y>e&&(e=n[f].y,i=f),h.push(f),a++;else{if(a>2){var c=s.optimizeSingleLorentzian(u,{x:n[i].x,y:e,width:Math.abs(u[0][0]-u[u.length-1][0])});r.push({x:c[0][0],y:c[1][0],width:c[2][0],soft:!1})}else h.map(function(t){r.push(n[t])});u=[[n[f].x,n[f].y]],h=[f],e=n[f].y,i=f,a=1}return r.sort(function(r,t){return r.x-t.x}),r}var s=o(2);r.exports={optimizePeaks:e,joinBroadPeaks:a}},function(r,t,o){"use strict";function n(r,t,o){var n,e,i,a,s=t.length/3,f=r.rows,u=m.zeros(r.length,1);for(e=0;s>e;e++)for(a=Math.pow(t[e+2*s][0]/2,2),n=t[e+s][0]*a,i=0;f>i;i++)u[i][0]+=n/(Math.pow(r[i][0]-t[e][0],2)+a);return u}function e(r,t,o){for(var n=t[1][0]*Math.pow(t[2][0]/2,2),e=r.rows,i=new m(r.rows,r.columns),a=0;e>a;a++)i[a][0]=n/(Math.pow(r[a][0]-t[0][0],2)+Math.pow(t[2][0]/2,2));return i}function i(r,t,o){for(var n=t[2][0]*t[2][0]/2,e=r.rows,i=new m(r.rows,r.columns),a=0;e>a;a++)i[a][0]=t[1][0]*Math.exp(-(r[a][0]-t[0][0])*(r[a][0]-t[0][0])/n);return i}function a(r,t,o){var n=h(r),i=n[0],a=n[1],s=n[2],f=i.columns,u=[f/Math.sqrt(a.dot(a))],o=Object.create(o||[3,100,.001,.001,.001,.01,.01,11,9,1]),l=[],p=Math.abs(i[0][0]-i[1][0]),w=new m([[-p/1e4],[-.001],[-p/1e4]]),v=new m([[t.x],[1],[t.width]]),d=new m([[t.x-p],[.75],[t.width/4]]),y=new m([[t.x+p],[1.25],[4*t.width]]),g=c.optimize(e,v,i,a,u,w,d,y,l,o);return g=g.p,[g[0],[g[1][0]*s],g[2]]}function s(r,t,o){var n=h(r),e=n[0],a=n[1],s=n[2],f=e.columns,u=[f/Math.sqrt(a.dot(a))],o=Object.create(o||[3,100,.001,.001,.001,.01,.01,11,9,1]),l=[],p=Math.abs(e[0][0]-e[1][0]),w=new m([[-p/1e4],[-.001],[-p/1e4]]),w=new m([[-Math.abs(e[0][0]-e[1][0])/1e3],[-.001],[-t.width/1e3]]),v=new m([[t.x],[1],[t.width]]),d=new m([[t.x-p],[.75],[t.width/4]]),y=new m([[t.x+p],[1.25],[4*t.width]]),g=c.optimize(i,v,e,a,u,w,d,y,l,o);return g=g.p,[g[0],[g[1][0]*s],g[2]]}function f(r,t,o){var e,i=h(r),a=i[0],s=i[1],f=i[2],u=a.columns,p=[u/l.sqrt(s.dot(s))],o=Object.create(o||[3,100,.001,.001,.001,.01,.01,11,9,1]),w=[],v=t.length,d=new m(3*v,1),y=new m(3*v,1),g=new m(3*v,1),b=new m(3*v,1),M=Math.abs(a[0][0]-a[1][0]);for(e=0;v>e;e++)d[e][0]=t[e].x,d[e+v][0]=1,d[e+2*v][0]=t[e].width,y[e][0]=t[e].x-M,y[e+v][0]=0,y[e+2*v][0]=t[e].width/4,g[e][0]=t[e].x+M,g[e+v][0]=1.5,g[e+2*v][0]=4*t[e].width,b[e][0]=-M/1e3,b[e+v][0]=-.001,b[e+2*v][0]=-M/1e3;var b=-Math.abs(a[0][0]-a[1][0])/1e4,x=c.optimize(n,d,a,s,p,b,y,g,w,o);x=x.p;var A=new Array(v);for(e=0;v>e;e++)A[e]=[x[e],[x[e+v][0]*f],x[e+2*v]];return A}function u(r,t,o){var e,i=h(r),a=i[0],s=i[1],f=i[2],u=a.rows,p=new m(u,1),w=u/l.sqrt(s.dot(s));for(e=0;u>e;e++)p[e][0]=w;var o=Object.create(o||[3,100,.001,.001,.001,.01,.01,11,9,2]),v=[],d=t.length,y=new m(3*d,1),g=new m(3*d,1),b=new m(3*d,1),M=new m(3*d,1),x=Math.abs(a[0][0]-a[1][0]);for(e=0;d>e;e++)y[e][0]=t[e].x,y[e+d][0]=t[e].y/f,y[e+2*d][0]=t[e].width,g[e][0]=t[e].x-x,g[e+d][0]=.8*t[e].y/f,g[e+2*d][0]=t[e].width/2,b[e][0]=t[e].x+x,b[e+d][0]=1.2*t[e].y/f,b[e+2*d][0]=2*t[e].width,M[e][0]=-x/1e3,M[e+d][0]=-.001,M[e+2*d][0]=-x/1e3;var A=c.optimize(n,y,a,s,p,M,g,b,v,o);A=A.p;var R=new Array(d);for(e=0;d>e;e++)R[e]=[A[e],[A[e+d][0]*f],A[e+2*d]];return R}function h(r){var t,o,n,e=r.length,i=null,a=null,s=0;if(2==e){var f=r[0].length;if(3>f)throw new SizeException(f);if(i=new m(f,1),a=new m(f,1),t=r[0],o=r[1],"number"==typeof t[0])for(n=0;f>n;n++)i[n][0]=t[n],a[n][0]=o[n],o[n]>s&&(s=o[n]);else if("object"==typeof t[0])for(n=0;f>n;n++)i[n][0]=t[n][0],a[n][0]=o[n][0],o[n][0]>s&&(s=o[n][0])}else{var f=e;if(3>f)throw new SizeException(f);for(i=new m(f,1),a=new m(f,1),n=0;f>n;n++)i[n][0]=r[n][0],a[n][0]=r[n][1],a[n][0]>s&&(s=a[n][0])}for(n=0;f>n;n++)a[n][0]/=s;return[i,a,s]}var c=o(3),l=c.Matrix.algebra,m=o(5);r.exports.optimizeSingleLorentzian=a,r.exports.optimizeLorentzianSum=f,r.exports.optimizeSingleGaussian=s,r.exports.optimizeGaussianSum=u,r.exports.singleGaussian=i,r.exports.singleLorentzian=e},function(r,t,o){"use strict";r.exports=o(4),r.exports.Matrix=o(5),r.exports.Matrix.algebra=o(14)},function(r,t,o){var n=o(5),e=o(14),i={optimize:function(r,t,o,i,a,s,f,u,h,c){var l=0,m=0;if("object"!=typeof t[0])for(var p=0;p<t.length;p++)t[p]=[t[p]];var p,w,v=-50,d=t.length,y=i.length,g=n.zeros(d,1),b=n.zeros(y,1),M=.01/v,x=.01/v,A=n.zeros(y,d);if(o.length!=i.length){console.log("lm.m error: the length of t must equal the length of y_dat"),length_t=o.length,length_y_dat=i.length;var M=0;if(!l)return}a=a||Math.sqrt((y-d+1)/e.multiply(e.transpose(i),i)),s=s||.001,f=f||e.multiply(Math.abs(t),-100),u=u||e.multiply(Math.abs(t),100),h=h||1,c=c||[3,10*d,.001,.001,.001,.01,.01,11,9,1];var R=c[0],z=c[1],k=c[2],S=(c[3],c[4],c[5]),j=c[6],E=c[7],V=c[8],C=c[9];if(l&&3==R&&(R=2),!s.length||1==s.length){for(var q=new Array(d),p=0;d>p;p++)q[p]=[s];s=q}var D=[];for(p=0;p<s.length;p++)0!=s[p][0]&&D.push(p);var I=D.length,O=!1,_=null;if(!a.length||a.length<y){var L=e.multiply(n.ones(y,1),a[0]);_=e.dotMultiply(L,L)}else _=e.dotMultiply(a,a);var J=this.lm_matx(r,o,g,b,1,A,t,i,_,s,h),U=J.JtWJ,T=J.JtWdy,M=J.Chi_sq,P=J.y_hat,A=J.J;switch(Math.max(Math.abs(T))<k&&(console.log(" *** Your Initial Guess is Extremely Close to Optimal ***"),console.log(" *** epsilon_1 = ",k),O=!0),C){case 1:lambda=j;break;default:lambda=j*Math.max(e.diag(U)),nu=2}x=M;for(var W=null;!O&&z>=m;){switch(m+=1,C){case 1:W=e.solve(e.add(U,e.multiply(e.diag(e.diag(U)),lambda)),T);break;default:W=e.solve(e.add(U,e.multiply(n.eye(d),lambda)),T)}var N=new Array(D.length);for(w=0;w<D.length;w++)N[w]=W[D[w]];var G=e.add(t,N);for(w=0;w<G.length;w++)G[w][0]=Math.min(Math.max(f[w][0],G[w][0]),u[w][0]);var F=e.subtract(i,r(o,G,h)),Q=e.multiply(e.transpose(F),e.dotMultiply(F,_));if(2==C){var X=e.multiply(e.transpose(T),W),Y=e.multiply(X,e.inv(e.add(e.multiply(e.subtract(Q-M),.5)),e.multiply(X,2)));W=e.multiply(Y,W);for(var w=0;w<D.length;w++)N[w]=W[D[w]];G=e.add(t,N),G=e.min(e.max(f,G),u),F=e.subtract(i,r(o,G,h)),Q=e.multiply(e.transpose(F),mat.dotMultiply(F,_))}var B=(M-Q)/e.multiply(e.multiply(e.transpose(W),2),e.add(e.multiply(lambda,W),T));if(B>S)switch(dX2=M-x,x=M,g=t,b=P,t=G,J=this.lm_matx(r,o,g,b,dX2,A,t,i,_,s,h),U=J.JtWJ,T=J.JtWdy,M=J.Chi_sq,P=J.y_hat,A=J.J,C){case 1:lambda=Math.max(lambda/V,1e-7);break;case 2:lambda=Math.max(lambda/(1+Y),1e-7);break;case 3:lambda=e.multiply(Math.max(1/3,1-(2*B-1)^3),lambda),nu=2}else switch(M=x,m%(2*d)==0&&(J=this.lm_matx(r,o,g,b,-1,A,t,i,_,s,h),U=J.JtWJ,T=J.JtWdy,dX2=J.Chi_sq,P=J.y_hat,A=J.J),C){case 1:lambda=Math.min(lambda*E,1e7);break;case 2:lambda+=Math.abs((Q-M)/2/Y);break;case 3:lambda*=nu,nu=2*nu}}return _=e.multiply(e.multiply(e.transpose(F),F),n.ones(y,1)),_.apply(function(r,t){_[r][t]=(y-I+1)/_[r][t]}),J=this.lm_matx(r,o,g,b,-1,A,t,i,_,s,h),U=J.JtWJ,T=J.JtWdy,M=J.Chi_sq,P=J.y_hat,A=J.J,{p:t,X2:M}},lm_FD_J:function(r,t,o,i,a,s){var f=i.length,u=o.length;a=a||e.multiply(n.ones(u,1),.001);for(var h=o.clone(),c=new n(f,u),l=new Array(u),m=0;u>m;m++){if(l[m]=a[m]*(1+Math.abs(o[m][0])),o[m]=[h[m][0]+l[m]],0!=l[m])if(y1=r(t,o,s),a[m][0]<0)for(var p=e.dotDivide(e.subtract(y1,i),l[m]),w=0;f>w;w++)c[w][m]=p[w][0];else{o[m][0]=h[m][0]-l[m];for(var p=e.dotDivide(e.subtract(y1,r(t,o,s)),2*l[m]),w=0;f>w;w++)c[w][m]=p[w][0]}o[m]=h[m]}return c},lm_Broyden_J:function(r,t,o,n,i){var a=e.subtract(n,r),s=e.transpose(a);return s.div(e.multiply(s,a)),o=e.add(o,e.multiply(e.subtract(i,e.add(t,e.multiply(o,a))),s))},lm_matx:function(r,t,o,i,a,s,f,u,h,c,l,m){var p=(u.length,f.length);c=c||.001;var w=r(t,f,l);s=m%(2*p)==0||a>0?this.lm_FD_J(r,t,f,w,c,l):this.lm_Broyden_J(o,i,s,f,w);var v=e.subtract(u,w),d=e.multiply(e.transpose(v),e.dotMultiply(v,h)),y=e.transpose(s),g=e.multiply(y,e.dotMultiply(s,e.multiply(h,n.ones(1,p)))),b=e.multiply(y,e.dotMultiply(h,v));return{JtWJ:g,JtWdy:b,Chi_sq:d,y_hat:w,J:s}}};r.exports=i},function(r,t,o){"use strict";r.exports=o(6),r.exports.Decompositions=r.exports.DC=o(7)},function(r,t){"use strict";function o(r){for(var t=0,o=r.length,n=new Array(o);o>t;t++)n[t]=r[t];return n}function n(r,t){var e,i,a=0;if(Array.isArray(r)){if(i=t,e=i?o(r):r,r=e.length,t=e[0].length,"undefined"==typeof t)throw new TypeError("Data must be a 2D array");if(!(r>0&&t>0))throw new RangeError("Invalid dimensions: "+r+"x"+t);for(;r>a;a++){if(e[a].length!==t)throw new RangeError("Inconsistent array dimensions");i&&(e[a]=o(e[a]))}}else{if("number"!=typeof r)throw new TypeError("Invalid arguments");if(!(r>0&&t>0))throw new RangeError("Invalid dimensions: "+r+"x"+t);for(e=new Array(r);r>a;a++)e[a]=new Array(t)}return Object.defineProperty(e,"rows",{writable:!0,value:r}),Object.defineProperty(e,"columns",{writable:!0,value:t}),e.__proto__=n.prototype,e}var e=Array.prototype.splice,i=Array.prototype.concat;n.from1DArray=function(r,t,o){var e,i,a=0;if(e=r*t,e!==o.length)throw new RangeError("Data length does not match given dimensions");for(i=new Array(r);r>a;a++)i[a]=o.slice(a*t,(a+1)*t);return new n(i)},n.rowVector=function(r){return new n([r])},n.columnVector=function(r){for(var t=r.length,o=new Array(t),e=0;t>e;e++)o[e]=[r[e]];return new n(o)},n.empty=function(r,t){return new n(r,t)},n.zeros=function(r,t){return n.empty(r,t).fill(0)},n.ones=function(r,t){return n.empty(r,t).fill(1)},n.rand=function(r,t){for(var o=n.empty(r,t),e=0,i=o.rows;i>e;e++)for(var a=0,s=o.columns;s>a;a++)o[e][a]=Math.random();return o},n.eye=function(r){for(var t=n.zeros(r,r),o=t.rows,e=0;o>e;e++)t[e][e]=1;return t},n.diag=function(r){for(var t=r.length,o=n.zeros(t,t),e=0;t>e;e++)o[e][e]=r[e];return o},n.indices=function(r,t){for(var o=new Array(t-r),n=0;n<o.length;n++)o[n]=r++;return o},n.stack=function(r){var t,o,e;if(n.isMatrix(r)){var i=0,a=0;for(t=0;t<arguments.length;t++)i+=arguments[t].rows,arguments[t].columns>a&&(a=arguments[t].columns);var s=n.zeros(i,a),f=0;for(t=0;t<arguments.length;t++){var u=arguments[t];for(o=0;o<u.rows;o++){for(e=0;e<u.columns;e++)s[f][e]=u[o][e];f++}}return s}if(Array.isArray(r)){var h=n.empty(arguments.length,r.length);for(t=0;t<arguments.length;t++)h.setRow(t,arguments[t]);return h}},n.expand=function(r,t){for(var o=[],e=0;e<t.length;e++)for(var i=0;i<t[e];i++)o.push(r[e]);return new n(o)},n.checkMatrix=function(r){if(!r)throw new TypeError("Argument has to be a matrix");return"Matrix"!==r.klass&&(r=new n(r)),r},n.isMatrix=function(r){return r?"Matrix"===r.klass:!1},Object.defineProperty(n.prototype,"klass",{get:function(){return"Matrix"}}),Object.defineProperty(n.prototype,"size",{get:function(){return this.rows*this.columns}}),n.prototype.checkRowIndex=function(r){if(0>r||r>this.rows-1)throw new RangeError("Row index out of range.")},n.prototype.checkColumnIndex=function(r){if(0>r||r>this.columns-1)throw new RangeError("Column index out of range.")},n.prototype.checkDimensions=function(r){if(this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal.")},n.prototype.apply=function(r){for(var t=this.rows,o=this.columns,n=0;t>n;n++)for(var e=0;o>e;e++)r.call(this,n,e);return this},n.prototype.clone=function(){return new n(this.to2DArray())},n.prototype.to1DArray=function(){return i.apply([],this)},n.prototype.to2DArray=function(){for(var r=this.rows,t=new Array(r),n=0;r>n;n++)t[n]=o(this[n]);return t},n.prototype.isRowVector=function(){return 1===this.rows},n.prototype.isColumnVector=function(){return 1===this.columns},n.prototype.isVector=function(){return 1===this.rows||1===this.columns},n.prototype.isSquare=function(){return this.rows===this.columns},n.prototype.isSymmetric=function(){if(this.isSquare()){for(var r=this.rows,t=0;r>t;t++)for(var o=0;t>=o;o++)if(this[t][o]!==this[o][t])return!1;return!0}return!1},n.prototype.set=function(r,t,o){return this[r][t]=o,this},n.prototype.get=function(r,t){return this[r][t]},n.prototype.fill=function(r){for(var t=this.rows,o=this.columns,n=0;t>n;n++)for(var e=0;o>e;e++)this[n][e]=r;return this},n.prototype.neg=function(){return this.mulS(-1)},n.prototype.add=function(r){return"number"==typeof r?this.addS(r):(r=n.checkMatrix(r),this.addM(r))},n.prototype.addS=function(r){for(var t=this.rows,o=this.columns,n=0;t>n;n++)for(var e=0;o>e;e++)this[n][e]+=r;return this},n.prototype.addM=function(r){this.checkDimensions(r);for(var t=this.rows,o=this.columns,n=0;t>n;n++)for(var e=0;o>e;e++)this[n][e]+=r[n][e];return this},n.prototype.sub=function(r){return"number"==typeof r?this.subS(r):(r=n.checkMatrix(r),this.subM(r))},n.prototype.subS=function(r){for(var t=this.rows,o=this.columns,n=0;t>n;n++)for(var e=0;o>e;e++)this[n][e]-=r;return this},n.prototype.subM=function(r){this.checkDimensions(r);for(var t=this.rows,o=this.columns,n=0;t>n;n++)for(var e=0;o>e;e++)this[n][e]-=r[n][e];return this},n.prototype.mul=function(r){return"number"==typeof r?this.mulS(r):(r=n.checkMatrix(r),this.mulM(r))},n.prototype.mulS=function(r){for(var t=this.rows,o=this.columns,n=0;t>n;n++)for(var e=0;o>e;e++)this[n][e]*=r;return this},n.prototype.mulM=function(r){this.checkDimensions(r);for(var t=this.rows,o=this.columns,n=0;t>n;n++)for(var e=0;o>e;e++)this[n][e]*=r[n][e];return this},n.prototype.div=function(r){return"number"==typeof r?this.divS(r):(r=n.checkMatrix(r),this.divM(r))},n.prototype.divS=function(r){for(var t=this.rows,o=this.columns,n=0;t>n;n++)for(var e=0;o>e;e++)this[n][e]/=r;return this},n.prototype.divM=function(r){this.checkDimensions(r);for(var t=this.rows,o=this.columns,n=0;t>n;n++)for(var e=0;o>e;e++)this[n][e]/=r[n][e];return this},n.prototype.getRow=function(r){return this.checkRowIndex(r),o(this[r])},n.prototype.getRowVector=function(r){return n.rowVector(this.getRow(r))},n.prototype.setRow=function(r,t){if(this.checkRowIndex(r),n.isMatrix(t)&&(t=t.to1DArray()),t.length!==this.columns)throw new RangeError("Invalid row size");return this[r]=o(t),this},n.prototype.removeRow=function(r){if(this.checkRowIndex(r),1===this.rows)throw new RangeError("A matrix cannot have less than one row");return e.call(this,r,1),this.rows-=1,this},n.prototype.addRow=function(r,t){if("undefined"==typeof t&&(t=r,r=this.rows),0>r||r>this.rows)throw new RangeError("Row index out of range.");if(n.isMatrix(t)&&(t=t.to1DArray()),t.length!==this.columns)throw new RangeError("Invalid row size");return e.call(this,r,0,o(t)),this.rows+=1,this},n.prototype.swapRows=function(r,t){this.checkRowIndex(r),this.checkRowIndex(t);var o=this[r];return this[r]=this[t],this[t]=o,this},n.prototype.getColumn=function(r){this.checkColumnIndex(r);for(var t=this.rows,o=new Array(t),n=0;t>n;n++)o[n]=this[n][r];return o},n.prototype.getColumnVector=function(r){return n.columnVector(this.getColumn(r))},n.prototype.setColumn=function(r,t){this.checkColumnIndex(r),n.isMatrix(t)&&(t=t.to1DArray());var o=this.rows;if(t.length!==o)throw new RangeError("Invalid column size");for(var e=0;o>e;e++)this[e][r]=t[e];return this},n.prototype.removeColumn=function(r){if(this.checkColumnIndex(r),1===this.columns)throw new RangeError("A matrix cannot have less than one column");for(var t=0,o=this.rows;o>t;t++)this[t].splice(r,1);return this.columns-=1,this},n.prototype.addColumn=function(r,t){if("undefined"==typeof t&&(t=r,r=this.columns),0>r||r>this.columns)throw new RangeError("Column index out of range.");n.isMatrix(t)&&(t=t.to1DArray());var o=this.rows;if(t.length!==o)throw new RangeError("Invalid column size");for(var e=0;o>e;e++)this[e].splice(r,0,t[e]);return this.columns+=1,this},n.prototype.swapColumns=function(r,t){this.checkRowIndex(r),this.checkRowIndex(t);for(var o,n,e=this.rows,i=0;e>i;i++)n=this[i],o=n[r],n[r]=n[t],n[t]=o;return this},n.prototype.checkRowVector=function(r){if(n.isMatrix(r)&&(r=r.to1DArray()),r.length!==this.columns)throw new RangeError("vector size must be the same as the number of columns");return r},n.prototype.checkColumnVector=function(r){if(n.isMatrix(r)&&(r=r.to1DArray()),r.length!==this.rows)throw new RangeError("vector size must be the same as the number of rows");return r},n.prototype.addRowVector=function(r){r=this.checkRowVector(r);for(var t=this.rows,o=this.columns,n=0;t>n;n++)for(var e=0;o>e;e++)this[n][e]+=r[e];return this},n.prototype.subRowVector=function(r){r=this.checkRowVector(r);for(var t=this.rows,o=this.columns,n=0;t>n;n++)for(var e=0;o>e;e++)this[n][e]-=r[e];return this},n.prototype.mulRowVector=function(r){r=this.checkRowVector(r);for(var t=this.rows,o=this.columns,n=0;t>n;n++)for(var e=0;o>e;e++)this[n][e]*=r[e];return this},n.prototype.divRowVector=function(r){r=this.checkRowVector(r);for(var t=this.rows,o=this.columns,n=0;t>n;n++)for(var e=0;o>e;e++)this[n][e]/=r[e];return this},n.prototype.addColumnVector=function(r){r=this.checkColumnVector(r);for(var t=this.rows,o=this.columns,n=0;t>n;n++)for(var e=0;o>e;e++)this[n][e]+=r[n];return this},n.prototype.subColumnVector=function(r){r=this.checkColumnVector(r);for(var t=this.rows,o=this.columns,n=0;t>n;n++)for(var e=0;o>e;e++)this[n][e]-=r[n];return this},n.prototype.mulColumnVector=function(r){r=this.checkColumnVector(r);for(var t=this.rows,o=this.columns,n=0;t>n;n++)for(var e=0;o>e;e++)this[n][e]*=r[n];return this},n.prototype.divColumnVector=function(r){r=this.checkColumnVector(r);for(var t=this.rows,o=this.columns,n=0;t>n;n++)for(var e=0;o>e;e++)this[n][e]/=r[n];return this},n.prototype.mulRow=function(r,t){this.checkRowIndex(r);for(var o=0,n=this.columns;n>o;o++)this[r][o]*=t;return this},n.prototype.mulColumn=function(r,t){this.checkColumnIndex(r);for(var o=0,n=this.rows;n>o;o++)this[o][r]*=t},n.prototype.max=function(){for(var r=-(1/0),t=this.rows,o=this.columns,n=0;t>n;n++)for(var e=0;o>e;e++)this[n][e]>r&&(r=this[n][e]);return r},n.prototype.maxIndex=function(){for(var r=-(1/0),t={},o=this.rows,n=this.columns,e=0;o>e;e++)for(var i=0;n>i;i++)this[e][i]>r&&(r=this[e][i],t.row=e,t.column=i);return t},n.prototype.min=function(){for(var r=1/0,t=this.rows,o=this.columns,n=0;t>n;n++)for(var e=0;o>e;e++)this[n][e]<r&&(r=this[n][e]);return r},n.prototype.minIndex=function(){for(var r=1/0,t={},o=this.rows,n=this.columns,e=0;o>e;e++)for(var i=0;n>i;i++)this[e][i]<r&&(r=this[e][i],t.row=e,t.column=i);return t},n.prototype.maxRow=function(r){this.checkRowIndex(r);for(var t=-(1/0),o=0,n=this.columns;n>o;o++)this[r][o]>t&&(t=this[r][o]);return t},n.prototype.maxRowIndex=function(r){this.checkRowIndex(r);for(var t=-(1/0),o={row:r},n=0,e=this.columns;e>n;n++)this[r][n]>t&&(t=this[r][n],o.column=n);return o},n.prototype.minRow=function(r){this.checkRowIndex(r);for(var t=1/0,o=0,n=this.columns;n>o;o++)this[r][o]<t&&(t=this[r][o]);return t},n.prototype.minRowIndex=function(r){this.checkRowIndex(r);for(var t=1/0,o={row:r,column:0},n=0,e=this.columns;e>n;n++)this[r][n]<t&&(t=this[r][n],o.column=n);return o},n.prototype.maxColumn=function(r){this.checkColumnIndex(r);for(var t=-(1/0),o=0,n=this.rows;n>o;o++)this[o][r]>t&&(t=this[o][r]);return t},n.prototype.maxColumnIndex=function(r){this.checkColumnIndex(r);for(var t=-(1/0),o={row:0,column:r},n=0,e=this.rows;e>n;n++)this[n][r]>t&&(t=this[n][r],o.row=n);return o},n.prototype.minColumn=function(r){this.checkColumnIndex(r);for(var t=1/0,o=0,n=this.rows;n>o;o++)this[o][r]<t&&(t=this[o][r]);return t},n.prototype.minColumnIndex=function(r){this.checkColumnIndex(r);for(var t=1/0,o={row:0,column:r},n=0,e=this.rows;e>n;n++)this[n][r]<t&&(t=this[n][r],o.row=n);return o},n.prototype.diag=function a(){if(!this.isSquare())throw new TypeError("Only square matrices have a diagonal.");for(var a=new Array(this.rows),r=0,t=this.rows;t>r;r++)a[r]=this[r][r];return a},n.prototype.sum=function(){for(var r=0,t=this.rows,o=this.columns,n=0;t>n;n++)for(var e=0;o>e;e++)r+=this[n][e];return r},n.prototype.mean=function(){return this.sum()/this.size},n.prototype.prod=function s(){for(var s=1,r=this.rows,t=this.columns,o=0;r>o;o++)for(var n=0;t>n;n++)s*=this[o][n];return s},n.prototype.cumulativeSum=function(){for(var r=0,t=this.rows,o=this.columns,n=0;t>n;n++)for(var e=0;o>e;e++)r+=this[n][e],this[n][e]=r;return this},n.prototype.dot=function f(r){if(this.size!==r.size)throw new RangeError("vectors do not have the same size");for(var t=this.to1DArray(),o=r.to1DArray(),f=0,n=t.length,e=0;n>e;e++)f+=t[e]*o[e];return f},n.prototype.mmul=function(r){if(!n.isMatrix(r))throw new TypeError('parameter "other" must be a matrix');this.columns!==r.rows&&console.warn("Number of columns of left matrix are not equal to number of rows of right matrix.");var t,o,e,i=this.rows,a=this.columns,s=r.columns,f=new n(i,s),u=new Array(a);for(o=0;s>o;o++){for(e=0;a>e;e++)u[e]=r[e][o];for(t=0;i>t;t++){var h=this[t],c=0;for(e=0;a>e;e++)c+=h[e]*u[e];f[t][o]=c}}return f},n.prototype.sortRows=function(r){for(var t=0,o=this.rows;o>t;t++)this[t].sort(r);return this},n.prototype.sortColumns=function(r){for(var t=0,o=this.columns;o>t;t++)this.setColumn(t,this.getColumn(t).sort(r));return this},n.prototype.transpose=function(){for(var r=new n(this.columns,this.rows),t=this.rows,o=this.columns,e=0;t>e;e++)for(var i=0;o>i;i++)r[i][e]=this[e][i];return r},n.prototype.subMatrix=function(r,t,o,e){if(r>t||o>e||0>r||r>=this.rows||0>t||t>=this.rows||0>o||o>=this.columns||0>e||e>=this.columns)throw new RangeError("Argument out of range");for(var i=new n(t-r+1,e-o+1),a=r;t>=a;a++)for(var s=o;e>=s;s++)i[a-r][s-o]=this[a][s];return i},n.prototype.subMatrixRow=function(r,t,o){if("undefined"==typeof t?(t=0,o=this.columns-1):"undefined"==typeof o&&(o=this.columns-1),t>o||0>t||t>=this.columns||0>o||o>=this.columns)throw new RangeError("Argument out of range.");for(var e=r.length,i=this.rows,a=new n(e,o-t+1),s=0;e>s;s++)for(var f=t;o>=f;f++){if(r[s]<0||r[s]>=i)throw new RangeError("Argument out of range.");a[s][f-t]=this[r[s]][f]}return a},n.prototype.subMatrixColumn=function(r,t,o){if("undefined"==typeof t?(t=0,o=this.rows-1):"undefined"==typeof o&&(o=this.rows-1),t>o||0>t||t>=this.rows||0>o||o>=this.rows)throw new RangeError("Argument out of range.");for(var e=r.length,i=this.columns,a=new n(o-t+1,e),s=0;e>s;s++)for(var f=t;o>=f;f++){if(r[s]<0||r[s]>=i)throw new RangeError("Argument out of range.");a[f-t][s]=this[f][r[s]]}return a},n.prototype.trace=function u(){if(!this.isSquare())throw new TypeError("The matrix is not square");for(var u=0,r=0,t=this.rows;t>r;r++)u+=this[r][r];return u},n.prototype.abs=function(){for(var r=this.rows,t=this.columns,o=0;r>o;o++)for(var n=0;t>n;n++)this[o][n]=Math.abs(this[o][n])},r.exports=n},function(r,t,o){"use strict";function n(r){return e(r,i.eye(r.rows))}function e(r,t){return r.isSquare()?new f(r).solve(t):new u(r).solve(t)}var i=o(6),a=o(8),s=o(10),f=o(11),u=o(12),h=o(13);i.prototype.inverse=function(){return n(this)},i.prototype.solve=function(r){return e(this,r)},r.exports={SingularValueDecomposition:a,SVD:a,EigenvalueDecomposition:s,EVD:s,LuDecomposition:f,LU:f,QrDecomposition:u,QR:u,CholeskyDecomposition:h,CHO:h,inverse:n,solve:e}},function(r,t,o){"use strict";function n(r,t){if(!(this instanceof n))return new n(r,t);r=e.checkMatrix(r),t=t||{};var o=r.clone(),a=r.rows,s=r.columns,f=Math.min(a,s),u=!0,h=!0;t.computeLeftSingularVectors===!1&&(u=!1),t.computeRightSingularVectors===!1&&(h=!1);var c=t.autoTranspose===!0,l=!1;if(s>a)if(c){o=o.transpose(),a=o.rows,s=o.columns,l=!0;var m=u;u=h,h=m}else console.warn("Computing SVD on a matrix with more columns than rows. Consider enabling autoTranspose");var p,w,v,d,y,g,b,M,x,A,R,z,k,S,j,E,V,C,q,D,I,O=new Array(Math.min(a+1,s)),_=e.zeros(a,f),L=e.zeros(s,s),J=new Array(s),U=new Array(a),T=Math.min(a-1,s),P=Math.max(0,Math.min(s-2,a));for(v=0,A=Math.max(T,P);A>v;v++){if(T>v){for(O[v]=0,p=v;a>p;p++)O[v]=i(O[v],o[p][v]);if(0!==O[v]){for(o[v][v]<0&&(O[v]=-O[v]),p=v;a>p;p++)o[p][v]/=O[v];o[v][v]+=1}O[v]=-O[v]}for(w=v+1;s>w;w++){if(T>v&&0!==O[v]){for(y=0,p=v;a>p;p++)y+=o[p][v]*o[p][w];for(y=-y/o[v][v],p=v;a>p;p++)o[p][w]+=y*o[p][v]}J[w]=o[v][w]}if(u&&T>v)for(p=v;a>p;p++)_[p][v]=o[p][v];if(P>v){for(J[v]=0,p=v+1;s>p;p++)J[v]=i(J[v],J[p]);if(0!==J[v]){for(J[v+1]<0&&(J[v]=-J[v]),p=v+1;s>p;p++)J[p]/=J[v];J[v+1]+=1}if(J[v]=-J[v],a>v+1&&0!==J[v]){for(p=v+1;a>p;p++)U[p]=0;for(w=v+1;s>w;w++)for(p=v+1;a>p;p++)U[p]+=J[w]*o[p][w];for(w=v+1;s>w;w++)for(y=-J[w]/J[v+1],p=v+1;a>p;p++)o[p][w]+=y*U[p]}if(h)for(p=v+1;s>p;p++)L[p][v]=J[p]}}if(d=Math.min(s,a+1),s>T&&(O[T]=o[T][T]),d>a&&(O[d-1]=0),d>P+1&&(J[P]=o[P][d-1]),J[d-1]=0,u){for(w=T;f>w;w++){for(p=0;a>p;p++)_[p][w]=0;_[w][w]=1}for(v=T-1;v>=0;v--)if(0!==O[v]){for(w=v+1;f>w;w++){for(y=0,p=v;a>p;p++)y+=_[p][v]*_[p][w];for(y=-y/_[v][v],p=v;a>p;p++)_[p][w]+=y*_[p][v]}for(p=v;a>p;p++)_[p][v]=-_[p][v];for(_[v][v]=1+_[v][v],p=0;v-1>p;p++)_[p][v]=0}else{for(p=0;a>p;p++)_[p][v]=0;_[v][v]=1}}if(h)for(v=s-1;v>=0;v--){if(P>v&&0!==J[v])for(w=v+1;s>w;w++){for(y=0,p=v+1;s>p;p++)y+=L[p][v]*L[p][w];for(y=-y/L[v+1][v],p=v+1;s>p;p++)L[p][w]+=y*L[p][v]}for(p=0;s>p;p++)L[p][v]=0;L[v][v]=1}for(var W=d-1,N=0,G=Math.pow(2,-52);d>0;){for(v=d-2;v>=-1&&-1!==v;v--)if(Math.abs(J[v])<=G*(Math.abs(O[v])+Math.abs(O[v+1]))){J[v]=0;break}if(v===d-2)R=4;else{for(g=d-1;g>=v&&g!==v;g--)if(y=(g!==d?Math.abs(J[g]):0)+(g!==v+1?Math.abs(J[g-1]):0),Math.abs(O[g])<=G*y){O[g]=0;break}g===v?R=3:g===d-1?R=1:(R=2,v=g)}switch(v++,R){case 1:for(b=J[d-2],J[d-2]=0,w=d-2;w>=v;w--)if(y=i(O[w],b),M=O[w]/y,x=b/y,O[w]=y,w!==v&&(b=-x*J[w-1],J[w-1]=M*J[w-1]),h)for(p=0;s>p;p++)y=M*L[p][w]+x*L[p][d-1],L[p][d-1]=-x*L[p][w]+M*L[p][d-1],L[p][w]=y;break;case 2:for(b=J[v-1],J[v-1]=0,w=v;d>w;w++)if(y=i(O[w],b),M=O[w]/y,x=b/y,O[w]=y,b=-x*J[w],J[w]=M*J[w],u)for(p=0;a>p;p++)y=M*_[p][w]+x*_[p][v-1],_[p][v-1]=-x*_[p][w]+M*_[p][v-1],_[p][w]=y;break;case 3:for(z=Math.max(Math.max(Math.max(Math.max(Math.abs(O[d-1]),Math.abs(O[d-2])),Math.abs(J[d-2])),Math.abs(O[v])),Math.abs(J[v])),k=O[d-1]/z,S=O[d-2]/z,j=J[d-2]/z,E=O[v]/z,V=J[v]/z,C=((S+k)*(S-k)+j*j)/2,q=k*j*(k*j),D=0,(0!==C||0!==q)&&(D=Math.sqrt(C*C+q),0>C&&(D=-D),D=q/(C+D)),b=(E+k)*(E-k)+D,I=E*V,w=v;d-1>w;w++){if(y=i(b,I),M=b/y,x=I/y,w!==v&&(J[w-1]=y),b=M*O[w]+x*J[w],J[w]=M*J[w]-x*O[w],I=x*O[w+1],O[w+1]=M*O[w+1],h)for(p=0;s>p;p++)y=M*L[p][w]+x*L[p][w+1],L[p][w+1]=-x*L[p][w]+M*L[p][w+1],L[p][w]=y;if(y=i(b,I),M=b/y,x=I/y,O[w]=y,b=M*J[w]+x*O[w+1],O[w+1]=-x*J[w]+M*O[w+1],I=x*J[w+1],J[w+1]=M*J[w+1],u&&a-1>w)for(p=0;a>p;p++)y=M*_[p][w]+x*_[p][w+1],_[p][w+1]=-x*_[p][w]+M*_[p][w+1],_[p][w]=y}J[d-2]=b,N+=1;break;case 4:if(O[v]<=0&&(O[v]=O[v]<0?-O[v]:0,h))for(p=0;W>=p;p++)L[p][v]=-L[p][v];for(;W>v&&!(O[v]>=O[v+1]);){if(y=O[v],O[v]=O[v+1],O[v+1]=y,h&&s-1>v)for(p=0;s>p;p++)y=L[p][v+1],L[p][v+1]=L[p][v],L[p][v]=y;if(u&&a-1>v)for(p=0;a>p;p++)y=_[p][v+1],_[p][v+1]=_[p][v],_[p][v]=y;v++}N=0,d--}}if(l){var F=L;L=_,_=F}this.m=a,this.n=s,this.s=O,this.U=_,this.V=L}var e=o(6),i=o(9).hypotenuse;n.prototype={get condition(){return this.s[0]/this.s[Math.min(this.m,this.n)-1]},get norm2(){return this.s[0]},get rank(){for(var r=Math.pow(2,-52),t=Math.max(this.m,this.n)*this.s[0]*r,o=0,n=this.s,e=0,i=n.length;i>e;e++)n[e]>t&&o++;return o},get diagonal(){return this.s},get threshold(){return Math.pow(2,-52)/2*Math.max(this.m,this.n)*this.s[0]},get leftSingularVectors(){return this.U},get rightSingularVectors(){return this.V},get diagonalMatrix(){return e.diag(this.s)},solve:function(r){var t,o=r,n=this.threshold,i=this.s.length,a=e.zeros(i,i);for(t=0;i>t;t++)Math.abs(this.s[t])<=n?a[t][t]=0:a[t][t]=1/this.s[t];var s,f,u,h=this.V.mmul(a),c=this.V.rows,l=this.U.rows,m=e.zeros(c,l);for(t=0;c>t;t++)for(s=0;l>s;s++){for(u=0,f=0;i>f;f++)u+=h[t][f]*this.U[s][f];m[t][s]=u}return m.mmul(o)},solveForDiagonal:function(r){return this.solve(e.diag(r))},inverse:function(){var r,t,o=this.threshold,n=this.V.rows,i=this.V.columns,a=new e(n,this.s.length);for(r=0;n>r;r++)for(t=0;i>t;t++)Math.abs(this.s[t])>o?a[r][t]=this.V[r][t]/this.s[t]:a[r][t]=0;var s,f,u=this.U.rows,h=this.U.columns,c=new e(n,u);for(r=0;n>r;r++)for(t=0;u>t;t++){for(f=0,s=0;h>s;s++)f+=a[r][s]*this.U[t][s];c[r][t]=f}return c}},r.exports=n},function(r,t){"use strict";t.hypotenuse=function(r,t){var o;return Math.abs(r)>Math.abs(t)?(o=t/r,Math.abs(r)*Math.sqrt(1+o*o)):0!==t?(o=r/t,Math.abs(t)*Math.sqrt(1+o*o)):0}},function(r,t,o){"use strict";function n(r){if(!(this instanceof n))return new n(r);if(r=u.checkMatrix(r),!r.isSquare())throw new Error("Matrix is not a square matrix");var t,o,f=r.columns,h=u.zeros(f,f),c=new Array(f),l=new Array(f),m=r;if(r.isSymmetric()){for(t=0;f>t;t++)for(o=0;f>o;o++)h[t][o]=m[t][o];e(f,l,c,h),i(f,l,c,h)}else{var p=u.zeros(f,f),w=new Array(f);for(o=0;f>o;o++)for(t=0;f>t;t++)p[t][o]=m[t][o];a(f,p,w,h),s(f,l,c,h,p)}this.n=f,this.e=l,this.d=c,this.V=h}function e(r,t,o,n){var e,i,a,s,f,u,h,c;for(f=0;r>f;f++)o[f]=n[r-1][f];for(s=r-1;s>0;s--){for(c=0,a=0,u=0;s>u;u++)c+=Math.abs(o[u]);if(0===c)for(t[s]=o[s-1],f=0;s>f;f++)o[f]=n[s-1][f],n[s][f]=0,n[f][s]=0;else{for(u=0;s>u;u++)o[u]/=c,a+=o[u]*o[u];for(e=o[s-1],i=Math.sqrt(a),e>0&&(i=-i),t[s]=c*i,a-=e*i,o[s-1]=e-i,f=0;s>f;f++)t[f]=0;for(f=0;s>f;f++){for(e=o[f],n[f][s]=e,i=t[f]+n[f][f]*e,u=f+1;s-1>=u;u++)i+=n[u][f]*o[u],t[u]+=n[u][f]*e;t[f]=i}for(e=0,f=0;s>f;f++)t[f]/=a,e+=t[f]*o[f];for(h=e/(a+a),f=0;s>f;f++)t[f]-=h*o[f];for(f=0;s>f;f++){for(e=o[f],i=t[f],u=f;s-1>=u;u++)n[u][f]-=e*t[u]+i*o[u];o[f]=n[s-1][f],n[s][f]=0}}o[s]=a}for(s=0;r-1>s;s++){if(n[r-1][s]=n[s][s],n[s][s]=1,a=o[s+1],0!==a){for(u=0;s>=u;u++)o[u]=n[u][s+1]/a;for(f=0;s>=f;f++){for(i=0,u=0;s>=u;u++)i+=n[u][s+1]*n[u][f];for(u=0;s>=u;u++)n[u][f]-=i*o[u]}}for(u=0;s>=u;u++)n[u][s+1]=0}for(f=0;r>f;f++)o[f]=n[r-1][f],n[r-1][f]=0;n[r-1][r-1]=1,t[0]=0}function i(r,t,o,n){var e,i,a,s,f,u,c,l,m,p,w,v,d,y,g,b,M;for(a=1;r>a;a++)t[a-1]=t[a];t[r-1]=0;var x=0,A=0,R=Math.pow(2,-52);for(u=0;r>u;u++){for(A=Math.max(A,Math.abs(o[u])+Math.abs(t[u])),c=u;r>c&&!(Math.abs(t[c])<=R*A);)c++; | ||
if(c>u){M=0;do{for(M+=1,e=o[u],l=(o[u+1]-e)/(2*t[u]),m=h(l,1),0>l&&(m=-m),o[u]=t[u]/(l+m),o[u+1]=t[u]*(l+m),p=o[u+1],i=e-o[u],a=u+2;r>a;a++)o[a]-=i;for(x+=i,l=o[c],w=1,v=w,d=w,y=t[u+1],g=0,b=0,a=c-1;a>=u;a--)for(d=v,v=w,b=g,e=w*t[a],i=w*l,m=h(l,t[a]),t[a+1]=g*m,g=t[a]/m,w=l/m,l=w*o[a]-g*e,o[a+1]=i+g*(w*e+g*o[a]),f=0;r>f;f++)i=n[f][a+1],n[f][a+1]=g*n[f][a]+w*i,n[f][a]=w*n[f][a]-g*i;l=-g*b*d*y*t[u]/p,t[u]=g*l,o[u]=w*l}while(Math.abs(t[u])>R*A)}o[u]=o[u]+x,t[u]=0}for(a=0;r-1>a;a++){for(f=a,l=o[a],s=a+1;r>s;s++)o[s]<l&&(f=s,l=o[s]);if(f!==a)for(o[f]=o[a],o[a]=l,s=0;r>s;s++)l=n[s][a],n[s][a]=n[s][f],n[s][f]=l}}function a(r,t,o,n){var e,i,a,s,f,u,h,c=0,l=r-1;for(u=c+1;l-1>=u;u++){for(h=0,s=u;l>=s;s++)h+=Math.abs(t[s][u-1]);if(0!==h){for(a=0,s=l;s>=u;s--)o[s]=t[s][u-1]/h,a+=o[s]*o[s];for(i=Math.sqrt(a),o[u]>0&&(i=-i),a-=o[u]*i,o[u]=o[u]-i,f=u;r>f;f++){for(e=0,s=l;s>=u;s--)e+=o[s]*t[s][f];for(e/=a,s=u;l>=s;s++)t[s][f]-=e*o[s]}for(s=0;l>=s;s++){for(e=0,f=l;f>=u;f--)e+=o[f]*t[s][f];for(e/=a,f=u;l>=f;f++)t[s][f]-=e*o[f]}o[u]=h*o[u],t[u][u-1]=h*i}}for(s=0;r>s;s++)for(f=0;r>f;f++)n[s][f]=s===f?1:0;for(u=l-1;u>=c+1;u--)if(0!==t[u][u-1]){for(s=u+1;l>=s;s++)o[s]=t[s][u-1];for(f=u;l>=f;f++){for(i=0,s=u;l>=s;s++)i+=o[s]*n[s][f];for(i=i/o[u]/t[u][u-1],s=u;l>=s;s++)n[s][f]+=i*o[s]}}}function s(r,t,o,n,e){var i,a,s,u,h,c,l,m,p,w,v,d,y,g,b,M=r-1,x=0,A=r-1,R=Math.pow(2,-52),z=0,k=0,S=0,j=0,E=0,V=0,C=0,q=0;for(i=0;r>i;i++)for((x>i||i>A)&&(o[i]=e[i][i],t[i]=0),a=Math.max(i-1,0);r>a;a++)k+=Math.abs(e[i][a]);for(;M>=x;){for(u=M;u>x&&(V=Math.abs(e[u-1][u-1])+Math.abs(e[u][u]),0===V&&(V=k),!(Math.abs(e[u][u-1])<R*V));)u--;if(u===M)e[M][M]=e[M][M]+z,o[M]=e[M][M],t[M]=0,M--,q=0;else if(u===M-1){if(l=e[M][M-1]*e[M-1][M],S=(e[M-1][M-1]-e[M][M])/2,j=S*S+l,C=Math.sqrt(Math.abs(j)),e[M][M]=e[M][M]+z,e[M-1][M-1]=e[M-1][M-1]+z,m=e[M][M],j>=0){for(C=S>=0?S+C:S-C,o[M-1]=m+C,o[M]=o[M-1],0!==C&&(o[M]=m-l/C),t[M-1]=0,t[M]=0,m=e[M][M-1],V=Math.abs(m)+Math.abs(C),S=m/V,j=C/V,E=Math.sqrt(S*S+j*j),S/=E,j/=E,a=M-1;r>a;a++)C=e[M-1][a],e[M-1][a]=j*C+S*e[M][a],e[M][a]=j*e[M][a]-S*C;for(i=0;M>=i;i++)C=e[i][M-1],e[i][M-1]=j*C+S*e[i][M],e[i][M]=j*e[i][M]-S*C;for(i=x;A>=i;i++)C=n[i][M-1],n[i][M-1]=j*C+S*n[i][M],n[i][M]=j*n[i][M]-S*C}else o[M-1]=m+S,o[M]=m+S,t[M-1]=C,t[M]=-C;M-=2,q=0}else{if(m=e[M][M],p=0,l=0,M>u&&(p=e[M-1][M-1],l=e[M][M-1]*e[M-1][M]),10===q){for(z+=m,i=x;M>=i;i++)e[i][i]-=m;V=Math.abs(e[M][M-1])+Math.abs(e[M-1][M-2]),m=p=.75*V,l=-.4375*V*V}if(30===q&&(V=(p-m)/2,V=V*V+l,V>0)){for(V=Math.sqrt(V),m>p&&(V=-V),V=m-l/((p-m)/2+V),i=x;M>=i;i++)e[i][i]-=V;z+=V,m=p=l=.964}for(q+=1,h=M-2;h>=u&&(C=e[h][h],E=m-C,V=p-C,S=(E*V-l)/e[h+1][h]+e[h][h+1],j=e[h+1][h+1]-C-E-V,E=e[h+2][h+1],V=Math.abs(S)+Math.abs(j)+Math.abs(E),S/=V,j/=V,E/=V,h!==u)&&!(Math.abs(e[h][h-1])*(Math.abs(j)+Math.abs(E))<R*(Math.abs(S)*(Math.abs(e[h-1][h-1])+Math.abs(C)+Math.abs(e[h+1][h+1]))));)h--;for(i=h+2;M>=i;i++)e[i][i-2]=0,i>h+2&&(e[i][i-3]=0);for(s=h;M-1>=s&&(g=s!==M-1,s!==h&&(S=e[s][s-1],j=e[s+1][s-1],E=g?e[s+2][s-1]:0,m=Math.abs(S)+Math.abs(j)+Math.abs(E),0!==m&&(S/=m,j/=m,E/=m)),0!==m);s++)if(V=Math.sqrt(S*S+j*j+E*E),0>S&&(V=-V),0!==V){for(s!==h?e[s][s-1]=-V*m:u!==h&&(e[s][s-1]=-e[s][s-1]),S+=V,m=S/V,p=j/V,C=E/V,j/=S,E/=S,a=s;r>a;a++)S=e[s][a]+j*e[s+1][a],g&&(S+=E*e[s+2][a],e[s+2][a]=e[s+2][a]-S*C),e[s][a]=e[s][a]-S*m,e[s+1][a]=e[s+1][a]-S*p;for(i=0;i<=Math.min(M,s+3);i++)S=m*e[i][s]+p*e[i][s+1],g&&(S+=C*e[i][s+2],e[i][s+2]=e[i][s+2]-S*E),e[i][s]=e[i][s]-S,e[i][s+1]=e[i][s+1]-S*j;for(i=x;A>=i;i++)S=m*n[i][s]+p*n[i][s+1],g&&(S+=C*n[i][s+2],n[i][s+2]=n[i][s+2]-S*E),n[i][s]=n[i][s]-S,n[i][s+1]=n[i][s+1]-S*j}}}if(0!==k){for(M=r-1;M>=0;M--)if(S=o[M],j=t[M],0===j)for(u=M,e[M][M]=1,i=M-1;i>=0;i--){for(l=e[i][i]-S,E=0,a=u;M>=a;a++)E+=e[i][a]*e[a][M];if(t[i]<0)C=l,V=E;else if(u=i,0===t[i]?e[i][M]=0!==l?-E/l:-E/(R*k):(m=e[i][i+1],p=e[i+1][i],j=(o[i]-S)*(o[i]-S)+t[i]*t[i],c=(m*V-C*E)/j,e[i][M]=c,e[i+1][M]=Math.abs(m)>Math.abs(C)?(-E-l*c)/m:(-V-p*c)/C),c=Math.abs(e[i][M]),R*c*c>1)for(a=i;M>=a;a++)e[a][M]=e[a][M]/c}else if(0>j)for(u=M-1,Math.abs(e[M][M-1])>Math.abs(e[M-1][M])?(e[M-1][M-1]=j/e[M][M-1],e[M-1][M]=-(e[M][M]-S)/e[M][M-1]):(b=f(0,-e[M-1][M],e[M-1][M-1]-S,j),e[M-1][M-1]=b[0],e[M-1][M]=b[1]),e[M][M-1]=0,e[M][M]=1,i=M-2;i>=0;i--){for(w=0,v=0,a=u;M>=a;a++)w+=e[i][a]*e[a][M-1],v+=e[i][a]*e[a][M];if(l=e[i][i]-S,t[i]<0)C=l,E=w,V=v;else if(u=i,0===t[i]?(b=f(-w,-v,l,j),e[i][M-1]=b[0],e[i][M]=b[1]):(m=e[i][i+1],p=e[i+1][i],d=(o[i]-S)*(o[i]-S)+t[i]*t[i]-j*j,y=2*(o[i]-S)*j,0===d&&0===y&&(d=R*k*(Math.abs(l)+Math.abs(j)+Math.abs(m)+Math.abs(p)+Math.abs(C))),b=f(m*E-C*w+j*v,m*V-C*v-j*w,d,y),e[i][M-1]=b[0],e[i][M]=b[1],Math.abs(m)>Math.abs(C)+Math.abs(j)?(e[i+1][M-1]=(-w-l*e[i][M-1]+j*e[i][M])/m,e[i+1][M]=(-v-l*e[i][M]-j*e[i][M-1])/m):(b=f(-E-p*e[i][M-1],-V-p*e[i][M],C,j),e[i+1][M-1]=b[0],e[i+1][M]=b[1])),c=Math.max(Math.abs(e[i][M-1]),Math.abs(e[i][M])),R*c*c>1)for(a=i;M>=a;a++)e[a][M-1]=e[a][M-1]/c,e[a][M]=e[a][M]/c}for(i=0;r>i;i++)if(x>i||i>A)for(a=i;r>a;a++)n[i][a]=e[i][a];for(a=r-1;a>=x;a--)for(i=x;A>=i;i++){for(C=0,s=x;s<=Math.min(a,A);s++)C+=n[i][s]*e[s][a];n[i][a]=C}}}function f(r,t,o,n){var e,i;return Math.abs(o)>Math.abs(n)?(e=n/o,i=o+e*n,[(r+e*t)/i,(t-e*r)/i]):(e=o/n,i=n+e*o,[(e*r+t)/i,(e*t-r)/i])}var u=o(6),h=o(9).hypotenuse;n.prototype={get realEigenvalues(){return this.d},get imaginaryEigenvalues(){return this.e},get eigenvectorMatrix(){return this.V},get diagonalMatrix(){var r,t,o=this.n,n=this.e,e=this.d,i=new u(o,o);for(r=0;o>r;r++){for(t=0;o>t;t++)i[r][t]=0;i[r][r]=e[r],n[r]>0?i[r][r+1]=n[r]:n[r]<0&&(i[r][r-1]=n[r])}return i}},r.exports=n},function(r,t,o){"use strict";function n(r){if(!(this instanceof n))return new n(r);r=e.checkMatrix(r);var t,o,i,a,s,f,u,h,c,l,m=r.clone(),p=m.rows,w=m.columns,v=new Array(p),d=1;for(t=0;p>t;t++)v[t]=t;for(c=new Array(p),o=0;w>o;o++){for(t=0;p>t;t++)c[t]=m[t][o];for(t=0;p>t;t++){for(h=m[t],l=Math.min(t,o),s=0,i=0;l>i;i++)s+=h[i]*c[i];h[o]=c[t]-=s}for(a=o,t=o+1;p>t;t++)Math.abs(c[t])>Math.abs(c[a])&&(a=t);if(a!==o){for(i=0;w>i;i++)f=m[a][i],m[a][i]=m[o][i],m[o][i]=f;u=v[a],v[a]=v[o],v[o]=u,d=-d}if(p>o&&0!==m[o][o])for(t=o+1;p>t;t++)m[t][o]/=m[o][o]}this.LU=m,this.pivotVector=v,this.pivotSign=d}var e=o(6);n.prototype={isSingular:function(){for(var r=this.LU,t=r.columns,o=0;t>o;o++)if(0===r[o][o])return!0;return!1},get determinant(){var r=this.LU;if(!r.isSquare())throw new Error("Matrix must be square");for(var t=this.pivotSign,o=r.columns,n=0;o>n;n++)t*=r[n][n];return t},get lowerTriangularFactor(){for(var r=this.LU,t=r.rows,o=r.columns,n=new e(t,o),i=0;t>i;i++)for(var a=0;o>a;a++)i>a?n[i][a]=r[i][a]:i===a?n[i][a]=1:n[i][a]=0;return n},get upperTriangularFactor(){for(var r=this.LU,t=r.rows,o=r.columns,n=new e(t,o),i=0;t>i;i++)for(var a=0;o>a;a++)a>=i?n[i][a]=r[i][a]:n[i][a]=0;return n},get pivotPermutationVector(){return this.pivotVector.slice()},solve:function(r){r=e.checkMatrix(r);var t=this.LU,o=t.rows;if(o!==r.rows)throw new Error("Invalid matrix dimensions");if(this.isSingular())throw new Error("LU matrix is singular");var n,i,a,s=r.columns,f=r.subMatrixRow(this.pivotVector,0,s-1),u=t.columns;for(a=0;u>a;a++)for(n=a+1;u>n;n++)for(i=0;s>i;i++)f[n][i]-=f[a][i]*t[n][a];for(a=u-1;a>=0;a--){for(i=0;s>i;i++)f[a][i]/=t[a][a];for(n=0;a>n;n++)for(i=0;s>i;i++)f[n][i]-=f[a][i]*t[n][a]}return f}},r.exports=n},function(r,t,o){"use strict";function n(r){if(!(this instanceof n))return new n(r);r=e.checkMatrix(r);var t,o,a,s,f=r.clone(),u=r.rows,h=r.columns,c=new Array(h);for(a=0;h>a;a++){var l=0;for(t=a;u>t;t++)l=i(l,f[t][a]);if(0!==l){for(f[a][a]<0&&(l=-l),t=a;u>t;t++)f[t][a]/=l;for(f[a][a]+=1,o=a+1;h>o;o++){for(s=0,t=a;u>t;t++)s+=f[t][a]*f[t][o];for(s=-s/f[a][a],t=a;u>t;t++)f[t][o]+=s*f[t][a]}}c[a]=-l}this.QR=f,this.Rdiag=c}var e=o(6),i=o(9).hypotenuse;n.prototype={solve:function(r){r=e.checkMatrix(r);var t=this.QR,o=t.rows;if(r.rows!==o)throw new Error("Matrix row dimensions must agree");if(!this.isFullRank())throw new Error("Matrix is rank deficient");var n,i,a,s,f=r.columns,u=r.clone(),h=t.columns;for(a=0;h>a;a++)for(i=0;f>i;i++){for(s=0,n=a;o>n;n++)s+=t[n][a]*u[n][i];for(s=-s/t[a][a],n=a;o>n;n++)u[n][i]+=s*t[n][a]}for(a=h-1;a>=0;a--){for(i=0;f>i;i++)u[a][i]/=this.Rdiag[a];for(n=0;a>n;n++)for(i=0;f>i;i++)u[n][i]-=u[a][i]*t[n][a]}return u.subMatrix(0,h-1,0,f-1)},isFullRank:function(){for(var r=this.QR.columns,t=0;r>t;t++)if(0===this.Rdiag[t])return!1;return!0},get upperTriangularFactor(){var r,t,o=this.QR,n=o.columns,i=new e(n,n);for(r=0;n>r;r++)for(t=0;n>t;t++)t>r?i[r][t]=o[r][t]:r===t?i[r][t]=this.Rdiag[r]:i[r][t]=0;return i},get orthogonalFactor(){var r,t,o,n,i=this.QR,a=i.rows,s=i.columns,f=new e(a,s);for(o=s-1;o>=0;o--){for(r=0;a>r;r++)f[r][o]=0;for(f[o][o]=1,t=o;s>t;t++)if(0!==i[o][o]){for(n=0,r=o;a>r;r++)n+=i[r][o]*f[r][t];for(n=-n/i[o][o],r=o;a>r;r++)f[r][t]+=n*i[r][o]}}return f}},r.exports=n},function(r,t,o){"use strict";function n(r){if(!(this instanceof n))return new n(r);if(r=e.checkMatrix(r),!r.isSymmetric())throw new Error("Matrix is not symmetric");var t,o,i,a=r,s=a.rows,f=new e(s,s),u=!0;for(o=0;s>o;o++){var h=f[o],c=0;for(i=0;o>i;i++){var l=f[i],m=0;for(t=0;i>t;t++)m+=l[t]*h[t];h[i]=m=(a[o][i]-m)/f[i][i],c+=m*m}for(c=a[o][o]-c,u&=c>0,f[o][o]=Math.sqrt(Math.max(c,0)),i=o+1;s>i;i++)f[o][i]=0}if(!u)throw new Error("Matrix is not positive definite");this.L=f}var e=o(6);n.prototype={get leftTriangularFactor(){return this.L},solve:function(r){r=e.checkMatrix(r);var t=this.L,o=t.rows;if(r.rows!==o)throw new Error("Matrix dimensions do not match");var n,i,a,s=r.columns,f=r.clone();for(a=0;o>a;a++)for(i=0;s>i;i++){for(n=0;a>n;n++)f[a][i]-=f[n][i]*t[a][n];f[a][i]/=t[a][a]}for(a=o-1;a>=0;a--)for(i=0;s>i;i++){for(n=a+1;o>n;n++)f[a][i]-=f[n][i]*t[n][a];f[a][i]/=t[a][a]}return f}},r.exports=n},function(r,t,o){"use strict";function n(r,t){return new A(r,t)}function e(r,t){return A.ones(r,t)}function i(r,t){return A.eye(r,t)}function a(r,t){return A.zeros(r,t)}function s(r,t){return A.rand(r,t)}function f(r){if("number"==typeof r)return r;var t=r.clone();return t.transpose()}function u(r,t){if("number"==typeof r&&"number"==typeof t)return r+t;if("number"==typeof r)return this.add(t,r);var o=r.clone();return o.add(t)}function h(r,t){if("number"==typeof r&&"number"==typeof t)return r-t;if("number"==typeof r)return this.subtract(t,r);var o=r.clone();return o.sub(t)}function c(r,t){if("number"==typeof r&&"number"==typeof t)return r*t;if("number"==typeof r)return this.multiply(t,r);var o=r.clone();return"number"==typeof t?o.mul(t):o=o.mmul(t),1==o.rows&&1==o.columns?o[0][0]:o}function l(r,t){var o=r.clone();return o.mul(t)}function m(r,t){var o=r.clone();return o.div(t)}function p(r){var t,o,n=null,e=r.rows,i=r.columns;if("undefined"==typeof i&&"object"==typeof r)if(r[0]&&r[0].length)for(e=r.length,i=r[0].length,o=Math.min(e,i),n=A.zeros(i,i),t=0;i>t;t++)n[t][t]=r[t][t];else for(i=r.length,n=A.zeros(i,i),t=0;i>t;t++)n[t][t]=r[t];if(1==e)for(n=A.zeros(i,i),t=0;i>t;t++)n[t][t]=r[0][t];else if(e>0&&i>0)for(o=Math.min(e,i),n=new Array(o),t=0;o>t;t++)n[t]=r[t][t];return n}function w(r,t){if("number"==typeof r&&"number"==typeof t)return Math.min(r,t);for(var o=r.rows,n=r.columns,e=new A(o,n),i=0;o>i;i++)for(var a=0;n>a;a++)r[i][a]<t[i][a]?e[i][a]=r[i][a]:e[i][a]=t[i][a];return e}function v(r,t){if("number"==typeof r&&"number"==typeof t)return Math.max(r,t);for(var o=r.rows,n=r.columns,e=new A(o,n),i=0;o>i;i++)for(var a=0;n>a;a++)r[i][a]>t[i][a]?e[i][a]=r[i][a]:e[i][a]=t[i][a];return e}function d(r){if("number"==typeof r)return Math.sqrt(r);for(var t=r.rows,o=r.columns,n=new A(t,o),e=0;t>e;e++)for(var i=0;o>i;i++)n[e][i]=Math.sqrt(r[e][i]);return n}function y(r){if("number"==typeof r)return Math.abs(r);for(var t=r.rows,o=r.columns,n=new A(t,o),e=0;t>e;e++)for(var i=0;o>i;i++)n[e][i]=Math.abs(r[e][i]);return n}function g(r){if("number"==typeof r)return Math.sqrt(r);for(var t=r.rows,o=r.columns,n=new A(t,o),e=0;t>e;e++)for(var i=0;o>i;i++)n[e][i]=Math.exp(r[e][i]);return n}function b(r,t){if("number"==typeof r)return Math.pow(r,t);for(var o=r.rows,n=r.columns,e=new A(o,n),i=0;o>i;i++)for(var a=0;n>a;a++)e[i][a]=Math.pow(r[i][a],t);return e}function M(r,t){return r.solve(t)}function x(r){return"number"==typeof r?1/r:r.inverse()}var A=o(5);r.exports={transpose:f,add:u,subtract:h,multiply:c,dotMultiply:l,dotDivide:m,diag:p,min:w,max:v,solve:M,inv:x,sqrt:d,exp:g,dotPow:b,abs:y,matrix:n,ones:e,zeros:a,random:s,eye:i}},function(r,t,o){function n(r,t,o){var o=Object.create(o||{});void 0===o.minMaxRatio&&(o.minMaxRatio=25e-5),void 0===o.broadRatio&&(o.broadRatio=0),void 0===o.noiseLevel&&(o.noiseLevel=void 0),void 0===o.noiseFactor&&(o.noiseFactor=3),void 0===o.maxCriteria&&(o.maxCriteria=!0),void 0===o.smoothY&&(o.smoothY=!0),void 0===o.realTopDetection&&(o.realTopDetection=!1);var n=a({},f,o.sgOptions);if(void 0===o.noiseLevel){for(var u,h=0,c=Number.MAX_VALUE,l=0;l<r.length-1;l++){var u=Math.abs(r[l+1]-r[l]);c>u&&(c=u),u>h&&(h=u)}.05>(h-c)/h?o.noiseLevel=e(t):o.noiseLevel=0}t=[].concat(t);var m={m:1,b:o.noiseLevel};o.maxCriteria||(m.m=-1,m.b*=-1);for(var l=0;l<t.length;l++)t[l]=m.m*t[l]-m.b;for(var l=0;l<t.length;l++)t[l]<0&&(t[l]=0);var p=t;if(.05>(h-c)/h){o.smoothY&&(p=s(t,r[1]-r[0],{windowSize:n.windowSize,polynomial:n.polynomial,derivative:0}));var w=s(t,r[1]-r[0],{windowSize:n.windowSize,polynomial:n.polynomial,derivative:1}),v=s(t,r[1]-r[0],{windowSize:n.windowSize,polynomial:n.polynomial,derivative:2})}else{o.smoothY&&(p=s(t,r,{windowSize:n.windowSize,polynomial:n.polynomial,derivative:0}));var w=s(t,r,{windowSize:n.windowSize,polynomial:n.polynomial,derivative:1}),v=s(t,r,{windowSize:n.windowSize,polynomial:n.polynomial,derivative:2})}for(var d=r,y=r[1]-r[0],g=0,b=0,l=0;l<p.length;l++)Math.abs(v[l])>g&&(g=Math.abs(v[l])),Math.abs(p[l])>b&&(b=Math.abs(p[l]));for(var M=[],x=[],A=[],R=null,z=null,k=new Array,l=1;l<p.length-1;l++)(w[l]<w[l-1]&&w[l]<=w[l+1]||w[l]<=w[l-1]&&w[l]<w[l+1])&&(z=d[l],y>0&&null!=R&&(x.push(R),A.push(z))),(w[l]>=w[l-1]&&w[l]>w[l+1]||w[l]>w[l-1]&&w[l]>=w[l+1])&&(R=d[l],0>y&&null!=z&&(x.push(R),A.push(z))),v[l]<v[l-1]&&v[l]<v[l+1]&&(M.push(l),Math.abs(v[l])>o.broadRatio*g?k.push(!1):k.push(!0));for(var S,j,E,V,C,q,D=[],I=0,O=0;O<M.length;O++){for(E=d[M[O]],S=-1,j=I+1,C=Number.MAX_VALUE,V=0,q=!0;-1==S&&j<x.length&&q;)V=Math.abs(E-(x[j]+A[j])/2),C>V?C=V:q=!1,V<Math.abs(x[j]-A[j])/2&&(S=j,I=j),j++;-1!=S&&Math.abs(p[M[O]])>o.minMaxRatio*b&&D.push({i:M[O],x:E,y:(p[M[O]]-m.b)/m.m,width:Math.abs(A[S]-x[S]),soft:k[O]})}o.realTopDetection&&i(D,d,p);for(var O=0;O<D.length;O++)D[O].base=o.noiseLevel;return D.sort(function(r,t){return r.x-t.x}),D}function e(r){var t=0,o=0,n=r.length,e=0;for(e=0;n>e;e++)t+=r[e];t/=n;var i=new Array(n);for(e=0;n>e;e++)i[e]=Math.abs(r[e]-t);return i.sort(),o=n%2==1?i[(n-1)/2]/.6745:.5*(i[n/2]+i[n/2-1])/.6745}function i(r,t,o){for(var n,e,i,a,s,f=0;f<r.length;f++){s=r[f].i;o[s-1]>=o[s-2]&&o[s-1]>=o[s]?s--:o[s+1]>=o[s]&&o[s+1]>=o[s+2]?s++:o[s-2]>=o[s-3]&&o[s-2]>=o[s-1]?s-=2:o[s+2]>=o[s+1]&&o[s+2]>=o[s+3]&&(s+=2),o[s-1]>0&&o[s+1]>0&&o[s]>=o[s-1]&&o[s]>=o[s+1]&&(n=20*Math.log10(o[s-1]),e=20*Math.log10(o[s]),i=20*Math.log10(o[s+1]),a=.5*(n-i)/(n-2*e+i),r[f].x=t[s]+(t[s]-t[s-1])*a,r[f].y=o[s]-.25*(o[s-1]-o[s+1])*a)}}var a=(o(2),o(16),o(19)),s=o(20),f={windowSize:9,polynomial:3};r.exports=n},function(r,t,o){"use strict";t.array=o(17),t.matrix=o(18)},function(r,t){"use strict";function o(r,t){return r-t}t.sum=function n(r){for(var n=0,t=0;t<r.length;t++)n+=r[t];return n},t.max=function e(r){for(var e=-(1/0),t=r.length,o=0;t>o;o++)r[o]>e&&(e=r[o]);return e},t.min=function i(r){for(var i=1/0,t=r.length,o=0;t>o;o++)r[o]<i&&(i=r[o]);return i},t.minMax=function(r){for(var t=1/0,o=-(1/0),n=r.length,e=0;n>e;e++)r[e]<t&&(t=r[e]),r[e]>o&&(o=r[e]);return{min:t,max:o}},t.arithmeticMean=function(r){for(var t=0,o=r.length,n=0;o>n;n++)t+=r[n];return t/o},t.mean=t.arithmeticMean,t.geometricMean=function(r){for(var t=1,o=r.length,n=0;o>n;n++)t*=r[n];return Math.pow(t,1/o)},t.logMean=function(r){for(var t=0,o=r.length,n=0;o>n;n++)t+=Math.log(r[n]);return t/o},t.grandMean=function(r,t){for(var o=0,n=0,e=r.length,i=0;e>i;i++)o+=t[i]*r[i],n+=t[i];return o/n},t.truncatedMean=function(r,t,n){void 0===n&&(n=!1),n||(r=r.slice().sort(o));for(var e=r.length,i=Math.floor(e*t),a=0,s=i;e-i>s;s++)a+=r[s];return a/(e-2*i)},t.harmonicMean=function(r){for(var t=0,o=r.length,n=0;o>n;n++){if(0===r[n])throw new RangeError("value at index "+n+"is zero");t+=1/r[n]}return o/t},t.contraHarmonicMean=function(r){for(var t=0,o=0,n=r.length,e=0;n>e;e++)t+=r[e]*r[e],o+=r[e];if(0>o)throw new RangeError("sum of values is negative");return t/o},t.median=function(r,t){void 0===t&&(t=!1),t||(r=r.slice().sort(o));var n=r.length,e=Math.floor(n/2);return n%2===0?.5*(r[e-1]+r[e]):r[e]},t.variance=function(r,o){void 0===o&&(o=!0);for(var n=t.mean(r),e=0,i=r.length,a=0;i>a;a++){var s=r[a]-n;e+=s*s}return o?e/(i-1):e/i},t.standardDeviation=function(r,o){return Math.sqrt(t.variance(r,o))},t.standardError=function(r){return t.standardDeviation(r)/Math.sqrt(r.length)},t.quartiles=function(r,n){"undefined"==typeof n&&(n=!1),n||(r=r.slice(),r.sort(o));var e=r.length/4,i=r[Math.ceil(e)-1],a=t.median(r,!0),s=r[Math.ceil(3*e)-1];return{q1:i,q2:a,q3:s}},t.pooledStandardDeviation=function(r,o){return Math.sqrt(t.pooledVariance(r,o))},t.pooledVariance=function(r,o){"undefined"==typeof o&&(o=!0);for(var n=0,e=0,i=r.length,a=0;i>a;a++){var s=r[a],f=t.variance(s);n+=(s.length-1)*f,e+=o?s.length-1:s.length}return n/e},t.mode=function(r){var t,o=r.length,n=new Array(o);for(t=0;o>t;t++)n[t]=0;var e=new Array(o),i=0;for(t=0;o>t;t++){var a=e.indexOf(r[t]);a>=0?n[a]++:(e[i]=r[t],n[i]=1,i++)}var s=0,f=0;for(t=0;i>t;t++)n[t]>s&&(s=n[t],f=t);return e[f]},t.covariance=function(r,o,n){"undefined"==typeof n&&(n=!0);var e=t.mean(r),i=t.mean(o);if(r.length!==o.length)throw"Vectors do not have the same dimensions";for(var a=0,s=r.length,f=0;s>f;f++){var u=r[f]-e,h=o[f]-i;a+=u*h}return n?a/(s-1):a/s},t.skewness=function(r,o){"undefined"==typeof o&&(o=!0);for(var n=t.mean(r),e=0,i=0,a=r.length,s=0;a>s;s++){var f=r[s]-n;e+=f*f,i+=f*f*f}var u=e/a,h=i/a,c=h/Math.pow(u,1.5);if(o){var l=Math.sqrt(a*(a-1)),m=a-2;return l/m*c}return c},t.kurtosis=function(r,o){"undefined"==typeof o&&(o=!0);for(var n=t.mean(r),e=r.length,i=0,a=0,s=0;e>s;s++){var f=r[s]-n;i+=f*f,a+=f*f*f*f}var u=i/e,h=a/e;if(o){var c=i/(e-1),l=e*(e+1)/((e-1)*(e-2)*(e-3)),m=a/(c*c),p=(e-1)*(e-1)/((e-2)*(e-3));return l*m-3*p}return h/(u*u)-3},t.entropy=function(r,t){"undefined"==typeof t&&(t=0);for(var o=0,n=r.length,e=0;n>e;e++)o+=r[e]*Math.log(r[e]+t);return-o},t.weightedMean=function(r,t){for(var o=0,n=r.length,e=0;n>e;e++)o+=r[e]*t[e];return o},t.weightedStandardDeviation=function(r,o){return Math.sqrt(t.weightedVariance(r,o))},t.weightedVariance=function(r,o){for(var n=t.weightedMean(r,o),e=0,i=r.length,a=0,s=0,f=0;i>f;f++){var u=r[f]-n,h=o[f];e+=h*(u*u),s+=h,a+=h*h}return e*(s/(s*s-a))},t.center=function(r,o){"undefined"==typeof o&&(o=!1);var n=r;o||(n=r.slice());for(var e=t.mean(n),i=n.length,a=0;i>a;a++)n[a]-=e},t.standardize=function(r,o,n){"undefined"==typeof o&&(o=t.standardDeviation(r)),"undefined"==typeof n&&(n=!1);for(var e=r.length,i=n?r:new Array(e),a=0;e>a;a++)i[a]=r[a]/o;return i},t.cumulativeSum=function(r){var t=r.length,o=new Array(t);o[0]=r[0];for(var n=1;t>n;n++)o[n]=o[n-1]+r[n];return o}},function(r,t,o){"use strict";function n(r,t){"undefined"==typeof t&&(t=0);for(var o=0,n=r.length,e=r[0].length,i=0;n>i;i++)for(var a=0;e>a;a++)o+=r[i][a]*Math.log(r[i][a]+t);return-o}function e(r,t){"undefined"==typeof t&&(t=0);var o,n,e,i,a=r.length,s=r[0].length;if(-1===t){for(o=[0],n=a*s,e=0;a>e;e++)for(i=0;s>i;i++)o[0]+=r[e][i];o[0]/=n}else if(0===t)for(o=new Array(s),n=a,i=0;s>i;i++){for(o[i]=0,e=0;a>e;e++)o[i]+=r[e][i];o[i]/=n}else{if(1!==t)throw new Error("Invalid dimension");for(o=new Array(a),n=s,i=0;a>i;i++){for(o[i]=0,e=0;s>e;e++)o[i]+=r[i][e];o[i]/=n}}return o}function i(r,t,o){for(var n=a(r,t,o),e=n.length,i=0;e>i;i++)n[i]=Math.sqrt(n[i]);return n}function a(r,t,o){"undefined"==typeof o&&(o=!0),t=t||e(r);var n=r.length;if(0===n)return[];for(var i=r[0].length,a=new Array(i),s=0;i>s;s++){for(var f=0,u=0,h=0,c=0;n>c;c++)h=r[c][s]-t[s],f+=h,u+=h*h;o?a[s]=(u-f*f/n)/(n-1):a[s]=(u-f*f/n)/n}return a}function s(r){for(var t=r.length,o=r[0].length,n=new Array(o),e=0;o>e;e++){for(var i=new Array(t),a=0;t>a;a++)i[a]=r[a][e];i.sort();var s=i.length;s%2===0?n[e]=.5*(i[s/2]+i[s/2-1]):n[e]=i[Math.floor(s/2)]}return n}function f(r){var t,o,n=r.length,e=r[0].length,i=new Array(e);for(t=0;e>t;t++){for(var a=new Array(n),s=0;n>s;s++)a[s]=0;var f=new Array(n),u=0;for(o=0;n>o;o++){var h=f.indexOf(r[o][t]);h>=0?a[h]++:(f[u]=r[o][t],a[u]=1,u++)}var c=0,l=0;for(o=0;u>o;o++)a[o]>c&&(c=a[o],l=o);i[t]=f[l]}return i}function u(r,t){"undefined"==typeof t&&(t=!0);for(var o=e(r),n=r.length,i=o.length,a=new Array(i),s=0;i>s;s++){for(var f=0,u=0,h=0;n>h;h++){var c=r[h][s]-o[s];f+=c*c,u+=c*c*c}var l=f/n,m=u/n,p=m/Math.pow(l,1.5);if(t){var w=Math.sqrt(n*(n-1)),v=n-2;a[s]=w/v*p}else a[s]=p}return a}function h(r,t){"undefined"==typeof t&&(t=!0);for(var o=e(r),n=r.length,i=r[0].length,a=new Array(i),s=0;i>s;s++){for(var f=0,u=0,h=0;n>h;h++){var c=r[h][s]-o[s];f+=c*c,u+=c*c*c*c}var l=f/n,m=u/n;if(t){var p=f/(n-1),w=n*(n+1)/((n-1)*(n-2)*(n-3)),v=u/(p*p),d=(n-1)*(n-1)/((n-2)*(n-3));a[s]=w*v-3*d}else a[s]=m/(l*l)-3}return a}function c(r){for(var t=r.length,o=i(r),n=o.length,e=new Array(n),a=Math.sqrt(t),s=0;n>s;s++)e[s]=o[s]/a;return e}function l(r,t){return m(r,void 0,t)}function m(r,t,o){"undefined"==typeof o&&(o=0),"undefined"==typeof t&&(0===o?t=r.length-1:1===o&&(t=r[0].length-1));var n=e(r,o),i=r.length;if(0===i)return[[]];var a,s,f,u,h,c=r[0].length;if(0===o){for(a=new Array(c),s=0;c>s;s++)a[s]=new Array(c);for(s=0;c>s;s++)for(f=s;c>f;f++){for(u=0,h=0;i>h;h++)u+=(r[h][f]-n[f])*(r[h][s]-n[s]);u/=t,a[s][f]=u,a[f][s]=u}}else{if(1!==o)throw new Error("Invalid dimension");for(a=new Array(i),s=0;i>s;s++)a[s]=new Array(i);for(s=0;i>s;s++)for(f=s;i>f;f++){for(u=0,h=0;c>h;h++)u+=(r[f][h]-n[f])*(r[s][h]-n[s]);u/=t,a[s][f]=u,a[f][s]=u}}return a}function p(r){var t,o,n=e(r),a=i(r,!0,n),s=w(r,n,a),f=r.length,u=r[0].length,h=new Array(u);for(t=0;u>t;t++)h[t]=new Array(u);for(t=0;u>t;t++)for(o=t;u>o;o++){for(var c=0,l=0,m=s.length;m>l;l++)c+=s[l][o]*s[l][t];c/=f-1,h[t][o]=c,h[o][t]=c}return h}function w(r,t,o){return t=t||e(r),"undefined"==typeof o&&(o=i(r,!0,t)),d(v(r,t,!1),o,!0)}function v(r,t,o){t=t||e(r);var n,i,a,s=r,f=r.length;if(!o)for(s=new Array(f),n=0;f>n;n++)s[n]=new Array(r[n].length);for(n=0;f>n;n++){var u=s[n];for(i=0,a=u.length;a>i;i++)u[i]=r[n][i]-t[i]}return s}function d(r,t,o){"undefined"==typeof t&&(t=i(r));var n,e,a,s=r,f=r.length;if(!o)for(s=new Array(f),n=0;f>n;n++)s[n]=new Array(r[n].length);for(n=0;f>n;n++){var u=s[n],h=r[n];for(e=0,a=u.length;a>e;e++)0===t[e]||isNaN(t[e])||(u[e]=h[e]/t[e])}return s}function y(r,t){var o=e(r),n=r.length;if(0===n)return[];for(var i=r[0].length,a=new Array(i),s=0;i>s;s++){for(var f=0,u=0,h=0,c=0;n>c;c++){var l=r[c][s]-o[s],m=t[c];f+=m*(l*l),h+=m,u+=m*m}a[s]=f*(h/(h*h-u))}return a}function g(r,t,o){"undefined"==typeof o&&(o=0);var n=r.length;if(0===n)return[];var e,i,a,s,f,u,h=r[0].length;if(0===o){for(e=new Array(h),i=0;h>i;i++)e[i]=0;for(i=0;n>i;i++)for(u=r[i],f=t[i],s=0;h>s;s++)e[s]+=u[s]*f}else{if(1!==o)throw new Error("Invalid dimension");for(e=new Array(n),i=0;n>i;i++)e[i]=0;for(s=0;n>s;s++)for(u=r[s],f=t[s],i=0;h>i;i++)e[s]+=u[i]*f}var c=x.sum(t);if(0!==c)for(i=0,a=e.length;a>i;i++)e[i]/=c;return e}function b(r,t,o,n){n=n||0,o=o||g(r,t,n);for(var e=0,i=0,a=0,s=t.length;s>a;a++)e+=t[a],i+=t[a]*t[a];var f=e/(e*e-i);return M(r,t,o,f,n)}function M(r,t,o,n,e){e=e||0,o=o||g(r,t,e),"undefined"==typeof n&&(n=1);var i=r.length;if(0===i)return[[]];var a,s,f,u,h,c=r[0].length;if(0===e){for(a=new Array(c),s=0;c>s;s++)a[s]=new Array(c);for(s=0;c>s;s++)for(f=s;c>f;f++){for(h=0,u=0;i>u;u++)h+=t[u]*(r[u][f]-o[f])*(r[u][s]-o[s]);a[s][f]=h*n,a[f][s]=h*n}}else{if(1!==e)throw new Error("Invalid dimension");for(a=new Array(i),s=0;i>s;s++)a[s]=new Array(i);for(s=0;i>s;s++)for(f=s;i>f;f++){for(h=0,u=0;c>u;u++)h+=t[u]*(r[f][u]-o[f])*(r[s][u]-o[s]);a[s][f]=h*n,a[f][s]=h*n}}return a}var x=o(17);r.exports={entropy:n,mean:e,standardDeviation:i,variance:a,median:s,mode:f,skewness:u,kurtosis:h,standardError:c,covariance:l,scatter:m,correlation:p,zScores:w,center:v,standardize:d,weightedVariance:y,weightedMean:g,weightedCovariance:b,weightedScatter:M}},function(r,t){"use strict";var o=Object.prototype.hasOwnProperty,n=Object.prototype.toString,e=function(r){return"function"==typeof Array.isArray?Array.isArray(r):"[object Array]"===n.call(r)},i=function(r){if(!r||"[object Object]"!==n.call(r))return!1;var t=o.call(r,"constructor"),e=r.constructor&&r.constructor.prototype&&o.call(r.constructor.prototype,"isPrototypeOf");if(r.constructor&&!t&&!e)return!1;var i;for(i in r);return"undefined"==typeof i||o.call(r,i)};r.exports=function a(){var r,t,o,n,s,f,u=arguments[0],h=1,c=arguments.length,l=!1;for("boolean"==typeof u?(l=u,u=arguments[1]||{},h=2):("object"!=typeof u&&"function"!=typeof u||null==u)&&(u={});c>h;++h)if(r=arguments[h],null!=r)for(t in r)o=u[t],n=r[t],u!==n&&(l&&n&&(i(n)||(s=e(n)))?(s?(s=!1,f=o&&e(o)?o:[]):f=o&&i(o)?o:{},u[t]=a(l,f,n)):"undefined"!=typeof n&&(u[t]=n));return u}},function(r,t,o){function n(r,t,o){if(o=u({},h,o),o.windowSize%2===0||o.windowSize<5||!Number.isInteger(o.windowSize))throw new RangeError("Invalid window size (should be odd and at least 5 integer number)");if(o.windowSize>r.length)throw new RangeError("Window size is higher than the data length "+o.windowSize+">"+r.length);if(o.derivative<0||!Number.isInteger(o.derivative))throw new RangeError("Derivative should be a positive integer");if(o.polynomial<1||!Number.isInteger(o.polynomial))throw new RangeError("Polynomial should be a positive integer");o.polynomial>=6&&console.warn("You should not use polynomial grade higher than 5 if you are not sure that your data arises from such a model. Possible polynomial oscillation problems");var n=o.windowSize,i=Math.floor(n/2),a=r.length,s=new Array(a),c=f(n,o.polynomial,o.derivative),l=0,m=!0;"[object Array]"===Object.prototype.toString.call(t)?m=!1:l=Math.pow(t,o.derivative);for(var p=0;i>p;p++){for(var w=c[i-p-1],v=c[i+p+1],d=0,y=0,g=0;n>g;g++)d+=w[g]*r[g],y+=v[g]*r[a-n+g-1];m?(s[i-p-1]=d/l,s[a-i+p]=y/l):(l=e(t,i-p-1,i,o.derivative),s[i-p-1]=d/l,l=e(t,a-i+p,i,o.derivative),s[a-i+p]=y/l)}for(var b=c[i],p=n;a+1>p;p++){for(var M=0,g=0;n>g;g++)M+=b[g]*r[g+p-n];m||(l=e(t,p-i-1,i,o.derivative)),s[p-i-1]=M/l}return s}function e(r,t,o,n){for(var e=0,i=0,a=t-o;t+o>a;a++)a>=0&&a<r.length-1&&(e+=r[a+1]-r[a],i++);return Math.pow(e/i,n)}function i(r,t,o,n){var e=0;return e=o>0?(4*o-2)/(o*(2*t-o+1))*(r*i(r,t,o-1,n)+n*i(r,t,o-1,n-1))-(o-1)*(2*t+o)/(o*(2*t-o+1))*i(r,t,o-2,n):0==o&&0==n?1:0}function a(r,t){var o=1;if(r>=t)for(var n=r-t+1;r>=n;n++)o*=n;return o}function s(r,t,o,n,e){for(var s=0,f=0;n>=f;f++)s+=(2*f+1)*(a(2*o,f)/a(2*o+f+1,f+1))*i(r,o,f,0)*i(t,o,f,e);return s}function f(r,t,o){for(var n=new Array(r),e=Math.floor(r/2),i=-e;e>=i;i++){n[i+e]=new Array(r);for(var a=-e;e>=a;a++)n[i+e][a+e]=s(a,i,e,t,o)}return n}var u=o(19),h=(o(16),{windowSize:9,derivative:0,polynomial:3});r.exports=n}])}); | ||
//# sourceMappingURL=ml-gsd.min.js.map |
{ | ||
"name": "ml-gsd", | ||
"version": "1.1.2", | ||
"version": "1.1.4", | ||
"description": "Global Spectra Deconvolution", | ||
@@ -36,11 +36,11 @@ "main": "src/index.js", | ||
"should": "^7.0.2", | ||
"chemcalc": "^3.0.1" | ||
"chemcalc": "^3.0.6" | ||
}, | ||
"dependencies": { | ||
"ml-optimize-lorentzian": "0.0.2", | ||
"ml-stat": "^1.0.1", | ||
"xy-parser": "^1.1.0", | ||
"ml-savitzky-golay-generalized": "1.0.3", | ||
"ml-stat": "^1.1.0", | ||
"xy-parser": "^1.2.0", | ||
"ml-savitzky-golay-generalized": "1.1.0", | ||
"extend": "3.0.0" | ||
} | ||
} |
@@ -30,5 +30,5 @@ # global-spectral-deconvolution | ||
``` | ||
var peakPicking = require("ml-gsd"); | ||
var CC = require('chemcalc'); | ||
var Stat = require('ml-stat'); | ||
var peakPicking = require("../src/index"); | ||
@@ -35,0 +35,0 @@ |
110
src/gsd.js
@@ -17,3 +17,4 @@ var Opt = require("ml-optimize-lorentzian"); | ||
if (options.broadRatio===undefined) options.broadRatio=0.00; | ||
if (options.noiseLevel===undefined) options.noiseLevel=0; | ||
if (options.noiseLevel===undefined) options.noiseLevel=undefined; | ||
if (options.noiseFactor===undefined) options.noiseFactor=3; | ||
if (options.maxCriteria===undefined) options.maxCriteria=true; | ||
@@ -25,33 +26,43 @@ if (options.smoothY===undefined) options.smoothY=true; | ||
//Transform y to use the standard algorithm. | ||
var yCorrection = {m:1, b:0}; | ||
if(!options.maxCriteria||options.noiseLevel>0){ | ||
y=[].concat(y); | ||
if(!options.maxCriteria){ | ||
yCorrection = {m:-1, b:stats.array.max(y)}; | ||
for (var i=0; i<y.length; i++){ | ||
y[i]=-y[i]+yCorrection.b; | ||
//console.log(JSON.stringify(stats.array.minMax(y))); | ||
if(options.noiseLevel===undefined){ | ||
//We have to know if x is equally spaced | ||
var maxDx=0, minDx=Number.MAX_VALUE,tmp; | ||
for(var i=0;i< x.length-1;i++){ | ||
var tmp = Math.abs(x[i+1]-x[i]); | ||
if(tmp<minDx){ | ||
minDx = tmp; | ||
} | ||
options.noiseLevel=-options.noiseLevel+yCorrection.b; | ||
} | ||
if (options.noiseLevel>0) { | ||
for (var i=0; i<y.length; i++){ | ||
if(Math.abs(y[i])<options.noiseLevel) { | ||
y[i]=0; | ||
} | ||
if(tmp>maxDx){ | ||
maxDx = tmp; | ||
} | ||
} | ||
} | ||
//We have to know if x is equally spaced | ||
var maxDx=0, minDx=Number.MAX_VALUE,tmp; | ||
for(var i=0;i< x.length-1;i++){ | ||
var tmp = Math.abs(x[i+1]-x[i]); | ||
if(tmp<minDx){ | ||
minDx = tmp; | ||
if((maxDx-minDx)/maxDx<0.05){ | ||
options.noiseLevel = getNoiseLevel(y); | ||
//console.log(options.noiseLevel+" "+stats.array.median(y)); | ||
} | ||
if(tmp>maxDx){ | ||
maxDx = tmp; | ||
else{ | ||
options.noiseLevel = 0; | ||
} | ||
} | ||
//console.log("options.noiseLevel "+options.noiseLevel); | ||
y=[].concat(y); | ||
var yCorrection = {m:1, b:options.noiseLevel}; | ||
if(!options.maxCriteria){ | ||
yCorrection.m =-1; | ||
yCorrection.b*=-1; | ||
} | ||
for (var i=0; i<y.length; i++){ | ||
y[i]=yCorrection.m*y[i]-yCorrection.b; | ||
} | ||
for (var i=0; i<y.length; i++) { | ||
if (y[i] < 0) { | ||
y[i] = 0; | ||
} | ||
} | ||
//If the max difference between delta x is less than 5%, then, we can assume it to be equally spaced variable | ||
@@ -71,3 +82,3 @@ var Y = y; | ||
} | ||
var X = x; | ||
@@ -128,5 +139,2 @@ var dx = x[1]-x[0]; | ||
} | ||
if(options.realTopDetection){ | ||
realTopDetection(minddY,X,Y); | ||
} | ||
// | ||
@@ -163,2 +171,3 @@ //console.log(intervalL.length+" "+minddY.length+" "+broadMask.length); | ||
signals.push({ | ||
i:minddY[j], | ||
x: frequency, | ||
@@ -173,2 +182,12 @@ y: (Y[minddY[j]]-yCorrection.b)/yCorrection.m, | ||
if(options.realTopDetection){ | ||
realTopDetection(signals,X,Y); | ||
} | ||
//Correct the values to fit the original spectra data | ||
for(var j=0;j<signals.length;j++){ | ||
signals[j].base=options.noiseLevel; | ||
} | ||
signals.sort(function (a, b) { | ||
@@ -182,2 +201,22 @@ return a.x - b.x; | ||
function getNoiseLevel(y){ | ||
var mean = 0,stddev=0; | ||
var length = y.length,i=0; | ||
for(i = 0; i < length; i++){ | ||
mean+=y[i]; | ||
} | ||
mean/=length; | ||
var averageDeviations = new Array(length); | ||
for (i = 0; i < length; i++) | ||
averageDeviations[i] = Math.abs(y[i] - mean); | ||
averageDeviations.sort(); | ||
if (length % 2 == 1) { | ||
stddev = averageDeviations[(length-1)/2] / 0.6745; | ||
} else { | ||
stddev = 0.5*(averageDeviations[length/2]+averageDeviations[length/2-1]) / 0.6745; | ||
} | ||
return stddev; | ||
} | ||
function realTopDetection(peakList, x, y){ | ||
@@ -190,3 +229,4 @@ //console.log(peakList); | ||
for(var j=0;j<peakList.length;j++){ | ||
currentPoint = peakList[j];//peakList[j][2]; | ||
currentPoint = peakList[j].i;//peakList[j][2]; | ||
var tmp = currentPoint; | ||
//The detected peak could be moved 1 or 2 unit to left or right. | ||
@@ -222,6 +262,8 @@ if(y[currentPoint-1]>=y[currentPoint-2] | ||
p = 0.5 * (alpha - gamma) / (alpha - 2 * beta + gamma); | ||
x[peakList[j]] = x[currentPoint] + (x[currentPoint]-x[currentPoint-1])*p; | ||
y[peakList[j]] = y[currentPoint] - 0.25 * (y[currentPoint - 1] | ||
- [currentPoint + 1]) * p;//signal.peaks[j].intensity); | ||
//console.log("p: "+p); | ||
//console.log(x[currentPoint]+" "+tmp+" "+currentPoint); | ||
peakList[j].x = x[currentPoint] + (x[currentPoint]-x[currentPoint-1])*p; | ||
peakList[j].y = y[currentPoint] - 0.25 * (y[currentPoint - 1] | ||
- y[currentPoint + 1]) * p;//signal.peaks[j].intensity); | ||
//console.log(y[tmp]+" "+peakList[j].y); | ||
} | ||
@@ -228,0 +270,0 @@ } |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
769766
6351
+ Addedml-savitzky-golay-generalized@1.1.0(transitive)
- Removedml-savitzky-golay-generalized@1.0.3(transitive)
Updatedml-stat@^1.1.0
Updatedxy-parser@^1.2.0