w-cluster 1.0.16 → 1.0.18
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/.eslintrc.js +1 -0
- package/README.md +3 -2
- package/dist/w-cluster.umd.js +7 -0
- package/dist/w-cluster.umd.js.map +1 -0
- package/dist/w-cluster.wk.umd.js +1 -0
- package/docs/WCluster.mjs.html +1 -1
- package/docs/examples/ex-PCA.html +1 -1
- package/docs/examples/ex-cluster-webworker.html +1 -1
- package/docs/examples/ex-cluster.html +1 -1
- package/docs/global.html +1 -1
- package/docs/index.html +1 -1
- package/package.json +4 -4
- package/src/WClusterMat.mjs +1 -1
package/.eslintrc.js
CHANGED
package/README.md
CHANGED
|
@@ -6,6 +6,7 @@ A tool for data PCA(Principle Component Analysis) and cluster(K-Means & K-Medoid
|
|
|
6
6
|
[](https://npmjs.org/package/w-cluster)
|
|
7
7
|
[](https://github.com/yuda-lyu/w-cluster)
|
|
8
8
|
[](https://npmjs.org/package/w-cluster)
|
|
9
|
+
[](https://npmjs.org/package/w-cluster)
|
|
9
10
|
[](https://www.jsdelivr.com/package/npm/w-cluster)
|
|
10
11
|
|
|
11
12
|
## Documentation
|
|
@@ -278,9 +279,9 @@ testCluster()
|
|
|
278
279
|
```alias
|
|
279
280
|
|
|
280
281
|
<!-- for basic -->
|
|
281
|
-
<script src="https://cdn.jsdelivr.net/npm/w-cluster@1.0.
|
|
282
|
+
<script src="https://cdn.jsdelivr.net/npm/w-cluster@1.0.18/dist/w-cluster.umd.js"></script>
|
|
282
283
|
|
|
283
284
|
<!-- for web workers -->
|
|
284
|
-
<script src="https://cdn.jsdelivr.net/npm/w-cluster@1.0.
|
|
285
|
+
<script src="https://cdn.jsdelivr.net/npm/w-cluster@1.0.18/dist/w-cluster.wk.umd.js"></script>
|
|
285
286
|
|
|
286
287
|
```
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* w-cluster v1.0.18
|
|
3
|
+
* (c) 2018-2021 yuda-lyu(semisphere)
|
|
4
|
+
* Released under the MIT License.
|
|
5
|
+
*/
|
|
6
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self)["w-cluster"]=e()}(this,(function(){"use strict";var t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function e(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var r=Array.isArray,n="object"==typeof t&&t&&t.Object===Object&&t,o=n,s="object"==typeof self&&self&&self.Object===Object&&self,i=o||s||Function("return this")(),u=i.Symbol,a=u,l=Object.prototype,h=l.hasOwnProperty,c=l.toString,f=a?a.toStringTag:void 0;var g=function(t){var e=h.call(t,f),r=t[f];try{t[f]=void 0;var n=!0}catch(t){}var o=c.call(t);return n&&(e?t[f]=r:delete t[f]),o},m=Object.prototype.toString;var p=g,d=function(t){return m.call(t)},w=u?u.toStringTag:void 0;var b=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":w&&w in Object(t)?p(t):d(t)};var y=function(t){return null!=t&&"object"==typeof t},v=b,M=y;var j=function(t){return"symbol"==typeof t||M(t)&&"[object Symbol]"==v(t)},x=r,_=j,E=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,S=/^\w*$/;var O=function(t,e){if(x(t))return!1;var r=typeof t;return!("number"!=r&&"symbol"!=r&&"boolean"!=r&&null!=t&&!_(t))||(S.test(t)||!E.test(t)||null!=e&&t in Object(e))};var A=function(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)},C=b,R=A;var I,N=function(t){if(!R(t))return!1;var e=C(t);return"[object Function]"==e||"[object GeneratorFunction]"==e||"[object AsyncFunction]"==e||"[object Proxy]"==e},k=i["__core-js_shared__"],F=(I=/[^.]+$/.exec(k&&k.keys&&k.keys.IE_PROTO||""))?"Symbol(src)_1."+I:"";var P=function(t){return!!F&&F in t},T=Function.prototype.toString;var z=function(t){if(null!=t){try{return T.call(t)}catch(t){}try{return t+""}catch(t){}}return""},V=N,$=P,q=A,D=z,U=/^\[object .+?Constructor\]$/,L=Function.prototype,B=Object.prototype,G=L.toString,W=B.hasOwnProperty,K=RegExp("^"+G.call(W).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");var Y=function(t){return!(!q(t)||$(t))&&(V(t)?K:U).test(D(t))},X=function(t,e){return null==t?void 0:t[e]};var J=function(t,e){var r=X(t,e);return Y(r)?r:void 0},Z=J(Object,"create"),H=Z;var Q=function(){this.__data__=H?H(null):{},this.size=0};var tt=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},et=Z,rt=Object.prototype.hasOwnProperty;var nt=function(t){var e=this.__data__;if(et){var r=e[t];return"__lodash_hash_undefined__"===r?void 0:r}return rt.call(e,t)?e[t]:void 0},ot=Z,st=Object.prototype.hasOwnProperty;var it=Z;var ut=Q,at=tt,lt=nt,ht=function(t){var e=this.__data__;return ot?void 0!==e[t]:st.call(e,t)},ct=function(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=it&&void 0===e?"__lodash_hash_undefined__":e,this};function ft(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}ft.prototype.clear=ut,ft.prototype.delete=at,ft.prototype.get=lt,ft.prototype.has=ht,ft.prototype.set=ct;var gt=ft;var mt=function(){this.__data__=[],this.size=0};var pt=function(t,e){return t===e||t!=t&&e!=e},dt=pt;var wt=function(t,e){for(var r=t.length;r--;)if(dt(t[r][0],e))return r;return-1},bt=wt,yt=Array.prototype.splice;var vt=wt;var Mt=wt;var jt=wt;var xt=mt,_t=function(t){var e=this.__data__,r=bt(e,t);return!(r<0)&&(r==e.length-1?e.pop():yt.call(e,r,1),--this.size,!0)},Et=function(t){var e=this.__data__,r=vt(e,t);return r<0?void 0:e[r][1]},St=function(t){return Mt(this.__data__,t)>-1},Ot=function(t,e){var r=this.__data__,n=jt(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=e,this};function At(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}At.prototype.clear=xt,At.prototype.delete=_t,At.prototype.get=Et,At.prototype.has=St,At.prototype.set=Ot;var Ct=At,Rt=J(i,"Map"),It=gt,Nt=Ct,kt=Rt;var Ft=function(t){var e=typeof t;return"string"==e||"number"==e||"symbol"==e||"boolean"==e?"__proto__"!==t:null===t};var Pt=function(t,e){var r=t.__data__;return Ft(e)?r["string"==typeof e?"string":"hash"]:r.map},Tt=Pt;var zt=Pt;var Vt=Pt;var $t=Pt;var qt=function(t,e){var r=$t(this,t),n=r.size;return r.set(t,e),this.size+=r.size==n?0:1,this},Dt=function(){this.size=0,this.__data__={hash:new It,map:new(kt||Nt),string:new It}},Ut=function(t){var e=Tt(this,t).delete(t);return this.size-=e?1:0,e},Lt=function(t){return zt(this,t).get(t)},Bt=function(t){return Vt(this,t).has(t)},Gt=qt;function Wt(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}Wt.prototype.clear=Dt,Wt.prototype.delete=Ut,Wt.prototype.get=Lt,Wt.prototype.has=Bt,Wt.prototype.set=Gt;var Kt=Wt,Yt=Kt;function Xt(t,e){if("function"!=typeof t||null!=e&&"function"!=typeof e)throw new TypeError("Expected a function");var r=function(){var n=arguments,o=e?e.apply(this,n):n[0],s=r.cache;if(s.has(o))return s.get(o);var i=t.apply(this,n);return r.cache=s.set(o,i)||s,i};return r.cache=new(Xt.Cache||Yt),r}Xt.Cache=Yt;var Jt=Xt;var Zt=function(t){var e=Jt(t,(function(t){return 500===r.size&&r.clear(),t})),r=e.cache;return e},Ht=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,Qt=/\\(\\)?/g,te=Zt((function(t){var e=[];return 46===t.charCodeAt(0)&&e.push(""),t.replace(Ht,(function(t,r,n,o){e.push(n?o.replace(Qt,"$1"):r||t)})),e}));var ee=function(t,e){for(var r=-1,n=null==t?0:t.length,o=Array(n);++r<n;)o[r]=e(t[r],r,t);return o},re=ee,ne=r,oe=j,se=u?u.prototype:void 0,ie=se?se.toString:void 0;var ue=function t(e){if("string"==typeof e)return e;if(ne(e))return re(e,t)+"";if(oe(e))return ie?ie.call(e):"";var r=e+"";return"0"==r&&1/e==-Infinity?"-0":r},ae=ue;var le=r,he=O,ce=te,fe=function(t){return null==t?"":ae(t)};var ge=function(t,e){return le(t)?t:he(t,e)?[t]:ce(fe(t))},me=j;var pe=function(t){if("string"==typeof t||me(t))return t;var e=t+"";return"0"==e&&1/t==-Infinity?"-0":e},de=ge,we=pe;var be=function(t,e){for(var r=0,n=(e=de(e,t)).length;null!=t&&r<n;)t=t[we(e[r++])];return r&&r==n?t:void 0},ye=be;var ve=function(t,e,r){var n=null==t?void 0:ye(t,e);return void 0===n?r:n},Me=Object.prototype;var je=function(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||Me)};var xe=function(t,e){return function(r){return t(e(r))}},_e=xe(Object.keys,Object),Ee=je,Se=_e,Oe=Object.prototype.hasOwnProperty;var Ae=function(t){if(!Ee(t))return Se(t);var e=[];for(var r in Object(t))Oe.call(t,r)&&"constructor"!=r&&e.push(r);return e},Ce=J(i,"DataView"),Re=Rt,Ie=J(i,"Promise"),Ne=J(i,"Set"),ke=J(i,"WeakMap"),Fe=b,Pe=z,Te="[object Map]",ze="[object Promise]",Ve="[object Set]",$e="[object WeakMap]",qe="[object DataView]",De=Pe(Ce),Ue=Pe(Re),Le=Pe(Ie),Be=Pe(Ne),Ge=Pe(ke),We=Fe;(Ce&&We(new Ce(new ArrayBuffer(1)))!=qe||Re&&We(new Re)!=Te||Ie&&We(Ie.resolve())!=ze||Ne&&We(new Ne)!=Ve||ke&&We(new ke)!=$e)&&(We=function(t){var e=Fe(t),r="[object Object]"==e?t.constructor:void 0,n=r?Pe(r):"";if(n)switch(n){case De:return qe;case Ue:return Te;case Le:return ze;case Be:return Ve;case Ge:return $e}return e});var Ke=We;var Ye=function(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=9007199254740991},Xe=N,Je=Ye;var Ze=function(t){return null!=t&&Je(t.length)&&!Xe(t)},He=b,Qe=r,tr=y;var er=function(t){return"string"==typeof t||!Qe(t)&&tr(t)&&"[object String]"==He(t)};var rr=function(t){return function(e){return null==e?void 0:e[t]}},nr=rr("length"),or=RegExp("[\\u200d\\ud800-\\udfff\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff\\ufe0e\\ufe0f]");var sr=function(t){return or.test(t)},ir="\\ud800-\\udfff",ur="["+ir+"]",ar="[\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff]",lr="\\ud83c[\\udffb-\\udfff]",hr="[^"+ir+"]",cr="(?:\\ud83c[\\udde6-\\uddff]){2}",fr="[\\ud800-\\udbff][\\udc00-\\udfff]",gr="(?:"+ar+"|"+lr+")"+"?",mr="[\\ufe0e\\ufe0f]?",pr=mr+gr+("(?:\\u200d(?:"+[hr,cr,fr].join("|")+")"+mr+gr+")*"),dr="(?:"+[hr+ar+"?",ar,cr,fr,ur].join("|")+")",wr=RegExp(lr+"(?="+lr+")|"+dr+pr,"g");var br=nr,yr=sr,vr=function(t){for(var e=wr.lastIndex=0;wr.test(t);)++e;return e};var Mr=Ae,jr=Ke,xr=Ze,_r=er,Er=function(t){return yr(t)?vr(t):br(t)};var Sr=function(t){if(null==t)return 0;if(xr(t))return _r(t)?Er(t):t.length;var e=jr(t);return"[object Map]"==e||"[object Set]"==e?t.size:Mr(t).length};function Or(t){return"[object Array]"===Object.prototype.toString.call(t)}function Ar(t){return"[object Object]"===Object.prototype.toString.call(t)}function Cr(t){return"[object String]"===Object.prototype.toString.call(t)}function Rr(t){return t!=t}function Ir(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(Ar(t)){for(let e in t)return!1;return!0}return!1}(t)||(!!function(t){return!(!Cr(t)||""!==t)}(t)||(!!function(t){return!!Or(t)&&0===t.length}(t)||!!Rr(t)))))}function Nr(t){return!!Or(t)&&(0!==t.length&&(1!==t.length||!Ir(t[0])))}var kr="object"==typeof global&&global&&global.Object===Object&&global,Fr="object"==typeof self&&self&&self.Object===Object&&self,Pr=kr||Fr||Function("return this")(),Tr=Pr.Symbol,zr=Object.prototype,Vr=zr.hasOwnProperty,$r=zr.toString,qr=Tr?Tr.toStringTag:void 0;var Dr=Object.prototype.toString;var Ur="[object Null]",Lr="[object Undefined]",Br=Tr?Tr.toStringTag:void 0;function Gr(t){return null==t?void 0===t?Lr:Ur:Br&&Br in Object(t)?function(t){var e=Vr.call(t,qr),r=t[qr];try{t[qr]=void 0;var n=!0}catch(t){}var o=$r.call(t);return n&&(e?t[qr]=r:delete t[qr]),o}(t):function(t){return Dr.call(t)}(t)}function Wr(t){return null!=t&&"object"==typeof t}var Kr="[object Boolean]";function Yr(t){return!0===(e=t)||!1===e||Wr(e)&&Gr(e)==Kr;var e}function Xr(t){return!(!Cr(t)||""===t)}function Jr(t){let e=!1;if(Xr(t))e=!isNaN(Number(t));else if(function(t){return"[object Number]"===Object.prototype.toString.call(t)}(t)){if(Rr(t))return!1;e=!0}return e}var Zr=/\s/;var Hr=/^\s+/;function Qr(t){return t?t.slice(0,function(t){for(var e=t.length;e--&&Zr.test(t.charAt(e)););return e}(t)+1).replace(Hr,""):t}function tn(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}var en="[object Symbol]";function rn(t){return"symbol"==typeof t||Wr(t)&&Gr(t)==en}var nn=NaN,on=/^[-+]0x[0-9a-f]+$/i,sn=/^0b[01]+$/i,un=/^0o[0-7]+$/i,an=parseInt;function ln(t){if("number"==typeof t)return t;if(rn(t))return nn;if(tn(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=tn(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=Qr(t);var r=sn.test(t);return r||un.test(t)?an(t.slice(2),r?2:8):on.test(t)?nn:+t}var hn=1/0,cn=17976931348623157e292;function fn(t){return t?(t=ln(t))===hn||t===-hn?(t<0?-1:1)*cn:t==t?t:0:0===t?t:0}var gn=Array.isArray,mn=1/0,pn=Tr?Tr.prototype:void 0,dn=pn?pn.toString:void 0;function wn(t){if("string"==typeof t)return t;if(gn(t))return function(t,e){for(var r=-1,n=null==t?0:t.length,o=Array(n);++r<n;)o[r]=e(t[r],r,t);return o}(t,wn)+"";if(rn(t))return dn?dn.call(t):"";var e=t+"";return"0"==e&&1/t==-mn?"-0":e}function bn(t){return null==t?"":wn(t)}var yn=Pr.isFinite,vn=Math.min;var Mn,jn=(Mn=Math["round"],function(t,e){if(t=ln(t),e=null==e?0:vn(function(t){var e=fn(t),r=e%1;return e==e?r?e-r:e:0}(e),292),e&&yn(t)){var r=(bn(t)+"e").split("e");return+((r=(bn(Mn(r[0]+"e"+(+r[1]+e)))+"e").split("e"))[0]+"e"+(+r[1]-e))}return Mn(t)});function xn(t){if(!Jr(t))return 0;t=function(t){return Jr(t)?fn(t):0}(t);let e=jn(t);return"0"===String(e)?0:e}const _n=Object.prototype.toString;function En(t){return _n.call(t).endsWith("Array]")}function Sn(t){var e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!En(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");if(void 0!==r.output){if(!En(r.output))throw new TypeError("output option must be an array if specified");e=r.output}else e=new Array(t.length);var n=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!En(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");var r=e.fromIndex,n=void 0===r?0:r,o=e.toIndex,s=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(s<=n||s>t.length||!Number.isInteger(s))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var i=t[n],u=n+1;u<s;u++)t[u]<i&&(i=t[u]);return i}(t),o=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!En(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");var r=e.fromIndex,n=void 0===r?0:r,o=e.toIndex,s=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(s<=n||s>t.length||!Number.isInteger(s))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var i=t[n],u=n+1;u<s;u++)t[u]>i&&(i=t[u]);return i}(t);if(n===o)throw new RangeError("minimum and maximum input values are equal. Cannot rescale a constant array");var s=r.min,i=void 0===s?r.autoMinMax?n:0:s,u=r.max,a=void 0===u?r.autoMinMax?o:1:u;if(i>=a)throw new RangeError("min option must be smaller than max option");for(var l=(a-i)/(o-n),h=0;h<t.length;h++)e[h]=(t[h]-n)*l+i;return e}const On=" ".repeat(2),An=" ".repeat(4);function Cn(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const{maxRows:r=15,maxColumns:n=10,maxNumSize:o=8,padMinus:s="auto"}=e;return`${t.constructor.name} {\n${On}[\n${An}${function(t,e,r,n,o){const{rows:s,columns:i}=t,u=Math.min(s,e),a=Math.min(i,r),l=[];if("auto"===o){o=!1;t:for(let e=0;e<u;e++)for(let r=0;r<a;r++)if(t.get(e,r)<0){o=!0;break t}}for(let e=0;e<u;e++){let r=[];for(let s=0;s<a;s++)r.push(Rn(t.get(e,s),n,o));l.push(`${r.join(" ")}`)}a!==i&&(l[l.length-1]+=` ... ${i-r} more columns`);u!==s&&l.push(`... ${s-e} more rows`);return l.join(`\n${An}`)}(t,r,n,o,s)}\n${On}]\n${On}rows: ${t.rows}\n${On}columns: ${t.columns}\n}`}function Rn(t,e,r){return(t>=0&&r?` ${In(t,e-1)}`:In(t,e)).padEnd(e)}function In(t,e){let r=t.toString();if(r.length<=e)return r;let n=t.toFixed(e);if(n.length>e&&(n=t.toFixed(Math.max(0,e-(n.length-e)))),n.length<=e&&!n.startsWith("0.000")&&!n.startsWith("-0.000"))return n;let o=t.toExponential(e);return o.length>e&&(o=t.toExponential(Math.max(0,e-(o.length-e)))),o.slice(0)}function Nn(t,e,r){let n=r?t.rows:t.rows-1;if(e<0||e>n)throw new RangeError("Row index out of range")}function kn(t,e,r){let n=r?t.columns:t.columns-1;if(e<0||e>n)throw new RangeError("Column index out of range")}function Fn(t,e){if(e.to1DArray&&(e=e.to1DArray()),e.length!==t.columns)throw new RangeError("vector size must be the same as the number of columns");return e}function Pn(t,e){if(e.to1DArray&&(e=e.to1DArray()),e.length!==t.rows)throw new RangeError("vector size must be the same as the number of rows");return e}function Tn(t,e,r,n,o){if(5!==arguments.length)throw new RangeError("expected 4 arguments");if(Vn("startRow",e),Vn("endRow",r),Vn("startColumn",n),Vn("endColumn",o),e>r||n>o||e<0||e>=t.rows||r<0||r>=t.rows||n<0||n>=t.columns||o<0||o>=t.columns)throw new RangeError("Submatrix indices are out of range")}function zn(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=[];for(let n=0;n<t;n++)r.push(e);return r}function Vn(t,e){if("number"!=typeof e)throw new TypeError(`${t} must be a number`)}function $n(t){if(t.isEmpty())throw new Error("Empty matrix has no elements to index")}class qn{static from1DArray(t,e,r){if(t*e!==r.length)throw new RangeError("data length does not match given dimensions");let n=new Un(t,e);for(let o=0;o<t;o++)for(let t=0;t<e;t++)n.set(o,t,r[o*e+t]);return n}static rowVector(t){let e=new Un(1,t.length);for(let r=0;r<t.length;r++)e.set(0,r,t[r]);return e}static columnVector(t){let e=new Un(t.length,1);for(let r=0;r<t.length;r++)e.set(r,0,t[r]);return e}static zeros(t,e){return new Un(t,e)}static ones(t,e){return new Un(t,e).fill(1)}static rand(t,e){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("object"!=typeof r)throw new TypeError("options must be an object");const{random:n=Math.random}=r;let o=new Un(t,e);for(let r=0;r<t;r++)for(let t=0;t<e;t++)o.set(r,t,n());return o}static randInt(t,e){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("object"!=typeof r)throw new TypeError("options must be an object");const{min:n=0,max:o=1e3,random:s=Math.random}=r;if(!Number.isInteger(n))throw new TypeError("min must be an integer");if(!Number.isInteger(o))throw new TypeError("max must be an integer");if(n>=o)throw new RangeError("min must be smaller than max");let i=o-n,u=new Un(t,e);for(let r=0;r<t;r++)for(let t=0;t<e;t++){let e=n+Math.round(s()*i);u.set(r,t,e)}return u}static eye(t,e,r){void 0===e&&(e=t),void 0===r&&(r=1);let n=Math.min(t,e),o=this.zeros(t,e);for(let t=0;t<n;t++)o.set(t,t,r);return o}static diag(t,e,r){let n=t.length;void 0===e&&(e=n),void 0===r&&(r=e);let o=Math.min(n,e,r),s=this.zeros(e,r);for(let e=0;e<o;e++)s.set(e,e,t[e]);return s}static min(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,n=t.columns,o=new Un(r,n);for(let s=0;s<r;s++)for(let r=0;r<n;r++)o.set(s,r,Math.min(t.get(s,r),e.get(s,r)));return o}static max(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,n=t.columns,o=new this(r,n);for(let s=0;s<r;s++)for(let r=0;r<n;r++)o.set(s,r,Math.max(t.get(s,r),e.get(s,r)));return o}static checkMatrix(t){return qn.isMatrix(t)?t:new Un(t)}static isMatrix(t){return null!=t&&"Matrix"===t.klass}get size(){return this.rows*this.columns}apply(t){if("function"!=typeof t)throw new TypeError("callback must be a function");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.call(this,e,r);return this}to1DArray(){let t=[];for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.push(this.get(e,r));return t}to2DArray(){let t=[];for(let e=0;e<this.rows;e++){t.push([]);for(let r=0;r<this.columns;r++)t[e].push(this.get(e,r))}return t}toJSON(){return this.to2DArray()}isRowVector(){return 1===this.rows}isColumnVector(){return 1===this.columns}isVector(){return 1===this.rows||1===this.columns}isSquare(){return this.rows===this.columns}isEmpty(){return 0===this.rows||0===this.columns}isSymmetric(){if(this.isSquare()){for(let t=0;t<this.rows;t++)for(let e=0;e<=t;e++)if(this.get(t,e)!==this.get(e,t))return!1;return!0}return!1}isEchelonForm(){let t=0,e=0,r=-1,n=!0,o=!1;for(;t<this.rows&&n;){for(e=0,o=!1;e<this.columns&&!1===o;)0===this.get(t,e)?e++:1===this.get(t,e)&&e>r?(o=!0,r=e):(n=!1,o=!0);t++}return n}isReducedEchelonForm(){let t=0,e=0,r=-1,n=!0,o=!1;for(;t<this.rows&&n;){for(e=0,o=!1;e<this.columns&&!1===o;)0===this.get(t,e)?e++:1===this.get(t,e)&&e>r?(o=!0,r=e):(n=!1,o=!0);for(let r=e+1;r<this.rows;r++)0!==this.get(t,r)&&(n=!1);t++}return n}echelonForm(){let t=this.clone(),e=0,r=0;for(;e<t.rows&&r<t.columns;){let n=e;for(let o=e;o<t.rows;o++)t.get(o,r)>t.get(n,r)&&(n=o);if(0===t.get(n,r))r++;else{t.swapRows(e,n);let o=t.get(e,r);for(let n=r;n<t.columns;n++)t.set(e,n,t.get(e,n)/o);for(let n=e+1;n<t.rows;n++){let o=t.get(n,r)/t.get(e,r);t.set(n,r,0);for(let s=r+1;s<t.columns;s++)t.set(n,s,t.get(n,s)-t.get(e,s)*o)}e++,r++}}return t}reducedEchelonForm(){let t=this.echelonForm(),e=t.columns,r=t.rows,n=r-1;for(;n>=0;)if(0===t.maxRow(n))n--;else{let o=0,s=!1;for(;o<r&&!1===s;)1===t.get(n,o)?s=!0:o++;for(let r=0;r<n;r++){let s=t.get(r,o);for(let i=o;i<e;i++){let e=t.get(r,i)-s*t.get(n,i);t.set(r,i,e)}}n--}return t}set(){throw new Error("set method is unimplemented")}get(){throw new Error("get method is unimplemented")}repeat(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if("object"!=typeof t)throw new TypeError("options must be an object");const{rows:e=1,columns:r=1}=t;if(!Number.isInteger(e)||e<=0)throw new TypeError("rows must be a positive integer");if(!Number.isInteger(r)||r<=0)throw new TypeError("columns must be a positive integer");let n=new Un(this.rows*e,this.columns*r);for(let t=0;t<e;t++)for(let e=0;e<r;e++)n.setSubMatrix(this,this.rows*t,this.columns*e);return n}fill(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,t);return this}neg(){return this.mulS(-1)}getRow(t){Nn(this,t);let e=[];for(let r=0;r<this.columns;r++)e.push(this.get(t,r));return e}getRowVector(t){return Un.rowVector(this.getRow(t))}setRow(t,e){Nn(this,t),e=Fn(this,e);for(let r=0;r<this.columns;r++)this.set(t,r,e[r]);return this}swapRows(t,e){Nn(this,t),Nn(this,e);for(let r=0;r<this.columns;r++){let n=this.get(t,r);this.set(t,r,this.get(e,r)),this.set(e,r,n)}return this}getColumn(t){kn(this,t);let e=[];for(let r=0;r<this.rows;r++)e.push(this.get(r,t));return e}getColumnVector(t){return Un.columnVector(this.getColumn(t))}setColumn(t,e){kn(this,t),e=Pn(this,e);for(let r=0;r<this.rows;r++)this.set(r,t,e[r]);return this}swapColumns(t,e){kn(this,t),kn(this,e);for(let r=0;r<this.rows;r++){let n=this.get(r,t);this.set(r,t,this.get(r,e)),this.set(r,e,n)}return this}addRowVector(t){t=Fn(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t[r]);return this}subRowVector(t){t=Fn(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t[r]);return this}mulRowVector(t){t=Fn(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t[r]);return this}divRowVector(t){t=Fn(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t[r]);return this}addColumnVector(t){t=Pn(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t[e]);return this}subColumnVector(t){t=Pn(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t[e]);return this}mulColumnVector(t){t=Pn(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t[e]);return this}divColumnVector(t){t=Pn(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t[e]);return this}mulRow(t,e){Nn(this,t);for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)*e);return this}mulColumn(t,e){kn(this,t);for(let r=0;r<this.rows;r++)this.set(r,t,this.get(r,t)*e);return this}max(t){if(this.isEmpty())return NaN;switch(t){case"row":{const t=new Array(this.rows).fill(Number.NEGATIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)>t[e]&&(t[e]=this.get(e,r));return t}case"column":{const t=new Array(this.columns).fill(Number.NEGATIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)>t[r]&&(t[r]=this.get(e,r));return t}case void 0:{let t=this.get(0,0);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)>t&&(t=this.get(e,r));return t}default:throw new Error(`invalid option: ${t}`)}}maxIndex(){$n(this);let t=this.get(0,0),e=[0,0];for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)>t&&(t=this.get(r,n),e[0]=r,e[1]=n);return e}min(t){if(this.isEmpty())return NaN;switch(t){case"row":{const t=new Array(this.rows).fill(Number.POSITIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)<t[e]&&(t[e]=this.get(e,r));return t}case"column":{const t=new Array(this.columns).fill(Number.POSITIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)<t[r]&&(t[r]=this.get(e,r));return t}case void 0:{let t=this.get(0,0);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)<t&&(t=this.get(e,r));return t}default:throw new Error(`invalid option: ${t}`)}}minIndex(){$n(this);let t=this.get(0,0),e=[0,0];for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)<t&&(t=this.get(r,n),e[0]=r,e[1]=n);return e}maxRow(t){if(Nn(this,t),this.isEmpty())return NaN;let e=this.get(t,0);for(let r=1;r<this.columns;r++)this.get(t,r)>e&&(e=this.get(t,r));return e}maxRowIndex(t){Nn(this,t),$n(this);let e=this.get(t,0),r=[t,0];for(let n=1;n<this.columns;n++)this.get(t,n)>e&&(e=this.get(t,n),r[1]=n);return r}minRow(t){if(Nn(this,t),this.isEmpty())return NaN;let e=this.get(t,0);for(let r=1;r<this.columns;r++)this.get(t,r)<e&&(e=this.get(t,r));return e}minRowIndex(t){Nn(this,t),$n(this);let e=this.get(t,0),r=[t,0];for(let n=1;n<this.columns;n++)this.get(t,n)<e&&(e=this.get(t,n),r[1]=n);return r}maxColumn(t){if(kn(this,t),this.isEmpty())return NaN;let e=this.get(0,t);for(let r=1;r<this.rows;r++)this.get(r,t)>e&&(e=this.get(r,t));return e}maxColumnIndex(t){kn(this,t),$n(this);let e=this.get(0,t),r=[0,t];for(let n=1;n<this.rows;n++)this.get(n,t)>e&&(e=this.get(n,t),r[0]=n);return r}minColumn(t){if(kn(this,t),this.isEmpty())return NaN;let e=this.get(0,t);for(let r=1;r<this.rows;r++)this.get(r,t)<e&&(e=this.get(r,t));return e}minColumnIndex(t){kn(this,t),$n(this);let e=this.get(0,t),r=[0,t];for(let n=1;n<this.rows;n++)this.get(n,t)<e&&(e=this.get(n,t),r[0]=n);return r}diag(){let t=Math.min(this.rows,this.columns),e=[];for(let r=0;r<t;r++)e.push(this.get(r,r));return e}norm(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"frobenius",e=0;if("max"===t)return this.max();if("frobenius"===t){for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)e+=this.get(t,r)*this.get(t,r);return Math.sqrt(e)}throw new RangeError(`unknown norm type: ${t}`)}cumulativeSum(){let t=0;for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t+=this.get(e,r),this.set(e,r,t);return this}dot(t){qn.isMatrix(t)&&(t=t.to1DArray());let e=this.to1DArray();if(e.length!==t.length)throw new RangeError("vectors do not have the same size");let r=0;for(let n=0;n<e.length;n++)r+=e[n]*t[n];return r}mmul(t){t=Un.checkMatrix(t);let e=this.rows,r=this.columns,n=t.columns,o=new Un(e,n),s=new Float64Array(r);for(let i=0;i<n;i++){for(let e=0;e<r;e++)s[e]=t.get(e,i);for(let t=0;t<e;t++){let e=0;for(let n=0;n<r;n++)e+=this.get(t,n)*s[n];o.set(t,i,e)}}return o}strassen2x2(t){t=Un.checkMatrix(t);let e=new Un(2,2);const r=this.get(0,0),n=t.get(0,0),o=this.get(0,1),s=t.get(0,1),i=this.get(1,0),u=t.get(1,0),a=this.get(1,1),l=t.get(1,1),h=(r+a)*(n+l),c=(i+a)*n,f=r*(s-l),g=a*(u-n),m=(r+o)*l,p=h+g-m+(o-a)*(u+l),d=f+m,w=c+g,b=h-c+f+(i-r)*(n+s);return e.set(0,0,p),e.set(0,1,d),e.set(1,0,w),e.set(1,1,b),e}strassen3x3(t){t=Un.checkMatrix(t);let e=new Un(3,3);const r=this.get(0,0),n=this.get(0,1),o=this.get(0,2),s=this.get(1,0),i=this.get(1,1),u=this.get(1,2),a=this.get(2,0),l=this.get(2,1),h=this.get(2,2),c=t.get(0,0),f=t.get(0,1),g=t.get(0,2),m=t.get(1,0),p=t.get(1,1),d=t.get(1,2),w=t.get(2,0),b=t.get(2,1),y=t.get(2,2),v=(r-s)*(-f+p),M=(-r+s+i)*(c-f+p),j=(s+i)*(-c+f),x=r*c,_=(-r+a+l)*(c-g+d),E=(-r+a)*(g-d),S=(a+l)*(-c+g),O=(-o+l+h)*(p+w-b),A=(o-h)*(p-b),C=o*w,R=(l+h)*(-w+b),I=(-o+i+u)*(d+w-y),N=(o-u)*(d-y),k=(i+u)*(-w+y),F=x+C+n*m,P=(r+n+o-s-i-l-h)*p+M+j+x+O+C+R,T=x+_+S+(r+n+o-i-u-a-l)*d+C+I+k,z=v+i*(-c+f+m-p-d-w+y)+M+x+C+I+N,V=v+M+j+x+u*b,$=C+I+N+k+s*g,q=x+_+E+l*(-c+g+m-p-d-w+b)+O+A+C,D=O+A+C+R+a*f,U=x+_+E+S+h*y;return e.set(0,0,F),e.set(0,1,P),e.set(0,2,T),e.set(1,0,z),e.set(1,1,V),e.set(1,2,$),e.set(2,0,q),e.set(2,1,D),e.set(2,2,U),e}mmulStrassen(t){t=Un.checkMatrix(t);let e=this.clone(),r=e.rows,n=e.columns,o=t.rows,s=t.columns;function i(t,e,r){let n=t.rows,o=t.columns;if(n===e&&o===r)return t;{let n=qn.zeros(e,r);return n=n.setSubMatrix(t,0,0),n}}n!==o&&console.warn(`Multiplying ${r} x ${n} and ${o} x ${s} matrix: dimensions do not match.`);let u=Math.max(r,o),a=Math.max(n,s);return e=i(e,u,a),function t(e,r,n,o){if(n<=512||o<=512)return e.mmul(r);n%2==1&&o%2==1?(e=i(e,n+1,o+1),r=i(r,n+1,o+1)):n%2==1?(e=i(e,n+1,o),r=i(r,n+1,o)):o%2==1&&(e=i(e,n,o+1),r=i(r,n,o+1));let s=parseInt(e.rows/2,10),u=parseInt(e.columns/2,10),a=e.subMatrix(0,s-1,0,u-1),l=r.subMatrix(0,s-1,0,u-1),h=e.subMatrix(0,s-1,u,e.columns-1),c=r.subMatrix(0,s-1,u,r.columns-1),f=e.subMatrix(s,e.rows-1,0,u-1),g=r.subMatrix(s,r.rows-1,0,u-1),m=e.subMatrix(s,e.rows-1,u,e.columns-1),p=r.subMatrix(s,r.rows-1,u,r.columns-1),d=t(qn.add(a,m),qn.add(l,p),s,u),w=t(qn.add(f,m),l,s,u),b=t(a,qn.sub(c,p),s,u),y=t(m,qn.sub(g,l),s,u),v=t(qn.add(a,h),p,s,u),M=t(qn.sub(f,a),qn.add(l,c),s,u),j=t(qn.sub(h,m),qn.add(g,p),s,u),x=qn.add(d,y);x.sub(v),x.add(j);let _=qn.add(b,v),E=qn.add(w,y),S=qn.sub(d,w);S.add(b),S.add(M);let O=qn.zeros(2*x.rows,2*x.columns);return O=O.setSubMatrix(x,0,0),O=O.setSubMatrix(_,x.rows,0),O=O.setSubMatrix(E,0,x.columns),O=O.setSubMatrix(S,x.rows,x.columns),O.subMatrix(0,n-1,0,o-1)}(e,t=i(t,u,a),u,a)}scaleRows(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if("object"!=typeof t)throw new TypeError("options must be an object");const{min:e=0,max:r=1}=t;if(!Number.isFinite(e))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(e>=r)throw new RangeError("min must be smaller than max");let n=new Un(this.rows,this.columns);for(let t=0;t<this.rows;t++){const o=this.getRow(t);o.length>0&&Sn(o,{min:e,max:r,output:o}),n.setRow(t,o)}return n}scaleColumns(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if("object"!=typeof t)throw new TypeError("options must be an object");const{min:e=0,max:r=1}=t;if(!Number.isFinite(e))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(e>=r)throw new RangeError("min must be smaller than max");let n=new Un(this.rows,this.columns);for(let t=0;t<this.columns;t++){const o=this.getColumn(t);o.length&&Sn(o,{min:e,max:r,output:o}),n.setColumn(t,o)}return n}flipRows(){const t=Math.ceil(this.columns/2);for(let e=0;e<this.rows;e++)for(let r=0;r<t;r++){let t=this.get(e,r),n=this.get(e,this.columns-1-r);this.set(e,r,n),this.set(e,this.columns-1-r,t)}return this}flipColumns(){const t=Math.ceil(this.rows/2);for(let e=0;e<this.columns;e++)for(let r=0;r<t;r++){let t=this.get(r,e),n=this.get(this.rows-1-r,e);this.set(r,e,n),this.set(this.rows-1-r,e,t)}return this}kroneckerProduct(t){t=Un.checkMatrix(t);let e=this.rows,r=this.columns,n=t.rows,o=t.columns,s=new Un(e*n,r*o);for(let i=0;i<e;i++)for(let e=0;e<r;e++)for(let r=0;r<n;r++)for(let u=0;u<o;u++)s.set(n*i+r,o*e+u,this.get(i,e)*t.get(r,u));return s}kroneckerSum(t){if(t=Un.checkMatrix(t),!this.isSquare()||!t.isSquare())throw new Error("Kronecker Sum needs two Square Matrices");let e=this.rows,r=t.rows,n=this.kroneckerProduct(Un.eye(r,r)),o=Un.eye(e,e).kroneckerProduct(t);return n.add(o)}transpose(){let t=new Un(this.columns,this.rows);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.set(r,e,this.get(e,r));return t}sortRows(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Dn;for(let e=0;e<this.rows;e++)this.setRow(e,this.getRow(e).sort(t));return this}sortColumns(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Dn;for(let e=0;e<this.columns;e++)this.setColumn(e,this.getColumn(e).sort(t));return this}subMatrix(t,e,r,n){Tn(this,t,e,r,n);let o=new Un(e-t+1,n-r+1);for(let s=t;s<=e;s++)for(let e=r;e<=n;e++)o.set(s-t,e-r,this.get(s,e));return o}subMatrixRow(t,e,r){if(void 0===e&&(e=0),void 0===r&&(r=this.columns-1),e>r||e<0||e>=this.columns||r<0||r>=this.columns)throw new RangeError("Argument out of range");let n=new Un(t.length,r-e+1);for(let o=0;o<t.length;o++)for(let s=e;s<=r;s++){if(t[o]<0||t[o]>=this.rows)throw new RangeError(`Row index out of range: ${t[o]}`);n.set(o,s-e,this.get(t[o],s))}return n}subMatrixColumn(t,e,r){if(void 0===e&&(e=0),void 0===r&&(r=this.rows-1),e>r||e<0||e>=this.rows||r<0||r>=this.rows)throw new RangeError("Argument out of range");let n=new Un(r-e+1,t.length);for(let o=0;o<t.length;o++)for(let s=e;s<=r;s++){if(t[o]<0||t[o]>=this.columns)throw new RangeError(`Column index out of range: ${t[o]}`);n.set(s-e,o,this.get(s,t[o]))}return n}setSubMatrix(t,e,r){if((t=Un.checkMatrix(t)).isEmpty())return this;Tn(this,e,e+t.rows-1,r,r+t.columns-1);for(let n=0;n<t.rows;n++)for(let o=0;o<t.columns;o++)this.set(e+n,r+o,t.get(n,o));return this}selection(t,e){!function(t,e){if(!En(e))throw new TypeError("row indices must be an array");for(let r=0;r<e.length;r++)if(e[r]<0||e[r]>=t.rows)throw new RangeError("row indices are out of range")}(this,t),function(t,e){if(!En(e))throw new TypeError("column indices must be an array");for(let r=0;r<e.length;r++)if(e[r]<0||e[r]>=t.columns)throw new RangeError("column indices are out of range")}(this,e);let r=new Un(t.length,e.length);for(let n=0;n<t.length;n++){let o=t[n];for(let t=0;t<e.length;t++){let s=e[t];r.set(n,t,this.get(o,s))}}return r}trace(){let t=Math.min(this.rows,this.columns),e=0;for(let r=0;r<t;r++)e+=this.get(r,r);return e}clone(){let t=new Un(this.rows,this.columns);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.set(e,r,this.get(e,r));return t}sum(t){switch(t){case"row":return function(t){let e=zn(t.rows);for(let r=0;r<t.rows;++r)for(let n=0;n<t.columns;++n)e[r]+=t.get(r,n);return e}(this);case"column":return function(t){let e=zn(t.columns);for(let r=0;r<t.rows;++r)for(let n=0;n<t.columns;++n)e[n]+=t.get(r,n);return e}(this);case void 0:return function(t){let e=0;for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)e+=t.get(r,n);return e}(this);default:throw new Error(`invalid option: ${t}`)}}product(t){switch(t){case"row":return function(t){let e=zn(t.rows,1);for(let r=0;r<t.rows;++r)for(let n=0;n<t.columns;++n)e[r]*=t.get(r,n);return e}(this);case"column":return function(t){let e=zn(t.columns,1);for(let r=0;r<t.rows;++r)for(let n=0;n<t.columns;++n)e[n]*=t.get(r,n);return e}(this);case void 0:return function(t){let e=1;for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)e*=t.get(r,n);return e}(this);default:throw new Error(`invalid option: ${t}`)}}mean(t){const e=this.sum(t);switch(t){case"row":for(let t=0;t<this.rows;t++)e[t]/=this.columns;return e;case"column":for(let t=0;t<this.columns;t++)e[t]/=this.rows;return e;case void 0:return e/this.size;default:throw new Error(`invalid option: ${t}`)}}variance(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");const{unbiased:r=!0,mean:n=this.mean(t)}=e;if("boolean"!=typeof r)throw new TypeError("unbiased must be a boolean");switch(t){case"row":if(!En(n))throw new TypeError("mean must be an array");return function(t,e,r){const n=t.rows,o=t.columns,s=[];for(let i=0;i<n;i++){let n=0,u=0,a=0;for(let e=0;e<o;e++)a=t.get(i,e)-r[i],n+=a,u+=a*a;e?s.push((u-n*n/o)/(o-1)):s.push((u-n*n/o)/o)}return s}(this,r,n);case"column":if(!En(n))throw new TypeError("mean must be an array");return function(t,e,r){const n=t.rows,o=t.columns,s=[];for(let i=0;i<o;i++){let o=0,u=0,a=0;for(let e=0;e<n;e++)a=t.get(e,i)-r[i],o+=a,u+=a*a;e?s.push((u-o*o/n)/(n-1)):s.push((u-o*o/n)/n)}return s}(this,r,n);case void 0:if("number"!=typeof n)throw new TypeError("mean must be a number");return function(t,e,r){const n=t.rows,o=t.columns,s=n*o;let i=0,u=0,a=0;for(let e=0;e<n;e++)for(let n=0;n<o;n++)a=t.get(e,n)-r,i+=a,u+=a*a;return e?(u-i*i/s)/(s-1):(u-i*i/s)/s}(this,r,n);default:throw new Error(`invalid option: ${t}`)}}standardDeviation(t,e){"object"==typeof t&&(e=t,t=void 0);const r=this.variance(t,e);if(void 0===t)return Math.sqrt(r);for(let t=0;t<r.length;t++)r[t]=Math.sqrt(r[t]);return r}center(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");const{center:r=this.mean(t)}=e;switch(t){case"row":if(!En(r))throw new TypeError("center must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)t.set(r,n,t.get(r,n)-e[r])}(this,r),this;case"column":if(!En(r))throw new TypeError("center must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)t.set(r,n,t.get(r,n)-e[n])}(this,r),this;case void 0:if("number"!=typeof r)throw new TypeError("center must be a number");return function(t,e){for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)t.set(r,n,t.get(r,n)-e)}(this,r),this;default:throw new Error(`invalid option: ${t}`)}}scale(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");let r=e.scale;switch(t){case"row":if(void 0===r)r=function(t){const e=[];for(let r=0;r<t.rows;r++){let n=0;for(let e=0;e<t.columns;e++)n+=Math.pow(t.get(r,e),2)/(t.columns-1);e.push(Math.sqrt(n))}return e}(this);else if(!En(r))throw new TypeError("scale must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)t.set(r,n,t.get(r,n)/e[r])}(this,r),this;case"column":if(void 0===r)r=function(t){const e=[];for(let r=0;r<t.columns;r++){let n=0;for(let e=0;e<t.rows;e++)n+=Math.pow(t.get(e,r),2)/(t.rows-1);e.push(Math.sqrt(n))}return e}(this);else if(!En(r))throw new TypeError("scale must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)t.set(r,n,t.get(r,n)/e[n])}(this,r),this;case void 0:if(void 0===r)r=function(t){const e=t.size-1;let r=0;for(let n=0;n<t.columns;n++)for(let o=0;o<t.rows;o++)r+=Math.pow(t.get(o,n),2)/e;return Math.sqrt(r)}(this);else if("number"!=typeof r)throw new TypeError("scale must be a number");return function(t,e){for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)t.set(r,n,t.get(r,n)/e)}(this,r),this;default:throw new Error(`invalid option: ${t}`)}}toString(t){return Cn(this,t)}}function Dn(t,e){return t-e}qn.prototype.klass="Matrix","undefined"!=typeof Symbol&&(qn.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return Cn(this)}),qn.random=qn.rand,qn.randomInt=qn.randInt,qn.diagonal=qn.diag,qn.prototype.diagonal=qn.prototype.diag,qn.identity=qn.eye,qn.prototype.negate=qn.prototype.neg,qn.prototype.tensorProduct=qn.prototype.kroneckerProduct;class Un extends qn{constructor(t,e){if(super(),Un.isMatrix(t))return t.clone();if(Number.isInteger(t)&&t>=0){if(this.data=[],!(Number.isInteger(e)&&e>=0))throw new TypeError("nColumns must be a positive integer");for(let r=0;r<t;r++)this.data.push(new Float64Array(e))}else{if(!En(t))throw new TypeError("First argument must be a positive number or an array");{const r=t;if("number"!=typeof(e=(t=r.length)?r[0].length:0))throw new TypeError("Data must be a 2D array with at least one element");this.data=[];for(let n=0;n<t;n++){if(r[n].length!==e)throw new RangeError("Inconsistent array dimensions");if(!r[n].every((t=>"number"==typeof t)))throw new TypeError("Input data contains non-numeric values");this.data.push(Float64Array.from(r[n]))}}}this.rows=t,this.columns=e}set(t,e,r){return this.data[t][e]=r,this}get(t,e){return this.data[t][e]}removeRow(t){return Nn(this,t),this.data.splice(t,1),this.rows-=1,this}addRow(t,e){return void 0===e&&(e=t,t=this.rows),Nn(this,t,!0),e=Float64Array.from(Fn(this,e)),this.data.splice(t,0,e),this.rows+=1,this}removeColumn(t){kn(this,t);for(let e=0;e<this.rows;e++){const r=new Float64Array(this.columns-1);for(let n=0;n<t;n++)r[n]=this.data[e][n];for(let n=t+1;n<this.columns;n++)r[n-1]=this.data[e][n];this.data[e]=r}return this.columns-=1,this}addColumn(t,e){void 0===e&&(e=t,t=this.columns),kn(this,t,!0),e=Pn(this,e);for(let r=0;r<this.rows;r++){const n=new Float64Array(this.columns+1);let o=0;for(;o<t;o++)n[o]=this.data[r][o];for(n[o++]=e[r];o<this.columns+1;o++)n[o]=this.data[r][o-1];this.data[r]=n}return this.columns+=1,this}}!function(t,e){t.prototype.add=function(t){return"number"==typeof t?this.addS(t):this.addM(t)},t.prototype.addS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t);return this},t.prototype.addM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t.get(e,r));return this},t.add=function(t,r){return new e(t).add(r)},t.prototype.sub=function(t){return"number"==typeof t?this.subS(t):this.subM(t)},t.prototype.subS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t);return this},t.prototype.subM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t.get(e,r));return this},t.sub=function(t,r){return new e(t).sub(r)},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(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t);return this},t.prototype.mulM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t.get(e,r));return this},t.mul=function(t,r){return new e(t).mul(r)},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(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t);return this},t.prototype.divM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t.get(e,r));return this},t.div=function(t,r){return new e(t).div(r)},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(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)%t);return this},t.prototype.modM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)%t.get(e,r));return this},t.mod=function(t,r){return new e(t).mod(r)},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(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)&t);return this},t.prototype.andM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)&t.get(e,r));return this},t.and=function(t,r){return new e(t).and(r)},t.prototype.or=function(t){return"number"==typeof t?this.orS(t):this.orM(t)},t.prototype.orS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)|t);return this},t.prototype.orM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)|t.get(e,r));return this},t.or=function(t,r){return new e(t).or(r)},t.prototype.xor=function(t){return"number"==typeof t?this.xorS(t):this.xorM(t)},t.prototype.xorS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)^t);return this},t.prototype.xorM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)^t.get(e,r));return this},t.xor=function(t,r){return new e(t).xor(r)},t.prototype.leftShift=function(t){return"number"==typeof t?this.leftShiftS(t):this.leftShiftM(t)},t.prototype.leftShiftS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)<<t);return this},t.prototype.leftShiftM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)<<t.get(e,r));return this},t.leftShift=function(t,r){return new e(t).leftShift(r)},t.prototype.signPropagatingRightShift=function(t){return"number"==typeof t?this.signPropagatingRightShiftS(t):this.signPropagatingRightShiftM(t)},t.prototype.signPropagatingRightShiftS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>t);return this},t.prototype.signPropagatingRightShiftM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>t.get(e,r));return this},t.signPropagatingRightShift=function(t,r){return new e(t).signPropagatingRightShift(r)},t.prototype.rightShift=function(t){return"number"==typeof t?this.rightShiftS(t):this.rightShiftM(t)},t.prototype.rightShiftS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>>t);return this},t.prototype.rightShiftM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>>t.get(e,r));return this},t.rightShift=function(t,r){return new e(t).rightShift(r)},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(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,~this.get(t,e));return this},t.not=function(t){return new e(t).not()},t.prototype.abs=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.abs(this.get(t,e)));return this},t.abs=function(t){return new e(t).abs()},t.prototype.acos=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.acos(this.get(t,e)));return this},t.acos=function(t){return new e(t).acos()},t.prototype.acosh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.acosh(this.get(t,e)));return this},t.acosh=function(t){return new e(t).acosh()},t.prototype.asin=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.asin(this.get(t,e)));return this},t.asin=function(t){return new e(t).asin()},t.prototype.asinh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.asinh(this.get(t,e)));return this},t.asinh=function(t){return new e(t).asinh()},t.prototype.atan=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.atan(this.get(t,e)));return this},t.atan=function(t){return new e(t).atan()},t.prototype.atanh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.atanh(this.get(t,e)));return this},t.atanh=function(t){return new e(t).atanh()},t.prototype.cbrt=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.cbrt(this.get(t,e)));return this},t.cbrt=function(t){return new e(t).cbrt()},t.prototype.ceil=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.ceil(this.get(t,e)));return this},t.ceil=function(t){return new e(t).ceil()},t.prototype.clz32=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.clz32(this.get(t,e)));return this},t.clz32=function(t){return new e(t).clz32()},t.prototype.cos=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.cos(this.get(t,e)));return this},t.cos=function(t){return new e(t).cos()},t.prototype.cosh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.cosh(this.get(t,e)));return this},t.cosh=function(t){return new e(t).cosh()},t.prototype.exp=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.exp(this.get(t,e)));return this},t.exp=function(t){return new e(t).exp()},t.prototype.expm1=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.expm1(this.get(t,e)));return this},t.expm1=function(t){return new e(t).expm1()},t.prototype.floor=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.floor(this.get(t,e)));return this},t.floor=function(t){return new e(t).floor()},t.prototype.fround=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.fround(this.get(t,e)));return this},t.fround=function(t){return new e(t).fround()},t.prototype.log=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log(this.get(t,e)));return this},t.log=function(t){return new e(t).log()},t.prototype.log1p=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log1p(this.get(t,e)));return this},t.log1p=function(t){return new e(t).log1p()},t.prototype.log10=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log10(this.get(t,e)));return this},t.log10=function(t){return new e(t).log10()},t.prototype.log2=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log2(this.get(t,e)));return this},t.log2=function(t){return new e(t).log2()},t.prototype.round=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.round(this.get(t,e)));return this},t.round=function(t){return new e(t).round()},t.prototype.sign=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sign(this.get(t,e)));return this},t.sign=function(t){return new e(t).sign()},t.prototype.sin=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sin(this.get(t,e)));return this},t.sin=function(t){return new e(t).sin()},t.prototype.sinh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sinh(this.get(t,e)));return this},t.sinh=function(t){return new e(t).sinh()},t.prototype.sqrt=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sqrt(this.get(t,e)));return this},t.sqrt=function(t){return new e(t).sqrt()},t.prototype.tan=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.tan(this.get(t,e)));return this},t.tan=function(t){return new e(t).tan()},t.prototype.tanh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.tanh(this.get(t,e)));return this},t.tanh=function(t){return new e(t).tanh()},t.prototype.trunc=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.trunc(this.get(t,e)));return this},t.trunc=function(t){return new e(t).trunc()},t.pow=function(t,r){return new e(t).pow(r)},t.prototype.pow=function(t){return"number"==typeof t?this.powS(t):this.powM(t)},t.prototype.powS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,Math.pow(this.get(e,r),t));return this},t.prototype.powM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,Math.pow(this.get(e,r),t.get(e,r)));return this}}(qn,Un);class Ln extends qn{constructor(t,e,r){super(),this.matrix=t,this.rows=e,this.columns=r}}class Bn extends Ln{constructor(t){super(t,t.columns,t.rows)}set(t,e,r){return this.matrix.set(e,t,r),this}get(t,e){return this.matrix.get(e,t)}}class Gn extends qn{constructor(t){super(),this.data=t,this.rows=t.length,this.columns=t[0].length}set(t,e,r){return this.data[t][e]=r,this}get(t,e){return this.data[t][e]}}function Wn(t,e){let r=0;return Math.abs(t)>Math.abs(e)?(r=e/t,Math.abs(t)*Math.sqrt(1+r*r)):0!==e?(r=t/e,Math.abs(e)*Math.sqrt(1+r*r)):0}class Kn{constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if((t=Gn.checkMatrix(t)).isEmpty())throw new Error("Matrix must be non-empty");let r=t.rows,n=t.columns;const{computeLeftSingularVectors:o=!0,computeRightSingularVectors:s=!0,autoTranspose:i=!1}=e;let u,a=Boolean(o),l=Boolean(s),h=!1;if(r<n)if(i){u=t.transpose(),r=u.rows,n=u.columns,h=!0;let e=a;a=l,l=e}else u=t.clone(),console.warn("Computing SVD on a matrix with more columns than rows. Consider enabling autoTranspose");else u=t.clone();let c=Math.min(r,n),f=Math.min(r+1,n),g=new Float64Array(f),m=new Un(r,c),p=new Un(n,n),d=new Float64Array(n),w=new Float64Array(r),b=new Float64Array(f);for(let t=0;t<f;t++)b[t]=t;let y=Math.min(r-1,n),v=Math.max(0,Math.min(n-2,r)),M=Math.max(y,v);for(let t=0;t<M;t++){if(t<y){g[t]=0;for(let e=t;e<r;e++)g[t]=Wn(g[t],u.get(e,t));if(0!==g[t]){u.get(t,t)<0&&(g[t]=-g[t]);for(let e=t;e<r;e++)u.set(e,t,u.get(e,t)/g[t]);u.set(t,t,u.get(t,t)+1)}g[t]=-g[t]}for(let e=t+1;e<n;e++){if(t<y&&0!==g[t]){let n=0;for(let o=t;o<r;o++)n+=u.get(o,t)*u.get(o,e);n=-n/u.get(t,t);for(let o=t;o<r;o++)u.set(o,e,u.get(o,e)+n*u.get(o,t))}d[e]=u.get(t,e)}if(a&&t<y)for(let e=t;e<r;e++)m.set(e,t,u.get(e,t));if(t<v){d[t]=0;for(let e=t+1;e<n;e++)d[t]=Wn(d[t],d[e]);if(0!==d[t]){d[t+1]<0&&(d[t]=0-d[t]);for(let e=t+1;e<n;e++)d[e]/=d[t];d[t+1]+=1}if(d[t]=-d[t],t+1<r&&0!==d[t]){for(let e=t+1;e<r;e++)w[e]=0;for(let e=t+1;e<r;e++)for(let r=t+1;r<n;r++)w[e]+=d[r]*u.get(e,r);for(let e=t+1;e<n;e++){let n=-d[e]/d[t+1];for(let o=t+1;o<r;o++)u.set(o,e,u.get(o,e)+n*w[o])}}if(l)for(let e=t+1;e<n;e++)p.set(e,t,d[e])}}let j=Math.min(n,r+1);if(y<n&&(g[y]=u.get(y,y)),r<j&&(g[j-1]=0),v+1<j&&(d[v]=u.get(v,j-1)),d[j-1]=0,a){for(let t=y;t<c;t++){for(let e=0;e<r;e++)m.set(e,t,0);m.set(t,t,1)}for(let t=y-1;t>=0;t--)if(0!==g[t]){for(let e=t+1;e<c;e++){let n=0;for(let o=t;o<r;o++)n+=m.get(o,t)*m.get(o,e);n=-n/m.get(t,t);for(let o=t;o<r;o++)m.set(o,e,m.get(o,e)+n*m.get(o,t))}for(let e=t;e<r;e++)m.set(e,t,-m.get(e,t));m.set(t,t,1+m.get(t,t));for(let e=0;e<t-1;e++)m.set(e,t,0)}else{for(let e=0;e<r;e++)m.set(e,t,0);m.set(t,t,1)}}if(l)for(let t=n-1;t>=0;t--){if(t<v&&0!==d[t])for(let e=t+1;e<n;e++){let r=0;for(let o=t+1;o<n;o++)r+=p.get(o,t)*p.get(o,e);r=-r/p.get(t+1,t);for(let o=t+1;o<n;o++)p.set(o,e,p.get(o,e)+r*p.get(o,t))}for(let e=0;e<n;e++)p.set(e,t,0);p.set(t,t,1)}let x=j-1,_=Number.EPSILON;for(;j>0;){let t,e;for(t=j-2;t>=-1&&-1!==t;t--){const e=Number.MIN_VALUE+_*Math.abs(g[t]+Math.abs(g[t+1]));if(Math.abs(d[t])<=e||Number.isNaN(d[t])){d[t]=0;break}}if(t===j-2)e=4;else{let r;for(r=j-1;r>=t&&r!==t;r--){let e=(r!==j?Math.abs(d[r]):0)+(r!==t+1?Math.abs(d[r-1]):0);if(Math.abs(g[r])<=_*e){g[r]=0;break}}r===t?e=3:r===j-1?e=1:(e=2,t=r)}switch(t++,e){case 1:{let e=d[j-2];d[j-2]=0;for(let r=j-2;r>=t;r--){let o=Wn(g[r],e),s=g[r]/o,i=e/o;if(g[r]=o,r!==t&&(e=-i*d[r-1],d[r-1]=s*d[r-1]),l)for(let t=0;t<n;t++)o=s*p.get(t,r)+i*p.get(t,j-1),p.set(t,j-1,-i*p.get(t,r)+s*p.get(t,j-1)),p.set(t,r,o)}break}case 2:{let e=d[t-1];d[t-1]=0;for(let n=t;n<j;n++){let o=Wn(g[n],e),s=g[n]/o,i=e/o;if(g[n]=o,e=-i*d[n],d[n]=s*d[n],a)for(let e=0;e<r;e++)o=s*m.get(e,n)+i*m.get(e,t-1),m.set(e,t-1,-i*m.get(e,n)+s*m.get(e,t-1)),m.set(e,n,o)}break}case 3:{const e=Math.max(Math.abs(g[j-1]),Math.abs(g[j-2]),Math.abs(d[j-2]),Math.abs(g[t]),Math.abs(d[t])),o=g[j-1]/e,s=g[j-2]/e,i=d[j-2]/e,u=g[t]/e,h=d[t]/e,c=((s+o)*(s-o)+i*i)/2,f=o*i*(o*i);let w=0;0===c&&0===f||(w=c<0?0-Math.sqrt(c*c+f):Math.sqrt(c*c+f),w=f/(c+w));let b=(u+o)*(u-o)+w,y=u*h;for(let e=t;e<j-1;e++){let o=Wn(b,y);0===o&&(o=Number.MIN_VALUE);let s=b/o,i=y/o;if(e!==t&&(d[e-1]=o),b=s*g[e]+i*d[e],d[e]=s*d[e]-i*g[e],y=i*g[e+1],g[e+1]=s*g[e+1],l)for(let t=0;t<n;t++)o=s*p.get(t,e)+i*p.get(t,e+1),p.set(t,e+1,-i*p.get(t,e)+s*p.get(t,e+1)),p.set(t,e,o);if(o=Wn(b,y),0===o&&(o=Number.MIN_VALUE),s=b/o,i=y/o,g[e]=o,b=s*d[e]+i*g[e+1],g[e+1]=-i*d[e]+s*g[e+1],y=i*d[e+1],d[e+1]=s*d[e+1],a&&e<r-1)for(let t=0;t<r;t++)o=s*m.get(t,e)+i*m.get(t,e+1),m.set(t,e+1,-i*m.get(t,e)+s*m.get(t,e+1)),m.set(t,e,o)}d[j-2]=b;break}case 4:if(g[t]<=0&&(g[t]=g[t]<0?-g[t]:0,l))for(let e=0;e<=x;e++)p.set(e,t,-p.get(e,t));for(;t<x&&!(g[t]>=g[t+1]);){let e=g[t];if(g[t]=g[t+1],g[t+1]=e,l&&t<n-1)for(let r=0;r<n;r++)e=p.get(r,t+1),p.set(r,t+1,p.get(r,t)),p.set(r,t,e);if(a&&t<r-1)for(let n=0;n<r;n++)e=m.get(n,t+1),m.set(n,t+1,m.get(n,t)),m.set(n,t,e);t++}j--}}if(h){let t=p;p=m,m=t}this.m=r,this.n=n,this.s=g,this.U=m,this.V=p}solve(t){let e=t,r=this.threshold,n=this.s.length,o=Un.zeros(n,n);for(let t=0;t<n;t++)Math.abs(this.s[t])<=r?o.set(t,t,0):o.set(t,t,1/this.s[t]);let s=this.U,i=this.rightSingularVectors,u=i.mmul(o),a=i.rows,l=s.rows,h=Un.zeros(a,l);for(let t=0;t<a;t++)for(let e=0;e<l;e++){let r=0;for(let o=0;o<n;o++)r+=u.get(t,o)*s.get(e,o);h.set(t,e,r)}return h.mmul(e)}solveForDiagonal(t){return this.solve(Un.diag(t))}inverse(){let t=this.V,e=this.threshold,r=t.rows,n=t.columns,o=new Un(r,this.s.length);for(let s=0;s<r;s++)for(let r=0;r<n;r++)Math.abs(this.s[r])>e&&o.set(s,r,t.get(s,r)/this.s[r]);let s=this.U,i=s.rows,u=s.columns,a=new Un(r,i);for(let t=0;t<r;t++)for(let e=0;e<i;e++){let r=0;for(let n=0;n<u;n++)r+=o.get(t,n)*s.get(e,n);a.set(t,e,r)}return a}get condition(){return this.s[0]/this.s[Math.min(this.m,this.n)-1]}get norm2(){return this.s[0]}get rank(){let t=Math.max(this.m,this.n)*this.s[0]*Number.EPSILON,e=0,r=this.s;for(let n=0,o=r.length;n<o;n++)r[n]>t&&e++;return e}get diagonal(){return Array.from(this.s)}get threshold(){return Number.EPSILON/2*Math.max(this.m,this.n)*this.s[0]}get leftSingularVectors(){return this.U}get rightSingularVectors(){return this.V}get diagonalMatrix(){return Un.diag(this.s)}}class Yn{constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const{assumeSymmetric:r=!1}=e;if(!(t=Gn.checkMatrix(t)).isSquare())throw new Error("Matrix is not a square matrix");if(t.isEmpty())throw new Error("Matrix must be non-empty");let n,o,s=t.columns,i=new Un(s,s),u=new Float64Array(s),a=new Float64Array(s),l=t,h=!1;if(h=!!r||t.isSymmetric(),h){for(n=0;n<s;n++)for(o=0;o<s;o++)i.set(n,o,l.get(n,o));!function(t,e,r,n){let o,s,i,u,a,l,h,c;for(a=0;a<t;a++)r[a]=n.get(t-1,a);for(u=t-1;u>0;u--){for(c=0,i=0,l=0;l<u;l++)c+=Math.abs(r[l]);if(0===c)for(e[u]=r[u-1],a=0;a<u;a++)r[a]=n.get(u-1,a),n.set(u,a,0),n.set(a,u,0);else{for(l=0;l<u;l++)r[l]/=c,i+=r[l]*r[l];for(o=r[u-1],s=Math.sqrt(i),o>0&&(s=-s),e[u]=c*s,i-=o*s,r[u-1]=o-s,a=0;a<u;a++)e[a]=0;for(a=0;a<u;a++){for(o=r[a],n.set(a,u,o),s=e[a]+n.get(a,a)*o,l=a+1;l<=u-1;l++)s+=n.get(l,a)*r[l],e[l]+=n.get(l,a)*o;e[a]=s}for(o=0,a=0;a<u;a++)e[a]/=i,o+=e[a]*r[a];for(h=o/(i+i),a=0;a<u;a++)e[a]-=h*r[a];for(a=0;a<u;a++){for(o=r[a],s=e[a],l=a;l<=u-1;l++)n.set(l,a,n.get(l,a)-(o*e[l]+s*r[l]));r[a]=n.get(u-1,a),n.set(u,a,0)}}r[u]=i}for(u=0;u<t-1;u++){if(n.set(t-1,u,n.get(u,u)),n.set(u,u,1),i=r[u+1],0!==i){for(l=0;l<=u;l++)r[l]=n.get(l,u+1)/i;for(a=0;a<=u;a++){for(s=0,l=0;l<=u;l++)s+=n.get(l,u+1)*n.get(l,a);for(l=0;l<=u;l++)n.set(l,a,n.get(l,a)-s*r[l])}}for(l=0;l<=u;l++)n.set(l,u+1,0)}for(a=0;a<t;a++)r[a]=n.get(t-1,a),n.set(t-1,a,0);n.set(t-1,t-1,1),e[0]=0}(s,a,u,i),function(t,e,r,n){let o,s,i,u,a,l,h,c,f,g,m,p,d,w,b,y;for(i=1;i<t;i++)e[i-1]=e[i];e[t-1]=0;let v=0,M=0,j=Number.EPSILON;for(l=0;l<t;l++){for(M=Math.max(M,Math.abs(r[l])+Math.abs(e[l])),h=l;h<t&&!(Math.abs(e[h])<=j*M);)h++;if(h>l)do{for(o=r[l],c=(r[l+1]-o)/(2*e[l]),f=Wn(c,1),c<0&&(f=-f),r[l]=e[l]/(c+f),r[l+1]=e[l]*(c+f),g=r[l+1],s=o-r[l],i=l+2;i<t;i++)r[i]-=s;for(v+=s,c=r[h],m=1,p=m,d=m,w=e[l+1],b=0,y=0,i=h-1;i>=l;i--)for(d=p,p=m,y=b,o=m*e[i],s=m*c,f=Wn(c,e[i]),e[i+1]=b*f,b=e[i]/f,m=c/f,c=m*r[i]-b*o,r[i+1]=s+b*(m*o+b*r[i]),a=0;a<t;a++)s=n.get(a,i+1),n.set(a,i+1,b*n.get(a,i)+m*s),n.set(a,i,m*n.get(a,i)-b*s);c=-b*y*d*w*e[l]/g,e[l]=b*c,r[l]=m*c}while(Math.abs(e[l])>j*M);r[l]=r[l]+v,e[l]=0}for(i=0;i<t-1;i++){for(a=i,c=r[i],u=i+1;u<t;u++)r[u]<c&&(a=u,c=r[u]);if(a!==i)for(r[a]=r[i],r[i]=c,u=0;u<t;u++)c=n.get(u,i),n.set(u,i,n.get(u,a)),n.set(u,a,c)}}(s,a,u,i)}else{let t=new Un(s,s),e=new Float64Array(s);for(o=0;o<s;o++)for(n=0;n<s;n++)t.set(n,o,l.get(n,o));!function(t,e,r,n){let o,s,i,u,a,l,h,c=0,f=t-1;for(l=c+1;l<=f-1;l++){for(h=0,u=l;u<=f;u++)h+=Math.abs(e.get(u,l-1));if(0!==h){for(i=0,u=f;u>=l;u--)r[u]=e.get(u,l-1)/h,i+=r[u]*r[u];for(s=Math.sqrt(i),r[l]>0&&(s=-s),i-=r[l]*s,r[l]=r[l]-s,a=l;a<t;a++){for(o=0,u=f;u>=l;u--)o+=r[u]*e.get(u,a);for(o/=i,u=l;u<=f;u++)e.set(u,a,e.get(u,a)-o*r[u])}for(u=0;u<=f;u++){for(o=0,a=f;a>=l;a--)o+=r[a]*e.get(u,a);for(o/=i,a=l;a<=f;a++)e.set(u,a,e.get(u,a)-o*r[a])}r[l]=h*r[l],e.set(l,l-1,h*s)}}for(u=0;u<t;u++)for(a=0;a<t;a++)n.set(u,a,u===a?1:0);for(l=f-1;l>=c+1;l--)if(0!==e.get(l,l-1)){for(u=l+1;u<=f;u++)r[u]=e.get(u,l-1);for(a=l;a<=f;a++){for(s=0,u=l;u<=f;u++)s+=r[u]*n.get(u,a);for(s=s/r[l]/e.get(l,l-1),u=l;u<=f;u++)n.set(u,a,n.get(u,a)+s*r[u])}}}(s,t,e,i),function(t,e,r,n,o){let s,i,u,a,l,h,c,f,g,m,p,d,w,b,y,v=t-1,M=0,j=t-1,x=Number.EPSILON,_=0,E=0,S=0,O=0,A=0,C=0,R=0,I=0;for(s=0;s<t;s++)for((s<M||s>j)&&(r[s]=o.get(s,s),e[s]=0),i=Math.max(s-1,0);i<t;i++)E+=Math.abs(o.get(s,i));for(;v>=M;){for(a=v;a>M&&(C=Math.abs(o.get(a-1,a-1))+Math.abs(o.get(a,a)),0===C&&(C=E),!(Math.abs(o.get(a,a-1))<x*C));)a--;if(a===v)o.set(v,v,o.get(v,v)+_),r[v]=o.get(v,v),e[v]=0,v--,I=0;else if(a===v-1){if(c=o.get(v,v-1)*o.get(v-1,v),S=(o.get(v-1,v-1)-o.get(v,v))/2,O=S*S+c,R=Math.sqrt(Math.abs(O)),o.set(v,v,o.get(v,v)+_),o.set(v-1,v-1,o.get(v-1,v-1)+_),f=o.get(v,v),O>=0){for(R=S>=0?S+R:S-R,r[v-1]=f+R,r[v]=r[v-1],0!==R&&(r[v]=f-c/R),e[v-1]=0,e[v]=0,f=o.get(v,v-1),C=Math.abs(f)+Math.abs(R),S=f/C,O=R/C,A=Math.sqrt(S*S+O*O),S/=A,O/=A,i=v-1;i<t;i++)R=o.get(v-1,i),o.set(v-1,i,O*R+S*o.get(v,i)),o.set(v,i,O*o.get(v,i)-S*R);for(s=0;s<=v;s++)R=o.get(s,v-1),o.set(s,v-1,O*R+S*o.get(s,v)),o.set(s,v,O*o.get(s,v)-S*R);for(s=M;s<=j;s++)R=n.get(s,v-1),n.set(s,v-1,O*R+S*n.get(s,v)),n.set(s,v,O*n.get(s,v)-S*R)}else r[v-1]=f+S,r[v]=f+S,e[v-1]=R,e[v]=-R;v-=2,I=0}else{if(f=o.get(v,v),g=0,c=0,a<v&&(g=o.get(v-1,v-1),c=o.get(v,v-1)*o.get(v-1,v)),10===I){for(_+=f,s=M;s<=v;s++)o.set(s,s,o.get(s,s)-f);C=Math.abs(o.get(v,v-1))+Math.abs(o.get(v-1,v-2)),f=g=.75*C,c=-.4375*C*C}if(30===I&&(C=(g-f)/2,C=C*C+c,C>0)){for(C=Math.sqrt(C),g<f&&(C=-C),C=f-c/((g-f)/2+C),s=M;s<=v;s++)o.set(s,s,o.get(s,s)-C);_+=C,f=g=c=.964}for(I+=1,l=v-2;l>=a&&(R=o.get(l,l),A=f-R,C=g-R,S=(A*C-c)/o.get(l+1,l)+o.get(l,l+1),O=o.get(l+1,l+1)-R-A-C,A=o.get(l+2,l+1),C=Math.abs(S)+Math.abs(O)+Math.abs(A),S/=C,O/=C,A/=C,l!==a)&&!(Math.abs(o.get(l,l-1))*(Math.abs(O)+Math.abs(A))<x*(Math.abs(S)*(Math.abs(o.get(l-1,l-1))+Math.abs(R)+Math.abs(o.get(l+1,l+1)))));)l--;for(s=l+2;s<=v;s++)o.set(s,s-2,0),s>l+2&&o.set(s,s-3,0);for(u=l;u<=v-1&&(b=u!==v-1,u!==l&&(S=o.get(u,u-1),O=o.get(u+1,u-1),A=b?o.get(u+2,u-1):0,f=Math.abs(S)+Math.abs(O)+Math.abs(A),0!==f&&(S/=f,O/=f,A/=f)),0!==f);u++)if(C=Math.sqrt(S*S+O*O+A*A),S<0&&(C=-C),0!==C){for(u!==l?o.set(u,u-1,-C*f):a!==l&&o.set(u,u-1,-o.get(u,u-1)),S+=C,f=S/C,g=O/C,R=A/C,O/=S,A/=S,i=u;i<t;i++)S=o.get(u,i)+O*o.get(u+1,i),b&&(S+=A*o.get(u+2,i),o.set(u+2,i,o.get(u+2,i)-S*R)),o.set(u,i,o.get(u,i)-S*f),o.set(u+1,i,o.get(u+1,i)-S*g);for(s=0;s<=Math.min(v,u+3);s++)S=f*o.get(s,u)+g*o.get(s,u+1),b&&(S+=R*o.get(s,u+2),o.set(s,u+2,o.get(s,u+2)-S*A)),o.set(s,u,o.get(s,u)-S),o.set(s,u+1,o.get(s,u+1)-S*O);for(s=M;s<=j;s++)S=f*n.get(s,u)+g*n.get(s,u+1),b&&(S+=R*n.get(s,u+2),n.set(s,u+2,n.get(s,u+2)-S*A)),n.set(s,u,n.get(s,u)-S),n.set(s,u+1,n.get(s,u+1)-S*O)}}}if(0===E)return;for(v=t-1;v>=0;v--)if(S=r[v],O=e[v],0===O)for(a=v,o.set(v,v,1),s=v-1;s>=0;s--){for(c=o.get(s,s)-S,A=0,i=a;i<=v;i++)A+=o.get(s,i)*o.get(i,v);if(e[s]<0)R=c,C=A;else if(a=s,0===e[s]?o.set(s,v,0!==c?-A/c:-A/(x*E)):(f=o.get(s,s+1),g=o.get(s+1,s),O=(r[s]-S)*(r[s]-S)+e[s]*e[s],h=(f*C-R*A)/O,o.set(s,v,h),o.set(s+1,v,Math.abs(f)>Math.abs(R)?(-A-c*h)/f:(-C-g*h)/R)),h=Math.abs(o.get(s,v)),x*h*h>1)for(i=s;i<=v;i++)o.set(i,v,o.get(i,v)/h)}else if(O<0)for(a=v-1,Math.abs(o.get(v,v-1))>Math.abs(o.get(v-1,v))?(o.set(v-1,v-1,O/o.get(v,v-1)),o.set(v-1,v,-(o.get(v,v)-S)/o.get(v,v-1))):(y=Xn(0,-o.get(v-1,v),o.get(v-1,v-1)-S,O),o.set(v-1,v-1,y[0]),o.set(v-1,v,y[1])),o.set(v,v-1,0),o.set(v,v,1),s=v-2;s>=0;s--){for(m=0,p=0,i=a;i<=v;i++)m+=o.get(s,i)*o.get(i,v-1),p+=o.get(s,i)*o.get(i,v);if(c=o.get(s,s)-S,e[s]<0)R=c,A=m,C=p;else if(a=s,0===e[s]?(y=Xn(-m,-p,c,O),o.set(s,v-1,y[0]),o.set(s,v,y[1])):(f=o.get(s,s+1),g=o.get(s+1,s),d=(r[s]-S)*(r[s]-S)+e[s]*e[s]-O*O,w=2*(r[s]-S)*O,0===d&&0===w&&(d=x*E*(Math.abs(c)+Math.abs(O)+Math.abs(f)+Math.abs(g)+Math.abs(R))),y=Xn(f*A-R*m+O*p,f*C-R*p-O*m,d,w),o.set(s,v-1,y[0]),o.set(s,v,y[1]),Math.abs(f)>Math.abs(R)+Math.abs(O)?(o.set(s+1,v-1,(-m-c*o.get(s,v-1)+O*o.get(s,v))/f),o.set(s+1,v,(-p-c*o.get(s,v)-O*o.get(s,v-1))/f)):(y=Xn(-A-g*o.get(s,v-1),-C-g*o.get(s,v),R,O),o.set(s+1,v-1,y[0]),o.set(s+1,v,y[1]))),h=Math.max(Math.abs(o.get(s,v-1)),Math.abs(o.get(s,v))),x*h*h>1)for(i=s;i<=v;i++)o.set(i,v-1,o.get(i,v-1)/h),o.set(i,v,o.get(i,v)/h)}for(s=0;s<t;s++)if(s<M||s>j)for(i=s;i<t;i++)n.set(s,i,o.get(s,i));for(i=t-1;i>=M;i--)for(s=M;s<=j;s++){for(R=0,u=M;u<=Math.min(i,j);u++)R+=n.get(s,u)*o.get(u,i);n.set(s,i,R)}}(s,a,u,i,t)}this.n=s,this.e=a,this.d=u,this.V=i}get realEigenvalues(){return Array.from(this.d)}get imaginaryEigenvalues(){return Array.from(this.e)}get eigenvectorMatrix(){return this.V}get diagonalMatrix(){let t,e,r=this.n,n=this.e,o=this.d,s=new Un(r,r);for(t=0;t<r;t++){for(e=0;e<r;e++)s.set(t,e,0);s.set(t,t,o[t]),n[t]>0?s.set(t,t+1,n[t]):n[t]<0&&s.set(t,t-1,n[t])}return s}}function Xn(t,e,r,n){let o,s;return Math.abs(r)>Math.abs(n)?(o=n/r,s=r+o*n,[(t+o*e)/s,(e-o*t)/s]):(o=r/n,s=n+o*r,[(o*t+e)/s,(o*e-t)/s])}class Jn{constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};t=Gn.checkMatrix(t);let{Y:r}=e;const{scaleScores:n=!1,maxIterations:o=1e3,terminationCriteria:s=1e-10}=e;let i;if(r){if(r=En(r)&&"number"==typeof r[0]?Un.columnVector(r):Gn.checkMatrix(r),r.rows!==t.rows)throw new Error("Y should have the same number of rows as X");i=r.getColumnVector(0)}else i=t.getColumnVector(0);let u,a,l,h,c=1;for(let e=0;e<o&&c>s;e++)l=t.transpose().mmul(i).div(i.transpose().mmul(i).get(0,0)),l=l.div(l.norm()),u=t.mmul(l).div(l.transpose().mmul(l).get(0,0)),e>0&&(c=u.clone().sub(h).pow(2).sum()),h=u.clone(),r?(a=r.transpose().mmul(u).div(u.transpose().mmul(u).get(0,0)),a=a.div(a.norm()),i=r.mmul(a).div(a.transpose().mmul(a).get(0,0))):i=u;if(r){let e=t.transpose().mmul(u).div(u.transpose().mmul(u).get(0,0));e=e.div(e.norm());let n=t.clone().sub(u.clone().mmul(e.transpose())),o=i.transpose().mmul(u).div(u.transpose().mmul(u).get(0,0)),s=r.clone().sub(u.clone().mulS(o.get(0,0)).mmul(a.transpose()));this.t=u,this.p=e.transpose(),this.w=l.transpose(),this.q=a,this.u=i,this.s=u.transpose().mmul(u),this.xResidual=n,this.yResidual=s,this.betas=o}else this.w=l.transpose(),this.s=u.transpose().mmul(u).sqrt(),this.t=n?u.clone().div(this.s.get(0,0)):u,this.xResidual=t.sub(u.mmul(l.transpose()))}}let Zn=class t{constructor(t){let e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;if(this.U=null,this.S=null,n)return this.center=n.center,this.scale=n.scale,this.means=n.means,this.stdevs=n.stdevs,this.U=Un.checkMatrix(n.U),this.S=n.S,this.R=n.R,void(this.excludedFeatures=n.excludedFeatures||[]);e=(Array.isArray(t),new Un(t));const{isCovarianceMatrix:o=!1,method:s="SVD",nCompNIPALS:i=2,center:u=!0,scale:a=!1,ignoreZeroVariance:l=!1}=r;if(this.center=u,this.scale=a,this.means=null,this.stdevs=null,this.excludedFeatures=[],o)this._computeFromCovarianceMatrix(e);else switch(this._adjust(e,l),s){case"covarianceMatrix":{const t=new Bn(e).mmul(e).div(e.rows-1);this._computeFromCovarianceMatrix(t);break}case"NIPALS":this._computeWithNIPALS(e,i);break;case"SVD":{const t=new Kn(e,{computeLeftSingularVectors:!1,computeRightSingularVectors:!0,autoTranspose:!0});this.U=t.rightSingularVectors;const r=t.diagonal,n=[];for(const t of r)n.push(t*t/(e.rows-1));this.S=n;break}default:throw new Error(`unknown method: ${s}`)}}static load(e){if("string"!=typeof e.name)throw new TypeError("model must have a name property");if("PCA"!==e.name)throw new RangeError(`invalid model: ${e.name}`);return new t(void 0,void 0,e)}predict(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const{nComponents:r=this.U.columns}=e;let n;if(n=(Array.isArray(t),new Un(t)),this.center&&(n.subRowVector(this.means),this.scale)){for(let t of this.excludedFeatures)n.removeColumn(t);n.divRowVector(this.stdevs)}let o=n.mmul(this.U);return o.subMatrix(0,o.rows-1,0,r-1)}invert(t){let e=(t=Un.checkMatrix(t)).mmul(this.U.transpose());return this.center&&(this.scale&&e.mulRowVector(this.stdevs),e.addRowVector(this.means)),e}getExplainedVariance(){let t=0;if(this.S)for(const e of this.S)t+=e;return this.S?this.S.map((e=>e/t)):[]}getCumulativeVariance(){let t=this.getExplainedVariance();for(let e=1;e<t.length;e++)t[e]+=t[e-1];return t}getEigenvectors(){return this.U}getEigenvalues(){return this.S}getStandardDeviations(){return this.S.map((t=>Math.sqrt(t)))}getLoadings(){return this.U.transpose()}toJSON(){return{name:"PCA",center:this.center,scale:this.scale,means:this.means,stdevs:this.stdevs,U:this.U,S:this.S,excludedFeatures:this.excludedFeatures}}_adjust(t,e){if(this.center){const r=t.mean("column"),n=this.scale?t.standardDeviation("column",{mean:r}):null;if(this.means=r,t.subRowVector(r),this.scale){for(let r=0;r<n.length;r++)if(0===n[r]){if(!e)throw new RangeError(`Cannot scale the dataset (standard deviation is zero at index ${r}`);t.removeColumn(r),n.splice(r,1),this.excludedFeatures.push(r),r--}this.stdevs=n,t.divRowVector(n)}}}_computeFromCovarianceMatrix(t){const e=new Yn(t,{assumeSymmetric:!0});this.U=e.eigenvectorMatrix,this.U.flipRows(),this.S=e.realEigenvalues,this.S.reverse()}_computeWithNIPALS(t,e){this.U=new Un(e,t.columns),this.S=[];let r=t;for(let t=0;t<e;t++){let e=new Jn(r);this.U.setRow(t,e.w.transpose()),this.S.push(Math.pow(e.s.get(0,0),2)),r=e.xResidual}this.U=this.U.transpose()}};function Hn(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!Nr(t))throw new Error("data is not eff. array");let r=ve(e,"scale");Yr(r)||(r=!0);let n=ve(e,"nCompNIPALS");Jr(n)||(n=2),n=xn(n);let o=Sr(ve(t,0,[]));if(0===o)throw new Error("invalid dimension of data");if(n>o)throw new Error(`nCompNIPALS[${n}] is more than the dimension[${o}] of data`);return new Zn(t,{method:"NIPALS",scale:r,nCompNIPALS:n}).predict(t).toJSON()}var Qn={},to={get exports(){return Qn},set exports(t){Qn=t}};var eo=function(t,e){for(var r=-1,n=null==t?0:t.length;++r<n&&!1!==e(t[r],r,t););return t};var ro=function(t){return function(e,r,n){for(var o=-1,s=Object(e),i=n(e),u=i.length;u--;){var a=i[t?u:++o];if(!1===r(s[a],a,s))break}return e}},no=ro();var oo=function(t,e){for(var r=-1,n=Array(t);++r<t;)n[r]=e(r);return n},so=b,io=y;var uo=function(t){return io(t)&&"[object Arguments]"==so(t)},ao=y,lo=Object.prototype,ho=lo.hasOwnProperty,co=lo.propertyIsEnumerable,fo=uo(function(){return arguments}())?uo:function(t){return ao(t)&&ho.call(t,"callee")&&!co.call(t,"callee")},go=fo,mo={};var po=function(){return!1};!function(t,e){var r=i,n=po,o=e&&!e.nodeType&&e,s=o&&t&&!t.nodeType&&t,u=s&&s.exports===o?r.Buffer:void 0,a=(u?u.isBuffer:void 0)||n;t.exports=a}({get exports(){return mo},set exports(t){mo=t}},mo);var wo=/^(?:0|[1-9]\d*)$/;var bo=function(t,e){var r=typeof t;return!!(e=null==e?9007199254740991:e)&&("number"==r||"symbol"!=r&&wo.test(t))&&t>-1&&t%1==0&&t<e},yo=b,vo=Ye,Mo=y,jo={};jo["[object Float32Array]"]=jo["[object Float64Array]"]=jo["[object Int8Array]"]=jo["[object Int16Array]"]=jo["[object Int32Array]"]=jo["[object Uint8Array]"]=jo["[object Uint8ClampedArray]"]=jo["[object Uint16Array]"]=jo["[object Uint32Array]"]=!0,jo["[object Arguments]"]=jo["[object Array]"]=jo["[object ArrayBuffer]"]=jo["[object Boolean]"]=jo["[object DataView]"]=jo["[object Date]"]=jo["[object Error]"]=jo["[object Function]"]=jo["[object Map]"]=jo["[object Number]"]=jo["[object Object]"]=jo["[object RegExp]"]=jo["[object Set]"]=jo["[object String]"]=jo["[object WeakMap]"]=!1;var xo=function(t){return Mo(t)&&vo(t.length)&&!!jo[yo(t)]};var _o=function(t){return function(e){return t(e)}},Eo={};!function(t,e){var r=n,o=e&&!e.nodeType&&e,s=o&&t&&!t.nodeType&&t,i=s&&s.exports===o&&r.process,u=function(){try{var t=s&&s.require&&s.require("util").types;return t||i&&i.binding&&i.binding("util")}catch(t){}}();t.exports=u}({get exports(){return Eo},set exports(t){Eo=t}},Eo);var So=xo,Oo=_o,Ao=Eo&&Eo.isTypedArray,Co=Ao?Oo(Ao):So,Ro=oo,Io=go,No=r,ko=mo,Fo=bo,Po=Co,To=Object.prototype.hasOwnProperty;var zo=function(t,e){var r=No(t),n=!r&&Io(t),o=!r&&!n&&ko(t),s=!r&&!n&&!o&&Po(t),i=r||n||o||s,u=i?Ro(t.length,String):[],a=u.length;for(var l in t)!e&&!To.call(t,l)||i&&("length"==l||o&&("offset"==l||"parent"==l)||s&&("buffer"==l||"byteLength"==l||"byteOffset"==l)||Fo(l,a))||u.push(l);return u},Vo=Ae,$o=Ze;var qo=function(t){return $o(t)?zo(t):Vo(t)},Do=no,Uo=qo;var Lo=Ze;var Bo=function(t,e){return function(r,n){if(null==r)return r;if(!Lo(r))return t(r,n);for(var o=r.length,s=e?o:-1,i=Object(r);(e?s--:++s<o)&&!1!==n(i[s],s,i););return r}},Go=Bo((function(t,e){return t&&Do(t,e,Uo)}));var Wo=function(t){return t},Ko=Wo;var Yo=eo,Xo=Go,Jo=function(t){return"function"==typeof t?t:Ko},Zo=r;var Ho=function(t,e){return(Zo(t)?Yo:Xo)(t,Jo(e))};!function(t){t.exports=Ho}(to);var Qo=e(Qn),ts=Ct;var es=Ct,rs=Rt,ns=Kt;var os=Ct,ss=function(){this.__data__=new ts,this.size=0},is=function(t){var e=this.__data__,r=e.delete(t);return this.size=e.size,r},us=function(t){return this.__data__.get(t)},as=function(t){return this.__data__.has(t)},ls=function(t,e){var r=this.__data__;if(r instanceof es){var n=r.__data__;if(!rs||n.length<199)return n.push([t,e]),this.size=++r.size,this;r=this.__data__=new ns(n)}return r.set(t,e),this.size=r.size,this};function hs(t){var e=this.__data__=new os(t);this.size=e.size}hs.prototype.clear=ss,hs.prototype.delete=is,hs.prototype.get=us,hs.prototype.has=as,hs.prototype.set=ls;var cs=hs;var fs=Kt,gs=function(t){return this.__data__.set(t,"__lodash_hash_undefined__"),this},ms=function(t){return this.__data__.has(t)};function ps(t){var e=-1,r=null==t?0:t.length;for(this.__data__=new fs;++e<r;)this.add(t[e])}ps.prototype.add=ps.prototype.push=gs,ps.prototype.has=ms;var ds=ps,ws=function(t,e){for(var r=-1,n=null==t?0:t.length;++r<n;)if(e(t[r],r,t))return!0;return!1},bs=function(t,e){return t.has(e)};var ys=function(t,e,r,n,o,s){var i=1&r,u=t.length,a=e.length;if(u!=a&&!(i&&a>u))return!1;var l=s.get(t),h=s.get(e);if(l&&h)return l==e&&h==t;var c=-1,f=!0,g=2&r?new ds:void 0;for(s.set(t,e),s.set(e,t);++c<u;){var m=t[c],p=e[c];if(n)var d=i?n(p,m,c,e,t,s):n(m,p,c,t,e,s);if(void 0!==d){if(d)continue;f=!1;break}if(g){if(!ws(e,(function(t,e){if(!bs(g,e)&&(m===t||o(m,t,r,n,s)))return g.push(e)}))){f=!1;break}}else if(m!==p&&!o(m,p,r,n,s)){f=!1;break}}return s.delete(t),s.delete(e),f};var vs=function(t){var e=-1,r=Array(t.size);return t.forEach((function(t,n){r[++e]=[n,t]})),r};var Ms=i.Uint8Array,js=pt,xs=ys,_s=vs,Es=function(t){var e=-1,r=Array(t.size);return t.forEach((function(t){r[++e]=t})),r},Ss=u?u.prototype:void 0,Os=Ss?Ss.valueOf:void 0;var As=function(t,e,r,n,o,s,i){switch(r){case"[object DataView]":if(t.byteLength!=e.byteLength||t.byteOffset!=e.byteOffset)return!1;t=t.buffer,e=e.buffer;case"[object ArrayBuffer]":return!(t.byteLength!=e.byteLength||!s(new Ms(t),new Ms(e)));case"[object Boolean]":case"[object Date]":case"[object Number]":return js(+t,+e);case"[object Error]":return t.name==e.name&&t.message==e.message;case"[object RegExp]":case"[object String]":return t==e+"";case"[object Map]":var u=_s;case"[object Set]":var a=1&n;if(u||(u=Es),t.size!=e.size&&!a)return!1;var l=i.get(t);if(l)return l==e;n|=2,i.set(t,e);var h=xs(u(t),u(e),n,o,s,i);return i.delete(t),h;case"[object Symbol]":if(Os)return Os.call(t)==Os.call(e)}return!1};var Cs=function(t,e){for(var r=-1,n=e.length,o=t.length;++r<n;)t[o+r]=e[r];return t},Rs=Cs,Is=r;var Ns=function(t,e,r){var n=e(t);return Is(t)?n:Rs(n,r(t))};var ks=function(t,e){for(var r=-1,n=null==t?0:t.length,o=0,s=[];++r<n;){var i=t[r];e(i,r,t)&&(s[o++]=i)}return s},Fs=function(){return[]},Ps=Object.prototype.propertyIsEnumerable,Ts=Object.getOwnPropertySymbols,zs=Ns,Vs=Ts?function(t){return null==t?[]:(t=Object(t),ks(Ts(t),(function(e){return Ps.call(t,e)})))}:Fs,$s=qo;var qs=function(t){return zs(t,$s,Vs)},Ds=Object.prototype.hasOwnProperty;var Us=cs,Ls=ys,Bs=As,Gs=function(t,e,r,n,o,s){var i=1&r,u=qs(t),a=u.length;if(a!=qs(e).length&&!i)return!1;for(var l=a;l--;){var h=u[l];if(!(i?h in e:Ds.call(e,h)))return!1}var c=s.get(t),f=s.get(e);if(c&&f)return c==e&&f==t;var g=!0;s.set(t,e),s.set(e,t);for(var m=i;++l<a;){var p=t[h=u[l]],d=e[h];if(n)var w=i?n(d,p,h,e,t,s):n(p,d,h,t,e,s);if(!(void 0===w?p===d||o(p,d,r,n,s):w)){g=!1;break}m||(m="constructor"==h)}if(g&&!m){var b=t.constructor,y=e.constructor;b==y||!("constructor"in t)||!("constructor"in e)||"function"==typeof b&&b instanceof b&&"function"==typeof y&&y instanceof y||(g=!1)}return s.delete(t),s.delete(e),g},Ws=Ke,Ks=r,Ys=mo,Xs=Co,Js="[object Arguments]",Zs="[object Array]",Hs="[object Object]",Qs=Object.prototype.hasOwnProperty;var ti=function(t,e,r,n,o,s){var i=Ks(t),u=Ks(e),a=i?Zs:Ws(t),l=u?Zs:Ws(e),h=(a=a==Js?Hs:a)==Hs,c=(l=l==Js?Hs:l)==Hs,f=a==l;if(f&&Ys(t)){if(!Ys(e))return!1;i=!0,h=!1}if(f&&!h)return s||(s=new Us),i||Xs(t)?Ls(t,e,r,n,o,s):Bs(t,e,a,r,n,o,s);if(!(1&r)){var g=h&&Qs.call(t,"__wrapped__"),m=c&&Qs.call(e,"__wrapped__");if(g||m){var p=g?t.value():t,d=m?e.value():e;return s||(s=new Us),o(p,d,r,n,s)}}return!!f&&(s||(s=new Us),Gs(t,e,r,n,o,s))},ei=y;var ri=function t(e,r,n,o,s){return e===r||(null==e||null==r||!ei(e)&&!ei(r)?e!=e&&r!=r:ti(e,r,n,o,t,s))},ni=cs,oi=ri;var si=A;var ii=function(t){return t==t&&!si(t)},ui=ii,ai=qo;var li=function(t,e){return function(r){return null!=r&&(r[t]===e&&(void 0!==e||t in Object(r)))}},hi=function(t,e,r,n){var o=r.length,s=o,i=!n;if(null==t)return!s;for(t=Object(t);o--;){var u=r[o];if(i&&u[2]?u[1]!==t[u[0]]:!(u[0]in t))return!1}for(;++o<s;){var a=(u=r[o])[0],l=t[a],h=u[1];if(i&&u[2]){if(void 0===l&&!(a in t))return!1}else{var c=new ni;if(n)var f=n(l,h,a,t,e,c);if(!(void 0===f?oi(h,l,3,n,c):f))return!1}}return!0},ci=function(t){for(var e=ai(t),r=e.length;r--;){var n=e[r],o=t[n];e[r]=[n,o,ui(o)]}return e},fi=li;var gi=ge,mi=go,pi=r,di=bo,wi=Ye,bi=pe;var yi=function(t,e){return null!=t&&e in Object(t)},vi=function(t,e,r){for(var n=-1,o=(e=gi(e,t)).length,s=!1;++n<o;){var i=bi(e[n]);if(!(s=null!=t&&r(t,i)))break;t=t[i]}return s||++n!=o?s:!!(o=null==t?0:t.length)&&wi(o)&&di(i,o)&&(pi(t)||mi(t))};var Mi=ri,ji=ve,xi=function(t,e){return null!=t&&vi(t,e,yi)},_i=O,Ei=ii,Si=li,Oi=pe;var Ai=be;var Ci=rr,Ri=function(t){return function(e){return Ai(e,t)}},Ii=O,Ni=pe;var ki=function(t){var e=ci(t);return 1==e.length&&e[0][2]?fi(e[0][0],e[0][1]):function(r){return r===t||hi(r,t,e)}},Fi=function(t,e){return _i(t)&&Ei(e)?Si(Oi(t),e):function(r){var n=ji(r,t);return void 0===n&&n===e?xi(r,t):Mi(e,n,3)}},Pi=Wo,Ti=r,zi=function(t){return Ii(t)?Ci(Ni(t)):Ri(t)};var Vi=Go,$i=Ze;var qi=ee,Di=function(t){return"function"==typeof t?t:null==t?Pi:"object"==typeof t?Ti(t)?Fi(t[0],t[1]):ki(t):zi(t)},Ui=function(t,e){var r=-1,n=$i(t)?Array(t.length):[];return Vi(t,(function(t,o,s){n[++r]=e(t,o,s)})),n},Li=r;var Bi=function(t,e){return(Li(t)?qi:Ui)(t,Di(e))},Gi=ee;var Wi=function(t,e){return Gi(e,(function(e){return t[e]}))},Ki=qo;var Yi=function(t){return null==t?[]:Wi(t,Ki(t))};function Xi(t,e){for(var r=-1,n=null==t?0:t.length;++r<n&&!1!==e(t[r],r,t););return t}var Ji,Zi=function(t,e,r){for(var n=-1,o=Object(t),s=r(t),i=s.length;i--;){var u=s[Ji?i:++n];if(!1===e(o[u],u,o))break}return t};function Hi(t){return Wr(t)&&"[object Arguments]"==Gr(t)}var Qi=Object.prototype,tu=Qi.hasOwnProperty,eu=Qi.propertyIsEnumerable,ru=Hi(function(){return arguments}())?Hi:function(t){return Wr(t)&&tu.call(t,"callee")&&!eu.call(t,"callee")},nu=ru;var ou="object"==typeof exports&&exports&&!exports.nodeType&&exports,su=ou&&"object"==typeof module&&module&&!module.nodeType&&module,iu=su&&su.exports===ou?Pr.Buffer:void 0,uu=(iu?iu.isBuffer:void 0)||function(){return!1},au=9007199254740991,lu=/^(?:0|[1-9]\d*)$/;function hu(t,e){var r=typeof t;return!!(e=null==e?au:e)&&("number"==r||"symbol"!=r&&lu.test(t))&&t>-1&&t%1==0&&t<e}var cu=9007199254740991;function fu(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=cu}var gu={};gu["[object Float32Array]"]=gu["[object Float64Array]"]=gu["[object Int8Array]"]=gu["[object Int16Array]"]=gu["[object Int32Array]"]=gu["[object Uint8Array]"]=gu["[object Uint8ClampedArray]"]=gu["[object Uint16Array]"]=gu["[object Uint32Array]"]=!0,gu["[object Arguments]"]=gu["[object Array]"]=gu["[object ArrayBuffer]"]=gu["[object Boolean]"]=gu["[object DataView]"]=gu["[object Date]"]=gu["[object Error]"]=gu["[object Function]"]=gu["[object Map]"]=gu["[object Number]"]=gu["[object Object]"]=gu["[object RegExp]"]=gu["[object Set]"]=gu["[object String]"]=gu["[object WeakMap]"]=!1;var mu="object"==typeof exports&&exports&&!exports.nodeType&&exports,pu=mu&&"object"==typeof module&&module&&!module.nodeType&&module,du=pu&&pu.exports===mu&&kr.process,wu=function(){try{var t=pu&&pu.require&&pu.require("util").types;return t||du&&du.binding&&du.binding("util")}catch(t){}}(),bu=wu&&wu.isTypedArray,yu=bu?function(t){return function(e){return t(e)}}(bu):function(t){return Wr(t)&&fu(t.length)&&!!gu[Gr(t)]},vu=yu,Mu=Object.prototype.hasOwnProperty;function ju(t,e){var r=gn(t),n=!r&&nu(t),o=!r&&!n&&uu(t),s=!r&&!n&&!o&&vu(t),i=r||n||o||s,u=i?function(t,e){for(var r=-1,n=Array(t);++r<t;)n[r]=e(r);return n}(t.length,String):[],a=u.length;for(var l in t)!e&&!Mu.call(t,l)||i&&("length"==l||o&&("offset"==l||"parent"==l)||s&&("buffer"==l||"byteLength"==l||"byteOffset"==l)||hu(l,a))||u.push(l);return u}var xu=Object.prototype;var _u=function(t,e){return function(r){return t(e(r))}}(Object.keys,Object),Eu=_u,Su=Object.prototype.hasOwnProperty;function Ou(t){if(r=(e=t)&&e.constructor,e!==("function"==typeof r&&r.prototype||xu))return Eu(t);var e,r,n=[];for(var o in Object(t))Su.call(t,o)&&"constructor"!=o&&n.push(o);return n}var Au="[object AsyncFunction]",Cu="[object Function]",Ru="[object GeneratorFunction]",Iu="[object Proxy]";function Nu(t){if(!tn(t))return!1;var e=Gr(t);return e==Cu||e==Ru||e==Au||e==Iu}function ku(t){return null!=t&&fu(t.length)&&!Nu(t)}function Fu(t){return ku(t)?ju(t):Ou(t)}var Pu=function(t,e){return function(r,n){if(null==r)return r;if(!ku(r))return t(r,n);for(var o=r.length,s=e?o:-1,i=Object(r);(e?s--:++s<o)&&!1!==n(i[s],s,i););return r}}((function(t,e){return t&&Zi(t,e,Fu)})),Tu=Pu;function zu(t){return t}function Vu(t,e){var r;return(gn(t)?Xi:Tu)(t,"function"==typeof(r=e)?r:zu)}var $u=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,qu=/^\w*$/;var Du=Pr["__core-js_shared__"],Uu=function(){var t=/[^.]+$/.exec(Du&&Du.keys&&Du.keys.IE_PROTO||"");return t?"Symbol(src)_1."+t:""}();var Lu=Function.prototype.toString;var Bu=/^\[object .+?Constructor\]$/,Gu=Function.prototype,Wu=Object.prototype,Ku=Gu.toString,Yu=Wu.hasOwnProperty,Xu=RegExp("^"+Ku.call(Yu).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function Ju(t){return!(!tn(t)||function(t){return!!Uu&&Uu in t}(t))&&(Nu(t)?Xu:Bu).test(function(t){if(null!=t){try{return Lu.call(t)}catch(t){}try{return t+""}catch(t){}}return""}(t))}function Zu(t,e){var r=function(t,e){return null==t?void 0:t[e]}(t,e);return Ju(r)?r:void 0}var Hu=Zu(Object,"create");var Qu=Object.prototype.hasOwnProperty;var ta=Object.prototype.hasOwnProperty;function ea(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function ra(t,e){for(var r,n,o=t.length;o--;)if((r=t[o][0])===(n=e)||r!=r&&n!=n)return o;return-1}ea.prototype.clear=function(){this.__data__=Hu?Hu(null):{},this.size=0},ea.prototype.delete=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},ea.prototype.get=function(t){var e=this.__data__;if(Hu){var r=e[t];return"__lodash_hash_undefined__"===r?void 0:r}return Qu.call(e,t)?e[t]:void 0},ea.prototype.has=function(t){var e=this.__data__;return Hu?void 0!==e[t]:ta.call(e,t)},ea.prototype.set=function(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=Hu&&void 0===e?"__lodash_hash_undefined__":e,this};var na=Array.prototype.splice;function oa(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}oa.prototype.clear=function(){this.__data__=[],this.size=0},oa.prototype.delete=function(t){var e=this.__data__,r=ra(e,t);return!(r<0)&&(r==e.length-1?e.pop():na.call(e,r,1),--this.size,!0)},oa.prototype.get=function(t){var e=this.__data__,r=ra(e,t);return r<0?void 0:e[r][1]},oa.prototype.has=function(t){return ra(this.__data__,t)>-1},oa.prototype.set=function(t,e){var r=this.__data__,n=ra(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=e,this};var sa=Zu(Pr,"Map");function ia(t,e){var r,n,o=t.__data__;return("string"==(n=typeof(r=e))||"number"==n||"symbol"==n||"boolean"==n?"__proto__"!==r:null===r)?o["string"==typeof e?"string":"hash"]:o.map}function ua(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}ua.prototype.clear=function(){this.size=0,this.__data__={hash:new ea,map:new(sa||oa),string:new ea}},ua.prototype.delete=function(t){var e=ia(this,t).delete(t);return this.size-=e?1:0,e},ua.prototype.get=function(t){return ia(this,t).get(t)},ua.prototype.has=function(t){return ia(this,t).has(t)},ua.prototype.set=function(t,e){var r=ia(this,t),n=r.size;return r.set(t,e),this.size+=r.size==n?0:1,this};var aa="Expected a function";function la(t,e){if("function"!=typeof t||null!=e&&"function"!=typeof e)throw new TypeError(aa);var r=function(){var n=arguments,o=e?e.apply(this,n):n[0],s=r.cache;if(s.has(o))return s.get(o);var i=t.apply(this,n);return r.cache=s.set(o,i)||s,i};return r.cache=new(la.Cache||ua),r}la.Cache=ua;var ha=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,ca=/\\(\\)?/g,fa=function(t){var e=la(t,(function(t){return 500===r.size&&r.clear(),t})),r=e.cache;return e}((function(t){var e=[];return 46===t.charCodeAt(0)&&e.push(""),t.replace(ha,(function(t,r,n,o){e.push(n?o.replace(ca,"$1"):r||t)})),e})),ga=fa;function ma(t,e){return gn(t)?t:function(t,e){if(gn(t))return!1;var r=typeof t;return!("number"!=r&&"symbol"!=r&&"boolean"!=r&&null!=t&&!rn(t))||qu.test(t)||!$u.test(t)||null!=e&&t in Object(e)}(t,e)?[t]:ga(bn(t))}var pa=1/0;function da(t){if("string"==typeof t||rn(t))return t;var e=t+"";return"0"==e&&1/t==-pa?"-0":e}function wa(t,e,r){var n=null==t?void 0:function(t,e){for(var r=0,n=(e=ma(e,t)).length;null!=t&&r<n;)t=t[da(e[r++])];return r&&r==n?t:void 0}(t,e);return void 0===n?r:n}function ba(t,e){if(!Ar(t))return{};if(!Nr(e))return{};let r={};return Vu(e,(function(e){(function(t,e){return!!Ar(t)&&!(!Xr(e)&&!Jr(e))&&e in t})(t,e)&&(r[e]=wa(t,e))})),r}var ya=Array.prototype.join;var va=function(t,e){return null==t?"":ya.call(t,e)},Ma={},ja={};Object.defineProperty(ja,"__esModule",{value:!0});class xa{constructor(t){this.getCost=()=>this.Elements.map((t=>t.DistanceFromMedoid)).reduce(((t,e)=>t+e),0),this.findBestMedoidIdx=t=>this.Elements.map((e=>this.calcCostForGivenElementAsMedoid(e,t))).reduce(((t,e,r,n)=>e.CostIfMadeMedoid<n[t].CostIfMadeMedoid?r:t),0),this.calcCostForGivenElementAsMedoid=(t,e)=>({CostIfMadeMedoid:new xa({Elements:this.Elements.map((r=>({DistanceFromMedoid:e(r.Element,t.Element),Element:r.Element}))),Medoid:t.Element}).getCost(),Element:t}),this.Elements=t.Elements,this.Medoid=t.Medoid}}ja.Cluster=xa;var _a={},Ea={};Object.defineProperty(Ea,"__esModule",{value:!0}),Ea.distance=(t,e)=>{if(t.length!==e.length)throw new Error("the inputs must have the same dimension");const r=Array.from(t.keys()).map((r=>Math.pow(Math.abs(t[r]-e[r]),2))).reduce(((t,e)=>t+e),0);return Math.sqrt(r)};var Sa={};Object.defineProperty(Sa,"__esModule",{value:!0}),Sa.kGtElementArrLength="k must be less than the number of elements in the input array",Object.defineProperty(_a,"__esModule",{value:!0});const Oa=Ea,Aa=Sa,Ca=ja;class Ra{constructor(t,e,r){this.Elements=t,this.K=e,this.DistanceFn=r,this.OptimisationCompleted=!1,this.iterate=()=>{this.IterationCount++,this.Clusters||this.allocateToClustersAroundCurrentMedoids();const t=this.Medoids,e=this.Clusters,r=this.calculateCurrentCost();let n=r;for(let t=0;t<this.Medoids.length;t++){const e=t=>0===this.Medoids.filter((e=>0===this.DistanceFn(t,e))).length;for(const r of this.Elements.filter(e)){const e=this.Medoids.slice();e[t]=r;const o=new Ra(this.Elements.slice(),this.K,this.DistanceFn);o.Medoids=e,o.allocateToClustersAroundCurrentMedoids();const s=o.calculateCurrentCost();s<n&&(n=s,this.Clusters=o.Clusters,this.Medoids=e)}}return this.calculateCurrentCost()<r||(this.Clusters=e,this.Medoids=t,this.OptimisationCompleted=!0,!1)},this.getClusteredData=()=>(this.OptimisationCompleted||this.runToCompletion(),this.Clusters.map((t=>t.Elements.map((t=>t.Element))))),this.runToCompletion=()=>{for(;this.iterate(););},this.allocateToClustersAroundCurrentMedoids=()=>{this.Clusters=new Array,this.Medoids.forEach((t=>{this.Clusters.push(new Ca.Cluster({Elements:[],Medoid:t}))})),this.Elements.forEach(((t,e)=>{const r=this.findDistances(this.Clusters.map((t=>t.Medoid)),t),n=r.reduce(((t,e,r,n)=>e<n[t]?r:t),0);this.Clusters[n].Elements.push({DistanceFromMedoid:r[n],Element:t})}))},this.calculateCurrentCost=()=>this.Clusters.map((t=>t.getCost())).reduce(((t,e)=>t+e),0),this.findDistances=(t,e)=>t.map((t=>this.DistanceFn(t,e))),this.selectInitialMedoids=()=>{if(this.K>=this.Elements.length)throw Aa.kGtElementArrLength;const t=[],e=(t,e)=>{for(const r of e)if(0===this.DistanceFn(r,t))return!1;return!0};let r=0;for(;r<this.Elements.length&&t.length<this.K;)e(this.Elements[r],t)&&t.push(this.Elements[r]),r++;return t},this.DistanceFn=this.DistanceFn||Oa.distance,this.Medoids=this.selectInitialMedoids(),this.IterationCount=0}get OptimisationStarted(){return this.IterationCount>0}}Ra.clusterElements=(t,e,r)=>{Ra.getInstance(t,e,r);return new Array},Ra.getInstance=(t,e,r)=>new Ra(t,e,r),_a.Clusterer=Ra,function(t){function e(e){for(var r in e)t.hasOwnProperty(r)||(t[r]=e[r])}Object.defineProperty(t,"__esModule",{value:!0}),e(ja),e(_a)}(Ma);var Ia=e(Ma);function Na(t){return Na="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},Na(t)}function ka(t){var e=function(t,e){if("object"!==Na(t)||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e||"default");if("object"!==Na(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"===Na(e)?e:String(e)}function Fa(t,e,r){return(e=ka(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function Pa(t,e){let r=0;for(let n=0;n<t.length;n++)r+=(t[n]-e[n])*(t[n]-e[n]);return r}const Ta={distanceFunction:Pa};function za(t,e){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Ta;const n=r.distanceFunction||Ta.distanceFunction,o=r.similarityFunction||Ta.similarityFunction;let s=-1;if("function"==typeof o){let r=Number.MIN_VALUE;for(let n=0;n<t.length;n++){const i=o(e,t[n]);i>r&&(r=i,s=n)}}else{if("function"!=typeof n)throw new Error("A similarity or distance function it's required");{let r=Number.MAX_VALUE;for(let o=0;o<t.length;o++){const i=n(e,t[o]);i<r&&(r=i,s=o)}}}return s}function Va(t,e,r,n){for(let o=0;o<t.length;o++)r[o]=za(e,t[o],{distanceFunction:n});return r}class $a{constructor(t,e,r,n,o){this.clusters=t,this.centroids=e,this.converged=r,this.iterations=n,this.distance=o}nearest(t){const e=new Array(t.length);return Va(t,this.centroids,e,this.distance)}computeInformation(t){let e=this.centroids.map((t=>({centroid:t,error:0,size:0})));for(let r=0;r<t.length;r++)e[this.clusters[r]].error+=this.distance(t[r],this.centroids[this.clusters[r]]),e[this.clusters[r]].size++;for(let t=0;t<this.centroids.length;t++){let r=e[t].error;e[t].size&&-1!==r?r/=e[t].size:e[t].error=-1}return e}}function qa(t,e){const r=65535&(t>>>=0);return((t-r)*(e>>>=0)>>>0)+r*e>>>0}class Da{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Date.now();this.state=new Uint32Array(4),this.init(t),this.random=this.getFloat.bind(this)}getUint32(){return this.nextState(),this.state[3]+this.state[2]>>>0}getFloat(){return 5.960464477539063e-8*(this.getUint32()>>>8)}init(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(let t=1;t<8;t++)this.state[3&t]^=t+qa(1812433253,this.state[t-1&3]^this.state[t-1&3]>>>30>>>0)>>>0;this.periodCertification();for(let t=0;t<8;t++)this.nextState()}periodCertification(){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)}nextState(){let 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}}function Ua(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Math.random;const{size:n=1,replace:o=!1,probabilities:s}=e;let i,u;if(i="number"==typeof t?function(t){const e=[];for(let r=0;r<t;r++)e.push(r);return e}(t):t.slice(),s){if(!o)throw new Error("choice with probabilities and no replacement is not implemented");if(s.length!==i.length)throw new Error("the length of probabilities option should be equal to the number of choices");u=[s[0]];for(let t=1;t<s.length;t++)u[t]=u[t-1]+s[t];if(Math.abs(1-u[u.length-1])>1e-8)throw new Error(`probabilities should sum to 1, but instead sums to ${u[u.length-1]}`)}if(!1===o&&n>i.length)throw new Error("size option is too large");const a=[];for(let t=0;t<n;t++){const t=La(i.length,r,u);a.push(i[t]),o||i.splice(t,1)}return a}function La(t,e,r){const n=e();if(r){let t=0;for(;n>r[t];)t++;return t}return Math.floor(n*t)}class Ba{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Math.random;if("number"==typeof t){const e=new Da(t);this.randomGenerator=e.random}else this.randomGenerator=t}choice(t,e){return Ua(t,e,this.randomGenerator)}random(){return this.randomGenerator()}randInt(t,e){return void 0===e&&(e=t,t=0),t+Math.floor(this.randomGenerator()*(e-t))}randomSample(t){const e=[];for(let r=0;r<t;r++)e.push(this.random());return e}}function Ga(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function Wa(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?Ga(Object(r),!0).forEach((function(e){Fa(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):Ga(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function Ka(t,e){const r=new Un(t.rows,e.rows);for(let n=0;n<t.rows;n++)for(let o=0;o<e.rows;o++)r.set(n,o,Pa(t.getRow(n),e.getRow(o)));return r}function Ya(t){let e=[];for(let r=0;r<t;r++)e.push(r);return e}function Xa(t){let e=[t[0]];for(let r=1;r<t.length;r++)e[r]=e[r-1]+t[r];return e}function Ja(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function Za(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?Ja(Object(r),!0).forEach((function(e){Fa(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):Ja(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}const Ha={maxIterations:100,tolerance:1e-6,initialization:"kmeans++",distanceFunction:Pa};function Qa(t,e,r,n,o,s){let i=function(t,e,r,n){const o=e[0].length;let s=new Array(n),i=new Array(n);for(let t=0;t<n;t++){s[t]=new Array(o),i[t]=0;for(let e=0;e<o;e++)s[t][e]=0}for(let t=0;t<e.length;t++){i[r[t]]++;for(let n=0;n<o;n++)s[r[t]][n]+=e[t][n]}for(let e=0;e<n;e++)for(let r=0;r<o;r++)i[e]?s[e][r]/=i[e]:s[e][r]=t[e][r];return s}(t,e,r=Va(e,t,r,o.distanceFunction),n),u=function(t,e,r,n){for(let o=0;o<t.length;o++)if(r(t[o],e[o])>n)return!1;return!0}(i,t,o.distanceFunction,o.tolerance);return new $a(r,i,u,s,o.distanceFunction)}function tl(t,e,r){const n=function(t){return Za(Za({},Ha),t)}(r);!function(t,e){if(e<=0||e>t.length||!Number.isInteger(e))throw new Error("K should be a positive integer smaller than the number of points")}(t,e);let o=function(t,e,r){let n;if(Array.isArray(r.initialization)){if(r.initialization.length!==e)throw new Error("The initial centers should have the same length as K");n=r.initialization}else switch(r.initialization){case"kmeans++":n=function(t,e){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const n=new Un(t),o=n.rows,s=new Ba(r.seed),i=[],u=r.localTrials||2+Math.floor(Math.log(e)),a=s.randInt(o);i.push(n.getRow(a));let l=new Un(1,n.rows);for(let t=0;t<n.rows;t++)l.set(0,t,Pa(n.getRow(t),i[0]));let h=[Xa(l.getRow(0))];const c=1/h[0][o-1];let f=Un.mul(l,c);for(let t=1;t<e;t++){const e=s.choice(o,{replace:!0,size:u,probabilities:f.getRow(0)}),r=Ka(n.selection(e,Ya(n.columns)),n);let a=1/0,c=1/0,g=l;for(let t=0;t<u;t++){const n=Un.min(l,[r.getRow(t)]),o=n.sum();o<c&&(a=e[t],c=o,g=n)}i[t]=n.getRow(a),l=g,h=[Xa(l.getRow(0))],f=Un.mul(l,1/h[0][o-1])}return i}(t,e,r);break;case"random":n=function(t,e,r){return new Ba(r).choice(t,{size:e})}(t,e,r.seed);break;case"mostDistant":n=function(t,e,r,n){const o=new Ba(n);let s=new Array(e);if(s[0]=Math.floor(o.random()*t.length),e>1){let n={dist:-1,index:-1};for(let e=0;e<t.length;++e)r[s[0]][e]>n.dist&&(n.dist=r[s[0]][e],n.index=e);if(s[1]=n.index,e>2)for(let n=2;n<e;++n){let e={dist:-1,index:-1};for(let o=0;o<t.length;++o){let t={dist:Number.MAX_VALUE,index:-1};for(let e=0;e<n;++e)r[e][o]<t.dist&&!s.includes(o)&&(t={dist:r[e][o],index:o});t.dist!==Number.MAX_VALUE&&t.dist>e.dist&&(e=Wa({},t))}s[n]=e.index}}return s.map((e=>t[e]))}(t,e,function(t,e){let r=new Array(t.length);for(let n=0;n<t.length;++n)for(let o=n;o<t.length;++o){r[n]||(r[n]=new Array(t.length)),r[o]||(r[o]=new Array(t.length));const s=e(t[n],t[o]);r[n][o]=s,r[o][n]=s}return r}(t,r.distanceFunction),r.seed);break;default:!function(t,e){throw new Error(`${e}: "${String(t)}"`)}(r.initialization,"Unknown initialization method")}return n}(t,e,n);0===n.maxIterations&&(n.maxIterations=Number.MAX_VALUE);let s,i=new Array(t.length),u=!1,a=0;for(;!u&&a<n.maxIterations;)s=Qa(o,t,i,e,n,++a),u=s.converged,o=s.centroids;if(!s)throw new Error("unreachable: no kmeans step executed");return s}function el(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=ve(e,"kNumber");r=Jr(r)?xn(r):2;let n,o=ve(e,"mode");if("k-medoids"!==o&&"k-means"!==o&&(o="k-medoids"),"k-medoids"===o)n=function(t,e){let r={};function n(t){return va(t,":")}Qo(t,((t,e)=>{let o=n(t);r[o]=e}));let o=Ia.Clusterer.getInstance(t,e).getClusteredData();return o=Bi(o,(t=>Bi(t,(t=>{let e=n(t);return r[e]})))),o}(t,r);else{if("k-means"!==o)throw new Error(`invalid mode[${o}]`);n=function(t,e){let r=tl(t,e),n={};return Qo(r.clusters,((t,e)=>{n[t]||(n[t]=[]),n[t].push(e)})),Yi(n)}(t,r)}return n}function rl(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!Nr(t))throw new Error("data is not eff. array");let r=ve(e,"kNumber");Jr(r)||(r=2),r=xn(r);let n=ve(e,"nCompNIPALS");Jr(n)||(n=2),n=xn(n);let o=ve(e,"mode"),s="",i=Sr(t),u=0,a=0;if(Qo(t,(t=>{!function(t){if(Ar(t)){for(let e in t)return!0;return!1}return!1}(t)?Nr(t)&&(a+=1):u+=1})),u===i)s="obj";else{if(a!==i)throw new Error("data is not of the same type");s="mat"}let l,h=null;"obj"===s?(h=function(t){let e={};Qo(t,(t=>{Qo(t,((t,r)=>{e[r]||(e[r]=0),0===e[r]&&Jr(t)&&(e[r]=1),1!==e[r]||Jr(t)||(e[r]=-1)}))}));let r=[];return Qo(e,((t,e)=>{1===t&&r.push(e)})),r}(t),l=function(t,e){return Bi(t,(t=>{let r=ba(t,e);return Yi(r)}))}(t,h)):l=t;let c=Hn(l,{nCompNIPALS:n}),f=el(c,{kNumber:r,mode:o});return{keys:h,ginds:f,gmat:Bi(f,(t=>Bi(t,(t=>c[t])))),gltdt:Bi(f,(e=>Bi(e,(e=>t[e]))))}}let nl={PCA:async function(t){return Hn(t,arguments.length>1&&void 0!==arguments[1]?arguments[1]:{})},cluster:async function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};try{return rl(t,e)}catch(t){return Promise.reject(t)}}};return nl}));
|
|
7
|
+
//# sourceMappingURL=w-cluster.umd.js.map
|