w-cluster 1.0.15 → 1.0.17
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/.github/workflows/ci-test.yml +1 -1
- package/README.md +2 -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 +3 -3
- package/src/WClusterMat.mjs +1 -1
package/.eslintrc.js
CHANGED
package/README.md
CHANGED
|
@@ -278,9 +278,9 @@ testCluster()
|
|
|
278
278
|
```alias
|
|
279
279
|
|
|
280
280
|
<!-- for basic -->
|
|
281
|
-
<script src="https://cdn.jsdelivr.net/npm/w-cluster@1.0.
|
|
281
|
+
<script src="https://cdn.jsdelivr.net/npm/w-cluster@1.0.17/dist/w-cluster.umd.js"></script>
|
|
282
282
|
|
|
283
283
|
<!-- for web workers -->
|
|
284
|
-
<script src="https://cdn.jsdelivr.net/npm/w-cluster@1.0.
|
|
284
|
+
<script src="https://cdn.jsdelivr.net/npm/w-cluster@1.0.17/dist/w-cluster.wk.umd.js"></script>
|
|
285
285
|
|
|
286
286
|
```
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* w-cluster v1.0.17
|
|
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,o="object"==typeof t&&t&&t.Object===Object&&t,n=o,s="object"==typeof self&&self&&self.Object===Object&&self,i=n||s||Function("return this")(),u=i.Symbol,a=u,h=Object.prototype,l=h.hasOwnProperty,c=h.toString,f=a?a.toStringTag:void 0;var m=function(t){var e=l.call(t,f),r=t[f];try{t[f]=void 0;var o=!0}catch(t){}var n=c.call(t);return o&&(e?t[f]=r:delete t[f]),n},g=Object.prototype.toString;var p=m,w=function(t){return g.call(t)},d=u?u.toStringTag:void 0;var b=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":d&&d in Object(t)?p(t):w(t)};var y=function(t){return null!=t&&"object"==typeof t},v=b,M=y;var x=function(t){return"symbol"==typeof t||M(t)&&"[object Symbol]"==v(t)},E=r,S=x,j=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,_=/^\w*$/;var A=function(t,e){if(E(t))return!1;var r=typeof t;return!("number"!=r&&"symbol"!=r&&"boolean"!=r&&null!=t&&!S(t))||(_.test(t)||!j.test(t)||null!=e&&t in Object(e))};var O=function(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)},R=b,C=O;var I,N=function(t){if(!C(t))return!1;var e=R(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 T=function(t){return!!F&&F in t},P=Function.prototype.toString;var z=function(t){if(null!=t){try{return P.call(t)}catch(t){}try{return t+""}catch(t){}}return""},V=N,$=T,q=O,D=z,U=/^\[object .+?Constructor\]$/,L=Function.prototype,G=Object.prototype,B=L.toString,W=G.hasOwnProperty,K=RegExp("^"+B.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 ot=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},nt=Z,st=Object.prototype.hasOwnProperty;var it=Z;var ut=Q,at=tt,ht=ot,lt=function(t){var e=this.__data__;return nt?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 o=t[e];this.set(o[0],o[1])}}ft.prototype.clear=ut,ft.prototype.delete=at,ft.prototype.get=ht,ft.prototype.has=lt,ft.prototype.set=ct;var mt=ft;var gt=function(){this.__data__=[],this.size=0};var pt=function(t,e){return t===e||t!=t&&e!=e},wt=pt;var dt=function(t,e){for(var r=t.length;r--;)if(wt(t[r][0],e))return r;return-1},bt=dt,yt=Array.prototype.splice;var vt=dt;var Mt=dt;var xt=dt;var Et=gt,St=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)},jt=function(t){var e=this.__data__,r=vt(e,t);return r<0?void 0:e[r][1]},_t=function(t){return Mt(this.__data__,t)>-1},At=function(t,e){var r=this.__data__,o=xt(r,t);return o<0?(++this.size,r.push([t,e])):r[o][1]=e,this};function Ot(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var o=t[e];this.set(o[0],o[1])}}Ot.prototype.clear=Et,Ot.prototype.delete=St,Ot.prototype.get=jt,Ot.prototype.has=_t,Ot.prototype.set=At;var Rt=Ot,Ct=J(i,"Map"),It=mt,Nt=Rt,kt=Ct;var Ft=function(t){var e=typeof t;return"string"==e||"number"==e||"symbol"==e||"boolean"==e?"__proto__"!==t:null===t};var Tt=function(t,e){var r=t.__data__;return Ft(e)?r["string"==typeof e?"string":"hash"]:r.map},Pt=Tt;var zt=Tt;var Vt=Tt;var $t=Tt;var qt=function(t,e){var r=$t(this,t),o=r.size;return r.set(t,e),this.size+=r.size==o?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=Pt(this,t).delete(t);return this.size-=e?1:0,e},Lt=function(t){return zt(this,t).get(t)},Gt=function(t){return Vt(this,t).has(t)},Bt=qt;function Wt(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var o=t[e];this.set(o[0],o[1])}}Wt.prototype.clear=Dt,Wt.prototype.delete=Ut,Wt.prototype.get=Lt,Wt.prototype.has=Gt,Wt.prototype.set=Bt;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 o=arguments,n=e?e.apply(this,o):o[0],s=r.cache;if(s.has(n))return s.get(n);var i=t.apply(this,o);return r.cache=s.set(n,i)||s,i};return r.cache=new(Xt.Cache||Yt),r}Xt.Cache=Yt;var Jt=Xt;var Zt=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,Ht=/\\(\\)?/g,Qt=function(t){var e=Jt(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(Zt,(function(t,r,o,n){e.push(o?n.replace(Ht,"$1"):r||t)})),e}));var te=function(t,e){for(var r=-1,o=null==t?0:t.length,n=Array(o);++r<o;)n[r]=e(t[r],r,t);return n},ee=te,re=r,oe=x,ne=u?u.prototype:void 0,se=ne?ne.toString:void 0;var ie=function t(e){if("string"==typeof e)return e;if(re(e))return ee(e,t)+"";if(oe(e))return se?se.call(e):"";var r=e+"";return"0"==r&&1/e==-Infinity?"-0":r},ue=ie;var ae=function(t){return null==t?"":ue(t)},he=r,le=A,ce=Qt,fe=ae;var me=function(t,e){return he(t)?t:le(t,e)?[t]:ce(fe(t))},ge=x;var pe=function(t){if("string"==typeof t||ge(t))return t;var e=t+"";return"0"==e&&1/t==-Infinity?"-0":e},we=me,de=pe;var be=function(t,e){for(var r=0,o=(e=we(e,t)).length;null!=t&&r<o;)t=t[de(e[r++])];return r&&r==o?t:void 0},ye=be;var ve=function(t,e,r){var o=null==t?void 0:ye(t,e);return void 0===o?r:o},Me=Object.prototype;var xe=function(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||Me)};var Ee=function(t,e){return function(r){return t(e(r))}}(Object.keys,Object),Se=xe,je=Ee,_e=Object.prototype.hasOwnProperty;var Ae=function(t){if(!Se(t))return je(t);var e=[];for(var r in Object(t))_e.call(t,r)&&"constructor"!=r&&e.push(r);return e},Oe=J(i,"DataView"),Re=Ct,Ce=J(i,"Promise"),Ie=J(i,"Set"),Ne=J(i,"WeakMap"),ke=b,Fe=z,Te="[object Map]",Pe="[object Promise]",ze="[object Set]",Ve="[object WeakMap]",$e="[object DataView]",qe=Fe(Oe),De=Fe(Re),Ue=Fe(Ce),Le=Fe(Ie),Ge=Fe(Ne),Be=ke;(Oe&&Be(new Oe(new ArrayBuffer(1)))!=$e||Re&&Be(new Re)!=Te||Ce&&Be(Ce.resolve())!=Pe||Ie&&Be(new Ie)!=ze||Ne&&Be(new Ne)!=Ve)&&(Be=function(t){var e=ke(t),r="[object Object]"==e?t.constructor:void 0,o=r?Fe(r):"";if(o)switch(o){case qe:return $e;case De:return Te;case Ue:return Pe;case Le:return ze;case Ge:return Ve}return e});var We=Be;var Ke=function(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=9007199254740991},Ye=N,Xe=Ke;var Je=function(t){return null!=t&&Xe(t.length)&&!Ye(t)},Ze=b,He=r,Qe=y;var tr=function(t){return"string"==typeof t||!He(t)&&Qe(t)&&"[object String]"==Ze(t)};var er=function(t){return function(e){return null==e?void 0:e[t]}},rr=er("length"),or=RegExp("[\\u200d\\ud800-\\udfff\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff\\ufe0e\\ufe0f]");var nr=function(t){return or.test(t)},sr="\\ud800-\\udfff",ir="["+sr+"]",ur="[\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff]",ar="\\ud83c[\\udffb-\\udfff]",hr="[^"+sr+"]",lr="(?:\\ud83c[\\udde6-\\uddff]){2}",cr="[\\ud800-\\udbff][\\udc00-\\udfff]",fr="(?:"+ur+"|"+ar+")"+"?",mr="[\\ufe0e\\ufe0f]?",gr=mr+fr+("(?:\\u200d(?:"+[hr,lr,cr].join("|")+")"+mr+fr+")*"),pr="(?:"+[hr+ur+"?",ur,lr,cr,ir].join("|")+")",wr=RegExp(ar+"(?="+ar+")|"+pr+gr,"g");var dr=rr,br=nr,yr=function(t){for(var e=wr.lastIndex=0;wr.test(t);)++e;return e};var vr=Ae,Mr=We,xr=Je,Er=tr,Sr=function(t){return br(t)?yr(t):dr(t)};var jr=function(t){if(null==t)return 0;if(xr(t))return Er(t)?Sr(t):t.length;var e=Mr(t);return"[object Map]"==e||"[object Set]"==e?t.size:vr(t).length};function _r(t){return"[object Array]"===Object.prototype.toString.call(t)}function Ar(t){return"[object Object]"===Object.prototype.toString.call(t)}function Or(t){return"[object String]"===Object.prototype.toString.call(t)}function Rr(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!(!Or(t)||""!==t)}(t)||!!function(t){return!!_r(t)&&0===t.length}(t))))}function Cr(t){return!!_r(t)&&(0!==t.length&&(1!==t.length||!Rr(t[0])))}var Ir=b,Nr=y;var kr=function(t){return!0===t||!1===t||Nr(t)&&"[object Boolean]"==Ir(t)};function Fr(t){return!(!Or(t)||""===t)}function Tr(t){let e=!1;return Fr(t)?e=!isNaN(Number(t)):function(t){return"[object Number]"===Object.prototype.toString.call(t)}(t)&&(e=!0),e}var Pr=/\s/;var zr=function(t){for(var e=t.length;e--&&Pr.test(t.charAt(e)););return e},Vr=/^\s+/;var $r=function(t){return t?t.slice(0,zr(t)+1).replace(Vr,""):t},qr=O,Dr=x,Ur=/^[-+]0x[0-9a-f]+$/i,Lr=/^0b[01]+$/i,Gr=/^0o[0-7]+$/i,Br=parseInt;var Wr=function(t){if("number"==typeof t)return t;if(Dr(t))return NaN;if(qr(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=qr(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=$r(t);var r=Lr.test(t);return r||Gr.test(t)?Br(t.slice(2),r?2:8):Ur.test(t)?NaN:+t},Kr=Wr,Yr=1/0;var Xr=function(t){return t?(t=Kr(t))===Yr||t===-1/0?17976931348623157e292*(t<0?-1:1):t==t?t:0:0===t?t:0},Jr=Xr;var Zr=function(t){var e=Jr(t),r=e%1;return e==e?r?e-r:e:0},Hr=Wr,Qr=ae,to=i.isFinite,eo=Math.min;var ro=function(t){var e=Math[t];return function(t,r){if(t=Hr(t),(r=null==r?0:eo(Zr(r),292))&&to(t)){var o=(Qr(t)+"e").split("e"),n=e(o[0]+"e"+(+o[1]+r));return+((o=(Qr(n)+"e").split("e"))[0]+"e"+(+o[1]-r))}return e(t)}}("round");function oo(t){if(!Tr(t))return 0;t=function(t){return Tr(t)?Xr(t):0}(t);let e=ro(t);return"0"===String(e)?0:e}const no=Object.prototype.toString;function so(t){return no.call(t).endsWith("Array]")}function io(t){var e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!so(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(!so(r.output))throw new TypeError("output option must be an array if specified");e=r.output}else e=new Array(t.length);var o=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!so(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,o=void 0===r?0:r,n=e.toIndex,s=void 0===n?t.length:n;if(o<0||o>=t.length||!Number.isInteger(o))throw new Error("fromIndex must be a positive integer smaller than length");if(s<=o||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[o],u=o+1;u<s;u++)t[u]<i&&(i=t[u]);return i}(t),n=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!so(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,o=void 0===r?0:r,n=e.toIndex,s=void 0===n?t.length:n;if(o<0||o>=t.length||!Number.isInteger(o))throw new Error("fromIndex must be a positive integer smaller than length");if(s<=o||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[o],u=o+1;u<s;u++)t[u]>i&&(i=t[u]);return i}(t);if(o===n)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?o:0:s,u=r.max,a=void 0===u?r.autoMinMax?n:1:u;if(i>=a)throw new RangeError("min option must be smaller than max option");for(var h=(a-i)/(n-o),l=0;l<t.length;l++)e[l]=(t[l]-o)*h+i;return e}const uo=" ".repeat(2),ao=" ".repeat(4);function ho(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const{maxRows:r=15,maxColumns:o=10,maxNumSize:n=8,padMinus:s="auto"}=e;return`${t.constructor.name} {\n${uo}[\n${ao}${function(t,e,r,o,n){const{rows:s,columns:i}=t,u=Math.min(s,e),a=Math.min(i,r),h=[];if("auto"===n){n=!1;t:for(let e=0;e<u;e++)for(let r=0;r<a;r++)if(t.get(e,r)<0){n=!0;break t}}for(let e=0;e<u;e++){let r=[];for(let s=0;s<a;s++)r.push(lo(t.get(e,s),o,n));h.push(`${r.join(" ")}`)}a!==i&&(h[h.length-1]+=` ... ${i-r} more columns`);u!==s&&h.push(`... ${s-e} more rows`);return h.join(`\n${ao}`)}(t,r,o,n,s)}\n${uo}]\n${uo}rows: ${t.rows}\n${uo}columns: ${t.columns}\n}`}function lo(t,e,r){return(t>=0&&r?` ${co(t,e-1)}`:co(t,e)).padEnd(e)}function co(t,e){let r=t.toString();if(r.length<=e)return r;let o=t.toFixed(e);if(o.length>e&&(o=t.toFixed(Math.max(0,e-(o.length-e)))),o.length<=e&&!o.startsWith("0.000")&&!o.startsWith("-0.000"))return o;let n=t.toExponential(e);return n.length>e&&(n=t.toExponential(Math.max(0,e-(n.length-e)))),n.slice(0)}function fo(t,e,r){let o=r?t.rows:t.rows-1;if(e<0||e>o)throw new RangeError("Row index out of range")}function mo(t,e,r){let o=r?t.columns:t.columns-1;if(e<0||e>o)throw new RangeError("Column index out of range")}function go(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 po(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 wo(t,e,r,o,n){if(5!==arguments.length)throw new RangeError("expected 4 arguments");if(yo("startRow",e),yo("endRow",r),yo("startColumn",o),yo("endColumn",n),e>r||o>n||e<0||e>=t.rows||r<0||r>=t.rows||o<0||o>=t.columns||n<0||n>=t.columns)throw new RangeError("Submatrix indices are out of range")}function bo(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=[];for(let o=0;o<t;o++)r.push(e);return r}function yo(t,e){if("number"!=typeof e)throw new TypeError(`${t} must be a number`)}function vo(t){if(t.isEmpty())throw new Error("Empty matrix has no elements to index")}class Mo{static from1DArray(t,e,r){if(t*e!==r.length)throw new RangeError("data length does not match given dimensions");let o=new Eo(t,e);for(let n=0;n<t;n++)for(let t=0;t<e;t++)o.set(n,t,r[n*e+t]);return o}static rowVector(t){let e=new Eo(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 Eo(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 Eo(t,e)}static ones(t,e){return new Eo(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:o=Math.random}=r;let n=new Eo(t,e);for(let r=0;r<t;r++)for(let t=0;t<e;t++)n.set(r,t,o());return n}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:o=0,max:n=1e3,random:s=Math.random}=r;if(!Number.isInteger(o))throw new TypeError("min must be an integer");if(!Number.isInteger(n))throw new TypeError("max must be an integer");if(o>=n)throw new RangeError("min must be smaller than max");let i=n-o,u=new Eo(t,e);for(let r=0;r<t;r++)for(let t=0;t<e;t++){let e=o+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 o=Math.min(t,e),n=this.zeros(t,e);for(let t=0;t<o;t++)n.set(t,t,r);return n}static diag(t,e,r){let o=t.length;void 0===e&&(e=o),void 0===r&&(r=e);let n=Math.min(o,e,r),s=this.zeros(e,r);for(let e=0;e<n;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,o=t.columns,n=new Eo(r,o);for(let s=0;s<r;s++)for(let r=0;r<o;r++)n.set(s,r,Math.min(t.get(s,r),e.get(s,r)));return n}static max(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,o=t.columns,n=new this(r,o);for(let s=0;s<r;s++)for(let r=0;r<o;r++)n.set(s,r,Math.max(t.get(s,r),e.get(s,r)));return n}static checkMatrix(t){return Mo.isMatrix(t)?t:new Eo(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,o=!0,n=!1;for(;t<this.rows&&o;){for(e=0,n=!1;e<this.columns&&!1===n;)0===this.get(t,e)?e++:1===this.get(t,e)&&e>r?(n=!0,r=e):(o=!1,n=!0);t++}return o}isReducedEchelonForm(){let t=0,e=0,r=-1,o=!0,n=!1;for(;t<this.rows&&o;){for(e=0,n=!1;e<this.columns&&!1===n;)0===this.get(t,e)?e++:1===this.get(t,e)&&e>r?(n=!0,r=e):(o=!1,n=!0);for(let r=e+1;r<this.rows;r++)0!==this.get(t,r)&&(o=!1);t++}return o}echelonForm(){let t=this.clone(),e=0,r=0;for(;e<t.rows&&r<t.columns;){let o=e;for(let n=e;n<t.rows;n++)t.get(n,r)>t.get(o,r)&&(o=n);if(0===t.get(o,r))r++;else{t.swapRows(e,o);let n=t.get(e,r);for(let o=r;o<t.columns;o++)t.set(e,o,t.get(e,o)/n);for(let o=e+1;o<t.rows;o++){let n=t.get(o,r)/t.get(e,r);t.set(o,r,0);for(let s=r+1;s<t.columns;s++)t.set(o,s,t.get(o,s)-t.get(e,s)*n)}e++,r++}}return t}reducedEchelonForm(){let t=this.echelonForm(),e=t.columns,r=t.rows,o=r-1;for(;o>=0;)if(0===t.maxRow(o))o--;else{let n=0,s=!1;for(;n<r&&!1===s;)1===t.get(o,n)?s=!0:n++;for(let r=0;r<o;r++){let s=t.get(r,n);for(let i=n;i<e;i++){let e=t.get(r,i)-s*t.get(o,i);t.set(r,i,e)}}o--}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 o=new Eo(this.rows*e,this.columns*r);for(let t=0;t<e;t++)for(let e=0;e<r;e++)o.setSubMatrix(this,this.rows*t,this.columns*e);return o}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){fo(this,t);let e=[];for(let r=0;r<this.columns;r++)e.push(this.get(t,r));return e}getRowVector(t){return Eo.rowVector(this.getRow(t))}setRow(t,e){fo(this,t),e=go(this,e);for(let r=0;r<this.columns;r++)this.set(t,r,e[r]);return this}swapRows(t,e){fo(this,t),fo(this,e);for(let r=0;r<this.columns;r++){let o=this.get(t,r);this.set(t,r,this.get(e,r)),this.set(e,r,o)}return this}getColumn(t){mo(this,t);let e=[];for(let r=0;r<this.rows;r++)e.push(this.get(r,t));return e}getColumnVector(t){return Eo.columnVector(this.getColumn(t))}setColumn(t,e){mo(this,t),e=po(this,e);for(let r=0;r<this.rows;r++)this.set(r,t,e[r]);return this}swapColumns(t,e){mo(this,t),mo(this,e);for(let r=0;r<this.rows;r++){let o=this.get(r,t);this.set(r,t,this.get(r,e)),this.set(r,e,o)}return this}addRowVector(t){t=go(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=go(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=go(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=go(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=po(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=po(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=po(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=po(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){fo(this,t);for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)*e);return this}mulColumn(t,e){mo(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(){vo(this);let t=this.get(0,0),e=[0,0];for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.get(r,o)>t&&(t=this.get(r,o),e[0]=r,e[1]=o);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(){vo(this);let t=this.get(0,0),e=[0,0];for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.get(r,o)<t&&(t=this.get(r,o),e[0]=r,e[1]=o);return e}maxRow(t){if(fo(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){fo(this,t),vo(this);let e=this.get(t,0),r=[t,0];for(let o=1;o<this.columns;o++)this.get(t,o)>e&&(e=this.get(t,o),r[1]=o);return r}minRow(t){if(fo(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){fo(this,t),vo(this);let e=this.get(t,0),r=[t,0];for(let o=1;o<this.columns;o++)this.get(t,o)<e&&(e=this.get(t,o),r[1]=o);return r}maxColumn(t){if(mo(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){mo(this,t),vo(this);let e=this.get(0,t),r=[0,t];for(let o=1;o<this.rows;o++)this.get(o,t)>e&&(e=this.get(o,t),r[0]=o);return r}minColumn(t){if(mo(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){mo(this,t),vo(this);let e=this.get(0,t),r=[0,t];for(let o=1;o<this.rows;o++)this.get(o,t)<e&&(e=this.get(o,t),r[0]=o);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){Mo.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 o=0;o<e.length;o++)r+=e[o]*t[o];return r}mmul(t){t=Eo.checkMatrix(t);let e=this.rows,r=this.columns,o=t.columns,n=new Eo(e,o),s=new Float64Array(r);for(let i=0;i<o;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 o=0;o<r;o++)e+=this.get(t,o)*s[o];n.set(t,i,e)}}return n}strassen2x2(t){t=Eo.checkMatrix(t);let e=new Eo(2,2);const r=this.get(0,0),o=t.get(0,0),n=this.get(0,1),s=t.get(0,1),i=this.get(1,0),u=t.get(1,0),a=this.get(1,1),h=t.get(1,1),l=(r+a)*(o+h),c=(i+a)*o,f=r*(s-h),m=a*(u-o),g=(r+n)*h,p=l+m-g+(n-a)*(u+h),w=f+g,d=c+m,b=l-c+f+(i-r)*(o+s);return e.set(0,0,p),e.set(0,1,w),e.set(1,0,d),e.set(1,1,b),e}strassen3x3(t){t=Eo.checkMatrix(t);let e=new Eo(3,3);const r=this.get(0,0),o=this.get(0,1),n=this.get(0,2),s=this.get(1,0),i=this.get(1,1),u=this.get(1,2),a=this.get(2,0),h=this.get(2,1),l=this.get(2,2),c=t.get(0,0),f=t.get(0,1),m=t.get(0,2),g=t.get(1,0),p=t.get(1,1),w=t.get(1,2),d=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),x=(s+i)*(-c+f),E=r*c,S=(-r+a+h)*(c-m+w),j=(-r+a)*(m-w),_=(a+h)*(-c+m),A=(-n+h+l)*(p+d-b),O=(n-l)*(p-b),R=n*d,C=(h+l)*(-d+b),I=(-n+i+u)*(w+d-y),N=(n-u)*(w-y),k=(i+u)*(-d+y),F=E+R+o*g,T=(r+o+n-s-i-h-l)*p+M+x+E+A+R+C,P=E+S+_+(r+o+n-i-u-a-h)*w+R+I+k,z=v+i*(-c+f+g-p-w-d+y)+M+E+R+I+N,V=v+M+x+E+u*b,$=R+I+N+k+s*m,q=E+S+j+h*(-c+m+g-p-w-d+b)+A+O+R,D=A+O+R+C+a*f,U=E+S+j+_+l*y;return e.set(0,0,F),e.set(0,1,T),e.set(0,2,P),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=Eo.checkMatrix(t);let e=this.clone(),r=e.rows,o=e.columns,n=t.rows,s=t.columns;function i(t,e,r){let o=t.rows,n=t.columns;if(o===e&&n===r)return t;{let o=Mo.zeros(e,r);return o=o.setSubMatrix(t,0,0),o}}o!==n&&console.warn(`Multiplying ${r} x ${o} and ${n} x ${s} matrix: dimensions do not match.`);let u=Math.max(r,n),a=Math.max(o,s);return e=i(e,u,a),function t(e,r,o,n){if(o<=512||n<=512)return e.mmul(r);o%2==1&&n%2==1?(e=i(e,o+1,n+1),r=i(r,o+1,n+1)):o%2==1?(e=i(e,o+1,n),r=i(r,o+1,n)):n%2==1&&(e=i(e,o,n+1),r=i(r,o,n+1));let s=parseInt(e.rows/2,10),u=parseInt(e.columns/2,10),a=e.subMatrix(0,s-1,0,u-1),h=r.subMatrix(0,s-1,0,u-1),l=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),m=r.subMatrix(s,r.rows-1,0,u-1),g=e.subMatrix(s,e.rows-1,u,e.columns-1),p=r.subMatrix(s,r.rows-1,u,r.columns-1),w=t(Mo.add(a,g),Mo.add(h,p),s,u),d=t(Mo.add(f,g),h,s,u),b=t(a,Mo.sub(c,p),s,u),y=t(g,Mo.sub(m,h),s,u),v=t(Mo.add(a,l),p,s,u),M=t(Mo.sub(f,a),Mo.add(h,c),s,u),x=t(Mo.sub(l,g),Mo.add(m,p),s,u),E=Mo.add(w,y);E.sub(v),E.add(x);let S=Mo.add(b,v),j=Mo.add(d,y),_=Mo.sub(w,d);_.add(b),_.add(M);let A=Mo.zeros(2*E.rows,2*E.columns);return A=A.setSubMatrix(E,0,0),A=A.setSubMatrix(S,E.rows,0),A=A.setSubMatrix(j,0,E.columns),A=A.setSubMatrix(_,E.rows,E.columns),A.subMatrix(0,o-1,0,n-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 o=new Eo(this.rows,this.columns);for(let t=0;t<this.rows;t++){const n=this.getRow(t);n.length>0&&io(n,{min:e,max:r,output:n}),o.setRow(t,n)}return o}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 o=new Eo(this.rows,this.columns);for(let t=0;t<this.columns;t++){const n=this.getColumn(t);n.length&&io(n,{min:e,max:r,output:n}),o.setColumn(t,n)}return o}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),o=this.get(e,this.columns-1-r);this.set(e,r,o),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),o=this.get(this.rows-1-r,e);this.set(r,e,o),this.set(this.rows-1-r,e,t)}return this}kroneckerProduct(t){t=Eo.checkMatrix(t);let e=this.rows,r=this.columns,o=t.rows,n=t.columns,s=new Eo(e*o,r*n);for(let i=0;i<e;i++)for(let e=0;e<r;e++)for(let r=0;r<o;r++)for(let u=0;u<n;u++)s.set(o*i+r,n*e+u,this.get(i,e)*t.get(r,u));return s}kroneckerSum(t){if(t=Eo.checkMatrix(t),!this.isSquare()||!t.isSquare())throw new Error("Kronecker Sum needs two Square Matrices");let e=this.rows,r=t.rows,o=this.kroneckerProduct(Eo.eye(r,r)),n=Eo.eye(e,e).kroneckerProduct(t);return o.add(n)}transpose(){let t=new Eo(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]:xo;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]:xo;for(let e=0;e<this.columns;e++)this.setColumn(e,this.getColumn(e).sort(t));return this}subMatrix(t,e,r,o){wo(this,t,e,r,o);let n=new Eo(e-t+1,o-r+1);for(let s=t;s<=e;s++)for(let e=r;e<=o;e++)n.set(s-t,e-r,this.get(s,e));return n}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 o=new Eo(t.length,r-e+1);for(let n=0;n<t.length;n++)for(let s=e;s<=r;s++){if(t[n]<0||t[n]>=this.rows)throw new RangeError(`Row index out of range: ${t[n]}`);o.set(n,s-e,this.get(t[n],s))}return o}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 o=new Eo(r-e+1,t.length);for(let n=0;n<t.length;n++)for(let s=e;s<=r;s++){if(t[n]<0||t[n]>=this.columns)throw new RangeError(`Column index out of range: ${t[n]}`);o.set(s-e,n,this.get(s,t[n]))}return o}setSubMatrix(t,e,r){if((t=Eo.checkMatrix(t)).isEmpty())return this;wo(this,e,e+t.rows-1,r,r+t.columns-1);for(let o=0;o<t.rows;o++)for(let n=0;n<t.columns;n++)this.set(e+o,r+n,t.get(o,n));return this}selection(t,e){!function(t,e){if(!so(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(!so(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 Eo(t.length,e.length);for(let o=0;o<t.length;o++){let n=t[o];for(let t=0;t<e.length;t++){let s=e[t];r.set(o,t,this.get(n,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 Eo(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=bo(t.rows);for(let r=0;r<t.rows;++r)for(let o=0;o<t.columns;++o)e[r]+=t.get(r,o);return e}(this);case"column":return function(t){let e=bo(t.columns);for(let r=0;r<t.rows;++r)for(let o=0;o<t.columns;++o)e[o]+=t.get(r,o);return e}(this);case void 0:return function(t){let e=0;for(let r=0;r<t.rows;r++)for(let o=0;o<t.columns;o++)e+=t.get(r,o);return e}(this);default:throw new Error(`invalid option: ${t}`)}}product(t){switch(t){case"row":return function(t){let e=bo(t.rows,1);for(let r=0;r<t.rows;++r)for(let o=0;o<t.columns;++o)e[r]*=t.get(r,o);return e}(this);case"column":return function(t){let e=bo(t.columns,1);for(let r=0;r<t.rows;++r)for(let o=0;o<t.columns;++o)e[o]*=t.get(r,o);return e}(this);case void 0:return function(t){let e=1;for(let r=0;r<t.rows;r++)for(let o=0;o<t.columns;o++)e*=t.get(r,o);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:o=this.mean(t)}=e;if("boolean"!=typeof r)throw new TypeError("unbiased must be a boolean");switch(t){case"row":if(!so(o))throw new TypeError("mean must be an array");return function(t,e,r){const o=t.rows,n=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(i,e)-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,o);case"column":if(!so(o))throw new TypeError("mean must be an array");return function(t,e,r){const o=t.rows,n=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(e,i)-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,o);case void 0:if("number"!=typeof o)throw new TypeError("mean must be a number");return function(t,e,r){const o=t.rows,n=t.columns,s=o*n;let i=0,u=0,a=0;for(let e=0;e<o;e++)for(let o=0;o<n;o++)a=t.get(e,o)-r,i+=a,u+=a*a;return e?(u-i*i/s)/(s-1):(u-i*i/s)/s}(this,r,o);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(!so(r))throw new TypeError("center must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let o=0;o<t.columns;o++)t.set(r,o,t.get(r,o)-e[r])}(this,r),this;case"column":if(!so(r))throw new TypeError("center must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let o=0;o<t.columns;o++)t.set(r,o,t.get(r,o)-e[o])}(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 o=0;o<t.columns;o++)t.set(r,o,t.get(r,o)-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 o=0;for(let e=0;e<t.columns;e++)o+=Math.pow(t.get(r,e),2)/(t.columns-1);e.push(Math.sqrt(o))}return e}(this);else if(!so(r))throw new TypeError("scale must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let o=0;o<t.columns;o++)t.set(r,o,t.get(r,o)/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 o=0;for(let e=0;e<t.rows;e++)o+=Math.pow(t.get(e,r),2)/(t.rows-1);e.push(Math.sqrt(o))}return e}(this);else if(!so(r))throw new TypeError("scale must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let o=0;o<t.columns;o++)t.set(r,o,t.get(r,o)/e[o])}(this,r),this;case void 0:if(void 0===r)r=function(t){const e=t.size-1;let r=0;for(let o=0;o<t.columns;o++)for(let n=0;n<t.rows;n++)r+=Math.pow(t.get(n,o),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 o=0;o<t.columns;o++)t.set(r,o,t.get(r,o)/e)}(this,r),this;default:throw new Error(`invalid option: ${t}`)}}toString(t){return ho(this,t)}}function xo(t,e){return t-e}Mo.prototype.klass="Matrix","undefined"!=typeof Symbol&&(Mo.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return ho(this)}),Mo.random=Mo.rand,Mo.randomInt=Mo.randInt,Mo.diagonal=Mo.diag,Mo.prototype.diagonal=Mo.prototype.diag,Mo.identity=Mo.eye,Mo.prototype.negate=Mo.prototype.neg,Mo.prototype.tensorProduct=Mo.prototype.kroneckerProduct;class Eo extends Mo{constructor(t,e){if(super(),Eo.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(!so(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 o=0;o<t;o++){if(r[o].length!==e)throw new RangeError("Inconsistent array dimensions");if(!r[o].every((t=>"number"==typeof t)))throw new TypeError("Input data contains non-numeric values");this.data.push(Float64Array.from(r[o]))}}}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 fo(this,t),this.data.splice(t,1),this.rows-=1,this}addRow(t,e){return void 0===e&&(e=t,t=this.rows),fo(this,t,!0),e=Float64Array.from(go(this,e)),this.data.splice(t,0,e),this.rows+=1,this}removeColumn(t){mo(this,t);for(let e=0;e<this.rows;e++){const r=new Float64Array(this.columns-1);for(let o=0;o<t;o++)r[o]=this.data[e][o];for(let o=t+1;o<this.columns;o++)r[o-1]=this.data[e][o];this.data[e]=r}return this.columns-=1,this}addColumn(t,e){void 0===e&&(e=t,t=this.columns),mo(this,t,!0),e=po(this,e);for(let r=0;r<this.rows;r++){const o=new Float64Array(this.columns+1);let n=0;for(;n<t;n++)o[n]=this.data[r][n];for(o[n++]=e[r];n<this.columns+1;n++)o[n]=this.data[r][n-1];this.data[r]=o}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}}(Mo,Eo);class So extends Mo{constructor(t,e,r){super(),this.matrix=t,this.rows=e,this.columns=r}}class jo extends So{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 _o extends Mo{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 Ao(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 Oo{constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if((t=_o.checkMatrix(t)).isEmpty())throw new Error("Matrix must be non-empty");let r=t.rows,o=t.columns;const{computeLeftSingularVectors:n=!0,computeRightSingularVectors:s=!0,autoTranspose:i=!1}=e;let u,a=Boolean(n),h=Boolean(s),l=!1;if(r<o)if(i){u=t.transpose(),r=u.rows,o=u.columns,l=!0;let e=a;a=h,h=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,o),f=Math.min(r+1,o),m=new Float64Array(f),g=new Eo(r,c),p=new Eo(o,o),w=new Float64Array(o),d=new Float64Array(r),b=new Float64Array(f);for(let t=0;t<f;t++)b[t]=t;let y=Math.min(r-1,o),v=Math.max(0,Math.min(o-2,r)),M=Math.max(y,v);for(let t=0;t<M;t++){if(t<y){m[t]=0;for(let e=t;e<r;e++)m[t]=Ao(m[t],u.get(e,t));if(0!==m[t]){u.get(t,t)<0&&(m[t]=-m[t]);for(let e=t;e<r;e++)u.set(e,t,u.get(e,t)/m[t]);u.set(t,t,u.get(t,t)+1)}m[t]=-m[t]}for(let e=t+1;e<o;e++){if(t<y&&0!==m[t]){let o=0;for(let n=t;n<r;n++)o+=u.get(n,t)*u.get(n,e);o=-o/u.get(t,t);for(let n=t;n<r;n++)u.set(n,e,u.get(n,e)+o*u.get(n,t))}w[e]=u.get(t,e)}if(a&&t<y)for(let e=t;e<r;e++)g.set(e,t,u.get(e,t));if(t<v){w[t]=0;for(let e=t+1;e<o;e++)w[t]=Ao(w[t],w[e]);if(0!==w[t]){w[t+1]<0&&(w[t]=0-w[t]);for(let e=t+1;e<o;e++)w[e]/=w[t];w[t+1]+=1}if(w[t]=-w[t],t+1<r&&0!==w[t]){for(let e=t+1;e<r;e++)d[e]=0;for(let e=t+1;e<r;e++)for(let r=t+1;r<o;r++)d[e]+=w[r]*u.get(e,r);for(let e=t+1;e<o;e++){let o=-w[e]/w[t+1];for(let n=t+1;n<r;n++)u.set(n,e,u.get(n,e)+o*d[n])}}if(h)for(let e=t+1;e<o;e++)p.set(e,t,w[e])}}let x=Math.min(o,r+1);if(y<o&&(m[y]=u.get(y,y)),r<x&&(m[x-1]=0),v+1<x&&(w[v]=u.get(v,x-1)),w[x-1]=0,a){for(let t=y;t<c;t++){for(let e=0;e<r;e++)g.set(e,t,0);g.set(t,t,1)}for(let t=y-1;t>=0;t--)if(0!==m[t]){for(let e=t+1;e<c;e++){let o=0;for(let n=t;n<r;n++)o+=g.get(n,t)*g.get(n,e);o=-o/g.get(t,t);for(let n=t;n<r;n++)g.set(n,e,g.get(n,e)+o*g.get(n,t))}for(let e=t;e<r;e++)g.set(e,t,-g.get(e,t));g.set(t,t,1+g.get(t,t));for(let e=0;e<t-1;e++)g.set(e,t,0)}else{for(let e=0;e<r;e++)g.set(e,t,0);g.set(t,t,1)}}if(h)for(let t=o-1;t>=0;t--){if(t<v&&0!==w[t])for(let e=t+1;e<o;e++){let r=0;for(let n=t+1;n<o;n++)r+=p.get(n,t)*p.get(n,e);r=-r/p.get(t+1,t);for(let n=t+1;n<o;n++)p.set(n,e,p.get(n,e)+r*p.get(n,t))}for(let e=0;e<o;e++)p.set(e,t,0);p.set(t,t,1)}let E=x-1,S=Number.EPSILON;for(;x>0;){let t,e;for(t=x-2;t>=-1&&-1!==t;t--){const e=Number.MIN_VALUE+S*Math.abs(m[t]+Math.abs(m[t+1]));if(Math.abs(w[t])<=e||Number.isNaN(w[t])){w[t]=0;break}}if(t===x-2)e=4;else{let r;for(r=x-1;r>=t&&r!==t;r--){let e=(r!==x?Math.abs(w[r]):0)+(r!==t+1?Math.abs(w[r-1]):0);if(Math.abs(m[r])<=S*e){m[r]=0;break}}r===t?e=3:r===x-1?e=1:(e=2,t=r)}switch(t++,e){case 1:{let e=w[x-2];w[x-2]=0;for(let r=x-2;r>=t;r--){let n=Ao(m[r],e),s=m[r]/n,i=e/n;if(m[r]=n,r!==t&&(e=-i*w[r-1],w[r-1]=s*w[r-1]),h)for(let t=0;t<o;t++)n=s*p.get(t,r)+i*p.get(t,x-1),p.set(t,x-1,-i*p.get(t,r)+s*p.get(t,x-1)),p.set(t,r,n)}break}case 2:{let e=w[t-1];w[t-1]=0;for(let o=t;o<x;o++){let n=Ao(m[o],e),s=m[o]/n,i=e/n;if(m[o]=n,e=-i*w[o],w[o]=s*w[o],a)for(let e=0;e<r;e++)n=s*g.get(e,o)+i*g.get(e,t-1),g.set(e,t-1,-i*g.get(e,o)+s*g.get(e,t-1)),g.set(e,o,n)}break}case 3:{const e=Math.max(Math.abs(m[x-1]),Math.abs(m[x-2]),Math.abs(w[x-2]),Math.abs(m[t]),Math.abs(w[t])),n=m[x-1]/e,s=m[x-2]/e,i=w[x-2]/e,u=m[t]/e,l=w[t]/e,c=((s+n)*(s-n)+i*i)/2,f=n*i*(n*i);let d=0;0===c&&0===f||(d=c<0?0-Math.sqrt(c*c+f):Math.sqrt(c*c+f),d=f/(c+d));let b=(u+n)*(u-n)+d,y=u*l;for(let e=t;e<x-1;e++){let n=Ao(b,y);0===n&&(n=Number.MIN_VALUE);let s=b/n,i=y/n;if(e!==t&&(w[e-1]=n),b=s*m[e]+i*w[e],w[e]=s*w[e]-i*m[e],y=i*m[e+1],m[e+1]=s*m[e+1],h)for(let t=0;t<o;t++)n=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,n);if(n=Ao(b,y),0===n&&(n=Number.MIN_VALUE),s=b/n,i=y/n,m[e]=n,b=s*w[e]+i*m[e+1],m[e+1]=-i*w[e]+s*m[e+1],y=i*w[e+1],w[e+1]=s*w[e+1],a&&e<r-1)for(let t=0;t<r;t++)n=s*g.get(t,e)+i*g.get(t,e+1),g.set(t,e+1,-i*g.get(t,e)+s*g.get(t,e+1)),g.set(t,e,n)}w[x-2]=b;break}case 4:if(m[t]<=0&&(m[t]=m[t]<0?-m[t]:0,h))for(let e=0;e<=E;e++)p.set(e,t,-p.get(e,t));for(;t<E&&!(m[t]>=m[t+1]);){let e=m[t];if(m[t]=m[t+1],m[t+1]=e,h&&t<o-1)for(let r=0;r<o;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 o=0;o<r;o++)e=g.get(o,t+1),g.set(o,t+1,g.get(o,t)),g.set(o,t,e);t++}x--}}if(l){let t=p;p=g,g=t}this.m=r,this.n=o,this.s=m,this.U=g,this.V=p}solve(t){let e=t,r=this.threshold,o=this.s.length,n=Eo.zeros(o,o);for(let t=0;t<o;t++)Math.abs(this.s[t])<=r?n.set(t,t,0):n.set(t,t,1/this.s[t]);let s=this.U,i=this.rightSingularVectors,u=i.mmul(n),a=i.rows,h=s.rows,l=Eo.zeros(a,h);for(let t=0;t<a;t++)for(let e=0;e<h;e++){let r=0;for(let n=0;n<o;n++)r+=u.get(t,n)*s.get(e,n);l.set(t,e,r)}return l.mmul(e)}solveForDiagonal(t){return this.solve(Eo.diag(t))}inverse(){let t=this.V,e=this.threshold,r=t.rows,o=t.columns,n=new Eo(r,this.s.length);for(let s=0;s<r;s++)for(let r=0;r<o;r++)Math.abs(this.s[r])>e&&n.set(s,r,t.get(s,r)/this.s[r]);let s=this.U,i=s.rows,u=s.columns,a=new Eo(r,i);for(let t=0;t<r;t++)for(let e=0;e<i;e++){let r=0;for(let o=0;o<u;o++)r+=n.get(t,o)*s.get(e,o);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 o=0,n=r.length;o<n;o++)r[o]>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 Eo.diag(this.s)}}class Ro{constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const{assumeSymmetric:r=!1}=e;if(!(t=_o.checkMatrix(t)).isSquare())throw new Error("Matrix is not a square matrix");if(t.isEmpty())throw new Error("Matrix must be non-empty");let o,n,s=t.columns,i=new Eo(s,s),u=new Float64Array(s),a=new Float64Array(s),h=t,l=!1;if(l=!!r||t.isSymmetric(),l){for(o=0;o<s;o++)for(n=0;n<s;n++)i.set(o,n,h.get(o,n));!function(t,e,r,o){let n,s,i,u,a,h,l,c;for(a=0;a<t;a++)r[a]=o.get(t-1,a);for(u=t-1;u>0;u--){for(c=0,i=0,h=0;h<u;h++)c+=Math.abs(r[h]);if(0===c)for(e[u]=r[u-1],a=0;a<u;a++)r[a]=o.get(u-1,a),o.set(u,a,0),o.set(a,u,0);else{for(h=0;h<u;h++)r[h]/=c,i+=r[h]*r[h];for(n=r[u-1],s=Math.sqrt(i),n>0&&(s=-s),e[u]=c*s,i-=n*s,r[u-1]=n-s,a=0;a<u;a++)e[a]=0;for(a=0;a<u;a++){for(n=r[a],o.set(a,u,n),s=e[a]+o.get(a,a)*n,h=a+1;h<=u-1;h++)s+=o.get(h,a)*r[h],e[h]+=o.get(h,a)*n;e[a]=s}for(n=0,a=0;a<u;a++)e[a]/=i,n+=e[a]*r[a];for(l=n/(i+i),a=0;a<u;a++)e[a]-=l*r[a];for(a=0;a<u;a++){for(n=r[a],s=e[a],h=a;h<=u-1;h++)o.set(h,a,o.get(h,a)-(n*e[h]+s*r[h]));r[a]=o.get(u-1,a),o.set(u,a,0)}}r[u]=i}for(u=0;u<t-1;u++){if(o.set(t-1,u,o.get(u,u)),o.set(u,u,1),i=r[u+1],0!==i){for(h=0;h<=u;h++)r[h]=o.get(h,u+1)/i;for(a=0;a<=u;a++){for(s=0,h=0;h<=u;h++)s+=o.get(h,u+1)*o.get(h,a);for(h=0;h<=u;h++)o.set(h,a,o.get(h,a)-s*r[h])}}for(h=0;h<=u;h++)o.set(h,u+1,0)}for(a=0;a<t;a++)r[a]=o.get(t-1,a),o.set(t-1,a,0);o.set(t-1,t-1,1),e[0]=0}(s,a,u,i),function(t,e,r,o){let n,s,i,u,a,h,l,c,f,m,g,p,w,d,b,y;for(i=1;i<t;i++)e[i-1]=e[i];e[t-1]=0;let v=0,M=0,x=Number.EPSILON;for(h=0;h<t;h++){for(M=Math.max(M,Math.abs(r[h])+Math.abs(e[h])),l=h;l<t&&!(Math.abs(e[l])<=x*M);)l++;if(l>h)do{for(n=r[h],c=(r[h+1]-n)/(2*e[h]),f=Ao(c,1),c<0&&(f=-f),r[h]=e[h]/(c+f),r[h+1]=e[h]*(c+f),m=r[h+1],s=n-r[h],i=h+2;i<t;i++)r[i]-=s;for(v+=s,c=r[l],g=1,p=g,w=g,d=e[h+1],b=0,y=0,i=l-1;i>=h;i--)for(w=p,p=g,y=b,n=g*e[i],s=g*c,f=Ao(c,e[i]),e[i+1]=b*f,b=e[i]/f,g=c/f,c=g*r[i]-b*n,r[i+1]=s+b*(g*n+b*r[i]),a=0;a<t;a++)s=o.get(a,i+1),o.set(a,i+1,b*o.get(a,i)+g*s),o.set(a,i,g*o.get(a,i)-b*s);c=-b*y*w*d*e[h]/m,e[h]=b*c,r[h]=g*c}while(Math.abs(e[h])>x*M);r[h]=r[h]+v,e[h]=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=o.get(u,i),o.set(u,i,o.get(u,a)),o.set(u,a,c)}}(s,a,u,i)}else{let t=new Eo(s,s),e=new Float64Array(s);for(n=0;n<s;n++)for(o=0;o<s;o++)t.set(o,n,h.get(o,n));!function(t,e,r,o){let n,s,i,u,a,h,l,c=0,f=t-1;for(h=c+1;h<=f-1;h++){for(l=0,u=h;u<=f;u++)l+=Math.abs(e.get(u,h-1));if(0!==l){for(i=0,u=f;u>=h;u--)r[u]=e.get(u,h-1)/l,i+=r[u]*r[u];for(s=Math.sqrt(i),r[h]>0&&(s=-s),i-=r[h]*s,r[h]=r[h]-s,a=h;a<t;a++){for(n=0,u=f;u>=h;u--)n+=r[u]*e.get(u,a);for(n/=i,u=h;u<=f;u++)e.set(u,a,e.get(u,a)-n*r[u])}for(u=0;u<=f;u++){for(n=0,a=f;a>=h;a--)n+=r[a]*e.get(u,a);for(n/=i,a=h;a<=f;a++)e.set(u,a,e.get(u,a)-n*r[a])}r[h]=l*r[h],e.set(h,h-1,l*s)}}for(u=0;u<t;u++)for(a=0;a<t;a++)o.set(u,a,u===a?1:0);for(h=f-1;h>=c+1;h--)if(0!==e.get(h,h-1)){for(u=h+1;u<=f;u++)r[u]=e.get(u,h-1);for(a=h;a<=f;a++){for(s=0,u=h;u<=f;u++)s+=r[u]*o.get(u,a);for(s=s/r[h]/e.get(h,h-1),u=h;u<=f;u++)o.set(u,a,o.get(u,a)+s*r[u])}}}(s,t,e,i),function(t,e,r,o,n){let s,i,u,a,h,l,c,f,m,g,p,w,d,b,y,v=t-1,M=0,x=t-1,E=Number.EPSILON,S=0,j=0,_=0,A=0,O=0,R=0,C=0,I=0;for(s=0;s<t;s++)for((s<M||s>x)&&(r[s]=n.get(s,s),e[s]=0),i=Math.max(s-1,0);i<t;i++)j+=Math.abs(n.get(s,i));for(;v>=M;){for(a=v;a>M&&(R=Math.abs(n.get(a-1,a-1))+Math.abs(n.get(a,a)),0===R&&(R=j),!(Math.abs(n.get(a,a-1))<E*R));)a--;if(a===v)n.set(v,v,n.get(v,v)+S),r[v]=n.get(v,v),e[v]=0,v--,I=0;else if(a===v-1){if(c=n.get(v,v-1)*n.get(v-1,v),_=(n.get(v-1,v-1)-n.get(v,v))/2,A=_*_+c,C=Math.sqrt(Math.abs(A)),n.set(v,v,n.get(v,v)+S),n.set(v-1,v-1,n.get(v-1,v-1)+S),f=n.get(v,v),A>=0){for(C=_>=0?_+C:_-C,r[v-1]=f+C,r[v]=r[v-1],0!==C&&(r[v]=f-c/C),e[v-1]=0,e[v]=0,f=n.get(v,v-1),R=Math.abs(f)+Math.abs(C),_=f/R,A=C/R,O=Math.sqrt(_*_+A*A),_/=O,A/=O,i=v-1;i<t;i++)C=n.get(v-1,i),n.set(v-1,i,A*C+_*n.get(v,i)),n.set(v,i,A*n.get(v,i)-_*C);for(s=0;s<=v;s++)C=n.get(s,v-1),n.set(s,v-1,A*C+_*n.get(s,v)),n.set(s,v,A*n.get(s,v)-_*C);for(s=M;s<=x;s++)C=o.get(s,v-1),o.set(s,v-1,A*C+_*o.get(s,v)),o.set(s,v,A*o.get(s,v)-_*C)}else r[v-1]=f+_,r[v]=f+_,e[v-1]=C,e[v]=-C;v-=2,I=0}else{if(f=n.get(v,v),m=0,c=0,a<v&&(m=n.get(v-1,v-1),c=n.get(v,v-1)*n.get(v-1,v)),10===I){for(S+=f,s=M;s<=v;s++)n.set(s,s,n.get(s,s)-f);R=Math.abs(n.get(v,v-1))+Math.abs(n.get(v-1,v-2)),f=m=.75*R,c=-.4375*R*R}if(30===I&&(R=(m-f)/2,R=R*R+c,R>0)){for(R=Math.sqrt(R),m<f&&(R=-R),R=f-c/((m-f)/2+R),s=M;s<=v;s++)n.set(s,s,n.get(s,s)-R);S+=R,f=m=c=.964}for(I+=1,h=v-2;h>=a&&(C=n.get(h,h),O=f-C,R=m-C,_=(O*R-c)/n.get(h+1,h)+n.get(h,h+1),A=n.get(h+1,h+1)-C-O-R,O=n.get(h+2,h+1),R=Math.abs(_)+Math.abs(A)+Math.abs(O),_/=R,A/=R,O/=R,h!==a)&&!(Math.abs(n.get(h,h-1))*(Math.abs(A)+Math.abs(O))<E*(Math.abs(_)*(Math.abs(n.get(h-1,h-1))+Math.abs(C)+Math.abs(n.get(h+1,h+1)))));)h--;for(s=h+2;s<=v;s++)n.set(s,s-2,0),s>h+2&&n.set(s,s-3,0);for(u=h;u<=v-1&&(b=u!==v-1,u!==h&&(_=n.get(u,u-1),A=n.get(u+1,u-1),O=b?n.get(u+2,u-1):0,f=Math.abs(_)+Math.abs(A)+Math.abs(O),0!==f&&(_/=f,A/=f,O/=f)),0!==f);u++)if(R=Math.sqrt(_*_+A*A+O*O),_<0&&(R=-R),0!==R){for(u!==h?n.set(u,u-1,-R*f):a!==h&&n.set(u,u-1,-n.get(u,u-1)),_+=R,f=_/R,m=A/R,C=O/R,A/=_,O/=_,i=u;i<t;i++)_=n.get(u,i)+A*n.get(u+1,i),b&&(_+=O*n.get(u+2,i),n.set(u+2,i,n.get(u+2,i)-_*C)),n.set(u,i,n.get(u,i)-_*f),n.set(u+1,i,n.get(u+1,i)-_*m);for(s=0;s<=Math.min(v,u+3);s++)_=f*n.get(s,u)+m*n.get(s,u+1),b&&(_+=C*n.get(s,u+2),n.set(s,u+2,n.get(s,u+2)-_*O)),n.set(s,u,n.get(s,u)-_),n.set(s,u+1,n.get(s,u+1)-_*A);for(s=M;s<=x;s++)_=f*o.get(s,u)+m*o.get(s,u+1),b&&(_+=C*o.get(s,u+2),o.set(s,u+2,o.get(s,u+2)-_*O)),o.set(s,u,o.get(s,u)-_),o.set(s,u+1,o.get(s,u+1)-_*A)}}}if(0===j)return;for(v=t-1;v>=0;v--)if(_=r[v],A=e[v],0===A)for(a=v,n.set(v,v,1),s=v-1;s>=0;s--){for(c=n.get(s,s)-_,O=0,i=a;i<=v;i++)O+=n.get(s,i)*n.get(i,v);if(e[s]<0)C=c,R=O;else if(a=s,0===e[s]?n.set(s,v,0!==c?-O/c:-O/(E*j)):(f=n.get(s,s+1),m=n.get(s+1,s),A=(r[s]-_)*(r[s]-_)+e[s]*e[s],l=(f*R-C*O)/A,n.set(s,v,l),n.set(s+1,v,Math.abs(f)>Math.abs(C)?(-O-c*l)/f:(-R-m*l)/C)),l=Math.abs(n.get(s,v)),E*l*l>1)for(i=s;i<=v;i++)n.set(i,v,n.get(i,v)/l)}else if(A<0)for(a=v-1,Math.abs(n.get(v,v-1))>Math.abs(n.get(v-1,v))?(n.set(v-1,v-1,A/n.get(v,v-1)),n.set(v-1,v,-(n.get(v,v)-_)/n.get(v,v-1))):(y=Co(0,-n.get(v-1,v),n.get(v-1,v-1)-_,A),n.set(v-1,v-1,y[0]),n.set(v-1,v,y[1])),n.set(v,v-1,0),n.set(v,v,1),s=v-2;s>=0;s--){for(g=0,p=0,i=a;i<=v;i++)g+=n.get(s,i)*n.get(i,v-1),p+=n.get(s,i)*n.get(i,v);if(c=n.get(s,s)-_,e[s]<0)C=c,O=g,R=p;else if(a=s,0===e[s]?(y=Co(-g,-p,c,A),n.set(s,v-1,y[0]),n.set(s,v,y[1])):(f=n.get(s,s+1),m=n.get(s+1,s),w=(r[s]-_)*(r[s]-_)+e[s]*e[s]-A*A,d=2*(r[s]-_)*A,0===w&&0===d&&(w=E*j*(Math.abs(c)+Math.abs(A)+Math.abs(f)+Math.abs(m)+Math.abs(C))),y=Co(f*O-C*g+A*p,f*R-C*p-A*g,w,d),n.set(s,v-1,y[0]),n.set(s,v,y[1]),Math.abs(f)>Math.abs(C)+Math.abs(A)?(n.set(s+1,v-1,(-g-c*n.get(s,v-1)+A*n.get(s,v))/f),n.set(s+1,v,(-p-c*n.get(s,v)-A*n.get(s,v-1))/f)):(y=Co(-O-m*n.get(s,v-1),-R-m*n.get(s,v),C,A),n.set(s+1,v-1,y[0]),n.set(s+1,v,y[1]))),l=Math.max(Math.abs(n.get(s,v-1)),Math.abs(n.get(s,v))),E*l*l>1)for(i=s;i<=v;i++)n.set(i,v-1,n.get(i,v-1)/l),n.set(i,v,n.get(i,v)/l)}for(s=0;s<t;s++)if(s<M||s>x)for(i=s;i<t;i++)o.set(s,i,n.get(s,i));for(i=t-1;i>=M;i--)for(s=M;s<=x;s++){for(C=0,u=M;u<=Math.min(i,x);u++)C+=o.get(s,u)*n.get(u,i);o.set(s,i,C)}}(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,o=this.e,n=this.d,s=new Eo(r,r);for(t=0;t<r;t++){for(e=0;e<r;e++)s.set(t,e,0);s.set(t,t,n[t]),o[t]>0?s.set(t,t+1,o[t]):o[t]<0&&s.set(t,t-1,o[t])}return s}}function Co(t,e,r,o){let n,s;return Math.abs(r)>Math.abs(o)?(n=o/r,s=r+n*o,[(t+n*e)/s,(e-n*t)/s]):(n=r/o,s=o+n*r,[(n*t+e)/s,(n*e-t)/s])}class Io{constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};t=_o.checkMatrix(t);let{Y:r}=e;const{scaleScores:o=!1,maxIterations:n=1e3,terminationCriteria:s=1e-10}=e;let i;if(r){if(r=so(r)&&"number"==typeof r[0]?Eo.columnVector(r):_o.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,h,l,c=1;for(let e=0;e<n&&c>s;e++)h=t.transpose().mmul(i).div(i.transpose().mmul(i).get(0,0)),h=h.div(h.norm()),u=t.mmul(h).div(h.transpose().mmul(h).get(0,0)),e>0&&(c=u.clone().sub(l).pow(2).sum()),l=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 o=t.clone().sub(u.clone().mmul(e.transpose())),n=i.transpose().mmul(u).div(u.transpose().mmul(u).get(0,0)),s=r.clone().sub(u.clone().mulS(n.get(0,0)).mmul(a.transpose()));this.t=u,this.p=e.transpose(),this.w=h.transpose(),this.q=a,this.u=i,this.s=u.transpose().mmul(u),this.xResidual=o,this.yResidual=s,this.betas=n}else this.w=h.transpose(),this.s=u.transpose().mmul(u).sqrt(),this.t=o?u.clone().div(this.s.get(0,0)):u,this.xResidual=t.sub(u.mmul(h.transpose()))}}let No=class t{constructor(t){let e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o=arguments.length>2?arguments[2]:void 0;if(this.U=null,this.S=null,o)return this.center=o.center,this.scale=o.scale,this.means=o.means,this.stdevs=o.stdevs,this.U=Eo.checkMatrix(o.U),this.S=o.S,this.R=o.R,void(this.excludedFeatures=o.excludedFeatures||[]);e=(Array.isArray(t),new Eo(t));const{isCovarianceMatrix:n=!1,method:s="SVD",nCompNIPALS:i=2,center:u=!0,scale:a=!1,ignoreZeroVariance:h=!1}=r;if(this.center=u,this.scale=a,this.means=null,this.stdevs=null,this.excludedFeatures=[],n)this._computeFromCovarianceMatrix(e);else switch(this._adjust(e,h),s){case"covarianceMatrix":{const t=new jo(e).mmul(e).div(e.rows-1);this._computeFromCovarianceMatrix(t);break}case"NIPALS":this._computeWithNIPALS(e,i);break;case"SVD":{const t=new Oo(e,{computeLeftSingularVectors:!1,computeRightSingularVectors:!0,autoTranspose:!0});this.U=t.rightSingularVectors;const r=t.diagonal,o=[];for(const t of r)o.push(t*t/(e.rows-1));this.S=o;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 o;if(o=(Array.isArray(t),new Eo(t)),this.center&&(o.subRowVector(this.means),this.scale)){for(let t of this.excludedFeatures)o.removeColumn(t);o.divRowVector(this.stdevs)}let n=o.mmul(this.U);return n.subMatrix(0,n.rows-1,0,r-1)}invert(t){let e=(t=Eo.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"),o=this.scale?t.standardDeviation("column",{mean:r}):null;if(this.means=r,t.subRowVector(r),this.scale){for(let r=0;r<o.length;r++)if(0===o[r]){if(!e)throw new RangeError(`Cannot scale the dataset (standard deviation is zero at index ${r}`);t.removeColumn(r),o.splice(r,1),this.excludedFeatures.push(r),r--}this.stdevs=o,t.divRowVector(o)}}}_computeFromCovarianceMatrix(t){const e=new Ro(t,{assumeSymmetric:!0});this.U=e.eigenvectorMatrix,this.U.flipRows(),this.S=e.realEigenvalues,this.S.reverse()}_computeWithNIPALS(t,e){this.U=new Eo(e,t.columns),this.S=[];let r=t;for(let t=0;t<e;t++){let e=new Io(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 ko(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!Cr(t))throw new Error("data is not eff. array");let r=ve(e,"scale");kr(r)||(r=!0);let o=ve(e,"nCompNIPALS");Tr(o)||(o=2),o=oo(o);let n=jr(ve(t,0,[]));if(0===n)throw new Error("invalid dimension of data");if(o>n)throw new Error(`nCompNIPALS[${o}] is more than the dimension[${n}] of data`);return new No(t,{method:"NIPALS",scale:r,nCompNIPALS:o}).predict(t).toJSON()}var Fo={},To={get exports(){return Fo},set exports(t){Fo=t}};var Po=function(t,e){for(var r=-1,o=null==t?0:t.length;++r<o&&!1!==e(t[r],r,t););return t};var zo=function(t){return function(e,r,o){for(var n=-1,s=Object(e),i=o(e),u=i.length;u--;){var a=i[t?u:++n];if(!1===r(s[a],a,s))break}return e}}();var Vo=function(t,e){for(var r=-1,o=Array(t);++r<t;)o[r]=e(r);return o},$o=b,qo=y;var Do=function(t){return qo(t)&&"[object Arguments]"==$o(t)},Uo=y,Lo=Object.prototype,Go=Lo.hasOwnProperty,Bo=Lo.propertyIsEnumerable,Wo=Do(function(){return arguments}())?Do:function(t){return Uo(t)&&Go.call(t,"callee")&&!Bo.call(t,"callee")},Ko=Wo,Yo={};var Xo=function(){return!1};!function(t,e){var r=i,o=Xo,n=e&&!e.nodeType&&e,s=n&&t&&!t.nodeType&&t,u=s&&s.exports===n?r.Buffer:void 0,a=(u?u.isBuffer:void 0)||o;t.exports=a}({get exports(){return Yo},set exports(t){Yo=t}},Yo);var Jo=/^(?:0|[1-9]\d*)$/;var Zo=function(t,e){var r=typeof t;return!!(e=null==e?9007199254740991:e)&&("number"==r||"symbol"!=r&&Jo.test(t))&&t>-1&&t%1==0&&t<e},Ho=b,Qo=Ke,tn=y,en={};en["[object Float32Array]"]=en["[object Float64Array]"]=en["[object Int8Array]"]=en["[object Int16Array]"]=en["[object Int32Array]"]=en["[object Uint8Array]"]=en["[object Uint8ClampedArray]"]=en["[object Uint16Array]"]=en["[object Uint32Array]"]=!0,en["[object Arguments]"]=en["[object Array]"]=en["[object ArrayBuffer]"]=en["[object Boolean]"]=en["[object DataView]"]=en["[object Date]"]=en["[object Error]"]=en["[object Function]"]=en["[object Map]"]=en["[object Number]"]=en["[object Object]"]=en["[object RegExp]"]=en["[object Set]"]=en["[object String]"]=en["[object WeakMap]"]=!1;var rn=function(t){return tn(t)&&Qo(t.length)&&!!en[Ho(t)]};var on=function(t){return function(e){return t(e)}},nn={};!function(t,e){var r=o,n=e&&!e.nodeType&&e,s=n&&t&&!t.nodeType&&t,i=s&&s.exports===n&&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 nn},set exports(t){nn=t}},nn);var sn=rn,un=on,an=nn&&nn.isTypedArray,hn=an?un(an):sn,ln=Vo,cn=Ko,fn=r,mn=Yo,gn=Zo,pn=hn,wn=Object.prototype.hasOwnProperty;var dn=function(t,e){var r=fn(t),o=!r&&cn(t),n=!r&&!o&&mn(t),s=!r&&!o&&!n&&pn(t),i=r||o||n||s,u=i?ln(t.length,String):[],a=u.length;for(var h in t)!e&&!wn.call(t,h)||i&&("length"==h||n&&("offset"==h||"parent"==h)||s&&("buffer"==h||"byteLength"==h||"byteOffset"==h)||gn(h,a))||u.push(h);return u},bn=Ae,yn=Je;var vn=function(t){return yn(t)?dn(t):bn(t)},Mn=zo,xn=vn;var En=Je;var Sn=function(t,e){return function(r,o){if(null==r)return r;if(!En(r))return t(r,o);for(var n=r.length,s=e?n:-1,i=Object(r);(e?s--:++s<n)&&!1!==o(i[s],s,i););return r}}((function(t,e){return t&&Mn(t,e,xn)}));var jn=function(t){return t},_n=jn;var An=Po,On=Sn,Rn=function(t){return"function"==typeof t?t:_n},Cn=r;var In=function(t,e){return(Cn(t)?An:On)(t,Rn(e))};!function(t){t.exports=In}(To);var Nn=e(Fo),kn=Rt;var Fn=Rt,Tn=Ct,Pn=Kt;var zn=Rt,Vn=function(){this.__data__=new kn,this.size=0},$n=function(t){var e=this.__data__,r=e.delete(t);return this.size=e.size,r},qn=function(t){return this.__data__.get(t)},Dn=function(t){return this.__data__.has(t)},Un=function(t,e){var r=this.__data__;if(r instanceof Fn){var o=r.__data__;if(!Tn||o.length<199)return o.push([t,e]),this.size=++r.size,this;r=this.__data__=new Pn(o)}return r.set(t,e),this.size=r.size,this};function Ln(t){var e=this.__data__=new zn(t);this.size=e.size}Ln.prototype.clear=Vn,Ln.prototype.delete=$n,Ln.prototype.get=qn,Ln.prototype.has=Dn,Ln.prototype.set=Un;var Gn=Ln;var Bn=Kt,Wn=function(t){return this.__data__.set(t,"__lodash_hash_undefined__"),this},Kn=function(t){return this.__data__.has(t)};function Yn(t){var e=-1,r=null==t?0:t.length;for(this.__data__=new Bn;++e<r;)this.add(t[e])}Yn.prototype.add=Yn.prototype.push=Wn,Yn.prototype.has=Kn;var Xn=Yn,Jn=function(t,e){for(var r=-1,o=null==t?0:t.length;++r<o;)if(e(t[r],r,t))return!0;return!1},Zn=function(t,e){return t.has(e)};var Hn=function(t,e,r,o,n,s){var i=1&r,u=t.length,a=e.length;if(u!=a&&!(i&&a>u))return!1;var h=s.get(t),l=s.get(e);if(h&&l)return h==e&&l==t;var c=-1,f=!0,m=2&r?new Xn:void 0;for(s.set(t,e),s.set(e,t);++c<u;){var g=t[c],p=e[c];if(o)var w=i?o(p,g,c,e,t,s):o(g,p,c,t,e,s);if(void 0!==w){if(w)continue;f=!1;break}if(m){if(!Jn(e,(function(t,e){if(!Zn(m,e)&&(g===t||n(g,t,r,o,s)))return m.push(e)}))){f=!1;break}}else if(g!==p&&!n(g,p,r,o,s)){f=!1;break}}return s.delete(t),s.delete(e),f};var Qn=function(t){var e=-1,r=Array(t.size);return t.forEach((function(t,o){r[++e]=[o,t]})),r};var ts=i.Uint8Array,es=pt,rs=Hn,os=Qn,ns=function(t){var e=-1,r=Array(t.size);return t.forEach((function(t){r[++e]=t})),r},ss=u?u.prototype:void 0,is=ss?ss.valueOf:void 0;var us=function(t,e,r,o,n,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 ts(t),new ts(e)));case"[object Boolean]":case"[object Date]":case"[object Number]":return es(+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=os;case"[object Set]":var a=1&o;if(u||(u=ns),t.size!=e.size&&!a)return!1;var h=i.get(t);if(h)return h==e;o|=2,i.set(t,e);var l=rs(u(t),u(e),o,n,s,i);return i.delete(t),l;case"[object Symbol]":if(is)return is.call(t)==is.call(e)}return!1};var as=function(t,e){for(var r=-1,o=e.length,n=t.length;++r<o;)t[n+r]=e[r];return t},hs=as,ls=r;var cs=function(t,e,r){var o=e(t);return ls(t)?o:hs(o,r(t))};var fs=function(t,e){for(var r=-1,o=null==t?0:t.length,n=0,s=[];++r<o;){var i=t[r];e(i,r,t)&&(s[n++]=i)}return s},ms=function(){return[]},gs=Object.prototype.propertyIsEnumerable,ps=Object.getOwnPropertySymbols,ws=cs,ds=ps?function(t){return null==t?[]:(t=Object(t),fs(ps(t),(function(e){return gs.call(t,e)})))}:ms,bs=vn;var ys=function(t){return ws(t,bs,ds)},vs=Object.prototype.hasOwnProperty;var Ms=Gn,xs=Hn,Es=us,Ss=function(t,e,r,o,n,s){var i=1&r,u=ys(t),a=u.length;if(a!=ys(e).length&&!i)return!1;for(var h=a;h--;){var l=u[h];if(!(i?l in e:vs.call(e,l)))return!1}var c=s.get(t),f=s.get(e);if(c&&f)return c==e&&f==t;var m=!0;s.set(t,e),s.set(e,t);for(var g=i;++h<a;){var p=t[l=u[h]],w=e[l];if(o)var d=i?o(w,p,l,e,t,s):o(p,w,l,t,e,s);if(!(void 0===d?p===w||n(p,w,r,o,s):d)){m=!1;break}g||(g="constructor"==l)}if(m&&!g){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||(m=!1)}return s.delete(t),s.delete(e),m},js=We,_s=r,As=Yo,Os=hn,Rs="[object Arguments]",Cs="[object Array]",Is="[object Object]",Ns=Object.prototype.hasOwnProperty;var ks=function(t,e,r,o,n,s){var i=_s(t),u=_s(e),a=i?Cs:js(t),h=u?Cs:js(e),l=(a=a==Rs?Is:a)==Is,c=(h=h==Rs?Is:h)==Is,f=a==h;if(f&&As(t)){if(!As(e))return!1;i=!0,l=!1}if(f&&!l)return s||(s=new Ms),i||Os(t)?xs(t,e,r,o,n,s):Es(t,e,a,r,o,n,s);if(!(1&r)){var m=l&&Ns.call(t,"__wrapped__"),g=c&&Ns.call(e,"__wrapped__");if(m||g){var p=m?t.value():t,w=g?e.value():e;return s||(s=new Ms),n(p,w,r,o,s)}}return!!f&&(s||(s=new Ms),Ss(t,e,r,o,n,s))},Fs=y;var Ts=function t(e,r,o,n,s){return e===r||(null==e||null==r||!Fs(e)&&!Fs(r)?e!=e&&r!=r:ks(e,r,o,n,t,s))},Ps=Gn,zs=Ts;var Vs=O;var $s=function(t){return t==t&&!Vs(t)},qs=$s,Ds=vn;var Us=function(t,e){return function(r){return null!=r&&(r[t]===e&&(void 0!==e||t in Object(r)))}},Ls=function(t,e,r,o){var n=r.length,s=n,i=!o;if(null==t)return!s;for(t=Object(t);n--;){var u=r[n];if(i&&u[2]?u[1]!==t[u[0]]:!(u[0]in t))return!1}for(;++n<s;){var a=(u=r[n])[0],h=t[a],l=u[1];if(i&&u[2]){if(void 0===h&&!(a in t))return!1}else{var c=new Ps;if(o)var f=o(h,l,a,t,e,c);if(!(void 0===f?zs(l,h,3,o,c):f))return!1}}return!0},Gs=function(t){for(var e=Ds(t),r=e.length;r--;){var o=e[r],n=t[o];e[r]=[o,n,qs(n)]}return e},Bs=Us;var Ws=me,Ks=Ko,Ys=r,Xs=Zo,Js=Ke,Zs=pe;var Hs=function(t,e){return null!=t&&e in Object(t)},Qs=function(t,e,r){for(var o=-1,n=(e=Ws(e,t)).length,s=!1;++o<n;){var i=Zs(e[o]);if(!(s=null!=t&&r(t,i)))break;t=t[i]}return s||++o!=n?s:!!(n=null==t?0:t.length)&&Js(n)&&Xs(i,n)&&(Ys(t)||Ks(t))};var ti=Ts,ei=ve,ri=function(t,e){return null!=t&&Qs(t,e,Hs)},oi=A,ni=$s,si=Us,ii=pe;var ui=be;var ai=er,hi=function(t){return function(e){return ui(e,t)}},li=A,ci=pe;var fi=function(t){var e=Gs(t);return 1==e.length&&e[0][2]?Bs(e[0][0],e[0][1]):function(r){return r===t||Ls(r,t,e)}},mi=function(t,e){return oi(t)&&ni(e)?si(ii(t),e):function(r){var o=ei(r,t);return void 0===o&&o===e?ri(r,t):ti(e,o,3)}},gi=jn,pi=r,wi=function(t){return li(t)?ai(ci(t)):hi(t)};var di=Sn,bi=Je;var yi=te,vi=function(t){return"function"==typeof t?t:null==t?gi:"object"==typeof t?pi(t)?mi(t[0],t[1]):fi(t):wi(t)},Mi=function(t,e){var r=-1,o=bi(t)?Array(t.length):[];return di(t,(function(t,n,s){o[++r]=e(t,n,s)})),o},xi=r;var Ei=function(t,e){return(xi(t)?yi:Mi)(t,vi(e))},Si=te;var ji=function(t,e){return Si(e,(function(e){return t[e]}))},_i=vn;var Ai=function(t){return null==t?[]:ji(t,_i(t))};function Oi(t,e){if(!Ar(t))return{};if(!Cr(e))return{};let r={};return Nn(e,(function(e){(function(t,e){return!!Ar(t)&&!(!Fr(e)&&!Tr(e))&&e in t})(t,e)&&(r[e]=ve(t,e))})),r}var Ri=Array.prototype.join;var Ci=function(t,e){return null==t?"":Ri.call(t,e)},Ii={},Ni={};Object.defineProperty(Ni,"__esModule",{value:!0});class ki{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,o)=>e.CostIfMadeMedoid<o[t].CostIfMadeMedoid?r:t),0),this.calcCostForGivenElementAsMedoid=(t,e)=>({CostIfMadeMedoid:new ki({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}}Ni.Cluster=ki;var Fi={},Ti={};Object.defineProperty(Ti,"__esModule",{value:!0}),Ti.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 Pi={};Object.defineProperty(Pi,"__esModule",{value:!0}),Pi.kGtElementArrLength="k must be less than the number of elements in the input array",Object.defineProperty(Fi,"__esModule",{value:!0});const zi=Ti,Vi=Pi,$i=Ni;class qi{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 o=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 n=new qi(this.Elements.slice(),this.K,this.DistanceFn);n.Medoids=e,n.allocateToClustersAroundCurrentMedoids();const s=n.calculateCurrentCost();s<o&&(o=s,this.Clusters=n.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 $i.Cluster({Elements:[],Medoid:t}))})),this.Elements.forEach(((t,e)=>{const r=this.findDistances(this.Clusters.map((t=>t.Medoid)),t),o=r.reduce(((t,e,r,o)=>e<o[t]?r:t),0);this.Clusters[o].Elements.push({DistanceFromMedoid:r[o],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 Vi.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||zi.distance,this.Medoids=this.selectInitialMedoids(),this.IterationCount=0}get OptimisationStarted(){return this.IterationCount>0}}qi.clusterElements=(t,e,r)=>{qi.getInstance(t,e,r);return new Array},qi.getInstance=(t,e,r)=>new qi(t,e,r),Fi.Clusterer=qi,function(t){function e(e){for(var r in e)t.hasOwnProperty(r)||(t[r]=e[r])}Object.defineProperty(t,"__esModule",{value:!0}),e(Ni),e(Fi)}(Ii);var Di=e(Ii);function Ui(t){return Ui="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},Ui(t)}function Li(t){var e=function(t,e){if("object"!==Ui(t)||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var o=r.call(t,e||"default");if("object"!==Ui(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"===Ui(e)?e:String(e)}function Gi(t,e,r){return(e=Li(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function Bi(t,e){let r=0;for(let o=0;o<t.length;o++)r+=(t[o]-e[o])*(t[o]-e[o]);return r}const Wi={distanceFunction:Bi};function Ki(t,e){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Wi;const o=r.distanceFunction||Wi.distanceFunction,n=r.similarityFunction||Wi.similarityFunction;let s=-1;if("function"==typeof n){let r=Number.MIN_VALUE;for(let o=0;o<t.length;o++){const i=n(e,t[o]);i>r&&(r=i,s=o)}}else{if("function"!=typeof o)throw new Error("A similarity or distance function it's required");{let r=Number.MAX_VALUE;for(let n=0;n<t.length;n++){const i=o(e,t[n]);i<r&&(r=i,s=n)}}}return s}function Yi(t,e,r,o){for(let n=0;n<t.length;n++)r[n]=Ki(e,t[n],{distanceFunction:o});return r}class Xi{constructor(t,e,r,o,n){this.clusters=t,this.centroids=e,this.converged=r,this.iterations=o,this.distance=n}nearest(t){const e=new Array(t.length);return Yi(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 Ji(t,e){const r=65535&(t>>>=0);return((t-r)*(e>>>=0)>>>0)+r*e>>>0}class Zi{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+Ji(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 Hi(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:o=1,replace:n=!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(!n)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===n&&o>i.length)throw new Error("size option is too large");const a=[];for(let t=0;t<o;t++){const t=Qi(i.length,r,u);a.push(i[t]),n||i.splice(t,1)}return a}function Qi(t,e,r){const o=e();if(r){let t=0;for(;o>r[t];)t++;return t}return Math.floor(o*t)}class tu{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Math.random;if("number"==typeof t){const e=new Zi(t);this.randomGenerator=e.random}else this.randomGenerator=t}choice(t,e){return Hi(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 eu(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,o)}return r}function ru(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?eu(Object(r),!0).forEach((function(e){Gi(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):eu(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function ou(t,e){const r=new Eo(t.rows,e.rows);for(let o=0;o<t.rows;o++)for(let n=0;n<e.rows;n++)r.set(o,n,Bi(t.getRow(o),e.getRow(n)));return r}function nu(t){let e=[];for(let r=0;r<t;r++)e.push(r);return e}function su(t){let e=[t[0]];for(let r=1;r<t.length;r++)e[r]=e[r-1]+t[r];return e}function iu(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,o)}return r}function uu(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?iu(Object(r),!0).forEach((function(e){Gi(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):iu(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}const au={maxIterations:100,tolerance:1e-6,initialization:"kmeans++",distanceFunction:Bi};function hu(t,e,r,o,n,s){let i=function(t,e,r,o){const n=e[0].length;let s=new Array(o),i=new Array(o);for(let t=0;t<o;t++){s[t]=new Array(n),i[t]=0;for(let e=0;e<n;e++)s[t][e]=0}for(let t=0;t<e.length;t++){i[r[t]]++;for(let o=0;o<n;o++)s[r[t]][o]+=e[t][o]}for(let e=0;e<o;e++)for(let r=0;r<n;r++)i[e]?s[e][r]/=i[e]:s[e][r]=t[e][r];return s}(t,e,r=Yi(e,t,r,n.distanceFunction),o),u=function(t,e,r,o){for(let n=0;n<t.length;n++)if(r(t[n],e[n])>o)return!1;return!0}(i,t,n.distanceFunction,n.tolerance);return new Xi(r,i,u,s,n.distanceFunction)}function lu(t,e,r){const o=function(t){return uu(uu({},au),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 n=function(t,e,r){let o;if(Array.isArray(r.initialization)){if(r.initialization.length!==e)throw new Error("The initial centers should have the same length as K");o=r.initialization}else switch(r.initialization){case"kmeans++":o=function(t,e){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const o=new Eo(t),n=o.rows,s=new tu(r.seed),i=[],u=r.localTrials||2+Math.floor(Math.log(e)),a=s.randInt(n);i.push(o.getRow(a));let h=new Eo(1,o.rows);for(let t=0;t<o.rows;t++)h.set(0,t,Bi(o.getRow(t),i[0]));let l=[su(h.getRow(0))];const c=1/l[0][n-1];let f=Eo.mul(h,c);for(let t=1;t<e;t++){const e=s.choice(n,{replace:!0,size:u,probabilities:f.getRow(0)}),r=ou(o.selection(e,nu(o.columns)),o);let a=1/0,c=1/0,m=h;for(let t=0;t<u;t++){const o=Eo.min(h,[r.getRow(t)]),n=o.sum();n<c&&(a=e[t],c=n,m=o)}i[t]=o.getRow(a),h=m,l=[su(h.getRow(0))],f=Eo.mul(h,1/l[0][n-1])}return i}(t,e,r);break;case"random":o=function(t,e,r){return new tu(r).choice(t,{size:e})}(t,e,r.seed);break;case"mostDistant":o=function(t,e,r,o){const n=new tu(o);let s=new Array(e);if(s[0]=Math.floor(n.random()*t.length),e>1){let o={dist:-1,index:-1};for(let e=0;e<t.length;++e)r[s[0]][e]>o.dist&&(o.dist=r[s[0]][e],o.index=e);if(s[1]=o.index,e>2)for(let o=2;o<e;++o){let e={dist:-1,index:-1};for(let n=0;n<t.length;++n){let t={dist:Number.MAX_VALUE,index:-1};for(let e=0;e<o;++e)r[e][n]<t.dist&&!s.includes(n)&&(t={dist:r[e][n],index:n});t.dist!==Number.MAX_VALUE&&t.dist>e.dist&&(e=ru({},t))}s[o]=e.index}}return s.map((e=>t[e]))}(t,e,function(t,e){let r=new Array(t.length);for(let o=0;o<t.length;++o)for(let n=o;n<t.length;++n){r[o]||(r[o]=new Array(t.length)),r[n]||(r[n]=new Array(t.length));const s=e(t[o],t[n]);r[o][n]=s,r[n][o]=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 o}(t,e,o);0===o.maxIterations&&(o.maxIterations=Number.MAX_VALUE);let s,i=new Array(t.length),u=!1,a=0;for(;!u&&a<o.maxIterations;)s=hu(n,t,i,e,o,++a),u=s.converged,n=s.centroids;if(!s)throw new Error("unreachable: no kmeans step executed");return s}function cu(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=ve(e,"kNumber");r=Tr(r)?oo(r):2;let o,n=ve(e,"mode");if("k-medoids"!==n&&"k-means"!==n&&(n="k-medoids"),"k-medoids"===n)o=function(t,e){let r={};function o(t){return Ci(t,":")}Nn(t,((t,e)=>{let n=o(t);r[n]=e}));let n=Di.Clusterer.getInstance(t,e).getClusteredData();return n=Ei(n,(t=>Ei(t,(t=>{let e=o(t);return r[e]})))),n}(t,r);else{if("k-means"!==n)throw new Error(`invalid mode[${n}]`);o=function(t,e){let r=lu(t,e),o={};return Nn(r.clusters,((t,e)=>{o[t]||(o[t]=[]),o[t].push(e)})),Ai(o)}(t,r)}return o}function fu(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!Cr(t))throw new Error("data is not eff. array");let r=ve(e,"kNumber");Tr(r)||(r=2),r=oo(r);let o=ve(e,"nCompNIPALS");Tr(o)||(o=2),o=oo(o);let n=ve(e,"mode"),s="",i=jr(t),u=0,a=0;if(Nn(t,(t=>{!function(t){if(Ar(t)){for(let e in t)return!0;return!1}return!1}(t)?Cr(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 h,l=null;"obj"===s?(l=function(t){let e={};Nn(t,(t=>{Nn(t,((t,r)=>{e[r]||(e[r]=0),0===e[r]&&Tr(t)&&(e[r]=1),1!==e[r]||Tr(t)||(e[r]=-1)}))}));let r=[];return Nn(e,((t,e)=>{1===t&&r.push(e)})),r}(t),h=function(t,e){return Ei(t,(t=>{let r=Oi(t,e);return Ai(r)}))}(t,l)):h=t;let c=ko(h,{nCompNIPALS:o}),f=cu(c,{kNumber:r,mode:n});return{keys:l,ginds:f,gmat:Ei(f,(t=>Ei(t,(t=>c[t])))),gltdt:Ei(f,(e=>Ei(e,(e=>t[e]))))}}let mu={PCA:async function(t){return ko(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 fu(t,e)}catch(t){return Promise.reject(t)}}};return mu}));
|
|
7
|
+
//# sourceMappingURL=w-cluster.umd.js.map
|