w-cluster 1.0.5 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/w-cluster.umd.js +2 -2
- package/dist/w-cluster.umd.js.map +1 -1
- package/dist/w-cluster.wk.umd.js +1 -1
- package/docs/WCluster.mjs.html +1 -1
- package/docs/examples/ex-PCA.html +1 -1
- package/docs/examples/ex-cluster-k-means.html +1 -1
- package/docs/examples/ex-cluster-k-medoids.html +1 -1
- package/docs/examples/ex-cluster-webworker-k-medoids.html +1 -1
- package/docs/global.html +1 -1
- package/docs/index.html +1 -1
- package/package.json +3 -3
- package/temp-bzmWVlF38ndGv0ip7atIxG1RSDXI39mk-nw.js +1 -0
- package/toolg/gDistRollup.mjs +1 -1
package/README.md
CHANGED
|
@@ -163,10 +163,10 @@ testCluster()
|
|
|
163
163
|
```alias
|
|
164
164
|
|
|
165
165
|
<!-- for basic -->
|
|
166
|
-
<script src="https://cdn.jsdelivr.net/npm/w-cluster@1.0.
|
|
166
|
+
<script src="https://cdn.jsdelivr.net/npm/w-cluster@1.0.9/dist/w-cluster.umd.js"></script>
|
|
167
167
|
|
|
168
168
|
<!-- for web workers -->
|
|
169
|
-
<script src="https://cdn.jsdelivr.net/npm/w-cluster@1.0.
|
|
169
|
+
<script src="https://cdn.jsdelivr.net/npm/w-cluster@1.0.9/dist/w-cluster.wk.umd.js"></script>
|
|
170
170
|
|
|
171
171
|
```
|
|
172
172
|
|
package/dist/w-cluster.umd.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* w-cluster v1.0.
|
|
2
|
+
* w-cluster v1.0.9
|
|
3
3
|
* (c) 2018-2021 yuda-lyu(semisphere)
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
|
-
!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(t="undefined"!=typeof globalThis?globalThis:t||self)["w-cluster"]=r()}(this,(function(){"use strict";function t(t,r,e,n,o,i,s){try{var a=t[i](s),u=a.value}catch(t){return void e(t)}a.done?r(u):Promise.resolve(u).then(n,o)}function r(r){return function(){var e=this,n=arguments;return new Promise((function(o,i){var s=r.apply(e,n);function a(r){t(s,o,i,a,u,"next",r)}function u(r){t(s,o,i,a,u,"throw",r)}a(void 0)}))}}function e(t){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var n="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function o(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function i(t){var r={exports:{}};return t(r,r.exports),r.exports}var s=i((function(t){var r=function(t){var r,n=Object.prototype,o=n.hasOwnProperty,i="function"==typeof Symbol?Symbol:{},s=i.iterator||"@@iterator",a=i.asyncIterator||"@@asyncIterator",u=i.toStringTag||"@@toStringTag";function c(t,r,e){return Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}),t[r]}try{c({},"")}catch(t){c=function(t,r,e){return t[r]=e}}function f(t,r,e,n){var o=r&&r.prototype instanceof d?r:d,i=Object.create(o.prototype),s=new R(n||[]);return i._invoke=function(t,r,e){var n=l;return function(o,i){if(n===m)throw new Error("Generator is already running");if(n===g){if("throw"===o)throw i;return C()}for(e.method=o,e.arg=i;;){var s=e.delegate;if(s){var a=_(s,e);if(a){if(a===p)continue;return a}}if("next"===e.method)e.sent=e._sent=e.arg;else if("throw"===e.method){if(n===l)throw n=g,e.arg;e.dispatchException(e.arg)}else"return"===e.method&&e.abrupt("return",e.arg);n=m;var u=h(t,r,e);if("normal"===u.type){if(n=e.done?g:v,u.arg===p)continue;return{value:u.arg,done:e.done}}"throw"===u.type&&(n=g,e.method="throw",e.arg=u.arg)}}}(t,e,s),i}function h(t,r,e){try{return{type:"normal",arg:t.call(r,e)}}catch(t){return{type:"throw",arg:t}}}t.wrap=f;var l="suspendedStart",v="suspendedYield",m="executing",g="completed",p={};function d(){}function w(){}function y(){}var b={};b[s]=function(){return this};var M=Object.getPrototypeOf,x=M&&M(M(O([])));x&&x!==n&&o.call(x,s)&&(b=x);var k=y.prototype=d.prototype=Object.create(b);function E(t){["next","throw","return"].forEach((function(r){c(t,r,(function(t){return this._invoke(r,t)}))}))}function S(t,r){function n(i,s,a,u){var c=h(t[i],t,s);if("throw"!==c.type){var f=c.arg,l=f.value;return l&&"object"===e(l)&&o.call(l,"__await")?r.resolve(l.__await).then((function(t){n("next",t,a,u)}),(function(t){n("throw",t,a,u)})):r.resolve(l).then((function(t){f.value=t,a(f)}),(function(t){return n("throw",t,a,u)}))}u(c.arg)}var i;this._invoke=function(t,e){function o(){return new r((function(r,o){n(t,e,r,o)}))}return i=i?i.then(o,o):o()}}function _(t,e){var n=t.iterator[e.method];if(n===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=r,_(t,e),"throw"===e.method))return p;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return p}var o=h(n,t.iterator,e.arg);if("throw"===o.type)return e.method="throw",e.arg=o.arg,e.delegate=null,p;var i=o.arg;return i?i.done?(e[t.resultName]=i.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=r),e.delegate=null,p):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,p)}function j(t){var r={tryLoc:t[0]};1 in t&&(r.catchLoc=t[1]),2 in t&&(r.finallyLoc=t[2],r.afterLoc=t[3]),this.tryEntries.push(r)}function A(t){var r=t.completion||{};r.type="normal",delete r.arg,t.completion=r}function R(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(j,this),this.reset(!0)}function O(t){if(t){var e=t[s];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,i=function e(){for(;++n<t.length;)if(o.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=r,e.done=!0,e};return i.next=i}}return{next:C}}function C(){return{value:r,done:!0}}return w.prototype=k.constructor=y,y.constructor=w,w.displayName=c(y,u,"GeneratorFunction"),t.isGeneratorFunction=function(t){var r="function"==typeof t&&t.constructor;return!!r&&(r===w||"GeneratorFunction"===(r.displayName||r.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,y):(t.__proto__=y,c(t,u,"GeneratorFunction")),t.prototype=Object.create(k),t},t.awrap=function(t){return{__await:t}},E(S.prototype),S.prototype[a]=function(){return this},t.AsyncIterator=S,t.async=function(r,e,n,o,i){void 0===i&&(i=Promise);var s=new S(f(r,e,n,o),i);return t.isGeneratorFunction(e)?s:s.next().then((function(t){return t.done?t.value:s.next()}))},E(k),c(k,u,"Generator"),k[s]=function(){return this},k.toString=function(){return"[object Generator]"},t.keys=function(t){var r=[];for(var e in t)r.push(e);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},t.values=O,R.prototype={constructor:R,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=r,this.done=!1,this.delegate=null,this.method="next",this.arg=r,this.tryEntries.forEach(A),!t)for(var e in this)"t"===e.charAt(0)&&o.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=r)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(n,o){return a.type="throw",a.arg=t,e.next=n,o&&(e.method="next",e.arg=r),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var s=this.tryEntries[i],a=s.completion;if("root"===s.tryLoc)return n("end");if(s.tryLoc<=this.prev){var u=o.call(s,"catchLoc"),c=o.call(s,"finallyLoc");if(u&&c){if(this.prev<s.catchLoc)return n(s.catchLoc,!0);if(this.prev<s.finallyLoc)return n(s.finallyLoc)}else if(u){if(this.prev<s.catchLoc)return n(s.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<s.finallyLoc)return n(s.finallyLoc)}}}},abrupt:function(t,r){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc<=this.prev&&o.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var i=n;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=r&&r<=i.finallyLoc&&(i=null);var s=i?i.completion:{};return s.type=t,s.arg=r,i?(this.method="next",this.next=i.finallyLoc,p):this.complete(s)},complete:function(t,r){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&r&&(this.next=r),p},finish:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.finallyLoc===t)return this.complete(e.completion,e.afterLoc),A(e),p}},catch:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.tryLoc===t){var n=e.completion;if("throw"===n.type){var o=n.arg;A(e)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,n){return this.delegate={iterator:O(t),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=r),p}},t}(t.exports);try{regeneratorRuntime=r}catch(t){Function("r","regeneratorRuntime = r")(r)}})),a=Array.isArray,u="object"==e(n)&&n&&n.Object===Object&&n,c="object"==("undefined"==typeof self?"undefined":e(self))&&self&&self.Object===Object&&self,f=u||c||Function("return this")(),h=f.Symbol,l=Object.prototype,v=l.hasOwnProperty,m=l.toString,g=h?h.toStringTag:void 0;var p=function(t){var r=v.call(t,g),e=t[g];try{t[g]=void 0;var n=!0}catch(t){}var o=m.call(t);return n&&(r?t[g]=e:delete t[g]),o},d=Object.prototype.toString;var w=function(t){return d.call(t)},y=h?h.toStringTag:void 0;var b=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":y&&y in Object(t)?p(t):w(t)};var M=function(t){return null!=t&&"object"==e(t)};var x=function(t){return"symbol"==e(t)||M(t)&&"[object Symbol]"==b(t)},k=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,E=/^\w*$/;var S=function(t,r){if(a(t))return!1;var n=e(t);return!("number"!=n&&"symbol"!=n&&"boolean"!=n&&null!=t&&!x(t))||(E.test(t)||!k.test(t)||null!=r&&t in Object(r))};var _=function(t){var r=e(t);return null!=t&&("object"==r||"function"==r)};var j,A=function(t){if(!_(t))return!1;var r=b(t);return"[object Function]"==r||"[object GeneratorFunction]"==r||"[object AsyncFunction]"==r||"[object Proxy]"==r},R=f["__core-js_shared__"],O=(j=/[^.]+$/.exec(R&&R.keys&&R.keys.IE_PROTO||""))?"Symbol(src)_1."+j:"";var C=function(t){return!!O&&O in t},I=Function.prototype.toString;var N=function(t){if(null!=t){try{return I.call(t)}catch(t){}try{return t+""}catch(t){}}return""},F=/^\[object .+?Constructor\]$/,T=Function.prototype,P=Object.prototype,z=T.toString,L=P.hasOwnProperty,V=RegExp("^"+z.call(L).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");var q=function(t){return!(!_(t)||C(t))&&(A(t)?V:F).test(N(t))};var D=function(t,r){return null==t?void 0:t[r]};var U=function(t,r){var e=D(t,r);return q(e)?e:void 0},B=U(Object,"create");var G=function(){this.__data__=B?B(null):{},this.size=0};var $=function(t){var r=this.has(t)&&delete this.__data__[t];return this.size-=r?1:0,r},K=Object.prototype.hasOwnProperty;var W=function(t){var r=this.__data__;if(B){var e=r[t];return"__lodash_hash_undefined__"===e?void 0:e}return K.call(r,t)?r[t]:void 0},X=Object.prototype.hasOwnProperty;var Y=function(t){var r=this.__data__;return B?void 0!==r[t]:X.call(r,t)};var J=function(t,r){var e=this.__data__;return this.size+=this.has(t)?0:1,e[t]=B&&void 0===r?"__lodash_hash_undefined__":r,this};function Z(t){var r=-1,e=null==t?0:t.length;for(this.clear();++r<e;){var n=t[r];this.set(n[0],n[1])}}Z.prototype.clear=G,Z.prototype.delete=$,Z.prototype.get=W,Z.prototype.has=Y,Z.prototype.set=J;var H=Z;var Q=function(){this.__data__=[],this.size=0};var tt=function(t,r){return t===r||t!=t&&r!=r};var rt=function(t,r){for(var e=t.length;e--;)if(tt(t[e][0],r))return e;return-1},et=Array.prototype.splice;var nt=function(t){var r=this.__data__,e=rt(r,t);return!(e<0)&&(e==r.length-1?r.pop():et.call(r,e,1),--this.size,!0)};var ot=function(t){var r=this.__data__,e=rt(r,t);return e<0?void 0:r[e][1]};var it=function(t){return rt(this.__data__,t)>-1};var st=function(t,r){var e=this.__data__,n=rt(e,t);return n<0?(++this.size,e.push([t,r])):e[n][1]=r,this};function at(t){var r=-1,e=null==t?0:t.length;for(this.clear();++r<e;){var n=t[r];this.set(n[0],n[1])}}at.prototype.clear=Q,at.prototype.delete=nt,at.prototype.get=ot,at.prototype.has=it,at.prototype.set=st;var ut=at,ct=U(f,"Map");var ft=function(){this.size=0,this.__data__={hash:new H,map:new(ct||ut),string:new H}};var ht=function(t){var r=e(t);return"string"==r||"number"==r||"symbol"==r||"boolean"==r?"__proto__"!==t:null===t};var lt=function(t,r){var e=t.__data__;return ht(r)?e["string"==typeof r?"string":"hash"]:e.map};var vt=function(t){var r=lt(this,t).delete(t);return this.size-=r?1:0,r};var mt=function(t){return lt(this,t).get(t)};var gt=function(t){return lt(this,t).has(t)};var pt=function(t,r){var e=lt(this,t),n=e.size;return e.set(t,r),this.size+=e.size==n?0:1,this};function dt(t){var r=-1,e=null==t?0:t.length;for(this.clear();++r<e;){var n=t[r];this.set(n[0],n[1])}}dt.prototype.clear=ft,dt.prototype.delete=vt,dt.prototype.get=mt,dt.prototype.has=gt,dt.prototype.set=pt;var wt=dt;function yt(t,r){if("function"!=typeof t||null!=r&&"function"!=typeof r)throw new TypeError("Expected a function");var e=function e(){var n=arguments,o=r?r.apply(this,n):n[0],i=e.cache;if(i.has(o))return i.get(o);var s=t.apply(this,n);return e.cache=i.set(o,s)||i,s};return e.cache=new(yt.Cache||wt),e}yt.Cache=wt;var bt=yt;var Mt=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,xt=/\\(\\)?/g,kt=function(t){var r=bt(t,(function(t){return 500===e.size&&e.clear(),t})),e=r.cache;return r}((function(t){var r=[];return 46===t.charCodeAt(0)&&r.push(""),t.replace(Mt,(function(t,e,n,o){r.push(n?o.replace(xt,"$1"):e||t)})),r}));var Et=function(t,r){for(var e=-1,n=null==t?0:t.length,o=Array(n);++e<n;)o[e]=r(t[e],e,t);return o},St=h?h.prototype:void 0,_t=St?St.toString:void 0;var jt=function t(r){if("string"==typeof r)return r;if(a(r))return Et(r,t)+"";if(x(r))return _t?_t.call(r):"";var e=r+"";return"0"==e&&1/r==-Infinity?"-0":e};var At=function(t){return null==t?"":jt(t)};var Rt=function(t,r){return a(t)?t:S(t,r)?[t]:kt(At(t))};var Ot=function(t){if("string"==typeof t||x(t))return t;var r=t+"";return"0"==r&&1/t==-Infinity?"-0":r};var Ct=function(t,r){for(var e=0,n=(r=Rt(r,t)).length;null!=t&&e<n;)t=t[Ot(r[e++])];return e&&e==n?t:void 0};var It=function(t,r,e){var n=null==t?void 0:Ct(t,r);return void 0===n?e:n},Nt=Object.prototype;var Ft=function(t){var r=t&&t.constructor;return t===("function"==typeof r&&r.prototype||Nt)};var Tt=function(t,r){return function(e){return t(r(e))}}(Object.keys,Object),Pt=Object.prototype.hasOwnProperty;var zt=function(t){if(!Ft(t))return Tt(t);var r=[];for(var e in Object(t))Pt.call(t,e)&&"constructor"!=e&&r.push(e);return r},Lt=U(f,"DataView"),Vt=U(f,"Promise"),qt=U(f,"Set"),Dt=U(f,"WeakMap"),Ut="[object Map]",Bt="[object Promise]",Gt="[object Set]",$t="[object WeakMap]",Kt="[object DataView]",Wt=N(Lt),Xt=N(ct),Yt=N(Vt),Jt=N(qt),Zt=N(Dt),Ht=b;(Lt&&Ht(new Lt(new ArrayBuffer(1)))!=Kt||ct&&Ht(new ct)!=Ut||Vt&&Ht(Vt.resolve())!=Bt||qt&&Ht(new qt)!=Gt||Dt&&Ht(new Dt)!=$t)&&(Ht=function(t){var r=b(t),e="[object Object]"==r?t.constructor:void 0,n=e?N(e):"";if(n)switch(n){case Wt:return Kt;case Xt:return Ut;case Yt:return Bt;case Jt:return Gt;case Zt:return $t}return r});var Qt=Ht;var tr=function(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=9007199254740991};var rr=function(t){return null!=t&&tr(t.length)&&!A(t)};var er=function(t){return"string"==typeof t||!a(t)&&M(t)&&"[object String]"==b(t)};var nr=function(t){return function(r){return null==r?void 0:r[t]}},or=nr("length"),ir=RegExp("[\\u200d\\ud800-\\udfff\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff\\ufe0e\\ufe0f]");var sr=function(t){return ir.test(t)},ar="[\\ud800-\\udfff]",ur="[\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff]",cr="\\ud83c[\\udffb-\\udfff]",fr="[^\\ud800-\\udfff]",hr="(?:\\ud83c[\\udde6-\\uddff]){2}",lr="[\\ud800-\\udbff][\\udc00-\\udfff]",vr="(?:"+ur+"|"+cr+")"+"?",mr="[\\ufe0e\\ufe0f]?",gr=mr+vr+("(?:\\u200d(?:"+[fr,hr,lr].join("|")+")"+mr+vr+")*"),pr="(?:"+[fr+ur+"?",ur,hr,lr,ar].join("|")+")",dr=RegExp(cr+"(?="+cr+")|"+pr+gr,"g");var wr=function(t){for(var r=dr.lastIndex=0;dr.test(t);)++r;return r};var yr=function(t){return sr(t)?wr(t):or(t)};var br=function(t){if(null==t)return 0;if(rr(t))return er(t)?yr(t):t.length;var r=Qt(t);return"[object Map]"==r||"[object Set]"==r?t.size:zt(t).length};var Mr=function(t){return"number"==typeof t||M(t)&&"[object Number]"==b(t)};var xr=function(t){return!0===t||!1===t||M(t)&&"[object Boolean]"==b(t)};function kr(t){return"[object Array]"===Object.prototype.toString.call(t)}function Er(t){return"[object Object]"===Object.prototype.toString.call(t)}function Sr(t){return"[object String]"===Object.prototype.toString.call(t)}function _r(t){return!!function(t){return"[object Undefined]"===Object.prototype.toString.call(t)}(t)||(!!function(t){return"[object Null]"===Object.prototype.toString.call(t)}(t)||(!!function(t){if(Er(t)){for(var r in t)return!1;return!0}return!1}(t)||(!!function(t){return!(!Sr(t)||""!==t)}(t)||!!function(t){return!!kr(t)&&0===t.length}(t))))}function jr(t){return!!kr(t)&&(0!==t.length&&(1!==t.length||!_r(t[0])))}function Ar(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")}function Rr(t,r){for(var e=0;e<r.length;e++){var n=r[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function Or(t,r,e){return r&&Rr(t.prototype,r),e&&Rr(t,e),t}function Cr(t,r){return(Cr=Object.setPrototypeOf||function(t,r){return t.__proto__=r,t})(t,r)}function Ir(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(r&&r.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),r&&Cr(t,r)}function Nr(t,r){return!r||"object"!==e(r)&&"function"!=typeof r?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):r}function Fr(t){return(Fr=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var Tr=Object.prototype.toString;function Pr(t){return Tr.call(t).endsWith("Array]")}function zr(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!Pr(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");var e=r.fromIndex,n=void 0===e?0:e,o=r.toIndex,i=void 0===o?t.length:o;if(n<0||n>=t.length||!Number.isInteger(n))throw new Error("fromIndex must be a positive integer smaller than length");if(i<=n||i>t.length||!Number.isInteger(i))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var s=t[n],a=n+1;a<i;a++)t[a]>s&&(s=t[a]);return s}function Lr(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!Pr(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");var e=r.fromIndex,n=void 0===e?0:e,o=r.toIndex,i=void 0===o?t.length:o;if(n<0||n>=t.length||!Number.isInteger(n))throw new Error("fromIndex must be a positive integer smaller than length");if(i<=n||i>t.length||!Number.isInteger(i))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var s=t[n],a=n+1;a<i;a++)t[a]<s&&(s=t[a]);return s}function Vr(t){var r,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!Pr(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");if(void 0!==e.output){if(!Pr(e.output))throw new TypeError("output option must be an array if specified");r=e.output}else r=new Array(t.length);var n=Lr(t),o=zr(t);if(n===o)throw new RangeError("minimum and maximum input values are equal. Cannot rescale a constant array");var i=e.min,s=void 0===i?e.autoMinMax?n:0:i,a=e.max,u=void 0===a?e.autoMinMax?o:1:a;if(s>=u)throw new RangeError("min option must be smaller than max option");for(var c=(u-s)/(o-n),f=0;f<t.length;f++)r[f]=(t[f]-n)*c+s;return r}var qr=" ".repeat(2),Dr=" ".repeat(4);function Ur(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},e=r.maxRows,n=void 0===e?15:e,o=r.maxColumns,i=void 0===o?10:o,s=r.maxNumSize,a=void 0===s?8:s;return"".concat(t.constructor.name," {\n").concat(qr,"[\n").concat(Dr).concat(Br(t,n,i,a),"\n").concat(qr,"]\n").concat(qr,"rows: ").concat(t.rows,"\n").concat(qr,"columns: ").concat(t.columns,"\n}")}function Br(t,r,e,n){for(var o=t.rows,i=t.columns,s=Math.min(o,r),a=Math.min(i,e),u=[],c=0;c<s;c++){for(var f=[],h=0;h<a;h++)f.push(Gr(t.get(c,h),n));u.push("".concat(f.join(" ")))}return a!==i&&(u[u.length-1]+=" ... ".concat(i-e," more columns")),s!==o&&u.push("... ".concat(o-r," more rows")),u.join("\n".concat(Dr))}function Gr(t,r){var e=String(t);if(e.length<=r)return e.padEnd(r," ");var n=t.toPrecision(r-2);if(n.length<=r)return n;var o=t.toExponential(r-2),i=o.indexOf("e"),s=o.slice(i);return o.slice(0,r-s.length)+s}function $r(t,r,e){var n=e?t.rows:t.rows-1;if(r<0||r>n)throw new RangeError("Row index out of range")}function Kr(t,r,e){var n=e?t.columns:t.columns-1;if(r<0||r>n)throw new RangeError("Column index out of range")}function Wr(t,r){if(r.to1DArray&&(r=r.to1DArray()),r.length!==t.columns)throw new RangeError("vector size must be the same as the number of columns");return r}function Xr(t,r){if(r.to1DArray&&(r=r.to1DArray()),r.length!==t.rows)throw new RangeError("vector size must be the same as the number of rows");return r}function Yr(t,r){if("object"!==e(r))throw new TypeError("unexpected type for row indices");if(r.some((function(r){return r<0||r>=t.rows})))throw new RangeError("row indices are out of range");return Array.isArray(r)||(r=Array.from(r)),r}function Jr(t,r){if("object"!==e(r))throw new TypeError("unexpected type for column indices");if(r.some((function(r){return r<0||r>=t.columns})))throw new RangeError("column indices are out of range");return Array.isArray(r)||(r=Array.from(r)),r}function Zr(t,r,e,n,o){if(5!==arguments.length)throw new RangeError("expected 4 arguments");if(Qr("startRow",r),Qr("endRow",e),Qr("startColumn",n),Qr("endColumn",o),r>e||n>o||r<0||r>=t.rows||e<0||e>=t.rows||n<0||n>=t.columns||o<0||o>=t.columns)throw new RangeError("Submatrix indices are out of range")}function Hr(t){for(var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,e=[],n=0;n<t;n++)e.push(r);return e}function Qr(t,r){if("number"!=typeof r)throw new TypeError("".concat(t," must be a number"))}function te(t){if(t.isEmpty())throw new Error("Empty matrix has no elements to index")}function re(t,r,e){for(var n=t.rows,o=t.columns,i=[],s=0;s<n;s++){for(var a=0,u=0,c=0,f=0;f<o;f++)a+=c=t.get(s,f)-e[s],u+=c*c;r?i.push((u-a*a/o)/(o-1)):i.push((u-a*a/o)/o)}return i}function ee(t,r,e){for(var n=t.rows,o=t.columns,i=[],s=0;s<o;s++){for(var a=0,u=0,c=0,f=0;f<n;f++)a+=c=t.get(f,s)-e[s],u+=c*c;r?i.push((u-a*a/n)/(n-1)):i.push((u-a*a/n)/n)}return i}function ne(t,r,e){for(var n=t.rows,o=t.columns,i=n*o,s=0,a=0,u=0,c=0;c<n;c++)for(var f=0;f<o;f++)s+=u=t.get(c,f)-e,a+=u*u;return r?(a-s*s/i)/(i-1):(a-s*s/i)/i}function oe(t,r){for(var e=0;e<t.rows;e++)for(var n=0;n<t.columns;n++)t.set(e,n,t.get(e,n)-r[e])}function ie(t,r){for(var e=0;e<t.rows;e++)for(var n=0;n<t.columns;n++)t.set(e,n,t.get(e,n)-r[n])}function se(t,r){for(var e=0;e<t.rows;e++)for(var n=0;n<t.columns;n++)t.set(e,n,t.get(e,n)-r)}function ae(t){for(var r=[],e=0;e<t.rows;e++){for(var n=0,o=0;o<t.columns;o++)n+=Math.pow(t.get(e,o),2)/(t.columns-1);r.push(Math.sqrt(n))}return r}function ue(t,r){for(var e=0;e<t.rows;e++)for(var n=0;n<t.columns;n++)t.set(e,n,t.get(e,n)/r[e])}function ce(t){for(var r=[],e=0;e<t.columns;e++){for(var n=0,o=0;o<t.rows;o++)n+=Math.pow(t.get(o,e),2)/(t.rows-1);r.push(Math.sqrt(n))}return r}function fe(t,r){for(var e=0;e<t.rows;e++)for(var n=0;n<t.columns;n++)t.set(e,n,t.get(e,n)/r[n])}function he(t){for(var r=t.size-1,e=0,n=0;n<t.columns;n++)for(var o=0;o<t.rows;o++)e+=Math.pow(t.get(o,n),2)/r;return Math.sqrt(e)}function le(t,r){for(var e=0;e<t.rows;e++)for(var n=0;n<t.columns;n++)t.set(e,n,t.get(e,n)/r)}function ve(t){var r=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var e,n=Fr(t);if(r){var o=Fr(this).constructor;e=Reflect.construct(n,arguments,o)}else e=n.apply(this,arguments);return Nr(this,e)}}var me=function(){function t(){Ar(this,t)}return Or(t,[{key:"size",get:function(){return this.rows*this.columns}},{key:"apply",value:function(t){if("function"!=typeof t)throw new TypeError("callback must be a function");for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)t.call(this,r,e);return this}},{key:"to1DArray",value:function(){for(var t=[],r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)t.push(this.get(r,e));return t}},{key:"to2DArray",value:function(){for(var t=[],r=0;r<this.rows;r++){t.push([]);for(var e=0;e<this.columns;e++)t[r].push(this.get(r,e))}return t}},{key:"toJSON",value:function(){return this.to2DArray()}},{key:"isRowVector",value:function(){return 1===this.rows}},{key:"isColumnVector",value:function(){return 1===this.columns}},{key:"isVector",value:function(){return 1===this.rows||1===this.columns}},{key:"isSquare",value:function(){return this.rows===this.columns}},{key:"isEmpty",value:function(){return 0===this.rows||0===this.columns}},{key:"isSymmetric",value:function(){if(this.isSquare()){for(var t=0;t<this.rows;t++)for(var r=0;r<=t;r++)if(this.get(t,r)!==this.get(r,t))return!1;return!0}return!1}},{key:"isEchelonForm",value:function(){for(var t=0,r=0,e=-1,n=!0,o=!1;t<this.rows&&n;){for(r=0,o=!1;r<this.columns&&!1===o;)0===this.get(t,r)?r++:1===this.get(t,r)&&r>e?(o=!0,e=r):(n=!1,o=!0);t++}return n}},{key:"isReducedEchelonForm",value:function(){for(var t=0,r=0,e=-1,n=!0,o=!1;t<this.rows&&n;){for(r=0,o=!1;r<this.columns&&!1===o;)0===this.get(t,r)?r++:1===this.get(t,r)&&r>e?(o=!0,e=r):(n=!1,o=!0);for(var i=r+1;i<this.rows;i++)0!==this.get(t,i)&&(n=!1);t++}return n}},{key:"echelonForm",value:function(){for(var t=this.clone(),r=0,e=0;r<t.rows&&e<t.columns;){for(var n=r,o=r;o<t.rows;o++)t.get(o,e)>t.get(n,e)&&(n=o);if(0===t.get(n,e))e++;else{t.swapRows(r,n);for(var i=t.get(r,e),s=e;s<t.columns;s++)t.set(r,s,t.get(r,s)/i);for(var a=r+1;a<t.rows;a++){var u=t.get(a,e)/t.get(r,e);t.set(a,e,0);for(var c=e+1;c<t.columns;c++)t.set(a,c,t.get(a,c)-t.get(r,c)*u)}r++,e++}}return t}},{key:"reducedEchelonForm",value:function(){for(var t=this.echelonForm(),r=t.columns,e=t.rows,n=e-1;n>=0;)if(0===t.maxRow(n))n--;else{for(var o=0,i=!1;o<e&&!1===i;)1===t.get(n,o)?i=!0:o++;for(var s=0;s<n;s++)for(var a=t.get(s,o),u=o;u<r;u++){var c=t.get(s,u)-a*t.get(n,u);t.set(s,u,c)}n--}return t}},{key:"set",value:function(){throw new Error("set method is unimplemented")}},{key:"get",value:function(){throw new Error("get method is unimplemented")}},{key:"repeat",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if("object"!==e(t))throw new TypeError("options must be an object");var r=t.rows,n=void 0===r?1:r,o=t.columns,i=void 0===o?1:o;if(!Number.isInteger(n)||n<=0)throw new TypeError("rows must be a positive integer");if(!Number.isInteger(i)||i<=0)throw new TypeError("columns must be a positive integer");for(var s=new pe(this.rows*n,this.columns*i),a=0;a<n;a++)for(var u=0;u<i;u++)s.setSubMatrix(this,this.rows*a,this.columns*u);return s}},{key:"fill",value:function(t){for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,t);return this}},{key:"neg",value:function(){return this.mulS(-1)}},{key:"getRow",value:function(t){$r(this,t);for(var r=[],e=0;e<this.columns;e++)r.push(this.get(t,e));return r}},{key:"getRowVector",value:function(t){return pe.rowVector(this.getRow(t))}},{key:"setRow",value:function(t,r){$r(this,t),r=Wr(this,r);for(var e=0;e<this.columns;e++)this.set(t,e,r[e]);return this}},{key:"swapRows",value:function(t,r){$r(this,t),$r(this,r);for(var e=0;e<this.columns;e++){var n=this.get(t,e);this.set(t,e,this.get(r,e)),this.set(r,e,n)}return this}},{key:"getColumn",value:function(t){Kr(this,t);for(var r=[],e=0;e<this.rows;e++)r.push(this.get(e,t));return r}},{key:"getColumnVector",value:function(t){return pe.columnVector(this.getColumn(t))}},{key:"setColumn",value:function(t,r){Kr(this,t),r=Xr(this,r);for(var e=0;e<this.rows;e++)this.set(e,t,r[e]);return this}},{key:"swapColumns",value:function(t,r){Kr(this,t),Kr(this,r);for(var e=0;e<this.rows;e++){var n=this.get(e,t);this.set(e,t,this.get(e,r)),this.set(e,r,n)}return this}},{key:"addRowVector",value:function(t){t=Wr(this,t);for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)+t[e]);return this}},{key:"subRowVector",value:function(t){t=Wr(this,t);for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)-t[e]);return this}},{key:"mulRowVector",value:function(t){t=Wr(this,t);for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)*t[e]);return this}},{key:"divRowVector",value:function(t){t=Wr(this,t);for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)/t[e]);return this}},{key:"addColumnVector",value:function(t){t=Xr(this,t);for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)+t[r]);return this}},{key:"subColumnVector",value:function(t){t=Xr(this,t);for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)-t[r]);return this}},{key:"mulColumnVector",value:function(t){t=Xr(this,t);for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)*t[r]);return this}},{key:"divColumnVector",value:function(t){t=Xr(this,t);for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)/t[r]);return this}},{key:"mulRow",value:function(t,r){$r(this,t);for(var e=0;e<this.columns;e++)this.set(t,e,this.get(t,e)*r);return this}},{key:"mulColumn",value:function(t,r){Kr(this,t);for(var e=0;e<this.rows;e++)this.set(e,t,this.get(e,t)*r);return this}},{key:"max",value:function(){if(this.isEmpty())return NaN;for(var t=this.get(0,0),r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.get(r,e)>t&&(t=this.get(r,e));return t}},{key:"maxIndex",value:function(){te(this);for(var t=this.get(0,0),r=[0,0],e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)this.get(e,n)>t&&(t=this.get(e,n),r[0]=e,r[1]=n);return r}},{key:"min",value:function(){if(this.isEmpty())return NaN;for(var t=this.get(0,0),r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.get(r,e)<t&&(t=this.get(r,e));return t}},{key:"minIndex",value:function(){te(this);for(var t=this.get(0,0),r=[0,0],e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)this.get(e,n)<t&&(t=this.get(e,n),r[0]=e,r[1]=n);return r}},{key:"maxRow",value:function(t){if($r(this,t),this.isEmpty())return NaN;for(var r=this.get(t,0),e=1;e<this.columns;e++)this.get(t,e)>r&&(r=this.get(t,e));return r}},{key:"maxRowIndex",value:function(t){$r(this,t),te(this);for(var r=this.get(t,0),e=[t,0],n=1;n<this.columns;n++)this.get(t,n)>r&&(r=this.get(t,n),e[1]=n);return e}},{key:"minRow",value:function(t){if($r(this,t),this.isEmpty())return NaN;for(var r=this.get(t,0),e=1;e<this.columns;e++)this.get(t,e)<r&&(r=this.get(t,e));return r}},{key:"minRowIndex",value:function(t){$r(this,t),te(this);for(var r=this.get(t,0),e=[t,0],n=1;n<this.columns;n++)this.get(t,n)<r&&(r=this.get(t,n),e[1]=n);return e}},{key:"maxColumn",value:function(t){if(Kr(this,t),this.isEmpty())return NaN;for(var r=this.get(0,t),e=1;e<this.rows;e++)this.get(e,t)>r&&(r=this.get(e,t));return r}},{key:"maxColumnIndex",value:function(t){Kr(this,t),te(this);for(var r=this.get(0,t),e=[0,t],n=1;n<this.rows;n++)this.get(n,t)>r&&(r=this.get(n,t),e[0]=n);return e}},{key:"minColumn",value:function(t){if(Kr(this,t),this.isEmpty())return NaN;for(var r=this.get(0,t),e=1;e<this.rows;e++)this.get(e,t)<r&&(r=this.get(e,t));return r}},{key:"minColumnIndex",value:function(t){Kr(this,t),te(this);for(var r=this.get(0,t),e=[0,t],n=1;n<this.rows;n++)this.get(n,t)<r&&(r=this.get(n,t),e[0]=n);return e}},{key:"diag",value:function(){for(var t=Math.min(this.rows,this.columns),r=[],e=0;e<t;e++)r.push(this.get(e,e));return r}},{key:"norm",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"frobenius",r=0;if("max"===t)return this.max();if("frobenius"===t){for(var e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)r+=this.get(e,n)*this.get(e,n);return Math.sqrt(r)}throw new RangeError("unknown norm type: ".concat(t))}},{key:"cumulativeSum",value:function(){for(var t=0,r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)t+=this.get(r,e),this.set(r,e,t);return this}},{key:"dot",value:function(r){t.isMatrix(r)&&(r=r.to1DArray());var e=this.to1DArray();if(e.length!==r.length)throw new RangeError("vectors do not have the same size");for(var n=0,o=0;o<e.length;o++)n+=e[o]*r[o];return n}},{key:"mmul",value:function(t){t=pe.checkMatrix(t);for(var r=this.rows,e=this.columns,n=t.columns,o=new pe(r,n),i=new Float64Array(e),s=0;s<n;s++){for(var a=0;a<e;a++)i[a]=t.get(a,s);for(var u=0;u<r;u++){for(var c=0,f=0;f<e;f++)c+=this.get(u,f)*i[f];o.set(u,s,c)}}return o}},{key:"strassen2x2",value:function(t){t=pe.checkMatrix(t);var r=new pe(2,2),e=this.get(0,0),n=t.get(0,0),o=this.get(0,1),i=t.get(0,1),s=this.get(1,0),a=t.get(1,0),u=this.get(1,1),c=t.get(1,1),f=(e+u)*(n+c),h=(s+u)*n,l=e*(i-c),v=u*(a-n),m=(e+o)*c,g=f+v-m+(o-u)*(a+c),p=l+m,d=h+v,w=f-h+l+(s-e)*(n+i);return r.set(0,0,g),r.set(0,1,p),r.set(1,0,d),r.set(1,1,w),r}},{key:"strassen3x3",value:function(t){t=pe.checkMatrix(t);var r=new pe(3,3),e=this.get(0,0),n=this.get(0,1),o=this.get(0,2),i=this.get(1,0),s=this.get(1,1),a=this.get(1,2),u=this.get(2,0),c=this.get(2,1),f=this.get(2,2),h=t.get(0,0),l=t.get(0,1),v=t.get(0,2),m=t.get(1,0),g=t.get(1,1),p=t.get(1,2),d=t.get(2,0),w=t.get(2,1),y=t.get(2,2),b=(e-i)*(-l+g),M=(-e+i+s)*(h-l+g),x=(i+s)*(-h+l),k=e*h,E=(-e+u+c)*(h-v+p),S=(-e+u)*(v-p),_=(u+c)*(-h+v),j=(-o+c+f)*(g+d-w),A=(o-f)*(g-w),R=o*d,O=(c+f)*(-d+w),C=(-o+s+a)*(p+d-y),I=(o-a)*(p-y),N=(s+a)*(-d+y),F=k+R+n*m,T=(e+n+o-i-s-c-f)*g+M+x+k+j+R+O,P=k+E+_+(e+n+o-s-a-u-c)*p+R+C+N,z=b+s*(-h+l+m-g-p-d+y)+M+k+R+C+I,L=b+M+x+k+a*w,V=R+C+I+N+i*v,q=k+E+S+c*(-h+v+m-g-p-d+w)+j+A+R,D=j+A+R+O+u*l,U=k+E+S+_+f*y;return r.set(0,0,F),r.set(0,1,T),r.set(0,2,P),r.set(1,0,z),r.set(1,1,L),r.set(1,2,V),r.set(2,0,q),r.set(2,1,D),r.set(2,2,U),r}},{key:"mmulStrassen",value:function(r){r=pe.checkMatrix(r);var e=this.clone(),n=e.rows,o=e.columns,i=r.rows,s=r.columns;function a(r,e,n){var o=r.rows,i=r.columns;if(o===e&&i===n)return r;var s=t.zeros(e,n);return s=s.setSubMatrix(r,0,0)}o!==i&&console.warn("Multiplying ".concat(n," x ").concat(o," and ").concat(i," x ").concat(s," matrix: dimensions do not match."));var u=Math.max(n,i),c=Math.max(o,s);return function r(e,n,o,i){if(o<=512||i<=512)return e.mmul(n);o%2==1&&i%2==1?(e=a(e,o+1,i+1),n=a(n,o+1,i+1)):o%2==1?(e=a(e,o+1,i),n=a(n,o+1,i)):i%2==1&&(e=a(e,o,i+1),n=a(n,o,i+1));var s=parseInt(e.rows/2,10),u=parseInt(e.columns/2,10),c=e.subMatrix(0,s-1,0,u-1),f=n.subMatrix(0,s-1,0,u-1),h=e.subMatrix(0,s-1,u,e.columns-1),l=n.subMatrix(0,s-1,u,n.columns-1),v=e.subMatrix(s,e.rows-1,0,u-1),m=n.subMatrix(s,n.rows-1,0,u-1),g=e.subMatrix(s,e.rows-1,u,e.columns-1),p=n.subMatrix(s,n.rows-1,u,n.columns-1),d=r(t.add(c,g),t.add(f,p),s,u),w=r(t.add(v,g),f,s,u),y=r(c,t.sub(l,p),s,u),b=r(g,t.sub(m,f),s,u),M=r(t.add(c,h),p,s,u),x=r(t.sub(v,c),t.add(f,l),s,u),k=r(t.sub(h,g),t.add(m,p),s,u),E=t.add(d,b);E.sub(M),E.add(k);var S=t.add(y,M),_=t.add(w,b),j=t.sub(d,w);j.add(y),j.add(x);var A=t.zeros(2*E.rows,2*E.columns);return(A=(A=(A=(A=A.setSubMatrix(E,0,0)).setSubMatrix(S,E.rows,0)).setSubMatrix(_,0,E.columns)).setSubMatrix(j,E.rows,E.columns)).subMatrix(0,o-1,0,i-1)}(e=a(e,u,c),r=a(r,u,c),u,c)}},{key:"scaleRows",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if("object"!==e(t))throw new TypeError("options must be an object");var r=t.min,n=void 0===r?0:r,o=t.max,i=void 0===o?1:o;if(!Number.isFinite(n))throw new TypeError("min must be a number");if(!Number.isFinite(i))throw new TypeError("max must be a number");if(n>=i)throw new RangeError("min must be smaller than max");for(var s=new pe(this.rows,this.columns),a=0;a<this.rows;a++){var u=this.getRow(a);u.length>0&&Vr(u,{min:n,max:i,output:u}),s.setRow(a,u)}return s}},{key:"scaleColumns",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if("object"!==e(t))throw new TypeError("options must be an object");var r=t.min,n=void 0===r?0:r,o=t.max,i=void 0===o?1:o;if(!Number.isFinite(n))throw new TypeError("min must be a number");if(!Number.isFinite(i))throw new TypeError("max must be a number");if(n>=i)throw new RangeError("min must be smaller than max");for(var s=new pe(this.rows,this.columns),a=0;a<this.columns;a++){var u=this.getColumn(a);u.length&&Vr(u,{min:n,max:i,output:u}),s.setColumn(a,u)}return s}},{key:"flipRows",value:function(){for(var t=Math.ceil(this.columns/2),r=0;r<this.rows;r++)for(var e=0;e<t;e++){var n=this.get(r,e),o=this.get(r,this.columns-1-e);this.set(r,e,o),this.set(r,this.columns-1-e,n)}return this}},{key:"flipColumns",value:function(){for(var t=Math.ceil(this.rows/2),r=0;r<this.columns;r++)for(var e=0;e<t;e++){var n=this.get(e,r),o=this.get(this.rows-1-e,r);this.set(e,r,o),this.set(this.rows-1-e,r,n)}return this}},{key:"kroneckerProduct",value:function(t){t=pe.checkMatrix(t);for(var r=this.rows,e=this.columns,n=t.rows,o=t.columns,i=new pe(r*n,e*o),s=0;s<r;s++)for(var a=0;a<e;a++)for(var u=0;u<n;u++)for(var c=0;c<o;c++)i.set(n*s+u,o*a+c,this.get(s,a)*t.get(u,c));return i}},{key:"kroneckerSum",value:function(t){if(t=pe.checkMatrix(t),!this.isSquare()||!t.isSquare())throw new Error("Kronecker Sum needs two Square Matrices");var r=this.rows,e=t.rows,n=this.kroneckerProduct(pe.eye(e,e)),o=pe.eye(r,r).kroneckerProduct(t);return n.add(o)}},{key:"transpose",value:function(){for(var t=new pe(this.columns,this.rows),r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)t.set(e,r,this.get(r,e));return t}},{key:"sortRows",value:function(){for(var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:ge,r=0;r<this.rows;r++)this.setRow(r,this.getRow(r).sort(t));return this}},{key:"sortColumns",value:function(){for(var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:ge,r=0;r<this.columns;r++)this.setColumn(r,this.getColumn(r).sort(t));return this}},{key:"subMatrix",value:function(t,r,e,n){Zr(this,t,r,e,n);for(var o=new pe(r-t+1,n-e+1),i=t;i<=r;i++)for(var s=e;s<=n;s++)o.set(i-t,s-e,this.get(i,s));return o}},{key:"subMatrixRow",value:function(t,r,e){if(void 0===r&&(r=0),void 0===e&&(e=this.columns-1),r>e||r<0||r>=this.columns||e<0||e>=this.columns)throw new RangeError("Argument out of range");for(var n=new pe(t.length,e-r+1),o=0;o<t.length;o++)for(var i=r;i<=e;i++){if(t[o]<0||t[o]>=this.rows)throw new RangeError("Row index out of range: ".concat(t[o]));n.set(o,i-r,this.get(t[o],i))}return n}},{key:"subMatrixColumn",value:function(t,r,e){if(void 0===r&&(r=0),void 0===e&&(e=this.rows-1),r>e||r<0||r>=this.rows||e<0||e>=this.rows)throw new RangeError("Argument out of range");for(var n=new pe(e-r+1,t.length),o=0;o<t.length;o++)for(var i=r;i<=e;i++){if(t[o]<0||t[o]>=this.columns)throw new RangeError("Column index out of range: ".concat(t[o]));n.set(i-r,o,this.get(i,t[o]))}return n}},{key:"setSubMatrix",value:function(t,r,e){if((t=pe.checkMatrix(t)).isEmpty())return this;Zr(this,r,r+t.rows-1,e,e+t.columns-1);for(var n=0;n<t.rows;n++)for(var o=0;o<t.columns;o++)this.set(r+n,e+o,t.get(n,o));return this}},{key:"selection",value:function(t,r){for(var e=function(t,r,e){return{row:Yr(t,r),column:Jr(t,e)}}(this,t,r),n=new pe(t.length,r.length),o=0;o<e.row.length;o++)for(var i=e.row[o],s=0;s<e.column.length;s++){var a=e.column[s];n.set(o,s,this.get(i,a))}return n}},{key:"trace",value:function(){for(var t=Math.min(this.rows,this.columns),r=0,e=0;e<t;e++)r+=this.get(e,e);return r}},{key:"clone",value:function(){for(var t=new pe(this.rows,this.columns),r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)t.set(r,e,this.get(r,e));return t}},{key:"sum",value:function(t){switch(t){case"row":return function(t){for(var r=Hr(t.rows),e=0;e<t.rows;++e)for(var n=0;n<t.columns;++n)r[e]+=t.get(e,n);return r}(this);case"column":return function(t){for(var r=Hr(t.columns),e=0;e<t.rows;++e)for(var n=0;n<t.columns;++n)r[n]+=t.get(e,n);return r}(this);case void 0:return function(t){for(var r=0,e=0;e<t.rows;e++)for(var n=0;n<t.columns;n++)r+=t.get(e,n);return r}(this);default:throw new Error("invalid option: ".concat(t))}}},{key:"product",value:function(t){switch(t){case"row":return function(t){for(var r=Hr(t.rows,1),e=0;e<t.rows;++e)for(var n=0;n<t.columns;++n)r[e]*=t.get(e,n);return r}(this);case"column":return function(t){for(var r=Hr(t.columns,1),e=0;e<t.rows;++e)for(var n=0;n<t.columns;++n)r[n]*=t.get(e,n);return r}(this);case void 0:return function(t){for(var r=1,e=0;e<t.rows;e++)for(var n=0;n<t.columns;n++)r*=t.get(e,n);return r}(this);default:throw new Error("invalid option: ".concat(t))}}},{key:"mean",value:function(t){var r=this.sum(t);switch(t){case"row":for(var e=0;e<this.rows;e++)r[e]/=this.columns;return r;case"column":for(var n=0;n<this.columns;n++)r[n]/=this.rows;return r;case void 0:return r/this.size;default:throw new Error("invalid option: ".concat(t))}}},{key:"variance",value:function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if("object"===e(t)&&(r=t,t=void 0),"object"!==e(r))throw new TypeError("options must be an object");var n=r,o=n.unbiased,i=void 0===o||o,s=n.mean,a=void 0===s?this.mean(t):s;if("boolean"!=typeof i)throw new TypeError("unbiased must be a boolean");switch(t){case"row":if(!Array.isArray(a))throw new TypeError("mean must be an array");return re(this,i,a);case"column":if(!Array.isArray(a))throw new TypeError("mean must be an array");return ee(this,i,a);case void 0:if("number"!=typeof a)throw new TypeError("mean must be a number");return ne(this,i,a);default:throw new Error("invalid option: ".concat(t))}}},{key:"standardDeviation",value:function(t,r){"object"===e(t)&&(r=t,t=void 0);var n=this.variance(t,r);if(void 0===t)return Math.sqrt(n);for(var o=0;o<n.length;o++)n[o]=Math.sqrt(n[o]);return n}},{key:"center",value:function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if("object"===e(t)&&(r=t,t=void 0),"object"!==e(r))throw new TypeError("options must be an object");var n=r,o=n.center,i=void 0===o?this.mean(t):o;switch(t){case"row":if(!Array.isArray(i))throw new TypeError("center must be an array");return oe(this,i),this;case"column":if(!Array.isArray(i))throw new TypeError("center must be an array");return ie(this,i),this;case void 0:if("number"!=typeof i)throw new TypeError("center must be a number");return se(this,i),this;default:throw new Error("invalid option: ".concat(t))}}},{key:"scale",value:function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if("object"===e(t)&&(r=t,t=void 0),"object"!==e(r))throw new TypeError("options must be an object");var n=r.scale;switch(t){case"row":if(void 0===n)n=ae(this);else if(!Array.isArray(n))throw new TypeError("scale must be an array");return ue(this,n),this;case"column":if(void 0===n)n=ce(this);else if(!Array.isArray(n))throw new TypeError("scale must be an array");return fe(this,n),this;case void 0:if(void 0===n)n=he(this);else if("number"!=typeof n)throw new TypeError("scale must be a number");return le(this,n),this;default:throw new Error("invalid option: ".concat(t))}}},{key:"toString",value:function(t){return Ur(this,t)}}],[{key:"from1DArray",value:function(t,r,e){if(t*r!==e.length)throw new RangeError("data length does not match given dimensions");for(var n=new pe(t,r),o=0;o<t;o++)for(var i=0;i<r;i++)n.set(o,i,e[o*r+i]);return n}},{key:"rowVector",value:function(t){for(var r=new pe(1,t.length),e=0;e<t.length;e++)r.set(0,e,t[e]);return r}},{key:"columnVector",value:function(t){for(var r=new pe(t.length,1),e=0;e<t.length;e++)r.set(e,0,t[e]);return r}},{key:"zeros",value:function(t,r){return new pe(t,r)}},{key:"ones",value:function(t,r){return new pe(t,r).fill(1)}},{key:"rand",value:function(t,r){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("object"!==e(n))throw new TypeError("options must be an object");for(var o=n.random,i=void 0===o?Math.random:o,s=new pe(t,r),a=0;a<t;a++)for(var u=0;u<r;u++)s.set(a,u,i());return s}},{key:"randInt",value:function(t,r){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("object"!==e(n))throw new TypeError("options must be an object");var o=n.min,i=void 0===o?0:o,s=n.max,a=void 0===s?1e3:s,u=n.random,c=void 0===u?Math.random:u;if(!Number.isInteger(i))throw new TypeError("min must be an integer");if(!Number.isInteger(a))throw new TypeError("max must be an integer");if(i>=a)throw new RangeError("min must be smaller than max");for(var f=a-i,h=new pe(t,r),l=0;l<t;l++)for(var v=0;v<r;v++){var m=i+Math.round(c()*f);h.set(l,v,m)}return h}},{key:"eye",value:function(t,r,e){void 0===r&&(r=t),void 0===e&&(e=1);for(var n=Math.min(t,r),o=this.zeros(t,r),i=0;i<n;i++)o.set(i,i,e);return o}},{key:"diag",value:function(t,r,e){var n=t.length;void 0===r&&(r=n),void 0===e&&(e=r);for(var o=Math.min(n,r,e),i=this.zeros(r,e),s=0;s<o;s++)i.set(s,s,t[s]);return i}},{key:"min",value:function(t,r){t=this.checkMatrix(t),r=this.checkMatrix(r);for(var e=t.rows,n=t.columns,o=new pe(e,n),i=0;i<e;i++)for(var s=0;s<n;s++)o.set(i,s,Math.min(t.get(i,s),r.get(i,s)));return o}},{key:"max",value:function(t,r){t=this.checkMatrix(t),r=this.checkMatrix(r);for(var e=t.rows,n=t.columns,o=new this(e,n),i=0;i<e;i++)for(var s=0;s<n;s++)o.set(i,s,Math.max(t.get(i,s),r.get(i,s)));return o}},{key:"checkMatrix",value:function(r){return t.isMatrix(r)?r:new pe(r)}},{key:"isMatrix",value:function(t){return null!=t&&"Matrix"===t.klass}}]),t}();function ge(t,r){return t-r}me.prototype.klass="Matrix","undefined"!=typeof Symbol&&(me.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return Ur(this)}),me.random=me.rand,me.randomInt=me.randInt,me.diagonal=me.diag,me.prototype.diagonal=me.prototype.diag,me.identity=me.eye,me.prototype.negate=me.prototype.neg,me.prototype.tensorProduct=me.prototype.kroneckerProduct;var pe=function(t){Ir(e,t);var r=ve(e);function e(t,n){var o;if(Ar(this,e),o=r.call(this),e.isMatrix(t))return Nr(o,t.clone());if(Number.isInteger(t)&&t>=0){if(o.data=[],!(Number.isInteger(n)&&n>=0))throw new TypeError("nColumns must be a positive integer");for(var i=0;i<t;i++)o.data.push(new Float64Array(n))}else{if(!Array.isArray(t))throw new TypeError("First argument must be a positive number or an array");var s=t;if("number"!=typeof(n=(t=s.length)?s[0].length:0))throw new TypeError("Data must be a 2D array with at least one element");o.data=[];for(var a=0;a<t;a++){if(s[a].length!==n)throw new RangeError("Inconsistent array dimensions");o.data.push(Float64Array.from(s[a]))}}return o.rows=t,o.columns=n,o}return Or(e,[{key:"set",value:function(t,r,e){return this.data[t][r]=e,this}},{key:"get",value:function(t,r){return this.data[t][r]}},{key:"removeRow",value:function(t){return $r(this,t),this.data.splice(t,1),this.rows-=1,this}},{key:"addRow",value:function(t,r){return void 0===r&&(r=t,t=this.rows),$r(this,t,!0),r=Float64Array.from(Wr(this,r)),this.data.splice(t,0,r),this.rows+=1,this}},{key:"removeColumn",value:function(t){Kr(this,t);for(var r=0;r<this.rows;r++){for(var e=new Float64Array(this.columns-1),n=0;n<t;n++)e[n]=this.data[r][n];for(var o=t+1;o<this.columns;o++)e[o-1]=this.data[r][o];this.data[r]=e}return this.columns-=1,this}},{key:"addColumn",value:function(t,r){void 0===r&&(r=t,t=this.columns),Kr(this,t,!0),r=Xr(this,r);for(var e=0;e<this.rows;e++){for(var n=new Float64Array(this.columns+1),o=0;o<t;o++)n[o]=this.data[e][o];for(n[o++]=r[e];o<this.columns+1;o++)n[o]=this.data[e][o-1];this.data[e]=n}return this.columns+=1,this}}]),e}(me);function de(t){var r=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var e,n=Fr(t);if(r){var o=Fr(this).constructor;e=Reflect.construct(n,arguments,o)}else e=n.apply(this,arguments);return Nr(this,e)}}function we(t){var r=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var e,n=Fr(t);if(r){var o=Fr(this).constructor;e=Reflect.construct(n,arguments,o)}else e=n.apply(this,arguments);return Nr(this,e)}}!function(t,r){t.prototype.add=function(t){return"number"==typeof t?this.addS(t):this.addM(t)},t.prototype.addS=function(t){for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)+t);return this},t.prototype.addM=function(t){if(t=r.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(var e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)this.set(e,n,this.get(e,n)+t.get(e,n));return this},t.add=function(t,e){return new r(t).add(e)},t.prototype.sub=function(t){return"number"==typeof t?this.subS(t):this.subM(t)},t.prototype.subS=function(t){for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)-t);return this},t.prototype.subM=function(t){if(t=r.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(var e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)this.set(e,n,this.get(e,n)-t.get(e,n));return this},t.sub=function(t,e){return new r(t).sub(e)},t.prototype.subtract=t.prototype.sub,t.prototype.subtractS=t.prototype.subS,t.prototype.subtractM=t.prototype.subM,t.subtract=t.sub,t.prototype.mul=function(t){return"number"==typeof t?this.mulS(t):this.mulM(t)},t.prototype.mulS=function(t){for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)*t);return this},t.prototype.mulM=function(t){if(t=r.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(var e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)this.set(e,n,this.get(e,n)*t.get(e,n));return this},t.mul=function(t,e){return new r(t).mul(e)},t.prototype.multiply=t.prototype.mul,t.prototype.multiplyS=t.prototype.mulS,t.prototype.multiplyM=t.prototype.mulM,t.multiply=t.mul,t.prototype.div=function(t){return"number"==typeof t?this.divS(t):this.divM(t)},t.prototype.divS=function(t){for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)/t);return this},t.prototype.divM=function(t){if(t=r.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(var e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)this.set(e,n,this.get(e,n)/t.get(e,n));return this},t.div=function(t,e){return new r(t).div(e)},t.prototype.divide=t.prototype.div,t.prototype.divideS=t.prototype.divS,t.prototype.divideM=t.prototype.divM,t.divide=t.div,t.prototype.mod=function(t){return"number"==typeof t?this.modS(t):this.modM(t)},t.prototype.modS=function(t){for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)%t);return this},t.prototype.modM=function(t){if(t=r.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(var e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)this.set(e,n,this.get(e,n)%t.get(e,n));return this},t.mod=function(t,e){return new r(t).mod(e)},t.prototype.modulus=t.prototype.mod,t.prototype.modulusS=t.prototype.modS,t.prototype.modulusM=t.prototype.modM,t.modulus=t.mod,t.prototype.and=function(t){return"number"==typeof t?this.andS(t):this.andM(t)},t.prototype.andS=function(t){for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)&t);return this},t.prototype.andM=function(t){if(t=r.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(var e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)this.set(e,n,this.get(e,n)&t.get(e,n));return this},t.and=function(t,e){return new r(t).and(e)},t.prototype.or=function(t){return"number"==typeof t?this.orS(t):this.orM(t)},t.prototype.orS=function(t){for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)|t);return this},t.prototype.orM=function(t){if(t=r.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(var e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)this.set(e,n,this.get(e,n)|t.get(e,n));return this},t.or=function(t,e){return new r(t).or(e)},t.prototype.xor=function(t){return"number"==typeof t?this.xorS(t):this.xorM(t)},t.prototype.xorS=function(t){for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)^t);return this},t.prototype.xorM=function(t){if(t=r.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(var e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)this.set(e,n,this.get(e,n)^t.get(e,n));return this},t.xor=function(t,e){return new r(t).xor(e)},t.prototype.leftShift=function(t){return"number"==typeof t?this.leftShiftS(t):this.leftShiftM(t)},t.prototype.leftShiftS=function(t){for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)<<t);return this},t.prototype.leftShiftM=function(t){if(t=r.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(var e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)this.set(e,n,this.get(e,n)<<t.get(e,n));return this},t.leftShift=function(t,e){return new r(t).leftShift(e)},t.prototype.signPropagatingRightShift=function(t){return"number"==typeof t?this.signPropagatingRightShiftS(t):this.signPropagatingRightShiftM(t)},t.prototype.signPropagatingRightShiftS=function(t){for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)>>t);return this},t.prototype.signPropagatingRightShiftM=function(t){if(t=r.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(var e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)this.set(e,n,this.get(e,n)>>t.get(e,n));return this},t.signPropagatingRightShift=function(t,e){return new r(t).signPropagatingRightShift(e)},t.prototype.rightShift=function(t){return"number"==typeof t?this.rightShiftS(t):this.rightShiftM(t)},t.prototype.rightShiftS=function(t){for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)>>>t);return this},t.prototype.rightShiftM=function(t){if(t=r.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(var e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)this.set(e,n,this.get(e,n)>>>t.get(e,n));return this},t.rightShift=function(t,e){return new r(t).rightShift(e)},t.prototype.zeroFillRightShift=t.prototype.rightShift,t.prototype.zeroFillRightShiftS=t.prototype.rightShiftS,t.prototype.zeroFillRightShiftM=t.prototype.rightShiftM,t.zeroFillRightShift=t.rightShift,t.prototype.not=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,~this.get(t,r));return this},t.not=function(t){return new r(t).not()},t.prototype.abs=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.abs(this.get(t,r)));return this},t.abs=function(t){return new r(t).abs()},t.prototype.acos=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.acos(this.get(t,r)));return this},t.acos=function(t){return new r(t).acos()},t.prototype.acosh=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.acosh(this.get(t,r)));return this},t.acosh=function(t){return new r(t).acosh()},t.prototype.asin=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.asin(this.get(t,r)));return this},t.asin=function(t){return new r(t).asin()},t.prototype.asinh=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.asinh(this.get(t,r)));return this},t.asinh=function(t){return new r(t).asinh()},t.prototype.atan=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.atan(this.get(t,r)));return this},t.atan=function(t){return new r(t).atan()},t.prototype.atanh=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.atanh(this.get(t,r)));return this},t.atanh=function(t){return new r(t).atanh()},t.prototype.cbrt=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.cbrt(this.get(t,r)));return this},t.cbrt=function(t){return new r(t).cbrt()},t.prototype.ceil=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.ceil(this.get(t,r)));return this},t.ceil=function(t){return new r(t).ceil()},t.prototype.clz32=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.clz32(this.get(t,r)));return this},t.clz32=function(t){return new r(t).clz32()},t.prototype.cos=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.cos(this.get(t,r)));return this},t.cos=function(t){return new r(t).cos()},t.prototype.cosh=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.cosh(this.get(t,r)));return this},t.cosh=function(t){return new r(t).cosh()},t.prototype.exp=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.exp(this.get(t,r)));return this},t.exp=function(t){return new r(t).exp()},t.prototype.expm1=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.expm1(this.get(t,r)));return this},t.expm1=function(t){return new r(t).expm1()},t.prototype.floor=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.floor(this.get(t,r)));return this},t.floor=function(t){return new r(t).floor()},t.prototype.fround=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.fround(this.get(t,r)));return this},t.fround=function(t){return new r(t).fround()},t.prototype.log=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.log(this.get(t,r)));return this},t.log=function(t){return new r(t).log()},t.prototype.log1p=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.log1p(this.get(t,r)));return this},t.log1p=function(t){return new r(t).log1p()},t.prototype.log10=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.log10(this.get(t,r)));return this},t.log10=function(t){return new r(t).log10()},t.prototype.log2=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.log2(this.get(t,r)));return this},t.log2=function(t){return new r(t).log2()},t.prototype.round=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.round(this.get(t,r)));return this},t.round=function(t){return new r(t).round()},t.prototype.sign=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.sign(this.get(t,r)));return this},t.sign=function(t){return new r(t).sign()},t.prototype.sin=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.sin(this.get(t,r)));return this},t.sin=function(t){return new r(t).sin()},t.prototype.sinh=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.sinh(this.get(t,r)));return this},t.sinh=function(t){return new r(t).sinh()},t.prototype.sqrt=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.sqrt(this.get(t,r)));return this},t.sqrt=function(t){return new r(t).sqrt()},t.prototype.tan=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.tan(this.get(t,r)));return this},t.tan=function(t){return new r(t).tan()},t.prototype.tanh=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.tanh(this.get(t,r)));return this},t.tanh=function(t){return new r(t).tanh()},t.prototype.trunc=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.trunc(this.get(t,r)));return this},t.trunc=function(t){return new r(t).trunc()},t.pow=function(t,e){return new r(t).pow(e)},t.prototype.pow=function(t){return"number"==typeof t?this.powS(t):this.powM(t)},t.prototype.powS=function(t){for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,Math.pow(this.get(r,e),t));return this},t.prototype.powM=function(t){if(t=r.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(var e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)this.set(e,n,Math.pow(this.get(e,n),t.get(e,n)));return this}}(me,pe);var ye=function(t){Ir(e,t);var r=we(e);function e(t){return Ar(this,e),r.call(this,t,t.columns,t.rows)}return Or(e,[{key:"set",value:function(t,r,e){return this.matrix.set(r,t,e),this}},{key:"get",value:function(t,r){return this.matrix.get(r,t)}}]),e}(function(t){Ir(e,t);var r=de(e);function e(t,n,o){var i;return Ar(this,e),(i=r.call(this)).matrix=t,i.rows=n,i.columns=o,i}return e}(me));function be(t){var r=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var e,n=Fr(t);if(r){var o=Fr(this).constructor;e=Reflect.construct(n,arguments,o)}else e=n.apply(this,arguments);return Nr(this,e)}}var Me=function(t){Ir(e,t);var r=be(e);function e(t){var n;return Ar(this,e),(n=r.call(this)).data=t,n.rows=t.length,n.columns=t[0].length,n}return Or(e,[{key:"set",value:function(t,r,e){return this.data[t][r]=e,this}},{key:"get",value:function(t,r){return this.data[t][r]}}]),e}(me);function xe(t,r){var e=0;return Math.abs(t)>Math.abs(r)?(e=r/t,Math.abs(t)*Math.sqrt(1+e*e)):0!==r?(e=t/r,Math.abs(r)*Math.sqrt(1+e*e)):0}var ke=function(){function t(r){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(Ar(this,t),(r=Me.checkMatrix(r)).isEmpty())throw new Error("Matrix must be non-empty");var n,o=r.rows,i=r.columns,s=e.computeLeftSingularVectors,a=void 0===s||s,u=e.computeRightSingularVectors,c=void 0===u||u,f=e.autoTranspose,h=void 0!==f&&f,l=Boolean(a),v=Boolean(c),m=!1;if(o<i)if(h){o=(n=r.transpose()).rows,i=n.columns,m=!0;var g=l;l=v,v=g}else n=r.clone(),console.warn("Computing SVD on a matrix with more columns than rows. Consider enabling autoTranspose");else n=r.clone();for(var p=Math.min(o,i),d=Math.min(o+1,i),w=new Float64Array(d),y=new pe(o,p),b=new pe(i,i),M=new Float64Array(i),x=new Float64Array(o),k=new Float64Array(d),E=0;E<d;E++)k[E]=E;for(var S=Math.min(o-1,i),_=Math.max(0,Math.min(i-2,o)),j=Math.max(S,_),A=0;A<j;A++){if(A<S){w[A]=0;for(var R=A;R<o;R++)w[A]=xe(w[A],n.get(R,A));if(0!==w[A]){n.get(A,A)<0&&(w[A]=-w[A]);for(var O=A;O<o;O++)n.set(O,A,n.get(O,A)/w[A]);n.set(A,A,n.get(A,A)+1)}w[A]=-w[A]}for(var C=A+1;C<i;C++){if(A<S&&0!==w[A]){for(var I=0,N=A;N<o;N++)I+=n.get(N,A)*n.get(N,C);I=-I/n.get(A,A);for(var F=A;F<o;F++)n.set(F,C,n.get(F,C)+I*n.get(F,A))}M[C]=n.get(A,C)}if(l&&A<S)for(var T=A;T<o;T++)y.set(T,A,n.get(T,A));if(A<_){M[A]=0;for(var P=A+1;P<i;P++)M[A]=xe(M[A],M[P]);if(0!==M[A]){M[A+1]<0&&(M[A]=0-M[A]);for(var z=A+1;z<i;z++)M[z]/=M[A];M[A+1]+=1}if(M[A]=-M[A],A+1<o&&0!==M[A]){for(var L=A+1;L<o;L++)x[L]=0;for(var V=A+1;V<o;V++)for(var q=A+1;q<i;q++)x[V]+=M[q]*n.get(V,q);for(var D=A+1;D<i;D++)for(var U=-M[D]/M[A+1],B=A+1;B<o;B++)n.set(B,D,n.get(B,D)+U*x[B])}if(v)for(var G=A+1;G<i;G++)b.set(G,A,M[G])}}var $=Math.min(i,o+1);if(S<i&&(w[S]=n.get(S,S)),o<$&&(w[$-1]=0),_+1<$&&(M[_]=n.get(_,$-1)),M[$-1]=0,l){for(var K=S;K<p;K++){for(var W=0;W<o;W++)y.set(W,K,0);y.set(K,K,1)}for(var X=S-1;X>=0;X--)if(0!==w[X]){for(var Y=X+1;Y<p;Y++){for(var J=0,Z=X;Z<o;Z++)J+=y.get(Z,X)*y.get(Z,Y);J=-J/y.get(X,X);for(var H=X;H<o;H++)y.set(H,Y,y.get(H,Y)+J*y.get(H,X))}for(var Q=X;Q<o;Q++)y.set(Q,X,-y.get(Q,X));y.set(X,X,1+y.get(X,X));for(var tt=0;tt<X-1;tt++)y.set(tt,X,0)}else{for(var rt=0;rt<o;rt++)y.set(rt,X,0);y.set(X,X,1)}}if(v)for(var et=i-1;et>=0;et--){if(et<_&&0!==M[et])for(var nt=et+1;nt<i;nt++){for(var ot=0,it=et+1;it<i;it++)ot+=b.get(it,et)*b.get(it,nt);ot=-ot/b.get(et+1,et);for(var st=et+1;st<i;st++)b.set(st,nt,b.get(st,nt)+ot*b.get(st,et))}for(var at=0;at<i;at++)b.set(at,et,0);b.set(et,et,1)}for(var ut=$-1,ct=Number.EPSILON;$>0;){var ft=void 0,ht=void 0;for(ft=$-2;ft>=-1&&-1!==ft;ft--){var lt=Number.MIN_VALUE+ct*Math.abs(w[ft]+Math.abs(w[ft+1]));if(Math.abs(M[ft])<=lt||Number.isNaN(M[ft])){M[ft]=0;break}}if(ft===$-2)ht=4;else{var vt=void 0;for(vt=$-1;vt>=ft&&vt!==ft;vt--){var mt=(vt!==$?Math.abs(M[vt]):0)+(vt!==ft+1?Math.abs(M[vt-1]):0);if(Math.abs(w[vt])<=ct*mt){w[vt]=0;break}}vt===ft?ht=3:vt===$-1?ht=1:(ht=2,ft=vt)}switch(ft++,ht){case 1:var gt=M[$-2];M[$-2]=0;for(var pt=$-2;pt>=ft;pt--){var dt=xe(w[pt],gt),wt=w[pt]/dt,yt=gt/dt;if(w[pt]=dt,pt!==ft&&(gt=-yt*M[pt-1],M[pt-1]=wt*M[pt-1]),v)for(var bt=0;bt<i;bt++)dt=wt*b.get(bt,pt)+yt*b.get(bt,$-1),b.set(bt,$-1,-yt*b.get(bt,pt)+wt*b.get(bt,$-1)),b.set(bt,pt,dt)}break;case 2:var Mt=M[ft-1];M[ft-1]=0;for(var xt=ft;xt<$;xt++){var kt=xe(w[xt],Mt),Et=w[xt]/kt,St=Mt/kt;if(w[xt]=kt,Mt=-St*M[xt],M[xt]=Et*M[xt],l)for(var _t=0;_t<o;_t++)kt=Et*y.get(_t,xt)+St*y.get(_t,ft-1),y.set(_t,ft-1,-St*y.get(_t,xt)+Et*y.get(_t,ft-1)),y.set(_t,xt,kt)}break;case 3:var jt=Math.max(Math.abs(w[$-1]),Math.abs(w[$-2]),Math.abs(M[$-2]),Math.abs(w[ft]),Math.abs(M[ft])),At=w[$-1]/jt,Rt=w[$-2]/jt,Ot=M[$-2]/jt,Ct=w[ft]/jt,It=M[ft]/jt,Nt=((Rt+At)*(Rt-At)+Ot*Ot)/2,Ft=At*Ot*(At*Ot),Tt=0;0===Nt&&0===Ft||(Tt=Ft/(Nt+(Tt=Nt<0?0-Math.sqrt(Nt*Nt+Ft):Math.sqrt(Nt*Nt+Ft))));for(var Pt=(Ct+At)*(Ct-At)+Tt,zt=Ct*It,Lt=ft;Lt<$-1;Lt++){var Vt=xe(Pt,zt);0===Vt&&(Vt=Number.MIN_VALUE);var qt=Pt/Vt,Dt=zt/Vt;if(Lt!==ft&&(M[Lt-1]=Vt),Pt=qt*w[Lt]+Dt*M[Lt],M[Lt]=qt*M[Lt]-Dt*w[Lt],zt=Dt*w[Lt+1],w[Lt+1]=qt*w[Lt+1],v)for(var Ut=0;Ut<i;Ut++)Vt=qt*b.get(Ut,Lt)+Dt*b.get(Ut,Lt+1),b.set(Ut,Lt+1,-Dt*b.get(Ut,Lt)+qt*b.get(Ut,Lt+1)),b.set(Ut,Lt,Vt);if(0===(Vt=xe(Pt,zt))&&(Vt=Number.MIN_VALUE),qt=Pt/Vt,Dt=zt/Vt,w[Lt]=Vt,Pt=qt*M[Lt]+Dt*w[Lt+1],w[Lt+1]=-Dt*M[Lt]+qt*w[Lt+1],zt=Dt*M[Lt+1],M[Lt+1]=qt*M[Lt+1],l&&Lt<o-1)for(var Bt=0;Bt<o;Bt++)Vt=qt*y.get(Bt,Lt)+Dt*y.get(Bt,Lt+1),y.set(Bt,Lt+1,-Dt*y.get(Bt,Lt)+qt*y.get(Bt,Lt+1)),y.set(Bt,Lt,Vt)}M[$-2]=Pt;break;case 4:if(w[ft]<=0&&(w[ft]=w[ft]<0?-w[ft]:0,v))for(var Gt=0;Gt<=ut;Gt++)b.set(Gt,ft,-b.get(Gt,ft));for(;ft<ut&&!(w[ft]>=w[ft+1]);){var $t=w[ft];if(w[ft]=w[ft+1],w[ft+1]=$t,v&&ft<i-1)for(var Kt=0;Kt<i;Kt++)$t=b.get(Kt,ft+1),b.set(Kt,ft+1,b.get(Kt,ft)),b.set(Kt,ft,$t);if(l&&ft<o-1)for(var Wt=0;Wt<o;Wt++)$t=y.get(Wt,ft+1),y.set(Wt,ft+1,y.get(Wt,ft)),y.set(Wt,ft,$t);ft++}$--}}if(m){var Xt=b;b=y,y=Xt}this.m=o,this.n=i,this.s=w,this.U=y,this.V=b}return Or(t,[{key:"solve",value:function(t){for(var r=t,e=this.threshold,n=this.s.length,o=pe.zeros(n,n),i=0;i<n;i++)Math.abs(this.s[i])<=e?o.set(i,i,0):o.set(i,i,1/this.s[i]);for(var s=this.U,a=this.rightSingularVectors,u=a.mmul(o),c=a.rows,f=s.rows,h=pe.zeros(c,f),l=0;l<c;l++)for(var v=0;v<f;v++){for(var m=0,g=0;g<n;g++)m+=u.get(l,g)*s.get(v,g);h.set(l,v,m)}return h.mmul(r)}},{key:"solveForDiagonal",value:function(t){return this.solve(pe.diag(t))}},{key:"inverse",value:function(){for(var t=this.V,r=this.threshold,e=t.rows,n=t.columns,o=new pe(e,this.s.length),i=0;i<e;i++)for(var s=0;s<n;s++)Math.abs(this.s[s])>r&&o.set(i,s,t.get(i,s)/this.s[s]);for(var a=this.U,u=a.rows,c=a.columns,f=new pe(e,u),h=0;h<e;h++)for(var l=0;l<u;l++){for(var v=0,m=0;m<c;m++)v+=o.get(h,m)*a.get(l,m);f.set(h,l,v)}return f}},{key:"condition",get:function(){return this.s[0]/this.s[Math.min(this.m,this.n)-1]}},{key:"norm2",get:function(){return this.s[0]}},{key:"rank",get:function(){for(var t=Math.max(this.m,this.n)*this.s[0]*Number.EPSILON,r=0,e=this.s,n=0,o=e.length;n<o;n++)e[n]>t&&r++;return r}},{key:"diagonal",get:function(){return Array.from(this.s)}},{key:"threshold",get:function(){return Number.EPSILON/2*Math.max(this.m,this.n)*this.s[0]}},{key:"leftSingularVectors",get:function(){return this.U}},{key:"rightSingularVectors",get:function(){return this.V}},{key:"diagonalMatrix",get:function(){return pe.diag(this.s)}}]),t}(),Ee=function(){function t(r){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};Ar(this,t);var n=e.assumeSymmetric,o=void 0!==n&&n;if(!(r=Me.checkMatrix(r)).isSquare())throw new Error("Matrix is not a square matrix");if(r.isEmpty())throw new Error("Matrix must be non-empty");var i,s,a=r.columns,u=new pe(a,a),c=new Float64Array(a),f=new Float64Array(a),h=r;if(!!o||r.isSymmetric()){for(i=0;i<a;i++)for(s=0;s<a;s++)u.set(i,s,h.get(i,s));Se(a,f,c,u),_e(a,f,c,u)}else{var l=new pe(a,a),v=new Float64Array(a);for(s=0;s<a;s++)for(i=0;i<a;i++)l.set(i,s,h.get(i,s));je(a,l,v,u),Ae(a,f,c,u,l)}this.n=a,this.e=f,this.d=c,this.V=u}return Or(t,[{key:"realEigenvalues",get:function(){return Array.from(this.d)}},{key:"imaginaryEigenvalues",get:function(){return Array.from(this.e)}},{key:"eigenvectorMatrix",get:function(){return this.V}},{key:"diagonalMatrix",get:function(){var t,r,e=this.n,n=this.e,o=this.d,i=new pe(e,e);for(t=0;t<e;t++){for(r=0;r<e;r++)i.set(t,r,0);i.set(t,t,o[t]),n[t]>0?i.set(t,t+1,n[t]):n[t]<0&&i.set(t,t-1,n[t])}return i}}]),t}();function Se(t,r,e,n){var o,i,s,a,u,c,f,h;for(u=0;u<t;u++)e[u]=n.get(t-1,u);for(a=t-1;a>0;a--){for(h=0,s=0,c=0;c<a;c++)h+=Math.abs(e[c]);if(0===h)for(r[a]=e[a-1],u=0;u<a;u++)e[u]=n.get(a-1,u),n.set(a,u,0),n.set(u,a,0);else{for(c=0;c<a;c++)e[c]/=h,s+=e[c]*e[c];for(o=e[a-1],i=Math.sqrt(s),o>0&&(i=-i),r[a]=h*i,s-=o*i,e[a-1]=o-i,u=0;u<a;u++)r[u]=0;for(u=0;u<a;u++){for(o=e[u],n.set(u,a,o),i=r[u]+n.get(u,u)*o,c=u+1;c<=a-1;c++)i+=n.get(c,u)*e[c],r[c]+=n.get(c,u)*o;r[u]=i}for(o=0,u=0;u<a;u++)r[u]/=s,o+=r[u]*e[u];for(f=o/(s+s),u=0;u<a;u++)r[u]-=f*e[u];for(u=0;u<a;u++){for(o=e[u],i=r[u],c=u;c<=a-1;c++)n.set(c,u,n.get(c,u)-(o*r[c]+i*e[c]));e[u]=n.get(a-1,u),n.set(a,u,0)}}e[a]=s}for(a=0;a<t-1;a++){if(n.set(t-1,a,n.get(a,a)),n.set(a,a,1),0!==(s=e[a+1])){for(c=0;c<=a;c++)e[c]=n.get(c,a+1)/s;for(u=0;u<=a;u++){for(i=0,c=0;c<=a;c++)i+=n.get(c,a+1)*n.get(c,u);for(c=0;c<=a;c++)n.set(c,u,n.get(c,u)-i*e[c])}}for(c=0;c<=a;c++)n.set(c,a+1,0)}for(u=0;u<t;u++)e[u]=n.get(t-1,u),n.set(t-1,u,0);n.set(t-1,t-1,1),r[0]=0}function _e(t,r,e,n){var o,i,s,a,u,c,f,h,l,v,m,g,p,d,w,y;for(s=1;s<t;s++)r[s-1]=r[s];r[t-1]=0;var b=0,M=0,x=Number.EPSILON;for(c=0;c<t;c++){for(M=Math.max(M,Math.abs(e[c])+Math.abs(r[c])),f=c;f<t&&!(Math.abs(r[f])<=x*M);)f++;if(f>c)do{for(o=e[c],l=xe(h=(e[c+1]-o)/(2*r[c]),1),h<0&&(l=-l),e[c]=r[c]/(h+l),e[c+1]=r[c]*(h+l),v=e[c+1],i=o-e[c],s=c+2;s<t;s++)e[s]-=i;for(b+=i,h=e[f],g=m=1,p=m,d=r[c+1],w=0,y=0,s=f-1;s>=c;s--)for(p=g,g=m,y=w,o=m*r[s],i=m*h,l=xe(h,r[s]),r[s+1]=w*l,w=r[s]/l,h=(m=h/l)*e[s]-w*o,e[s+1]=i+w*(m*o+w*e[s]),u=0;u<t;u++)i=n.get(u,s+1),n.set(u,s+1,w*n.get(u,s)+m*i),n.set(u,s,m*n.get(u,s)-w*i);h=-w*y*p*d*r[c]/v,r[c]=w*h,e[c]=m*h}while(Math.abs(r[c])>x*M);e[c]=e[c]+b,r[c]=0}for(s=0;s<t-1;s++){for(u=s,h=e[s],a=s+1;a<t;a++)e[a]<h&&(u=a,h=e[a]);if(u!==s)for(e[u]=e[s],e[s]=h,a=0;a<t;a++)h=n.get(a,s),n.set(a,s,n.get(a,u)),n.set(a,u,h)}}function je(t,r,e,n){var o,i,s,a,u,c,f,h=t-1;for(c=1;c<=h-1;c++){for(f=0,a=c;a<=h;a++)f+=Math.abs(r.get(a,c-1));if(0!==f){for(s=0,a=h;a>=c;a--)e[a]=r.get(a,c-1)/f,s+=e[a]*e[a];for(i=Math.sqrt(s),e[c]>0&&(i=-i),s-=e[c]*i,e[c]=e[c]-i,u=c;u<t;u++){for(o=0,a=h;a>=c;a--)o+=e[a]*r.get(a,u);for(o/=s,a=c;a<=h;a++)r.set(a,u,r.get(a,u)-o*e[a])}for(a=0;a<=h;a++){for(o=0,u=h;u>=c;u--)o+=e[u]*r.get(a,u);for(o/=s,u=c;u<=h;u++)r.set(a,u,r.get(a,u)-o*e[u])}e[c]=f*e[c],r.set(c,c-1,f*i)}}for(a=0;a<t;a++)for(u=0;u<t;u++)n.set(a,u,a===u?1:0);for(c=h-1;c>=1;c--)if(0!==r.get(c,c-1)){for(a=c+1;a<=h;a++)e[a]=r.get(a,c-1);for(u=c;u<=h;u++){for(i=0,a=c;a<=h;a++)i+=e[a]*n.get(a,u);for(i=i/e[c]/r.get(c,c-1),a=c;a<=h;a++)n.set(a,u,n.get(a,u)+i*e[a])}}}function Ae(t,r,e,n,o){var i,s,a,u,c,f,h,l,v,m,g,p,d,w,y,b=t-1,M=t-1,x=Number.EPSILON,k=0,E=0,S=0,_=0,j=0,A=0,R=0,O=0;for(i=0;i<t;i++)for((i<0||i>M)&&(e[i]=o.get(i,i),r[i]=0),s=Math.max(i-1,0);s<t;s++)E+=Math.abs(o.get(i,s));for(;b>=0;){for(u=b;u>0&&(0===(A=Math.abs(o.get(u-1,u-1))+Math.abs(o.get(u,u)))&&(A=E),!(Math.abs(o.get(u,u-1))<x*A));)u--;if(u===b)o.set(b,b,o.get(b,b)+k),e[b]=o.get(b,b),r[b]=0,b--,O=0;else if(u===b-1){if(h=o.get(b,b-1)*o.get(b-1,b),_=(S=(o.get(b-1,b-1)-o.get(b,b))/2)*S+h,R=Math.sqrt(Math.abs(_)),o.set(b,b,o.get(b,b)+k),o.set(b-1,b-1,o.get(b-1,b-1)+k),l=o.get(b,b),_>=0){for(R=S>=0?S+R:S-R,e[b-1]=l+R,e[b]=e[b-1],0!==R&&(e[b]=l-h/R),r[b-1]=0,r[b]=0,S=(l=o.get(b,b-1))/(A=Math.abs(l)+Math.abs(R)),_=R/A,S/=j=Math.sqrt(S*S+_*_),_/=j,s=b-1;s<t;s++)R=o.get(b-1,s),o.set(b-1,s,_*R+S*o.get(b,s)),o.set(b,s,_*o.get(b,s)-S*R);for(i=0;i<=b;i++)R=o.get(i,b-1),o.set(i,b-1,_*R+S*o.get(i,b)),o.set(i,b,_*o.get(i,b)-S*R);for(i=0;i<=M;i++)R=n.get(i,b-1),n.set(i,b-1,_*R+S*n.get(i,b)),n.set(i,b,_*n.get(i,b)-S*R)}else e[b-1]=l+S,e[b]=l+S,r[b-1]=R,r[b]=-R;b-=2,O=0}else{if(l=o.get(b,b),v=0,h=0,u<b&&(v=o.get(b-1,b-1),h=o.get(b,b-1)*o.get(b-1,b)),10===O){for(k+=l,i=0;i<=b;i++)o.set(i,i,o.get(i,i)-l);l=v=.75*(A=Math.abs(o.get(b,b-1))+Math.abs(o.get(b-1,b-2))),h=-.4375*A*A}if(30===O&&(A=(A=(v-l)/2)*A+h)>0){for(A=Math.sqrt(A),v<l&&(A=-A),A=l-h/((v-l)/2+A),i=0;i<=b;i++)o.set(i,i,o.get(i,i)-A);k+=A,l=v=h=.964}for(O+=1,c=b-2;c>=u&&(S=((j=l-(R=o.get(c,c)))*(A=v-R)-h)/o.get(c+1,c)+o.get(c,c+1),_=o.get(c+1,c+1)-R-j-A,j=o.get(c+2,c+1),S/=A=Math.abs(S)+Math.abs(_)+Math.abs(j),_/=A,j/=A,c!==u)&&!(Math.abs(o.get(c,c-1))*(Math.abs(_)+Math.abs(j))<x*(Math.abs(S)*(Math.abs(o.get(c-1,c-1))+Math.abs(R)+Math.abs(o.get(c+1,c+1)))));)c--;for(i=c+2;i<=b;i++)o.set(i,i-2,0),i>c+2&&o.set(i,i-3,0);for(a=c;a<=b-1&&(w=a!==b-1,a!==c&&(S=o.get(a,a-1),_=o.get(a+1,a-1),j=w?o.get(a+2,a-1):0,0!==(l=Math.abs(S)+Math.abs(_)+Math.abs(j))&&(S/=l,_/=l,j/=l)),0!==l);a++)if(A=Math.sqrt(S*S+_*_+j*j),S<0&&(A=-A),0!==A){for(a!==c?o.set(a,a-1,-A*l):u!==c&&o.set(a,a-1,-o.get(a,a-1)),l=(S+=A)/A,v=_/A,R=j/A,_/=S,j/=S,s=a;s<t;s++)S=o.get(a,s)+_*o.get(a+1,s),w&&(S+=j*o.get(a+2,s),o.set(a+2,s,o.get(a+2,s)-S*R)),o.set(a,s,o.get(a,s)-S*l),o.set(a+1,s,o.get(a+1,s)-S*v);for(i=0;i<=Math.min(b,a+3);i++)S=l*o.get(i,a)+v*o.get(i,a+1),w&&(S+=R*o.get(i,a+2),o.set(i,a+2,o.get(i,a+2)-S*j)),o.set(i,a,o.get(i,a)-S),o.set(i,a+1,o.get(i,a+1)-S*_);for(i=0;i<=M;i++)S=l*n.get(i,a)+v*n.get(i,a+1),w&&(S+=R*n.get(i,a+2),n.set(i,a+2,n.get(i,a+2)-S*j)),n.set(i,a,n.get(i,a)-S),n.set(i,a+1,n.get(i,a+1)-S*_)}}}if(0!==E){for(b=t-1;b>=0;b--)if(S=e[b],0===(_=r[b]))for(u=b,o.set(b,b,1),i=b-1;i>=0;i--){for(h=o.get(i,i)-S,j=0,s=u;s<=b;s++)j+=o.get(i,s)*o.get(s,b);if(r[i]<0)R=h,A=j;else if(u=i,0===r[i]?o.set(i,b,0!==h?-j/h:-j/(x*E)):(l=o.get(i,i+1),v=o.get(i+1,i),f=(l*A-R*j)/(_=(e[i]-S)*(e[i]-S)+r[i]*r[i]),o.set(i,b,f),o.set(i+1,b,Math.abs(l)>Math.abs(R)?(-j-h*f)/l:(-A-v*f)/R)),x*(f=Math.abs(o.get(i,b)))*f>1)for(s=i;s<=b;s++)o.set(s,b,o.get(s,b)/f)}else if(_<0)for(u=b-1,Math.abs(o.get(b,b-1))>Math.abs(o.get(b-1,b))?(o.set(b-1,b-1,_/o.get(b,b-1)),o.set(b-1,b,-(o.get(b,b)-S)/o.get(b,b-1))):(y=Re(0,-o.get(b-1,b),o.get(b-1,b-1)-S,_),o.set(b-1,b-1,y[0]),o.set(b-1,b,y[1])),o.set(b,b-1,0),o.set(b,b,1),i=b-2;i>=0;i--){for(m=0,g=0,s=u;s<=b;s++)m+=o.get(i,s)*o.get(s,b-1),g+=o.get(i,s)*o.get(s,b);if(h=o.get(i,i)-S,r[i]<0)R=h,j=m,A=g;else if(u=i,0===r[i]?(y=Re(-m,-g,h,_),o.set(i,b-1,y[0]),o.set(i,b,y[1])):(l=o.get(i,i+1),v=o.get(i+1,i),p=(e[i]-S)*(e[i]-S)+r[i]*r[i]-_*_,d=2*(e[i]-S)*_,0===p&&0===d&&(p=x*E*(Math.abs(h)+Math.abs(_)+Math.abs(l)+Math.abs(v)+Math.abs(R))),y=Re(l*j-R*m+_*g,l*A-R*g-_*m,p,d),o.set(i,b-1,y[0]),o.set(i,b,y[1]),Math.abs(l)>Math.abs(R)+Math.abs(_)?(o.set(i+1,b-1,(-m-h*o.get(i,b-1)+_*o.get(i,b))/l),o.set(i+1,b,(-g-h*o.get(i,b)-_*o.get(i,b-1))/l)):(y=Re(-j-v*o.get(i,b-1),-A-v*o.get(i,b),R,_),o.set(i+1,b-1,y[0]),o.set(i+1,b,y[1]))),x*(f=Math.max(Math.abs(o.get(i,b-1)),Math.abs(o.get(i,b))))*f>1)for(s=i;s<=b;s++)o.set(s,b-1,o.get(s,b-1)/f),o.set(s,b,o.get(s,b)/f)}for(i=0;i<t;i++)if(i<0||i>M)for(s=i;s<t;s++)n.set(i,s,o.get(i,s));for(s=t-1;s>=0;s--)for(i=0;i<=M;i++){for(R=0,a=0;a<=Math.min(s,M);a++)R+=n.get(i,a)*o.get(a,s);n.set(i,s,R)}}}function Re(t,r,e,n){var o,i;return Math.abs(e)>Math.abs(n)?[(t+(o=n/e)*r)/(i=e+o*n),(r-o*t)/i]:[((o=e/n)*t+r)/(i=n+o*e),(o*r-t)/i]}var Oe=function t(r){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};Ar(this,t),r=Me.checkMatrix(r);var n,o=e.Y,i=e.scaleScores,s=void 0!==i&&i,a=e.maxIterations,u=void 0===a?1e3:a,c=e.terminationCriteria,f=void 0===c?1e-10:c;if(o){if((o=Array.isArray(o)&&"number"==typeof o[0]?pe.columnVector(o):Me.checkMatrix(o)).rows!==r.rows)throw new Error("Y should have the same number of rows as X");n=o.getColumnVector(0)}else n=r.getColumnVector(0);for(var h,l,v,m,g=1,p=0;p<u&&g>f;p++)v=(v=r.transpose().mmul(n).div(n.transpose().mmul(n).get(0,0))).div(v.norm()),h=r.mmul(v).div(v.transpose().mmul(v).get(0,0)),p>0&&(g=h.clone().sub(m).pow(2).sum()),m=h.clone(),o?(l=(l=o.transpose().mmul(h).div(h.transpose().mmul(h).get(0,0))).div(l.norm()),n=o.mmul(l).div(l.transpose().mmul(l).get(0,0))):n=h;if(o){var d=r.transpose().mmul(h).div(h.transpose().mmul(h).get(0,0));d=d.div(d.norm());var w=r.clone().sub(h.clone().mmul(d.transpose())),y=n.transpose().mmul(h).div(h.transpose().mmul(h).get(0,0)),b=o.clone().sub(h.clone().mulS(y.get(0,0)).mmul(l.transpose()));this.t=h,this.p=d.transpose(),this.w=v.transpose(),this.q=l,this.u=n,this.s=h.transpose().mmul(h),this.xResidual=w,this.yResidual=b,this.betas=y}else this.w=v.transpose(),this.s=h.transpose().mmul(h).sqrt(),this.t=s?h.clone().div(this.s.get(0,0)):h,this.xResidual=r.sub(h.mmul(v.transpose()))};function Ce(t,r){var e="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!e){if(Array.isArray(t)||(e=function(t,r){if(!t)return;if("string"==typeof t)return Ie(t,r);var e=Object.prototype.toString.call(t).slice(8,-1);"Object"===e&&t.constructor&&(e=t.constructor.name);if("Map"===e||"Set"===e)return Array.from(t);if("Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e))return Ie(t,r)}(t))||r&&t&&"number"==typeof t.length){e&&(t=e);var n=0,o=function(){};return{s:o,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,s=!0,a=!1;return{s:function(){e=e.call(t)},n:function(){var t=e.next();return s=t.done,t},e:function(t){a=!0,i=t},f:function(){try{s||null==e.return||e.return()}finally{if(a)throw i}}}}function Ie(t,r){(null==r||r>t.length)&&(r=t.length);for(var e=0,n=new Array(r);e<r;e++)n[e]=t[e];return n}var Ne=function(){function t(r){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(Ar(this,t),!0===r){var n=e;return this.center=n.center,this.scale=n.scale,this.means=n.means,this.stdevs=n.stdevs,this.U=pe.checkMatrix(n.U),this.S=n.S,this.R=n.R,void(this.excludedFeatures=n.excludedFeatures||[])}r=new pe(r);var o=e.isCovarianceMatrix,i=void 0!==o&&o,s=e.method,a=void 0===s?"SVD":s,u=e.nCompNIPALS,c=void 0===u?2:u,f=e.center,h=void 0===f||f,l=e.scale,v=void 0!==l&&l,m=e.ignoreZeroVariance,g=void 0!==m&&m;if(this.center=h,this.scale=v,this.means=null,this.stdevs=null,this.excludedFeatures=[],i)this._computeFromCovarianceMatrix(r);else switch(this._adjust(r,g),a){case"covarianceMatrix":var p=new ye(r).mmul(r).div(r.rows-1);this._computeFromCovarianceMatrix(p);break;case"NIPALS":this._computeWithNIPALS(r,c);break;case"SVD":var d=new ke(r,{computeLeftSingularVectors:!1,computeRightSingularVectors:!0,autoTranspose:!0});this.U=d.rightSingularVectors;var w,y=d.diagonal,b=[],M=Ce(y);try{for(M.s();!(w=M.n()).done;){var x=w.value;b.push(x*x/(r.rows-1))}}catch(t){M.e(t)}finally{M.f()}this.S=b;break;default:throw new Error("unknown method: ".concat(a))}}return Or(t,[{key:"predict",value:function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},e=r.nComponents,n=void 0===e?this.U.columns:e;if(t=new pe(t),this.center&&(t.subRowVector(this.means),this.scale)){var o,i=Ce(this.excludedFeatures);try{for(i.s();!(o=i.n()).done;){var s=o.value;t.removeColumn(s)}}catch(t){i.e(t)}finally{i.f()}t.divRowVector(this.stdevs)}var a=t.mmul(this.U);return a.subMatrix(0,a.rows-1,0,n-1)}},{key:"invert",value:function(t){var r=(t=pe.checkMatrix(t)).mmul(this.U.transpose());return this.center&&(this.scale&&r.mulRowVector(this.stdevs),r.addRowVector(this.means)),r}},{key:"getExplainedVariance",value:function(){var t,r=0,e=Ce(this.S);try{for(e.s();!(t=e.n()).done;){var n=t.value;r+=n}}catch(t){e.e(t)}finally{e.f()}return this.S.map((function(t){return t/r}))}},{key:"getCumulativeVariance",value:function(){for(var t=this.getExplainedVariance(),r=1;r<t.length;r++)t[r]+=t[r-1];return t}},{key:"getEigenvectors",value:function(){return this.U}},{key:"getEigenvalues",value:function(){return this.S}},{key:"getStandardDeviations",value:function(){return this.S.map((function(t){return Math.sqrt(t)}))}},{key:"getLoadings",value:function(){return this.U.transpose()}},{key:"toJSON",value:function(){return{name:"PCA",center:this.center,scale:this.scale,means:this.means,stdevs:this.stdevs,U:this.U,S:this.S,excludedFeatures:this.excludedFeatures}}},{key:"_adjust",value:function(t,r){if(this.center){var e=t.mean("column"),n=this.scale?t.standardDeviation("column",{mean:e}):null;if(this.means=e,t.subRowVector(e),this.scale){for(var o=0;o<n.length;o++)if(0===n[o]){if(!r)throw new RangeError("Cannot scale the dataset (standard deviation is zero at index ".concat(o));t.removeColumn(o),n.splice(o,1),this.excludedFeatures.push(o),o--}this.stdevs=n,t.divRowVector(n)}}}},{key:"_computeFromCovarianceMatrix",value:function(t){var r=new Ee(t,{assumeSymmetric:!0});this.U=r.eigenvectorMatrix,this.U.flipRows(),this.S=r.realEigenvalues,this.S.reverse()}},{key:"_computeWithNIPALS",value:function(t,r){this.U=new pe(r,t.columns),this.S=[];for(var e=t,n=0;n<r;n++){var o=new Oe(e);this.U.setRow(n,o.w.transpose()),this.S.push(Math.pow(o.s.get(0,0),2)),e=o.xResidual}this.U=this.U.transpose()}}],[{key:"load",value:function(r){if("string"!=typeof r.name)throw new TypeError("model must have a name property");if("PCA"!==r.name)throw new RangeError("invalid model: ".concat(r.name));return new t(!0,r)}}]),t}();function Fe(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!jr(t))throw new Error("data is not eff. array");var e=It(r,"scale");xr(e)||(e=!0);var n=It(r,"nCompNIPALS");Mr(n)||(n=2);var o=br(It(t,0,[]));if(0===o)throw new Error("invalid dimension of data");if(n>o)throw new Error("nCompNIPALS is more than the dimension of data");var i="NIPALS",s=new Ne(t,{method:i,scale:e,nCompNIPALS:n}),a=s.predict(t),u=s.invert(a),c=u.toJSON();return c}var Te=function(t,r){for(var e=-1,n=null==t?0:t.length;++e<n&&!1!==r(t[e],e,t););return t};var Pe=function(t){return function(r,e,n){for(var o=-1,i=Object(r),s=n(r),a=s.length;a--;){var u=s[t?a:++o];if(!1===e(i[u],u,i))break}return r}}();var ze=function(t,r){for(var e=-1,n=Array(t);++e<t;)n[e]=r(e);return n};var Le=function(t){return M(t)&&"[object Arguments]"==b(t)},Ve=Object.prototype,qe=Ve.hasOwnProperty,De=Ve.propertyIsEnumerable,Ue=Le(function(){return arguments}())?Le:function(t){return M(t)&&qe.call(t,"callee")&&!De.call(t,"callee")};var Be=function(){return!1},Ge=i((function(t,r){var e=r&&!r.nodeType&&r,n=e&&t&&!t.nodeType&&t,o=n&&n.exports===e?f.Buffer:void 0,i=(o?o.isBuffer:void 0)||Be;t.exports=i})),$e=/^(?:0|[1-9]\d*)$/;var Ke=function(t,r){var n=e(t);return!!(r=null==r?9007199254740991:r)&&("number"==n||"symbol"!=n&&$e.test(t))&&t>-1&&t%1==0&&t<r},We={};We["[object Float32Array]"]=We["[object Float64Array]"]=We["[object Int8Array]"]=We["[object Int16Array]"]=We["[object Int32Array]"]=We["[object Uint8Array]"]=We["[object Uint8ClampedArray]"]=We["[object Uint16Array]"]=We["[object Uint32Array]"]=!0,We["[object Arguments]"]=We["[object Array]"]=We["[object ArrayBuffer]"]=We["[object Boolean]"]=We["[object DataView]"]=We["[object Date]"]=We["[object Error]"]=We["[object Function]"]=We["[object Map]"]=We["[object Number]"]=We["[object Object]"]=We["[object RegExp]"]=We["[object Set]"]=We["[object String]"]=We["[object WeakMap]"]=!1;var Xe=function(t){return M(t)&&tr(t.length)&&!!We[b(t)]};var Ye=function(t){return function(r){return t(r)}},Je=i((function(t,r){var e=r&&!r.nodeType&&r,n=e&&t&&!t.nodeType&&t,o=n&&n.exports===e&&u.process,i=function(){try{var t=n&&n.require&&n.require("util").types;return t||o&&o.binding&&o.binding("util")}catch(t){}}();t.exports=i})),Ze=Je&&Je.isTypedArray,He=Ze?Ye(Ze):Xe,Qe=Object.prototype.hasOwnProperty;var tn=function(t,r){var e=a(t),n=!e&&Ue(t),o=!e&&!n&&Ge(t),i=!e&&!n&&!o&&He(t),s=e||n||o||i,u=s?ze(t.length,String):[],c=u.length;for(var f in t)!r&&!Qe.call(t,f)||s&&("length"==f||o&&("offset"==f||"parent"==f)||i&&("buffer"==f||"byteLength"==f||"byteOffset"==f)||Ke(f,c))||u.push(f);return u};var rn=function(t){return rr(t)?tn(t):zt(t)};var en=function(t,r){return function(e,n){if(null==e)return e;if(!rr(e))return t(e,n);for(var o=e.length,i=r?o:-1,s=Object(e);(r?i--:++i<o)&&!1!==n(s[i],i,s););return e}}((function(t,r){return t&&Pe(t,r,rn)}));var nn=function(t){return t};var on=function(t){return"function"==typeof t?t:nn};var sn=function(t,r){return(a(t)?Te:en)(t,on(r))};var an=function(){this.__data__=new ut,this.size=0};var un=function(t){var r=this.__data__,e=r.delete(t);return this.size=r.size,e};var cn=function(t){return this.__data__.get(t)};var fn=function(t){return this.__data__.has(t)};var hn=function(t,r){var e=this.__data__;if(e instanceof ut){var n=e.__data__;if(!ct||n.length<199)return n.push([t,r]),this.size=++e.size,this;e=this.__data__=new wt(n)}return e.set(t,r),this.size=e.size,this};function ln(t){var r=this.__data__=new ut(t);this.size=r.size}ln.prototype.clear=an,ln.prototype.delete=un,ln.prototype.get=cn,ln.prototype.has=fn,ln.prototype.set=hn;var vn=ln;var mn=function(t){return this.__data__.set(t,"__lodash_hash_undefined__"),this};var gn=function(t){return this.__data__.has(t)};function pn(t){var r=-1,e=null==t?0:t.length;for(this.__data__=new wt;++r<e;)this.add(t[r])}pn.prototype.add=pn.prototype.push=mn,pn.prototype.has=gn;var dn=pn;var wn=function(t,r){for(var e=-1,n=null==t?0:t.length;++e<n;)if(r(t[e],e,t))return!0;return!1};var yn=function(t,r){return t.has(r)};var bn=function(t,r,e,n,o,i){var s=1&e,a=t.length,u=r.length;if(a!=u&&!(s&&u>a))return!1;var c=i.get(t),f=i.get(r);if(c&&f)return c==r&&f==t;var h=-1,l=!0,v=2&e?new dn:void 0;for(i.set(t,r),i.set(r,t);++h<a;){var m=t[h],g=r[h];if(n)var p=s?n(g,m,h,r,t,i):n(m,g,h,t,r,i);if(void 0!==p){if(p)continue;l=!1;break}if(v){if(!wn(r,(function(t,r){if(!yn(v,r)&&(m===t||o(m,t,e,n,i)))return v.push(r)}))){l=!1;break}}else if(m!==g&&!o(m,g,e,n,i)){l=!1;break}}return i.delete(t),i.delete(r),l},Mn=f.Uint8Array;var xn=function(t){var r=-1,e=Array(t.size);return t.forEach((function(t,n){e[++r]=[n,t]})),e};var kn=function(t){var r=-1,e=Array(t.size);return t.forEach((function(t){e[++r]=t})),e},En=h?h.prototype:void 0,Sn=En?En.valueOf:void 0;var _n=function(t,r,e,n,o,i,s){switch(e){case"[object DataView]":if(t.byteLength!=r.byteLength||t.byteOffset!=r.byteOffset)return!1;t=t.buffer,r=r.buffer;case"[object ArrayBuffer]":return!(t.byteLength!=r.byteLength||!i(new Mn(t),new Mn(r)));case"[object Boolean]":case"[object Date]":case"[object Number]":return tt(+t,+r);case"[object Error]":return t.name==r.name&&t.message==r.message;case"[object RegExp]":case"[object String]":return t==r+"";case"[object Map]":var a=xn;case"[object Set]":var u=1&n;if(a||(a=kn),t.size!=r.size&&!u)return!1;var c=s.get(t);if(c)return c==r;n|=2,s.set(t,r);var f=bn(a(t),a(r),n,o,i,s);return s.delete(t),f;case"[object Symbol]":if(Sn)return Sn.call(t)==Sn.call(r)}return!1};var jn=function(t,r){for(var e=-1,n=r.length,o=t.length;++e<n;)t[o+e]=r[e];return t};var An=function(t,r,e){var n=r(t);return a(t)?n:jn(n,e(t))};var Rn=function(t,r){for(var e=-1,n=null==t?0:t.length,o=0,i=[];++e<n;){var s=t[e];r(s,e,t)&&(i[o++]=s)}return i};var On=function(){return[]},Cn=Object.prototype.propertyIsEnumerable,In=Object.getOwnPropertySymbols,Nn=In?function(t){return null==t?[]:(t=Object(t),Rn(In(t),(function(r){return Cn.call(t,r)})))}:On;var Fn=function(t){return An(t,rn,Nn)},Tn=Object.prototype.hasOwnProperty;var Pn=function(t,r,e,n,o,i){var s=1&e,a=Fn(t),u=a.length;if(u!=Fn(r).length&&!s)return!1;for(var c=u;c--;){var f=a[c];if(!(s?f in r:Tn.call(r,f)))return!1}var h=i.get(t),l=i.get(r);if(h&&l)return h==r&&l==t;var v=!0;i.set(t,r),i.set(r,t);for(var m=s;++c<u;){var g=t[f=a[c]],p=r[f];if(n)var d=s?n(p,g,f,r,t,i):n(g,p,f,t,r,i);if(!(void 0===d?g===p||o(g,p,e,n,i):d)){v=!1;break}m||(m="constructor"==f)}if(v&&!m){var w=t.constructor,y=r.constructor;w==y||!("constructor"in t)||!("constructor"in r)||"function"==typeof w&&w instanceof w&&"function"==typeof y&&y instanceof y||(v=!1)}return i.delete(t),i.delete(r),v},zn="[object Arguments]",Ln="[object Array]",Vn="[object Object]",qn=Object.prototype.hasOwnProperty;var Dn=function(t,r,e,n,o,i){var s=a(t),u=a(r),c=s?Ln:Qt(t),f=u?Ln:Qt(r),h=(c=c==zn?Vn:c)==Vn,l=(f=f==zn?Vn:f)==Vn,v=c==f;if(v&&Ge(t)){if(!Ge(r))return!1;s=!0,h=!1}if(v&&!h)return i||(i=new vn),s||He(t)?bn(t,r,e,n,o,i):_n(t,r,c,e,n,o,i);if(!(1&e)){var m=h&&qn.call(t,"__wrapped__"),g=l&&qn.call(r,"__wrapped__");if(m||g){var p=m?t.value():t,d=g?r.value():r;return i||(i=new vn),o(p,d,e,n,i)}}return!!v&&(i||(i=new vn),Pn(t,r,e,n,o,i))};var Un=function t(r,e,n,o,i){return r===e||(null==r||null==e||!M(r)&&!M(e)?r!=r&&e!=e:Dn(r,e,n,o,t,i))};var Bn=function(t,r,e,n){var o=e.length,i=o,s=!n;if(null==t)return!i;for(t=Object(t);o--;){var a=e[o];if(s&&a[2]?a[1]!==t[a[0]]:!(a[0]in t))return!1}for(;++o<i;){var u=(a=e[o])[0],c=t[u],f=a[1];if(s&&a[2]){if(void 0===c&&!(u in t))return!1}else{var h=new vn;if(n)var l=n(c,f,u,t,r,h);if(!(void 0===l?Un(f,c,3,n,h):l))return!1}}return!0};var Gn=function(t){return t==t&&!_(t)};var $n=function(t){for(var r=rn(t),e=r.length;e--;){var n=r[e],o=t[n];r[e]=[n,o,Gn(o)]}return r};var Kn=function(t,r){return function(e){return null!=e&&(e[t]===r&&(void 0!==r||t in Object(e)))}};var Wn=function(t){var r=$n(t);return 1==r.length&&r[0][2]?Kn(r[0][0],r[0][1]):function(e){return e===t||Bn(e,t,r)}};var Xn=function(t,r){return null!=t&&r in Object(t)};var Yn=function(t,r,e){for(var n=-1,o=(r=Rt(r,t)).length,i=!1;++n<o;){var s=Ot(r[n]);if(!(i=null!=t&&e(t,s)))break;t=t[s]}return i||++n!=o?i:!!(o=null==t?0:t.length)&&tr(o)&&Ke(s,o)&&(a(t)||Ue(t))};var Jn=function(t,r){return null!=t&&Yn(t,r,Xn)};var Zn=function(t,r){return S(t)&&Gn(r)?Kn(Ot(t),r):function(e){var n=It(e,t);return void 0===n&&n===r?Jn(e,t):Un(r,n,3)}};var Hn=function(t){return function(r){return Ct(r,t)}};var Qn=function(t){return S(t)?nr(Ot(t)):Hn(t)};var to=function(t){return"function"==typeof t?t:null==t?nn:"object"==e(t)?a(t)?Zn(t[0],t[1]):Wn(t):Qn(t)};var ro=function(t,r){var e=-1,n=rr(t)?Array(t.length):[];return en(t,(function(t,o,i){n[++e]=r(t,o,i)})),n};var eo=function(t,r){return(a(t)?Et:ro)(t,to(r))};var no=function(t,r){return Et(r,(function(r){return t[r]}))};var oo=function(t){return null==t?[]:no(t,rn(t))};function io(t){return!(!Sr(t)||""===t)}function so(t){var r=!1;return io(t)?r=!isNaN(Number(t)):function(t){return"[object Number]"===Object.prototype.toString.call(t)}(t)&&(r=!0),r}function ao(t,r){if(!Er(t))return{};if(!jr(r))return{};var e={};return sn(r,(function(r){(function(t,r){return!!Er(t)&&!(!io(r)&&!so(r))&&r in t})(t,r)&&(e[r]=It(t,r))})),e}function uo(t){if(Er(t)){for(var r in t)return!0;return!1}return!1}var co=/\s/;var fo=function(t){for(var r=t.length;r--&&co.test(t.charAt(r)););return r},ho=/^\s+/;var lo=function(t){return t?t.slice(0,fo(t)+1).replace(ho,""):t},vo=/^[-+]0x[0-9a-f]+$/i,mo=/^0b[01]+$/i,go=/^0o[0-7]+$/i,po=parseInt;var wo=function(t){if("number"==typeof t)return t;if(x(t))return NaN;if(_(t)){var r="function"==typeof t.valueOf?t.valueOf():t;t=_(r)?r+"":r}if("string"!=typeof t)return 0===t?t:+t;t=lo(t);var e=mo.test(t);return e||go.test(t)?po(t.slice(2),e?2:8):vo.test(t)?NaN:+t},yo=1/0;var bo=function(t){return t?(t=wo(t))===yo||t===-1/0?17976931348623157e292*(t<0?-1:1):t==t?t:0:0===t?t:0};var Mo=function(t){var r=bo(t),e=r%1;return r==r?e?r-e:r:0},xo=f.isFinite,ko=Math.min;var Eo=function(t){var r=Math[t];return function(t,e){if(t=wo(t),(e=null==e?0:ko(Mo(e),292))&&xo(t)){var n=(At(t)+"e").split("e"),o=r(n[0]+"e"+(+n[1]+e));return+((n=(At(o)+"e").split("e"))[0]+"e"+(+n[1]-e))}return r(t)}}("round");function So(t){if(!so(t))return 0;t=function(t){return so(t)?bo(t):0}(t);var r=Eo(t);return"0"===String(r)?0:r}var _o=Array.prototype.join;var jo=function(t,r){return null==t?"":_o.call(t,r)},Ao=function t(r){var e=this;Ar(this,t),this.getCost=function(){return e.Elements.map((function(t){return t.DistanceFromMedoid})).reduce((function(t,r){return t+r}),0)},this.findBestMedoidIdx=function(t){return e.Elements.map((function(r){return e.calcCostForGivenElementAsMedoid(r,t)})).reduce((function(t,r,e,n){return r.CostIfMadeMedoid<n[t].CostIfMadeMedoid?e:t}),0)},this.calcCostForGivenElementAsMedoid=function(r,n){return{CostIfMadeMedoid:new t({Elements:e.Elements.map((function(t){return{DistanceFromMedoid:n(t.Element,r.Element),Element:t.Element}})),Medoid:r.Element}).getCost(),Element:r}},this.Elements=r.Elements,this.Medoid=r.Medoid},Ro=Object.defineProperty({Cluster:Ao},"__esModule",{value:!0}),Oo=Object.defineProperty({distance:function(t,r){if(t.length!==r.length)throw new Error("the inputs must have the same dimension");var e=Array.from(t.keys()).map((function(e){return Math.pow(Math.abs(t[e]-r[e]),2)})).reduce((function(t,r){return t+r}),0);return Math.sqrt(e)}},"__esModule",{value:!0}),Co=Object.defineProperty({kGtElementArrLength:"k must be less than the number of elements in the input array"},"__esModule",{value:!0});function Io(t,r){var e="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!e){if(Array.isArray(t)||(e=function(t,r){if(!t)return;if("string"==typeof t)return No(t,r);var e=Object.prototype.toString.call(t).slice(8,-1);"Object"===e&&t.constructor&&(e=t.constructor.name);if("Map"===e||"Set"===e)return Array.from(t);if("Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e))return No(t,r)}(t))||r&&t&&"number"==typeof t.length){e&&(t=e);var n=0,o=function(){};return{s:o,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,s=!0,a=!1;return{s:function(){e=e.call(t)},n:function(){var t=e.next();return s=t.done,t},e:function(t){a=!0,i=t},f:function(){try{s||null==e.return||e.return()}finally{if(a)throw i}}}}function No(t,r){(null==r||r>t.length)&&(r=t.length);for(var e=0,n=new Array(r);e<r;e++)n[e]=t[e];return n}var Fo=function(){function t(r,e,n){var o=this;Ar(this,t),this.Elements=r,this.K=e,this.DistanceFn=n,this.OptimisationCompleted=!1,this.iterate=function(){o.IterationCount++,o.Clusters||o.allocateToClustersAroundCurrentMedoids();for(var r=o.Medoids,e=o.Clusters,n=o.calculateCurrentCost(),i=n,s=0;s<o.Medoids.length;s++){var a,u=Io(o.Elements.filter((function(t){return 0===o.Medoids.filter((function(r){return 0===o.DistanceFn(t,r)})).length})));try{for(u.s();!(a=u.n()).done;){var c=a.value,f=o.Medoids.slice();f[s]=c;var h=new t(o.Elements.slice(),o.K,o.DistanceFn);h.Medoids=f,h.allocateToClustersAroundCurrentMedoids();var l=h.calculateCurrentCost();l<i&&(i=l,o.Clusters=h.Clusters,o.Medoids=f)}}catch(t){u.e(t)}finally{u.f()}}return o.calculateCurrentCost()<n||(o.Clusters=e,o.Medoids=r,o.OptimisationCompleted=!0,!1)},this.getClusteredData=function(){return o.OptimisationCompleted||o.runToCompletion(),o.Clusters.map((function(t){return t.Elements.map((function(t){return t.Element}))}))},this.runToCompletion=function(){for(;o.iterate(););},this.allocateToClustersAroundCurrentMedoids=function(){o.Clusters=new Array,o.Medoids.forEach((function(t){o.Clusters.push(new Ro.Cluster({Elements:[],Medoid:t}))})),o.Elements.forEach((function(t,r){var e=o.findDistances(o.Clusters.map((function(t){return t.Medoid})),t),n=e.reduce((function(t,r,e,n){return r<n[t]?e:t}),0);o.Clusters[n].Elements.push({DistanceFromMedoid:e[n],Element:t})}))},this.calculateCurrentCost=function(){return o.Clusters.map((function(t){return t.getCost()})).reduce((function(t,r){return t+r}),0)},this.findDistances=function(t,r){return t.map((function(t){return o.DistanceFn(t,r)}))},this.selectInitialMedoids=function(){if(o.K>=o.Elements.length)throw Co.kGtElementArrLength;for(var t=[],r=function(t,r){var e,n=Io(r);try{for(n.s();!(e=n.n()).done;){var i=e.value;if(0===o.DistanceFn(i,t))return!1}}catch(t){n.e(t)}finally{n.f()}return!0},e=0;e<o.Elements.length&&t.length<o.K;)r(o.Elements[e],t)&&t.push(o.Elements[e]),e++;return t},this.DistanceFn=this.DistanceFn||Oo.distance,this.Medoids=this.selectInitialMedoids(),this.IterationCount=0}return Or(t,[{key:"OptimisationStarted",get:function(){return this.IterationCount>0}}]),t}();Fo.clusterElements=function(t,r,e){return Fo.getInstance(t,r,e),new Array},Fo.getInstance=function(t,r,e){return new Fo(t,r,e)};var To=Fo,Po=Object.defineProperty({Clusterer:To},"__esModule",{value:!0}),zo=o(i((function(t,r){function e(t){for(var e in t)r.hasOwnProperty(e)||(r[e]=t[e])}Object.defineProperty(r,"__esModule",{value:!0}),e(Ro),e(Po)})));function Lo(t,r){for(var e=0,n=0;n<t.length;n++)e+=(t[n]-r[n])*(t[n]-r[n]);return e}var Vo={distanceFunction:Lo};function qo(t,r){var e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Vo,n=e.distanceFunction||Vo.distanceFunction,o=e.similarityFunction||Vo.similarityFunction,i=-1;if("function"==typeof o)for(var s=Number.MIN_VALUE,a=0;a<t.length;a++){var u=o(r,t[a]);u>s&&(s=u,i=a)}else{if("function"!=typeof n)throw new Error("A similarity or distance function it's required");for(var c=Number.MAX_VALUE,f=0;f<t.length;f++){var h=n(r,t[f]);h<c&&(c=h,i=f)}}return i}function Do(t,r,e,n){for(var o=0;o<t.length;o++)e[o]=qo(r,t[o],{distanceFunction:n});return e}var Uo=function(){function t(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Date.now();Ar(this,t),this.state=new Uint32Array(4),this.init(r),this.random=this.getFloat.bind(this)}return Or(t,[{key:"getUint32",value:function(){return this.nextState(),this.state[3]+this.state[2]>>>0}},{key:"getFloat",value:function(){return 5.960464477539063e-8*(this.getUint32()>>>8)}},{key:"init",value:function(t){if(!Number.isInteger(t))throw new TypeError("seed must be an integer");this.state[0]=t,this.state[1]=0,this.state[2]=0,this.state[3]=0;for(var r=1;r<8;r++)this.state[3&r]^=r+(e=1812433253,n=this.state[r-1&3]^this.state[r-1&3]>>>30>>>0,o=void 0,o=65535&(e>>>=0),((e-o)*(n>>>=0)>>>0)+o*n>>>0)>>>0;var e,n,o;this.periodCertification();for(var i=0;i<8;i++)this.nextState()}},{key:"periodCertification",value:function(){0===this.state[0]&&0===this.state[1]&&0===this.state[2]&&0===this.state[3]&&(this.state[0]=88,this.state[1]=83,this.state[2]=65,this.state[3]=68)}},{key:"nextState",value:function(){var t=this.state[0];t^=t<<15,t^=t>>>18,t^=this.state[3]<<11,this.state[0]=this.state[1],this.state[1]=this.state[2],this.state[2]=this.state[3],this.state[3]=t}}]),t}();function Bo(t){var r,e,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Math.random,i=n.size,s=void 0===i?1:i,a=n.replace,u=void 0!==a&&a,c=n.probabilities;if(r="number"==typeof t?Go(t):t.slice(),c){if(!u)throw new Error("choice with probabilities and no replacement is not implemented");if(c.length!==r.length)throw new Error("the length of probabilities option should be equal to the number of choices");e=[c[0]];for(var f=1;f<c.length;f++)e[f]=e[f-1]+c[f];if(Math.abs(1-e[e.length-1])>1e-8)throw new Error("probabilities should sum to 1, but instead sums to ".concat(e[e.length-1]))}if(!1===u&&s>r.length)throw new Error("size option is too large");for(var h=[],l=0;l<s;l++){var v=$o(r.length,o,e);h.push(r[v]),u||r.splice(v,1)}return h}function Go(t){for(var r=[],e=0;e<t;e++)r.push(e);return r}function $o(t,r,e){var n=r();if(e){for(var o=0;n>e[o];)o++;return o}return Math.floor(n*t)}var Ko=function(){function t(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Math.random;if(Ar(this,t),"number"==typeof r){var e=new Uo(r);this.randomGenerator=e.random}else this.randomGenerator=r}return Or(t,[{key:"choice",value:function(t,r){return Bo(t,r,this.randomGenerator)}},{key:"random",value:function(){return this.randomGenerator()}},{key:"randInt",value:function(t,r){return void 0===r&&(r=t,t=0),t+Math.floor(this.randomGenerator()*(r-t))}},{key:"randomSample",value:function(t){for(var r=[],e=0;e<t;e++)r.push(this.random());return r}}]),t}();function Wo(t,r){for(var e=new pe(t.rows,r.rows),n=0;n<t.rows;n++)for(var o=0;o<r.rows;o++)e.set(n,o,Lo(t.getRow(n),r.getRow(o)));return e}function Xo(t){for(var r=[],e=0;e<t;e++)r.push(e);return r}function Yo(t){for(var r=[t[0]],e=1;e<t.length;e++)r[e]=r[e-1]+t[e];return r}var Jo=Symbol("distance"),Zo=function(){function t(r,e,n,o,i){Ar(this,t),this.clusters=r,this.centroids=e,this.converged=n,this.iterations=o,this[Jo]=i}return Or(t,[{key:"nearest",value:function(t){var r=new Array(t.length);return Do(t,this.centroids.map((function(t){return t.centroid})),r,this[Jo])}},{key:"computeInformation",value:function(r){for(var e=this.centroids.map((function(t){return{centroid:t,error:0,size:0}})),n=0;n<r.length;n++)e[this.clusters[n]].error+=this[Jo](r[n],this.centroids[this.clusters[n]]),e[this.clusters[n]].size++;for(var o=0;o<this.centroids.length;o++)e[o].size?e[o].error/=e[o].size:e[o].error=null;return new t(this.clusters,e,this.converged,this.iterations,this[Jo])}}]),t}(),Ho=s.mark(ri),Qo={maxIterations:100,tolerance:1e-6,withIterations:!1,initialization:"kmeans++",distanceFunction:Lo};function ti(t,r,e,n,o,i){var s=function(t,r,e,n){for(var o=r[0].length,i=new Array(n),s=new Array(n),a=0;a<n;a++){i[a]=new Array(o),s[a]=0;for(var u=0;u<o;u++)i[a][u]=0}for(var c=0;c<r.length;c++){s[e[c]]++;for(var f=0;f<o;f++)i[e[c]][f]+=r[c][f]}for(var h=0;h<n;h++)for(var l=0;l<o;l++)s[h]?i[h][l]/=s[h]:i[h][l]=t[h][l];return i}(t,r,e=Do(r,t,e,o.distanceFunction),n),a=function(t,r,e,n){for(var o=0;o<t.length;o++)if(e(t[o],r[o])>n)return!1;return!0}(s,t,o.distanceFunction,o.tolerance);return new Zo(e,s,a,i,o.distanceFunction)}function ri(t,r,e,n,o){var i,a,u;return s.wrap((function(s){for(;;)switch(s.prev=s.next){case 0:i=!1,a=0;case 2:if(i||!(a<o.maxIterations)){s.next=10;break}return u=ti(t,r,e,n,o,++a),s.next=6,u.computeInformation(r);case 6:i=u.converged,t=u.centroids,s.next=2;break;case 10:case"end":return s.stop()}}),Ho)}function ei(t,r,e){if(e=Object.assign({},Qo,e),r<=0||r>t.length||!Number.isInteger(r))throw new Error("K should be a positive integer smaller than the number of points");var n;if(Array.isArray(e.initialization)){if(e.initialization.length!==r)throw new Error("The initial centers should have the same length as K");n=e.initialization}else switch(e.initialization){case"kmeans++":n=function(t,r){var e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=(t=new pe(t)).rows,o=new Ko(e.seed),i=[],s=e.localTrials||2+Math.floor(Math.log(r)),a=o.randInt(n);i.push(t.getRow(a));for(var u=new pe(1,t.rows),c=0;c<t.rows;c++)u.set(0,c,Lo(t.getRow(c),i[0]));for(var f=[Yo(u.getRow(0))],h=1/f[0][n-1],l=pe.mul(u,h),v=1;v<r;v++){for(var m=o.choice(n,{replace:!0,size:s,probabilities:l[0]}),g=Wo(t.selection(m,Xo(t.columns)),t),p=void 0,d=void 0,w=void 0,y=0;y<s;y++){var b=pe.min(u,[g.getRow(y)]),M=b.sum();(void 0===p||M<d)&&(p=m[y],d=M,w=b)}i[v]=t.getRow(p),f=[Yo((u=w).getRow(0))],l=pe.mul(u,1/f[0][n-1])}return i}(t,r,e);break;case"random":n=function(t,r,e){return new Ko(e).choice(t,{size:r})}(t,r,e.seed);break;case"mostDistant":n=function(t,r,e,n){var o=new Ko(n),i=new Array(r);if(i[0]=Math.floor(o.random()*t.length),r>1){for(var s={dist:-1,index:-1},a=0;a<t.length;++a)e[i[0]][a]>s.dist&&(s.dist=e[i[0]][a],s.index=a);if(i[1]=s.index,r>2)for(var u=2;u<r;++u){for(var c={dist:-1,index:-1},f=0;f<t.length;++f){for(var h={dist:Number.MAX_VALUE,index:-1},l=0;l<u;++l)e[l][f]<h.dist&&-1===i.indexOf(f)&&(h={dist:e[l][f],index:f});h.dist!==Number.MAX_VALUE&&h.dist>c.dist&&(c=Object.assign({},h))}i[u]=c.index}}return i.map((function(r){return t[r]}))}(t,r,function(t,r){for(var e=new Array(t.length),n=0;n<t.length;++n)for(var o=n;o<t.length;++o){e[n]||(e[n]=new Array(t.length)),e[o]||(e[o]=new Array(t.length));var i=r(t[n],t[o]);e[n][o]=i,e[o][n]=i}return e}(t,e.distanceFunction),e.seed);break;default:throw new Error('Unknown initialization method: "'.concat(e.initialization,'"'))}0===e.maxIterations&&(e.maxIterations=Number.MAX_VALUE);var o=new Array(t.length);if(e.withIterations)return ri(n,t,o,r,e);for(var i,s=!1,a=0;!s&&a<e.maxIterations;)s=(i=ti(n,t,o,r,e,++a)).converged,n=i.centroids;return i.computeInformation(t)}function ni(t,r){var e={};function n(t){return jo(t,":")}sn(t,(function(t,r){var o=n(t);e[o]=r}));var o=zo.Clusterer.getInstance(t,r).getClusteredData();return o=eo(o,(function(t){return eo(t,(function(t){var r=n(t);return e[r]}))}))}function oi(t,r){var e=ei(t,r),n={};return sn(e.clusters,(function(t,r){n[t]||(n[t]=[]),n[t].push(r)})),oo(n)}function ii(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},e=It(r,"kNumber");e=so(e)?So(e):2;var n,o=It(r,"mode");if("k-medoids"!==o&&"k-means"!==o&&(o="k-medoids"),"k-medoids"===o)n=ni(t,e);else{if("k-means"!==o)throw new Error("invalid mode");n=oi(t,e)}return n}function si(t){var r={};sn(t,(function(t){sn(t,(function(t,e){r[e]||(r[e]=0),0===r[e]&&so(t)&&(r[e]=1),1!==r[e]||so(t)||(r[e]=-1)}))}));var e=[];return sn(r,(function(t,r){1===t&&e.push(r)})),e}function ai(t,r){return eo(t,(function(t){var e=ao(t,r);return oo(e)}))}function ui(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!jr(t))throw new Error("data is not eff. array");var e=It(r,"kNumber");e=so(e)?So(e):2;var n=It(r,"nCompNIPALS");n=so(n)?So(n):2;var o=It(r,"mode"),i="",s=br(t),a=0,u=0;if(sn(t,(function(t){uo(t)?a+=1:jr(t)&&(u+=1)})),a===s)i="obj";else{if(u!==s)throw new Error("data is not of the same type");i="mat"}var c,f=null;"obj"===i?(f=si(t),c=ai(t,f)):c=t;var h=Fe(c,{nCompNIPALS:n}),l=ii(h,{kNumber:e,mode:o}),v=eo(l,(function(t){return eo(t,(function(t){return h[t]}))})),m=eo(l,(function(r){return eo(r,(function(r){return t[r]}))}));return{keys:f,ginds:l,gltdt:m,gmat:v}}function ci(){return(ci=r(s.mark((function t(r){var e,n=arguments;return s.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e=n.length>1&&void 0!==n[1]?n[1]:{},t.abrupt("return",Fe(r,e));case 2:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function fi(){return(fi=r(s.mark((function t(r){var e,n=arguments;return s.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e=n.length>1&&void 0!==n[1]?n[1]:{},t.prev=1,t.abrupt("return",ui(r,e));case 5:return t.prev=5,t.t0=t.catch(1),t.abrupt("return",Promise.reject(t.t0));case 8:case"end":return t.stop()}}),t,null,[[1,5]])})))).apply(this,arguments)}return{PCA:function(t){return ci.apply(this,arguments)},cluster:function(t){return fi.apply(this,arguments)}}}));
|
|
6
|
+
!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(t="undefined"!=typeof globalThis?globalThis:t||self)["w-cluster"]=r()}(this,(function(){"use strict";function t(t,r,e,n,o,i,s){try{var a=t[i](s),u=a.value}catch(t){return void e(t)}a.done?r(u):Promise.resolve(u).then(n,o)}function r(r){return function(){var e=this,n=arguments;return new Promise((function(o,i){var s=r.apply(e,n);function a(r){t(s,o,i,a,u,"next",r)}function u(r){t(s,o,i,a,u,"throw",r)}a(void 0)}))}}function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},e(t)}var n="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function o(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function i(t){var r={exports:{}};return t(r,r.exports),r.exports}var s=i((function(t){var r=function(t){var r,n=Object.prototype,o=n.hasOwnProperty,i="function"==typeof Symbol?Symbol:{},s=i.iterator||"@@iterator",a=i.asyncIterator||"@@asyncIterator",u=i.toStringTag||"@@toStringTag";function c(t,r,e){return Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}),t[r]}try{c({},"")}catch(t){c=function(t,r,e){return t[r]=e}}function f(t,r,e,n){var o=r&&r.prototype instanceof d?r:d,i=Object.create(o.prototype),s=new A(n||[]);return i._invoke=function(t,r,e){var n=l;return function(o,i){if(n===m)throw new Error("Generator is already running");if(n===g){if("throw"===o)throw i;return C()}for(e.method=o,e.arg=i;;){var s=e.delegate;if(s){var a=_(s,e);if(a){if(a===p)continue;return a}}if("next"===e.method)e.sent=e._sent=e.arg;else if("throw"===e.method){if(n===l)throw n=g,e.arg;e.dispatchException(e.arg)}else"return"===e.method&&e.abrupt("return",e.arg);n=m;var u=h(t,r,e);if("normal"===u.type){if(n=e.done?g:v,u.arg===p)continue;return{value:u.arg,done:e.done}}"throw"===u.type&&(n=g,e.method="throw",e.arg=u.arg)}}}(t,e,s),i}function h(t,r,e){try{return{type:"normal",arg:t.call(r,e)}}catch(t){return{type:"throw",arg:t}}}t.wrap=f;var l="suspendedStart",v="suspendedYield",m="executing",g="completed",p={};function d(){}function w(){}function y(){}var b={};c(b,s,(function(){return this}));var M=Object.getPrototypeOf,x=M&&M(M(O([])));x&&x!==n&&o.call(x,s)&&(b=x);var k=y.prototype=d.prototype=Object.create(b);function E(t){["next","throw","return"].forEach((function(r){c(t,r,(function(t){return this._invoke(r,t)}))}))}function S(t,r){function n(i,s,a,u){var c=h(t[i],t,s);if("throw"!==c.type){var f=c.arg,l=f.value;return l&&"object"===e(l)&&o.call(l,"__await")?r.resolve(l.__await).then((function(t){n("next",t,a,u)}),(function(t){n("throw",t,a,u)})):r.resolve(l).then((function(t){f.value=t,a(f)}),(function(t){return n("throw",t,a,u)}))}u(c.arg)}var i;this._invoke=function(t,e){function o(){return new r((function(r,o){n(t,e,r,o)}))}return i=i?i.then(o,o):o()}}function _(t,e){var n=t.iterator[e.method];if(n===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=r,_(t,e),"throw"===e.method))return p;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return p}var o=h(n,t.iterator,e.arg);if("throw"===o.type)return e.method="throw",e.arg=o.arg,e.delegate=null,p;var i=o.arg;return i?i.done?(e[t.resultName]=i.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=r),e.delegate=null,p):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,p)}function j(t){var r={tryLoc:t[0]};1 in t&&(r.catchLoc=t[1]),2 in t&&(r.finallyLoc=t[2],r.afterLoc=t[3]),this.tryEntries.push(r)}function R(t){var r=t.completion||{};r.type="normal",delete r.arg,t.completion=r}function A(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(j,this),this.reset(!0)}function O(t){if(t){var e=t[s];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,i=function e(){for(;++n<t.length;)if(o.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=r,e.done=!0,e};return i.next=i}}return{next:C}}function C(){return{value:r,done:!0}}return w.prototype=y,c(k,"constructor",y),c(y,"constructor",w),w.displayName=c(y,u,"GeneratorFunction"),t.isGeneratorFunction=function(t){var r="function"==typeof t&&t.constructor;return!!r&&(r===w||"GeneratorFunction"===(r.displayName||r.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,y):(t.__proto__=y,c(t,u,"GeneratorFunction")),t.prototype=Object.create(k),t},t.awrap=function(t){return{__await:t}},E(S.prototype),c(S.prototype,a,(function(){return this})),t.AsyncIterator=S,t.async=function(r,e,n,o,i){void 0===i&&(i=Promise);var s=new S(f(r,e,n,o),i);return t.isGeneratorFunction(e)?s:s.next().then((function(t){return t.done?t.value:s.next()}))},E(k),c(k,u,"Generator"),c(k,s,(function(){return this})),c(k,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var r=[];for(var e in t)r.push(e);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},t.values=O,A.prototype={constructor:A,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=r,this.done=!1,this.delegate=null,this.method="next",this.arg=r,this.tryEntries.forEach(R),!t)for(var e in this)"t"===e.charAt(0)&&o.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=r)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(n,o){return a.type="throw",a.arg=t,e.next=n,o&&(e.method="next",e.arg=r),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var s=this.tryEntries[i],a=s.completion;if("root"===s.tryLoc)return n("end");if(s.tryLoc<=this.prev){var u=o.call(s,"catchLoc"),c=o.call(s,"finallyLoc");if(u&&c){if(this.prev<s.catchLoc)return n(s.catchLoc,!0);if(this.prev<s.finallyLoc)return n(s.finallyLoc)}else if(u){if(this.prev<s.catchLoc)return n(s.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<s.finallyLoc)return n(s.finallyLoc)}}}},abrupt:function(t,r){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc<=this.prev&&o.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var i=n;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=r&&r<=i.finallyLoc&&(i=null);var s=i?i.completion:{};return s.type=t,s.arg=r,i?(this.method="next",this.next=i.finallyLoc,p):this.complete(s)},complete:function(t,r){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&r&&(this.next=r),p},finish:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.finallyLoc===t)return this.complete(e.completion,e.afterLoc),R(e),p}},catch:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.tryLoc===t){var n=e.completion;if("throw"===n.type){var o=n.arg;R(e)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,n){return this.delegate={iterator:O(t),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=r),p}},t}(t.exports);try{regeneratorRuntime=r}catch(t){"object"===("undefined"==typeof globalThis?"undefined":e(globalThis))?globalThis.regeneratorRuntime=r:Function("r","regeneratorRuntime = r")(r)}})),a=s,u=Array.isArray,c="object"==e(n)&&n&&n.Object===Object&&n,f="object"==("undefined"==typeof self?"undefined":e(self))&&self&&self.Object===Object&&self,h=c||f||Function("return this")(),l=h.Symbol,v=Object.prototype,m=v.hasOwnProperty,g=v.toString,p=l?l.toStringTag:void 0;var d=function(t){var r=m.call(t,p),e=t[p];try{t[p]=void 0;var n=!0}catch(t){}var o=g.call(t);return n&&(r?t[p]=e:delete t[p]),o},w=Object.prototype.toString;var y=function(t){return w.call(t)},b=l?l.toStringTag:void 0;var M=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":b&&b in Object(t)?d(t):y(t)};var x=function(t){return null!=t&&"object"==e(t)};var k=function(t){return"symbol"==e(t)||x(t)&&"[object Symbol]"==M(t)},E=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,S=/^\w*$/;var _=function(t,r){if(u(t))return!1;var n=e(t);return!("number"!=n&&"symbol"!=n&&"boolean"!=n&&null!=t&&!k(t))||(S.test(t)||!E.test(t)||null!=r&&t in Object(r))};var j=function(t){var r=e(t);return null!=t&&("object"==r||"function"==r)};var R,A=function(t){if(!j(t))return!1;var r=M(t);return"[object Function]"==r||"[object GeneratorFunction]"==r||"[object AsyncFunction]"==r||"[object Proxy]"==r},O=h["__core-js_shared__"],C=(R=/[^.]+$/.exec(O&&O.keys&&O.keys.IE_PROTO||""))?"Symbol(src)_1."+R:"";var I=function(t){return!!C&&C in t},N=Function.prototype.toString;var F=function(t){if(null!=t){try{return N.call(t)}catch(t){}try{return t+""}catch(t){}}return""},T=/^\[object .+?Constructor\]$/,P=Function.prototype,z=Object.prototype,L=P.toString,V=z.hasOwnProperty,q=RegExp("^"+L.call(V).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");var D=function(t){return!(!j(t)||I(t))&&(A(t)?q:T).test(F(t))};var U=function(t,r){return null==t?void 0:t[r]};var B=function(t,r){var e=U(t,r);return D(e)?e:void 0},G=B(Object,"create");var $=function(){this.__data__=G?G(null):{},this.size=0};var K=function(t){var r=this.has(t)&&delete this.__data__[t];return this.size-=r?1:0,r},W=Object.prototype.hasOwnProperty;var X=function(t){var r=this.__data__;if(G){var e=r[t];return"__lodash_hash_undefined__"===e?void 0:e}return W.call(r,t)?r[t]:void 0},Y=Object.prototype.hasOwnProperty;var J=function(t){var r=this.__data__;return G?void 0!==r[t]:Y.call(r,t)};var Z=function(t,r){var e=this.__data__;return this.size+=this.has(t)?0:1,e[t]=G&&void 0===r?"__lodash_hash_undefined__":r,this};function H(t){var r=-1,e=null==t?0:t.length;for(this.clear();++r<e;){var n=t[r];this.set(n[0],n[1])}}H.prototype.clear=$,H.prototype.delete=K,H.prototype.get=X,H.prototype.has=J,H.prototype.set=Z;var Q=H;var tt=function(){this.__data__=[],this.size=0};var rt=function(t,r){return t===r||t!=t&&r!=r};var et=function(t,r){for(var e=t.length;e--;)if(rt(t[e][0],r))return e;return-1},nt=Array.prototype.splice;var ot=function(t){var r=this.__data__,e=et(r,t);return!(e<0)&&(e==r.length-1?r.pop():nt.call(r,e,1),--this.size,!0)};var it=function(t){var r=this.__data__,e=et(r,t);return e<0?void 0:r[e][1]};var st=function(t){return et(this.__data__,t)>-1};var at=function(t,r){var e=this.__data__,n=et(e,t);return n<0?(++this.size,e.push([t,r])):e[n][1]=r,this};function ut(t){var r=-1,e=null==t?0:t.length;for(this.clear();++r<e;){var n=t[r];this.set(n[0],n[1])}}ut.prototype.clear=tt,ut.prototype.delete=ot,ut.prototype.get=it,ut.prototype.has=st,ut.prototype.set=at;var ct=ut,ft=B(h,"Map");var ht=function(){this.size=0,this.__data__={hash:new Q,map:new(ft||ct),string:new Q}};var lt=function(t){var r=e(t);return"string"==r||"number"==r||"symbol"==r||"boolean"==r?"__proto__"!==t:null===t};var vt=function(t,r){var e=t.__data__;return lt(r)?e["string"==typeof r?"string":"hash"]:e.map};var mt=function(t){var r=vt(this,t).delete(t);return this.size-=r?1:0,r};var gt=function(t){return vt(this,t).get(t)};var pt=function(t){return vt(this,t).has(t)};var dt=function(t,r){var e=vt(this,t),n=e.size;return e.set(t,r),this.size+=e.size==n?0:1,this};function wt(t){var r=-1,e=null==t?0:t.length;for(this.clear();++r<e;){var n=t[r];this.set(n[0],n[1])}}wt.prototype.clear=ht,wt.prototype.delete=mt,wt.prototype.get=gt,wt.prototype.has=pt,wt.prototype.set=dt;var yt=wt;function bt(t,r){if("function"!=typeof t||null!=r&&"function"!=typeof r)throw new TypeError("Expected a function");var e=function e(){var n=arguments,o=r?r.apply(this,n):n[0],i=e.cache;if(i.has(o))return i.get(o);var s=t.apply(this,n);return e.cache=i.set(o,s)||i,s};return e.cache=new(bt.Cache||yt),e}bt.Cache=yt;var Mt=bt;var xt=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,kt=/\\(\\)?/g,Et=function(t){var r=Mt(t,(function(t){return 500===e.size&&e.clear(),t})),e=r.cache;return r}((function(t){var r=[];return 46===t.charCodeAt(0)&&r.push(""),t.replace(xt,(function(t,e,n,o){r.push(n?o.replace(kt,"$1"):e||t)})),r}));var St=function(t,r){for(var e=-1,n=null==t?0:t.length,o=Array(n);++e<n;)o[e]=r(t[e],e,t);return o},_t=l?l.prototype:void 0,jt=_t?_t.toString:void 0;var Rt=function t(r){if("string"==typeof r)return r;if(u(r))return St(r,t)+"";if(k(r))return jt?jt.call(r):"";var e=r+"";return"0"==e&&1/r==-Infinity?"-0":e};var At=function(t){return null==t?"":Rt(t)};var Ot=function(t,r){return u(t)?t:_(t,r)?[t]:Et(At(t))};var Ct=function(t){if("string"==typeof t||k(t))return t;var r=t+"";return"0"==r&&1/t==-Infinity?"-0":r};var It=function(t,r){for(var e=0,n=(r=Ot(r,t)).length;null!=t&&e<n;)t=t[Ct(r[e++])];return e&&e==n?t:void 0};var Nt=function(t,r,e){var n=null==t?void 0:It(t,r);return void 0===n?e:n},Ft=Object.prototype;var Tt=function(t){var r=t&&t.constructor;return t===("function"==typeof r&&r.prototype||Ft)};var Pt=function(t,r){return function(e){return t(r(e))}}(Object.keys,Object),zt=Object.prototype.hasOwnProperty;var Lt=function(t){if(!Tt(t))return Pt(t);var r=[];for(var e in Object(t))zt.call(t,e)&&"constructor"!=e&&r.push(e);return r},Vt=B(h,"DataView"),qt=B(h,"Promise"),Dt=B(h,"Set"),Ut=B(h,"WeakMap"),Bt="[object Map]",Gt="[object Promise]",$t="[object Set]",Kt="[object WeakMap]",Wt="[object DataView]",Xt=F(Vt),Yt=F(ft),Jt=F(qt),Zt=F(Dt),Ht=F(Ut),Qt=M;(Vt&&Qt(new Vt(new ArrayBuffer(1)))!=Wt||ft&&Qt(new ft)!=Bt||qt&&Qt(qt.resolve())!=Gt||Dt&&Qt(new Dt)!=$t||Ut&&Qt(new Ut)!=Kt)&&(Qt=function(t){var r=M(t),e="[object Object]"==r?t.constructor:void 0,n=e?F(e):"";if(n)switch(n){case Xt:return Wt;case Yt:return Bt;case Jt:return Gt;case Zt:return $t;case Ht:return Kt}return r});var tr=Qt;var rr=function(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=9007199254740991};var er=function(t){return null!=t&&rr(t.length)&&!A(t)};var nr=function(t){return"string"==typeof t||!u(t)&&x(t)&&"[object String]"==M(t)};var or=function(t){return function(r){return null==r?void 0:r[t]}},ir=or("length"),sr=RegExp("[\\u200d\\ud800-\\udfff\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff\\ufe0e\\ufe0f]");var ar=function(t){return sr.test(t)},ur="[\\ud800-\\udfff]",cr="[\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff]",fr="\\ud83c[\\udffb-\\udfff]",hr="[^\\ud800-\\udfff]",lr="(?:\\ud83c[\\udde6-\\uddff]){2}",vr="[\\ud800-\\udbff][\\udc00-\\udfff]",mr="(?:"+cr+"|"+fr+")"+"?",gr="[\\ufe0e\\ufe0f]?",pr=gr+mr+("(?:\\u200d(?:"+[hr,lr,vr].join("|")+")"+gr+mr+")*"),dr="(?:"+[hr+cr+"?",cr,lr,vr,ur].join("|")+")",wr=RegExp(fr+"(?="+fr+")|"+dr+pr,"g");var yr=function(t){for(var r=wr.lastIndex=0;wr.test(t);)++r;return r};var br=function(t){return ar(t)?yr(t):ir(t)};var Mr=function(t){if(null==t)return 0;if(er(t))return nr(t)?br(t):t.length;var r=tr(t);return"[object Map]"==r||"[object Set]"==r?t.size:Lt(t).length};var xr=function(t){return"number"==typeof t||x(t)&&"[object Number]"==M(t)};var kr=function(t){return!0===t||!1===t||x(t)&&"[object Boolean]"==M(t)};function Er(t){return"[object Array]"===Object.prototype.toString.call(t)}function Sr(t){return"[object Object]"===Object.prototype.toString.call(t)}function _r(t){return"[object String]"===Object.prototype.toString.call(t)}function jr(t){return!!function(t){return"[object Undefined]"===Object.prototype.toString.call(t)}(t)||(!!function(t){return"[object Null]"===Object.prototype.toString.call(t)}(t)||(!!function(t){if(Sr(t)){for(var r in t)return!1;return!0}return!1}(t)||(!!function(t){return!(!_r(t)||""!==t)}(t)||!!function(t){return!!Er(t)&&0===t.length}(t))))}function Rr(t){return!!Er(t)&&(0!==t.length&&(1!==t.length||!jr(t[0])))}function Ar(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")}function Or(t,r){for(var e=0;e<r.length;e++){var n=r[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function Cr(t,r,e){return r&&Or(t.prototype,r),e&&Or(t,e),Object.defineProperty(t,"prototype",{writable:!1}),t}function Ir(t,r){return Ir=Object.setPrototypeOf||function(t,r){return t.__proto__=r,t},Ir(t,r)}function Nr(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(r&&r.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),r&&Ir(t,r)}function Fr(t,r){if(r&&("object"===e(r)||"function"==typeof r))return r;if(void 0!==r)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}function Tr(t){return Tr=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},Tr(t)}var Pr=Object.prototype.toString;function zr(t){return Pr.call(t).endsWith("Array]")}function Lr(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!zr(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");var e=r.fromIndex,n=void 0===e?0:e,o=r.toIndex,i=void 0===o?t.length:o;if(n<0||n>=t.length||!Number.isInteger(n))throw new Error("fromIndex must be a positive integer smaller than length");if(i<=n||i>t.length||!Number.isInteger(i))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var s=t[n],a=n+1;a<i;a++)t[a]>s&&(s=t[a]);return s}function Vr(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!zr(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");var e=r.fromIndex,n=void 0===e?0:e,o=r.toIndex,i=void 0===o?t.length:o;if(n<0||n>=t.length||!Number.isInteger(n))throw new Error("fromIndex must be a positive integer smaller than length");if(i<=n||i>t.length||!Number.isInteger(i))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var s=t[n],a=n+1;a<i;a++)t[a]<s&&(s=t[a]);return s}function qr(t){var r,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!zr(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");if(void 0!==e.output){if(!zr(e.output))throw new TypeError("output option must be an array if specified");r=e.output}else r=new Array(t.length);var n=Vr(t),o=Lr(t);if(n===o)throw new RangeError("minimum and maximum input values are equal. Cannot rescale a constant array");var i=e.min,s=void 0===i?e.autoMinMax?n:0:i,a=e.max,u=void 0===a?e.autoMinMax?o:1:a;if(s>=u)throw new RangeError("min option must be smaller than max option");for(var c=(u-s)/(o-n),f=0;f<t.length;f++)r[f]=(t[f]-n)*c+s;return r}var Dr=" ".repeat(2),Ur=" ".repeat(4);function Br(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},e=r.maxRows,n=void 0===e?15:e,o=r.maxColumns,i=void 0===o?10:o,s=r.maxNumSize,a=void 0===s?8:s;return"".concat(t.constructor.name," {\n").concat(Dr,"[\n").concat(Ur).concat(Gr(t,n,i,a),"\n").concat(Dr,"]\n").concat(Dr,"rows: ").concat(t.rows,"\n").concat(Dr,"columns: ").concat(t.columns,"\n}")}function Gr(t,r,e,n){for(var o=t.rows,i=t.columns,s=Math.min(o,r),a=Math.min(i,e),u=[],c=0;c<s;c++){for(var f=[],h=0;h<a;h++)f.push($r(t.get(c,h),n));u.push("".concat(f.join(" ")))}return a!==i&&(u[u.length-1]+=" ... ".concat(i-e," more columns")),s!==o&&u.push("... ".concat(o-r," more rows")),u.join("\n".concat(Ur))}function $r(t,r){var e=String(t);if(e.length<=r)return e.padEnd(r," ");var n=t.toPrecision(r-2);if(n.length<=r)return n;var o=t.toExponential(r-2),i=o.indexOf("e"),s=o.slice(i);return o.slice(0,r-s.length)+s}function Kr(t,r,e){var n=e?t.rows:t.rows-1;if(r<0||r>n)throw new RangeError("Row index out of range")}function Wr(t,r,e){var n=e?t.columns:t.columns-1;if(r<0||r>n)throw new RangeError("Column index out of range")}function Xr(t,r){if(r.to1DArray&&(r=r.to1DArray()),r.length!==t.columns)throw new RangeError("vector size must be the same as the number of columns");return r}function Yr(t,r){if(r.to1DArray&&(r=r.to1DArray()),r.length!==t.rows)throw new RangeError("vector size must be the same as the number of rows");return r}function Jr(t,r,e,n,o){if(5!==arguments.length)throw new RangeError("expected 4 arguments");if(Hr("startRow",r),Hr("endRow",e),Hr("startColumn",n),Hr("endColumn",o),r>e||n>o||r<0||r>=t.rows||e<0||e>=t.rows||n<0||n>=t.columns||o<0||o>=t.columns)throw new RangeError("Submatrix indices are out of range")}function Zr(t){for(var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,e=[],n=0;n<t;n++)e.push(r);return e}function Hr(t,r){if("number"!=typeof r)throw new TypeError("".concat(t," must be a number"))}function Qr(t){if(t.isEmpty())throw new Error("Empty matrix has no elements to index")}function te(t,r,e){for(var n=t.rows,o=t.columns,i=[],s=0;s<n;s++){for(var a=0,u=0,c=0,f=0;f<o;f++)a+=c=t.get(s,f)-e[s],u+=c*c;r?i.push((u-a*a/o)/(o-1)):i.push((u-a*a/o)/o)}return i}function re(t,r,e){for(var n=t.rows,o=t.columns,i=[],s=0;s<o;s++){for(var a=0,u=0,c=0,f=0;f<n;f++)a+=c=t.get(f,s)-e[s],u+=c*c;r?i.push((u-a*a/n)/(n-1)):i.push((u-a*a/n)/n)}return i}function ee(t,r,e){for(var n=t.rows,o=t.columns,i=n*o,s=0,a=0,u=0,c=0;c<n;c++)for(var f=0;f<o;f++)s+=u=t.get(c,f)-e,a+=u*u;return r?(a-s*s/i)/(i-1):(a-s*s/i)/i}function ne(t,r){for(var e=0;e<t.rows;e++)for(var n=0;n<t.columns;n++)t.set(e,n,t.get(e,n)-r[e])}function oe(t,r){for(var e=0;e<t.rows;e++)for(var n=0;n<t.columns;n++)t.set(e,n,t.get(e,n)-r[n])}function ie(t,r){for(var e=0;e<t.rows;e++)for(var n=0;n<t.columns;n++)t.set(e,n,t.get(e,n)-r)}function se(t){for(var r=[],e=0;e<t.rows;e++){for(var n=0,o=0;o<t.columns;o++)n+=Math.pow(t.get(e,o),2)/(t.columns-1);r.push(Math.sqrt(n))}return r}function ae(t,r){for(var e=0;e<t.rows;e++)for(var n=0;n<t.columns;n++)t.set(e,n,t.get(e,n)/r[e])}function ue(t){for(var r=[],e=0;e<t.columns;e++){for(var n=0,o=0;o<t.rows;o++)n+=Math.pow(t.get(o,e),2)/(t.rows-1);r.push(Math.sqrt(n))}return r}function ce(t,r){for(var e=0;e<t.rows;e++)for(var n=0;n<t.columns;n++)t.set(e,n,t.get(e,n)/r[n])}function fe(t){for(var r=t.size-1,e=0,n=0;n<t.columns;n++)for(var o=0;o<t.rows;o++)e+=Math.pow(t.get(o,n),2)/r;return Math.sqrt(e)}function he(t,r){for(var e=0;e<t.rows;e++)for(var n=0;n<t.columns;n++)t.set(e,n,t.get(e,n)/r)}function le(t){var r=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var e,n=Tr(t);if(r){var o=Tr(this).constructor;e=Reflect.construct(n,arguments,o)}else e=n.apply(this,arguments);return Fr(this,e)}}var ve=function(){function t(){Ar(this,t)}return Cr(t,[{key:"size",get:function(){return this.rows*this.columns}},{key:"apply",value:function(t){if("function"!=typeof t)throw new TypeError("callback must be a function");for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)t.call(this,r,e);return this}},{key:"to1DArray",value:function(){for(var t=[],r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)t.push(this.get(r,e));return t}},{key:"to2DArray",value:function(){for(var t=[],r=0;r<this.rows;r++){t.push([]);for(var e=0;e<this.columns;e++)t[r].push(this.get(r,e))}return t}},{key:"toJSON",value:function(){return this.to2DArray()}},{key:"isRowVector",value:function(){return 1===this.rows}},{key:"isColumnVector",value:function(){return 1===this.columns}},{key:"isVector",value:function(){return 1===this.rows||1===this.columns}},{key:"isSquare",value:function(){return this.rows===this.columns}},{key:"isEmpty",value:function(){return 0===this.rows||0===this.columns}},{key:"isSymmetric",value:function(){if(this.isSquare()){for(var t=0;t<this.rows;t++)for(var r=0;r<=t;r++)if(this.get(t,r)!==this.get(r,t))return!1;return!0}return!1}},{key:"isEchelonForm",value:function(){for(var t=0,r=0,e=-1,n=!0,o=!1;t<this.rows&&n;){for(r=0,o=!1;r<this.columns&&!1===o;)0===this.get(t,r)?r++:1===this.get(t,r)&&r>e?(o=!0,e=r):(n=!1,o=!0);t++}return n}},{key:"isReducedEchelonForm",value:function(){for(var t=0,r=0,e=-1,n=!0,o=!1;t<this.rows&&n;){for(r=0,o=!1;r<this.columns&&!1===o;)0===this.get(t,r)?r++:1===this.get(t,r)&&r>e?(o=!0,e=r):(n=!1,o=!0);for(var i=r+1;i<this.rows;i++)0!==this.get(t,i)&&(n=!1);t++}return n}},{key:"echelonForm",value:function(){for(var t=this.clone(),r=0,e=0;r<t.rows&&e<t.columns;){for(var n=r,o=r;o<t.rows;o++)t.get(o,e)>t.get(n,e)&&(n=o);if(0===t.get(n,e))e++;else{t.swapRows(r,n);for(var i=t.get(r,e),s=e;s<t.columns;s++)t.set(r,s,t.get(r,s)/i);for(var a=r+1;a<t.rows;a++){var u=t.get(a,e)/t.get(r,e);t.set(a,e,0);for(var c=e+1;c<t.columns;c++)t.set(a,c,t.get(a,c)-t.get(r,c)*u)}r++,e++}}return t}},{key:"reducedEchelonForm",value:function(){for(var t=this.echelonForm(),r=t.columns,e=t.rows,n=e-1;n>=0;)if(0===t.maxRow(n))n--;else{for(var o=0,i=!1;o<e&&!1===i;)1===t.get(n,o)?i=!0:o++;for(var s=0;s<n;s++)for(var a=t.get(s,o),u=o;u<r;u++){var c=t.get(s,u)-a*t.get(n,u);t.set(s,u,c)}n--}return t}},{key:"set",value:function(){throw new Error("set method is unimplemented")}},{key:"get",value:function(){throw new Error("get method is unimplemented")}},{key:"repeat",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if("object"!==e(t))throw new TypeError("options must be an object");var r=t.rows,n=void 0===r?1:r,o=t.columns,i=void 0===o?1:o;if(!Number.isInteger(n)||n<=0)throw new TypeError("rows must be a positive integer");if(!Number.isInteger(i)||i<=0)throw new TypeError("columns must be a positive integer");for(var s=new ge(this.rows*n,this.columns*i),a=0;a<n;a++)for(var u=0;u<i;u++)s.setSubMatrix(this,this.rows*a,this.columns*u);return s}},{key:"fill",value:function(t){for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,t);return this}},{key:"neg",value:function(){return this.mulS(-1)}},{key:"getRow",value:function(t){Kr(this,t);for(var r=[],e=0;e<this.columns;e++)r.push(this.get(t,e));return r}},{key:"getRowVector",value:function(t){return ge.rowVector(this.getRow(t))}},{key:"setRow",value:function(t,r){Kr(this,t),r=Xr(this,r);for(var e=0;e<this.columns;e++)this.set(t,e,r[e]);return this}},{key:"swapRows",value:function(t,r){Kr(this,t),Kr(this,r);for(var e=0;e<this.columns;e++){var n=this.get(t,e);this.set(t,e,this.get(r,e)),this.set(r,e,n)}return this}},{key:"getColumn",value:function(t){Wr(this,t);for(var r=[],e=0;e<this.rows;e++)r.push(this.get(e,t));return r}},{key:"getColumnVector",value:function(t){return ge.columnVector(this.getColumn(t))}},{key:"setColumn",value:function(t,r){Wr(this,t),r=Yr(this,r);for(var e=0;e<this.rows;e++)this.set(e,t,r[e]);return this}},{key:"swapColumns",value:function(t,r){Wr(this,t),Wr(this,r);for(var e=0;e<this.rows;e++){var n=this.get(e,t);this.set(e,t,this.get(e,r)),this.set(e,r,n)}return this}},{key:"addRowVector",value:function(t){t=Xr(this,t);for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)+t[e]);return this}},{key:"subRowVector",value:function(t){t=Xr(this,t);for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)-t[e]);return this}},{key:"mulRowVector",value:function(t){t=Xr(this,t);for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)*t[e]);return this}},{key:"divRowVector",value:function(t){t=Xr(this,t);for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)/t[e]);return this}},{key:"addColumnVector",value:function(t){t=Yr(this,t);for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)+t[r]);return this}},{key:"subColumnVector",value:function(t){t=Yr(this,t);for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)-t[r]);return this}},{key:"mulColumnVector",value:function(t){t=Yr(this,t);for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)*t[r]);return this}},{key:"divColumnVector",value:function(t){t=Yr(this,t);for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)/t[r]);return this}},{key:"mulRow",value:function(t,r){Kr(this,t);for(var e=0;e<this.columns;e++)this.set(t,e,this.get(t,e)*r);return this}},{key:"mulColumn",value:function(t,r){Wr(this,t);for(var e=0;e<this.rows;e++)this.set(e,t,this.get(e,t)*r);return this}},{key:"max",value:function(){if(this.isEmpty())return NaN;for(var t=this.get(0,0),r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.get(r,e)>t&&(t=this.get(r,e));return t}},{key:"maxIndex",value:function(){Qr(this);for(var t=this.get(0,0),r=[0,0],e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)this.get(e,n)>t&&(t=this.get(e,n),r[0]=e,r[1]=n);return r}},{key:"min",value:function(){if(this.isEmpty())return NaN;for(var t=this.get(0,0),r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.get(r,e)<t&&(t=this.get(r,e));return t}},{key:"minIndex",value:function(){Qr(this);for(var t=this.get(0,0),r=[0,0],e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)this.get(e,n)<t&&(t=this.get(e,n),r[0]=e,r[1]=n);return r}},{key:"maxRow",value:function(t){if(Kr(this,t),this.isEmpty())return NaN;for(var r=this.get(t,0),e=1;e<this.columns;e++)this.get(t,e)>r&&(r=this.get(t,e));return r}},{key:"maxRowIndex",value:function(t){Kr(this,t),Qr(this);for(var r=this.get(t,0),e=[t,0],n=1;n<this.columns;n++)this.get(t,n)>r&&(r=this.get(t,n),e[1]=n);return e}},{key:"minRow",value:function(t){if(Kr(this,t),this.isEmpty())return NaN;for(var r=this.get(t,0),e=1;e<this.columns;e++)this.get(t,e)<r&&(r=this.get(t,e));return r}},{key:"minRowIndex",value:function(t){Kr(this,t),Qr(this);for(var r=this.get(t,0),e=[t,0],n=1;n<this.columns;n++)this.get(t,n)<r&&(r=this.get(t,n),e[1]=n);return e}},{key:"maxColumn",value:function(t){if(Wr(this,t),this.isEmpty())return NaN;for(var r=this.get(0,t),e=1;e<this.rows;e++)this.get(e,t)>r&&(r=this.get(e,t));return r}},{key:"maxColumnIndex",value:function(t){Wr(this,t),Qr(this);for(var r=this.get(0,t),e=[0,t],n=1;n<this.rows;n++)this.get(n,t)>r&&(r=this.get(n,t),e[0]=n);return e}},{key:"minColumn",value:function(t){if(Wr(this,t),this.isEmpty())return NaN;for(var r=this.get(0,t),e=1;e<this.rows;e++)this.get(e,t)<r&&(r=this.get(e,t));return r}},{key:"minColumnIndex",value:function(t){Wr(this,t),Qr(this);for(var r=this.get(0,t),e=[0,t],n=1;n<this.rows;n++)this.get(n,t)<r&&(r=this.get(n,t),e[0]=n);return e}},{key:"diag",value:function(){for(var t=Math.min(this.rows,this.columns),r=[],e=0;e<t;e++)r.push(this.get(e,e));return r}},{key:"norm",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"frobenius",r=0;if("max"===t)return this.max();if("frobenius"===t){for(var e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)r+=this.get(e,n)*this.get(e,n);return Math.sqrt(r)}throw new RangeError("unknown norm type: ".concat(t))}},{key:"cumulativeSum",value:function(){for(var t=0,r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)t+=this.get(r,e),this.set(r,e,t);return this}},{key:"dot",value:function(r){t.isMatrix(r)&&(r=r.to1DArray());var e=this.to1DArray();if(e.length!==r.length)throw new RangeError("vectors do not have the same size");for(var n=0,o=0;o<e.length;o++)n+=e[o]*r[o];return n}},{key:"mmul",value:function(t){t=ge.checkMatrix(t);for(var r=this.rows,e=this.columns,n=t.columns,o=new ge(r,n),i=new Float64Array(e),s=0;s<n;s++){for(var a=0;a<e;a++)i[a]=t.get(a,s);for(var u=0;u<r;u++){for(var c=0,f=0;f<e;f++)c+=this.get(u,f)*i[f];o.set(u,s,c)}}return o}},{key:"strassen2x2",value:function(t){t=ge.checkMatrix(t);var r=new ge(2,2),e=this.get(0,0),n=t.get(0,0),o=this.get(0,1),i=t.get(0,1),s=this.get(1,0),a=t.get(1,0),u=this.get(1,1),c=t.get(1,1),f=(e+u)*(n+c),h=(s+u)*n,l=e*(i-c),v=u*(a-n),m=(e+o)*c,g=f+v-m+(o-u)*(a+c),p=l+m,d=h+v,w=f-h+l+(s-e)*(n+i);return r.set(0,0,g),r.set(0,1,p),r.set(1,0,d),r.set(1,1,w),r}},{key:"strassen3x3",value:function(t){t=ge.checkMatrix(t);var r=new ge(3,3),e=this.get(0,0),n=this.get(0,1),o=this.get(0,2),i=this.get(1,0),s=this.get(1,1),a=this.get(1,2),u=this.get(2,0),c=this.get(2,1),f=this.get(2,2),h=t.get(0,0),l=t.get(0,1),v=t.get(0,2),m=t.get(1,0),g=t.get(1,1),p=t.get(1,2),d=t.get(2,0),w=t.get(2,1),y=t.get(2,2),b=(e-i)*(-l+g),M=(-e+i+s)*(h-l+g),x=(i+s)*(-h+l),k=e*h,E=(-e+u+c)*(h-v+p),S=(-e+u)*(v-p),_=(u+c)*(-h+v),j=(-o+c+f)*(g+d-w),R=(o-f)*(g-w),A=o*d,O=(c+f)*(-d+w),C=(-o+s+a)*(p+d-y),I=(o-a)*(p-y),N=(s+a)*(-d+y),F=k+A+n*m,T=(e+n+o-i-s-c-f)*g+M+x+k+j+A+O,P=k+E+_+(e+n+o-s-a-u-c)*p+A+C+N,z=b+s*(-h+l+m-g-p-d+y)+M+k+A+C+I,L=b+M+x+k+a*w,V=A+C+I+N+i*v,q=k+E+S+c*(-h+v+m-g-p-d+w)+j+R+A,D=j+R+A+O+u*l,U=k+E+S+_+f*y;return r.set(0,0,F),r.set(0,1,T),r.set(0,2,P),r.set(1,0,z),r.set(1,1,L),r.set(1,2,V),r.set(2,0,q),r.set(2,1,D),r.set(2,2,U),r}},{key:"mmulStrassen",value:function(r){r=ge.checkMatrix(r);var e=this.clone(),n=e.rows,o=e.columns,i=r.rows,s=r.columns;function a(r,e,n){var o=r.rows,i=r.columns;if(o===e&&i===n)return r;var s=t.zeros(e,n);return s=s.setSubMatrix(r,0,0)}o!==i&&console.warn("Multiplying ".concat(n," x ").concat(o," and ").concat(i," x ").concat(s," matrix: dimensions do not match."));var u=Math.max(n,i),c=Math.max(o,s);return function r(e,n,o,i){if(o<=512||i<=512)return e.mmul(n);o%2==1&&i%2==1?(e=a(e,o+1,i+1),n=a(n,o+1,i+1)):o%2==1?(e=a(e,o+1,i),n=a(n,o+1,i)):i%2==1&&(e=a(e,o,i+1),n=a(n,o,i+1));var s=parseInt(e.rows/2,10),u=parseInt(e.columns/2,10),c=e.subMatrix(0,s-1,0,u-1),f=n.subMatrix(0,s-1,0,u-1),h=e.subMatrix(0,s-1,u,e.columns-1),l=n.subMatrix(0,s-1,u,n.columns-1),v=e.subMatrix(s,e.rows-1,0,u-1),m=n.subMatrix(s,n.rows-1,0,u-1),g=e.subMatrix(s,e.rows-1,u,e.columns-1),p=n.subMatrix(s,n.rows-1,u,n.columns-1),d=r(t.add(c,g),t.add(f,p),s,u),w=r(t.add(v,g),f,s,u),y=r(c,t.sub(l,p),s,u),b=r(g,t.sub(m,f),s,u),M=r(t.add(c,h),p,s,u),x=r(t.sub(v,c),t.add(f,l),s,u),k=r(t.sub(h,g),t.add(m,p),s,u),E=t.add(d,b);E.sub(M),E.add(k);var S=t.add(y,M),_=t.add(w,b),j=t.sub(d,w);j.add(y),j.add(x);var R=t.zeros(2*E.rows,2*E.columns);return(R=(R=(R=(R=R.setSubMatrix(E,0,0)).setSubMatrix(S,E.rows,0)).setSubMatrix(_,0,E.columns)).setSubMatrix(j,E.rows,E.columns)).subMatrix(0,o-1,0,i-1)}(e=a(e,u,c),r=a(r,u,c),u,c)}},{key:"scaleRows",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if("object"!==e(t))throw new TypeError("options must be an object");var r=t.min,n=void 0===r?0:r,o=t.max,i=void 0===o?1:o;if(!Number.isFinite(n))throw new TypeError("min must be a number");if(!Number.isFinite(i))throw new TypeError("max must be a number");if(n>=i)throw new RangeError("min must be smaller than max");for(var s=new ge(this.rows,this.columns),a=0;a<this.rows;a++){var u=this.getRow(a);u.length>0&&qr(u,{min:n,max:i,output:u}),s.setRow(a,u)}return s}},{key:"scaleColumns",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if("object"!==e(t))throw new TypeError("options must be an object");var r=t.min,n=void 0===r?0:r,o=t.max,i=void 0===o?1:o;if(!Number.isFinite(n))throw new TypeError("min must be a number");if(!Number.isFinite(i))throw new TypeError("max must be a number");if(n>=i)throw new RangeError("min must be smaller than max");for(var s=new ge(this.rows,this.columns),a=0;a<this.columns;a++){var u=this.getColumn(a);u.length&&qr(u,{min:n,max:i,output:u}),s.setColumn(a,u)}return s}},{key:"flipRows",value:function(){for(var t=Math.ceil(this.columns/2),r=0;r<this.rows;r++)for(var e=0;e<t;e++){var n=this.get(r,e),o=this.get(r,this.columns-1-e);this.set(r,e,o),this.set(r,this.columns-1-e,n)}return this}},{key:"flipColumns",value:function(){for(var t=Math.ceil(this.rows/2),r=0;r<this.columns;r++)for(var e=0;e<t;e++){var n=this.get(e,r),o=this.get(this.rows-1-e,r);this.set(e,r,o),this.set(this.rows-1-e,r,n)}return this}},{key:"kroneckerProduct",value:function(t){t=ge.checkMatrix(t);for(var r=this.rows,e=this.columns,n=t.rows,o=t.columns,i=new ge(r*n,e*o),s=0;s<r;s++)for(var a=0;a<e;a++)for(var u=0;u<n;u++)for(var c=0;c<o;c++)i.set(n*s+u,o*a+c,this.get(s,a)*t.get(u,c));return i}},{key:"kroneckerSum",value:function(t){if(t=ge.checkMatrix(t),!this.isSquare()||!t.isSquare())throw new Error("Kronecker Sum needs two Square Matrices");var r=this.rows,e=t.rows,n=this.kroneckerProduct(ge.eye(e,e)),o=ge.eye(r,r).kroneckerProduct(t);return n.add(o)}},{key:"transpose",value:function(){for(var t=new ge(this.columns,this.rows),r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)t.set(e,r,this.get(r,e));return t}},{key:"sortRows",value:function(){for(var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:me,r=0;r<this.rows;r++)this.setRow(r,this.getRow(r).sort(t));return this}},{key:"sortColumns",value:function(){for(var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:me,r=0;r<this.columns;r++)this.setColumn(r,this.getColumn(r).sort(t));return this}},{key:"subMatrix",value:function(t,r,e,n){Jr(this,t,r,e,n);for(var o=new ge(r-t+1,n-e+1),i=t;i<=r;i++)for(var s=e;s<=n;s++)o.set(i-t,s-e,this.get(i,s));return o}},{key:"subMatrixRow",value:function(t,r,e){if(void 0===r&&(r=0),void 0===e&&(e=this.columns-1),r>e||r<0||r>=this.columns||e<0||e>=this.columns)throw new RangeError("Argument out of range");for(var n=new ge(t.length,e-r+1),o=0;o<t.length;o++)for(var i=r;i<=e;i++){if(t[o]<0||t[o]>=this.rows)throw new RangeError("Row index out of range: ".concat(t[o]));n.set(o,i-r,this.get(t[o],i))}return n}},{key:"subMatrixColumn",value:function(t,r,e){if(void 0===r&&(r=0),void 0===e&&(e=this.rows-1),r>e||r<0||r>=this.rows||e<0||e>=this.rows)throw new RangeError("Argument out of range");for(var n=new ge(e-r+1,t.length),o=0;o<t.length;o++)for(var i=r;i<=e;i++){if(t[o]<0||t[o]>=this.columns)throw new RangeError("Column index out of range: ".concat(t[o]));n.set(i-r,o,this.get(i,t[o]))}return n}},{key:"setSubMatrix",value:function(t,r,e){if((t=ge.checkMatrix(t)).isEmpty())return this;Jr(this,r,r+t.rows-1,e,e+t.columns-1);for(var n=0;n<t.rows;n++)for(var o=0;o<t.columns;o++)this.set(r+n,e+o,t.get(n,o));return this}},{key:"selection",value:function(t,r){!function(t,r){if(!zr(r))throw new TypeError("row indices must be an array");for(var e=0;e<r.length;e++)if(r[e]<0||r[e]>=t.rows)throw new RangeError("row indices are out of range")}(this,t),function(t,r){if(!zr(r))throw new TypeError("column indices must be an array");for(var e=0;e<r.length;e++)if(r[e]<0||r[e]>=t.columns)throw new RangeError("column indices are out of range")}(this,r);for(var e=new ge(t.length,r.length),n=0;n<t.length;n++)for(var o=t[n],i=0;i<r.length;i++){var s=r[i];e.set(n,i,this.get(o,s))}return e}},{key:"trace",value:function(){for(var t=Math.min(this.rows,this.columns),r=0,e=0;e<t;e++)r+=this.get(e,e);return r}},{key:"clone",value:function(){for(var t=new ge(this.rows,this.columns),r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)t.set(r,e,this.get(r,e));return t}},{key:"sum",value:function(t){switch(t){case"row":return function(t){for(var r=Zr(t.rows),e=0;e<t.rows;++e)for(var n=0;n<t.columns;++n)r[e]+=t.get(e,n);return r}(this);case"column":return function(t){for(var r=Zr(t.columns),e=0;e<t.rows;++e)for(var n=0;n<t.columns;++n)r[n]+=t.get(e,n);return r}(this);case void 0:return function(t){for(var r=0,e=0;e<t.rows;e++)for(var n=0;n<t.columns;n++)r+=t.get(e,n);return r}(this);default:throw new Error("invalid option: ".concat(t))}}},{key:"product",value:function(t){switch(t){case"row":return function(t){for(var r=Zr(t.rows,1),e=0;e<t.rows;++e)for(var n=0;n<t.columns;++n)r[e]*=t.get(e,n);return r}(this);case"column":return function(t){for(var r=Zr(t.columns,1),e=0;e<t.rows;++e)for(var n=0;n<t.columns;++n)r[n]*=t.get(e,n);return r}(this);case void 0:return function(t){for(var r=1,e=0;e<t.rows;e++)for(var n=0;n<t.columns;n++)r*=t.get(e,n);return r}(this);default:throw new Error("invalid option: ".concat(t))}}},{key:"mean",value:function(t){var r=this.sum(t);switch(t){case"row":for(var e=0;e<this.rows;e++)r[e]/=this.columns;return r;case"column":for(var n=0;n<this.columns;n++)r[n]/=this.rows;return r;case void 0:return r/this.size;default:throw new Error("invalid option: ".concat(t))}}},{key:"variance",value:function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if("object"===e(t)&&(r=t,t=void 0),"object"!==e(r))throw new TypeError("options must be an object");var n=r,o=n.unbiased,i=void 0===o||o,s=n.mean,a=void 0===s?this.mean(t):s;if("boolean"!=typeof i)throw new TypeError("unbiased must be a boolean");switch(t){case"row":if(!zr(a))throw new TypeError("mean must be an array");return te(this,i,a);case"column":if(!zr(a))throw new TypeError("mean must be an array");return re(this,i,a);case void 0:if("number"!=typeof a)throw new TypeError("mean must be a number");return ee(this,i,a);default:throw new Error("invalid option: ".concat(t))}}},{key:"standardDeviation",value:function(t,r){"object"===e(t)&&(r=t,t=void 0);var n=this.variance(t,r);if(void 0===t)return Math.sqrt(n);for(var o=0;o<n.length;o++)n[o]=Math.sqrt(n[o]);return n}},{key:"center",value:function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if("object"===e(t)&&(r=t,t=void 0),"object"!==e(r))throw new TypeError("options must be an object");var n=r,o=n.center,i=void 0===o?this.mean(t):o;switch(t){case"row":if(!zr(i))throw new TypeError("center must be an array");return ne(this,i),this;case"column":if(!zr(i))throw new TypeError("center must be an array");return oe(this,i),this;case void 0:if("number"!=typeof i)throw new TypeError("center must be a number");return ie(this,i),this;default:throw new Error("invalid option: ".concat(t))}}},{key:"scale",value:function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if("object"===e(t)&&(r=t,t=void 0),"object"!==e(r))throw new TypeError("options must be an object");var n=r.scale;switch(t){case"row":if(void 0===n)n=se(this);else if(!zr(n))throw new TypeError("scale must be an array");return ae(this,n),this;case"column":if(void 0===n)n=ue(this);else if(!zr(n))throw new TypeError("scale must be an array");return ce(this,n),this;case void 0:if(void 0===n)n=fe(this);else if("number"!=typeof n)throw new TypeError("scale must be a number");return he(this,n),this;default:throw new Error("invalid option: ".concat(t))}}},{key:"toString",value:function(t){return Br(this,t)}}],[{key:"from1DArray",value:function(t,r,e){if(t*r!==e.length)throw new RangeError("data length does not match given dimensions");for(var n=new ge(t,r),o=0;o<t;o++)for(var i=0;i<r;i++)n.set(o,i,e[o*r+i]);return n}},{key:"rowVector",value:function(t){for(var r=new ge(1,t.length),e=0;e<t.length;e++)r.set(0,e,t[e]);return r}},{key:"columnVector",value:function(t){for(var r=new ge(t.length,1),e=0;e<t.length;e++)r.set(e,0,t[e]);return r}},{key:"zeros",value:function(t,r){return new ge(t,r)}},{key:"ones",value:function(t,r){return new ge(t,r).fill(1)}},{key:"rand",value:function(t,r){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("object"!==e(n))throw new TypeError("options must be an object");for(var o=n.random,i=void 0===o?Math.random:o,s=new ge(t,r),a=0;a<t;a++)for(var u=0;u<r;u++)s.set(a,u,i());return s}},{key:"randInt",value:function(t,r){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("object"!==e(n))throw new TypeError("options must be an object");var o=n.min,i=void 0===o?0:o,s=n.max,a=void 0===s?1e3:s,u=n.random,c=void 0===u?Math.random:u;if(!Number.isInteger(i))throw new TypeError("min must be an integer");if(!Number.isInteger(a))throw new TypeError("max must be an integer");if(i>=a)throw new RangeError("min must be smaller than max");for(var f=a-i,h=new ge(t,r),l=0;l<t;l++)for(var v=0;v<r;v++){var m=i+Math.round(c()*f);h.set(l,v,m)}return h}},{key:"eye",value:function(t,r,e){void 0===r&&(r=t),void 0===e&&(e=1);for(var n=Math.min(t,r),o=this.zeros(t,r),i=0;i<n;i++)o.set(i,i,e);return o}},{key:"diag",value:function(t,r,e){var n=t.length;void 0===r&&(r=n),void 0===e&&(e=r);for(var o=Math.min(n,r,e),i=this.zeros(r,e),s=0;s<o;s++)i.set(s,s,t[s]);return i}},{key:"min",value:function(t,r){t=this.checkMatrix(t),r=this.checkMatrix(r);for(var e=t.rows,n=t.columns,o=new ge(e,n),i=0;i<e;i++)for(var s=0;s<n;s++)o.set(i,s,Math.min(t.get(i,s),r.get(i,s)));return o}},{key:"max",value:function(t,r){t=this.checkMatrix(t),r=this.checkMatrix(r);for(var e=t.rows,n=t.columns,o=new this(e,n),i=0;i<e;i++)for(var s=0;s<n;s++)o.set(i,s,Math.max(t.get(i,s),r.get(i,s)));return o}},{key:"checkMatrix",value:function(r){return t.isMatrix(r)?r:new ge(r)}},{key:"isMatrix",value:function(t){return null!=t&&"Matrix"===t.klass}}]),t}();function me(t,r){return t-r}ve.prototype.klass="Matrix","undefined"!=typeof Symbol&&(ve.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return Br(this)}),ve.random=ve.rand,ve.randomInt=ve.randInt,ve.diagonal=ve.diag,ve.prototype.diagonal=ve.prototype.diag,ve.identity=ve.eye,ve.prototype.negate=ve.prototype.neg,ve.prototype.tensorProduct=ve.prototype.kroneckerProduct;var ge=function(t){Nr(e,t);var r=le(e);function e(t,n){var o;if(Ar(this,e),o=r.call(this),e.isMatrix(t))return Fr(o,t.clone());if(Number.isInteger(t)&&t>=0){if(o.data=[],!(Number.isInteger(n)&&n>=0))throw new TypeError("nColumns must be a positive integer");for(var i=0;i<t;i++)o.data.push(new Float64Array(n))}else{if(!zr(t))throw new TypeError("First argument must be a positive number or an array");var s=t;if("number"!=typeof(n=(t=s.length)?s[0].length:0))throw new TypeError("Data must be a 2D array with at least one element");o.data=[];for(var a=0;a<t;a++){if(s[a].length!==n)throw new RangeError("Inconsistent array dimensions");o.data.push(Float64Array.from(s[a]))}}return o.rows=t,o.columns=n,o}return Cr(e,[{key:"set",value:function(t,r,e){return this.data[t][r]=e,this}},{key:"get",value:function(t,r){return this.data[t][r]}},{key:"removeRow",value:function(t){return Kr(this,t),this.data.splice(t,1),this.rows-=1,this}},{key:"addRow",value:function(t,r){return void 0===r&&(r=t,t=this.rows),Kr(this,t,!0),r=Float64Array.from(Xr(this,r)),this.data.splice(t,0,r),this.rows+=1,this}},{key:"removeColumn",value:function(t){Wr(this,t);for(var r=0;r<this.rows;r++){for(var e=new Float64Array(this.columns-1),n=0;n<t;n++)e[n]=this.data[r][n];for(var o=t+1;o<this.columns;o++)e[o-1]=this.data[r][o];this.data[r]=e}return this.columns-=1,this}},{key:"addColumn",value:function(t,r){void 0===r&&(r=t,t=this.columns),Wr(this,t,!0),r=Yr(this,r);for(var e=0;e<this.rows;e++){for(var n=new Float64Array(this.columns+1),o=0;o<t;o++)n[o]=this.data[e][o];for(n[o++]=r[e];o<this.columns+1;o++)n[o]=this.data[e][o-1];this.data[e]=n}return this.columns+=1,this}}]),e}(ve);function pe(t){var r=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var e,n=Tr(t);if(r){var o=Tr(this).constructor;e=Reflect.construct(n,arguments,o)}else e=n.apply(this,arguments);return Fr(this,e)}}function de(t){var r=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var e,n=Tr(t);if(r){var o=Tr(this).constructor;e=Reflect.construct(n,arguments,o)}else e=n.apply(this,arguments);return Fr(this,e)}}!function(t,r){t.prototype.add=function(t){return"number"==typeof t?this.addS(t):this.addM(t)},t.prototype.addS=function(t){for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)+t);return this},t.prototype.addM=function(t){if(t=r.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(var e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)this.set(e,n,this.get(e,n)+t.get(e,n));return this},t.add=function(t,e){return new r(t).add(e)},t.prototype.sub=function(t){return"number"==typeof t?this.subS(t):this.subM(t)},t.prototype.subS=function(t){for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)-t);return this},t.prototype.subM=function(t){if(t=r.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(var e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)this.set(e,n,this.get(e,n)-t.get(e,n));return this},t.sub=function(t,e){return new r(t).sub(e)},t.prototype.subtract=t.prototype.sub,t.prototype.subtractS=t.prototype.subS,t.prototype.subtractM=t.prototype.subM,t.subtract=t.sub,t.prototype.mul=function(t){return"number"==typeof t?this.mulS(t):this.mulM(t)},t.prototype.mulS=function(t){for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)*t);return this},t.prototype.mulM=function(t){if(t=r.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(var e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)this.set(e,n,this.get(e,n)*t.get(e,n));return this},t.mul=function(t,e){return new r(t).mul(e)},t.prototype.multiply=t.prototype.mul,t.prototype.multiplyS=t.prototype.mulS,t.prototype.multiplyM=t.prototype.mulM,t.multiply=t.mul,t.prototype.div=function(t){return"number"==typeof t?this.divS(t):this.divM(t)},t.prototype.divS=function(t){for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)/t);return this},t.prototype.divM=function(t){if(t=r.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(var e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)this.set(e,n,this.get(e,n)/t.get(e,n));return this},t.div=function(t,e){return new r(t).div(e)},t.prototype.divide=t.prototype.div,t.prototype.divideS=t.prototype.divS,t.prototype.divideM=t.prototype.divM,t.divide=t.div,t.prototype.mod=function(t){return"number"==typeof t?this.modS(t):this.modM(t)},t.prototype.modS=function(t){for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)%t);return this},t.prototype.modM=function(t){if(t=r.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(var e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)this.set(e,n,this.get(e,n)%t.get(e,n));return this},t.mod=function(t,e){return new r(t).mod(e)},t.prototype.modulus=t.prototype.mod,t.prototype.modulusS=t.prototype.modS,t.prototype.modulusM=t.prototype.modM,t.modulus=t.mod,t.prototype.and=function(t){return"number"==typeof t?this.andS(t):this.andM(t)},t.prototype.andS=function(t){for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)&t);return this},t.prototype.andM=function(t){if(t=r.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(var e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)this.set(e,n,this.get(e,n)&t.get(e,n));return this},t.and=function(t,e){return new r(t).and(e)},t.prototype.or=function(t){return"number"==typeof t?this.orS(t):this.orM(t)},t.prototype.orS=function(t){for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)|t);return this},t.prototype.orM=function(t){if(t=r.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(var e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)this.set(e,n,this.get(e,n)|t.get(e,n));return this},t.or=function(t,e){return new r(t).or(e)},t.prototype.xor=function(t){return"number"==typeof t?this.xorS(t):this.xorM(t)},t.prototype.xorS=function(t){for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)^t);return this},t.prototype.xorM=function(t){if(t=r.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(var e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)this.set(e,n,this.get(e,n)^t.get(e,n));return this},t.xor=function(t,e){return new r(t).xor(e)},t.prototype.leftShift=function(t){return"number"==typeof t?this.leftShiftS(t):this.leftShiftM(t)},t.prototype.leftShiftS=function(t){for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)<<t);return this},t.prototype.leftShiftM=function(t){if(t=r.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(var e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)this.set(e,n,this.get(e,n)<<t.get(e,n));return this},t.leftShift=function(t,e){return new r(t).leftShift(e)},t.prototype.signPropagatingRightShift=function(t){return"number"==typeof t?this.signPropagatingRightShiftS(t):this.signPropagatingRightShiftM(t)},t.prototype.signPropagatingRightShiftS=function(t){for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)>>t);return this},t.prototype.signPropagatingRightShiftM=function(t){if(t=r.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(var e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)this.set(e,n,this.get(e,n)>>t.get(e,n));return this},t.signPropagatingRightShift=function(t,e){return new r(t).signPropagatingRightShift(e)},t.prototype.rightShift=function(t){return"number"==typeof t?this.rightShiftS(t):this.rightShiftM(t)},t.prototype.rightShiftS=function(t){for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)>>>t);return this},t.prototype.rightShiftM=function(t){if(t=r.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(var e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)this.set(e,n,this.get(e,n)>>>t.get(e,n));return this},t.rightShift=function(t,e){return new r(t).rightShift(e)},t.prototype.zeroFillRightShift=t.prototype.rightShift,t.prototype.zeroFillRightShiftS=t.prototype.rightShiftS,t.prototype.zeroFillRightShiftM=t.prototype.rightShiftM,t.zeroFillRightShift=t.rightShift,t.prototype.not=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,~this.get(t,r));return this},t.not=function(t){return new r(t).not()},t.prototype.abs=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.abs(this.get(t,r)));return this},t.abs=function(t){return new r(t).abs()},t.prototype.acos=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.acos(this.get(t,r)));return this},t.acos=function(t){return new r(t).acos()},t.prototype.acosh=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.acosh(this.get(t,r)));return this},t.acosh=function(t){return new r(t).acosh()},t.prototype.asin=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.asin(this.get(t,r)));return this},t.asin=function(t){return new r(t).asin()},t.prototype.asinh=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.asinh(this.get(t,r)));return this},t.asinh=function(t){return new r(t).asinh()},t.prototype.atan=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.atan(this.get(t,r)));return this},t.atan=function(t){return new r(t).atan()},t.prototype.atanh=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.atanh(this.get(t,r)));return this},t.atanh=function(t){return new r(t).atanh()},t.prototype.cbrt=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.cbrt(this.get(t,r)));return this},t.cbrt=function(t){return new r(t).cbrt()},t.prototype.ceil=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.ceil(this.get(t,r)));return this},t.ceil=function(t){return new r(t).ceil()},t.prototype.clz32=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.clz32(this.get(t,r)));return this},t.clz32=function(t){return new r(t).clz32()},t.prototype.cos=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.cos(this.get(t,r)));return this},t.cos=function(t){return new r(t).cos()},t.prototype.cosh=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.cosh(this.get(t,r)));return this},t.cosh=function(t){return new r(t).cosh()},t.prototype.exp=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.exp(this.get(t,r)));return this},t.exp=function(t){return new r(t).exp()},t.prototype.expm1=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.expm1(this.get(t,r)));return this},t.expm1=function(t){return new r(t).expm1()},t.prototype.floor=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.floor(this.get(t,r)));return this},t.floor=function(t){return new r(t).floor()},t.prototype.fround=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.fround(this.get(t,r)));return this},t.fround=function(t){return new r(t).fround()},t.prototype.log=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.log(this.get(t,r)));return this},t.log=function(t){return new r(t).log()},t.prototype.log1p=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.log1p(this.get(t,r)));return this},t.log1p=function(t){return new r(t).log1p()},t.prototype.log10=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.log10(this.get(t,r)));return this},t.log10=function(t){return new r(t).log10()},t.prototype.log2=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.log2(this.get(t,r)));return this},t.log2=function(t){return new r(t).log2()},t.prototype.round=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.round(this.get(t,r)));return this},t.round=function(t){return new r(t).round()},t.prototype.sign=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.sign(this.get(t,r)));return this},t.sign=function(t){return new r(t).sign()},t.prototype.sin=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.sin(this.get(t,r)));return this},t.sin=function(t){return new r(t).sin()},t.prototype.sinh=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.sinh(this.get(t,r)));return this},t.sinh=function(t){return new r(t).sinh()},t.prototype.sqrt=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.sqrt(this.get(t,r)));return this},t.sqrt=function(t){return new r(t).sqrt()},t.prototype.tan=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.tan(this.get(t,r)));return this},t.tan=function(t){return new r(t).tan()},t.prototype.tanh=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.tanh(this.get(t,r)));return this},t.tanh=function(t){return new r(t).tanh()},t.prototype.trunc=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.trunc(this.get(t,r)));return this},t.trunc=function(t){return new r(t).trunc()},t.pow=function(t,e){return new r(t).pow(e)},t.prototype.pow=function(t){return"number"==typeof t?this.powS(t):this.powM(t)},t.prototype.powS=function(t){for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,Math.pow(this.get(r,e),t));return this},t.prototype.powM=function(t){if(t=r.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(var e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)this.set(e,n,Math.pow(this.get(e,n),t.get(e,n)));return this}}(ve,ge);var we=function(t){Nr(e,t);var r=de(e);function e(t){return Ar(this,e),r.call(this,t,t.columns,t.rows)}return Cr(e,[{key:"set",value:function(t,r,e){return this.matrix.set(r,t,e),this}},{key:"get",value:function(t,r){return this.matrix.get(r,t)}}]),e}(function(t){Nr(e,t);var r=pe(e);function e(t,n,o){var i;return Ar(this,e),(i=r.call(this)).matrix=t,i.rows=n,i.columns=o,i}return Cr(e)}(ve));function ye(t){var r=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var e,n=Tr(t);if(r){var o=Tr(this).constructor;e=Reflect.construct(n,arguments,o)}else e=n.apply(this,arguments);return Fr(this,e)}}var be=function(t){Nr(e,t);var r=ye(e);function e(t){var n;return Ar(this,e),(n=r.call(this)).data=t,n.rows=t.length,n.columns=t[0].length,n}return Cr(e,[{key:"set",value:function(t,r,e){return this.data[t][r]=e,this}},{key:"get",value:function(t,r){return this.data[t][r]}}]),e}(ve);function Me(t,r){var e=0;return Math.abs(t)>Math.abs(r)?(e=r/t,Math.abs(t)*Math.sqrt(1+e*e)):0!==r?(e=t/r,Math.abs(r)*Math.sqrt(1+e*e)):0}var xe=function(){function t(r){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(Ar(this,t),(r=be.checkMatrix(r)).isEmpty())throw new Error("Matrix must be non-empty");var n,o=r.rows,i=r.columns,s=e.computeLeftSingularVectors,a=void 0===s||s,u=e.computeRightSingularVectors,c=void 0===u||u,f=e.autoTranspose,h=void 0!==f&&f,l=Boolean(a),v=Boolean(c),m=!1;if(o<i)if(h){o=(n=r.transpose()).rows,i=n.columns,m=!0;var g=l;l=v,v=g}else n=r.clone(),console.warn("Computing SVD on a matrix with more columns than rows. Consider enabling autoTranspose");else n=r.clone();for(var p=Math.min(o,i),d=Math.min(o+1,i),w=new Float64Array(d),y=new ge(o,p),b=new ge(i,i),M=new Float64Array(i),x=new Float64Array(o),k=new Float64Array(d),E=0;E<d;E++)k[E]=E;for(var S=Math.min(o-1,i),_=Math.max(0,Math.min(i-2,o)),j=Math.max(S,_),R=0;R<j;R++){if(R<S){w[R]=0;for(var A=R;A<o;A++)w[R]=Me(w[R],n.get(A,R));if(0!==w[R]){n.get(R,R)<0&&(w[R]=-w[R]);for(var O=R;O<o;O++)n.set(O,R,n.get(O,R)/w[R]);n.set(R,R,n.get(R,R)+1)}w[R]=-w[R]}for(var C=R+1;C<i;C++){if(R<S&&0!==w[R]){for(var I=0,N=R;N<o;N++)I+=n.get(N,R)*n.get(N,C);I=-I/n.get(R,R);for(var F=R;F<o;F++)n.set(F,C,n.get(F,C)+I*n.get(F,R))}M[C]=n.get(R,C)}if(l&&R<S)for(var T=R;T<o;T++)y.set(T,R,n.get(T,R));if(R<_){M[R]=0;for(var P=R+1;P<i;P++)M[R]=Me(M[R],M[P]);if(0!==M[R]){M[R+1]<0&&(M[R]=0-M[R]);for(var z=R+1;z<i;z++)M[z]/=M[R];M[R+1]+=1}if(M[R]=-M[R],R+1<o&&0!==M[R]){for(var L=R+1;L<o;L++)x[L]=0;for(var V=R+1;V<o;V++)for(var q=R+1;q<i;q++)x[V]+=M[q]*n.get(V,q);for(var D=R+1;D<i;D++)for(var U=-M[D]/M[R+1],B=R+1;B<o;B++)n.set(B,D,n.get(B,D)+U*x[B])}if(v)for(var G=R+1;G<i;G++)b.set(G,R,M[G])}}var $=Math.min(i,o+1);if(S<i&&(w[S]=n.get(S,S)),o<$&&(w[$-1]=0),_+1<$&&(M[_]=n.get(_,$-1)),M[$-1]=0,l){for(var K=S;K<p;K++){for(var W=0;W<o;W++)y.set(W,K,0);y.set(K,K,1)}for(var X=S-1;X>=0;X--)if(0!==w[X]){for(var Y=X+1;Y<p;Y++){for(var J=0,Z=X;Z<o;Z++)J+=y.get(Z,X)*y.get(Z,Y);J=-J/y.get(X,X);for(var H=X;H<o;H++)y.set(H,Y,y.get(H,Y)+J*y.get(H,X))}for(var Q=X;Q<o;Q++)y.set(Q,X,-y.get(Q,X));y.set(X,X,1+y.get(X,X));for(var tt=0;tt<X-1;tt++)y.set(tt,X,0)}else{for(var rt=0;rt<o;rt++)y.set(rt,X,0);y.set(X,X,1)}}if(v)for(var et=i-1;et>=0;et--){if(et<_&&0!==M[et])for(var nt=et+1;nt<i;nt++){for(var ot=0,it=et+1;it<i;it++)ot+=b.get(it,et)*b.get(it,nt);ot=-ot/b.get(et+1,et);for(var st=et+1;st<i;st++)b.set(st,nt,b.get(st,nt)+ot*b.get(st,et))}for(var at=0;at<i;at++)b.set(at,et,0);b.set(et,et,1)}for(var ut=$-1,ct=Number.EPSILON;$>0;){var ft=void 0,ht=void 0;for(ft=$-2;ft>=-1&&-1!==ft;ft--){var lt=Number.MIN_VALUE+ct*Math.abs(w[ft]+Math.abs(w[ft+1]));if(Math.abs(M[ft])<=lt||Number.isNaN(M[ft])){M[ft]=0;break}}if(ft===$-2)ht=4;else{var vt=void 0;for(vt=$-1;vt>=ft&&vt!==ft;vt--){var mt=(vt!==$?Math.abs(M[vt]):0)+(vt!==ft+1?Math.abs(M[vt-1]):0);if(Math.abs(w[vt])<=ct*mt){w[vt]=0;break}}vt===ft?ht=3:vt===$-1?ht=1:(ht=2,ft=vt)}switch(ft++,ht){case 1:var gt=M[$-2];M[$-2]=0;for(var pt=$-2;pt>=ft;pt--){var dt=Me(w[pt],gt),wt=w[pt]/dt,yt=gt/dt;if(w[pt]=dt,pt!==ft&&(gt=-yt*M[pt-1],M[pt-1]=wt*M[pt-1]),v)for(var bt=0;bt<i;bt++)dt=wt*b.get(bt,pt)+yt*b.get(bt,$-1),b.set(bt,$-1,-yt*b.get(bt,pt)+wt*b.get(bt,$-1)),b.set(bt,pt,dt)}break;case 2:var Mt=M[ft-1];M[ft-1]=0;for(var xt=ft;xt<$;xt++){var kt=Me(w[xt],Mt),Et=w[xt]/kt,St=Mt/kt;if(w[xt]=kt,Mt=-St*M[xt],M[xt]=Et*M[xt],l)for(var _t=0;_t<o;_t++)kt=Et*y.get(_t,xt)+St*y.get(_t,ft-1),y.set(_t,ft-1,-St*y.get(_t,xt)+Et*y.get(_t,ft-1)),y.set(_t,xt,kt)}break;case 3:var jt=Math.max(Math.abs(w[$-1]),Math.abs(w[$-2]),Math.abs(M[$-2]),Math.abs(w[ft]),Math.abs(M[ft])),Rt=w[$-1]/jt,At=w[$-2]/jt,Ot=M[$-2]/jt,Ct=w[ft]/jt,It=M[ft]/jt,Nt=((At+Rt)*(At-Rt)+Ot*Ot)/2,Ft=Rt*Ot*(Rt*Ot),Tt=0;0===Nt&&0===Ft||(Tt=Ft/(Nt+(Tt=Nt<0?0-Math.sqrt(Nt*Nt+Ft):Math.sqrt(Nt*Nt+Ft))));for(var Pt=(Ct+Rt)*(Ct-Rt)+Tt,zt=Ct*It,Lt=ft;Lt<$-1;Lt++){var Vt=Me(Pt,zt);0===Vt&&(Vt=Number.MIN_VALUE);var qt=Pt/Vt,Dt=zt/Vt;if(Lt!==ft&&(M[Lt-1]=Vt),Pt=qt*w[Lt]+Dt*M[Lt],M[Lt]=qt*M[Lt]-Dt*w[Lt],zt=Dt*w[Lt+1],w[Lt+1]=qt*w[Lt+1],v)for(var Ut=0;Ut<i;Ut++)Vt=qt*b.get(Ut,Lt)+Dt*b.get(Ut,Lt+1),b.set(Ut,Lt+1,-Dt*b.get(Ut,Lt)+qt*b.get(Ut,Lt+1)),b.set(Ut,Lt,Vt);if(0===(Vt=Me(Pt,zt))&&(Vt=Number.MIN_VALUE),qt=Pt/Vt,Dt=zt/Vt,w[Lt]=Vt,Pt=qt*M[Lt]+Dt*w[Lt+1],w[Lt+1]=-Dt*M[Lt]+qt*w[Lt+1],zt=Dt*M[Lt+1],M[Lt+1]=qt*M[Lt+1],l&&Lt<o-1)for(var Bt=0;Bt<o;Bt++)Vt=qt*y.get(Bt,Lt)+Dt*y.get(Bt,Lt+1),y.set(Bt,Lt+1,-Dt*y.get(Bt,Lt)+qt*y.get(Bt,Lt+1)),y.set(Bt,Lt,Vt)}M[$-2]=Pt;break;case 4:if(w[ft]<=0&&(w[ft]=w[ft]<0?-w[ft]:0,v))for(var Gt=0;Gt<=ut;Gt++)b.set(Gt,ft,-b.get(Gt,ft));for(;ft<ut&&!(w[ft]>=w[ft+1]);){var $t=w[ft];if(w[ft]=w[ft+1],w[ft+1]=$t,v&&ft<i-1)for(var Kt=0;Kt<i;Kt++)$t=b.get(Kt,ft+1),b.set(Kt,ft+1,b.get(Kt,ft)),b.set(Kt,ft,$t);if(l&&ft<o-1)for(var Wt=0;Wt<o;Wt++)$t=y.get(Wt,ft+1),y.set(Wt,ft+1,y.get(Wt,ft)),y.set(Wt,ft,$t);ft++}$--}}if(m){var Xt=b;b=y,y=Xt}this.m=o,this.n=i,this.s=w,this.U=y,this.V=b}return Cr(t,[{key:"solve",value:function(t){for(var r=t,e=this.threshold,n=this.s.length,o=ge.zeros(n,n),i=0;i<n;i++)Math.abs(this.s[i])<=e?o.set(i,i,0):o.set(i,i,1/this.s[i]);for(var s=this.U,a=this.rightSingularVectors,u=a.mmul(o),c=a.rows,f=s.rows,h=ge.zeros(c,f),l=0;l<c;l++)for(var v=0;v<f;v++){for(var m=0,g=0;g<n;g++)m+=u.get(l,g)*s.get(v,g);h.set(l,v,m)}return h.mmul(r)}},{key:"solveForDiagonal",value:function(t){return this.solve(ge.diag(t))}},{key:"inverse",value:function(){for(var t=this.V,r=this.threshold,e=t.rows,n=t.columns,o=new ge(e,this.s.length),i=0;i<e;i++)for(var s=0;s<n;s++)Math.abs(this.s[s])>r&&o.set(i,s,t.get(i,s)/this.s[s]);for(var a=this.U,u=a.rows,c=a.columns,f=new ge(e,u),h=0;h<e;h++)for(var l=0;l<u;l++){for(var v=0,m=0;m<c;m++)v+=o.get(h,m)*a.get(l,m);f.set(h,l,v)}return f}},{key:"condition",get:function(){return this.s[0]/this.s[Math.min(this.m,this.n)-1]}},{key:"norm2",get:function(){return this.s[0]}},{key:"rank",get:function(){for(var t=Math.max(this.m,this.n)*this.s[0]*Number.EPSILON,r=0,e=this.s,n=0,o=e.length;n<o;n++)e[n]>t&&r++;return r}},{key:"diagonal",get:function(){return Array.from(this.s)}},{key:"threshold",get:function(){return Number.EPSILON/2*Math.max(this.m,this.n)*this.s[0]}},{key:"leftSingularVectors",get:function(){return this.U}},{key:"rightSingularVectors",get:function(){return this.V}},{key:"diagonalMatrix",get:function(){return ge.diag(this.s)}}]),t}(),ke=function(){function t(r){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};Ar(this,t);var n=e.assumeSymmetric,o=void 0!==n&&n;if(!(r=be.checkMatrix(r)).isSquare())throw new Error("Matrix is not a square matrix");if(r.isEmpty())throw new Error("Matrix must be non-empty");var i,s,a=r.columns,u=new ge(a,a),c=new Float64Array(a),f=new Float64Array(a),h=r;if(!!o||r.isSymmetric()){for(i=0;i<a;i++)for(s=0;s<a;s++)u.set(i,s,h.get(i,s));Ee(a,f,c,u),Se(a,f,c,u)}else{var l=new ge(a,a),v=new Float64Array(a);for(s=0;s<a;s++)for(i=0;i<a;i++)l.set(i,s,h.get(i,s));_e(a,l,v,u),je(a,f,c,u,l)}this.n=a,this.e=f,this.d=c,this.V=u}return Cr(t,[{key:"realEigenvalues",get:function(){return Array.from(this.d)}},{key:"imaginaryEigenvalues",get:function(){return Array.from(this.e)}},{key:"eigenvectorMatrix",get:function(){return this.V}},{key:"diagonalMatrix",get:function(){var t,r,e=this.n,n=this.e,o=this.d,i=new ge(e,e);for(t=0;t<e;t++){for(r=0;r<e;r++)i.set(t,r,0);i.set(t,t,o[t]),n[t]>0?i.set(t,t+1,n[t]):n[t]<0&&i.set(t,t-1,n[t])}return i}}]),t}();function Ee(t,r,e,n){var o,i,s,a,u,c,f,h;for(u=0;u<t;u++)e[u]=n.get(t-1,u);for(a=t-1;a>0;a--){for(h=0,s=0,c=0;c<a;c++)h+=Math.abs(e[c]);if(0===h)for(r[a]=e[a-1],u=0;u<a;u++)e[u]=n.get(a-1,u),n.set(a,u,0),n.set(u,a,0);else{for(c=0;c<a;c++)e[c]/=h,s+=e[c]*e[c];for(o=e[a-1],i=Math.sqrt(s),o>0&&(i=-i),r[a]=h*i,s-=o*i,e[a-1]=o-i,u=0;u<a;u++)r[u]=0;for(u=0;u<a;u++){for(o=e[u],n.set(u,a,o),i=r[u]+n.get(u,u)*o,c=u+1;c<=a-1;c++)i+=n.get(c,u)*e[c],r[c]+=n.get(c,u)*o;r[u]=i}for(o=0,u=0;u<a;u++)r[u]/=s,o+=r[u]*e[u];for(f=o/(s+s),u=0;u<a;u++)r[u]-=f*e[u];for(u=0;u<a;u++){for(o=e[u],i=r[u],c=u;c<=a-1;c++)n.set(c,u,n.get(c,u)-(o*r[c]+i*e[c]));e[u]=n.get(a-1,u),n.set(a,u,0)}}e[a]=s}for(a=0;a<t-1;a++){if(n.set(t-1,a,n.get(a,a)),n.set(a,a,1),0!==(s=e[a+1])){for(c=0;c<=a;c++)e[c]=n.get(c,a+1)/s;for(u=0;u<=a;u++){for(i=0,c=0;c<=a;c++)i+=n.get(c,a+1)*n.get(c,u);for(c=0;c<=a;c++)n.set(c,u,n.get(c,u)-i*e[c])}}for(c=0;c<=a;c++)n.set(c,a+1,0)}for(u=0;u<t;u++)e[u]=n.get(t-1,u),n.set(t-1,u,0);n.set(t-1,t-1,1),r[0]=0}function Se(t,r,e,n){var o,i,s,a,u,c,f,h,l,v,m,g,p,d,w,y;for(s=1;s<t;s++)r[s-1]=r[s];r[t-1]=0;var b=0,M=0,x=Number.EPSILON;for(c=0;c<t;c++){for(M=Math.max(M,Math.abs(e[c])+Math.abs(r[c])),f=c;f<t&&!(Math.abs(r[f])<=x*M);)f++;if(f>c)do{for(o=e[c],l=Me(h=(e[c+1]-o)/(2*r[c]),1),h<0&&(l=-l),e[c]=r[c]/(h+l),e[c+1]=r[c]*(h+l),v=e[c+1],i=o-e[c],s=c+2;s<t;s++)e[s]-=i;for(b+=i,h=e[f],g=m=1,p=m,d=r[c+1],w=0,y=0,s=f-1;s>=c;s--)for(p=g,g=m,y=w,o=m*r[s],i=m*h,l=Me(h,r[s]),r[s+1]=w*l,w=r[s]/l,h=(m=h/l)*e[s]-w*o,e[s+1]=i+w*(m*o+w*e[s]),u=0;u<t;u++)i=n.get(u,s+1),n.set(u,s+1,w*n.get(u,s)+m*i),n.set(u,s,m*n.get(u,s)-w*i);h=-w*y*p*d*r[c]/v,r[c]=w*h,e[c]=m*h}while(Math.abs(r[c])>x*M);e[c]=e[c]+b,r[c]=0}for(s=0;s<t-1;s++){for(u=s,h=e[s],a=s+1;a<t;a++)e[a]<h&&(u=a,h=e[a]);if(u!==s)for(e[u]=e[s],e[s]=h,a=0;a<t;a++)h=n.get(a,s),n.set(a,s,n.get(a,u)),n.set(a,u,h)}}function _e(t,r,e,n){var o,i,s,a,u,c,f,h=t-1;for(c=1;c<=h-1;c++){for(f=0,a=c;a<=h;a++)f+=Math.abs(r.get(a,c-1));if(0!==f){for(s=0,a=h;a>=c;a--)e[a]=r.get(a,c-1)/f,s+=e[a]*e[a];for(i=Math.sqrt(s),e[c]>0&&(i=-i),s-=e[c]*i,e[c]=e[c]-i,u=c;u<t;u++){for(o=0,a=h;a>=c;a--)o+=e[a]*r.get(a,u);for(o/=s,a=c;a<=h;a++)r.set(a,u,r.get(a,u)-o*e[a])}for(a=0;a<=h;a++){for(o=0,u=h;u>=c;u--)o+=e[u]*r.get(a,u);for(o/=s,u=c;u<=h;u++)r.set(a,u,r.get(a,u)-o*e[u])}e[c]=f*e[c],r.set(c,c-1,f*i)}}for(a=0;a<t;a++)for(u=0;u<t;u++)n.set(a,u,a===u?1:0);for(c=h-1;c>=1;c--)if(0!==r.get(c,c-1)){for(a=c+1;a<=h;a++)e[a]=r.get(a,c-1);for(u=c;u<=h;u++){for(i=0,a=c;a<=h;a++)i+=e[a]*n.get(a,u);for(i=i/e[c]/r.get(c,c-1),a=c;a<=h;a++)n.set(a,u,n.get(a,u)+i*e[a])}}}function je(t,r,e,n,o){var i,s,a,u,c,f,h,l,v,m,g,p,d,w,y,b=t-1,M=t-1,x=Number.EPSILON,k=0,E=0,S=0,_=0,j=0,R=0,A=0,O=0;for(i=0;i<t;i++)for((i<0||i>M)&&(e[i]=o.get(i,i),r[i]=0),s=Math.max(i-1,0);s<t;s++)E+=Math.abs(o.get(i,s));for(;b>=0;){for(u=b;u>0&&(0===(R=Math.abs(o.get(u-1,u-1))+Math.abs(o.get(u,u)))&&(R=E),!(Math.abs(o.get(u,u-1))<x*R));)u--;if(u===b)o.set(b,b,o.get(b,b)+k),e[b]=o.get(b,b),r[b]=0,b--,O=0;else if(u===b-1){if(h=o.get(b,b-1)*o.get(b-1,b),_=(S=(o.get(b-1,b-1)-o.get(b,b))/2)*S+h,A=Math.sqrt(Math.abs(_)),o.set(b,b,o.get(b,b)+k),o.set(b-1,b-1,o.get(b-1,b-1)+k),l=o.get(b,b),_>=0){for(A=S>=0?S+A:S-A,e[b-1]=l+A,e[b]=e[b-1],0!==A&&(e[b]=l-h/A),r[b-1]=0,r[b]=0,S=(l=o.get(b,b-1))/(R=Math.abs(l)+Math.abs(A)),_=A/R,S/=j=Math.sqrt(S*S+_*_),_/=j,s=b-1;s<t;s++)A=o.get(b-1,s),o.set(b-1,s,_*A+S*o.get(b,s)),o.set(b,s,_*o.get(b,s)-S*A);for(i=0;i<=b;i++)A=o.get(i,b-1),o.set(i,b-1,_*A+S*o.get(i,b)),o.set(i,b,_*o.get(i,b)-S*A);for(i=0;i<=M;i++)A=n.get(i,b-1),n.set(i,b-1,_*A+S*n.get(i,b)),n.set(i,b,_*n.get(i,b)-S*A)}else e[b-1]=l+S,e[b]=l+S,r[b-1]=A,r[b]=-A;b-=2,O=0}else{if(l=o.get(b,b),v=0,h=0,u<b&&(v=o.get(b-1,b-1),h=o.get(b,b-1)*o.get(b-1,b)),10===O){for(k+=l,i=0;i<=b;i++)o.set(i,i,o.get(i,i)-l);l=v=.75*(R=Math.abs(o.get(b,b-1))+Math.abs(o.get(b-1,b-2))),h=-.4375*R*R}if(30===O&&(R=(R=(v-l)/2)*R+h)>0){for(R=Math.sqrt(R),v<l&&(R=-R),R=l-h/((v-l)/2+R),i=0;i<=b;i++)o.set(i,i,o.get(i,i)-R);k+=R,l=v=h=.964}for(O+=1,c=b-2;c>=u&&(S=((j=l-(A=o.get(c,c)))*(R=v-A)-h)/o.get(c+1,c)+o.get(c,c+1),_=o.get(c+1,c+1)-A-j-R,j=o.get(c+2,c+1),S/=R=Math.abs(S)+Math.abs(_)+Math.abs(j),_/=R,j/=R,c!==u)&&!(Math.abs(o.get(c,c-1))*(Math.abs(_)+Math.abs(j))<x*(Math.abs(S)*(Math.abs(o.get(c-1,c-1))+Math.abs(A)+Math.abs(o.get(c+1,c+1)))));)c--;for(i=c+2;i<=b;i++)o.set(i,i-2,0),i>c+2&&o.set(i,i-3,0);for(a=c;a<=b-1&&(w=a!==b-1,a!==c&&(S=o.get(a,a-1),_=o.get(a+1,a-1),j=w?o.get(a+2,a-1):0,0!==(l=Math.abs(S)+Math.abs(_)+Math.abs(j))&&(S/=l,_/=l,j/=l)),0!==l);a++)if(R=Math.sqrt(S*S+_*_+j*j),S<0&&(R=-R),0!==R){for(a!==c?o.set(a,a-1,-R*l):u!==c&&o.set(a,a-1,-o.get(a,a-1)),l=(S+=R)/R,v=_/R,A=j/R,_/=S,j/=S,s=a;s<t;s++)S=o.get(a,s)+_*o.get(a+1,s),w&&(S+=j*o.get(a+2,s),o.set(a+2,s,o.get(a+2,s)-S*A)),o.set(a,s,o.get(a,s)-S*l),o.set(a+1,s,o.get(a+1,s)-S*v);for(i=0;i<=Math.min(b,a+3);i++)S=l*o.get(i,a)+v*o.get(i,a+1),w&&(S+=A*o.get(i,a+2),o.set(i,a+2,o.get(i,a+2)-S*j)),o.set(i,a,o.get(i,a)-S),o.set(i,a+1,o.get(i,a+1)-S*_);for(i=0;i<=M;i++)S=l*n.get(i,a)+v*n.get(i,a+1),w&&(S+=A*n.get(i,a+2),n.set(i,a+2,n.get(i,a+2)-S*j)),n.set(i,a,n.get(i,a)-S),n.set(i,a+1,n.get(i,a+1)-S*_)}}}if(0!==E){for(b=t-1;b>=0;b--)if(S=e[b],0===(_=r[b]))for(u=b,o.set(b,b,1),i=b-1;i>=0;i--){for(h=o.get(i,i)-S,j=0,s=u;s<=b;s++)j+=o.get(i,s)*o.get(s,b);if(r[i]<0)A=h,R=j;else if(u=i,0===r[i]?o.set(i,b,0!==h?-j/h:-j/(x*E)):(l=o.get(i,i+1),v=o.get(i+1,i),f=(l*R-A*j)/(_=(e[i]-S)*(e[i]-S)+r[i]*r[i]),o.set(i,b,f),o.set(i+1,b,Math.abs(l)>Math.abs(A)?(-j-h*f)/l:(-R-v*f)/A)),x*(f=Math.abs(o.get(i,b)))*f>1)for(s=i;s<=b;s++)o.set(s,b,o.get(s,b)/f)}else if(_<0)for(u=b-1,Math.abs(o.get(b,b-1))>Math.abs(o.get(b-1,b))?(o.set(b-1,b-1,_/o.get(b,b-1)),o.set(b-1,b,-(o.get(b,b)-S)/o.get(b,b-1))):(y=Re(0,-o.get(b-1,b),o.get(b-1,b-1)-S,_),o.set(b-1,b-1,y[0]),o.set(b-1,b,y[1])),o.set(b,b-1,0),o.set(b,b,1),i=b-2;i>=0;i--){for(m=0,g=0,s=u;s<=b;s++)m+=o.get(i,s)*o.get(s,b-1),g+=o.get(i,s)*o.get(s,b);if(h=o.get(i,i)-S,r[i]<0)A=h,j=m,R=g;else if(u=i,0===r[i]?(y=Re(-m,-g,h,_),o.set(i,b-1,y[0]),o.set(i,b,y[1])):(l=o.get(i,i+1),v=o.get(i+1,i),p=(e[i]-S)*(e[i]-S)+r[i]*r[i]-_*_,d=2*(e[i]-S)*_,0===p&&0===d&&(p=x*E*(Math.abs(h)+Math.abs(_)+Math.abs(l)+Math.abs(v)+Math.abs(A))),y=Re(l*j-A*m+_*g,l*R-A*g-_*m,p,d),o.set(i,b-1,y[0]),o.set(i,b,y[1]),Math.abs(l)>Math.abs(A)+Math.abs(_)?(o.set(i+1,b-1,(-m-h*o.get(i,b-1)+_*o.get(i,b))/l),o.set(i+1,b,(-g-h*o.get(i,b)-_*o.get(i,b-1))/l)):(y=Re(-j-v*o.get(i,b-1),-R-v*o.get(i,b),A,_),o.set(i+1,b-1,y[0]),o.set(i+1,b,y[1]))),x*(f=Math.max(Math.abs(o.get(i,b-1)),Math.abs(o.get(i,b))))*f>1)for(s=i;s<=b;s++)o.set(s,b-1,o.get(s,b-1)/f),o.set(s,b,o.get(s,b)/f)}for(i=0;i<t;i++)if(i<0||i>M)for(s=i;s<t;s++)n.set(i,s,o.get(i,s));for(s=t-1;s>=0;s--)for(i=0;i<=M;i++){for(A=0,a=0;a<=Math.min(s,M);a++)A+=n.get(i,a)*o.get(a,s);n.set(i,s,A)}}}function Re(t,r,e,n){var o,i;return Math.abs(e)>Math.abs(n)?[(t+(o=n/e)*r)/(i=e+o*n),(r-o*t)/i]:[((o=e/n)*t+r)/(i=n+o*e),(o*r-t)/i]}var Ae=Cr((function t(r){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};Ar(this,t),r=be.checkMatrix(r);var n,o=e.Y,i=e.scaleScores,s=void 0!==i&&i,a=e.maxIterations,u=void 0===a?1e3:a,c=e.terminationCriteria,f=void 0===c?1e-10:c;if(o){if((o=zr(o)&&"number"==typeof o[0]?ge.columnVector(o):be.checkMatrix(o)).rows!==r.rows)throw new Error("Y should have the same number of rows as X");n=o.getColumnVector(0)}else n=r.getColumnVector(0);for(var h,l,v,m,g=1,p=0;p<u&&g>f;p++)v=(v=r.transpose().mmul(n).div(n.transpose().mmul(n).get(0,0))).div(v.norm()),h=r.mmul(v).div(v.transpose().mmul(v).get(0,0)),p>0&&(g=h.clone().sub(m).pow(2).sum()),m=h.clone(),o?(l=(l=o.transpose().mmul(h).div(h.transpose().mmul(h).get(0,0))).div(l.norm()),n=o.mmul(l).div(l.transpose().mmul(l).get(0,0))):n=h;if(o){var d=r.transpose().mmul(h).div(h.transpose().mmul(h).get(0,0));d=d.div(d.norm());var w=r.clone().sub(h.clone().mmul(d.transpose())),y=n.transpose().mmul(h).div(h.transpose().mmul(h).get(0,0)),b=o.clone().sub(h.clone().mulS(y.get(0,0)).mmul(l.transpose()));this.t=h,this.p=d.transpose(),this.w=v.transpose(),this.q=l,this.u=n,this.s=h.transpose().mmul(h),this.xResidual=w,this.yResidual=b,this.betas=y}else this.w=v.transpose(),this.s=h.transpose().mmul(h).sqrt(),this.t=s?h.clone().div(this.s.get(0,0)):h,this.xResidual=r.sub(h.mmul(v.transpose()))}));function Oe(t,r){var e="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!e){if(Array.isArray(t)||(e=function(t,r){if(!t)return;if("string"==typeof t)return Ce(t,r);var e=Object.prototype.toString.call(t).slice(8,-1);"Object"===e&&t.constructor&&(e=t.constructor.name);if("Map"===e||"Set"===e)return Array.from(t);if("Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e))return Ce(t,r)}(t))||r&&t&&"number"==typeof t.length){e&&(t=e);var n=0,o=function(){};return{s:o,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,s=!0,a=!1;return{s:function(){e=e.call(t)},n:function(){var t=e.next();return s=t.done,t},e:function(t){a=!0,i=t},f:function(){try{s||null==e.return||e.return()}finally{if(a)throw i}}}}function Ce(t,r){(null==r||r>t.length)&&(r=t.length);for(var e=0,n=new Array(r);e<r;e++)n[e]=t[e];return n}var Ie=function(){function t(r){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(Ar(this,t),!0===r){var n=e;return this.center=n.center,this.scale=n.scale,this.means=n.means,this.stdevs=n.stdevs,this.U=ge.checkMatrix(n.U),this.S=n.S,this.R=n.R,void(this.excludedFeatures=n.excludedFeatures||[])}r=new ge(r);var o=e.isCovarianceMatrix,i=void 0!==o&&o,s=e.method,a=void 0===s?"SVD":s,u=e.nCompNIPALS,c=void 0===u?2:u,f=e.center,h=void 0===f||f,l=e.scale,v=void 0!==l&&l,m=e.ignoreZeroVariance,g=void 0!==m&&m;if(this.center=h,this.scale=v,this.means=null,this.stdevs=null,this.excludedFeatures=[],i)this._computeFromCovarianceMatrix(r);else switch(this._adjust(r,g),a){case"covarianceMatrix":var p=new we(r).mmul(r).div(r.rows-1);this._computeFromCovarianceMatrix(p);break;case"NIPALS":this._computeWithNIPALS(r,c);break;case"SVD":var d=new xe(r,{computeLeftSingularVectors:!1,computeRightSingularVectors:!0,autoTranspose:!0});this.U=d.rightSingularVectors;var w,y=d.diagonal,b=[],M=Oe(y);try{for(M.s();!(w=M.n()).done;){var x=w.value;b.push(x*x/(r.rows-1))}}catch(t){M.e(t)}finally{M.f()}this.S=b;break;default:throw new Error("unknown method: ".concat(a))}}return Cr(t,[{key:"predict",value:function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},e=r.nComponents,n=void 0===e?this.U.columns:e;if(t=new ge(t),this.center&&(t.subRowVector(this.means),this.scale)){var o,i=Oe(this.excludedFeatures);try{for(i.s();!(o=i.n()).done;){var s=o.value;t.removeColumn(s)}}catch(t){i.e(t)}finally{i.f()}t.divRowVector(this.stdevs)}var a=t.mmul(this.U);return a.subMatrix(0,a.rows-1,0,n-1)}},{key:"invert",value:function(t){var r=(t=ge.checkMatrix(t)).mmul(this.U.transpose());return this.center&&(this.scale&&r.mulRowVector(this.stdevs),r.addRowVector(this.means)),r}},{key:"getExplainedVariance",value:function(){var t,r=0,e=Oe(this.S);try{for(e.s();!(t=e.n()).done;){var n=t.value;r+=n}}catch(t){e.e(t)}finally{e.f()}return this.S.map((function(t){return t/r}))}},{key:"getCumulativeVariance",value:function(){for(var t=this.getExplainedVariance(),r=1;r<t.length;r++)t[r]+=t[r-1];return t}},{key:"getEigenvectors",value:function(){return this.U}},{key:"getEigenvalues",value:function(){return this.S}},{key:"getStandardDeviations",value:function(){return this.S.map((function(t){return Math.sqrt(t)}))}},{key:"getLoadings",value:function(){return this.U.transpose()}},{key:"toJSON",value:function(){return{name:"PCA",center:this.center,scale:this.scale,means:this.means,stdevs:this.stdevs,U:this.U,S:this.S,excludedFeatures:this.excludedFeatures}}},{key:"_adjust",value:function(t,r){if(this.center){var e=t.mean("column"),n=this.scale?t.standardDeviation("column",{mean:e}):null;if(this.means=e,t.subRowVector(e),this.scale){for(var o=0;o<n.length;o++)if(0===n[o]){if(!r)throw new RangeError("Cannot scale the dataset (standard deviation is zero at index ".concat(o));t.removeColumn(o),n.splice(o,1),this.excludedFeatures.push(o),o--}this.stdevs=n,t.divRowVector(n)}}}},{key:"_computeFromCovarianceMatrix",value:function(t){var r=new ke(t,{assumeSymmetric:!0});this.U=r.eigenvectorMatrix,this.U.flipRows(),this.S=r.realEigenvalues,this.S.reverse()}},{key:"_computeWithNIPALS",value:function(t,r){this.U=new ge(r,t.columns),this.S=[];for(var e=t,n=0;n<r;n++){var o=new Ae(e);this.U.setRow(n,o.w.transpose()),this.S.push(Math.pow(o.s.get(0,0),2)),e=o.xResidual}this.U=this.U.transpose()}}],[{key:"load",value:function(r){if("string"!=typeof r.name)throw new TypeError("model must have a name property");if("PCA"!==r.name)throw new RangeError("invalid model: ".concat(r.name));return new t(!0,r)}}]),t}();function Ne(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!Rr(t))throw new Error("data is not eff. array");var e=Nt(r,"scale");kr(e)||(e=!0);var n=Nt(r,"nCompNIPALS");xr(n)||(n=2);var o=Mr(Nt(t,0,[]));if(0===o)throw new Error("invalid dimension of data");if(n>o)throw new Error("nCompNIPALS is more than the dimension of data");var i="NIPALS",s=new Ie(t,{method:i,scale:e,nCompNIPALS:n}),a=s.predict(t),u=s.invert(a),c=u.toJSON();return c}var Fe=function(t,r){for(var e=-1,n=null==t?0:t.length;++e<n&&!1!==r(t[e],e,t););return t};var Te=function(t){return function(r,e,n){for(var o=-1,i=Object(r),s=n(r),a=s.length;a--;){var u=s[t?a:++o];if(!1===e(i[u],u,i))break}return r}}();var Pe=function(t,r){for(var e=-1,n=Array(t);++e<t;)n[e]=r(e);return n};var ze=function(t){return x(t)&&"[object Arguments]"==M(t)},Le=Object.prototype,Ve=Le.hasOwnProperty,qe=Le.propertyIsEnumerable,De=ze(function(){return arguments}())?ze:function(t){return x(t)&&Ve.call(t,"callee")&&!qe.call(t,"callee")},Ue=De;var Be=function(){return!1},Ge=i((function(t,r){var e=r&&!r.nodeType&&r,n=e&&t&&!t.nodeType&&t,o=n&&n.exports===e?h.Buffer:void 0,i=(o?o.isBuffer:void 0)||Be;t.exports=i})),$e=/^(?:0|[1-9]\d*)$/;var Ke=function(t,r){var n=e(t);return!!(r=null==r?9007199254740991:r)&&("number"==n||"symbol"!=n&&$e.test(t))&&t>-1&&t%1==0&&t<r},We={};We["[object Float32Array]"]=We["[object Float64Array]"]=We["[object Int8Array]"]=We["[object Int16Array]"]=We["[object Int32Array]"]=We["[object Uint8Array]"]=We["[object Uint8ClampedArray]"]=We["[object Uint16Array]"]=We["[object Uint32Array]"]=!0,We["[object Arguments]"]=We["[object Array]"]=We["[object ArrayBuffer]"]=We["[object Boolean]"]=We["[object DataView]"]=We["[object Date]"]=We["[object Error]"]=We["[object Function]"]=We["[object Map]"]=We["[object Number]"]=We["[object Object]"]=We["[object RegExp]"]=We["[object Set]"]=We["[object String]"]=We["[object WeakMap]"]=!1;var Xe=function(t){return x(t)&&rr(t.length)&&!!We[M(t)]};var Ye=function(t){return function(r){return t(r)}},Je=i((function(t,r){var e=r&&!r.nodeType&&r,n=e&&t&&!t.nodeType&&t,o=n&&n.exports===e&&c.process,i=function(){try{var t=n&&n.require&&n.require("util").types;return t||o&&o.binding&&o.binding("util")}catch(t){}}();t.exports=i})),Ze=Je&&Je.isTypedArray,He=Ze?Ye(Ze):Xe,Qe=Object.prototype.hasOwnProperty;var tn=function(t,r){var e=u(t),n=!e&&Ue(t),o=!e&&!n&&Ge(t),i=!e&&!n&&!o&&He(t),s=e||n||o||i,a=s?Pe(t.length,String):[],c=a.length;for(var f in t)!r&&!Qe.call(t,f)||s&&("length"==f||o&&("offset"==f||"parent"==f)||i&&("buffer"==f||"byteLength"==f||"byteOffset"==f)||Ke(f,c))||a.push(f);return a};var rn=function(t){return er(t)?tn(t):Lt(t)};var en=function(t,r){return function(e,n){if(null==e)return e;if(!er(e))return t(e,n);for(var o=e.length,i=r?o:-1,s=Object(e);(r?i--:++i<o)&&!1!==n(s[i],i,s););return e}}((function(t,r){return t&&Te(t,r,rn)}));var nn=function(t){return t};var on=function(t){return"function"==typeof t?t:nn};var sn=function(t,r){return(u(t)?Fe:en)(t,on(r))};var an=function(){this.__data__=new ct,this.size=0};var un=function(t){var r=this.__data__,e=r.delete(t);return this.size=r.size,e};var cn=function(t){return this.__data__.get(t)};var fn=function(t){return this.__data__.has(t)};var hn=function(t,r){var e=this.__data__;if(e instanceof ct){var n=e.__data__;if(!ft||n.length<199)return n.push([t,r]),this.size=++e.size,this;e=this.__data__=new yt(n)}return e.set(t,r),this.size=e.size,this};function ln(t){var r=this.__data__=new ct(t);this.size=r.size}ln.prototype.clear=an,ln.prototype.delete=un,ln.prototype.get=cn,ln.prototype.has=fn,ln.prototype.set=hn;var vn=ln;var mn=function(t){return this.__data__.set(t,"__lodash_hash_undefined__"),this};var gn=function(t){return this.__data__.has(t)};function pn(t){var r=-1,e=null==t?0:t.length;for(this.__data__=new yt;++r<e;)this.add(t[r])}pn.prototype.add=pn.prototype.push=mn,pn.prototype.has=gn;var dn=pn;var wn=function(t,r){for(var e=-1,n=null==t?0:t.length;++e<n;)if(r(t[e],e,t))return!0;return!1};var yn=function(t,r){return t.has(r)};var bn=function(t,r,e,n,o,i){var s=1&e,a=t.length,u=r.length;if(a!=u&&!(s&&u>a))return!1;var c=i.get(t),f=i.get(r);if(c&&f)return c==r&&f==t;var h=-1,l=!0,v=2&e?new dn:void 0;for(i.set(t,r),i.set(r,t);++h<a;){var m=t[h],g=r[h];if(n)var p=s?n(g,m,h,r,t,i):n(m,g,h,t,r,i);if(void 0!==p){if(p)continue;l=!1;break}if(v){if(!wn(r,(function(t,r){if(!yn(v,r)&&(m===t||o(m,t,e,n,i)))return v.push(r)}))){l=!1;break}}else if(m!==g&&!o(m,g,e,n,i)){l=!1;break}}return i.delete(t),i.delete(r),l},Mn=h.Uint8Array;var xn=function(t){var r=-1,e=Array(t.size);return t.forEach((function(t,n){e[++r]=[n,t]})),e};var kn=function(t){var r=-1,e=Array(t.size);return t.forEach((function(t){e[++r]=t})),e},En=l?l.prototype:void 0,Sn=En?En.valueOf:void 0;var _n=function(t,r,e,n,o,i,s){switch(e){case"[object DataView]":if(t.byteLength!=r.byteLength||t.byteOffset!=r.byteOffset)return!1;t=t.buffer,r=r.buffer;case"[object ArrayBuffer]":return!(t.byteLength!=r.byteLength||!i(new Mn(t),new Mn(r)));case"[object Boolean]":case"[object Date]":case"[object Number]":return rt(+t,+r);case"[object Error]":return t.name==r.name&&t.message==r.message;case"[object RegExp]":case"[object String]":return t==r+"";case"[object Map]":var a=xn;case"[object Set]":var u=1&n;if(a||(a=kn),t.size!=r.size&&!u)return!1;var c=s.get(t);if(c)return c==r;n|=2,s.set(t,r);var f=bn(a(t),a(r),n,o,i,s);return s.delete(t),f;case"[object Symbol]":if(Sn)return Sn.call(t)==Sn.call(r)}return!1};var jn=function(t,r){for(var e=-1,n=r.length,o=t.length;++e<n;)t[o+e]=r[e];return t};var Rn=function(t,r,e){var n=r(t);return u(t)?n:jn(n,e(t))};var An=function(t,r){for(var e=-1,n=null==t?0:t.length,o=0,i=[];++e<n;){var s=t[e];r(s,e,t)&&(i[o++]=s)}return i};var On=function(){return[]},Cn=Object.prototype.propertyIsEnumerable,In=Object.getOwnPropertySymbols,Nn=In?function(t){return null==t?[]:(t=Object(t),An(In(t),(function(r){return Cn.call(t,r)})))}:On;var Fn=function(t){return Rn(t,rn,Nn)},Tn=Object.prototype.hasOwnProperty;var Pn=function(t,r,e,n,o,i){var s=1&e,a=Fn(t),u=a.length;if(u!=Fn(r).length&&!s)return!1;for(var c=u;c--;){var f=a[c];if(!(s?f in r:Tn.call(r,f)))return!1}var h=i.get(t),l=i.get(r);if(h&&l)return h==r&&l==t;var v=!0;i.set(t,r),i.set(r,t);for(var m=s;++c<u;){var g=t[f=a[c]],p=r[f];if(n)var d=s?n(p,g,f,r,t,i):n(g,p,f,t,r,i);if(!(void 0===d?g===p||o(g,p,e,n,i):d)){v=!1;break}m||(m="constructor"==f)}if(v&&!m){var w=t.constructor,y=r.constructor;w==y||!("constructor"in t)||!("constructor"in r)||"function"==typeof w&&w instanceof w&&"function"==typeof y&&y instanceof y||(v=!1)}return i.delete(t),i.delete(r),v},zn="[object Arguments]",Ln="[object Array]",Vn="[object Object]",qn=Object.prototype.hasOwnProperty;var Dn=function(t,r,e,n,o,i){var s=u(t),a=u(r),c=s?Ln:tr(t),f=a?Ln:tr(r),h=(c=c==zn?Vn:c)==Vn,l=(f=f==zn?Vn:f)==Vn,v=c==f;if(v&&Ge(t)){if(!Ge(r))return!1;s=!0,h=!1}if(v&&!h)return i||(i=new vn),s||He(t)?bn(t,r,e,n,o,i):_n(t,r,c,e,n,o,i);if(!(1&e)){var m=h&&qn.call(t,"__wrapped__"),g=l&&qn.call(r,"__wrapped__");if(m||g){var p=m?t.value():t,d=g?r.value():r;return i||(i=new vn),o(p,d,e,n,i)}}return!!v&&(i||(i=new vn),Pn(t,r,e,n,o,i))};var Un=function t(r,e,n,o,i){return r===e||(null==r||null==e||!x(r)&&!x(e)?r!=r&&e!=e:Dn(r,e,n,o,t,i))};var Bn=function(t,r,e,n){var o=e.length,i=o,s=!n;if(null==t)return!i;for(t=Object(t);o--;){var a=e[o];if(s&&a[2]?a[1]!==t[a[0]]:!(a[0]in t))return!1}for(;++o<i;){var u=(a=e[o])[0],c=t[u],f=a[1];if(s&&a[2]){if(void 0===c&&!(u in t))return!1}else{var h=new vn;if(n)var l=n(c,f,u,t,r,h);if(!(void 0===l?Un(f,c,3,n,h):l))return!1}}return!0};var Gn=function(t){return t==t&&!j(t)};var $n=function(t){for(var r=rn(t),e=r.length;e--;){var n=r[e],o=t[n];r[e]=[n,o,Gn(o)]}return r};var Kn=function(t,r){return function(e){return null!=e&&(e[t]===r&&(void 0!==r||t in Object(e)))}};var Wn=function(t){var r=$n(t);return 1==r.length&&r[0][2]?Kn(r[0][0],r[0][1]):function(e){return e===t||Bn(e,t,r)}};var Xn=function(t,r){return null!=t&&r in Object(t)};var Yn=function(t,r,e){for(var n=-1,o=(r=Ot(r,t)).length,i=!1;++n<o;){var s=Ct(r[n]);if(!(i=null!=t&&e(t,s)))break;t=t[s]}return i||++n!=o?i:!!(o=null==t?0:t.length)&&rr(o)&&Ke(s,o)&&(u(t)||Ue(t))};var Jn=function(t,r){return null!=t&&Yn(t,r,Xn)};var Zn=function(t,r){return _(t)&&Gn(r)?Kn(Ct(t),r):function(e){var n=Nt(e,t);return void 0===n&&n===r?Jn(e,t):Un(r,n,3)}};var Hn=function(t){return function(r){return It(r,t)}};var Qn=function(t){return _(t)?or(Ct(t)):Hn(t)};var to=function(t){return"function"==typeof t?t:null==t?nn:"object"==e(t)?u(t)?Zn(t[0],t[1]):Wn(t):Qn(t)};var ro=function(t,r){var e=-1,n=er(t)?Array(t.length):[];return en(t,(function(t,o,i){n[++e]=r(t,o,i)})),n};var eo=function(t,r){return(u(t)?St:ro)(t,to(r))};var no=function(t,r){return St(r,(function(r){return t[r]}))};var oo=function(t){return null==t?[]:no(t,rn(t))};function io(t){return!(!_r(t)||""===t)}function so(t){var r=!1;return io(t)?r=!isNaN(Number(t)):function(t){return"[object Number]"===Object.prototype.toString.call(t)}(t)&&(r=!0),r}function ao(t,r){if(!Sr(t))return{};if(!Rr(r))return{};var e={};return sn(r,(function(r){(function(t,r){return!!Sr(t)&&!(!io(r)&&!so(r))&&r in t})(t,r)&&(e[r]=Nt(t,r))})),e}function uo(t){if(Sr(t)){for(var r in t)return!0;return!1}return!1}var co=/\s/;var fo=function(t){for(var r=t.length;r--&&co.test(t.charAt(r)););return r},ho=/^\s+/;var lo=function(t){return t?t.slice(0,fo(t)+1).replace(ho,""):t},vo=/^[-+]0x[0-9a-f]+$/i,mo=/^0b[01]+$/i,go=/^0o[0-7]+$/i,po=parseInt;var wo=function(t){if("number"==typeof t)return t;if(k(t))return NaN;if(j(t)){var r="function"==typeof t.valueOf?t.valueOf():t;t=j(r)?r+"":r}if("string"!=typeof t)return 0===t?t:+t;t=lo(t);var e=mo.test(t);return e||go.test(t)?po(t.slice(2),e?2:8):vo.test(t)?NaN:+t},yo=1/0;var bo=function(t){return t?(t=wo(t))===yo||t===-1/0?17976931348623157e292*(t<0?-1:1):t==t?t:0:0===t?t:0};var Mo=function(t){var r=bo(t),e=r%1;return r==r?e?r-e:r:0},xo=h.isFinite,ko=Math.min;var Eo=function(t){var r=Math[t];return function(t,e){if(t=wo(t),(e=null==e?0:ko(Mo(e),292))&&xo(t)){var n=(At(t)+"e").split("e"),o=r(n[0]+"e"+(+n[1]+e));return+((n=(At(o)+"e").split("e"))[0]+"e"+(+n[1]-e))}return r(t)}}("round");function So(t){if(!so(t))return 0;t=function(t){return so(t)?bo(t):0}(t);var r=Eo(t);return"0"===String(r)?0:r}var _o=Array.prototype.join;var jo=function(t,r){return null==t?"":_o.call(t,r)},Ro=Cr((function t(r){var e=this;Ar(this,t),this.getCost=function(){return e.Elements.map((function(t){return t.DistanceFromMedoid})).reduce((function(t,r){return t+r}),0)},this.findBestMedoidIdx=function(t){return e.Elements.map((function(r){return e.calcCostForGivenElementAsMedoid(r,t)})).reduce((function(t,r,e,n){return r.CostIfMadeMedoid<n[t].CostIfMadeMedoid?e:t}),0)},this.calcCostForGivenElementAsMedoid=function(r,n){return{CostIfMadeMedoid:new t({Elements:e.Elements.map((function(t){return{DistanceFromMedoid:n(t.Element,r.Element),Element:t.Element}})),Medoid:r.Element}).getCost(),Element:r}},this.Elements=r.Elements,this.Medoid=r.Medoid})),Ao=Ro,Oo=Object.defineProperty({Cluster:Ao},"__esModule",{value:!0}),Co=Object.defineProperty({distance:function(t,r){if(t.length!==r.length)throw new Error("the inputs must have the same dimension");var e=Array.from(t.keys()).map((function(e){return Math.pow(Math.abs(t[e]-r[e]),2)})).reduce((function(t,r){return t+r}),0);return Math.sqrt(e)}},"__esModule",{value:!0}),Io=Object.defineProperty({kGtElementArrLength:"k must be less than the number of elements in the input array"},"__esModule",{value:!0});function No(t,r){var e="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!e){if(Array.isArray(t)||(e=function(t,r){if(!t)return;if("string"==typeof t)return Fo(t,r);var e=Object.prototype.toString.call(t).slice(8,-1);"Object"===e&&t.constructor&&(e=t.constructor.name);if("Map"===e||"Set"===e)return Array.from(t);if("Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e))return Fo(t,r)}(t))||r&&t&&"number"==typeof t.length){e&&(t=e);var n=0,o=function(){};return{s:o,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,s=!0,a=!1;return{s:function(){e=e.call(t)},n:function(){var t=e.next();return s=t.done,t},e:function(t){a=!0,i=t},f:function(){try{s||null==e.return||e.return()}finally{if(a)throw i}}}}function Fo(t,r){(null==r||r>t.length)&&(r=t.length);for(var e=0,n=new Array(r);e<r;e++)n[e]=t[e];return n}var To=function(){function t(r,e,n){var o=this;Ar(this,t),this.Elements=r,this.K=e,this.DistanceFn=n,this.OptimisationCompleted=!1,this.iterate=function(){o.IterationCount++,o.Clusters||o.allocateToClustersAroundCurrentMedoids();for(var r=o.Medoids,e=o.Clusters,n=o.calculateCurrentCost(),i=n,s=0;s<o.Medoids.length;s++){var a,u=No(o.Elements.filter((function(t){return 0===o.Medoids.filter((function(r){return 0===o.DistanceFn(t,r)})).length})));try{for(u.s();!(a=u.n()).done;){var c=a.value,f=o.Medoids.slice();f[s]=c;var h=new t(o.Elements.slice(),o.K,o.DistanceFn);h.Medoids=f,h.allocateToClustersAroundCurrentMedoids();var l=h.calculateCurrentCost();l<i&&(i=l,o.Clusters=h.Clusters,o.Medoids=f)}}catch(t){u.e(t)}finally{u.f()}}return o.calculateCurrentCost()<n||(o.Clusters=e,o.Medoids=r,o.OptimisationCompleted=!0,!1)},this.getClusteredData=function(){return o.OptimisationCompleted||o.runToCompletion(),o.Clusters.map((function(t){return t.Elements.map((function(t){return t.Element}))}))},this.runToCompletion=function(){for(;o.iterate(););},this.allocateToClustersAroundCurrentMedoids=function(){o.Clusters=new Array,o.Medoids.forEach((function(t){o.Clusters.push(new Oo.Cluster({Elements:[],Medoid:t}))})),o.Elements.forEach((function(t,r){var e=o.findDistances(o.Clusters.map((function(t){return t.Medoid})),t),n=e.reduce((function(t,r,e,n){return r<n[t]?e:t}),0);o.Clusters[n].Elements.push({DistanceFromMedoid:e[n],Element:t})}))},this.calculateCurrentCost=function(){return o.Clusters.map((function(t){return t.getCost()})).reduce((function(t,r){return t+r}),0)},this.findDistances=function(t,r){return t.map((function(t){return o.DistanceFn(t,r)}))},this.selectInitialMedoids=function(){if(o.K>=o.Elements.length)throw Io.kGtElementArrLength;for(var t=[],r=function(t,r){var e,n=No(r);try{for(n.s();!(e=n.n()).done;){var i=e.value;if(0===o.DistanceFn(i,t))return!1}}catch(t){n.e(t)}finally{n.f()}return!0},e=0;e<o.Elements.length&&t.length<o.K;)r(o.Elements[e],t)&&t.push(o.Elements[e]),e++;return t},this.DistanceFn=this.DistanceFn||Co.distance,this.Medoids=this.selectInitialMedoids(),this.IterationCount=0}return Cr(t,[{key:"OptimisationStarted",get:function(){return this.IterationCount>0}}]),t}();To.clusterElements=function(t,r,e){return To.getInstance(t,r,e),new Array},To.getInstance=function(t,r,e){return new To(t,r,e)};var Po=To,zo=Object.defineProperty({Clusterer:Po},"__esModule",{value:!0}),Lo=o(i((function(t,r){function e(t){for(var e in t)r.hasOwnProperty(e)||(r[e]=t[e])}Object.defineProperty(r,"__esModule",{value:!0}),e(Oo),e(zo)})));function Vo(t,r){for(var e=0,n=0;n<t.length;n++)e+=(t[n]-r[n])*(t[n]-r[n]);return e}var qo={distanceFunction:Vo};function Do(t,r){var e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:qo,n=e.distanceFunction||qo.distanceFunction,o=e.similarityFunction||qo.similarityFunction,i=-1;if("function"==typeof o)for(var s=Number.MIN_VALUE,a=0;a<t.length;a++){var u=o(r,t[a]);u>s&&(s=u,i=a)}else{if("function"!=typeof n)throw new Error("A similarity or distance function it's required");for(var c=Number.MAX_VALUE,f=0;f<t.length;f++){var h=n(r,t[f]);h<c&&(c=h,i=f)}}return i}function Uo(t,r,e,n){for(var o=0;o<t.length;o++)e[o]=Do(r,t[o],{distanceFunction:n});return e}var Bo=function(){function t(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Date.now();Ar(this,t),this.state=new Uint32Array(4),this.init(r),this.random=this.getFloat.bind(this)}return Cr(t,[{key:"getUint32",value:function(){return this.nextState(),this.state[3]+this.state[2]>>>0}},{key:"getFloat",value:function(){return 5.960464477539063e-8*(this.getUint32()>>>8)}},{key:"init",value:function(t){if(!Number.isInteger(t))throw new TypeError("seed must be an integer");this.state[0]=t,this.state[1]=0,this.state[2]=0,this.state[3]=0;for(var r=1;r<8;r++)this.state[3&r]^=r+(e=1812433253,n=this.state[r-1&3]^this.state[r-1&3]>>>30>>>0,o=void 0,o=65535&(e>>>=0),((e-o)*(n>>>=0)>>>0)+o*n>>>0)>>>0;var e,n,o;this.periodCertification();for(var i=0;i<8;i++)this.nextState()}},{key:"periodCertification",value:function(){0===this.state[0]&&0===this.state[1]&&0===this.state[2]&&0===this.state[3]&&(this.state[0]=88,this.state[1]=83,this.state[2]=65,this.state[3]=68)}},{key:"nextState",value:function(){var t=this.state[0];t^=t<<15,t^=t>>>18,t^=this.state[3]<<11,this.state[0]=this.state[1],this.state[1]=this.state[2],this.state[2]=this.state[3],this.state[3]=t}}]),t}();function Go(t){var r,e,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Math.random,i=n.size,s=void 0===i?1:i,a=n.replace,u=void 0!==a&&a,c=n.probabilities;if(r="number"==typeof t?$o(t):t.slice(),c){if(!u)throw new Error("choice with probabilities and no replacement is not implemented");if(c.length!==r.length)throw new Error("the length of probabilities option should be equal to the number of choices");e=[c[0]];for(var f=1;f<c.length;f++)e[f]=e[f-1]+c[f];if(Math.abs(1-e[e.length-1])>1e-8)throw new Error("probabilities should sum to 1, but instead sums to ".concat(e[e.length-1]))}if(!1===u&&s>r.length)throw new Error("size option is too large");for(var h=[],l=0;l<s;l++){var v=Ko(r.length,o,e);h.push(r[v]),u||r.splice(v,1)}return h}function $o(t){for(var r=[],e=0;e<t;e++)r.push(e);return r}function Ko(t,r,e){var n=r();if(e){for(var o=0;n>e[o];)o++;return o}return Math.floor(n*t)}var Wo=function(){function t(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Math.random;if(Ar(this,t),"number"==typeof r){var e=new Bo(r);this.randomGenerator=e.random}else this.randomGenerator=r}return Cr(t,[{key:"choice",value:function(t,r){return Go(t,r,this.randomGenerator)}},{key:"random",value:function(){return this.randomGenerator()}},{key:"randInt",value:function(t,r){return void 0===r&&(r=t,t=0),t+Math.floor(this.randomGenerator()*(r-t))}},{key:"randomSample",value:function(t){for(var r=[],e=0;e<t;e++)r.push(this.random());return r}}]),t}();function Xo(t,r){for(var e=new ge(t.rows,r.rows),n=0;n<t.rows;n++)for(var o=0;o<r.rows;o++)e.set(n,o,Vo(t.getRow(n),r.getRow(o)));return e}function Yo(t){for(var r=[],e=0;e<t;e++)r.push(e);return r}function Jo(t){for(var r=[t[0]],e=1;e<t.length;e++)r[e]=r[e-1]+t[e];return r}var Zo=Symbol("distance"),Ho=function(){function t(r,e,n,o,i){Ar(this,t),this.clusters=r,this.centroids=e,this.converged=n,this.iterations=o,this[Zo]=i}return Cr(t,[{key:"nearest",value:function(t){var r=new Array(t.length);return Uo(t,this.centroids.map((function(t){return t.centroid})),r,this[Zo])}},{key:"computeInformation",value:function(r){for(var e=this.centroids.map((function(t){return{centroid:t,error:0,size:0}})),n=0;n<r.length;n++)e[this.clusters[n]].error+=this[Zo](r[n],this.centroids[this.clusters[n]]),e[this.clusters[n]].size++;for(var o=0;o<this.centroids.length;o++)e[o].size?e[o].error/=e[o].size:e[o].error=null;return new t(this.clusters,e,this.converged,this.iterations,this[Zo])}}]),t}(),Qo=a.mark(ei),ti={maxIterations:100,tolerance:1e-6,withIterations:!1,initialization:"kmeans++",distanceFunction:Vo};function ri(t,r,e,n,o,i){var s=function(t,r,e,n){for(var o=r[0].length,i=new Array(n),s=new Array(n),a=0;a<n;a++){i[a]=new Array(o),s[a]=0;for(var u=0;u<o;u++)i[a][u]=0}for(var c=0;c<r.length;c++){s[e[c]]++;for(var f=0;f<o;f++)i[e[c]][f]+=r[c][f]}for(var h=0;h<n;h++)for(var l=0;l<o;l++)s[h]?i[h][l]/=s[h]:i[h][l]=t[h][l];return i}(t,r,e=Uo(r,t,e,o.distanceFunction),n),a=function(t,r,e,n){for(var o=0;o<t.length;o++)if(e(t[o],r[o])>n)return!1;return!0}(s,t,o.distanceFunction,o.tolerance);return new Ho(e,s,a,i,o.distanceFunction)}function ei(t,r,e,n,o){var i,s,u;return a.wrap((function(a){for(;;)switch(a.prev=a.next){case 0:i=!1,s=0;case 2:if(i||!(s<o.maxIterations)){a.next=10;break}return u=ri(t,r,e,n,o,++s),a.next=6,u.computeInformation(r);case 6:i=u.converged,t=u.centroids,a.next=2;break;case 10:case"end":return a.stop()}}),Qo)}function ni(t,r,e){if(e=Object.assign({},ti,e),r<=0||r>t.length||!Number.isInteger(r))throw new Error("K should be a positive integer smaller than the number of points");var n;if(Array.isArray(e.initialization)){if(e.initialization.length!==r)throw new Error("The initial centers should have the same length as K");n=e.initialization}else switch(e.initialization){case"kmeans++":n=function(t,r){var e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=(t=new ge(t)).rows,o=new Wo(e.seed),i=[],s=e.localTrials||2+Math.floor(Math.log(r)),a=o.randInt(n);i.push(t.getRow(a));for(var u=new ge(1,t.rows),c=0;c<t.rows;c++)u.set(0,c,Vo(t.getRow(c),i[0]));for(var f=[Jo(u.getRow(0))],h=1/f[0][n-1],l=ge.mul(u,h),v=1;v<r;v++){for(var m=o.choice(n,{replace:!0,size:s,probabilities:l[0]}),g=Xo(t.selection(m,Yo(t.columns)),t),p=void 0,d=void 0,w=void 0,y=0;y<s;y++){var b=ge.min(u,[g.getRow(y)]),M=b.sum();(void 0===p||M<d)&&(p=m[y],d=M,w=b)}i[v]=t.getRow(p),f=[Jo((u=w).getRow(0))],l=ge.mul(u,1/f[0][n-1])}return i}(t,r,e);break;case"random":n=function(t,r,e){return new Wo(e).choice(t,{size:r})}(t,r,e.seed);break;case"mostDistant":n=function(t,r,e,n){var o=new Wo(n),i=new Array(r);if(i[0]=Math.floor(o.random()*t.length),r>1){for(var s={dist:-1,index:-1},a=0;a<t.length;++a)e[i[0]][a]>s.dist&&(s.dist=e[i[0]][a],s.index=a);if(i[1]=s.index,r>2)for(var u=2;u<r;++u){for(var c={dist:-1,index:-1},f=0;f<t.length;++f){for(var h={dist:Number.MAX_VALUE,index:-1},l=0;l<u;++l)e[l][f]<h.dist&&-1===i.indexOf(f)&&(h={dist:e[l][f],index:f});h.dist!==Number.MAX_VALUE&&h.dist>c.dist&&(c=Object.assign({},h))}i[u]=c.index}}return i.map((function(r){return t[r]}))}(t,r,function(t,r){for(var e=new Array(t.length),n=0;n<t.length;++n)for(var o=n;o<t.length;++o){e[n]||(e[n]=new Array(t.length)),e[o]||(e[o]=new Array(t.length));var i=r(t[n],t[o]);e[n][o]=i,e[o][n]=i}return e}(t,e.distanceFunction),e.seed);break;default:throw new Error('Unknown initialization method: "'.concat(e.initialization,'"'))}0===e.maxIterations&&(e.maxIterations=Number.MAX_VALUE);var o=new Array(t.length);if(e.withIterations)return ei(n,t,o,r,e);for(var i,s=!1,a=0;!s&&a<e.maxIterations;)s=(i=ri(n,t,o,r,e,++a)).converged,n=i.centroids;return i.computeInformation(t)}function oi(t,r){var e={};function n(t){return jo(t,":")}sn(t,(function(t,r){var o=n(t);e[o]=r}));var o=Lo.Clusterer.getInstance(t,r).getClusteredData();return o=eo(o,(function(t){return eo(t,(function(t){var r=n(t);return e[r]}))}))}function ii(t,r){var e=ni(t,r),n={};return sn(e.clusters,(function(t,r){n[t]||(n[t]=[]),n[t].push(r)})),oo(n)}function si(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},e=Nt(r,"kNumber");e=so(e)?So(e):2;var n,o=Nt(r,"mode");if("k-medoids"!==o&&"k-means"!==o&&(o="k-medoids"),"k-medoids"===o)n=oi(t,e);else{if("k-means"!==o)throw new Error("invalid mode");n=ii(t,e)}return n}function ai(t){var r={};sn(t,(function(t){sn(t,(function(t,e){r[e]||(r[e]=0),0===r[e]&&so(t)&&(r[e]=1),1!==r[e]||so(t)||(r[e]=-1)}))}));var e=[];return sn(r,(function(t,r){1===t&&e.push(r)})),e}function ui(t,r){return eo(t,(function(t){var e=ao(t,r);return oo(e)}))}function ci(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!Rr(t))throw new Error("data is not eff. array");var e=Nt(r,"kNumber");e=so(e)?So(e):2;var n=Nt(r,"nCompNIPALS");n=so(n)?So(n):2;var o=Nt(r,"mode"),i="",s=Mr(t),a=0,u=0;if(sn(t,(function(t){uo(t)?a+=1:Rr(t)&&(u+=1)})),a===s)i="obj";else{if(u!==s)throw new Error("data is not of the same type");i="mat"}var c,f=null;"obj"===i?(f=ai(t),c=ui(t,f)):c=t;var h=Ne(c,{nCompNIPALS:n}),l=si(h,{kNumber:e,mode:o}),v=eo(l,(function(t){return eo(t,(function(t){return h[t]}))})),m=eo(l,(function(r){return eo(r,(function(r){return t[r]}))}));return{keys:f,ginds:l,gltdt:m,gmat:v}}function fi(){return fi=r(a.mark((function t(r){var e,n=arguments;return a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e=n.length>1&&void 0!==n[1]?n[1]:{},t.abrupt("return",Ne(r,e));case 2:case"end":return t.stop()}}),t)}))),fi.apply(this,arguments)}function hi(){return hi=r(a.mark((function t(r){var e,n=arguments;return a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e=n.length>1&&void 0!==n[1]?n[1]:{},t.prev=1,t.abrupt("return",ci(r,e));case 5:return t.prev=5,t.t0=t.catch(1),t.abrupt("return",Promise.reject(t.t0));case 8:case"end":return t.stop()}}),t,null,[[1,5]])}))),hi.apply(this,arguments)}var li={PCA:function(t){return fi.apply(this,arguments)},cluster:function(t){return hi.apply(this,arguments)}};return li}));
|
|
7
7
|
//# sourceMappingURL=w-cluster.umd.js.map
|