ml-optimize-lorentzian
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -1,3 +0,3 @@ | ||
!function(t,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports.mlOptimizeLorentzian=r():t.mlOptimizeLorentzian=r()}(this,function(){return function(t){function r(n){if(o[n])return o[n].exports;var e=o[n]={exports:{},id:n,loaded:!1};return t[n].call(e.exports,e,e.exports,r),e.loaded=!0,e.exports}var o={};return r.m=t,r.c=o,r.p="",r(0)}([function(t,r,o){"use strict";function n(t,r,o){var n,e,i,s,a=r.length/3,u=t.rows,f=m.zeros(t.length,1);for(e=0;a>e;e++)for(s=Math.pow(r[e+2*a][0]/2,2),n=r[e+a][0]*s,i=0;u>i;i++)f[i][0]+=n/(Math.pow(t[i][0]-r[e][0],2)+s);return f}function e(t,r,o){for(var n=r[1][0]*Math.pow(r[2][0]/2,2),e=t.rows,i=new m(t.rows,t.columns),s=0;e>s;s++)i[s][0]=n/(Math.pow(t[s][0]-r[0][0],2)+Math.pow(r[2][0]/2,2));return i}function i(t,r,o){for(var n=r[2][0]*r[2][0]/2,e=t.rows,i=new m(t.rows,t.columns),s=0;e>s;s++)i[s][0]=r[1][0]*Math.exp(-(t[s][0]-r[0][0])*(t[s][0]-r[0][0])/n);return i}function s(t,r,o){var n=h(t),i=n[0],s=n[1],a=n[2],u=i.columns,f=[u/Math.sqrt(s.dot(s))],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([[r.x],[1],[r.width]]),y=new m([[r.x-p],[.75],[r.width/4]]),b=new m([[r.x+p],[1.25],[4*r.width]]),d=c.optimize(e,v,i,s,f,w,y,b,l,o);return d=d.p,[d[0],[d[1][0]*a],d[2]]}function a(t,r,o){var n=h(t),e=n[0],s=n[1],a=n[2],u=e.columns,f=[u/Math.sqrt(s.dot(s))],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],[-r.width/1e3]]),v=new m([[r.x],[1],[r.width]]),y=new m([[r.x-p],[.75],[r.width/4]]),b=new m([[r.x+p],[1.25],[4*r.width]]),d=c.optimize(i,v,e,s,f,w,y,b,l,o);return d=d.p,[d[0],[d[1][0]*a],d[2]]}function u(t,r,o){var e,i=h(t),s=i[0],a=i[1],u=i[2],f=s.columns,p=[f/l.sqrt(a.dot(a))],o=Object.create(o||[3,100,.001,.001,.001,.01,.01,11,9,1]),w=[],v=r.length,y=new m(3*v,1),b=new m(3*v,1),d=new m(3*v,1),M=new m(3*v,1),g=Math.abs(s[0][0]-s[1][0]);for(e=0;v>e;e++)y[e][0]=r[e].x,y[e+v][0]=1,y[e+2*v][0]=r[e].width,b[e][0]=r[e].x-g,b[e+v][0]=0,b[e+2*v][0]=r[e].width/4,d[e][0]=r[e].x+g,d[e+v][0]=1.5,d[e+2*v][0]=4*r[e].width,M[e][0]=-g/1e3,M[e+v][0]=-.001,M[e+2*v][0]=-g/1e3;var M=-Math.abs(s[0][0]-s[1][0])/1e4,x=c.optimize(n,y,s,a,p,M,b,d,w,o);x=x.p;var R=new Array(v);for(e=0;v>e;e++)R[e]=[x[e],[x[e+v][0]*u],x[e+2*v]];return R}function f(t,r,o){var e,i=h(t),s=i[0],a=i[1],u=i[2],f=s.rows,p=new m(f,1),w=f/l.sqrt(a.dot(a));for(e=0;f>e;e++)p[e][0]=w;var o=Object.create(o||[3,100,.001,.001,.001,.01,.01,11,9,2]),v=[],y=r.length,b=new m(3*y,1),d=new m(3*y,1),M=new m(3*y,1),g=new m(3*y,1),x=Math.abs(s[0][0]-s[1][0]);for(e=0;y>e;e++)b[e][0]=r[e].x,b[e+y][0]=r[e].y/u,b[e+2*y][0]=r[e].width,d[e][0]=r[e].x-x,d[e+y][0]=.8*r[e].y/u,d[e+2*y][0]=r[e].width/2,M[e][0]=r[e].x+x,M[e+y][0]=1.2*r[e].y/u,M[e+2*y][0]=2*r[e].width,g[e][0]=-x/1e3,g[e+y][0]=-.001,g[e+2*y][0]=-x/1e3;var R=c.optimize(n,b,s,a,p,g,d,M,v,o);R=R.p;var k=new Array(y);for(e=0;y>e;e++)k[e]=[R[e],[R[e+y][0]*u],R[e+2*y]];return k}function h(t){var r,o,n,e=t.length,i=null,s=null,a=0;if(2==e){var u=t[0].length;if(3>u)throw new SizeException(u);if(i=new m(u,1),s=new m(u,1),r=t[0],o=t[1],"number"==typeof r[0])for(n=0;u>n;n++)i[n][0]=r[n],s[n][0]=o[n],o[n]>a&&(a=o[n]);else if("object"==typeof r[0])for(n=0;u>n;n++)i[n][0]=r[n][0],s[n][0]=o[n][0],o[n][0]>a&&(a=o[n][0])}else{var u=e;if(3>u)throw new SizeException(u);for(i=new m(u,1),s=new m(u,1),n=0;u>n;n++)i[n][0]=t[n][0],s[n][0]=t[n][1],s[n][0]>a&&(a=s[n][0])}for(n=0;u>n;n++)s[n][0]/=a;return[i,s,a]}var c=o(1),l=c.Matrix.algebra,m=o(3);t.exports.optimizeSingleLorentzian=s,t.exports.optimizeLorentzianSum=u,t.exports.optimizeSingleGaussian=a,t.exports.optimizeGaussianSum=f,t.exports.singleGaussian=i,t.exports.singleLorentzian=e},function(t,r,o){"use strict";t.exports=o(2),t.exports.Matrix=o(3),t.exports.Matrix.algebra=o(12)},function(t,r,o){var n=o(3),e=o(12),i={optimize:function(t,r,o,i,s,a,u,f,h,c){var l=0,m=0;if("object"!=typeof r[0])for(var p=0;p<r.length;p++)r[p]=[r[p]];var p,w,v=-50,y=r.length,b=i.length,d=n.zeros(y,1),M=n.zeros(b,1),g=.01/v,x=.01/v,R=n.zeros(b,y);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 g=0;if(!l)return}s=s||Math.sqrt((b-y+1)/e.multiply(e.transpose(i),i)),a=a||.001,u=u||e.multiply(Math.abs(r),-100),f=f||e.multiply(Math.abs(r),100),h=h||1,c=c||[3,10*y,.001,.001,.001,.01,.01,11,9,1];var k=c[0],j=c[1],A=c[2],z=(c[3],c[4],c[5]),C=c[6],V=c[7],E=c[8],q=c[9];if(l&&3==k&&(k=2),!a.length||1==a.length){for(var I=new Array(y),p=0;y>p;p++)I[p]=[a];a=I}var D=[];for(p=0;p<a.length;p++)0!=a[p][0]&&D.push(p);var S=D.length,O=!1,_=null;if(!s.length||s.length<b){var J=e.multiply(n.ones(b,1),s[0]);_=e.dotMultiply(J,J)}else _=e.dotMultiply(s,s);var L=this.lm_matx(t,o,d,M,1,R,r,i,_,a,h),U=L.JtWJ,W=L.JtWdy,g=L.Chi_sq,T=L.y_hat,R=L.J;switch(Math.max(Math.abs(W))<A&&(console.log(" *** Your Initial Guess is Extremely Close to Optimal ***"),console.log(" *** epsilon_1 = ",A),O=!0),q){case 1:lambda=C;break;default:lambda=C*Math.max(e.diag(U)),nu=2}x=g;for(var Q=null;!O&&j>=m;){switch(m+=1,q){case 1:Q=e.solve(e.add(U,e.multiply(e.diag(e.diag(U)),lambda)),W);break;default:Q=e.solve(e.add(U,e.multiply(n.eye(y),lambda)),W)}var F=new Array(D.length);for(w=0;w<D.length;w++)F[w]=Q[D[w]];var P=e.add(r,F);for(w=0;w<P.length;w++)P[w][0]=Math.min(Math.max(u[w][0],P[w][0]),f[w][0]);var G=e.subtract(i,t(o,P,h)),X=e.multiply(e.transpose(G),e.dotMultiply(G,_));if(2==q){var B=e.multiply(e.transpose(W),Q),H=e.multiply(B,e.inv(e.add(e.multiply(e.subtract(X-g),.5)),e.multiply(B,2)));Q=e.multiply(H,Q);for(var w=0;w<D.length;w++)F[w]=Q[D[w]];P=e.add(r,F),P=e.min(e.max(u,P),f),G=e.subtract(i,t(o,P,h)),X=e.multiply(e.transpose(G),mat.dotMultiply(G,_))}var N=(g-X)/e.multiply(e.multiply(e.transpose(Q),2),e.add(e.multiply(lambda,Q),W));if(N>z)switch(dX2=g-x,x=g,d=r,M=T,r=P,L=this.lm_matx(t,o,d,M,dX2,R,r,i,_,a,h),U=L.JtWJ,W=L.JtWdy,g=L.Chi_sq,T=L.y_hat,R=L.J,q){case 1:lambda=Math.max(lambda/E,1e-7);break;case 2:lambda=Math.max(lambda/(1+H),1e-7);break;case 3:lambda=e.multiply(Math.max(1/3,1-(2*N-1)^3),lambda),nu=2}else switch(g=x,m%(2*y)==0&&(L=this.lm_matx(t,o,d,M,-1,R,r,i,_,a,h),U=L.JtWJ,W=L.JtWdy,dX2=L.Chi_sq,T=L.y_hat,R=L.J),q){case 1:lambda=Math.min(lambda*V,1e7);break;case 2:lambda+=Math.abs((X-g)/2/H);break;case 3:lambda*=nu,nu=2*nu}}return _=e.multiply(e.multiply(e.transpose(G),G),n.ones(b,1)),_.apply(function(t,r){_[t][r]=(b-S+1)/_[t][r]}),L=this.lm_matx(t,o,d,M,-1,R,r,i,_,a,h),U=L.JtWJ,W=L.JtWdy,g=L.Chi_sq,T=L.y_hat,R=L.J,{p:r,X2:g}},lm_FD_J:function(t,r,o,i,s,a){var u=i.length,f=o.length;s=s||e.multiply(n.ones(f,1),.001);for(var h=o.clone(),c=new n(u,f),l=new Array(f),m=0;f>m;m++){if(l[m]=s[m]*(1+Math.abs(o[m][0])),o[m]=[h[m][0]+l[m]],0!=l[m])if(y1=t(r,o,a),s[m][0]<0)for(var p=e.dotDivide(e.subtract(y1,i),l[m]),w=0;u>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,t(r,o,a)),2*l[m]),w=0;u>w;w++)c[w][m]=p[w][0]}o[m]=h[m]}return c},lm_Broyden_J:function(t,r,o,n,i){var s=e.subtract(n,t),a=e.transpose(s);return a.div(e.multiply(a,s)),o=e.add(o,e.multiply(e.subtract(i,e.add(r,e.multiply(o,s))),a))},lm_matx:function(t,r,o,i,s,a,u,f,h,c,l,m){var p=(f.length,u.length);c=c||.001;var w=t(r,u,l);a=m%(2*p)==0||s>0?this.lm_FD_J(t,r,u,w,c,l):this.lm_Broyden_J(o,i,a,u,w);var v=e.subtract(f,w),y=e.multiply(e.transpose(v),e.dotMultiply(v,h)),b=e.transpose(a),d=e.multiply(b,e.dotMultiply(a,e.multiply(h,n.ones(1,p)))),M=e.multiply(b,e.dotMultiply(h,v));return{JtWJ:d,JtWdy:M,Chi_sq:y,y_hat:w,J:a}}};t.exports=i},function(t,r,o){"use strict";t.exports=o(4),t.exports.Decompositions=t.exports.DC=o(5)},function(t,r){"use strict";function o(t){for(var r=0,o=t.length,n=new Array(o);o>r;r++)n[r]=t[r];return n}function n(t,r){var e,i,s=0;if(Array.isArray(t)){if(i=r,e=i?o(t):t,t=e.length,r=e[0].length,"undefined"==typeof r)throw new TypeError("Data must be a 2D array");if(!(t>0&&r>0))throw new RangeError("Invalid dimensions: "+t+"x"+r);for(;t>s;s++){if(e[s].length!==r)throw new RangeError("Inconsistent array dimensions");i&&(e[s]=o(e[s]))}}else{if("number"!=typeof t)throw new TypeError("Invalid arguments");if(!(t>0&&r>0))throw new RangeError("Invalid dimensions: "+t+"x"+r);for(e=new Array(t);t>s;s++)e[s]=new Array(r)}return Object.defineProperty(e,"rows",{writable:!0,value:t}),Object.defineProperty(e,"columns",{writable:!0,value:r}),e.__proto__=n.prototype,e}var e=Array.prototype.splice,i=Array.prototype.concat;n.from1DArray=function(t,r,o){var e,i,s=0;if(e=t*r,e!==o.length)throw new RangeError("Data length does not match given dimensions");for(i=new Array(t);t>s;s++)i[s]=o.slice(s*r,(s+1)*r);return new n(i)},n.rowVector=function(t){return new n([t])},n.columnVector=function(t){for(var r=t.length,o=new Array(r),e=0;r>e;e++)o[e]=[t[e]];return new n(o)},n.empty=function(t,r){return new n(t,r)},n.zeros=function(t,r){return n.empty(t,r).fill(0)},n.ones=function(t,r){return n.empty(t,r).fill(1)},n.rand=function(t,r){for(var o=n.empty(t,r),e=0,i=o.rows;i>e;e++)for(var s=0,a=o.columns;a>s;s++)o[e][s]=Math.random();return o},n.eye=function(t){for(var r=n.zeros(t,t),o=r.rows,e=0;o>e;e++)r[e][e]=1;return r},n.diag=function(t){for(var r=t.length,o=n.zeros(r,r),e=0;r>e;e++)o[e][e]=t[e];return o},n.indices=function(t,r){for(var o=new Array(r-t),n=0;n<o.length;n++)o[n]=t++;return o},n.stack=function(t){var r,o,e;if(n.isMatrix(t)){var i=0,s=0;for(r=0;r<arguments.length;r++)i+=arguments[r].rows,arguments[r].columns>s&&(s=arguments[r].columns);var a=n.zeros(i,s),u=0;for(r=0;r<arguments.length;r++){var f=arguments[r];for(o=0;o<f.rows;o++){for(e=0;e<f.columns;e++)a[u][e]=f[o][e];u++}}return a}if(Array.isArray(t)){var h=n.empty(arguments.length,t.length);for(r=0;r<arguments.length;r++)h.setRow(r,arguments[r]);return h}},n.expand=function(t,r){for(var o=[],e=0;e<r.length;e++)for(var i=0;i<r[e];i++)o.push(t[e]);return new n(o)},n.checkMatrix=function(t){if(!t)throw new TypeError("Argument has to be a matrix");return"Matrix"!==t.klass&&(t=new n(t)),t},n.isMatrix=function(t){return t?"Matrix"===t.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(t){if(0>t||t>this.rows-1)throw new RangeError("Row index out of range.")},n.prototype.checkColumnIndex=function(t){if(0>t||t>this.columns-1)throw new RangeError("Column index out of range.")},n.prototype.checkDimensions=function(t){if(this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal.")},n.prototype.apply=function(t){for(var r=this.rows,o=this.columns,n=0;r>n;n++)for(var e=0;o>e;e++)t.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 t=this.rows,r=new Array(t),n=0;t>n;n++)r[n]=o(this[n]);return r},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 t=this.rows,r=0;t>r;r++)for(var o=0;r>=o;o++)if(this[r][o]!==this[o][r])return!1;return!0}return!1},n.prototype.set=function(t,r,o){return this[t][r]=o,this},n.prototype.get=function(t,r){return this[t][r]},n.prototype.fill=function(t){for(var r=this.rows,o=this.columns,n=0;r>n;n++)for(var e=0;o>e;e++)this[n][e]=t;return this},n.prototype.neg=function(){return this.mulS(-1)},n.prototype.add=function(t){return"number"==typeof t?this.addS(t):(t=n.checkMatrix(t),this.addM(t))},n.prototype.addS=function(t){for(var r=this.rows,o=this.columns,n=0;r>n;n++)for(var e=0;o>e;e++)this[n][e]+=t;return this},n.prototype.addM=function(t){this.checkDimensions(t);for(var r=this.rows,o=this.columns,n=0;r>n;n++)for(var e=0;o>e;e++)this[n][e]+=t[n][e];return this},n.prototype.sub=function(t){return"number"==typeof t?this.subS(t):(t=n.checkMatrix(t),this.subM(t))},n.prototype.subS=function(t){for(var r=this.rows,o=this.columns,n=0;r>n;n++)for(var e=0;o>e;e++)this[n][e]-=t;return this},n.prototype.subM=function(t){this.checkDimensions(t);for(var r=this.rows,o=this.columns,n=0;r>n;n++)for(var e=0;o>e;e++)this[n][e]-=t[n][e];return this},n.prototype.mul=function(t){return"number"==typeof t?this.mulS(t):(t=n.checkMatrix(t),this.mulM(t))},n.prototype.mulS=function(t){for(var r=this.rows,o=this.columns,n=0;r>n;n++)for(var e=0;o>e;e++)this[n][e]*=t;return this},n.prototype.mulM=function(t){this.checkDimensions(t);for(var r=this.rows,o=this.columns,n=0;r>n;n++)for(var e=0;o>e;e++)this[n][e]*=t[n][e];return this},n.prototype.div=function(t){return"number"==typeof t?this.divS(t):(t=n.checkMatrix(t),this.divM(t))},n.prototype.divS=function(t){for(var r=this.rows,o=this.columns,n=0;r>n;n++)for(var e=0;o>e;e++)this[n][e]/=t;return this},n.prototype.divM=function(t){this.checkDimensions(t);for(var r=this.rows,o=this.columns,n=0;r>n;n++)for(var e=0;o>e;e++)this[n][e]/=t[n][e];return this},n.prototype.getRow=function(t){return this.checkRowIndex(t),o(this[t])},n.prototype.getRowVector=function(t){return n.rowVector(this.getRow(t))},n.prototype.setRow=function(t,r){if(this.checkRowIndex(t),n.isMatrix(r)&&(r=r.to1DArray()),r.length!==this.columns)throw new RangeError("Invalid row size");return this[t]=o(r),this},n.prototype.removeRow=function(t){if(this.checkRowIndex(t),1===this.rows)throw new RangeError("A matrix cannot have less than one row");return e.call(this,t,1),this.rows-=1,this},n.prototype.addRow=function(t,r){if("undefined"==typeof r&&(r=t,t=this.rows),0>t||t>this.rows)throw new RangeError("Row index out of range.");if(n.isMatrix(r)&&(r=r.to1DArray()),r.length!==this.columns)throw new RangeError("Invalid row size");return e.call(this,t,0,o(r)),this.rows+=1,this},n.prototype.swapRows=function(t,r){this.checkRowIndex(t),this.checkRowIndex(r);var o=this[t];return this[t]=this[r],this[r]=o,this},n.prototype.getColumn=function(t){this.checkColumnIndex(t);for(var r=this.rows,o=new Array(r),n=0;r>n;n++)o[n]=this[n][t];return o},n.prototype.getColumnVector=function(t){return n.columnVector(this.getColumn(t))},n.prototype.setColumn=function(t,r){this.checkColumnIndex(t),n.isMatrix(r)&&(r=r.to1DArray());var o=this.rows;if(r.length!==o)throw new RangeError("Invalid column size");for(var e=0;o>e;e++)this[e][t]=r[e];return this},n.prototype.removeColumn=function(t){if(this.checkColumnIndex(t),1===this.columns)throw new RangeError("A matrix cannot have less than one column");for(var r=0,o=this.rows;o>r;r++)this[r].splice(t,1);return this.columns-=1,this},n.prototype.addColumn=function(t,r){if("undefined"==typeof r&&(r=t,t=this.columns),0>t||t>this.columns)throw new RangeError("Column index out of range.");n.isMatrix(r)&&(r=r.to1DArray());var o=this.rows;if(r.length!==o)throw new RangeError("Invalid column size");for(var e=0;o>e;e++)this[e].splice(t,0,r[e]);return this.columns+=1,this},n.prototype.swapColumns=function(t,r){this.checkRowIndex(t),this.checkRowIndex(r);for(var o,n,e=this.rows,i=0;e>i;i++)n=this[i],o=n[t],n[t]=n[r],n[r]=o;return this},n.prototype.checkRowVector=function(t){if(n.isMatrix(t)&&(t=t.to1DArray()),t.length!==this.columns)throw new RangeError("vector size must be the same as the number of columns");return t},n.prototype.checkColumnVector=function(t){if(n.isMatrix(t)&&(t=t.to1DArray()),t.length!==this.rows)throw new RangeError("vector size must be the same as the number of rows");return t},n.prototype.addRowVector=function(t){t=this.checkRowVector(t);for(var r=this.rows,o=this.columns,n=0;r>n;n++)for(var e=0;o>e;e++)this[n][e]+=t[e];return this},n.prototype.subRowVector=function(t){t=this.checkRowVector(t);for(var r=this.rows,o=this.columns,n=0;r>n;n++)for(var e=0;o>e;e++)this[n][e]-=t[e];return this},n.prototype.mulRowVector=function(t){t=this.checkRowVector(t);for(var r=this.rows,o=this.columns,n=0;r>n;n++)for(var e=0;o>e;e++)this[n][e]*=t[e];return this},n.prototype.divRowVector=function(t){t=this.checkRowVector(t);for(var r=this.rows,o=this.columns,n=0;r>n;n++)for(var e=0;o>e;e++)this[n][e]/=t[e];return this},n.prototype.addColumnVector=function(t){t=this.checkColumnVector(t);for(var r=this.rows,o=this.columns,n=0;r>n;n++)for(var e=0;o>e;e++)this[n][e]+=t[n];return this},n.prototype.subColumnVector=function(t){t=this.checkColumnVector(t);for(var r=this.rows,o=this.columns,n=0;r>n;n++)for(var e=0;o>e;e++)this[n][e]-=t[n];return this},n.prototype.mulColumnVector=function(t){t=this.checkColumnVector(t);for(var r=this.rows,o=this.columns,n=0;r>n;n++)for(var e=0;o>e;e++)this[n][e]*=t[n];return this},n.prototype.divColumnVector=function(t){t=this.checkColumnVector(t);for(var r=this.rows,o=this.columns,n=0;r>n;n++)for(var e=0;o>e;e++)this[n][e]/=t[n];return this},n.prototype.mulRow=function(t,r){this.checkRowIndex(t);for(var o=0,n=this.columns;n>o;o++)this[t][o]*=r;return this},n.prototype.mulColumn=function(t,r){this.checkColumnIndex(t);for(var o=0,n=this.rows;n>o;o++)this[o][t]*=r},n.prototype.max=function(){for(var t=-(1/0),r=this.rows,o=this.columns,n=0;r>n;n++)for(var e=0;o>e;e++)this[n][e]>t&&(t=this[n][e]);return t},n.prototype.maxIndex=function(){for(var t=-(1/0),r={},o=this.rows,n=this.columns,e=0;o>e;e++)for(var i=0;n>i;i++)this[e][i]>t&&(t=this[e][i],r.row=e,r.column=i);return r},n.prototype.min=function(){for(var t=1/0,r=this.rows,o=this.columns,n=0;r>n;n++)for(var e=0;o>e;e++)this[n][e]<t&&(t=this[n][e]);return t},n.prototype.minIndex=function(){for(var t=1/0,r={},o=this.rows,n=this.columns,e=0;o>e;e++)for(var i=0;n>i;i++)this[e][i]<t&&(t=this[e][i],r.row=e,r.column=i);return r},n.prototype.maxRow=function(t){this.checkRowIndex(t);for(var r=-(1/0),o=0,n=this.columns;n>o;o++)this[t][o]>r&&(r=this[t][o]);return r},n.prototype.maxRowIndex=function(t){this.checkRowIndex(t);for(var r=-(1/0),o={row:t},n=0,e=this.columns;e>n;n++)this[t][n]>r&&(r=this[t][n],o.column=n);return o},n.prototype.minRow=function(t){this.checkRowIndex(t);for(var r=1/0,o=0,n=this.columns;n>o;o++)this[t][o]<r&&(r=this[t][o]);return r},n.prototype.minRowIndex=function(t){this.checkRowIndex(t);for(var r=1/0,o={row:t,column:0},n=0,e=this.columns;e>n;n++)this[t][n]<r&&(r=this[t][n],o.column=n);return o},n.prototype.maxColumn=function(t){this.checkColumnIndex(t);for(var r=-(1/0),o=0,n=this.rows;n>o;o++)this[o][t]>r&&(r=this[o][t]);return r},n.prototype.maxColumnIndex=function(t){this.checkColumnIndex(t);for(var r=-(1/0),o={row:0,column:t},n=0,e=this.rows;e>n;n++)this[n][t]>r&&(r=this[n][t],o.row=n);return o},n.prototype.minColumn=function(t){this.checkColumnIndex(t);for(var r=1/0,o=0,n=this.rows;n>o;o++)this[o][t]<r&&(r=this[o][t]);return r},n.prototype.minColumnIndex=function(t){this.checkColumnIndex(t);for(var r=1/0,o={row:0,column:t},n=0,e=this.rows;e>n;n++)this[n][t]<r&&(r=this[n][t],o.row=n);return o},n.prototype.diag=function s(){if(!this.isSquare())throw new TypeError("Only square matrices have a diagonal.");for(var s=new Array(this.rows),t=0,r=this.rows;r>t;t++)s[t]=this[t][t];return s},n.prototype.sum=function(){for(var t=0,r=this.rows,o=this.columns,n=0;r>n;n++)for(var e=0;o>e;e++)t+=this[n][e];return t},n.prototype.mean=function(){return this.sum()/this.size},n.prototype.prod=function a(){for(var a=1,t=this.rows,r=this.columns,o=0;t>o;o++)for(var n=0;r>n;n++)a*=this[o][n];return a},n.prototype.cumulativeSum=function(){for(var t=0,r=this.rows,o=this.columns,n=0;r>n;n++)for(var e=0;o>e;e++)t+=this[n][e],this[n][e]=t;return this},n.prototype.dot=function u(t){if(this.size!==t.size)throw new RangeError("vectors do not have the same size");for(var r=this.to1DArray(),o=t.to1DArray(),u=0,n=r.length,e=0;n>e;e++)u+=r[e]*o[e];return u},n.prototype.mmul=function(t){if(!n.isMatrix(t))throw new TypeError('parameter "other" must be a matrix');this.columns!==t.rows&&console.warn("Number of columns of left matrix are not equal to number of rows of right matrix.");var r,o,e,i=this.rows,s=this.columns,a=t.columns,u=new n(i,a),f=new Array(s);for(o=0;a>o;o++){for(e=0;s>e;e++)f[e]=t[e][o];for(r=0;i>r;r++){var h=this[r],c=0;for(e=0;s>e;e++)c+=h[e]*f[e];u[r][o]=c}}return u},n.prototype.sortRows=function(t){for(var r=0,o=this.rows;o>r;r++)this[r].sort(t);return this},n.prototype.sortColumns=function(t){for(var r=0,o=this.columns;o>r;r++)this.setColumn(r,this.getColumn(r).sort(t));return this},n.prototype.transpose=function(){for(var t=new n(this.columns,this.rows),r=this.rows,o=this.columns,e=0;r>e;e++)for(var i=0;o>i;i++)t[i][e]=this[e][i];return t},n.prototype.subMatrix=function(t,r,o,e){if(t>r||o>e||0>t||t>=this.rows||0>r||r>=this.rows||0>o||o>=this.columns||0>e||e>=this.columns)throw new RangeError("Argument out of range");for(var i=new n(r-t+1,e-o+1),s=t;r>=s;s++)for(var a=o;e>=a;a++)i[s-t][a-o]=this[s][a];return i},n.prototype.subMatrixRow=function(t,r,o){if("undefined"==typeof r?(r=0,o=this.columns-1):"undefined"==typeof o&&(o=this.columns-1),r>o||0>r||r>=this.columns||0>o||o>=this.columns)throw new RangeError("Argument out of range.");for(var e=t.length,i=this.rows,s=new n(e,o-r+1),a=0;e>a;a++)for(var u=r;o>=u;u++){if(t[a]<0||t[a]>=i)throw new RangeError("Argument out of range.");s[a][u-r]=this[t[a]][u]}return s},n.prototype.subMatrixColumn=function(t,r,o){if("undefined"==typeof r?(r=0,o=this.rows-1):"undefined"==typeof o&&(o=this.rows-1),r>o||0>r||r>=this.rows||0>o||o>=this.rows)throw new RangeError("Argument out of range.");for(var e=t.length,i=this.columns,s=new n(o-r+1,e),a=0;e>a;a++)for(var u=r;o>=u;u++){if(t[a]<0||t[a]>=i)throw new RangeError("Argument out of range.");s[u-r][a]=this[u][t[a]]}return s},n.prototype.trace=function f(){if(!this.isSquare())throw new TypeError("The matrix is not square");for(var f=0,t=0,r=this.rows;r>t;t++)f+=this[t][t];return f},n.prototype.abs=function(){for(var t=this.rows,r=this.columns,o=0;t>o;o++)for(var n=0;r>n;n++)this[o][n]=Math.abs(this[o][n])},t.exports=n},function(t,r,o){"use strict";function n(t){return e(t,i.eye(t.rows))}function e(t,r){return t.isSquare()?new u(t).solve(r):new f(t).solve(r)}var i=o(4),s=o(6),a=o(8),u=o(9),f=o(10),h=o(11);i.prototype.inverse=function(){return n(this)},i.prototype.solve=function(t){return e(this,t)},t.exports={SingularValueDecomposition:s,SVD:s,EigenvalueDecomposition:a,EVD:a,LuDecomposition:u,LU:u,QrDecomposition:f,QR:f,CholeskyDecomposition:h,CHO:h,inverse:n,solve:e}},function(t,r,o){"use strict";function n(t,r){if(!(this instanceof n))return new n(t,r);t=e.checkMatrix(t),r=r||{};var o=t.clone(),s=t.rows,a=t.columns,u=Math.min(s,a),f=!0,h=!0;r.computeLeftSingularVectors===!1&&(f=!1),r.computeRightSingularVectors===!1&&(h=!1);var c=r.autoTranspose===!0,l=!1;if(a>s)if(c){o=o.transpose(),s=o.rows,a=o.columns,l=!0;var m=f;f=h,h=m}else console.warn("Computing SVD on a matrix with more columns than rows. Consider enabling autoTranspose");var p,w,v,y,b,d,M,g,x,R,k,j,A,z,C,V,E,q,I,D,S,O=new Array(Math.min(s+1,a)),_=e.zeros(s,u),J=e.zeros(a,a),L=new Array(a),U=new Array(s),W=Math.min(s-1,a),T=Math.max(0,Math.min(a-2,s));for(v=0,R=Math.max(W,T);R>v;v++){if(W>v){for(O[v]=0,p=v;s>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;s>p;p++)o[p][v]/=O[v];o[v][v]+=1}O[v]=-O[v]}for(w=v+1;a>w;w++){if(W>v&&0!==O[v]){for(b=0,p=v;s>p;p++)b+=o[p][v]*o[p][w];for(b=-b/o[v][v],p=v;s>p;p++)o[p][w]+=b*o[p][v]}L[w]=o[v][w]}if(f&&W>v)for(p=v;s>p;p++)_[p][v]=o[p][v];if(T>v){for(L[v]=0,p=v+1;a>p;p++)L[v]=i(L[v],L[p]);if(0!==L[v]){for(L[v+1]<0&&(L[v]=-L[v]),p=v+1;a>p;p++)L[p]/=L[v];L[v+1]+=1}if(L[v]=-L[v],s>v+1&&0!==L[v]){for(p=v+1;s>p;p++)U[p]=0;for(w=v+1;a>w;w++)for(p=v+1;s>p;p++)U[p]+=L[w]*o[p][w];for(w=v+1;a>w;w++)for(b=-L[w]/L[v+1],p=v+1;s>p;p++)o[p][w]+=b*U[p]}if(h)for(p=v+1;a>p;p++)J[p][v]=L[p]}}if(y=Math.min(a,s+1),a>W&&(O[W]=o[W][W]),y>s&&(O[y-1]=0),y>T+1&&(L[T]=o[T][y-1]),L[y-1]=0,f){for(w=W;u>w;w++){for(p=0;s>p;p++)_[p][w]=0;_[w][w]=1}for(v=W-1;v>=0;v--)if(0!==O[v]){for(w=v+1;u>w;w++){for(b=0,p=v;s>p;p++)b+=_[p][v]*_[p][w];for(b=-b/_[v][v],p=v;s>p;p++)_[p][w]+=b*_[p][v]}for(p=v;s>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;s>p;p++)_[p][v]=0;_[v][v]=1}}if(h)for(v=a-1;v>=0;v--){if(T>v&&0!==L[v])for(w=v+1;a>w;w++){for(b=0,p=v+1;a>p;p++)b+=J[p][v]*J[p][w];for(b=-b/J[v+1][v],p=v+1;a>p;p++)J[p][w]+=b*J[p][v]}for(p=0;a>p;p++)J[p][v]=0;J[v][v]=1}for(var Q=y-1,F=0,P=Math.pow(2,-52);y>0;){for(v=y-2;v>=-1&&-1!==v;v--)if(Math.abs(L[v])<=P*(Math.abs(O[v])+Math.abs(O[v+1]))){L[v]=0;break}if(v===y-2)k=4;else{for(d=y-1;d>=v&&d!==v;d--)if(b=(d!==y?Math.abs(L[d]):0)+(d!==v+1?Math.abs(L[d-1]):0),Math.abs(O[d])<=P*b){O[d]=0;break}d===v?k=3:d===y-1?k=1:(k=2,v=d)}switch(v++,k){case 1:for(M=L[y-2],L[y-2]=0,w=y-2;w>=v;w--)if(b=i(O[w],M),g=O[w]/b,x=M/b,O[w]=b,w!==v&&(M=-x*L[w-1],L[w-1]=g*L[w-1]),h)for(p=0;a>p;p++)b=g*J[p][w]+x*J[p][y-1],J[p][y-1]=-x*J[p][w]+g*J[p][y-1],J[p][w]=b;break;case 2:for(M=L[v-1],L[v-1]=0,w=v;y>w;w++)if(b=i(O[w],M),g=O[w]/b,x=M/b,O[w]=b,M=-x*L[w],L[w]=g*L[w],f)for(p=0;s>p;p++)b=g*_[p][w]+x*_[p][v-1],_[p][v-1]=-x*_[p][w]+g*_[p][v-1],_[p][w]=b;break;case 3:for(j=Math.max(Math.max(Math.max(Math.max(Math.abs(O[y-1]),Math.abs(O[y-2])),Math.abs(L[y-2])),Math.abs(O[v])),Math.abs(L[v])),A=O[y-1]/j,z=O[y-2]/j,C=L[y-2]/j,V=O[v]/j,E=L[v]/j,q=((z+A)*(z-A)+C*C)/2,I=A*C*(A*C),D=0,(0!==q||0!==I)&&(D=Math.sqrt(q*q+I),0>q&&(D=-D),D=I/(q+D)),M=(V+A)*(V-A)+D,S=V*E,w=v;y-1>w;w++){if(b=i(M,S),g=M/b,x=S/b,w!==v&&(L[w-1]=b),M=g*O[w]+x*L[w],L[w]=g*L[w]-x*O[w],S=x*O[w+1],O[w+1]=g*O[w+1],h)for(p=0;a>p;p++)b=g*J[p][w]+x*J[p][w+1],J[p][w+1]=-x*J[p][w]+g*J[p][w+1],J[p][w]=b;if(b=i(M,S),g=M/b,x=S/b,O[w]=b,M=g*L[w]+x*O[w+1],O[w+1]=-x*L[w]+g*O[w+1],S=x*L[w+1],L[w+1]=g*L[w+1],f&&s-1>w)for(p=0;s>p;p++)b=g*_[p][w]+x*_[p][w+1],_[p][w+1]=-x*_[p][w]+g*_[p][w+1],_[p][w]=b}L[y-2]=M,F+=1;break;case 4:if(O[v]<=0&&(O[v]=O[v]<0?-O[v]:0,h))for(p=0;Q>=p;p++)J[p][v]=-J[p][v];for(;Q>v&&!(O[v]>=O[v+1]);){if(b=O[v],O[v]=O[v+1],O[v+1]=b,h&&a-1>v)for(p=0;a>p;p++)b=J[p][v+1],J[p][v+1]=J[p][v],J[p][v]=b;if(f&&s-1>v)for(p=0;s>p;p++)b=_[p][v+1],_[p][v+1]=_[p][v],_[p][v]=b;v++}F=0,y--}}if(l){var G=J;J=_,_=G}this.m=s,this.n=a,this.s=O,this.U=_,this.V=J}var e=o(4),i=o(7).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 t=Math.pow(2,-52),r=Math.max(this.m,this.n)*this.s[0]*t,o=0,n=this.s,e=0,i=n.length;i>e;e++)n[e]>r&&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(t){var r,o=t,n=this.threshold,i=this.s.length,s=e.zeros(i,i);for(r=0;i>r;r++)Math.abs(this.s[r])<=n?s[r][r]=0:s[r][r]=1/this.s[r];var a,u,f,h=this.V.mmul(s),c=this.V.rows,l=this.U.rows,m=e.zeros(c,l);for(r=0;c>r;r++)for(a=0;l>a;a++){for(f=0,u=0;i>u;u++)f+=h[r][u]*this.U[a][u];m[r][a]=f}return m.mmul(o)},solveForDiagonal:function(t){return this.solve(e.diag(t))},inverse:function(){var t,r,o=this.threshold,n=this.V.rows,i=this.V.columns,s=new e(n,this.s.length);for(t=0;n>t;t++)for(r=0;i>r;r++)Math.abs(this.s[r])>o?s[t][r]=this.V[t][r]/this.s[r]:s[t][r]=0;var a,u,f=this.U.rows,h=this.U.columns,c=new e(n,f);for(t=0;n>t;t++)for(r=0;f>r;r++){for(u=0,a=0;h>a;a++)u+=s[t][a]*this.U[r][a];c[t][r]=u}return c}},t.exports=n},function(t,r){"use strict";r.hypotenuse=function(t,r){var o;return Math.abs(t)>Math.abs(r)?(o=r/t,Math.abs(t)*Math.sqrt(1+o*o)):0!==r?(o=t/r,Math.abs(r)*Math.sqrt(1+o*o)):0}},function(t,r,o){"use strict";function n(t){if(!(this instanceof n))return new n(t);if(t=f.checkMatrix(t),!t.isSquare())throw new Error("Matrix is not a square matrix");var r,o,u=t.columns,h=f.zeros(u,u),c=new Array(u),l=new Array(u),m=t;if(t.isSymmetric()){for(r=0;u>r;r++)for(o=0;u>o;o++)h[r][o]=m[r][o];e(u,l,c,h),i(u,l,c,h)}else{var p=f.zeros(u,u),w=new Array(u);for(o=0;u>o;o++)for(r=0;u>r;r++)p[r][o]=m[r][o];s(u,p,w,h),a(u,l,c,h,p)}this.n=u,this.e=l,this.d=c,this.V=h}function e(t,r,o,n){var e,i,s,a,u,f,h,c;for(u=0;t>u;u++)o[u]=n[t-1][u];for(a=t-1;a>0;a--){for(c=0,s=0,f=0;a>f;f++)c+=Math.abs(o[f]);if(0===c)for(r[a]=o[a-1],u=0;a>u;u++)o[u]=n[a-1][u],n[a][u]=0,n[u][a]=0;else{for(f=0;a>f;f++)o[f]/=c,s+=o[f]*o[f];for(e=o[a-1],i=Math.sqrt(s),e>0&&(i=-i),r[a]=c*i,s-=e*i,o[a-1]=e-i,u=0;a>u;u++)r[u]=0;for(u=0;a>u;u++){for(e=o[u],n[u][a]=e,i=r[u]+n[u][u]*e,f=u+1;a-1>=f;f++)i+=n[f][u]*o[f],r[f]+=n[f][u]*e;r[u]=i}for(e=0,u=0;a>u;u++)r[u]/=s,e+=r[u]*o[u];for(h=e/(s+s),u=0;a>u;u++)r[u]-=h*o[u];for(u=0;a>u;u++){for(e=o[u],i=r[u],f=u;a-1>=f;f++)n[f][u]-=e*r[f]+i*o[f];o[u]=n[a-1][u],n[a][u]=0}}o[a]=s}for(a=0;t-1>a;a++){if(n[t-1][a]=n[a][a],n[a][a]=1,s=o[a+1],0!==s){for(f=0;a>=f;f++)o[f]=n[f][a+1]/s;for(u=0;a>=u;u++){for(i=0,f=0;a>=f;f++)i+=n[f][a+1]*n[f][u];for(f=0;a>=f;f++)n[f][u]-=i*o[f]}}for(f=0;a>=f;f++)n[f][a+1]=0}for(u=0;t>u;u++)o[u]=n[t-1][u],n[t-1][u]=0;n[t-1][t-1]=1,r[0]=0}function i(t,r,o,n){var e,i,s,a,u,f,c,l,m,p,w,v,y,b,d,M,g;for(s=1;t>s;s++)r[s-1]=r[s];r[t-1]=0;var x=0,R=0,k=Math.pow(2,-52);for(f=0;t>f;f++){for(R=Math.max(R,Math.abs(o[f])+Math.abs(r[f])),c=f;t>c&&!(Math.abs(r[c])<=k*R);)c++;if(c>f){g=0;do{for(g+=1,e=o[f],l=(o[f+1]-e)/(2*r[f]),m=h(l,1),0>l&&(m=-m),o[f]=r[f]/(l+m),o[f+1]=r[f]*(l+m),p=o[f+1],i=e-o[f],s=f+2;t>s;s++)o[s]-=i;for(x+=i,l=o[c],w=1,v=w,y=w,b=r[f+1],d=0,M=0,s=c-1;s>=f;s--)for(y=v,v=w,M=d,e=w*r[s],i=w*l,m=h(l,r[s]),r[s+1]=d*m,d=r[s]/m,w=l/m,l=w*o[s]-d*e,o[s+1]=i+d*(w*e+d*o[s]),u=0;t>u;u++)i=n[u][s+1],n[u][s+1]=d*n[u][s]+w*i,n[u][s]=w*n[u][s]-d*i;l=-d*M*y*b*r[f]/p,r[f]=d*l,o[f]=w*l}while(Math.abs(r[f])>k*R)}o[f]=o[f]+x,r[f]=0}for(s=0;t-1>s;s++){for(u=s,l=o[s],a=s+1;t>a;a++)o[a]<l&&(u=a,l=o[a]);if(u!==s)for(o[u]=o[s],o[s]=l,a=0;t>a;a++)l=n[a][s],n[a][s]=n[a][u],n[a][u]=l}}function s(t,r,o,n){var e,i,s,a,u,f,h,c=0,l=t-1;for(f=c+1;l-1>=f;f++){for(h=0,a=f;l>=a;a++)h+=Math.abs(r[a][f-1]);if(0!==h){for(s=0,a=l;a>=f;a--)o[a]=r[a][f-1]/h,s+=o[a]*o[a];for(i=Math.sqrt(s),o[f]>0&&(i=-i),s-=o[f]*i,o[f]=o[f]-i,u=f;t>u;u++){for(e=0,a=l;a>=f;a--)e+=o[a]*r[a][u];for(e/=s,a=f;l>=a;a++)r[a][u]-=e*o[a]}for(a=0;l>=a;a++){for(e=0,u=l;u>=f;u--)e+=o[u]*r[a][u];for(e/=s,u=f;l>=u;u++)r[a][u]-=e*o[u]}o[f]=h*o[f],r[f][f-1]=h*i}}for(a=0;t>a;a++)for(u=0;t>u;u++)n[a][u]=a===u?1:0;for(f=l-1;f>=c+1;f--)if(0!==r[f][f-1]){for(a=f+1;l>=a;a++)o[a]=r[a][f-1];for(u=f;l>=u;u++){for(i=0,a=f;l>=a;a++)i+=o[a]*n[a][u];for(i=i/o[f]/r[f][f-1],a=f;l>=a;a++)n[a][u]+=i*o[a]}}}function a(t,r,o,n,e){var i,s,a,f,h,c,l,m,p,w,v,y,b,d,M,g=t-1,x=0,R=t-1,k=Math.pow(2,-52),j=0,A=0,z=0,C=0,V=0,E=0,q=0,I=0;for(i=0;t>i;i++)for((x>i||i>R)&&(o[i]=e[i][i],r[i]=0),s=Math.max(i-1,0);t>s;s++)A+=Math.abs(e[i][s]);for(;g>=x;){for(f=g;f>x&&(E=Math.abs(e[f-1][f-1])+Math.abs(e[f][f]),0===E&&(E=A),!(Math.abs(e[f][f-1])<k*E));)f--;if(f===g)e[g][g]=e[g][g]+j,o[g]=e[g][g],r[g]=0,g--,I=0;else if(f===g-1){if(l=e[g][g-1]*e[g-1][g],z=(e[g-1][g-1]-e[g][g])/2,C=z*z+l,q=Math.sqrt(Math.abs(C)),e[g][g]=e[g][g]+j,e[g-1][g-1]=e[g-1][g-1]+j,m=e[g][g],C>=0){for(q=z>=0?z+q:z-q,o[g-1]=m+q,o[g]=o[g-1],0!==q&&(o[g]=m-l/q),r[g-1]=0,r[g]=0,m=e[g][g-1],E=Math.abs(m)+Math.abs(q),z=m/E,C=q/E,V=Math.sqrt(z*z+C*C),z/=V,C/=V,s=g-1;t>s;s++)q=e[g-1][s],e[g-1][s]=C*q+z*e[g][s],e[g][s]=C*e[g][s]-z*q;for(i=0;g>=i;i++)q=e[i][g-1],e[i][g-1]=C*q+z*e[i][g],e[i][g]=C*e[i][g]-z*q;for(i=x;R>=i;i++)q=n[i][g-1],n[i][g-1]=C*q+z*n[i][g],n[i][g]=C*n[i][g]-z*q}else o[g-1]=m+z,o[g]=m+z,r[g-1]=q,r[g]=-q;g-=2,I=0}else{if(m=e[g][g],p=0,l=0,g>f&&(p=e[g-1][g-1],l=e[g][g-1]*e[g-1][g]),10===I){for(j+=m,i=x;g>=i;i++)e[i][i]-=m;E=Math.abs(e[g][g-1])+Math.abs(e[g-1][g-2]),m=p=.75*E,l=-.4375*E*E}if(30===I&&(E=(p-m)/2,E=E*E+l,E>0)){for(E=Math.sqrt(E),m>p&&(E=-E),E=m-l/((p-m)/2+E), | ||
i=x;g>=i;i++)e[i][i]-=E;j+=E,m=p=l=.964}for(I+=1,h=g-2;h>=f&&(q=e[h][h],V=m-q,E=p-q,z=(V*E-l)/e[h+1][h]+e[h][h+1],C=e[h+1][h+1]-q-V-E,V=e[h+2][h+1],E=Math.abs(z)+Math.abs(C)+Math.abs(V),z/=E,C/=E,V/=E,h!==f)&&!(Math.abs(e[h][h-1])*(Math.abs(C)+Math.abs(V))<k*(Math.abs(z)*(Math.abs(e[h-1][h-1])+Math.abs(q)+Math.abs(e[h+1][h+1]))));)h--;for(i=h+2;g>=i;i++)e[i][i-2]=0,i>h+2&&(e[i][i-3]=0);for(a=h;g-1>=a&&(d=a!==g-1,a!==h&&(z=e[a][a-1],C=e[a+1][a-1],V=d?e[a+2][a-1]:0,m=Math.abs(z)+Math.abs(C)+Math.abs(V),0!==m&&(z/=m,C/=m,V/=m)),0!==m);a++)if(E=Math.sqrt(z*z+C*C+V*V),0>z&&(E=-E),0!==E){for(a!==h?e[a][a-1]=-E*m:f!==h&&(e[a][a-1]=-e[a][a-1]),z+=E,m=z/E,p=C/E,q=V/E,C/=z,V/=z,s=a;t>s;s++)z=e[a][s]+C*e[a+1][s],d&&(z+=V*e[a+2][s],e[a+2][s]=e[a+2][s]-z*q),e[a][s]=e[a][s]-z*m,e[a+1][s]=e[a+1][s]-z*p;for(i=0;i<=Math.min(g,a+3);i++)z=m*e[i][a]+p*e[i][a+1],d&&(z+=q*e[i][a+2],e[i][a+2]=e[i][a+2]-z*V),e[i][a]=e[i][a]-z,e[i][a+1]=e[i][a+1]-z*C;for(i=x;R>=i;i++)z=m*n[i][a]+p*n[i][a+1],d&&(z+=q*n[i][a+2],n[i][a+2]=n[i][a+2]-z*V),n[i][a]=n[i][a]-z,n[i][a+1]=n[i][a+1]-z*C}}}if(0!==A){for(g=t-1;g>=0;g--)if(z=o[g],C=r[g],0===C)for(f=g,e[g][g]=1,i=g-1;i>=0;i--){for(l=e[i][i]-z,V=0,s=f;g>=s;s++)V+=e[i][s]*e[s][g];if(r[i]<0)q=l,E=V;else if(f=i,0===r[i]?e[i][g]=0!==l?-V/l:-V/(k*A):(m=e[i][i+1],p=e[i+1][i],C=(o[i]-z)*(o[i]-z)+r[i]*r[i],c=(m*E-q*V)/C,e[i][g]=c,e[i+1][g]=Math.abs(m)>Math.abs(q)?(-V-l*c)/m:(-E-p*c)/q),c=Math.abs(e[i][g]),k*c*c>1)for(s=i;g>=s;s++)e[s][g]=e[s][g]/c}else if(0>C)for(f=g-1,Math.abs(e[g][g-1])>Math.abs(e[g-1][g])?(e[g-1][g-1]=C/e[g][g-1],e[g-1][g]=-(e[g][g]-z)/e[g][g-1]):(M=u(0,-e[g-1][g],e[g-1][g-1]-z,C),e[g-1][g-1]=M[0],e[g-1][g]=M[1]),e[g][g-1]=0,e[g][g]=1,i=g-2;i>=0;i--){for(w=0,v=0,s=f;g>=s;s++)w+=e[i][s]*e[s][g-1],v+=e[i][s]*e[s][g];if(l=e[i][i]-z,r[i]<0)q=l,V=w,E=v;else if(f=i,0===r[i]?(M=u(-w,-v,l,C),e[i][g-1]=M[0],e[i][g]=M[1]):(m=e[i][i+1],p=e[i+1][i],y=(o[i]-z)*(o[i]-z)+r[i]*r[i]-C*C,b=2*(o[i]-z)*C,0===y&&0===b&&(y=k*A*(Math.abs(l)+Math.abs(C)+Math.abs(m)+Math.abs(p)+Math.abs(q))),M=u(m*V-q*w+C*v,m*E-q*v-C*w,y,b),e[i][g-1]=M[0],e[i][g]=M[1],Math.abs(m)>Math.abs(q)+Math.abs(C)?(e[i+1][g-1]=(-w-l*e[i][g-1]+C*e[i][g])/m,e[i+1][g]=(-v-l*e[i][g]-C*e[i][g-1])/m):(M=u(-V-p*e[i][g-1],-E-p*e[i][g],q,C),e[i+1][g-1]=M[0],e[i+1][g]=M[1])),c=Math.max(Math.abs(e[i][g-1]),Math.abs(e[i][g])),k*c*c>1)for(s=i;g>=s;s++)e[s][g-1]=e[s][g-1]/c,e[s][g]=e[s][g]/c}for(i=0;t>i;i++)if(x>i||i>R)for(s=i;t>s;s++)n[i][s]=e[i][s];for(s=t-1;s>=x;s--)for(i=x;R>=i;i++){for(q=0,a=x;a<=Math.min(s,R);a++)q+=n[i][a]*e[a][s];n[i][s]=q}}}function u(t,r,o,n){var e,i;return Math.abs(o)>Math.abs(n)?(e=n/o,i=o+e*n,[(t+e*r)/i,(r-e*t)/i]):(e=o/n,i=n+e*o,[(e*t+r)/i,(e*r-t)/i])}var f=o(4),h=o(7).hypotenuse;n.prototype={get realEigenvalues(){return this.d},get imaginaryEigenvalues(){return this.e},get eigenvectorMatrix(){return this.V},get diagonalMatrix(){var t,r,o=this.n,n=this.e,e=this.d,i=new f(o,o);for(t=0;o>t;t++){for(r=0;o>r;r++)i[t][r]=0;i[t][t]=e[t],n[t]>0?i[t][t+1]=n[t]:n[t]<0&&(i[t][t-1]=n[t])}return i}},t.exports=n},function(t,r,o){"use strict";function n(t){if(!(this instanceof n))return new n(t);t=e.checkMatrix(t);var r,o,i,s,a,u,f,h,c,l,m=t.clone(),p=m.rows,w=m.columns,v=new Array(p),y=1;for(r=0;p>r;r++)v[r]=r;for(c=new Array(p),o=0;w>o;o++){for(r=0;p>r;r++)c[r]=m[r][o];for(r=0;p>r;r++){for(h=m[r],l=Math.min(r,o),a=0,i=0;l>i;i++)a+=h[i]*c[i];h[o]=c[r]-=a}for(s=o,r=o+1;p>r;r++)Math.abs(c[r])>Math.abs(c[s])&&(s=r);if(s!==o){for(i=0;w>i;i++)u=m[s][i],m[s][i]=m[o][i],m[o][i]=u;f=v[s],v[s]=v[o],v[o]=f,y=-y}if(p>o&&0!==m[o][o])for(r=o+1;p>r;r++)m[r][o]/=m[o][o]}this.LU=m,this.pivotVector=v,this.pivotSign=y}var e=o(4);n.prototype={isSingular:function(){for(var t=this.LU,r=t.columns,o=0;r>o;o++)if(0===t[o][o])return!0;return!1},get determinant(){var t=this.LU;if(!t.isSquare())throw new Error("Matrix must be square");for(var r=this.pivotSign,o=t.columns,n=0;o>n;n++)r*=t[n][n];return r},get lowerTriangularFactor(){for(var t=this.LU,r=t.rows,o=t.columns,n=new e(r,o),i=0;r>i;i++)for(var s=0;o>s;s++)i>s?n[i][s]=t[i][s]:i===s?n[i][s]=1:n[i][s]=0;return n},get upperTriangularFactor(){for(var t=this.LU,r=t.rows,o=t.columns,n=new e(r,o),i=0;r>i;i++)for(var s=0;o>s;s++)s>=i?n[i][s]=t[i][s]:n[i][s]=0;return n},get pivotPermutationVector(){return this.pivotVector.slice()},solve:function(t){t=e.checkMatrix(t);var r=this.LU,o=r.rows;if(o!==t.rows)throw new Error("Invalid matrix dimensions");if(this.isSingular())throw new Error("LU matrix is singular");var n,i,s,a=t.columns,u=t.subMatrixRow(this.pivotVector,0,a-1),f=r.columns;for(s=0;f>s;s++)for(n=s+1;f>n;n++)for(i=0;a>i;i++)u[n][i]-=u[s][i]*r[n][s];for(s=f-1;s>=0;s--){for(i=0;a>i;i++)u[s][i]/=r[s][s];for(n=0;s>n;n++)for(i=0;a>i;i++)u[n][i]-=u[s][i]*r[n][s]}return u}},t.exports=n},function(t,r,o){"use strict";function n(t){if(!(this instanceof n))return new n(t);t=e.checkMatrix(t);var r,o,s,a,u=t.clone(),f=t.rows,h=t.columns,c=new Array(h);for(s=0;h>s;s++){var l=0;for(r=s;f>r;r++)l=i(l,u[r][s]);if(0!==l){for(u[s][s]<0&&(l=-l),r=s;f>r;r++)u[r][s]/=l;for(u[s][s]+=1,o=s+1;h>o;o++){for(a=0,r=s;f>r;r++)a+=u[r][s]*u[r][o];for(a=-a/u[s][s],r=s;f>r;r++)u[r][o]+=a*u[r][s]}}c[s]=-l}this.QR=u,this.Rdiag=c}var e=o(4),i=o(7).hypotenuse;n.prototype={solve:function(t){t=e.checkMatrix(t);var r=this.QR,o=r.rows;if(t.rows!==o)throw new Error("Matrix row dimensions must agree");if(!this.isFullRank())throw new Error("Matrix is rank deficient");var n,i,s,a,u=t.columns,f=t.clone(),h=r.columns;for(s=0;h>s;s++)for(i=0;u>i;i++){for(a=0,n=s;o>n;n++)a+=r[n][s]*f[n][i];for(a=-a/r[s][s],n=s;o>n;n++)f[n][i]+=a*r[n][s]}for(s=h-1;s>=0;s--){for(i=0;u>i;i++)f[s][i]/=this.Rdiag[s];for(n=0;s>n;n++)for(i=0;u>i;i++)f[n][i]-=f[s][i]*r[n][s]}return f.subMatrix(0,h-1,0,u-1)},isFullRank:function(){for(var t=this.QR.columns,r=0;t>r;r++)if(0===this.Rdiag[r])return!1;return!0},get upperTriangularFactor(){var t,r,o=this.QR,n=o.columns,i=new e(n,n);for(t=0;n>t;t++)for(r=0;n>r;r++)r>t?i[t][r]=o[t][r]:t===r?i[t][r]=this.Rdiag[t]:i[t][r]=0;return i},get orthogonalFactor(){var t,r,o,n,i=this.QR,s=i.rows,a=i.columns,u=new e(s,a);for(o=a-1;o>=0;o--){for(t=0;s>t;t++)u[t][o]=0;for(u[o][o]=1,r=o;a>r;r++)if(0!==i[o][o]){for(n=0,t=o;s>t;t++)n+=i[t][o]*u[t][r];for(n=-n/i[o][o],t=o;s>t;t++)u[t][r]+=n*i[t][o]}}return u}},t.exports=n},function(t,r,o){"use strict";function n(t){if(!(this instanceof n))return new n(t);if(t=e.checkMatrix(t),!t.isSymmetric())throw new Error("Matrix is not symmetric");var r,o,i,s=t,a=s.rows,u=new e(a,a),f=!0;for(o=0;a>o;o++){var h=u[o],c=0;for(i=0;o>i;i++){var l=u[i],m=0;for(r=0;i>r;r++)m+=l[r]*h[r];h[i]=m=(s[o][i]-m)/u[i][i],c+=m*m}for(c=s[o][o]-c,f&=c>0,u[o][o]=Math.sqrt(Math.max(c,0)),i=o+1;a>i;i++)u[o][i]=0}if(!f)throw new Error("Matrix is not positive definite");this.L=u}var e=o(4);n.prototype={get leftTriangularFactor(){return this.L},solve:function(t){t=e.checkMatrix(t);var r=this.L,o=r.rows;if(t.rows!==o)throw new Error("Matrix dimensions do not match");var n,i,s,a=t.columns,u=t.clone();for(s=0;o>s;s++)for(i=0;a>i;i++){for(n=0;s>n;n++)u[s][i]-=u[n][i]*r[s][n];u[s][i]/=r[s][s]}for(s=o-1;s>=0;s--)for(i=0;a>i;i++){for(n=s+1;o>n;n++)u[s][i]-=u[n][i]*r[n][s];u[s][i]/=r[s][s]}return u}},t.exports=n},function(t,r,o){"use strict";function n(t,r){return new R(t,r)}function e(t,r){return R.ones(t,r)}function i(t,r){return R.eye(t,r)}function s(t,r){return R.zeros(t,r)}function a(t,r){return R.rand(t,r)}function u(t){if("number"==typeof t)return t;var r=t.clone();return r.transpose()}function f(t,r){if("number"==typeof t&&"number"==typeof r)return t+r;if("number"==typeof t)return this.add(r,t);var o=t.clone();return o.add(r)}function h(t,r){if("number"==typeof t&&"number"==typeof r)return t-r;if("number"==typeof t)return this.subtract(r,t);var o=t.clone();return o.sub(r)}function c(t,r){if("number"==typeof t&&"number"==typeof r)return t*r;if("number"==typeof t)return this.multiply(r,t);var o=t.clone();return"number"==typeof r?o.mul(r):o=o.mmul(r),1==o.rows&&1==o.columns?o[0][0]:o}function l(t,r){var o=t.clone();return o.mul(r)}function m(t,r){var o=t.clone();return o.div(r)}function p(t){var r,o,n=null,e=t.rows,i=t.columns;if("undefined"==typeof i&&"object"==typeof t)if(t[0]&&t[0].length)for(e=t.length,i=t[0].length,o=Math.min(e,i),n=R.zeros(i,i),r=0;i>r;r++)n[r][r]=t[r][r];else for(i=t.length,n=R.zeros(i,i),r=0;i>r;r++)n[r][r]=t[r];if(1==e)for(n=R.zeros(i,i),r=0;i>r;r++)n[r][r]=t[0][r];else if(e>0&&i>0)for(o=Math.min(e,i),n=new Array(o),r=0;o>r;r++)n[r]=t[r][r];return n}function w(t,r){if("number"==typeof t&&"number"==typeof r)return Math.min(t,r);for(var o=t.rows,n=t.columns,e=new R(o,n),i=0;o>i;i++)for(var s=0;n>s;s++)t[i][s]<r[i][s]?e[i][s]=t[i][s]:e[i][s]=r[i][s];return e}function v(t,r){if("number"==typeof t&&"number"==typeof r)return Math.max(t,r);for(var o=t.rows,n=t.columns,e=new R(o,n),i=0;o>i;i++)for(var s=0;n>s;s++)t[i][s]>r[i][s]?e[i][s]=t[i][s]:e[i][s]=r[i][s];return e}function y(t){if("number"==typeof t)return Math.sqrt(t);for(var r=t.rows,o=t.columns,n=new R(r,o),e=0;r>e;e++)for(var i=0;o>i;i++)n[e][i]=Math.sqrt(t[e][i]);return n}function b(t){if("number"==typeof t)return Math.abs(t);for(var r=t.rows,o=t.columns,n=new R(r,o),e=0;r>e;e++)for(var i=0;o>i;i++)n[e][i]=Math.abs(t[e][i]);return n}function d(t){if("number"==typeof t)return Math.sqrt(t);for(var r=t.rows,o=t.columns,n=new R(r,o),e=0;r>e;e++)for(var i=0;o>i;i++)n[e][i]=Math.exp(t[e][i]);return n}function M(t,r){if("number"==typeof t)return Math.pow(t,r);for(var o=t.rows,n=t.columns,e=new R(o,n),i=0;o>i;i++)for(var s=0;n>s;s++)e[i][s]=Math.pow(t[i][s],r);return e}function g(t,r){return t.solve(r)}function x(t){return"number"==typeof t?1/t:t.inverse()}var R=o(3);t.exports={transpose:u,add:f,subtract:h,multiply:c,dotMultiply:l,dotDivide:m,diag:p,min:w,max:v,solve:g,inv:x,sqrt:y,exp:d,dotPow:M,abs:b,matrix:n,ones:e,zeros:s,random:a,eye:i}}])}); | ||
!function(t,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports.mlOptimizeLorentzian=r():t.mlOptimizeLorentzian=r()}(this,function(){return function(t){function r(n){if(o[n])return o[n].exports;var e=o[n]={exports:{},id:n,loaded:!1};return t[n].call(e.exports,e,e.exports,r),e.loaded=!0,e.exports}var o={};return r.m=t,r.c=o,r.p="",r(0)}([function(t,r,o){"use strict";function n(t,r,o){var n,e,i,s,a=r.length/3,u=t.rows,h=w.zeros(t.length,1);for(e=0;a>e;e++)for(s=Math.pow(r[e+2*a][0]/2,2),n=r[e+a][0]*s,i=0;u>i;i++)h[i][0]+=n/(Math.pow(t[i][0]-r[e][0],2)+s);return h}function e(t,r,o){for(var n=r[1][0]*Math.pow(r[2][0]/2,2),e=t.rows,i=new w(t.rows,t.columns),s=0;e>s;s++)i[s][0]=n/(Math.pow(t[s][0]-r[0][0],2)+Math.pow(r[2][0]/2,2));return i}function i(t,r,o){for(var n=r[2][0]*r[2][0]/2,e=t.rows,i=new w(t.rows,t.columns),s=0;e>s;s++)i[s][0]=r[1][0]*Math.exp(-(t[s][0]-r[0][0])*(t[s][0]-r[0][0])/n);return i}function s(t,r,o){o=o||{};var n=l(t,o.percentage||0);if(null===n||n[0].rows<3)return null;var i=n[0],s=n[1],a=n[2],u=i.rows,h=[u/Math.sqrt(s.dot(s))],o=Object.create(o.LMOptions||[3,100,.001,.001,.001,.01,.01,11,9,1]),f=[],c=Math.abs(i[0][0]-i[1][0]),m=new w([[-c/1e4],[-.001],[-c/1e4]]),v=new w([[r.x],[1],[r.width]]),y=new w([[r.x-c],[.75],[r.width/4]]),d=new w([[r.x+c],[1.25],[4*r.width]]),b=p.optimize(e,v,i,s,h,m,y,d,f,o);return b=b.p,[b[0],[b[1][0]*a],b[2]]}function a(t,r,o){o=o||{};var n=l(t,o.percentage||0);if(null===n||n[0].rows<3)return null;var e=n[0],s=n[1],a=n[2],u=e.rows,h=[u/Math.sqrt(s.dot(s))],o=Object.create(o.LMOptions||[3,100,.001,.001,.001,.01,.01,11,9,1]),f=[],c=Math.abs(e[0][0]-e[1][0]),m=new w([[-c/1e4],[-.001],[-c/1e4]]),m=new w([[-Math.abs(e[0][0]-e[1][0])/1e3],[-.001],[-r.width/1e3]]),v=new w([[r.x],[1],[r.width]]),y=new w([[r.x-c],[.75],[r.width/4]]),d=new w([[r.x+c],[1.25],[4*r.width]]),b=p.optimize(i,v,e,s,h,m,y,d,f,o);return b=b.p,[b[0],[b[1][0]*a],b[2]]}function u(t,r,o){var n=l(t);if(null===n||n[0].rows<3)return null;for(var e,i,a,u,h,f=n[0],c=n[1],u=n[2],p=0,m=f.length,w=[],v=0;v<r.length;v++){for(e=r[v].x-2*r[v].width;f[p++]<e&&m>p;);for(e=r[v].x+2*r[v].width,i=[],a=[];f[p]<=e&&m>p;)i.push(f[p][0]),a.push(c[p][0]*u),p++;h=s([i,a],r[v],o),h?w.push({x:h[0][0],y:h[1][0],width:h[2][0],opt:!0}):w.push({x:r[v].x,y:r[v].y,width:r[v].width,opt:!1})}return w}function h(t,r,o){var n=l(t);if(null===n||n[0].rows<3)return null;for(var e,i,s,u,h,f=n[0],c=n[1],u=n[2],p=0,m=f.length,w=[],v=0;v<r.length;v++){for(e=r[v].x-2*r[v].width;f[p++]<e&&m>p;);for(e=r[v].x+2*r[v].width,i=[],s=[];f[p]<=e&&m>p;)i.push(f[p][0]),s.push(c[p][0]*u),p++;h=a([i,s],r[v],o),h?w.push({x:h[0][0],y:h[1][0],width:h[2][0],opt:!0}):w.push({x:r[v].x,y:r[v].y,width:r[v].width,opt:!1})}return w}function f(t,r,o){var e=l(t);if(null===e||e[0].rows<3)return null;var i,s=e[0],a=e[1],u=e[2],h=s.rows,f=[h/m.sqrt(a.dot(a))],o=Object.create(o||[3,100,.001,.001,.001,.01,.01,11,9,1]),c=[],v=r.length,y=new w(3*v,1),d=new w(3*v,1),b=new w(3*v,1),M=new w(3*v,1),x=Math.abs(s[0][0]-s[1][0]);for(i=0;v>i;i++)y[i][0]=r[i].x,y[i+v][0]=1,y[i+2*v][0]=r[i].width,d[i][0]=r[i].x-x,d[i+v][0]=0,d[i+2*v][0]=r[i].width/4,b[i][0]=r[i].x+x,b[i+v][0]=1.5,b[i+2*v][0]=4*r[i].width,M[i][0]=-x/1e3,M[i+v][0]=-.001,M[i+2*v][0]=-x/1e3;var M=-Math.abs(s[0][0]-s[1][0])/1e4,g=p.optimize(n,y,s,a,f,M,d,b,c,o);g=g.p;var R=new Array(v);for(i=0;v>i;i++)R[i]=[g[i],[g[i+v][0]*u],g[i+2*v]];return R}function c(t,r,o){var e=l(t);if(null===e||e[0].rows<3)return null;var i,s=e[0],a=e[1],u=e[2],h=s.rows,f=new w(h,1),c=h/m.sqrt(a.dot(a));for(i=0;h>i;i++)f[i][0]=c;var o=Object.create(o||[3,100,.001,.001,.001,.01,.01,11,9,2]),v=[],y=r.length,d=new w(3*y,1),b=new w(3*y,1),M=new w(3*y,1),x=new w(3*y,1),g=Math.abs(s[0][0]-s[1][0]);for(i=0;y>i;i++)d[i][0]=r[i].x,d[i+y][0]=r[i].y/u,d[i+2*y][0]=r[i].width,b[i][0]=r[i].x-g,b[i+y][0]=.8*r[i].y/u,b[i+2*y][0]=r[i].width/2,M[i][0]=r[i].x+g,M[i+y][0]=1.2*r[i].y/u,M[i+2*y][0]=2*r[i].width,x[i][0]=-g/1e3,x[i+y][0]=-.001,x[i+2*y][0]=-g/1e3;var R=p.optimize(n,d,s,a,f,x,b,M,v,o);R=R.p;var k=new Array(y);for(i=0;y>i;i++)k[i]=[R[i],[R[i+y][0]*u],R[i+2*y]];return k}function l(t,r){var o,n,e,i=t.length,s=null,a=null,u=0;if(2==i){var h=t[0].length;if(s=new Array(h),a=new Array(h),o=t[0],n=t[1],"number"==typeof o[0])for(e=0;h>e;e++)s[e]=o[e],a[e]=n[e],n[e]>u&&(u=n[e]);else if("object"==typeof o[0])for(e=0;h>e;e++)s[e]=o[e][0],a[e]=n[e][0],n[e][0]>u&&(u=n[e][0])}else{var h=i;for(s=new Array(h),a=new Array(h),e=0;h>e;e++)s[e]=t[e][0],a[e]=t[e][1],a[e]>u&&(u=a[e])}for(e=0;h>e;e++)a[e]/=u;if(r)for(e=h-1;e>=0;e--)a[e]<r&&(a.splice(e,1),s.splice(e,1));return s.length>0?[new w([s]).transpose(),new w([a]).transpose(),u]:null}var p=o(1),m=p.Matrix.algebra,w=o(3);t.exports.optimizeSingleLorentzian=s,t.exports.optimizeLorentzianSum=f,t.exports.optimizeSingleGaussian=a,t.exports.optimizeGaussianSum=c,t.exports.singleGaussian=i,t.exports.singleLorentzian=e,t.exports.optimizeGaussianTrain=h,t.exports.optimizeLorentzianTrain=u},function(t,r,o){"use strict";t.exports=o(2),t.exports.Matrix=o(3),t.exports.Matrix.algebra=o(12)},function(t,r,o){var n=o(3),e=o(12),i={optimize:function(t,r,o,i,s,a,u,h,f,c){var l=0,p=0;if("object"!=typeof r[0])for(var m=0;m<r.length;m++)r[m]=[r[m]];var m,w,v=-50,y=r.length,d=i.length,b=n.zeros(y,1),M=n.zeros(d,1),x=.01/v,g=.01/v,R=n.zeros(d,y);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 x=0;if(!l)return}s=s||Math.sqrt((d-y+1)/e.multiply(e.transpose(i),i)),a=a||.001,u=u||e.multiply(Math.abs(r),-100),h=h||e.multiply(Math.abs(r),100),f=f||1,c=c||[3,10*y,.001,.001,.001,.01,.01,11,9,1];var k=c[0],A=c[1],j=c[2],z=(c[3],c[4],c[5]),C=c[6],V=c[7],E=c[8],q=c[9];if(l&&3==k&&(k=2),!a.length||1==a.length){for(var I=new Array(y),m=0;y>m;m++)I[m]=[a];a=I}var D=[];for(m=0;m<a.length;m++)0!=a[m][0]&&D.push(m);var O=D.length,S=!1,_=null;if(!s.length||s.length<d){var J=e.multiply(n.ones(d,1),s[0]);_=e.dotMultiply(J,J)}else _=e.dotMultiply(s,s);var L=this.lm_matx(t,o,b,M,1,R,r,i,_,a,f),U=L.JtWJ,T=L.JtWdy,x=L.Chi_sq,W=L.y_hat,R=L.J;switch(Math.max(Math.abs(T))<j&&(console.log(" *** Your Initial Guess is Extremely Close to Optimal ***"),console.log(" *** epsilon_1 = ",j),S=!0),q){case 1:lambda=C;break;default:lambda=C*Math.max(e.diag(U)),nu=2}g=x;for(var Q=null;!S&&A>=p;){switch(p+=1,q){case 1:Q=e.solve(e.add(U,e.multiply(e.diag(e.diag(U)),lambda)),T);break;default:Q=e.solve(e.add(U,e.multiply(n.eye(y),lambda)),T)}var F=new Array(D.length);for(w=0;w<D.length;w++)F[w]=Q[D[w]];var G=e.add(r,F);for(w=0;w<G.length;w++)G[w][0]=Math.min(Math.max(u[w][0],G[w][0]),h[w][0]);var P=e.subtract(i,t(o,G,f)),X=e.multiply(e.transpose(P),e.dotMultiply(P,_));if(2==q){var B=e.multiply(e.transpose(T),Q),H=e.multiply(B,e.inv(e.add(e.multiply(e.subtract(X-x),.5)),e.multiply(B,2)));Q=e.multiply(H,Q);for(var w=0;w<D.length;w++)F[w]=Q[D[w]];G=e.add(r,F),G=e.min(e.max(u,G),h),P=e.subtract(i,t(o,G,f)),X=e.multiply(e.transpose(P),mat.dotMultiply(P,_))}var N=(x-X)/e.multiply(e.multiply(e.transpose(Q),2),e.add(e.multiply(lambda,Q),T));if(N>z)switch(dX2=x-g,g=x,b=r,M=W,r=G,L=this.lm_matx(t,o,b,M,dX2,R,r,i,_,a,f),U=L.JtWJ,T=L.JtWdy,x=L.Chi_sq,W=L.y_hat,R=L.J,q){case 1:lambda=Math.max(lambda/E,1e-7);break;case 2:lambda=Math.max(lambda/(1+H),1e-7);break;case 3:lambda=e.multiply(Math.max(1/3,1-(2*N-1)^3),lambda),nu=2}else switch(x=g,p%(2*y)==0&&(L=this.lm_matx(t,o,b,M,-1,R,r,i,_,a,f),U=L.JtWJ,T=L.JtWdy,dX2=L.Chi_sq,W=L.y_hat,R=L.J),q){case 1:lambda=Math.min(lambda*V,1e7);break;case 2:lambda+=Math.abs((X-x)/2/H);break;case 3:lambda*=nu,nu=2*nu}}return _=e.multiply(e.multiply(e.transpose(P),P),n.ones(d,1)),_.apply(function(t,r){_[t][r]=(d-O+1)/_[t][r]}),L=this.lm_matx(t,o,b,M,-1,R,r,i,_,a,f),U=L.JtWJ,T=L.JtWdy,x=L.Chi_sq,W=L.y_hat,R=L.J,{p:r,X2:x}},lm_FD_J:function(t,r,o,i,s,a){var u=i.length,h=o.length;s=s||e.multiply(n.ones(h,1),.001);for(var f=o.clone(),c=new n(u,h),l=new Array(h),p=0;h>p;p++){if(l[p]=s[p]*(1+Math.abs(o[p][0])),o[p]=[f[p][0]+l[p]],0!=l[p])if(y1=t(r,o,a),s[p][0]<0)for(var m=e.dotDivide(e.subtract(y1,i),l[p]),w=0;u>w;w++)c[w][p]=m[w][0];else{o[p][0]=f[p][0]-l[p];for(var m=e.dotDivide(e.subtract(y1,t(r,o,a)),2*l[p]),w=0;u>w;w++)c[w][p]=m[w][0]}o[p]=f[p]}return c},lm_Broyden_J:function(t,r,o,n,i){var s=e.subtract(n,t),a=e.transpose(s);return a.div(e.multiply(a,s)),o=e.add(o,e.multiply(e.subtract(i,e.add(r,e.multiply(o,s))),a))},lm_matx:function(t,r,o,i,s,a,u,h,f,c,l,p){var m=(h.length,u.length);c=c||.001;var w=t(r,u,l);a=p%(2*m)==0||s>0?this.lm_FD_J(t,r,u,w,c,l):this.lm_Broyden_J(o,i,a,u,w);var v=e.subtract(h,w),y=e.multiply(e.transpose(v),e.dotMultiply(v,f)),d=e.transpose(a),b=e.multiply(d,e.dotMultiply(a,e.multiply(f,n.ones(1,m)))),M=e.multiply(d,e.dotMultiply(f,v));return{JtWJ:b,JtWdy:M,Chi_sq:y,y_hat:w,J:a}}};t.exports=i},function(t,r,o){"use strict";t.exports=o(4),t.exports.Decompositions=t.exports.DC=o(5)},function(t,r){"use strict";function o(t){for(var r=0,o=t.length,n=new Array(o);o>r;r++)n[r]=t[r];return n}function n(t,r){var e,i,s=0;if(Array.isArray(t)){if(i=r,e=i?o(t):t,t=e.length,r=e[0].length,"undefined"==typeof r)throw new TypeError("Data must be a 2D array");if(!(t>0&&r>0))throw new RangeError("Invalid dimensions: "+t+"x"+r);for(;t>s;s++){if(e[s].length!==r)throw new RangeError("Inconsistent array dimensions");i&&(e[s]=o(e[s]))}}else{if("number"!=typeof t)throw new TypeError("Invalid arguments");if(!(t>0&&r>0))throw new RangeError("Invalid dimensions: "+t+"x"+r);for(e=new Array(t);t>s;s++)e[s]=new Array(r)}return Object.defineProperty(e,"rows",{writable:!0,value:t}),Object.defineProperty(e,"columns",{writable:!0,value:r}),e.__proto__=n.prototype,e}var e=Array.prototype.splice,i=Array.prototype.concat;n.from1DArray=function(t,r,o){var e,i,s=0;if(e=t*r,e!==o.length)throw new RangeError("Data length does not match given dimensions");for(i=new Array(t);t>s;s++)i[s]=o.slice(s*r,(s+1)*r);return new n(i)},n.rowVector=function(t){return new n([t])},n.columnVector=function(t){for(var r=t.length,o=new Array(r),e=0;r>e;e++)o[e]=[t[e]];return new n(o)},n.empty=function(t,r){return new n(t,r)},n.zeros=function(t,r){return n.empty(t,r).fill(0)},n.ones=function(t,r){return n.empty(t,r).fill(1)},n.rand=function(t,r){for(var o=n.empty(t,r),e=0,i=o.rows;i>e;e++)for(var s=0,a=o.columns;a>s;s++)o[e][s]=Math.random();return o},n.eye=function(t){for(var r=n.zeros(t,t),o=r.rows,e=0;o>e;e++)r[e][e]=1;return r},n.diag=function(t){for(var r=t.length,o=n.zeros(r,r),e=0;r>e;e++)o[e][e]=t[e];return o},n.indices=function(t,r){for(var o=new Array(r-t),n=0;n<o.length;n++)o[n]=t++;return o},n.stack=function(t){var r,o,e;if(n.isMatrix(t)){var i=0,s=0;for(r=0;r<arguments.length;r++)i+=arguments[r].rows,arguments[r].columns>s&&(s=arguments[r].columns);var a=n.zeros(i,s),u=0;for(r=0;r<arguments.length;r++){var h=arguments[r];for(o=0;o<h.rows;o++){for(e=0;e<h.columns;e++)a[u][e]=h[o][e];u++}}return a}if(Array.isArray(t)){var f=n.empty(arguments.length,t.length);for(r=0;r<arguments.length;r++)f.setRow(r,arguments[r]);return f}},n.expand=function(t,r){for(var o=[],e=0;e<r.length;e++)for(var i=0;i<r[e];i++)o.push(t[e]);return new n(o)},n.checkMatrix=function(t){if(!t)throw new TypeError("Argument has to be a matrix");return"Matrix"!==t.klass&&(t=new n(t)),t},n.isMatrix=function(t){return t?"Matrix"===t.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(t){if(0>t||t>this.rows-1)throw new RangeError("Row index out of range.")},n.prototype.checkColumnIndex=function(t){if(0>t||t>this.columns-1)throw new RangeError("Column index out of range.")},n.prototype.checkDimensions=function(t){if(this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal.")},n.prototype.apply=function(t){for(var r=this.rows,o=this.columns,n=0;r>n;n++)for(var e=0;o>e;e++)t.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 t=this.rows,r=new Array(t),n=0;t>n;n++)r[n]=o(this[n]);return r},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 t=this.rows,r=0;t>r;r++)for(var o=0;r>=o;o++)if(this[r][o]!==this[o][r])return!1;return!0}return!1},n.prototype.set=function(t,r,o){return this[t][r]=o,this},n.prototype.get=function(t,r){return this[t][r]},n.prototype.fill=function(t){for(var r=this.rows,o=this.columns,n=0;r>n;n++)for(var e=0;o>e;e++)this[n][e]=t;return this},n.prototype.neg=function(){return this.mulS(-1)},n.prototype.add=function(t){return"number"==typeof t?this.addS(t):(t=n.checkMatrix(t),this.addM(t))},n.prototype.addS=function(t){for(var r=this.rows,o=this.columns,n=0;r>n;n++)for(var e=0;o>e;e++)this[n][e]+=t;return this},n.prototype.addM=function(t){this.checkDimensions(t);for(var r=this.rows,o=this.columns,n=0;r>n;n++)for(var e=0;o>e;e++)this[n][e]+=t[n][e];return this},n.prototype.sub=function(t){return"number"==typeof t?this.subS(t):(t=n.checkMatrix(t),this.subM(t))},n.prototype.subS=function(t){for(var r=this.rows,o=this.columns,n=0;r>n;n++)for(var e=0;o>e;e++)this[n][e]-=t;return this},n.prototype.subM=function(t){this.checkDimensions(t);for(var r=this.rows,o=this.columns,n=0;r>n;n++)for(var e=0;o>e;e++)this[n][e]-=t[n][e];return this},n.prototype.mul=function(t){return"number"==typeof t?this.mulS(t):(t=n.checkMatrix(t),this.mulM(t))},n.prototype.mulS=function(t){for(var r=this.rows,o=this.columns,n=0;r>n;n++)for(var e=0;o>e;e++)this[n][e]*=t;return this},n.prototype.mulM=function(t){this.checkDimensions(t);for(var r=this.rows,o=this.columns,n=0;r>n;n++)for(var e=0;o>e;e++)this[n][e]*=t[n][e];return this},n.prototype.div=function(t){return"number"==typeof t?this.divS(t):(t=n.checkMatrix(t),this.divM(t))},n.prototype.divS=function(t){for(var r=this.rows,o=this.columns,n=0;r>n;n++)for(var e=0;o>e;e++)this[n][e]/=t;return this},n.prototype.divM=function(t){this.checkDimensions(t);for(var r=this.rows,o=this.columns,n=0;r>n;n++)for(var e=0;o>e;e++)this[n][e]/=t[n][e];return this},n.prototype.getRow=function(t){return this.checkRowIndex(t),o(this[t])},n.prototype.getRowVector=function(t){return n.rowVector(this.getRow(t))},n.prototype.setRow=function(t,r){if(this.checkRowIndex(t),n.isMatrix(r)&&(r=r.to1DArray()),r.length!==this.columns)throw new RangeError("Invalid row size");return this[t]=o(r),this},n.prototype.removeRow=function(t){if(this.checkRowIndex(t),1===this.rows)throw new RangeError("A matrix cannot have less than one row");return e.call(this,t,1),this.rows-=1,this},n.prototype.addRow=function(t,r){if("undefined"==typeof r&&(r=t,t=this.rows),0>t||t>this.rows)throw new RangeError("Row index out of range.");if(n.isMatrix(r)&&(r=r.to1DArray()),r.length!==this.columns)throw new RangeError("Invalid row size");return e.call(this,t,0,o(r)),this.rows+=1,this},n.prototype.swapRows=function(t,r){this.checkRowIndex(t),this.checkRowIndex(r);var o=this[t];return this[t]=this[r],this[r]=o,this},n.prototype.getColumn=function(t){this.checkColumnIndex(t);for(var r=this.rows,o=new Array(r),n=0;r>n;n++)o[n]=this[n][t];return o},n.prototype.getColumnVector=function(t){return n.columnVector(this.getColumn(t))},n.prototype.setColumn=function(t,r){this.checkColumnIndex(t),n.isMatrix(r)&&(r=r.to1DArray());var o=this.rows;if(r.length!==o)throw new RangeError("Invalid column size");for(var e=0;o>e;e++)this[e][t]=r[e];return this},n.prototype.removeColumn=function(t){if(this.checkColumnIndex(t),1===this.columns)throw new RangeError("A matrix cannot have less than one column");for(var r=0,o=this.rows;o>r;r++)this[r].splice(t,1);return this.columns-=1,this},n.prototype.addColumn=function(t,r){if("undefined"==typeof r&&(r=t,t=this.columns),0>t||t>this.columns)throw new RangeError("Column index out of range.");n.isMatrix(r)&&(r=r.to1DArray());var o=this.rows;if(r.length!==o)throw new RangeError("Invalid column size");for(var e=0;o>e;e++)this[e].splice(t,0,r[e]);return this.columns+=1,this},n.prototype.swapColumns=function(t,r){this.checkRowIndex(t),this.checkRowIndex(r);for(var o,n,e=this.rows,i=0;e>i;i++)n=this[i],o=n[t],n[t]=n[r],n[r]=o;return this},n.prototype.checkRowVector=function(t){if(n.isMatrix(t)&&(t=t.to1DArray()),t.length!==this.columns)throw new RangeError("vector size must be the same as the number of columns");return t},n.prototype.checkColumnVector=function(t){if(n.isMatrix(t)&&(t=t.to1DArray()),t.length!==this.rows)throw new RangeError("vector size must be the same as the number of rows");return t},n.prototype.addRowVector=function(t){t=this.checkRowVector(t);for(var r=this.rows,o=this.columns,n=0;r>n;n++)for(var e=0;o>e;e++)this[n][e]+=t[e];return this},n.prototype.subRowVector=function(t){t=this.checkRowVector(t);for(var r=this.rows,o=this.columns,n=0;r>n;n++)for(var e=0;o>e;e++)this[n][e]-=t[e];return this},n.prototype.mulRowVector=function(t){t=this.checkRowVector(t);for(var r=this.rows,o=this.columns,n=0;r>n;n++)for(var e=0;o>e;e++)this[n][e]*=t[e];return this},n.prototype.divRowVector=function(t){t=this.checkRowVector(t);for(var r=this.rows,o=this.columns,n=0;r>n;n++)for(var e=0;o>e;e++)this[n][e]/=t[e];return this},n.prototype.addColumnVector=function(t){t=this.checkColumnVector(t);for(var r=this.rows,o=this.columns,n=0;r>n;n++)for(var e=0;o>e;e++)this[n][e]+=t[n];return this},n.prototype.subColumnVector=function(t){t=this.checkColumnVector(t);for(var r=this.rows,o=this.columns,n=0;r>n;n++)for(var e=0;o>e;e++)this[n][e]-=t[n];return this},n.prototype.mulColumnVector=function(t){t=this.checkColumnVector(t);for(var r=this.rows,o=this.columns,n=0;r>n;n++)for(var e=0;o>e;e++)this[n][e]*=t[n];return this},n.prototype.divColumnVector=function(t){t=this.checkColumnVector(t);for(var r=this.rows,o=this.columns,n=0;r>n;n++)for(var e=0;o>e;e++)this[n][e]/=t[n];return this},n.prototype.mulRow=function(t,r){this.checkRowIndex(t);for(var o=0,n=this.columns;n>o;o++)this[t][o]*=r;return this},n.prototype.mulColumn=function(t,r){this.checkColumnIndex(t);for(var o=0,n=this.rows;n>o;o++)this[o][t]*=r},n.prototype.max=function(){for(var t=-(1/0),r=this.rows,o=this.columns,n=0;r>n;n++)for(var e=0;o>e;e++)this[n][e]>t&&(t=this[n][e]);return t},n.prototype.maxIndex=function(){for(var t=-(1/0),r={},o=this.rows,n=this.columns,e=0;o>e;e++)for(var i=0;n>i;i++)this[e][i]>t&&(t=this[e][i],r.row=e,r.column=i);return r},n.prototype.min=function(){for(var t=1/0,r=this.rows,o=this.columns,n=0;r>n;n++)for(var e=0;o>e;e++)this[n][e]<t&&(t=this[n][e]);return t},n.prototype.minIndex=function(){for(var t=1/0,r={},o=this.rows,n=this.columns,e=0;o>e;e++)for(var i=0;n>i;i++)this[e][i]<t&&(t=this[e][i],r.row=e,r.column=i);return r},n.prototype.maxRow=function(t){this.checkRowIndex(t);for(var r=-(1/0),o=0,n=this.columns;n>o;o++)this[t][o]>r&&(r=this[t][o]);return r},n.prototype.maxRowIndex=function(t){this.checkRowIndex(t);for(var r=-(1/0),o={row:t},n=0,e=this.columns;e>n;n++)this[t][n]>r&&(r=this[t][n],o.column=n);return o},n.prototype.minRow=function(t){this.checkRowIndex(t);for(var r=1/0,o=0,n=this.columns;n>o;o++)this[t][o]<r&&(r=this[t][o]);return r},n.prototype.minRowIndex=function(t){this.checkRowIndex(t);for(var r=1/0,o={row:t,column:0},n=0,e=this.columns;e>n;n++)this[t][n]<r&&(r=this[t][n],o.column=n);return o},n.prototype.maxColumn=function(t){this.checkColumnIndex(t);for(var r=-(1/0),o=0,n=this.rows;n>o;o++)this[o][t]>r&&(r=this[o][t]);return r},n.prototype.maxColumnIndex=function(t){this.checkColumnIndex(t);for(var r=-(1/0),o={row:0,column:t},n=0,e=this.rows;e>n;n++)this[n][t]>r&&(r=this[n][t],o.row=n);return o},n.prototype.minColumn=function(t){this.checkColumnIndex(t);for(var r=1/0,o=0,n=this.rows;n>o;o++)this[o][t]<r&&(r=this[o][t]);return r},n.prototype.minColumnIndex=function(t){this.checkColumnIndex(t);for(var r=1/0,o={row:0,column:t},n=0,e=this.rows;e>n;n++)this[n][t]<r&&(r=this[n][t],o.row=n);return o},n.prototype.diag=function s(){if(!this.isSquare())throw new TypeError("Only square matrices have a diagonal.");for(var s=new Array(this.rows),t=0,r=this.rows;r>t;t++)s[t]=this[t][t];return s},n.prototype.sum=function(){for(var t=0,r=this.rows,o=this.columns,n=0;r>n;n++)for(var e=0;o>e;e++)t+=this[n][e];return t},n.prototype.mean=function(){return this.sum()/this.size},n.prototype.prod=function a(){for(var a=1,t=this.rows,r=this.columns,o=0;t>o;o++)for(var n=0;r>n;n++)a*=this[o][n];return a},n.prototype.cumulativeSum=function(){for(var t=0,r=this.rows,o=this.columns,n=0;r>n;n++)for(var e=0;o>e;e++)t+=this[n][e],this[n][e]=t;return this},n.prototype.dot=function u(t){if(this.size!==t.size)throw new RangeError("vectors do not have the same size");for(var r=this.to1DArray(),o=t.to1DArray(),u=0,n=r.length,e=0;n>e;e++)u+=r[e]*o[e];return u},n.prototype.mmul=function(t){if(!n.isMatrix(t))throw new TypeError('parameter "other" must be a matrix');this.columns!==t.rows&&console.warn("Number of columns of left matrix are not equal to number of rows of right matrix.");var r,o,e,i=this.rows,s=this.columns,a=t.columns,u=new n(i,a),h=new Array(s);for(o=0;a>o;o++){for(e=0;s>e;e++)h[e]=t[e][o];for(r=0;i>r;r++){var f=this[r],c=0;for(e=0;s>e;e++)c+=f[e]*h[e];u[r][o]=c}}return u},n.prototype.sortRows=function(t){for(var r=0,o=this.rows;o>r;r++)this[r].sort(t);return this},n.prototype.sortColumns=function(t){for(var r=0,o=this.columns;o>r;r++)this.setColumn(r,this.getColumn(r).sort(t));return this},n.prototype.transpose=function(){for(var t=new n(this.columns,this.rows),r=this.rows,o=this.columns,e=0;r>e;e++)for(var i=0;o>i;i++)t[i][e]=this[e][i];return t},n.prototype.subMatrix=function(t,r,o,e){if(t>r||o>e||0>t||t>=this.rows||0>r||r>=this.rows||0>o||o>=this.columns||0>e||e>=this.columns)throw new RangeError("Argument out of range");for(var i=new n(r-t+1,e-o+1),s=t;r>=s;s++)for(var a=o;e>=a;a++)i[s-t][a-o]=this[s][a];return i},n.prototype.subMatrixRow=function(t,r,o){if("undefined"==typeof r?(r=0,o=this.columns-1):"undefined"==typeof o&&(o=this.columns-1),r>o||0>r||r>=this.columns||0>o||o>=this.columns)throw new RangeError("Argument out of range.");for(var e=t.length,i=this.rows,s=new n(e,o-r+1),a=0;e>a;a++)for(var u=r;o>=u;u++){if(t[a]<0||t[a]>=i)throw new RangeError("Argument out of range.");s[a][u-r]=this[t[a]][u]}return s},n.prototype.subMatrixColumn=function(t,r,o){if("undefined"==typeof r?(r=0,o=this.rows-1):"undefined"==typeof o&&(o=this.rows-1),r>o||0>r||r>=this.rows||0>o||o>=this.rows)throw new RangeError("Argument out of range.");for(var e=t.length,i=this.columns,s=new n(o-r+1,e),a=0;e>a;a++)for(var u=r;o>=u;u++){if(t[a]<0||t[a]>=i)throw new RangeError("Argument out of range.");s[u-r][a]=this[u][t[a]]}return s},n.prototype.trace=function h(){if(!this.isSquare())throw new TypeError("The matrix is not square");for(var h=0,t=0,r=this.rows;r>t;t++)h+=this[t][t];return h},n.prototype.abs=function(){for(var t=this.rows,r=this.columns,o=0;t>o;o++)for(var n=0;r>n;n++)this[o][n]=Math.abs(this[o][n])},t.exports=n},function(t,r,o){"use strict";function n(t){return e(t,i.eye(t.rows))}function e(t,r){return t.isSquare()?new u(t).solve(r):new h(t).solve(r)}var i=o(4),s=o(6),a=o(8),u=o(9),h=o(10),f=o(11);i.prototype.inverse=function(){return n(this)},i.prototype.solve=function(t){return e(this,t)},t.exports={SingularValueDecomposition:s,SVD:s,EigenvalueDecomposition:a,EVD:a,LuDecomposition:u,LU:u,QrDecomposition:h,QR:h,CholeskyDecomposition:f,CHO:f,inverse:n,solve:e}},function(t,r,o){"use strict";function n(t,r){if(!(this instanceof n))return new n(t,r);t=e.checkMatrix(t),r=r||{};var o=t.clone(),s=t.rows,a=t.columns,u=Math.min(s,a),h=!0,f=!0;r.computeLeftSingularVectors===!1&&(h=!1),r.computeRightSingularVectors===!1&&(f=!1);var c=r.autoTranspose===!0,l=!1;if(a>s)if(c){o=o.transpose(),s=o.rows,a=o.columns,l=!0;var p=h;h=f,f=p}else console.warn("Computing SVD on a matrix with more columns than rows. Consider enabling autoTranspose");var m,w,v,y,d,b,M,x,g,R,k,A,j,z,C,V,E,q,I,D,O,S=new Array(Math.min(s+1,a)),_=e.zeros(s,u),J=e.zeros(a,a),L=new Array(a),U=new Array(s),T=Math.min(s-1,a),W=Math.max(0,Math.min(a-2,s));for(v=0,R=Math.max(T,W);R>v;v++){if(T>v){for(S[v]=0,m=v;s>m;m++)S[v]=i(S[v],o[m][v]);if(0!==S[v]){for(o[v][v]<0&&(S[v]=-S[v]),m=v;s>m;m++)o[m][v]/=S[v];o[v][v]+=1}S[v]=-S[v]}for(w=v+1;a>w;w++){if(T>v&&0!==S[v]){for(d=0,m=v;s>m;m++)d+=o[m][v]*o[m][w];for(d=-d/o[v][v],m=v;s>m;m++)o[m][w]+=d*o[m][v]}L[w]=o[v][w]}if(h&&T>v)for(m=v;s>m;m++)_[m][v]=o[m][v];if(W>v){for(L[v]=0,m=v+1;a>m;m++)L[v]=i(L[v],L[m]);if(0!==L[v]){for(L[v+1]<0&&(L[v]=-L[v]),m=v+1;a>m;m++)L[m]/=L[v];L[v+1]+=1}if(L[v]=-L[v],s>v+1&&0!==L[v]){for(m=v+1;s>m;m++)U[m]=0;for(w=v+1;a>w;w++)for(m=v+1;s>m;m++)U[m]+=L[w]*o[m][w];for(w=v+1;a>w;w++)for(d=-L[w]/L[v+1],m=v+1;s>m;m++)o[m][w]+=d*U[m]}if(f)for(m=v+1;a>m;m++)J[m][v]=L[m]}}if(y=Math.min(a,s+1),a>T&&(S[T]=o[T][T]),y>s&&(S[y-1]=0),y>W+1&&(L[W]=o[W][y-1]),L[y-1]=0,h){for(w=T;u>w;w++){for(m=0;s>m;m++)_[m][w]=0;_[w][w]=1}for(v=T-1;v>=0;v--)if(0!==S[v]){for(w=v+1;u>w;w++){for(d=0,m=v;s>m;m++)d+=_[m][v]*_[m][w];for(d=-d/_[v][v],m=v;s>m;m++)_[m][w]+=d*_[m][v]}for(m=v;s>m;m++)_[m][v]=-_[m][v];for(_[v][v]=1+_[v][v],m=0;v-1>m;m++)_[m][v]=0}else{for(m=0;s>m;m++)_[m][v]=0;_[v][v]=1}}if(f)for(v=a-1;v>=0;v--){if(W>v&&0!==L[v])for(w=v+1;a>w;w++){for(d=0,m=v+1;a>m;m++)d+=J[m][v]*J[m][w];for(d=-d/J[v+1][v],m=v+1;a>m;m++)J[m][w]+=d*J[m][v]}for(m=0;a>m;m++)J[m][v]=0;J[v][v]=1}for(var Q=y-1,F=0,G=Math.pow(2,-52);y>0;){for(v=y-2;v>=-1&&-1!==v;v--)if(Math.abs(L[v])<=G*(Math.abs(S[v])+Math.abs(S[v+1]))){L[v]=0;break}if(v===y-2)k=4;else{for(b=y-1;b>=v&&b!==v;b--)if(d=(b!==y?Math.abs(L[b]):0)+(b!==v+1?Math.abs(L[b-1]):0),Math.abs(S[b])<=G*d){S[b]=0;break}b===v?k=3:b===y-1?k=1:(k=2,v=b)}switch(v++,k){case 1:for(M=L[y-2],L[y-2]=0,w=y-2;w>=v;w--)if(d=i(S[w],M),x=S[w]/d,g=M/d,S[w]=d,w!==v&&(M=-g*L[w-1],L[w-1]=x*L[w-1]),f)for(m=0;a>m;m++)d=x*J[m][w]+g*J[m][y-1],J[m][y-1]=-g*J[m][w]+x*J[m][y-1],J[m][w]=d;break;case 2:for(M=L[v-1],L[v-1]=0,w=v;y>w;w++)if(d=i(S[w],M),x=S[w]/d,g=M/d,S[w]=d,M=-g*L[w],L[w]=x*L[w],h)for(m=0;s>m;m++)d=x*_[m][w]+g*_[m][v-1],_[m][v-1]=-g*_[m][w]+x*_[m][v-1],_[m][w]=d;break;case 3:for(A=Math.max(Math.max(Math.max(Math.max(Math.abs(S[y-1]),Math.abs(S[y-2])),Math.abs(L[y-2])),Math.abs(S[v])),Math.abs(L[v])),j=S[y-1]/A,z=S[y-2]/A,C=L[y-2]/A,V=S[v]/A,E=L[v]/A,q=((z+j)*(z-j)+C*C)/2,I=j*C*(j*C),D=0,0===q&&0===I||(D=Math.sqrt(q*q+I),0>q&&(D=-D),D=I/(q+D)),M=(V+j)*(V-j)+D,O=V*E,w=v;y-1>w;w++){if(d=i(M,O),x=M/d,g=O/d,w!==v&&(L[w-1]=d),M=x*S[w]+g*L[w],L[w]=x*L[w]-g*S[w],O=g*S[w+1],S[w+1]=x*S[w+1],f)for(m=0;a>m;m++)d=x*J[m][w]+g*J[m][w+1],J[m][w+1]=-g*J[m][w]+x*J[m][w+1],J[m][w]=d;if(d=i(M,O),x=M/d,g=O/d,S[w]=d,M=x*L[w]+g*S[w+1],S[w+1]=-g*L[w]+x*S[w+1],O=g*L[w+1],L[w+1]=x*L[w+1],h&&s-1>w)for(m=0;s>m;m++)d=x*_[m][w]+g*_[m][w+1],_[m][w+1]=-g*_[m][w]+x*_[m][w+1],_[m][w]=d}L[y-2]=M,F+=1;break;case 4:if(S[v]<=0&&(S[v]=S[v]<0?-S[v]:0,f))for(m=0;Q>=m;m++)J[m][v]=-J[m][v];for(;Q>v&&!(S[v]>=S[v+1]);){if(d=S[v],S[v]=S[v+1],S[v+1]=d,f&&a-1>v)for(m=0;a>m;m++)d=J[m][v+1],J[m][v+1]=J[m][v],J[m][v]=d;if(h&&s-1>v)for(m=0;s>m;m++)d=_[m][v+1],_[m][v+1]=_[m][v],_[m][v]=d;v++}F=0,y--}}if(l){var P=J;J=_,_=P}this.m=s,this.n=a,this.s=S,this.U=_,this.V=J}var e=o(4),i=o(7).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 t=Math.pow(2,-52),r=Math.max(this.m,this.n)*this.s[0]*t,o=0,n=this.s,e=0,i=n.length;i>e;e++)n[e]>r&&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(t){var r,o=t,n=this.threshold,i=this.s.length,s=e.zeros(i,i);for(r=0;i>r;r++)Math.abs(this.s[r])<=n?s[r][r]=0:s[r][r]=1/this.s[r];var a,u,h,f=this.V.mmul(s),c=this.V.rows,l=this.U.rows,p=e.zeros(c,l);for(r=0;c>r;r++)for(a=0;l>a;a++){for(h=0,u=0;i>u;u++)h+=f[r][u]*this.U[a][u];p[r][a]=h}return p.mmul(o)},solveForDiagonal:function(t){return this.solve(e.diag(t))},inverse:function(){var t,r,o=this.threshold,n=this.V.rows,i=this.V.columns,s=new e(n,this.s.length);for(t=0;n>t;t++)for(r=0;i>r;r++)Math.abs(this.s[r])>o?s[t][r]=this.V[t][r]/this.s[r]:s[t][r]=0;var a,u,h=this.U.rows,f=this.U.columns,c=new e(n,h);for(t=0;n>t;t++)for(r=0;h>r;r++){for(u=0,a=0;f>a;a++)u+=s[t][a]*this.U[r][a];c[t][r]=u}return c}},t.exports=n},function(t,r){"use strict";r.hypotenuse=function(t,r){var o;return Math.abs(t)>Math.abs(r)?(o=r/t,Math.abs(t)*Math.sqrt(1+o*o)):0!==r?(o=t/r,Math.abs(r)*Math.sqrt(1+o*o)):0}},function(t,r,o){"use strict";function n(t){if(!(this instanceof n))return new n(t);if(t=h.checkMatrix(t),!t.isSquare())throw new Error("Matrix is not a square matrix");var r,o,u=t.columns,f=h.zeros(u,u),c=new Array(u),l=new Array(u),p=t;if(t.isSymmetric()){for(r=0;u>r;r++)for(o=0;u>o;o++)f[r][o]=p[r][o];e(u,l,c,f),i(u,l,c,f)}else{var m=h.zeros(u,u),w=new Array(u);for(o=0;u>o;o++)for(r=0;u>r;r++)m[r][o]=p[r][o];s(u,m,w,f),a(u,l,c,f,m)}this.n=u,this.e=l,this.d=c,this.V=f}function e(t,r,o,n){var e,i,s,a,u,h,f,c;for(u=0;t>u;u++)o[u]=n[t-1][u];for(a=t-1;a>0;a--){for(c=0,s=0,h=0;a>h;h++)c+=Math.abs(o[h]);if(0===c)for(r[a]=o[a-1],u=0;a>u;u++)o[u]=n[a-1][u],n[a][u]=0,n[u][a]=0;else{for(h=0;a>h;h++)o[h]/=c,s+=o[h]*o[h];for(e=o[a-1],i=Math.sqrt(s),e>0&&(i=-i),r[a]=c*i,s-=e*i,o[a-1]=e-i,u=0;a>u;u++)r[u]=0;for(u=0;a>u;u++){for(e=o[u],n[u][a]=e,i=r[u]+n[u][u]*e,h=u+1;a-1>=h;h++)i+=n[h][u]*o[h],r[h]+=n[h][u]*e;r[u]=i}for(e=0,u=0;a>u;u++)r[u]/=s,e+=r[u]*o[u];for(f=e/(s+s),u=0;a>u;u++)r[u]-=f*o[u];for(u=0;a>u;u++){for(e=o[u],i=r[u],h=u;a-1>=h;h++)n[h][u]-=e*r[h]+i*o[h];o[u]=n[a-1][u],n[a][u]=0}}o[a]=s}for(a=0;t-1>a;a++){if(n[t-1][a]=n[a][a],n[a][a]=1,s=o[a+1],0!==s){for(h=0;a>=h;h++)o[h]=n[h][a+1]/s;for(u=0;a>=u;u++){for(i=0,h=0;a>=h;h++)i+=n[h][a+1]*n[h][u];for(h=0;a>=h;h++)n[h][u]-=i*o[h]}}for(h=0;a>=h;h++)n[h][a+1]=0}for(u=0;t>u;u++)o[u]=n[t-1][u],n[t-1][u]=0;n[t-1][t-1]=1,r[0]=0}function i(t,r,o,n){var e,i,s,a,u,h,c,l,p,m,w,v,y,d,b,M,x;for(s=1;t>s;s++)r[s-1]=r[s];r[t-1]=0;var g=0,R=0,k=Math.pow(2,-52);for(h=0;t>h;h++){for(R=Math.max(R,Math.abs(o[h])+Math.abs(r[h])),c=h;t>c&&!(Math.abs(r[c])<=k*R);)c++;if(c>h){x=0;do{for(x+=1,e=o[h],l=(o[h+1]-e)/(2*r[h]),p=f(l,1),0>l&&(p=-p),o[h]=r[h]/(l+p),o[h+1]=r[h]*(l+p),m=o[h+1],i=e-o[h],s=h+2;t>s;s++)o[s]-=i;for(g+=i,l=o[c],w=1,v=w,y=w,d=r[h+1],b=0,M=0,s=c-1;s>=h;s--)for(y=v,v=w,M=b,e=w*r[s],i=w*l,p=f(l,r[s]),r[s+1]=b*p,b=r[s]/p,w=l/p,l=w*o[s]-b*e,o[s+1]=i+b*(w*e+b*o[s]),u=0;t>u;u++)i=n[u][s+1],n[u][s+1]=b*n[u][s]+w*i,n[u][s]=w*n[u][s]-b*i;l=-b*M*y*d*r[h]/m,r[h]=b*l,o[h]=w*l}while(Math.abs(r[h])>k*R)}o[h]=o[h]+g,r[h]=0}for(s=0;t-1>s;s++){for(u=s,l=o[s],a=s+1;t>a;a++)o[a]<l&&(u=a,l=o[a]);if(u!==s)for(o[u]=o[s],o[s]=l,a=0;t>a;a++)l=n[a][s],n[a][s]=n[a][u],n[a][u]=l}}function s(t,r,o,n){var e,i,s,a,u,h,f,c=0,l=t-1;for(h=c+1;l-1>=h;h++){for(f=0,a=h;l>=a;a++)f+=Math.abs(r[a][h-1]);if(0!==f){for(s=0,a=l;a>=h;a--)o[a]=r[a][h-1]/f,s+=o[a]*o[a];for(i=Math.sqrt(s),o[h]>0&&(i=-i),s-=o[h]*i,o[h]=o[h]-i,u=h;t>u;u++){for(e=0,a=l;a>=h;a--)e+=o[a]*r[a][u];for(e/=s,a=h;l>=a;a++)r[a][u]-=e*o[a]}for(a=0;l>=a;a++){for(e=0,u=l;u>=h;u--)e+=o[u]*r[a][u];for(e/=s,u=h;l>=u;u++)r[a][u]-=e*o[u]}o[h]=f*o[h],r[h][h-1]=f*i}}for(a=0;t>a;a++)for(u=0;t>u;u++)n[a][u]=a===u?1:0;for(h=l-1;h>=c+1;h--)if(0!==r[h][h-1]){for(a=h+1;l>=a;a++)o[a]=r[a][h-1];for(u=h;l>=u;u++){for(i=0,a=h;l>=a;a++)i+=o[a]*n[a][u];for(i=i/o[h]/r[h][h-1],a=h;l>=a;a++)n[a][u]+=i*o[a]}}}function a(t,r,o,n,e){var i,s,a,h,f,c,l,p,m,w,v,y,d,b,M,x=t-1,g=0,R=t-1,k=Math.pow(2,-52),A=0,j=0,z=0,C=0,V=0,E=0,q=0,I=0; | ||
for(i=0;t>i;i++)for((g>i||i>R)&&(o[i]=e[i][i],r[i]=0),s=Math.max(i-1,0);t>s;s++)j+=Math.abs(e[i][s]);for(;x>=g;){for(h=x;h>g&&(E=Math.abs(e[h-1][h-1])+Math.abs(e[h][h]),0===E&&(E=j),!(Math.abs(e[h][h-1])<k*E));)h--;if(h===x)e[x][x]=e[x][x]+A,o[x]=e[x][x],r[x]=0,x--,I=0;else if(h===x-1){if(l=e[x][x-1]*e[x-1][x],z=(e[x-1][x-1]-e[x][x])/2,C=z*z+l,q=Math.sqrt(Math.abs(C)),e[x][x]=e[x][x]+A,e[x-1][x-1]=e[x-1][x-1]+A,p=e[x][x],C>=0){for(q=z>=0?z+q:z-q,o[x-1]=p+q,o[x]=o[x-1],0!==q&&(o[x]=p-l/q),r[x-1]=0,r[x]=0,p=e[x][x-1],E=Math.abs(p)+Math.abs(q),z=p/E,C=q/E,V=Math.sqrt(z*z+C*C),z/=V,C/=V,s=x-1;t>s;s++)q=e[x-1][s],e[x-1][s]=C*q+z*e[x][s],e[x][s]=C*e[x][s]-z*q;for(i=0;x>=i;i++)q=e[i][x-1],e[i][x-1]=C*q+z*e[i][x],e[i][x]=C*e[i][x]-z*q;for(i=g;R>=i;i++)q=n[i][x-1],n[i][x-1]=C*q+z*n[i][x],n[i][x]=C*n[i][x]-z*q}else o[x-1]=p+z,o[x]=p+z,r[x-1]=q,r[x]=-q;x-=2,I=0}else{if(p=e[x][x],m=0,l=0,x>h&&(m=e[x-1][x-1],l=e[x][x-1]*e[x-1][x]),10===I){for(A+=p,i=g;x>=i;i++)e[i][i]-=p;E=Math.abs(e[x][x-1])+Math.abs(e[x-1][x-2]),p=m=.75*E,l=-.4375*E*E}if(30===I&&(E=(m-p)/2,E=E*E+l,E>0)){for(E=Math.sqrt(E),p>m&&(E=-E),E=p-l/((m-p)/2+E),i=g;x>=i;i++)e[i][i]-=E;A+=E,p=m=l=.964}for(I+=1,f=x-2;f>=h&&(q=e[f][f],V=p-q,E=m-q,z=(V*E-l)/e[f+1][f]+e[f][f+1],C=e[f+1][f+1]-q-V-E,V=e[f+2][f+1],E=Math.abs(z)+Math.abs(C)+Math.abs(V),z/=E,C/=E,V/=E,f!==h)&&!(Math.abs(e[f][f-1])*(Math.abs(C)+Math.abs(V))<k*(Math.abs(z)*(Math.abs(e[f-1][f-1])+Math.abs(q)+Math.abs(e[f+1][f+1]))));)f--;for(i=f+2;x>=i;i++)e[i][i-2]=0,i>f+2&&(e[i][i-3]=0);for(a=f;x-1>=a&&(b=a!==x-1,a!==f&&(z=e[a][a-1],C=e[a+1][a-1],V=b?e[a+2][a-1]:0,p=Math.abs(z)+Math.abs(C)+Math.abs(V),0!==p&&(z/=p,C/=p,V/=p)),0!==p);a++)if(E=Math.sqrt(z*z+C*C+V*V),0>z&&(E=-E),0!==E){for(a!==f?e[a][a-1]=-E*p:h!==f&&(e[a][a-1]=-e[a][a-1]),z+=E,p=z/E,m=C/E,q=V/E,C/=z,V/=z,s=a;t>s;s++)z=e[a][s]+C*e[a+1][s],b&&(z+=V*e[a+2][s],e[a+2][s]=e[a+2][s]-z*q),e[a][s]=e[a][s]-z*p,e[a+1][s]=e[a+1][s]-z*m;for(i=0;i<=Math.min(x,a+3);i++)z=p*e[i][a]+m*e[i][a+1],b&&(z+=q*e[i][a+2],e[i][a+2]=e[i][a+2]-z*V),e[i][a]=e[i][a]-z,e[i][a+1]=e[i][a+1]-z*C;for(i=g;R>=i;i++)z=p*n[i][a]+m*n[i][a+1],b&&(z+=q*n[i][a+2],n[i][a+2]=n[i][a+2]-z*V),n[i][a]=n[i][a]-z,n[i][a+1]=n[i][a+1]-z*C}}}if(0!==j){for(x=t-1;x>=0;x--)if(z=o[x],C=r[x],0===C)for(h=x,e[x][x]=1,i=x-1;i>=0;i--){for(l=e[i][i]-z,V=0,s=h;x>=s;s++)V+=e[i][s]*e[s][x];if(r[i]<0)q=l,E=V;else if(h=i,0===r[i]?e[i][x]=0!==l?-V/l:-V/(k*j):(p=e[i][i+1],m=e[i+1][i],C=(o[i]-z)*(o[i]-z)+r[i]*r[i],c=(p*E-q*V)/C,e[i][x]=c,e[i+1][x]=Math.abs(p)>Math.abs(q)?(-V-l*c)/p:(-E-m*c)/q),c=Math.abs(e[i][x]),k*c*c>1)for(s=i;x>=s;s++)e[s][x]=e[s][x]/c}else if(0>C)for(h=x-1,Math.abs(e[x][x-1])>Math.abs(e[x-1][x])?(e[x-1][x-1]=C/e[x][x-1],e[x-1][x]=-(e[x][x]-z)/e[x][x-1]):(M=u(0,-e[x-1][x],e[x-1][x-1]-z,C),e[x-1][x-1]=M[0],e[x-1][x]=M[1]),e[x][x-1]=0,e[x][x]=1,i=x-2;i>=0;i--){for(w=0,v=0,s=h;x>=s;s++)w+=e[i][s]*e[s][x-1],v+=e[i][s]*e[s][x];if(l=e[i][i]-z,r[i]<0)q=l,V=w,E=v;else if(h=i,0===r[i]?(M=u(-w,-v,l,C),e[i][x-1]=M[0],e[i][x]=M[1]):(p=e[i][i+1],m=e[i+1][i],y=(o[i]-z)*(o[i]-z)+r[i]*r[i]-C*C,d=2*(o[i]-z)*C,0===y&&0===d&&(y=k*j*(Math.abs(l)+Math.abs(C)+Math.abs(p)+Math.abs(m)+Math.abs(q))),M=u(p*V-q*w+C*v,p*E-q*v-C*w,y,d),e[i][x-1]=M[0],e[i][x]=M[1],Math.abs(p)>Math.abs(q)+Math.abs(C)?(e[i+1][x-1]=(-w-l*e[i][x-1]+C*e[i][x])/p,e[i+1][x]=(-v-l*e[i][x]-C*e[i][x-1])/p):(M=u(-V-m*e[i][x-1],-E-m*e[i][x],q,C),e[i+1][x-1]=M[0],e[i+1][x]=M[1])),c=Math.max(Math.abs(e[i][x-1]),Math.abs(e[i][x])),k*c*c>1)for(s=i;x>=s;s++)e[s][x-1]=e[s][x-1]/c,e[s][x]=e[s][x]/c}for(i=0;t>i;i++)if(g>i||i>R)for(s=i;t>s;s++)n[i][s]=e[i][s];for(s=t-1;s>=g;s--)for(i=g;R>=i;i++){for(q=0,a=g;a<=Math.min(s,R);a++)q+=n[i][a]*e[a][s];n[i][s]=q}}}function u(t,r,o,n){var e,i;return Math.abs(o)>Math.abs(n)?(e=n/o,i=o+e*n,[(t+e*r)/i,(r-e*t)/i]):(e=o/n,i=n+e*o,[(e*t+r)/i,(e*r-t)/i])}var h=o(4),f=o(7).hypotenuse;n.prototype={get realEigenvalues(){return this.d},get imaginaryEigenvalues(){return this.e},get eigenvectorMatrix(){return this.V},get diagonalMatrix(){var t,r,o=this.n,n=this.e,e=this.d,i=new h(o,o);for(t=0;o>t;t++){for(r=0;o>r;r++)i[t][r]=0;i[t][t]=e[t],n[t]>0?i[t][t+1]=n[t]:n[t]<0&&(i[t][t-1]=n[t])}return i}},t.exports=n},function(t,r,o){"use strict";function n(t){if(!(this instanceof n))return new n(t);t=e.checkMatrix(t);var r,o,i,s,a,u,h,f,c,l,p=t.clone(),m=p.rows,w=p.columns,v=new Array(m),y=1;for(r=0;m>r;r++)v[r]=r;for(c=new Array(m),o=0;w>o;o++){for(r=0;m>r;r++)c[r]=p[r][o];for(r=0;m>r;r++){for(f=p[r],l=Math.min(r,o),a=0,i=0;l>i;i++)a+=f[i]*c[i];f[o]=c[r]-=a}for(s=o,r=o+1;m>r;r++)Math.abs(c[r])>Math.abs(c[s])&&(s=r);if(s!==o){for(i=0;w>i;i++)u=p[s][i],p[s][i]=p[o][i],p[o][i]=u;h=v[s],v[s]=v[o],v[o]=h,y=-y}if(m>o&&0!==p[o][o])for(r=o+1;m>r;r++)p[r][o]/=p[o][o]}this.LU=p,this.pivotVector=v,this.pivotSign=y}var e=o(4);n.prototype={isSingular:function(){for(var t=this.LU,r=t.columns,o=0;r>o;o++)if(0===t[o][o])return!0;return!1},get determinant(){var t=this.LU;if(!t.isSquare())throw new Error("Matrix must be square");for(var r=this.pivotSign,o=t.columns,n=0;o>n;n++)r*=t[n][n];return r},get lowerTriangularFactor(){for(var t=this.LU,r=t.rows,o=t.columns,n=new e(r,o),i=0;r>i;i++)for(var s=0;o>s;s++)i>s?n[i][s]=t[i][s]:i===s?n[i][s]=1:n[i][s]=0;return n},get upperTriangularFactor(){for(var t=this.LU,r=t.rows,o=t.columns,n=new e(r,o),i=0;r>i;i++)for(var s=0;o>s;s++)s>=i?n[i][s]=t[i][s]:n[i][s]=0;return n},get pivotPermutationVector(){return this.pivotVector.slice()},solve:function(t){t=e.checkMatrix(t);var r=this.LU,o=r.rows;if(o!==t.rows)throw new Error("Invalid matrix dimensions");if(this.isSingular())throw new Error("LU matrix is singular");var n,i,s,a=t.columns,u=t.subMatrixRow(this.pivotVector,0,a-1),h=r.columns;for(s=0;h>s;s++)for(n=s+1;h>n;n++)for(i=0;a>i;i++)u[n][i]-=u[s][i]*r[n][s];for(s=h-1;s>=0;s--){for(i=0;a>i;i++)u[s][i]/=r[s][s];for(n=0;s>n;n++)for(i=0;a>i;i++)u[n][i]-=u[s][i]*r[n][s]}return u}},t.exports=n},function(t,r,o){"use strict";function n(t){if(!(this instanceof n))return new n(t);t=e.checkMatrix(t);var r,o,s,a,u=t.clone(),h=t.rows,f=t.columns,c=new Array(f);for(s=0;f>s;s++){var l=0;for(r=s;h>r;r++)l=i(l,u[r][s]);if(0!==l){for(u[s][s]<0&&(l=-l),r=s;h>r;r++)u[r][s]/=l;for(u[s][s]+=1,o=s+1;f>o;o++){for(a=0,r=s;h>r;r++)a+=u[r][s]*u[r][o];for(a=-a/u[s][s],r=s;h>r;r++)u[r][o]+=a*u[r][s]}}c[s]=-l}this.QR=u,this.Rdiag=c}var e=o(4),i=o(7).hypotenuse;n.prototype={solve:function(t){t=e.checkMatrix(t);var r=this.QR,o=r.rows;if(t.rows!==o)throw new Error("Matrix row dimensions must agree");if(!this.isFullRank())throw new Error("Matrix is rank deficient");var n,i,s,a,u=t.columns,h=t.clone(),f=r.columns;for(s=0;f>s;s++)for(i=0;u>i;i++){for(a=0,n=s;o>n;n++)a+=r[n][s]*h[n][i];for(a=-a/r[s][s],n=s;o>n;n++)h[n][i]+=a*r[n][s]}for(s=f-1;s>=0;s--){for(i=0;u>i;i++)h[s][i]/=this.Rdiag[s];for(n=0;s>n;n++)for(i=0;u>i;i++)h[n][i]-=h[s][i]*r[n][s]}return h.subMatrix(0,f-1,0,u-1)},isFullRank:function(){for(var t=this.QR.columns,r=0;t>r;r++)if(0===this.Rdiag[r])return!1;return!0},get upperTriangularFactor(){var t,r,o=this.QR,n=o.columns,i=new e(n,n);for(t=0;n>t;t++)for(r=0;n>r;r++)r>t?i[t][r]=o[t][r]:t===r?i[t][r]=this.Rdiag[t]:i[t][r]=0;return i},get orthogonalFactor(){var t,r,o,n,i=this.QR,s=i.rows,a=i.columns,u=new e(s,a);for(o=a-1;o>=0;o--){for(t=0;s>t;t++)u[t][o]=0;for(u[o][o]=1,r=o;a>r;r++)if(0!==i[o][o]){for(n=0,t=o;s>t;t++)n+=i[t][o]*u[t][r];for(n=-n/i[o][o],t=o;s>t;t++)u[t][r]+=n*i[t][o]}}return u}},t.exports=n},function(t,r,o){"use strict";function n(t){if(!(this instanceof n))return new n(t);if(t=e.checkMatrix(t),!t.isSymmetric())throw new Error("Matrix is not symmetric");var r,o,i,s=t,a=s.rows,u=new e(a,a),h=!0;for(o=0;a>o;o++){var f=u[o],c=0;for(i=0;o>i;i++){var l=u[i],p=0;for(r=0;i>r;r++)p+=l[r]*f[r];f[i]=p=(s[o][i]-p)/u[i][i],c+=p*p}for(c=s[o][o]-c,h&=c>0,u[o][o]=Math.sqrt(Math.max(c,0)),i=o+1;a>i;i++)u[o][i]=0}if(!h)throw new Error("Matrix is not positive definite");this.L=u}var e=o(4);n.prototype={get leftTriangularFactor(){return this.L},solve:function(t){t=e.checkMatrix(t);var r=this.L,o=r.rows;if(t.rows!==o)throw new Error("Matrix dimensions do not match");var n,i,s,a=t.columns,u=t.clone();for(s=0;o>s;s++)for(i=0;a>i;i++){for(n=0;s>n;n++)u[s][i]-=u[n][i]*r[s][n];u[s][i]/=r[s][s]}for(s=o-1;s>=0;s--)for(i=0;a>i;i++){for(n=s+1;o>n;n++)u[s][i]-=u[n][i]*r[n][s];u[s][i]/=r[s][s]}return u}},t.exports=n},function(t,r,o){"use strict";function n(t,r){return new R(t,r)}function e(t,r){return R.ones(t,r)}function i(t,r){return R.eye(t,r)}function s(t,r){return R.zeros(t,r)}function a(t,r){return R.rand(t,r)}function u(t){if("number"==typeof t)return t;var r=t.clone();return r.transpose()}function h(t,r){if("number"==typeof t&&"number"==typeof r)return t+r;if("number"==typeof t)return this.add(r,t);var o=t.clone();return o.add(r)}function f(t,r){if("number"==typeof t&&"number"==typeof r)return t-r;if("number"==typeof t)return this.subtract(r,t);var o=t.clone();return o.sub(r)}function c(t,r){if("number"==typeof t&&"number"==typeof r)return t*r;if("number"==typeof t)return this.multiply(r,t);var o=t.clone();return"number"==typeof r?o.mul(r):o=o.mmul(r),1==o.rows&&1==o.columns?o[0][0]:o}function l(t,r){var o=t.clone();return o.mul(r)}function p(t,r){var o=t.clone();return o.div(r)}function m(t){var r,o,n=null,e=t.rows,i=t.columns;if("undefined"==typeof i&&"object"==typeof t)if(t[0]&&t[0].length)for(e=t.length,i=t[0].length,o=Math.min(e,i),n=R.zeros(i,i),r=0;i>r;r++)n[r][r]=t[r][r];else for(i=t.length,n=R.zeros(i,i),r=0;i>r;r++)n[r][r]=t[r];if(1==e)for(n=R.zeros(i,i),r=0;i>r;r++)n[r][r]=t[0][r];else if(e>0&&i>0)for(o=Math.min(e,i),n=new Array(o),r=0;o>r;r++)n[r]=t[r][r];return n}function w(t,r){if("number"==typeof t&&"number"==typeof r)return Math.min(t,r);for(var o=t.rows,n=t.columns,e=new R(o,n),i=0;o>i;i++)for(var s=0;n>s;s++)t[i][s]<r[i][s]?e[i][s]=t[i][s]:e[i][s]=r[i][s];return e}function v(t,r){if("number"==typeof t&&"number"==typeof r)return Math.max(t,r);for(var o=t.rows,n=t.columns,e=new R(o,n),i=0;o>i;i++)for(var s=0;n>s;s++)t[i][s]>r[i][s]?e[i][s]=t[i][s]:e[i][s]=r[i][s];return e}function y(t){if("number"==typeof t)return Math.sqrt(t);for(var r=t.rows,o=t.columns,n=new R(r,o),e=0;r>e;e++)for(var i=0;o>i;i++)n[e][i]=Math.sqrt(t[e][i]);return n}function d(t){if("number"==typeof t)return Math.abs(t);for(var r=t.rows,o=t.columns,n=new R(r,o),e=0;r>e;e++)for(var i=0;o>i;i++)n[e][i]=Math.abs(t[e][i]);return n}function b(t){if("number"==typeof t)return Math.sqrt(t);for(var r=t.rows,o=t.columns,n=new R(r,o),e=0;r>e;e++)for(var i=0;o>i;i++)n[e][i]=Math.exp(t[e][i]);return n}function M(t,r){if("number"==typeof t)return Math.pow(t,r);for(var o=t.rows,n=t.columns,e=new R(o,n),i=0;o>i;i++)for(var s=0;n>s;s++)e[i][s]=Math.pow(t[i][s],r);return e}function x(t,r){return t.solve(r)}function g(t){return"number"==typeof t?1/t:t.inverse()}var R=o(3);t.exports={transpose:u,add:h,subtract:f,multiply:c,dotMultiply:l,dotDivide:p,diag:m,min:w,max:v,solve:x,inv:g,sqrt:y,exp:b,dotPow:M,abs:d,matrix:n,ones:e,zeros:s,random:a,eye:i}}])}); | ||
//# sourceMappingURL=ml-optimize-lorentzian.min.js.map |
{ | ||
"name": "ml-optimize-lorentzian", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "Optimize Lorentzian", | ||
@@ -20,3 +20,4 @@ "main": "src/index.js", | ||
"Optimization", | ||
"Loreztzian" | ||
"Lorentzian", | ||
"Guassian" | ||
], | ||
@@ -23,0 +24,0 @@ "author": "Andres Castillo", |
@@ -180,6 +180,6 @@ 'use strict'; | ||
for(var i=0; i<group.length;i++){ | ||
nextX = group[i].x-group[i].width*4; | ||
nextX = group[i].x-group[i].width*2; | ||
//console.log(group[i]); | ||
while(t[currentIndex++]<nextX&¤tIndex<nbPoints); | ||
nextX = group[i].x+group[i].width*4; | ||
nextX = group[i].x+group[i].width*2; | ||
tI = []; | ||
@@ -222,6 +222,6 @@ yI = []; | ||
for(var i=0; i<group.length;i++){ | ||
nextX = group[i].x-group[i].width*4; | ||
nextX = group[i].x-group[i].width*2; | ||
//console.log(group[i]); | ||
while(t[currentIndex++]<nextX&¤tIndex<nbPoints); | ||
nextX = group[i].x+group[i].width*4; | ||
nextX = group[i].x+group[i].width*2; | ||
tI = []; | ||
@@ -228,0 +228,0 @@ yI = []; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
563821
4635