@datagrok/bio 2.4.2 → 2.4.5
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.json +1 -1
- package/detectors.js +22 -19
- package/dist/153.js +2 -0
- package/dist/153.js.map +1 -0
- package/dist/package-test.js +1 -1
- package/dist/package-test.js.map +1 -1
- package/dist/package.js +1 -1
- package/dist/package.js.map +1 -1
- package/package.json +3 -2
- package/src/demo/bio01-similarity-diversity.ts +45 -0
- package/src/demo/bio01a-hierarchical-clustering-and-sequence-space.ts +68 -0
- package/src/demo/bio01b-hierarchical-clustering-and-activity-cliffs.ts +94 -0
- package/src/demo/bio05-helm-msa-sequence-space.ts +59 -0
- package/src/demo/utils.ts +95 -0
- package/src/package-test.ts +1 -0
- package/src/package.ts +44 -9
- package/src/tests/detectors-weak-and-likely-tests.ts +129 -0
- package/src/tests/similarity-diversity-tests.ts +1 -0
- package/src/utils/pepsea.ts +9 -5
- package/tsconfig.json +1 -1
package/.eslintrc.json
CHANGED
package/detectors.js
CHANGED
|
@@ -44,9 +44,8 @@ const UnitsHandler = {
|
|
|
44
44
|
const isUrlRe = /[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)?/i;
|
|
45
45
|
|
|
46
46
|
class BioPackageDetectors extends DG.Package {
|
|
47
|
-
|
|
48
47
|
/** Parts of the column name required in the column's name under the detector. It must be in lowercase. */
|
|
49
|
-
|
|
48
|
+
likelyColNamePartList = ['seq', 'msa', 'dna', 'rna', 'fasta', 'helm', 'sense', 'protein'];
|
|
50
49
|
|
|
51
50
|
peptideFastaAlphabet = new Set([
|
|
52
51
|
'G', 'L', 'Y', 'S', 'E', 'Q', 'D', 'N', 'F', 'A',
|
|
@@ -89,9 +88,9 @@ class BioPackageDetectors extends DG.Package {
|
|
|
89
88
|
const t1 = Date.now();
|
|
90
89
|
try {
|
|
91
90
|
const colName = col.name;
|
|
92
|
-
|
|
93
|
-
(requiredColNamePart) => colName.toLowerCase().includes(requiredColNamePart)
|
|
94
|
-
|
|
91
|
+
const colNameLikely = this.likelyColNamePartList.some(
|
|
92
|
+
(requiredColNamePart) => colName.toLowerCase().includes(requiredColNamePart));
|
|
93
|
+
const seqMinLength = colNameLikely ? 3 : 5;
|
|
95
94
|
|
|
96
95
|
// Fail early
|
|
97
96
|
if (col.type !== DG.TYPE.STRING) return null;
|
|
@@ -147,7 +146,7 @@ class BioPackageDetectors extends DG.Package {
|
|
|
147
146
|
|
|
148
147
|
// TODO: Detect HELM sequence
|
|
149
148
|
// TODO: Lazy calculations could be helpful for performance and convenient for expressing classification logic.
|
|
150
|
-
const statsAsChars = this.getStats(categoriesSample,
|
|
149
|
+
const statsAsChars = this.getStats(categoriesSample, seqMinLength,
|
|
151
150
|
this.getSplitterAsChars(SEQ_SAMPLE_LENGTH_LIMIT));
|
|
152
151
|
// Empty statsAsShars.freq alphabet means no strings of enough length presented in the data
|
|
153
152
|
if (Object.keys(statsAsChars.freq).length === 0) return null;
|
|
@@ -164,17 +163,21 @@ class BioPackageDetectors extends DG.Package {
|
|
|
164
163
|
this.getSplitterAsFasta(SEQ_SAMPLE_LENGTH_LIMIT);
|
|
165
164
|
|
|
166
165
|
if (statsAsChars.sameLength) {
|
|
167
|
-
const stats = this.getStats(categoriesSample,
|
|
168
|
-
const alphabet = this.detectAlphabet(stats.freq, candidateAlphabets, '-');
|
|
169
|
-
if (alphabet === ALPHABET.UN) return null;
|
|
166
|
+
const stats = this.getStats(categoriesSample, seqMinLength, splitter);
|
|
167
|
+
const alphabet = this.detectAlphabet(stats.freq, candidateAlphabets, '-', colNameLikely);
|
|
168
|
+
if (alphabet === ALPHABET.UN && !colNameLikely) return null;
|
|
170
169
|
|
|
171
170
|
col.setTag(DG.TAGS.UNITS, units);
|
|
172
171
|
if (separator) col.setTag(UnitsHandler.TAGS.separator, separator);
|
|
173
172
|
col.setTag(UnitsHandler.TAGS.aligned, ALIGNMENT.SEQ_MSA);
|
|
174
173
|
col.setTag(UnitsHandler.TAGS.alphabet, alphabet);
|
|
174
|
+
if (alphabet === ALPHABET.UN) {
|
|
175
|
+
const alphabetIsMultichar = Object.keys(stats.freq).some((m) => m.length > 1);
|
|
176
|
+
col.setTag(UnitsHandler.TAGS.alphabetIsMultichar, alphabetIsMultichar ? 'true' : 'false');
|
|
177
|
+
}
|
|
175
178
|
return DG.SEMTYPE.MACROMOLECULE;
|
|
176
179
|
} else {
|
|
177
|
-
const stats = this.getStats(categoriesSample,
|
|
180
|
+
const stats = this.getStats(categoriesSample, seqMinLength, splitter);
|
|
178
181
|
const alphabetIsMultichar = Object.keys(stats.freq).some((m) => m.length > 1);
|
|
179
182
|
// Empty monomer alphabet is not allowed
|
|
180
183
|
if (Object.keys(stats.freq).length === 0) return null;
|
|
@@ -189,8 +192,9 @@ class BioPackageDetectors extends DG.Package {
|
|
|
189
192
|
const aligned = stats.sameLength ? ALIGNMENT.SEQ_MSA : ALIGNMENT.SEQ;
|
|
190
193
|
|
|
191
194
|
// TODO: If separator detected, then extra efforts to detect alphabet are allowed.
|
|
192
|
-
const alphabet = this.detectAlphabet(stats.freq, candidateAlphabets, gapSymbol);
|
|
193
|
-
|
|
195
|
+
const alphabet = this.detectAlphabet(stats.freq, candidateAlphabets, gapSymbol, colNameLikely);
|
|
196
|
+
/* Likely column name allows detecting 'fasta' notation with 'UN' alphabet, 2023-04-13, atanas, askalkin */
|
|
197
|
+
if (units === NOTATION.FASTA && alphabet === ALPHABET.UN && !alphabetIsMultichar && !colNameLikely) return null;
|
|
194
198
|
|
|
195
199
|
// const forbidden = this.checkForbiddenWoSeparator(stats.freq);
|
|
196
200
|
col.setTag(DG.TAGS.UNITS, units);
|
|
@@ -199,9 +203,7 @@ class BioPackageDetectors extends DG.Package {
|
|
|
199
203
|
col.setTag(UnitsHandler.TAGS.alphabet, alphabet);
|
|
200
204
|
if (alphabet === ALPHABET.UN) {
|
|
201
205
|
// alphabetSize calculated on (sub)sample of data is incorrect
|
|
202
|
-
// const alphabetSize = Object.keys(stats.freq).length;
|
|
203
206
|
const alphabetIsMultichar = Object.keys(stats.freq).some((m) => m.length > 1);
|
|
204
|
-
// col.setTag(UnitsHandler.TAGS.alphabetSize, alphabetSize.toString());
|
|
205
207
|
col.setTag(UnitsHandler.TAGS.alphabetIsMultichar, alphabetIsMultichar ? 'true' : 'false');
|
|
206
208
|
}
|
|
207
209
|
return DG.SEMTYPE.MACROMOLECULE;
|
|
@@ -216,7 +218,7 @@ class BioPackageDetectors extends DG.Package {
|
|
|
216
218
|
* Does not use any splitting strategies, estimates just by single characters.
|
|
217
219
|
* */
|
|
218
220
|
detectSeparator(freq) {
|
|
219
|
-
// To detect a separator we
|
|
221
|
+
// To detect a separator we analyze col's sequences character frequencies.
|
|
220
222
|
// If there is an exceptionally frequent symbol, then we will call it the separator.
|
|
221
223
|
// The most frequent symbol should occur with a rate of at least 0.15
|
|
222
224
|
// of all other symbols in sum to be called the separator.
|
|
@@ -287,7 +289,7 @@ class BioPackageDetectors extends DG.Package {
|
|
|
287
289
|
sameLength = false;
|
|
288
290
|
}
|
|
289
291
|
|
|
290
|
-
if (mSeq.length
|
|
292
|
+
if (mSeq.length >= minLength) {
|
|
291
293
|
for (const m of mSeq) {
|
|
292
294
|
if (!(m in freq)) freq[m] = 0;
|
|
293
295
|
freq[m] += 1;
|
|
@@ -300,10 +302,11 @@ class BioPackageDetectors extends DG.Package {
|
|
|
300
302
|
/** Detects alphabet for freq by freq similarity to alphabet monomer set.
|
|
301
303
|
* @param freq frequencies of monomers in sequence set
|
|
302
304
|
* @param candidates an array of pairs [name, monomer set]
|
|
303
|
-
*
|
|
304
|
-
|
|
305
|
+
* @param {boolean} colNameLikely The column name suggests the column is Macromolecule more likely
|
|
306
|
+
*/
|
|
307
|
+
detectAlphabet(freq, candidates, gapSymbol, colNameLikely = false) {
|
|
305
308
|
const candidatesSims = candidates.map((c) => {
|
|
306
|
-
const sim = this.getAlphabetSimilarity(freq, c[1], gapSymbol);
|
|
309
|
+
const sim = this.getAlphabetSimilarity(freq, c[1], gapSymbol) + (colNameLikely ? 0.15 : 0);
|
|
307
310
|
return [c[0], c[1], c[2], freq, sim];
|
|
308
311
|
});
|
|
309
312
|
|
package/dist/153.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var bio;(()=>{"use strict";var t={7659:(t,e,r)=>{e.Z=void 0;var n=r(6215);Object.defineProperty(e,"Z",{enumerable:!0,get:function(){return n.TSNE}})},6215:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.TSNE=void 0,e.TSNE=class{constructor(t){this.returnV=!1,this.vValue=0,this.iter=0,t=t||{},this.perplexity=this.getopt(t,"perplexity",30),this.dim=this.getopt(t,"dim",2),this.epsilon=this.getopt(t,"epsilon",10)}assert(t,e){if(!t)throw e||"Assertion failed"}getopt(t,e,r){return t.hasOwnProperty(e)?t[e]:r}gaussRandom(){if(this.returnV)return this.returnV=!1,this.vValue;const t=2*Math.random()-1,e=2*Math.random()-1,r=t*t+e*e;if(0===r||r>1)return this.gaussRandom();const n=Math.sqrt(-2*Math.log(r)/r);return this.vValue=e*n,this.returnV=!0,t*n}randn(t,e){return t+this.gaussRandom()*e}zeros(t){if(void 0===t||isNaN(t))return[];if("undefined"==typeof ArrayBuffer){const e=new Array(t);for(let r=0;r<t;r++)e[r]=0;return e}return new Float64Array(t)}randn2d(t,e,r){const n=void 0!==r,s=[];for(let i=0;i<t;i++){const t=[];for(let s=0;s<e;s++)n?t.push(r):t.push(this.randn(0,1e-4));s.push(t)}return s}L2(t,e){const r=t.length;let n=0;for(let s=0;s<r;s++){const r=t[s],i=e[s];n+=(r-i)*(r-i)}return n}xtod(t){const e=t.length,r=this.zeros(e*e);for(let n=0;n<e;n++)for(let s=n+1;s<e;s++){const i=this.L2(t[n],t[s]);r[n*e+s]=i,r[s*e+n]=i}return r}d2p(t,e,r){const n=Math.sqrt(t.length),s=Math.floor(n);this.assert(s===n,"D should have square number of elements.");const i=Math.log(e),o=this.zeros(s*s),h=this.zeros(s);for(let e=0;e<s;e++){let n=-1/0,a=1/0,l=1,u=!1;const c=50;let f=0;for(;!u;){let o=0;for(let r=0;r<s;r++){let n=Math.exp(-t[e*s+r]*l);e===r&&(n=0),h[r]=n,o+=n}let g=0;for(let t=0;t<s;t++){let e;e=0===o?0:h[t]/o,h[t]=e,e>1e-7&&(g-=e*Math.log(e))}g>i?(n=l,a===1/0?l*=2:l=(l+a)/2):(a=l,n===-1/0?l/=2:l=(l+n)/2),f++,Math.abs(g-i)<r&&(u=!0),f>=c&&(u=!0)}for(let t=0;t<s;t++)o[e*s+t]=h[t]}const a=this.zeros(s*s),l=2*s;for(let t=0;t<s;t++)for(let e=0;e<s;e++)a[t*s+e]=Math.max((o[t*s+e]+o[e*s+t])/l,1e-100);return a}sign(t){return t>0?1:t<0?-1:0}initDataRaw(t){const e=t.length,r=t[0].length;this.assert(e>0," X is empty? You must have some data!"),this.assert(r>0," X[0] is empty? Where is the data?");const n=this.xtod(t);this.P=this.d2p(n,this.perplexity,1e-4),this.N=e,this.initSolution()}initDataDist(t){const e=t.length;this.assert(e>0," X is empty? You must have some data!");const r=this.zeros(e*e);for(let n=0;n<e;n++)for(let s=n+1;s<e;s++){const i=t[n][s];r[n*e+s]=i,r[s*e+n]=i}this.P=this.d2p(r,this.perplexity,1e-4),this.N=e,this.initSolution()}initSolution(){this.Y=this.randn2d(this.N,this.dim),this.gains=this.randn2d(this.N,this.dim,1),this.ystep=this.randn2d(this.N,this.dim,0),this.iter=0}getSolution(){return this.Y}step(){this.iter+=1;const t=this.N,e=this.costGrad(this.Y),r=e.cost,n=e.grad,s=this.zeros(this.dim);for(let e=0;e<t;e++)for(let t=0;t<this.dim;t++){const r=n[e][t],i=this.ystep[e][t],o=this.gains[e][t];let h=this.sign(r)===this.sign(i)?.8*o:o+.2;h<.01&&(h=.01),this.gains[e][t]=h;const a=(this.iter<250?.5:.8)*i-this.epsilon*h*n[e][t];this.ystep[e][t]=a,this.Y[e][t]+=a,s[t]+=this.Y[e][t]}for(let e=0;e<t;e++)for(let r=0;r<this.dim;r++)this.Y[e][r]-=s[r]/t;return r}debugGrad(){const t=this.N,e=this.costGrad(this.Y),r=(e.cost,e.grad),n=1e-5;for(let e=0;e<t;e++)for(let t=0;t<this.dim;t++){const s=this.Y[e][t];this.Y[e][t]=s+n;const i=this.costGrad(this.Y);this.Y[e][t]=s-n;const o=this.costGrad(this.Y),h=r[e][t],a=(i.cost-o.cost)/(2*n);console.log(e+","+t+": gradcheck analytic: "+h+" vs. numerical: "+a),this.Y[e][t]=s}}costGrad(t){const e=this.N,r=this.dim,n=this.P,s=this.iter<100?4:1,i=this.zeros(e*e);let o=0;for(let n=0;n<e;n++)for(let s=n+1;s<e;s++){let h=0;for(let e=0;e<r;e++){const r=t[n][e]-t[s][e];h+=r*r}const a=1/(1+h);i[n*e+s]=a,i[s*e+n]=a,o+=2*a}const h=e*e,a=this.zeros(h);for(let t=0;t<h;t++)a[t]=Math.max(i[t]/o,1e-100);let l=0;const u=[];for(let o=0;o<e;o++){const h=new Array(r);for(let t=0;t<r;t++)h[t]=0;for(let u=0;u<e;u++){l+=-n[o*e+u]*Math.log(a[o*e+u]);const c=4*(s*n[o*e+u]-a[o*e+u])*i[o*e+u];for(let e=0;e<r;e++)h[e]+=c*(t[o][e]-t[u][e])}u.push(h)}return{cost:l,grad:u}}}},3979:(t,e)=>{e.H$=void 0,e.H$=function(t,e,r){var n=function(t,e,r){if(0===t.length||0===e.length)return 0;if(r&&!r.caseSensitive&&(t=t.toUpperCase(),e=e.toUpperCase()),t===e)return 1;for(var n=0,s=t.length,i=e.length,o=Math.floor(Math.max(s,i)/2)-1,h=new Array(s),a=new Array(i),l=0;l<s;l++)for(var u=Math.max(0,l-o);u<=Math.min(i,l+o+1);u++)if(!h[l]&&!a[u]&&t[l]===e[u]){++n,h[l]=a[u]=!0;break}if(0===n)return 0;var c=0,f=0;for(l=0;l<s;l++)if(h[l]){for(;!a[f];)f++;t.charAt(l)!==e.charAt(f++)&&c++}return(n/s+n/i+(n-(c/=2))/n)/3}(t,e,r),s=0;if(n>.7){for(var i=Math.min(t.length,e.length),o=0;t[o]===e[o]&&o<4&&o<i;)++s,o++;n+=.1*s*(1-n)}return n}},9251:(t,e,r)=>{r.r(e),r.d(e,{default:()=>V});const n=Object.prototype.toString;function s(t){return n.call(t).endsWith("Array]")}function i(t,e,r){let n=0;const s=r(e);for(let e=0;e<t.x.length;e++)n+=Math.abs(t.y[e]-s(t.x[e]));return n}const o=Object.prototype.toString;function h(t){return o.call(t).endsWith("Array]")}const a=Object.prototype.toString;function l(t){return a.call(t).endsWith("Array]")}const u=Object.prototype.toString;const c=Object.prototype.toString;function f(t){var e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!l(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(!l(r.output))throw new TypeError("output option must be an array if specified");e=r.output}else e=new Array(t.length);var n=function(t){var e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(e=t,!c.call(e).endsWith("Array]"))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");var n=r.fromIndex,s=void 0===n?0:n,i=r.toIndex,o=void 0===i?t.length:i;if(s<0||s>=t.length||!Number.isInteger(s))throw new Error("fromIndex must be a positive integer smaller than length");if(o<=s||o>t.length||!Number.isInteger(o))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var h=t[s],a=s+1;a<o;a++)t[a]<h&&(h=t[a]);return h}(t),s=function(t){var e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(e=t,!u.call(e).endsWith("Array]"))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");var n=r.fromIndex,s=void 0===n?0:n,i=r.toIndex,o=void 0===i?t.length:i;if(s<0||s>=t.length||!Number.isInteger(s))throw new Error("fromIndex must be a positive integer smaller than length");if(o<=s||o>t.length||!Number.isInteger(o))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var h=t[s],a=s+1;a<o;a++)t[a]>h&&(h=t[a]);return h}(t);if(n===s)throw new RangeError("minimum and maximum input values are equal. Cannot rescale a constant array");var i=r.min,o=void 0===i?r.autoMinMax?n:0:i,h=r.max,a=void 0===h?r.autoMinMax?s:1:h;if(o>=a)throw new RangeError("min option must be smaller than max option");for(var f=(a-o)/(s-n),g=0;g<t.length;g++)e[g]=(t[g]-n)*f+o;return e}const g=" ".repeat(2),m=" ".repeat(4);function p(t,e={}){const{maxRows:r=15,maxColumns:n=10,maxNumSize:s=8,padMinus:i="auto"}=e;return`${t.constructor.name} {\n${g}[\n${m}${function(t,e,r,n,s){const{rows:i,columns:o}=t,h=Math.min(i,e),a=Math.min(o,r),l=[];if("auto"===s){s=!1;t:for(let e=0;e<h;e++)for(let r=0;r<a;r++)if(t.get(e,r)<0){s=!0;break t}}for(let e=0;e<h;e++){let r=[];for(let i=0;i<a;i++)r.push(d(t.get(e,i),n,s));l.push(`${r.join(" ")}`)}return a!==o&&(l[l.length-1]+=` ... ${o-r} more columns`),h!==i&&l.push(`... ${i-e} more rows`),l.join(`\n${m}`)}(t,r,n,s,i)}\n${g}]\n${g}rows: ${t.rows}\n${g}columns: ${t.columns}\n}`}function d(t,e,r){return(t>=0&&r?` ${w(t,e-1)}`:w(t,e)).padEnd(e)}function w(t,e){let r=t.toString();if(r.length<=e)return r;let n=t.toFixed(e);if(n.length>e&&(n=t.toFixed(Math.max(0,e-(n.length-e)))),n.length<=e&&!n.startsWith("0.000")&&!n.startsWith("-0.000"))return n;let s=t.toExponential(e);return s.length>e&&(s=t.toExponential(Math.max(0,e-(s.length-e)))),s.slice(0)}function y(t,e,r){let n=r?t.rows:t.rows-1;if(e<0||e>n)throw new RangeError("Row index out of range")}function v(t,e,r){let n=r?t.columns:t.columns-1;if(e<0||e>n)throw new RangeError("Column index out of range")}function b(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 M(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 x(t,e,r,n,s){if(5!==arguments.length)throw new RangeError("expected 4 arguments");if(_("startRow",e),_("endRow",r),_("startColumn",n),_("endColumn",s),e>r||n>s||e<0||e>=t.rows||r<0||r>=t.rows||n<0||n>=t.columns||s<0||s>=t.columns)throw new RangeError("Submatrix indices are out of range")}function S(t,e=0){let r=[];for(let n=0;n<t;n++)r.push(e);return r}function _(t,e){if("number"!=typeof e)throw new TypeError(`${t} must be a number`)}function E(t){if(t.isEmpty())throw new Error("Empty matrix has no elements to index")}class R{static from1DArray(t,e,r){if(t*e!==r.length)throw new RangeError("data length does not match given dimensions");let n=new C(t,e);for(let s=0;s<t;s++)for(let t=0;t<e;t++)n.set(s,t,r[s*e+t]);return n}static rowVector(t){let e=new C(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 C(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 C(t,e)}static ones(t,e){return new C(t,e).fill(1)}static rand(t,e,r={}){if("object"!=typeof r)throw new TypeError("options must be an object");const{random:n=Math.random}=r;let s=new C(t,e);for(let r=0;r<t;r++)for(let t=0;t<e;t++)s.set(r,t,n());return s}static randInt(t,e,r={}){if("object"!=typeof r)throw new TypeError("options must be an object");const{min:n=0,max:s=1e3,random:i=Math.random}=r;if(!Number.isInteger(n))throw new TypeError("min must be an integer");if(!Number.isInteger(s))throw new TypeError("max must be an integer");if(n>=s)throw new RangeError("min must be smaller than max");let o=s-n,h=new C(t,e);for(let r=0;r<t;r++)for(let t=0;t<e;t++){let e=n+Math.round(i()*o);h.set(r,t,e)}return h}static eye(t,e,r){void 0===e&&(e=t),void 0===r&&(r=1);let n=Math.min(t,e),s=this.zeros(t,e);for(let t=0;t<n;t++)s.set(t,t,r);return s}static diag(t,e,r){let n=t.length;void 0===e&&(e=n),void 0===r&&(r=e);let s=Math.min(n,e,r),i=this.zeros(e,r);for(let e=0;e<s;e++)i.set(e,e,t[e]);return i}static min(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,n=t.columns,s=new C(r,n);for(let i=0;i<r;i++)for(let r=0;r<n;r++)s.set(i,r,Math.min(t.get(i,r),e.get(i,r)));return s}static max(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,n=t.columns,s=new this(r,n);for(let i=0;i<r;i++)for(let r=0;r<n;r++)s.set(i,r,Math.max(t.get(i,r),e.get(i,r)));return s}static checkMatrix(t){return R.isMatrix(t)?t:new C(t)}static isMatrix(t){return null!=t&&"Matrix"===t.klass}get size(){return this.rows*this.columns}apply(t){if("function"!=typeof t)throw new TypeError("callback must be a function");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.call(this,e,r);return this}to1DArray(){let t=[];for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.push(this.get(e,r));return t}to2DArray(){let t=[];for(let e=0;e<this.rows;e++){t.push([]);for(let r=0;r<this.columns;r++)t[e].push(this.get(e,r))}return t}toJSON(){return this.to2DArray()}isRowVector(){return 1===this.rows}isColumnVector(){return 1===this.columns}isVector(){return 1===this.rows||1===this.columns}isSquare(){return this.rows===this.columns}isEmpty(){return 0===this.rows||0===this.columns}isSymmetric(){if(this.isSquare()){for(let t=0;t<this.rows;t++)for(let e=0;e<=t;e++)if(this.get(t,e)!==this.get(e,t))return!1;return!0}return!1}isEchelonForm(){let t=0,e=0,r=-1,n=!0,s=!1;for(;t<this.rows&&n;){for(e=0,s=!1;e<this.columns&&!1===s;)0===this.get(t,e)?e++:1===this.get(t,e)&&e>r?(s=!0,r=e):(n=!1,s=!0);t++}return n}isReducedEchelonForm(){let t=0,e=0,r=-1,n=!0,s=!1;for(;t<this.rows&&n;){for(e=0,s=!1;e<this.columns&&!1===s;)0===this.get(t,e)?e++:1===this.get(t,e)&&e>r?(s=!0,r=e):(n=!1,s=!0);for(let r=e+1;r<this.rows;r++)0!==this.get(t,r)&&(n=!1);t++}return n}echelonForm(){let t=this.clone(),e=0,r=0;for(;e<t.rows&&r<t.columns;){let n=e;for(let s=e;s<t.rows;s++)t.get(s,r)>t.get(n,r)&&(n=s);if(0===t.get(n,r))r++;else{t.swapRows(e,n);let s=t.get(e,r);for(let n=r;n<t.columns;n++)t.set(e,n,t.get(e,n)/s);for(let n=e+1;n<t.rows;n++){let s=t.get(n,r)/t.get(e,r);t.set(n,r,0);for(let i=r+1;i<t.columns;i++)t.set(n,i,t.get(n,i)-t.get(e,i)*s)}e++,r++}}return t}reducedEchelonForm(){let t=this.echelonForm(),e=t.columns,r=t.rows,n=r-1;for(;n>=0;)if(0===t.maxRow(n))n--;else{let s=0,i=!1;for(;s<r&&!1===i;)1===t.get(n,s)?i=!0:s++;for(let r=0;r<n;r++){let i=t.get(r,s);for(let o=s;o<e;o++){let e=t.get(r,o)-i*t.get(n,o);t.set(r,o,e)}}n--}return t}set(){throw new Error("set method is unimplemented")}get(){throw new Error("get method is unimplemented")}repeat(t={}){if("object"!=typeof t)throw new TypeError("options must be an object");const{rows:e=1,columns:r=1}=t;if(!Number.isInteger(e)||e<=0)throw new TypeError("rows must be a positive integer");if(!Number.isInteger(r)||r<=0)throw new TypeError("columns must be a positive integer");let n=new C(this.rows*e,this.columns*r);for(let t=0;t<e;t++)for(let e=0;e<r;e++)n.setSubMatrix(this,this.rows*t,this.columns*e);return n}fill(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,t);return this}neg(){return this.mulS(-1)}getRow(t){y(this,t);let e=[];for(let r=0;r<this.columns;r++)e.push(this.get(t,r));return e}getRowVector(t){return C.rowVector(this.getRow(t))}setRow(t,e){y(this,t),e=b(this,e);for(let r=0;r<this.columns;r++)this.set(t,r,e[r]);return this}swapRows(t,e){y(this,t),y(this,e);for(let r=0;r<this.columns;r++){let n=this.get(t,r);this.set(t,r,this.get(e,r)),this.set(e,r,n)}return this}getColumn(t){v(this,t);let e=[];for(let r=0;r<this.rows;r++)e.push(this.get(r,t));return e}getColumnVector(t){return C.columnVector(this.getColumn(t))}setColumn(t,e){v(this,t),e=M(this,e);for(let r=0;r<this.rows;r++)this.set(r,t,e[r]);return this}swapColumns(t,e){v(this,t),v(this,e);for(let r=0;r<this.rows;r++){let n=this.get(r,t);this.set(r,t,this.get(r,e)),this.set(r,e,n)}return this}addRowVector(t){t=b(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=b(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=b(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=b(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=M(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=M(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=M(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=M(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){y(this,t);for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)*e);return this}mulColumn(t,e){v(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(){E(this);let t=this.get(0,0),e=[0,0];for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)>t&&(t=this.get(r,n),e[0]=r,e[1]=n);return e}min(t){if(this.isEmpty())return NaN;switch(t){case"row":{const t=new Array(this.rows).fill(Number.POSITIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)<t[e]&&(t[e]=this.get(e,r));return t}case"column":{const t=new Array(this.columns).fill(Number.POSITIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)<t[r]&&(t[r]=this.get(e,r));return t}case void 0:{let t=this.get(0,0);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)<t&&(t=this.get(e,r));return t}default:throw new Error(`invalid option: ${t}`)}}minIndex(){E(this);let t=this.get(0,0),e=[0,0];for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)<t&&(t=this.get(r,n),e[0]=r,e[1]=n);return e}maxRow(t){if(y(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){y(this,t),E(this);let e=this.get(t,0),r=[t,0];for(let n=1;n<this.columns;n++)this.get(t,n)>e&&(e=this.get(t,n),r[1]=n);return r}minRow(t){if(y(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){y(this,t),E(this);let e=this.get(t,0),r=[t,0];for(let n=1;n<this.columns;n++)this.get(t,n)<e&&(e=this.get(t,n),r[1]=n);return r}maxColumn(t){if(v(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){v(this,t),E(this);let e=this.get(0,t),r=[0,t];for(let n=1;n<this.rows;n++)this.get(n,t)>e&&(e=this.get(n,t),r[0]=n);return r}minColumn(t){if(v(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){v(this,t),E(this);let e=this.get(0,t),r=[0,t];for(let n=1;n<this.rows;n++)this.get(n,t)<e&&(e=this.get(n,t),r[0]=n);return r}diag(){let t=Math.min(this.rows,this.columns),e=[];for(let r=0;r<t;r++)e.push(this.get(r,r));return e}norm(t="frobenius"){let 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){R.isMatrix(t)&&(t=t.to1DArray());let e=this.to1DArray();if(e.length!==t.length)throw new RangeError("vectors do not have the same size");let r=0;for(let n=0;n<e.length;n++)r+=e[n]*t[n];return r}mmul(t){t=C.checkMatrix(t);let e=this.rows,r=this.columns,n=t.columns,s=new C(e,n),i=new Float64Array(r);for(let o=0;o<n;o++){for(let e=0;e<r;e++)i[e]=t.get(e,o);for(let t=0;t<e;t++){let e=0;for(let n=0;n<r;n++)e+=this.get(t,n)*i[n];s.set(t,o,e)}}return s}strassen2x2(t){t=C.checkMatrix(t);let e=new C(2,2);const r=this.get(0,0),n=t.get(0,0),s=this.get(0,1),i=t.get(0,1),o=this.get(1,0),h=t.get(1,0),a=this.get(1,1),l=t.get(1,1),u=(r+a)*(n+l),c=(o+a)*n,f=r*(i-l),g=a*(h-n),m=(r+s)*l,p=u+g-m+(s-a)*(h+l),d=f+m,w=c+g,y=u-c+f+(o-r)*(n+i);return e.set(0,0,p),e.set(0,1,d),e.set(1,0,w),e.set(1,1,y),e}strassen3x3(t){t=C.checkMatrix(t);let e=new C(3,3);const r=this.get(0,0),n=this.get(0,1),s=this.get(0,2),i=this.get(1,0),o=this.get(1,1),h=this.get(1,2),a=this.get(2,0),l=this.get(2,1),u=this.get(2,2),c=t.get(0,0),f=t.get(0,1),g=t.get(0,2),m=t.get(1,0),p=t.get(1,1),d=t.get(1,2),w=t.get(2,0),y=t.get(2,1),v=t.get(2,2),b=(r-i)*(-f+p),M=(-r+i+o)*(c-f+p),x=(i+o)*(-c+f),S=r*c,_=(-r+a+l)*(c-g+d),E=(-r+a)*(g-d),R=(a+l)*(-c+g),N=(-s+l+u)*(p+w-y),k=(s-u)*(p-y),I=s*w,A=(l+u)*(-w+y),z=(-s+o+h)*(d+w-v),F=(s-h)*(d-v),T=(o+h)*(-w+v),V=S+I+n*m,P=(r+n+s-i-o-l-u)*p+M+x+S+N+I+A,D=S+_+R+(r+n+s-o-h-a-l)*d+I+z+T,O=b+o*(-c+f+m-p-d-w+v)+M+S+I+z+F,B=b+M+x+S+h*y,j=I+z+F+T+i*g,q=S+_+E+l*(-c+g+m-p-d-w+y)+N+k+I,L=N+k+I+A+a*f,$=S+_+E+R+u*v;return e.set(0,0,V),e.set(0,1,P),e.set(0,2,D),e.set(1,0,O),e.set(1,1,B),e.set(1,2,j),e.set(2,0,q),e.set(2,1,L),e.set(2,2,$),e}mmulStrassen(t){t=C.checkMatrix(t);let e=this.clone(),r=e.rows,n=e.columns,s=t.rows,i=t.columns;function o(t,e,r){let n=t.rows,s=t.columns;if(n===e&&s===r)return t;{let n=R.zeros(e,r);return n=n.setSubMatrix(t,0,0),n}}n!==s&&console.warn(`Multiplying ${r} x ${n} and ${s} x ${i} matrix: dimensions do not match.`);let h=Math.max(r,s),a=Math.max(n,i);return e=o(e,h,a),function t(e,r,n,s){if(n<=512||s<=512)return e.mmul(r);n%2==1&&s%2==1?(e=o(e,n+1,s+1),r=o(r,n+1,s+1)):n%2==1?(e=o(e,n+1,s),r=o(r,n+1,s)):s%2==1&&(e=o(e,n,s+1),r=o(r,n,s+1));let i=parseInt(e.rows/2,10),h=parseInt(e.columns/2,10),a=e.subMatrix(0,i-1,0,h-1),l=r.subMatrix(0,i-1,0,h-1),u=e.subMatrix(0,i-1,h,e.columns-1),c=r.subMatrix(0,i-1,h,r.columns-1),f=e.subMatrix(i,e.rows-1,0,h-1),g=r.subMatrix(i,r.rows-1,0,h-1),m=e.subMatrix(i,e.rows-1,h,e.columns-1),p=r.subMatrix(i,r.rows-1,h,r.columns-1),d=t(R.add(a,m),R.add(l,p),i,h),w=t(R.add(f,m),l,i,h),y=t(a,R.sub(c,p),i,h),v=t(m,R.sub(g,l),i,h),b=t(R.add(a,u),p,i,h),M=t(R.sub(f,a),R.add(l,c),i,h),x=t(R.sub(u,m),R.add(g,p),i,h),S=R.add(d,v);S.sub(b),S.add(x);let _=R.add(y,b),E=R.add(w,v),N=R.sub(d,w);N.add(y),N.add(M);let C=R.zeros(2*S.rows,2*S.columns);return C=C.setSubMatrix(S,0,0),C=C.setSubMatrix(_,S.rows,0),C=C.setSubMatrix(E,0,S.columns),C=C.setSubMatrix(N,S.rows,S.columns),C.subMatrix(0,n-1,0,s-1)}(e,t=o(t,h,a),h,a)}scaleRows(t={}){if("object"!=typeof t)throw new TypeError("options must be an object");const{min:e=0,max:r=1}=t;if(!Number.isFinite(e))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(e>=r)throw new RangeError("min must be smaller than max");let n=new C(this.rows,this.columns);for(let t=0;t<this.rows;t++){const s=this.getRow(t);s.length>0&&f(s,{min:e,max:r,output:s}),n.setRow(t,s)}return n}scaleColumns(t={}){if("object"!=typeof t)throw new TypeError("options must be an object");const{min:e=0,max:r=1}=t;if(!Number.isFinite(e))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(e>=r)throw new RangeError("min must be smaller than max");let n=new C(this.rows,this.columns);for(let t=0;t<this.columns;t++){const s=this.getColumn(t);s.length&&f(s,{min:e,max:r,output:s}),n.setColumn(t,s)}return n}flipRows(){const t=Math.ceil(this.columns/2);for(let e=0;e<this.rows;e++)for(let r=0;r<t;r++){let t=this.get(e,r),n=this.get(e,this.columns-1-r);this.set(e,r,n),this.set(e,this.columns-1-r,t)}return this}flipColumns(){const t=Math.ceil(this.rows/2);for(let e=0;e<this.columns;e++)for(let r=0;r<t;r++){let t=this.get(r,e),n=this.get(this.rows-1-r,e);this.set(r,e,n),this.set(this.rows-1-r,e,t)}return this}kroneckerProduct(t){t=C.checkMatrix(t);let e=this.rows,r=this.columns,n=t.rows,s=t.columns,i=new C(e*n,r*s);for(let o=0;o<e;o++)for(let e=0;e<r;e++)for(let r=0;r<n;r++)for(let h=0;h<s;h++)i.set(n*o+r,s*e+h,this.get(o,e)*t.get(r,h));return i}kroneckerSum(t){if(t=C.checkMatrix(t),!this.isSquare()||!t.isSquare())throw new Error("Kronecker Sum needs two Square Matrices");let e=this.rows,r=t.rows,n=this.kroneckerProduct(C.eye(r,r)),s=C.eye(e,e).kroneckerProduct(t);return n.add(s)}transpose(){let t=new C(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(t=N){for(let e=0;e<this.rows;e++)this.setRow(e,this.getRow(e).sort(t));return this}sortColumns(t=N){for(let e=0;e<this.columns;e++)this.setColumn(e,this.getColumn(e).sort(t));return this}subMatrix(t,e,r,n){x(this,t,e,r,n);let s=new C(e-t+1,n-r+1);for(let i=t;i<=e;i++)for(let e=r;e<=n;e++)s.set(i-t,e-r,this.get(i,e));return s}subMatrixRow(t,e,r){if(void 0===e&&(e=0),void 0===r&&(r=this.columns-1),e>r||e<0||e>=this.columns||r<0||r>=this.columns)throw new RangeError("Argument out of range");let n=new C(t.length,r-e+1);for(let s=0;s<t.length;s++)for(let i=e;i<=r;i++){if(t[s]<0||t[s]>=this.rows)throw new RangeError(`Row index out of range: ${t[s]}`);n.set(s,i-e,this.get(t[s],i))}return n}subMatrixColumn(t,e,r){if(void 0===e&&(e=0),void 0===r&&(r=this.rows-1),e>r||e<0||e>=this.rows||r<0||r>=this.rows)throw new RangeError("Argument out of range");let n=new C(r-e+1,t.length);for(let s=0;s<t.length;s++)for(let i=e;i<=r;i++){if(t[s]<0||t[s]>=this.columns)throw new RangeError(`Column index out of range: ${t[s]}`);n.set(i-e,s,this.get(i,t[s]))}return n}setSubMatrix(t,e,r){if((t=C.checkMatrix(t)).isEmpty())return this;x(this,e,e+t.rows-1,r,r+t.columns-1);for(let n=0;n<t.rows;n++)for(let s=0;s<t.columns;s++)this.set(e+n,r+s,t.get(n,s));return this}selection(t,e){!function(t,e){if(!h(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(!h(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 C(t.length,e.length);for(let n=0;n<t.length;n++){let s=t[n];for(let t=0;t<e.length;t++){let i=e[t];r.set(n,t,this.get(s,i))}}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 C(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=S(t.rows);for(let r=0;r<t.rows;++r)for(let n=0;n<t.columns;++n)e[r]+=t.get(r,n);return e}(this);case"column":return function(t){let e=S(t.columns);for(let r=0;r<t.rows;++r)for(let n=0;n<t.columns;++n)e[n]+=t.get(r,n);return e}(this);case void 0:return function(t){let e=0;for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)e+=t.get(r,n);return e}(this);default:throw new Error(`invalid option: ${t}`)}}product(t){switch(t){case"row":return function(t){let e=S(t.rows,1);for(let r=0;r<t.rows;++r)for(let n=0;n<t.columns;++n)e[r]*=t.get(r,n);return e}(this);case"column":return function(t){let e=S(t.columns,1);for(let r=0;r<t.rows;++r)for(let n=0;n<t.columns;++n)e[n]*=t.get(r,n);return e}(this);case void 0:return function(t){let e=1;for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)e*=t.get(r,n);return e}(this);default:throw new Error(`invalid option: ${t}`)}}mean(t){const e=this.sum(t);switch(t){case"row":for(let t=0;t<this.rows;t++)e[t]/=this.columns;return e;case"column":for(let t=0;t<this.columns;t++)e[t]/=this.rows;return e;case void 0:return e/this.size;default:throw new Error(`invalid option: ${t}`)}}variance(t,e={}){if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");const{unbiased:r=!0,mean:n=this.mean(t)}=e;if("boolean"!=typeof r)throw new TypeError("unbiased must be a boolean");switch(t){case"row":if(!h(n))throw new TypeError("mean must be an array");return function(t,e,r){const n=t.rows,s=t.columns,i=[];for(let o=0;o<n;o++){let n=0,h=0,a=0;for(let e=0;e<s;e++)a=t.get(o,e)-r[o],n+=a,h+=a*a;e?i.push((h-n*n/s)/(s-1)):i.push((h-n*n/s)/s)}return i}(this,r,n);case"column":if(!h(n))throw new TypeError("mean must be an array");return function(t,e,r){const n=t.rows,s=t.columns,i=[];for(let o=0;o<s;o++){let s=0,h=0,a=0;for(let e=0;e<n;e++)a=t.get(e,o)-r[o],s+=a,h+=a*a;e?i.push((h-s*s/n)/(n-1)):i.push((h-s*s/n)/n)}return i}(this,r,n);case void 0:if("number"!=typeof n)throw new TypeError("mean must be a number");return function(t,e,r){const n=t.rows,s=t.columns,i=n*s;let o=0,h=0,a=0;for(let e=0;e<n;e++)for(let n=0;n<s;n++)a=t.get(e,n)-r,o+=a,h+=a*a;return e?(h-o*o/i)/(i-1):(h-o*o/i)/i}(this,r,n);default:throw new Error(`invalid option: ${t}`)}}standardDeviation(t,e){"object"==typeof t&&(e=t,t=void 0);const r=this.variance(t,e);if(void 0===t)return Math.sqrt(r);for(let t=0;t<r.length;t++)r[t]=Math.sqrt(r[t]);return r}center(t,e={}){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(!h(r))throw new TypeError("center must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)t.set(r,n,t.get(r,n)-e[r])}(this,r),this;case"column":if(!h(r))throw new TypeError("center must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)t.set(r,n,t.get(r,n)-e[n])}(this,r),this;case void 0:if("number"!=typeof r)throw new TypeError("center must be a number");return function(t,e){for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)t.set(r,n,t.get(r,n)-e)}(this,r),this;default:throw new Error(`invalid option: ${t}`)}}scale(t,e={}){if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");let r=e.scale;switch(t){case"row":if(void 0===r)r=function(t){const e=[];for(let r=0;r<t.rows;r++){let n=0;for(let e=0;e<t.columns;e++)n+=Math.pow(t.get(r,e),2)/(t.columns-1);e.push(Math.sqrt(n))}return e}(this);else if(!h(r))throw new TypeError("scale must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)t.set(r,n,t.get(r,n)/e[r])}(this,r),this;case"column":if(void 0===r)r=function(t){const e=[];for(let r=0;r<t.columns;r++){let n=0;for(let e=0;e<t.rows;e++)n+=Math.pow(t.get(e,r),2)/(t.rows-1);e.push(Math.sqrt(n))}return e}(this);else if(!h(r))throw new TypeError("scale must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)t.set(r,n,t.get(r,n)/e[n])}(this,r),this;case void 0:if(void 0===r)r=function(t){const e=t.size-1;let r=0;for(let n=0;n<t.columns;n++)for(let s=0;s<t.rows;s++)r+=Math.pow(t.get(s,n),2)/e;return Math.sqrt(r)}(this);else if("number"!=typeof r)throw new TypeError("scale must be a number");return function(t,e){for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)t.set(r,n,t.get(r,n)/e)}(this,r),this;default:throw new Error(`invalid option: ${t}`)}}toString(t){return p(this,t)}}function N(t,e){return t-e}R.prototype.klass="Matrix","undefined"!=typeof Symbol&&(R.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return p(this)}),R.random=R.rand,R.randomInt=R.randInt,R.diagonal=R.diag,R.prototype.diagonal=R.prototype.diag,R.identity=R.eye,R.prototype.negate=R.prototype.neg,R.prototype.tensorProduct=R.prototype.kroneckerProduct;class C extends R{constructor(t,e){if(super(),C.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(!h(t))throw new TypeError("First argument must be a positive number or an array");{const r=t;if("number"!=typeof(e=(t=r.length)?r[0].length:0))throw new TypeError("Data must be a 2D array with at least one element");this.data=[];for(let n=0;n<t;n++){if(r[n].length!==e)throw new RangeError("Inconsistent array dimensions");if(!r[n].every((t=>"number"==typeof t)))throw new TypeError("Input data contains non-numeric values");this.data.push(Float64Array.from(r[n]))}}}this.rows=t,this.columns=e}set(t,e,r){return this.data[t][e]=r,this}get(t,e){return this.data[t][e]}removeRow(t){return y(this,t),this.data.splice(t,1),this.rows-=1,this}addRow(t,e){return void 0===e&&(e=t,t=this.rows),y(this,t,!0),e=Float64Array.from(b(this,e)),this.data.splice(t,0,e),this.rows+=1,this}removeColumn(t){v(this,t);for(let e=0;e<this.rows;e++){const r=new Float64Array(this.columns-1);for(let n=0;n<t;n++)r[n]=this.data[e][n];for(let n=t+1;n<this.columns;n++)r[n-1]=this.data[e][n];this.data[e]=r}return this.columns-=1,this}addColumn(t,e){void 0===e&&(e=t,t=this.columns),v(this,t,!0),e=M(this,e);for(let r=0;r<this.rows;r++){const n=new Float64Array(this.columns+1);let s=0;for(;s<t;s++)n[s]=this.data[r][s];for(n[s++]=e[r];s<this.columns+1;s++)n[s]=this.data[r][s-1];this.data[r]=n}return this.columns+=1,this}}!function(t,e){t.prototype.add=function(t){return"number"==typeof t?this.addS(t):this.addM(t)},t.prototype.addS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t);return this},t.prototype.addM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t.get(e,r));return this},t.add=function(t,r){return new e(t).add(r)},t.prototype.sub=function(t){return"number"==typeof t?this.subS(t):this.subM(t)},t.prototype.subS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t);return this},t.prototype.subM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t.get(e,r));return this},t.sub=function(t,r){return new e(t).sub(r)},t.prototype.subtract=t.prototype.sub,t.prototype.subtractS=t.prototype.subS,t.prototype.subtractM=t.prototype.subM,t.subtract=t.sub,t.prototype.mul=function(t){return"number"==typeof t?this.mulS(t):this.mulM(t)},t.prototype.mulS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t);return this},t.prototype.mulM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t.get(e,r));return this},t.mul=function(t,r){return new e(t).mul(r)},t.prototype.multiply=t.prototype.mul,t.prototype.multiplyS=t.prototype.mulS,t.prototype.multiplyM=t.prototype.mulM,t.multiply=t.mul,t.prototype.div=function(t){return"number"==typeof t?this.divS(t):this.divM(t)},t.prototype.divS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t);return this},t.prototype.divM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t.get(e,r));return this},t.div=function(t,r){return new e(t).div(r)},t.prototype.divide=t.prototype.div,t.prototype.divideS=t.prototype.divS,t.prototype.divideM=t.prototype.divM,t.divide=t.div,t.prototype.mod=function(t){return"number"==typeof t?this.modS(t):this.modM(t)},t.prototype.modS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)%t);return this},t.prototype.modM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)%t.get(e,r));return this},t.mod=function(t,r){return new e(t).mod(r)},t.prototype.modulus=t.prototype.mod,t.prototype.modulusS=t.prototype.modS,t.prototype.modulusM=t.prototype.modM,t.modulus=t.mod,t.prototype.and=function(t){return"number"==typeof t?this.andS(t):this.andM(t)},t.prototype.andS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)&t);return this},t.prototype.andM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)&t.get(e,r));return this},t.and=function(t,r){return new e(t).and(r)},t.prototype.or=function(t){return"number"==typeof t?this.orS(t):this.orM(t)},t.prototype.orS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)|t);return this},t.prototype.orM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)|t.get(e,r));return this},t.or=function(t,r){return new e(t).or(r)},t.prototype.xor=function(t){return"number"==typeof t?this.xorS(t):this.xorM(t)},t.prototype.xorS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)^t);return this},t.prototype.xorM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)^t.get(e,r));return this},t.xor=function(t,r){return new e(t).xor(r)},t.prototype.leftShift=function(t){return"number"==typeof t?this.leftShiftS(t):this.leftShiftM(t)},t.prototype.leftShiftS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)<<t);return this},t.prototype.leftShiftM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)<<t.get(e,r));return this},t.leftShift=function(t,r){return new e(t).leftShift(r)},t.prototype.signPropagatingRightShift=function(t){return"number"==typeof t?this.signPropagatingRightShiftS(t):this.signPropagatingRightShiftM(t)},t.prototype.signPropagatingRightShiftS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>t);return this},t.prototype.signPropagatingRightShiftM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>t.get(e,r));return this},t.signPropagatingRightShift=function(t,r){return new e(t).signPropagatingRightShift(r)},t.prototype.rightShift=function(t){return"number"==typeof t?this.rightShiftS(t):this.rightShiftM(t)},t.prototype.rightShiftS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>>t);return this},t.prototype.rightShiftM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>>t.get(e,r));return this},t.rightShift=function(t,r){return new e(t).rightShift(r)},t.prototype.zeroFillRightShift=t.prototype.rightShift,t.prototype.zeroFillRightShiftS=t.prototype.rightShiftS,t.prototype.zeroFillRightShiftM=t.prototype.rightShiftM,t.zeroFillRightShift=t.rightShift,t.prototype.not=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,~this.get(t,e));return this},t.not=function(t){return new e(t).not()},t.prototype.abs=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.abs(this.get(t,e)));return this},t.abs=function(t){return new e(t).abs()},t.prototype.acos=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.acos(this.get(t,e)));return this},t.acos=function(t){return new e(t).acos()},t.prototype.acosh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.acosh(this.get(t,e)));return this},t.acosh=function(t){return new e(t).acosh()},t.prototype.asin=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.asin(this.get(t,e)));return this},t.asin=function(t){return new e(t).asin()},t.prototype.asinh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.asinh(this.get(t,e)));return this},t.asinh=function(t){return new e(t).asinh()},t.prototype.atan=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.atan(this.get(t,e)));return this},t.atan=function(t){return new e(t).atan()},t.prototype.atanh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.atanh(this.get(t,e)));return this},t.atanh=function(t){return new e(t).atanh()},t.prototype.cbrt=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.cbrt(this.get(t,e)));return this},t.cbrt=function(t){return new e(t).cbrt()},t.prototype.ceil=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.ceil(this.get(t,e)));return this},t.ceil=function(t){return new e(t).ceil()},t.prototype.clz32=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.clz32(this.get(t,e)));return this},t.clz32=function(t){return new e(t).clz32()},t.prototype.cos=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.cos(this.get(t,e)));return this},t.cos=function(t){return new e(t).cos()},t.prototype.cosh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.cosh(this.get(t,e)));return this},t.cosh=function(t){return new e(t).cosh()},t.prototype.exp=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.exp(this.get(t,e)));return this},t.exp=function(t){return new e(t).exp()},t.prototype.expm1=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.expm1(this.get(t,e)));return this},t.expm1=function(t){return new e(t).expm1()},t.prototype.floor=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.floor(this.get(t,e)));return this},t.floor=function(t){return new e(t).floor()},t.prototype.fround=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.fround(this.get(t,e)));return this},t.fround=function(t){return new e(t).fround()},t.prototype.log=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log(this.get(t,e)));return this},t.log=function(t){return new e(t).log()},t.prototype.log1p=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log1p(this.get(t,e)));return this},t.log1p=function(t){return new e(t).log1p()},t.prototype.log10=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log10(this.get(t,e)));return this},t.log10=function(t){return new e(t).log10()},t.prototype.log2=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log2(this.get(t,e)));return this},t.log2=function(t){return new e(t).log2()},t.prototype.round=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.round(this.get(t,e)));return this},t.round=function(t){return new e(t).round()},t.prototype.sign=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sign(this.get(t,e)));return this},t.sign=function(t){return new e(t).sign()},t.prototype.sin=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sin(this.get(t,e)));return this},t.sin=function(t){return new e(t).sin()},t.prototype.sinh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sinh(this.get(t,e)));return this},t.sinh=function(t){return new e(t).sinh()},t.prototype.sqrt=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sqrt(this.get(t,e)));return this},t.sqrt=function(t){return new e(t).sqrt()},t.prototype.tan=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.tan(this.get(t,e)));return this},t.tan=function(t){return new e(t).tan()},t.prototype.tanh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.tanh(this.get(t,e)));return this},t.tanh=function(t){return new e(t).tanh()},t.prototype.trunc=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.trunc(this.get(t,e)));return this},t.trunc=function(t){return new e(t).trunc()},t.pow=function(t,r){return new e(t).pow(r)},t.prototype.pow=function(t){return"number"==typeof t?this.powS(t):this.powM(t)},t.prototype.powS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,Math.pow(this.get(e,r),t));return this},t.prototype.powM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,Math.pow(this.get(e,r),t.get(e,r)));return this}}(R,C);class k extends R{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]}}class I{constructor(t){let e,r,n,s,i,o,h,a,l,u=(t=k.checkMatrix(t)).clone(),c=u.rows,f=u.columns,g=new Float64Array(c),m=1;for(e=0;e<c;e++)g[e]=e;for(a=new Float64Array(c),r=0;r<f;r++){for(e=0;e<c;e++)a[e]=u.get(e,r);for(e=0;e<c;e++){for(l=Math.min(e,r),i=0,n=0;n<l;n++)i+=u.get(e,n)*a[n];a[e]-=i,u.set(e,r,a[e])}for(s=r,e=r+1;e<c;e++)Math.abs(a[e])>Math.abs(a[s])&&(s=e);if(s!==r){for(n=0;n<f;n++)o=u.get(s,n),u.set(s,n,u.get(r,n)),u.set(r,n,o);h=g[s],g[s]=g[r],g[r]=h,m=-m}if(r<c&&0!==u.get(r,r))for(e=r+1;e<c;e++)u.set(e,r,u.get(e,r)/u.get(r,r))}this.LU=u,this.pivotVector=g,this.pivotSign=m}isSingular(){let t=this.LU,e=t.columns;for(let r=0;r<e;r++)if(0===t.get(r,r))return!0;return!1}solve(t){t=C.checkMatrix(t);let e=this.LU;if(e.rows!==t.rows)throw new Error("Invalid matrix dimensions");if(this.isSingular())throw new Error("LU matrix is singular");let r,n,s,i=t.columns,o=t.subMatrixRow(this.pivotVector,0,i-1),h=e.columns;for(s=0;s<h;s++)for(r=s+1;r<h;r++)for(n=0;n<i;n++)o.set(r,n,o.get(r,n)-o.get(s,n)*e.get(r,s));for(s=h-1;s>=0;s--){for(n=0;n<i;n++)o.set(s,n,o.get(s,n)/e.get(s,s));for(r=0;r<s;r++)for(n=0;n<i;n++)o.set(r,n,o.get(r,n)-o.get(s,n)*e.get(r,s))}return o}get determinant(){let t=this.LU;if(!t.isSquare())throw new Error("Matrix must be square");let e=this.pivotSign,r=t.columns;for(let n=0;n<r;n++)e*=t.get(n,n);return e}get lowerTriangularMatrix(){let t=this.LU,e=t.rows,r=t.columns,n=new C(e,r);for(let s=0;s<e;s++)for(let e=0;e<r;e++)s>e?n.set(s,e,t.get(s,e)):s===e?n.set(s,e,1):n.set(s,e,0);return n}get upperTriangularMatrix(){let t=this.LU,e=t.rows,r=t.columns,n=new C(e,r);for(let s=0;s<e;s++)for(let e=0;e<r;e++)s<=e?n.set(s,e,t.get(s,e)):n.set(s,e,0);return n}get pivotPermutationVector(){return Array.from(this.pivotVector)}}function A(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 z{constructor(t){let e,r,n,s,i=(t=k.checkMatrix(t)).clone(),o=t.rows,h=t.columns,a=new Float64Array(h);for(n=0;n<h;n++){let t=0;for(e=n;e<o;e++)t=A(t,i.get(e,n));if(0!==t){for(i.get(n,n)<0&&(t=-t),e=n;e<o;e++)i.set(e,n,i.get(e,n)/t);for(i.set(n,n,i.get(n,n)+1),r=n+1;r<h;r++){for(s=0,e=n;e<o;e++)s+=i.get(e,n)*i.get(e,r);for(s=-s/i.get(n,n),e=n;e<o;e++)i.set(e,r,i.get(e,r)+s*i.get(e,n))}}a[n]=-t}this.QR=i,this.Rdiag=a}solve(t){t=C.checkMatrix(t);let e=this.QR,r=e.rows;if(t.rows!==r)throw new Error("Matrix row dimensions must agree");if(!this.isFullRank())throw new Error("Matrix is rank deficient");let n,s,i,o,h=t.columns,a=t.clone(),l=e.columns;for(i=0;i<l;i++)for(s=0;s<h;s++){for(o=0,n=i;n<r;n++)o+=e.get(n,i)*a.get(n,s);for(o=-o/e.get(i,i),n=i;n<r;n++)a.set(n,s,a.get(n,s)+o*e.get(n,i))}for(i=l-1;i>=0;i--){for(s=0;s<h;s++)a.set(i,s,a.get(i,s)/this.Rdiag[i]);for(n=0;n<i;n++)for(s=0;s<h;s++)a.set(n,s,a.get(n,s)-a.get(i,s)*e.get(n,i))}return a.subMatrix(0,l-1,0,h-1)}isFullRank(){let t=this.QR.columns;for(let e=0;e<t;e++)if(0===this.Rdiag[e])return!1;return!0}get upperTriangularMatrix(){let t,e,r=this.QR,n=r.columns,s=new C(n,n);for(t=0;t<n;t++)for(e=0;e<n;e++)t<e?s.set(t,e,r.get(t,e)):t===e?s.set(t,e,this.Rdiag[t]):s.set(t,e,0);return s}get orthogonalMatrix(){let t,e,r,n,s=this.QR,i=s.rows,o=s.columns,h=new C(i,o);for(r=o-1;r>=0;r--){for(t=0;t<i;t++)h.set(t,r,0);for(h.set(r,r,1),e=r;e<o;e++)if(0!==s.get(r,r)){for(n=0,t=r;t<i;t++)n+=s.get(t,r)*h.get(t,e);for(n=-n/s.get(r,r),t=r;t<i;t++)h.set(t,e,h.get(t,e)+n*s.get(t,r))}}return h}}class F{constructor(t,e={}){if((t=k.checkMatrix(t)).isEmpty())throw new Error("Matrix must be non-empty");let r=t.rows,n=t.columns;const{computeLeftSingularVectors:s=!0,computeRightSingularVectors:i=!0,autoTranspose:o=!1}=e;let h,a=Boolean(s),l=Boolean(i),u=!1;if(r<n)if(o){h=t.transpose(),r=h.rows,n=h.columns,u=!0;let e=a;a=l,l=e}else h=t.clone(),console.warn("Computing SVD on a matrix with more columns than rows. Consider enabling autoTranspose");else h=t.clone();let c=Math.min(r,n),f=Math.min(r+1,n),g=new Float64Array(f),m=new C(r,c),p=new C(n,n),d=new Float64Array(n),w=new Float64Array(r),y=new Float64Array(f);for(let t=0;t<f;t++)y[t]=t;let v=Math.min(r-1,n),b=Math.max(0,Math.min(n-2,r)),M=Math.max(v,b);for(let t=0;t<M;t++){if(t<v){g[t]=0;for(let e=t;e<r;e++)g[t]=A(g[t],h.get(e,t));if(0!==g[t]){h.get(t,t)<0&&(g[t]=-g[t]);for(let e=t;e<r;e++)h.set(e,t,h.get(e,t)/g[t]);h.set(t,t,h.get(t,t)+1)}g[t]=-g[t]}for(let e=t+1;e<n;e++){if(t<v&&0!==g[t]){let n=0;for(let s=t;s<r;s++)n+=h.get(s,t)*h.get(s,e);n=-n/h.get(t,t);for(let s=t;s<r;s++)h.set(s,e,h.get(s,e)+n*h.get(s,t))}d[e]=h.get(t,e)}if(a&&t<v)for(let e=t;e<r;e++)m.set(e,t,h.get(e,t));if(t<b){d[t]=0;for(let e=t+1;e<n;e++)d[t]=A(d[t],d[e]);if(0!==d[t]){d[t+1]<0&&(d[t]=0-d[t]);for(let e=t+1;e<n;e++)d[e]/=d[t];d[t+1]+=1}if(d[t]=-d[t],t+1<r&&0!==d[t]){for(let e=t+1;e<r;e++)w[e]=0;for(let e=t+1;e<r;e++)for(let r=t+1;r<n;r++)w[e]+=d[r]*h.get(e,r);for(let e=t+1;e<n;e++){let n=-d[e]/d[t+1];for(let s=t+1;s<r;s++)h.set(s,e,h.get(s,e)+n*w[s])}}if(l)for(let e=t+1;e<n;e++)p.set(e,t,d[e])}}let x=Math.min(n,r+1);if(v<n&&(g[v]=h.get(v,v)),r<x&&(g[x-1]=0),b+1<x&&(d[b]=h.get(b,x-1)),d[x-1]=0,a){for(let t=v;t<c;t++){for(let e=0;e<r;e++)m.set(e,t,0);m.set(t,t,1)}for(let t=v-1;t>=0;t--)if(0!==g[t]){for(let e=t+1;e<c;e++){let n=0;for(let s=t;s<r;s++)n+=m.get(s,t)*m.get(s,e);n=-n/m.get(t,t);for(let s=t;s<r;s++)m.set(s,e,m.get(s,e)+n*m.get(s,t))}for(let e=t;e<r;e++)m.set(e,t,-m.get(e,t));m.set(t,t,1+m.get(t,t));for(let e=0;e<t-1;e++)m.set(e,t,0)}else{for(let e=0;e<r;e++)m.set(e,t,0);m.set(t,t,1)}}if(l)for(let t=n-1;t>=0;t--){if(t<b&&0!==d[t])for(let e=t+1;e<n;e++){let r=0;for(let s=t+1;s<n;s++)r+=p.get(s,t)*p.get(s,e);r=-r/p.get(t+1,t);for(let s=t+1;s<n;s++)p.set(s,e,p.get(s,e)+r*p.get(s,t))}for(let e=0;e<n;e++)p.set(e,t,0);p.set(t,t,1)}let S=x-1,_=0,E=Number.EPSILON;for(;x>0;){let t,e;for(t=x-2;t>=-1&&-1!==t;t--){const e=Number.MIN_VALUE+E*Math.abs(g[t]+Math.abs(g[t+1]));if(Math.abs(d[t])<=e||Number.isNaN(d[t])){d[t]=0;break}}if(t===x-2)e=4;else{let r;for(r=x-1;r>=t&&r!==t;r--){let e=(r!==x?Math.abs(d[r]):0)+(r!==t+1?Math.abs(d[r-1]):0);if(Math.abs(g[r])<=E*e){g[r]=0;break}}r===t?e=3:r===x-1?e=1:(e=2,t=r)}switch(t++,e){case 1:{let e=d[x-2];d[x-2]=0;for(let r=x-2;r>=t;r--){let s=A(g[r],e),i=g[r]/s,o=e/s;if(g[r]=s,r!==t&&(e=-o*d[r-1],d[r-1]=i*d[r-1]),l)for(let t=0;t<n;t++)s=i*p.get(t,r)+o*p.get(t,x-1),p.set(t,x-1,-o*p.get(t,r)+i*p.get(t,x-1)),p.set(t,r,s)}break}case 2:{let e=d[t-1];d[t-1]=0;for(let n=t;n<x;n++){let s=A(g[n],e),i=g[n]/s,o=e/s;if(g[n]=s,e=-o*d[n],d[n]=i*d[n],a)for(let e=0;e<r;e++)s=i*m.get(e,n)+o*m.get(e,t-1),m.set(e,t-1,-o*m.get(e,n)+i*m.get(e,t-1)),m.set(e,n,s)}break}case 3:{const e=Math.max(Math.abs(g[x-1]),Math.abs(g[x-2]),Math.abs(d[x-2]),Math.abs(g[t]),Math.abs(d[t])),s=g[x-1]/e,i=g[x-2]/e,o=d[x-2]/e,h=g[t]/e,u=d[t]/e,c=((i+s)*(i-s)+o*o)/2,f=s*o*(s*o);let w=0;0===c&&0===f||(w=c<0?0-Math.sqrt(c*c+f):Math.sqrt(c*c+f),w=f/(c+w));let y=(h+s)*(h-s)+w,v=h*u;for(let e=t;e<x-1;e++){let s=A(y,v);0===s&&(s=Number.MIN_VALUE);let i=y/s,o=v/s;if(e!==t&&(d[e-1]=s),y=i*g[e]+o*d[e],d[e]=i*d[e]-o*g[e],v=o*g[e+1],g[e+1]=i*g[e+1],l)for(let t=0;t<n;t++)s=i*p.get(t,e)+o*p.get(t,e+1),p.set(t,e+1,-o*p.get(t,e)+i*p.get(t,e+1)),p.set(t,e,s);if(s=A(y,v),0===s&&(s=Number.MIN_VALUE),i=y/s,o=v/s,g[e]=s,y=i*d[e]+o*g[e+1],g[e+1]=-o*d[e]+i*g[e+1],v=o*d[e+1],d[e+1]=i*d[e+1],a&&e<r-1)for(let t=0;t<r;t++)s=i*m.get(t,e)+o*m.get(t,e+1),m.set(t,e+1,-o*m.get(t,e)+i*m.get(t,e+1)),m.set(t,e,s)}d[x-2]=y,_+=1;break}case 4:if(g[t]<=0&&(g[t]=g[t]<0?-g[t]:0,l))for(let e=0;e<=S;e++)p.set(e,t,-p.get(e,t));for(;t<S&&!(g[t]>=g[t+1]);){let e=g[t];if(g[t]=g[t+1],g[t+1]=e,l&&t<n-1)for(let r=0;r<n;r++)e=p.get(r,t+1),p.set(r,t+1,p.get(r,t)),p.set(r,t,e);if(a&&t<r-1)for(let n=0;n<r;n++)e=m.get(n,t+1),m.set(n,t+1,m.get(n,t)),m.set(n,t,e);t++}_=0,x--}}if(u){let t=p;p=m,m=t}this.m=r,this.n=n,this.s=g,this.U=m,this.V=p}solve(t){let e=t,r=this.threshold,n=this.s.length,s=C.zeros(n,n);for(let t=0;t<n;t++)Math.abs(this.s[t])<=r?s.set(t,t,0):s.set(t,t,1/this.s[t]);let i=this.U,o=this.rightSingularVectors,h=o.mmul(s),a=o.rows,l=i.rows,u=C.zeros(a,l);for(let t=0;t<a;t++)for(let e=0;e<l;e++){let r=0;for(let s=0;s<n;s++)r+=h.get(t,s)*i.get(e,s);u.set(t,e,r)}return u.mmul(e)}solveForDiagonal(t){return this.solve(C.diag(t))}inverse(){let t=this.V,e=this.threshold,r=t.rows,n=t.columns,s=new C(r,this.s.length);for(let i=0;i<r;i++)for(let r=0;r<n;r++)Math.abs(this.s[r])>e&&s.set(i,r,t.get(i,r)/this.s[r]);let i=this.U,o=i.rows,h=i.columns,a=new C(r,o);for(let t=0;t<r;t++)for(let e=0;e<o;e++){let r=0;for(let n=0;n<h;n++)r+=s.get(t,n)*i.get(e,n);a.set(t,e,r)}return a}get condition(){return this.s[0]/this.s[Math.min(this.m,this.n)-1]}get norm2(){return this.s[0]}get rank(){let t=Math.max(this.m,this.n)*this.s[0]*Number.EPSILON,e=0,r=this.s;for(let n=0,s=r.length;n<s;n++)r[n]>t&&e++;return e}get diagonal(){return Array.from(this.s)}get threshold(){return Number.EPSILON/2*Math.max(this.m,this.n)*this.s[0]}get leftSingularVectors(){return this.U}get rightSingularVectors(){return this.V}get diagonalMatrix(){return C.diag(this.s)}}function T(t,e,r,n,s){let i=r*n*n,o=C.eye(e.length,e.length,i);const h=s(e);let a=new Float64Array(t.x.length);for(let e=0;e<t.x.length;e++)a[e]=h(t.x[e]);let l=function(t,e,r,n,s){const i=r.length,o=t.x.length;let h=new Array(i);for(let a=0;a<i;a++){h[a]=new Array(o);let i=r.slice();i[a]+=n;let l=s(i);for(let r=0;r<o;r++)h[a][r]=e[r]-l(t.x[r])}return new C(h)}(t,a,e,n,s),u=function(t,e){const r=t.x.length;let n=new Array(r);for(let s=0;s<r;s++)n[s]=[t.y[s]-e[s]];return new C(n)}(t,a),c=function(t,e=!1){return t=k.checkMatrix(t),e?new F(t).inverse():function(t,e,r=!1){return t=k.checkMatrix(t),e=k.checkMatrix(e),r?new F(t).solve(e):t.isSquare()?new I(t).solve(e):new z(t).solve(e)}(t,C.eye(t.rows))}(o.add(l.mmul(l.transpose())));return(e=(e=new C([e])).sub(c.mmul(l).mmul(u).mul(n).transpose())).to1DArray()}function V(t,e,r={}){let{maxIterations:n=100,gradientDifference:o=.1,damping:h=0,errorTolerance:a=.01,minValues:l,maxValues:u,initialValues:c}=r;if(h<=0)throw new Error("The damping option must be a positive number");if(!t.x||!t.y)throw new Error("The data parameter must have x and y elements");if(!s(t.x)||t.x.length<2||!s(t.y)||t.y.length<2)throw new Error("The data parameter elements must be an array with more than 2 points");if(t.x.length!==t.y.length)throw new Error("The data parameter elements must have the same size");let f=c||new Array(e.length).fill(1),g=f.length;if(u=u||new Array(g).fill(Number.MAX_SAFE_INTEGER),l=l||new Array(g).fill(Number.MIN_SAFE_INTEGER),u.length!==l.length)throw new Error("minValues and maxValues must be the same size");if(!s(f))throw new Error("initialValues must be an array");let m,p=i(t,f,e),d=p<=a;for(m=0;m<n&&!d;m++){f=T(t,f,h,o,e);for(let t=0;t<g;t++)f[t]=Math.min(Math.max(l[t],f[t]),u[t]);if(p=i(t,f,e),isNaN(p))break;d=p<=a}return{parameterValues:f,parameterError:p,iterations:m}}},9378:function(t,e,r){var n=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var r in t)Object.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e.default=t,e};Object.defineProperty(e,"__esModule",{value:!0});var s=n(r(4517));function i(t,e){var r=function(r){return s.empty(t).map((function(){return s.filled(e,r)}))},n=[];return n.push(r(-1)),n.push(r(1/0)),n.push(r(0)),n}function o(t,e,r,n,s){e=Math.floor(e);var i=t[0][e],o=t[1][e];if(t[2][e],r>=o[0])return 0;for(var a=0;a<i.length;a++)if(n===i[a])return 0;return h(t,e,r,n,s)}function h(t,e,r,n,s){var i=t[0][e],o=t[1][e],h=t[2][e];if(r>=o[0])return 0;o[0]=r,i[0]=n,h[0]=s;for(var a=0,l=0;;){var u=2*a+1,c=u+1,f=t[0][0].length;if(u>=f)break;if(c>=f){if(!(o[u]>r))break;l=u}else if(o[u]>=o[c]){if(!(r<o[u]))break;l=u}else{if(!(r<o[c]))break;l=c}o[a]=o[l],i[a]=i[l],h[a]=h[l],a=l}return o[a]=r,i[a]=n,h[a]=s,1}function a(t,e,r,n){for(;2*n+1<r;){var s=2*n+1,i=s+1,o=n;if(t[o]<t[s]&&(o=s),i<r&&t[o]<t[i]&&(o=i),o===n)break;var h=t[n];t[n]=t[o],t[o]=h;var a=e[n];e[n]=e[o],e[o]=a,n=o}}e.makeHeap=i,e.rejectionSample=function(t,e,r){for(var n=s.zeros(t),i=0;i<t;i++){for(var o=!0,h=0;o;){h=s.tauRandInt(e,r);for(var a=!1,l=0;l<i;l++)if(h===n[l]){a=!0;break}a||(o=!1)}n[i]=h}return n},e.heapPush=o,e.uncheckedHeapPush=h,e.buildCandidates=function(t,e,r,n,h){for(var a=i(e,n),l=0;l<e;l++)for(var u=0;u<r;u++)if(!(t[0][l][u]<0)){var c=t[0][l][u],f=t[2][l][u],g=s.tauRand(h);o(a,l,g,c,f),o(a,c,g,l,f),t[2][l][u]=0}return a},e.deheapSort=function(t){for(var e=t[0],r=t[1],n=0;n<e.length;n++)for(var s=e[n],i=r[n],o=0;o<s.length-1;o++){var h=s.length-o-1,l=i.length-o-1,u=s[0];s[0]=s[h],s[h]=u;var c=i[0];i[0]=i[l],i[l]=c,a(i,s,l,0)}return{indices:e,weights:r}},e.smallestFlagged=function(t,e){for(var r=t[0][e],n=t[1][e],s=t[2][e],i=1/0,o=-1,h=0;h>r.length;h++)1===s[h]&&n[h]<i&&(i=n[h],o=h);return o>=0?(s[o]=0,Math.floor(r[o])):-1}},4221:(t,e,r)=>{var n=r(4364);e.u=n.UMAP},5686:function(t,e,r){var n,s=this&&this.__read||function(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var n,s,i=r.call(t),o=[];try{for(;(void 0===e||e-- >0)&&!(n=i.next()).done;)o.push(n.value)}catch(t){s={error:t}}finally{try{n&&!n.done&&(r=i.return)&&r.call(i)}finally{if(s)throw s.error}}return o},i=this&&this.__values||function(t){var e="function"==typeof Symbol&&t[Symbol.iterator],r=0;return e?e.call(t):{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}}},o=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var r in t)Object.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e.default=t,e};Object.defineProperty(e,"__esModule",{value:!0});var h=o(r(4517)),a=function(){function t(t,e,r,n){if(this.entries=new Map,this.nRows=0,this.nCols=0,t.length!==e.length||t.length!==r.length)throw new Error("rows, cols and values arrays must all have the same length");this.nRows=n[0],this.nCols=n[1];for(var s=0;s<r.length;s++){var i=t[s],o=e[s];this.checkDims(i,o);var h=this.makeKey(i,o);this.entries.set(h,{value:r[s],row:i,col:o})}}return t.prototype.makeKey=function(t,e){return t+":"+e},t.prototype.checkDims=function(t,e){if(!(t<this.nRows&&e<this.nCols))throw new Error("row and/or col specified outside of matrix dimensions")},t.prototype.set=function(t,e,r){this.checkDims(t,e);var n=this.makeKey(t,e);this.entries.has(n)?this.entries.get(n).value=r:this.entries.set(n,{value:r,row:t,col:e})},t.prototype.get=function(t,e,r){void 0===r&&(r=0),this.checkDims(t,e);var n=this.makeKey(t,e);return this.entries.has(n)?this.entries.get(n).value:r},t.prototype.getAll=function(t){void 0===t&&(t=!0);var e=[];return this.entries.forEach((function(t){e.push(t)})),t&&e.sort((function(t,e){return t.row===e.row?t.col-e.col:t.row-e.row})),e},t.prototype.getDims=function(){return[this.nRows,this.nCols]},t.prototype.getRows=function(){return Array.from(this.entries,(function(t){var e=s(t,2);return e[0],e[1].row}))},t.prototype.getCols=function(){return Array.from(this.entries,(function(t){var e=s(t,2);return e[0],e[1].col}))},t.prototype.getValues=function(){return Array.from(this.entries,(function(t){var e=s(t,2);return e[0],e[1].value}))},t.prototype.forEach=function(t){this.entries.forEach((function(e){return t(e.value,e.row,e.col)}))},t.prototype.map=function(e){var r=[];this.entries.forEach((function(t){r.push(e(t.value,t.row,t.col))}));var n=[this.nRows,this.nCols];return new t(this.getRows(),this.getCols(),r,n)},t.prototype.toArray=function(){var t=this,e=h.empty(this.nRows).map((function(){return h.zeros(t.nCols)}));return this.entries.forEach((function(t){e[t.row][t.col]=t.value})),e},t}();e.SparseMatrix=a,e.transpose=function(t){var e=[],r=[],n=[];t.forEach((function(t,s,i){e.push(s),r.push(i),n.push(t)}));var s=[t.nCols,t.nRows];return new a(r,e,n,s)},e.identity=function(t){for(var e=s(t,1)[0],r=new a([],[],[],t),n=0;n<e;n++)r.set(n,n,1);return r},e.pairwiseMultiply=function(t,e){return u(t,e,(function(t,e){return t*e}))},e.add=function(t,e){return u(t,e,(function(t,e){return t+e}))},e.subtract=function(t,e){return u(t,e,(function(t,e){return t-e}))},e.maximum=function(t,e){return u(t,e,(function(t,e){return t>e?t:e}))},e.multiplyScalar=function(t,e){return t.map((function(t){return t*e}))},e.eliminateZeros=function(t){for(var e=new Set,r=t.getValues(),n=t.getRows(),s=t.getCols(),i=0;i<r.length;i++)0===r[i]&&e.add(i);var o=function(t,r){return!e.has(r)},h=r.filter(o),l=n.filter(o),u=s.filter(o);return new a(l,u,h,t.getDims())},e.normalize=function(t,e){var r,n;void 0===e&&(e="l2");var s=l[e],o=new Map;t.forEach((function(t,e,r){var n=o.get(e)||[];n.push(r),o.set(e,n)}));var h=new a([],[],[],t.getDims()),u=function(e){for(var r=o.get(e).sort(),n=r.map((function(r){return t.get(e,r)})),i=s(n),a=0;a<i.length;a++)h.set(e,r[a],i[a])};try{for(var c=i(o.keys()),f=c.next();!f.done;f=c.next())u(f.value)}catch(t){r={error:t}}finally{try{f&&!f.done&&(n=c.return)&&n.call(c)}finally{if(r)throw r.error}}return h};var l=((n={}).max=function(t){for(var e=-1/0,r=0;r<t.length;r++)e=t[r]>e?t[r]:e;return t.map((function(t){return t/e}))},n.l1=function(t){for(var e=0,r=0;r<t.length;r++)e+=t[r];return t.map((function(t){return t/e}))},n.l2=function(t){for(var e=0,r=0;r<t.length;r++)e+=Math.pow(t[r],2);return t.map((function(t){return Math.sqrt(Math.pow(t,2)/e)}))},n);function u(t,e,r){for(var n=new Set,s=[],i=[],o=[],h=function(n,h){s.push(n),i.push(h);var a=r(t.get(n,h),e.get(n,h));o.push(a)},l=t.getValues(),u=t.getRows(),c=t.getCols(),f=0;f<l.length;f++){var g=(w=u[f])+":"+(y=c[f]);n.add(g),h(w,y)}var m=e.getValues(),p=e.getRows(),d=e.getCols();for(f=0;f<m.length;f++){var w,y;g=(w=p[f])+":"+(y=d[f]),n.has(g)||h(w,y)}var v=[t.nRows,t.nCols];return new a(s,i,o,v)}e.getCSR=function(t){var e=[];t.forEach((function(t,r,n){e.push({value:t,row:r,col:n})})),e.sort((function(t,e){return t.row===e.row?t.col-e.col:t.row-e.row}));for(var r=[],n=[],s=[],i=-1,o=0;o<e.length;o++){var h=e[o],a=h.row,l=h.col,u=h.value;a!==i&&(i=a,s.push(o)),r.push(l),n.push(u)}return{indices:r,values:n,indptr:s}}},760:function(t,e,r){var n=this&&this.__values||function(t){var e="function"==typeof Symbol&&t[Symbol.iterator],r=0;return e?e.call(t):{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}}},s=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var r in t)Object.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e.default=t,e};Object.defineProperty(e,"__esModule",{value:!0});var i=s(r(9378)),o=s(r(5686)),h=s(r(2320)),a=s(r(4517));e.makeNNDescent=function(t,e){return function(r,n,s,o,h,l,u,c){void 0===o&&(o=10),void 0===h&&(h=50),void 0===l&&(l=.001),void 0===u&&(u=.5),void 0===c&&(c=!0);for(var f=r.length,g=i.makeHeap(r.length,s),m=0;m<r.length;m++)for(var p=i.rejectionSample(s,r.length,e),d=0;d<p.length;d++){var w=t(r[m],r[p[d]]);i.heapPush(g,m,w,p[d],1),i.heapPush(g,p[d],w,m,1)}if(c)for(var y=0;y<n.length;y++)for(m=0;m<n[y].length&&!(n[y][m]<0);m++)for(d=m+1;d<n[y].length&&!(n[y][d]<0);d++)w=t(r[n[y][m]],r[n[y][d]]),i.heapPush(g,n[y][m],w,n[y][d],1),i.heapPush(g,n[y][d],w,n[y][m],1);for(y=0;y<o;y++){var v=i.buildCandidates(g,f,s,h,e),b=0;for(m=0;m<f;m++)for(d=0;d<h;d++){var M=Math.floor(v[0][m][d]);if(!(M<0||a.tauRand(e)<u))for(var x=0;x<h;x++){var S=Math.floor(v[0][m][x]),_=v[2][m][d],E=v[2][m][x];S<0||!_&&!E||(w=t(r[M],r[S]),b+=i.heapPush(g,M,w,S,1),b+=i.heapPush(g,S,w,M,1))}}if(b<=l*s*r.length)break}return i.deheapSort(g)}},e.makeInitializations=function(t){return{initFromRandom:function(e,r,n,s,o){for(var h=0;h<n.length;h++)for(var l=a.rejectionSample(e,r.length,o),u=0;u<l.length;u++)if(!(l[u]<0)){var c=t(r[l[u]],n[h]);i.heapPush(s,h,c,l[u],1)}},initFromTree:function(e,r,n,s,o){for(var a=0;a<n.length;a++)for(var l=h.searchFlatTree(n[a],e,o),u=0;u<l.length;u++){if(l[u]<0)return;var c=t(r[l[u]],n[a]);i.heapPush(s,a,c,l[u],1)}}}},e.makeInitializedNNSearch=function(t){return function(e,r,s,h){for(var a,l,u=o.getCSR(r),c=u.indices,f=u.indptr,g=0;g<h.length;g++)for(var m=new Set(s[0][g]);;){var p=i.smallestFlagged(s,g);if(-1===p)break;var d=c.slice(f[p],f[p+1]);try{for(var w=n(d),y=w.next();!y.done;y=w.next()){var v=y.value;if(v!==p&&-1!==v&&!m.has(v)){var b=t(e[v],h[g]);i.uncheckedHeapPush(s,g,b,v,1),m.add(v)}}}catch(t){a={error:t}}finally{try{y&&!y.done&&(l=w.return)&&l.call(w)}finally{if(a)throw a.error}}}return s}},e.initializeSearch=function(t,e,r,s,o,h,a){var l,u,c=i.makeHeap(r.length,s);if(o(s,e,r,c,a),t)try{for(var f=n(t),g=f.next();!g.done;g=f.next())h(g.value,e,r,c,a)}catch(t){l={error:t}}finally{try{g&&!g.done&&(u=f.return)&&u.call(f)}finally{if(l)throw l.error}}return c}},2320:function(t,e,r){var n=this&&this.__read||function(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var n,s,i=r.call(t),o=[];try{for(;(void 0===e||e-- >0)&&!(n=i.next()).done;)o.push(n.value)}catch(t){s={error:t}}finally{try{n&&!n.done&&(r=i.return)&&r.call(i)}finally{if(s)throw s.error}}return o},s=this&&this.__spread||function(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(n(arguments[e]));return t},i=this&&this.__values||function(t){var e="function"==typeof Symbol&&t[Symbol.iterator],r=0;return e?e.call(t):{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}}},o=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var r in t)Object.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e.default=t,e};Object.defineProperty(e,"__esModule",{value:!0});var h=o(r(4517)),a=function(t,e,r,n){this.hyperplanes=t,this.offsets=e,this.children=r,this.indices=n};function l(t,e,r,n,s){if(void 0===r&&(r=30),e.length>r){var i=function(t,e,r){var n=t[0].length,s=h.tauRandInt(e.length,r),i=h.tauRandInt(e.length,r);i=(i+=s===i?1:0)%e.length;for(var o=e[s],a=e[i],l=0,u=h.zeros(n),c=0;c<u.length;c++)u[c]=t[o][c]-t[a][c],l-=u[c]*(t[o][c]+t[a][c])/2;var f=0,g=0,m=h.zeros(e.length);for(c=0;c<e.length;c++){for(var p=l,d=0;d<n;d++)p+=u[d]*t[e[c]][d];0===p?(m[c]=h.tauRandInt(2,r),0===m[c]?f+=1:g+=1):p>0?(m[c]=0,f+=1):(m[c]=1,g+=1)}var w=h.zeros(f),y=h.zeros(g);for(f=0,g=0,c=0;c<m.length;c++)0===m[c]?(w[f]=e[c],f+=1):(y[g]=e[c],g+=1);return{indicesLeft:w,indicesRight:y,hyperplane:u,offset:l}}(t,e,s),o=i.indicesLeft,a=i.indicesRight,u=i.hyperplane,c=i.offset;return{leftChild:l(t,o,r,n+1,s),rightChild:l(t,a,r,n+1,s),isLeaf:!1,hyperplane:u,offset:c}}return{indices:e,isLeaf:!0}}function u(t,e,r,n,i,o,h){var a;if(t.isLeaf)return n[o][0]=-h,(a=i[h]).splice.apply(a,s([0,t.indices.length],t.indices)),{nodeNum:o,leafNum:h+=1};e[o]=t.hyperplane,r[o]=t.offset,n[o][0]=o+1;var l=o,c=u(t.leftChild,e,r,n,i,o+1,h);return o=c.nodeNum,h=c.leafNum,n[l][1]=o+1,{nodeNum:(c=u(t.rightChild,e,r,n,i,o+1,h)).nodeNum,leafNum:c.leafNum}}function c(t){return t.isLeaf?1:1+c(t.leftChild)+c(t.rightChild)}function f(t){return t.isLeaf?1:f(t.leftChild)+f(t.rightChild)}function g(t,e,r,n){for(var s=e,i=0;i<r.length;i++)s+=t[i]*r[i];return 0===s?h.tauRandInt(2,n):s>0?0:1}e.FlatTree=a,e.makeForest=function(t,e,r,n){var s=Math.max(10,e);return h.range(r).map((function(e,r){return function(t,e,r,n){return void 0===e&&(e=30),l(t,h.range(t.length),e,r,n)}(t,s,r,n)})).map((function(t){return function(t,e){var r=c(t),n=f(t),s=h.range(r).map((function(){return h.zeros(t.hyperplane?t.hyperplane.length:0)})),i=h.zeros(r),o=h.range(r).map((function(){return[-1,-1]})),l=h.range(n).map((function(){return h.range(e).map((function(){return-1}))}));return u(t,s,i,o,l,0,0),new a(s,i,o,l)}(t,s)}))},e.makeLeafArray=function(t){var e,r;if(t.length>0){var n=[];try{for(var o=i(t),h=o.next();!h.done;h=o.next()){var a=h.value;n.push.apply(n,s(a.indices))}}catch(t){e={error:t}}finally{try{h&&!h.done&&(r=o.return)&&r.call(o)}finally{if(e)throw e.error}}return n}return[[-1]]},e.searchFlatTree=function(t,e,r){for(var n=0;e.children[n][0]>0;)n=0===g(e.hyperplanes[n],e.offsets[n],t,r)?e.children[n][0]:e.children[n][1];var s=-1*e.children[n][0];return e.indices[s]}},4364:function(t,e,r){var n=this&&this.__awaiter||function(t,e,r,n){return new(r||(r=Promise))((function(s,i){function o(t){try{a(n.next(t))}catch(t){i(t)}}function h(t){try{a(n.throw(t))}catch(t){i(t)}}function a(t){t.done?s(t.value):new r((function(e){e(t.value)})).then(o,h)}a((n=n.apply(t,e||[])).next())}))},s=this&&this.__generator||function(t,e){var r,n,s,i,o={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]};return i={next:h(0),throw:h(1),return:h(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function h(i){return function(h){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;o;)try{if(r=1,n&&(s=2&i[0]?n.return:i[0]?n.throw||((s=n.return)&&s.call(n),0):n.next)&&!(s=s.call(n,i[1])).done)return s;switch(n=0,s&&(i=[2&i[0],s.value]),i[0]){case 0:case 1:s=i;break;case 4:return o.label++,{value:i[1],done:!1};case 5:o.label++,n=i[1],i=[0];continue;case 7:i=o.ops.pop(),o.trys.pop();continue;default:if(!((s=(s=o.trys).length>0&&s[s.length-1])||6!==i[0]&&2!==i[0])){o=0;continue}if(3===i[0]&&(!s||i[1]>s[0]&&i[1]<s[3])){o.label=i[1];break}if(6===i[0]&&o.label<s[1]){o.label=s[1],s=i;break}if(s&&o.label<s[2]){o.label=s[2],o.ops.push(i);break}s[2]&&o.ops.pop(),o.trys.pop();continue}i=e.call(t,o)}catch(t){i=[6,t],n=0}finally{r=s=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,h])}}},i=this&&this.__read||function(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var n,s,i=r.call(t),o=[];try{for(;(void 0===e||e-- >0)&&!(n=i.next()).done;)o.push(n.value)}catch(t){s={error:t}}finally{try{n&&!n.done&&(r=i.return)&&r.call(i)}finally{if(s)throw s.error}}return o},o=this&&this.__spread||function(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(i(arguments[e]));return t},h=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var r in t)Object.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e.default=t,e},a=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var l=h(r(9378)),u=h(r(5686)),c=h(r(760)),f=h(r(2320)),g=h(r(4517)),m=a(r(9251)),p=1e-5,d=.001,w=function(){function t(t){void 0===t&&(t={});var e=this;this.learningRate=1,this.localConnectivity=1,this.minDist=.1,this.nComponents=2,this.nEpochs=0,this.nNeighbors=15,this.negativeSampleRate=5,this.random=Math.random,this.repulsionStrength=1,this.setOpMixRatio=1,this.spread=1,this.transformQueueSize=4,this.targetMetric="categorical",this.targetWeight=.5,this.targetNNeighbors=this.nNeighbors,this.distanceFn=y,this.isInitialized=!1,this.rpForest=[],this.embedding=[],this.optimizationState=new v;var r=function(r){void 0!==t[r]&&(e[r]=t[r])};r("distanceFn"),r("learningRate"),r("localConnectivity"),r("minDist"),r("nComponents"),r("nEpochs"),r("nNeighbors"),r("negativeSampleRate"),r("random"),r("repulsionStrength"),r("setOpMixRatio"),r("spread"),r("transformQueueSize")}return t.prototype.fit=function(t){return this.initializeFit(t),this.optimizeLayout(),this.embedding},t.prototype.fitAsync=function(t,e){return void 0===e&&(e=function(){return!0}),n(this,void 0,void 0,(function(){return s(this,(function(r){switch(r.label){case 0:return this.initializeFit(t),[4,this.optimizeLayoutAsync(e)];case 1:return r.sent(),[2,this.embedding]}}))}))},t.prototype.setSupervisedProjection=function(t,e){void 0===e&&(e={}),this.Y=t,this.targetMetric=e.targetMetric||this.targetMetric,this.targetWeight=e.targetWeight||this.targetWeight,this.targetNNeighbors=e.targetNNeighbors||this.targetNNeighbors},t.prototype.setPrecomputedKNN=function(t,e){this.knnIndices=t,this.knnDistances=e},t.prototype.initializeFit=function(t){if(t.length<=this.nNeighbors)throw new Error("Not enough data points ("+t.length+") to create nNeighbors: "+this.nNeighbors+". Add more data points or adjust the configuration.");if(this.X===t&&this.isInitialized)return this.getNEpochs();if(this.X=t,!this.knnIndices&&!this.knnDistances){var e=this.nearestNeighbors(t);this.knnIndices=e.knnIndices,this.knnDistances=e.knnDistances}this.graph=this.fuzzySimplicialSet(t,this.nNeighbors,this.setOpMixRatio),this.makeSearchFns(),this.searchGraph=this.makeSearchGraph(t),this.processGraphForSupervisedProjection();var r=this.initializeSimplicialSetEmbedding(),n=r.head,s=r.tail,i=r.epochsPerSample;return this.optimizationState.head=n,this.optimizationState.tail=s,this.optimizationState.epochsPerSample=i,this.initializeOptimization(),this.prepareForOptimizationLoop(),this.isInitialized=!0,this.getNEpochs()},t.prototype.makeSearchFns=function(){var t=c.makeInitializations(this.distanceFn),e=t.initFromTree,r=t.initFromRandom;this.initFromTree=e,this.initFromRandom=r,this.search=c.makeInitializedNNSearch(this.distanceFn)},t.prototype.makeSearchGraph=function(t){for(var e=this.knnIndices,r=this.knnDistances,n=[t.length,t.length],s=new u.SparseMatrix([],[],[],n),i=0;i<e.length;i++)for(var o=e[i],h=r[i],a=0;a<o.length;a++){var l=o[a],c=h[a];c>0&&s.set(i,l,c)}var f=u.transpose(s);return u.maximum(s,f)},t.prototype.transform=function(t){var e=this,r=this.X;if(void 0===r||0===r.length)throw new Error("No data has been fit.");var n=Math.floor(this.nNeighbors*this.transformQueueSize);n=Math.min(r.length,n);var s=c.initializeSearch(this.rpForest,r,t,n,this.initFromRandom,this.initFromTree,this.random),i=this.search(r,this.searchGraph,s,t),o=l.deheapSort(i),h=o.indices,a=o.weights;h=h.map((function(t){return t.slice(0,e.nNeighbors)})),a=a.map((function(t){return t.slice(0,e.nNeighbors)}));var f=Math.max(0,this.localConnectivity-1),m=this.smoothKNNDistance(a,this.nNeighbors,f),p=m.sigmas,d=m.rhos,w=this.computeMembershipStrengths(h,a,p,d),y=w.rows,v=w.cols,b=w.vals,M=[t.length,r.length],x=new u.SparseMatrix(y,v,b,M),S=u.normalize(x,"l1"),_=u.getCSR(S),R=t.length,N=E(g.reshape2d(_.indices,R,this.nNeighbors),g.reshape2d(_.values,R,this.nNeighbors),this.embedding),C=this.nEpochs?this.nEpochs/3:x.nRows<=1e4?100:30,k=x.getValues().reduce((function(t,e){return e>t?e:t}),0);x=x.map((function(t){return t<k/C?0:t})),x=u.eliminateZeros(x);var I=this.makeEpochsPerSample(x.getValues(),C),A=x.getRows(),z=x.getCols();return this.assignOptimizationStateParameters({headEmbedding:N,tailEmbedding:this.embedding,head:A,tail:z,currentEpoch:0,nEpochs:C,nVertices:x.getDims()[1],epochsPerSample:I}),this.prepareForOptimizationLoop(),this.optimizeLayout()},t.prototype.processGraphForSupervisedProjection=function(){var t=this.Y,e=this.X;if(t){if(t.length!==e.length)throw new Error("Length of X and y must be equal");if("categorical"===this.targetMetric){var r=this.targetWeight<1?1/(1-this.targetWeight)*2.5:1e12;this.graph=this.categoricalSimplicialSetIntersection(this.graph,t,r)}}},t.prototype.step=function(){var t=this.optimizationState.currentEpoch;return t<this.getNEpochs()&&this.optimizeLayoutStep(t),this.optimizationState.currentEpoch},t.prototype.getEmbedding=function(){return this.embedding},t.prototype.nearestNeighbors=function(t){var e,r=this.distanceFn,n=this.nNeighbors,s=c.makeNNDescent(r,this.random),i=5+Math.floor(.5==(e=Math.pow(t.length,.5)/20)?0:Math.round(e)),o=Math.max(5,Math.floor(Math.round(function(t){return Math.log(t)/Math.log(2)}(t.length))));this.rpForest=f.makeForest(t,n,i,this.random);var h=s(t,f.makeLeafArray(this.rpForest),n,o);return{knnIndices:h.indices,knnDistances:h.weights}},t.prototype.fuzzySimplicialSet=function(t,e,r){void 0===r&&(r=1);var n=this,s=n.knnIndices,i=void 0===s?[]:s,o=n.knnDistances,h=void 0===o?[]:o,a=n.localConnectivity,l=this.smoothKNNDistance(h,e,a),c=l.sigmas,f=l.rhos,g=this.computeMembershipStrengths(i,h,c,f),m=g.rows,p=g.cols,d=g.vals,w=[t.length,t.length],y=new u.SparseMatrix(m,p,d,w),v=u.transpose(y),b=u.pairwiseMultiply(y,v),M=u.subtract(u.add(y,v),b),x=u.multiplyScalar(M,r),S=u.multiplyScalar(b,1-r);return u.add(x,S)},t.prototype.categoricalSimplicialSetIntersection=function(t,e,r,n){void 0===n&&(n=1);var s=S(t,e,n,r);return _(s=u.eliminateZeros(s))},t.prototype.smoothKNNDistance=function(t,e,r,n,s){void 0===r&&(r=1),void 0===n&&(n=64),void 0===s&&(s=1);for(var i=Math.log(e)/Math.log(2)*s,o=g.zeros(t.length),h=g.zeros(t.length),a=0;a<t.length;a++){var l=0,u=1/0,c=1,f=t[a],m=f.filter((function(t){return t>0}));if(m.length>=r){var w=Math.floor(r),y=r-w;w>0?(o[a]=m[w-1],y>p&&(o[a]+=y*(m[w]-m[w-1]))):o[a]=y*m[0]}else m.length>0&&(o[a]=g.max(m));for(var v=0;v<n;v++){for(var b=0,M=1;M<t[a].length;M++){var x=t[a][M]-o[a];b+=x>0?Math.exp(-x/c):1}if(Math.abs(b-i)<p)break;b>i?c=(l+(u=c))/2:(l=c,u===1/0?c*=2:c=(l+u)/2)}if(h[a]=c,o[a]>0){var S=g.mean(f);h[a]<d*S&&(h[a]=d*S)}else{var _=g.mean(t.map(g.mean));h[a]<d*_&&(h[a]=d*_)}}return{sigmas:h,rhos:o}},t.prototype.computeMembershipStrengths=function(t,e,r,n){for(var s=t.length,i=t[0].length,o=g.zeros(s*i),h=g.zeros(s*i),a=g.zeros(s*i),l=0;l<s;l++)for(var u=0;u<i;u++){var c=0;-1!==t[l][u]&&(c=t[l][u]===l?0:e[l][u]-n[l]<=0?1:Math.exp(-(e[l][u]-n[l])/r[l]),o[l*i+u]=l,h[l*i+u]=t[l][u],a[l*i+u]=c)}return{rows:o,cols:h,vals:a}},t.prototype.initializeSimplicialSetEmbedding=function(){for(var t=this,e=this.getNEpochs(),r=this.nComponents,n=this.graph.getValues(),s=0,i=0;i<n.length;i++){var o=n[i];s<n[i]&&(s=o)}var h=this.graph.map((function(t){return t<s/e?0:t}));this.embedding=g.zeros(h.nRows).map((function(){return g.zeros(r).map((function(){return 20*g.tauRand(t.random)-10}))}));var a=[],l=[],u=[],c=h.getAll();for(i=0;i<c.length;i++){var f=c[i];f.value&&(a.push(f.value),u.push(f.row),l.push(f.col))}return{head:l,tail:u,epochsPerSample:this.makeEpochsPerSample(a,e)}},t.prototype.makeEpochsPerSample=function(t,e){var r=g.filled(t.length,-1),n=g.max(t),s=t.map((function(t){return t/n*e}));return s.forEach((function(t,n){t>0&&(r[n]=e/s[n])})),r},t.prototype.assignOptimizationStateParameters=function(t){Object.assign(this.optimizationState,t)},t.prototype.prepareForOptimizationLoop=function(){var t=this,e=t.repulsionStrength,r=t.learningRate,n=t.negativeSampleRate,s=this.optimizationState,i=s.epochsPerSample,h=s.headEmbedding,a=s.tailEmbedding,l=h[0].length,u=h.length===a.length,c=i.map((function(t){return t/n})),f=o(c),g=o(i);this.assignOptimizationStateParameters({epochOfNextSample:g,epochOfNextNegativeSample:f,epochsPerNegativeSample:c,moveOther:u,initialAlpha:r,alpha:r,gamma:e,dim:l})},t.prototype.initializeOptimization=function(){var t=this.embedding,e=this.embedding,r=this.optimizationState,n=r.head,s=r.tail,i=r.epochsPerSample,o=this.getNEpochs(),h=this.graph.nCols,a=x(this.spread,this.minDist),l=a.a,u=a.b;this.assignOptimizationStateParameters({headEmbedding:t,tailEmbedding:e,head:n,tail:s,epochsPerSample:i,a:l,b:u,nEpochs:o,nVertices:h})},t.prototype.optimizeLayoutStep=function(t){for(var e=this.optimizationState,r=e.head,n=e.tail,s=e.headEmbedding,i=e.tailEmbedding,o=e.epochsPerSample,h=e.epochOfNextSample,a=e.epochOfNextNegativeSample,l=e.epochsPerNegativeSample,u=e.moveOther,c=e.initialAlpha,f=e.alpha,m=e.gamma,p=e.a,d=e.b,w=e.dim,y=e.nEpochs,v=e.nVertices,x=0;x<o.length;x++)if(!(h[x]>t)){var S=r[x],_=n[x],E=s[S],R=i[_],N=M(E,R),C=0;N>0&&(C=-2*p*d*Math.pow(N,d-1),C/=p*Math.pow(N,d)+1);for(var k=0;k<w;k++){var I=b(C*(E[k]-R[k]),4);E[k]+=I*f,u&&(R[k]+=-I*f)}h[x]+=o[x];for(var A=Math.floor((t-a[x])/l[x]),z=0;z<A;z++){var F=g.tauRandInt(v,this.random),T=i[F],V=M(E,T),P=0;if(V>0)P=2*m*d,P/=(.001+V)*(p*Math.pow(V,d)+1);else if(S===F)continue;for(k=0;k<w;k++)I=4,P>0&&(I=b(P*(E[k]-T[k]),4)),E[k]+=I*f}a[x]+=A*l[x]}return e.alpha=c*(1-t/y),e.currentEpoch+=1,s},t.prototype.optimizeLayoutAsync=function(t){var e=this;return void 0===t&&(t=function(){return!0}),new Promise((function(r,i){var o=function(){return n(e,void 0,void 0,(function(){var e,n,h,a,l,u;return s(this,(function(s){try{if(e=this.optimizationState,n=e.nEpochs,h=e.currentEpoch,this.embedding=this.optimizeLayoutStep(h),a=this.optimizationState.currentEpoch,l=!1===t(a),u=a===n,l||u)return[2,r(u)];setTimeout((function(){return o()}),0)}catch(t){i(t)}return[2]}))}))};setTimeout((function(){return o()}),0)}))},t.prototype.optimizeLayout=function(t){void 0===t&&(t=function(){return!0});for(var e=!1,r=[];!e;){var n=this.optimizationState,s=n.nEpochs,i=n.currentEpoch;r=this.optimizeLayoutStep(i);var o=this.optimizationState.currentEpoch,h=!1===t(o);e=o===s||h}return r},t.prototype.getNEpochs=function(){var t=this.graph;if(this.nEpochs>0)return this.nEpochs;var e=t.nRows;return e<=2500?500:e<=5e3?400:e<=7500?300:200},t}();function y(t,e){for(var r=0,n=0;n<t.length;n++)r+=Math.pow(t[n]-e[n],2);return Math.sqrt(r)}e.UMAP=w,e.euclidean=y,e.cosine=function(t,e){for(var r=0,n=0,s=0,i=0;i<t.length;i++)r+=t[i]*e[i],n+=Math.pow(t[i],2),s+=Math.pow(e[i],2);return 0===n&&0===s?0:0===n||0===s?1:1-r/Math.sqrt(n*s)};var v=function(){this.currentEpoch=0,this.headEmbedding=[],this.tailEmbedding=[],this.head=[],this.tail=[],this.epochsPerSample=[],this.epochOfNextSample=[],this.epochOfNextNegativeSample=[],this.epochsPerNegativeSample=[],this.moveOther=!0,this.initialAlpha=1,this.alpha=1,this.gamma=1,this.a=1.5769434603113077,this.b=.8950608779109733,this.dim=2,this.nEpochs=500,this.nVertices=0};function b(t,e){return t>e?e:t<-e?-e:t}function M(t,e){for(var r=0,n=0;n<t.length;n++)r+=Math.pow(t[n]-e[n],2);return r}function x(t,e){var r=g.linear(0,3*t,300).map((function(t){return t<e?1:t})),n=g.zeros(r.length).map((function(n,s){return r[s]>=e?Math.exp(-(r[s]-e)/t):n})),s={x:r,y:n},o=m.default(s,(function(t){var e=i(t,2),r=e[0],n=e[1];return function(t){return 1/(1+r*Math.pow(t,2*n))}}),{damping:1.5,initialValues:[.5,.5],gradientDifference:.1,maxIterations:100,errorTolerance:.01}).parameterValues,h=i(o,2);return{a:h[0],b:h[1]}}function S(t,e,r,n){return void 0===r&&(r=1),void 0===n&&(n=5),t.map((function(t,s,i){return-1===e[s]||-1===e[i]?t*Math.exp(-r):e[s]!==e[i]?t*Math.exp(-n):t}))}function _(t){t=u.normalize(t,"max");var e=u.transpose(t),r=u.pairwiseMultiply(e,t);return t=u.add(t,u.subtract(e,r)),u.eliminateZeros(t)}function E(t,e,r){for(var n=g.zeros(t.length).map((function(t){return g.zeros(r[0].length)})),s=0;s<t.length;s++)for(var i=0;i<t[0].length;i++)for(var o=0;o<r[0].length;o++){var h=t[s][i];n[s][o]+=e[s][i]*r[h][o]}return n}e.findABParams=x,e.fastIntersection=S,e.resetLocalConnectivity=_,e.initTransform=E},4517:function(t,e){var r=this&&this.__values||function(t){var e="function"==typeof Symbol&&t[Symbol.iterator],r=0;return e?e.call(t):{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}}};function n(t,e){return Math.floor(e()*t)}function s(t){for(var e=[],r=0;r<t;r++)e.push(void 0);return e}function i(t,e){return s(t).map((function(){return e}))}function o(t){return i(t,0)}function h(t){return t.reduce((function(t,e){return t+e}))}Object.defineProperty(e,"__esModule",{value:!0}),e.tauRandInt=n,e.tauRand=function(t){return t()},e.norm=function(t){var e,n,s=0;try{for(var i=r(t),o=i.next();!o.done;o=i.next()){var h=o.value;s+=Math.pow(h,2)}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}return Math.sqrt(s)},e.empty=s,e.range=function(t){return s(t).map((function(t,e){return e}))},e.filled=i,e.zeros=o,e.ones=function(t){return i(t,1)},e.linear=function(t,e,r){return s(r).map((function(n,s){return t+s*((e-t)/(r-1))}))},e.sum=h,e.mean=function(t){return h(t)/t.length},e.max=function(t){for(var e=0,r=0;r<t.length;r++)e=t[r]>e?t[r]:e;return e},e.max2d=function(t){for(var e=0,r=0;r<t.length;r++)for(var n=0;n<t[r].length;n++)e=t[r][n]>e?t[r][n]:e;return e},e.rejectionSample=function(t,e,r){for(var s=o(t),i=0;i<t;i++)for(var h=!0;h;){for(var a=n(e,r),l=!1,u=0;u<i;u++)if(a===s[u]){l=!0;break}l||(h=!1),s[i]=a}return s},e.reshape2d=function(t,e,r){var n=[],s=0;if(t.length!==e*r)throw new Error("Array dimensions must match input length.");for(var i=0;i<e;i++){for(var o=[],h=0;h<r;h++)o.push(t[s]),s+=1;n.push(o)}return n}}},e={};function r(n){var s=e[n];if(void 0!==s)return s.exports;var i=e[n]={exports:{}};return t[n].call(i.exports,i,i.exports,r),i.exports}r.d=(t,e)=>{for(var n in e)r.o(e,n)&&!r.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},(()=>{var t=r(4221),e=r(7659);class n extends Float32Array{}function s(t){return Math.random()*t}function i(t){return Math.floor(s(t))}function o(t=!1,e="Assertion error."){if(!t)throw new Error(e)}function h(t,e,r=0){return new Array(t).fill(r).map((()=>new n(e).fill(r)))}function a(t,e,r=1){const s=t.length;o(s==e.length,"Vector lengths do not match.");const i=new n(s);for(let n=0;n<t.length;++n)i[n]=t[n]+r*e[n];return i}function l(t,e,r=1){const n=h(t,e);for(let i=0;i<t;++i)for(let t=0;t<e;++t)n[i][t]=s(r);return n}function u(t,e){const r=function(t){let e=0;for(let r=0;r<t.length;++r)e+=t[r];return e}(function(t){const e=t.length,r=new n(e);for(let e=0;e<t.length;++e)r[e]=t[e]*t[e];return r}(a(t,e,-1)));return Math.sqrt(r)}function c(t,e){const r=t.length,n=h(r,r,0);for(let s=0;s<r;++s)for(let i=s+1;i<r;++i){const r=null==t[s]||null==t[i]?0:e(t[s],t[i]);n[s][i]=n[i][s]=r}return n}class f{constructor(t){var e,r,n,s,i,o,h;this.steps=null!==(e=null==t?void 0:t.steps)&&void 0!==e?e:0,this.cycles=null!==(r=null==t?void 0:t.cycles)&&void 0!==r?r:1e6,this.cutoff=null!==(n=null==t?void 0:t.cutoff)&&void 0!==n?n:0,this.lambda=null!==(s=null==t?void 0:t.lambda)&&void 0!==s?s:2,this.dlambda=null!==(i=null==t?void 0:t.dlambda)&&void 0!==i?i:.01,this.lambda2=this.lambda/2,this.dlambda2=this.dlambda/2,this.epsilon=null!==(o=null==t?void 0:t.epsilon)&&void 0!==o?o:1e-10,this.distanceFunction=null!==(h=null==t?void 0:t.distance)&&void 0!==h?h:u,this.distance=[]}initDistance(t){this.distance=c(t,this.distanceFunction)}calcDistance(t,e,r){return this.distance[e][r]}embed(t){const e=t.length,r=l(e,f.dimension,40);let n=this.lambda2;0==this.steps&&(this.steps=t.length-1),this.initDistance(t);for(let s=0;s<this.cycles;++s){for(let s=0;s<this.steps;++s){const s=i(e);let o=i(e);for(;s==o;)o=i(e);const h=r[s],l=r[o],c=this.calcDistance(t,s,o),f=u(h,l);if(0==this.cutoff||c<=this.cutoff||f<c){const t=n*(c-f)/(f+this.epsilon),e=a(h,l,-1);r[s]=a(h,e,t),r[o]=a(l,e,-t)}}if(n-=this.dlambda2,n<=0)break}return r}}f.dimension=2;class g extends f{embed(t){const e=t.length,r=l(e,g.dimension,40);let n=this.lambda;this.initDistance(t);for(let s=0;s<this.cycles;++s){const s=i(e),o=r[s];for(let i=0;i<e;++i){if(s==i)continue;const e=r[i],h=this.calcDistance(t,s,i),l=u(o,e);if(0==this.cutoff||h<=this.cutoff||l<h){const t=n*(h-l)/(l+this.epsilon),s=a(o,e,-1);r[i]=a(e,s,-t)}}if(n-=this.dlambda,n<=0)break}return r}}class m extends f{constructor(t){var e,r,n,s,i;super(t),this.cycles=null!==(e=null==t?void 0:t.cycles)&&void 0!==e?e:1e3,this.steps=null!==(r=null==t?void 0:t.steps)&&void 0!==r?r:1e5,this.radiusPercent=null!==(n=null==t?void 0:t.radiusPercent)&&void 0!==n?n:1,this.maxDistance=null!==(s=null==t?void 0:t.maxDistance)&&void 0!==s?s:null,this.maxDistanceSteps=null!==(i=null==t?void 0:t.maxDistanceSteps)&&void 0!==i?i:null}embed(t){const e=t.length,r=l(e,m.dimension,40);if(this.initDistance(t),null==this.maxDistanceSteps&&(this.maxDistanceSteps=e*Math.floor((e-1)/2)),null==this.maxDistance){this.maxDistance=-1e37;for(let r=0;r<this.maxDistanceSteps;r++){const r=i(e);let n=i(e);for(;r==n;)n=i(e);const s=this.calcDistance(t,r,n);s>this.maxDistance&&(this.maxDistance=s)}}let n=this.lambda;const s=0==this.radiusPercent?this.maxDistance:this.maxDistance*this.radiusPercent;for(let o=0;o<this.cycles;++o){for(let o=0;o<this.steps;++o){const o=i(e);let h=i(e);for(;o==h;)h=i(e);const l=r[o],c=r[h],f=this.calcDistance(t,o,h),g=u(l,c);if(f<=s||g<f){const t=.5*n*(f-g)/(g+this.epsilon),e=a(l,c,-1);r[o]=a(l,e,t),r[h]=a(c,e,-t)}}if(n-=(this.lambda-this.dlambda)/(this.cycles-1),n<this.dlambda)break}return r}}const p=new Uint32Array(65536);var d,w,y,v=r(3979);function b(t){return 1/t-1}!function(t){t.Levenshtein="Levenshtein",t.JaroWinkler="Jaro-Winkler",t.Manhattan="Manhattan"}(d||(d={})),function(t){t.Euclidean="Euclidean"}(w||(w={})),function(t){t.Tanimoto="Tanimoto",t.Dice="Dice",t.Asymmetric="Asymmetric",t.BraunBlanquet="Braun-Blanquet",t.Cosine="Cosine",t.Kulczynski="Kulczynski",t.McConnaughey="Mc-Connaughey",t.RogotGoldberg="Rogot-Goldberg",t.Russel="Russel",t.Sokal="Sokal",t.Hamming="Hamming",t.Euclidean="Euclidean"}(y||(y={}));const M={[w.Euclidean]:u},x={[d.Levenshtein]:(t,e)=>{if(t.length<e.length){const r=e;e=t,t=r}return 0===e.length?t.length:t.length<=32?((t,e)=>{const r=t.length,n=e.length,s=1<<r-1;let i=-1,o=0,h=r,a=r;for(;a--;)p[t.charCodeAt(a)]|=1<<a;for(a=0;a<n;a++){let t=p[e.charCodeAt(a)];const r=t|o;t|=(t&i)+i^i,o|=~(t|i),i&=t,o&s&&h++,i&s&&h--,o=o<<1|1,i=i<<1|~(r|o),o&=r}for(a=r;a--;)p[t.charCodeAt(a)]=0;return h})(t,e):((t,e)=>{const r=e.length,n=t.length,s=[],i=[],o=Math.ceil(r/32),h=Math.ceil(n/32);for(let t=0;t<o;t++)i[t]=-1,s[t]=0;let a=0;for(;a<h-1;a++){let o=0,h=-1;const l=32*a,u=Math.min(32,n)+l;for(let e=l;e<u;e++)p[t.charCodeAt(e)]|=1<<e;for(let t=0;t<r;t++){const r=p[e.charCodeAt(t)],n=i[t/32|0]>>>t&1,a=s[t/32|0]>>>t&1,l=r|o,u=((r|a)&h)+h^h|r|a;let c=o|~(u|h),f=h&u;c>>>31^n&&(i[t/32|0]^=1<<t),f>>>31^a&&(s[t/32|0]^=1<<t),c=c<<1|n,f=f<<1|a,h=f|~(l|c),o=c&l}for(let e=l;e<u;e++)p[t.charCodeAt(e)]=0}let l=0,u=-1;const c=32*a,f=Math.min(32,n-c)+c;for(let e=c;e<f;e++)p[t.charCodeAt(e)]|=1<<e;let g=n;for(let t=0;t<r;t++){const r=p[e.charCodeAt(t)],o=i[t/32|0]>>>t&1,h=s[t/32|0]>>>t&1,a=r|l,c=((r|h)&u)+u^u|r|h;let f=l|~(c|u),m=u&c;g+=f>>>n-1&1,g-=m>>>n-1&1,f>>>31^o&&(i[t/32|0]^=1<<t),m>>>31^h&&(s[t/32|0]^=1<<t),f=f<<1|o,m=m<<1|h,u=m|~(a|f),l=f&a}for(let e=c;e<f;e++)p[t.charCodeAt(e)]=0;return g})(t,e)},[d.JaroWinkler]:v.H$,[d.Manhattan]:function(t,e){if(t.length!==e.length)return 1;{let r=0;for(let n=1;n<t.length;n++)r+=t[n]==e[n]?0:1;return r/t.length}}},S={[y.Tanimoto]:function(t,e){return b(function(t,e){const r=t.trueCount()+e.trueCount();if(0==r)return 1;const n=t.andWithCountBits(e,!0);return n/(r-n)}(t,e))},[y.Dice]:function(t,e){return b(function(t,e){const r=t.trueCount()+e.trueCount();return 0==r?0:2*t.andWithCountBits(e,!0)/r}(t,e))},[y.Asymmetric]:function(t,e){return b(function(t,e){const r=Math.min(t.trueCount(),e.trueCount());return 0==r?0:t.andWithCountBits(e,!0)/r}(t,e))},[y.BraunBlanquet]:function(t,e){return b(function(t,e){const r=Math.max(t.trueCount(),e.trueCount());return 0==r?0:t.andWithCountBits(e,!0)/r}(t,e))},[y.Cosine]:function(t,e){return b(function(t,e){const r=t.trueCount()*e.trueCount();return 0==r?0:t.andWithCountBits(e,!0)/Math.sqrt(r)}(t,e))},[y.Kulczynski]:function(t,e){return b(function(t,e){const r=t.trueCount()+e.trueCount(),n=t.trueCount()*e.trueCount();return 0==n?0:t.andWithCountBits(e,!0)*r/(2*n)}(t,e))},[y.McConnaughey]:function(t,e){return b(function(t,e){const r=t.trueCount()+e.trueCount(),n=t.trueCount()*e.trueCount();return 0==n?0:(t.andWithCountBits(e,!0)*r-n)/n}(t,e))},[y.RogotGoldberg]:function(t,e){return b(function(t,e){const r=t.andWithCountBits(e,!0),n=t.countBits(!0)+e.countBits(!0),s=t.length,i=s-n+r;return r==s||i==s?1:r/n+i/(2*s-n)}(t,e))},[y.Russel]:function(t,e){return b(function(t,e){return 0==t.length?0:t.andWithCountBits(e,!0)/t.length}(t,e))},[y.Sokal]:function(t,e){return b(function(t,e){const r=t.trueCount()+e.trueCount(),n=t.andWithCountBits(e,!0);return n/(2*r-3*n)}(t,e))},[y.Hamming]:function(t,e){return t.trueCount()+e.trueCount()-2*t.andWithCountBits(e,!0)},[y.Euclidean]:function(t,e){return Math.sqrt(t.trueCount()+e.trueCount()-2*t.andWithCountBits(e,!0))}};var _;!function(t){t.Vector="Vector",t.String="String",t.BitArray="BitArray"}(_||(_={}));const E={[_.Vector]:{[w.Euclidean]:M[w.Euclidean]},[_.String]:{[d.Levenshtein]:x[d.Levenshtein],[d.JaroWinkler]:x[d.JaroWinkler],[d.Manhattan]:x[d.Manhattan]},[_.BitArray]:{[y.Tanimoto]:S[y.Tanimoto],[y.Dice]:S[y.Dice],[y.Asymmetric]:S[y.Asymmetric],[y.BraunBlanquet]:S[y.BraunBlanquet],[y.Cosine]:S[y.Cosine],[y.Kulczynski]:S[y.Kulczynski],[y.McConnaughey]:S[y.McConnaughey],[y.RogotGoldberg]:S[y.RogotGoldberg],[y.Russel]:S[y.Russel],[y.Sokal]:S[y.Sokal]}},R=Object.keys(E).reduce(((t,e)=>{for(const r of Object.keys(E[e]))t[r]=e;return t}),{});class N{constructor(t){this.method=t,this.dataType=R[t]}getMeasure(){return E[this.dataType][this.method]}static getMetricByDataType(t){return Object.keys(E[t])}static get availableMeasures(){return Object.keys(E)}}class C{constructor(t,e=!1){if(this._length=0,this._version=0,this._updateLevel=0,this._selectedCount=0,this._selectedCountVersion=-1,this._selectedIndexesVersion=-1,this._versionedName="",this._versionedNameVersion=-1,this.SHRINK_THRESHOLD=256,"number"==typeof t){const r=t,n=C._createBuffer(r);if(e)for(let t=0;t<n.length;t++)n[t]=-1;this._data=n,this._length=r}else{if(!(t instanceof Uint32Array))throw new Error("Invalid constructor");this._data=t,this._length=e}}getRawData(){return this._data}assureGoez(t,e){if(t<0)throw new Error(`${e} should be greater than zero`)}assureInRange(t,e,r,n){if(t<e||t>r)throw new Error(`Argument ${n} (${t}) out of range (${e}, ${r})`)}copy(t,e,r){for(let n=0;n<r;n++)e[n]=t[n]}copyFrom(t){if(this._length!=t._length)throw new Error(`Lengths differ (${this._length} != ${t._length})`);this.copy(t._data,this._data,this.lengthInInts),this._version++}get length(){return this._length}get buffer(){return this._data}set buffer(t){this._data=t,this._version++}get version(){return this._version}set version(t){this._version=t}incrementVersion(t=!0){this._version++}get lengthInInts(){return Math.floor((this._length+31)/32)}get versionedName(){return this._version==this._versionedNameVersion?this._versionedName:""}set versionedName(t){this._versionedName=t,this._versionedNameVersion=this._version}get self(){return this}setLength(t){if(t<0)throw new Error("should be >= 0");if(t==this._length)return;const e=Math.floor((t+31)/32);if(e>this._data.length||e+this.SHRINK_THRESHOLD<this._data.length){const t=new Uint32Array(e);this.copy(this._data,t,e>this._data.length?this._data.length:e),this._data=t}t>this._length&&(this._length%32>0&&(this._data[this.lengthInInts-1]&=(1<<(this._length%32&31))-1),this._data.fill(0,this.lengthInInts,e)),this._length=t,this._version++}static fromAnd(t,e){if(t._length!=e._length)throw new Error(`Lengths differ (${t._length} != ${e._length})`);const r=new C(t._length);r._length=t._length,r._data=C._createBuffer(r._length),r._version=0;const n=t.lengthInInts;for(let s=0;s<n;s++)r._data[s]=t._data[s]&e._data[s];return r}static _createBuffer(t){return new Uint32Array(Math.floor((t+31)/32))}static fromValues(t){const e=new C(t.length);e._version=0;for(let r=0;r<e._length;r++)t[r]&&(e._data[Math.floor(r/32)]|=1<<(r%32&31));return e}static fromSeq(t,e){const r=new C(t);for(let n=0;n<t;++n)r.setBit(n,e(n));return r._version=0,r}static fromString(t){return C.fromSeq(t.length,(e=>"1"==t.charAt(e)))}static fromUint32Array(t,e){const r=new C(t);return r._data=e,r}static fromBytes(t){const e=t.length,r=new C(8*e);r._data=new Uint32Array(Math.floor((e+3)/4)),r._length=8*e;let n=0,s=0;for(;e-s>=4;)r._data[n++]=255&t[s]|(255&t[s+1])<<8|(255&t[s+2])<<16|(255&t[s+3])<<24,s+=4;return e-s==3&&(r._data[n]=(255&t[s+2])<<16),e-s==2&&(r._data[n]|=(255&t[s+1])<<8),e-s==1&&(r._data[n]|=255&t[s]),r._version=0,r}toString(){return`${this._length} bits, ${this.countBits(!0)} set`}equals(t){if(this==t)return!0;if(null==t)return!1;if(this._length!=t._length)return!1;if(0==this._length)return!0;for(let e=0;e<this._data.length-1;e++)if(this._data[e]!=t._data[e])return!1;for(let e=8*(this._data.length-1);e<this._length;e++)if(this.getBit(e)!=t.getBit(e))return!1;return!0}clone(){const t=new C(0,!1);return t._data=Uint32Array.from(this._data),t._length=this._length,t._version=this._version,t}init(t,e){this.setAll(!1,!1);for(let e=0;e<this._length;e++)t(e)&&(this._data[Math.floor(e/32)]|=1<<(e%32&31));return this.incrementVersion(e),this}invert(t=!0){for(let t=0;t<this._data.length;t++)this._data[t]^=-1;this.incrementVersion(t)}setAll(t,e=!1){const r=t?-1:0,n=this.lengthInInts;for(let t=0;t<n;t++)this._data[t]=r;this.incrementVersion(e)}setIndexes(t,e=!0,r=!0,n=!0){r&&this.setAll(!e,!1);for(const r of t)this.setFast(r,e);this.incrementVersion(n)}everyIndex(t,e=!0){for(const r of t)if(this.getBit(r)!=e)return!1;return!0}anyIndex(t,e=!0){for(const r of t)if(this.getBit(r)==e)return!0;return!1}setWhere(t,e=!0,r=!0,n=!0,s=!0){if(r&&s&&this.setAll(!e,!1),s)for(let r=0;r<this._length;r++)t(r)&&this.setFast(r,e);else for(let r=0;r<this._length;r++)this.setFast(r,t(r)?e:!e);this.incrementVersion(n)}getRange(t,e){this.assureInRange(t,0,this._length-1,"from"),this.assureInRange(e,0,this._length,"to");const r=[];for(let n=t;n<e;++n)r.push(this.getBit(n));return C.fromValues(r)}getRangeAsList(t,e){this.assureInRange(t,0,this._length-1,"from"),this.assureInRange(e,0,this._length,"to");const r=[];for(let n=t;n<e;++n)r.push(this.getBit(n));return r}setRange(t,e,r,n=!0){this.assureInRange(t,0,this._length-1,"from"),this.assureInRange(e,0,this._length-1,"to");const s=Math.min(t,e),i=Math.max(t,e);if(r)for(let t=s;t<=i;t++)this.setTrue(t);else for(let t=s;t<=i;t++)this.setFalse(t);return this.incrementVersion(n),this}setRandom(t,e,r=!0){if(t<0||t>this._length)throw new Error("n must be >= 0 && <= Count");t>this._length/2&&this.setRandom(this._length-t,!e),this.setAll(!e);for(let r=0;r<t;){const t=Math.floor(Math.random()*this._length);this.getBit(t)!=e&&(this.setFast(t,e),r++)}this.incrementVersion(r)}and(t,e=!0){if(this._length!=t._length)throw new Error("Array lengths differ.");for(let e=0,r=this.lengthInInts;e<r;e++)this._data[e]&=t._data[e];return this.incrementVersion(e),this}andNot(t,e=!0){if(this._length!=t._length)throw new Error("Array lengths differ.");const r=this.lengthInInts;for(let e=0;e<r;e++)this._data[e]&=~t._data[e];return this.incrementVersion(e),this}notAnd(t,e=!0){if(this._length!=t._length)throw new Error("Array lengths differ.");for(let e=0,r=this.lengthInInts;e<r;e++)this._data[e]=~this._data[e]&t._data[e];return this.incrementVersion(e),this}not(t=!0){for(let t=0,e=this.lengthInInts;t<e;t++)this._data[t]=~this._data[t];return this.incrementVersion(t),this}or(t,e=!0){if(this._length!=t._length)throw new Error("Array lengths differ.");for(let e=0,r=this.lengthInInts;e<r;e++)this._data[e]|=t._data[e];return this.incrementVersion(e),this}xor(t,e=!0){if(this._length!=t._length)throw new Error("Array lengths differ.");for(let e=0,r=this.lengthInInts;e<r;e++)this._data[e]^=t._data[e];return this.incrementVersion(e),this}insertAt(t,e,r=!1){if(this.assureInRange(t,0,this._length,"pos"),0==e)return;const n=this._length;this.setLength(this._length+e);for(let r=n-1;r>=t;r--)this.setBit(r+e,this.getBit(r));for(let n=t;n<t+e;n++)this.setBit(n,r)}removeAt(t,e=1){if(e<0)throw new Error("n cannot be negative");if(this.assureInRange(t,0,this._length-e,"pos"),this.contains(!0))for(let r=t;r<this._length-e;r++)this.setBit(r,this.getBit(r+e));this.setLength(this._length-e)}removeByMask(t,e=!0){if(this._length!=t.length)throw new Error("length != mask.length");if(t==this)this.setLength(t.countBits(!e)),this.setAll(!e);else{let r=0;for(let n=-1;-1!=(n=t.findNext(n,!e));)this.setFast(r++,this.getBit(n));this._length=r,this._version++}return this}getBit(t){return 0!=(this._data[Math.floor(t/32)]&1<<(31&t))}setBit(t,e,r=!0){this.setFast(t,e),this._version++}setFast(t,e){e?this._data[Math.floor(t/32)]|=1<<(31&t):this._data[Math.floor(t/32)]&=~(1<<(31&t))}setTrue(t){this._data[Math.floor(t/32)]|=1<<(31&t)}setFalse(t){this._data[Math.floor(t/32)]&=~(1<<(31&t))}trueCount(){return this.countBits(!0)}falseCount(){return this.countBits(!1)}countBits(t){if(0==this._length)return 0;if(this._selectedCountVersion!=this._version){this._selectedCount=0;const t=this.lengthInInts;let e=0;for(;e<t-1;e++)for(let t=this._data[e];0!=t;t>>>=8)this._selectedCount+=C._onBitCount[255&t];let r=this._data[e];const n=31&this._length;for(0!=n&&(r&=~(4294967295<<n));0!=r;r>>>=8)this._selectedCount+=C._onBitCount[255&r];this._selectedCountVersion=this._version}return t?this._selectedCount:this._length-this._selectedCount}countWhere(t){let e=0;if(this.trueCount()==this._length)for(let r=0;r<this._length;r++)e+=t(r)?1:0;else for(let r=-1;-1!=(r=this.findNext(r,!0));)e+=t(r)?1:0;return e}andWithCountBits(t,e){if(0==this._length)return 0;let r=0;const n=this.lengthInInts;let s=0;for(;s<n-1;s++)for(let e=this._data[s]&t._data[s];0!=e;e>>>=8)r+=C._onBitCount[255&e];let i=this._data[s]&t._data[s];const o=31&this._length;for(0!=o&&(i&=~(4294967295<<o));0!=i;i>>>=8)r+=C._onBitCount[255&i];return e?r:this._length-r}clear(){this.setLength(0)}contains(t){return this.findNext(-1,t)>=0}get allTrue(){return this.countBits(!0)==this._length}get allFalse(){return this.countBits(!1)==this._length}get anyTrue(){return this.countBits(!0)>0}get anyFalse(){return this.countBits(!1)>0}findNext(t,e=!0){if(this.assureInRange(t,-1,this._length,"index"),t>=this._length-1)return-1;let r=31&(t=t<0?0:t+1);const n=this.lengthInInts;for(let s=Math.floor(t/32);s<n;s++){let n=e?this._data[s]:~this._data[s];if(0!=r)n&=4294967295<<r&4294967295,r=0;else if(!e&&-4294967296==n)continue;for(let e=0;0!=n;e+=8,n>>>=8){const r=C._firstOnBit[255&n];if(r>=0)return(t=r+32*s+e)>=this._length?-1:t}}return-1}findPrev(t,e=!0){if(0==t)return-1;this.assureInRange(t,-1,this._length,"index");let r=1+(t=t<0?this._length-1:t-1)&31;for(let n=Math.floor(t/32);n>=0;n--){let t=e?this._data[n]:~this._data[n];0!=r&&(t&=~(4294967295<<r),r=0);for(let e=24;0!=t;e-=8,t<<=8){const r=C._lastOnBit[t>>>24];if(r>=0)return r+32*n+e}}return-1}}C._onBitCount=Int8Array.from([0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,4,5,5,6,5,6,6,7,5,6,6,7,6,7,7,8]),C._firstOnBit=Int8Array.from([-1,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,6,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,7,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,6,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0]),C._lastOnBit=Int8Array.from([-1,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7]);class k{constructor(t){this.data=t.data}}const I={UMAP:class extends k{constructor(e){super(e),o("distanceFn"in e),this.distanceFn=e.distanceFn,this.vectors=[],e.distanceFn=this._encodedDistance.bind(this),this.data.length<15&&(e.nNeighbors=this.data.length-1),this.reducer=new t.u(e)}_encodedDistance(t,e){return this.distanceFn(this.data[t[0]],this.data[e[0]])}_encode(){for(let t=0;t<this.data.length;++t)this.vectors.push([t])}transform(){this._encode();const t=this.reducer.fit(this.vectors);return{embedding:(e=t,new Array(e.length).fill(0).map(((t,r)=>n.from(e[r]))))};var e}},"t-SNE":class extends k{constructor(t){var r;super(t),this.reducer=new e.Z(t),this.iterations=null!==(r=null==t?void 0:t.iterations)&&void 0!==r?r:100,this.distanceFn=t.distance}transform(){const t=c(this.data,this.distanceFn);this.reducer.initDataDist(t);for(let t=0;t<this.iterations;++t)this.reducer.step();return{distance:t,embedding:this.reducer.getSolution()}}},SPE:class extends k{constructor(t){super(t),this.reducer=new f(t)}transform(){const t=this.reducer.embed(this.data);return{distance:this.reducer.distance,embedding:t}}},pSPE:class extends k{constructor(t){super(t),this.reducer=new g(t)}transform(){const t=this.reducer.embed(this.data);return{distance:this.reducer.distance,embedding:t}}},OriginalSPE:class extends k{constructor(t){super(t),this.reducer=new m(t)}transform(){const t=this.reducer.embed(this.data);return{distance:this.reducer.distance,embedding:t}}}};class A{constructor(t,e,r,n){var s;const i=new N(r).getMeasure();let o={};if("BitArray"==R[r])for(let e=0;e<t.length;++e)t[e]=new C(t[e]._data,t[e]._length);o="UMAP"==e?Object.assign(Object.assign(Object.assign({data:t},{distanceFn:i}),{nEpochs:null==n?void 0:n.cycles}),n):"t-SNE"==e?Object.assign(Object.assign(Object.assign({data:t},{distance:i}),{iterations:null!==(s=null==n?void 0:n.cycles)&&void 0!==s?s:void 0}),n):Object.assign(Object.assign({data:t},{distance:i}),n),this.reducer=new I[e](o)}transform(t=!1){if(null==this.reducer)throw new Error("Reducer was not defined.");let{embedding:e,distance:r}=this.reducer.transform();var s;return t&&(s=e,e=new Array(s[0].length).fill(0).map(((t,e)=>new n(s.length).fill(0).map(((t,r)=>s[r][e]))))),{distance:r,embedding:e}}static availableMetricsByType(t){return Object.keys(E[t])}static get availableMethods(){return Object.keys(I)}static get availableMetrics(){let t=[];return Object.values(E).forEach((e=>{const r=Object.values(e);t=[...t,...r]})),t}}self.onmessage=({data:{columnData:t,method:e,measure:r,options:n}})=>{let s;try{s=function(t,e,r,n){return new A(t,e,r,n).transform(!0)}(t,e,r,n)}catch(t){s={error:t}}self.postMessage({error:s.error,distance:s.distance,embedding:s.embedding})}})(),bio={}})();
|
|
2
|
+
//# sourceMappingURL=153.js.map
|