@datagrok/eda 1.3.2 → 1.3.4
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 +2 -1
- package/CHANGELOG.md +8 -0
- package/dist/731.js +1 -1
- package/dist/731.js.map +1 -1
- package/dist/980.js +1 -1
- package/dist/980.js.map +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 +2 -2
- package/src/pls/pls-tools.ts +8 -16
- package/src/utils.ts +48 -2
- package/test-console-output-1.log +121 -125
- package/test-record-1.mp4 +0 -0
package/dist/package.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var eda;(()=>{var t={5540:(t,e,n)=>{"use strict";t=n.hmd(t);var r,o=(r="undefined"!=typeof document&&document.currentScript?document.currentScript.src:void 0,function(t={}){var e,n,o=void 0!==t?t:{};o.ready=new Promise((function(t,r){e=t,n=r}));var i,a=Object.assign({},o),s="object"==typeof window,u="function"==typeof importScripts,c=("object"==typeof process&&"object"==typeof process.versions&&process.versions.node,"");(s||u)&&(u?c=self.location.href:"undefined"!=typeof document&&document.currentScript&&(c=document.currentScript.src),r&&(c=r),c=0!==c.indexOf("blob:")?c.substr(0,c.replace(/[?#].*/,"").lastIndexOf("/")+1):"",u&&(i=t=>{var e=new XMLHttpRequest;return e.open("GET",t,!1),e.responseType="arraybuffer",e.send(null),new Uint8Array(e.response)})),o.print||console.log.bind(console);var l,d,h=o.printErr||console.warn.bind(console);Object.assign(o,a),a=null,o.arguments&&o.arguments,o.thisProgram&&o.thisProgram,o.quit&&o.quit,o.wasmBinary&&(l=o.wasmBinary),o.noExitRuntime,"object"!=typeof WebAssembly&&S("no native wasm support detected");var f,p,m,g=!1;function y(){var t=d.buffer;o.HEAP8=f=new Int8Array(t),o.HEAP16=new Int16Array(t),o.HEAP32=new Int32Array(t),o.HEAPU8=p=new Uint8Array(t),o.HEAPU16=new Uint16Array(t),o.HEAPU32=m=new Uint32Array(t),o.HEAPF32=new Float32Array(t),o.HEAPF64=new Float64Array(t)}var v=[],w=[],b=[],E=0,A=null,C=null;function S(t){o.onAbort&&o.onAbort(t),h(t="Aborted("+t+")"),g=!0,t+=". Build with -sASSERTIONS for more info.";var e=new WebAssembly.RuntimeError(t);throw n(e),e}var _,N;function I(t){return t.startsWith("data:application/octet-stream;base64,")}function M(t){try{if(t==_&&l)return new Uint8Array(l);if(i)return i(t);throw"both async and sync fetching of the wasm failed"}catch(t){S(t)}}function T(t,e,n){return function(t){return l||!s&&!u||"function"!=typeof fetch?Promise.resolve().then((function(){return M(t)})):fetch(t,{credentials:"same-origin"}).then((function(e){if(!e.ok)throw"failed to load wasm binary file at '"+t+"'";return e.arrayBuffer()})).catch((function(){return M(t)}))}(t).then((function(t){return WebAssembly.instantiate(t,e)})).then((function(t){return t})).then(n,(function(t){h("failed to asynchronously prepare wasm: "+t),S(t)}))}function O(t){for(;t.length>0;)t.shift()(o)}function P(t){this.excPtr=t,this.ptr=t-24,this.set_type=function(t){m[this.ptr+4>>2]=t},this.get_type=function(){return m[this.ptr+4>>2]},this.set_destructor=function(t){m[this.ptr+8>>2]=t},this.get_destructor=function(){return m[this.ptr+8>>2]},this.set_caught=function(t){t=t?1:0,f[this.ptr+12|0]=t},this.get_caught=function(){return 0!=f[this.ptr+12|0]},this.set_rethrown=function(t){t=t?1:0,f[this.ptr+13|0]=t},this.get_rethrown=function(){return 0!=f[this.ptr+13|0]},this.init=function(t,e){this.set_adjusted_ptr(0),this.set_type(t),this.set_destructor(e)},this.set_adjusted_ptr=function(t){m[this.ptr+16>>2]=t},this.get_adjusted_ptr=function(){return m[this.ptr+16>>2]},this.get_exception_ptr=function(){if(V(this.get_type()))return m[this.excPtr>>2];var t=this.get_adjusted_ptr();return 0!==t?t:this.excPtr}}function L(t){var e=d.buffer;try{return d.grow(t-e.byteLength+65535>>>16),y(),1}catch(t){}}function x(t){return o["_"+t]}I(_="wasmDbscan.wasm")||(N=_,_=o.locateFile?o.locateFile(N,c):c+N);var F="undefined"!=typeof TextDecoder?new TextDecoder("utf8"):void 0;function R(t,e,n,r,o){var i={string:t=>{var e=0;return null!=t&&0!==t&&(e=function(t){var e=function(t){for(var e=0,n=0;n<t.length;++n){var r=t.charCodeAt(n);r<=127?e++:r<=2047?e+=2:r>=55296&&r<=57343?(e+=4,++n):e+=3}return e}(t)+1,n=B(e);return function(t,e,n){!function(t,e,n,r){if(!(r>0))return 0;for(var o=n+r-1,i=0;i<t.length;++i){var a=t.charCodeAt(i);if(a>=55296&&a<=57343&&(a=65536+((1023&a)<<10)|1023&t.charCodeAt(++i)),a<=127){if(n>=o)break;e[n++]=a}else if(a<=2047){if(n+1>=o)break;e[n++]=192|a>>6,e[n++]=128|63&a}else if(a<=65535){if(n+2>=o)break;e[n++]=224|a>>12,e[n++]=128|a>>6&63,e[n++]=128|63&a}else{if(n+3>=o)break;e[n++]=240|a>>18,e[n++]=128|a>>12&63,e[n++]=128|a>>6&63,e[n++]=128|63&a}}e[n]=0}(t,p,e,n)}(t,n,e),n}(t)),e},array:t=>{var e,n,r=B(t.length);return e=t,n=r,f.set(e,n),r}},a=x(t),s=[],u=0;if(r)for(var c=0;c<r.length;c++){var l=i[n[c]];l?(0===u&&(u=k()),s[c]=l(r[c])):s[c]=r[c]}var d=a.apply(null,s);return function(t){return 0!==u&&G(u),function(t){return"string"===e?(n=t)?function(t,e,n){for(var r=e+n,o=e;t[o]&&!(o>=r);)++o;if(o-e>16&&t.buffer&&F)return F.decode(t.subarray(e,o));for(var i="";e<o;){var a=t[e++];if(128&a){var s=63&t[e++];if(192!=(224&a)){var u=63&t[e++];if((a=224==(240&a)?(15&a)<<12|s<<6|u:(7&a)<<18|s<<12|u<<6|63&t[e++])<65536)i+=String.fromCharCode(a);else{var c=a-65536;i+=String.fromCharCode(55296|c>>10,56320|1023&c)}}else i+=String.fromCharCode((31&a)<<6|s)}else i+=String.fromCharCode(a)}return i}(p,n,r):"":"boolean"===e?Boolean(t):t;var n,r}(t)}(d)}var D,U={__cxa_throw:function(t,e,n){throw new P(t).init(e,n),t},abort:function(){S("")},emscripten_memcpy_big:function(t,e,n){p.copyWithin(t,e,e+n)},emscripten_resize_heap:function(t){var e,n=p.length,r=2147483648;if((t>>>=0)>r)return!1;for(var o=1;o<=4;o*=2){var i=n*(1+.2/o);if(i=Math.min(i,t+100663296),L(Math.min(r,(e=Math.max(t,i))+(65536-e%65536)%65536)))return!0}return!1}},k=(function(){var t,e,r,i,a={env:U,wasi_snapshot_preview1:U};function s(t,e){var n,r=t.exports;return o.asm=r,d=o.asm.memory,y(),o.asm.__indirect_function_table,n=o.asm.__wasm_call_ctors,w.unshift(n),function(){if(E--,o.monitorRunDependencies&&o.monitorRunDependencies(E),0==E&&(null!==A&&(clearInterval(A),A=null),C)){var t=C;C=null,t()}}(),r}if(E++,o.monitorRunDependencies&&o.monitorRunDependencies(E),o.instantiateWasm)try{return o.instantiateWasm(a,s)}catch(t){h("Module.instantiateWasm callback failed with error: "+t),n(t)}(t=l,e=_,r=a,i=function(t){s(t.instance)},t||"function"!=typeof WebAssembly.instantiateStreaming||I(e)||"function"!=typeof fetch?T(e,r,i):fetch(e,{credentials:"same-origin"}).then((function(t){return WebAssembly.instantiateStreaming(t,r).then(i,(function(t){return h("wasm streaming compile failed: "+t),h("falling back to ArrayBuffer instantiation"),T(e,r,i)}))}))).catch(n)}(),o._dbscan=function(){return(o._dbscan=o.asm.dbscan).apply(null,arguments)},o._malloc=function(){return(o._malloc=o.asm.malloc).apply(null,arguments)},o._free=function(){return(o._free=o.asm.free).apply(null,arguments)},function(){return(k=o.asm.stackSave).apply(null,arguments)}),G=function(){return(G=o.asm.stackRestore).apply(null,arguments)},B=function(){return(B=o.asm.stackAlloc).apply(null,arguments)},V=function(){return(V=o.asm.__cxa_is_pointer_type).apply(null,arguments)};function W(){function t(){D||(D=!0,o.calledRun=!0,g||(O(w),e(o),o.onRuntimeInitialized&&o.onRuntimeInitialized(),function(){if(o.postRun)for("function"==typeof o.postRun&&(o.postRun=[o.postRun]);o.postRun.length;)t=o.postRun.shift(),b.unshift(t);var t;O(b)}()))}E>0||(function(){if(o.preRun)for("function"==typeof o.preRun&&(o.preRun=[o.preRun]);o.preRun.length;)t=o.preRun.shift(),v.unshift(t);var t;O(v)}(),E>0||(o.setStatus?(o.setStatus("Running..."),setTimeout((function(){setTimeout((function(){o.setStatus("")}),1),t()}),1)):t()))}if(o.ccall=R,o.cwrap=function(t,e,n,r){var o=!n||n.every((t=>"number"===t||"boolean"===t));return"string"!==e&&o&&!r?x(t):function(){return R(t,e,n,arguments)}},C=function t(){D||W(),D||(C=t)},o.preInit)for("function"==typeof o.preInit&&(o.preInit=[o.preInit]);o.preInit.length>0;)o.preInit.pop()();return W(),t.ready});"object"==typeof exports?t.exports=o:"function"==typeof define&&n.amdO?define([],(function(){return o})):"object"==typeof exports&&(exports.exportCppDbscanLib=o)},7939:(t,e,n)=>{"use strict";n.d(e,{A:()=>s});var r=n(1354),o=n.n(r),i=n(6314),a=n.n(i)()(o());a.push([t.id,".scatter_plot_link {\n right: 10px;\n}\n\n.cliffs_div {\n flex-grow: initial!important;\n justify-content: flex-end;\n flex-wrap: wrap;\n}\n\n.cliffs_grid {\n margin: 0!important;\n}\n\n.ml-dim-reduction-settings-input i.grok-icon.grok-font-icon-settings {\n font-size: 18px;\n position: absolute;\n height: 28px;\n}\n\n.ml-dim-reduction-settings-input i.grok-icon.grok-font-icon-settings:not(.ml-dim-reduction-column-editor-input-root i) {\n left: -20px;\n}\n.dlg-dimensionality-reduction.ui-form, .dlg-markov-clustering.ui-form, .dlg-markov-clustering.ui-form .ui-form, .dlg-dimensionality-reduction.ui-form .ui-form {\n max-width: unset;\n}\n\n.ml-dim-reduction-column-editor-input-root label {\n display: none !important;\n}\n\n.dim-reduction-dialog-form > .ui-input-root, .dim-reduction-dialog-form > div > .ui-input-root {\n margin-left: 10px;\n}\n\n.ml-dim-reduction-column-editor-input-root input, .ml-dim-reduction-column-editor-input-root select {\n margin-left: 20px !important;\n}\n\nh3.ml-dim-reduction-column-editor-input-root {\n margin: 0 !important;\n}\n\n.ml-dim-reduction-column-editor-root, .ml-dim-reduction-column-editor-header-root {\n display: flex;\n flex-direction: row;\n align-items: center;\n margin-bottom: 10px !important;\n width: 700px !important;\n}\n\n.ml-dim-reduction-column-editor-column-title {\n text-overflow: ellipsis;\n overflow: hidden;\n}\n\n.ml-dim-reduction-column-editor-header-root > h1:not(:first-child) {\n margin-left: 20px !important;\n}\n\n.ml-dim-reduction-column-editor-table-root .header > td:not(:first-child) {\n padding-left: 32px;\n}","",{version:3,sources:["webpack://./node_modules/@datagrok-libraries/ml/css/styles.css"],names:[],mappings:"AAAA;IACI,WAAW;AACf;;AAEA;IACI,4BAA4B;IAC5B,yBAAyB;IACzB,eAAe;AACnB;;AAEA;GACG,mBAAmB;AACtB;;AAEA;IACI,eAAe;IACf,kBAAkB;IAClB,YAAY;AAChB;;AAEA;IACI,WAAW;AACf;AACA;IACI,gBAAgB;AACpB;;AAEA;IACI,wBAAwB;AAC5B;;AAEA;IACI,iBAAiB;AACrB;;AAEA;IACI,4BAA4B;AAChC;;AAEA;IACI,oBAAoB;AACxB;;AAEA;IACI,aAAa;IACb,mBAAmB;IACnB,mBAAmB;IACnB,8BAA8B;IAC9B,uBAAuB;AAC3B;;AAEA;IACI,uBAAuB;IACvB,gBAAgB;AACpB;;AAEA;IACI,4BAA4B;AAChC;;AAEA;IACI,kBAAkB;AACtB",sourcesContent:[".scatter_plot_link {\n right: 10px;\n}\n\n.cliffs_div {\n flex-grow: initial!important;\n justify-content: flex-end;\n flex-wrap: wrap;\n}\n\n.cliffs_grid {\n margin: 0!important;\n}\n\n.ml-dim-reduction-settings-input i.grok-icon.grok-font-icon-settings {\n font-size: 18px;\n position: absolute;\n height: 28px;\n}\n\n.ml-dim-reduction-settings-input i.grok-icon.grok-font-icon-settings:not(.ml-dim-reduction-column-editor-input-root i) {\n left: -20px;\n}\n.dlg-dimensionality-reduction.ui-form, .dlg-markov-clustering.ui-form, .dlg-markov-clustering.ui-form .ui-form, .dlg-dimensionality-reduction.ui-form .ui-form {\n max-width: unset;\n}\n\n.ml-dim-reduction-column-editor-input-root label {\n display: none !important;\n}\n\n.dim-reduction-dialog-form > .ui-input-root, .dim-reduction-dialog-form > div > .ui-input-root {\n margin-left: 10px;\n}\n\n.ml-dim-reduction-column-editor-input-root input, .ml-dim-reduction-column-editor-input-root select {\n margin-left: 20px !important;\n}\n\nh3.ml-dim-reduction-column-editor-input-root {\n margin: 0 !important;\n}\n\n.ml-dim-reduction-column-editor-root, .ml-dim-reduction-column-editor-header-root {\n display: flex;\n flex-direction: row;\n align-items: center;\n margin-bottom: 10px !important;\n width: 700px !important;\n}\n\n.ml-dim-reduction-column-editor-column-title {\n text-overflow: ellipsis;\n overflow: hidden;\n}\n\n.ml-dim-reduction-column-editor-header-root > h1:not(:first-child) {\n margin-left: 20px !important;\n}\n\n.ml-dim-reduction-column-editor-table-root .header > td:not(:first-child) {\n padding-left: 32px;\n}"],sourceRoot:""}]);const s=a},6314:t=>{"use strict";t.exports=function(t){var e=[];return e.toString=function(){return this.map((function(e){var n="",r=void 0!==e[5];return e[4]&&(n+="@supports (".concat(e[4],") {")),e[2]&&(n+="@media ".concat(e[2]," {")),r&&(n+="@layer".concat(e[5].length>0?" ".concat(e[5]):""," {")),n+=t(e),r&&(n+="}"),e[2]&&(n+="}"),e[4]&&(n+="}"),n})).join("")},e.i=function(t,n,r,o,i){"string"==typeof t&&(t=[[null,t,void 0]]);var a={};if(r)for(var s=0;s<this.length;s++){var u=this[s][0];null!=u&&(a[u]=!0)}for(var c=0;c<t.length;c++){var l=[].concat(t[c]);r&&a[l[0]]||(void 0!==i&&(void 0===l[5]||(l[1]="@layer".concat(l[5].length>0?" ".concat(l[5]):""," {").concat(l[1],"}")),l[5]=i),n&&(l[2]?(l[1]="@media ".concat(l[2]," {").concat(l[1],"}"),l[2]=n):l[2]=n),o&&(l[4]?(l[1]="@supports (".concat(l[4],") {").concat(l[1],"}"),l[4]=o):l[4]="".concat(o)),e.push(l))}},e}},1354:t=>{"use strict";t.exports=function(t){var e=t[1],n=t[3];if(!n)return e;if("function"==typeof btoa){var r=btoa(unescape(encodeURIComponent(JSON.stringify(n)))),o="sourceMappingURL=data:application/json;charset=utf-8;base64,".concat(r),i="/*# ".concat(o," */");return[e].concat([i]).join("\n")}return[e].join("\n")}},9937:t=>{t.exports={linLogMode:!1,outboundAttractionDistribution:!1,adjustSizes:!1,edgeWeightInfluence:1,scalingRatio:1,strongGravityMode:!1,gravity:1,slowDown:1,barnesHutOptimize:!1,barnesHutTheta:.5}},1782:(t,e)=>{e.assign=function(t){t=t||{};var e,n,r,o=Array.prototype.slice.call(arguments).slice(1);for(e=0,r=o.length;e<r;e++)if(o[e])for(n in o[e])t[n]=o[e][n];return t},e.validateSettings=function(t){return"linLogMode"in t&&"boolean"!=typeof t.linLogMode?{message:"the `linLogMode` setting should be a boolean."}:"outboundAttractionDistribution"in t&&"boolean"!=typeof t.outboundAttractionDistribution?{message:"the `outboundAttractionDistribution` setting should be a boolean."}:"adjustSizes"in t&&"boolean"!=typeof t.adjustSizes?{message:"the `adjustSizes` setting should be a boolean."}:"edgeWeightInfluence"in t&&"number"!=typeof t.edgeWeightInfluence?{message:"the `edgeWeightInfluence` setting should be a number."}:!("scalingRatio"in t)||"number"==typeof t.scalingRatio&&t.scalingRatio>=0?"strongGravityMode"in t&&"boolean"!=typeof t.strongGravityMode?{message:"the `strongGravityMode` setting should be a boolean."}:!("gravity"in t)||"number"==typeof t.gravity&&t.gravity>=0?"slowDown"in t&&!("number"==typeof t.slowDown||t.slowDown>=0)?{message:"the `slowDown` setting should be a number >= 0."}:"barnesHutOptimize"in t&&"boolean"!=typeof t.barnesHutOptimize?{message:"the `barnesHutOptimize` setting should be a boolean."}:!("barnesHutTheta"in t)||"number"==typeof t.barnesHutTheta&&t.barnesHutTheta>=0?null:{message:"the `barnesHutTheta` setting should be a number >= 0."}:{message:"the `gravity` setting should be a number >= 0."}:{message:"the `scalingRatio` setting should be a number >= 0."}},e.graphToByteArrays=function(t,e){var n,r=t.order,o=t.size,i={},a=new Float32Array(10*r),s=new Float32Array(3*o);return n=0,t.forEachNode((function(t,e){i[t]=n,a[n]=e.x,a[n+1]=e.y,a[n+2]=0,a[n+3]=0,a[n+4]=0,a[n+5]=0,a[n+6]=1,a[n+7]=1,a[n+8]=e.size||1,a[n+9]=e.fixed?1:0,n+=10})),n=0,t.forEachEdge((function(t,r,o,u,c,l,d){var h=i[o],f=i[u],p=e(t,r,o,u,c,l,d);a[h+6]+=p,a[f+6]+=p,s[n]=h,s[n+1]=f,s[n+2]=p,n+=3})),{nodes:a,edges:s}},e.assignLayoutChanges=function(t,e,n){var r=0;t.updateEachNodeAttributes((function(t,o){return o.x=e[r],o.y=e[r+1],r+=10,n?n(t,o):o}))},e.readGraphPositions=function(t,e){var n=0;t.forEachNode((function(t,r){e[n]=r.x,e[n+1]=r.y,n+=10}))},e.collectLayoutChanges=function(t,e,n){for(var r=t.nodes(),o={},i=0,a=0,s=e.length;i<s;i+=10){if(n){var u=Object.assign({},t.getNodeAttributes(r[a]));u.x=e[i],u.y=e[i+1],u=n(r[a],u),o[r[a]]={x:u.x,y:u.y}}else o[r[a]]={x:e[i],y:e[i+1]};a++}return o},e.createWorker=function(t){var e=window.URL||window.webkitURL,n=t.toString(),r=e.createObjectURL(new Blob(["("+n+").call(this);"],{type:"text/javascript"})),o=new Worker(r);return e.revokeObjectURL(r),o}},8903:(t,e,n)=>{var r=n(1736),o=n(8153).Fd,i=n(2561),a=n(1782),s=n(9937);function u(t,e,n){if(!r(e))throw new Error("graphology-layout-forceatlas2: the given graph is not a valid graphology instance.");"number"==typeof n&&(n={iterations:n});var u=n.iterations;if("number"!=typeof u)throw new Error("graphology-layout-forceatlas2: invalid number of iterations.");if(u<=0)throw new Error("graphology-layout-forceatlas2: you should provide a positive number of iterations.");var c=o("getEdgeWeight"in n?n.getEdgeWeight:"weight").fromEntry,l="function"==typeof n.outputReducer?n.outputReducer:null,d=a.assign({},s,n.settings),h=a.validateSettings(d);if(h)throw new Error("graphology-layout-forceatlas2: "+h.message);var f,p=a.graphToByteArrays(e,c);for(f=0;f<u;f++)i(d,p.nodes,p.edges);if(!t)return a.collectLayoutChanges(e,p.nodes);a.assignLayoutChanges(e,p.nodes,l)}var c=u.bind(null,!1);c.assign=u.bind(null,!0),c.inferSettings=function(t){var e="number"==typeof t?t:t.order;return{barnesHutOptimize:e>2e3,strongGravityMode:!0,gravity:.05,scalingRatio:10,slowDown:1+Math.log(e)}},t.exports=c},2561:t=>{var e=10;t.exports=function(t,n,r){var o,i,a,s,u,c,l,d,h,f,p,m,g,y,v,w,b,E,A,C,S,_,N,I=n.length,M=r.length,T=t.adjustSizes,O=t.barnesHutTheta*t.barnesHutTheta,P=[];for(a=0;a<I;a+=e)n[a+4]=n[a+2],n[a+5]=n[a+3],n[a+2]=0,n[a+3]=0;if(t.outboundAttractionDistribution){for(p=0,a=0;a<I;a+=e)p+=n[a+6];p/=I/e}if(t.barnesHutOptimize){var L,x,F,R=1/0,D=-1/0,U=1/0,k=-1/0;for(a=0;a<I;a+=e)R=Math.min(R,n[a+0]),D=Math.max(D,n[a+0]),U=Math.min(U,n[a+1]),k=Math.max(k,n[a+1]);var G=D-R,B=k-U;for(G>B?k=(U-=(G-B)/2)+G:D=(R-=(B-G)/2)+B,P[0]=-1,P[1]=(R+D)/2,P[2]=(U+k)/2,P[3]=Math.max(D-R,k-U),P[4]=-1,P[5]=-1,P[6]=0,P[7]=0,P[8]=0,o=1,a=0;a<I;a+=e)for(i=0,F=3;;){if(!(P[i+5]>=0)){if(P[i+0]<0){P[i+0]=a;break}if(P[i+5]=9*o,d=P[i+3]/2,P[(h=P[i+5])+0]=-1,P[h+1]=P[i+1]-d,P[h+2]=P[i+2]-d,P[h+3]=d,P[h+4]=h+9,P[h+5]=-1,P[h+6]=0,P[h+7]=0,P[h+8]=0,P[(h+=9)+0]=-1,P[h+1]=P[i+1]-d,P[h+2]=P[i+2]+d,P[h+3]=d,P[h+4]=h+9,P[h+5]=-1,P[h+6]=0,P[h+7]=0,P[h+8]=0,P[(h+=9)+0]=-1,P[h+1]=P[i+1]+d,P[h+2]=P[i+2]-d,P[h+3]=d,P[h+4]=h+9,P[h+5]=-1,P[h+6]=0,P[h+7]=0,P[h+8]=0,P[(h+=9)+0]=-1,P[h+1]=P[i+1]+d,P[h+2]=P[i+2]+d,P[h+3]=d,P[h+4]=P[i+4],P[h+5]=-1,P[h+6]=0,P[h+7]=0,P[h+8]=0,o+=4,L=n[P[i+0]+0]<P[i+1]?n[P[i+0]+1]<P[i+2]?P[i+5]:P[i+5]+9:n[P[i+0]+1]<P[i+2]?P[i+5]+18:P[i+5]+27,P[i+6]=n[P[i+0]+6],P[i+7]=n[P[i+0]+0],P[i+8]=n[P[i+0]+1],P[L+0]=P[i+0],P[i+0]=-1,L===(x=n[a+0]<P[i+1]?n[a+1]<P[i+2]?P[i+5]:P[i+5]+9:n[a+1]<P[i+2]?P[i+5]+18:P[i+5]+27)){if(F--){i=L;continue}F=3;break}P[x+0]=a;break}L=n[a+0]<P[i+1]?n[a+1]<P[i+2]?P[i+5]:P[i+5]+9:n[a+1]<P[i+2]?P[i+5]+18:P[i+5]+27,P[i+7]=(P[i+7]*P[i+6]+n[a+0]*n[a+6])/(P[i+6]+n[a+6]),P[i+8]=(P[i+8]*P[i+6]+n[a+1]*n[a+6])/(P[i+6]+n[a+6]),P[i+6]+=n[a+6],i=L}}if(t.barnesHutOptimize){for(m=t.scalingRatio,a=0;a<I;a+=e)for(i=0;;)if(P[i+5]>=0){if(w=Math.pow(n[a+0]-P[i+7],2)+Math.pow(n[a+1]-P[i+8],2),4*(f=P[i+3])*f/w<O){if(g=n[a+0]-P[i+7],y=n[a+1]-P[i+8],!0===T?w>0?(b=m*n[a+6]*P[i+6]/w,n[a+2]+=g*b,n[a+3]+=y*b):w<0&&(b=-m*n[a+6]*P[i+6]/Math.sqrt(w),n[a+2]+=g*b,n[a+3]+=y*b):w>0&&(b=m*n[a+6]*P[i+6]/w,n[a+2]+=g*b,n[a+3]+=y*b),(i=P[i+4])<0)break;continue}i=P[i+5]}else if((c=P[i+0])>=0&&c!==a&&(w=(g=n[a+0]-n[c+0])*g+(y=n[a+1]-n[c+1])*y,!0===T?w>0?(b=m*n[a+6]*n[c+6]/w,n[a+2]+=g*b,n[a+3]+=y*b):w<0&&(b=-m*n[a+6]*n[c+6]/Math.sqrt(w),n[a+2]+=g*b,n[a+3]+=y*b):w>0&&(b=m*n[a+6]*n[c+6]/w,n[a+2]+=g*b,n[a+3]+=y*b)),(i=P[i+4])<0)break}else for(m=t.scalingRatio,s=0;s<I;s+=e)for(u=0;u<s;u+=e)g=n[s+0]-n[u+0],y=n[s+1]-n[u+1],!0===T?(w=Math.sqrt(g*g+y*y)-n[s+8]-n[u+8])>0?(b=m*n[s+6]*n[u+6]/w/w,n[s+2]+=g*b,n[s+3]+=y*b,n[u+2]-=g*b,n[u+3]-=y*b):w<0&&(b=100*m*n[s+6]*n[u+6],n[s+2]+=g*b,n[s+3]+=y*b,n[u+2]-=g*b,n[u+3]-=y*b):(w=Math.sqrt(g*g+y*y))>0&&(b=m*n[s+6]*n[u+6]/w/w,n[s+2]+=g*b,n[s+3]+=y*b,n[u+2]-=g*b,n[u+3]-=y*b);for(h=t.gravity/t.scalingRatio,m=t.scalingRatio,a=0;a<I;a+=e)b=0,g=n[a+0],y=n[a+1],w=Math.sqrt(Math.pow(g,2)+Math.pow(y,2)),t.strongGravityMode?w>0&&(b=m*n[a+6]*h):w>0&&(b=m*n[a+6]*h/w),n[a+2]-=g*b,n[a+3]-=y*b;for(m=1*(t.outboundAttractionDistribution?p:1),l=0;l<M;l+=3)s=r[l+0],u=r[l+1],d=r[l+2],v=Math.pow(d,t.edgeWeightInfluence),g=n[s+0]-n[u+0],y=n[s+1]-n[u+1],!0===T?(w=Math.sqrt(g*g+y*y)-n[s+8]-n[u+8],t.linLogMode?t.outboundAttractionDistribution?w>0&&(b=-m*v*Math.log(1+w)/w/n[s+6]):w>0&&(b=-m*v*Math.log(1+w)/w):t.outboundAttractionDistribution?w>0&&(b=-m*v/n[s+6]):w>0&&(b=-m*v)):(w=Math.sqrt(Math.pow(g,2)+Math.pow(y,2)),t.linLogMode?t.outboundAttractionDistribution?w>0&&(b=-m*v*Math.log(1+w)/w/n[s+6]):w>0&&(b=-m*v*Math.log(1+w)/w):t.outboundAttractionDistribution?(w=1,b=-m*v/n[s+6]):(w=1,b=-m*v)),w>0&&(n[s+2]+=g*b,n[s+3]+=y*b,n[u+2]-=g*b,n[u+3]-=y*b);if(!0===T)for(a=0;a<I;a+=e)1!==n[a+9]&&((E=Math.sqrt(Math.pow(n[a+2],2)+Math.pow(n[a+3],2)))>10&&(n[a+2]=10*n[a+2]/E,n[a+3]=10*n[a+3]/E),A=n[a+6]*Math.sqrt((n[a+4]-n[a+2])*(n[a+4]-n[a+2])+(n[a+5]-n[a+3])*(n[a+5]-n[a+3])),C=Math.sqrt((n[a+4]+n[a+2])*(n[a+4]+n[a+2])+(n[a+5]+n[a+3])*(n[a+5]+n[a+3]))/2,S=.1*Math.log(1+C)/(1+Math.sqrt(A)),_=n[a+0]+n[a+2]*(S/t.slowDown),n[a+0]=_,N=n[a+1]+n[a+3]*(S/t.slowDown),n[a+1]=N);else for(a=0;a<I;a+=e)1!==n[a+9]&&(A=n[a+6]*Math.sqrt((n[a+4]-n[a+2])*(n[a+4]-n[a+2])+(n[a+5]-n[a+3])*(n[a+5]-n[a+3])),C=Math.sqrt((n[a+4]+n[a+2])*(n[a+4]+n[a+2])+(n[a+5]+n[a+3])*(n[a+5]+n[a+3]))/2,S=n[a+7]*Math.log(1+C)/(1+Math.sqrt(A)),n[a+7]=Math.min(1,Math.sqrt(S*(Math.pow(n[a+2],2)+Math.pow(n[a+3],2))/(1+Math.sqrt(A)))),_=n[a+0]+n[a+2]*(S/t.slowDown),n[a+0]=_,N=n[a+1]+n[a+3]*(S/t.slowDown),n[a+1]=N);return{}}},8153:(t,e)=>{function n(t){return"number"!=typeof t||isNaN(t)?1:t}e.Fd=function(t){return function(t,e){var n={},r=function(t){return void 0===t?e:t};"function"==typeof e&&(r=e);var o=function(e){return r(e[t])},i=function(){return r(void 0)};return"string"==typeof t?(n.fromAttributes=o,n.fromGraph=function(t,e){return o(t.getEdgeAttributes(e))},n.fromEntry=function(t,e){return o(e)},n.fromPartialEntry=n.fromEntry,n.fromMinimalEntry=n.fromEntry):"function"==typeof t?(n.fromAttributes=function(){throw new Error("graphology-utils/getters/createEdgeValueGetter: irrelevant usage.")},n.fromGraph=function(e,n){var o=e.extremities(n);return r(t(n,e.getEdgeAttributes(n),o[0],o[1],e.getNodeAttributes(o[0]),e.getNodeAttributes(o[1]),e.isUndirected(n)))},n.fromEntry=function(e,n,o,i,a,s,u){return r(t(e,n,o,i,a,s,u))},n.fromPartialEntry=function(e,n,o,i){return r(t(e,n,o,i))},n.fromMinimalEntry=function(e,n){return r(t(e,n))}):(n.fromAttributes=i,n.fromGraph=i,n.fromEntry=i,n.fromMinimalEntry=i),n}(t,n)}},1736:t=>{t.exports=function(t){return null!==t&&"object"==typeof t&&"function"==typeof t.addUndirectedEdgeWithKey&&"function"==typeof t.dropNode&&"boolean"==typeof t.multi}},934:function(t){t.exports=function(){"use strict";function t(e){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(e)}function e(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,r(t,e)}function n(t){return n=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},n(t)}function r(t,e){return r=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},r(t,e)}function o(t,e,n){return o=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}()?Reflect.construct.bind():function(t,e,n){var o=[null];o.push.apply(o,e);var i=new(Function.bind.apply(t,o));return n&&r(i,n.prototype),i},o.apply(null,arguments)}function i(t){var e="function"==typeof Map?new Map:void 0;return i=function(t){if(null===t||(i=t,-1===Function.toString.call(i).indexOf("[native code]")))return t;var i;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,a)}function a(){return o(t,arguments,n(this).constructor)}return a.prototype=Object.create(t.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}}),r(a,t)},i(t)}function a(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}var s=function(){for(var t=arguments[0],e=1,n=arguments.length;e<n;e++)if(arguments[e])for(var r in arguments[e])t[r]=arguments[e][r];return t};function u(t,e,n,r){var o=t._nodes.get(e),i=null;return o?i="mixed"===r?o.out&&o.out[n]||o.undirected&&o.undirected[n]:"directed"===r?o.out&&o.out[n]:o.undirected&&o.undirected[n]:i}function c(e){return"object"===t(e)&&null!==e}function l(t){var e;for(e in t)return!1;return!0}function d(t,e,n){Object.defineProperty(t,e,{enumerable:!1,configurable:!1,writable:!0,value:n})}function h(t,e,n){var r={enumerable:!0,configurable:!0};"function"==typeof n?r.get=n:(r.value=n,r.writable=!1),Object.defineProperty(t,e,r)}function f(t){return!(!c(t)||t.attributes&&!Array.isArray(t.attributes))}"function"==typeof Object.assign&&(s=Object.assign);var p,m={exports:{}},g="object"==typeof Reflect?Reflect:null,y=g&&"function"==typeof g.apply?g.apply:function(t,e,n){return Function.prototype.apply.call(t,e,n)};p=g&&"function"==typeof g.ownKeys?g.ownKeys:Object.getOwnPropertySymbols?function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:function(t){return Object.getOwnPropertyNames(t)};var v=Number.isNaN||function(t){return t!=t};function w(){w.init.call(this)}m.exports=w,m.exports.once=function(t,e){return new Promise((function(n,r){function o(n){t.removeListener(e,i),r(n)}function i(){"function"==typeof t.removeListener&&t.removeListener("error",o),n([].slice.call(arguments))}T(t,e,i,{once:!0}),"error"!==e&&function(t,e){"function"==typeof t.on&&T(t,"error",e,{once:!0})}(t,o)}))},w.EventEmitter=w,w.prototype._events=void 0,w.prototype._eventsCount=0,w.prototype._maxListeners=void 0;var b=10;function E(t){if("function"!=typeof t)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t)}function A(t){return void 0===t._maxListeners?w.defaultMaxListeners:t._maxListeners}function C(t,e,n,r){var o,i,a,s;if(E(n),void 0===(i=t._events)?(i=t._events=Object.create(null),t._eventsCount=0):(void 0!==i.newListener&&(t.emit("newListener",e,n.listener?n.listener:n),i=t._events),a=i[e]),void 0===a)a=i[e]=n,++t._eventsCount;else if("function"==typeof a?a=i[e]=r?[n,a]:[a,n]:r?a.unshift(n):a.push(n),(o=A(t))>0&&a.length>o&&!a.warned){a.warned=!0;var u=new Error("Possible EventEmitter memory leak detected. "+a.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");u.name="MaxListenersExceededWarning",u.emitter=t,u.type=e,u.count=a.length,s=u,console&&console.warn&&console.warn(s)}return t}function S(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,0===arguments.length?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function _(t,e,n){var r={fired:!1,wrapFn:void 0,target:t,type:e,listener:n},o=S.bind(r);return o.listener=n,r.wrapFn=o,o}function N(t,e,n){var r=t._events;if(void 0===r)return[];var o=r[e];return void 0===o?[]:"function"==typeof o?n?[o.listener||o]:[o]:n?function(t){for(var e=new Array(t.length),n=0;n<e.length;++n)e[n]=t[n].listener||t[n];return e}(o):M(o,o.length)}function I(t){var e=this._events;if(void 0!==e){var n=e[t];if("function"==typeof n)return 1;if(void 0!==n)return n.length}return 0}function M(t,e){for(var n=new Array(e),r=0;r<e;++r)n[r]=t[r];return n}function T(t,e,n,r){if("function"==typeof t.on)r.once?t.once(e,n):t.on(e,n);else{if("function"!=typeof t.addEventListener)throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof t);t.addEventListener(e,(function o(i){r.once&&t.removeEventListener(e,o),n(i)}))}}function O(t){if("function"!=typeof t)throw new Error("obliterator/iterator: expecting a function!");this.next=t}Object.defineProperty(w,"defaultMaxListeners",{enumerable:!0,get:function(){return b},set:function(t){if("number"!=typeof t||t<0||v(t))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+t+".");b=t}}),w.init=function(){void 0!==this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},w.prototype.setMaxListeners=function(t){if("number"!=typeof t||t<0||v(t))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+t+".");return this._maxListeners=t,this},w.prototype.getMaxListeners=function(){return A(this)},w.prototype.emit=function(t){for(var e=[],n=1;n<arguments.length;n++)e.push(arguments[n]);var r="error"===t,o=this._events;if(void 0!==o)r=r&&void 0===o.error;else if(!r)return!1;if(r){var i;if(e.length>0&&(i=e[0]),i instanceof Error)throw i;var a=new Error("Unhandled error."+(i?" ("+i.message+")":""));throw a.context=i,a}var s=o[t];if(void 0===s)return!1;if("function"==typeof s)y(s,this,e);else{var u=s.length,c=M(s,u);for(n=0;n<u;++n)y(c[n],this,e)}return!0},w.prototype.addListener=function(t,e){return C(this,t,e,!1)},w.prototype.on=w.prototype.addListener,w.prototype.prependListener=function(t,e){return C(this,t,e,!0)},w.prototype.once=function(t,e){return E(e),this.on(t,_(this,t,e)),this},w.prototype.prependOnceListener=function(t,e){return E(e),this.prependListener(t,_(this,t,e)),this},w.prototype.removeListener=function(t,e){var n,r,o,i,a;if(E(e),void 0===(r=this._events))return this;if(void 0===(n=r[t]))return this;if(n===e||n.listener===e)0==--this._eventsCount?this._events=Object.create(null):(delete r[t],r.removeListener&&this.emit("removeListener",t,n.listener||e));else if("function"!=typeof n){for(o=-1,i=n.length-1;i>=0;i--)if(n[i]===e||n[i].listener===e){a=n[i].listener,o=i;break}if(o<0)return this;0===o?n.shift():function(t,e){for(;e+1<t.length;e++)t[e]=t[e+1];t.pop()}(n,o),1===n.length&&(r[t]=n[0]),void 0!==r.removeListener&&this.emit("removeListener",t,a||e)}return this},w.prototype.off=w.prototype.removeListener,w.prototype.removeAllListeners=function(t){var e,n,r;if(void 0===(n=this._events))return this;if(void 0===n.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==n[t]&&(0==--this._eventsCount?this._events=Object.create(null):delete n[t]),this;if(0===arguments.length){var o,i=Object.keys(n);for(r=0;r<i.length;++r)"removeListener"!==(o=i[r])&&this.removeAllListeners(o);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(e=n[t]))this.removeListener(t,e);else if(void 0!==e)for(r=e.length-1;r>=0;r--)this.removeListener(t,e[r]);return this},w.prototype.listeners=function(t){return N(this,t,!0)},w.prototype.rawListeners=function(t){return N(this,t,!1)},w.listenerCount=function(t,e){return"function"==typeof t.listenerCount?t.listenerCount(e):I.call(t,e)},w.prototype.listenerCount=I,w.prototype.eventNames=function(){return this._eventsCount>0?p(this._events):[]},"undefined"!=typeof Symbol&&(O.prototype[Symbol.iterator]=function(){return this}),O.of=function(){var t=arguments,e=t.length,n=0;return new O((function(){return n>=e?{done:!0}:{done:!1,value:t[n++]}}))},O.empty=function(){return new O((function(){return{done:!0}}))},O.fromSequence=function(t){var e=0,n=t.length;return new O((function(){return e>=n?{done:!0}:{done:!1,value:t[e++]}}))},O.is=function(t){return t instanceof O||"object"==typeof t&&null!==t&&"function"==typeof t.next};var P=O,L={};L.ARRAY_BUFFER_SUPPORT="undefined"!=typeof ArrayBuffer,L.SYMBOL_SUPPORT="undefined"!=typeof Symbol;var x=P,F=L,R=F.ARRAY_BUFFER_SUPPORT,D=F.SYMBOL_SUPPORT,U=function(t){var e=function(t){return"string"==typeof t||Array.isArray(t)||R&&ArrayBuffer.isView(t)?x.fromSequence(t):"object"!=typeof t||null===t?null:D&&"function"==typeof t[Symbol.iterator]?t[Symbol.iterator]():"function"==typeof t.next?t:null}(t);if(!e)throw new Error("obliterator: target is not iterable nor a valid iterator.");return e},k=U,G=function(t,e){for(var n,r=arguments.length>1?e:1/0,o=r!==1/0?new Array(r):[],i=0,a=k(t);;){if(i===r)return o;if((n=a.next()).done)return i!==e&&(o.length=i),o;o[i++]=n.value}},B=function(t){function n(e){var n;return(n=t.call(this)||this).name="GraphError",n.message=e,n}return e(n,t),n}(i(Error)),V=function(t){function n(e){var r;return(r=t.call(this,e)||this).name="InvalidArgumentsGraphError","function"==typeof Error.captureStackTrace&&Error.captureStackTrace(a(r),n.prototype.constructor),r}return e(n,t),n}(B),W=function(t){function n(e){var r;return(r=t.call(this,e)||this).name="NotFoundGraphError","function"==typeof Error.captureStackTrace&&Error.captureStackTrace(a(r),n.prototype.constructor),r}return e(n,t),n}(B),j=function(t){function n(e){var r;return(r=t.call(this,e)||this).name="UsageGraphError","function"==typeof Error.captureStackTrace&&Error.captureStackTrace(a(r),n.prototype.constructor),r}return e(n,t),n}(B);function Y(t,e){this.key=t,this.attributes=e,this.clear()}function z(t,e){this.key=t,this.attributes=e,this.clear()}function q(t,e){this.key=t,this.attributes=e,this.clear()}function H(t,e,n,r,o){this.key=e,this.attributes=o,this.undirected=t,this.source=n,this.target=r}function $(t,e,n,r,o,i,a){var s,u,c,l;if(r=""+r,0===n){if(!(s=t._nodes.get(r)))throw new W("Graph.".concat(e,': could not find the "').concat(r,'" node in the graph.'));c=o,l=i}else if(3===n){if(o=""+o,!(u=t._edges.get(o)))throw new W("Graph.".concat(e,': could not find the "').concat(o,'" edge in the graph.'));var d=u.source.key,h=u.target.key;if(r===d)s=u.target;else{if(r!==h)throw new W("Graph.".concat(e,': the "').concat(r,'" node is not attached to the "').concat(o,'" edge (').concat(d,", ").concat(h,")."));s=u.source}c=i,l=a}else{if(!(u=t._edges.get(r)))throw new W("Graph.".concat(e,': could not find the "').concat(r,'" edge in the graph.'));s=1===n?u.source:u.target,c=o,l=i}return[s,c,l]}Y.prototype.clear=function(){this.inDegree=0,this.outDegree=0,this.undirectedDegree=0,this.undirectedLoops=0,this.directedLoops=0,this.in={},this.out={},this.undirected={}},z.prototype.clear=function(){this.inDegree=0,this.outDegree=0,this.directedLoops=0,this.in={},this.out={}},q.prototype.clear=function(){this.undirectedDegree=0,this.undirectedLoops=0,this.undirected={}},H.prototype.attach=function(){var t="out",e="in";this.undirected&&(t=e="undirected");var n=this.source.key,r=this.target.key;this.source[t][r]=this,this.undirected&&n===r||(this.target[e][n]=this)},H.prototype.attachMulti=function(){var t="out",e="in",n=this.source.key,r=this.target.key;this.undirected&&(t=e="undirected");var o=this.source[t],i=o[r];if(void 0===i)return o[r]=this,void(this.undirected&&n===r||(this.target[e][n]=this));i.previous=this,this.next=i,o[r]=this,this.target[e][n]=this},H.prototype.detach=function(){var t=this.source.key,e=this.target.key,n="out",r="in";this.undirected&&(n=r="undirected"),delete this.source[n][e],delete this.target[r][t]},H.prototype.detachMulti=function(){var t=this.source.key,e=this.target.key,n="out",r="in";this.undirected&&(n=r="undirected"),void 0===this.previous?void 0===this.next?(delete this.source[n][e],delete this.target[r][t]):(this.next.previous=void 0,this.source[n][e]=this.next,this.target[r][t]=this.next):(this.previous.next=this.next,void 0!==this.next&&(this.next.previous=this.previous))};var K=[{name:function(t){return"get".concat(t,"Attribute")},attacher:function(t,e,n){t.prototype[e]=function(t,r,o){var i=$(this,e,n,t,r,o),a=i[0],s=i[1];return a.attributes[s]}}},{name:function(t){return"get".concat(t,"Attributes")},attacher:function(t,e,n){t.prototype[e]=function(t,r){return $(this,e,n,t,r)[0].attributes}}},{name:function(t){return"has".concat(t,"Attribute")},attacher:function(t,e,n){t.prototype[e]=function(t,r,o){var i=$(this,e,n,t,r,o),a=i[0],s=i[1];return a.attributes.hasOwnProperty(s)}}},{name:function(t){return"set".concat(t,"Attribute")},attacher:function(t,e,n){t.prototype[e]=function(t,r,o,i){var a=$(this,e,n,t,r,o,i),s=a[0],u=a[1],c=a[2];return s.attributes[u]=c,this.emit("nodeAttributesUpdated",{key:s.key,type:"set",attributes:s.attributes,name:u}),this}}},{name:function(t){return"update".concat(t,"Attribute")},attacher:function(t,e,n){t.prototype[e]=function(t,r,o,i){var a=$(this,e,n,t,r,o,i),s=a[0],u=a[1],c=a[2];if("function"!=typeof c)throw new V("Graph.".concat(e,": updater should be a function."));var l=s.attributes,d=c(l[u]);return l[u]=d,this.emit("nodeAttributesUpdated",{key:s.key,type:"set",attributes:s.attributes,name:u}),this}}},{name:function(t){return"remove".concat(t,"Attribute")},attacher:function(t,e,n){t.prototype[e]=function(t,r,o){var i=$(this,e,n,t,r,o),a=i[0],s=i[1];return delete a.attributes[s],this.emit("nodeAttributesUpdated",{key:a.key,type:"remove",attributes:a.attributes,name:s}),this}}},{name:function(t){return"replace".concat(t,"Attributes")},attacher:function(t,e,n){t.prototype[e]=function(t,r,o){var i=$(this,e,n,t,r,o),a=i[0],s=i[1];if(!c(s))throw new V("Graph.".concat(e,": provided attributes are not a plain object."));return a.attributes=s,this.emit("nodeAttributesUpdated",{key:a.key,type:"replace",attributes:a.attributes}),this}}},{name:function(t){return"merge".concat(t,"Attributes")},attacher:function(t,e,n){t.prototype[e]=function(t,r,o){var i=$(this,e,n,t,r,o),a=i[0],u=i[1];if(!c(u))throw new V("Graph.".concat(e,": provided attributes are not a plain object."));return s(a.attributes,u),this.emit("nodeAttributesUpdated",{key:a.key,type:"merge",attributes:a.attributes,data:u}),this}}},{name:function(t){return"update".concat(t,"Attributes")},attacher:function(t,e,n){t.prototype[e]=function(t,r,o){var i=$(this,e,n,t,r,o),a=i[0],s=i[1];if("function"!=typeof s)throw new V("Graph.".concat(e,": provided updater is not a function."));return a.attributes=s(a.attributes),this.emit("nodeAttributesUpdated",{key:a.key,type:"update",attributes:a.attributes}),this}}}],X=[{name:function(t){return"get".concat(t,"Attribute")},attacher:function(t,e,n){t.prototype[e]=function(t,r){var o;if("mixed"!==this.type&&"mixed"!==n&&n!==this.type)throw new j("Graph.".concat(e,": cannot find this type of edges in your ").concat(this.type," graph."));if(arguments.length>2){if(this.multi)throw new j("Graph.".concat(e,": cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about."));var i=""+t,a=""+r;if(r=arguments[2],!(o=u(this,i,a,n)))throw new W("Graph.".concat(e,': could not find an edge for the given path ("').concat(i,'" - "').concat(a,'").'))}else{if("mixed"!==n)throw new j("Graph.".concat(e,": calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type."));if(t=""+t,!(o=this._edges.get(t)))throw new W("Graph.".concat(e,': could not find the "').concat(t,'" edge in the graph.'))}return o.attributes[r]}}},{name:function(t){return"get".concat(t,"Attributes")},attacher:function(t,e,n){t.prototype[e]=function(t){var r;if("mixed"!==this.type&&"mixed"!==n&&n!==this.type)throw new j("Graph.".concat(e,": cannot find this type of edges in your ").concat(this.type," graph."));if(arguments.length>1){if(this.multi)throw new j("Graph.".concat(e,": cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about."));var o=""+t,i=""+arguments[1];if(!(r=u(this,o,i,n)))throw new W("Graph.".concat(e,': could not find an edge for the given path ("').concat(o,'" - "').concat(i,'").'))}else{if("mixed"!==n)throw new j("Graph.".concat(e,": calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type."));if(t=""+t,!(r=this._edges.get(t)))throw new W("Graph.".concat(e,': could not find the "').concat(t,'" edge in the graph.'))}return r.attributes}}},{name:function(t){return"has".concat(t,"Attribute")},attacher:function(t,e,n){t.prototype[e]=function(t,r){var o;if("mixed"!==this.type&&"mixed"!==n&&n!==this.type)throw new j("Graph.".concat(e,": cannot find this type of edges in your ").concat(this.type," graph."));if(arguments.length>2){if(this.multi)throw new j("Graph.".concat(e,": cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about."));var i=""+t,a=""+r;if(r=arguments[2],!(o=u(this,i,a,n)))throw new W("Graph.".concat(e,': could not find an edge for the given path ("').concat(i,'" - "').concat(a,'").'))}else{if("mixed"!==n)throw new j("Graph.".concat(e,": calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type."));if(t=""+t,!(o=this._edges.get(t)))throw new W("Graph.".concat(e,': could not find the "').concat(t,'" edge in the graph.'))}return o.attributes.hasOwnProperty(r)}}},{name:function(t){return"set".concat(t,"Attribute")},attacher:function(t,e,n){t.prototype[e]=function(t,r,o){var i;if("mixed"!==this.type&&"mixed"!==n&&n!==this.type)throw new j("Graph.".concat(e,": cannot find this type of edges in your ").concat(this.type," graph."));if(arguments.length>3){if(this.multi)throw new j("Graph.".concat(e,": cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about."));var a=""+t,s=""+r;if(r=arguments[2],o=arguments[3],!(i=u(this,a,s,n)))throw new W("Graph.".concat(e,': could not find an edge for the given path ("').concat(a,'" - "').concat(s,'").'))}else{if("mixed"!==n)throw new j("Graph.".concat(e,": calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type."));if(t=""+t,!(i=this._edges.get(t)))throw new W("Graph.".concat(e,': could not find the "').concat(t,'" edge in the graph.'))}return i.attributes[r]=o,this.emit("edgeAttributesUpdated",{key:i.key,type:"set",attributes:i.attributes,name:r}),this}}},{name:function(t){return"update".concat(t,"Attribute")},attacher:function(t,e,n){t.prototype[e]=function(t,r,o){var i;if("mixed"!==this.type&&"mixed"!==n&&n!==this.type)throw new j("Graph.".concat(e,": cannot find this type of edges in your ").concat(this.type," graph."));if(arguments.length>3){if(this.multi)throw new j("Graph.".concat(e,": cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about."));var a=""+t,s=""+r;if(r=arguments[2],o=arguments[3],!(i=u(this,a,s,n)))throw new W("Graph.".concat(e,': could not find an edge for the given path ("').concat(a,'" - "').concat(s,'").'))}else{if("mixed"!==n)throw new j("Graph.".concat(e,": calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type."));if(t=""+t,!(i=this._edges.get(t)))throw new W("Graph.".concat(e,': could not find the "').concat(t,'" edge in the graph.'))}if("function"!=typeof o)throw new V("Graph.".concat(e,": updater should be a function."));return i.attributes[r]=o(i.attributes[r]),this.emit("edgeAttributesUpdated",{key:i.key,type:"set",attributes:i.attributes,name:r}),this}}},{name:function(t){return"remove".concat(t,"Attribute")},attacher:function(t,e,n){t.prototype[e]=function(t,r){var o;if("mixed"!==this.type&&"mixed"!==n&&n!==this.type)throw new j("Graph.".concat(e,": cannot find this type of edges in your ").concat(this.type," graph."));if(arguments.length>2){if(this.multi)throw new j("Graph.".concat(e,": cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about."));var i=""+t,a=""+r;if(r=arguments[2],!(o=u(this,i,a,n)))throw new W("Graph.".concat(e,': could not find an edge for the given path ("').concat(i,'" - "').concat(a,'").'))}else{if("mixed"!==n)throw new j("Graph.".concat(e,": calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type."));if(t=""+t,!(o=this._edges.get(t)))throw new W("Graph.".concat(e,': could not find the "').concat(t,'" edge in the graph.'))}return delete o.attributes[r],this.emit("edgeAttributesUpdated",{key:o.key,type:"remove",attributes:o.attributes,name:r}),this}}},{name:function(t){return"replace".concat(t,"Attributes")},attacher:function(t,e,n){t.prototype[e]=function(t,r){var o;if("mixed"!==this.type&&"mixed"!==n&&n!==this.type)throw new j("Graph.".concat(e,": cannot find this type of edges in your ").concat(this.type," graph."));if(arguments.length>2){if(this.multi)throw new j("Graph.".concat(e,": cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about."));var i=""+t,a=""+r;if(r=arguments[2],!(o=u(this,i,a,n)))throw new W("Graph.".concat(e,': could not find an edge for the given path ("').concat(i,'" - "').concat(a,'").'))}else{if("mixed"!==n)throw new j("Graph.".concat(e,": calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type."));if(t=""+t,!(o=this._edges.get(t)))throw new W("Graph.".concat(e,': could not find the "').concat(t,'" edge in the graph.'))}if(!c(r))throw new V("Graph.".concat(e,": provided attributes are not a plain object."));return o.attributes=r,this.emit("edgeAttributesUpdated",{key:o.key,type:"replace",attributes:o.attributes}),this}}},{name:function(t){return"merge".concat(t,"Attributes")},attacher:function(t,e,n){t.prototype[e]=function(t,r){var o;if("mixed"!==this.type&&"mixed"!==n&&n!==this.type)throw new j("Graph.".concat(e,": cannot find this type of edges in your ").concat(this.type," graph."));if(arguments.length>2){if(this.multi)throw new j("Graph.".concat(e,": cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about."));var i=""+t,a=""+r;if(r=arguments[2],!(o=u(this,i,a,n)))throw new W("Graph.".concat(e,': could not find an edge for the given path ("').concat(i,'" - "').concat(a,'").'))}else{if("mixed"!==n)throw new j("Graph.".concat(e,": calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type."));if(t=""+t,!(o=this._edges.get(t)))throw new W("Graph.".concat(e,': could not find the "').concat(t,'" edge in the graph.'))}if(!c(r))throw new V("Graph.".concat(e,": provided attributes are not a plain object."));return s(o.attributes,r),this.emit("edgeAttributesUpdated",{key:o.key,type:"merge",attributes:o.attributes,data:r}),this}}},{name:function(t){return"update".concat(t,"Attributes")},attacher:function(t,e,n){t.prototype[e]=function(t,r){var o;if("mixed"!==this.type&&"mixed"!==n&&n!==this.type)throw new j("Graph.".concat(e,": cannot find this type of edges in your ").concat(this.type," graph."));if(arguments.length>2){if(this.multi)throw new j("Graph.".concat(e,": cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about."));var i=""+t,a=""+r;if(r=arguments[2],!(o=u(this,i,a,n)))throw new W("Graph.".concat(e,': could not find an edge for the given path ("').concat(i,'" - "').concat(a,'").'))}else{if("mixed"!==n)throw new j("Graph.".concat(e,": calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type."));if(t=""+t,!(o=this._edges.get(t)))throw new W("Graph.".concat(e,': could not find the "').concat(t,'" edge in the graph.'))}if("function"!=typeof r)throw new V("Graph.".concat(e,": provided updater is not a function."));return o.attributes=r(o.attributes),this.emit("edgeAttributesUpdated",{key:o.key,type:"update",attributes:o.attributes}),this}}}],Q=P,J=U,Z=function(){var t=arguments,e=null,n=-1;return new Q((function(){for(var r=null;;){if(null===e){if(++n>=t.length)return{done:!0};e=J(t[n])}if(!0!==(r=e.next()).done)break;e=null}return r}))},tt=[{name:"edges",type:"mixed"},{name:"inEdges",type:"directed",direction:"in"},{name:"outEdges",type:"directed",direction:"out"},{name:"inboundEdges",type:"mixed",direction:"in"},{name:"outboundEdges",type:"mixed",direction:"out"},{name:"directedEdges",type:"directed"},{name:"undirectedEdges",type:"undirected"}];function et(t,e,n,r){var o=!1;for(var i in e)if(i!==r){var a=e[i];if(o=n(a.key,a.attributes,a.source.key,a.target.key,a.source.attributes,a.target.attributes,a.undirected),t&&o)return a.key}}function nt(t,e,n,r){var o,i,a,s=!1;for(var u in e)if(u!==r){o=e[u];do{if(i=o.source,a=o.target,s=n(o.key,o.attributes,i.key,a.key,i.attributes,a.attributes,o.undirected),t&&s)return o.key;o=o.next}while(void 0!==o)}}function rt(t,e){var n,r=Object.keys(t),o=r.length,i=0;return new P((function(){do{if(n)n=n.next;else{if(i>=o)return{done:!0};var a=r[i++];if(a===e){n=void 0;continue}n=t[a]}}while(!n);return{done:!1,value:{edge:n.key,attributes:n.attributes,source:n.source.key,target:n.target.key,sourceAttributes:n.source.attributes,targetAttributes:n.target.attributes,undirected:n.undirected}}}))}function ot(t,e,n,r){var o=e[n];if(o){var i=o.source,a=o.target;return r(o.key,o.attributes,i.key,a.key,i.attributes,a.attributes,o.undirected)&&t?o.key:void 0}}function it(t,e,n,r){var o=e[n];if(o){var i=!1;do{if(i=r(o.key,o.attributes,o.source.key,o.target.key,o.source.attributes,o.target.attributes,o.undirected),t&&i)return o.key;o=o.next}while(void 0!==o)}}function at(t,e){var n=t[e];return void 0!==n.next?new P((function(){if(!n)return{done:!0};var t={edge:n.key,attributes:n.attributes,source:n.source.key,target:n.target.key,sourceAttributes:n.source.attributes,targetAttributes:n.target.attributes,undirected:n.undirected};return n=n.next,{done:!1,value:t}})):P.of({edge:n.key,attributes:n.attributes,source:n.source.key,target:n.target.key,sourceAttributes:n.source.attributes,targetAttributes:n.target.attributes,undirected:n.undirected})}function st(t,e,n,r){if(0!==e.size)for(var o,i,a="mixed"!==n&&n!==e.type,s="undirected"===n,u=!1,c=e._edges.values();!0!==(o=c.next()).done;)if(i=o.value,!a||i.undirected===s){var l=i,d=l.key,h=l.attributes,f=l.source,p=l.target;if(u=r(d,h,f.key,p.key,f.attributes,p.attributes,i.undirected),t&&u)return d}}function ut(t,e,n,r,o,i){var a,s=e?nt:et;if("undirected"!==n){if("out"!==r&&(a=s(t,o.in,i),t&&a))return a;if("in"!==r&&(a=s(t,o.out,i,r?void 0:o.key),t&&a))return a}if("directed"!==n&&(a=s(t,o.undirected,i),t&&a))return a}function ct(t,e,n,r,o,i,a){var s,u=n?it:ot;if("undirected"!==e){if(void 0!==o.in&&"out"!==r&&(s=u(t,o.in,i,a),t&&s))return s;if(void 0!==o.out&&"in"!==r&&(r||o.key!==i)&&(s=u(t,o.out,i,a),t&&s))return s}if("directed"!==e&&void 0!==o.undirected&&(s=u(t,o.undirected,i,a),t&&s))return s}var lt=[{name:"neighbors",type:"mixed"},{name:"inNeighbors",type:"directed",direction:"in"},{name:"outNeighbors",type:"directed",direction:"out"},{name:"inboundNeighbors",type:"mixed",direction:"in"},{name:"outboundNeighbors",type:"mixed",direction:"out"},{name:"directedNeighbors",type:"directed"},{name:"undirectedNeighbors",type:"undirected"}];function dt(){this.A=null,this.B=null}function ht(t,e,n,r,o){for(var i in r){var a=r[i],s=a.source,u=a.target,c=s===n?u:s;if(!e||!e.has(c.key)){var l=o(c.key,c.attributes);if(t&&l)return c.key}}}function ft(t,e,n,r,o){if("mixed"!==e){if("undirected"===e)return ht(t,null,r,r.undirected,o);if("string"==typeof n)return ht(t,null,r,r[n],o)}var i,a=new dt;if("undirected"!==e){if("out"!==n){if(i=ht(t,null,r,r.in,o),t&&i)return i;a.wrap(r.in)}if("in"!==n){if(i=ht(t,a,r,r.out,o),t&&i)return i;a.wrap(r.out)}}if("directed"!==e&&(i=ht(t,a,r,r.undirected,o),t&&i))return i}function pt(t,e,n){var r=Object.keys(n),o=r.length,i=0;return new P((function(){var a=null;do{if(i>=o)return t&&t.wrap(n),{done:!0};var s=n[r[i++]],u=s.source,c=s.target;a=u===e?c:u,t&&t.has(a.key)&&(a=null)}while(null===a);return{done:!1,value:{neighbor:a.key,attributes:a.attributes}}}))}function mt(t,e,n,r,o){for(var i,a,s,u,c,l,d,h=r._nodes.values(),f=r.type;!0!==(i=h.next()).done;){var p=!1;if(a=i.value,"undirected"!==f)for(s in u=a.out){c=u[s];do{if(l=c.target,p=!0,d=o(a.key,l.key,a.attributes,l.attributes,c.key,c.attributes,c.undirected),t&&d)return c;c=c.next}while(c)}if("directed"!==f)for(s in u=a.undirected)if(!(e&&a.key>s)){c=u[s];do{if((l=c.target).key!==s&&(l=c.source),p=!0,d=o(a.key,l.key,a.attributes,l.attributes,c.key,c.attributes,c.undirected),t&&d)return c;c=c.next}while(c)}if(n&&!p&&(d=o(a.key,null,a.attributes,null,null,null,null),t&&d))return null}}function gt(t){if(!c(t))throw new V('Graph.import: invalid serialized node. A serialized node should be a plain object with at least a "key" property.');if(!("key"in t))throw new V("Graph.import: serialized node is missing its key.");if("attributes"in t&&(!c(t.attributes)||null===t.attributes))throw new V("Graph.import: invalid attributes. Attributes should be a plain object, null or omitted.")}function yt(t){if(!c(t))throw new V('Graph.import: invalid serialized edge. A serialized edge should be a plain object with at least a "source" & "target" property.');if(!("source"in t))throw new V("Graph.import: serialized edge is missing its source.");if(!("target"in t))throw new V("Graph.import: serialized edge is missing its target.");if("attributes"in t&&(!c(t.attributes)||null===t.attributes))throw new V("Graph.import: invalid attributes. Attributes should be a plain object, null or omitted.");if("undirected"in t&&"boolean"!=typeof t.undirected)throw new V("Graph.import: invalid undirectedness information. Undirected should be boolean or omitted.")}dt.prototype.wrap=function(t){null===this.A?this.A=t:null===this.B&&(this.B=t)},dt.prototype.has=function(t){return null!==this.A&&t in this.A||null!==this.B&&t in this.B};var vt,wt=(vt=255&Math.floor(256*Math.random()),function(){return vt++}),bt=new Set(["directed","undirected","mixed"]),Et=new Set(["domain","_events","_eventsCount","_maxListeners"]),At={allowSelfLoops:!0,multi:!1,type:"mixed"};function Ct(t,e,n){var r=new t.NodeDataClass(e,n);return t._nodes.set(e,r),t.emit("nodeAdded",{key:e,attributes:n}),r}function St(t,e,n,r,o,i,a,s){if(!r&&"undirected"===t.type)throw new j("Graph.".concat(e,": you cannot add a directed edge to an undirected graph. Use the #.addEdge or #.addUndirectedEdge instead."));if(r&&"directed"===t.type)throw new j("Graph.".concat(e,": you cannot add an undirected edge to a directed graph. Use the #.addEdge or #.addDirectedEdge instead."));if(s&&!c(s))throw new V("Graph.".concat(e,': invalid attributes. Expecting an object but got "').concat(s,'"'));if(i=""+i,a=""+a,s=s||{},!t.allowSelfLoops&&i===a)throw new j("Graph.".concat(e,': source & target are the same ("').concat(i,"\"), thus creating a loop explicitly forbidden by this graph 'allowSelfLoops' option set to false."));var u=t._nodes.get(i),l=t._nodes.get(a);if(!u)throw new W("Graph.".concat(e,': source node "').concat(i,'" not found.'));if(!l)throw new W("Graph.".concat(e,': target node "').concat(a,'" not found.'));var d={key:null,undirected:r,source:i,target:a,attributes:s};if(n)o=t._edgeKeyGenerator();else if(o=""+o,t._edges.has(o))throw new j("Graph.".concat(e,': the "').concat(o,'" edge already exists in the graph.'));if(!t.multi&&(r?void 0!==u.undirected[a]:void 0!==u.out[a]))throw new j("Graph.".concat(e,': an edge linking "').concat(i,'" to "').concat(a,"\" already exists. If you really want to add multiple edges linking those nodes, you should create a multi graph by using the 'multi' option."));var h=new H(r,o,u,l,s);t._edges.set(o,h);var f=i===a;return r?(u.undirectedDegree++,l.undirectedDegree++,f&&(u.undirectedLoops++,t._undirectedSelfLoopCount++)):(u.outDegree++,l.inDegree++,f&&(u.directedLoops++,t._directedSelfLoopCount++)),t.multi?h.attachMulti():h.attach(),r?t._undirectedSize++:t._directedSize++,d.key=o,t.emit("edgeAdded",d),o}function _t(t,e,n,r,o,i,a,u,l){if(!r&&"undirected"===t.type)throw new j("Graph.".concat(e,": you cannot merge/update a directed edge to an undirected graph. Use the #.mergeEdge/#.updateEdge or #.addUndirectedEdge instead."));if(r&&"directed"===t.type)throw new j("Graph.".concat(e,": you cannot merge/update an undirected edge to a directed graph. Use the #.mergeEdge/#.updateEdge or #.addDirectedEdge instead."));if(u)if(l){if("function"!=typeof u)throw new V("Graph.".concat(e,': invalid updater function. Expecting a function but got "').concat(u,'"'))}else if(!c(u))throw new V("Graph.".concat(e,': invalid attributes. Expecting an object but got "').concat(u,'"'));var d;if(i=""+i,a=""+a,l&&(d=u,u=void 0),!t.allowSelfLoops&&i===a)throw new j("Graph.".concat(e,': source & target are the same ("').concat(i,"\"), thus creating a loop explicitly forbidden by this graph 'allowSelfLoops' option set to false."));var h,f,p=t._nodes.get(i),m=t._nodes.get(a);if(!n&&(h=t._edges.get(o))){if(!(h.source.key===i&&h.target.key===a||r&&h.source.key===a&&h.target.key===i))throw new j("Graph.".concat(e,': inconsistency detected when attempting to merge the "').concat(o,'" edge with "').concat(i,'" source & "').concat(a,'" target vs. ("').concat(h.source.key,'", "').concat(h.target.key,'").'));f=h}if(f||t.multi||!p||(f=r?p.undirected[a]:p.out[a]),f){var g=[f.key,!1,!1,!1];if(l?!d:!u)return g;if(l){var y=f.attributes;f.attributes=d(y),t.emit("edgeAttributesUpdated",{type:"replace",key:f.key,attributes:f.attributes})}else s(f.attributes,u),t.emit("edgeAttributesUpdated",{type:"merge",key:f.key,attributes:f.attributes,data:u});return g}u=u||{},l&&d&&(u=d(u));var v={key:null,undirected:r,source:i,target:a,attributes:u};if(n)o=t._edgeKeyGenerator();else if(o=""+o,t._edges.has(o))throw new j("Graph.".concat(e,': the "').concat(o,'" edge already exists in the graph.'));var w=!1,b=!1;p||(p=Ct(t,i,{}),w=!0,i===a&&(m=p,b=!0)),m||(m=Ct(t,a,{}),b=!0),h=new H(r,o,p,m,u),t._edges.set(o,h);var E=i===a;return r?(p.undirectedDegree++,m.undirectedDegree++,E&&(p.undirectedLoops++,t._undirectedSelfLoopCount++)):(p.outDegree++,m.inDegree++,E&&(p.directedLoops++,t._directedSelfLoopCount++)),t.multi?h.attachMulti():h.attach(),r?t._undirectedSize++:t._directedSize++,v.key=o,t.emit("edgeAdded",v),[o,!0,w,b]}function Nt(t,e){t._edges.delete(e.key);var n=e.source,r=e.target,o=e.attributes,i=e.undirected,a=n===r;i?(n.undirectedDegree--,r.undirectedDegree--,a&&(n.undirectedLoops--,t._undirectedSelfLoopCount--)):(n.outDegree--,r.inDegree--,a&&(n.directedLoops--,t._directedSelfLoopCount--)),t.multi?e.detachMulti():e.detach(),i?t._undirectedSize--:t._directedSize--,t.emit("edgeDropped",{key:e.key,attributes:o,source:n.key,target:r.key,undirected:i})}var It=function(n){function r(t){var e;if(e=n.call(this)||this,"boolean"!=typeof(t=s({},At,t)).multi)throw new V("Graph.constructor: invalid 'multi' option. Expecting a boolean but got \"".concat(t.multi,'".'));if(!bt.has(t.type))throw new V('Graph.constructor: invalid \'type\' option. Should be one of "mixed", "directed" or "undirected" but got "'.concat(t.type,'".'));if("boolean"!=typeof t.allowSelfLoops)throw new V("Graph.constructor: invalid 'allowSelfLoops' option. Expecting a boolean but got \"".concat(t.allowSelfLoops,'".'));var r="mixed"===t.type?Y:"directed"===t.type?z:q;d(a(e),"NodeDataClass",r);var o="geid_"+wt()+"_",i=0;return d(a(e),"_attributes",{}),d(a(e),"_nodes",new Map),d(a(e),"_edges",new Map),d(a(e),"_directedSize",0),d(a(e),"_undirectedSize",0),d(a(e),"_directedSelfLoopCount",0),d(a(e),"_undirectedSelfLoopCount",0),d(a(e),"_edgeKeyGenerator",(function(){var t;do{t=o+i++}while(e._edges.has(t));return t})),d(a(e),"_options",t),Et.forEach((function(t){return d(a(e),t,e[t])})),h(a(e),"order",(function(){return e._nodes.size})),h(a(e),"size",(function(){return e._edges.size})),h(a(e),"directedSize",(function(){return e._directedSize})),h(a(e),"undirectedSize",(function(){return e._undirectedSize})),h(a(e),"selfLoopCount",(function(){return e._directedSelfLoopCount+e._undirectedSelfLoopCount})),h(a(e),"directedSelfLoopCount",(function(){return e._directedSelfLoopCount})),h(a(e),"undirectedSelfLoopCount",(function(){return e._undirectedSelfLoopCount})),h(a(e),"multi",e._options.multi),h(a(e),"type",e._options.type),h(a(e),"allowSelfLoops",e._options.allowSelfLoops),h(a(e),"implementation",(function(){return"graphology"})),e}e(r,n);var o=r.prototype;return o._resetInstanceCounters=function(){this._directedSize=0,this._undirectedSize=0,this._directedSelfLoopCount=0,this._undirectedSelfLoopCount=0},o.hasNode=function(t){return this._nodes.has(""+t)},o.hasDirectedEdge=function(t,e){if("undirected"===this.type)return!1;if(1===arguments.length){var n=""+t,r=this._edges.get(n);return!!r&&!r.undirected}if(2===arguments.length){t=""+t,e=""+e;var o=this._nodes.get(t);return!!o&&o.out.hasOwnProperty(e)}throw new V("Graph.hasDirectedEdge: invalid arity (".concat(arguments.length,", instead of 1 or 2). You can either ask for an edge id or for the existence of an edge between a source & a target."))},o.hasUndirectedEdge=function(t,e){if("directed"===this.type)return!1;if(1===arguments.length){var n=""+t,r=this._edges.get(n);return!!r&&r.undirected}if(2===arguments.length){t=""+t,e=""+e;var o=this._nodes.get(t);return!!o&&o.undirected.hasOwnProperty(e)}throw new V("Graph.hasDirectedEdge: invalid arity (".concat(arguments.length,", instead of 1 or 2). You can either ask for an edge id or for the existence of an edge between a source & a target."))},o.hasEdge=function(t,e){if(1===arguments.length){var n=""+t;return this._edges.has(n)}if(2===arguments.length){t=""+t,e=""+e;var r=this._nodes.get(t);return!!r&&(void 0!==r.out&&r.out.hasOwnProperty(e)||void 0!==r.undirected&&r.undirected.hasOwnProperty(e))}throw new V("Graph.hasEdge: invalid arity (".concat(arguments.length,", instead of 1 or 2). You can either ask for an edge id or for the existence of an edge between a source & a target."))},o.directedEdge=function(t,e){if("undirected"!==this.type){if(t=""+t,e=""+e,this.multi)throw new j("Graph.directedEdge: this method is irrelevant with multigraphs since there might be multiple edges between source & target. See #.directedEdges instead.");var n=this._nodes.get(t);if(!n)throw new W('Graph.directedEdge: could not find the "'.concat(t,'" source node in the graph.'));if(!this._nodes.has(e))throw new W('Graph.directedEdge: could not find the "'.concat(e,'" target node in the graph.'));var r=n.out&&n.out[e]||void 0;return r?r.key:void 0}},o.undirectedEdge=function(t,e){if("directed"!==this.type){if(t=""+t,e=""+e,this.multi)throw new j("Graph.undirectedEdge: this method is irrelevant with multigraphs since there might be multiple edges between source & target. See #.undirectedEdges instead.");var n=this._nodes.get(t);if(!n)throw new W('Graph.undirectedEdge: could not find the "'.concat(t,'" source node in the graph.'));if(!this._nodes.has(e))throw new W('Graph.undirectedEdge: could not find the "'.concat(e,'" target node in the graph.'));var r=n.undirected&&n.undirected[e]||void 0;return r?r.key:void 0}},o.edge=function(t,e){if(this.multi)throw new j("Graph.edge: this method is irrelevant with multigraphs since there might be multiple edges between source & target. See #.edges instead.");t=""+t,e=""+e;var n=this._nodes.get(t);if(!n)throw new W('Graph.edge: could not find the "'.concat(t,'" source node in the graph.'));if(!this._nodes.has(e))throw new W('Graph.edge: could not find the "'.concat(e,'" target node in the graph.'));var r=n.out&&n.out[e]||n.undirected&&n.undirected[e]||void 0;if(r)return r.key},o.areDirectedNeighbors=function(t,e){t=""+t,e=""+e;var n=this._nodes.get(t);if(!n)throw new W('Graph.areDirectedNeighbors: could not find the "'.concat(t,'" node in the graph.'));return"undirected"!==this.type&&(e in n.in||e in n.out)},o.areOutNeighbors=function(t,e){t=""+t,e=""+e;var n=this._nodes.get(t);if(!n)throw new W('Graph.areOutNeighbors: could not find the "'.concat(t,'" node in the graph.'));return"undirected"!==this.type&&e in n.out},o.areInNeighbors=function(t,e){t=""+t,e=""+e;var n=this._nodes.get(t);if(!n)throw new W('Graph.areInNeighbors: could not find the "'.concat(t,'" node in the graph.'));return"undirected"!==this.type&&e in n.in},o.areUndirectedNeighbors=function(t,e){t=""+t,e=""+e;var n=this._nodes.get(t);if(!n)throw new W('Graph.areUndirectedNeighbors: could not find the "'.concat(t,'" node in the graph.'));return"directed"!==this.type&&e in n.undirected},o.areNeighbors=function(t,e){t=""+t,e=""+e;var n=this._nodes.get(t);if(!n)throw new W('Graph.areNeighbors: could not find the "'.concat(t,'" node in the graph.'));return"undirected"!==this.type&&(e in n.in||e in n.out)||"directed"!==this.type&&e in n.undirected},o.areInboundNeighbors=function(t,e){t=""+t,e=""+e;var n=this._nodes.get(t);if(!n)throw new W('Graph.areInboundNeighbors: could not find the "'.concat(t,'" node in the graph.'));return"undirected"!==this.type&&e in n.in||"directed"!==this.type&&e in n.undirected},o.areOutboundNeighbors=function(t,e){t=""+t,e=""+e;var n=this._nodes.get(t);if(!n)throw new W('Graph.areOutboundNeighbors: could not find the "'.concat(t,'" node in the graph.'));return"undirected"!==this.type&&e in n.out||"directed"!==this.type&&e in n.undirected},o.inDegree=function(t){t=""+t;var e=this._nodes.get(t);if(!e)throw new W('Graph.inDegree: could not find the "'.concat(t,'" node in the graph.'));return"undirected"===this.type?0:e.inDegree},o.outDegree=function(t){t=""+t;var e=this._nodes.get(t);if(!e)throw new W('Graph.outDegree: could not find the "'.concat(t,'" node in the graph.'));return"undirected"===this.type?0:e.outDegree},o.directedDegree=function(t){t=""+t;var e=this._nodes.get(t);if(!e)throw new W('Graph.directedDegree: could not find the "'.concat(t,'" node in the graph.'));return"undirected"===this.type?0:e.inDegree+e.outDegree},o.undirectedDegree=function(t){t=""+t;var e=this._nodes.get(t);if(!e)throw new W('Graph.undirectedDegree: could not find the "'.concat(t,'" node in the graph.'));return"directed"===this.type?0:e.undirectedDegree},o.inboundDegree=function(t){t=""+t;var e=this._nodes.get(t);if(!e)throw new W('Graph.inboundDegree: could not find the "'.concat(t,'" node in the graph.'));var n=0;return"directed"!==this.type&&(n+=e.undirectedDegree),"undirected"!==this.type&&(n+=e.inDegree),n},o.outboundDegree=function(t){t=""+t;var e=this._nodes.get(t);if(!e)throw new W('Graph.outboundDegree: could not find the "'.concat(t,'" node in the graph.'));var n=0;return"directed"!==this.type&&(n+=e.undirectedDegree),"undirected"!==this.type&&(n+=e.outDegree),n},o.degree=function(t){t=""+t;var e=this._nodes.get(t);if(!e)throw new W('Graph.degree: could not find the "'.concat(t,'" node in the graph.'));var n=0;return"directed"!==this.type&&(n+=e.undirectedDegree),"undirected"!==this.type&&(n+=e.inDegree+e.outDegree),n},o.inDegreeWithoutSelfLoops=function(t){t=""+t;var e=this._nodes.get(t);if(!e)throw new W('Graph.inDegreeWithoutSelfLoops: could not find the "'.concat(t,'" node in the graph.'));return"undirected"===this.type?0:e.inDegree-e.directedLoops},o.outDegreeWithoutSelfLoops=function(t){t=""+t;var e=this._nodes.get(t);if(!e)throw new W('Graph.outDegreeWithoutSelfLoops: could not find the "'.concat(t,'" node in the graph.'));return"undirected"===this.type?0:e.outDegree-e.directedLoops},o.directedDegreeWithoutSelfLoops=function(t){t=""+t;var e=this._nodes.get(t);if(!e)throw new W('Graph.directedDegreeWithoutSelfLoops: could not find the "'.concat(t,'" node in the graph.'));return"undirected"===this.type?0:e.inDegree+e.outDegree-2*e.directedLoops},o.undirectedDegreeWithoutSelfLoops=function(t){t=""+t;var e=this._nodes.get(t);if(!e)throw new W('Graph.undirectedDegreeWithoutSelfLoops: could not find the "'.concat(t,'" node in the graph.'));return"directed"===this.type?0:e.undirectedDegree-2*e.undirectedLoops},o.inboundDegreeWithoutSelfLoops=function(t){t=""+t;var e=this._nodes.get(t);if(!e)throw new W('Graph.inboundDegreeWithoutSelfLoops: could not find the "'.concat(t,'" node in the graph.'));var n=0,r=0;return"directed"!==this.type&&(n+=e.undirectedDegree,r+=2*e.undirectedLoops),"undirected"!==this.type&&(n+=e.inDegree,r+=e.directedLoops),n-r},o.outboundDegreeWithoutSelfLoops=function(t){t=""+t;var e=this._nodes.get(t);if(!e)throw new W('Graph.outboundDegreeWithoutSelfLoops: could not find the "'.concat(t,'" node in the graph.'));var n=0,r=0;return"directed"!==this.type&&(n+=e.undirectedDegree,r+=2*e.undirectedLoops),"undirected"!==this.type&&(n+=e.outDegree,r+=e.directedLoops),n-r},o.degreeWithoutSelfLoops=function(t){t=""+t;var e=this._nodes.get(t);if(!e)throw new W('Graph.degreeWithoutSelfLoops: could not find the "'.concat(t,'" node in the graph.'));var n=0,r=0;return"directed"!==this.type&&(n+=e.undirectedDegree,r+=2*e.undirectedLoops),"undirected"!==this.type&&(n+=e.inDegree+e.outDegree,r+=2*e.directedLoops),n-r},o.source=function(t){t=""+t;var e=this._edges.get(t);if(!e)throw new W('Graph.source: could not find the "'.concat(t,'" edge in the graph.'));return e.source.key},o.target=function(t){t=""+t;var e=this._edges.get(t);if(!e)throw new W('Graph.target: could not find the "'.concat(t,'" edge in the graph.'));return e.target.key},o.extremities=function(t){t=""+t;var e=this._edges.get(t);if(!e)throw new W('Graph.extremities: could not find the "'.concat(t,'" edge in the graph.'));return[e.source.key,e.target.key]},o.opposite=function(t,e){t=""+t,e=""+e;var n=this._edges.get(e);if(!n)throw new W('Graph.opposite: could not find the "'.concat(e,'" edge in the graph.'));var r=n.source.key,o=n.target.key;if(t===r)return o;if(t===o)return r;throw new W('Graph.opposite: the "'.concat(t,'" node is not attached to the "').concat(e,'" edge (').concat(r,", ").concat(o,")."))},o.hasExtremity=function(t,e){t=""+t,e=""+e;var n=this._edges.get(t);if(!n)throw new W('Graph.hasExtremity: could not find the "'.concat(t,'" edge in the graph.'));return n.source.key===e||n.target.key===e},o.isUndirected=function(t){t=""+t;var e=this._edges.get(t);if(!e)throw new W('Graph.isUndirected: could not find the "'.concat(t,'" edge in the graph.'));return e.undirected},o.isDirected=function(t){t=""+t;var e=this._edges.get(t);if(!e)throw new W('Graph.isDirected: could not find the "'.concat(t,'" edge in the graph.'));return!e.undirected},o.isSelfLoop=function(t){t=""+t;var e=this._edges.get(t);if(!e)throw new W('Graph.isSelfLoop: could not find the "'.concat(t,'" edge in the graph.'));return e.source===e.target},o.addNode=function(t,e){var n=function(t,e,n){if(n&&!c(n))throw new V('Graph.addNode: invalid attributes. Expecting an object but got "'.concat(n,'"'));if(e=""+e,n=n||{},t._nodes.has(e))throw new j('Graph.addNode: the "'.concat(e,'" node already exist in the graph.'));var r=new t.NodeDataClass(e,n);return t._nodes.set(e,r),t.emit("nodeAdded",{key:e,attributes:n}),r}(this,t,e);return n.key},o.mergeNode=function(t,e){if(e&&!c(e))throw new V('Graph.mergeNode: invalid attributes. Expecting an object but got "'.concat(e,'"'));t=""+t,e=e||{};var n=this._nodes.get(t);return n?(e&&(s(n.attributes,e),this.emit("nodeAttributesUpdated",{type:"merge",key:t,attributes:n.attributes,data:e})),[t,!1]):(n=new this.NodeDataClass(t,e),this._nodes.set(t,n),this.emit("nodeAdded",{key:t,attributes:e}),[t,!0])},o.updateNode=function(t,e){if(e&&"function"!=typeof e)throw new V('Graph.updateNode: invalid updater function. Expecting a function but got "'.concat(e,'"'));t=""+t;var n=this._nodes.get(t);if(n){if(e){var r=n.attributes;n.attributes=e(r),this.emit("nodeAttributesUpdated",{type:"replace",key:t,attributes:n.attributes})}return[t,!1]}var o=e?e({}):{};return n=new this.NodeDataClass(t,o),this._nodes.set(t,n),this.emit("nodeAdded",{key:t,attributes:o}),[t,!0]},o.dropNode=function(t){t=""+t;var e,n=this._nodes.get(t);if(!n)throw new W('Graph.dropNode: could not find the "'.concat(t,'" node in the graph.'));if("undirected"!==this.type){for(var r in n.out){e=n.out[r];do{Nt(this,e),e=e.next}while(e)}for(var o in n.in){e=n.in[o];do{Nt(this,e),e=e.next}while(e)}}if("directed"!==this.type)for(var i in n.undirected){e=n.undirected[i];do{Nt(this,e),e=e.next}while(e)}this._nodes.delete(t),this.emit("nodeDropped",{key:t,attributes:n.attributes})},o.dropEdge=function(t){var e;if(arguments.length>1){var n=""+arguments[0],r=""+arguments[1];if(!(e=u(this,n,r,this.type)))throw new W('Graph.dropEdge: could not find the "'.concat(n,'" -> "').concat(r,'" edge in the graph.'))}else if(t=""+t,!(e=this._edges.get(t)))throw new W('Graph.dropEdge: could not find the "'.concat(t,'" edge in the graph.'));return Nt(this,e),this},o.dropDirectedEdge=function(t,e){if(arguments.length<2)throw new j("Graph.dropDirectedEdge: it does not make sense to try and drop a directed edge by key. What if the edge with this key is undirected? Use #.dropEdge for this purpose instead.");if(this.multi)throw new j("Graph.dropDirectedEdge: cannot use a {source,target} combo when dropping an edge in a MultiGraph since we cannot infer the one you want to delete as there could be multiple ones.");var n=u(this,t=""+t,e=""+e,"directed");if(!n)throw new W('Graph.dropDirectedEdge: could not find a "'.concat(t,'" -> "').concat(e,'" edge in the graph.'));return Nt(this,n),this},o.dropUndirectedEdge=function(t,e){if(arguments.length<2)throw new j("Graph.dropUndirectedEdge: it does not make sense to drop a directed edge by key. What if the edge with this key is undirected? Use #.dropEdge for this purpose instead.");if(this.multi)throw new j("Graph.dropUndirectedEdge: cannot use a {source,target} combo when dropping an edge in a MultiGraph since we cannot infer the one you want to delete as there could be multiple ones.");var n=u(this,t,e,"undirected");if(!n)throw new W('Graph.dropUndirectedEdge: could not find a "'.concat(t,'" -> "').concat(e,'" edge in the graph.'));return Nt(this,n),this},o.clear=function(){this._edges.clear(),this._nodes.clear(),this._resetInstanceCounters(),this.emit("cleared")},o.clearEdges=function(){for(var t,e=this._nodes.values();!0!==(t=e.next()).done;)t.value.clear();this._edges.clear(),this._resetInstanceCounters(),this.emit("edgesCleared")},o.getAttribute=function(t){return this._attributes[t]},o.getAttributes=function(){return this._attributes},o.hasAttribute=function(t){return this._attributes.hasOwnProperty(t)},o.setAttribute=function(t,e){return this._attributes[t]=e,this.emit("attributesUpdated",{type:"set",attributes:this._attributes,name:t}),this},o.updateAttribute=function(t,e){if("function"!=typeof e)throw new V("Graph.updateAttribute: updater should be a function.");var n=this._attributes[t];return this._attributes[t]=e(n),this.emit("attributesUpdated",{type:"set",attributes:this._attributes,name:t}),this},o.removeAttribute=function(t){return delete this._attributes[t],this.emit("attributesUpdated",{type:"remove",attributes:this._attributes,name:t}),this},o.replaceAttributes=function(t){if(!c(t))throw new V("Graph.replaceAttributes: provided attributes are not a plain object.");return this._attributes=t,this.emit("attributesUpdated",{type:"replace",attributes:this._attributes}),this},o.mergeAttributes=function(t){if(!c(t))throw new V("Graph.mergeAttributes: provided attributes are not a plain object.");return s(this._attributes,t),this.emit("attributesUpdated",{type:"merge",attributes:this._attributes,data:t}),this},o.updateAttributes=function(t){if("function"!=typeof t)throw new V("Graph.updateAttributes: provided updater is not a function.");return this._attributes=t(this._attributes),this.emit("attributesUpdated",{type:"update",attributes:this._attributes}),this},o.updateEachNodeAttributes=function(t,e){if("function"!=typeof t)throw new V("Graph.updateEachNodeAttributes: expecting an updater function.");if(e&&!f(e))throw new V("Graph.updateEachNodeAttributes: invalid hints. Expecting an object having the following shape: {attributes?: [string]}");for(var n,r,o=this._nodes.values();!0!==(n=o.next()).done;)(r=n.value).attributes=t(r.key,r.attributes);this.emit("eachNodeAttributesUpdated",{hints:e||null})},o.updateEachEdgeAttributes=function(t,e){if("function"!=typeof t)throw new V("Graph.updateEachEdgeAttributes: expecting an updater function.");if(e&&!f(e))throw new V("Graph.updateEachEdgeAttributes: invalid hints. Expecting an object having the following shape: {attributes?: [string]}");for(var n,r,o,i,a=this._edges.values();!0!==(n=a.next()).done;)o=(r=n.value).source,i=r.target,r.attributes=t(r.key,r.attributes,o.key,i.key,o.attributes,i.attributes,r.undirected);this.emit("eachEdgeAttributesUpdated",{hints:e||null})},o.forEachAdjacencyEntry=function(t){if("function"!=typeof t)throw new V("Graph.forEachAdjacencyEntry: expecting a callback.");mt(!1,!1,!1,this,t)},o.forEachAdjacencyEntryWithOrphans=function(t){if("function"!=typeof t)throw new V("Graph.forEachAdjacencyEntryWithOrphans: expecting a callback.");mt(!1,!1,!0,this,t)},o.forEachAssymetricAdjacencyEntry=function(t){if("function"!=typeof t)throw new V("Graph.forEachAssymetricAdjacencyEntry: expecting a callback.");mt(!1,!0,!1,this,t)},o.forEachAssymetricAdjacencyEntryWithOrphans=function(t){if("function"!=typeof t)throw new V("Graph.forEachAssymetricAdjacencyEntryWithOrphans: expecting a callback.");mt(!1,!0,!0,this,t)},o.nodes=function(){return"function"==typeof Array.from?Array.from(this._nodes.keys()):G(this._nodes.keys(),this._nodes.size)},o.forEachNode=function(t){if("function"!=typeof t)throw new V("Graph.forEachNode: expecting a callback.");for(var e,n,r=this._nodes.values();!0!==(e=r.next()).done;)t((n=e.value).key,n.attributes)},o.findNode=function(t){if("function"!=typeof t)throw new V("Graph.findNode: expecting a callback.");for(var e,n,r=this._nodes.values();!0!==(e=r.next()).done;)if(t((n=e.value).key,n.attributes))return n.key},o.mapNodes=function(t){if("function"!=typeof t)throw new V("Graph.mapNode: expecting a callback.");for(var e,n,r=this._nodes.values(),o=new Array(this.order),i=0;!0!==(e=r.next()).done;)n=e.value,o[i++]=t(n.key,n.attributes);return o},o.someNode=function(t){if("function"!=typeof t)throw new V("Graph.someNode: expecting a callback.");for(var e,n,r=this._nodes.values();!0!==(e=r.next()).done;)if(t((n=e.value).key,n.attributes))return!0;return!1},o.everyNode=function(t){if("function"!=typeof t)throw new V("Graph.everyNode: expecting a callback.");for(var e,n,r=this._nodes.values();!0!==(e=r.next()).done;)if(!t((n=e.value).key,n.attributes))return!1;return!0},o.filterNodes=function(t){if("function"!=typeof t)throw new V("Graph.filterNodes: expecting a callback.");for(var e,n,r=this._nodes.values(),o=[];!0!==(e=r.next()).done;)t((n=e.value).key,n.attributes)&&o.push(n.key);return o},o.reduceNodes=function(t,e){if("function"!=typeof t)throw new V("Graph.reduceNodes: expecting a callback.");if(arguments.length<2)throw new V("Graph.reduceNodes: missing initial value. You must provide it because the callback takes more than one argument and we cannot infer the initial value from the first iteration, as you could with a simple array.");for(var n,r,o=e,i=this._nodes.values();!0!==(n=i.next()).done;)o=t(o,(r=n.value).key,r.attributes);return o},o.nodeEntries=function(){var t=this._nodes.values();return new P((function(){var e=t.next();if(e.done)return e;var n=e.value;return{value:{node:n.key,attributes:n.attributes},done:!1}}))},o.export=function(){var t=this,e=new Array(this._nodes.size),n=0;this._nodes.forEach((function(t,r){e[n++]=function(t,e){var n={key:t};return l(e.attributes)||(n.attributes=s({},e.attributes)),n}(r,t)}));var r=new Array(this._edges.size);return n=0,this._edges.forEach((function(e,o){r[n++]=function(t,e,n){var r={key:e,source:n.source.key,target:n.target.key};return l(n.attributes)||(r.attributes=s({},n.attributes)),"mixed"===t&&n.undirected&&(r.undirected=!0),r}(t.type,o,e)})),{options:{type:this.type,multi:this.multi,allowSelfLoops:this.allowSelfLoops},attributes:this.getAttributes(),nodes:e,edges:r}},o.import=function(t){var e,n,o,i,a,s=this,u=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(t instanceof r)return t.forEachNode((function(t,e){u?s.mergeNode(t,e):s.addNode(t,e)})),t.forEachEdge((function(t,e,n,r,o,i,a){u?a?s.mergeUndirectedEdgeWithKey(t,n,r,e):s.mergeDirectedEdgeWithKey(t,n,r,e):a?s.addUndirectedEdgeWithKey(t,n,r,e):s.addDirectedEdgeWithKey(t,n,r,e)})),this;if(!c(t))throw new V("Graph.import: invalid argument. Expecting a serialized graph or, alternatively, a Graph instance.");if(t.attributes){if(!c(t.attributes))throw new V("Graph.import: invalid attributes. Expecting a plain object.");u?this.mergeAttributes(t.attributes):this.replaceAttributes(t.attributes)}if(t.nodes){if(o=t.nodes,!Array.isArray(o))throw new V("Graph.import: invalid nodes. Expecting an array.");for(e=0,n=o.length;e<n;e++){gt(i=o[e]);var l=i,d=l.key,h=l.attributes;u?this.mergeNode(d,h):this.addNode(d,h)}}if(t.edges){var f=!1;if("undirected"===this.type&&(f=!0),o=t.edges,!Array.isArray(o))throw new V("Graph.import: invalid edges. Expecting an array.");for(e=0,n=o.length;e<n;e++){yt(a=o[e]);var p=a,m=p.source,g=p.target,y=p.attributes,v=p.undirected,w=void 0===v?f:v;"key"in a?(u?w?this.mergeUndirectedEdgeWithKey:this.mergeDirectedEdgeWithKey:w?this.addUndirectedEdgeWithKey:this.addDirectedEdgeWithKey).call(this,a.key,m,g,y):(u?w?this.mergeUndirectedEdge:this.mergeDirectedEdge:w?this.addUndirectedEdge:this.addDirectedEdge).call(this,m,g,y)}}return this},o.nullCopy=function(t){var e=new r(s({},this._options,t));return e.replaceAttributes(s({},this.getAttributes())),e},o.emptyCopy=function(t){var e=this.nullCopy(t);return this._nodes.forEach((function(t,n){var r=s({},t.attributes);t=new e.NodeDataClass(n,r),e._nodes.set(n,t)})),e},o.copy=function(t){if("string"==typeof(t=t||{}).type&&t.type!==this.type&&"mixed"!==t.type)throw new j('Graph.copy: cannot create an incompatible copy from "'.concat(this.type,'" type to "').concat(t.type,'" because this would mean losing information about the current graph.'));if("boolean"==typeof t.multi&&t.multi!==this.multi&&!0!==t.multi)throw new j("Graph.copy: cannot create an incompatible copy by downgrading a multi graph to a simple one because this would mean losing information about the current graph.");if("boolean"==typeof t.allowSelfLoops&&t.allowSelfLoops!==this.allowSelfLoops&&!0!==t.allowSelfLoops)throw new j("Graph.copy: cannot create an incompatible copy from a graph allowing self loops to one that does not because this would mean losing information about the current graph.");for(var e,n,r=this.emptyCopy(t),o=this._edges.values();!0!==(e=o.next()).done;)St(r,"copy",!1,(n=e.value).undirected,n.key,n.source.key,n.target.key,s({},n.attributes));return r},o.toJSON=function(){return this.export()},o.toString=function(){return"[object Graph]"},o.inspect=function(){var e=this,n={};this._nodes.forEach((function(t,e){n[e]=t.attributes}));var r={},o={};this._edges.forEach((function(t,n){var i,a=t.undirected?"--":"->",s="",u=t.source.key,c=t.target.key;t.undirected&&u>c&&(i=u,u=c,c=i);var l="(".concat(u,")").concat(a,"(").concat(c,")");n.startsWith("geid_")?e.multi&&(void 0===o[l]?o[l]=0:o[l]++,s+="".concat(o[l],". ")):s+="[".concat(n,"]: "),r[s+=l]=t.attributes}));var i={};for(var a in this)this.hasOwnProperty(a)&&!Et.has(a)&&"function"!=typeof this[a]&&"symbol"!==t(a)&&(i[a]=this[a]);return i.attributes=this._attributes,i.nodes=n,i.edges=r,d(i,"constructor",this.constructor),i},r}(m.exports.EventEmitter);"undefined"!=typeof Symbol&&(It.prototype[Symbol.for("nodejs.util.inspect.custom")]=It.prototype.inspect),[{name:function(t){return"".concat(t,"Edge")},generateKey:!0},{name:function(t){return"".concat(t,"DirectedEdge")},generateKey:!0,type:"directed"},{name:function(t){return"".concat(t,"UndirectedEdge")},generateKey:!0,type:"undirected"},{name:function(t){return"".concat(t,"EdgeWithKey")}},{name:function(t){return"".concat(t,"DirectedEdgeWithKey")},type:"directed"},{name:function(t){return"".concat(t,"UndirectedEdgeWithKey")},type:"undirected"}].forEach((function(t){["add","merge","update"].forEach((function(e){var n=t.name(e),r="add"===e?St:_t;t.generateKey?It.prototype[n]=function(o,i,a){return r(this,n,!0,"undirected"===(t.type||this.type),null,o,i,a,"update"===e)}:It.prototype[n]=function(o,i,a,s){return r(this,n,!1,"undirected"===(t.type||this.type),o,i,a,s,"update"===e)}}))})),function(t){K.forEach((function(e){var n=e.name,r=e.attacher;r(t,n("Node"),0),r(t,n("Source"),1),r(t,n("Target"),2),r(t,n("Opposite"),3)}))}(It),function(t){X.forEach((function(e){var n=e.name,r=e.attacher;r(t,n("Edge"),"mixed"),r(t,n("DirectedEdge"),"directed"),r(t,n("UndirectedEdge"),"undirected")}))}(It),function(t){tt.forEach((function(e){!function(t,e){var n=e.name,r=e.type,o=e.direction;t.prototype[n]=function(t,e){if("mixed"!==r&&"mixed"!==this.type&&r!==this.type)return[];if(!arguments.length)return function(t,e){if(0===t.size)return[];if("mixed"===e||e===t.type)return"function"==typeof Array.from?Array.from(t._edges.keys()):G(t._edges.keys(),t._edges.size);for(var n,r,o="undirected"===e?t.undirectedSize:t.directedSize,i=new Array(o),a="undirected"===e,s=t._edges.values(),u=0;!0!==(n=s.next()).done;)(r=n.value).undirected===a&&(i[u++]=r.key);return i}(this,r);if(1===arguments.length){t=""+t;var i=this._nodes.get(t);if(void 0===i)throw new W("Graph.".concat(n,': could not find the "').concat(t,'" node in the graph.'));return function(t,e,n,r){var o=[];return ut(!1,t,e,n,r,(function(t){o.push(t)})),o}(this.multi,"mixed"===r?this.type:r,o,i)}if(2===arguments.length){t=""+t,e=""+e;var a=this._nodes.get(t);if(!a)throw new W("Graph.".concat(n,': could not find the "').concat(t,'" source node in the graph.'));if(!this._nodes.has(e))throw new W("Graph.".concat(n,': could not find the "').concat(e,'" target node in the graph.'));return function(t,e,n,r,o){var i=[];return ct(!1,t,e,n,r,o,(function(t){i.push(t)})),i}(r,this.multi,o,a,e)}throw new V("Graph.".concat(n,": too many arguments (expecting 0, 1 or 2 and got ").concat(arguments.length,")."))}}(t,e),function(t,e){var n=e.name,r=e.type,o=e.direction,i="forEach"+n[0].toUpperCase()+n.slice(1,-1);t.prototype[i]=function(t,e,n){if("mixed"===r||"mixed"===this.type||r===this.type){if(1===arguments.length)return st(!1,this,r,n=t);if(2===arguments.length){t=""+t,n=e;var a=this._nodes.get(t);if(void 0===a)throw new W("Graph.".concat(i,': could not find the "').concat(t,'" node in the graph.'));return ut(!1,this.multi,"mixed"===r?this.type:r,o,a,n)}if(3===arguments.length){t=""+t,e=""+e;var s=this._nodes.get(t);if(!s)throw new W("Graph.".concat(i,': could not find the "').concat(t,'" source node in the graph.'));if(!this._nodes.has(e))throw new W("Graph.".concat(i,': could not find the "').concat(e,'" target node in the graph.'));return ct(!1,r,this.multi,o,s,e,n)}throw new V("Graph.".concat(i,": too many arguments (expecting 1, 2 or 3 and got ").concat(arguments.length,")."))}};var a="map"+n[0].toUpperCase()+n.slice(1);t.prototype[a]=function(){var t,e=Array.prototype.slice.call(arguments),n=e.pop();if(0===e.length){var o=0;"directed"!==r&&(o+=this.undirectedSize),"undirected"!==r&&(o+=this.directedSize),t=new Array(o);var a=0;e.push((function(e,r,o,i,s,u,c){t[a++]=n(e,r,o,i,s,u,c)}))}else t=[],e.push((function(e,r,o,i,a,s,u){t.push(n(e,r,o,i,a,s,u))}));return this[i].apply(this,e),t};var s="filter"+n[0].toUpperCase()+n.slice(1);t.prototype[s]=function(){var t=Array.prototype.slice.call(arguments),e=t.pop(),n=[];return t.push((function(t,r,o,i,a,s,u){e(t,r,o,i,a,s,u)&&n.push(t)})),this[i].apply(this,t),n};var u="reduce"+n[0].toUpperCase()+n.slice(1);t.prototype[u]=function(){var t,e,n=Array.prototype.slice.call(arguments);if(n.length<2||n.length>4)throw new V("Graph.".concat(u,": invalid number of arguments (expecting 2, 3 or 4 and got ").concat(n.length,")."));if("function"==typeof n[n.length-1]&&"function"!=typeof n[n.length-2])throw new V("Graph.".concat(u,": missing initial value. You must provide it because the callback takes more than one argument and we cannot infer the initial value from the first iteration, as you could with a simple array."));2===n.length?(t=n[0],e=n[1],n=[]):3===n.length?(t=n[1],e=n[2],n=[n[0]]):4===n.length&&(t=n[2],e=n[3],n=[n[0],n[1]]);var r=e;return n.push((function(e,n,o,i,a,s,u){r=t(r,e,n,o,i,a,s,u)})),this[i].apply(this,n),r}}(t,e),function(t,e){var n=e.name,r=e.type,o=e.direction,i="find"+n[0].toUpperCase()+n.slice(1,-1);t.prototype[i]=function(t,e,n){if("mixed"!==r&&"mixed"!==this.type&&r!==this.type)return!1;if(1===arguments.length)return st(!0,this,r,n=t);if(2===arguments.length){t=""+t,n=e;var a=this._nodes.get(t);if(void 0===a)throw new W("Graph.".concat(i,': could not find the "').concat(t,'" node in the graph.'));return ut(!0,this.multi,"mixed"===r?this.type:r,o,a,n)}if(3===arguments.length){t=""+t,e=""+e;var s=this._nodes.get(t);if(!s)throw new W("Graph.".concat(i,': could not find the "').concat(t,'" source node in the graph.'));if(!this._nodes.has(e))throw new W("Graph.".concat(i,': could not find the "').concat(e,'" target node in the graph.'));return ct(!0,r,this.multi,o,s,e,n)}throw new V("Graph.".concat(i,": too many arguments (expecting 1, 2 or 3 and got ").concat(arguments.length,")."))};var a="some"+n[0].toUpperCase()+n.slice(1,-1);t.prototype[a]=function(){var t=Array.prototype.slice.call(arguments),e=t.pop();return t.push((function(t,n,r,o,i,a,s){return e(t,n,r,o,i,a,s)})),!!this[i].apply(this,t)};var s="every"+n[0].toUpperCase()+n.slice(1,-1);t.prototype[s]=function(){var t=Array.prototype.slice.call(arguments),e=t.pop();return t.push((function(t,n,r,o,i,a,s){return!e(t,n,r,o,i,a,s)})),!this[i].apply(this,t)}}(t,e),function(t,e){var n=e.name,r=e.type,o=e.direction,i=n.slice(0,-1)+"Entries";t.prototype[i]=function(t,e){if("mixed"!==r&&"mixed"!==this.type&&r!==this.type)return P.empty();if(!arguments.length)return function(t,e){if(0===t.size)return P.empty();var n="mixed"!==e&&e!==t.type,r="undirected"===e,o=t._edges.values();return new P((function(){for(var t,e;;){if((t=o.next()).done)return t;if(e=t.value,!n||e.undirected===r)break}return{value:{edge:e.key,attributes:e.attributes,source:e.source.key,target:e.target.key,sourceAttributes:e.source.attributes,targetAttributes:e.target.attributes,undirected:e.undirected},done:!1}}))}(this,r);if(1===arguments.length){t=""+t;var n=this._nodes.get(t);if(!n)throw new W("Graph.".concat(i,': could not find the "').concat(t,'" node in the graph.'));return function(t,e,n){var r=P.empty();return"undirected"!==t&&("out"!==e&&void 0!==n.in&&(r=Z(r,rt(n.in))),"in"!==e&&void 0!==n.out&&(r=Z(r,rt(n.out,e?void 0:n.key)))),"directed"!==t&&void 0!==n.undirected&&(r=Z(r,rt(n.undirected))),r}(r,o,n)}if(2===arguments.length){t=""+t,e=""+e;var a=this._nodes.get(t);if(!a)throw new W("Graph.".concat(i,': could not find the "').concat(t,'" source node in the graph.'));if(!this._nodes.has(e))throw new W("Graph.".concat(i,': could not find the "').concat(e,'" target node in the graph.'));return function(t,e,n,r){var o=P.empty();return"undirected"!==t&&(void 0!==n.in&&"out"!==e&&r in n.in&&(o=Z(o,at(n.in,r))),void 0!==n.out&&"in"!==e&&r in n.out&&(e||n.key!==r)&&(o=Z(o,at(n.out,r)))),"directed"!==t&&void 0!==n.undirected&&r in n.undirected&&(o=Z(o,at(n.undirected,r))),o}(r,o,a,e)}throw new V("Graph.".concat(i,": too many arguments (expecting 0, 1 or 2 and got ").concat(arguments.length,")."))}}(t,e)}))}(It),function(t){lt.forEach((function(e){(function(t,e){var n=e.name,r=e.type,o=e.direction;t.prototype[n]=function(t){if("mixed"!==r&&"mixed"!==this.type&&r!==this.type)return[];t=""+t;var e=this._nodes.get(t);if(void 0===e)throw new W("Graph.".concat(n,': could not find the "').concat(t,'" node in the graph.'));return function(t,e,n){if("mixed"!==t){if("undirected"===t)return Object.keys(n.undirected);if("string"==typeof e)return Object.keys(n[e])}var r=[];return ft(!1,t,e,n,(function(t){r.push(t)})),r}("mixed"===r?this.type:r,o,e)}})(t,e),function(t,e){var n=e.name,r=e.type,o=e.direction,i="forEach"+n[0].toUpperCase()+n.slice(1,-1);t.prototype[i]=function(t,e){if("mixed"===r||"mixed"===this.type||r===this.type){t=""+t;var n=this._nodes.get(t);if(void 0===n)throw new W("Graph.".concat(i,': could not find the "').concat(t,'" node in the graph.'));ft(!1,"mixed"===r?this.type:r,o,n,e)}};var a="map"+n[0].toUpperCase()+n.slice(1);t.prototype[a]=function(t,e){var n=[];return this[i](t,(function(t,r){n.push(e(t,r))})),n};var s="filter"+n[0].toUpperCase()+n.slice(1);t.prototype[s]=function(t,e){var n=[];return this[i](t,(function(t,r){e(t,r)&&n.push(t)})),n};var u="reduce"+n[0].toUpperCase()+n.slice(1);t.prototype[u]=function(t,e,n){if(arguments.length<3)throw new V("Graph.".concat(u,": missing initial value. You must provide it because the callback takes more than one argument and we cannot infer the initial value from the first iteration, as you could with a simple array."));var r=n;return this[i](t,(function(t,n){r=e(r,t,n)})),r}}(t,e),function(t,e){var n=e.name,r=e.type,o=e.direction,i=n[0].toUpperCase()+n.slice(1,-1),a="find"+i;t.prototype[a]=function(t,e){if("mixed"===r||"mixed"===this.type||r===this.type){t=""+t;var n=this._nodes.get(t);if(void 0===n)throw new W("Graph.".concat(a,': could not find the "').concat(t,'" node in the graph.'));return ft(!0,"mixed"===r?this.type:r,o,n,e)}};var s="some"+i;t.prototype[s]=function(t,e){return!!this[a](t,e)};var u="every"+i;t.prototype[u]=function(t,e){return!this[a](t,(function(t,n){return!e(t,n)}))}}(t,e),function(t,e){var n=e.name,r=e.type,o=e.direction,i=n.slice(0,-1)+"Entries";t.prototype[i]=function(t){if("mixed"!==r&&"mixed"!==this.type&&r!==this.type)return P.empty();t=""+t;var e=this._nodes.get(t);if(void 0===e)throw new W("Graph.".concat(i,': could not find the "').concat(t,'" node in the graph.'));return function(t,e,n){if("mixed"!==t){if("undirected"===t)return pt(null,n,n.undirected);if("string"==typeof e)return pt(null,n,n[e])}var r=P.empty(),o=new dt;return"undirected"!==t&&("out"!==e&&(r=Z(r,pt(o,n,n.in))),"in"!==e&&(r=Z(r,pt(o,n,n.out)))),"directed"!==t&&(r=Z(r,pt(o,n,n.undirected))),r}("mixed"===r?this.type:r,o,e)}}(t,e)}))}(It);var Mt=function(t){function n(e){var n=s({type:"directed"},e);if("multi"in n&&!1!==n.multi)throw new V("DirectedGraph.from: inconsistent indication that the graph should be multi in given options!");if("directed"!==n.type)throw new V('DirectedGraph.from: inconsistent "'+n.type+'" type in given options!');return t.call(this,n)||this}return e(n,t),n}(It),Tt=function(t){function n(e){var n=s({type:"undirected"},e);if("multi"in n&&!1!==n.multi)throw new V("UndirectedGraph.from: inconsistent indication that the graph should be multi in given options!");if("undirected"!==n.type)throw new V('UndirectedGraph.from: inconsistent "'+n.type+'" type in given options!');return t.call(this,n)||this}return e(n,t),n}(It),Ot=function(t){function n(e){var n=s({multi:!0},e);if("multi"in n&&!0!==n.multi)throw new V("MultiGraph.from: inconsistent indication that the graph should be simple in given options!");return t.call(this,n)||this}return e(n,t),n}(It),Pt=function(t){function n(e){var n=s({type:"directed",multi:!0},e);if("multi"in n&&!0!==n.multi)throw new V("MultiDirectedGraph.from: inconsistent indication that the graph should be simple in given options!");if("directed"!==n.type)throw new V('MultiDirectedGraph.from: inconsistent "'+n.type+'" type in given options!');return t.call(this,n)||this}return e(n,t),n}(It),Lt=function(t){function n(e){var n=s({type:"undirected",multi:!0},e);if("multi"in n&&!0!==n.multi)throw new V("MultiUndirectedGraph.from: inconsistent indication that the graph should be simple in given options!");if("undirected"!==n.type)throw new V('MultiUndirectedGraph.from: inconsistent "'+n.type+'" type in given options!');return t.call(this,n)||this}return e(n,t),n}(It);function xt(t){t.from=function(e,n){var r=s({},e.options,n),o=new t(r);return o.import(e),o}}return xt(It),xt(Mt),xt(Tt),xt(Ot),xt(Pt),xt(Lt),It.Graph=It,It.DirectedGraph=Mt,It.UndirectedGraph=Tt,It.MultiGraph=Ot,It.MultiDirectedGraph=Pt,It.MultiUndirectedGraph=Lt,It.InvalidArgumentsGraphError=V,It.NotFoundGraphError=W,It.UsageGraphError=j,It}()},6572:function(t){var e;t.exports=(e=function(t,e){var n=Array.prototype.concat,r=Array.prototype.slice,o=Object.prototype.toString;function i(e,n){var r=e>n?e:n;return t.pow(10,17-~~(t.log(r>0?r:-r)*t.LOG10E))}var a=Array.isArray||function(t){return"[object Array]"===o.call(t)};function s(t){return"[object Function]"===o.call(t)}function u(t){return"number"==typeof t&&t-t==0}function c(){return new c._init(arguments)}function l(){return 0}function d(){return 1}function h(t,e){return t===e?1:0}c.fn=c.prototype,c._init=function(t){if(a(t[0]))if(a(t[0][0])){s(t[1])&&(t[0]=c.map(t[0],t[1]));for(var e=0;e<t[0].length;e++)this[e]=t[0][e];this.length=t[0].length}else this[0]=s(t[1])?c.map(t[0],t[1]):t[0],this.length=1;else if(u(t[0]))this[0]=c.seq.apply(null,t),this.length=1;else{if(t[0]instanceof c)return c(t[0].toArray());this[0]=[],this.length=1}return this},c._init.prototype=c.prototype,c._init.constructor=c,c.utils={calcRdx:i,isArray:a,isFunction:s,isNumber:u,toVector:function(t){return n.apply([],t)}},c._random_fn=t.random,c.setRandom=function(t){if("function"!=typeof t)throw new TypeError("fn is not a function");c._random_fn=t},c.extend=function(t){var e,n;if(1===arguments.length){for(n in t)c[n]=t[n];return this}for(e=1;e<arguments.length;e++)for(n in arguments[e])t[n]=arguments[e][n];return t},c.rows=function(t){return t.length||1},c.cols=function(t){return t[0].length||1},c.dimensions=function(t){return{rows:c.rows(t),cols:c.cols(t)}},c.row=function(t,e){return a(e)?e.map((function(e){return c.row(t,e)})):t[e]},c.rowa=function(t,e){return c.row(t,e)},c.col=function(t,e){if(a(e)){var n=c.arange(t.length).map((function(){return new Array(e.length)}));return e.forEach((function(e,r){c.arange(t.length).forEach((function(o){n[o][r]=t[o][e]}))})),n}for(var r=new Array(t.length),o=0;o<t.length;o++)r[o]=[t[o][e]];return r},c.cola=function(t,e){return c.col(t,e).map((function(t){return t[0]}))},c.diag=function(t){for(var e=c.rows(t),n=new Array(e),r=0;r<e;r++)n[r]=[t[r][r]];return n},c.antidiag=function(t){for(var e=c.rows(t)-1,n=new Array(e),r=0;e>=0;e--,r++)n[r]=[t[r][e]];return n},c.transpose=function(t){var e,n,r,o,i,s=[];for(a(t[0])||(t=[t]),n=t.length,r=t[0].length,i=0;i<r;i++){for(e=new Array(n),o=0;o<n;o++)e[o]=t[o][i];s.push(e)}return 1===s.length?s[0]:s},c.map=function(t,e,n){var r,o,i,s,u;for(a(t[0])||(t=[t]),o=t.length,i=t[0].length,s=n?t:new Array(o),r=0;r<o;r++)for(s[r]||(s[r]=new Array(i)),u=0;u<i;u++)s[r][u]=e(t[r][u],r,u);return 1===s.length?s[0]:s},c.cumreduce=function(t,e,n){var r,o,i,s,u;for(a(t[0])||(t=[t]),o=t.length,i=t[0].length,s=n?t:new Array(o),r=0;r<o;r++)for(s[r]||(s[r]=new Array(i)),i>0&&(s[r][0]=t[r][0]),u=1;u<i;u++)s[r][u]=e(s[r][u-1],t[r][u]);return 1===s.length?s[0]:s},c.alter=function(t,e){return c.map(t,e,!0)},c.create=function(t,e,n){var r,o,i=new Array(t);for(s(e)&&(n=e,e=t),r=0;r<t;r++)for(i[r]=new Array(e),o=0;o<e;o++)i[r][o]=n(r,o);return i},c.zeros=function(t,e){return u(e)||(e=t),c.create(t,e,l)},c.ones=function(t,e){return u(e)||(e=t),c.create(t,e,d)},c.rand=function(t,e){return u(e)||(e=t),c.create(t,e,c._random_fn)},c.identity=function(t,e){return u(e)||(e=t),c.create(t,e,h)},c.symmetric=function(t){var e,n,r=t.length;if(t.length!==t[0].length)return!1;for(e=0;e<r;e++)for(n=0;n<r;n++)if(t[n][e]!==t[e][n])return!1;return!0},c.clear=function(t){return c.alter(t,l)},c.seq=function(t,e,n,r){s(r)||(r=!1);var o,a=[],u=i(t,e),c=(e*u-t*u)/((n-1)*u),l=t;for(o=0;l<=e&&o<n;l=(t*u+c*u*++o)/u)a.push(r?r(l,o):l);return a},c.arange=function(t,n,r){var o,i=[];if(r=r||1,n===e&&(n=t,t=0),t===n||0===r)return[];if(t<n&&r<0)return[];if(t>n&&r>0)return[];if(r>0)for(o=t;o<n;o+=r)i.push(o);else for(o=t;o>n;o+=r)i.push(o);return i},c.slice=function(){function t(t,n,r,o){var i,a=[],s=t.length;if(n===e&&r===e&&o===e)return c.copy(t);if(o=o||1,(n=(n=n||0)>=0?n:s+n)===(r=(r=r||t.length)>=0?r:s+r)||0===o)return[];if(n<r&&o<0)return[];if(n>r&&o>0)return[];if(o>0)for(i=n;i<r;i+=o)a.push(t[i]);else for(i=n;i>r;i+=o)a.push(t[i]);return a}return function(e,n){var r,o;return u((n=n||{}).row)?u(n.col)?e[n.row][n.col]:t(c.rowa(e,n.row),(r=n.col||{}).start,r.end,r.step):u(n.col)?t(c.cola(e,n.col),(o=n.row||{}).start,o.end,o.step):(o=n.row||{},r=n.col||{},t(e,o.start,o.end,o.step).map((function(e){return t(e,r.start,r.end,r.step)})))}}(),c.sliceAssign=function(n,r,o){var i,a;if(u(r.row)){if(u(r.col))return n[r.row][r.col]=o;r.col=r.col||{},r.col.start=r.col.start||0,r.col.end=r.col.end||n[0].length,r.col.step=r.col.step||1,i=c.arange(r.col.start,t.min(n.length,r.col.end),r.col.step);var s=r.row;return i.forEach((function(t,e){n[s][t]=o[e]})),n}if(u(r.col)){r.row=r.row||{},r.row.start=r.row.start||0,r.row.end=r.row.end||n.length,r.row.step=r.row.step||1,a=c.arange(r.row.start,t.min(n[0].length,r.row.end),r.row.step);var l=r.col;return a.forEach((function(t,e){n[t][l]=o[e]})),n}return o[0].length===e&&(o=[o]),r.row.start=r.row.start||0,r.row.end=r.row.end||n.length,r.row.step=r.row.step||1,r.col.start=r.col.start||0,r.col.end=r.col.end||n[0].length,r.col.step=r.col.step||1,a=c.arange(r.row.start,t.min(n.length,r.row.end),r.row.step),i=c.arange(r.col.start,t.min(n[0].length,r.col.end),r.col.step),a.forEach((function(t,e){i.forEach((function(r,i){n[t][r]=o[e][i]}))})),n},c.diagonal=function(t){var e=c.zeros(t.length,t.length);return t.forEach((function(t,n){e[n][n]=t})),e},c.copy=function(t){return t.map((function(t){return u(t)?t:t.map((function(t){return t}))}))};var f=c.prototype;return f.length=0,f.push=Array.prototype.push,f.sort=Array.prototype.sort,f.splice=Array.prototype.splice,f.slice=Array.prototype.slice,f.toArray=function(){return this.length>1?r.call(this):r.call(this)[0]},f.map=function(t,e){return c(c.map(this,t,e))},f.cumreduce=function(t,e){return c(c.cumreduce(this,t,e))},f.alter=function(t){return c.alter(this,t),this},function(t){for(var e=0;e<t.length;e++)!function(t){f[t]=function(e){var n,r=this;return e?(setTimeout((function(){e.call(r,f[t].call(r))})),this):(n=c[t](this),a(n)?c(n):n)}}(t[e])}("transpose clear symmetric rows cols dimensions diag antidiag".split(" ")),function(t){for(var e=0;e<t.length;e++)!function(t){f[t]=function(e,n){var r=this;return n?(setTimeout((function(){n.call(r,f[t].call(r,e))})),this):c(c[t](this,e))}}(t[e])}("row col".split(" ")),function(t){for(var e=0;e<t.length;e++)!function(t){f[t]=function(){return c(c[t].apply(null,arguments))}}(t[e])}("create zeros ones rand identity".split(" ")),c}(Math),function(t,e){var n=t.utils.isFunction;function r(t,e){return t-e}function o(t,n,r){return e.max(n,e.min(t,r))}t.sum=function(t){for(var e=0,n=t.length;--n>=0;)e+=t[n];return e},t.sumsqrd=function(t){for(var e=0,n=t.length;--n>=0;)e+=t[n]*t[n];return e},t.sumsqerr=function(e){for(var n,r=t.mean(e),o=0,i=e.length;--i>=0;)o+=(n=e[i]-r)*n;return o},t.sumrow=function(t){for(var e=0,n=t.length;--n>=0;)e+=t[n];return e},t.product=function(t){for(var e=1,n=t.length;--n>=0;)e*=t[n];return e},t.min=function(t){for(var e=t[0],n=0;++n<t.length;)t[n]<e&&(e=t[n]);return e},t.max=function(t){for(var e=t[0],n=0;++n<t.length;)t[n]>e&&(e=t[n]);return e},t.unique=function(t){for(var e={},n=[],r=0;r<t.length;r++)e[t[r]]||(e[t[r]]=!0,n.push(t[r]));return n},t.mean=function(e){return t.sum(e)/e.length},t.meansqerr=function(e){return t.sumsqerr(e)/e.length},t.geomean=function(n){var r=n.map(e.log),o=t.mean(r);return e.exp(o)},t.median=function(t){var e=t.length,n=t.slice().sort(r);return 1&e?n[e/2|0]:(n[e/2-1]+n[e/2])/2},t.cumsum=function(e){return t.cumreduce(e,(function(t,e){return t+e}))},t.cumprod=function(e){return t.cumreduce(e,(function(t,e){return t*e}))},t.diff=function(t){var e,n=[],r=t.length;for(e=1;e<r;e++)n.push(t[e]-t[e-1]);return n},t.rank=function(t){var e,n=[],o={};for(e=0;e<t.length;e++)o[u=t[e]]?o[u]++:(o[u]=1,n.push(u));var i=n.sort(r),a={},s=1;for(e=0;e<i.length;e++){var u,c=o[u=i[e]],l=(s+(s+c-1))/2;a[u]=l,s+=c}return t.map((function(t){return a[t]}))},t.mode=function(t){var e,n=t.length,o=t.slice().sort(r),i=1,a=0,s=0,u=[];for(e=0;e<n;e++)o[e]===o[e+1]?i++:(i>a?(u=[o[e]],a=i,s=0):i===a&&(u.push(o[e]),s++),i=1);return 0===s?u[0]:u},t.range=function(e){return t.max(e)-t.min(e)},t.variance=function(e,n){return t.sumsqerr(e)/(e.length-(n?1:0))},t.pooledvariance=function(e){return e.reduce((function(e,n){return e+t.sumsqerr(n)}),0)/(e.reduce((function(t,e){return t+e.length}),0)-e.length)},t.deviation=function(e){for(var n=t.mean(e),r=e.length,o=new Array(r),i=0;i<r;i++)o[i]=e[i]-n;return o},t.stdev=function(n,r){return e.sqrt(t.variance(n,r))},t.pooledstdev=function(n){return e.sqrt(t.pooledvariance(n))},t.meandev=function(n){for(var r=t.mean(n),o=[],i=n.length-1;i>=0;i--)o.push(e.abs(n[i]-r));return t.mean(o)},t.meddev=function(n){for(var r=t.median(n),o=[],i=n.length-1;i>=0;i--)o.push(e.abs(n[i]-r));return t.median(o)},t.coeffvar=function(e){return t.stdev(e)/t.mean(e)},t.quartiles=function(t){var n=t.length,o=t.slice().sort(r);return[o[e.round(n/4)-1],o[e.round(n/2)-1],o[e.round(3*n/4)-1]]},t.quantiles=function(t,n,i,a){var s,u,c,l,d,h=t.slice().sort(r),f=[n.length],p=t.length;for(void 0===i&&(i=3/8),void 0===a&&(a=3/8),s=0;s<n.length;s++)c=p*(u=n[s])+(i+u*(1-i-a)),l=e.floor(o(c,1,p-1)),d=o(c-l,0,1),f[s]=(1-d)*h[l-1]+d*h[l];return f},t.percentile=function(t,e,n){var o=t.slice().sort(r),i=e*(o.length+(n?1:-1))+(n?0:1),a=parseInt(i),s=i-a;return a+1<o.length?o[a-1]+s*(o[a]-o[a-1]):o[a-1]},t.percentileOfScore=function(t,e,n){var r,o,i=0,a=t.length,s=!1;for("strict"===n&&(s=!0),o=0;o<a;o++)r=t[o],(s&&r<e||!s&&r<=e)&&i++;return i/a},t.histogram=function(n,r){r=r||4;var o,i=t.min(n),a=(t.max(n)-i)/r,s=n.length,u=[];for(o=0;o<r;o++)u[o]=0;for(o=0;o<s;o++)u[e.min(e.floor((n[o]-i)/a),r-1)]+=1;return u},t.covariance=function(e,n){var r,o=t.mean(e),i=t.mean(n),a=e.length,s=new Array(a);for(r=0;r<a;r++)s[r]=(e[r]-o)*(n[r]-i);return t.sum(s)/(a-1)},t.corrcoeff=function(e,n){return t.covariance(e,n)/t.stdev(e,1)/t.stdev(n,1)},t.spearmancoeff=function(e,n){return e=t.rank(e),n=t.rank(n),t.corrcoeff(e,n)},t.stanMoment=function(n,r){for(var o=t.mean(n),i=t.stdev(n),a=n.length,s=0,u=0;u<a;u++)s+=e.pow((n[u]-o)/i,r);return s/n.length},t.skewness=function(e){return t.stanMoment(e,3)},t.kurtosis=function(e){return t.stanMoment(e,4)-3};var i=t.prototype;!function(e){for(var r=0;r<e.length;r++)!function(e){i[e]=function(r,o){var a=[],s=0,u=this;if(n(r)&&(o=r,r=!1),o)return setTimeout((function(){o.call(u,i[e].call(u,r))})),this;if(this.length>1){for(u=!0===r?this:this.transpose();s<u.length;s++)a[s]=t[e](u[s]);return a}return t[e](this[0],r)}}(e[r])}("cumsum cumprod".split(" ")),function(e){for(var r=0;r<e.length;r++)!function(e){i[e]=function(r,o){var a=[],s=0,u=this;if(n(r)&&(o=r,r=!1),o)return setTimeout((function(){o.call(u,i[e].call(u,r))})),this;if(this.length>1){for("sumrow"!==e&&(u=!0===r?this:this.transpose());s<u.length;s++)a[s]=t[e](u[s]);return!0===r?t[e](t.utils.toVector(a)):a}return t[e](this[0],r)}}(e[r])}("sum sumsqrd sumsqerr sumrow product min max unique mean meansqerr geomean median diff rank mode range variance deviation stdev meandev meddev coeffvar quartiles histogram skewness kurtosis".split(" ")),function(e){for(var r=0;r<e.length;r++)!function(e){i[e]=function(){var r,o=[],a=0,s=this,u=Array.prototype.slice.call(arguments);if(n(u[u.length-1])){r=u[u.length-1];var c=u.slice(0,u.length-1);return setTimeout((function(){r.call(s,i[e].apply(s,c))})),this}r=void 0;var l=function(n){return t[e].apply(s,[n].concat(u))};if(this.length>1){for(s=s.transpose();a<s.length;a++)o[a]=l(s[a]);return o}return l(this[0])}}(e[r])}("quantiles percentileOfScore".split(" "))}(e,Math),function(t,e){t.gammaln=function(t){var n,r,o,i=0,a=[76.18009172947146,-86.50532032941678,24.01409824083091,-1.231739572450155,.001208650973866179,-5395239384953e-18],s=1.000000000190015;for(o=(r=n=t)+5.5,o-=(n+.5)*e.log(o);i<6;i++)s+=a[i]/++r;return e.log(2.5066282746310007*s/n)-o},t.loggam=function(t){var n,r,o,i,a,s,u,c=[.08333333333333333,-.002777777777777778,.0007936507936507937,-.0005952380952380952,.0008417508417508418,-.001917526917526918,.00641025641025641,-.02955065359477124,.1796443723688307,-1.3924322169059];if(n=t,u=0,1==t||2==t)return 0;for(t<=7&&(n=t+(u=e.floor(7-t))),r=1/(n*n),o=2*e.PI,a=c[9],s=8;s>=0;s--)a*=r,a+=c[s];if(i=a/n+.5*e.log(o)+(n-.5)*e.log(n)-n,t<=7)for(s=1;s<=u;s++)i-=e.log(n-1),n-=1;return i},t.gammafn=function(t){var n,r,o,i,a=[-1.716185138865495,24.76565080557592,-379.80425647094563,629.3311553128184,866.9662027904133,-31451.272968848367,-36144.413418691176,66456.14382024054],s=[-30.8402300119739,315.35062697960416,-1015.1563674902192,-3107.771671572311,22538.11842098015,4755.846277527881,-134659.9598649693,-115132.2596755535],u=!1,c=0,l=0,d=0,h=t;if(t>171.6243769536076)return 1/0;if(h<=0){if(!(i=h%1+36e-17))return 1/0;u=(1&h?-1:1)*e.PI/e.sin(e.PI*i),h=1-h}for(o=h,r=h<1?h++:(h-=c=(0|h)-1)-1,n=0;n<8;++n)d=(d+a[n])*r,l=l*r+s[n];if(i=d/l+1,o<h)i/=o;else if(o>h)for(n=0;n<c;++n)i*=h,h++;return u&&(i=u/i),i},t.gammap=function(e,n){return t.lowRegGamma(e,n)*t.gammafn(e)},t.lowRegGamma=function(n,r){var o,i=t.gammaln(n),a=n,s=1/n,u=s,c=r+1-n,l=1/1e-30,d=1/c,h=d,f=1,p=-~(8.5*e.log(n>=1?n:1/n)+.4*n+17);if(r<0||n<=0)return NaN;if(r<n+1){for(;f<=p;f++)s+=u*=r/++a;return s*e.exp(-r+n*e.log(r)-i)}for(;f<=p;f++)h*=(d=1/(d=(o=-f*(f-n))*d+(c+=2)))*(l=c+o/l);return 1-h*e.exp(-r+n*e.log(r)-i)},t.factorialln=function(e){return e<0?NaN:t.gammaln(e+1)},t.factorial=function(e){return e<0?NaN:t.gammafn(e+1)},t.combination=function(n,r){return n>170||r>170?e.exp(t.combinationln(n,r)):t.factorial(n)/t.factorial(r)/t.factorial(n-r)},t.combinationln=function(e,n){return t.factorialln(e)-t.factorialln(n)-t.factorialln(e-n)},t.permutation=function(e,n){return t.factorial(e)/t.factorial(e-n)},t.betafn=function(n,r){if(!(n<=0||r<=0))return n+r>170?e.exp(t.betaln(n,r)):t.gammafn(n)*t.gammafn(r)/t.gammafn(n+r)},t.betaln=function(e,n){return t.gammaln(e)+t.gammaln(n)-t.gammaln(e+n)},t.betacf=function(t,n,r){var o,i,a,s,u=1e-30,c=1,l=n+r,d=n+1,h=n-1,f=1,p=1-l*t/d;for(e.abs(p)<u&&(p=u),s=p=1/p;c<=100&&(p=1+(i=c*(r-c)*t/((h+(o=2*c))*(n+o)))*p,e.abs(p)<u&&(p=u),f=1+i/f,e.abs(f)<u&&(f=u),s*=(p=1/p)*f,p=1+(i=-(n+c)*(l+c)*t/((n+o)*(d+o)))*p,e.abs(p)<u&&(p=u),f=1+i/f,e.abs(f)<u&&(f=u),s*=a=(p=1/p)*f,!(e.abs(a-1)<3e-7));c++);return s},t.gammapinv=function(n,r){var o,i,a,s,u,c,l=0,d=r-1,h=t.gammaln(r);if(n>=1)return e.max(100,r+100*e.sqrt(r));if(n<=0)return 0;for(r>1?(u=e.log(d),c=e.exp(d*(u-1)-h),s=n<.5?n:1-n,o=(2.30753+.27061*(i=e.sqrt(-2*e.log(s))))/(1+i*(.99229+.04481*i))-i,n<.5&&(o=-o),o=e.max(.001,r*e.pow(1-1/(9*r)-o/(3*e.sqrt(r)),3))):o=n<(i=1-r*(.253+.12*r))?e.pow(n/i,1/r):1-e.log(1-(n-i)/(1-i));l<12;l++){if(o<=0)return 0;if((o-=i=(a=(t.lowRegGamma(r,o)-n)/(i=r>1?c*e.exp(-(o-d)+d*(e.log(o)-u)):e.exp(-o+d*e.log(o)-h)))/(1-.5*e.min(1,a*((r-1)/o-1))))<=0&&(o=.5*(o+i)),e.abs(i)<1e-8*o)break}return o},t.erf=function(t){var n,r,o,i,a=[-1.3026537197817094,.6419697923564902,.019476473204185836,-.00956151478680863,-.000946595344482036,.000366839497852761,42523324806907e-18,-20278578112534e-18,-1624290004647e-18,130365583558e-17,1.5626441722e-8,-8.5238095915e-8,6.529054439e-9,5.059343495e-9,-9.91364156e-10,-2.27365122e-10,96467911e-18,2394038e-18,-6886027e-18,894487e-18,313092e-18,-112708e-18,381e-18,7106e-18,-1523e-18,-94e-18,121e-18,-28e-18],s=a.length-1,u=!1,c=0,l=0;for(t<0&&(t=-t,u=!0),r=4*(n=2/(2+t))-2;s>0;s--)o=c,c=r*c-l+a[s],l=o;return i=n*e.exp(-t*t+.5*(a[0]+r*c)-l),u?i-1:1-i},t.erfc=function(e){return 1-t.erf(e)},t.erfcinv=function(n){var r,o,i,a,s=0;if(n>=2)return-100;if(n<=0)return 100;for(a=n<1?n:2-n,r=-.70711*((2.30753+.27061*(i=e.sqrt(-2*e.log(a/2))))/(1+i*(.99229+.04481*i))-i);s<2;s++)r+=(o=t.erfc(r)-a)/(1.1283791670955126*e.exp(-r*r)-r*o);return n<1?r:-r},t.ibetainv=function(n,r,o){var i,a,s,u,c,l,d,h,f,p,m=r-1,g=o-1,y=0;if(n<=0)return 0;if(n>=1)return 1;for(r>=1&&o>=1?(s=n<.5?n:1-n,l=(2.30753+.27061*(u=e.sqrt(-2*e.log(s))))/(1+u*(.99229+.04481*u))-u,n<.5&&(l=-l),d=(l*l-3)/6,h=2/(1/(2*r-1)+1/(2*o-1)),f=l*e.sqrt(d+h)/h-(1/(2*o-1)-1/(2*r-1))*(d+5/6-2/(3*h)),l=r/(r+o*e.exp(2*f))):(i=e.log(r/(r+o)),a=e.log(o/(r+o)),l=n<(u=e.exp(r*i)/r)/(f=u+(c=e.exp(o*a)/o))?e.pow(r*f*n,1/r):1-e.pow(o*f*(1-n),1/o)),p=-t.gammaln(r)-t.gammaln(o)+t.gammaln(r+o);y<10;y++){if(0===l||1===l)return l;if((l-=u=(c=(t.ibeta(l,r,o)-n)/(u=e.exp(m*e.log(l)+g*e.log(1-l)+p)))/(1-.5*e.min(1,c*(m/l-g/(1-l)))))<=0&&(l=.5*(l+u)),l>=1&&(l=.5*(l+u+1)),e.abs(u)<1e-8*l&&y>0)break}return l},t.ibeta=function(n,r,o){var i=0===n||1===n?0:e.exp(t.gammaln(r+o)-t.gammaln(r)-t.gammaln(o)+r*e.log(n)+o*e.log(1-n));return!(n<0||n>1)&&(n<(r+1)/(r+o+2)?i*t.betacf(n,r,o)/r:1-i*t.betacf(1-n,o,r)/o)},t.randn=function(n,r){var o,i,a,s,u;if(r||(r=n),n)return t.create(n,r,(function(){return t.randn()}));do{o=t._random_fn(),i=1.7156*(t._random_fn()-.5),u=(a=o-.449871)*a+(s=e.abs(i)+.386595)*(.196*s-.25472*a)}while(u>.27597&&(u>.27846||i*i>-4*e.log(o)*o*o));return i/o},t.randg=function(n,r,o){var i,a,s,u,c,l,d=n;if(o||(o=r),n||(n=1),r)return(l=t.zeros(r,o)).alter((function(){return t.randg(n)})),l;n<1&&(n+=1),i=n-1/3,a=1/e.sqrt(9*i);do{do{u=1+a*(c=t.randn())}while(u<=0);u*=u*u,s=t._random_fn()}while(s>1-.331*e.pow(c,4)&&e.log(s)>.5*c*c+i*(1-u+e.log(u)));if(n==d)return i*u;do{s=t._random_fn()}while(0===s);return e.pow(s,1/d)*i*u},function(e){for(var n=0;n<e.length;n++)!function(e){t.fn[e]=function(){return t(t.map(this,(function(n){return t[e](n)})))}}(e[n])}("gammaln gammafn factorial factorialln".split(" ")),function(e){for(var n=0;n<e.length;n++)!function(e){t.fn[e]=function(){return t(t[e].apply(null,arguments))}}(e[n])}("randn".split(" "))}(e,Math),function(t,e){function n(t,n,r,o){for(var i,a=0,s=1,u=1,c=1,l=0,d=0;e.abs((u-d)/u)>o;)d=u,s=c+(i=-(n+l)*(n+r+l)*t/(n+2*l)/(n+2*l+1))*s,u=(a=u+i*a)+(i=(l+=1)*(r-l)*t/(n+2*l-1)/(n+2*l))*u,a/=c=s+i*c,s/=c,u/=c,c=1;return u/n}function r(n,r,o){var i=[.9815606342467192,.9041172563704749,.7699026741943047,.5873179542866175,.3678314989981802,.1252334085114689],a=[.04717533638651183,.10693932599531843,.16007832854334622,.20316742672306592,.2334925365383548,.24914704581340277],s=.5*n;if(s>=8)return 1;var u,c=2*t.normal.cdf(s,0,1,1,0)-1;c=c>=e.exp(-50/o)?e.pow(c,o):0;for(var l=s,d=(8-s)/(u=n>3?2:3),h=l+d,f=0,p=o-1,m=1;m<=u;m++){for(var g=0,y=.5*(h+l),v=.5*(h-l),w=1;w<=12;w++){var b,E=y+v*(6<w?i[(b=12-w+1)-1]:-i[(b=w)-1]),A=E*E;if(A>60)break;var C=2*t.normal.cdf(E,0,1,1,0)*.5-2*t.normal.cdf(E,n,1,1,0)*.5;C>=e.exp(-30/p)&&(g+=C=a[b-1]*e.exp(-.5*A)*e.pow(C,p))}f+=g*=2*v*o/e.sqrt(2*e.PI),l=h,h+=d}return(c+=f)<=e.exp(-30/r)?0:(c=e.pow(c,r))>=1?1:c}!function(e){for(var n=0;n<e.length;n++)!function(e){t[e]=function t(e,n,r){return this instanceof t?(this._a=e,this._b=n,this._c=r,this):new t(e,n,r)},t.fn[e]=function(n,r,o){var i=t[e](n,r,o);return i.data=this,i},t[e].prototype.sample=function(n){var r=this._a,o=this._b,i=this._c;return n?t.alter(n,(function(){return t[e].sample(r,o,i)})):t[e].sample(r,o,i)},function(n){for(var r=0;r<n.length;r++)!function(n){t[e].prototype[n]=function(r){var o=this._a,i=this._b,a=this._c;return r||0===r||(r=this.data),"number"!=typeof r?t.fn.map.call(r,(function(r){return t[e][n](r,o,i,a)})):t[e][n](r,o,i,a)}}(n[r])}("pdf cdf inv".split(" ")),function(n){for(var r=0;r<n.length;r++)!function(n){t[e].prototype[n]=function(){return t[e][n](this._a,this._b,this._c)}}(n[r])}("mean median mode variance".split(" "))}(e[n])}("beta centralF cauchy chisquare exponential gamma invgamma kumaraswamy laplace lognormal noncentralt normal pareto studentt weibull uniform binomial negbin hypgeom poisson triangular tukey arcsine".split(" ")),t.extend(t.beta,{pdf:function(n,r,o){return n>1||n<0?0:1==r&&1==o?1:r<512&&o<512?e.pow(n,r-1)*e.pow(1-n,o-1)/t.betafn(r,o):e.exp((r-1)*e.log(n)+(o-1)*e.log(1-n)-t.betaln(r,o))},cdf:function(e,n,r){return e>1||e<0?1*(e>1):t.ibeta(e,n,r)},inv:function(e,n,r){return t.ibetainv(e,n,r)},mean:function(t,e){return t/(t+e)},median:function(e,n){return t.ibetainv(.5,e,n)},mode:function(t,e){return(t-1)/(t+e-2)},sample:function(e,n){var r=t.randg(e);return r/(r+t.randg(n))},variance:function(t,n){return t*n/(e.pow(t+n,2)*(t+n+1))}}),t.extend(t.centralF,{pdf:function(n,r,o){var i;return n<0?0:r<=2?0===n&&r<2?1/0:0===n&&2===r?1:1/t.betafn(r/2,o/2)*e.pow(r/o,r/2)*e.pow(n,r/2-1)*e.pow(1+r/o*n,-(r+o)/2):(i=r*n/(o+n*r),r*(o/(o+n*r))/2*t.binomial.pdf((r-2)/2,(r+o-2)/2,i))},cdf:function(e,n,r){return e<0?0:t.ibeta(n*e/(n*e+r),n/2,r/2)},inv:function(e,n,r){return r/(n*(1/t.ibetainv(e,n/2,r/2)-1))},mean:function(t,e){return e>2?e/(e-2):void 0},mode:function(t,e){return t>2?e*(t-2)/(t*(e+2)):void 0},sample:function(e,n){return 2*t.randg(e/2)/e/(2*t.randg(n/2)/n)},variance:function(t,e){if(!(e<=4))return 2*e*e*(t+e-2)/(t*(e-2)*(e-2)*(e-4))}}),t.extend(t.cauchy,{pdf:function(t,n,r){return r<0?0:r/(e.pow(t-n,2)+e.pow(r,2))/e.PI},cdf:function(t,n,r){return e.atan((t-n)/r)/e.PI+.5},inv:function(t,n,r){return n+r*e.tan(e.PI*(t-.5))},median:function(t){return t},mode:function(t){return t},sample:function(n,r){return t.randn()*e.sqrt(1/(2*t.randg(.5)))*r+n}}),t.extend(t.chisquare,{pdf:function(n,r){return n<0?0:0===n&&2===r?.5:e.exp((r/2-1)*e.log(n)-n/2-r/2*e.log(2)-t.gammaln(r/2))},cdf:function(e,n){return e<0?0:t.lowRegGamma(n/2,e/2)},inv:function(e,n){return 2*t.gammapinv(e,.5*n)},mean:function(t){return t},median:function(t){return t*e.pow(1-2/(9*t),3)},mode:function(t){return t-2>0?t-2:0},sample:function(e){return 2*t.randg(e/2)},variance:function(t){return 2*t}}),t.extend(t.exponential,{pdf:function(t,n){return t<0?0:n*e.exp(-n*t)},cdf:function(t,n){return t<0?0:1-e.exp(-n*t)},inv:function(t,n){return-e.log(1-t)/n},mean:function(t){return 1/t},median:function(t){return 1/t*e.log(2)},mode:function(){return 0},sample:function(n){return-1/n*e.log(t._random_fn())},variance:function(t){return e.pow(t,-2)}}),t.extend(t.gamma,{pdf:function(n,r,o){return n<0?0:0===n&&1===r?1/o:e.exp((r-1)*e.log(n)-n/o-t.gammaln(r)-r*e.log(o))},cdf:function(e,n,r){return e<0?0:t.lowRegGamma(n,e/r)},inv:function(e,n,r){return t.gammapinv(e,n)*r},mean:function(t,e){return t*e},mode:function(t,e){if(t>1)return(t-1)*e},sample:function(e,n){return t.randg(e)*n},variance:function(t,e){return t*e*e}}),t.extend(t.invgamma,{pdf:function(n,r,o){return n<=0?0:e.exp(-(r+1)*e.log(n)-o/n-t.gammaln(r)+r*e.log(o))},cdf:function(e,n,r){return e<=0?0:1-t.lowRegGamma(n,r/e)},inv:function(e,n,r){return r/t.gammapinv(1-e,n)},mean:function(t,e){return t>1?e/(t-1):void 0},mode:function(t,e){return e/(t+1)},sample:function(e,n){return n/t.randg(e)},variance:function(t,e){if(!(t<=2))return e*e/((t-1)*(t-1)*(t-2))}}),t.extend(t.kumaraswamy,{pdf:function(t,n,r){return 0===t&&1===n?r:1===t&&1===r?n:e.exp(e.log(n)+e.log(r)+(n-1)*e.log(t)+(r-1)*e.log(1-e.pow(t,n)))},cdf:function(t,n,r){return t<0?0:t>1?1:1-e.pow(1-e.pow(t,n),r)},inv:function(t,n,r){return e.pow(1-e.pow(1-t,1/r),1/n)},mean:function(e,n){return n*t.gammafn(1+1/e)*t.gammafn(n)/t.gammafn(1+1/e+n)},median:function(t,n){return e.pow(1-e.pow(2,-1/n),1/t)},mode:function(t,n){if(t>=1&&n>=1&&1!==t&&1!==n)return e.pow((t-1)/(t*n-1),1/t)},variance:function(){throw new Error("variance not yet implemented")}}),t.extend(t.lognormal,{pdf:function(t,n,r){return t<=0?0:e.exp(-e.log(t)-.5*e.log(2*e.PI)-e.log(r)-e.pow(e.log(t)-n,2)/(2*r*r))},cdf:function(n,r,o){return n<0?0:.5+.5*t.erf((e.log(n)-r)/e.sqrt(2*o*o))},inv:function(n,r,o){return e.exp(-1.4142135623730951*o*t.erfcinv(2*n)+r)},mean:function(t,n){return e.exp(t+n*n/2)},median:function(t){return e.exp(t)},mode:function(t,n){return e.exp(t-n*n)},sample:function(n,r){return e.exp(t.randn()*r+n)},variance:function(t,n){return(e.exp(n*n)-1)*e.exp(2*t+n*n)}}),t.extend(t.noncentralt,{pdf:function(n,r,o){return e.abs(o)<1e-14?t.studentt.pdf(n,r):e.abs(n)<1e-14?e.exp(t.gammaln((r+1)/2)-o*o/2-.5*e.log(e.PI*r)-t.gammaln(r/2)):r/n*(t.noncentralt.cdf(n*e.sqrt(1+2/r),r+2,o)-t.noncentralt.cdf(n,r,o))},cdf:function(n,r,o){var i=1e-14;if(e.abs(o)<i)return t.studentt.cdf(n,r);var a=!1;n<0&&(a=!0,o=-o);for(var s=t.normal.cdf(-o,0,1),u=i+1,c=u,l=n*n/(n*n+r),d=0,h=e.exp(-o*o/2),f=e.exp(-o*o/2-.5*e.log(2)-t.gammaln(1.5))*o;d<200||c>i||u>i;)c=u,d>0&&(h*=o*o/(2*d),f*=o*o/(2*(d+.5))),s+=.5*(u=h*t.beta.cdf(l,d+.5,r/2)+f*t.beta.cdf(l,d+1,r/2)),d++;return a?1-s:s}}),t.extend(t.normal,{pdf:function(t,n,r){return e.exp(-.5*e.log(2*e.PI)-e.log(r)-e.pow(t-n,2)/(2*r*r))},cdf:function(n,r,o){return.5*(1+t.erf((n-r)/e.sqrt(2*o*o)))},inv:function(e,n,r){return-1.4142135623730951*r*t.erfcinv(2*e)+n},mean:function(t){return t},median:function(t){return t},mode:function(t){return t},sample:function(e,n){return t.randn()*n+e},variance:function(t,e){return e*e}}),t.extend(t.pareto,{pdf:function(t,n,r){return t<n?0:r*e.pow(n,r)/e.pow(t,r+1)},cdf:function(t,n,r){return t<n?0:1-e.pow(n/t,r)},inv:function(t,n,r){return n/e.pow(1-t,1/r)},mean:function(t,n){if(!(n<=1))return n*e.pow(t,n)/(n-1)},median:function(t,n){return t*(n*e.SQRT2)},mode:function(t){return t},variance:function(t,n){if(!(n<=2))return t*t*n/(e.pow(n-1,2)*(n-2))}}),t.extend(t.studentt,{pdf:function(n,r){return r=r>1e100?1e100:r,1/(e.sqrt(r)*t.betafn(.5,r/2))*e.pow(1+n*n/r,-(r+1)/2)},cdf:function(n,r){var o=r/2;return t.ibeta((n+e.sqrt(n*n+r))/(2*e.sqrt(n*n+r)),o,o)},inv:function(n,r){var o=t.ibetainv(2*e.min(n,1-n),.5*r,.5);return o=e.sqrt(r*(1-o)/o),n>.5?o:-o},mean:function(t){return t>1?0:void 0},median:function(){return 0},mode:function(){return 0},sample:function(n){return t.randn()*e.sqrt(n/(2*t.randg(n/2)))},variance:function(t){return t>2?t/(t-2):t>1?1/0:void 0}}),t.extend(t.weibull,{pdf:function(t,n,r){return t<0||n<0||r<0?0:r/n*e.pow(t/n,r-1)*e.exp(-e.pow(t/n,r))},cdf:function(t,n,r){return t<0?0:1-e.exp(-e.pow(t/n,r))},inv:function(t,n,r){return n*e.pow(-e.log(1-t),1/r)},mean:function(e,n){return e*t.gammafn(1+1/n)},median:function(t,n){return t*e.pow(e.log(2),1/n)},mode:function(t,n){return n<=1?0:t*e.pow((n-1)/n,1/n)},sample:function(n,r){return n*e.pow(-e.log(t._random_fn()),1/r)},variance:function(n,r){return n*n*t.gammafn(1+2/r)-e.pow(t.weibull.mean(n,r),2)}}),t.extend(t.uniform,{pdf:function(t,e,n){return t<e||t>n?0:1/(n-e)},cdf:function(t,e,n){return t<e?0:t<n?(t-e)/(n-e):1},inv:function(t,e,n){return e+t*(n-e)},mean:function(t,e){return.5*(t+e)},median:function(e,n){return t.mean(e,n)},mode:function(){throw new Error("mode is not yet implemented")},sample:function(e,n){return e/2+n/2+(n/2-e/2)*(2*t._random_fn()-1)},variance:function(t,n){return e.pow(n-t,2)/12}}),t.extend(t.binomial,{pdf:function(n,r,o){return 0===o||1===o?r*o===n?1:0:t.combination(r,n)*e.pow(o,n)*e.pow(1-o,r-n)},cdf:function(r,o,i){var a,s=1e-10;if(r<0)return 0;if(r>=o)return 1;if(i<0||i>1||o<=0)return NaN;var u=i,c=(r=e.floor(r))+1,l=o-r,d=c+l,h=e.exp(t.gammaln(d)-t.gammaln(l)-t.gammaln(c)+c*e.log(u)+l*e.log(1-u));return a=u<(c+1)/(d+2)?h*n(u,c,l,s):1-h*n(1-u,l,c,s),e.round(1/s*(1-a))/(1/s)}}),t.extend(t.negbin,{pdf:function(n,r,o){return n===n>>>0&&(n<0?0:t.combination(n+r-1,r-1)*e.pow(1-o,n)*e.pow(o,r))},cdf:function(e,n,r){var o=0,i=0;if(e<0)return 0;for(;i<=e;i++)o+=t.negbin.pdf(i,n,r);return o}}),t.extend(t.hypgeom,{pdf:function(n,r,o,i){if(n!=n|0)return!1;if(n<0||n<o-(r-i))return 0;if(n>i||n>o)return 0;if(2*o>r)return 2*i>r?t.hypgeom.pdf(r-o-i+n,r,r-o,r-i):t.hypgeom.pdf(i-n,r,r-o,i);if(2*i>r)return t.hypgeom.pdf(o-n,r,o,r-i);if(o<i)return t.hypgeom.pdf(n,r,i,o);for(var a=1,s=0,u=0;u<n;u++){for(;a>1&&s<i;)a*=1-o/(r-s),s++;a*=(i-u)*(o-u)/((u+1)*(r-o-i+u+1))}for(;s<i;s++)a*=1-o/(r-s);return e.min(1,e.max(0,a))},cdf:function(n,r,o,i){if(n<0||n<o-(r-i))return 0;if(n>=i||n>=o)return 1;if(2*o>r)return 2*i>r?t.hypgeom.cdf(r-o-i+n,r,r-o,r-i):1-t.hypgeom.cdf(i-n-1,r,r-o,i);if(2*i>r)return 1-t.hypgeom.cdf(o-n-1,r,o,r-i);if(o<i)return t.hypgeom.cdf(n,r,i,o);for(var a=1,s=1,u=0,c=0;c<n;c++){for(;a>1&&u<i;){var l=1-o/(r-u);s*=l,a*=l,u++}a+=s*=(i-c)*(o-c)/((c+1)*(r-o-i+c+1))}for(;u<i;u++)a*=1-o/(r-u);return e.min(1,e.max(0,a))}}),t.extend(t.poisson,{pdf:function(n,r){return r<0||n%1!=0||n<0?0:e.pow(r,n)*e.exp(-r)/t.factorial(n)},cdf:function(e,n){var r=[],o=0;if(e<0)return 0;for(;o<=e;o++)r.push(t.poisson.pdf(o,n));return t.sum(r)},mean:function(t){return t},variance:function(t){return t},sampleSmall:function(n){var r=1,o=0,i=e.exp(-n);do{o++,r*=t._random_fn()}while(r>i);return o-1},sampleLarge:function(n){var r,o,i,a,s,u,c,l,d,h,f=n;for(a=e.sqrt(f),s=e.log(f),u=.02483*(c=.931+2.53*a)-.059,l=1.1239+1.1328/(c-3.4),d=.9277-3.6224/(c-2);;){if(o=e.random()-.5,i=e.random(),h=.5-e.abs(o),r=e.floor((2*u/h+c)*o+f+.43),h>=.07&&i<=d)return r;if(!(r<0||h<.013&&i>h)&&e.log(i)+e.log(l)-e.log(u/(h*h)+c)<=r*s-f-t.loggam(r+1))return r}},sample:function(t){return t<10?this.sampleSmall(t):this.sampleLarge(t)}}),t.extend(t.triangular,{pdf:function(t,e,n,r){return n<=e||r<e||r>n?NaN:t<e||t>n?0:t<r?2*(t-e)/((n-e)*(r-e)):t===r?2/(n-e):2*(n-t)/((n-e)*(n-r))},cdf:function(t,n,r,o){return r<=n||o<n||o>r?NaN:t<=n?0:t>=r?1:t<=o?e.pow(t-n,2)/((r-n)*(o-n)):1-e.pow(r-t,2)/((r-n)*(r-o))},inv:function(t,n,r,o){return r<=n||o<n||o>r?NaN:t<=(o-n)/(r-n)?n+(r-n)*e.sqrt(t*((o-n)/(r-n))):n+(r-n)*(1-e.sqrt((1-t)*(1-(o-n)/(r-n))))},mean:function(t,e,n){return(t+e+n)/3},median:function(t,n,r){return r<=(t+n)/2?n-e.sqrt((n-t)*(n-r))/e.sqrt(2):r>(t+n)/2?t+e.sqrt((n-t)*(r-t))/e.sqrt(2):void 0},mode:function(t,e,n){return n},sample:function(n,r,o){var i=t._random_fn();return i<(o-n)/(r-n)?n+e.sqrt(i*(r-n)*(o-n)):r-e.sqrt((1-i)*(r-n)*(r-o))},variance:function(t,e,n){return(t*t+e*e+n*n-t*e-t*n-e*n)/18}}),t.extend(t.arcsine,{pdf:function(t,n,r){return r<=n?NaN:t<=n||t>=r?0:2/e.PI*e.pow(e.pow(r-n,2)-e.pow(2*t-n-r,2),-.5)},cdf:function(t,n,r){return t<n?0:t<r?2/e.PI*e.asin(e.sqrt((t-n)/(r-n))):1},inv:function(t,n,r){return n+(.5-.5*e.cos(e.PI*t))*(r-n)},mean:function(t,e){return e<=t?NaN:(t+e)/2},median:function(t,e){return e<=t?NaN:(t+e)/2},mode:function(){throw new Error("mode is not yet implemented")},sample:function(n,r){return(n+r)/2+(r-n)/2*e.sin(2*e.PI*t.uniform.sample(0,1))},variance:function(t,n){return n<=t?NaN:e.pow(n-t,2)/8}}),t.extend(t.laplace,{pdf:function(t,n,r){return r<=0?0:e.exp(-e.abs(t-n)/r)/(2*r)},cdf:function(t,n,r){return r<=0?0:t<n?.5*e.exp((t-n)/r):1-.5*e.exp(-(t-n)/r)},mean:function(t){return t},median:function(t){return t},mode:function(t){return t},variance:function(t,e){return 2*e*e},sample:function(n,r){var o,i=t._random_fn()-.5;return n-r*((o=i)/e.abs(o))*e.log(1-2*e.abs(i))}}),t.extend(t.tukey,{cdf:function(n,o,i){var a=o,s=[.9894009349916499,.9445750230732326,.8656312023878318,.755404408355003,.6178762444026438,.45801677765722737,.2816035507792589,.09501250983763744],u=[.027152459411754096,.062253523938647894,.09515851168249279,.12462897125553388,.14959598881657674,.16915651939500254,.18260341504492358,.1894506104550685];if(n<=0)return 0;if(i<2||a<2)return NaN;if(!Number.isFinite(n))return 1;if(i>25e3)return r(n,1,a);var c,l=.5*i,d=l*e.log(i)-i*e.log(2)-t.gammaln(l),h=l-1,f=.25*i;c=i<=100?1:i<=800?.5:i<=5e3?.25:.125,d+=e.log(c);for(var p=0,m=1;m<=50;m++){for(var g=0,y=(2*m-1)*c,v=1;v<=16;v++){var w,b;8<v?(w=v-8-1,b=d+h*e.log(y+s[w]*c)-(s[w]*c+y)*f):(w=v-1,b=d+h*e.log(y-s[w]*c)+(s[w]*c-y)*f),b>=-30&&(g+=r(8<v?n*e.sqrt(.5*(s[w]*c+y)):n*e.sqrt(.5*(-s[w]*c+y)),1,a)*u[w]*e.exp(b))}if(m*c>=1&&g<=1e-14)break;p+=g}if(g>1e-14)throw new Error("tukey.cdf failed to converge");return p>1&&(p=1),p},inv:function(n,r,o){if(o<2||r<2)return NaN;if(n<0||n>1)return NaN;if(0===n)return 0;if(1===n)return 1/0;var i,a=function(t,n,r){var o=.5-.5*t,i=e.sqrt(e.log(1/(o*o))),a=i+((((-453642210148e-16*i-.204231210125)*i-.342242088547)*i-1)*i+.322232421088)/((((.0038560700634*i+.10353775285)*i+.531103462366)*i+.588581570495)*i+.099348462606);r<120&&(a+=(a*a*a+a)/r/4);var s=.8832-.2368*a;return r<120&&(s+=-1.214/r+1.208*a/r),a*(s*e.log(n-1)+1.4142)}(n,r,o),s=t.tukey.cdf(a,r,o)-n;i=s>0?e.max(0,a-1):a+1;for(var u,c=t.tukey.cdf(i,r,o)-n,l=1;l<50;l++)if(u=i-c*(i-a)/(c-s),s=c,a=i,u<0&&(u=0,c=-n),c=t.tukey.cdf(u,r,o)-n,i=u,e.abs(i-a)<1e-4)return u;throw new Error("tukey.inv failed to converge")}})}(e,Math),function(t,e){var n,r,o=Array.prototype.push,i=t.utils.isArray;function a(e){return i(e)||e instanceof t}t.extend({add:function(e,n){return a(n)?(a(n[0])||(n=[n]),t.map(e,(function(t,e,r){return t+n[e][r]}))):t.map(e,(function(t){return t+n}))},subtract:function(e,n){return a(n)?(a(n[0])||(n=[n]),t.map(e,(function(t,e,r){return t-n[e][r]||0}))):t.map(e,(function(t){return t-n}))},divide:function(e,n){return a(n)?(a(n[0])||(n=[n]),t.multiply(e,t.inv(n))):t.map(e,(function(t){return t/n}))},multiply:function(e,n){var r,o,i,s,u,c,l,d;if(void 0===e.length&&void 0===n.length)return e*n;if(u=e.length,c=e[0].length,l=t.zeros(u,i=a(n)?n[0].length:c),d=0,a(n)){for(;d<i;d++)for(r=0;r<u;r++){for(s=0,o=0;o<c;o++)s+=e[r][o]*n[o][d];l[r][d]=s}return 1===u&&1===d?l[0][0]:l}return t.map(e,(function(t){return t*n}))},outer:function(e,n){return t.multiply(e.map((function(t){return[t]})),[n])},dot:function(e,n){a(e[0])||(e=[e]),a(n[0])||(n=[n]);for(var r,o,i=1===e[0].length&&1!==e.length?t.transpose(e):e,s=1===n[0].length&&1!==n.length?t.transpose(n):n,u=[],c=0,l=i.length,d=i[0].length;c<l;c++){for(u[c]=[],r=0,o=0;o<d;o++)r+=i[c][o]*s[c][o];u[c]=r}return 1===u.length?u[0]:u},pow:function(n,r){return t.map(n,(function(t){return e.pow(t,r)}))},exp:function(n){return t.map(n,(function(t){return e.exp(t)}))},log:function(n){return t.map(n,(function(t){return e.log(t)}))},abs:function(n){return t.map(n,(function(t){return e.abs(t)}))},norm:function(t,n){var r=0,o=0;for(isNaN(n)&&(n=2),a(t[0])&&(t=t[0]);o<t.length;o++)r+=e.pow(e.abs(t[o]),n);return e.pow(r,1/n)},angle:function(n,r){return e.acos(t.dot(n,r)/(t.norm(n)*t.norm(r)))},aug:function(t,e){var n,r=[];for(n=0;n<t.length;n++)r.push(t[n].slice());for(n=0;n<r.length;n++)o.apply(r[n],e[n]);return r},inv:function(e){for(var n,r=e.length,o=e[0].length,i=t.identity(r,o),a=t.gauss_jordan(e,i),s=[],u=0;u<r;u++)for(s[u]=[],n=o;n<a[0].length;n++)s[u][n-o]=a[u][n];return s},det:function t(e){if(2===e.length)return e[0][0]*e[1][1]-e[0][1]*e[1][0];for(var n=0,r=0;r<e.length;r++){for(var o=[],i=1;i<e.length;i++){o[i-1]=[];for(var a=0;a<e.length;a++)a<r?o[i-1][a]=e[i][a]:a>r&&(o[i-1][a-1]=e[i][a])}var s=r%2?-1:1;n+=t(o)*e[0][r]*s}return n},gauss_elimination:function(n,r){var o,i,a,s,u=0,c=0,l=n.length,d=n[0].length,h=1,f=0,p=[];for(o=(n=t.aug(n,r))[0].length,u=0;u<l;u++){for(i=n[u][u],c=u,s=u+1;s<d;s++)i<e.abs(n[s][u])&&(i=n[s][u],c=s);if(c!=u)for(s=0;s<o;s++)a=n[u][s],n[u][s]=n[c][s],n[c][s]=a;for(c=u+1;c<l;c++)for(h=n[c][u]/n[u][u],s=u;s<o;s++)n[c][s]=n[c][s]-h*n[u][s]}for(u=l-1;u>=0;u--){for(f=0,c=u+1;c<=l-1;c++)f+=p[c]*n[u][c];p[u]=(n[u][o-1]-f)/n[u][u]}return p},gauss_jordan:function(n,r){var o,i,a,s=t.aug(n,r),u=s.length,c=s[0].length,l=0;for(i=0;i<u;i++){var d=i;for(a=i+1;a<u;a++)e.abs(s[a][i])>e.abs(s[d][i])&&(d=a);var h=s[i];for(s[i]=s[d],s[d]=h,a=i+1;a<u;a++)for(l=s[a][i]/s[i][i],o=i;o<c;o++)s[a][o]-=s[i][o]*l}for(i=u-1;i>=0;i--){for(l=s[i][i],a=0;a<i;a++)for(o=c-1;o>i-1;o--)s[a][o]-=s[i][o]*s[a][i]/l;for(s[i][i]/=l,o=u;o<c;o++)s[i][o]/=l}return s},triaUpSolve:function(e,n){var r,o=e[0].length,i=t.zeros(1,o)[0],a=!1;return null!=n[0].length&&(n=n.map((function(t){return t[0]})),a=!0),t.arange(o-1,-1,-1).forEach((function(a){r=t.arange(a+1,o).map((function(t){return i[t]*e[a][t]})),i[a]=(n[a]-t.sum(r))/e[a][a]})),a?i.map((function(t){return[t]})):i},triaLowSolve:function(e,n){var r,o=e[0].length,i=t.zeros(1,o)[0],a=!1;return null!=n[0].length&&(n=n.map((function(t){return t[0]})),a=!0),t.arange(o).forEach((function(o){r=t.arange(o).map((function(t){return e[o][t]*i[t]})),i[o]=(n[o]-t.sum(r))/e[o][o]})),a?i.map((function(t){return[t]})):i},lu:function(e){var n,r=e.length,o=t.identity(r),i=t.zeros(e.length,e[0].length);return t.arange(r).forEach((function(t){i[0][t]=e[0][t]})),t.arange(1,r).forEach((function(a){t.arange(a).forEach((function(r){n=t.arange(r).map((function(t){return o[a][t]*i[t][r]})),o[a][r]=(e[a][r]-t.sum(n))/i[r][r]})),t.arange(a,r).forEach((function(r){n=t.arange(a).map((function(t){return o[a][t]*i[t][r]})),i[a][r]=e[n.length][r]-t.sum(n)}))})),[o,i]},cholesky:function(n){var r,o=n.length,i=t.zeros(n.length,n[0].length);return t.arange(o).forEach((function(a){r=t.arange(a).map((function(t){return e.pow(i[a][t],2)})),i[a][a]=e.sqrt(n[a][a]-t.sum(r)),t.arange(a+1,o).forEach((function(e){r=t.arange(a).map((function(t){return i[a][t]*i[e][t]})),i[e][a]=(n[a][e]-t.sum(r))/i[a][a]}))})),i},gauss_jacobi:function(n,r,o,i){for(var a,s,u,c,l=0,d=0,h=n.length,f=[],p=[],m=[];l<h;l++)for(f[l]=[],p[l]=[],m[l]=[],d=0;d<h;d++)l>d?(f[l][d]=n[l][d],p[l][d]=m[l][d]=0):l<d?(p[l][d]=n[l][d],f[l][d]=m[l][d]=0):(m[l][d]=n[l][d],f[l][d]=p[l][d]=0);for(u=t.multiply(t.multiply(t.inv(m),t.add(f,p)),-1),s=t.multiply(t.inv(m),r),a=o,c=t.add(t.multiply(u,o),s),l=2;e.abs(t.norm(t.subtract(c,a)))>i;)a=c,c=t.add(t.multiply(u,a),s),l++;return c},gauss_seidel:function(n,r,o,i){for(var a,s,u,c,l,d=0,h=n.length,f=[],p=[],m=[];d<h;d++)for(f[d]=[],p[d]=[],m[d]=[],a=0;a<h;a++)d>a?(f[d][a]=n[d][a],p[d][a]=m[d][a]=0):d<a?(p[d][a]=n[d][a],f[d][a]=m[d][a]=0):(m[d][a]=n[d][a],f[d][a]=p[d][a]=0);for(c=t.multiply(t.multiply(t.inv(t.add(m,f)),p),-1),u=t.multiply(t.inv(t.add(m,f)),r),s=o,l=t.add(t.multiply(c,o),u),d=2;e.abs(t.norm(t.subtract(l,s)))>i;)s=l,l=t.add(t.multiply(c,s),u),d+=1;return l},SOR:function(n,r,o,i,a){for(var s,u,c,l,d,h=0,f=n.length,p=[],m=[],g=[];h<f;h++)for(p[h]=[],m[h]=[],g[h]=[],s=0;s<f;s++)h>s?(p[h][s]=n[h][s],m[h][s]=g[h][s]=0):h<s?(m[h][s]=n[h][s],p[h][s]=g[h][s]=0):(g[h][s]=n[h][s],p[h][s]=m[h][s]=0);for(l=t.multiply(t.inv(t.add(g,t.multiply(p,a))),t.subtract(t.multiply(g,1-a),t.multiply(m,a))),c=t.multiply(t.multiply(t.inv(t.add(g,t.multiply(p,a))),r),a),u=o,d=t.add(t.multiply(l,o),c),h=2;e.abs(t.norm(t.subtract(d,u)))>i;)u=d,d=t.add(t.multiply(l,u),c),h++;return d},householder:function(n){for(var r,o,i,a,s=n.length,u=n[0].length,c=0,l=[],d=[];c<s-1;c++){for(r=0,a=c+1;a<u;a++)r+=n[a][c]*n[a][c];for(r=(n[c+1][c]>0?-1:1)*e.sqrt(r),o=e.sqrt((r*r-n[c+1][c]*r)/2),(l=t.zeros(s,1))[c+1][0]=(n[c+1][c]-r)/(2*o),i=c+2;i<s;i++)l[i][0]=n[i][c]/(2*o);d=t.subtract(t.identity(s,u),t.multiply(t.multiply(l,t.transpose(l)),2)),n=t.multiply(d,t.multiply(n,d))}return n},QR:(n=t.sum,r=t.arange,function(o){var i,a,s,u=o.length,c=o[0].length,l=t.zeros(c,c);for(o=t.copy(o),a=0;a<c;a++){for(l[a][a]=e.sqrt(n(r(u).map((function(t){return o[t][a]*o[t][a]})))),i=0;i<u;i++)o[i][a]=o[i][a]/l[a][a];for(s=a+1;s<c;s++)for(l[a][s]=n(r(u).map((function(t){return o[t][a]*o[t][s]}))),i=0;i<u;i++)o[i][s]=o[i][s]-o[i][a]*l[a][s]}return[o,l]}),lstsq:function(e,n){var r=!1;void 0===n[0].length&&(n=n.map((function(t){return[t]})),r=!0);var o=t.QR(e),i=o[0],a=o[1],s=e[0].length,u=t.slice(i,{col:{end:s}}),c=function(e){var n=(e=t.copy(e)).length,r=t.identity(n);return t.arange(n-1,-1,-1).forEach((function(n){t.sliceAssign(r,{row:n},t.divide(t.slice(r,{row:n}),e[n][n])),t.sliceAssign(e,{row:n},t.divide(t.slice(e,{row:n}),e[n][n])),t.arange(n).forEach((function(o){var i=t.multiply(e[o][n],-1),a=t.slice(e,{row:o}),s=t.multiply(t.slice(e,{row:n}),i);t.sliceAssign(e,{row:o},t.add(a,s));var u=t.slice(r,{row:o}),c=t.multiply(t.slice(r,{row:n}),i);t.sliceAssign(r,{row:o},t.add(u,c))}))})),r}(t.slice(a,{row:{end:s}})),l=t.transpose(u);void 0===l[0].length&&(l=[l]);var d=t.multiply(t.multiply(c,l),n);return void 0===d.length&&(d=[[d]]),r?d.map((function(t){return t[0]})):d},jacobi:function(n){for(var r,o,i,a,s,u,c,l=1,d=n.length,h=t.identity(d,d),f=[];1===l;){for(s=n[0][1],i=0,a=1,r=0;r<d;r++)for(o=0;o<d;o++)r!=o&&s<e.abs(n[r][o])&&(s=e.abs(n[r][o]),i=r,a=o);for(u=n[i][i]===n[a][a]?n[i][a]>0?e.PI/4:-e.PI/4:e.atan(2*n[i][a]/(n[i][i]-n[a][a]))/2,(c=t.identity(d,d))[i][i]=e.cos(u),c[i][a]=-e.sin(u),c[a][i]=e.sin(u),c[a][a]=e.cos(u),h=t.multiply(h,c),n=t.multiply(t.multiply(t.inv(c),n),c),l=0,r=1;r<d;r++)for(o=1;o<d;o++)r!=o&&e.abs(n[r][o])>.001&&(l=1)}for(r=0;r<d;r++)f.push(n[r][r]);return[h,f]},rungekutta:function(t,e,n,r,o,i){var a,s,u;if(2===i)for(;r<=n;)o+=((a=e*t(r,o))+(s=e*t(r+e,o+a)))/2,r+=e;if(4===i)for(;r<=n;)o+=((a=e*t(r,o))+2*(s=e*t(r+e/2,o+a/2))+2*(u=e*t(r+e/2,o+s/2))+e*t(r+e,o+u))/6,r+=e;return o},romberg:function(t,n,r,o){for(var i,a,s,u,c,l=0,d=(r-n)/2,h=[],f=[],p=[];l<o/2;){for(c=t(n),s=n,u=0;s<=r;s+=d,u++)h[u]=s;for(i=h.length,s=1;s<i-1;s++)c+=(s%2!=0?4:2)*t(h[s]);c=d/3*(c+t(r)),p[l]=c,d/=2,l++}for(a=p.length,i=1;1!==a;){for(s=0;s<a-1;s++)f[s]=(e.pow(4,i)*p[s+1]-p[s])/(e.pow(4,i)-1);a=f.length,p=f,f=[],i++}return p},richardson:function(t,n,r,o){function i(t,e){for(var n,r=0,o=t.length;r<o;r++)t[r]===e&&(n=r);return n}for(var a,s,u,c,l,d=e.abs(r-t[i(t,r)+1]),h=0,f=[],p=[];o>=d;)a=i(t,r+o),s=i(t,r),f[h]=(n[a]-2*n[s]+n[2*s-a])/(o*o),o/=2,h++;for(c=f.length,u=1;1!=c;){for(l=0;l<c-1;l++)p[l]=(e.pow(4,u)*f[l+1]-f[l])/(e.pow(4,u)-1);c=p.length,f=p,p=[],u++}return f},simpson:function(t,e,n,r){for(var o,i=(n-e)/r,a=t(e),s=[],u=e,c=0,l=1;u<=n;u+=i,c++)s[c]=u;for(o=s.length;l<o-1;l++)a+=(l%2!=0?4:2)*t(s[l]);return i/3*(a+t(n))},hermite:function(t,e,n,r){for(var o,i=t.length,a=0,s=0,u=[],c=[],l=[],d=[];s<i;s++){for(u[s]=1,o=0;o<i;o++)s!=o&&(u[s]*=(r-t[o])/(t[s]-t[o]));for(c[s]=0,o=0;o<i;o++)s!=o&&(c[s]+=1/(t[s]-t[o]));l[s]=(1-2*(r-t[s])*c[s])*(u[s]*u[s]),d[s]=(r-t[s])*(u[s]*u[s]),a+=l[s]*e[s]+d[s]*n[s]}return a},lagrange:function(t,e,n){for(var r,o,i=0,a=0,s=t.length;a<s;a++){for(o=e[a],r=0;r<s;r++)a!=r&&(o*=(n-t[r])/(t[a]-t[r]));i+=o}return i},cubic_spline:function(e,n,r){for(var o,i,a=e.length,s=0,u=[],c=[],l=[],d=[],h=[],f=[];s<a-1;s++)d[s]=e[s+1]-e[s];for(l[0]=0,s=1;s<a-1;s++)l[s]=3/d[s]*(n[s+1]-n[s])-3/d[s-1]*(n[s]-n[s-1]);for(s=1;s<a-1;s++)u[s]=[],c[s]=[],u[s][s-1]=d[s-1],u[s][s]=2*(d[s-1]+d[s]),u[s][s+1]=d[s],c[s][0]=l[s];for(i=t.multiply(t.inv(u),c),o=0;o<a-1;o++)h[o]=(n[o+1]-n[o])/d[o]-d[o]*(i[o+1][0]+2*i[o][0])/3,f[o]=(i[o+1][0]-i[o][0])/(3*d[o]);for(o=0;o<a&&!(e[o]>r);o++);return n[o-=1]+(r-e[o])*h[o]+t.sq(r-e[o])*i[o]+(r-e[o])*t.sq(r-e[o])*f[o]},gauss_quadrature:function(){throw new Error("gauss_quadrature not yet implemented")},PCA:function(e){var n,r,o,i,a,s=e.length,u=e[0].length,c=0,l=[],d=[],h=[],f=[],p=[],m=[],g=[];for(c=0;c<s;c++)l[c]=t.sum(e[c])/u;for(c=0;c<u;c++)for(p[c]=[],n=0;n<s;n++)p[c][n]=e[n][c]-l[n];for(p=t.transpose(p),c=0;c<s;c++)for(m[c]=[],n=0;n<s;n++)m[c][n]=t.dot([p[c]],[p[n]])/(u-1);for(a=(o=t.jacobi(m))[0],d=o[1],g=t.transpose(a),c=0;c<d.length;c++)for(n=c;n<d.length;n++)d[c]<d[n]&&(r=d[c],d[c]=d[n],d[n]=r,h=g[c],g[c]=g[n],g[n]=h);for(i=t.transpose(p),c=0;c<s;c++)for(f[c]=[],n=0;n<i.length;n++)f[c][n]=t.dot([g[c]],[i[n]]);return[e,d,g,f]}}),function(e){for(var n=0;n<e.length;n++)!function(e){t.fn[e]=function(n,r){var o=this;return r?(setTimeout((function(){r.call(o,t.fn[e].call(o,n))}),15),this):"number"==typeof t[e](this,n)?t[e](this,n):t(t[e](this,n))}}(e[n])}("add divide multiply subtract dot pow exp log abs norm angle".split(" "))}(e,Math),function(t,e){var n=[].slice,r=t.utils.isNumber,o=t.utils.isArray;function i(t,n,r,o){if(t>1||r>1||t<=0||r<=0)throw new Error("Proportions should be greater than 0 and less than 1");var i=(t*n+r*o)/(n+o);return(t-r)/e.sqrt(i*(1-i)*(1/n+1/o))}t.extend({zscore:function(){var e=n.call(arguments);return r(e[1])?(e[0]-e[1])/e[2]:(e[0]-t.mean(e[1]))/t.stdev(e[1],e[2])},ztest:function(){var r,i=n.call(arguments);return o(i[1])?(r=t.zscore(i[0],i[1],i[3]),1===i[2]?t.normal.cdf(-e.abs(r),0,1):2*t.normal.cdf(-e.abs(r),0,1)):i.length>2?(r=t.zscore(i[0],i[1],i[2]),1===i[3]?t.normal.cdf(-e.abs(r),0,1):2*t.normal.cdf(-e.abs(r),0,1)):(r=i[0],1===i[1]?t.normal.cdf(-e.abs(r),0,1):2*t.normal.cdf(-e.abs(r),0,1))}}),t.extend(t.fn,{zscore:function(t,e){return(t-this.mean())/this.stdev(e)},ztest:function(n,r,o){var i=e.abs(this.zscore(n,o));return 1===r?t.normal.cdf(-i,0,1):2*t.normal.cdf(-i,0,1)}}),t.extend({tscore:function(){var r=n.call(arguments);return 4===r.length?(r[0]-r[1])/(r[2]/e.sqrt(r[3])):(r[0]-t.mean(r[1]))/(t.stdev(r[1],!0)/e.sqrt(r[1].length))},ttest:function(){var o,i=n.call(arguments);return 5===i.length?(o=e.abs(t.tscore(i[0],i[1],i[2],i[3])),1===i[4]?t.studentt.cdf(-o,i[3]-1):2*t.studentt.cdf(-o,i[3]-1)):r(i[1])?(o=e.abs(i[0]),1==i[2]?t.studentt.cdf(-o,i[1]-1):2*t.studentt.cdf(-o,i[1]-1)):(o=e.abs(t.tscore(i[0],i[1])),1==i[2]?t.studentt.cdf(-o,i[1].length-1):2*t.studentt.cdf(-o,i[1].length-1))}}),t.extend(t.fn,{tscore:function(t){return(t-this.mean())/(this.stdev(!0)/e.sqrt(this.cols()))},ttest:function(n,r){return 1===r?1-t.studentt.cdf(e.abs(this.tscore(n)),this.cols()-1):2*t.studentt.cdf(-e.abs(this.tscore(n)),this.cols()-1)}}),t.extend({anovafscore:function(){var r,o,i,a,s,u,c,l,d=n.call(arguments);if(1===d.length){for(s=new Array(d[0].length),c=0;c<d[0].length;c++)s[c]=d[0][c];d=s}for(o=new Array,c=0;c<d.length;c++)o=o.concat(d[c]);for(i=t.mean(o),r=0,c=0;c<d.length;c++)r+=d[c].length*e.pow(t.mean(d[c])-i,2);for(r/=d.length-1,u=0,c=0;c<d.length;c++)for(a=t.mean(d[c]),l=0;l<d[c].length;l++)u+=e.pow(d[c][l]-a,2);return r/(u/(o.length-d.length))},anovaftest:function(){var e,o,i,a,s=n.call(arguments);if(r(s[0]))return 1-t.centralF.cdf(s[0],s[1],s[2]);var u=t.anovafscore(s);for(e=s.length-1,i=0,a=0;a<s.length;a++)i+=s[a].length;return o=i-e-1,1-t.centralF.cdf(u,e,o)},ftest:function(e,n,r){return 1-t.centralF.cdf(e,n,r)}}),t.extend(t.fn,{anovafscore:function(){return t.anovafscore(this.toArray())},anovaftes:function(){var e,n=0;for(e=0;e<this.length;e++)n+=this[e].length;return t.ftest(this.anovafscore(),this.length-1,n-this.length)}}),t.extend({qscore:function(){var o,i,a,s,u,c=n.call(arguments);return r(c[0])?(o=c[0],i=c[1],a=c[2],s=c[3],u=c[4]):(o=t.mean(c[0]),i=t.mean(c[1]),a=c[0].length,s=c[1].length,u=c[2]),e.abs(o-i)/(u*e.sqrt((1/a+1/s)/2))},qtest:function(){var e,r=n.call(arguments);3===r.length?(e=r[0],r=r.slice(1)):7===r.length?(e=t.qscore(r[0],r[1],r[2],r[3],r[4]),r=r.slice(5)):(e=t.qscore(r[0],r[1],r[2]),r=r.slice(3));var o=r[0],i=r[1];return 1-t.tukey.cdf(e,i,o-i)},tukeyhsd:function(e){for(var n=t.pooledstdev(e),r=e.map((function(e){return t.mean(e)})),o=e.reduce((function(t,e){return t+e.length}),0),i=[],a=0;a<e.length;++a)for(var s=a+1;s<e.length;++s){var u=t.qtest(r[a],r[s],e[a].length,e[s].length,n,o,e.length);i.push([[a,s],u])}return i}}),t.extend({normalci:function(){var r,o=n.call(arguments),i=new Array(2);return r=4===o.length?e.abs(t.normal.inv(o[1]/2,0,1)*o[2]/e.sqrt(o[3])):e.abs(t.normal.inv(o[1]/2,0,1)*t.stdev(o[2])/e.sqrt(o[2].length)),i[0]=o[0]-r,i[1]=o[0]+r,i},tci:function(){var r,o=n.call(arguments),i=new Array(2);return r=4===o.length?e.abs(t.studentt.inv(o[1]/2,o[3]-1)*o[2]/e.sqrt(o[3])):e.abs(t.studentt.inv(o[1]/2,o[2].length-1)*t.stdev(o[2],!0)/e.sqrt(o[2].length)),i[0]=o[0]-r,i[1]=o[0]+r,i},significant:function(t,e){return t<e}}),t.extend(t.fn,{normalci:function(e,n){return t.normalci(e,n,this.toArray())},tci:function(e,n){return t.tci(e,n,this.toArray())}}),t.extend(t.fn,{oneSidedDifferenceOfProportions:function(e,n,r,o){var a=i(e,n,r,o);return t.ztest(a,1)},twoSidedDifferenceOfProportions:function(e,n,r,o){var a=i(e,n,r,o);return t.ztest(a,2)}})}(e,Math),e.models=function(){function t(t,n){var r=t.length,o=n[0].length-1,i=r-o-1,a=e.lstsq(n,t),s=e.multiply(n,a.map((function(t){return[t]}))).map((function(t){return t[0]})),u=e.subtract(t,s),c=e.mean(t),l=e.sum(s.map((function(t){return Math.pow(t-c,2)}))),d=e.sum(t.map((function(t,e){return Math.pow(t-s[e],2)}))),h=l+d;return{exog:n,endog:t,nobs:r,df_model:o,df_resid:i,coef:a,predict:s,resid:u,ybar:c,SST:h,SSE:l,SSR:d,R2:l/h}}function n(n){var r,o,i=(r=n.exog,o=r[0].length,e.arange(o).map((function(n){var i=e.arange(o).filter((function(t){return t!==n}));return t(e.col(r,n).map((function(t){return t[0]})),e.col(r,i))}))),a=Math.sqrt(n.SSR/n.df_resid),s=i.map((function(t){var e=t.SST,n=t.R2;return a/Math.sqrt(e*(1-n))})),u=n.coef.map((function(t,e){return(t-0)/s[e]})),c=u.map((function(t){var r=e.studentt.cdf(t,n.df_resid);return 2*(r>.5?1-r:r)})),l=e.studentt.inv(.975,n.df_resid),d=n.coef.map((function(t,e){var n=l*s[e];return[t-n,t+n]}));return{se:s,t:u,p:c,sigmaHat:a,interval95:d}}return{ols:function(r,o){var i=t(r,o),a=n(i),s=function(t){var n,r,o,i=t.R2/t.df_model/((1-t.R2)/t.df_resid);return{F_statistic:i,pvalue:1-(n=i,r=t.df_model,o=t.df_resid,e.beta.cdf(n/(o/r+n),r/2,o/2))}}(i),u=1-(1-i.R2)*((i.nobs-1)/i.df_resid);return i.t=a,i.f=s,i.adjust_R2=u,i}}}(),e.extend({buildxmatrix:function(){for(var t=new Array(arguments.length),n=0;n<arguments.length;n++){t[n]=[1].concat(arguments[n])}return e(t)},builddxmatrix:function(){for(var t=new Array(arguments[0].length),n=0;n<arguments[0].length;n++){t[n]=[1].concat(arguments[0][n])}return e(t)},buildjxmatrix:function(t){for(var n=new Array(t.length),r=0;r<t.length;r++)n[r]=t[r];return e.builddxmatrix(n)},buildymatrix:function(t){return e(t).transpose()},buildjymatrix:function(t){return t.transpose()},matrixmult:function(t,n){var r,o,i,a,s;if(t.cols()==n.rows()){if(n.rows()>1){for(a=[],r=0;r<t.rows();r++)for(a[r]=[],o=0;o<n.cols();o++){for(s=0,i=0;i<t.cols();i++)s+=t.toArray()[r][i]*n.toArray()[i][o];a[r][o]=s}return e(a)}for(a=[],r=0;r<t.rows();r++)for(a[r]=[],o=0;o<n.cols();o++){for(s=0,i=0;i<t.cols();i++)s+=t.toArray()[r][i]*n.toArray()[o];a[r][o]=s}return e(a)}},regress:function(t,n){var r=e.xtranspxinv(t),o=t.transpose(),i=e.matrixmult(e(r),o);return e.matrixmult(i,n)},regresst:function(t,n,r){var o=e.regress(t,n),i={anova:{}},a=e.jMatYBar(t,o);i.yBar=a;var s=n.mean();i.anova.residuals=e.residuals(n,a),i.anova.ssr=e.ssr(a,s),i.anova.msr=i.anova.ssr/(t[0].length-1),i.anova.sse=e.sse(n,a),i.anova.mse=i.anova.sse/(n.length-(t[0].length-1)-1),i.anova.sst=e.sst(n,s),i.anova.mst=i.anova.sst/(n.length-1),i.anova.r2=1-i.anova.sse/i.anova.sst,i.anova.r2<0&&(i.anova.r2=0),i.anova.fratio=i.anova.msr/i.anova.mse,i.anova.pvalue=e.anovaftest(i.anova.fratio,t[0].length-1,n.length-(t[0].length-1)-1),i.anova.rmse=Math.sqrt(i.anova.mse),i.anova.r2adj=1-i.anova.mse/i.anova.mst,i.anova.r2adj<0&&(i.anova.r2adj=0),i.stats=new Array(t[0].length);for(var u,c,l,d=e.xtranspxinv(t),h=0;h<o.length;h++)u=Math.sqrt(i.anova.mse*Math.abs(d[h][h])),c=Math.abs(o[h]/u),l=e.ttest(c,n.length-t[0].length-1,r),i.stats[h]=[o[h],u,c,l];return i.regress=o,i},xtranspx:function(t){return e.matrixmult(t.transpose(),t)},xtranspxinv:function(t){var n=e.matrixmult(t.transpose(),t);return e.inv(n)},jMatYBar:function(t,n){var r=e.matrixmult(t,n);return new e(r)},residuals:function(t,n){return e.matrixsubtract(t,n)},ssr:function(t,e){for(var n=0,r=0;r<t.length;r++)n+=Math.pow(t[r]-e,2);return n},sse:function(t,e){for(var n=0,r=0;r<t.length;r++)n+=Math.pow(t[r]-e[r],2);return n},sst:function(t,e){for(var n=0,r=0;r<t.length;r++)n+=Math.pow(t[r]-e,2);return n},matrixsubtract:function(t,n){for(var r=new Array(t.length),o=0;o<t.length;o++){r[o]=new Array(t[o].length);for(var i=0;i<t[o].length;i++)r[o][i]=t[o][i]-n[o][i]}return e(r)}}),e.jStat=e,e)},5072:t=>{"use strict";var e=[];function n(t){for(var n=-1,r=0;r<e.length;r++)if(e[r].identifier===t){n=r;break}return n}function r(t,r){for(var i={},a=[],s=0;s<t.length;s++){var u=t[s],c=r.base?u[0]+r.base:u[0],l=i[c]||0,d="".concat(c," ").concat(l);i[c]=l+1;var h=n(d),f={css:u[1],media:u[2],sourceMap:u[3],supports:u[4],layer:u[5]};if(-1!==h)e[h].references++,e[h].updater(f);else{var p=o(f,r);r.byIndex=s,e.splice(s,0,{identifier:d,updater:p,references:1})}a.push(d)}return a}function o(t,e){var n=e.domAPI(e);return n.update(t),function(e){if(e){if(e.css===t.css&&e.media===t.media&&e.sourceMap===t.sourceMap&&e.supports===t.supports&&e.layer===t.layer)return;n.update(t=e)}else n.remove()}}t.exports=function(t,o){var i=r(t=t||[],o=o||{});return function(t){t=t||[];for(var a=0;a<i.length;a++){var s=n(i[a]);e[s].references--}for(var u=r(t,o),c=0;c<i.length;c++){var l=n(i[c]);0===e[l].references&&(e[l].updater(),e.splice(l,1))}i=u}}},7659:t=>{"use strict";var e={};t.exports=function(t,n){var r=function(t){if(void 0===e[t]){var n=document.querySelector(t);if(window.HTMLIFrameElement&&n instanceof window.HTMLIFrameElement)try{n=n.contentDocument.head}catch(t){n=null}e[t]=n}return e[t]}(t);if(!r)throw new Error("Couldn't find a style target. This probably means that the value for the 'insert' parameter is invalid.");r.appendChild(n)}},540:t=>{"use strict";t.exports=function(t){var e=document.createElement("style");return t.setAttributes(e,t.attributes),t.insert(e,t.options),e}},5056:(t,e,n)=>{"use strict";t.exports=function(t){var e=n.nc;e&&t.setAttribute("nonce",e)}},7825:t=>{"use strict";t.exports=function(t){if("undefined"==typeof document)return{update:function(){},remove:function(){}};var e=t.insertStyleElement(t);return{update:function(n){!function(t,e,n){var r="";n.supports&&(r+="@supports (".concat(n.supports,") {")),n.media&&(r+="@media ".concat(n.media," {"));var o=void 0!==n.layer;o&&(r+="@layer".concat(n.layer.length>0?" ".concat(n.layer):""," {")),r+=n.css,o&&(r+="}"),n.media&&(r+="}"),n.supports&&(r+="}");var i=n.sourceMap;i&&"undefined"!=typeof btoa&&(r+="\n/*# sourceMappingURL=data:application/json;base64,".concat(btoa(unescape(encodeURIComponent(JSON.stringify(i))))," */")),e.styleTagTransform(r,t,e.options)}(e,t,n)},remove:function(){!function(t){if(null===t.parentNode)return!1;t.parentNode.removeChild(t)}(e)}}}},1113:t=>{"use strict";t.exports=function(t,e){if(e.styleSheet)e.styleSheet.cssText=t;else{for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(document.createTextNode(t))}}}},e={};function n(r){var o=e[r];if(void 0!==o)return o.exports;var i=e[r]={id:r,loaded:!1,exports:{}};return t[r].call(i.exports,i,i.exports,n),i.loaded=!0,i.exports}n.m=t,n.amdO={},n.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return n.d(e,{a:e}),e},n.d=(t,e)=>{for(var r in e)n.o(e,r)&&!n.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},n.u=t=>t+".js",n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"==typeof window)return window}}(),n.hmd=t=>((t=Object.create(t)).children||(t.children=[]),Object.defineProperty(t,"exports",{enumerable:!0,set:()=>{throw new Error("ES Modules may not assign module.exports or exports.*, Use ESM export syntax, instead: "+t.id)}}),t),n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},(()=>{var t;n.g.importScripts&&(t=n.g.location+"");var e=n.g.document;if(!t&&e&&(e.currentScript&&"SCRIPT"===e.currentScript.tagName.toUpperCase()&&(t=e.currentScript.src),!t)){var r=e.getElementsByTagName("script");if(r.length)for(var o=r.length-1;o>-1&&(!t||!/^http(s?):/.test(t));)t=r[o--].src}if(!t)throw new Error("Automatic publicPath is not supported in this browser");t=t.replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),n.p=t})(),n.b=document.baseURI||self.location.href,n.nc=void 0;var r={};(()=>{"use strict";n.r(r),n.d(r,{GetMCLEditor:()=>xr,MCLClustering:()=>Fr,MVA:()=>kr,PCA:()=>Mr,PLS:()=>Dr,_package:()=>Sr,anova:()=>ao,applyLinearKernelSVM:()=>Vr,applyLinearRegression:()=>lo,applyPLSRegression:()=>wo,applyPolynomialKernelSVM:()=>Qr,applyRBFkernelSVM:()=>qr,applySigmoidKernelSVM:()=>no,applySoftmax:()=>mo,applyXGBooster:()=>So,dbScan:()=>Ir,dbscanPostProcessingFunction:()=>Tr,demoMultivariateAnalysis:()=>Gr,info:()=>_r,init:()=>Nr,isApplicableLinearKernelSVM:()=>Wr,isApplicableLinearRegression:()=>ho,isApplicablePLSRegression:()=>bo,isApplicablePolynomialKernelSVM:()=>Jr,isApplicableRBFkernelSVM:()=>Hr,isApplicableSigmoidKernelSVM:()=>ro,isApplicableSoftmax:()=>go,isApplicableXGBooster:()=>No,isInteractiveLinearKernelSVM:()=>jr,isInteractiveLinearRegression:()=>fo,isInteractivePLSRegression:()=>Ao,isInteractivePolynomialKernelSVM:()=>Zr,isInteractiveRBFkernelSVM:()=>$r,isInteractiveSigmoidKernelSVM:()=>oo,isInteractiveSoftmax:()=>yo,isInteractiveXGBooster:()=>_o,kNNImputation:()=>so,kNNImputationForTable:()=>uo,markovClusteringViewer:()=>Rr,numberPreprocessingFunction:()=>Or,reduceDimensionality:()=>Lr,stringPreprocessingFunction:()=>Pr,topMenuPLS:()=>Ur,trainLinearKernelSVM:()=>Br,trainLinearRegression:()=>co,trainPLSRegression:()=>vo,trainPolynomialKernelSVM:()=>Xr,trainRBFkernelSVM:()=>zr,trainSigmoidKernelSVM:()=>eo,trainSoftmax:()=>po,trainXGBooster:()=>Co,visualizeLinearKernelSVM:()=>Yr,visualizePLSRegression:()=>Eo,visualizePolynomialKernelSVM:()=>to,visualizeRBFkernelSVM:()=>Kr,visualizeSigmoidKernelSVM:()=>io});const t=grok,e=ui,o=DG,i={i32:"HEAP32",f32:"HEAPF32"},a={i32:Int32Array,f32:Float32Array},s={i32:2,f32:2},u={i32:DG.Column.fromInt32Array,f32:DG.Column.fromFloat32Array};class c{constructor(t){this.data=t}complementArrOfParams(t){t.push(this.data)}complementArrOfTypes(t){t.push("number")}allocateMemoryForBuffer(t){}isMemoryForBufferAllocated(){return!0}putDataToBuffer(t){}getDataFromBuffer(t){}freeBuffer(t){}}class l extends c{constructor(t,e,n=!1){super(t),this.type=e,this.toUpdate=n,this.buf=0,this.numOfRows=t.length}complementArrOfParams(t){t.push(this.buf),t.push(this.numOfRows)}complementArrOfTypes(t){t.push("number"),t.push("number")}allocateMemoryForBuffer(t){this.buf=t._malloc(this.numOfRows*a[this.type].BYTES_PER_ELEMENT)}isMemoryForBufferAllocated(){return 0!=this.buf}putDataToBuffer(t){if(this.isMemoryForBufferAllocated()){const e=this.type,n=s[e],r=t[i[e]];let o=null;const u=this.data;o="int"==u.type&&"i32"==e||"double"==u.type&&"f32"==e?u.getRawData():new a[e](u.getRawData()),o&&r.set(o,this.buf>>n)}}getDataFromBuffer(t){if(this.toUpdate&&this.isMemoryForBufferAllocated()){const e=this.type,n=t[i[e]],r=this.buf,o=a[e].BYTES_PER_ELEMENT,s=this.data.getRawData();for(let t=0;t<this.numOfRows;t++)s[t]=n[r/o+t]}}freeBuffer(t){this.isMemoryForBufferAllocated()&&(t._free(this.buf),this.buf=0)}}class d extends l{constructor(t,e){super([],t,!0),this.numOfRows=e}putDataToBuffer(t){}getDataFromBuffer(t){if(this.toUpdate&&this.isMemoryForBufferAllocated()){const e=this.type,n=t[i[e]],r=this.buf,o=u[e],s=new a[e](this.numOfRows);for(let t=0;t<s.length;t++)s[t]=n[r/s.BYTES_PER_ELEMENT+t];this.data=o("name",s)}}}class h extends c{constructor(t,e,n=!1){super(t),this.type=e,this.toUpdate=n,this.buf=0,this.numOfColumns=t.length,this.numOfRows=t[0].length}complementArrOfParams(t){t.push(this.buf),t.push(this.numOfRows),t.push(this.numOfColumns)}complementArrOfTypes(t){t.push("number"),t.push("number"),t.push("number")}allocateMemoryForBuffer(t){this.buf=t._malloc(this.numOfRows*this.numOfColumns*a[this.type].BYTES_PER_ELEMENT)}isMemoryForBufferAllocated(){return 0!=this.buf}putDataToBuffer(t){if(this.isMemoryForBufferAllocated()){const e=this.type,n=s[e],r=t[i[e]],o=a[e].BYTES_PER_ELEMENT;for(let t=0;t<this.numOfColumns;t++){let i=null;const s=this.data[t];i="int"==s.type&&"i32"==e||"double"==s.type&&"f32"==e?s.getRawData():new a[e](s.getRawData()),null!=i&&r.set(i,this.buf+t*this.numOfRows*o>>n)}}}getDataFromBuffer(t){if(this.toUpdate&&this.isMemoryForBufferAllocated()){const e=this.type,n=t[i[e]],r=this.numOfRows,o=this.numOfColumns,s=new a[e](n.buffer,this.buf,r*o);for(let t=0;t<o;t++){const e=this.data[t].getRawData();for(let n=0;n<r;n++)e[n]=s[n+t*r]}}}freeBuffer(t){this.isMemoryForBufferAllocated()&&(t._free(this.buf),this.buf=0)}}class f extends h{constructor(t,e,n){super([[]],t,!0),this.data=[],this.numOfColumns=n,this.numOfRows=e}putDataToBuffer(t){}getDataFromBuffer(t){if(this.toUpdate&&this.isMemoryForBufferAllocated()){const e=this.type,n=t[i[e]],r=this.numOfRows,o=this.numOfColumns,s=a[e].BYTES_PER_ELEMENT,c=u[e],l=this.buf;for(let t=0;t<o;t++){const o=new a[e](r);for(let e=0;e<r;e++)o[e]=n[l/s+e+t*r];this.data.push(c((t+1).toString(),o))}}}}const p={intColumn:t=>new l(t,"i32"),newIntColumn:t=>new d("i32",t),intColumns:t=>new h(t.toList(),"i32"),newIntColumns:(t,e)=>new f("i32",t,e),floatColumn:t=>new l(t,"f32"),newFloatColumn:t=>new d("f32",t),floatColumns:t=>new h(t.toList(),"f32"),newFloatColumns:(t,e)=>new f("f32",t,e),int:t=>new c(t),num:t=>new c(t)},m={tableFromColumns:t=>DG.DataFrame.fromColumns(t.data),num:t=>t,int:t=>t,double:t=>t,column:t=>t.data};function g(t,e,n){const r=t[e],o=r.arguments,i=[];let a=0;for(const t in o){const e=o[t];if("_callResult"!=t){switch(e.type){case"floatColumns":case"int":case"num":case"floatColumn":case"intColumn":case"intColumns":e.data=p[e.type](n[a]),a++;break;case"newFloatColumns":case"newIntColumns":const t=o[e.numOfRows.ref].data[e.numOfRows.value],r=o[e.numOfColumns.ref].data[e.numOfColumns.value];e.data=p[e.type](t,r);break;case"newFloatColumn":case"newIntColumn":const i=o[e.numOfRows.ref].data[e.numOfRows.value];e.data=p[e.type](i)}i.push(o[t].data)}}const s=function(t,e,n,r){let o;for(const e of r)e.allocateMemoryForBuffer(t);let i=!0;for(const t of r)i&=t.isMemoryForBufferAllocated();if(i){const n=[],i=[];for(const e of r)e.complementArrOfParams(n),e.complementArrOfTypes(i),e.putDataToBuffer(t);const a="number";o=t.ccall(e,a,i,n);for(const e of r)e.getDataFromBuffer(t)}for(const e of r)e.freeBuffer(t);if(null!=o)return o}(t,e,0,i);o._callResult=p.num(s);const u=r.output;if("objects"!=u.type)return m[u.type](o[u.source].data);const c=[];for(const t of u.source)c.push(o[t].data.data);return c}const y="num",v="floatColumn",w="intColumn",b="floatColumns",E="newFloatColumns",A="intColumns",C="newIntColumns",S="newFloatColumn",_="newIntColumn",N="column",I="_callResult",M="numOfRows",T="numOfColumns",O="ref",P="value",L="tableFromColumns",x="objects",F="int",R="double",D={intColumn:Int32Array,floatColumn:Float32Array,floatColumns:Float32Array,newFloatColumns:Float32Array,intColumns:Int32Array,newIntColumns:Int32Array,newFloatColumn:Float32Array,newIntColumn:Int32Array};function U(t,e){let n,r=[],o=0;for(const i in t){const a=t[i],s=a.type;if(i!==I){switch(s){case y:case F:case R:a.data=e[o],o++;break;case w:case v:let r;const i=e[o],u=i.length;r=i.type===F&&s===w||i.type===R&&s===v?i.getRawData().slice(0,u):new D[s](i.getRawData().slice(0,u)),a.data={array:r,numOfRows:u},o++;break;case _:case S:let c=0;n=a[M][O],c=t[n].type===y?t[n].data:t[n].data[a[M][P]],a.data={numOfRows:c},o++;break;case A:case b:let l=[];const d=e[o].byIndex(0).length;for(const t of e[o].toList())t.type===F&&s===w||t.type===R&&s===v?l.push(t.getRawData().slice(0,d)):l.push(new D[s](t.getRawData().slice(0,d)));a.data={arrays:l,numOfRows:d,numOfColumns:l.length},o++;break;case C:case E:let h=0,f=0;n=a[M][O],h=t[n].type===y?t[n].data:t[n].data[a[M][P]],n=a[T][O],f=t[n].type===y?t[n].data:t[n].data[a[T][P]],a.data={numOfRows:h,numOfColumns:f},o++;break;default:return}r.push(a)}}return r}function k(t,e){t.arguments._callResult=e.callResult,function(t,e){const n={newFloatColumns:DG.Column.fromFloat32Array,newIntColumns:DG.Column.fromInt32Array,newFloatColumn:DG.Column.fromFloat32Array,newIntColumn:DG.Column.fromInt32Array};let r=0;for(const o in t){const i=t[o];switch(i.type){case y:case F:case R:case w:case v:case b:case A:break;case S:case _:let t;null==i.name?t=(0).toString():s=i.name,i.column=n[i.type](t,e[r].array);break;case C:case E:let o=[],a=e[r].arrays.length,s=[];if(null==i.names)for(let t=1;t<=a;t++)s.push(t.toString());else s=i.names;for(let t=0;t<a;t++)o.push(n[i.type](s[t],e[r].arrays[t]));i.columns=o}r++}}(t.arguments,e.args);let n=function(t){let e=t.output;const n={newFloatColumns:"columns",newIntColumns:"columns",newFloatColumn:"column",newIntColumn:"column"};switch(e.type){case y:case F:case R:return t.arguments[e.source];case N:return t.arguments[e.source].column;case L:return DG.DataFrame.fromColumns(t.arguments[e.source].columns);case x:let r=[];for(let o of e.source){let e=t.arguments[o];r.push(e[n[e.type]])}return r}}(t);return function(t){for(const e in t){const n=t[e];switch(n.type){case y:case F:case R:case w:case v:case A:case b:break;case _:case S:n.column=null;break;case C:case E:n.columns=null}}}(t.arguments),n}async function G(t,e,r){return new Promise(((t,o)=>{const i=new Worker(new URL(n.p+n.u(128),n.b));i.postMessage(U(EDA.principalComponentAnalysisNipals.arguments,[e,r])),i.onmessage=function(e){i.terminate(),t(k(EDA.principalComponentAnalysisNipals,e.data))}}))}const B=1,V=1e8,W=900,j=1e-6,Y="components must be positive.",z="components must not be greater than features count.",q="dataframe is too big.",H="unsupported column type: ";function $(t){if(t.type!=o.COLUMN_TYPE.FLOAT&&t.type!=o.COLUMN_TYPE.INT)throw new Error(H+t.type)}function K(t){if(t.stats.missingValueCount>0)throw new Error(`The column '${t.name}' has missing values.`)}function X(t,e){if(function(t,e){if(e<B)throw new Error(Y);if(e>t.length)throw new Error(z);for(const e of t)$(e),K(e)}(t,e),t.length*t.byIndex(0).length>V)throw new Error(q)}function Q(t,e,n){return e?n?function(t){const e=t.rowCount;for(const n of t.columns)if(n.isNumerical){const t=n.stats.stdev,r=n.stats.avg,o=n.getRawData();if(t>0)for(let n=0;n<e;++n)o[n]=(o[n]-r)/t;else for(let t=0;t<e;++t)o[t]-=r}return t}(t):function(t){const e=t.rowCount;for(const n of t.columns)if(n.isNumerical){const t=n.stats.avg;if(Math.abs(t)>j){const r=n.getRawData();for(let n=0;n<e;++n)r[n]-=t}}return t}(t):n?function(t){const e=t.rowCount;for(const n of t.columns)if(n.isNumerical){const t=n.stats.stdev;if(Math.abs(t-1)>j&&t>0){const r=n.getRawData();for(let n=0;n<e;++n)r[n]/=t}}return t}(t):t}var J=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{u(r.next(t))}catch(t){i(t)}}function s(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,s)}u((r=r.apply(t,e||[])).next())}))};var Z=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{u(r.next(t))}catch(t){i(t)}}function s(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,s)}u((r=r.apply(t,e||[])).next())}))};const tt=0,et=1,nt=2,rt=3,ot=4,it=0,at=1,st=2,ut=3,ct=4,lt=5,dt=6,ht=7,ft=0,pt=1,mt=2,gt=3,yt=0,vt=0,wt=1,bt=0,Et=1,At=0,Ct=0,St=0,_t=0,Nt="gamma must be strictly positive.",It="sigma must be strictly positive.",Mt="c must be strictly positive.",Tt="d must be strictly positive.",Ot="incorrect kernel.",Pt="labels must be strings of two categories.",Lt="Labels",xt="predicted",Ft="correctness",Rt="Confusion matrix",Dt="mean",Ut="std dev",kt="alpha",Gt="weight",Bt="Gamma",Vt="Kernel",Wt="Kernel params",jt="Kernel parameter 1",Yt="Kernel parameter 2",zt="Features count",qt="Train samples count",Ht="Train error, %",$t=["linear","polynomial","RBF","sigmoid"],Kt="Sensitivity",Xt="Specificity",Qt="Balanced accuracy",Jt="Positive predicitve value",Zt="Negative predicitve value",te="prediction",ee=4,ne=3,re=2,oe=0,ie=1,ae=2,se=0,ue=1;function ce(t,e,r){return Z(this,void 0,void 0,(function*(){const i=e.columns;if(2!=r.categories.length)throw new Error(Pt);const a=o.Column.float(r.name,r.length);for(let t=0;t<r.length;t++)a.set(t,r.get(t)==r.categories[0]?-1:1,!1);const s=yield function(t,e,r){return Z(this,void 0,void 0,(function*(){!function(t){if(t.gamma<=At)throw new Error(Nt);switch(t.kernel){case tt:return;case nt:if(t.sigma<=Ct)throw new Error(It);return;case et:if(t.cParam<=St)throw new Error(Mt);if(t.dParam<=_t)throw new Error(Tt);return;case rt:return;default:throw new Error(Ot)}}(t);const i=[se,se];switch(t.kernel){case tt:break;case nt:i[yt]=t.sigma;break;case et:i[vt]=t.cParam,i[wt]=t.dParam;break;case rt:i[bt]=t.kappa,i[Et]=t.theta;break;default:throw new Error(Ot)}const a=o.Column.fromList("double",Wt,i),s=e.toList(),u=s[0].length+ue,c=s.length+ue,l=ot;let d;const h=async function(t,e,r,o,i,a,s,u){return new Promise(((c,l)=>{const d=new Worker(new URL(n.p+n.u(656),n.b));d.postMessage(U(EDA.trainAndAnalyzeLSSVM.arguments,[t,e,r,o,i,a,s,u])),d.onmessage=function(t){d.terminate(),c(k(EDA.trainAndAnalyzeLSSVM,t.data))}}))}(t.gamma,t.kernel,a,u,c,l,e,r);yield h.then((t=>{d=t}),(t=>{throw new Error(`Error: ${t}`)})),d[at].name=Dt,d[st].name=Ut,d[ut].name=kt,d[ct].name=Gt,d[lt].name=xt,d[dt].name=Ft,d[ht].name=Rt;const f={trainGamma:t.gamma,kernelType:t.kernel,kernelParams:a,trainLabels:r,normalizedTrainData:o.DataFrame.fromColumns(d[it]),means:d[at],stdDevs:d[st],modelParams:d[ut],modelWeights:d[ct],predictedLabels:d[lt],correctness:d[dt],confusionMatrix:d[ht],trainError:void 0,featuresCount:s.length,trainSamplesCount:s[0].length};return function(t){const e=t.confusionMatrix.getRawData(),n=e[ft],r=e[gt],o=e[mt],i=e[pt],a=n+i,s=o+r,u=n/a,c=r/s,l=n/(n+o),d=r/(r+i),h=(n+r)/(a+s),f=(u+c)/2;t.sensitivity=u,t.specificity=c,t.balancedAccuracy=f,t.positivePredicitveValue=l,t.negativePredicitveValue=d,t.trainError=100*(1-h)}(f),f}))}(t,i,a);return s.realLabels=r,s}))}function le(t,e){const n=he(e);return o.Viewer.form(n.modelInfo,{showNavigation:!1}).root}function de(t){const e=t.normalizedTrainData.columns,n=t.trainSamplesCount,r=t.featuresCount,i=o.DataFrame.fromColumns([t.realLabels]).toByteArray(),a=ee+i.length+4-i.length%4,s=function(t){const e=t.kernelParams.getRawData();return o.DataFrame.fromColumns([o.Column.fromList("double",Bt,[t.trainGamma]),o.Column.fromStrings(Vt,[$t[t.kernelType]]),o.Column.fromList("double",jt,[e[0]]),o.Column.fromList("double",Yt,[e[1]]),o.Column.fromList("double",zt,[t.featuresCount]),o.Column.fromList("double",qt,[t.trainSamplesCount]),o.Column.fromList("double",Ht,[t.trainError]),o.Column.fromList("double",Qt,[t.balancedAccuracy]),o.Column.fromList("double",Kt,[t.sensitivity]),o.Column.fromList("double",Xt,[t.specificity]),o.Column.fromList("double",Jt,[t.positivePredicitveValue]),o.Column.fromList("double",Zt,[t.negativePredicitveValue])])}(t).toByteArray(),u=ee+s.length+4-s.length%4,c=new Uint8Array(ee*(ne+re+n+r+r+n+ue+r+ue+r*n)+a+u),l=c.buffer;let d=0,h=new Int32Array(l,d,ne);h[oe]=t.kernelType,h[ie]=n,h[ae]=r,d+=ne*ee;let f=new Float32Array(l,d,re);f.set(t.kernelParams.getRawData()),d+=re*ee,f=new Float32Array(l,d,n),f.set(t.trainLabels.getRawData()),d+=n*ee,f=new Float32Array(l,d,r),f.set(t.means.getRawData()),d+=r*ee,f=new Float32Array(l,d,r),f.set(t.stdDevs.getRawData()),d+=r*ee,f=new Float32Array(l,d,n+ue),f.set(t.modelParams.getRawData()),d+=(n+ue)*ee,f=new Float32Array(l,d,r+ue),f.set(t.modelWeights.getRawData()),d+=(r+ue)*ee;for(const t of e)f=new Float32Array(l,d,r),f.set(t.getRawData()),d+=r*ee;return h=new Int32Array(l,d,1),h[0]=i.length,c.set(i,d+ee),d+=a,h=new Int32Array(l,d,1),h[0]=s.length,c.set(s,d+ee),d+=u,c}function he(t){const e=t.buffer;let n=0;const r=new Int32Array(e,n,ne);n+=ne*ee;const i=r[ie],a=r[ae],s=o.Column.fromFloat32Array(Wt,new Float32Array(e,n,re));n+=re*ee;const u=o.Column.fromFloat32Array(Lt,new Float32Array(e,n,i));n+=i*ee;const c=o.Column.fromFloat32Array(Dt,new Float32Array(e,n,a));n+=a*ee;const l=o.Column.fromFloat32Array(Ut,new Float32Array(e,n,a));n+=a*ee;const d=o.Column.fromFloat32Array(kt,new Float32Array(e,n,i+ue));n+=(i+ue)*ee;const h=o.Column.fromFloat32Array(Gt,new Float32Array(e,n,a+ue));n+=(a+ue)*ee;const f=[];for(let t=0;t<i;t++)f.push(o.Column.fromFloat32Array(t.toString(),new Float32Array(e,n,a))),n+=a*ee;const p=o.DataFrame.fromColumns(f),m=new Int32Array(e,n,1)[0],g=m+4-m%4;n+=ee;const y=o.DataFrame.fromByteArray(new Uint8Array(e,n,m)).columns.byIndex(0);n+=g;const v=new Int32Array(e,n,1)[0],w=v+4-v%4;n+=ee;const b=o.DataFrame.fromByteArray(new Uint8Array(e,n,v));return n+=w,{kernelType:r[oe],kernelParams:s,trainLabels:u,realLabels:y,means:c,stdDevs:l,modelParams:d,modelWeights:h,normalizedTrainData:p,modelInfo:b}}function fe(t,e){return Z(this,void 0,void 0,(function*(){const r=he(new Uint8Array(e)),i=yield function(t,e){return Z(this,void 0,void 0,(function*(){let r;const o=async function(t,e,r,o,i,a,s,u,c){return new Promise(((l,d)=>{const h=new Worker(new URL(n.p+n.u(763),n.b));h.postMessage(U(EDA.predictByLSSVM.arguments,[t,e,r,o,i,a,s,u,c])),h.onmessage=function(t){h.terminate(),l(k(EDA.predictByLSSVM,t.data))}}))}(t.kernelType,t.kernelParams,t.normalizedTrainData.columns,t.trainLabels,t.means,t.stdDevs,t.modelParams,t.modelWeights,e);return yield o.then((t=>{r=t}),(t=>{throw new Error(`Error: ${t}`)})),r}))}(r,t.columns),a=o.Column.string(te,i.length),s=r.realLabels.categories;for(let t=0;t<a.length;t++)a.set(t,-1==i.get(t)?s[0]:s[1]);return o.DataFrame.fromColumns([a])}))}function pe(t,e){const n=t.columns;if(!e.matches("categorical")||e.categories.length>2)return!1;let r=!0;for(let t=0;t<n.length;t++)r=r&&n.byIndex(t).matches("numerical");return r}function me(t,e){return t.rowCount<=1e3}var ge,ye,ve,we,be,Ee,Ae,Ce;!function(t){t[t.COMPUTE_COMPONENTS=0]="COMPUTE_COMPONENTS",t[t.PERFORM_MVA=1]="PERFORM_MVA",t[t.DEMO=2]="DEMO"}(ge||(ge={})),function(t){t.NO_DF="No dataframe is opened",t.NO_COLS="No numeric columns without missing values",t.ONE_COL="No columns to be used as features (just one numeric columns without missing values)",t.EMPTY_DF="Dataframe is empty"}(ye||(ye={})),function(t){t.PREDICT="Predict",t.USING="Using",t.COMPONENTS="Components",t.PLS="PLS",t.MVA="Multivariate Analysis (PLS)",t.RUN="RUN",t.NAMES="Names",t.MODEL="Observed vs. Predicted",t.FEATURE="Feature",t.REGR_COEFS="Regression Coefficients",t.XLOADING="x.loading.p",t.LOADINGS="Loadings",t.XSCORE="x.score.t",t.YSCORE="y.score.u",t.SCORES="Scores",t.EXPL_VAR="Explained Variance",t.EXPLORE="Explore",t.FEATURES="Feature names",t.BROWSE="Browse",t.ANALYSIS="Features Analysis"}(ve||(ve={})),function(t){t.PREDICT="Column with the response variable",t.FEATURES="Predictors (features)",t.COMPONENTS="Number of PLS components",t.PLS="Compute PLS components",t.MVA="Perform multivariate analysis",t.NAMES="Names of data samples"}(we||(we={})),function(t){t.PLS="/help/explore/multivariate-analysis/pls#pls-components",t.MVA="/help/explore/multivariate-analysis/pls",t.MODEL="/help/explore/multivariate-analysis/plots/predicted-vs-reference",t.COEFFS="/help/explore/multivariate-analysis/plots/regression-coefficients",t.LOADINGS="/help/explore/multivariate-analysis/plots/loadings",t.EXPL_VARS="/help/explore/multivariate-analysis/plots/explained-variance",t.SCORES="/help/explore/multivariate-analysis/plots/scores"}(be||(be={})),function(t){t[t.DEFAULT=3]="DEFAULT",t[t.MIN=1]="MIN"}(Ee||(Ee={})),function(t){t.PREFIX="PLS",t.SUFFIX="(predicted)",t.COMP="component",t.COMPS="components"}(Ae||(Ae={})),function(t){t[t.PREDICTION=0]="PREDICTION",t[t.REGR_COEFFS=1]="REGR_COEFFS",t[t.T_SCORES=2]="T_SCORES",t[t.U_SCORES=3]="U_SCORES",t[t.X_LOADINGS=4]="X_LOADINGS",t[t.Y_LOADINGS=5]="Y_LOADINGS"}(Ce||(Ce={}));const Se="Int",_e=6,Ne=[.49,.79,.99],Ie=1,Me=200,Te=200;var Oe;!function(t){t.AXIS="#838383",t.CIRCLE="#0000FF"}(Oe||(Oe={}));const Pe="# Data\nEach car has many features - patterns extraction is complicated.\n\n# Model\nPredict car price by its other features.\n\n# Try\nPress 'RUN' to perform multivariate analysis using partial least squares\n([PLS](https://en.wikipedia.org/wiki/Partial_least_squares_regression)) regression.\n\n# Essence\nThe method finds the latent factors that\n\n* capture the maximum variance in the features\n* maximize correlation with the response variable",Le=[{caption:ve.MODEL,text:"Closer to the line means better price prediction."},{caption:ve.SCORES,text:"The latent factor values for each sample reflect the similarities and dissimilarities among observations."},{caption:ve.LOADINGS,text:"The impact of each feature on the latent factors: higher loading means stronger influence."},{caption:ve.REGR_COEFS,text:"Parameters of the obtained linear model: features make different contribution to the prediction."},{caption:ve.EXPL_VAR,text:"How well the latent components fit source data: closer to one means better fit."}],xe=Le.map((t=>`# ${t.caption}\n\n${t.text}`)).join("\n\n")+`\n\n# Learn more\n \n * [Multivariate analysis](${be.MVA}),\n * [ANOVA](https://datagrok.ai/help/explore/anova)`;var Fe=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{u(r.next(t))}catch(t){i(t)}}function s(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,s)}u((r=r.apply(t,e||[])).next())}))};const Re=Math.min,De=Math.max;function Ue(t){const e=[],n=(t,n)=>{e.push({type:"line",formula:t,width:Ie,visible:!0,title:" ",min:-n,max:n,color:Oe.CIRCLE})};return t.forEach((r=>{const o="${"+r+"}";e.push({type:"line",formula:`${o} = 0`,width:Ie,visible:!0,title:" ",color:Oe.AXIS}),t.forEach((t=>{const e="${"+t+"}";Ne.forEach((t=>{n(e+` = sqrt(${t*t} - ${o} * ${o})`,t),n(e+` = -sqrt(${t*t} - ${o} * ${o})`,t)}))}))})),e}function ke(t){return Fe(this,void 0,void 0,(function*(){X(t.features,t.components),$(t.predict),K(t.predict);const e=yield async function(t,e,r,o){return new Promise(((t,i)=>{const a=new Worker(new URL(n.p+n.u(412),n.b));a.postMessage(U(EDA.partialLeastSquareRegression.arguments,[e,r,o])),a.onmessage=function(e){a.terminate(),t(k(EDA.partialLeastSquareRegression,e.data))}}))}(t.table,t.features,t.predict,t.components);return{prediction:e[Ce.PREDICTION],regressionCoefficients:e[Ce.REGR_COEFFS],tScores:e[Ce.T_SCORES],uScores:e[Ce.U_SCORES],xLoadings:e[Ce.X_LOADINGS],yLoadings:e[Ce.Y_LOADINGS]}}))}function Ge(n){return Fe(this,void 0,void 0,(function*(){const r=n===ge.DEMO?t.shell.view(ve.BROWSE).preview.table:t.shell.t;if(null===r)return void t.shell.warning(ye.NO_DF);if(0===r.rowCount)return void t.shell.warning(ye.EMPTY_DF);const i=[],a=[],s=[],u=t=>(t.type===o.COLUMN_TYPE.INT||t.type===o.COLUMN_TYPE.FLOAT)&&0===t.stats.missingValueCount;if(r.columns.toList().forEach((t=>{u(t)?(i.push(t.name),a.push(t)):t.type===o.COLUMN_TYPE.STRING&&s.push(t)})),0===i.length)return void t.shell.warning(ye.NO_COLS);if(1===i.length)return void t.shell.warning(ye.ONE_COL);let c=a[a.length-1];const l=e.input.column(ve.PREDICT,{table:r,value:c,onValueChanged:t=>{c=t,v()},filter:t=>u(t)});let d;l.setTooltip(we.PREDICT);const h=e.input.columns(ve.USING,{table:r,available:i});h.onInput.subscribe((()=>v())),h.setTooltip(we.FEATURES);let f=Re(i.length-1,Ee.DEFAULT);const p=e.input.forProperty(o.Property.fromOptions({name:ve.COMPONENTS,inputType:Se,defaultValue:f,showPlusMinus:!0,min:Ee.MIN}));let m,g,y;p.onInput.subscribe((()=>v())),p.setTooltip(we.COMPONENTS),n===ge.COMPUTE_COMPONENTS?(m=ve.PLS,g=be.PLS,y=we.PLS):(m=ve.MVA,g=be.MVA,y=we.MVA);const v=()=>{var t;h.value=h.value.filter((t=>t!==c)),d=h.value,p.value=Re(De(null!==(t=p.value)&&void 0!==t?t:f,Ee.MIN),d.length),f=p.value,E.getButton(ve.RUN).disabled=0===d.length||f<=0};let w=s.length>0?s[0]:void 0;const b=e.input.column(ve.NAMES,{table:r,value:w,onValueChanged:t=>w=null!=t?t:void 0,filter:t=>t.type===o.COLUMN_TYPE.STRING});b.setTooltip(we.NAMES),b.root.hidden=0===s.length||n===ge.COMPUTE_COMPONENTS;const E=e.dialog({title:m,helpUrl:g}).add(e.form([l,h,p,b])).addButton(ve.RUN,(()=>Fe(this,void 0,void 0,(function*(){E.close(),console.log(w),yield function(n,r){return Fe(this,void 0,void 0,(function*(){var i,a,s;const u=yield ke(n),c=u.tScores,l=n.table.columns,d=n.features,h=d.names(),f=r===ge.COMPUTE_COMPONENTS?Ae.PREFIX:ve.XSCORE;if(c.forEach(((t,e)=>{t.name=l.getUnusedName(`${f}${e+1}`),l.add(t)})),r===ge.COMPUTE_COMPONENTS)return;const p=r===ge.DEMO?t.shell.view(ve.BROWSE).preview:t.shell.tableView(n.table.name),m=o.DataFrame.fromColumns([o.Column.fromStrings(ve.FEATURE,h),u.regressionCoefficients]);m.name=`${n.table.name}(${ve.ANALYSIS})`,t.shell.addTable(m),u.xLoadings.forEach(((t,e)=>{t.name=m.columns.getUnusedName(`${ve.XLOADING}${e+1}`),m.columns.add(t)}));const g=function(t,e,n,r){const i=n.length,a=t.length,s=e.getRawData(),u=new Float32Array(i),c=r.getRawData();let l=n.stats.avg;for(let e=0;e<a;++e)l-=s[e]*t.byIndex(e).stats.avg;for(let t=0;t<i;++t)u[t]=l+c[t];return o.Column.fromFloat32Array("Debiased",u,i)}(d,u.regressionCoefficients,n.predict,u.prediction);g.name=l.getUnusedName(`${n.predict.name} ${Ae.SUFFIX}`),l.add(g);const y=p.addViewer(o.Viewer.scatterPlot(n.table,{title:ve.MODEL,xColumnName:n.predict.name,yColumnName:g.name,showRegressionLine:!0,markerType:o.MARKER_TYPE.CIRCLE,showLabels:"Always",help:be.MODEL}));console.log(null===(i=n.names)||void 0===i?void 0:i.name),void 0!==n.names&&null!==n.names&&y.setOptions({labelColumnNames:[null===(a=n.names)||void 0===a?void 0:a.name]}),u.regressionCoefficients.name=ve.REGR_COEFS;const v=p.addViewer(o.Viewer.barChart(m,{table:m.name,title:ve.REGR_COEFS,splitColumnName:ve.FEATURE,valueColumnName:u.regressionCoefficients.name,valueAggrType:o.AGG.AVG,help:be.COEFFS,showValueSelector:!1,showStackSelector:!1}));u.xLoadings.forEach(((t,e)=>t.name=`${ve.XLOADING}${e+1}`));const w=p.addViewer(o.Viewer.scatterPlot(m,{table:m.name,title:ve.LOADINGS,xColumnName:`${ve.XLOADING}1`,yColumnName:`${ve.XLOADING}${u.xLoadings.length>1?"2":"1"}`,markerType:o.MARKER_TYPE.CIRCLE,labelColumnNames:[ve.FEATURE],help:be.LOADINGS})),b=c.map((t=>t.name));u.uScores.forEach(((t,e)=>{t.name=l.getUnusedName(`${ve.YSCORE}${e+1}`),l.add(t),b.push(t.name)}));const E=o.Viewer.scatterPlot(n.table,{title:ve.SCORES,xColumnName:c[0].name,yColumnName:c.length>1?c[1].name:u.uScores[0].name,markerType:o.MARKER_TYPE.CIRCLE,help:be.SCORES,showViewerFormulaLines:!0});void 0!==n.names&&null!==n.names&&E.setOptions({labelColumnNames:[null===(s=n.names)||void 0===s?void 0:s.name]}),E.meta.formulaLines.addAll(Ue(b)),p.addViewer(E);const A=u.yLoadings.getRawData(),C=u.xLoadings.map((t=>t.getRawData())),S=n.table.rowCount,_=h.length,N=n.components,I=new Float32Array(N),M=[],T=[];for(let t=0;t<_;++t)T.push(new Float32Array(N));I[0]=Math.pow(A[0],2)/S,M.push(`1 ${Ae.COMP}`),T.forEach(((t,e)=>{t[0]=Math.pow(C[0][e],2)/S}));for(let t=1;t<N;++t)I[t]=I[t-1]+Math.pow(A[t],2)/S,T.forEach(((e,n)=>e[t]=e[t-1]+Math.pow(C[t][n],2)/S)),M.push(`${t+1} ${Ae.COMPS}`);const O=o.DataFrame.fromColumns([o.Column.fromStrings(ve.COMPONENTS,M),o.Column.fromFloat32Array(n.predict.name,I)]);O.name=`${n.table.name}(${ve.EXPL_VAR})`,t.shell.addTable(O),T.forEach(((t,e)=>O.columns.add(o.Column.fromFloat32Array(h[e],t))));const P=p.addViewer(o.Viewer.barChart(O,{table:O.name,title:ve.EXPL_VAR,splitColumnName:ve.COMPONENTS,valueColumnName:n.predict.name,valueAggrType:o.AGG.AVG,help:be.EXPL_VARS,showCategorySelector:!1,showStackSelector:!1}));if(r===ge.DEMO){const n=[y,E,w,v,P].map(((t,e)=>({text:Le[e].text,showNextTo:t.root})));e.hints.addTextHint({title:ve.EXPLORE,pages:n}).helpUrl=be.MVA,t.shell.windows.help.showHelp(e.markdown(xe))}}))}({table:r,features:o.DataFrame.fromColumns(d).columns,predict:c,components:f,names:w},n)}))),void 0,y).show({x:Me,y:Te});setTimeout((()=>{h.value=a.filter((t=>t!==c)),d=h.value}),_e),t.shell.v.append(E.root)}))}var Be,Ve=n(6572);!function(t){t.NO_DATAFRAME="No dataframe is opened",t.NO_MISSING_VALUES="No missing values",t.ONE_AVAILABLE_FEATURE="Not enough of feature columns to apply imputation using the KNN method",t.ONE_FEATURE_SELECTED="Imputation cannot be applied to",t.UNSUPPORTED_COLUMN_TYPE="Unsupported column type",t.UNSUPPORTED_IMPUTATION_STRATEGY="Unsupported imputation strategy",t.KNN_CANNOT_BE_APPLIED="KNN imputer cannot be applied: no columns to be used as features",t.KNN_NO_TARGET_COLUMNS="KNN imputer cannot be applied: no columns with missing values",t.KNN_NO_FEATURE_COLUMNS="KNN imputer cannot be applied: no feature columns",t.KNN_NOT_ENOUGH_OF_ROWS="KNN imputer cannot be applied: not enough of rows",t.KNN_IMPOSSIBLE_IMPUTATION="Imputation is impossible, no features can be used",t.INCORRECT_NEIGHBORS="Incorrect number of neighbors",t.KNN_FAILS="KNN IMPUTATION FAILS",t.CORE_ISSUE="Core issue",t.FAILED_TO_IMPUTE="Failed to impute",t.UNSUPPORTED_FILL_VALUE_TYPE="Unsupported fill value type",t.EMPTY_COLUMN="Column contains just null values",t.FAILS_TO_PREDICT_IMPUTATION_FAILS="Failed to predict imputation fails",t.WRONG_PREDICTIONS="wrong evaluation of KNN imputation fails"}(Be||(Be={}));const We="copy";var je;!function(t){t.KNN_IMPUTER="k-NN Imputation",t.TABLE="Table",t.IN_PLACE="In-place",t.COLUMNS="Impute",t.FEATURES="Using",t.CANCEL="CANCEL",t.RUN="RUN",t.OK="OK",t.NEIGHBORS="Neighbors",t.DISTANCE="Distance",t.FILL="Fill",t.MARK="Mark",t.SIMPLE_IMPUTER="Simple impute",t.SETTINGS="Settings",t.KEEP_EMPTY="Keep empty"}(je||(je={}));const Ye="/help/explore/missing-values-imputation#the-k-nn-method";var ze;!function(t){t.TARGET="Columns with missing values that must be filled",t.FEATURES="Columns with features to be used for determining the 'nearest' elements in the k-NN method",t.IN_PLACE="Defines whether to use in-place imputation or add a new column without missing values",t.METRIC="Type of metric between the feature values",t.WEIGHT="Weight",t.NEIGHBORS="Neighbors count used in the KNN method",t.DISTANCE="Type of distance between elements with the specified features",t.METRIC_SETTINGS="Show additional options",t.FILL_FAILED_ITEMS="Impute missing values using a simple approach: mean, median or most frequent",t.MARK_FAILED_ITEMS="Mark missing values cells with a color",t.FILL_VALUE="Fill value",t.IMPUTATION_SETTINGS="Simple imputation settings",t.KEEP_EMPTY="Defines whether to keep empty missing values failed to be imputed OR fill them using simple imputation",t.RUN="Run imputation using the k-NN method"}(ze||(ze={}));const qe=15,He=[o.COLUMN_TYPE.INT,o.COLUMN_TYPE.FLOAT,o.COLUMN_TYPE.STRING,o.COLUMN_TYPE.DATE_TIME,o.COLUMN_TYPE.QNUM];function $e(t){switch(t.type){case o.COLUMN_TYPE.INT:return o.INT_NULL;case o.COLUMN_TYPE.FLOAT:case o.COLUMN_TYPE.QNUM:case o.COLUMN_TYPE.DATE_TIME:return o.FLOAT_NULL;case o.COLUMN_TYPE.STRING:return t.max;default:throw new Error(Be.UNSUPPORTED_COLUMN_TYPE)}}var Ke,Xe,Qe;!function(t){t.ONE_HOT="One-hot",t.DIFFERENCE="Difference"}(Ke||(Ke={})),function(t){t.EUCLIDEAN="Euclidean",t.MANHATTAN="Manhattan"}(Xe||(Xe={})),function(t){t[t.WEIGHT=1]="WEIGHT",t[t.NEIGHBORS=4]="NEIGHBORS",t[t.IN_PLACE=1]="IN_PLACE",t[t.SELECTED=1]="SELECTED",t[t.KEEP_EMPTY=0]="KEEP_EMPTY"}(Qe||(Qe={}));const Je=1;function Ze(t,e,n){for(const t of e)if(!n.has(t))return!1;for(const r of t){const t=n.get(r);if(void 0===t)throw new Error(Be.FAILS_TO_PREDICT_IMPUTATION_FAILS);for(const r of t){let t=!0;for(const o of e){const e=n.get(o);if(void 0===e)throw new Error(Be.FAILS_TO_PREDICT_IMPUTATION_FAILS);if(!e.includes(r)){t=!1;break}}if(t)return!0}}return!1}var tn;function en(t){if(t<=0||t>=1)throw new Error(tn.INCORRECT_SIGNIFICANCE_LEVEL)}function nn(t){const e=t.size;return e<=1?0:(t.sumOfSquares-Math.pow(t.sum,2)/e)/(e-1)}function rn(t,e,n){en(n);const r=nn(t),o=nn(e);return 0===r||0===o?r===o:r/o<Ve.centralF.inv(1-n,t.size-1,e.size-1)}!function(t){t.NON_EQUAL_FACTORS_VALUES_SIZE="non-equal sizes of factor and values arrays",t.INCORRECT_SIGNIFICANCE_LEVEL="incorrect significance level",t.NON_EQUAL_VARIANCES="non-equal variances",t.NON_NORMAL_DISTRIB="non-normal distribution",t.UNSUPPORTED_COLUMN_TYPE="unsupported feature column type",t.INCORRECT_CATEGORIES_COL_TYPE="incorrect categories column type",t.SINGLE_FACTOR="single category features",t.CATS_EQUAL_SIZE="single value in each category",t.NO_FEATURE_VARIATION="no feature variation",t.NO_FEATURE_VARIATION_WITHIN_GROUPS="no feature variation within groups"}(tn||(tn={}));class on{constructor(t,e,n){if(this.nullsCount=0,t.length!==e.length)throw new Error(tn.NON_EQUAL_FACTORS_VALUES_SIZE);if(!(e.stats.stdev>0))throw new Error(tn.NO_FEATURE_VARIATION);this.setStats(t,e,n)}areVarsEqual(t){const e=this.catCount;if(1===e)return!0;const n={sum:this.sums[0],sumOfSquares:this.sumsOfSquares[0],size:this.subSampleSizes[0]};for(let r=1;r<e;++r)if(!rn(n,{sum:this.sums[r],sumOfSquares:this.sumsOfSquares[r],size:this.subSampleSizes[r]},t))return!1;return!0}getOneWayAnova(){let t=0,e=0,n=0,r=this.catCount,o=r;for(let i=0;i<r;++i)0!==this.subSampleSizes[i]?(t+=this.sums[i],e+=this.sumsOfSquares[i],n+=Math.pow(this.sums[i],2)/this.subSampleSizes[i]):--o;if(r=o,1===r)throw new Error(tn.SINGLE_FACTOR);const i=this.size-this.nullsCount;if(i===r)throw new Error(tn.CATS_EQUAL_SIZE);const a=e-Math.pow(t,2)/i,s=n-Math.pow(t,2)/i,u=a-s;if(0===u)throw new Error(tn.NO_FEATURE_VARIATION_WITHIN_GROUPS);const c=r-1,l=i-r,d=s/c,h=u/l,f=d/h;return{ssBn:s,ssWn:u,ssTot:a,dfBn:c,dfWn:l,dfTot:i-1,msBn:d,msWn:h,fStat:f,pValue:1-Ve.centralF.cdf(f,c,l)}}setStats(t,e,n){const r=e.type,i=e.length,a=$e(e);switch(r){case o.COLUMN_TYPE.INT:case o.COLUMN_TYPE.FLOAT:const r=n;this.catCount=r,this.size=i;const s=e.getRawData(),u=t.getRawData(),c=new Float64Array(r).fill(0),l=new Float64Array(r).fill(0),d=new Int32Array(r).fill(0);let h;if(t.type==o.COLUMN_TYPE.BOOL){let t=0,e=0,n=u[0];const r=8*u.BYTES_PER_ELEMENT-1;for(let o=0;o<i;++o)h=1&n>>e,s[o]!==a?(c[h]+=s[o],l[h]+=Math.pow(s[o],2),++d[h]):++this.nullsCount,++e,e>r&&(e=0,++t,n=u[t])}else{const e=t.stats.missingValueCount>0?$e(t):-1;for(let t=0;t<i;++t)h=u[t],h!==e&&s[t]!==a?(c[h]+=s[t],l[h]+=Math.pow(s[t],2),++d[h]):++this.nullsCount}this.sums=c,this.sumsOfSquares=l,this.subSampleSizes=d;break;default:throw new Error(tn.UNSUPPORTED_COLUMN_TYPE)}}}const an=[o.COLUMN_TYPE.INT,o.COLUMN_TYPE.FLOAT],sn=[o.COLUMN_TYPE.STRING,o.COLUMN_TYPE.BOOL],un="/help/explore/anova";var cn,ln;function dn(){const n=t.shell.t;if(null===n)return void t.shell.warning("No dataframe is opened");const r=n.columns,i=[],a=[];for(const t of r)an.includes(t.type)?a.push(t.name):sn.includes(t.type)&&i.push(t.name);const s=i.length;if(s<1)return void t.shell.warning(e.markdown(`No acceptable factor columns:\n\n - type: ${sn.join(", ")} \n - at least two categories`));let u=n.col(ln.FACTOR);if(null===u){let t,e=0,n=r.byName(i[0]).categories.length;for(let o=1;o<s;++o)t=r.byName(i[o]).categories.length,t<n&&(n=t,e=o);u=r.byName(i[e])}if(a.length<1)return void t.shell.warning(e.markdown(`No acceptable feature columns:\n \n - type: ${an.join(", ")}`));const c=e.input.column("Category",{table:n,value:u,tooltipText:"Column with factor values",onValueChanged:t=>u=t,filter:t=>i.includes(t.name),nullable:!1});let l=n.col(ln.FEATURE);null===l&&(l=r.byName(a[0]));const d=e.input.column("Feature",{table:n,value:l,tooltipText:"Column with feature values",onValueChanged:t=>l=t,filter:t=>a.includes(t.name),nullable:!1});let h=cn.DEFAULT;const f=e.input.float("Alpha",{min:cn.MIN,max:cn.MAX,value:h,nullable:!1,tooltipText:"Significance level",onValueChanged:t=>{h=t,g.disabled=h<=cn.INFIMUM||h>=cn.SUPREMUM}}),p=e.dialog({title:"ANOVA",helpUrl:un}),m=t.shell.getTableView(n.name);m.root.appendChild(p.root),p.addButton("Run",(()=>{p.close();try{const r=function(t,e,n,r=!0){en(n);const o=t.stats.uniqueCount;if(o<2)throw new Error(tn.SINGLE_FACTOR);const i=new on(t,e,o);if(r&&!i.areVarsEqual(n))throw new Error(tn.NON_EQUAL_VARIANCES);const a=i.getOneWayAnova();return{anovaTable:a,fCritical:Ve.centralF.inv(1-n,a.dfBn,a.dfWn),significance:n}}(u,l,h);!function(n,r,i,a){const s=a.anovaTable.fStat>a.fCritical,u=s?`"${r}" affects the "${i}"`:`"${r}" doesn't affect the "${i}"`,c=t.shell.getTableView(n.name),l=o.Viewer.boxPlot(n,{categoryColumnNames:[r],valueColumnName:i,showPValue:!1,showStatistics:!1,description:u,showColorSelector:!1}),d=c.dockManager.dock(l.root,o.DOCK_TYPE.RIGHT,null,"ANOVA"),h=e.markdown(`**H0:** the "${r}" \n factor does not produce a significant difference in the "${i}" feature.`);e.tooltip.bind(h,"Null hypothesis");const f=e.markdown("**Test result:** "+(s?"means differ significantly.":"means do not differ significantly.")),p=s?e.divV([e.p(`Reject the null hypothesis, since F > F-critical: \n ${a.anovaTable.fStat.toFixed(2)} > ${a.fCritical.toFixed(2)}.`),e.h2("There is a significant difference among sample averages.")]):e.divV([e.p(`Fail to reject the null hypothesis, since F < F-critical: \n ${a.anovaTable.fStat.toFixed(2)} < ${a.fCritical.toFixed(2)}.`),e.h2("There is no significant difference among sample averages.")]);e.tooltip.bind(f,(()=>p));const m=e.divV([h,f,e.link("Learn more",(()=>window.open("https://en.wikipedia.org/wiki/F-test","_blank")),"Click to open in a new tab")]);m.style.marginLeft="20px";const g=t.shell.dockManager.dock(m,o.DOCK_TYPE.DOWN,d,"F-test",.3),y=function(t){const n=t.anovaTable,r=o.Viewer.grid(o.DataFrame.fromColumns([o.Column.fromStrings("Source of variance",["Between groups","Within groups","Total"]),o.Column.fromList(o.COLUMN_TYPE.FLOAT,"SS",[n.ssBn,n.ssWn,n.ssTot]),o.Column.fromList(o.COLUMN_TYPE.INT,"DF",[n.dfBn,n.dfWn,n.dfTot]),o.Column.fromList(o.COLUMN_TYPE.FLOAT,"MS",[n.msBn,n.msWn,null]),o.Column.fromList(o.COLUMN_TYPE.FLOAT,"F",[n.fStat,null,null]),o.Column.fromList(o.COLUMN_TYPE.FLOAT,"F-critical",[t.fCritical,null,null]),o.Column.fromList(o.COLUMN_TYPE.FLOAT,"p-value",[n.pValue,null,null])])),i=new Map([["Source of variance","List of the explored variation sources"],["SS","Sum of squares (SS)"],["DF","Degrees of freedom (DF)"],["MS","Mean square (MS)"],["F","F-statistics (F)"],["F-critical",`${t.significance}-critical value of F-statistics (F)`],["p-value","Probability to obtain F-statistics (F) greater than the actual observation."]]);return r.onCellTooltip((function(t,n,r){if(t.isColHeader)return e.tooltip.show(e.divV([e.p(i.get(t.tableColumn.name))]),n,r),!0})),r.helpUrl=un,r}(a);t.shell.dockManager.dock(y.root,o.DOCK_TYPE.FILL,g,"Analysis")}(n,u.name,l.name,r)}catch(n){n instanceof Error?(t.shell.warning((r=n.message,e.divV([e.markdown(`ANOVA cannot be performed:\n \n ${r}`),e.link("Learn more",(()=>window.open("https://en.wikipedia.org/wiki/Analysis_of_variance#Assumptions","_blank")),"Click to open in a new tab")]))),m.addViewer(o.VIEWER.BOX_PLOT,{categoryColumnNames:[u.name],valueColumnName:l.name,showStatistics:!1,showPValue:!1})):t.shell.error("ANOVA fails: the platform issue")}var r}),void 0,"Perform analysis of variances");const g=p.getButton("Run");p.add(c).add(d).add(f).show()}!function(t){t[t.DEFAULT=.05]="DEFAULT",t[t.MIN=.01]="MIN",t[t.MAX=.99]="MAX",t[t.INFIMUM=0]="INFIMUM",t[t.SUPREMUM=1]="SUPREMUM"}(cn||(cn={})),function(t){t.FACTOR="race",t.FEATURE="age"}(ln||(ln={}));var hn=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{u(r.next(t))}catch(t){i(t)}}function s(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,s)}u((r=r.apply(t,e||[])).next())}))};function fn(t,e,r,o){return hn(this,void 0,void 0,(function*(){return new Promise((function(i,a){const s=new Worker(new URL(n.p+n.u(682),n.b));s.postMessage({embedX:t,embedY:e,minPts:o,epsilon:r}),s.onmessage=({data:{error:t,clusters:e}})=>{s.terminate(),t?a(t):i(e)}}))}))}n(5540);let pn=null;function mn(){return t=this,e=void 0,r=function*(){if(!navigator.gpu)return console.error("WebGPU is not supported in this browser"),null;if(!pn&&(pn=yield navigator.gpu.requestAdapter(),null==pn))return null;let t=null;return"info"in pn&&(t=pn.info),t?gn(t.description,gn(t.vendor,"No GPU description available")):"No GPU description available"},new((n=void 0)||(n=Promise))((function(o,i){function a(t){try{u(r.next(t))}catch(t){i(t)}}function s(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,s)}u((r=r.apply(t,e||[])).next())}));var t,e,n,r}function gn(t,e){return t&&""!=t?t:e}var yn,vn,wn,bn,En,An,Cn,Sn,_n;(vn=yn||(yn={})).EUCLIDEAN="EUCLIDEAN",vn.MANHATTAN="MANHATTAN",yn.EUCLIDEAN,yn.MANHATTAN,(bn=wn||(wn={})).HAMMING="Hamming",bn.EUCLIDEAN="Euclidean",bn.MANHATTAN="Manhattan",bn.TANIMOTO="Tanimoto",bn.LEVENSTEIN="Levenshtein",bn.NEEDLEMAN_WUNSCH="Needlemann-Wunsch",bn.MONOMER_CHEMICAL_DISTANCE="Monomer chemical distance",bn.SOKAL="Sokal",bn.COSINE="Cosine",bn.ASYMMETRIC="Asymmetric",bn.Difference="Difference",bn.OneHot="One-Hot",wn.HAMMING,wn.EUCLIDEAN,wn.MANHATTAN,wn.TANIMOTO,wn.LEVENSTEIN,wn.NEEDLEMAN_WUNSCH,wn.MONOMER_CHEMICAL_DISTANCE,wn.SOKAL,wn.COSINE,wn.ASYMMETRIC,wn.Difference,wn.OneHot,wn.HAMMING,wn.EUCLIDEAN,wn.MANHATTAN,wn.TANIMOTO,wn.SOKAL,wn.COSINE,wn.ASYMMETRIC,wn.LEVENSTEIN,wn.NEEDLEMAN_WUNSCH,wn.MONOMER_CHEMICAL_DISTANCE,wn.Difference,wn.OneHot,new Set([wn.HAMMING,wn.LEVENSTEIN,wn.NEEDLEMAN_WUNSCH,wn.MONOMER_CHEMICAL_DISTANCE,wn.OneHot]),new Set([wn.HAMMING,wn.EUCLIDEAN,wn.MANHATTAN,wn.MONOMER_CHEMICAL_DISTANCE,wn.LEVENSTEIN,wn.NEEDLEMAN_WUNSCH,wn.TANIMOTO,wn.COSINE,wn.SOKAL,wn.ASYMMETRIC,wn.OneHot,wn.Difference]),new Set([wn.EUCLIDEAN,wn.MANHATTAN,wn.OneHot,wn.Difference]),new Set([wn.EUCLIDEAN,wn.MANHATTAN,wn.Difference]),new Set([wn.EUCLIDEAN,wn.MANHATTAN,wn.Difference]),new Set([wn.TANIMOTO,wn.COSINE,wn.SOKAL,wn.ASYMMETRIC]),function(t){t.ADD="ADD",t.SUB="SUB",t.MULT="MULT"}(En||(En={})),function(t){t.SQUARE="SQUARE",t.INVERSE="INVERSE",t.TRANSPOSE="TRANSPOSE",t.NORM="NORM",t.COLUMN_NORM="COLUMN_NORM"}(An||(An={})),function(t){t.SCALARMULT="SCALARMULT",t.SCALARADD="SCALARADD",t.SCALARPOW="SCALARPOW"}(Cn||(Cn={})),Object.prototype.toString,(_n=Sn||(Sn={})).UMAP="UMAP",_n.T_SNE="t-SNE",Promise.resolve(),n(934),n(8903);const Nn=2;o.SEMTYPE.MOLECULE,o.SEMTYPE.MACROMOLECULE;class In{constructor(){this.epsilon={uiName:"Epsilon",value:.01,tooltip:"Minimum distance between cluster points",min:0,max:2,step:.005},this.minPts={uiName:"Minimum points",value:4,tooltip:"Minimum number of points in cluster",min:1,max:1e3,step:1}}}const Mn="bypassLargeDataWarning",Tn="show-scatterplot-progress";var On,Pn;(Pn=On||(On={})).EUCLIDEAN="EUCLIDEAN",Pn.MANHATTAN="MANHATTAN";const Ln=rxjs;var xn=n(5072),Fn=n.n(xn),Rn=n(7825),Dn=n.n(Rn),Un=n(7659),kn=n.n(Un),Gn=n(5056),Bn=n.n(Gn),Vn=n(540),Wn=n.n(Vn),jn=n(1113),Yn=n.n(jn),zn=n(7939),qn={};qn.styleTagTransform=Yn(),qn.setAttributes=Bn(),qn.insert=kn().bind(null,"head"),qn.domAPI=Dn(),qn.insertStyleElement=Wn(),Fn()(zn.A,qn),zn.A&&zn.A.locals&&zn.A.locals;class Hn{constructor(){this.learningRate={uiName:"Learninig rate",value:1,tooltip:"The initial learning rate for the embedding optimization"},this.nEpochs={uiName:"Epochs",value:0,tooltip:"The number of epochs to optimize embeddings via SGD. Computed automatically if set to 0"},this.nNeighbors={uiName:"Neighbors",value:15,tooltip:"The number of nearest neighbors to construct the fuzzy manifold"},this.spread={uiName:"Spread",value:1,tooltip:"The effective scale of embedded points, used with min distance to control \n the clumped/dispersed nature of the embedding"},this.minDist={uiName:"Min distance",value:.1,tooltip:"The effective minimum distance between embedded points, \n used with spread to control the clumped/dispersed nature of the embedding"},this.randomSeed={uiName:"Random seed",value:null,tooltip:"Random seed",type:"string"},this.useWebGPU={uiName:"Use WebGPU",value:!1,tooltip:"Use WebGPU for Distance and UMAP computations",type:"boolean",disableTooltip:"WebGPU is not available"},mn().then((t=>{t?(this.useWebGPU.tooltip+=` (${t})`,this.useWebGPU.value=!0):(this.useWebGPU.value=!1,this.useWebGPU.disable=!0)}))}}class $n{constructor(){this.epsilon={uiName:"Epsilon",value:10,tooltip:"Epsilon is learning rate"},this.perplexity={uiName:"Perplexity",value:30,tooltip:"Roughly how many neighbors each point influences"}}}class Kn{constructor(n={}){this.editorSettings={},this.columnOptEditors=[],this.columnOptEditorsRoot=e.div(),this.columnParamsEditorRoot=e.div(),this.weightsEditorRoot=e.div(),this.columnFunctionsMap={},this.methodsParams={[Sn.UMAP]:new Hn,[Sn.T_SNE]:new $n},this.dbScanParams=new In,this.methodSettingsDivs=[],this.supportedFunctions={},this.methodSettingsAnchor=e.div(),this.plotEmbeddingsInput=e.input.bool("Plot embeddings",{value:!0}),this.aggregationMethodInput=e.input.choice("Aggregation",{value:On.EUCLIDEAN,items:[On.EUCLIDEAN,On.MANHATTAN]}),this.aggregationMethodInput.setTooltip("Aggregation method for combining distances between columns"),this.onColumnsChanged=new Ln.Subject,this.editorSettings=n,this.columnParamsEditorAccordion=e.accordion(),o.Func.find({tags:["dim-red-preprocessing-function"]}).forEach((t=>{const e=t.options.get("supportedSemTypes")??"",n=t.friendlyName??t.name,r=t.options.get("supportedTypes")??"",o=t.options.get("supportedUnits")??"",i=t.options.get("supportedDistanceFunctions")??"";this.editorSettings.semtype&&!e.includes(this.editorSettings.semtype)||this.editorSettings.type&&!r.includes(this.editorSettings.type)||this.editorSettings.units&&!o.includes(this.editorSettings.units)||(this.supportedFunctions[n]={func:t,semTypes:e?e.split(","):[],types:r?r.split(","):[],units:o?o.split(","):[],distanceFunctions:i?i.split(","):[]})})),this.postProcessingEditor=new Jn,this.tableInput=e.input.table("Table",{value:t.shell.tv.dataFrame,items:t.shell.tables,onValueChanged:()=>{this.onTableInputChanged()}}),this.onTableInputChanged();let r=!1;this.methodInput=e.input.choice("Method",{value:Sn.UMAP,items:[Sn.UMAP,Sn.T_SNE],onValueChanged:t=>{r&&this.createAlgorithmSettingsDiv(this.methodsParams[t])}}),this.methodSettingsIcon=e.icons.settings((()=>{r=!r,r?this.createAlgorithmSettingsDiv(this.methodsParams[this.methodInput.value]):(this.methodSettingsDivs.forEach((t=>t.remove())),this.methodSettingsDivs=[])}),"Modify methods parameters"),this.methodInput.root.classList.add("ml-dim-reduction-settings-input"),this.methodInput.root.prepend(this.methodSettingsIcon),this.columnParamsEditorAccordion.addPane("Column options",(()=>this.columnOptEditorsRoot),!0,null,!1),this.columnParamsEditorAccordion.root.style.display="none",this.columnParamsEditorRoot.appendChild(this.columnParamsEditorAccordion.root),this.columnParamsEditorRoot.appendChild(this.weightsEditorRoot)}onTableInputChanged(){const t=this.tableInput.value;if(!t)return;e.empty(this.columnOptEditorsRoot),e.empty(this.weightsEditorRoot),this.columnFunctionsMap={},t.columns.toList().forEach((t=>{Object.keys(this.supportedFunctions).forEach((e=>{const n=this.supportedFunctions[e].semTypes,r=this.supportedFunctions[e].types,o=this.supportedFunctions[e].units,i=!n.length||t.semType&&n.includes(t.semType),a=!r.length||r.includes(t.type),s=!o.length||t.meta.units&&o.includes(t.meta.units);i&&a&&s&&(this.columnFunctionsMap[t.name]||(this.columnFunctionsMap[t.name]=[]),this.columnFunctionsMap[t.name].push(e))}))}));const n=Object.keys(this.columnFunctionsMap),r=e.input.columns("Columns",{table:t,onValueChanged:t=>{if(this.onColumnsChanged.next(),e.empty(this.columnOptEditorsRoot),e.empty(this.weightsEditorRoot),this.aggregationMethodInput.root.style.display=!t||t?.length<2?"none":"flex",!t||0===t.length)return void(this.columnParamsEditorAccordion.root.style.display="none");this.columnOptEditors=t.map((t=>new Xn(t,this.columnFunctionsMap[t.name].map((t=>this.supportedFunctions[t])))));const n=e.divV([],{style:{maxHeight:"400px",overflow:"auto"}});this.columnOptEditors.forEach((t=>{n.appendChild(t.accordionDiv)}));const r=new Array(2*this.columnOptEditors.length).fill(null).map(((t,e)=>e%2==0?this.columnOptEditors[e/2].colOptEditors:[]));let o=0;const i=e.table(r,(t=>(o++,t&&t.length>0?t:[this.columnOptEditors[Math.floor((o-1)/2)].preprocessingFuncSettingsDiv=e.div([]),e.div(),e.div(),e.div()])),["Column","Encoding function","Similarity metric","Weight"]);this.columnOptEditors.forEach((t=>{t.preprocessingFuncSettingsDiv?.parentElement?.setAttribute("colspan","4"),t.preprocessingFuncSettingsDiv?.parentElement?.parentElement?.style?.setProperty("height","unset")})),this.columnOptEditors.length>0&&(this.columnParamsEditorAccordion.root.style.display="flex"),i.classList.add("ml-dim-reduction-column-editor-table-root"),this.columnOptEditorsRoot.appendChild(i)},available:n});r.fireChanged(),this.columnsInputRoot?(e.empty(this.columnsInputRoot),this.columnsInput=r,Array.from(this.columnsInput.root.children).forEach((t=>this.columnsInputRoot.appendChild(t)))):(this.columnsInputRoot=r.root,this.columnsInput=r)}createAlgorithmSettingsDiv(t){this.methodSettingsDivs.forEach((t=>t.remove())),this.methodSettingsDivs=[];const n=this.methodSettingsAnchor,r=n.parentElement;r&&Object.keys(t).forEach((o=>{const i=t[o],a="string"===i.type?e.input.string(i.uiName,{value:i.value??"",onValueChanged:t=>{i.value=t}}):"boolean"===i.type?e.input.bool(i.uiName,{value:i.value??!1,onValueChanged:t=>{i.value=t}}):e.input.float(i.uiName,{value:i.value,onValueChanged:t=>{i.value=t}});i.disable?(a.enabled=!1,e.tooltip.bind(a.input??a.root,i.disableTooltip??"")):e.tooltip.bind(a.input??a.root,i.tooltip),r.insertBefore(a.root,n),this.methodSettingsDivs.push(a.root)}))}get algorithmOptions(){const t=this.methodsParams[this.methodInput.value],e={};return Object.keys(t).forEach((n=>{null!=t[n].value&&(e[n]=t[n].value)})),e}get dbScanOptions(){return{dbScanEpsilon:this.dbScanParams.epsilon.value??.01,dbScanMinPts:this.dbScanParams.minPts.value??4}}getEditor(){return e.div([this.tableInput.root,this.columnsInputRoot,this.columnParamsEditorRoot,this.aggregationMethodInput.root,this.methodInput.root,this.methodSettingsAnchor,this.plotEmbeddingsInput,this.postProcessingEditor.root],{style:{minWidth:"420px"},classes:"dim-reduction-dialog-form"})}getParams(){return{table:this.tableInput.value,columns:this.columnsInput.value,methodName:this.methodInput.value,preprocessingFunctions:this.columnOptEditors.map((t=>t.preProcessingFunction)),distanceMetrics:this.columnOptEditors.map((t=>t.similarityMetricInput.value)),weights:this.columnOptEditors.map((t=>t.weight??1)),options:{...this.algorithmOptions,...this.dbScanOptions,preprocessingFuncArgs:this.columnOptEditors.map((t=>t.preprocessingFunctionSettings))},plotEmbeddings:this.plotEmbeddingsInput.value,clusterEmbeddings:!1,postProcessingFunction:this.postProcessingEditor.postProcessingFunction,postProcessingFunctionArgs:this.postProcessingEditor.args,aggreaggregationMethod:this.aggregationMethodInput.value}}getInput(){return{columns:this.columnsInput.value.map((t=>t.name)),method:this.methodInput.value,preprocessingFunctions:this.columnOptEditors.map((t=>t.preprocessingFunctionInput.value)),distanceMetrics:this.columnOptEditors.map((t=>t.similarityMetricInput.value)),weights:this.columnOptEditors.map((t=>t.weight??1)),options:{...this.algorithmOptions,...this.dbScanOptions,preprocessingFuncArgs:this.columnOptEditors.map((t=>t.preprocessingFunctionSettings))},plotEmbeddings:this.plotEmbeddingsInput.value,postProcessingFunction:this.postProcessingEditor.postProcessingFunctionInput.value??null,postProcessingFunctionArgs:this.postProcessingEditor.args,aggreaggregationMethod:this.aggregationMethodInput.value}}getStringInput(){return JSON.stringify(this.getInput())}async applyStringInput(e){try{const t=JSON.parse(e);await this.applyInput(t)}catch(e){t.shell.error("Error applying input from history"),console.error(e)}}async applyInput(e){try{const t=e.columns.map((t=>this.tableInput.value.col(t)));if(t.some((t=>!t)))throw new Error("Some columns are not found");this.columnsInput.value=t,this.columnsInput.fireChanged(),this.methodInput.value=e.method,this.columnOptEditors.forEach(((t,n)=>{t.preprocessingFunctionInput.value=e.preprocessingFunctions[n],t.similarityMetricInput.value=e.distanceMetrics[n],t.weightInput.value=e.weights[n],t.preprocessingFunctionSettings=e.options.preprocessingFuncArgs[n]})),this.plotEmbeddingsInput.value=e.plotEmbeddings,this.postProcessingEditor.postProcessingFunctionInput.value=e.postProcessingFunction,await this.postProcessingEditor._prevChangePromise,this.postProcessingEditor._postProcessingArgs=e.postProcessingFunctionArgs,this.aggregationMethodInput.value=e.aggreaggregationMethod;const n={};Object.keys(this.methodsParams[e.method]).forEach((t=>{n[t]=e.options[t]})),Object.keys(this.methodsParams[e.method]).forEach((t=>{this.methodsParams[e.method][t].value=n[t]}));const r=this.methodSettingsDivs.length>0;this.createAlgorithmSettingsDiv(this.methodsParams[e.method]),r||(this.methodSettingsDivs.forEach((t=>t.remove())),this.methodSettingsDivs=[]),await this.postProcessingEditor.onFunctionChanged(e.postProcessingFunctionArgs)}catch(e){t.shell.error("Error applying input from history"),console.error(e)}}}class Xn{constructor(t,n){this.preprocessingFuncSettingsDiv=e.div([]),this.preprocessingFunctionSettings={},this.editorDiv=e.div([]),this.hasExtraSettings=!0,this.functionsMap={},this.needsConfiguration=!1,this.weight=1,this.colOptEditors=[],this.weightInput=e.input.float("Weight",{value:1,onValueChanged:t=>{this.weight=t??1}}),this.column=t,this.supportedFunctions=n.sort(((t,e)=>0!==t.units.length&&0!==e.units.length||t.units.length===e.units.length?t.units.length!==e.units.length?t.units.length-e.units.length:0===t.semTypes.length||0===e.semTypes.length?e.semTypes.length-t.semTypes.length:t.semTypes.length!==e.semTypes.length?t.semTypes.length-e.semTypes.length:t.types.length-e.types.length:e.units.length-t.units.length)),this.supportedFunctions.forEach((t=>{this.functionsMap[Qn(t.func)]=t.func})),this.preprocessingFunctionInput=e.input.choice("Encoding function",{value:Qn(this.supportedFunctions[0].func),items:this.supportedFunctions.map((t=>Qn(t.func))),onValueChanged:t=>{const n=this.functionsMap[t];this.preprocessingFunctionSettings={},this.hasExtraSettings=n.inputs.length>2;const o=this.supportedFunctions.find((e=>Qn(e.func)===t));this.getSimilarityMetricInput(o),e.empty(this.preprocessingFuncSettingsDiv),r=!1,this.hasExtraSettings?this.preprocessingFuncSettingsIcon.style.display="flex":this.preprocessingFuncSettingsIcon.style.display="none"}}),this.preprocessingFunctionInput.root.style.display="flex",this.createSettingsDiv(this.preprocessingFuncSettingsDiv,this.supportedFunctions[0].func).then((()=>{e.empty(this.preprocessingFuncSettingsDiv)})),this.getSimilarityMetricInput(this.supportedFunctions[0]),this.hasExtraSettings=this.supportedFunctions[0].func.inputs.length>2;let r=!1;this.preprocessingFuncSettingsIcon=e.icons.settings((async()=>{r=!r,r?await this.createSettingsDiv(this.preprocessingFuncSettingsDiv,this.functionsMap[this.preprocessingFunctionInput.value]):e.empty(this.preprocessingFuncSettingsDiv)}),"Modify encoding function parameters"),this.preprocessingFunctionInput.root.classList.add("ml-dim-reduction-settings-input"),this.preprocessingFunctionInput.root.prepend(this.preprocessingFuncSettingsIcon),this.hasExtraSettings?this.preprocessingFuncSettingsIcon.style.display="flex":this.preprocessingFuncSettingsIcon.style.display="none",this.needsConfiguration=!(n.length<2&&!this.hasExtraSettings&&n[0].distanceFunctions.length<2);const o=e.h3(this.column.name,{classes:"ml-dim-reduction-column-editor-column-title"});this.colOptEditors=[o,this.preprocessingFunctionInput.root,this.similarityMetricInputRoot,this.weightInput.root],e.tooltip.bind(o,this.column.name),this.colOptEditors.forEach((t=>t.classList.add("ml-dim-reduction-column-editor-input-root")));const i=e.divH(this.colOptEditors,{classes:"ml-dim-reduction-column-editor-root"});this.accordionDiv=e.divV([]),this.editorDiv.appendChild(i),this.editorDiv.appendChild(this.preprocessingFuncSettingsDiv),this.accordionDiv.appendChild(this.editorDiv)}getSimilarityMetricInput(t){const n=e.input.choice("Similarity metric",{value:t.distanceFunctions[0],items:t.distanceFunctions});this.similarityMetricInputRoot?(e.empty(this.similarityMetricInputRoot),this.similarityMetricInput=n,Array.from(this.similarityMetricInput.root.children).forEach((t=>this.similarityMetricInputRoot.appendChild(t)))):(this.similarityMetricInputRoot=n.root,this.similarityMetricInput=n)}get preProcessingFunction(){return this.functionsMap[this.preprocessingFunctionInput.value]}async createSettingsDiv(t,n){if(e.empty(t),n.inputs.length<3)return e.div();const r=n.prepare(),o=await r.buildEditor(e.div());for(let e=2;e<n.inputs.length;e++){const i=n.inputs[e],a=this.preprocessingFunctionSettings[i.name]||r.inputParams[n.inputs[e].name].value||i.defaultValue;a&&(this.preprocessingFunctionSettings[i.name]=a);const s=o.find((t=>t.property.name===i.name));s&&(null!==this.preprocessingFunctionSettings[i.name]&&void 0!==this.preprocessingFunctionSettings[i.name]&&(s.value=this.preprocessingFunctionSettings[i.name]),s.onChanged.subscribe((t=>{this.preprocessingFunctionSettings[i.name]=t})),t.append(s.root))}return t.style.marginBottom="10px",t}}function Qn(t){return t.friendlyName??t.name}class Jn{constructor(){this.postProcessingFunctionsMap={},this._root=e.div([]),this._postProcessingArgs={},this._argsElement=e.div([]),this._settingsOpened=!1,this._prevChangePromise=Promise.resolve(),this._settingsIcon=e.icons.settings((async()=>{this._settingsOpened=!this._settingsOpened,this._settingsOpened?this._argsElement.style.display="block":this._argsElement.style.display="none"})),this._argsElement.style.display="none",o.Func.find({tags:["dim-red-postprocessing-function"]}).filter((t=>t.inputs.length>=2)).forEach((t=>{const e=t.friendlyName??t.name;this.postProcessingFunctionsMap[e]=t})),this.postProcessingFunctionsMap.None=null;const t=Object.keys(this.postProcessingFunctionsMap).find((t=>!!this.postProcessingFunctionsMap[t]?.options?.defaultPostProcessingFunction))??"None";this.postProcessingFunctionInput=e.input.choice("Postprocessing",{value:t,items:Object.keys(this.postProcessingFunctionsMap),onValueChanged:async()=>{await this.onFunctionChanged()},nullable:!1}),this.onFunctionChanged(),this.postProcessingFunctionInput.nullable=!1,this.postProcessingFunctionInput.classList.add("ml-dim-reduction-settings-input"),this.postProcessingFunctionInput.root.prepend(this._settingsIcon),this._root.appendChild(this.postProcessingFunctionInput.root),this._root.appendChild(this._argsElement)}get postProcessingFunction(){return this.postProcessingFunctionInput.value?this.postProcessingFunctionsMap[this.postProcessingFunctionInput.value]:null}async onFunctionChanged(n={}){let r;await this._prevChangePromise,this._prevChangePromise=new Promise((t=>r=t));try{const t=this.postProcessingFunction;if(e.empty(this._argsElement),this._postProcessingArgs={},!t||t.inputs.length<3)return void(this._settingsIcon.style.display="none");this._settingsIcon.style.display="flex";const r=t.prepare(n),o=await r.buildEditor(e.div());for(let e=2;e<t.inputs.length;e++){const n=t.inputs[e],i=this._postProcessingArgs[n.name]||r.inputParams[t.inputs[e].name].value||n.defaultValue;i&&(this._postProcessingArgs[n.name]=i);const a=o.find((t=>t.property.name===n.name));a&&(a.onChanged.subscribe((t=>{this._postProcessingArgs[n.name]=t})),this._argsElement.append(a.root))}}catch(e){t.shell.error("Error applying postprocessing function"),console.error(e)}finally{r()}}get root(){return this._root}get args(){return this._postProcessingArgs}}const Zn="dimensionality-reducer-terminate-event",tr=t=>null==t;function er(t,e){return`${e} (${t.length>4?`${t.length} columns`:t.map((t=>t.name)).join(", ")})`}var nr=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{u(r.next(t))}catch(t){i(t)}}function s(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,s)}u((r=r.apply(t,e||[])).next())}))};function rr(n){return nr(this,void 0,void 0,(function*(){if(null!=n||(n=t.shell.t),null===n)return void t.shell.warning(Be.NO_DATAFRAME);const r=[],i=[],a=[];n.columns.toList().filter((t=>He.includes(t.type))).forEach((t=>{const e=t.stats.missingValueCount;e!==t.length&&(a.push(t.name),e>0&&(r.push(t),i.push(t.name)))}));const s=function(t){const e=new Map;for(const n of t){if(!He.includes(n.type))throw new Error(Be.UNSUPPORTED_COLUMN_TYPE);if(0===n.stats.missingValueCount)continue;const t=[],r=$e(n);n.getRawData().forEach(((e,n)=>{e===r&&t.push(n)})),e.set(n.name,t)}return e}(r);if(0===r.length)return void t.shell.info(Be.NO_MISSING_VALUES);if(1===a.length)return void t.shell.error(Be.ONE_AVAILABLE_FEATURE);let u=Qe.IN_PLACE>0;const c=e.input.bool(je.IN_PLACE,{value:u,onValueChanged:t=>{u=null!=t&&t}});c.setTooltip(ze.IN_PLACE);let l=Qe.KEEP_EMPTY>0;const d=e.input.bool(je.KEEP_EMPTY,{value:l,onValueChanged:t=>{l=null!=t&&t}});d.setTooltip(ze.KEEP_EMPTY);let h=Qe.NEIGHBORS;const f=e.input.int(je.NEIGHBORS,{value:h,showPlusMinus:!0,min:Je,nullable:!1,onValueChanged:t=>{null!==t&&t>=Je&&(h=t),E()}});f.setTooltip(ze.NEIGHBORS);let p=Xe.EUCLIDEAN;const m=e.input.choice(je.DISTANCE,{value:p,items:[Xe.EUCLIDEAN,Xe.MANHATTAN],onValueChanged:t=>p=null!=t?t:Xe.EUCLIDEAN});m.setTooltip(ze.DISTANCE);let g=r.map((t=>t.name));const y=e.input.columns(je.COLUMNS,{table:n,value:n.columns.byNames(i),onValueChanged:t=>{g=t.map((t=>t.name)),E()},available:i});y.setTooltip(ze.TARGET);let v=a;const w=e.input.columns(je.FEATURES,{value:n.columns.byNames(a),table:n,onValueChanged:t=>{v=t.map((t=>t.name)),v.length>0?(E(),C.forEach(((t,e)=>t.hidden=!v.includes(e)))):b()},available:a});w.setTooltip(ze.FEATURES);const b=()=>{_.getButton(je.RUN).disabled=!0,c.root.hidden=!0,d.root.hidden=!0,f.root.hidden=!0,I.hidden=!0,S.hidden=!0},E=()=>{_.getButton(je.RUN).disabled=null===f.value||f.value<Je,I.hidden=!1,c.root.hidden=!1,f.root.hidden=!1,m.root.hidden=!1,d.root.hidden=!Ze(g,v,s),1===v.length&&g.forEach((e=>{v[0]===e&&(b(),t.shell.warning(`${Be.ONE_FEATURE_SELECTED} the column '${e}'`))})),g.length<1&&b()},A=new Map,C=new Map,S=e.divV([]);S.style.overflow="auto",a.forEach((t=>{const r=function(t){switch(t){case o.COLUMN_TYPE.STRING:case o.COLUMN_TYPE.DATE_TIME:return{defaultWeight:Qe.WEIGHT,defaultMetric:Ke.ONE_HOT,availableMetrics:[Ke.ONE_HOT]};case o.COLUMN_TYPE.INT:case o.COLUMN_TYPE.FLOAT:case o.COLUMN_TYPE.QNUM:return{defaultWeight:Qe.WEIGHT,defaultMetric:Ke.DIFFERENCE,availableMetrics:[Ke.DIFFERENCE,Ke.ONE_HOT]};default:throw new Error(Be.UNSUPPORTED_COLUMN_TYPE)}}(n.col(t).type);A.set(t,{weight:r.defaultWeight,type:r.defaultMetric});const i=e.input.choice(t,{value:r.defaultMetric,items:r.availableMetrics,onValueChanged:e=>{var n;const o=null!==(n=A.get(t))&&void 0!==n?n:{weight:r.defaultWeight,type:r.defaultMetric};o.type=null!=e?e:r.defaultMetric,A.set(t,o)}});i.root.style.width="50%",i.setTooltip(ze.METRIC),i.root.hidden=!0;const a=o.Property.fromOptions({name:t.length<qe?t:t.slice(0,qe).concat("..."),inputType:"Float",min:0,max:10,showSlider:!0,step:1}),s=e.input.forProperty(a);s.value=r.defaultWeight,s.onChanged.subscribe((e=>{var n;const o=null!==(n=A.get(t))&&void 0!==n?n:{weight:r.defaultWeight,type:r.defaultMetric};o.weight=null!=e?e:r.defaultWeight,A.set(t,o)})),e.tooltip.bind(s.captionLabel,t),e.tooltip.bind(s.input,ze.WEIGHT),C.set(t,s.root),S.append(s.root)}));const _=e.dialog({title:je.KNN_IMPUTER,helpUrl:Ye});t.shell.v.root.appendChild(_.root),S.hidden=!0,d.root.hidden=!Ze(g,v,s);const N=e.icons.settings((()=>{S.hidden=!S.hidden}),ze.METRIC_SETTINGS),I=e.divH([m.root,N]);let M,T,O=!1;const P=new Promise(((t,e)=>{M=t,T=e}));return _.addButton(je.RUN,(()=>{O=!0,_.close(),a.filter((t=>!v.includes(t))).forEach((t=>A.delete(t)));try{const e=function(e,n,r,i,a,s,u){if(s<Je)throw new Error(Be.INCORRECT_NEIGHBORS);if(e.rowCount<2)throw new Error(Be.KNN_NOT_ENOUGH_OF_ROWS);if(0===n.length)throw new Error(Be.KNN_NO_TARGET_COLUMNS);if(0===r.size)throw new Error(Be.KNN_NO_FEATURE_COLUMNS);1===r.size&&n.forEach((t=>{if(r.has(t))throw new Error(`${Be.KNN_NO_FEATURE_COLUMNS} can be used for the column '${t}'`)})),n.forEach((t=>{if(!i.has(t))throw new Error(`${Be.KNN_FAILS}: ${Be.WRONG_PREDICTIONS}`)}));const c=e.columns;n.forEach((t=>{if(!He.includes(c.byName(t).type))throw new Error(Be.UNSUPPORTED_COLUMN_TYPE)})),r.forEach(((t,n)=>{if(!He.includes(e.getCol(n).type))throw new Error(Be.UNSUPPORTED_COLUMN_TYPE)}));const l=new Map;return n.forEach((n=>{const d=c.byName(n),h=$e(d),f=d.length,p=d.getRawData(),m=new Uint16Array(d.categories.length),g=[],y=[],v=[],w=[];r.forEach(((t,e)=>{if(e!==d.name){const n=c.byName(e);switch(g.push(n.getRawData()),y.push($e(n)),t.type){case Ke.DIFFERENCE:v.push(((e,n)=>t.weight*Math.abs(e-n)));break;case Ke.ONE_HOT:v.push(((e,n)=>t.weight*(e===n?0:1)))}}}));const b=g.length,E=new Uint32Array(g.length),A=new Float32Array(g.length);let C=0;const S=new Array(s);let _=0,N=0,I=0,M=0,T=0;const O=(t,e)=>{E.forEach(((n,r)=>{A[r]=v[n](g[n][t],g[n][e])}))},P=a===Xe.EUCLIDEAN?()=>{let t=0;for(let e=0;e<C;++e)t+=A[e]*A[e];return Math.sqrt(t)}:()=>{let t=0;for(let e=0;e<C;++e)t+=Math.abs(A[e]);return Math.sqrt(t)},L=t=>{if(p[t]===h)return!1;for(let e=0;e<C;++e)if(g[E[e]][t]===y[E[e]])return!1;return!0},x=t=>{if((t=>{C=0;for(let e=0;e<b;++e)g[e][t]!==y[e]&&(E[C]=e,++C)})(t),0===C)throw new Error(`${Be.KNN_IMPOSSIBLE_IMPUTATION}: the column "${d.name}", row ${t+1}`);_=0;for(let e=0;e<f;++e)if(L(e)&&e!==t){O(t,e);const n=P();if(_<s)S[_]={index:e,dist:n},++_;else{N=0,I=S[0].dist;for(let t=1;t<_;++t)I<S[t].dist&&(I=S[t].dist,N=t);n<I&&(S[N]={index:e,dist:n})}}if(0===_)throw new Error(`${Be.KNN_IMPOSSIBLE_IMPUTATION}: the column "${d.name}", row ${t+1}`);if(d.type===o.COLUMN_TYPE.STRING)return(()=>{m.forEach(((t,e,n)=>n[e]=0));let t=0;for(t=0;t<_;++t)++m[p[S[t].index]];let e=m[0],n=0;return m.forEach(((t,r)=>{t>e&&(e=t,n=r)})),n})();M=0;for(let t=0;t<_;++t)M+=p[S[t].index];return T=M/_,d.type===o.COLUMN_TYPE.INT?Math.round(T):T};if(u){for(const e of i.get(n))try{p[e]=x(e)}catch(n){w.push(e),n instanceof Error||t.shell.error(Be.CORE_ISSUE)}w.length>0&&l.set(n,w),d.set(0,d.get(0))}else{const r=d.clone();let o=1,a=`${n}(${We})`;for(;e.columns.contains(a);)a=`${n}(${We} ${o})`,++o;r.name=a;const s=r.getRawData();for(const e of i.get(n))try{s[e]=x(e)}catch(n){w.push(e),n instanceof Error||t.shell.error(Be.CORE_ISSUE)}w.length>0&&l.set(a,w),r.set(0,r.get(0)),e.columns.add(r)}})),l}(n,g,A,s,p,h,u);l||function(t,e){e.forEach(((e,n)=>{const r=t.col(n);if(null!==r){if(!He.includes(r.type))throw new Error(Be.UNSUPPORTED_COLUMN_TYPE);const t=function(t){switch(t.type){case o.COLUMN_TYPE.STRING:case o.COLUMN_TYPE.DATE_TIME:return function(t){const e=$e(t),n=t.getRawData(),r=n.length;for(let o=0;o<r;++o)if(n[o]!==e)return t.get(o);throw new Error(Be.EMPTY_COLUMN)}(t);case o.COLUMN_TYPE.INT:case o.COLUMN_TYPE.FLOAT:case o.COLUMN_TYPE.QNUM:return t.stats.avg;default:throw new Error(Be.UNSUPPORTED_COLUMN_TYPE)}}(r);e.forEach((e=>r.set(e,t)))}}))}(n,e),M()}catch(e){e instanceof Error?t.shell.error(`${Be.KNN_FAILS}: ${e.message}`):t.shell.error(`${Be.KNN_FAILS}: ${Be.CORE_ISSUE}`),T(e)}}),void 0,ze.RUN),_.add(y).add(w).add(I).add(S).add(f).add(c).add(d).show().onClose.subscribe((()=>!O&&M())),P}))}class or extends Kn{constructor(t={}){super(t),this.similarityThresholdInput=e.input.int("Similarity Threshold",{value:80}),this.maxIterationsInput=e.input.int("Max Iterations",{value:5}),this.useWebGPUInput=e.input.bool("Use WebGPU",{value:!1}),this.inflateInput=e.input.float("Inflation Factor",{value:Nn}),this.minClusterSizeInput=e.input.int("Min Cluster Size",{value:5}),mn().then((t=>{t?(this.useWebGPUInput.setTooltip(`Use webGPU for MCL calculation (${t})`),this.useWebGPUInput.value=!0):(this.useWebGPUInput.value=!1,this.useWebGPUInput.setTooltip("WebGPU is not available"),this.useWebGPUInput.enabled=!1)}))}getEditor(){return e.div([this.tableInput.root,this.columnsInputRoot,this.columnParamsEditorRoot,this.aggregationMethodInput.root,this.similarityThresholdInput.root,this.inflateInput.root,this.maxIterationsInput.root,this.minClusterSizeInput.root,this.useWebGPUInput.root],{style:{minWidth:"420px"},classes:"ui-form"})}getInput(){const t=super.getInput();return t.similarityThreshold=this.similarityThresholdInput.value,t.maxIterations=this.maxIterationsInput.value,t.useWebGPU=this.useWebGPUInput.value??!1,t.inflateFactor=this.inflateInput.value??Nn,t.minClusterSize=this.minClusterSizeInput.value??5,t}async applyInput(t){await super.applyInput(t),this.similarityThresholdInput.value=t.similarityThreshold,this.maxIterationsInput.value=t.maxIterations,this.useWebGPUInput.value=t.useWebGPU,this.inflateInput.value=t.inflateFactor,this.minClusterSizeInput.value=t.minClusterSize}get params(){return{table:this.tableInput.value,columns:this.columnsInput.value,methodName:this.methodInput.value,preprocessingFunctions:this.columnOptEditors.map((t=>t.preProcessingFunction)),distanceMetrics:this.columnOptEditors.map((t=>t.similarityMetricInput.value)),weights:this.columnOptEditors.map((t=>t.weight)),preprocessingFuncArgs:this.columnOptEditors.map((t=>t.preprocessingFunctionSettings)),aggreaggregationMethod:this.aggregationMethodInput.value,threshold:this.similarityThresholdInput.value,maxIterations:this.maxIterationsInput.value??5,useWebGPU:this.useWebGPUInput.value??!1,inflateFactor:this.inflateInput.value??Nn,minClusterSize:this.minClusterSizeInput.value??5}}}class ir{constructor(t,e,n,r,i,a){this.sc=t,this.from=e,this.to=n,this.shortLineThreshold=r,this.width=i,this.color=a,this.renderFlag=!1,this.renderSub=o.debounce(t.onAfterDrawScene,200).subscribe((()=>{if(this.renderFlag)return void(this.renderFlag=!1);this.renderFlag=!0;const e=t.onBeforeDrawScene.subscribe((t=>{this.render(),e.unsubscribe()}));setTimeout((()=>{this.sc.invalidateCanvas()}))})),t.subs.push(this.renderSub)}render(){const t=this.sc.dataFrame.getCol(this.sc.props.xColumnName),e=this.sc.dataFrame.getCol(this.sc.props.yColumnName),n=this.sc.filter,r=new Array(this.sc.dataFrame.rowCount).fill(null).map(((r,o)=>t.isNone(o)||e.isNone(o)||!n.get(o)?null:this.sc.pointToScreen(o))),o=this.sc.canvas.getContext("2d");if(!o)return;o.strokeStyle=`rgba(${this.color}, 0.3)`,o.lineWidth=this.width;const i=this.shortLineThreshold*this.shortLineThreshold;for(let t=0;t<this.from.length;t++){o.beginPath();const e=this.from[t],n=this.to[t];if(r[e]&&r[n]){const t=r[e],a=r[n],s=a.x-t.x,u=a.y-t.y;if(s*s+u*u<i)continue;o.moveTo(t.x,t.y),o.lineTo(a.x,a.y),o.stroke(),o.closePath()}}}destroy(){this.renderSub.unsubscribe()}}class ar extends o.JsViewer{constructor(){super(),this.initPromise=Promise.resolve(),this.initialized=!1,this.reseolver=()=>{},this.scratchCallTimer=null,this.mclProps=this.string("mclProps",null,{includeInLayout:!1,userEditable:!1,nullable:!0}),this.lines=this.string("lines",null,{includeInLayout:!1,userEditable:!1,nullable:!0}),this.scProps=this.string("scProps",null,{includeInLayout:!1,userEditable:!1,nullable:!0}),this.initPromise=new Promise((t=>{this.reseolver=t}))}onFrameAttached(e){if(e.rowCount>65535)throw new Error("MCL viewer supports only dataframes with less than 65535 rows");this.sc=e.plot.scatter({showXAxis:!1,showYAxis:!1,showXSelector:!1,showYSelector:!1,title:"MCL"}),this.root.appendChild(this.sc.root),this.subs.push(t.events.onCurrentObjectChanged.subscribe((e=>{this.sc&&t.shell.o===this&&setTimeout((()=>{t.shell.o=this.sc}))}))),this.subs.push(o.debounce(this.sc.onPropertyValueChanged,1e3).subscribe((t=>{this.sc&&this.getProperty("scProps").set(this,JSON.stringify(Object.assign({},this.sc.props)))})))}setScProps(){if(!this.sc)return;const t=this.scProps;if(!t)return;const e=this.sc.props;if(t===JSON.stringify(Object.assign({},e)))return;const n=JSON.parse(t);Object.entries(n).forEach((([t,n])=>{e.hasProperty(t)&&e[t]!==n&&(this.sc.props[t]=n)}))}onPropertyChanged(t){null!==t&&("scProps"===t.name?this.setScProps():"lines"===t.name?this.decodeLines():"mclProps"===t.name&&(this.scratchCallTimer&&clearTimeout(this.scratchCallTimer),this.scratchCallTimer=setTimeout((()=>{this.initFromScratch()}),300)))}async initFromScratch(){if(!this.mclProps||!this.sc||!this.dataFrame||this.initialized)return;if(this.lines)return void this.decodeLines();const r=JSON.parse(this.mclProps),i=r.cols.map((t=>this.dataFrame.columns.byName(t))),a=r.preprocessingFuncs.map((t=>t?o.Func.byName(t):null)),s=await async function(r,i,a,s,u,c,l,d=80,h=10,f=!1,p=2,m=5,g){let y=null,v=g;v||(y=t.shell.tableView(r.name)??t.shell.addTableView(r),v=y.scatterPlot({showXAxis:!1,showYAxis:!1,showXSelector:!1,showYSelector:!1,title:"MCL"})),e.setUpdateIndicator(v.root,!0);const w=[],b=[];for(let t=0;t<c.length;++t){const e=c[t];if(e){const n=e.inputs[0].name,r=e.inputs[1].name,{entries:o,options:s}=await e.apply({[n]:i[t],[r]:a[t],...l[t]??{}});b.push({entries:o,options:s}),w.push(s??{})}else{const e=i[t].toList(),n={};b.push({entries:e,options:n}),w.push(n)}}const E=function(t,e,r,o,i,a,s=10,u=!1,c=2){const l=new Worker(new URL(n.p+n.u(980),n.b));let d;return l.postMessage({data:t,threshold:e,weights:r,aggregationMethod:o,distanceFns:i,distanceFnArgs:a,maxIterations:s,useWebGPU:u,inflate:c}),{promise:new Promise(((t,e)=>{d=t,l.onmessage=e=>{setTimeout((()=>l.terminate()),100),t(e.data.res)},l.onerror=t=>{setTimeout((()=>l.terminate()),100),e(t)}})),terminate:()=>{try{d(null),l.terminate()}catch(t){console.error(t)}}}}(b.map((t=>t.entries)),d,s,u,a,w,h,f,p),A=t.events.onViewerClosed.subscribe((t=>{t.args.viewer?.props?.title===v.props.title&&v.type===t.args?.viewer?.type&&(A.unsubscribe(),E.terminate())})),C=await E.promise;if(!C)return;const S=r.columns.getUnusedName("Cluster (MCL)"),_=r.columns.getUnusedName("EmbedX (MCL)"),N=r.columns.getUnusedName("EmbedY (MCL)"),I={};C.clusters.forEach((t=>{I[t]||(I[t]=0),I[t]++}));const M=new Uint32Array(C.embedX.length);for(let t=0;t<C.is.length;t++)M[C.is[t]]++,M[C.js[t]]++;const T=r.columns.getUnusedName("Cluster size (MCL)"),O=r.columns.getUnusedName("Connectivity (MCL)"),P=r.columns.addNewFloat(_);P.init((t=>C.embedX[t]));const L=r.columns.addNewFloat(N);L.init((t=>C.embedY[t]));const x=r.columns.addNewString(S);x.init((t=>I[C.clusters[t]]>=m?C.clusters[t].toString():"-1"));const F={"-1":o.Color.setAlpha(o.Color.lightBlue,100)};x.setTag(o.TAGS.COLOR_CODING_CATEGORICAL,JSON.stringify(F)),x.temp[o.TAGS.COLOR_CODING_CATEGORICAL]=F;const R=r.columns.addNewInt(T);R.init((t=>I[C.clusters[t]]));const D=r.columns.addNewInt(O);D.init((t=>M[t])),v.props.xColumnName=_,v.props.yColumnName=N,v.props.colorColumnName=S,v.props.markerDefaultSize=6,A.unsubscribe();const U=[],k=[],G=new Map;for(let t=0;t<C.is.length;t++){let e=C.clusters[C.is[t]],n=C.clusters[C.js[t]];if(e===n){U.push(C.is[t]),k.push(C.js[t]);continue}if(e>n){const t=e;e=n,n=t}let r=G.get(e);r||(r=new Map,G.set(e,r));let o=r.get(n);o||(o=0),o>=20||(o++,r.set(n,o),U.push(C.is[t]),k.push(C.js[t]))}return e.setUpdateIndicator(v.root,!1),{sc:v,embedXCol:P,embedYCol:L,clusterCol:x,clusterCounterCol:R,connectivityCol:D,i:U,j:k}}(this.dataFrame,i,r.metrics,r.weights,r.aggregationMethod,a,r.preprocessingFuncArgs,r.threshold,r.maxIterations,r.useWebGPU,r.inflate,r.minClusterSize,this.sc);return s?this.dataFrame.getTag(".script")?(this.linesRenderer?.destroy(),this.linesRenderer=new ir(this.sc,s.i,s.j,6,.75,"128,128,128"),this.initialized=!0,void this.reseolver()):void this.encodeLines(s.i,s.j):void 0}decodeLines(){if(!this.lines)return;const t=this.lines.length;if(t%2!=0)throw new Error("Invalid lines string");const e=new Array(t/2).fill(null).map(((t,e)=>this.lines.charCodeAt(2*e))),n=new Array(t/2).fill(null).map(((t,e)=>this.lines.charCodeAt(2*e+1)));this.linesRenderer?.destroy(),this.linesRenderer=new ir(this.sc,e,n,6,.75,"128,128,128"),this.initialized=!0,this.reseolver()}encodeLines(t,e){const n=new Array(t.length).fill(null).map(((n,r)=>`${String.fromCharCode(t[r])}${String.fromCharCode(e[r])}`)).join("");this.getProperty("lines").set(this,n)}}var sr=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{u(r.next(t))}catch(t){i(t)}}function s(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,s)}u((r=r.apply(t,e||[])).next())}))};function ur(t,e){const n=t.length;if(n!==e.length-1)throw new Error("Incorrect parameters count");const r=t.byIndex(0),i=r.length,a=new Float32Array(i);let s=r.getRawData();const u=e[n];let c=e[0];for(let t=0;t<i;++t)a[t]=u+c*s[t];for(let r=1;r<n;++r){s=t.byIndex(r).getRawData(),c=e[r];for(let t=0;t<i;++t)a[t]+=c*s[t]}return o.Column.fromFloat32Array(t.getUnusedName("prediction"),a,i)}const cr=(t,e)=>e<=t?Math.min(10,e):Math.min(10,t);var lr;!function(t){t[t.MAX_SAMLPES=1e5]="MAX_SAMLPES",t[t.MAX_FEATURES=1e3]="MAX_FEATURES"}(lr||(lr={}));class dr{static isApplicable(t,e){for(const e of t)if(!e.matches("numerical"))return!1;return!!e.matches("numerical")}static isInteractive(t,e){return t.length<=lr.MAX_FEATURES&&e.length<=lr.MAX_SAMLPES}constructor(t){if(this.specn=null,t)try{const e=new Uint32Array(t.buffer,0,2),n=e[0],r=e[1],i=new Uint8Array(t.buffer,8,n),a=o.DataFrame.fromByteArray(i),s=a.rowCount,u=a.columns,c=u.length,l=new Uint8Array(t.buffer,8+n,r),d=o.DataFrame.fromByteArray(l);if(c<3)throw new Error("incorrect columns count");const h=u.byName(ve.FEATURES).toList(),f=new Float32Array(s);f.set(u.byName(ve.REGR_COEFS).getRawData());const p=c-2,m=new Array(p);for(let t=0;t<p;++t)m[t]=new Float32Array(s),m[t].set(u.byIndex(t+2).getRawData());this.specn={params:f,loadings:m,names:h,dim:s-1,components:c-2,scores:d}}catch(t){throw new Error(`Failed to load model: ${t instanceof Error?t.message:"the platform issue"}`)}}fit(t,e,n){return r=this,i=void 0,s=function*(){const r=yield ke({table:o.DataFrame.fromColumns([e]),features:t,predict:e,components:n,names:void 0}),i=t.names();i.push("_");const a=this.getRegrCoeffs(t,e,r.regressionCoefficients),s=this.getLoadings(n,r.xLoadings);this.specn={names:i,params:a,loadings:s,components:n,dim:t.length,scores:this.getScoresDf(r)},this.computeExplVars(e.length,n,r.yLoadings)},new((a=void 0)||(a=Promise))((function(t,e){function n(t){try{u(s.next(t))}catch(t){e(t)}}function o(t){try{u(s.throw(t))}catch(t){e(t)}}function u(e){var r;e.done?t(e.value):(r=e.value,r instanceof a?r:new a((function(t){t(r)}))).then(n,o)}u((s=s.apply(r,i||[])).next())}));var r,i,a,s}getLoadings(t,e){const n=Array(t),r=e[0].length+1;for(let o=0;o<t;++o)n[o]=new Float32Array(r),n[o].set(e[o].getRawData());return n}getRegrCoeffs(t,e,n){const r=t.length,o=new Float32Array(r+1),i=n.getRawData();let a=0;for(let e=0;e<r;++e)o[e]=i[e],a+=i[e]*t.byIndex(e).stats.avg;return o[r]=e.stats.avg-a,o}computeExplVars(t,e,n){if(null===this.specn)throw new Error("Failed to compute explained variances");const r=n.getRawData(),o=this.specn.loadings[0].length-1;let i=Math.pow(r[0],2)/t;this.specn.loadings[0][o]=i;for(let n=1;n<e;++n)i+=Math.pow(r[n],2)/t,this.specn.loadings[n][o]=i}toBytes(){if(null===this.specn)throw new Error("Failed to pack untrained model");const t=o.DataFrame.fromColumns([o.Column.fromStrings(ve.FEATURES,this.specn.names),o.Column.fromFloat32Array(ve.REGR_COEFS,this.specn.params)]);this.specn.loadings.forEach(((e,n)=>t.columns.add(o.Column.fromFloat32Array(`${ve.XLOADING}${n+1}`,e))));const e=t.toByteArray(),n=e.length,r=this.specn.scores.toByteArray(),i=r.length,a=n+i+8,s=new Uint8Array(64*(Math.ceil(a/64)+1)),u=new Uint32Array(s.buffer,0,2);return u[0]=n,u[1]=i,s.set(e,8),s.set(r,8+n),s}predict(t){if(null===this.specn)throw new Error("Predicting failed: model is not trained");return ur(t,this.specn.params)}loadingsParamsViewers(){if(null===this.specn)throw new Error("Failed to create loadings and parameters viewers: untrained model");const t=[],e=this.specn.dim,n=o.DataFrame.fromColumns([o.Column.fromStrings(ve.FEATURES,this.specn.names.slice(0,-1)),o.Column.fromFloat32Array(ve.REGR_COEFS,this.specn.params,e)]),r=n.columns,i=r.length,a=this.specn.components;return this.specn.loadings.forEach(((t,r)=>n.columns.add(o.Column.fromFloat32Array(`${ve.XLOADING}${r+1}`,t,e)))),t.push(o.Viewer.scatterPlot(n,{title:ve.LOADINGS,xColumnName:r.byIndex(i).name,yColumnName:r.byIndex(i+(a>1?1:0)).name,markerType:o.MARKER_TYPE.CIRCLE,labelFormColumnNames:[ve.FEATURES],help:be.LOADINGS})),t.push(o.Viewer.barChart(n,{title:ve.REGR_COEFS,splitColumnName:ve.FEATURES,valueColumnName:ve.REGR_COEFS,valueAggrType:o.AGG.AVG,help:be.COEFFS,showValueSelector:!1,showStackSelector:!1})),t}explVarsViewer(){if(null===this.specn)throw new Error("Failed to create exaplained variances viewer: untrained model");const t=this.specn.components,e=this.specn.dim,n=new Array(t),r=new Float32Array(t);n[0]=`${Ae.COMP} 1`,r[0]=this.specn.loadings[0][e];for(let o=1;o<t;++o)n[o]=`${Ae.COMPS} ${o+1}`,r[o]=this.specn.loadings[o][e];return o.Viewer.barChart(o.DataFrame.fromColumns([o.Column.fromStrings(Ae.COMPS,n),o.Column.fromFloat32Array(ve.EXPL_VAR,r)]),{title:ve.EXPL_VAR,splitColumnName:Ae.COMPS,valueColumnName:ve.EXPL_VAR,valueAggrType:o.AGG.AVG,help:be.EXPL_VARS,showCategorySelector:!1,showStackSelector:!1,showValueSelector:!1})}viewers(){if(null===this.specn)throw new Error("Failed to create viewers: untrained model");const t=this.loadingsParamsViewers();return t.push(this.explVarsViewer(),this.getScoresScatter()),t}getScoresDf(t){const e=t.tScores,n=t.uScores;return e.forEach(((t,e)=>t.name=`${ve.XSCORE}${e+1}`)),n.forEach(((t,e)=>t.name=`${ve.YSCORE}${e+1}`)),o.DataFrame.fromColumns(e.concat(n))}getScoresScatter(){if(null===this.specn)throw new Error("Failed to create scores scatter: untrained model");const t=this.specn.scores.columns.names(),e=o.Viewer.scatterPlot(this.specn.scores,{title:ve.SCORES,xColumnName:t[0],yColumnName:t[1],markerType:o.MARKER_TYPE.CIRCLE,help:be.SCORES,showViewerFormulaLines:!0});return e.meta.formulaLines.addAll(Ue(t)),e}}var hr=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{u(r.next(t))}catch(t){i(t)}}function s(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,s)}u((r=r.apply(t,e||[])).next())}))};const fr="Avg-s",pr="Stddev-s";var mr;!function(t){t[t.MAX_SAMLPES=5e4]="MAX_SAMLPES",t[t.MAX_FEATURES=100]="MAX_FEATURES"}(mr||(mr={}));class gr{static isApplicable(t,e){for(const e of t)if(!e.matches("numerical"))return!1;return e.type===o.COLUMN_TYPE.STRING}static isInteractive(t,e){return t.length<=mr.MAX_FEATURES&&e.length<=mr.MAX_SAMLPES}constructor(t,e){if(this.params=void 0,this.classesCount=1,this.featuresCount=1,void 0!==t){const e=t.featuresCount,n=t.classesCount;if(e<1)throw new Error("Incorrect features count");if(n<1)throw new Error("Incorrect classes count");const r=e+1;this.avgs=new Float32Array(r),this.stdevs=new Float32Array(r),this.categories=new Array(r),this.featuresCount=e,this.classesCount=n}else{if(void 0===e)throw new Error("Softmax classifier not initialized");try{const t=new Uint32Array(e.buffer,0,1)[0],n=new Uint8Array(e.buffer,4,t),r=o.DataFrame.fromByteArray(n),i=r.columns,a=i.length;if(a<3)throw new Error("incorrect columns count");this.classesCount=a-2,this.featuresCount=r.rowCount-1;const s=this.classesCount;this.params=new Array(s),this.categories=new Array(r.rowCount);for(let t=0;t<s;++t){const e=i.byIndex(t);if(this.categories[t]=e.name,e.type!==o.COLUMN_TYPE.FLOAT)throw new Error(`Incorrect input column type. Expected: float, passed: ${e.type}`);this.params[t]=e.getRawData()}const u=i.byName(fr);if(u.type!==o.COLUMN_TYPE.FLOAT)throw new Error("incorrect average values column type");this.avgs=u.getRawData();const c=i.byName(pr);if(c.type!==o.COLUMN_TYPE.FLOAT)throw new Error("incorrect standard deviations column type");this.stdevs=c.getRawData()}catch(t){throw new Error(`Failed to load model: ${t instanceof Error?t.message:"the platform issue"}`)}}}toBytes(){if(void 0===this.params)throw new Error("Non-trained model");const t=this.classesCount,e=new Array(t+2);for(let n=0;n<t;++n)e[n]=o.Column.fromFloat32Array(this.categories[n],this.params[n]);e[t]=o.Column.fromFloat32Array(fr,this.avgs),e[t+1]=o.Column.fromFloat32Array(pr,this.stdevs);const n=o.DataFrame.fromColumns(e).toByteArray(),r=n.length,i=new Uint8Array(r+4);return new Uint32Array(i.buffer,0,1)[0]=r,i.set(n,4),i}fit(t,e){return hr(this,arguments,void 0,(function*(t,e,n=1,r=100,i=.1,a=.001){if(t.length!==this.featuresCount)throw new Error("Training failes - incorrect features count");if(n<=0||r<1||i<=0||a<=0)throw new Error("Training failes - incorrect fitting hyperparameters");this.extractStats(t);const s=e.length,u=e.categories.length,c=e.categories;for(let t=0;t<u;++t)this.categories[t]=c[t];try{const c=function(t,e,n,r,o,i,a,s,u,c,l){return g(EDA,"fitSoftmax",[t,e,n,r,o,i,a,s,u,c,l])}(t,o.Column.fromFloat32Array("avgs",this.avgs,this.featuresCount),o.Column.fromFloat32Array("stdevs",this.stdevs,this.featuresCount),o.Column.fromInt32Array("targets",e.getRawData(),s),u,r,n,i,a,this.featuresCount+1,u).columns;this.params=new Array(u);for(let t=0;t<u;++t)this.params[t]=c.byIndex(t).getRawData()}catch(o){try{this.params=yield this.fitSoftmaxParams(t,e,r,n,i,a)}catch(t){throw new Error("Training failes")}}if(void 0===this.params)throw new Error("Training failes")}))}extractStats(t){let e=0;for(const n of t){if(n.type!==o.COLUMN_TYPE.INT&&n.type!==o.COLUMN_TYPE.FLOAT)throw new Error("Training failes - incorrect features type");this.avgs[e]=n.stats.avg,this.stdevs[e]=n.stats.stdev,++e}}normalized(t){const e=t.byIndex(0).length,n=new Array(e);for(let t=0;t<e;++t)n[t]=new Float32Array(this.featuresCount);let r=0;for(const i of t){if(i.type!==o.COLUMN_TYPE.INT&&i.type!==o.COLUMN_TYPE.FLOAT)throw new Error("Training failes - incorrect features type");const t=i.getRawData(),a=this.avgs[r],s=this.stdevs[r];if(s>0)for(let o=0;o<e;++o)n[o][r]=(t[o]-a)/s;else for(let t=0;t<e;++t)n[t][r]=0;++r}return n}transposed(t){const e=t.byIndex(0).length,n=this.featuresCount,r=new Array(n);for(let t=0;t<n;++t)r[t]=new Float32Array(e);let i=0;for(const n of t){if(n.type!==o.COLUMN_TYPE.INT&&n.type!==o.COLUMN_TYPE.FLOAT)throw new Error("Training failes - incorrect features type");const t=n.getRawData(),a=this.avgs[i],s=this.stdevs[i];if(s>0)for(let n=0;n<e;++n)r[i][n]=(t[n]-a)/s;else for(let t=0;t<e;++t)r[i][t]=0;++i}return r}preprocessedTargets(t){if(t.type!==o.COLUMN_TYPE.STRING)throw new Error("Training failes - incorrect target type");const e=this.classesCount,n=t.length,r=t.getRawData(),i=new Array(n),a=new Uint32Array(e).fill(0);for(let t=0;t<n;++t)i[t]=new Uint8Array(e).fill(0);for(let t=0;t<n;++t)i[t][r[t]]=1,++a[r[t]];return{oneHot:i,weights:a}}predict(t){if(void 0===this.params)throw new Error("Non-trained model");if(t.length!==this.featuresCount)throw new Error("Predcition fails: incorrect features count");const e=this.normalized(t),n=e.length,r=this.featuresCount,i=this.classesCount;let a,s;const u=new Float32Array(i);let c,l,d;const h=new Array(n);for(let t=0;t<n;++t){a=e[t],c=0;for(let t=0;t<i;++t){s=this.params[t],c=s[r];for(let t=0;t<r;++t)c+=s[t]*a[t];u[t]=Math.exp(c)}l=u[0],d=0;for(let t=1;t<i;++t)l<u[t]&&(l=u[t],d=t);h[t]=this.categories[d]}return o.Column.fromStrings("predicted",h)}fitSoftmaxParams(t,e,r,o,i,a){return hr(this,void 0,void 0,(function*(){const s=this.preprocessedTargets(e);return new Promise(((u,c)=>{const l=new Worker(new URL(n.p+n.u(501),n.b));l.postMessage({features:this.normalized(t),transposed:this.transposed(t),oneHot:s.oneHot,classesWeights:s.weights,targetRaw:e.getRawData(),iterations:r,rate:o,penalty:i,tolerance:a}),l.onmessage=function(t){l.terminate(),u(t.data.params),console.log(`Loss: ${t.data.loss}`)}}))}))}}var yr,vr,wr;!function(t){t[t.ITERATIONS=20]="ITERATIONS",t[t.ETA=.3]="ETA",t[t.MAX_DEPTH=6]="MAX_DEPTH",t[t.LAMBDA=1]="LAMBDA",t[t.ALPHA=0]="ALPHA"}(yr||(yr={})),function(t){t[t.SAMLPES_HIGH=1e5]="SAMLPES_HIGH",t[t.SAMLPES_MID=5e4]="SAMLPES_MID",t[t.SAMPLES_LOW=1e4]="SAMPLES_LOW",t[t.FEATURES_HIGH=10]="FEATURES_HIGH",t[t.FEATURES_MID=20]="FEATURES_MID",t[t.FEATURES_LOW=100]="FEATURES_LOW"}(vr||(vr={})),function(t){t[t.MODEL=1e7]="MODEL",t[t.UTILS=1]="UTILS",t[t.PACK=128]="PACK",t[t.SIZE=4]="SIZE"}(wr||(wr={}));const br=o.FLOAT_NULL;var Er;!function(t){t.PREDICT="Prediction",t.TYPE="Type",t.PARAMS="Params count",t.CATS="Categories",t.CATS_SIZE="Categories size"}(Er||(Er={}));class Ar{static isApplicable(t,e){for(const e of t)if(!e.matches("numerical"))return!1;return!(!e.matches("numerical")&&!e.matches("string"))}static isInteractive(t,e){const n=t.length,r=e.length;return r<=vr.SAMPLES_LOW?n<=vr.FEATURES_LOW:r<=vr.SAMLPES_MID?n<=vr.FEATURES_MID:r<=vr.SAMLPES_HIGH&&n<=vr.FEATURES_HIGH}constructor(t){var e;if(this.modelParams=void 0,this.targetType=void 0,this.targetCategories=void 0,t)try{let n=0;const r=new Uint32Array(t.buffer,n,1)[0];n+=wr.SIZE;const i=o.DataFrame.fromByteArray(new Uint8Array(t.buffer,n,r));n+=r,this.targetType=i.get(Er.TYPE,0);const a=i.get(Er.PARAMS,0),s=i.get(Er.CATS_SIZE,0);if(s>0){const r=o.DataFrame.fromByteArray(new Uint8Array(t.buffer,n,s));this.targetCategories=null===(e=r.col(Er.CATS))||void 0===e?void 0:e.toList()}n+=s,n=4*Math.ceil(n/4),this.modelParams=new Int32Array(t.buffer,n,a)}catch(t){throw new Error(`Failed to load model: ${t instanceof Error?t.message:"the platform issue"}`)}}fit(t,e){return r=this,i=arguments,s=function*(t,e,r=yr.ITERATIONS,i=yr.ETA,a=yr.MAX_DEPTH,s=yr.LAMBDA,u=yr.ALPHA){this.targetType=e.type,this.targetType===o.COLUMN_TYPE.STRING&&(this.targetCategories=e.categories),this.modelParams=yield async function(t,e,r,o,i,a,s,u,c,l){return new Promise(((d,h)=>{const f=e.length,p=t.length,m=new Float32Array(f*p);let g,y;for(let e=0;e<p;++e){y=t.byIndex(e).getRawData(),g=e*f;for(let t=0;t<f;++t)m[t+g]=y[t]}const v=new Worker(new URL(n.p+n.u(990),n.b));v.postMessage({features:m,target:e.getRawData(),samplesCount:f,featuresCount:p,modelReserve:c,utilsLength:l,iterations:o,eta:i,maxDepth:a,lambda:s,alpha:u,missingValue:r}),v.onmessage=function(t){v.terminate(),d(t.data.params)}}))}(t,e,br,r,i,a,s,u,wr.MODEL,wr.UTILS)},new((a=void 0)||(a=Promise))((function(t,e){function n(t){try{u(s.next(t))}catch(t){e(t)}}function o(t){try{u(s.throw(t))}catch(t){e(t)}}function u(e){var r;e.done?t(e.value):(r=e.value,r instanceof a?r:new a((function(t){t(r)}))).then(n,o)}u((s=s.apply(r,i||[])).next())}));var r,i,a,s}predict(t){if(void 0===this.modelParams)throw new Error("Failed to apply non-trained model");const e=function(t,e,n){const r=t.byIndex(0).length,o=t.length,i=n.length;let a=XGBoostModule.HEAPF32;const s=XGBoostModule.HEAP32,u=XGBoostModule._malloc(r*o*4),c=XGBoostModule._malloc(4*r),l=XGBoostModule._malloc(4*i);for(let e=0;e<o;++e){const n=t.byIndex(e).getRawData();for(let t=0;t<r;++t)a[u/4+t+e*r]=n[t]}for(let t=0;t<i;++t)s[l/4+t]=n[t];XGBoostModule._predict(u,r,o,e,l,i,c,r),a=XGBoostModule.HEAPF32;const d=new Float32Array(r);for(let t=0;t<r;++t)d[t]=a[c/4+t];return XGBoostModule._free(u),XGBoostModule._free(c),XGBoostModule._free(l),d}(t,br,this.modelParams);switch(this.targetType){case o.COLUMN_TYPE.STRING:return this.stringColPrediction(e);case o.COLUMN_TYPE.INT:return this.intColPrediction(e);case o.COLUMN_TYPE.BIG_INT:return this.bigIntColPrediction(e);default:return o.Column.fromFloat32Array(Er.PREDICT,e)}}toBytes(){if(void 0===this.modelParams||void 0===this.targetType)throw new Error("Failed to pack non-trained model");const t=void 0!==this.targetCategories?o.DataFrame.fromColumns([o.Column.fromList(o.COLUMN_TYPE.STRING,Er.CATS,this.targetCategories)]).toByteArray():void 0,e=void 0!==t?t.length:0,n=this.modelParams.length*this.modelParams.BYTES_PER_ELEMENT,r=o.DataFrame.fromColumns([o.Column.fromStrings(Er.TYPE,[this.targetType]),o.Column.fromInt32Array(Er.PARAMS,new Int32Array([this.modelParams.length])),o.Column.fromInt32Array(Er.CATS_SIZE,new Int32Array([e]))]).toByteArray(),i=r.length,a=64*Math.ceil((wr.SIZE+i+e+n+wr.PACK)/64),s=new Uint8Array(a);let u=0;return new Uint32Array(s.buffer,u,1)[0]=i,u+=wr.SIZE,s.set(r,u),u+=i,e>0&&s.set(t,u),u+=e,u=4*Math.ceil(u/4),s.set(new Uint8Array(this.modelParams.buffer),u),s}stringColPrediction(t){const e=t.length;if(void 0===this.targetCategories)throw new Error("Predicting fails: undefined categories");const n=new Array(e),r=this.targetCategories.length-1;for(let o=0;o<e;++o)n[o]=this.targetCategories[(i=Math.round(t[o]),Math.max(0,Math.min(i,r)))];var i;return o.Column.fromList(o.COLUMN_TYPE.STRING,Er.PREDICT,n)}intColPrediction(t){const e=t.length,n=new Int32Array(e);for(let r=0;r<e;++r)n[r]=Math.round(t[r]);return o.Column.fromInt32Array(Er.PREDICT,n,e)}bigIntColPrediction(t){const e=t.length,n=new BigInt64Array(e);for(let r=0;r<e;++r)n[r]=BigInt(Math.round(t[r]));return o.Column.fromBigInt64Array(Er.PREDICT,n)}}var Cr=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{u(r.next(t))}catch(t){i(t)}}function s(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,s)}u((r=r.apply(t,e||[])).next())}))};const Sr=new o.Package;function _r(){t.shell.info(Sr.webRoot)}function Nr(){return Cr(this,void 0,void 0,(function*(){yield async function(){await initEDA()}(),yield async function(){await initXGBoostModule()}()}))}function Ir(t,e,n,r,i){return Cr(this,void 0,void 0,(function*(){const a=e.getRawData(),s=n.getRawData(),u=yield fn(a,s,r,i),c=t.columns.getUnusedName("Cluster (DBSCAN)"),l=o.Column.fromInt32Array(c,u);return t.columns.add(l),l}))}function Mr(e,r,i,a,s){return Cr(this,void 0,void 0,(function*(){try{const u=yield function(t,e,r,i,a){return J(this,void 0,void 0,(function*(){X(e,r);const s=t.rowCount,u=function(t){const e=[];for(const n of t)n.stats.stdev>0&&n.stats.missingValueCount<1&&e.push(n);return o.DataFrame.fromColumns(e)}(e),c=u.columns.length;if(0===c){const t=[];for(let e=0;e<r;++e)t.push(o.Column.fromFloat32Array(`${e+1}`,new Float32Array(s).fill(0)));return o.DataFrame.fromColumns(t)}const l=c<r?r-c:0,d=Math.min(r,c);let h;if(c>W)h=yield G(0,e,d);else{const t=yield async function(t,e,r){return new Promise(((t,o)=>{const i=new Worker(new URL(n.p+n.u(860),n.b));i.postMessage(U(EDA.principalComponentAnalysis.arguments,[e,r,1,0])),i.onmessage=function(e){i.terminate(),0===e.data.callResult?t(k(EDA.principalComponentAnalysis,e.data)):t(-1)}}))}(0,e,d);h=-1!==t?Q(t,i,a):yield G(0,e,d)}if(void 0===h)throw new Error("Failed to compute PCA");h=Q(h,i,a);const f=h.columns,p=f.length;for(let t=0;t<l;++t)f.add(o.Column.fromFloat32Array(`${p+t+1}`,new Float32Array(s).fill(0)));return h}))}(e,r,i,a,s);if(function(t,e){for(const t of e.toList())t.name="PC"+t.name}(0,u.columns),null===e.id)t.shell.addTableView(u);else{const t=e.columns;for(const e of u.columns)e.name=t.getUnusedName(e.name),t.add(e)}}catch(e){t.shell.warning(`Failed to compute PCA: ${e instanceof Error?e.message:"platform issue"}`)}}))}function Tr(e,n,r,i){return Cr(this,void 0,void 0,(function*(){const a=e.dataFrame;if(null===a)return;const s=yield Ir(a,e,n,r,i);a.changeColumnType(s,"string");const u=[e.name,n.name],c=t.shell.tableView(a.name);if(c)for(const t of c.viewers)if(t instanceof o.ScatterPlotViewer&&u.includes(t.props.xColumnName)&&u.includes(t.props.yColumnName))return void(t.props.colorColumnName=s.name)}))}function Or(t,e){const n=t.stats.max-t.stats.min;return{entries:t.toList(),options:{range:n}}}function Pr(t,e){return{entries:t.toList(),options:{}}}function Lr(){return Cr(this,void 0,void 0,(function*(){const r=new Kn,i=e.dialog("Dimensionality reduction").add(r.getEditor()).onOK((()=>Cr(this,void 0,void 0,(function*(){const i=r.getParams();0!==i.columns.length&&(yield async function(r,i,a,s,u,c,l,d=!0,h=!1,f={preprocessingFuncArgs:[]},p={},m=null,g={}){const y={showXAxis:!1,showYAxis:!1,showXSelector:!1,showYSelector:!1};if(i.length!==s.length||i.length!==c.length||i.length!==u.length||i.length!==f.preprocessingFuncArgs.length)throw new Error("columns, metrics and preprocessing functions, weights and function argumentsmust have the same length");const v=d?p.tableView??t.shell.tableView(r.name)??t.shell.addTableView(r):null,w=async()=>{const w=o.TaskBarProgressIndicator.create(`Initializing ${p.scatterPlotName??"dimensionality reduction"} ...`);let b;try{const E=function(t){const e=["Embed_X","Embed_Y"],n=t.columns.names().filter((t=>t.includes(e[0]))).length+1;return e.map((t=>`${t}_${n}`))}(r);function A(t,n,s){let u=null,c=null;r.columns.names().includes(E[0])?(u=r.columns.byName(E[0]),c=r.columns.byName(E[1])):(u=r.columns.add(o.Column.float(E[0],r.rowCount)),c=r.columns.add(o.Column.float(E[1],r.rowCount)),d&&!b&&(b=v.scatterPlot({...y,x:E[0],y:E[1],title:p.scatterPlotName??er(i,a)}))),p[Tn]&&(b?.root&&e.setUpdateIndicator(b.root,!1),u.init((t=>s[0]?s[0][t]:void 0)),c.init((t=>s[1]?s[1][t]:void 0)));const l=t/n*100;w.update(l,`Running ${p.scatterPlotName??"dimensionality reduction"}... ${l.toFixed(0)}%`)}async function C(){r.columns.add(o.Column.float(E[0],r.rowCount)),r.columns.add(o.Column.float(E[1],r.rowCount));let h=null;d&&(b=v.scatterPlot({...y,x:E[0],y:E[1],title:p.scatterPlotName??er(i,a)}),e.setUpdateIndicator(b.root,!0));const m=t.events.onViewerClosed.subscribe((e=>{const n=e.args.viewer;n?.getOptions()?.look?.title&&b?.getOptions()?.look?.title&&n?.getOptions()?.look?.title===b?.getOptions()?.look?.title&&(t.events.fireCustomEvent(Zn,{}),m.unsubscribe(),h?.(),w.close())})),g=new Promise((async(e,r)=>{try{h=e;const r=[];for(let t=0;t<c.length;++t){const e=c[t];if(f.distanceFnArgs||(f.distanceFnArgs=[]),e){const n=e.inputs[0].name,o=e.inputs[1].name,{entries:a,options:u}=await e.apply({[n]:i[t],[o]:s[t],...f.preprocessingFuncArgs[t]??{}});r.push({entries:a,options:u}),f.distanceFnArgs.push(u)}else{const e=i[t].toList(),n={};r.push({entries:e,options:n}),f.distanceFnArgs.push(n)}}e(await async function(e,r,o,i,a,s,u){let c=await async function(e,r,o,i,a,s,u){if(!s.distanceFnArgs)throw new Error("options.distanceFnArgs must be defined");if(e.length!==r.length||e.length!==s.distanceFnArgs.length||e.length!==i.length)throw new Error("data, metrics and options and weights must have the same length");return new Promise((function(c,l){const d=new Worker(new URL(n.p+n.u(234),n.b));d.postMessage({columnsData:e,distanceMetrics:r,method:o,options:s,weights:i,aggregationMethod:a});const h=t.events.onCustomEvent(Zn).subscribe((()=>{try{d?.terminate()}finally{h.unsubscribe()}}));d.onmessage=({data:{error:t,embedding:e,epochNum:n,epochsLength:r}})=>{tr(n)||tr(r)?(h.unsubscribe(),t?l(t):c(e),setTimeout((()=>d.terminate()),100)):u&&u(n,r,e)}}))}(e,o,r,i,a,s,u);return c=c.map((t=>function(t){const e=t.length;let n=0,r=0;for(let o=0;o<e;++o)n+=t[o],r+=Math.pow(t[o],2);const o=n/e,i=1/Math.sqrt(r/e-Math.pow(o,2));for(let n=0;n<e;++n)t[n]=(t[n]-o)*i;return t}(t))),c}(r.map((t=>t.entries)),a,s,u,l,f,p[Mn]?void 0:A))}catch(t){r(t)}})),C=await g;return w.close(),m.unsubscribe(),C}const S=await C();if(h&&S){const _=o.TaskBarProgressIndicator.create("Clustering embeddings ...");try{const N=await fn(S[0],S[1],f.dbScanEpsilon??.01,f.dbScanMinPts??4),I=r.columns.getUnusedName("Cluster (DBSCAN)");r.columns.addNewString(I).init((t=>N[t].toString())),b&&(b.props.colorColumnName=I)}catch(M){t.shell.error("Clustering embeddings failed"),console.error(M)}finally{_.close()}}if(S){const T=r.columns.byName(E[0]),O=r.columns.byName(E[1]);if(T.init((t=>S[0][t])),O.init((t=>S[1][t])),m)try{const P=m.inputs[0].name,L=m.inputs[1].name;await m.prepare({[P]:T,[L]:O,...g}).call(!0)}catch(x){t.shell.error("Post-processing failed"),console.error(x)}if(b)return e.setUpdateIndicator(b.root,!1),b.helpUrl="/help/compute/sequence-space",b}}catch(F){t.shell.error("Dimensionality reduction failed"),console.error(F),w.close(),b&&e.setUpdateIndicator(b.root,!1)}};return new Promise((async(t,n)=>{try{if(p.fastRowCount&&r.rowCount>p.fastRowCount&&!p[Mn])e.dialog().add(e.divText("Analysis might take several minutes. Do you want to continue?")).onOK((async()=>{try{const e=await w();t(e)}catch(t){n(t)}})).onCancel((()=>t(void 0))).show();else{const e=await w();t(e)}}catch(t){n(t)}}))}(i.table,i.columns,i.methodName,i.distanceMetrics,i.weights,i.preprocessingFunctions,i.aggreaggregationMethod,!!i.plotEmbeddings,!!i.clusterEmbeddings,i.options,{fastRowCount:1e4},i.postProcessingFunction,i.postProcessingFunctionArgs))})))).show();i.helpUrl="https://datagrok.ai/help/explore/dim-reduction.md";const a=()=>{const t=r.columnsInput.value,e=i.getButton("OK");e&&(t&&0!==t.length?e.classList.remove("disabled"):e.classList.add("disabled"))};i.history((()=>({editorSettings:r.getStringInput()})),(t=>r.applyStringInput(t.editorSettings))),r.onColumnsChanged.subscribe((()=>{try{a()}catch(t){console.error(t)}})),a()}))}function xr(n){try{const t=new or;e.dialog("Markov clustering").add(t.getEditor()).onOK((()=>Cr(this,void 0,void 0,(function*(){const e=t.params;return n.func.prepare({df:e.table,cols:e.columns,metrics:e.distanceMetrics,weights:e.weights,aggregationMethod:e.aggreaggregationMethod,preprocessingFuncs:e.preprocessingFunctions,preprocessingFuncArgs:e.preprocessingFuncArgs,threshold:e.threshold,maxIterations:e.maxIterations,useWebGPU:e.useWebGPU,inflate:e.inflateFactor,minClusterSize:e.minClusterSize}).call(!0)})))).show().history((()=>({editorSettings:t.getStringInput()})),(e=>t.applyStringInput(e.editorSettings)))}catch(e){const n=e instanceof Error?e.message:e.toString(),r=e instanceof Error?e.stack:void 0;t.shell.error(`Get region editor error: ${n}`),Sr.logger.error(n,void 0,r)}}function Fr(e,n,r,o,i,a,s){return Cr(this,arguments,void 0,(function*(e,n,r,o,i,a,s,u=80,c=10,l=!1,d=0,h=5){var f;const p=null!==(f=t.shell.tableView(e.name))&&void 0!==f?f:t.shell.addTableView(e),m=JSON.stringify({cols:n.map((t=>t.name)),metrics:r,weights:o,aggregationMethod:i,preprocessingFuncs:a.map((t=>{var e;return null!==(e=null==t?void 0:t.name)&&void 0!==e?e:null})),preprocessingFuncArgs:s,threshold:u,maxIterations:c,useWebGPU:l,inflate:d,minClusterSize:null!=h?h:5});return p.addViewer("MCL",{mclProps:m})}))}function Rr(){return new ar}function Dr(t,e,n,r,o){return Cr(this,void 0,void 0,(function*(){return yield ke({table:t,features:e,predict:n,components:r,names:o})}))}function Ur(){return Cr(this,void 0,void 0,(function*(){yield Ge(ge.COMPUTE_COMPONENTS)}))}function kr(){return Cr(this,void 0,void 0,(function*(){yield Ge(ge.PERFORM_MVA)}))}function Gr(){return Cr(this,void 0,void 0,(function*(){yield function(){return Fe(this,void 0,void 0,(function*(){t.shell.addTableView(o.DataFrame.fromColumns([o.Column.fromStrings("model",["alfaromeo","audi","bmw","chevrolet","dodge1","dodge2","honda1","honda2","isuzu","jaguar","mazda","mercedes","mercury","mitsubishi","nissan1","nissan2","peugot","plymouth","porsche","saab","subaru","toyota1","toyota2","toyota3","toyota4","volkswagen1","volkswagen2","volvo1","volvo2","volvo3"]),o.Column.fromInt32Array("diesel",new Int32Array([0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,1,0,1,1,0,0,0,1])),o.Column.fromInt32Array("turbo",new Int32Array([0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,1,1])),o.Column.fromInt32Array("two.doors",new Int32Array([1,0,1,0,1,0,1,0,0,0,0,0,1,1,0,1,0,0,1,0,0,1,0,1,0,1,0,0,0,0])),o.Column.fromInt32Array("hatchback",new Int32Array([1,0,0,0,1,1,1,0,0,0,0,0,1,1,0,0,1,0,0,0,0,1,0,1,0,0,0,0,0,0])),o.Column.fromFloat32Array("wheel.base",new Float32Array([94.5,105.80000305175781,101.19999694824219,94.5,93.69999694824219,93.69999694824219,93.69999694824219,96.5,94.30000305175781,113,93.0999984741211,115.5999984741211,102.69999694824219,93.69999694824219,94.5,94.5,93.69999694824219,114.19999694824219,89.5,99.0999984741211,97.19999694824219,95.69999694824219,95.69999694824219,98.4000015258789,102.4000015258789,97.30000305175781,100.4000015258789,104.30000305175781,109.0999984741211,109.0999984741211])),o.Column.fromFloat32Array("length",new Float32Array([171.1999969482422,192.6999969482422,176.8000030517578,158.8000030517578,157.3000030517578,157.3000030517578,150,175.39999389648438,170.6999969482422,199.60000610351562,166.8000030517578,202.60000610351562,178.39999389648438,157.3000030517578,170.1999969482422,165.3000030517578,157.3000030517578,198.89999389648438,168.89999389648438,186.60000610351562,172,158.6999969482422,166.3000030517578,176.1999969482422,175.60000610351562,171.6999969482422,180.1999969482422,188.8000030517578,188.8000030517578,188.8000030517578])),o.Column.fromFloat32Array("width",new Float32Array([65.5,71.4000015258789,64.80000305175781,63.599998474121094,63.79999923706055,63.79999923706055,64,65.19999694824219,61.79999923706055,69.5999984741211,64.19999694824219,71.69999694824219,68,64.4000015258789,63.79999923706055,63.79999923706055,63.79999923706055,68.4000015258789,65,66.5,65.4000015258789,63.599998474121094,64.4000015258789,65.5999984741211,66.5,65.5,66.9000015258789,67.19999694824219,68.80000305175781,68.9000015258789])),o.Column.fromFloat32Array("height",new Float32Array([52.400001525878906,55.70000076293945,54.29999923706055,52,50.79999923706055,50.599998474121094,52.599998474121094,54.099998474121094,53.5,52.79999923706055,54.099998474121094,56.29999923706055,54.79999923706055,50.79999923706055,53.5,54.5,50.599998474121094,58.70000076293945,51.599998474121094,56.099998474121094,52.5,54.5,53,52,54.900001525878906,55.70000076293945,55.099998474121094,56.20000076293945,55.5,55.5])),o.Column.fromInt32Array("curb.weight",new Int32Array([2823,2844,2395,1909,2128,1967,1956,2304,2337,4066,1950,3770,2910,1918,2024,1951,1967,3430,2800,2695,2190,1985,2275,2551,2480,2261,2661,2912,3049,3217])),o.Column.fromInt32Array("eng.size",new Int32Array([152,136,108,90,98,90,92,110,111,258,91,183,140,92,97,97,90,152,194,121,108,92,110,146,110,97,136,141,141,145])),o.Column.fromInt32Array("horsepower",new Int32Array([154,110,101,70,102,68,76,86,78,176,68,123,175,68,69,69,68,95,207,110,82,62,56,116,73,52,110,114,160,106])),o.Column.fromInt32Array("peak.rpm",new Int32Array([5e3,5500,5800,5400,5500,5500,6e3,5800,4800,4750,5e3,4350,5e3,5500,5200,5200,5500,4150,5900,5250,4400,4800,4500,4800,4500,4800,5500,5400,5300,4800])),o.Column.fromInt32Array("symbol",new Int32Array([1,1,2,0,1,1,1,0,0,0,1,-1,1,2,1,1,1,0,3,2,0,1,0,2,-1,2,0,-2,-1,-1])),o.Column.fromInt32Array("city.mpg",new Int32Array([19,19,23,38,24,31,30,27,24,15,31,22,19,37,31,31,31,25,17,21,28,35,34,24,30,37,19,23,19,26])),o.Column.fromInt32Array("highway.mpg",new Int32Array([26,25,29,43,30,38,34,33,29,19,38,25,24,41,37,37,38,25,25,28,33,39,36,30,33,46,24,28,25,27])),o.Column.fromInt32Array("price",new Int32Array([16500,17710,16430,6575,7957,6229,7129,8845,6785,35550,7395,31600,16503,5389,7349,7299,6229,13860,37028,12170,7775,5348,7898,9989,10698,7775,13295,12940,19045,22470]))])),t.shell.windows.help.visible=!0,t.shell.windows.help.showHelp(e.markdown(Pe)),t.shell.windows.showContextPanel=!1,t.shell.windows.showProperties=!1,yield Ge(ge.DEMO)}))}()}))}function Br(t,e,n){return Cr(this,void 0,void 0,(function*(){return de(yield ce({gamma:n,kernel:tt},t,e))}))}function Vr(t,e){return Cr(this,void 0,void 0,(function*(){return yield fe(t,e)}))}function Wr(t,e){return Cr(this,void 0,void 0,(function*(){return pe(t,e)}))}function jr(t,e){return Cr(this,void 0,void 0,(function*(){return me(t)}))}function Yr(t,e,n,r){return Cr(this,void 0,void 0,(function*(){return le(0,r)}))}function zr(t,e,n,r){return Cr(this,void 0,void 0,(function*(){return de(yield ce({gamma:n,kernel:nt,sigma:r},t,e))}))}function qr(t,e){return Cr(this,void 0,void 0,(function*(){return yield fe(t,e)}))}function Hr(t,e){return Cr(this,void 0,void 0,(function*(){return pe(t,e)}))}function $r(t,e){return Cr(this,void 0,void 0,(function*(){return me(t)}))}function Kr(t,e,n,r){return Cr(this,void 0,void 0,(function*(){return le(0,r)}))}function Xr(t,e,n,r,o){return Cr(this,void 0,void 0,(function*(){return de(yield ce({gamma:n,kernel:et,cParam:r,dParam:o},t,e))}))}function Qr(t,e){return Cr(this,void 0,void 0,(function*(){return yield fe(t,e)}))}function Jr(t,e){return Cr(this,void 0,void 0,(function*(){return pe(t,e)}))}function Zr(t,e){return Cr(this,void 0,void 0,(function*(){return me(t)}))}function to(t,e,n,r){return Cr(this,void 0,void 0,(function*(){return le(0,r)}))}function eo(t,e,n,r,o){return Cr(this,void 0,void 0,(function*(){return de(yield ce({gamma:n,kernel:rt,kappa:r,theta:o},t,e))}))}function no(t,e){return Cr(this,void 0,void 0,(function*(){return yield fe(t,e)}))}function ro(t,e){return Cr(this,void 0,void 0,(function*(){return pe(t,e)}))}function oo(t,e){return Cr(this,void 0,void 0,(function*(){return me(t)}))}function io(t,e,n,r){return Cr(this,void 0,void 0,(function*(){return le(0,r)}))}function ao(){dn()}function so(){rr()}function uo(t){return Cr(this,void 0,void 0,(function*(){yield rr(t)}))}function co(t,e){return Cr(this,void 0,void 0,(function*(){const n=t.columns,r=yield function(t,e){return sr(this,void 0,void 0,(function*(){const n=t.length,r=e.length,i=e.stats.avg,a=e.stats.stdev,s=new Float32Array(n+1).fill(0);if(s[n]=i,0===a||1===r)return s;try{const r=[],u=[],c=new Float32Array(n),l=new Float32Array(n);let d=0,h=0;for(const e of t){const t=e.stats;t.stdev>0&&(r.push(d),u.push(e),c[h]=t.avg,l[h]=t.stdev,++h),++d}if(0===h)return s;const f=function(t,e,n,r,o,i,a){return g(EDA,"fitLinearRegressionParamsWithDataNormalizing",[t,e,n,r,o,i,a])}(o.DataFrame.fromColumns(u).columns,o.Column.fromFloat32Array("xAvgs",c,h),o.Column.fromFloat32Array("xStdevs",l,h),e,i,a,h+1).getRawData();for(let t=0;t<h;++t)s[r[t]]=f[t];s[n]=f[h]}catch(r){const i=yield function(t,e,n){return sr(this,void 0,void 0,(function*(){return(yield ke({table:o.DataFrame.fromColumns([e]),features:t,predict:e,components:n,names:void 0})).regressionCoefficients.getRawData()}))}(t,e,cr(t.length,e.length));let a=0;for(let e=0;e<n;++e)s[e]=i[e],a+=i[e]*t.byIndex(e).stats.avg;s[n]-=a}return s}))}(n,e);return new Uint8Array(r.buffer)}))}function lo(t,e){const n=t.columns,r=new Float32Array(e.buffer);return o.DataFrame.fromColumns([ur(n,r)])}function ho(t,e){for(const e of t.columns)if(!e.matches("numerical"))return!1;return e.matches("numerical")}function fo(t,e){return t.rowCount<=1e5}function po(t,e,n,r,o,i){return Cr(this,void 0,void 0,(function*(){const a=t.columns,s=new gr({classesCount:e.categories.length,featuresCount:a.length});return yield s.fit(a,e,n,r,o,i),s.toBytes()}))}function mo(t,e){const n=t.columns,r=new gr(void 0,e);return o.DataFrame.fromColumns([r.predict(n)])}function go(t,e){return gr.isApplicable(t.columns,e)}function yo(t,e){return gr.isInteractive(t.columns,e)}function vo(t,e,n){return Cr(this,void 0,void 0,(function*(){const r=t.columns,o=new dr;return yield o.fit(r,e,Math.min(n,r.length)),o.toBytes()}))}function wo(t,e){const n=new dr(e);return o.DataFrame.fromColumns([n.predict(t.columns)])}function bo(t,e){return dr.isApplicable(t.columns,e)}function Eo(t,e,n,r){return Cr(this,void 0,void 0,(function*(){return new dr(r).viewers().map((t=>t.root))}))}function Ao(t,e){return dr.isInteractive(t.columns,e)}function Co(t,e,n,r,o,i,a){return Cr(this,void 0,void 0,(function*(){const s=t.columns,u=new Ar;return yield u.fit(s,e,n,r,o,i,a),u.toBytes()}))}function So(t,e){const n=new Ar(e);return o.DataFrame.fromColumns([n.predict(t.columns)])}function _o(t,e){return Ar.isInteractive(t.columns,e)}function No(t,e){return Ar.isApplicable(t.columns,e)}})(),eda=r})();
|
|
1
|
+
var eda;(()=>{var t={5540:(t,e,n)=>{"use strict";t=n.hmd(t);var r,o=(r="undefined"!=typeof document&&document.currentScript?document.currentScript.src:void 0,function(t={}){var e,n,o=void 0!==t?t:{};o.ready=new Promise((function(t,r){e=t,n=r}));var i,a=Object.assign({},o),s="object"==typeof window,u="function"==typeof importScripts,c=("object"==typeof process&&"object"==typeof process.versions&&process.versions.node,"");(s||u)&&(u?c=self.location.href:"undefined"!=typeof document&&document.currentScript&&(c=document.currentScript.src),r&&(c=r),c=0!==c.indexOf("blob:")?c.substr(0,c.replace(/[?#].*/,"").lastIndexOf("/")+1):"",u&&(i=t=>{var e=new XMLHttpRequest;return e.open("GET",t,!1),e.responseType="arraybuffer",e.send(null),new Uint8Array(e.response)})),o.print||console.log.bind(console);var l,d,h=o.printErr||console.warn.bind(console);Object.assign(o,a),a=null,o.arguments&&o.arguments,o.thisProgram&&o.thisProgram,o.quit&&o.quit,o.wasmBinary&&(l=o.wasmBinary),o.noExitRuntime,"object"!=typeof WebAssembly&&S("no native wasm support detected");var f,p,m,g=!1;function y(){var t=d.buffer;o.HEAP8=f=new Int8Array(t),o.HEAP16=new Int16Array(t),o.HEAP32=new Int32Array(t),o.HEAPU8=p=new Uint8Array(t),o.HEAPU16=new Uint16Array(t),o.HEAPU32=m=new Uint32Array(t),o.HEAPF32=new Float32Array(t),o.HEAPF64=new Float64Array(t)}var v=[],w=[],b=[],E=0,A=null,C=null;function S(t){o.onAbort&&o.onAbort(t),h(t="Aborted("+t+")"),g=!0,t+=". Build with -sASSERTIONS for more info.";var e=new WebAssembly.RuntimeError(t);throw n(e),e}var _,N;function I(t){return t.startsWith("data:application/octet-stream;base64,")}function M(t){try{if(t==_&&l)return new Uint8Array(l);if(i)return i(t);throw"both async and sync fetching of the wasm failed"}catch(t){S(t)}}function T(t,e,n){return function(t){return l||!s&&!u||"function"!=typeof fetch?Promise.resolve().then((function(){return M(t)})):fetch(t,{credentials:"same-origin"}).then((function(e){if(!e.ok)throw"failed to load wasm binary file at '"+t+"'";return e.arrayBuffer()})).catch((function(){return M(t)}))}(t).then((function(t){return WebAssembly.instantiate(t,e)})).then((function(t){return t})).then(n,(function(t){h("failed to asynchronously prepare wasm: "+t),S(t)}))}function O(t){for(;t.length>0;)t.shift()(o)}function P(t){this.excPtr=t,this.ptr=t-24,this.set_type=function(t){m[this.ptr+4>>2]=t},this.get_type=function(){return m[this.ptr+4>>2]},this.set_destructor=function(t){m[this.ptr+8>>2]=t},this.get_destructor=function(){return m[this.ptr+8>>2]},this.set_caught=function(t){t=t?1:0,f[this.ptr+12|0]=t},this.get_caught=function(){return 0!=f[this.ptr+12|0]},this.set_rethrown=function(t){t=t?1:0,f[this.ptr+13|0]=t},this.get_rethrown=function(){return 0!=f[this.ptr+13|0]},this.init=function(t,e){this.set_adjusted_ptr(0),this.set_type(t),this.set_destructor(e)},this.set_adjusted_ptr=function(t){m[this.ptr+16>>2]=t},this.get_adjusted_ptr=function(){return m[this.ptr+16>>2]},this.get_exception_ptr=function(){if(V(this.get_type()))return m[this.excPtr>>2];var t=this.get_adjusted_ptr();return 0!==t?t:this.excPtr}}function L(t){var e=d.buffer;try{return d.grow(t-e.byteLength+65535>>>16),y(),1}catch(t){}}function x(t){return o["_"+t]}I(_="wasmDbscan.wasm")||(N=_,_=o.locateFile?o.locateFile(N,c):c+N);var F="undefined"!=typeof TextDecoder?new TextDecoder("utf8"):void 0;function R(t,e,n,r,o){var i={string:t=>{var e=0;return null!=t&&0!==t&&(e=function(t){var e=function(t){for(var e=0,n=0;n<t.length;++n){var r=t.charCodeAt(n);r<=127?e++:r<=2047?e+=2:r>=55296&&r<=57343?(e+=4,++n):e+=3}return e}(t)+1,n=B(e);return function(t,e,n){!function(t,e,n,r){if(!(r>0))return 0;for(var o=n+r-1,i=0;i<t.length;++i){var a=t.charCodeAt(i);if(a>=55296&&a<=57343&&(a=65536+((1023&a)<<10)|1023&t.charCodeAt(++i)),a<=127){if(n>=o)break;e[n++]=a}else if(a<=2047){if(n+1>=o)break;e[n++]=192|a>>6,e[n++]=128|63&a}else if(a<=65535){if(n+2>=o)break;e[n++]=224|a>>12,e[n++]=128|a>>6&63,e[n++]=128|63&a}else{if(n+3>=o)break;e[n++]=240|a>>18,e[n++]=128|a>>12&63,e[n++]=128|a>>6&63,e[n++]=128|63&a}}e[n]=0}(t,p,e,n)}(t,n,e),n}(t)),e},array:t=>{var e,n,r=B(t.length);return e=t,n=r,f.set(e,n),r}},a=x(t),s=[],u=0;if(r)for(var c=0;c<r.length;c++){var l=i[n[c]];l?(0===u&&(u=k()),s[c]=l(r[c])):s[c]=r[c]}var d=a.apply(null,s);return function(t){return 0!==u&&G(u),function(t){return"string"===e?(n=t)?function(t,e,n){for(var r=e+n,o=e;t[o]&&!(o>=r);)++o;if(o-e>16&&t.buffer&&F)return F.decode(t.subarray(e,o));for(var i="";e<o;){var a=t[e++];if(128&a){var s=63&t[e++];if(192!=(224&a)){var u=63&t[e++];if((a=224==(240&a)?(15&a)<<12|s<<6|u:(7&a)<<18|s<<12|u<<6|63&t[e++])<65536)i+=String.fromCharCode(a);else{var c=a-65536;i+=String.fromCharCode(55296|c>>10,56320|1023&c)}}else i+=String.fromCharCode((31&a)<<6|s)}else i+=String.fromCharCode(a)}return i}(p,n,r):"":"boolean"===e?Boolean(t):t;var n,r}(t)}(d)}var D,U={__cxa_throw:function(t,e,n){throw new P(t).init(e,n),t},abort:function(){S("")},emscripten_memcpy_big:function(t,e,n){p.copyWithin(t,e,e+n)},emscripten_resize_heap:function(t){var e,n=p.length,r=2147483648;if((t>>>=0)>r)return!1;for(var o=1;o<=4;o*=2){var i=n*(1+.2/o);if(i=Math.min(i,t+100663296),L(Math.min(r,(e=Math.max(t,i))+(65536-e%65536)%65536)))return!0}return!1}},k=(function(){var t,e,r,i,a={env:U,wasi_snapshot_preview1:U};function s(t,e){var n,r=t.exports;return o.asm=r,d=o.asm.memory,y(),o.asm.__indirect_function_table,n=o.asm.__wasm_call_ctors,w.unshift(n),function(){if(E--,o.monitorRunDependencies&&o.monitorRunDependencies(E),0==E&&(null!==A&&(clearInterval(A),A=null),C)){var t=C;C=null,t()}}(),r}if(E++,o.monitorRunDependencies&&o.monitorRunDependencies(E),o.instantiateWasm)try{return o.instantiateWasm(a,s)}catch(t){h("Module.instantiateWasm callback failed with error: "+t),n(t)}(t=l,e=_,r=a,i=function(t){s(t.instance)},t||"function"!=typeof WebAssembly.instantiateStreaming||I(e)||"function"!=typeof fetch?T(e,r,i):fetch(e,{credentials:"same-origin"}).then((function(t){return WebAssembly.instantiateStreaming(t,r).then(i,(function(t){return h("wasm streaming compile failed: "+t),h("falling back to ArrayBuffer instantiation"),T(e,r,i)}))}))).catch(n)}(),o._dbscan=function(){return(o._dbscan=o.asm.dbscan).apply(null,arguments)},o._malloc=function(){return(o._malloc=o.asm.malloc).apply(null,arguments)},o._free=function(){return(o._free=o.asm.free).apply(null,arguments)},function(){return(k=o.asm.stackSave).apply(null,arguments)}),G=function(){return(G=o.asm.stackRestore).apply(null,arguments)},B=function(){return(B=o.asm.stackAlloc).apply(null,arguments)},V=function(){return(V=o.asm.__cxa_is_pointer_type).apply(null,arguments)};function W(){function t(){D||(D=!0,o.calledRun=!0,g||(O(w),e(o),o.onRuntimeInitialized&&o.onRuntimeInitialized(),function(){if(o.postRun)for("function"==typeof o.postRun&&(o.postRun=[o.postRun]);o.postRun.length;)t=o.postRun.shift(),b.unshift(t);var t;O(b)}()))}E>0||(function(){if(o.preRun)for("function"==typeof o.preRun&&(o.preRun=[o.preRun]);o.preRun.length;)t=o.preRun.shift(),v.unshift(t);var t;O(v)}(),E>0||(o.setStatus?(o.setStatus("Running..."),setTimeout((function(){setTimeout((function(){o.setStatus("")}),1),t()}),1)):t()))}if(o.ccall=R,o.cwrap=function(t,e,n,r){var o=!n||n.every((t=>"number"===t||"boolean"===t));return"string"!==e&&o&&!r?x(t):function(){return R(t,e,n,arguments)}},C=function t(){D||W(),D||(C=t)},o.preInit)for("function"==typeof o.preInit&&(o.preInit=[o.preInit]);o.preInit.length>0;)o.preInit.pop()();return W(),t.ready});"object"==typeof exports?t.exports=o:"function"==typeof define&&n.amdO?define([],(function(){return o})):"object"==typeof exports&&(exports.exportCppDbscanLib=o)},7939:(t,e,n)=>{"use strict";n.d(e,{A:()=>s});var r=n(1354),o=n.n(r),i=n(6314),a=n.n(i)()(o());a.push([t.id,".scatter_plot_link {\n right: 10px;\n}\n\n.cliffs_div {\n flex-grow: initial!important;\n justify-content: flex-end;\n flex-wrap: wrap;\n}\n\n.cliffs_grid {\n margin: 0!important;\n}\n\n.ml-dim-reduction-settings-input i.grok-icon.grok-font-icon-settings {\n font-size: 18px;\n position: absolute;\n height: 28px;\n}\n\n.ml-dim-reduction-settings-input i.grok-icon.grok-font-icon-settings:not(.ml-dim-reduction-column-editor-input-root i) {\n left: -20px;\n}\n.dlg-dimensionality-reduction.ui-form, .dlg-markov-clustering.ui-form, .dlg-markov-clustering.ui-form .ui-form, .dlg-dimensionality-reduction.ui-form .ui-form {\n max-width: unset;\n}\n\n.ml-dim-reduction-column-editor-input-root label {\n display: none !important;\n}\n\n.dim-reduction-dialog-form > .ui-input-root, .dim-reduction-dialog-form > div > .ui-input-root {\n margin-left: 10px;\n}\n\n.ml-dim-reduction-column-editor-input-root input, .ml-dim-reduction-column-editor-input-root select {\n margin-left: 20px !important;\n}\n\nh3.ml-dim-reduction-column-editor-input-root {\n margin: 0 !important;\n}\n\n.ml-dim-reduction-column-editor-root, .ml-dim-reduction-column-editor-header-root {\n display: flex;\n flex-direction: row;\n align-items: center;\n margin-bottom: 10px !important;\n width: 700px !important;\n}\n\n.ml-dim-reduction-column-editor-column-title {\n text-overflow: ellipsis;\n overflow: hidden;\n}\n\n.ml-dim-reduction-column-editor-header-root > h1:not(:first-child) {\n margin-left: 20px !important;\n}\n\n.ml-dim-reduction-column-editor-table-root .header > td:not(:first-child) {\n padding-left: 32px;\n}","",{version:3,sources:["webpack://./node_modules/@datagrok-libraries/ml/css/styles.css"],names:[],mappings:"AAAA;IACI,WAAW;AACf;;AAEA;IACI,4BAA4B;IAC5B,yBAAyB;IACzB,eAAe;AACnB;;AAEA;GACG,mBAAmB;AACtB;;AAEA;IACI,eAAe;IACf,kBAAkB;IAClB,YAAY;AAChB;;AAEA;IACI,WAAW;AACf;AACA;IACI,gBAAgB;AACpB;;AAEA;IACI,wBAAwB;AAC5B;;AAEA;IACI,iBAAiB;AACrB;;AAEA;IACI,4BAA4B;AAChC;;AAEA;IACI,oBAAoB;AACxB;;AAEA;IACI,aAAa;IACb,mBAAmB;IACnB,mBAAmB;IACnB,8BAA8B;IAC9B,uBAAuB;AAC3B;;AAEA;IACI,uBAAuB;IACvB,gBAAgB;AACpB;;AAEA;IACI,4BAA4B;AAChC;;AAEA;IACI,kBAAkB;AACtB",sourcesContent:[".scatter_plot_link {\n right: 10px;\n}\n\n.cliffs_div {\n flex-grow: initial!important;\n justify-content: flex-end;\n flex-wrap: wrap;\n}\n\n.cliffs_grid {\n margin: 0!important;\n}\n\n.ml-dim-reduction-settings-input i.grok-icon.grok-font-icon-settings {\n font-size: 18px;\n position: absolute;\n height: 28px;\n}\n\n.ml-dim-reduction-settings-input i.grok-icon.grok-font-icon-settings:not(.ml-dim-reduction-column-editor-input-root i) {\n left: -20px;\n}\n.dlg-dimensionality-reduction.ui-form, .dlg-markov-clustering.ui-form, .dlg-markov-clustering.ui-form .ui-form, .dlg-dimensionality-reduction.ui-form .ui-form {\n max-width: unset;\n}\n\n.ml-dim-reduction-column-editor-input-root label {\n display: none !important;\n}\n\n.dim-reduction-dialog-form > .ui-input-root, .dim-reduction-dialog-form > div > .ui-input-root {\n margin-left: 10px;\n}\n\n.ml-dim-reduction-column-editor-input-root input, .ml-dim-reduction-column-editor-input-root select {\n margin-left: 20px !important;\n}\n\nh3.ml-dim-reduction-column-editor-input-root {\n margin: 0 !important;\n}\n\n.ml-dim-reduction-column-editor-root, .ml-dim-reduction-column-editor-header-root {\n display: flex;\n flex-direction: row;\n align-items: center;\n margin-bottom: 10px !important;\n width: 700px !important;\n}\n\n.ml-dim-reduction-column-editor-column-title {\n text-overflow: ellipsis;\n overflow: hidden;\n}\n\n.ml-dim-reduction-column-editor-header-root > h1:not(:first-child) {\n margin-left: 20px !important;\n}\n\n.ml-dim-reduction-column-editor-table-root .header > td:not(:first-child) {\n padding-left: 32px;\n}"],sourceRoot:""}]);const s=a},6314:t=>{"use strict";t.exports=function(t){var e=[];return e.toString=function(){return this.map((function(e){var n="",r=void 0!==e[5];return e[4]&&(n+="@supports (".concat(e[4],") {")),e[2]&&(n+="@media ".concat(e[2]," {")),r&&(n+="@layer".concat(e[5].length>0?" ".concat(e[5]):""," {")),n+=t(e),r&&(n+="}"),e[2]&&(n+="}"),e[4]&&(n+="}"),n})).join("")},e.i=function(t,n,r,o,i){"string"==typeof t&&(t=[[null,t,void 0]]);var a={};if(r)for(var s=0;s<this.length;s++){var u=this[s][0];null!=u&&(a[u]=!0)}for(var c=0;c<t.length;c++){var l=[].concat(t[c]);r&&a[l[0]]||(void 0!==i&&(void 0===l[5]||(l[1]="@layer".concat(l[5].length>0?" ".concat(l[5]):""," {").concat(l[1],"}")),l[5]=i),n&&(l[2]?(l[1]="@media ".concat(l[2]," {").concat(l[1],"}"),l[2]=n):l[2]=n),o&&(l[4]?(l[1]="@supports (".concat(l[4],") {").concat(l[1],"}"),l[4]=o):l[4]="".concat(o)),e.push(l))}},e}},1354:t=>{"use strict";t.exports=function(t){var e=t[1],n=t[3];if(!n)return e;if("function"==typeof btoa){var r=btoa(unescape(encodeURIComponent(JSON.stringify(n)))),o="sourceMappingURL=data:application/json;charset=utf-8;base64,".concat(r),i="/*# ".concat(o," */");return[e].concat([i]).join("\n")}return[e].join("\n")}},9937:t=>{t.exports={linLogMode:!1,outboundAttractionDistribution:!1,adjustSizes:!1,edgeWeightInfluence:1,scalingRatio:1,strongGravityMode:!1,gravity:1,slowDown:1,barnesHutOptimize:!1,barnesHutTheta:.5}},1782:(t,e)=>{e.assign=function(t){t=t||{};var e,n,r,o=Array.prototype.slice.call(arguments).slice(1);for(e=0,r=o.length;e<r;e++)if(o[e])for(n in o[e])t[n]=o[e][n];return t},e.validateSettings=function(t){return"linLogMode"in t&&"boolean"!=typeof t.linLogMode?{message:"the `linLogMode` setting should be a boolean."}:"outboundAttractionDistribution"in t&&"boolean"!=typeof t.outboundAttractionDistribution?{message:"the `outboundAttractionDistribution` setting should be a boolean."}:"adjustSizes"in t&&"boolean"!=typeof t.adjustSizes?{message:"the `adjustSizes` setting should be a boolean."}:"edgeWeightInfluence"in t&&"number"!=typeof t.edgeWeightInfluence?{message:"the `edgeWeightInfluence` setting should be a number."}:!("scalingRatio"in t)||"number"==typeof t.scalingRatio&&t.scalingRatio>=0?"strongGravityMode"in t&&"boolean"!=typeof t.strongGravityMode?{message:"the `strongGravityMode` setting should be a boolean."}:!("gravity"in t)||"number"==typeof t.gravity&&t.gravity>=0?"slowDown"in t&&!("number"==typeof t.slowDown||t.slowDown>=0)?{message:"the `slowDown` setting should be a number >= 0."}:"barnesHutOptimize"in t&&"boolean"!=typeof t.barnesHutOptimize?{message:"the `barnesHutOptimize` setting should be a boolean."}:!("barnesHutTheta"in t)||"number"==typeof t.barnesHutTheta&&t.barnesHutTheta>=0?null:{message:"the `barnesHutTheta` setting should be a number >= 0."}:{message:"the `gravity` setting should be a number >= 0."}:{message:"the `scalingRatio` setting should be a number >= 0."}},e.graphToByteArrays=function(t,e){var n,r=t.order,o=t.size,i={},a=new Float32Array(10*r),s=new Float32Array(3*o);return n=0,t.forEachNode((function(t,e){i[t]=n,a[n]=e.x,a[n+1]=e.y,a[n+2]=0,a[n+3]=0,a[n+4]=0,a[n+5]=0,a[n+6]=1,a[n+7]=1,a[n+8]=e.size||1,a[n+9]=e.fixed?1:0,n+=10})),n=0,t.forEachEdge((function(t,r,o,u,c,l,d){var h=i[o],f=i[u],p=e(t,r,o,u,c,l,d);a[h+6]+=p,a[f+6]+=p,s[n]=h,s[n+1]=f,s[n+2]=p,n+=3})),{nodes:a,edges:s}},e.assignLayoutChanges=function(t,e,n){var r=0;t.updateEachNodeAttributes((function(t,o){return o.x=e[r],o.y=e[r+1],r+=10,n?n(t,o):o}))},e.readGraphPositions=function(t,e){var n=0;t.forEachNode((function(t,r){e[n]=r.x,e[n+1]=r.y,n+=10}))},e.collectLayoutChanges=function(t,e,n){for(var r=t.nodes(),o={},i=0,a=0,s=e.length;i<s;i+=10){if(n){var u=Object.assign({},t.getNodeAttributes(r[a]));u.x=e[i],u.y=e[i+1],u=n(r[a],u),o[r[a]]={x:u.x,y:u.y}}else o[r[a]]={x:e[i],y:e[i+1]};a++}return o},e.createWorker=function(t){var e=window.URL||window.webkitURL,n=t.toString(),r=e.createObjectURL(new Blob(["("+n+").call(this);"],{type:"text/javascript"})),o=new Worker(r);return e.revokeObjectURL(r),o}},8903:(t,e,n)=>{var r=n(1736),o=n(8153).Fd,i=n(2561),a=n(1782),s=n(9937);function u(t,e,n){if(!r(e))throw new Error("graphology-layout-forceatlas2: the given graph is not a valid graphology instance.");"number"==typeof n&&(n={iterations:n});var u=n.iterations;if("number"!=typeof u)throw new Error("graphology-layout-forceatlas2: invalid number of iterations.");if(u<=0)throw new Error("graphology-layout-forceatlas2: you should provide a positive number of iterations.");var c=o("getEdgeWeight"in n?n.getEdgeWeight:"weight").fromEntry,l="function"==typeof n.outputReducer?n.outputReducer:null,d=a.assign({},s,n.settings),h=a.validateSettings(d);if(h)throw new Error("graphology-layout-forceatlas2: "+h.message);var f,p=a.graphToByteArrays(e,c);for(f=0;f<u;f++)i(d,p.nodes,p.edges);if(!t)return a.collectLayoutChanges(e,p.nodes);a.assignLayoutChanges(e,p.nodes,l)}var c=u.bind(null,!1);c.assign=u.bind(null,!0),c.inferSettings=function(t){var e="number"==typeof t?t:t.order;return{barnesHutOptimize:e>2e3,strongGravityMode:!0,gravity:.05,scalingRatio:10,slowDown:1+Math.log(e)}},t.exports=c},2561:t=>{var e=10;t.exports=function(t,n,r){var o,i,a,s,u,c,l,d,h,f,p,m,g,y,v,w,b,E,A,C,S,_,N,I=n.length,M=r.length,T=t.adjustSizes,O=t.barnesHutTheta*t.barnesHutTheta,P=[];for(a=0;a<I;a+=e)n[a+4]=n[a+2],n[a+5]=n[a+3],n[a+2]=0,n[a+3]=0;if(t.outboundAttractionDistribution){for(p=0,a=0;a<I;a+=e)p+=n[a+6];p/=I/e}if(t.barnesHutOptimize){var L,x,F,R=1/0,D=-1/0,U=1/0,k=-1/0;for(a=0;a<I;a+=e)R=Math.min(R,n[a+0]),D=Math.max(D,n[a+0]),U=Math.min(U,n[a+1]),k=Math.max(k,n[a+1]);var G=D-R,B=k-U;for(G>B?k=(U-=(G-B)/2)+G:D=(R-=(B-G)/2)+B,P[0]=-1,P[1]=(R+D)/2,P[2]=(U+k)/2,P[3]=Math.max(D-R,k-U),P[4]=-1,P[5]=-1,P[6]=0,P[7]=0,P[8]=0,o=1,a=0;a<I;a+=e)for(i=0,F=3;;){if(!(P[i+5]>=0)){if(P[i+0]<0){P[i+0]=a;break}if(P[i+5]=9*o,d=P[i+3]/2,P[(h=P[i+5])+0]=-1,P[h+1]=P[i+1]-d,P[h+2]=P[i+2]-d,P[h+3]=d,P[h+4]=h+9,P[h+5]=-1,P[h+6]=0,P[h+7]=0,P[h+8]=0,P[(h+=9)+0]=-1,P[h+1]=P[i+1]-d,P[h+2]=P[i+2]+d,P[h+3]=d,P[h+4]=h+9,P[h+5]=-1,P[h+6]=0,P[h+7]=0,P[h+8]=0,P[(h+=9)+0]=-1,P[h+1]=P[i+1]+d,P[h+2]=P[i+2]-d,P[h+3]=d,P[h+4]=h+9,P[h+5]=-1,P[h+6]=0,P[h+7]=0,P[h+8]=0,P[(h+=9)+0]=-1,P[h+1]=P[i+1]+d,P[h+2]=P[i+2]+d,P[h+3]=d,P[h+4]=P[i+4],P[h+5]=-1,P[h+6]=0,P[h+7]=0,P[h+8]=0,o+=4,L=n[P[i+0]+0]<P[i+1]?n[P[i+0]+1]<P[i+2]?P[i+5]:P[i+5]+9:n[P[i+0]+1]<P[i+2]?P[i+5]+18:P[i+5]+27,P[i+6]=n[P[i+0]+6],P[i+7]=n[P[i+0]+0],P[i+8]=n[P[i+0]+1],P[L+0]=P[i+0],P[i+0]=-1,L===(x=n[a+0]<P[i+1]?n[a+1]<P[i+2]?P[i+5]:P[i+5]+9:n[a+1]<P[i+2]?P[i+5]+18:P[i+5]+27)){if(F--){i=L;continue}F=3;break}P[x+0]=a;break}L=n[a+0]<P[i+1]?n[a+1]<P[i+2]?P[i+5]:P[i+5]+9:n[a+1]<P[i+2]?P[i+5]+18:P[i+5]+27,P[i+7]=(P[i+7]*P[i+6]+n[a+0]*n[a+6])/(P[i+6]+n[a+6]),P[i+8]=(P[i+8]*P[i+6]+n[a+1]*n[a+6])/(P[i+6]+n[a+6]),P[i+6]+=n[a+6],i=L}}if(t.barnesHutOptimize){for(m=t.scalingRatio,a=0;a<I;a+=e)for(i=0;;)if(P[i+5]>=0){if(w=Math.pow(n[a+0]-P[i+7],2)+Math.pow(n[a+1]-P[i+8],2),4*(f=P[i+3])*f/w<O){if(g=n[a+0]-P[i+7],y=n[a+1]-P[i+8],!0===T?w>0?(b=m*n[a+6]*P[i+6]/w,n[a+2]+=g*b,n[a+3]+=y*b):w<0&&(b=-m*n[a+6]*P[i+6]/Math.sqrt(w),n[a+2]+=g*b,n[a+3]+=y*b):w>0&&(b=m*n[a+6]*P[i+6]/w,n[a+2]+=g*b,n[a+3]+=y*b),(i=P[i+4])<0)break;continue}i=P[i+5]}else if((c=P[i+0])>=0&&c!==a&&(w=(g=n[a+0]-n[c+0])*g+(y=n[a+1]-n[c+1])*y,!0===T?w>0?(b=m*n[a+6]*n[c+6]/w,n[a+2]+=g*b,n[a+3]+=y*b):w<0&&(b=-m*n[a+6]*n[c+6]/Math.sqrt(w),n[a+2]+=g*b,n[a+3]+=y*b):w>0&&(b=m*n[a+6]*n[c+6]/w,n[a+2]+=g*b,n[a+3]+=y*b)),(i=P[i+4])<0)break}else for(m=t.scalingRatio,s=0;s<I;s+=e)for(u=0;u<s;u+=e)g=n[s+0]-n[u+0],y=n[s+1]-n[u+1],!0===T?(w=Math.sqrt(g*g+y*y)-n[s+8]-n[u+8])>0?(b=m*n[s+6]*n[u+6]/w/w,n[s+2]+=g*b,n[s+3]+=y*b,n[u+2]-=g*b,n[u+3]-=y*b):w<0&&(b=100*m*n[s+6]*n[u+6],n[s+2]+=g*b,n[s+3]+=y*b,n[u+2]-=g*b,n[u+3]-=y*b):(w=Math.sqrt(g*g+y*y))>0&&(b=m*n[s+6]*n[u+6]/w/w,n[s+2]+=g*b,n[s+3]+=y*b,n[u+2]-=g*b,n[u+3]-=y*b);for(h=t.gravity/t.scalingRatio,m=t.scalingRatio,a=0;a<I;a+=e)b=0,g=n[a+0],y=n[a+1],w=Math.sqrt(Math.pow(g,2)+Math.pow(y,2)),t.strongGravityMode?w>0&&(b=m*n[a+6]*h):w>0&&(b=m*n[a+6]*h/w),n[a+2]-=g*b,n[a+3]-=y*b;for(m=1*(t.outboundAttractionDistribution?p:1),l=0;l<M;l+=3)s=r[l+0],u=r[l+1],d=r[l+2],v=Math.pow(d,t.edgeWeightInfluence),g=n[s+0]-n[u+0],y=n[s+1]-n[u+1],!0===T?(w=Math.sqrt(g*g+y*y)-n[s+8]-n[u+8],t.linLogMode?t.outboundAttractionDistribution?w>0&&(b=-m*v*Math.log(1+w)/w/n[s+6]):w>0&&(b=-m*v*Math.log(1+w)/w):t.outboundAttractionDistribution?w>0&&(b=-m*v/n[s+6]):w>0&&(b=-m*v)):(w=Math.sqrt(Math.pow(g,2)+Math.pow(y,2)),t.linLogMode?t.outboundAttractionDistribution?w>0&&(b=-m*v*Math.log(1+w)/w/n[s+6]):w>0&&(b=-m*v*Math.log(1+w)/w):t.outboundAttractionDistribution?(w=1,b=-m*v/n[s+6]):(w=1,b=-m*v)),w>0&&(n[s+2]+=g*b,n[s+3]+=y*b,n[u+2]-=g*b,n[u+3]-=y*b);if(!0===T)for(a=0;a<I;a+=e)1!==n[a+9]&&((E=Math.sqrt(Math.pow(n[a+2],2)+Math.pow(n[a+3],2)))>10&&(n[a+2]=10*n[a+2]/E,n[a+3]=10*n[a+3]/E),A=n[a+6]*Math.sqrt((n[a+4]-n[a+2])*(n[a+4]-n[a+2])+(n[a+5]-n[a+3])*(n[a+5]-n[a+3])),C=Math.sqrt((n[a+4]+n[a+2])*(n[a+4]+n[a+2])+(n[a+5]+n[a+3])*(n[a+5]+n[a+3]))/2,S=.1*Math.log(1+C)/(1+Math.sqrt(A)),_=n[a+0]+n[a+2]*(S/t.slowDown),n[a+0]=_,N=n[a+1]+n[a+3]*(S/t.slowDown),n[a+1]=N);else for(a=0;a<I;a+=e)1!==n[a+9]&&(A=n[a+6]*Math.sqrt((n[a+4]-n[a+2])*(n[a+4]-n[a+2])+(n[a+5]-n[a+3])*(n[a+5]-n[a+3])),C=Math.sqrt((n[a+4]+n[a+2])*(n[a+4]+n[a+2])+(n[a+5]+n[a+3])*(n[a+5]+n[a+3]))/2,S=n[a+7]*Math.log(1+C)/(1+Math.sqrt(A)),n[a+7]=Math.min(1,Math.sqrt(S*(Math.pow(n[a+2],2)+Math.pow(n[a+3],2))/(1+Math.sqrt(A)))),_=n[a+0]+n[a+2]*(S/t.slowDown),n[a+0]=_,N=n[a+1]+n[a+3]*(S/t.slowDown),n[a+1]=N);return{}}},8153:(t,e)=>{function n(t){return"number"!=typeof t||isNaN(t)?1:t}e.Fd=function(t){return function(t,e){var n={},r=function(t){return void 0===t?e:t};"function"==typeof e&&(r=e);var o=function(e){return r(e[t])},i=function(){return r(void 0)};return"string"==typeof t?(n.fromAttributes=o,n.fromGraph=function(t,e){return o(t.getEdgeAttributes(e))},n.fromEntry=function(t,e){return o(e)},n.fromPartialEntry=n.fromEntry,n.fromMinimalEntry=n.fromEntry):"function"==typeof t?(n.fromAttributes=function(){throw new Error("graphology-utils/getters/createEdgeValueGetter: irrelevant usage.")},n.fromGraph=function(e,n){var o=e.extremities(n);return r(t(n,e.getEdgeAttributes(n),o[0],o[1],e.getNodeAttributes(o[0]),e.getNodeAttributes(o[1]),e.isUndirected(n)))},n.fromEntry=function(e,n,o,i,a,s,u){return r(t(e,n,o,i,a,s,u))},n.fromPartialEntry=function(e,n,o,i){return r(t(e,n,o,i))},n.fromMinimalEntry=function(e,n){return r(t(e,n))}):(n.fromAttributes=i,n.fromGraph=i,n.fromEntry=i,n.fromMinimalEntry=i),n}(t,n)}},1736:t=>{t.exports=function(t){return null!==t&&"object"==typeof t&&"function"==typeof t.addUndirectedEdgeWithKey&&"function"==typeof t.dropNode&&"boolean"==typeof t.multi}},934:function(t){t.exports=function(){"use strict";function t(e){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(e)}function e(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,r(t,e)}function n(t){return n=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},n(t)}function r(t,e){return r=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},r(t,e)}function o(t,e,n){return o=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}()?Reflect.construct.bind():function(t,e,n){var o=[null];o.push.apply(o,e);var i=new(Function.bind.apply(t,o));return n&&r(i,n.prototype),i},o.apply(null,arguments)}function i(t){var e="function"==typeof Map?new Map:void 0;return i=function(t){if(null===t||(i=t,-1===Function.toString.call(i).indexOf("[native code]")))return t;var i;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,a)}function a(){return o(t,arguments,n(this).constructor)}return a.prototype=Object.create(t.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}}),r(a,t)},i(t)}function a(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}var s=function(){for(var t=arguments[0],e=1,n=arguments.length;e<n;e++)if(arguments[e])for(var r in arguments[e])t[r]=arguments[e][r];return t};function u(t,e,n,r){var o=t._nodes.get(e),i=null;return o?i="mixed"===r?o.out&&o.out[n]||o.undirected&&o.undirected[n]:"directed"===r?o.out&&o.out[n]:o.undirected&&o.undirected[n]:i}function c(e){return"object"===t(e)&&null!==e}function l(t){var e;for(e in t)return!1;return!0}function d(t,e,n){Object.defineProperty(t,e,{enumerable:!1,configurable:!1,writable:!0,value:n})}function h(t,e,n){var r={enumerable:!0,configurable:!0};"function"==typeof n?r.get=n:(r.value=n,r.writable=!1),Object.defineProperty(t,e,r)}function f(t){return!(!c(t)||t.attributes&&!Array.isArray(t.attributes))}"function"==typeof Object.assign&&(s=Object.assign);var p,m={exports:{}},g="object"==typeof Reflect?Reflect:null,y=g&&"function"==typeof g.apply?g.apply:function(t,e,n){return Function.prototype.apply.call(t,e,n)};p=g&&"function"==typeof g.ownKeys?g.ownKeys:Object.getOwnPropertySymbols?function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:function(t){return Object.getOwnPropertyNames(t)};var v=Number.isNaN||function(t){return t!=t};function w(){w.init.call(this)}m.exports=w,m.exports.once=function(t,e){return new Promise((function(n,r){function o(n){t.removeListener(e,i),r(n)}function i(){"function"==typeof t.removeListener&&t.removeListener("error",o),n([].slice.call(arguments))}T(t,e,i,{once:!0}),"error"!==e&&function(t,e){"function"==typeof t.on&&T(t,"error",e,{once:!0})}(t,o)}))},w.EventEmitter=w,w.prototype._events=void 0,w.prototype._eventsCount=0,w.prototype._maxListeners=void 0;var b=10;function E(t){if("function"!=typeof t)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t)}function A(t){return void 0===t._maxListeners?w.defaultMaxListeners:t._maxListeners}function C(t,e,n,r){var o,i,a,s;if(E(n),void 0===(i=t._events)?(i=t._events=Object.create(null),t._eventsCount=0):(void 0!==i.newListener&&(t.emit("newListener",e,n.listener?n.listener:n),i=t._events),a=i[e]),void 0===a)a=i[e]=n,++t._eventsCount;else if("function"==typeof a?a=i[e]=r?[n,a]:[a,n]:r?a.unshift(n):a.push(n),(o=A(t))>0&&a.length>o&&!a.warned){a.warned=!0;var u=new Error("Possible EventEmitter memory leak detected. "+a.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");u.name="MaxListenersExceededWarning",u.emitter=t,u.type=e,u.count=a.length,s=u,console&&console.warn&&console.warn(s)}return t}function S(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,0===arguments.length?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function _(t,e,n){var r={fired:!1,wrapFn:void 0,target:t,type:e,listener:n},o=S.bind(r);return o.listener=n,r.wrapFn=o,o}function N(t,e,n){var r=t._events;if(void 0===r)return[];var o=r[e];return void 0===o?[]:"function"==typeof o?n?[o.listener||o]:[o]:n?function(t){for(var e=new Array(t.length),n=0;n<e.length;++n)e[n]=t[n].listener||t[n];return e}(o):M(o,o.length)}function I(t){var e=this._events;if(void 0!==e){var n=e[t];if("function"==typeof n)return 1;if(void 0!==n)return n.length}return 0}function M(t,e){for(var n=new Array(e),r=0;r<e;++r)n[r]=t[r];return n}function T(t,e,n,r){if("function"==typeof t.on)r.once?t.once(e,n):t.on(e,n);else{if("function"!=typeof t.addEventListener)throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof t);t.addEventListener(e,(function o(i){r.once&&t.removeEventListener(e,o),n(i)}))}}function O(t){if("function"!=typeof t)throw new Error("obliterator/iterator: expecting a function!");this.next=t}Object.defineProperty(w,"defaultMaxListeners",{enumerable:!0,get:function(){return b},set:function(t){if("number"!=typeof t||t<0||v(t))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+t+".");b=t}}),w.init=function(){void 0!==this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},w.prototype.setMaxListeners=function(t){if("number"!=typeof t||t<0||v(t))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+t+".");return this._maxListeners=t,this},w.prototype.getMaxListeners=function(){return A(this)},w.prototype.emit=function(t){for(var e=[],n=1;n<arguments.length;n++)e.push(arguments[n]);var r="error"===t,o=this._events;if(void 0!==o)r=r&&void 0===o.error;else if(!r)return!1;if(r){var i;if(e.length>0&&(i=e[0]),i instanceof Error)throw i;var a=new Error("Unhandled error."+(i?" ("+i.message+")":""));throw a.context=i,a}var s=o[t];if(void 0===s)return!1;if("function"==typeof s)y(s,this,e);else{var u=s.length,c=M(s,u);for(n=0;n<u;++n)y(c[n],this,e)}return!0},w.prototype.addListener=function(t,e){return C(this,t,e,!1)},w.prototype.on=w.prototype.addListener,w.prototype.prependListener=function(t,e){return C(this,t,e,!0)},w.prototype.once=function(t,e){return E(e),this.on(t,_(this,t,e)),this},w.prototype.prependOnceListener=function(t,e){return E(e),this.prependListener(t,_(this,t,e)),this},w.prototype.removeListener=function(t,e){var n,r,o,i,a;if(E(e),void 0===(r=this._events))return this;if(void 0===(n=r[t]))return this;if(n===e||n.listener===e)0==--this._eventsCount?this._events=Object.create(null):(delete r[t],r.removeListener&&this.emit("removeListener",t,n.listener||e));else if("function"!=typeof n){for(o=-1,i=n.length-1;i>=0;i--)if(n[i]===e||n[i].listener===e){a=n[i].listener,o=i;break}if(o<0)return this;0===o?n.shift():function(t,e){for(;e+1<t.length;e++)t[e]=t[e+1];t.pop()}(n,o),1===n.length&&(r[t]=n[0]),void 0!==r.removeListener&&this.emit("removeListener",t,a||e)}return this},w.prototype.off=w.prototype.removeListener,w.prototype.removeAllListeners=function(t){var e,n,r;if(void 0===(n=this._events))return this;if(void 0===n.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==n[t]&&(0==--this._eventsCount?this._events=Object.create(null):delete n[t]),this;if(0===arguments.length){var o,i=Object.keys(n);for(r=0;r<i.length;++r)"removeListener"!==(o=i[r])&&this.removeAllListeners(o);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(e=n[t]))this.removeListener(t,e);else if(void 0!==e)for(r=e.length-1;r>=0;r--)this.removeListener(t,e[r]);return this},w.prototype.listeners=function(t){return N(this,t,!0)},w.prototype.rawListeners=function(t){return N(this,t,!1)},w.listenerCount=function(t,e){return"function"==typeof t.listenerCount?t.listenerCount(e):I.call(t,e)},w.prototype.listenerCount=I,w.prototype.eventNames=function(){return this._eventsCount>0?p(this._events):[]},"undefined"!=typeof Symbol&&(O.prototype[Symbol.iterator]=function(){return this}),O.of=function(){var t=arguments,e=t.length,n=0;return new O((function(){return n>=e?{done:!0}:{done:!1,value:t[n++]}}))},O.empty=function(){return new O((function(){return{done:!0}}))},O.fromSequence=function(t){var e=0,n=t.length;return new O((function(){return e>=n?{done:!0}:{done:!1,value:t[e++]}}))},O.is=function(t){return t instanceof O||"object"==typeof t&&null!==t&&"function"==typeof t.next};var P=O,L={};L.ARRAY_BUFFER_SUPPORT="undefined"!=typeof ArrayBuffer,L.SYMBOL_SUPPORT="undefined"!=typeof Symbol;var x=P,F=L,R=F.ARRAY_BUFFER_SUPPORT,D=F.SYMBOL_SUPPORT,U=function(t){var e=function(t){return"string"==typeof t||Array.isArray(t)||R&&ArrayBuffer.isView(t)?x.fromSequence(t):"object"!=typeof t||null===t?null:D&&"function"==typeof t[Symbol.iterator]?t[Symbol.iterator]():"function"==typeof t.next?t:null}(t);if(!e)throw new Error("obliterator: target is not iterable nor a valid iterator.");return e},k=U,G=function(t,e){for(var n,r=arguments.length>1?e:1/0,o=r!==1/0?new Array(r):[],i=0,a=k(t);;){if(i===r)return o;if((n=a.next()).done)return i!==e&&(o.length=i),o;o[i++]=n.value}},B=function(t){function n(e){var n;return(n=t.call(this)||this).name="GraphError",n.message=e,n}return e(n,t),n}(i(Error)),V=function(t){function n(e){var r;return(r=t.call(this,e)||this).name="InvalidArgumentsGraphError","function"==typeof Error.captureStackTrace&&Error.captureStackTrace(a(r),n.prototype.constructor),r}return e(n,t),n}(B),W=function(t){function n(e){var r;return(r=t.call(this,e)||this).name="NotFoundGraphError","function"==typeof Error.captureStackTrace&&Error.captureStackTrace(a(r),n.prototype.constructor),r}return e(n,t),n}(B),j=function(t){function n(e){var r;return(r=t.call(this,e)||this).name="UsageGraphError","function"==typeof Error.captureStackTrace&&Error.captureStackTrace(a(r),n.prototype.constructor),r}return e(n,t),n}(B);function Y(t,e){this.key=t,this.attributes=e,this.clear()}function z(t,e){this.key=t,this.attributes=e,this.clear()}function q(t,e){this.key=t,this.attributes=e,this.clear()}function H(t,e,n,r,o){this.key=e,this.attributes=o,this.undirected=t,this.source=n,this.target=r}function $(t,e,n,r,o,i,a){var s,u,c,l;if(r=""+r,0===n){if(!(s=t._nodes.get(r)))throw new W("Graph.".concat(e,': could not find the "').concat(r,'" node in the graph.'));c=o,l=i}else if(3===n){if(o=""+o,!(u=t._edges.get(o)))throw new W("Graph.".concat(e,': could not find the "').concat(o,'" edge in the graph.'));var d=u.source.key,h=u.target.key;if(r===d)s=u.target;else{if(r!==h)throw new W("Graph.".concat(e,': the "').concat(r,'" node is not attached to the "').concat(o,'" edge (').concat(d,", ").concat(h,")."));s=u.source}c=i,l=a}else{if(!(u=t._edges.get(r)))throw new W("Graph.".concat(e,': could not find the "').concat(r,'" edge in the graph.'));s=1===n?u.source:u.target,c=o,l=i}return[s,c,l]}Y.prototype.clear=function(){this.inDegree=0,this.outDegree=0,this.undirectedDegree=0,this.undirectedLoops=0,this.directedLoops=0,this.in={},this.out={},this.undirected={}},z.prototype.clear=function(){this.inDegree=0,this.outDegree=0,this.directedLoops=0,this.in={},this.out={}},q.prototype.clear=function(){this.undirectedDegree=0,this.undirectedLoops=0,this.undirected={}},H.prototype.attach=function(){var t="out",e="in";this.undirected&&(t=e="undirected");var n=this.source.key,r=this.target.key;this.source[t][r]=this,this.undirected&&n===r||(this.target[e][n]=this)},H.prototype.attachMulti=function(){var t="out",e="in",n=this.source.key,r=this.target.key;this.undirected&&(t=e="undirected");var o=this.source[t],i=o[r];if(void 0===i)return o[r]=this,void(this.undirected&&n===r||(this.target[e][n]=this));i.previous=this,this.next=i,o[r]=this,this.target[e][n]=this},H.prototype.detach=function(){var t=this.source.key,e=this.target.key,n="out",r="in";this.undirected&&(n=r="undirected"),delete this.source[n][e],delete this.target[r][t]},H.prototype.detachMulti=function(){var t=this.source.key,e=this.target.key,n="out",r="in";this.undirected&&(n=r="undirected"),void 0===this.previous?void 0===this.next?(delete this.source[n][e],delete this.target[r][t]):(this.next.previous=void 0,this.source[n][e]=this.next,this.target[r][t]=this.next):(this.previous.next=this.next,void 0!==this.next&&(this.next.previous=this.previous))};var K=[{name:function(t){return"get".concat(t,"Attribute")},attacher:function(t,e,n){t.prototype[e]=function(t,r,o){var i=$(this,e,n,t,r,o),a=i[0],s=i[1];return a.attributes[s]}}},{name:function(t){return"get".concat(t,"Attributes")},attacher:function(t,e,n){t.prototype[e]=function(t,r){return $(this,e,n,t,r)[0].attributes}}},{name:function(t){return"has".concat(t,"Attribute")},attacher:function(t,e,n){t.prototype[e]=function(t,r,o){var i=$(this,e,n,t,r,o),a=i[0],s=i[1];return a.attributes.hasOwnProperty(s)}}},{name:function(t){return"set".concat(t,"Attribute")},attacher:function(t,e,n){t.prototype[e]=function(t,r,o,i){var a=$(this,e,n,t,r,o,i),s=a[0],u=a[1],c=a[2];return s.attributes[u]=c,this.emit("nodeAttributesUpdated",{key:s.key,type:"set",attributes:s.attributes,name:u}),this}}},{name:function(t){return"update".concat(t,"Attribute")},attacher:function(t,e,n){t.prototype[e]=function(t,r,o,i){var a=$(this,e,n,t,r,o,i),s=a[0],u=a[1],c=a[2];if("function"!=typeof c)throw new V("Graph.".concat(e,": updater should be a function."));var l=s.attributes,d=c(l[u]);return l[u]=d,this.emit("nodeAttributesUpdated",{key:s.key,type:"set",attributes:s.attributes,name:u}),this}}},{name:function(t){return"remove".concat(t,"Attribute")},attacher:function(t,e,n){t.prototype[e]=function(t,r,o){var i=$(this,e,n,t,r,o),a=i[0],s=i[1];return delete a.attributes[s],this.emit("nodeAttributesUpdated",{key:a.key,type:"remove",attributes:a.attributes,name:s}),this}}},{name:function(t){return"replace".concat(t,"Attributes")},attacher:function(t,e,n){t.prototype[e]=function(t,r,o){var i=$(this,e,n,t,r,o),a=i[0],s=i[1];if(!c(s))throw new V("Graph.".concat(e,": provided attributes are not a plain object."));return a.attributes=s,this.emit("nodeAttributesUpdated",{key:a.key,type:"replace",attributes:a.attributes}),this}}},{name:function(t){return"merge".concat(t,"Attributes")},attacher:function(t,e,n){t.prototype[e]=function(t,r,o){var i=$(this,e,n,t,r,o),a=i[0],u=i[1];if(!c(u))throw new V("Graph.".concat(e,": provided attributes are not a plain object."));return s(a.attributes,u),this.emit("nodeAttributesUpdated",{key:a.key,type:"merge",attributes:a.attributes,data:u}),this}}},{name:function(t){return"update".concat(t,"Attributes")},attacher:function(t,e,n){t.prototype[e]=function(t,r,o){var i=$(this,e,n,t,r,o),a=i[0],s=i[1];if("function"!=typeof s)throw new V("Graph.".concat(e,": provided updater is not a function."));return a.attributes=s(a.attributes),this.emit("nodeAttributesUpdated",{key:a.key,type:"update",attributes:a.attributes}),this}}}],X=[{name:function(t){return"get".concat(t,"Attribute")},attacher:function(t,e,n){t.prototype[e]=function(t,r){var o;if("mixed"!==this.type&&"mixed"!==n&&n!==this.type)throw new j("Graph.".concat(e,": cannot find this type of edges in your ").concat(this.type," graph."));if(arguments.length>2){if(this.multi)throw new j("Graph.".concat(e,": cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about."));var i=""+t,a=""+r;if(r=arguments[2],!(o=u(this,i,a,n)))throw new W("Graph.".concat(e,': could not find an edge for the given path ("').concat(i,'" - "').concat(a,'").'))}else{if("mixed"!==n)throw new j("Graph.".concat(e,": calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type."));if(t=""+t,!(o=this._edges.get(t)))throw new W("Graph.".concat(e,': could not find the "').concat(t,'" edge in the graph.'))}return o.attributes[r]}}},{name:function(t){return"get".concat(t,"Attributes")},attacher:function(t,e,n){t.prototype[e]=function(t){var r;if("mixed"!==this.type&&"mixed"!==n&&n!==this.type)throw new j("Graph.".concat(e,": cannot find this type of edges in your ").concat(this.type," graph."));if(arguments.length>1){if(this.multi)throw new j("Graph.".concat(e,": cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about."));var o=""+t,i=""+arguments[1];if(!(r=u(this,o,i,n)))throw new W("Graph.".concat(e,': could not find an edge for the given path ("').concat(o,'" - "').concat(i,'").'))}else{if("mixed"!==n)throw new j("Graph.".concat(e,": calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type."));if(t=""+t,!(r=this._edges.get(t)))throw new W("Graph.".concat(e,': could not find the "').concat(t,'" edge in the graph.'))}return r.attributes}}},{name:function(t){return"has".concat(t,"Attribute")},attacher:function(t,e,n){t.prototype[e]=function(t,r){var o;if("mixed"!==this.type&&"mixed"!==n&&n!==this.type)throw new j("Graph.".concat(e,": cannot find this type of edges in your ").concat(this.type," graph."));if(arguments.length>2){if(this.multi)throw new j("Graph.".concat(e,": cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about."));var i=""+t,a=""+r;if(r=arguments[2],!(o=u(this,i,a,n)))throw new W("Graph.".concat(e,': could not find an edge for the given path ("').concat(i,'" - "').concat(a,'").'))}else{if("mixed"!==n)throw new j("Graph.".concat(e,": calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type."));if(t=""+t,!(o=this._edges.get(t)))throw new W("Graph.".concat(e,': could not find the "').concat(t,'" edge in the graph.'))}return o.attributes.hasOwnProperty(r)}}},{name:function(t){return"set".concat(t,"Attribute")},attacher:function(t,e,n){t.prototype[e]=function(t,r,o){var i;if("mixed"!==this.type&&"mixed"!==n&&n!==this.type)throw new j("Graph.".concat(e,": cannot find this type of edges in your ").concat(this.type," graph."));if(arguments.length>3){if(this.multi)throw new j("Graph.".concat(e,": cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about."));var a=""+t,s=""+r;if(r=arguments[2],o=arguments[3],!(i=u(this,a,s,n)))throw new W("Graph.".concat(e,': could not find an edge for the given path ("').concat(a,'" - "').concat(s,'").'))}else{if("mixed"!==n)throw new j("Graph.".concat(e,": calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type."));if(t=""+t,!(i=this._edges.get(t)))throw new W("Graph.".concat(e,': could not find the "').concat(t,'" edge in the graph.'))}return i.attributes[r]=o,this.emit("edgeAttributesUpdated",{key:i.key,type:"set",attributes:i.attributes,name:r}),this}}},{name:function(t){return"update".concat(t,"Attribute")},attacher:function(t,e,n){t.prototype[e]=function(t,r,o){var i;if("mixed"!==this.type&&"mixed"!==n&&n!==this.type)throw new j("Graph.".concat(e,": cannot find this type of edges in your ").concat(this.type," graph."));if(arguments.length>3){if(this.multi)throw new j("Graph.".concat(e,": cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about."));var a=""+t,s=""+r;if(r=arguments[2],o=arguments[3],!(i=u(this,a,s,n)))throw new W("Graph.".concat(e,': could not find an edge for the given path ("').concat(a,'" - "').concat(s,'").'))}else{if("mixed"!==n)throw new j("Graph.".concat(e,": calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type."));if(t=""+t,!(i=this._edges.get(t)))throw new W("Graph.".concat(e,': could not find the "').concat(t,'" edge in the graph.'))}if("function"!=typeof o)throw new V("Graph.".concat(e,": updater should be a function."));return i.attributes[r]=o(i.attributes[r]),this.emit("edgeAttributesUpdated",{key:i.key,type:"set",attributes:i.attributes,name:r}),this}}},{name:function(t){return"remove".concat(t,"Attribute")},attacher:function(t,e,n){t.prototype[e]=function(t,r){var o;if("mixed"!==this.type&&"mixed"!==n&&n!==this.type)throw new j("Graph.".concat(e,": cannot find this type of edges in your ").concat(this.type," graph."));if(arguments.length>2){if(this.multi)throw new j("Graph.".concat(e,": cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about."));var i=""+t,a=""+r;if(r=arguments[2],!(o=u(this,i,a,n)))throw new W("Graph.".concat(e,': could not find an edge for the given path ("').concat(i,'" - "').concat(a,'").'))}else{if("mixed"!==n)throw new j("Graph.".concat(e,": calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type."));if(t=""+t,!(o=this._edges.get(t)))throw new W("Graph.".concat(e,': could not find the "').concat(t,'" edge in the graph.'))}return delete o.attributes[r],this.emit("edgeAttributesUpdated",{key:o.key,type:"remove",attributes:o.attributes,name:r}),this}}},{name:function(t){return"replace".concat(t,"Attributes")},attacher:function(t,e,n){t.prototype[e]=function(t,r){var o;if("mixed"!==this.type&&"mixed"!==n&&n!==this.type)throw new j("Graph.".concat(e,": cannot find this type of edges in your ").concat(this.type," graph."));if(arguments.length>2){if(this.multi)throw new j("Graph.".concat(e,": cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about."));var i=""+t,a=""+r;if(r=arguments[2],!(o=u(this,i,a,n)))throw new W("Graph.".concat(e,': could not find an edge for the given path ("').concat(i,'" - "').concat(a,'").'))}else{if("mixed"!==n)throw new j("Graph.".concat(e,": calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type."));if(t=""+t,!(o=this._edges.get(t)))throw new W("Graph.".concat(e,': could not find the "').concat(t,'" edge in the graph.'))}if(!c(r))throw new V("Graph.".concat(e,": provided attributes are not a plain object."));return o.attributes=r,this.emit("edgeAttributesUpdated",{key:o.key,type:"replace",attributes:o.attributes}),this}}},{name:function(t){return"merge".concat(t,"Attributes")},attacher:function(t,e,n){t.prototype[e]=function(t,r){var o;if("mixed"!==this.type&&"mixed"!==n&&n!==this.type)throw new j("Graph.".concat(e,": cannot find this type of edges in your ").concat(this.type," graph."));if(arguments.length>2){if(this.multi)throw new j("Graph.".concat(e,": cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about."));var i=""+t,a=""+r;if(r=arguments[2],!(o=u(this,i,a,n)))throw new W("Graph.".concat(e,': could not find an edge for the given path ("').concat(i,'" - "').concat(a,'").'))}else{if("mixed"!==n)throw new j("Graph.".concat(e,": calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type."));if(t=""+t,!(o=this._edges.get(t)))throw new W("Graph.".concat(e,': could not find the "').concat(t,'" edge in the graph.'))}if(!c(r))throw new V("Graph.".concat(e,": provided attributes are not a plain object."));return s(o.attributes,r),this.emit("edgeAttributesUpdated",{key:o.key,type:"merge",attributes:o.attributes,data:r}),this}}},{name:function(t){return"update".concat(t,"Attributes")},attacher:function(t,e,n){t.prototype[e]=function(t,r){var o;if("mixed"!==this.type&&"mixed"!==n&&n!==this.type)throw new j("Graph.".concat(e,": cannot find this type of edges in your ").concat(this.type," graph."));if(arguments.length>2){if(this.multi)throw new j("Graph.".concat(e,": cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about."));var i=""+t,a=""+r;if(r=arguments[2],!(o=u(this,i,a,n)))throw new W("Graph.".concat(e,': could not find an edge for the given path ("').concat(i,'" - "').concat(a,'").'))}else{if("mixed"!==n)throw new j("Graph.".concat(e,": calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type."));if(t=""+t,!(o=this._edges.get(t)))throw new W("Graph.".concat(e,': could not find the "').concat(t,'" edge in the graph.'))}if("function"!=typeof r)throw new V("Graph.".concat(e,": provided updater is not a function."));return o.attributes=r(o.attributes),this.emit("edgeAttributesUpdated",{key:o.key,type:"update",attributes:o.attributes}),this}}}],Q=P,J=U,Z=function(){var t=arguments,e=null,n=-1;return new Q((function(){for(var r=null;;){if(null===e){if(++n>=t.length)return{done:!0};e=J(t[n])}if(!0!==(r=e.next()).done)break;e=null}return r}))},tt=[{name:"edges",type:"mixed"},{name:"inEdges",type:"directed",direction:"in"},{name:"outEdges",type:"directed",direction:"out"},{name:"inboundEdges",type:"mixed",direction:"in"},{name:"outboundEdges",type:"mixed",direction:"out"},{name:"directedEdges",type:"directed"},{name:"undirectedEdges",type:"undirected"}];function et(t,e,n,r){var o=!1;for(var i in e)if(i!==r){var a=e[i];if(o=n(a.key,a.attributes,a.source.key,a.target.key,a.source.attributes,a.target.attributes,a.undirected),t&&o)return a.key}}function nt(t,e,n,r){var o,i,a,s=!1;for(var u in e)if(u!==r){o=e[u];do{if(i=o.source,a=o.target,s=n(o.key,o.attributes,i.key,a.key,i.attributes,a.attributes,o.undirected),t&&s)return o.key;o=o.next}while(void 0!==o)}}function rt(t,e){var n,r=Object.keys(t),o=r.length,i=0;return new P((function(){do{if(n)n=n.next;else{if(i>=o)return{done:!0};var a=r[i++];if(a===e){n=void 0;continue}n=t[a]}}while(!n);return{done:!1,value:{edge:n.key,attributes:n.attributes,source:n.source.key,target:n.target.key,sourceAttributes:n.source.attributes,targetAttributes:n.target.attributes,undirected:n.undirected}}}))}function ot(t,e,n,r){var o=e[n];if(o){var i=o.source,a=o.target;return r(o.key,o.attributes,i.key,a.key,i.attributes,a.attributes,o.undirected)&&t?o.key:void 0}}function it(t,e,n,r){var o=e[n];if(o){var i=!1;do{if(i=r(o.key,o.attributes,o.source.key,o.target.key,o.source.attributes,o.target.attributes,o.undirected),t&&i)return o.key;o=o.next}while(void 0!==o)}}function at(t,e){var n=t[e];return void 0!==n.next?new P((function(){if(!n)return{done:!0};var t={edge:n.key,attributes:n.attributes,source:n.source.key,target:n.target.key,sourceAttributes:n.source.attributes,targetAttributes:n.target.attributes,undirected:n.undirected};return n=n.next,{done:!1,value:t}})):P.of({edge:n.key,attributes:n.attributes,source:n.source.key,target:n.target.key,sourceAttributes:n.source.attributes,targetAttributes:n.target.attributes,undirected:n.undirected})}function st(t,e,n,r){if(0!==e.size)for(var o,i,a="mixed"!==n&&n!==e.type,s="undirected"===n,u=!1,c=e._edges.values();!0!==(o=c.next()).done;)if(i=o.value,!a||i.undirected===s){var l=i,d=l.key,h=l.attributes,f=l.source,p=l.target;if(u=r(d,h,f.key,p.key,f.attributes,p.attributes,i.undirected),t&&u)return d}}function ut(t,e,n,r,o,i){var a,s=e?nt:et;if("undirected"!==n){if("out"!==r&&(a=s(t,o.in,i),t&&a))return a;if("in"!==r&&(a=s(t,o.out,i,r?void 0:o.key),t&&a))return a}if("directed"!==n&&(a=s(t,o.undirected,i),t&&a))return a}function ct(t,e,n,r,o,i,a){var s,u=n?it:ot;if("undirected"!==e){if(void 0!==o.in&&"out"!==r&&(s=u(t,o.in,i,a),t&&s))return s;if(void 0!==o.out&&"in"!==r&&(r||o.key!==i)&&(s=u(t,o.out,i,a),t&&s))return s}if("directed"!==e&&void 0!==o.undirected&&(s=u(t,o.undirected,i,a),t&&s))return s}var lt=[{name:"neighbors",type:"mixed"},{name:"inNeighbors",type:"directed",direction:"in"},{name:"outNeighbors",type:"directed",direction:"out"},{name:"inboundNeighbors",type:"mixed",direction:"in"},{name:"outboundNeighbors",type:"mixed",direction:"out"},{name:"directedNeighbors",type:"directed"},{name:"undirectedNeighbors",type:"undirected"}];function dt(){this.A=null,this.B=null}function ht(t,e,n,r,o){for(var i in r){var a=r[i],s=a.source,u=a.target,c=s===n?u:s;if(!e||!e.has(c.key)){var l=o(c.key,c.attributes);if(t&&l)return c.key}}}function ft(t,e,n,r,o){if("mixed"!==e){if("undirected"===e)return ht(t,null,r,r.undirected,o);if("string"==typeof n)return ht(t,null,r,r[n],o)}var i,a=new dt;if("undirected"!==e){if("out"!==n){if(i=ht(t,null,r,r.in,o),t&&i)return i;a.wrap(r.in)}if("in"!==n){if(i=ht(t,a,r,r.out,o),t&&i)return i;a.wrap(r.out)}}if("directed"!==e&&(i=ht(t,a,r,r.undirected,o),t&&i))return i}function pt(t,e,n){var r=Object.keys(n),o=r.length,i=0;return new P((function(){var a=null;do{if(i>=o)return t&&t.wrap(n),{done:!0};var s=n[r[i++]],u=s.source,c=s.target;a=u===e?c:u,t&&t.has(a.key)&&(a=null)}while(null===a);return{done:!1,value:{neighbor:a.key,attributes:a.attributes}}}))}function mt(t,e,n,r,o){for(var i,a,s,u,c,l,d,h=r._nodes.values(),f=r.type;!0!==(i=h.next()).done;){var p=!1;if(a=i.value,"undirected"!==f)for(s in u=a.out){c=u[s];do{if(l=c.target,p=!0,d=o(a.key,l.key,a.attributes,l.attributes,c.key,c.attributes,c.undirected),t&&d)return c;c=c.next}while(c)}if("directed"!==f)for(s in u=a.undirected)if(!(e&&a.key>s)){c=u[s];do{if((l=c.target).key!==s&&(l=c.source),p=!0,d=o(a.key,l.key,a.attributes,l.attributes,c.key,c.attributes,c.undirected),t&&d)return c;c=c.next}while(c)}if(n&&!p&&(d=o(a.key,null,a.attributes,null,null,null,null),t&&d))return null}}function gt(t){if(!c(t))throw new V('Graph.import: invalid serialized node. A serialized node should be a plain object with at least a "key" property.');if(!("key"in t))throw new V("Graph.import: serialized node is missing its key.");if("attributes"in t&&(!c(t.attributes)||null===t.attributes))throw new V("Graph.import: invalid attributes. Attributes should be a plain object, null or omitted.")}function yt(t){if(!c(t))throw new V('Graph.import: invalid serialized edge. A serialized edge should be a plain object with at least a "source" & "target" property.');if(!("source"in t))throw new V("Graph.import: serialized edge is missing its source.");if(!("target"in t))throw new V("Graph.import: serialized edge is missing its target.");if("attributes"in t&&(!c(t.attributes)||null===t.attributes))throw new V("Graph.import: invalid attributes. Attributes should be a plain object, null or omitted.");if("undirected"in t&&"boolean"!=typeof t.undirected)throw new V("Graph.import: invalid undirectedness information. Undirected should be boolean or omitted.")}dt.prototype.wrap=function(t){null===this.A?this.A=t:null===this.B&&(this.B=t)},dt.prototype.has=function(t){return null!==this.A&&t in this.A||null!==this.B&&t in this.B};var vt,wt=(vt=255&Math.floor(256*Math.random()),function(){return vt++}),bt=new Set(["directed","undirected","mixed"]),Et=new Set(["domain","_events","_eventsCount","_maxListeners"]),At={allowSelfLoops:!0,multi:!1,type:"mixed"};function Ct(t,e,n){var r=new t.NodeDataClass(e,n);return t._nodes.set(e,r),t.emit("nodeAdded",{key:e,attributes:n}),r}function St(t,e,n,r,o,i,a,s){if(!r&&"undirected"===t.type)throw new j("Graph.".concat(e,": you cannot add a directed edge to an undirected graph. Use the #.addEdge or #.addUndirectedEdge instead."));if(r&&"directed"===t.type)throw new j("Graph.".concat(e,": you cannot add an undirected edge to a directed graph. Use the #.addEdge or #.addDirectedEdge instead."));if(s&&!c(s))throw new V("Graph.".concat(e,': invalid attributes. Expecting an object but got "').concat(s,'"'));if(i=""+i,a=""+a,s=s||{},!t.allowSelfLoops&&i===a)throw new j("Graph.".concat(e,': source & target are the same ("').concat(i,"\"), thus creating a loop explicitly forbidden by this graph 'allowSelfLoops' option set to false."));var u=t._nodes.get(i),l=t._nodes.get(a);if(!u)throw new W("Graph.".concat(e,': source node "').concat(i,'" not found.'));if(!l)throw new W("Graph.".concat(e,': target node "').concat(a,'" not found.'));var d={key:null,undirected:r,source:i,target:a,attributes:s};if(n)o=t._edgeKeyGenerator();else if(o=""+o,t._edges.has(o))throw new j("Graph.".concat(e,': the "').concat(o,'" edge already exists in the graph.'));if(!t.multi&&(r?void 0!==u.undirected[a]:void 0!==u.out[a]))throw new j("Graph.".concat(e,': an edge linking "').concat(i,'" to "').concat(a,"\" already exists. If you really want to add multiple edges linking those nodes, you should create a multi graph by using the 'multi' option."));var h=new H(r,o,u,l,s);t._edges.set(o,h);var f=i===a;return r?(u.undirectedDegree++,l.undirectedDegree++,f&&(u.undirectedLoops++,t._undirectedSelfLoopCount++)):(u.outDegree++,l.inDegree++,f&&(u.directedLoops++,t._directedSelfLoopCount++)),t.multi?h.attachMulti():h.attach(),r?t._undirectedSize++:t._directedSize++,d.key=o,t.emit("edgeAdded",d),o}function _t(t,e,n,r,o,i,a,u,l){if(!r&&"undirected"===t.type)throw new j("Graph.".concat(e,": you cannot merge/update a directed edge to an undirected graph. Use the #.mergeEdge/#.updateEdge or #.addUndirectedEdge instead."));if(r&&"directed"===t.type)throw new j("Graph.".concat(e,": you cannot merge/update an undirected edge to a directed graph. Use the #.mergeEdge/#.updateEdge or #.addDirectedEdge instead."));if(u)if(l){if("function"!=typeof u)throw new V("Graph.".concat(e,': invalid updater function. Expecting a function but got "').concat(u,'"'))}else if(!c(u))throw new V("Graph.".concat(e,': invalid attributes. Expecting an object but got "').concat(u,'"'));var d;if(i=""+i,a=""+a,l&&(d=u,u=void 0),!t.allowSelfLoops&&i===a)throw new j("Graph.".concat(e,': source & target are the same ("').concat(i,"\"), thus creating a loop explicitly forbidden by this graph 'allowSelfLoops' option set to false."));var h,f,p=t._nodes.get(i),m=t._nodes.get(a);if(!n&&(h=t._edges.get(o))){if(!(h.source.key===i&&h.target.key===a||r&&h.source.key===a&&h.target.key===i))throw new j("Graph.".concat(e,': inconsistency detected when attempting to merge the "').concat(o,'" edge with "').concat(i,'" source & "').concat(a,'" target vs. ("').concat(h.source.key,'", "').concat(h.target.key,'").'));f=h}if(f||t.multi||!p||(f=r?p.undirected[a]:p.out[a]),f){var g=[f.key,!1,!1,!1];if(l?!d:!u)return g;if(l){var y=f.attributes;f.attributes=d(y),t.emit("edgeAttributesUpdated",{type:"replace",key:f.key,attributes:f.attributes})}else s(f.attributes,u),t.emit("edgeAttributesUpdated",{type:"merge",key:f.key,attributes:f.attributes,data:u});return g}u=u||{},l&&d&&(u=d(u));var v={key:null,undirected:r,source:i,target:a,attributes:u};if(n)o=t._edgeKeyGenerator();else if(o=""+o,t._edges.has(o))throw new j("Graph.".concat(e,': the "').concat(o,'" edge already exists in the graph.'));var w=!1,b=!1;p||(p=Ct(t,i,{}),w=!0,i===a&&(m=p,b=!0)),m||(m=Ct(t,a,{}),b=!0),h=new H(r,o,p,m,u),t._edges.set(o,h);var E=i===a;return r?(p.undirectedDegree++,m.undirectedDegree++,E&&(p.undirectedLoops++,t._undirectedSelfLoopCount++)):(p.outDegree++,m.inDegree++,E&&(p.directedLoops++,t._directedSelfLoopCount++)),t.multi?h.attachMulti():h.attach(),r?t._undirectedSize++:t._directedSize++,v.key=o,t.emit("edgeAdded",v),[o,!0,w,b]}function Nt(t,e){t._edges.delete(e.key);var n=e.source,r=e.target,o=e.attributes,i=e.undirected,a=n===r;i?(n.undirectedDegree--,r.undirectedDegree--,a&&(n.undirectedLoops--,t._undirectedSelfLoopCount--)):(n.outDegree--,r.inDegree--,a&&(n.directedLoops--,t._directedSelfLoopCount--)),t.multi?e.detachMulti():e.detach(),i?t._undirectedSize--:t._directedSize--,t.emit("edgeDropped",{key:e.key,attributes:o,source:n.key,target:r.key,undirected:i})}var It=function(n){function r(t){var e;if(e=n.call(this)||this,"boolean"!=typeof(t=s({},At,t)).multi)throw new V("Graph.constructor: invalid 'multi' option. Expecting a boolean but got \"".concat(t.multi,'".'));if(!bt.has(t.type))throw new V('Graph.constructor: invalid \'type\' option. Should be one of "mixed", "directed" or "undirected" but got "'.concat(t.type,'".'));if("boolean"!=typeof t.allowSelfLoops)throw new V("Graph.constructor: invalid 'allowSelfLoops' option. Expecting a boolean but got \"".concat(t.allowSelfLoops,'".'));var r="mixed"===t.type?Y:"directed"===t.type?z:q;d(a(e),"NodeDataClass",r);var o="geid_"+wt()+"_",i=0;return d(a(e),"_attributes",{}),d(a(e),"_nodes",new Map),d(a(e),"_edges",new Map),d(a(e),"_directedSize",0),d(a(e),"_undirectedSize",0),d(a(e),"_directedSelfLoopCount",0),d(a(e),"_undirectedSelfLoopCount",0),d(a(e),"_edgeKeyGenerator",(function(){var t;do{t=o+i++}while(e._edges.has(t));return t})),d(a(e),"_options",t),Et.forEach((function(t){return d(a(e),t,e[t])})),h(a(e),"order",(function(){return e._nodes.size})),h(a(e),"size",(function(){return e._edges.size})),h(a(e),"directedSize",(function(){return e._directedSize})),h(a(e),"undirectedSize",(function(){return e._undirectedSize})),h(a(e),"selfLoopCount",(function(){return e._directedSelfLoopCount+e._undirectedSelfLoopCount})),h(a(e),"directedSelfLoopCount",(function(){return e._directedSelfLoopCount})),h(a(e),"undirectedSelfLoopCount",(function(){return e._undirectedSelfLoopCount})),h(a(e),"multi",e._options.multi),h(a(e),"type",e._options.type),h(a(e),"allowSelfLoops",e._options.allowSelfLoops),h(a(e),"implementation",(function(){return"graphology"})),e}e(r,n);var o=r.prototype;return o._resetInstanceCounters=function(){this._directedSize=0,this._undirectedSize=0,this._directedSelfLoopCount=0,this._undirectedSelfLoopCount=0},o.hasNode=function(t){return this._nodes.has(""+t)},o.hasDirectedEdge=function(t,e){if("undirected"===this.type)return!1;if(1===arguments.length){var n=""+t,r=this._edges.get(n);return!!r&&!r.undirected}if(2===arguments.length){t=""+t,e=""+e;var o=this._nodes.get(t);return!!o&&o.out.hasOwnProperty(e)}throw new V("Graph.hasDirectedEdge: invalid arity (".concat(arguments.length,", instead of 1 or 2). You can either ask for an edge id or for the existence of an edge between a source & a target."))},o.hasUndirectedEdge=function(t,e){if("directed"===this.type)return!1;if(1===arguments.length){var n=""+t,r=this._edges.get(n);return!!r&&r.undirected}if(2===arguments.length){t=""+t,e=""+e;var o=this._nodes.get(t);return!!o&&o.undirected.hasOwnProperty(e)}throw new V("Graph.hasDirectedEdge: invalid arity (".concat(arguments.length,", instead of 1 or 2). You can either ask for an edge id or for the existence of an edge between a source & a target."))},o.hasEdge=function(t,e){if(1===arguments.length){var n=""+t;return this._edges.has(n)}if(2===arguments.length){t=""+t,e=""+e;var r=this._nodes.get(t);return!!r&&(void 0!==r.out&&r.out.hasOwnProperty(e)||void 0!==r.undirected&&r.undirected.hasOwnProperty(e))}throw new V("Graph.hasEdge: invalid arity (".concat(arguments.length,", instead of 1 or 2). You can either ask for an edge id or for the existence of an edge between a source & a target."))},o.directedEdge=function(t,e){if("undirected"!==this.type){if(t=""+t,e=""+e,this.multi)throw new j("Graph.directedEdge: this method is irrelevant with multigraphs since there might be multiple edges between source & target. See #.directedEdges instead.");var n=this._nodes.get(t);if(!n)throw new W('Graph.directedEdge: could not find the "'.concat(t,'" source node in the graph.'));if(!this._nodes.has(e))throw new W('Graph.directedEdge: could not find the "'.concat(e,'" target node in the graph.'));var r=n.out&&n.out[e]||void 0;return r?r.key:void 0}},o.undirectedEdge=function(t,e){if("directed"!==this.type){if(t=""+t,e=""+e,this.multi)throw new j("Graph.undirectedEdge: this method is irrelevant with multigraphs since there might be multiple edges between source & target. See #.undirectedEdges instead.");var n=this._nodes.get(t);if(!n)throw new W('Graph.undirectedEdge: could not find the "'.concat(t,'" source node in the graph.'));if(!this._nodes.has(e))throw new W('Graph.undirectedEdge: could not find the "'.concat(e,'" target node in the graph.'));var r=n.undirected&&n.undirected[e]||void 0;return r?r.key:void 0}},o.edge=function(t,e){if(this.multi)throw new j("Graph.edge: this method is irrelevant with multigraphs since there might be multiple edges between source & target. See #.edges instead.");t=""+t,e=""+e;var n=this._nodes.get(t);if(!n)throw new W('Graph.edge: could not find the "'.concat(t,'" source node in the graph.'));if(!this._nodes.has(e))throw new W('Graph.edge: could not find the "'.concat(e,'" target node in the graph.'));var r=n.out&&n.out[e]||n.undirected&&n.undirected[e]||void 0;if(r)return r.key},o.areDirectedNeighbors=function(t,e){t=""+t,e=""+e;var n=this._nodes.get(t);if(!n)throw new W('Graph.areDirectedNeighbors: could not find the "'.concat(t,'" node in the graph.'));return"undirected"!==this.type&&(e in n.in||e in n.out)},o.areOutNeighbors=function(t,e){t=""+t,e=""+e;var n=this._nodes.get(t);if(!n)throw new W('Graph.areOutNeighbors: could not find the "'.concat(t,'" node in the graph.'));return"undirected"!==this.type&&e in n.out},o.areInNeighbors=function(t,e){t=""+t,e=""+e;var n=this._nodes.get(t);if(!n)throw new W('Graph.areInNeighbors: could not find the "'.concat(t,'" node in the graph.'));return"undirected"!==this.type&&e in n.in},o.areUndirectedNeighbors=function(t,e){t=""+t,e=""+e;var n=this._nodes.get(t);if(!n)throw new W('Graph.areUndirectedNeighbors: could not find the "'.concat(t,'" node in the graph.'));return"directed"!==this.type&&e in n.undirected},o.areNeighbors=function(t,e){t=""+t,e=""+e;var n=this._nodes.get(t);if(!n)throw new W('Graph.areNeighbors: could not find the "'.concat(t,'" node in the graph.'));return"undirected"!==this.type&&(e in n.in||e in n.out)||"directed"!==this.type&&e in n.undirected},o.areInboundNeighbors=function(t,e){t=""+t,e=""+e;var n=this._nodes.get(t);if(!n)throw new W('Graph.areInboundNeighbors: could not find the "'.concat(t,'" node in the graph.'));return"undirected"!==this.type&&e in n.in||"directed"!==this.type&&e in n.undirected},o.areOutboundNeighbors=function(t,e){t=""+t,e=""+e;var n=this._nodes.get(t);if(!n)throw new W('Graph.areOutboundNeighbors: could not find the "'.concat(t,'" node in the graph.'));return"undirected"!==this.type&&e in n.out||"directed"!==this.type&&e in n.undirected},o.inDegree=function(t){t=""+t;var e=this._nodes.get(t);if(!e)throw new W('Graph.inDegree: could not find the "'.concat(t,'" node in the graph.'));return"undirected"===this.type?0:e.inDegree},o.outDegree=function(t){t=""+t;var e=this._nodes.get(t);if(!e)throw new W('Graph.outDegree: could not find the "'.concat(t,'" node in the graph.'));return"undirected"===this.type?0:e.outDegree},o.directedDegree=function(t){t=""+t;var e=this._nodes.get(t);if(!e)throw new W('Graph.directedDegree: could not find the "'.concat(t,'" node in the graph.'));return"undirected"===this.type?0:e.inDegree+e.outDegree},o.undirectedDegree=function(t){t=""+t;var e=this._nodes.get(t);if(!e)throw new W('Graph.undirectedDegree: could not find the "'.concat(t,'" node in the graph.'));return"directed"===this.type?0:e.undirectedDegree},o.inboundDegree=function(t){t=""+t;var e=this._nodes.get(t);if(!e)throw new W('Graph.inboundDegree: could not find the "'.concat(t,'" node in the graph.'));var n=0;return"directed"!==this.type&&(n+=e.undirectedDegree),"undirected"!==this.type&&(n+=e.inDegree),n},o.outboundDegree=function(t){t=""+t;var e=this._nodes.get(t);if(!e)throw new W('Graph.outboundDegree: could not find the "'.concat(t,'" node in the graph.'));var n=0;return"directed"!==this.type&&(n+=e.undirectedDegree),"undirected"!==this.type&&(n+=e.outDegree),n},o.degree=function(t){t=""+t;var e=this._nodes.get(t);if(!e)throw new W('Graph.degree: could not find the "'.concat(t,'" node in the graph.'));var n=0;return"directed"!==this.type&&(n+=e.undirectedDegree),"undirected"!==this.type&&(n+=e.inDegree+e.outDegree),n},o.inDegreeWithoutSelfLoops=function(t){t=""+t;var e=this._nodes.get(t);if(!e)throw new W('Graph.inDegreeWithoutSelfLoops: could not find the "'.concat(t,'" node in the graph.'));return"undirected"===this.type?0:e.inDegree-e.directedLoops},o.outDegreeWithoutSelfLoops=function(t){t=""+t;var e=this._nodes.get(t);if(!e)throw new W('Graph.outDegreeWithoutSelfLoops: could not find the "'.concat(t,'" node in the graph.'));return"undirected"===this.type?0:e.outDegree-e.directedLoops},o.directedDegreeWithoutSelfLoops=function(t){t=""+t;var e=this._nodes.get(t);if(!e)throw new W('Graph.directedDegreeWithoutSelfLoops: could not find the "'.concat(t,'" node in the graph.'));return"undirected"===this.type?0:e.inDegree+e.outDegree-2*e.directedLoops},o.undirectedDegreeWithoutSelfLoops=function(t){t=""+t;var e=this._nodes.get(t);if(!e)throw new W('Graph.undirectedDegreeWithoutSelfLoops: could not find the "'.concat(t,'" node in the graph.'));return"directed"===this.type?0:e.undirectedDegree-2*e.undirectedLoops},o.inboundDegreeWithoutSelfLoops=function(t){t=""+t;var e=this._nodes.get(t);if(!e)throw new W('Graph.inboundDegreeWithoutSelfLoops: could not find the "'.concat(t,'" node in the graph.'));var n=0,r=0;return"directed"!==this.type&&(n+=e.undirectedDegree,r+=2*e.undirectedLoops),"undirected"!==this.type&&(n+=e.inDegree,r+=e.directedLoops),n-r},o.outboundDegreeWithoutSelfLoops=function(t){t=""+t;var e=this._nodes.get(t);if(!e)throw new W('Graph.outboundDegreeWithoutSelfLoops: could not find the "'.concat(t,'" node in the graph.'));var n=0,r=0;return"directed"!==this.type&&(n+=e.undirectedDegree,r+=2*e.undirectedLoops),"undirected"!==this.type&&(n+=e.outDegree,r+=e.directedLoops),n-r},o.degreeWithoutSelfLoops=function(t){t=""+t;var e=this._nodes.get(t);if(!e)throw new W('Graph.degreeWithoutSelfLoops: could not find the "'.concat(t,'" node in the graph.'));var n=0,r=0;return"directed"!==this.type&&(n+=e.undirectedDegree,r+=2*e.undirectedLoops),"undirected"!==this.type&&(n+=e.inDegree+e.outDegree,r+=2*e.directedLoops),n-r},o.source=function(t){t=""+t;var e=this._edges.get(t);if(!e)throw new W('Graph.source: could not find the "'.concat(t,'" edge in the graph.'));return e.source.key},o.target=function(t){t=""+t;var e=this._edges.get(t);if(!e)throw new W('Graph.target: could not find the "'.concat(t,'" edge in the graph.'));return e.target.key},o.extremities=function(t){t=""+t;var e=this._edges.get(t);if(!e)throw new W('Graph.extremities: could not find the "'.concat(t,'" edge in the graph.'));return[e.source.key,e.target.key]},o.opposite=function(t,e){t=""+t,e=""+e;var n=this._edges.get(e);if(!n)throw new W('Graph.opposite: could not find the "'.concat(e,'" edge in the graph.'));var r=n.source.key,o=n.target.key;if(t===r)return o;if(t===o)return r;throw new W('Graph.opposite: the "'.concat(t,'" node is not attached to the "').concat(e,'" edge (').concat(r,", ").concat(o,")."))},o.hasExtremity=function(t,e){t=""+t,e=""+e;var n=this._edges.get(t);if(!n)throw new W('Graph.hasExtremity: could not find the "'.concat(t,'" edge in the graph.'));return n.source.key===e||n.target.key===e},o.isUndirected=function(t){t=""+t;var e=this._edges.get(t);if(!e)throw new W('Graph.isUndirected: could not find the "'.concat(t,'" edge in the graph.'));return e.undirected},o.isDirected=function(t){t=""+t;var e=this._edges.get(t);if(!e)throw new W('Graph.isDirected: could not find the "'.concat(t,'" edge in the graph.'));return!e.undirected},o.isSelfLoop=function(t){t=""+t;var e=this._edges.get(t);if(!e)throw new W('Graph.isSelfLoop: could not find the "'.concat(t,'" edge in the graph.'));return e.source===e.target},o.addNode=function(t,e){var n=function(t,e,n){if(n&&!c(n))throw new V('Graph.addNode: invalid attributes. Expecting an object but got "'.concat(n,'"'));if(e=""+e,n=n||{},t._nodes.has(e))throw new j('Graph.addNode: the "'.concat(e,'" node already exist in the graph.'));var r=new t.NodeDataClass(e,n);return t._nodes.set(e,r),t.emit("nodeAdded",{key:e,attributes:n}),r}(this,t,e);return n.key},o.mergeNode=function(t,e){if(e&&!c(e))throw new V('Graph.mergeNode: invalid attributes. Expecting an object but got "'.concat(e,'"'));t=""+t,e=e||{};var n=this._nodes.get(t);return n?(e&&(s(n.attributes,e),this.emit("nodeAttributesUpdated",{type:"merge",key:t,attributes:n.attributes,data:e})),[t,!1]):(n=new this.NodeDataClass(t,e),this._nodes.set(t,n),this.emit("nodeAdded",{key:t,attributes:e}),[t,!0])},o.updateNode=function(t,e){if(e&&"function"!=typeof e)throw new V('Graph.updateNode: invalid updater function. Expecting a function but got "'.concat(e,'"'));t=""+t;var n=this._nodes.get(t);if(n){if(e){var r=n.attributes;n.attributes=e(r),this.emit("nodeAttributesUpdated",{type:"replace",key:t,attributes:n.attributes})}return[t,!1]}var o=e?e({}):{};return n=new this.NodeDataClass(t,o),this._nodes.set(t,n),this.emit("nodeAdded",{key:t,attributes:o}),[t,!0]},o.dropNode=function(t){t=""+t;var e,n=this._nodes.get(t);if(!n)throw new W('Graph.dropNode: could not find the "'.concat(t,'" node in the graph.'));if("undirected"!==this.type){for(var r in n.out){e=n.out[r];do{Nt(this,e),e=e.next}while(e)}for(var o in n.in){e=n.in[o];do{Nt(this,e),e=e.next}while(e)}}if("directed"!==this.type)for(var i in n.undirected){e=n.undirected[i];do{Nt(this,e),e=e.next}while(e)}this._nodes.delete(t),this.emit("nodeDropped",{key:t,attributes:n.attributes})},o.dropEdge=function(t){var e;if(arguments.length>1){var n=""+arguments[0],r=""+arguments[1];if(!(e=u(this,n,r,this.type)))throw new W('Graph.dropEdge: could not find the "'.concat(n,'" -> "').concat(r,'" edge in the graph.'))}else if(t=""+t,!(e=this._edges.get(t)))throw new W('Graph.dropEdge: could not find the "'.concat(t,'" edge in the graph.'));return Nt(this,e),this},o.dropDirectedEdge=function(t,e){if(arguments.length<2)throw new j("Graph.dropDirectedEdge: it does not make sense to try and drop a directed edge by key. What if the edge with this key is undirected? Use #.dropEdge for this purpose instead.");if(this.multi)throw new j("Graph.dropDirectedEdge: cannot use a {source,target} combo when dropping an edge in a MultiGraph since we cannot infer the one you want to delete as there could be multiple ones.");var n=u(this,t=""+t,e=""+e,"directed");if(!n)throw new W('Graph.dropDirectedEdge: could not find a "'.concat(t,'" -> "').concat(e,'" edge in the graph.'));return Nt(this,n),this},o.dropUndirectedEdge=function(t,e){if(arguments.length<2)throw new j("Graph.dropUndirectedEdge: it does not make sense to drop a directed edge by key. What if the edge with this key is undirected? Use #.dropEdge for this purpose instead.");if(this.multi)throw new j("Graph.dropUndirectedEdge: cannot use a {source,target} combo when dropping an edge in a MultiGraph since we cannot infer the one you want to delete as there could be multiple ones.");var n=u(this,t,e,"undirected");if(!n)throw new W('Graph.dropUndirectedEdge: could not find a "'.concat(t,'" -> "').concat(e,'" edge in the graph.'));return Nt(this,n),this},o.clear=function(){this._edges.clear(),this._nodes.clear(),this._resetInstanceCounters(),this.emit("cleared")},o.clearEdges=function(){for(var t,e=this._nodes.values();!0!==(t=e.next()).done;)t.value.clear();this._edges.clear(),this._resetInstanceCounters(),this.emit("edgesCleared")},o.getAttribute=function(t){return this._attributes[t]},o.getAttributes=function(){return this._attributes},o.hasAttribute=function(t){return this._attributes.hasOwnProperty(t)},o.setAttribute=function(t,e){return this._attributes[t]=e,this.emit("attributesUpdated",{type:"set",attributes:this._attributes,name:t}),this},o.updateAttribute=function(t,e){if("function"!=typeof e)throw new V("Graph.updateAttribute: updater should be a function.");var n=this._attributes[t];return this._attributes[t]=e(n),this.emit("attributesUpdated",{type:"set",attributes:this._attributes,name:t}),this},o.removeAttribute=function(t){return delete this._attributes[t],this.emit("attributesUpdated",{type:"remove",attributes:this._attributes,name:t}),this},o.replaceAttributes=function(t){if(!c(t))throw new V("Graph.replaceAttributes: provided attributes are not a plain object.");return this._attributes=t,this.emit("attributesUpdated",{type:"replace",attributes:this._attributes}),this},o.mergeAttributes=function(t){if(!c(t))throw new V("Graph.mergeAttributes: provided attributes are not a plain object.");return s(this._attributes,t),this.emit("attributesUpdated",{type:"merge",attributes:this._attributes,data:t}),this},o.updateAttributes=function(t){if("function"!=typeof t)throw new V("Graph.updateAttributes: provided updater is not a function.");return this._attributes=t(this._attributes),this.emit("attributesUpdated",{type:"update",attributes:this._attributes}),this},o.updateEachNodeAttributes=function(t,e){if("function"!=typeof t)throw new V("Graph.updateEachNodeAttributes: expecting an updater function.");if(e&&!f(e))throw new V("Graph.updateEachNodeAttributes: invalid hints. Expecting an object having the following shape: {attributes?: [string]}");for(var n,r,o=this._nodes.values();!0!==(n=o.next()).done;)(r=n.value).attributes=t(r.key,r.attributes);this.emit("eachNodeAttributesUpdated",{hints:e||null})},o.updateEachEdgeAttributes=function(t,e){if("function"!=typeof t)throw new V("Graph.updateEachEdgeAttributes: expecting an updater function.");if(e&&!f(e))throw new V("Graph.updateEachEdgeAttributes: invalid hints. Expecting an object having the following shape: {attributes?: [string]}");for(var n,r,o,i,a=this._edges.values();!0!==(n=a.next()).done;)o=(r=n.value).source,i=r.target,r.attributes=t(r.key,r.attributes,o.key,i.key,o.attributes,i.attributes,r.undirected);this.emit("eachEdgeAttributesUpdated",{hints:e||null})},o.forEachAdjacencyEntry=function(t){if("function"!=typeof t)throw new V("Graph.forEachAdjacencyEntry: expecting a callback.");mt(!1,!1,!1,this,t)},o.forEachAdjacencyEntryWithOrphans=function(t){if("function"!=typeof t)throw new V("Graph.forEachAdjacencyEntryWithOrphans: expecting a callback.");mt(!1,!1,!0,this,t)},o.forEachAssymetricAdjacencyEntry=function(t){if("function"!=typeof t)throw new V("Graph.forEachAssymetricAdjacencyEntry: expecting a callback.");mt(!1,!0,!1,this,t)},o.forEachAssymetricAdjacencyEntryWithOrphans=function(t){if("function"!=typeof t)throw new V("Graph.forEachAssymetricAdjacencyEntryWithOrphans: expecting a callback.");mt(!1,!0,!0,this,t)},o.nodes=function(){return"function"==typeof Array.from?Array.from(this._nodes.keys()):G(this._nodes.keys(),this._nodes.size)},o.forEachNode=function(t){if("function"!=typeof t)throw new V("Graph.forEachNode: expecting a callback.");for(var e,n,r=this._nodes.values();!0!==(e=r.next()).done;)t((n=e.value).key,n.attributes)},o.findNode=function(t){if("function"!=typeof t)throw new V("Graph.findNode: expecting a callback.");for(var e,n,r=this._nodes.values();!0!==(e=r.next()).done;)if(t((n=e.value).key,n.attributes))return n.key},o.mapNodes=function(t){if("function"!=typeof t)throw new V("Graph.mapNode: expecting a callback.");for(var e,n,r=this._nodes.values(),o=new Array(this.order),i=0;!0!==(e=r.next()).done;)n=e.value,o[i++]=t(n.key,n.attributes);return o},o.someNode=function(t){if("function"!=typeof t)throw new V("Graph.someNode: expecting a callback.");for(var e,n,r=this._nodes.values();!0!==(e=r.next()).done;)if(t((n=e.value).key,n.attributes))return!0;return!1},o.everyNode=function(t){if("function"!=typeof t)throw new V("Graph.everyNode: expecting a callback.");for(var e,n,r=this._nodes.values();!0!==(e=r.next()).done;)if(!t((n=e.value).key,n.attributes))return!1;return!0},o.filterNodes=function(t){if("function"!=typeof t)throw new V("Graph.filterNodes: expecting a callback.");for(var e,n,r=this._nodes.values(),o=[];!0!==(e=r.next()).done;)t((n=e.value).key,n.attributes)&&o.push(n.key);return o},o.reduceNodes=function(t,e){if("function"!=typeof t)throw new V("Graph.reduceNodes: expecting a callback.");if(arguments.length<2)throw new V("Graph.reduceNodes: missing initial value. You must provide it because the callback takes more than one argument and we cannot infer the initial value from the first iteration, as you could with a simple array.");for(var n,r,o=e,i=this._nodes.values();!0!==(n=i.next()).done;)o=t(o,(r=n.value).key,r.attributes);return o},o.nodeEntries=function(){var t=this._nodes.values();return new P((function(){var e=t.next();if(e.done)return e;var n=e.value;return{value:{node:n.key,attributes:n.attributes},done:!1}}))},o.export=function(){var t=this,e=new Array(this._nodes.size),n=0;this._nodes.forEach((function(t,r){e[n++]=function(t,e){var n={key:t};return l(e.attributes)||(n.attributes=s({},e.attributes)),n}(r,t)}));var r=new Array(this._edges.size);return n=0,this._edges.forEach((function(e,o){r[n++]=function(t,e,n){var r={key:e,source:n.source.key,target:n.target.key};return l(n.attributes)||(r.attributes=s({},n.attributes)),"mixed"===t&&n.undirected&&(r.undirected=!0),r}(t.type,o,e)})),{options:{type:this.type,multi:this.multi,allowSelfLoops:this.allowSelfLoops},attributes:this.getAttributes(),nodes:e,edges:r}},o.import=function(t){var e,n,o,i,a,s=this,u=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(t instanceof r)return t.forEachNode((function(t,e){u?s.mergeNode(t,e):s.addNode(t,e)})),t.forEachEdge((function(t,e,n,r,o,i,a){u?a?s.mergeUndirectedEdgeWithKey(t,n,r,e):s.mergeDirectedEdgeWithKey(t,n,r,e):a?s.addUndirectedEdgeWithKey(t,n,r,e):s.addDirectedEdgeWithKey(t,n,r,e)})),this;if(!c(t))throw new V("Graph.import: invalid argument. Expecting a serialized graph or, alternatively, a Graph instance.");if(t.attributes){if(!c(t.attributes))throw new V("Graph.import: invalid attributes. Expecting a plain object.");u?this.mergeAttributes(t.attributes):this.replaceAttributes(t.attributes)}if(t.nodes){if(o=t.nodes,!Array.isArray(o))throw new V("Graph.import: invalid nodes. Expecting an array.");for(e=0,n=o.length;e<n;e++){gt(i=o[e]);var l=i,d=l.key,h=l.attributes;u?this.mergeNode(d,h):this.addNode(d,h)}}if(t.edges){var f=!1;if("undirected"===this.type&&(f=!0),o=t.edges,!Array.isArray(o))throw new V("Graph.import: invalid edges. Expecting an array.");for(e=0,n=o.length;e<n;e++){yt(a=o[e]);var p=a,m=p.source,g=p.target,y=p.attributes,v=p.undirected,w=void 0===v?f:v;"key"in a?(u?w?this.mergeUndirectedEdgeWithKey:this.mergeDirectedEdgeWithKey:w?this.addUndirectedEdgeWithKey:this.addDirectedEdgeWithKey).call(this,a.key,m,g,y):(u?w?this.mergeUndirectedEdge:this.mergeDirectedEdge:w?this.addUndirectedEdge:this.addDirectedEdge).call(this,m,g,y)}}return this},o.nullCopy=function(t){var e=new r(s({},this._options,t));return e.replaceAttributes(s({},this.getAttributes())),e},o.emptyCopy=function(t){var e=this.nullCopy(t);return this._nodes.forEach((function(t,n){var r=s({},t.attributes);t=new e.NodeDataClass(n,r),e._nodes.set(n,t)})),e},o.copy=function(t){if("string"==typeof(t=t||{}).type&&t.type!==this.type&&"mixed"!==t.type)throw new j('Graph.copy: cannot create an incompatible copy from "'.concat(this.type,'" type to "').concat(t.type,'" because this would mean losing information about the current graph.'));if("boolean"==typeof t.multi&&t.multi!==this.multi&&!0!==t.multi)throw new j("Graph.copy: cannot create an incompatible copy by downgrading a multi graph to a simple one because this would mean losing information about the current graph.");if("boolean"==typeof t.allowSelfLoops&&t.allowSelfLoops!==this.allowSelfLoops&&!0!==t.allowSelfLoops)throw new j("Graph.copy: cannot create an incompatible copy from a graph allowing self loops to one that does not because this would mean losing information about the current graph.");for(var e,n,r=this.emptyCopy(t),o=this._edges.values();!0!==(e=o.next()).done;)St(r,"copy",!1,(n=e.value).undirected,n.key,n.source.key,n.target.key,s({},n.attributes));return r},o.toJSON=function(){return this.export()},o.toString=function(){return"[object Graph]"},o.inspect=function(){var e=this,n={};this._nodes.forEach((function(t,e){n[e]=t.attributes}));var r={},o={};this._edges.forEach((function(t,n){var i,a=t.undirected?"--":"->",s="",u=t.source.key,c=t.target.key;t.undirected&&u>c&&(i=u,u=c,c=i);var l="(".concat(u,")").concat(a,"(").concat(c,")");n.startsWith("geid_")?e.multi&&(void 0===o[l]?o[l]=0:o[l]++,s+="".concat(o[l],". ")):s+="[".concat(n,"]: "),r[s+=l]=t.attributes}));var i={};for(var a in this)this.hasOwnProperty(a)&&!Et.has(a)&&"function"!=typeof this[a]&&"symbol"!==t(a)&&(i[a]=this[a]);return i.attributes=this._attributes,i.nodes=n,i.edges=r,d(i,"constructor",this.constructor),i},r}(m.exports.EventEmitter);"undefined"!=typeof Symbol&&(It.prototype[Symbol.for("nodejs.util.inspect.custom")]=It.prototype.inspect),[{name:function(t){return"".concat(t,"Edge")},generateKey:!0},{name:function(t){return"".concat(t,"DirectedEdge")},generateKey:!0,type:"directed"},{name:function(t){return"".concat(t,"UndirectedEdge")},generateKey:!0,type:"undirected"},{name:function(t){return"".concat(t,"EdgeWithKey")}},{name:function(t){return"".concat(t,"DirectedEdgeWithKey")},type:"directed"},{name:function(t){return"".concat(t,"UndirectedEdgeWithKey")},type:"undirected"}].forEach((function(t){["add","merge","update"].forEach((function(e){var n=t.name(e),r="add"===e?St:_t;t.generateKey?It.prototype[n]=function(o,i,a){return r(this,n,!0,"undirected"===(t.type||this.type),null,o,i,a,"update"===e)}:It.prototype[n]=function(o,i,a,s){return r(this,n,!1,"undirected"===(t.type||this.type),o,i,a,s,"update"===e)}}))})),function(t){K.forEach((function(e){var n=e.name,r=e.attacher;r(t,n("Node"),0),r(t,n("Source"),1),r(t,n("Target"),2),r(t,n("Opposite"),3)}))}(It),function(t){X.forEach((function(e){var n=e.name,r=e.attacher;r(t,n("Edge"),"mixed"),r(t,n("DirectedEdge"),"directed"),r(t,n("UndirectedEdge"),"undirected")}))}(It),function(t){tt.forEach((function(e){!function(t,e){var n=e.name,r=e.type,o=e.direction;t.prototype[n]=function(t,e){if("mixed"!==r&&"mixed"!==this.type&&r!==this.type)return[];if(!arguments.length)return function(t,e){if(0===t.size)return[];if("mixed"===e||e===t.type)return"function"==typeof Array.from?Array.from(t._edges.keys()):G(t._edges.keys(),t._edges.size);for(var n,r,o="undirected"===e?t.undirectedSize:t.directedSize,i=new Array(o),a="undirected"===e,s=t._edges.values(),u=0;!0!==(n=s.next()).done;)(r=n.value).undirected===a&&(i[u++]=r.key);return i}(this,r);if(1===arguments.length){t=""+t;var i=this._nodes.get(t);if(void 0===i)throw new W("Graph.".concat(n,': could not find the "').concat(t,'" node in the graph.'));return function(t,e,n,r){var o=[];return ut(!1,t,e,n,r,(function(t){o.push(t)})),o}(this.multi,"mixed"===r?this.type:r,o,i)}if(2===arguments.length){t=""+t,e=""+e;var a=this._nodes.get(t);if(!a)throw new W("Graph.".concat(n,': could not find the "').concat(t,'" source node in the graph.'));if(!this._nodes.has(e))throw new W("Graph.".concat(n,': could not find the "').concat(e,'" target node in the graph.'));return function(t,e,n,r,o){var i=[];return ct(!1,t,e,n,r,o,(function(t){i.push(t)})),i}(r,this.multi,o,a,e)}throw new V("Graph.".concat(n,": too many arguments (expecting 0, 1 or 2 and got ").concat(arguments.length,")."))}}(t,e),function(t,e){var n=e.name,r=e.type,o=e.direction,i="forEach"+n[0].toUpperCase()+n.slice(1,-1);t.prototype[i]=function(t,e,n){if("mixed"===r||"mixed"===this.type||r===this.type){if(1===arguments.length)return st(!1,this,r,n=t);if(2===arguments.length){t=""+t,n=e;var a=this._nodes.get(t);if(void 0===a)throw new W("Graph.".concat(i,': could not find the "').concat(t,'" node in the graph.'));return ut(!1,this.multi,"mixed"===r?this.type:r,o,a,n)}if(3===arguments.length){t=""+t,e=""+e;var s=this._nodes.get(t);if(!s)throw new W("Graph.".concat(i,': could not find the "').concat(t,'" source node in the graph.'));if(!this._nodes.has(e))throw new W("Graph.".concat(i,': could not find the "').concat(e,'" target node in the graph.'));return ct(!1,r,this.multi,o,s,e,n)}throw new V("Graph.".concat(i,": too many arguments (expecting 1, 2 or 3 and got ").concat(arguments.length,")."))}};var a="map"+n[0].toUpperCase()+n.slice(1);t.prototype[a]=function(){var t,e=Array.prototype.slice.call(arguments),n=e.pop();if(0===e.length){var o=0;"directed"!==r&&(o+=this.undirectedSize),"undirected"!==r&&(o+=this.directedSize),t=new Array(o);var a=0;e.push((function(e,r,o,i,s,u,c){t[a++]=n(e,r,o,i,s,u,c)}))}else t=[],e.push((function(e,r,o,i,a,s,u){t.push(n(e,r,o,i,a,s,u))}));return this[i].apply(this,e),t};var s="filter"+n[0].toUpperCase()+n.slice(1);t.prototype[s]=function(){var t=Array.prototype.slice.call(arguments),e=t.pop(),n=[];return t.push((function(t,r,o,i,a,s,u){e(t,r,o,i,a,s,u)&&n.push(t)})),this[i].apply(this,t),n};var u="reduce"+n[0].toUpperCase()+n.slice(1);t.prototype[u]=function(){var t,e,n=Array.prototype.slice.call(arguments);if(n.length<2||n.length>4)throw new V("Graph.".concat(u,": invalid number of arguments (expecting 2, 3 or 4 and got ").concat(n.length,")."));if("function"==typeof n[n.length-1]&&"function"!=typeof n[n.length-2])throw new V("Graph.".concat(u,": missing initial value. You must provide it because the callback takes more than one argument and we cannot infer the initial value from the first iteration, as you could with a simple array."));2===n.length?(t=n[0],e=n[1],n=[]):3===n.length?(t=n[1],e=n[2],n=[n[0]]):4===n.length&&(t=n[2],e=n[3],n=[n[0],n[1]]);var r=e;return n.push((function(e,n,o,i,a,s,u){r=t(r,e,n,o,i,a,s,u)})),this[i].apply(this,n),r}}(t,e),function(t,e){var n=e.name,r=e.type,o=e.direction,i="find"+n[0].toUpperCase()+n.slice(1,-1);t.prototype[i]=function(t,e,n){if("mixed"!==r&&"mixed"!==this.type&&r!==this.type)return!1;if(1===arguments.length)return st(!0,this,r,n=t);if(2===arguments.length){t=""+t,n=e;var a=this._nodes.get(t);if(void 0===a)throw new W("Graph.".concat(i,': could not find the "').concat(t,'" node in the graph.'));return ut(!0,this.multi,"mixed"===r?this.type:r,o,a,n)}if(3===arguments.length){t=""+t,e=""+e;var s=this._nodes.get(t);if(!s)throw new W("Graph.".concat(i,': could not find the "').concat(t,'" source node in the graph.'));if(!this._nodes.has(e))throw new W("Graph.".concat(i,': could not find the "').concat(e,'" target node in the graph.'));return ct(!0,r,this.multi,o,s,e,n)}throw new V("Graph.".concat(i,": too many arguments (expecting 1, 2 or 3 and got ").concat(arguments.length,")."))};var a="some"+n[0].toUpperCase()+n.slice(1,-1);t.prototype[a]=function(){var t=Array.prototype.slice.call(arguments),e=t.pop();return t.push((function(t,n,r,o,i,a,s){return e(t,n,r,o,i,a,s)})),!!this[i].apply(this,t)};var s="every"+n[0].toUpperCase()+n.slice(1,-1);t.prototype[s]=function(){var t=Array.prototype.slice.call(arguments),e=t.pop();return t.push((function(t,n,r,o,i,a,s){return!e(t,n,r,o,i,a,s)})),!this[i].apply(this,t)}}(t,e),function(t,e){var n=e.name,r=e.type,o=e.direction,i=n.slice(0,-1)+"Entries";t.prototype[i]=function(t,e){if("mixed"!==r&&"mixed"!==this.type&&r!==this.type)return P.empty();if(!arguments.length)return function(t,e){if(0===t.size)return P.empty();var n="mixed"!==e&&e!==t.type,r="undirected"===e,o=t._edges.values();return new P((function(){for(var t,e;;){if((t=o.next()).done)return t;if(e=t.value,!n||e.undirected===r)break}return{value:{edge:e.key,attributes:e.attributes,source:e.source.key,target:e.target.key,sourceAttributes:e.source.attributes,targetAttributes:e.target.attributes,undirected:e.undirected},done:!1}}))}(this,r);if(1===arguments.length){t=""+t;var n=this._nodes.get(t);if(!n)throw new W("Graph.".concat(i,': could not find the "').concat(t,'" node in the graph.'));return function(t,e,n){var r=P.empty();return"undirected"!==t&&("out"!==e&&void 0!==n.in&&(r=Z(r,rt(n.in))),"in"!==e&&void 0!==n.out&&(r=Z(r,rt(n.out,e?void 0:n.key)))),"directed"!==t&&void 0!==n.undirected&&(r=Z(r,rt(n.undirected))),r}(r,o,n)}if(2===arguments.length){t=""+t,e=""+e;var a=this._nodes.get(t);if(!a)throw new W("Graph.".concat(i,': could not find the "').concat(t,'" source node in the graph.'));if(!this._nodes.has(e))throw new W("Graph.".concat(i,': could not find the "').concat(e,'" target node in the graph.'));return function(t,e,n,r){var o=P.empty();return"undirected"!==t&&(void 0!==n.in&&"out"!==e&&r in n.in&&(o=Z(o,at(n.in,r))),void 0!==n.out&&"in"!==e&&r in n.out&&(e||n.key!==r)&&(o=Z(o,at(n.out,r)))),"directed"!==t&&void 0!==n.undirected&&r in n.undirected&&(o=Z(o,at(n.undirected,r))),o}(r,o,a,e)}throw new V("Graph.".concat(i,": too many arguments (expecting 0, 1 or 2 and got ").concat(arguments.length,")."))}}(t,e)}))}(It),function(t){lt.forEach((function(e){(function(t,e){var n=e.name,r=e.type,o=e.direction;t.prototype[n]=function(t){if("mixed"!==r&&"mixed"!==this.type&&r!==this.type)return[];t=""+t;var e=this._nodes.get(t);if(void 0===e)throw new W("Graph.".concat(n,': could not find the "').concat(t,'" node in the graph.'));return function(t,e,n){if("mixed"!==t){if("undirected"===t)return Object.keys(n.undirected);if("string"==typeof e)return Object.keys(n[e])}var r=[];return ft(!1,t,e,n,(function(t){r.push(t)})),r}("mixed"===r?this.type:r,o,e)}})(t,e),function(t,e){var n=e.name,r=e.type,o=e.direction,i="forEach"+n[0].toUpperCase()+n.slice(1,-1);t.prototype[i]=function(t,e){if("mixed"===r||"mixed"===this.type||r===this.type){t=""+t;var n=this._nodes.get(t);if(void 0===n)throw new W("Graph.".concat(i,': could not find the "').concat(t,'" node in the graph.'));ft(!1,"mixed"===r?this.type:r,o,n,e)}};var a="map"+n[0].toUpperCase()+n.slice(1);t.prototype[a]=function(t,e){var n=[];return this[i](t,(function(t,r){n.push(e(t,r))})),n};var s="filter"+n[0].toUpperCase()+n.slice(1);t.prototype[s]=function(t,e){var n=[];return this[i](t,(function(t,r){e(t,r)&&n.push(t)})),n};var u="reduce"+n[0].toUpperCase()+n.slice(1);t.prototype[u]=function(t,e,n){if(arguments.length<3)throw new V("Graph.".concat(u,": missing initial value. You must provide it because the callback takes more than one argument and we cannot infer the initial value from the first iteration, as you could with a simple array."));var r=n;return this[i](t,(function(t,n){r=e(r,t,n)})),r}}(t,e),function(t,e){var n=e.name,r=e.type,o=e.direction,i=n[0].toUpperCase()+n.slice(1,-1),a="find"+i;t.prototype[a]=function(t,e){if("mixed"===r||"mixed"===this.type||r===this.type){t=""+t;var n=this._nodes.get(t);if(void 0===n)throw new W("Graph.".concat(a,': could not find the "').concat(t,'" node in the graph.'));return ft(!0,"mixed"===r?this.type:r,o,n,e)}};var s="some"+i;t.prototype[s]=function(t,e){return!!this[a](t,e)};var u="every"+i;t.prototype[u]=function(t,e){return!this[a](t,(function(t,n){return!e(t,n)}))}}(t,e),function(t,e){var n=e.name,r=e.type,o=e.direction,i=n.slice(0,-1)+"Entries";t.prototype[i]=function(t){if("mixed"!==r&&"mixed"!==this.type&&r!==this.type)return P.empty();t=""+t;var e=this._nodes.get(t);if(void 0===e)throw new W("Graph.".concat(i,': could not find the "').concat(t,'" node in the graph.'));return function(t,e,n){if("mixed"!==t){if("undirected"===t)return pt(null,n,n.undirected);if("string"==typeof e)return pt(null,n,n[e])}var r=P.empty(),o=new dt;return"undirected"!==t&&("out"!==e&&(r=Z(r,pt(o,n,n.in))),"in"!==e&&(r=Z(r,pt(o,n,n.out)))),"directed"!==t&&(r=Z(r,pt(o,n,n.undirected))),r}("mixed"===r?this.type:r,o,e)}}(t,e)}))}(It);var Mt=function(t){function n(e){var n=s({type:"directed"},e);if("multi"in n&&!1!==n.multi)throw new V("DirectedGraph.from: inconsistent indication that the graph should be multi in given options!");if("directed"!==n.type)throw new V('DirectedGraph.from: inconsistent "'+n.type+'" type in given options!');return t.call(this,n)||this}return e(n,t),n}(It),Tt=function(t){function n(e){var n=s({type:"undirected"},e);if("multi"in n&&!1!==n.multi)throw new V("UndirectedGraph.from: inconsistent indication that the graph should be multi in given options!");if("undirected"!==n.type)throw new V('UndirectedGraph.from: inconsistent "'+n.type+'" type in given options!');return t.call(this,n)||this}return e(n,t),n}(It),Ot=function(t){function n(e){var n=s({multi:!0},e);if("multi"in n&&!0!==n.multi)throw new V("MultiGraph.from: inconsistent indication that the graph should be simple in given options!");return t.call(this,n)||this}return e(n,t),n}(It),Pt=function(t){function n(e){var n=s({type:"directed",multi:!0},e);if("multi"in n&&!0!==n.multi)throw new V("MultiDirectedGraph.from: inconsistent indication that the graph should be simple in given options!");if("directed"!==n.type)throw new V('MultiDirectedGraph.from: inconsistent "'+n.type+'" type in given options!');return t.call(this,n)||this}return e(n,t),n}(It),Lt=function(t){function n(e){var n=s({type:"undirected",multi:!0},e);if("multi"in n&&!0!==n.multi)throw new V("MultiUndirectedGraph.from: inconsistent indication that the graph should be simple in given options!");if("undirected"!==n.type)throw new V('MultiUndirectedGraph.from: inconsistent "'+n.type+'" type in given options!');return t.call(this,n)||this}return e(n,t),n}(It);function xt(t){t.from=function(e,n){var r=s({},e.options,n),o=new t(r);return o.import(e),o}}return xt(It),xt(Mt),xt(Tt),xt(Ot),xt(Pt),xt(Lt),It.Graph=It,It.DirectedGraph=Mt,It.UndirectedGraph=Tt,It.MultiGraph=Ot,It.MultiDirectedGraph=Pt,It.MultiUndirectedGraph=Lt,It.InvalidArgumentsGraphError=V,It.NotFoundGraphError=W,It.UsageGraphError=j,It}()},6572:function(t){var e;t.exports=(e=function(t,e){var n=Array.prototype.concat,r=Array.prototype.slice,o=Object.prototype.toString;function i(e,n){var r=e>n?e:n;return t.pow(10,17-~~(t.log(r>0?r:-r)*t.LOG10E))}var a=Array.isArray||function(t){return"[object Array]"===o.call(t)};function s(t){return"[object Function]"===o.call(t)}function u(t){return"number"==typeof t&&t-t==0}function c(){return new c._init(arguments)}function l(){return 0}function d(){return 1}function h(t,e){return t===e?1:0}c.fn=c.prototype,c._init=function(t){if(a(t[0]))if(a(t[0][0])){s(t[1])&&(t[0]=c.map(t[0],t[1]));for(var e=0;e<t[0].length;e++)this[e]=t[0][e];this.length=t[0].length}else this[0]=s(t[1])?c.map(t[0],t[1]):t[0],this.length=1;else if(u(t[0]))this[0]=c.seq.apply(null,t),this.length=1;else{if(t[0]instanceof c)return c(t[0].toArray());this[0]=[],this.length=1}return this},c._init.prototype=c.prototype,c._init.constructor=c,c.utils={calcRdx:i,isArray:a,isFunction:s,isNumber:u,toVector:function(t){return n.apply([],t)}},c._random_fn=t.random,c.setRandom=function(t){if("function"!=typeof t)throw new TypeError("fn is not a function");c._random_fn=t},c.extend=function(t){var e,n;if(1===arguments.length){for(n in t)c[n]=t[n];return this}for(e=1;e<arguments.length;e++)for(n in arguments[e])t[n]=arguments[e][n];return t},c.rows=function(t){return t.length||1},c.cols=function(t){return t[0].length||1},c.dimensions=function(t){return{rows:c.rows(t),cols:c.cols(t)}},c.row=function(t,e){return a(e)?e.map((function(e){return c.row(t,e)})):t[e]},c.rowa=function(t,e){return c.row(t,e)},c.col=function(t,e){if(a(e)){var n=c.arange(t.length).map((function(){return new Array(e.length)}));return e.forEach((function(e,r){c.arange(t.length).forEach((function(o){n[o][r]=t[o][e]}))})),n}for(var r=new Array(t.length),o=0;o<t.length;o++)r[o]=[t[o][e]];return r},c.cola=function(t,e){return c.col(t,e).map((function(t){return t[0]}))},c.diag=function(t){for(var e=c.rows(t),n=new Array(e),r=0;r<e;r++)n[r]=[t[r][r]];return n},c.antidiag=function(t){for(var e=c.rows(t)-1,n=new Array(e),r=0;e>=0;e--,r++)n[r]=[t[r][e]];return n},c.transpose=function(t){var e,n,r,o,i,s=[];for(a(t[0])||(t=[t]),n=t.length,r=t[0].length,i=0;i<r;i++){for(e=new Array(n),o=0;o<n;o++)e[o]=t[o][i];s.push(e)}return 1===s.length?s[0]:s},c.map=function(t,e,n){var r,o,i,s,u;for(a(t[0])||(t=[t]),o=t.length,i=t[0].length,s=n?t:new Array(o),r=0;r<o;r++)for(s[r]||(s[r]=new Array(i)),u=0;u<i;u++)s[r][u]=e(t[r][u],r,u);return 1===s.length?s[0]:s},c.cumreduce=function(t,e,n){var r,o,i,s,u;for(a(t[0])||(t=[t]),o=t.length,i=t[0].length,s=n?t:new Array(o),r=0;r<o;r++)for(s[r]||(s[r]=new Array(i)),i>0&&(s[r][0]=t[r][0]),u=1;u<i;u++)s[r][u]=e(s[r][u-1],t[r][u]);return 1===s.length?s[0]:s},c.alter=function(t,e){return c.map(t,e,!0)},c.create=function(t,e,n){var r,o,i=new Array(t);for(s(e)&&(n=e,e=t),r=0;r<t;r++)for(i[r]=new Array(e),o=0;o<e;o++)i[r][o]=n(r,o);return i},c.zeros=function(t,e){return u(e)||(e=t),c.create(t,e,l)},c.ones=function(t,e){return u(e)||(e=t),c.create(t,e,d)},c.rand=function(t,e){return u(e)||(e=t),c.create(t,e,c._random_fn)},c.identity=function(t,e){return u(e)||(e=t),c.create(t,e,h)},c.symmetric=function(t){var e,n,r=t.length;if(t.length!==t[0].length)return!1;for(e=0;e<r;e++)for(n=0;n<r;n++)if(t[n][e]!==t[e][n])return!1;return!0},c.clear=function(t){return c.alter(t,l)},c.seq=function(t,e,n,r){s(r)||(r=!1);var o,a=[],u=i(t,e),c=(e*u-t*u)/((n-1)*u),l=t;for(o=0;l<=e&&o<n;l=(t*u+c*u*++o)/u)a.push(r?r(l,o):l);return a},c.arange=function(t,n,r){var o,i=[];if(r=r||1,n===e&&(n=t,t=0),t===n||0===r)return[];if(t<n&&r<0)return[];if(t>n&&r>0)return[];if(r>0)for(o=t;o<n;o+=r)i.push(o);else for(o=t;o>n;o+=r)i.push(o);return i},c.slice=function(){function t(t,n,r,o){var i,a=[],s=t.length;if(n===e&&r===e&&o===e)return c.copy(t);if(o=o||1,(n=(n=n||0)>=0?n:s+n)===(r=(r=r||t.length)>=0?r:s+r)||0===o)return[];if(n<r&&o<0)return[];if(n>r&&o>0)return[];if(o>0)for(i=n;i<r;i+=o)a.push(t[i]);else for(i=n;i>r;i+=o)a.push(t[i]);return a}return function(e,n){var r,o;return u((n=n||{}).row)?u(n.col)?e[n.row][n.col]:t(c.rowa(e,n.row),(r=n.col||{}).start,r.end,r.step):u(n.col)?t(c.cola(e,n.col),(o=n.row||{}).start,o.end,o.step):(o=n.row||{},r=n.col||{},t(e,o.start,o.end,o.step).map((function(e){return t(e,r.start,r.end,r.step)})))}}(),c.sliceAssign=function(n,r,o){var i,a;if(u(r.row)){if(u(r.col))return n[r.row][r.col]=o;r.col=r.col||{},r.col.start=r.col.start||0,r.col.end=r.col.end||n[0].length,r.col.step=r.col.step||1,i=c.arange(r.col.start,t.min(n.length,r.col.end),r.col.step);var s=r.row;return i.forEach((function(t,e){n[s][t]=o[e]})),n}if(u(r.col)){r.row=r.row||{},r.row.start=r.row.start||0,r.row.end=r.row.end||n.length,r.row.step=r.row.step||1,a=c.arange(r.row.start,t.min(n[0].length,r.row.end),r.row.step);var l=r.col;return a.forEach((function(t,e){n[t][l]=o[e]})),n}return o[0].length===e&&(o=[o]),r.row.start=r.row.start||0,r.row.end=r.row.end||n.length,r.row.step=r.row.step||1,r.col.start=r.col.start||0,r.col.end=r.col.end||n[0].length,r.col.step=r.col.step||1,a=c.arange(r.row.start,t.min(n.length,r.row.end),r.row.step),i=c.arange(r.col.start,t.min(n[0].length,r.col.end),r.col.step),a.forEach((function(t,e){i.forEach((function(r,i){n[t][r]=o[e][i]}))})),n},c.diagonal=function(t){var e=c.zeros(t.length,t.length);return t.forEach((function(t,n){e[n][n]=t})),e},c.copy=function(t){return t.map((function(t){return u(t)?t:t.map((function(t){return t}))}))};var f=c.prototype;return f.length=0,f.push=Array.prototype.push,f.sort=Array.prototype.sort,f.splice=Array.prototype.splice,f.slice=Array.prototype.slice,f.toArray=function(){return this.length>1?r.call(this):r.call(this)[0]},f.map=function(t,e){return c(c.map(this,t,e))},f.cumreduce=function(t,e){return c(c.cumreduce(this,t,e))},f.alter=function(t){return c.alter(this,t),this},function(t){for(var e=0;e<t.length;e++)!function(t){f[t]=function(e){var n,r=this;return e?(setTimeout((function(){e.call(r,f[t].call(r))})),this):(n=c[t](this),a(n)?c(n):n)}}(t[e])}("transpose clear symmetric rows cols dimensions diag antidiag".split(" ")),function(t){for(var e=0;e<t.length;e++)!function(t){f[t]=function(e,n){var r=this;return n?(setTimeout((function(){n.call(r,f[t].call(r,e))})),this):c(c[t](this,e))}}(t[e])}("row col".split(" ")),function(t){for(var e=0;e<t.length;e++)!function(t){f[t]=function(){return c(c[t].apply(null,arguments))}}(t[e])}("create zeros ones rand identity".split(" ")),c}(Math),function(t,e){var n=t.utils.isFunction;function r(t,e){return t-e}function o(t,n,r){return e.max(n,e.min(t,r))}t.sum=function(t){for(var e=0,n=t.length;--n>=0;)e+=t[n];return e},t.sumsqrd=function(t){for(var e=0,n=t.length;--n>=0;)e+=t[n]*t[n];return e},t.sumsqerr=function(e){for(var n,r=t.mean(e),o=0,i=e.length;--i>=0;)o+=(n=e[i]-r)*n;return o},t.sumrow=function(t){for(var e=0,n=t.length;--n>=0;)e+=t[n];return e},t.product=function(t){for(var e=1,n=t.length;--n>=0;)e*=t[n];return e},t.min=function(t){for(var e=t[0],n=0;++n<t.length;)t[n]<e&&(e=t[n]);return e},t.max=function(t){for(var e=t[0],n=0;++n<t.length;)t[n]>e&&(e=t[n]);return e},t.unique=function(t){for(var e={},n=[],r=0;r<t.length;r++)e[t[r]]||(e[t[r]]=!0,n.push(t[r]));return n},t.mean=function(e){return t.sum(e)/e.length},t.meansqerr=function(e){return t.sumsqerr(e)/e.length},t.geomean=function(n){var r=n.map(e.log),o=t.mean(r);return e.exp(o)},t.median=function(t){var e=t.length,n=t.slice().sort(r);return 1&e?n[e/2|0]:(n[e/2-1]+n[e/2])/2},t.cumsum=function(e){return t.cumreduce(e,(function(t,e){return t+e}))},t.cumprod=function(e){return t.cumreduce(e,(function(t,e){return t*e}))},t.diff=function(t){var e,n=[],r=t.length;for(e=1;e<r;e++)n.push(t[e]-t[e-1]);return n},t.rank=function(t){var e,n=[],o={};for(e=0;e<t.length;e++)o[u=t[e]]?o[u]++:(o[u]=1,n.push(u));var i=n.sort(r),a={},s=1;for(e=0;e<i.length;e++){var u,c=o[u=i[e]],l=(s+(s+c-1))/2;a[u]=l,s+=c}return t.map((function(t){return a[t]}))},t.mode=function(t){var e,n=t.length,o=t.slice().sort(r),i=1,a=0,s=0,u=[];for(e=0;e<n;e++)o[e]===o[e+1]?i++:(i>a?(u=[o[e]],a=i,s=0):i===a&&(u.push(o[e]),s++),i=1);return 0===s?u[0]:u},t.range=function(e){return t.max(e)-t.min(e)},t.variance=function(e,n){return t.sumsqerr(e)/(e.length-(n?1:0))},t.pooledvariance=function(e){return e.reduce((function(e,n){return e+t.sumsqerr(n)}),0)/(e.reduce((function(t,e){return t+e.length}),0)-e.length)},t.deviation=function(e){for(var n=t.mean(e),r=e.length,o=new Array(r),i=0;i<r;i++)o[i]=e[i]-n;return o},t.stdev=function(n,r){return e.sqrt(t.variance(n,r))},t.pooledstdev=function(n){return e.sqrt(t.pooledvariance(n))},t.meandev=function(n){for(var r=t.mean(n),o=[],i=n.length-1;i>=0;i--)o.push(e.abs(n[i]-r));return t.mean(o)},t.meddev=function(n){for(var r=t.median(n),o=[],i=n.length-1;i>=0;i--)o.push(e.abs(n[i]-r));return t.median(o)},t.coeffvar=function(e){return t.stdev(e)/t.mean(e)},t.quartiles=function(t){var n=t.length,o=t.slice().sort(r);return[o[e.round(n/4)-1],o[e.round(n/2)-1],o[e.round(3*n/4)-1]]},t.quantiles=function(t,n,i,a){var s,u,c,l,d,h=t.slice().sort(r),f=[n.length],p=t.length;for(void 0===i&&(i=3/8),void 0===a&&(a=3/8),s=0;s<n.length;s++)c=p*(u=n[s])+(i+u*(1-i-a)),l=e.floor(o(c,1,p-1)),d=o(c-l,0,1),f[s]=(1-d)*h[l-1]+d*h[l];return f},t.percentile=function(t,e,n){var o=t.slice().sort(r),i=e*(o.length+(n?1:-1))+(n?0:1),a=parseInt(i),s=i-a;return a+1<o.length?o[a-1]+s*(o[a]-o[a-1]):o[a-1]},t.percentileOfScore=function(t,e,n){var r,o,i=0,a=t.length,s=!1;for("strict"===n&&(s=!0),o=0;o<a;o++)r=t[o],(s&&r<e||!s&&r<=e)&&i++;return i/a},t.histogram=function(n,r){r=r||4;var o,i=t.min(n),a=(t.max(n)-i)/r,s=n.length,u=[];for(o=0;o<r;o++)u[o]=0;for(o=0;o<s;o++)u[e.min(e.floor((n[o]-i)/a),r-1)]+=1;return u},t.covariance=function(e,n){var r,o=t.mean(e),i=t.mean(n),a=e.length,s=new Array(a);for(r=0;r<a;r++)s[r]=(e[r]-o)*(n[r]-i);return t.sum(s)/(a-1)},t.corrcoeff=function(e,n){return t.covariance(e,n)/t.stdev(e,1)/t.stdev(n,1)},t.spearmancoeff=function(e,n){return e=t.rank(e),n=t.rank(n),t.corrcoeff(e,n)},t.stanMoment=function(n,r){for(var o=t.mean(n),i=t.stdev(n),a=n.length,s=0,u=0;u<a;u++)s+=e.pow((n[u]-o)/i,r);return s/n.length},t.skewness=function(e){return t.stanMoment(e,3)},t.kurtosis=function(e){return t.stanMoment(e,4)-3};var i=t.prototype;!function(e){for(var r=0;r<e.length;r++)!function(e){i[e]=function(r,o){var a=[],s=0,u=this;if(n(r)&&(o=r,r=!1),o)return setTimeout((function(){o.call(u,i[e].call(u,r))})),this;if(this.length>1){for(u=!0===r?this:this.transpose();s<u.length;s++)a[s]=t[e](u[s]);return a}return t[e](this[0],r)}}(e[r])}("cumsum cumprod".split(" ")),function(e){for(var r=0;r<e.length;r++)!function(e){i[e]=function(r,o){var a=[],s=0,u=this;if(n(r)&&(o=r,r=!1),o)return setTimeout((function(){o.call(u,i[e].call(u,r))})),this;if(this.length>1){for("sumrow"!==e&&(u=!0===r?this:this.transpose());s<u.length;s++)a[s]=t[e](u[s]);return!0===r?t[e](t.utils.toVector(a)):a}return t[e](this[0],r)}}(e[r])}("sum sumsqrd sumsqerr sumrow product min max unique mean meansqerr geomean median diff rank mode range variance deviation stdev meandev meddev coeffvar quartiles histogram skewness kurtosis".split(" ")),function(e){for(var r=0;r<e.length;r++)!function(e){i[e]=function(){var r,o=[],a=0,s=this,u=Array.prototype.slice.call(arguments);if(n(u[u.length-1])){r=u[u.length-1];var c=u.slice(0,u.length-1);return setTimeout((function(){r.call(s,i[e].apply(s,c))})),this}r=void 0;var l=function(n){return t[e].apply(s,[n].concat(u))};if(this.length>1){for(s=s.transpose();a<s.length;a++)o[a]=l(s[a]);return o}return l(this[0])}}(e[r])}("quantiles percentileOfScore".split(" "))}(e,Math),function(t,e){t.gammaln=function(t){var n,r,o,i=0,a=[76.18009172947146,-86.50532032941678,24.01409824083091,-1.231739572450155,.001208650973866179,-5395239384953e-18],s=1.000000000190015;for(o=(r=n=t)+5.5,o-=(n+.5)*e.log(o);i<6;i++)s+=a[i]/++r;return e.log(2.5066282746310007*s/n)-o},t.loggam=function(t){var n,r,o,i,a,s,u,c=[.08333333333333333,-.002777777777777778,.0007936507936507937,-.0005952380952380952,.0008417508417508418,-.001917526917526918,.00641025641025641,-.02955065359477124,.1796443723688307,-1.3924322169059];if(n=t,u=0,1==t||2==t)return 0;for(t<=7&&(n=t+(u=e.floor(7-t))),r=1/(n*n),o=2*e.PI,a=c[9],s=8;s>=0;s--)a*=r,a+=c[s];if(i=a/n+.5*e.log(o)+(n-.5)*e.log(n)-n,t<=7)for(s=1;s<=u;s++)i-=e.log(n-1),n-=1;return i},t.gammafn=function(t){var n,r,o,i,a=[-1.716185138865495,24.76565080557592,-379.80425647094563,629.3311553128184,866.9662027904133,-31451.272968848367,-36144.413418691176,66456.14382024054],s=[-30.8402300119739,315.35062697960416,-1015.1563674902192,-3107.771671572311,22538.11842098015,4755.846277527881,-134659.9598649693,-115132.2596755535],u=!1,c=0,l=0,d=0,h=t;if(t>171.6243769536076)return 1/0;if(h<=0){if(!(i=h%1+36e-17))return 1/0;u=(1&h?-1:1)*e.PI/e.sin(e.PI*i),h=1-h}for(o=h,r=h<1?h++:(h-=c=(0|h)-1)-1,n=0;n<8;++n)d=(d+a[n])*r,l=l*r+s[n];if(i=d/l+1,o<h)i/=o;else if(o>h)for(n=0;n<c;++n)i*=h,h++;return u&&(i=u/i),i},t.gammap=function(e,n){return t.lowRegGamma(e,n)*t.gammafn(e)},t.lowRegGamma=function(n,r){var o,i=t.gammaln(n),a=n,s=1/n,u=s,c=r+1-n,l=1/1e-30,d=1/c,h=d,f=1,p=-~(8.5*e.log(n>=1?n:1/n)+.4*n+17);if(r<0||n<=0)return NaN;if(r<n+1){for(;f<=p;f++)s+=u*=r/++a;return s*e.exp(-r+n*e.log(r)-i)}for(;f<=p;f++)h*=(d=1/(d=(o=-f*(f-n))*d+(c+=2)))*(l=c+o/l);return 1-h*e.exp(-r+n*e.log(r)-i)},t.factorialln=function(e){return e<0?NaN:t.gammaln(e+1)},t.factorial=function(e){return e<0?NaN:t.gammafn(e+1)},t.combination=function(n,r){return n>170||r>170?e.exp(t.combinationln(n,r)):t.factorial(n)/t.factorial(r)/t.factorial(n-r)},t.combinationln=function(e,n){return t.factorialln(e)-t.factorialln(n)-t.factorialln(e-n)},t.permutation=function(e,n){return t.factorial(e)/t.factorial(e-n)},t.betafn=function(n,r){if(!(n<=0||r<=0))return n+r>170?e.exp(t.betaln(n,r)):t.gammafn(n)*t.gammafn(r)/t.gammafn(n+r)},t.betaln=function(e,n){return t.gammaln(e)+t.gammaln(n)-t.gammaln(e+n)},t.betacf=function(t,n,r){var o,i,a,s,u=1e-30,c=1,l=n+r,d=n+1,h=n-1,f=1,p=1-l*t/d;for(e.abs(p)<u&&(p=u),s=p=1/p;c<=100&&(p=1+(i=c*(r-c)*t/((h+(o=2*c))*(n+o)))*p,e.abs(p)<u&&(p=u),f=1+i/f,e.abs(f)<u&&(f=u),s*=(p=1/p)*f,p=1+(i=-(n+c)*(l+c)*t/((n+o)*(d+o)))*p,e.abs(p)<u&&(p=u),f=1+i/f,e.abs(f)<u&&(f=u),s*=a=(p=1/p)*f,!(e.abs(a-1)<3e-7));c++);return s},t.gammapinv=function(n,r){var o,i,a,s,u,c,l=0,d=r-1,h=t.gammaln(r);if(n>=1)return e.max(100,r+100*e.sqrt(r));if(n<=0)return 0;for(r>1?(u=e.log(d),c=e.exp(d*(u-1)-h),s=n<.5?n:1-n,o=(2.30753+.27061*(i=e.sqrt(-2*e.log(s))))/(1+i*(.99229+.04481*i))-i,n<.5&&(o=-o),o=e.max(.001,r*e.pow(1-1/(9*r)-o/(3*e.sqrt(r)),3))):o=n<(i=1-r*(.253+.12*r))?e.pow(n/i,1/r):1-e.log(1-(n-i)/(1-i));l<12;l++){if(o<=0)return 0;if((o-=i=(a=(t.lowRegGamma(r,o)-n)/(i=r>1?c*e.exp(-(o-d)+d*(e.log(o)-u)):e.exp(-o+d*e.log(o)-h)))/(1-.5*e.min(1,a*((r-1)/o-1))))<=0&&(o=.5*(o+i)),e.abs(i)<1e-8*o)break}return o},t.erf=function(t){var n,r,o,i,a=[-1.3026537197817094,.6419697923564902,.019476473204185836,-.00956151478680863,-.000946595344482036,.000366839497852761,42523324806907e-18,-20278578112534e-18,-1624290004647e-18,130365583558e-17,1.5626441722e-8,-8.5238095915e-8,6.529054439e-9,5.059343495e-9,-9.91364156e-10,-2.27365122e-10,96467911e-18,2394038e-18,-6886027e-18,894487e-18,313092e-18,-112708e-18,381e-18,7106e-18,-1523e-18,-94e-18,121e-18,-28e-18],s=a.length-1,u=!1,c=0,l=0;for(t<0&&(t=-t,u=!0),r=4*(n=2/(2+t))-2;s>0;s--)o=c,c=r*c-l+a[s],l=o;return i=n*e.exp(-t*t+.5*(a[0]+r*c)-l),u?i-1:1-i},t.erfc=function(e){return 1-t.erf(e)},t.erfcinv=function(n){var r,o,i,a,s=0;if(n>=2)return-100;if(n<=0)return 100;for(a=n<1?n:2-n,r=-.70711*((2.30753+.27061*(i=e.sqrt(-2*e.log(a/2))))/(1+i*(.99229+.04481*i))-i);s<2;s++)r+=(o=t.erfc(r)-a)/(1.1283791670955126*e.exp(-r*r)-r*o);return n<1?r:-r},t.ibetainv=function(n,r,o){var i,a,s,u,c,l,d,h,f,p,m=r-1,g=o-1,y=0;if(n<=0)return 0;if(n>=1)return 1;for(r>=1&&o>=1?(s=n<.5?n:1-n,l=(2.30753+.27061*(u=e.sqrt(-2*e.log(s))))/(1+u*(.99229+.04481*u))-u,n<.5&&(l=-l),d=(l*l-3)/6,h=2/(1/(2*r-1)+1/(2*o-1)),f=l*e.sqrt(d+h)/h-(1/(2*o-1)-1/(2*r-1))*(d+5/6-2/(3*h)),l=r/(r+o*e.exp(2*f))):(i=e.log(r/(r+o)),a=e.log(o/(r+o)),l=n<(u=e.exp(r*i)/r)/(f=u+(c=e.exp(o*a)/o))?e.pow(r*f*n,1/r):1-e.pow(o*f*(1-n),1/o)),p=-t.gammaln(r)-t.gammaln(o)+t.gammaln(r+o);y<10;y++){if(0===l||1===l)return l;if((l-=u=(c=(t.ibeta(l,r,o)-n)/(u=e.exp(m*e.log(l)+g*e.log(1-l)+p)))/(1-.5*e.min(1,c*(m/l-g/(1-l)))))<=0&&(l=.5*(l+u)),l>=1&&(l=.5*(l+u+1)),e.abs(u)<1e-8*l&&y>0)break}return l},t.ibeta=function(n,r,o){var i=0===n||1===n?0:e.exp(t.gammaln(r+o)-t.gammaln(r)-t.gammaln(o)+r*e.log(n)+o*e.log(1-n));return!(n<0||n>1)&&(n<(r+1)/(r+o+2)?i*t.betacf(n,r,o)/r:1-i*t.betacf(1-n,o,r)/o)},t.randn=function(n,r){var o,i,a,s,u;if(r||(r=n),n)return t.create(n,r,(function(){return t.randn()}));do{o=t._random_fn(),i=1.7156*(t._random_fn()-.5),u=(a=o-.449871)*a+(s=e.abs(i)+.386595)*(.196*s-.25472*a)}while(u>.27597&&(u>.27846||i*i>-4*e.log(o)*o*o));return i/o},t.randg=function(n,r,o){var i,a,s,u,c,l,d=n;if(o||(o=r),n||(n=1),r)return(l=t.zeros(r,o)).alter((function(){return t.randg(n)})),l;n<1&&(n+=1),i=n-1/3,a=1/e.sqrt(9*i);do{do{u=1+a*(c=t.randn())}while(u<=0);u*=u*u,s=t._random_fn()}while(s>1-.331*e.pow(c,4)&&e.log(s)>.5*c*c+i*(1-u+e.log(u)));if(n==d)return i*u;do{s=t._random_fn()}while(0===s);return e.pow(s,1/d)*i*u},function(e){for(var n=0;n<e.length;n++)!function(e){t.fn[e]=function(){return t(t.map(this,(function(n){return t[e](n)})))}}(e[n])}("gammaln gammafn factorial factorialln".split(" ")),function(e){for(var n=0;n<e.length;n++)!function(e){t.fn[e]=function(){return t(t[e].apply(null,arguments))}}(e[n])}("randn".split(" "))}(e,Math),function(t,e){function n(t,n,r,o){for(var i,a=0,s=1,u=1,c=1,l=0,d=0;e.abs((u-d)/u)>o;)d=u,s=c+(i=-(n+l)*(n+r+l)*t/(n+2*l)/(n+2*l+1))*s,u=(a=u+i*a)+(i=(l+=1)*(r-l)*t/(n+2*l-1)/(n+2*l))*u,a/=c=s+i*c,s/=c,u/=c,c=1;return u/n}function r(n,r,o){var i=[.9815606342467192,.9041172563704749,.7699026741943047,.5873179542866175,.3678314989981802,.1252334085114689],a=[.04717533638651183,.10693932599531843,.16007832854334622,.20316742672306592,.2334925365383548,.24914704581340277],s=.5*n;if(s>=8)return 1;var u,c=2*t.normal.cdf(s,0,1,1,0)-1;c=c>=e.exp(-50/o)?e.pow(c,o):0;for(var l=s,d=(8-s)/(u=n>3?2:3),h=l+d,f=0,p=o-1,m=1;m<=u;m++){for(var g=0,y=.5*(h+l),v=.5*(h-l),w=1;w<=12;w++){var b,E=y+v*(6<w?i[(b=12-w+1)-1]:-i[(b=w)-1]),A=E*E;if(A>60)break;var C=2*t.normal.cdf(E,0,1,1,0)*.5-2*t.normal.cdf(E,n,1,1,0)*.5;C>=e.exp(-30/p)&&(g+=C=a[b-1]*e.exp(-.5*A)*e.pow(C,p))}f+=g*=2*v*o/e.sqrt(2*e.PI),l=h,h+=d}return(c+=f)<=e.exp(-30/r)?0:(c=e.pow(c,r))>=1?1:c}!function(e){for(var n=0;n<e.length;n++)!function(e){t[e]=function t(e,n,r){return this instanceof t?(this._a=e,this._b=n,this._c=r,this):new t(e,n,r)},t.fn[e]=function(n,r,o){var i=t[e](n,r,o);return i.data=this,i},t[e].prototype.sample=function(n){var r=this._a,o=this._b,i=this._c;return n?t.alter(n,(function(){return t[e].sample(r,o,i)})):t[e].sample(r,o,i)},function(n){for(var r=0;r<n.length;r++)!function(n){t[e].prototype[n]=function(r){var o=this._a,i=this._b,a=this._c;return r||0===r||(r=this.data),"number"!=typeof r?t.fn.map.call(r,(function(r){return t[e][n](r,o,i,a)})):t[e][n](r,o,i,a)}}(n[r])}("pdf cdf inv".split(" ")),function(n){for(var r=0;r<n.length;r++)!function(n){t[e].prototype[n]=function(){return t[e][n](this._a,this._b,this._c)}}(n[r])}("mean median mode variance".split(" "))}(e[n])}("beta centralF cauchy chisquare exponential gamma invgamma kumaraswamy laplace lognormal noncentralt normal pareto studentt weibull uniform binomial negbin hypgeom poisson triangular tukey arcsine".split(" ")),t.extend(t.beta,{pdf:function(n,r,o){return n>1||n<0?0:1==r&&1==o?1:r<512&&o<512?e.pow(n,r-1)*e.pow(1-n,o-1)/t.betafn(r,o):e.exp((r-1)*e.log(n)+(o-1)*e.log(1-n)-t.betaln(r,o))},cdf:function(e,n,r){return e>1||e<0?1*(e>1):t.ibeta(e,n,r)},inv:function(e,n,r){return t.ibetainv(e,n,r)},mean:function(t,e){return t/(t+e)},median:function(e,n){return t.ibetainv(.5,e,n)},mode:function(t,e){return(t-1)/(t+e-2)},sample:function(e,n){var r=t.randg(e);return r/(r+t.randg(n))},variance:function(t,n){return t*n/(e.pow(t+n,2)*(t+n+1))}}),t.extend(t.centralF,{pdf:function(n,r,o){var i;return n<0?0:r<=2?0===n&&r<2?1/0:0===n&&2===r?1:1/t.betafn(r/2,o/2)*e.pow(r/o,r/2)*e.pow(n,r/2-1)*e.pow(1+r/o*n,-(r+o)/2):(i=r*n/(o+n*r),r*(o/(o+n*r))/2*t.binomial.pdf((r-2)/2,(r+o-2)/2,i))},cdf:function(e,n,r){return e<0?0:t.ibeta(n*e/(n*e+r),n/2,r/2)},inv:function(e,n,r){return r/(n*(1/t.ibetainv(e,n/2,r/2)-1))},mean:function(t,e){return e>2?e/(e-2):void 0},mode:function(t,e){return t>2?e*(t-2)/(t*(e+2)):void 0},sample:function(e,n){return 2*t.randg(e/2)/e/(2*t.randg(n/2)/n)},variance:function(t,e){if(!(e<=4))return 2*e*e*(t+e-2)/(t*(e-2)*(e-2)*(e-4))}}),t.extend(t.cauchy,{pdf:function(t,n,r){return r<0?0:r/(e.pow(t-n,2)+e.pow(r,2))/e.PI},cdf:function(t,n,r){return e.atan((t-n)/r)/e.PI+.5},inv:function(t,n,r){return n+r*e.tan(e.PI*(t-.5))},median:function(t){return t},mode:function(t){return t},sample:function(n,r){return t.randn()*e.sqrt(1/(2*t.randg(.5)))*r+n}}),t.extend(t.chisquare,{pdf:function(n,r){return n<0?0:0===n&&2===r?.5:e.exp((r/2-1)*e.log(n)-n/2-r/2*e.log(2)-t.gammaln(r/2))},cdf:function(e,n){return e<0?0:t.lowRegGamma(n/2,e/2)},inv:function(e,n){return 2*t.gammapinv(e,.5*n)},mean:function(t){return t},median:function(t){return t*e.pow(1-2/(9*t),3)},mode:function(t){return t-2>0?t-2:0},sample:function(e){return 2*t.randg(e/2)},variance:function(t){return 2*t}}),t.extend(t.exponential,{pdf:function(t,n){return t<0?0:n*e.exp(-n*t)},cdf:function(t,n){return t<0?0:1-e.exp(-n*t)},inv:function(t,n){return-e.log(1-t)/n},mean:function(t){return 1/t},median:function(t){return 1/t*e.log(2)},mode:function(){return 0},sample:function(n){return-1/n*e.log(t._random_fn())},variance:function(t){return e.pow(t,-2)}}),t.extend(t.gamma,{pdf:function(n,r,o){return n<0?0:0===n&&1===r?1/o:e.exp((r-1)*e.log(n)-n/o-t.gammaln(r)-r*e.log(o))},cdf:function(e,n,r){return e<0?0:t.lowRegGamma(n,e/r)},inv:function(e,n,r){return t.gammapinv(e,n)*r},mean:function(t,e){return t*e},mode:function(t,e){if(t>1)return(t-1)*e},sample:function(e,n){return t.randg(e)*n},variance:function(t,e){return t*e*e}}),t.extend(t.invgamma,{pdf:function(n,r,o){return n<=0?0:e.exp(-(r+1)*e.log(n)-o/n-t.gammaln(r)+r*e.log(o))},cdf:function(e,n,r){return e<=0?0:1-t.lowRegGamma(n,r/e)},inv:function(e,n,r){return r/t.gammapinv(1-e,n)},mean:function(t,e){return t>1?e/(t-1):void 0},mode:function(t,e){return e/(t+1)},sample:function(e,n){return n/t.randg(e)},variance:function(t,e){if(!(t<=2))return e*e/((t-1)*(t-1)*(t-2))}}),t.extend(t.kumaraswamy,{pdf:function(t,n,r){return 0===t&&1===n?r:1===t&&1===r?n:e.exp(e.log(n)+e.log(r)+(n-1)*e.log(t)+(r-1)*e.log(1-e.pow(t,n)))},cdf:function(t,n,r){return t<0?0:t>1?1:1-e.pow(1-e.pow(t,n),r)},inv:function(t,n,r){return e.pow(1-e.pow(1-t,1/r),1/n)},mean:function(e,n){return n*t.gammafn(1+1/e)*t.gammafn(n)/t.gammafn(1+1/e+n)},median:function(t,n){return e.pow(1-e.pow(2,-1/n),1/t)},mode:function(t,n){if(t>=1&&n>=1&&1!==t&&1!==n)return e.pow((t-1)/(t*n-1),1/t)},variance:function(){throw new Error("variance not yet implemented")}}),t.extend(t.lognormal,{pdf:function(t,n,r){return t<=0?0:e.exp(-e.log(t)-.5*e.log(2*e.PI)-e.log(r)-e.pow(e.log(t)-n,2)/(2*r*r))},cdf:function(n,r,o){return n<0?0:.5+.5*t.erf((e.log(n)-r)/e.sqrt(2*o*o))},inv:function(n,r,o){return e.exp(-1.4142135623730951*o*t.erfcinv(2*n)+r)},mean:function(t,n){return e.exp(t+n*n/2)},median:function(t){return e.exp(t)},mode:function(t,n){return e.exp(t-n*n)},sample:function(n,r){return e.exp(t.randn()*r+n)},variance:function(t,n){return(e.exp(n*n)-1)*e.exp(2*t+n*n)}}),t.extend(t.noncentralt,{pdf:function(n,r,o){return e.abs(o)<1e-14?t.studentt.pdf(n,r):e.abs(n)<1e-14?e.exp(t.gammaln((r+1)/2)-o*o/2-.5*e.log(e.PI*r)-t.gammaln(r/2)):r/n*(t.noncentralt.cdf(n*e.sqrt(1+2/r),r+2,o)-t.noncentralt.cdf(n,r,o))},cdf:function(n,r,o){var i=1e-14;if(e.abs(o)<i)return t.studentt.cdf(n,r);var a=!1;n<0&&(a=!0,o=-o);for(var s=t.normal.cdf(-o,0,1),u=i+1,c=u,l=n*n/(n*n+r),d=0,h=e.exp(-o*o/2),f=e.exp(-o*o/2-.5*e.log(2)-t.gammaln(1.5))*o;d<200||c>i||u>i;)c=u,d>0&&(h*=o*o/(2*d),f*=o*o/(2*(d+.5))),s+=.5*(u=h*t.beta.cdf(l,d+.5,r/2)+f*t.beta.cdf(l,d+1,r/2)),d++;return a?1-s:s}}),t.extend(t.normal,{pdf:function(t,n,r){return e.exp(-.5*e.log(2*e.PI)-e.log(r)-e.pow(t-n,2)/(2*r*r))},cdf:function(n,r,o){return.5*(1+t.erf((n-r)/e.sqrt(2*o*o)))},inv:function(e,n,r){return-1.4142135623730951*r*t.erfcinv(2*e)+n},mean:function(t){return t},median:function(t){return t},mode:function(t){return t},sample:function(e,n){return t.randn()*n+e},variance:function(t,e){return e*e}}),t.extend(t.pareto,{pdf:function(t,n,r){return t<n?0:r*e.pow(n,r)/e.pow(t,r+1)},cdf:function(t,n,r){return t<n?0:1-e.pow(n/t,r)},inv:function(t,n,r){return n/e.pow(1-t,1/r)},mean:function(t,n){if(!(n<=1))return n*e.pow(t,n)/(n-1)},median:function(t,n){return t*(n*e.SQRT2)},mode:function(t){return t},variance:function(t,n){if(!(n<=2))return t*t*n/(e.pow(n-1,2)*(n-2))}}),t.extend(t.studentt,{pdf:function(n,r){return r=r>1e100?1e100:r,1/(e.sqrt(r)*t.betafn(.5,r/2))*e.pow(1+n*n/r,-(r+1)/2)},cdf:function(n,r){var o=r/2;return t.ibeta((n+e.sqrt(n*n+r))/(2*e.sqrt(n*n+r)),o,o)},inv:function(n,r){var o=t.ibetainv(2*e.min(n,1-n),.5*r,.5);return o=e.sqrt(r*(1-o)/o),n>.5?o:-o},mean:function(t){return t>1?0:void 0},median:function(){return 0},mode:function(){return 0},sample:function(n){return t.randn()*e.sqrt(n/(2*t.randg(n/2)))},variance:function(t){return t>2?t/(t-2):t>1?1/0:void 0}}),t.extend(t.weibull,{pdf:function(t,n,r){return t<0||n<0||r<0?0:r/n*e.pow(t/n,r-1)*e.exp(-e.pow(t/n,r))},cdf:function(t,n,r){return t<0?0:1-e.exp(-e.pow(t/n,r))},inv:function(t,n,r){return n*e.pow(-e.log(1-t),1/r)},mean:function(e,n){return e*t.gammafn(1+1/n)},median:function(t,n){return t*e.pow(e.log(2),1/n)},mode:function(t,n){return n<=1?0:t*e.pow((n-1)/n,1/n)},sample:function(n,r){return n*e.pow(-e.log(t._random_fn()),1/r)},variance:function(n,r){return n*n*t.gammafn(1+2/r)-e.pow(t.weibull.mean(n,r),2)}}),t.extend(t.uniform,{pdf:function(t,e,n){return t<e||t>n?0:1/(n-e)},cdf:function(t,e,n){return t<e?0:t<n?(t-e)/(n-e):1},inv:function(t,e,n){return e+t*(n-e)},mean:function(t,e){return.5*(t+e)},median:function(e,n){return t.mean(e,n)},mode:function(){throw new Error("mode is not yet implemented")},sample:function(e,n){return e/2+n/2+(n/2-e/2)*(2*t._random_fn()-1)},variance:function(t,n){return e.pow(n-t,2)/12}}),t.extend(t.binomial,{pdf:function(n,r,o){return 0===o||1===o?r*o===n?1:0:t.combination(r,n)*e.pow(o,n)*e.pow(1-o,r-n)},cdf:function(r,o,i){var a,s=1e-10;if(r<0)return 0;if(r>=o)return 1;if(i<0||i>1||o<=0)return NaN;var u=i,c=(r=e.floor(r))+1,l=o-r,d=c+l,h=e.exp(t.gammaln(d)-t.gammaln(l)-t.gammaln(c)+c*e.log(u)+l*e.log(1-u));return a=u<(c+1)/(d+2)?h*n(u,c,l,s):1-h*n(1-u,l,c,s),e.round(1/s*(1-a))/(1/s)}}),t.extend(t.negbin,{pdf:function(n,r,o){return n===n>>>0&&(n<0?0:t.combination(n+r-1,r-1)*e.pow(1-o,n)*e.pow(o,r))},cdf:function(e,n,r){var o=0,i=0;if(e<0)return 0;for(;i<=e;i++)o+=t.negbin.pdf(i,n,r);return o}}),t.extend(t.hypgeom,{pdf:function(n,r,o,i){if(n!=n|0)return!1;if(n<0||n<o-(r-i))return 0;if(n>i||n>o)return 0;if(2*o>r)return 2*i>r?t.hypgeom.pdf(r-o-i+n,r,r-o,r-i):t.hypgeom.pdf(i-n,r,r-o,i);if(2*i>r)return t.hypgeom.pdf(o-n,r,o,r-i);if(o<i)return t.hypgeom.pdf(n,r,i,o);for(var a=1,s=0,u=0;u<n;u++){for(;a>1&&s<i;)a*=1-o/(r-s),s++;a*=(i-u)*(o-u)/((u+1)*(r-o-i+u+1))}for(;s<i;s++)a*=1-o/(r-s);return e.min(1,e.max(0,a))},cdf:function(n,r,o,i){if(n<0||n<o-(r-i))return 0;if(n>=i||n>=o)return 1;if(2*o>r)return 2*i>r?t.hypgeom.cdf(r-o-i+n,r,r-o,r-i):1-t.hypgeom.cdf(i-n-1,r,r-o,i);if(2*i>r)return 1-t.hypgeom.cdf(o-n-1,r,o,r-i);if(o<i)return t.hypgeom.cdf(n,r,i,o);for(var a=1,s=1,u=0,c=0;c<n;c++){for(;a>1&&u<i;){var l=1-o/(r-u);s*=l,a*=l,u++}a+=s*=(i-c)*(o-c)/((c+1)*(r-o-i+c+1))}for(;u<i;u++)a*=1-o/(r-u);return e.min(1,e.max(0,a))}}),t.extend(t.poisson,{pdf:function(n,r){return r<0||n%1!=0||n<0?0:e.pow(r,n)*e.exp(-r)/t.factorial(n)},cdf:function(e,n){var r=[],o=0;if(e<0)return 0;for(;o<=e;o++)r.push(t.poisson.pdf(o,n));return t.sum(r)},mean:function(t){return t},variance:function(t){return t},sampleSmall:function(n){var r=1,o=0,i=e.exp(-n);do{o++,r*=t._random_fn()}while(r>i);return o-1},sampleLarge:function(n){var r,o,i,a,s,u,c,l,d,h,f=n;for(a=e.sqrt(f),s=e.log(f),u=.02483*(c=.931+2.53*a)-.059,l=1.1239+1.1328/(c-3.4),d=.9277-3.6224/(c-2);;){if(o=e.random()-.5,i=e.random(),h=.5-e.abs(o),r=e.floor((2*u/h+c)*o+f+.43),h>=.07&&i<=d)return r;if(!(r<0||h<.013&&i>h)&&e.log(i)+e.log(l)-e.log(u/(h*h)+c)<=r*s-f-t.loggam(r+1))return r}},sample:function(t){return t<10?this.sampleSmall(t):this.sampleLarge(t)}}),t.extend(t.triangular,{pdf:function(t,e,n,r){return n<=e||r<e||r>n?NaN:t<e||t>n?0:t<r?2*(t-e)/((n-e)*(r-e)):t===r?2/(n-e):2*(n-t)/((n-e)*(n-r))},cdf:function(t,n,r,o){return r<=n||o<n||o>r?NaN:t<=n?0:t>=r?1:t<=o?e.pow(t-n,2)/((r-n)*(o-n)):1-e.pow(r-t,2)/((r-n)*(r-o))},inv:function(t,n,r,o){return r<=n||o<n||o>r?NaN:t<=(o-n)/(r-n)?n+(r-n)*e.sqrt(t*((o-n)/(r-n))):n+(r-n)*(1-e.sqrt((1-t)*(1-(o-n)/(r-n))))},mean:function(t,e,n){return(t+e+n)/3},median:function(t,n,r){return r<=(t+n)/2?n-e.sqrt((n-t)*(n-r))/e.sqrt(2):r>(t+n)/2?t+e.sqrt((n-t)*(r-t))/e.sqrt(2):void 0},mode:function(t,e,n){return n},sample:function(n,r,o){var i=t._random_fn();return i<(o-n)/(r-n)?n+e.sqrt(i*(r-n)*(o-n)):r-e.sqrt((1-i)*(r-n)*(r-o))},variance:function(t,e,n){return(t*t+e*e+n*n-t*e-t*n-e*n)/18}}),t.extend(t.arcsine,{pdf:function(t,n,r){return r<=n?NaN:t<=n||t>=r?0:2/e.PI*e.pow(e.pow(r-n,2)-e.pow(2*t-n-r,2),-.5)},cdf:function(t,n,r){return t<n?0:t<r?2/e.PI*e.asin(e.sqrt((t-n)/(r-n))):1},inv:function(t,n,r){return n+(.5-.5*e.cos(e.PI*t))*(r-n)},mean:function(t,e){return e<=t?NaN:(t+e)/2},median:function(t,e){return e<=t?NaN:(t+e)/2},mode:function(){throw new Error("mode is not yet implemented")},sample:function(n,r){return(n+r)/2+(r-n)/2*e.sin(2*e.PI*t.uniform.sample(0,1))},variance:function(t,n){return n<=t?NaN:e.pow(n-t,2)/8}}),t.extend(t.laplace,{pdf:function(t,n,r){return r<=0?0:e.exp(-e.abs(t-n)/r)/(2*r)},cdf:function(t,n,r){return r<=0?0:t<n?.5*e.exp((t-n)/r):1-.5*e.exp(-(t-n)/r)},mean:function(t){return t},median:function(t){return t},mode:function(t){return t},variance:function(t,e){return 2*e*e},sample:function(n,r){var o,i=t._random_fn()-.5;return n-r*((o=i)/e.abs(o))*e.log(1-2*e.abs(i))}}),t.extend(t.tukey,{cdf:function(n,o,i){var a=o,s=[.9894009349916499,.9445750230732326,.8656312023878318,.755404408355003,.6178762444026438,.45801677765722737,.2816035507792589,.09501250983763744],u=[.027152459411754096,.062253523938647894,.09515851168249279,.12462897125553388,.14959598881657674,.16915651939500254,.18260341504492358,.1894506104550685];if(n<=0)return 0;if(i<2||a<2)return NaN;if(!Number.isFinite(n))return 1;if(i>25e3)return r(n,1,a);var c,l=.5*i,d=l*e.log(i)-i*e.log(2)-t.gammaln(l),h=l-1,f=.25*i;c=i<=100?1:i<=800?.5:i<=5e3?.25:.125,d+=e.log(c);for(var p=0,m=1;m<=50;m++){for(var g=0,y=(2*m-1)*c,v=1;v<=16;v++){var w,b;8<v?(w=v-8-1,b=d+h*e.log(y+s[w]*c)-(s[w]*c+y)*f):(w=v-1,b=d+h*e.log(y-s[w]*c)+(s[w]*c-y)*f),b>=-30&&(g+=r(8<v?n*e.sqrt(.5*(s[w]*c+y)):n*e.sqrt(.5*(-s[w]*c+y)),1,a)*u[w]*e.exp(b))}if(m*c>=1&&g<=1e-14)break;p+=g}if(g>1e-14)throw new Error("tukey.cdf failed to converge");return p>1&&(p=1),p},inv:function(n,r,o){if(o<2||r<2)return NaN;if(n<0||n>1)return NaN;if(0===n)return 0;if(1===n)return 1/0;var i,a=function(t,n,r){var o=.5-.5*t,i=e.sqrt(e.log(1/(o*o))),a=i+((((-453642210148e-16*i-.204231210125)*i-.342242088547)*i-1)*i+.322232421088)/((((.0038560700634*i+.10353775285)*i+.531103462366)*i+.588581570495)*i+.099348462606);r<120&&(a+=(a*a*a+a)/r/4);var s=.8832-.2368*a;return r<120&&(s+=-1.214/r+1.208*a/r),a*(s*e.log(n-1)+1.4142)}(n,r,o),s=t.tukey.cdf(a,r,o)-n;i=s>0?e.max(0,a-1):a+1;for(var u,c=t.tukey.cdf(i,r,o)-n,l=1;l<50;l++)if(u=i-c*(i-a)/(c-s),s=c,a=i,u<0&&(u=0,c=-n),c=t.tukey.cdf(u,r,o)-n,i=u,e.abs(i-a)<1e-4)return u;throw new Error("tukey.inv failed to converge")}})}(e,Math),function(t,e){var n,r,o=Array.prototype.push,i=t.utils.isArray;function a(e){return i(e)||e instanceof t}t.extend({add:function(e,n){return a(n)?(a(n[0])||(n=[n]),t.map(e,(function(t,e,r){return t+n[e][r]}))):t.map(e,(function(t){return t+n}))},subtract:function(e,n){return a(n)?(a(n[0])||(n=[n]),t.map(e,(function(t,e,r){return t-n[e][r]||0}))):t.map(e,(function(t){return t-n}))},divide:function(e,n){return a(n)?(a(n[0])||(n=[n]),t.multiply(e,t.inv(n))):t.map(e,(function(t){return t/n}))},multiply:function(e,n){var r,o,i,s,u,c,l,d;if(void 0===e.length&&void 0===n.length)return e*n;if(u=e.length,c=e[0].length,l=t.zeros(u,i=a(n)?n[0].length:c),d=0,a(n)){for(;d<i;d++)for(r=0;r<u;r++){for(s=0,o=0;o<c;o++)s+=e[r][o]*n[o][d];l[r][d]=s}return 1===u&&1===d?l[0][0]:l}return t.map(e,(function(t){return t*n}))},outer:function(e,n){return t.multiply(e.map((function(t){return[t]})),[n])},dot:function(e,n){a(e[0])||(e=[e]),a(n[0])||(n=[n]);for(var r,o,i=1===e[0].length&&1!==e.length?t.transpose(e):e,s=1===n[0].length&&1!==n.length?t.transpose(n):n,u=[],c=0,l=i.length,d=i[0].length;c<l;c++){for(u[c]=[],r=0,o=0;o<d;o++)r+=i[c][o]*s[c][o];u[c]=r}return 1===u.length?u[0]:u},pow:function(n,r){return t.map(n,(function(t){return e.pow(t,r)}))},exp:function(n){return t.map(n,(function(t){return e.exp(t)}))},log:function(n){return t.map(n,(function(t){return e.log(t)}))},abs:function(n){return t.map(n,(function(t){return e.abs(t)}))},norm:function(t,n){var r=0,o=0;for(isNaN(n)&&(n=2),a(t[0])&&(t=t[0]);o<t.length;o++)r+=e.pow(e.abs(t[o]),n);return e.pow(r,1/n)},angle:function(n,r){return e.acos(t.dot(n,r)/(t.norm(n)*t.norm(r)))},aug:function(t,e){var n,r=[];for(n=0;n<t.length;n++)r.push(t[n].slice());for(n=0;n<r.length;n++)o.apply(r[n],e[n]);return r},inv:function(e){for(var n,r=e.length,o=e[0].length,i=t.identity(r,o),a=t.gauss_jordan(e,i),s=[],u=0;u<r;u++)for(s[u]=[],n=o;n<a[0].length;n++)s[u][n-o]=a[u][n];return s},det:function t(e){if(2===e.length)return e[0][0]*e[1][1]-e[0][1]*e[1][0];for(var n=0,r=0;r<e.length;r++){for(var o=[],i=1;i<e.length;i++){o[i-1]=[];for(var a=0;a<e.length;a++)a<r?o[i-1][a]=e[i][a]:a>r&&(o[i-1][a-1]=e[i][a])}var s=r%2?-1:1;n+=t(o)*e[0][r]*s}return n},gauss_elimination:function(n,r){var o,i,a,s,u=0,c=0,l=n.length,d=n[0].length,h=1,f=0,p=[];for(o=(n=t.aug(n,r))[0].length,u=0;u<l;u++){for(i=n[u][u],c=u,s=u+1;s<d;s++)i<e.abs(n[s][u])&&(i=n[s][u],c=s);if(c!=u)for(s=0;s<o;s++)a=n[u][s],n[u][s]=n[c][s],n[c][s]=a;for(c=u+1;c<l;c++)for(h=n[c][u]/n[u][u],s=u;s<o;s++)n[c][s]=n[c][s]-h*n[u][s]}for(u=l-1;u>=0;u--){for(f=0,c=u+1;c<=l-1;c++)f+=p[c]*n[u][c];p[u]=(n[u][o-1]-f)/n[u][u]}return p},gauss_jordan:function(n,r){var o,i,a,s=t.aug(n,r),u=s.length,c=s[0].length,l=0;for(i=0;i<u;i++){var d=i;for(a=i+1;a<u;a++)e.abs(s[a][i])>e.abs(s[d][i])&&(d=a);var h=s[i];for(s[i]=s[d],s[d]=h,a=i+1;a<u;a++)for(l=s[a][i]/s[i][i],o=i;o<c;o++)s[a][o]-=s[i][o]*l}for(i=u-1;i>=0;i--){for(l=s[i][i],a=0;a<i;a++)for(o=c-1;o>i-1;o--)s[a][o]-=s[i][o]*s[a][i]/l;for(s[i][i]/=l,o=u;o<c;o++)s[i][o]/=l}return s},triaUpSolve:function(e,n){var r,o=e[0].length,i=t.zeros(1,o)[0],a=!1;return null!=n[0].length&&(n=n.map((function(t){return t[0]})),a=!0),t.arange(o-1,-1,-1).forEach((function(a){r=t.arange(a+1,o).map((function(t){return i[t]*e[a][t]})),i[a]=(n[a]-t.sum(r))/e[a][a]})),a?i.map((function(t){return[t]})):i},triaLowSolve:function(e,n){var r,o=e[0].length,i=t.zeros(1,o)[0],a=!1;return null!=n[0].length&&(n=n.map((function(t){return t[0]})),a=!0),t.arange(o).forEach((function(o){r=t.arange(o).map((function(t){return e[o][t]*i[t]})),i[o]=(n[o]-t.sum(r))/e[o][o]})),a?i.map((function(t){return[t]})):i},lu:function(e){var n,r=e.length,o=t.identity(r),i=t.zeros(e.length,e[0].length);return t.arange(r).forEach((function(t){i[0][t]=e[0][t]})),t.arange(1,r).forEach((function(a){t.arange(a).forEach((function(r){n=t.arange(r).map((function(t){return o[a][t]*i[t][r]})),o[a][r]=(e[a][r]-t.sum(n))/i[r][r]})),t.arange(a,r).forEach((function(r){n=t.arange(a).map((function(t){return o[a][t]*i[t][r]})),i[a][r]=e[n.length][r]-t.sum(n)}))})),[o,i]},cholesky:function(n){var r,o=n.length,i=t.zeros(n.length,n[0].length);return t.arange(o).forEach((function(a){r=t.arange(a).map((function(t){return e.pow(i[a][t],2)})),i[a][a]=e.sqrt(n[a][a]-t.sum(r)),t.arange(a+1,o).forEach((function(e){r=t.arange(a).map((function(t){return i[a][t]*i[e][t]})),i[e][a]=(n[a][e]-t.sum(r))/i[a][a]}))})),i},gauss_jacobi:function(n,r,o,i){for(var a,s,u,c,l=0,d=0,h=n.length,f=[],p=[],m=[];l<h;l++)for(f[l]=[],p[l]=[],m[l]=[],d=0;d<h;d++)l>d?(f[l][d]=n[l][d],p[l][d]=m[l][d]=0):l<d?(p[l][d]=n[l][d],f[l][d]=m[l][d]=0):(m[l][d]=n[l][d],f[l][d]=p[l][d]=0);for(u=t.multiply(t.multiply(t.inv(m),t.add(f,p)),-1),s=t.multiply(t.inv(m),r),a=o,c=t.add(t.multiply(u,o),s),l=2;e.abs(t.norm(t.subtract(c,a)))>i;)a=c,c=t.add(t.multiply(u,a),s),l++;return c},gauss_seidel:function(n,r,o,i){for(var a,s,u,c,l,d=0,h=n.length,f=[],p=[],m=[];d<h;d++)for(f[d]=[],p[d]=[],m[d]=[],a=0;a<h;a++)d>a?(f[d][a]=n[d][a],p[d][a]=m[d][a]=0):d<a?(p[d][a]=n[d][a],f[d][a]=m[d][a]=0):(m[d][a]=n[d][a],f[d][a]=p[d][a]=0);for(c=t.multiply(t.multiply(t.inv(t.add(m,f)),p),-1),u=t.multiply(t.inv(t.add(m,f)),r),s=o,l=t.add(t.multiply(c,o),u),d=2;e.abs(t.norm(t.subtract(l,s)))>i;)s=l,l=t.add(t.multiply(c,s),u),d+=1;return l},SOR:function(n,r,o,i,a){for(var s,u,c,l,d,h=0,f=n.length,p=[],m=[],g=[];h<f;h++)for(p[h]=[],m[h]=[],g[h]=[],s=0;s<f;s++)h>s?(p[h][s]=n[h][s],m[h][s]=g[h][s]=0):h<s?(m[h][s]=n[h][s],p[h][s]=g[h][s]=0):(g[h][s]=n[h][s],p[h][s]=m[h][s]=0);for(l=t.multiply(t.inv(t.add(g,t.multiply(p,a))),t.subtract(t.multiply(g,1-a),t.multiply(m,a))),c=t.multiply(t.multiply(t.inv(t.add(g,t.multiply(p,a))),r),a),u=o,d=t.add(t.multiply(l,o),c),h=2;e.abs(t.norm(t.subtract(d,u)))>i;)u=d,d=t.add(t.multiply(l,u),c),h++;return d},householder:function(n){for(var r,o,i,a,s=n.length,u=n[0].length,c=0,l=[],d=[];c<s-1;c++){for(r=0,a=c+1;a<u;a++)r+=n[a][c]*n[a][c];for(r=(n[c+1][c]>0?-1:1)*e.sqrt(r),o=e.sqrt((r*r-n[c+1][c]*r)/2),(l=t.zeros(s,1))[c+1][0]=(n[c+1][c]-r)/(2*o),i=c+2;i<s;i++)l[i][0]=n[i][c]/(2*o);d=t.subtract(t.identity(s,u),t.multiply(t.multiply(l,t.transpose(l)),2)),n=t.multiply(d,t.multiply(n,d))}return n},QR:(n=t.sum,r=t.arange,function(o){var i,a,s,u=o.length,c=o[0].length,l=t.zeros(c,c);for(o=t.copy(o),a=0;a<c;a++){for(l[a][a]=e.sqrt(n(r(u).map((function(t){return o[t][a]*o[t][a]})))),i=0;i<u;i++)o[i][a]=o[i][a]/l[a][a];for(s=a+1;s<c;s++)for(l[a][s]=n(r(u).map((function(t){return o[t][a]*o[t][s]}))),i=0;i<u;i++)o[i][s]=o[i][s]-o[i][a]*l[a][s]}return[o,l]}),lstsq:function(e,n){var r=!1;void 0===n[0].length&&(n=n.map((function(t){return[t]})),r=!0);var o=t.QR(e),i=o[0],a=o[1],s=e[0].length,u=t.slice(i,{col:{end:s}}),c=function(e){var n=(e=t.copy(e)).length,r=t.identity(n);return t.arange(n-1,-1,-1).forEach((function(n){t.sliceAssign(r,{row:n},t.divide(t.slice(r,{row:n}),e[n][n])),t.sliceAssign(e,{row:n},t.divide(t.slice(e,{row:n}),e[n][n])),t.arange(n).forEach((function(o){var i=t.multiply(e[o][n],-1),a=t.slice(e,{row:o}),s=t.multiply(t.slice(e,{row:n}),i);t.sliceAssign(e,{row:o},t.add(a,s));var u=t.slice(r,{row:o}),c=t.multiply(t.slice(r,{row:n}),i);t.sliceAssign(r,{row:o},t.add(u,c))}))})),r}(t.slice(a,{row:{end:s}})),l=t.transpose(u);void 0===l[0].length&&(l=[l]);var d=t.multiply(t.multiply(c,l),n);return void 0===d.length&&(d=[[d]]),r?d.map((function(t){return t[0]})):d},jacobi:function(n){for(var r,o,i,a,s,u,c,l=1,d=n.length,h=t.identity(d,d),f=[];1===l;){for(s=n[0][1],i=0,a=1,r=0;r<d;r++)for(o=0;o<d;o++)r!=o&&s<e.abs(n[r][o])&&(s=e.abs(n[r][o]),i=r,a=o);for(u=n[i][i]===n[a][a]?n[i][a]>0?e.PI/4:-e.PI/4:e.atan(2*n[i][a]/(n[i][i]-n[a][a]))/2,(c=t.identity(d,d))[i][i]=e.cos(u),c[i][a]=-e.sin(u),c[a][i]=e.sin(u),c[a][a]=e.cos(u),h=t.multiply(h,c),n=t.multiply(t.multiply(t.inv(c),n),c),l=0,r=1;r<d;r++)for(o=1;o<d;o++)r!=o&&e.abs(n[r][o])>.001&&(l=1)}for(r=0;r<d;r++)f.push(n[r][r]);return[h,f]},rungekutta:function(t,e,n,r,o,i){var a,s,u;if(2===i)for(;r<=n;)o+=((a=e*t(r,o))+(s=e*t(r+e,o+a)))/2,r+=e;if(4===i)for(;r<=n;)o+=((a=e*t(r,o))+2*(s=e*t(r+e/2,o+a/2))+2*(u=e*t(r+e/2,o+s/2))+e*t(r+e,o+u))/6,r+=e;return o},romberg:function(t,n,r,o){for(var i,a,s,u,c,l=0,d=(r-n)/2,h=[],f=[],p=[];l<o/2;){for(c=t(n),s=n,u=0;s<=r;s+=d,u++)h[u]=s;for(i=h.length,s=1;s<i-1;s++)c+=(s%2!=0?4:2)*t(h[s]);c=d/3*(c+t(r)),p[l]=c,d/=2,l++}for(a=p.length,i=1;1!==a;){for(s=0;s<a-1;s++)f[s]=(e.pow(4,i)*p[s+1]-p[s])/(e.pow(4,i)-1);a=f.length,p=f,f=[],i++}return p},richardson:function(t,n,r,o){function i(t,e){for(var n,r=0,o=t.length;r<o;r++)t[r]===e&&(n=r);return n}for(var a,s,u,c,l,d=e.abs(r-t[i(t,r)+1]),h=0,f=[],p=[];o>=d;)a=i(t,r+o),s=i(t,r),f[h]=(n[a]-2*n[s]+n[2*s-a])/(o*o),o/=2,h++;for(c=f.length,u=1;1!=c;){for(l=0;l<c-1;l++)p[l]=(e.pow(4,u)*f[l+1]-f[l])/(e.pow(4,u)-1);c=p.length,f=p,p=[],u++}return f},simpson:function(t,e,n,r){for(var o,i=(n-e)/r,a=t(e),s=[],u=e,c=0,l=1;u<=n;u+=i,c++)s[c]=u;for(o=s.length;l<o-1;l++)a+=(l%2!=0?4:2)*t(s[l]);return i/3*(a+t(n))},hermite:function(t,e,n,r){for(var o,i=t.length,a=0,s=0,u=[],c=[],l=[],d=[];s<i;s++){for(u[s]=1,o=0;o<i;o++)s!=o&&(u[s]*=(r-t[o])/(t[s]-t[o]));for(c[s]=0,o=0;o<i;o++)s!=o&&(c[s]+=1/(t[s]-t[o]));l[s]=(1-2*(r-t[s])*c[s])*(u[s]*u[s]),d[s]=(r-t[s])*(u[s]*u[s]),a+=l[s]*e[s]+d[s]*n[s]}return a},lagrange:function(t,e,n){for(var r,o,i=0,a=0,s=t.length;a<s;a++){for(o=e[a],r=0;r<s;r++)a!=r&&(o*=(n-t[r])/(t[a]-t[r]));i+=o}return i},cubic_spline:function(e,n,r){for(var o,i,a=e.length,s=0,u=[],c=[],l=[],d=[],h=[],f=[];s<a-1;s++)d[s]=e[s+1]-e[s];for(l[0]=0,s=1;s<a-1;s++)l[s]=3/d[s]*(n[s+1]-n[s])-3/d[s-1]*(n[s]-n[s-1]);for(s=1;s<a-1;s++)u[s]=[],c[s]=[],u[s][s-1]=d[s-1],u[s][s]=2*(d[s-1]+d[s]),u[s][s+1]=d[s],c[s][0]=l[s];for(i=t.multiply(t.inv(u),c),o=0;o<a-1;o++)h[o]=(n[o+1]-n[o])/d[o]-d[o]*(i[o+1][0]+2*i[o][0])/3,f[o]=(i[o+1][0]-i[o][0])/(3*d[o]);for(o=0;o<a&&!(e[o]>r);o++);return n[o-=1]+(r-e[o])*h[o]+t.sq(r-e[o])*i[o]+(r-e[o])*t.sq(r-e[o])*f[o]},gauss_quadrature:function(){throw new Error("gauss_quadrature not yet implemented")},PCA:function(e){var n,r,o,i,a,s=e.length,u=e[0].length,c=0,l=[],d=[],h=[],f=[],p=[],m=[],g=[];for(c=0;c<s;c++)l[c]=t.sum(e[c])/u;for(c=0;c<u;c++)for(p[c]=[],n=0;n<s;n++)p[c][n]=e[n][c]-l[n];for(p=t.transpose(p),c=0;c<s;c++)for(m[c]=[],n=0;n<s;n++)m[c][n]=t.dot([p[c]],[p[n]])/(u-1);for(a=(o=t.jacobi(m))[0],d=o[1],g=t.transpose(a),c=0;c<d.length;c++)for(n=c;n<d.length;n++)d[c]<d[n]&&(r=d[c],d[c]=d[n],d[n]=r,h=g[c],g[c]=g[n],g[n]=h);for(i=t.transpose(p),c=0;c<s;c++)for(f[c]=[],n=0;n<i.length;n++)f[c][n]=t.dot([g[c]],[i[n]]);return[e,d,g,f]}}),function(e){for(var n=0;n<e.length;n++)!function(e){t.fn[e]=function(n,r){var o=this;return r?(setTimeout((function(){r.call(o,t.fn[e].call(o,n))}),15),this):"number"==typeof t[e](this,n)?t[e](this,n):t(t[e](this,n))}}(e[n])}("add divide multiply subtract dot pow exp log abs norm angle".split(" "))}(e,Math),function(t,e){var n=[].slice,r=t.utils.isNumber,o=t.utils.isArray;function i(t,n,r,o){if(t>1||r>1||t<=0||r<=0)throw new Error("Proportions should be greater than 0 and less than 1");var i=(t*n+r*o)/(n+o);return(t-r)/e.sqrt(i*(1-i)*(1/n+1/o))}t.extend({zscore:function(){var e=n.call(arguments);return r(e[1])?(e[0]-e[1])/e[2]:(e[0]-t.mean(e[1]))/t.stdev(e[1],e[2])},ztest:function(){var r,i=n.call(arguments);return o(i[1])?(r=t.zscore(i[0],i[1],i[3]),1===i[2]?t.normal.cdf(-e.abs(r),0,1):2*t.normal.cdf(-e.abs(r),0,1)):i.length>2?(r=t.zscore(i[0],i[1],i[2]),1===i[3]?t.normal.cdf(-e.abs(r),0,1):2*t.normal.cdf(-e.abs(r),0,1)):(r=i[0],1===i[1]?t.normal.cdf(-e.abs(r),0,1):2*t.normal.cdf(-e.abs(r),0,1))}}),t.extend(t.fn,{zscore:function(t,e){return(t-this.mean())/this.stdev(e)},ztest:function(n,r,o){var i=e.abs(this.zscore(n,o));return 1===r?t.normal.cdf(-i,0,1):2*t.normal.cdf(-i,0,1)}}),t.extend({tscore:function(){var r=n.call(arguments);return 4===r.length?(r[0]-r[1])/(r[2]/e.sqrt(r[3])):(r[0]-t.mean(r[1]))/(t.stdev(r[1],!0)/e.sqrt(r[1].length))},ttest:function(){var o,i=n.call(arguments);return 5===i.length?(o=e.abs(t.tscore(i[0],i[1],i[2],i[3])),1===i[4]?t.studentt.cdf(-o,i[3]-1):2*t.studentt.cdf(-o,i[3]-1)):r(i[1])?(o=e.abs(i[0]),1==i[2]?t.studentt.cdf(-o,i[1]-1):2*t.studentt.cdf(-o,i[1]-1)):(o=e.abs(t.tscore(i[0],i[1])),1==i[2]?t.studentt.cdf(-o,i[1].length-1):2*t.studentt.cdf(-o,i[1].length-1))}}),t.extend(t.fn,{tscore:function(t){return(t-this.mean())/(this.stdev(!0)/e.sqrt(this.cols()))},ttest:function(n,r){return 1===r?1-t.studentt.cdf(e.abs(this.tscore(n)),this.cols()-1):2*t.studentt.cdf(-e.abs(this.tscore(n)),this.cols()-1)}}),t.extend({anovafscore:function(){var r,o,i,a,s,u,c,l,d=n.call(arguments);if(1===d.length){for(s=new Array(d[0].length),c=0;c<d[0].length;c++)s[c]=d[0][c];d=s}for(o=new Array,c=0;c<d.length;c++)o=o.concat(d[c]);for(i=t.mean(o),r=0,c=0;c<d.length;c++)r+=d[c].length*e.pow(t.mean(d[c])-i,2);for(r/=d.length-1,u=0,c=0;c<d.length;c++)for(a=t.mean(d[c]),l=0;l<d[c].length;l++)u+=e.pow(d[c][l]-a,2);return r/(u/(o.length-d.length))},anovaftest:function(){var e,o,i,a,s=n.call(arguments);if(r(s[0]))return 1-t.centralF.cdf(s[0],s[1],s[2]);var u=t.anovafscore(s);for(e=s.length-1,i=0,a=0;a<s.length;a++)i+=s[a].length;return o=i-e-1,1-t.centralF.cdf(u,e,o)},ftest:function(e,n,r){return 1-t.centralF.cdf(e,n,r)}}),t.extend(t.fn,{anovafscore:function(){return t.anovafscore(this.toArray())},anovaftes:function(){var e,n=0;for(e=0;e<this.length;e++)n+=this[e].length;return t.ftest(this.anovafscore(),this.length-1,n-this.length)}}),t.extend({qscore:function(){var o,i,a,s,u,c=n.call(arguments);return r(c[0])?(o=c[0],i=c[1],a=c[2],s=c[3],u=c[4]):(o=t.mean(c[0]),i=t.mean(c[1]),a=c[0].length,s=c[1].length,u=c[2]),e.abs(o-i)/(u*e.sqrt((1/a+1/s)/2))},qtest:function(){var e,r=n.call(arguments);3===r.length?(e=r[0],r=r.slice(1)):7===r.length?(e=t.qscore(r[0],r[1],r[2],r[3],r[4]),r=r.slice(5)):(e=t.qscore(r[0],r[1],r[2]),r=r.slice(3));var o=r[0],i=r[1];return 1-t.tukey.cdf(e,i,o-i)},tukeyhsd:function(e){for(var n=t.pooledstdev(e),r=e.map((function(e){return t.mean(e)})),o=e.reduce((function(t,e){return t+e.length}),0),i=[],a=0;a<e.length;++a)for(var s=a+1;s<e.length;++s){var u=t.qtest(r[a],r[s],e[a].length,e[s].length,n,o,e.length);i.push([[a,s],u])}return i}}),t.extend({normalci:function(){var r,o=n.call(arguments),i=new Array(2);return r=4===o.length?e.abs(t.normal.inv(o[1]/2,0,1)*o[2]/e.sqrt(o[3])):e.abs(t.normal.inv(o[1]/2,0,1)*t.stdev(o[2])/e.sqrt(o[2].length)),i[0]=o[0]-r,i[1]=o[0]+r,i},tci:function(){var r,o=n.call(arguments),i=new Array(2);return r=4===o.length?e.abs(t.studentt.inv(o[1]/2,o[3]-1)*o[2]/e.sqrt(o[3])):e.abs(t.studentt.inv(o[1]/2,o[2].length-1)*t.stdev(o[2],!0)/e.sqrt(o[2].length)),i[0]=o[0]-r,i[1]=o[0]+r,i},significant:function(t,e){return t<e}}),t.extend(t.fn,{normalci:function(e,n){return t.normalci(e,n,this.toArray())},tci:function(e,n){return t.tci(e,n,this.toArray())}}),t.extend(t.fn,{oneSidedDifferenceOfProportions:function(e,n,r,o){var a=i(e,n,r,o);return t.ztest(a,1)},twoSidedDifferenceOfProportions:function(e,n,r,o){var a=i(e,n,r,o);return t.ztest(a,2)}})}(e,Math),e.models=function(){function t(t,n){var r=t.length,o=n[0].length-1,i=r-o-1,a=e.lstsq(n,t),s=e.multiply(n,a.map((function(t){return[t]}))).map((function(t){return t[0]})),u=e.subtract(t,s),c=e.mean(t),l=e.sum(s.map((function(t){return Math.pow(t-c,2)}))),d=e.sum(t.map((function(t,e){return Math.pow(t-s[e],2)}))),h=l+d;return{exog:n,endog:t,nobs:r,df_model:o,df_resid:i,coef:a,predict:s,resid:u,ybar:c,SST:h,SSE:l,SSR:d,R2:l/h}}function n(n){var r,o,i=(r=n.exog,o=r[0].length,e.arange(o).map((function(n){var i=e.arange(o).filter((function(t){return t!==n}));return t(e.col(r,n).map((function(t){return t[0]})),e.col(r,i))}))),a=Math.sqrt(n.SSR/n.df_resid),s=i.map((function(t){var e=t.SST,n=t.R2;return a/Math.sqrt(e*(1-n))})),u=n.coef.map((function(t,e){return(t-0)/s[e]})),c=u.map((function(t){var r=e.studentt.cdf(t,n.df_resid);return 2*(r>.5?1-r:r)})),l=e.studentt.inv(.975,n.df_resid),d=n.coef.map((function(t,e){var n=l*s[e];return[t-n,t+n]}));return{se:s,t:u,p:c,sigmaHat:a,interval95:d}}return{ols:function(r,o){var i=t(r,o),a=n(i),s=function(t){var n,r,o,i=t.R2/t.df_model/((1-t.R2)/t.df_resid);return{F_statistic:i,pvalue:1-(n=i,r=t.df_model,o=t.df_resid,e.beta.cdf(n/(o/r+n),r/2,o/2))}}(i),u=1-(1-i.R2)*((i.nobs-1)/i.df_resid);return i.t=a,i.f=s,i.adjust_R2=u,i}}}(),e.extend({buildxmatrix:function(){for(var t=new Array(arguments.length),n=0;n<arguments.length;n++){t[n]=[1].concat(arguments[n])}return e(t)},builddxmatrix:function(){for(var t=new Array(arguments[0].length),n=0;n<arguments[0].length;n++){t[n]=[1].concat(arguments[0][n])}return e(t)},buildjxmatrix:function(t){for(var n=new Array(t.length),r=0;r<t.length;r++)n[r]=t[r];return e.builddxmatrix(n)},buildymatrix:function(t){return e(t).transpose()},buildjymatrix:function(t){return t.transpose()},matrixmult:function(t,n){var r,o,i,a,s;if(t.cols()==n.rows()){if(n.rows()>1){for(a=[],r=0;r<t.rows();r++)for(a[r]=[],o=0;o<n.cols();o++){for(s=0,i=0;i<t.cols();i++)s+=t.toArray()[r][i]*n.toArray()[i][o];a[r][o]=s}return e(a)}for(a=[],r=0;r<t.rows();r++)for(a[r]=[],o=0;o<n.cols();o++){for(s=0,i=0;i<t.cols();i++)s+=t.toArray()[r][i]*n.toArray()[o];a[r][o]=s}return e(a)}},regress:function(t,n){var r=e.xtranspxinv(t),o=t.transpose(),i=e.matrixmult(e(r),o);return e.matrixmult(i,n)},regresst:function(t,n,r){var o=e.regress(t,n),i={anova:{}},a=e.jMatYBar(t,o);i.yBar=a;var s=n.mean();i.anova.residuals=e.residuals(n,a),i.anova.ssr=e.ssr(a,s),i.anova.msr=i.anova.ssr/(t[0].length-1),i.anova.sse=e.sse(n,a),i.anova.mse=i.anova.sse/(n.length-(t[0].length-1)-1),i.anova.sst=e.sst(n,s),i.anova.mst=i.anova.sst/(n.length-1),i.anova.r2=1-i.anova.sse/i.anova.sst,i.anova.r2<0&&(i.anova.r2=0),i.anova.fratio=i.anova.msr/i.anova.mse,i.anova.pvalue=e.anovaftest(i.anova.fratio,t[0].length-1,n.length-(t[0].length-1)-1),i.anova.rmse=Math.sqrt(i.anova.mse),i.anova.r2adj=1-i.anova.mse/i.anova.mst,i.anova.r2adj<0&&(i.anova.r2adj=0),i.stats=new Array(t[0].length);for(var u,c,l,d=e.xtranspxinv(t),h=0;h<o.length;h++)u=Math.sqrt(i.anova.mse*Math.abs(d[h][h])),c=Math.abs(o[h]/u),l=e.ttest(c,n.length-t[0].length-1,r),i.stats[h]=[o[h],u,c,l];return i.regress=o,i},xtranspx:function(t){return e.matrixmult(t.transpose(),t)},xtranspxinv:function(t){var n=e.matrixmult(t.transpose(),t);return e.inv(n)},jMatYBar:function(t,n){var r=e.matrixmult(t,n);return new e(r)},residuals:function(t,n){return e.matrixsubtract(t,n)},ssr:function(t,e){for(var n=0,r=0;r<t.length;r++)n+=Math.pow(t[r]-e,2);return n},sse:function(t,e){for(var n=0,r=0;r<t.length;r++)n+=Math.pow(t[r]-e[r],2);return n},sst:function(t,e){for(var n=0,r=0;r<t.length;r++)n+=Math.pow(t[r]-e,2);return n},matrixsubtract:function(t,n){for(var r=new Array(t.length),o=0;o<t.length;o++){r[o]=new Array(t[o].length);for(var i=0;i<t[o].length;i++)r[o][i]=t[o][i]-n[o][i]}return e(r)}}),e.jStat=e,e)},5072:t=>{"use strict";var e=[];function n(t){for(var n=-1,r=0;r<e.length;r++)if(e[r].identifier===t){n=r;break}return n}function r(t,r){for(var i={},a=[],s=0;s<t.length;s++){var u=t[s],c=r.base?u[0]+r.base:u[0],l=i[c]||0,d="".concat(c," ").concat(l);i[c]=l+1;var h=n(d),f={css:u[1],media:u[2],sourceMap:u[3],supports:u[4],layer:u[5]};if(-1!==h)e[h].references++,e[h].updater(f);else{var p=o(f,r);r.byIndex=s,e.splice(s,0,{identifier:d,updater:p,references:1})}a.push(d)}return a}function o(t,e){var n=e.domAPI(e);return n.update(t),function(e){if(e){if(e.css===t.css&&e.media===t.media&&e.sourceMap===t.sourceMap&&e.supports===t.supports&&e.layer===t.layer)return;n.update(t=e)}else n.remove()}}t.exports=function(t,o){var i=r(t=t||[],o=o||{});return function(t){t=t||[];for(var a=0;a<i.length;a++){var s=n(i[a]);e[s].references--}for(var u=r(t,o),c=0;c<i.length;c++){var l=n(i[c]);0===e[l].references&&(e[l].updater(),e.splice(l,1))}i=u}}},7659:t=>{"use strict";var e={};t.exports=function(t,n){var r=function(t){if(void 0===e[t]){var n=document.querySelector(t);if(window.HTMLIFrameElement&&n instanceof window.HTMLIFrameElement)try{n=n.contentDocument.head}catch(t){n=null}e[t]=n}return e[t]}(t);if(!r)throw new Error("Couldn't find a style target. This probably means that the value for the 'insert' parameter is invalid.");r.appendChild(n)}},540:t=>{"use strict";t.exports=function(t){var e=document.createElement("style");return t.setAttributes(e,t.attributes),t.insert(e,t.options),e}},5056:(t,e,n)=>{"use strict";t.exports=function(t){var e=n.nc;e&&t.setAttribute("nonce",e)}},7825:t=>{"use strict";t.exports=function(t){if("undefined"==typeof document)return{update:function(){},remove:function(){}};var e=t.insertStyleElement(t);return{update:function(n){!function(t,e,n){var r="";n.supports&&(r+="@supports (".concat(n.supports,") {")),n.media&&(r+="@media ".concat(n.media," {"));var o=void 0!==n.layer;o&&(r+="@layer".concat(n.layer.length>0?" ".concat(n.layer):""," {")),r+=n.css,o&&(r+="}"),n.media&&(r+="}"),n.supports&&(r+="}");var i=n.sourceMap;i&&"undefined"!=typeof btoa&&(r+="\n/*# sourceMappingURL=data:application/json;base64,".concat(btoa(unescape(encodeURIComponent(JSON.stringify(i))))," */")),e.styleTagTransform(r,t,e.options)}(e,t,n)},remove:function(){!function(t){if(null===t.parentNode)return!1;t.parentNode.removeChild(t)}(e)}}}},1113:t=>{"use strict";t.exports=function(t,e){if(e.styleSheet)e.styleSheet.cssText=t;else{for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(document.createTextNode(t))}}}},e={};function n(r){var o=e[r];if(void 0!==o)return o.exports;var i=e[r]={id:r,loaded:!1,exports:{}};return t[r].call(i.exports,i,i.exports,n),i.loaded=!0,i.exports}n.m=t,n.amdO={},n.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return n.d(e,{a:e}),e},n.d=(t,e)=>{for(var r in e)n.o(e,r)&&!n.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},n.u=t=>t+".js",n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"==typeof window)return window}}(),n.hmd=t=>((t=Object.create(t)).children||(t.children=[]),Object.defineProperty(t,"exports",{enumerable:!0,set:()=>{throw new Error("ES Modules may not assign module.exports or exports.*, Use ESM export syntax, instead: "+t.id)}}),t),n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},(()=>{var t;n.g.importScripts&&(t=n.g.location+"");var e=n.g.document;if(!t&&e&&(e.currentScript&&"SCRIPT"===e.currentScript.tagName.toUpperCase()&&(t=e.currentScript.src),!t)){var r=e.getElementsByTagName("script");if(r.length)for(var o=r.length-1;o>-1&&(!t||!/^http(s?):/.test(t));)t=r[o--].src}if(!t)throw new Error("Automatic publicPath is not supported in this browser");t=t.replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),n.p=t})(),n.b=document.baseURI||self.location.href,n.nc=void 0;var r={};(()=>{"use strict";n.r(r),n.d(r,{GetMCLEditor:()=>xr,MCLClustering:()=>Fr,MVA:()=>kr,PCA:()=>Mr,PLS:()=>Dr,_package:()=>Sr,anova:()=>ao,applyLinearKernelSVM:()=>Vr,applyLinearRegression:()=>lo,applyPLSRegression:()=>wo,applyPolynomialKernelSVM:()=>Qr,applyRBFkernelSVM:()=>qr,applySigmoidKernelSVM:()=>no,applySoftmax:()=>mo,applyXGBooster:()=>So,dbScan:()=>Ir,dbscanPostProcessingFunction:()=>Tr,demoMultivariateAnalysis:()=>Gr,info:()=>_r,init:()=>Nr,isApplicableLinearKernelSVM:()=>Wr,isApplicableLinearRegression:()=>ho,isApplicablePLSRegression:()=>bo,isApplicablePolynomialKernelSVM:()=>Jr,isApplicableRBFkernelSVM:()=>Hr,isApplicableSigmoidKernelSVM:()=>ro,isApplicableSoftmax:()=>go,isApplicableXGBooster:()=>No,isInteractiveLinearKernelSVM:()=>jr,isInteractiveLinearRegression:()=>fo,isInteractivePLSRegression:()=>Ao,isInteractivePolynomialKernelSVM:()=>Zr,isInteractiveRBFkernelSVM:()=>$r,isInteractiveSigmoidKernelSVM:()=>oo,isInteractiveSoftmax:()=>yo,isInteractiveXGBooster:()=>_o,kNNImputation:()=>so,kNNImputationForTable:()=>uo,markovClusteringViewer:()=>Rr,numberPreprocessingFunction:()=>Or,reduceDimensionality:()=>Lr,stringPreprocessingFunction:()=>Pr,topMenuPLS:()=>Ur,trainLinearKernelSVM:()=>Br,trainLinearRegression:()=>co,trainPLSRegression:()=>vo,trainPolynomialKernelSVM:()=>Xr,trainRBFkernelSVM:()=>zr,trainSigmoidKernelSVM:()=>eo,trainSoftmax:()=>po,trainXGBooster:()=>Co,visualizeLinearKernelSVM:()=>Yr,visualizePLSRegression:()=>Eo,visualizePolynomialKernelSVM:()=>to,visualizeRBFkernelSVM:()=>Kr,visualizeSigmoidKernelSVM:()=>io});const t=grok,e=ui,o=DG,i={i32:"HEAP32",f32:"HEAPF32"},a={i32:Int32Array,f32:Float32Array},s={i32:2,f32:2},u={i32:DG.Column.fromInt32Array,f32:DG.Column.fromFloat32Array};class c{constructor(t){this.data=t}complementArrOfParams(t){t.push(this.data)}complementArrOfTypes(t){t.push("number")}allocateMemoryForBuffer(t){}isMemoryForBufferAllocated(){return!0}putDataToBuffer(t){}getDataFromBuffer(t){}freeBuffer(t){}}class l extends c{constructor(t,e,n=!1){super(t),this.type=e,this.toUpdate=n,this.buf=0,this.numOfRows=t.length}complementArrOfParams(t){t.push(this.buf),t.push(this.numOfRows)}complementArrOfTypes(t){t.push("number"),t.push("number")}allocateMemoryForBuffer(t){this.buf=t._malloc(this.numOfRows*a[this.type].BYTES_PER_ELEMENT)}isMemoryForBufferAllocated(){return 0!=this.buf}putDataToBuffer(t){if(this.isMemoryForBufferAllocated()){const e=this.type,n=s[e],r=t[i[e]];let o=null;const u=this.data;o="int"==u.type&&"i32"==e||"double"==u.type&&"f32"==e?u.getRawData():new a[e](u.getRawData()),o&&r.set(o,this.buf>>n)}}getDataFromBuffer(t){if(this.toUpdate&&this.isMemoryForBufferAllocated()){const e=this.type,n=t[i[e]],r=this.buf,o=a[e].BYTES_PER_ELEMENT,s=this.data.getRawData();for(let t=0;t<this.numOfRows;t++)s[t]=n[r/o+t]}}freeBuffer(t){this.isMemoryForBufferAllocated()&&(t._free(this.buf),this.buf=0)}}class d extends l{constructor(t,e){super([],t,!0),this.numOfRows=e}putDataToBuffer(t){}getDataFromBuffer(t){if(this.toUpdate&&this.isMemoryForBufferAllocated()){const e=this.type,n=t[i[e]],r=this.buf,o=u[e],s=new a[e](this.numOfRows);for(let t=0;t<s.length;t++)s[t]=n[r/s.BYTES_PER_ELEMENT+t];this.data=o("name",s)}}}class h extends c{constructor(t,e,n=!1){super(t),this.type=e,this.toUpdate=n,this.buf=0,this.numOfColumns=t.length,this.numOfRows=t[0].length}complementArrOfParams(t){t.push(this.buf),t.push(this.numOfRows),t.push(this.numOfColumns)}complementArrOfTypes(t){t.push("number"),t.push("number"),t.push("number")}allocateMemoryForBuffer(t){this.buf=t._malloc(this.numOfRows*this.numOfColumns*a[this.type].BYTES_PER_ELEMENT)}isMemoryForBufferAllocated(){return 0!=this.buf}putDataToBuffer(t){if(this.isMemoryForBufferAllocated()){const e=this.type,n=s[e],r=t[i[e]],o=a[e].BYTES_PER_ELEMENT;for(let t=0;t<this.numOfColumns;t++){let i=null;const s=this.data[t];i="int"==s.type&&"i32"==e||"double"==s.type&&"f32"==e?s.getRawData():new a[e](s.getRawData()),null!=i&&r.set(i,this.buf+t*this.numOfRows*o>>n)}}}getDataFromBuffer(t){if(this.toUpdate&&this.isMemoryForBufferAllocated()){const e=this.type,n=t[i[e]],r=this.numOfRows,o=this.numOfColumns,s=new a[e](n.buffer,this.buf,r*o);for(let t=0;t<o;t++){const e=this.data[t].getRawData();for(let n=0;n<r;n++)e[n]=s[n+t*r]}}}freeBuffer(t){this.isMemoryForBufferAllocated()&&(t._free(this.buf),this.buf=0)}}class f extends h{constructor(t,e,n){super([[]],t,!0),this.data=[],this.numOfColumns=n,this.numOfRows=e}putDataToBuffer(t){}getDataFromBuffer(t){if(this.toUpdate&&this.isMemoryForBufferAllocated()){const e=this.type,n=t[i[e]],r=this.numOfRows,o=this.numOfColumns,s=a[e].BYTES_PER_ELEMENT,c=u[e],l=this.buf;for(let t=0;t<o;t++){const o=new a[e](r);for(let e=0;e<r;e++)o[e]=n[l/s+e+t*r];this.data.push(c((t+1).toString(),o))}}}}const p={intColumn:t=>new l(t,"i32"),newIntColumn:t=>new d("i32",t),intColumns:t=>new h(t.toList(),"i32"),newIntColumns:(t,e)=>new f("i32",t,e),floatColumn:t=>new l(t,"f32"),newFloatColumn:t=>new d("f32",t),floatColumns:t=>new h(t.toList(),"f32"),newFloatColumns:(t,e)=>new f("f32",t,e),int:t=>new c(t),num:t=>new c(t)},m={tableFromColumns:t=>DG.DataFrame.fromColumns(t.data),num:t=>t,int:t=>t,double:t=>t,column:t=>t.data};function g(t,e,n){const r=t[e],o=r.arguments,i=[];let a=0;for(const t in o){const e=o[t];if("_callResult"!=t){switch(e.type){case"floatColumns":case"int":case"num":case"floatColumn":case"intColumn":case"intColumns":e.data=p[e.type](n[a]),a++;break;case"newFloatColumns":case"newIntColumns":const t=o[e.numOfRows.ref].data[e.numOfRows.value],r=o[e.numOfColumns.ref].data[e.numOfColumns.value];e.data=p[e.type](t,r);break;case"newFloatColumn":case"newIntColumn":const i=o[e.numOfRows.ref].data[e.numOfRows.value];e.data=p[e.type](i)}i.push(o[t].data)}}const s=function(t,e,n,r){let o;for(const e of r)e.allocateMemoryForBuffer(t);let i=!0;for(const t of r)i&=t.isMemoryForBufferAllocated();if(i){const n=[],i=[];for(const e of r)e.complementArrOfParams(n),e.complementArrOfTypes(i),e.putDataToBuffer(t);const a="number";o=t.ccall(e,a,i,n);for(const e of r)e.getDataFromBuffer(t)}for(const e of r)e.freeBuffer(t);if(null!=o)return o}(t,e,0,i);o._callResult=p.num(s);const u=r.output;if("objects"!=u.type)return m[u.type](o[u.source].data);const c=[];for(const t of u.source)c.push(o[t].data.data);return c}const y="num",v="floatColumn",w="intColumn",b="floatColumns",E="newFloatColumns",A="intColumns",C="newIntColumns",S="newFloatColumn",_="newIntColumn",N="column",I="_callResult",M="numOfRows",T="numOfColumns",O="ref",P="value",L="tableFromColumns",x="objects",F="int",R="double",D={intColumn:Int32Array,floatColumn:Float32Array,floatColumns:Float32Array,newFloatColumns:Float32Array,intColumns:Int32Array,newIntColumns:Int32Array,newFloatColumn:Float32Array,newIntColumn:Int32Array};function U(t,e){let n,r=[],o=0;for(const i in t){const a=t[i],s=a.type;if(i!==I){switch(s){case y:case F:case R:a.data=e[o],o++;break;case w:case v:let r;const i=e[o],u=i.length;r=i.type===F&&s===w||i.type===R&&s===v?i.getRawData().slice(0,u):new D[s](i.getRawData().slice(0,u)),a.data={array:r,numOfRows:u},o++;break;case _:case S:let c=0;n=a[M][O],c=t[n].type===y?t[n].data:t[n].data[a[M][P]],a.data={numOfRows:c},o++;break;case A:case b:let l=[];const d=e[o].byIndex(0).length;for(const t of e[o].toList())t.type===F&&s===w||t.type===R&&s===v?l.push(t.getRawData().slice(0,d)):l.push(new D[s](t.getRawData().slice(0,d)));a.data={arrays:l,numOfRows:d,numOfColumns:l.length},o++;break;case C:case E:let h=0,f=0;n=a[M][O],h=t[n].type===y?t[n].data:t[n].data[a[M][P]],n=a[T][O],f=t[n].type===y?t[n].data:t[n].data[a[T][P]],a.data={numOfRows:h,numOfColumns:f},o++;break;default:return}r.push(a)}}return r}function k(t,e){t.arguments._callResult=e.callResult,function(t,e){const n={newFloatColumns:DG.Column.fromFloat32Array,newIntColumns:DG.Column.fromInt32Array,newFloatColumn:DG.Column.fromFloat32Array,newIntColumn:DG.Column.fromInt32Array};let r=0;for(const o in t){const i=t[o];switch(i.type){case y:case F:case R:case w:case v:case b:case A:break;case S:case _:let t;null==i.name?t=(0).toString():s=i.name,i.column=n[i.type](t,e[r].array);break;case C:case E:let o=[],a=e[r].arrays.length,s=[];if(null==i.names)for(let t=1;t<=a;t++)s.push(t.toString());else s=i.names;for(let t=0;t<a;t++)o.push(n[i.type](s[t],e[r].arrays[t]));i.columns=o}r++}}(t.arguments,e.args);let n=function(t){let e=t.output;const n={newFloatColumns:"columns",newIntColumns:"columns",newFloatColumn:"column",newIntColumn:"column"};switch(e.type){case y:case F:case R:return t.arguments[e.source];case N:return t.arguments[e.source].column;case L:return DG.DataFrame.fromColumns(t.arguments[e.source].columns);case x:let r=[];for(let o of e.source){let e=t.arguments[o];r.push(e[n[e.type]])}return r}}(t);return function(t){for(const e in t){const n=t[e];switch(n.type){case y:case F:case R:case w:case v:case A:case b:break;case _:case S:n.column=null;break;case C:case E:n.columns=null}}}(t.arguments),n}async function G(t,e,r){return new Promise(((t,o)=>{const i=new Worker(new URL(n.p+n.u(128),n.b));i.postMessage(U(EDA.principalComponentAnalysisNipals.arguments,[e,r])),i.onmessage=function(e){i.terminate(),t(k(EDA.principalComponentAnalysisNipals,e.data))}}))}const B=1,V=1e8,W=900,j=1e-6,Y="components must be positive.",z="components must not be greater than features count.",q="dataframe is too big.",H="unsupported column type: ";function $(t){if(t.type!=o.COLUMN_TYPE.FLOAT&&t.type!=o.COLUMN_TYPE.INT)throw new Error(H+t.type)}function K(t){if(t.stats.missingValueCount>0)throw new Error(`The column '${t.name}' has missing values.`)}function X(t,e){if(function(t,e){if(e<B)throw new Error(Y);if(e>t.length)throw new Error(z);for(const e of t)$(e),K(e)}(t,e),t.length*t.byIndex(0).length>V)throw new Error(q)}function Q(t,e,n){return e?n?function(t){const e=t.rowCount;for(const n of t.columns)if(n.isNumerical){const t=n.stats.stdev,r=n.stats.avg,o=n.getRawData();if(t>0)for(let n=0;n<e;++n)o[n]=(o[n]-r)/t;else for(let t=0;t<e;++t)o[t]-=r}return t}(t):function(t){const e=t.rowCount;for(const n of t.columns)if(n.isNumerical){const t=n.stats.avg;if(Math.abs(t)>j){const r=n.getRawData();for(let n=0;n<e;++n)r[n]-=t}}return t}(t):n?function(t){const e=t.rowCount;for(const n of t.columns)if(n.isNumerical){const t=n.stats.stdev;if(Math.abs(t-1)>j&&t>0){const r=n.getRawData();for(let n=0;n<e;++n)r[n]/=t}}return t}(t):t}var J=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{u(r.next(t))}catch(t){i(t)}}function s(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,s)}u((r=r.apply(t,e||[])).next())}))};var Z=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{u(r.next(t))}catch(t){i(t)}}function s(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,s)}u((r=r.apply(t,e||[])).next())}))};const tt=0,et=1,nt=2,rt=3,ot=4,it=0,at=1,st=2,ut=3,ct=4,lt=5,dt=6,ht=7,ft=0,pt=1,mt=2,gt=3,yt=0,vt=0,wt=1,bt=0,Et=1,At=0,Ct=0,St=0,_t=0,Nt="gamma must be strictly positive.",It="sigma must be strictly positive.",Mt="c must be strictly positive.",Tt="d must be strictly positive.",Ot="incorrect kernel.",Pt="labels must be strings of two categories.",Lt="Labels",xt="predicted",Ft="correctness",Rt="Confusion matrix",Dt="mean",Ut="std dev",kt="alpha",Gt="weight",Bt="Gamma",Vt="Kernel",Wt="Kernel params",jt="Kernel parameter 1",Yt="Kernel parameter 2",zt="Features count",qt="Train samples count",Ht="Train error, %",$t=["linear","polynomial","RBF","sigmoid"],Kt="Sensitivity",Xt="Specificity",Qt="Balanced accuracy",Jt="Positive predicitve value",Zt="Negative predicitve value",te="prediction",ee=4,ne=3,re=2,oe=0,ie=1,ae=2,se=0,ue=1;function ce(t,e,r){return Z(this,void 0,void 0,(function*(){const i=e.columns;if(2!=r.categories.length)throw new Error(Pt);const a=o.Column.float(r.name,r.length);for(let t=0;t<r.length;t++)a.set(t,r.get(t)==r.categories[0]?-1:1,!1);const s=yield function(t,e,r){return Z(this,void 0,void 0,(function*(){!function(t){if(t.gamma<=At)throw new Error(Nt);switch(t.kernel){case tt:return;case nt:if(t.sigma<=Ct)throw new Error(It);return;case et:if(t.cParam<=St)throw new Error(Mt);if(t.dParam<=_t)throw new Error(Tt);return;case rt:return;default:throw new Error(Ot)}}(t);const i=[se,se];switch(t.kernel){case tt:break;case nt:i[yt]=t.sigma;break;case et:i[vt]=t.cParam,i[wt]=t.dParam;break;case rt:i[bt]=t.kappa,i[Et]=t.theta;break;default:throw new Error(Ot)}const a=o.Column.fromList("double",Wt,i),s=e.toList(),u=s[0].length+ue,c=s.length+ue,l=ot;let d;const h=async function(t,e,r,o,i,a,s,u){return new Promise(((c,l)=>{const d=new Worker(new URL(n.p+n.u(656),n.b));d.postMessage(U(EDA.trainAndAnalyzeLSSVM.arguments,[t,e,r,o,i,a,s,u])),d.onmessage=function(t){d.terminate(),c(k(EDA.trainAndAnalyzeLSSVM,t.data))}}))}(t.gamma,t.kernel,a,u,c,l,e,r);yield h.then((t=>{d=t}),(t=>{throw new Error(`Error: ${t}`)})),d[at].name=Dt,d[st].name=Ut,d[ut].name=kt,d[ct].name=Gt,d[lt].name=xt,d[dt].name=Ft,d[ht].name=Rt;const f={trainGamma:t.gamma,kernelType:t.kernel,kernelParams:a,trainLabels:r,normalizedTrainData:o.DataFrame.fromColumns(d[it]),means:d[at],stdDevs:d[st],modelParams:d[ut],modelWeights:d[ct],predictedLabels:d[lt],correctness:d[dt],confusionMatrix:d[ht],trainError:void 0,featuresCount:s.length,trainSamplesCount:s[0].length};return function(t){const e=t.confusionMatrix.getRawData(),n=e[ft],r=e[gt],o=e[mt],i=e[pt],a=n+i,s=o+r,u=n/a,c=r/s,l=n/(n+o),d=r/(r+i),h=(n+r)/(a+s),f=(u+c)/2;t.sensitivity=u,t.specificity=c,t.balancedAccuracy=f,t.positivePredicitveValue=l,t.negativePredicitveValue=d,t.trainError=100*(1-h)}(f),f}))}(t,i,a);return s.realLabels=r,s}))}function le(t,e){const n=he(e);return o.Viewer.form(n.modelInfo,{showNavigation:!1}).root}function de(t){const e=t.normalizedTrainData.columns,n=t.trainSamplesCount,r=t.featuresCount,i=o.DataFrame.fromColumns([t.realLabels]).toByteArray(),a=ee+i.length+4-i.length%4,s=function(t){const e=t.kernelParams.getRawData();return o.DataFrame.fromColumns([o.Column.fromList("double",Bt,[t.trainGamma]),o.Column.fromStrings(Vt,[$t[t.kernelType]]),o.Column.fromList("double",jt,[e[0]]),o.Column.fromList("double",Yt,[e[1]]),o.Column.fromList("double",zt,[t.featuresCount]),o.Column.fromList("double",qt,[t.trainSamplesCount]),o.Column.fromList("double",Ht,[t.trainError]),o.Column.fromList("double",Qt,[t.balancedAccuracy]),o.Column.fromList("double",Kt,[t.sensitivity]),o.Column.fromList("double",Xt,[t.specificity]),o.Column.fromList("double",Jt,[t.positivePredicitveValue]),o.Column.fromList("double",Zt,[t.negativePredicitveValue])])}(t).toByteArray(),u=ee+s.length+4-s.length%4,c=new Uint8Array(ee*(ne+re+n+r+r+n+ue+r+ue+r*n)+a+u),l=c.buffer;let d=0,h=new Int32Array(l,d,ne);h[oe]=t.kernelType,h[ie]=n,h[ae]=r,d+=ne*ee;let f=new Float32Array(l,d,re);f.set(t.kernelParams.getRawData()),d+=re*ee,f=new Float32Array(l,d,n),f.set(t.trainLabels.getRawData()),d+=n*ee,f=new Float32Array(l,d,r),f.set(t.means.getRawData()),d+=r*ee,f=new Float32Array(l,d,r),f.set(t.stdDevs.getRawData()),d+=r*ee,f=new Float32Array(l,d,n+ue),f.set(t.modelParams.getRawData()),d+=(n+ue)*ee,f=new Float32Array(l,d,r+ue),f.set(t.modelWeights.getRawData()),d+=(r+ue)*ee;for(const t of e)f=new Float32Array(l,d,r),f.set(t.getRawData()),d+=r*ee;return h=new Int32Array(l,d,1),h[0]=i.length,c.set(i,d+ee),d+=a,h=new Int32Array(l,d,1),h[0]=s.length,c.set(s,d+ee),d+=u,c}function he(t){const e=t.buffer;let n=0;const r=new Int32Array(e,n,ne);n+=ne*ee;const i=r[ie],a=r[ae],s=o.Column.fromFloat32Array(Wt,new Float32Array(e,n,re));n+=re*ee;const u=o.Column.fromFloat32Array(Lt,new Float32Array(e,n,i));n+=i*ee;const c=o.Column.fromFloat32Array(Dt,new Float32Array(e,n,a));n+=a*ee;const l=o.Column.fromFloat32Array(Ut,new Float32Array(e,n,a));n+=a*ee;const d=o.Column.fromFloat32Array(kt,new Float32Array(e,n,i+ue));n+=(i+ue)*ee;const h=o.Column.fromFloat32Array(Gt,new Float32Array(e,n,a+ue));n+=(a+ue)*ee;const f=[];for(let t=0;t<i;t++)f.push(o.Column.fromFloat32Array(t.toString(),new Float32Array(e,n,a))),n+=a*ee;const p=o.DataFrame.fromColumns(f),m=new Int32Array(e,n,1)[0],g=m+4-m%4;n+=ee;const y=o.DataFrame.fromByteArray(new Uint8Array(e,n,m)).columns.byIndex(0);n+=g;const v=new Int32Array(e,n,1)[0],w=v+4-v%4;n+=ee;const b=o.DataFrame.fromByteArray(new Uint8Array(e,n,v));return n+=w,{kernelType:r[oe],kernelParams:s,trainLabels:u,realLabels:y,means:c,stdDevs:l,modelParams:d,modelWeights:h,normalizedTrainData:p,modelInfo:b}}function fe(t,e){return Z(this,void 0,void 0,(function*(){const r=he(new Uint8Array(e)),i=yield function(t,e){return Z(this,void 0,void 0,(function*(){let r;const o=async function(t,e,r,o,i,a,s,u,c){return new Promise(((l,d)=>{const h=new Worker(new URL(n.p+n.u(763),n.b));h.postMessage(U(EDA.predictByLSSVM.arguments,[t,e,r,o,i,a,s,u,c])),h.onmessage=function(t){h.terminate(),l(k(EDA.predictByLSSVM,t.data))}}))}(t.kernelType,t.kernelParams,t.normalizedTrainData.columns,t.trainLabels,t.means,t.stdDevs,t.modelParams,t.modelWeights,e);return yield o.then((t=>{r=t}),(t=>{throw new Error(`Error: ${t}`)})),r}))}(r,t.columns),a=o.Column.string(te,i.length),s=r.realLabels.categories;for(let t=0;t<a.length;t++)a.set(t,-1==i.get(t)?s[0]:s[1]);return o.DataFrame.fromColumns([a])}))}function pe(t,e){const n=t.columns;if(!e.matches("categorical")||e.categories.length>2)return!1;let r=!0;for(let t=0;t<n.length;t++)r=r&&n.byIndex(t).matches("numerical");return r}function me(t,e){return t.rowCount<=1e3}var ge,ye,ve,we,be,Ee,Ae,Ce;!function(t){t[t.COMPUTE_COMPONENTS=0]="COMPUTE_COMPONENTS",t[t.PERFORM_MVA=1]="PERFORM_MVA",t[t.DEMO=2]="DEMO"}(ge||(ge={})),function(t){t.NO_DF="No dataframe is opened",t.NO_COLS="No numeric columns without missing values",t.ONE_COL="No columns to be used as features (just one numeric columns without missing values)",t.EMPTY_DF="Dataframe is empty"}(ye||(ye={})),function(t){t.PREDICT="Predict",t.USING="Using",t.COMPONENTS="Components",t.PLS="PLS",t.MVA="Multivariate Analysis (PLS)",t.RUN="RUN",t.NAMES="Names",t.MODEL="Observed vs. Predicted",t.FEATURE="Feature",t.REGR_COEFS="Regression Coefficients",t.XLOADING="x.loading.p",t.LOADINGS="Loadings",t.XSCORE="x.score.t",t.YSCORE="y.score.u",t.SCORES="Scores",t.EXPL_VAR="Explained Variance",t.EXPLORE="Explore",t.FEATURES="Feature names",t.BROWSE="Browse",t.ANALYSIS="Features Analysis"}(ve||(ve={})),function(t){t.PREDICT="Column with the response variable",t.FEATURES="Predictors (features)",t.COMPONENTS="Number of PLS components",t.PLS="Compute PLS components",t.MVA="Perform multivariate analysis",t.NAMES="Names of data samples"}(we||(we={})),function(t){t.PLS="/help/explore/multivariate-analysis/pls#pls-components",t.MVA="/help/explore/multivariate-analysis/pls",t.MODEL="/help/explore/multivariate-analysis/plots/predicted-vs-reference",t.COEFFS="/help/explore/multivariate-analysis/plots/regression-coefficients",t.LOADINGS="/help/explore/multivariate-analysis/plots/loadings",t.EXPL_VARS="/help/explore/multivariate-analysis/plots/explained-variance",t.SCORES="/help/explore/multivariate-analysis/plots/scores"}(be||(be={})),function(t){t[t.DEFAULT=3]="DEFAULT",t[t.MIN=1]="MIN"}(Ee||(Ee={})),function(t){t.PREFIX="PLS",t.SUFFIX="(predicted)",t.COMP="component",t.COMPS="components"}(Ae||(Ae={})),function(t){t[t.PREDICTION=0]="PREDICTION",t[t.REGR_COEFFS=1]="REGR_COEFFS",t[t.T_SCORES=2]="T_SCORES",t[t.U_SCORES=3]="U_SCORES",t[t.X_LOADINGS=4]="X_LOADINGS",t[t.Y_LOADINGS=5]="Y_LOADINGS"}(Ce||(Ce={}));const Se="Int",_e=6,Ne=[.49,.79,.99],Ie=1,Me=200,Te=200;var Oe;!function(t){t.AXIS="#838383",t.CIRCLE="#0000FF"}(Oe||(Oe={}));const Pe="# Data\nEach car has many features - patterns extraction is complicated.\n\n# Model\nPredict car price by its other features.\n\n# Try\nPress 'RUN' to perform multivariate analysis using partial least squares\n([PLS](https://en.wikipedia.org/wiki/Partial_least_squares_regression)) regression.\n\n# Essence\nThe method finds the latent factors that\n\n* capture the maximum variance in the features\n* maximize correlation with the response variable",Le=[{caption:ve.MODEL,text:"Closer to the line means better price prediction."},{caption:ve.SCORES,text:"The latent factor values for each sample reflect the similarities and dissimilarities among observations."},{caption:ve.LOADINGS,text:"The impact of each feature on the latent factors: higher loading means stronger influence."},{caption:ve.REGR_COEFS,text:"Parameters of the obtained linear model: features make different contribution to the prediction."},{caption:ve.EXPL_VAR,text:"How well the latent components fit source data: closer to one means better fit."}],xe=Le.map((t=>`# ${t.caption}\n\n${t.text}`)).join("\n\n")+`\n\n# Learn more\n \n * [Multivariate analysis](${be.MVA}),\n * [ANOVA](https://datagrok.ai/help/explore/anova)`;var Fe=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{u(r.next(t))}catch(t){i(t)}}function s(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,s)}u((r=r.apply(t,e||[])).next())}))};const Re=Math.min,De=Math.max;function Ue(t){const e=[],n=(t,n)=>{e.push({type:"line",formula:t,width:Ie,visible:!0,title:" ",min:-n,max:n,color:Oe.CIRCLE})};return t.forEach((r=>{const o="${"+r+"}";e.push({type:"line",formula:`${o} = 0`,width:Ie,visible:!0,title:" ",color:Oe.AXIS}),t.forEach((t=>{const e="${"+t+"}";Ne.forEach((t=>{n(e+` = sqrt(${t*t} - ${o} * ${o})`,t),n(e+` = -sqrt(${t*t} - ${o} * ${o})`,t)}))}))})),e}function ke(t){return Fe(this,void 0,void 0,(function*(){X(t.features,t.components),$(t.predict),K(t.predict);const e=yield async function(t,e,r,o){return new Promise(((t,i)=>{const a=new Worker(new URL(n.p+n.u(412),n.b));a.postMessage(U(EDA.partialLeastSquareRegression.arguments,[e,r,o])),a.onmessage=function(e){a.terminate(),t(k(EDA.partialLeastSquareRegression,e.data))}}))}(t.table,t.features,t.predict,t.components);return{prediction:e[Ce.PREDICTION],regressionCoefficients:e[Ce.REGR_COEFFS],tScores:e[Ce.T_SCORES],uScores:e[Ce.U_SCORES],xLoadings:e[Ce.X_LOADINGS],yLoadings:e[Ce.Y_LOADINGS]}}))}function Ge(n){return Fe(this,void 0,void 0,(function*(){const r=n===ge.DEMO?t.shell.view(ve.BROWSE).preview.table:t.shell.t;if(null===r)return void t.shell.warning(ye.NO_DF);if(0===r.rowCount)return void t.shell.warning(ye.EMPTY_DF);const i=[],a=[],s=[],u=t=>(t.type===o.COLUMN_TYPE.INT||t.type===o.COLUMN_TYPE.FLOAT)&&0===t.stats.missingValueCount;if(r.columns.toList().forEach((t=>{u(t)?(i.push(t.name),a.push(t)):t.type===o.COLUMN_TYPE.STRING&&s.push(t)})),0===i.length)return void t.shell.warning(ye.NO_COLS);if(1===i.length)return void t.shell.warning(ye.ONE_COL);let c=a[a.length-1];const l=e.input.column(ve.PREDICT,{table:r,value:c,onValueChanged:t=>{c=t,v()},filter:t=>u(t)});let d;l.setTooltip(we.PREDICT);const h=e.input.columns(ve.USING,{table:r,available:i});h.onInput.subscribe((()=>v())),h.setTooltip(we.FEATURES);let f=Re(i.length-1,Ee.DEFAULT);const p=e.input.forProperty(o.Property.fromOptions({name:ve.COMPONENTS,inputType:Se,defaultValue:f,showPlusMinus:!0,min:Ee.MIN}));let m,g,y;p.onInput.subscribe((()=>v())),p.setTooltip(we.COMPONENTS),n===ge.COMPUTE_COMPONENTS?(m=ve.PLS,g=be.PLS,y=we.PLS):(m=ve.MVA,g=be.MVA,y=we.MVA);const v=()=>{var t;h.value=h.value.filter((t=>t!==c)),d=h.value,p.value=Re(De(null!==(t=p.value)&&void 0!==t?t:f,Ee.MIN),d.length),f=p.value,E.getButton(ve.RUN).disabled=0===d.length||f<=0};let w=s.length>0?s[0]:void 0;const b=e.input.column(ve.NAMES,{table:r,value:w,onValueChanged:t=>w=null!=t?t:void 0,filter:t=>t.type===o.COLUMN_TYPE.STRING});b.setTooltip(we.NAMES),b.root.hidden=0===s.length||n===ge.COMPUTE_COMPONENTS;const E=e.dialog({title:m,helpUrl:g}).add(e.form([l,h,p,b])).addButton(ve.RUN,(()=>Fe(this,void 0,void 0,(function*(){E.close(),yield function(n,r){return Fe(this,void 0,void 0,(function*(){var i,a;const s=yield ke(n),u=s.tScores,c=n.table.columns,l=n.features,d=l.names(),h=r===ge.COMPUTE_COMPONENTS?Ae.PREFIX:ve.XSCORE;if(u.forEach(((t,e)=>{t.name=c.getUnusedName(`${h}${e+1}`),c.add(t)})),r===ge.COMPUTE_COMPONENTS)return;const f=r===ge.DEMO?t.shell.view(ve.BROWSE).preview:t.shell.tableView(n.table.name),p=o.DataFrame.fromColumns([o.Column.fromStrings(ve.FEATURE,d),s.regressionCoefficients]);p.name=`${n.table.name}(${ve.ANALYSIS})`,t.shell.addTable(p),s.xLoadings.forEach(((t,e)=>{t.name=p.columns.getUnusedName(`${ve.XLOADING}${e+1}`),p.columns.add(t)}));const m=function(t,e,n,r){const i=n.length,a=t.length,s=e.getRawData(),u=new Float32Array(i),c=r.getRawData();let l=n.stats.avg;for(let e=0;e<a;++e)l-=s[e]*t.byIndex(e).stats.avg;for(let t=0;t<i;++t)u[t]=l+c[t];return o.Column.fromFloat32Array("Debiased",u,i)}(l,s.regressionCoefficients,n.predict,s.prediction);m.name=c.getUnusedName(`${n.predict.name} ${Ae.SUFFIX}`),c.add(m);const g=f.addViewer(o.Viewer.scatterPlot(n.table,{title:ve.MODEL,xColumnName:n.predict.name,yColumnName:m.name,showRegressionLine:!0,markerType:o.MARKER_TYPE.CIRCLE,showLabels:"Always",help:be.MODEL}));void 0!==n.names&&null!==n.names&&g.setOptions({labelColumnNames:[null===(i=n.names)||void 0===i?void 0:i.name]}),s.regressionCoefficients.name=ve.REGR_COEFS;const y=f.addViewer(o.Viewer.barChart(p,{table:p.name,title:ve.REGR_COEFS,splitColumnName:ve.FEATURE,valueColumnName:s.regressionCoefficients.name,valueAggrType:o.AGG.AVG,help:be.COEFFS,showValueSelector:!1,showStackSelector:!1}));s.xLoadings.forEach(((t,e)=>t.name=`${ve.XLOADING}${e+1}`));const v=f.addViewer(o.Viewer.scatterPlot(p,{table:p.name,title:ve.LOADINGS,xColumnName:`${ve.XLOADING}1`,yColumnName:`${ve.XLOADING}${s.xLoadings.length>1?"2":"1"}`,markerType:o.MARKER_TYPE.CIRCLE,labelColumnNames:[ve.FEATURE],help:be.LOADINGS})),w=u.map((t=>t.name));s.uScores.forEach(((t,e)=>{t.name=c.getUnusedName(`${ve.YSCORE}${e+1}`),c.add(t),w.push(t.name)}));const b=o.Viewer.scatterPlot(n.table,{title:ve.SCORES,xColumnName:u[0].name,yColumnName:u.length>1?u[1].name:s.uScores[0].name,markerType:o.MARKER_TYPE.CIRCLE,help:be.SCORES,showViewerFormulaLines:!0});void 0!==n.names&&null!==n.names&&b.setOptions({labelColumnNames:[null===(a=n.names)||void 0===a?void 0:a.name]}),b.meta.formulaLines.addAll(Ue(w)),f.addViewer(b);const E=s.yLoadings.getRawData(),A=s.xLoadings.map((t=>t.getRawData())),C=n.table.rowCount,S=d.length,_=n.components,N=new Float32Array(_),I=[],M=[];for(let t=0;t<S;++t)M.push(new Float32Array(_));N[0]=Math.pow(E[0],2)/C,I.push(`1 ${Ae.COMP}`),M.forEach(((t,e)=>{t[0]=Math.pow(A[0][e],2)/C}));for(let t=1;t<_;++t)N[t]=N[t-1]+Math.pow(E[t],2)/C,M.forEach(((e,n)=>e[t]=e[t-1]+Math.pow(A[t][n],2)/C)),I.push(`${t+1} ${Ae.COMPS}`);const T=o.DataFrame.fromColumns([o.Column.fromStrings(ve.COMPONENTS,I),o.Column.fromFloat32Array(n.predict.name,N)]);T.name=`${n.table.name}(${ve.EXPL_VAR})`,t.shell.addTable(T),M.forEach(((t,e)=>T.columns.add(o.Column.fromFloat32Array(d[e],t))));const O=f.addViewer(o.Viewer.barChart(T,{table:T.name,title:ve.EXPL_VAR,splitColumnName:ve.COMPONENTS,valueColumnName:n.predict.name,valueAggrType:o.AGG.AVG,help:be.EXPL_VARS,showCategorySelector:!1,showStackSelector:!1}));r===ge.DEMO&&(t.shell.windows.help.showHelp(e.markdown(xe)),function(t,n,r){if(t.length!==n.length)throw new Error("Non-equal size of viewer roots and descriptions");let o,i,a,s=0;const u=e.button("next",(()=>{a.remove(),++s,h()}),"Go to the next viewer"),c=e.button("prev",(()=>{s-=1,a.remove(),h()}),"Go to the previous viewer"),l=e.button("done",(()=>a.remove()),"Go to the next step"),d=e.divH([c,u,l]);d.style.marginLeft="auto",d.style.marginRight="0px";const h=()=>{s<t.length&&(i=e.divV([e.markdown(n[s]),d]),a=e.hints.addHint(t[s],i,r[s]),l.hidden=s<t.length-1,u.hidden=s===t.length-1,c.hidden=s<1,o=a.querySelector("i"),o.onclick=()=>l.click())};h()}([g,b,v,y,O].map((t=>t.root)),Le.map((t=>`<b>${t.caption}</b>\n\n${t.text}`)),["left","left","right","right","left"]))}))}({table:r,features:o.DataFrame.fromColumns(d).columns,predict:c,components:f,names:w},n)}))),void 0,y).show({x:Me,y:Te});setTimeout((()=>{h.value=a.filter((t=>t!==c)),d=h.value}),_e),t.shell.v.append(E.root)}))}var Be,Ve=n(6572);!function(t){t.NO_DATAFRAME="No dataframe is opened",t.NO_MISSING_VALUES="No missing values",t.ONE_AVAILABLE_FEATURE="Not enough of feature columns to apply imputation using the KNN method",t.ONE_FEATURE_SELECTED="Imputation cannot be applied to",t.UNSUPPORTED_COLUMN_TYPE="Unsupported column type",t.UNSUPPORTED_IMPUTATION_STRATEGY="Unsupported imputation strategy",t.KNN_CANNOT_BE_APPLIED="KNN imputer cannot be applied: no columns to be used as features",t.KNN_NO_TARGET_COLUMNS="KNN imputer cannot be applied: no columns with missing values",t.KNN_NO_FEATURE_COLUMNS="KNN imputer cannot be applied: no feature columns",t.KNN_NOT_ENOUGH_OF_ROWS="KNN imputer cannot be applied: not enough of rows",t.KNN_IMPOSSIBLE_IMPUTATION="Imputation is impossible, no features can be used",t.INCORRECT_NEIGHBORS="Incorrect number of neighbors",t.KNN_FAILS="KNN IMPUTATION FAILS",t.CORE_ISSUE="Core issue",t.FAILED_TO_IMPUTE="Failed to impute",t.UNSUPPORTED_FILL_VALUE_TYPE="Unsupported fill value type",t.EMPTY_COLUMN="Column contains just null values",t.FAILS_TO_PREDICT_IMPUTATION_FAILS="Failed to predict imputation fails",t.WRONG_PREDICTIONS="wrong evaluation of KNN imputation fails"}(Be||(Be={}));const We="copy";var je;!function(t){t.KNN_IMPUTER="k-NN Imputation",t.TABLE="Table",t.IN_PLACE="In-place",t.COLUMNS="Impute",t.FEATURES="Using",t.CANCEL="CANCEL",t.RUN="RUN",t.OK="OK",t.NEIGHBORS="Neighbors",t.DISTANCE="Distance",t.FILL="Fill",t.MARK="Mark",t.SIMPLE_IMPUTER="Simple impute",t.SETTINGS="Settings",t.KEEP_EMPTY="Keep empty"}(je||(je={}));const Ye="/help/explore/missing-values-imputation#the-k-nn-method";var ze;!function(t){t.TARGET="Columns with missing values that must be filled",t.FEATURES="Columns with features to be used for determining the 'nearest' elements in the k-NN method",t.IN_PLACE="Defines whether to use in-place imputation or add a new column without missing values",t.METRIC="Type of metric between the feature values",t.WEIGHT="Weight",t.NEIGHBORS="Neighbors count used in the KNN method",t.DISTANCE="Type of distance between elements with the specified features",t.METRIC_SETTINGS="Show additional options",t.FILL_FAILED_ITEMS="Impute missing values using a simple approach: mean, median or most frequent",t.MARK_FAILED_ITEMS="Mark missing values cells with a color",t.FILL_VALUE="Fill value",t.IMPUTATION_SETTINGS="Simple imputation settings",t.KEEP_EMPTY="Defines whether to keep empty missing values failed to be imputed OR fill them using simple imputation",t.RUN="Run imputation using the k-NN method"}(ze||(ze={}));const qe=15,He=[o.COLUMN_TYPE.INT,o.COLUMN_TYPE.FLOAT,o.COLUMN_TYPE.STRING,o.COLUMN_TYPE.DATE_TIME,o.COLUMN_TYPE.QNUM];function $e(t){switch(t.type){case o.COLUMN_TYPE.INT:return o.INT_NULL;case o.COLUMN_TYPE.FLOAT:case o.COLUMN_TYPE.QNUM:case o.COLUMN_TYPE.DATE_TIME:return o.FLOAT_NULL;case o.COLUMN_TYPE.STRING:return t.max;default:throw new Error(Be.UNSUPPORTED_COLUMN_TYPE)}}var Ke,Xe,Qe;!function(t){t.ONE_HOT="One-hot",t.DIFFERENCE="Difference"}(Ke||(Ke={})),function(t){t.EUCLIDEAN="Euclidean",t.MANHATTAN="Manhattan"}(Xe||(Xe={})),function(t){t[t.WEIGHT=1]="WEIGHT",t[t.NEIGHBORS=4]="NEIGHBORS",t[t.IN_PLACE=1]="IN_PLACE",t[t.SELECTED=1]="SELECTED",t[t.KEEP_EMPTY=0]="KEEP_EMPTY"}(Qe||(Qe={}));const Je=1;function Ze(t,e,n){for(const t of e)if(!n.has(t))return!1;for(const r of t){const t=n.get(r);if(void 0===t)throw new Error(Be.FAILS_TO_PREDICT_IMPUTATION_FAILS);for(const r of t){let t=!0;for(const o of e){const e=n.get(o);if(void 0===e)throw new Error(Be.FAILS_TO_PREDICT_IMPUTATION_FAILS);if(!e.includes(r)){t=!1;break}}if(t)return!0}}return!1}var tn;function en(t){if(t<=0||t>=1)throw new Error(tn.INCORRECT_SIGNIFICANCE_LEVEL)}function nn(t){const e=t.size;return e<=1?0:(t.sumOfSquares-Math.pow(t.sum,2)/e)/(e-1)}function rn(t,e,n){en(n);const r=nn(t),o=nn(e);return 0===r||0===o?r===o:r/o<Ve.centralF.inv(1-n,t.size-1,e.size-1)}!function(t){t.NON_EQUAL_FACTORS_VALUES_SIZE="non-equal sizes of factor and values arrays",t.INCORRECT_SIGNIFICANCE_LEVEL="incorrect significance level",t.NON_EQUAL_VARIANCES="non-equal variances",t.NON_NORMAL_DISTRIB="non-normal distribution",t.UNSUPPORTED_COLUMN_TYPE="unsupported feature column type",t.INCORRECT_CATEGORIES_COL_TYPE="incorrect categories column type",t.SINGLE_FACTOR="single category features",t.CATS_EQUAL_SIZE="single value in each category",t.NO_FEATURE_VARIATION="no feature variation",t.NO_FEATURE_VARIATION_WITHIN_GROUPS="no feature variation within groups"}(tn||(tn={}));class on{constructor(t,e,n){if(this.nullsCount=0,t.length!==e.length)throw new Error(tn.NON_EQUAL_FACTORS_VALUES_SIZE);if(!(e.stats.stdev>0))throw new Error(tn.NO_FEATURE_VARIATION);this.setStats(t,e,n)}areVarsEqual(t){const e=this.catCount;if(1===e)return!0;const n={sum:this.sums[0],sumOfSquares:this.sumsOfSquares[0],size:this.subSampleSizes[0]};for(let r=1;r<e;++r)if(!rn(n,{sum:this.sums[r],sumOfSquares:this.sumsOfSquares[r],size:this.subSampleSizes[r]},t))return!1;return!0}getOneWayAnova(){let t=0,e=0,n=0,r=this.catCount,o=r;for(let i=0;i<r;++i)0!==this.subSampleSizes[i]?(t+=this.sums[i],e+=this.sumsOfSquares[i],n+=Math.pow(this.sums[i],2)/this.subSampleSizes[i]):--o;if(r=o,1===r)throw new Error(tn.SINGLE_FACTOR);const i=this.size-this.nullsCount;if(i===r)throw new Error(tn.CATS_EQUAL_SIZE);const a=e-Math.pow(t,2)/i,s=n-Math.pow(t,2)/i,u=a-s;if(0===u)throw new Error(tn.NO_FEATURE_VARIATION_WITHIN_GROUPS);const c=r-1,l=i-r,d=s/c,h=u/l,f=d/h;return{ssBn:s,ssWn:u,ssTot:a,dfBn:c,dfWn:l,dfTot:i-1,msBn:d,msWn:h,fStat:f,pValue:1-Ve.centralF.cdf(f,c,l)}}setStats(t,e,n){const r=e.type,i=e.length,a=$e(e);switch(r){case o.COLUMN_TYPE.INT:case o.COLUMN_TYPE.FLOAT:const r=n;this.catCount=r,this.size=i;const s=e.getRawData(),u=t.getRawData(),c=new Float64Array(r).fill(0),l=new Float64Array(r).fill(0),d=new Int32Array(r).fill(0);let h;if(t.type==o.COLUMN_TYPE.BOOL){let t=0,e=0,n=u[0];const r=8*u.BYTES_PER_ELEMENT-1;for(let o=0;o<i;++o)h=1&n>>e,s[o]!==a?(c[h]+=s[o],l[h]+=Math.pow(s[o],2),++d[h]):++this.nullsCount,++e,e>r&&(e=0,++t,n=u[t])}else{const e=t.stats.missingValueCount>0?$e(t):-1;for(let t=0;t<i;++t)h=u[t],h!==e&&s[t]!==a?(c[h]+=s[t],l[h]+=Math.pow(s[t],2),++d[h]):++this.nullsCount}this.sums=c,this.sumsOfSquares=l,this.subSampleSizes=d;break;default:throw new Error(tn.UNSUPPORTED_COLUMN_TYPE)}}}const an=[o.COLUMN_TYPE.INT,o.COLUMN_TYPE.FLOAT],sn=[o.COLUMN_TYPE.STRING,o.COLUMN_TYPE.BOOL],un="/help/explore/anova";var cn,ln;function dn(){const n=t.shell.t;if(null===n)return void t.shell.warning("No dataframe is opened");const r=n.columns,i=[],a=[];for(const t of r)an.includes(t.type)?a.push(t.name):sn.includes(t.type)&&i.push(t.name);const s=i.length;if(s<1)return void t.shell.warning(e.markdown(`No acceptable factor columns:\n\n - type: ${sn.join(", ")} \n - at least two categories`));let u=n.col(ln.FACTOR);if(null===u){let t,e=0,n=r.byName(i[0]).categories.length;for(let o=1;o<s;++o)t=r.byName(i[o]).categories.length,t<n&&(n=t,e=o);u=r.byName(i[e])}if(a.length<1)return void t.shell.warning(e.markdown(`No acceptable feature columns:\n \n - type: ${an.join(", ")}`));const c=e.input.column("Category",{table:n,value:u,tooltipText:"Column with factor values",onValueChanged:t=>u=t,filter:t=>i.includes(t.name),nullable:!1});let l=n.col(ln.FEATURE);null===l&&(l=r.byName(a[0]));const d=e.input.column("Feature",{table:n,value:l,tooltipText:"Column with feature values",onValueChanged:t=>l=t,filter:t=>a.includes(t.name),nullable:!1});let h=cn.DEFAULT;const f=e.input.float("Alpha",{min:cn.MIN,max:cn.MAX,value:h,nullable:!1,tooltipText:"Significance level",onValueChanged:t=>{h=t,g.disabled=h<=cn.INFIMUM||h>=cn.SUPREMUM}}),p=e.dialog({title:"ANOVA",helpUrl:un}),m=t.shell.getTableView(n.name);m.root.appendChild(p.root),p.addButton("Run",(()=>{p.close();try{const r=function(t,e,n,r=!0){en(n);const o=t.stats.uniqueCount;if(o<2)throw new Error(tn.SINGLE_FACTOR);const i=new on(t,e,o);if(r&&!i.areVarsEqual(n))throw new Error(tn.NON_EQUAL_VARIANCES);const a=i.getOneWayAnova();return{anovaTable:a,fCritical:Ve.centralF.inv(1-n,a.dfBn,a.dfWn),significance:n}}(u,l,h);!function(n,r,i,a){const s=a.anovaTable.fStat>a.fCritical,u=s?`"${r}" affects the "${i}"`:`"${r}" doesn't affect the "${i}"`,c=t.shell.getTableView(n.name),l=o.Viewer.boxPlot(n,{categoryColumnNames:[r],valueColumnName:i,showPValue:!1,showStatistics:!1,description:u,showColorSelector:!1}),d=c.dockManager.dock(l.root,o.DOCK_TYPE.RIGHT,null,"ANOVA"),h=e.markdown(`**H0:** the "${r}" \n factor does not produce a significant difference in the "${i}" feature.`);e.tooltip.bind(h,"Null hypothesis");const f=e.markdown("**Test result:** "+(s?"means differ significantly.":"means do not differ significantly.")),p=s?e.divV([e.p(`Reject the null hypothesis, since F > F-critical: \n ${a.anovaTable.fStat.toFixed(2)} > ${a.fCritical.toFixed(2)}.`),e.h2("There is a significant difference among sample averages.")]):e.divV([e.p(`Fail to reject the null hypothesis, since F < F-critical: \n ${a.anovaTable.fStat.toFixed(2)} < ${a.fCritical.toFixed(2)}.`),e.h2("There is no significant difference among sample averages.")]);e.tooltip.bind(f,(()=>p));const m=e.divV([h,f,e.link("Learn more",(()=>window.open("https://en.wikipedia.org/wiki/F-test","_blank")),"Click to open in a new tab")]);m.style.marginLeft="20px";const g=t.shell.dockManager.dock(m,o.DOCK_TYPE.DOWN,d,"F-test",.3),y=function(t){const n=t.anovaTable,r=o.Viewer.grid(o.DataFrame.fromColumns([o.Column.fromStrings("Source of variance",["Between groups","Within groups","Total"]),o.Column.fromList(o.COLUMN_TYPE.FLOAT,"SS",[n.ssBn,n.ssWn,n.ssTot]),o.Column.fromList(o.COLUMN_TYPE.INT,"DF",[n.dfBn,n.dfWn,n.dfTot]),o.Column.fromList(o.COLUMN_TYPE.FLOAT,"MS",[n.msBn,n.msWn,null]),o.Column.fromList(o.COLUMN_TYPE.FLOAT,"F",[n.fStat,null,null]),o.Column.fromList(o.COLUMN_TYPE.FLOAT,"F-critical",[t.fCritical,null,null]),o.Column.fromList(o.COLUMN_TYPE.FLOAT,"p-value",[n.pValue,null,null])])),i=new Map([["Source of variance","List of the explored variation sources"],["SS","Sum of squares (SS)"],["DF","Degrees of freedom (DF)"],["MS","Mean square (MS)"],["F","F-statistics (F)"],["F-critical",`${t.significance}-critical value of F-statistics (F)`],["p-value","Probability to obtain F-statistics (F) greater than the actual observation."]]);return r.onCellTooltip((function(t,n,r){if(t.isColHeader)return e.tooltip.show(e.divV([e.p(i.get(t.tableColumn.name))]),n,r),!0})),r.helpUrl=un,r}(a);t.shell.dockManager.dock(y.root,o.DOCK_TYPE.FILL,g,"Analysis")}(n,u.name,l.name,r)}catch(n){n instanceof Error?(t.shell.warning((r=n.message,e.divV([e.markdown(`ANOVA cannot be performed:\n \n ${r}`),e.link("Learn more",(()=>window.open("https://en.wikipedia.org/wiki/Analysis_of_variance#Assumptions","_blank")),"Click to open in a new tab")]))),m.addViewer(o.VIEWER.BOX_PLOT,{categoryColumnNames:[u.name],valueColumnName:l.name,showStatistics:!1,showPValue:!1})):t.shell.error("ANOVA fails: the platform issue")}var r}),void 0,"Perform analysis of variances");const g=p.getButton("Run");p.add(c).add(d).add(f).show()}!function(t){t[t.DEFAULT=.05]="DEFAULT",t[t.MIN=.01]="MIN",t[t.MAX=.99]="MAX",t[t.INFIMUM=0]="INFIMUM",t[t.SUPREMUM=1]="SUPREMUM"}(cn||(cn={})),function(t){t.FACTOR="race",t.FEATURE="age"}(ln||(ln={}));var hn=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{u(r.next(t))}catch(t){i(t)}}function s(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,s)}u((r=r.apply(t,e||[])).next())}))};function fn(t,e,r,o){return hn(this,void 0,void 0,(function*(){return new Promise((function(i,a){const s=new Worker(new URL(n.p+n.u(682),n.b));s.postMessage({embedX:t,embedY:e,minPts:o,epsilon:r}),s.onmessage=({data:{error:t,clusters:e}})=>{s.terminate(),t?a(t):i(e)}}))}))}n(5540);let pn=null;function mn(){return t=this,e=void 0,r=function*(){if(!navigator.gpu)return console.error("WebGPU is not supported in this browser"),null;if(!pn&&(pn=yield navigator.gpu.requestAdapter(),null==pn))return null;let t=null;return"info"in pn&&(t=pn.info),t?gn(t.description,gn(t.vendor,"No GPU description available")):"No GPU description available"},new((n=void 0)||(n=Promise))((function(o,i){function a(t){try{u(r.next(t))}catch(t){i(t)}}function s(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,s)}u((r=r.apply(t,e||[])).next())}));var t,e,n,r}function gn(t,e){return t&&""!=t?t:e}var yn,vn,wn,bn,En,An,Cn,Sn,_n;(vn=yn||(yn={})).EUCLIDEAN="EUCLIDEAN",vn.MANHATTAN="MANHATTAN",yn.EUCLIDEAN,yn.MANHATTAN,(bn=wn||(wn={})).HAMMING="Hamming",bn.EUCLIDEAN="Euclidean",bn.MANHATTAN="Manhattan",bn.TANIMOTO="Tanimoto",bn.LEVENSTEIN="Levenshtein",bn.NEEDLEMAN_WUNSCH="Needlemann-Wunsch",bn.MONOMER_CHEMICAL_DISTANCE="Monomer chemical distance",bn.SOKAL="Sokal",bn.COSINE="Cosine",bn.ASYMMETRIC="Asymmetric",bn.Difference="Difference",bn.OneHot="One-Hot",wn.HAMMING,wn.EUCLIDEAN,wn.MANHATTAN,wn.TANIMOTO,wn.LEVENSTEIN,wn.NEEDLEMAN_WUNSCH,wn.MONOMER_CHEMICAL_DISTANCE,wn.SOKAL,wn.COSINE,wn.ASYMMETRIC,wn.Difference,wn.OneHot,wn.HAMMING,wn.EUCLIDEAN,wn.MANHATTAN,wn.TANIMOTO,wn.SOKAL,wn.COSINE,wn.ASYMMETRIC,wn.LEVENSTEIN,wn.NEEDLEMAN_WUNSCH,wn.MONOMER_CHEMICAL_DISTANCE,wn.Difference,wn.OneHot,new Set([wn.HAMMING,wn.LEVENSTEIN,wn.NEEDLEMAN_WUNSCH,wn.MONOMER_CHEMICAL_DISTANCE,wn.OneHot]),new Set([wn.HAMMING,wn.EUCLIDEAN,wn.MANHATTAN,wn.MONOMER_CHEMICAL_DISTANCE,wn.LEVENSTEIN,wn.NEEDLEMAN_WUNSCH,wn.TANIMOTO,wn.COSINE,wn.SOKAL,wn.ASYMMETRIC,wn.OneHot,wn.Difference]),new Set([wn.EUCLIDEAN,wn.MANHATTAN,wn.OneHot,wn.Difference]),new Set([wn.EUCLIDEAN,wn.MANHATTAN,wn.Difference]),new Set([wn.EUCLIDEAN,wn.MANHATTAN,wn.Difference]),new Set([wn.TANIMOTO,wn.COSINE,wn.SOKAL,wn.ASYMMETRIC]),function(t){t.ADD="ADD",t.SUB="SUB",t.MULT="MULT"}(En||(En={})),function(t){t.SQUARE="SQUARE",t.INVERSE="INVERSE",t.TRANSPOSE="TRANSPOSE",t.NORM="NORM",t.COLUMN_NORM="COLUMN_NORM"}(An||(An={})),function(t){t.SCALARMULT="SCALARMULT",t.SCALARADD="SCALARADD",t.SCALARPOW="SCALARPOW"}(Cn||(Cn={})),Object.prototype.toString,(_n=Sn||(Sn={})).UMAP="UMAP",_n.T_SNE="t-SNE",Promise.resolve(),n(934),n(8903);const Nn=2;o.SEMTYPE.MOLECULE,o.SEMTYPE.MACROMOLECULE;class In{constructor(){this.epsilon={uiName:"Epsilon",value:.01,tooltip:"Minimum distance between cluster points",min:0,max:2,step:.005},this.minPts={uiName:"Minimum points",value:4,tooltip:"Minimum number of points in cluster",min:1,max:1e3,step:1}}}const Mn="bypassLargeDataWarning",Tn="show-scatterplot-progress";var On,Pn;(Pn=On||(On={})).EUCLIDEAN="EUCLIDEAN",Pn.MANHATTAN="MANHATTAN";const Ln=rxjs;var xn=n(5072),Fn=n.n(xn),Rn=n(7825),Dn=n.n(Rn),Un=n(7659),kn=n.n(Un),Gn=n(5056),Bn=n.n(Gn),Vn=n(540),Wn=n.n(Vn),jn=n(1113),Yn=n.n(jn),zn=n(7939),qn={};qn.styleTagTransform=Yn(),qn.setAttributes=Bn(),qn.insert=kn().bind(null,"head"),qn.domAPI=Dn(),qn.insertStyleElement=Wn(),Fn()(zn.A,qn),zn.A&&zn.A.locals&&zn.A.locals;class Hn{constructor(){this.learningRate={uiName:"Learninig rate",value:1,tooltip:"The initial learning rate for the embedding optimization"},this.nEpochs={uiName:"Epochs",value:0,tooltip:"The number of epochs to optimize embeddings via SGD. Computed automatically if set to 0"},this.nNeighbors={uiName:"Neighbors",value:15,tooltip:"The number of nearest neighbors to construct the fuzzy manifold"},this.spread={uiName:"Spread",value:1,tooltip:"The effective scale of embedded points, used with min distance to control \n the clumped/dispersed nature of the embedding"},this.minDist={uiName:"Min distance",value:.1,tooltip:"The effective minimum distance between embedded points, \n used with spread to control the clumped/dispersed nature of the embedding"},this.randomSeed={uiName:"Random seed",value:null,tooltip:"Random seed",type:"string"},this.useWebGPU={uiName:"Use WebGPU",value:!1,tooltip:"Use WebGPU for Distance and UMAP computations",type:"boolean",disableTooltip:"WebGPU is not available"},mn().then((t=>{t?(this.useWebGPU.tooltip+=` (${t})`,this.useWebGPU.value=!0):(this.useWebGPU.value=!1,this.useWebGPU.disable=!0)}))}}class $n{constructor(){this.epsilon={uiName:"Epsilon",value:10,tooltip:"Epsilon is learning rate"},this.perplexity={uiName:"Perplexity",value:30,tooltip:"Roughly how many neighbors each point influences"}}}class Kn{constructor(n={}){this.editorSettings={},this.columnOptEditors=[],this.columnOptEditorsRoot=e.div(),this.columnParamsEditorRoot=e.div(),this.weightsEditorRoot=e.div(),this.columnFunctionsMap={},this.methodsParams={[Sn.UMAP]:new Hn,[Sn.T_SNE]:new $n},this.dbScanParams=new In,this.methodSettingsDivs=[],this.supportedFunctions={},this.methodSettingsAnchor=e.div(),this.plotEmbeddingsInput=e.input.bool("Plot embeddings",{value:!0}),this.aggregationMethodInput=e.input.choice("Aggregation",{value:On.EUCLIDEAN,items:[On.EUCLIDEAN,On.MANHATTAN]}),this.aggregationMethodInput.setTooltip("Aggregation method for combining distances between columns"),this.onColumnsChanged=new Ln.Subject,this.editorSettings=n,this.columnParamsEditorAccordion=e.accordion(),o.Func.find({tags:["dim-red-preprocessing-function"]}).forEach((t=>{const e=t.options.get("supportedSemTypes")??"",n=t.friendlyName??t.name,r=t.options.get("supportedTypes")??"",o=t.options.get("supportedUnits")??"",i=t.options.get("supportedDistanceFunctions")??"";this.editorSettings.semtype&&!e.includes(this.editorSettings.semtype)||this.editorSettings.type&&!r.includes(this.editorSettings.type)||this.editorSettings.units&&!o.includes(this.editorSettings.units)||(this.supportedFunctions[n]={func:t,semTypes:e?e.split(","):[],types:r?r.split(","):[],units:o?o.split(","):[],distanceFunctions:i?i.split(","):[]})})),this.postProcessingEditor=new Jn,this.tableInput=e.input.table("Table",{value:t.shell.tv.dataFrame,items:t.shell.tables,onValueChanged:()=>{this.onTableInputChanged()}}),this.onTableInputChanged();let r=!1;this.methodInput=e.input.choice("Method",{value:Sn.UMAP,items:[Sn.UMAP,Sn.T_SNE],onValueChanged:t=>{r&&this.createAlgorithmSettingsDiv(this.methodsParams[t])}}),this.methodSettingsIcon=e.icons.settings((()=>{r=!r,r?this.createAlgorithmSettingsDiv(this.methodsParams[this.methodInput.value]):(this.methodSettingsDivs.forEach((t=>t.remove())),this.methodSettingsDivs=[])}),"Modify methods parameters"),this.methodInput.root.classList.add("ml-dim-reduction-settings-input"),this.methodInput.root.prepend(this.methodSettingsIcon),this.columnParamsEditorAccordion.addPane("Column options",(()=>this.columnOptEditorsRoot),!0,null,!1),this.columnParamsEditorAccordion.root.style.display="none",this.columnParamsEditorRoot.appendChild(this.columnParamsEditorAccordion.root),this.columnParamsEditorRoot.appendChild(this.weightsEditorRoot)}onTableInputChanged(){const t=this.tableInput.value;if(!t)return;e.empty(this.columnOptEditorsRoot),e.empty(this.weightsEditorRoot),this.columnFunctionsMap={},t.columns.toList().forEach((t=>{Object.keys(this.supportedFunctions).forEach((e=>{const n=this.supportedFunctions[e].semTypes,r=this.supportedFunctions[e].types,o=this.supportedFunctions[e].units,i=!n.length||t.semType&&n.includes(t.semType),a=!r.length||r.includes(t.type),s=!o.length||t.meta.units&&o.includes(t.meta.units);i&&a&&s&&(this.columnFunctionsMap[t.name]||(this.columnFunctionsMap[t.name]=[]),this.columnFunctionsMap[t.name].push(e))}))}));const n=Object.keys(this.columnFunctionsMap),r=e.input.columns("Columns",{table:t,onValueChanged:t=>{if(this.onColumnsChanged.next(),e.empty(this.columnOptEditorsRoot),e.empty(this.weightsEditorRoot),this.aggregationMethodInput.root.style.display=!t||t?.length<2?"none":"flex",!t||0===t.length)return void(this.columnParamsEditorAccordion.root.style.display="none");this.columnOptEditors=t.map((t=>new Xn(t,this.columnFunctionsMap[t.name].map((t=>this.supportedFunctions[t])))));const n=e.divV([],{style:{maxHeight:"400px",overflow:"auto"}});this.columnOptEditors.forEach((t=>{n.appendChild(t.accordionDiv)}));const r=new Array(2*this.columnOptEditors.length).fill(null).map(((t,e)=>e%2==0?this.columnOptEditors[e/2].colOptEditors:[]));let o=0;const i=e.table(r,(t=>(o++,t&&t.length>0?t:[this.columnOptEditors[Math.floor((o-1)/2)].preprocessingFuncSettingsDiv=e.div([]),e.div(),e.div(),e.div()])),["Column","Encoding function","Similarity metric","Weight"]);this.columnOptEditors.forEach((t=>{t.preprocessingFuncSettingsDiv?.parentElement?.setAttribute("colspan","4"),t.preprocessingFuncSettingsDiv?.parentElement?.parentElement?.style?.setProperty("height","unset")})),this.columnOptEditors.length>0&&(this.columnParamsEditorAccordion.root.style.display="flex"),i.classList.add("ml-dim-reduction-column-editor-table-root"),this.columnOptEditorsRoot.appendChild(i)},available:n});r.fireChanged(),this.columnsInputRoot?(e.empty(this.columnsInputRoot),this.columnsInput=r,Array.from(this.columnsInput.root.children).forEach((t=>this.columnsInputRoot.appendChild(t)))):(this.columnsInputRoot=r.root,this.columnsInput=r)}createAlgorithmSettingsDiv(t){this.methodSettingsDivs.forEach((t=>t.remove())),this.methodSettingsDivs=[];const n=this.methodSettingsAnchor,r=n.parentElement;r&&Object.keys(t).forEach((o=>{const i=t[o],a="string"===i.type?e.input.string(i.uiName,{value:i.value??"",onValueChanged:t=>{i.value=t}}):"boolean"===i.type?e.input.bool(i.uiName,{value:i.value??!1,onValueChanged:t=>{i.value=t}}):e.input.float(i.uiName,{value:i.value,onValueChanged:t=>{i.value=t}});i.disable?(a.enabled=!1,e.tooltip.bind(a.input??a.root,i.disableTooltip??"")):e.tooltip.bind(a.input??a.root,i.tooltip),r.insertBefore(a.root,n),this.methodSettingsDivs.push(a.root)}))}get algorithmOptions(){const t=this.methodsParams[this.methodInput.value],e={};return Object.keys(t).forEach((n=>{null!=t[n].value&&(e[n]=t[n].value)})),e}get dbScanOptions(){return{dbScanEpsilon:this.dbScanParams.epsilon.value??.01,dbScanMinPts:this.dbScanParams.minPts.value??4}}getEditor(){return e.div([this.tableInput.root,this.columnsInputRoot,this.columnParamsEditorRoot,this.aggregationMethodInput.root,this.methodInput.root,this.methodSettingsAnchor,this.plotEmbeddingsInput,this.postProcessingEditor.root],{style:{minWidth:"420px"},classes:"dim-reduction-dialog-form"})}getParams(){return{table:this.tableInput.value,columns:this.columnsInput.value,methodName:this.methodInput.value,preprocessingFunctions:this.columnOptEditors.map((t=>t.preProcessingFunction)),distanceMetrics:this.columnOptEditors.map((t=>t.similarityMetricInput.value)),weights:this.columnOptEditors.map((t=>t.weight??1)),options:{...this.algorithmOptions,...this.dbScanOptions,preprocessingFuncArgs:this.columnOptEditors.map((t=>t.preprocessingFunctionSettings))},plotEmbeddings:this.plotEmbeddingsInput.value,clusterEmbeddings:!1,postProcessingFunction:this.postProcessingEditor.postProcessingFunction,postProcessingFunctionArgs:this.postProcessingEditor.args,aggreaggregationMethod:this.aggregationMethodInput.value}}getInput(){return{columns:this.columnsInput.value.map((t=>t.name)),method:this.methodInput.value,preprocessingFunctions:this.columnOptEditors.map((t=>t.preprocessingFunctionInput.value)),distanceMetrics:this.columnOptEditors.map((t=>t.similarityMetricInput.value)),weights:this.columnOptEditors.map((t=>t.weight??1)),options:{...this.algorithmOptions,...this.dbScanOptions,preprocessingFuncArgs:this.columnOptEditors.map((t=>t.preprocessingFunctionSettings))},plotEmbeddings:this.plotEmbeddingsInput.value,postProcessingFunction:this.postProcessingEditor.postProcessingFunctionInput.value??null,postProcessingFunctionArgs:this.postProcessingEditor.args,aggreaggregationMethod:this.aggregationMethodInput.value}}getStringInput(){return JSON.stringify(this.getInput())}async applyStringInput(e){try{const t=JSON.parse(e);await this.applyInput(t)}catch(e){t.shell.error("Error applying input from history"),console.error(e)}}async applyInput(e){try{const t=e.columns.map((t=>this.tableInput.value.col(t)));if(t.some((t=>!t)))throw new Error("Some columns are not found");this.columnsInput.value=t,this.columnsInput.fireChanged(),this.methodInput.value=e.method,this.columnOptEditors.forEach(((t,n)=>{t.preprocessingFunctionInput.value=e.preprocessingFunctions[n],t.similarityMetricInput.value=e.distanceMetrics[n],t.weightInput.value=e.weights[n],t.preprocessingFunctionSettings=e.options.preprocessingFuncArgs[n]})),this.plotEmbeddingsInput.value=e.plotEmbeddings,this.postProcessingEditor.postProcessingFunctionInput.value=e.postProcessingFunction,await this.postProcessingEditor._prevChangePromise,this.postProcessingEditor._postProcessingArgs=e.postProcessingFunctionArgs,this.aggregationMethodInput.value=e.aggreaggregationMethod;const n={};Object.keys(this.methodsParams[e.method]).forEach((t=>{n[t]=e.options[t]})),Object.keys(this.methodsParams[e.method]).forEach((t=>{this.methodsParams[e.method][t].value=n[t]}));const r=this.methodSettingsDivs.length>0;this.createAlgorithmSettingsDiv(this.methodsParams[e.method]),r||(this.methodSettingsDivs.forEach((t=>t.remove())),this.methodSettingsDivs=[]),await this.postProcessingEditor.onFunctionChanged(e.postProcessingFunctionArgs)}catch(e){t.shell.error("Error applying input from history"),console.error(e)}}}class Xn{constructor(t,n){this.preprocessingFuncSettingsDiv=e.div([]),this.preprocessingFunctionSettings={},this.editorDiv=e.div([]),this.hasExtraSettings=!0,this.functionsMap={},this.needsConfiguration=!1,this.weight=1,this.colOptEditors=[],this.weightInput=e.input.float("Weight",{value:1,onValueChanged:t=>{this.weight=t??1}}),this.column=t,this.supportedFunctions=n.sort(((t,e)=>0!==t.units.length&&0!==e.units.length||t.units.length===e.units.length?t.units.length!==e.units.length?t.units.length-e.units.length:0===t.semTypes.length||0===e.semTypes.length?e.semTypes.length-t.semTypes.length:t.semTypes.length!==e.semTypes.length?t.semTypes.length-e.semTypes.length:t.types.length-e.types.length:e.units.length-t.units.length)),this.supportedFunctions.forEach((t=>{this.functionsMap[Qn(t.func)]=t.func})),this.preprocessingFunctionInput=e.input.choice("Encoding function",{value:Qn(this.supportedFunctions[0].func),items:this.supportedFunctions.map((t=>Qn(t.func))),onValueChanged:t=>{const n=this.functionsMap[t];this.preprocessingFunctionSettings={},this.hasExtraSettings=n.inputs.length>2;const o=this.supportedFunctions.find((e=>Qn(e.func)===t));this.getSimilarityMetricInput(o),e.empty(this.preprocessingFuncSettingsDiv),r=!1,this.hasExtraSettings?this.preprocessingFuncSettingsIcon.style.display="flex":this.preprocessingFuncSettingsIcon.style.display="none"}}),this.preprocessingFunctionInput.root.style.display="flex",this.createSettingsDiv(this.preprocessingFuncSettingsDiv,this.supportedFunctions[0].func).then((()=>{e.empty(this.preprocessingFuncSettingsDiv)})),this.getSimilarityMetricInput(this.supportedFunctions[0]),this.hasExtraSettings=this.supportedFunctions[0].func.inputs.length>2;let r=!1;this.preprocessingFuncSettingsIcon=e.icons.settings((async()=>{r=!r,r?await this.createSettingsDiv(this.preprocessingFuncSettingsDiv,this.functionsMap[this.preprocessingFunctionInput.value]):e.empty(this.preprocessingFuncSettingsDiv)}),"Modify encoding function parameters"),this.preprocessingFunctionInput.root.classList.add("ml-dim-reduction-settings-input"),this.preprocessingFunctionInput.root.prepend(this.preprocessingFuncSettingsIcon),this.hasExtraSettings?this.preprocessingFuncSettingsIcon.style.display="flex":this.preprocessingFuncSettingsIcon.style.display="none",this.needsConfiguration=!(n.length<2&&!this.hasExtraSettings&&n[0].distanceFunctions.length<2);const o=e.h3(this.column.name,{classes:"ml-dim-reduction-column-editor-column-title"});this.colOptEditors=[o,this.preprocessingFunctionInput.root,this.similarityMetricInputRoot,this.weightInput.root],e.tooltip.bind(o,this.column.name),this.colOptEditors.forEach((t=>t.classList.add("ml-dim-reduction-column-editor-input-root")));const i=e.divH(this.colOptEditors,{classes:"ml-dim-reduction-column-editor-root"});this.accordionDiv=e.divV([]),this.editorDiv.appendChild(i),this.editorDiv.appendChild(this.preprocessingFuncSettingsDiv),this.accordionDiv.appendChild(this.editorDiv)}getSimilarityMetricInput(t){const n=e.input.choice("Similarity metric",{value:t.distanceFunctions[0],items:t.distanceFunctions});this.similarityMetricInputRoot?(e.empty(this.similarityMetricInputRoot),this.similarityMetricInput=n,Array.from(this.similarityMetricInput.root.children).forEach((t=>this.similarityMetricInputRoot.appendChild(t)))):(this.similarityMetricInputRoot=n.root,this.similarityMetricInput=n)}get preProcessingFunction(){return this.functionsMap[this.preprocessingFunctionInput.value]}async createSettingsDiv(t,n){if(e.empty(t),n.inputs.length<3)return e.div();const r=n.prepare(),o=await r.buildEditor(e.div());for(let e=2;e<n.inputs.length;e++){const i=n.inputs[e],a=this.preprocessingFunctionSettings[i.name]||r.inputParams[n.inputs[e].name].value||i.defaultValue;a&&(this.preprocessingFunctionSettings[i.name]=a);const s=o.find((t=>t.property.name===i.name));s&&(null!==this.preprocessingFunctionSettings[i.name]&&void 0!==this.preprocessingFunctionSettings[i.name]&&(s.value=this.preprocessingFunctionSettings[i.name]),s.onChanged.subscribe((t=>{this.preprocessingFunctionSettings[i.name]=t})),t.append(s.root))}return t.style.marginBottom="10px",t}}function Qn(t){return t.friendlyName??t.name}class Jn{constructor(){this.postProcessingFunctionsMap={},this._root=e.div([]),this._postProcessingArgs={},this._argsElement=e.div([]),this._settingsOpened=!1,this._prevChangePromise=Promise.resolve(),this._settingsIcon=e.icons.settings((async()=>{this._settingsOpened=!this._settingsOpened,this._settingsOpened?this._argsElement.style.display="block":this._argsElement.style.display="none"})),this._argsElement.style.display="none",o.Func.find({tags:["dim-red-postprocessing-function"]}).filter((t=>t.inputs.length>=2)).forEach((t=>{const e=t.friendlyName??t.name;this.postProcessingFunctionsMap[e]=t})),this.postProcessingFunctionsMap.None=null;const t=Object.keys(this.postProcessingFunctionsMap).find((t=>!!this.postProcessingFunctionsMap[t]?.options?.defaultPostProcessingFunction))??"None";this.postProcessingFunctionInput=e.input.choice("Postprocessing",{value:t,items:Object.keys(this.postProcessingFunctionsMap),onValueChanged:async()=>{await this.onFunctionChanged()},nullable:!1}),this.onFunctionChanged(),this.postProcessingFunctionInput.nullable=!1,this.postProcessingFunctionInput.classList.add("ml-dim-reduction-settings-input"),this.postProcessingFunctionInput.root.prepend(this._settingsIcon),this._root.appendChild(this.postProcessingFunctionInput.root),this._root.appendChild(this._argsElement)}get postProcessingFunction(){return this.postProcessingFunctionInput.value?this.postProcessingFunctionsMap[this.postProcessingFunctionInput.value]:null}async onFunctionChanged(n={}){let r;await this._prevChangePromise,this._prevChangePromise=new Promise((t=>r=t));try{const t=this.postProcessingFunction;if(e.empty(this._argsElement),this._postProcessingArgs={},!t||t.inputs.length<3)return void(this._settingsIcon.style.display="none");this._settingsIcon.style.display="flex";const r=t.prepare(n),o=await r.buildEditor(e.div());for(let e=2;e<t.inputs.length;e++){const n=t.inputs[e],i=this._postProcessingArgs[n.name]||r.inputParams[t.inputs[e].name].value||n.defaultValue;i&&(this._postProcessingArgs[n.name]=i);const a=o.find((t=>t.property.name===n.name));a&&(a.onChanged.subscribe((t=>{this._postProcessingArgs[n.name]=t})),this._argsElement.append(a.root))}}catch(e){t.shell.error("Error applying postprocessing function"),console.error(e)}finally{r()}}get root(){return this._root}get args(){return this._postProcessingArgs}}const Zn="dimensionality-reducer-terminate-event",tr=t=>null==t;function er(t,e){return`${e} (${t.length>4?`${t.length} columns`:t.map((t=>t.name)).join(", ")})`}var nr=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{u(r.next(t))}catch(t){i(t)}}function s(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,s)}u((r=r.apply(t,e||[])).next())}))};function rr(n){return nr(this,void 0,void 0,(function*(){if(null!=n||(n=t.shell.t),null===n)return void t.shell.warning(Be.NO_DATAFRAME);const r=[],i=[],a=[];n.columns.toList().filter((t=>He.includes(t.type))).forEach((t=>{const e=t.stats.missingValueCount;e!==t.length&&(a.push(t.name),e>0&&(r.push(t),i.push(t.name)))}));const s=function(t){const e=new Map;for(const n of t){if(!He.includes(n.type))throw new Error(Be.UNSUPPORTED_COLUMN_TYPE);if(0===n.stats.missingValueCount)continue;const t=[],r=$e(n);n.getRawData().forEach(((e,n)=>{e===r&&t.push(n)})),e.set(n.name,t)}return e}(r);if(0===r.length)return void t.shell.info(Be.NO_MISSING_VALUES);if(1===a.length)return void t.shell.error(Be.ONE_AVAILABLE_FEATURE);let u=Qe.IN_PLACE>0;const c=e.input.bool(je.IN_PLACE,{value:u,onValueChanged:t=>{u=null!=t&&t}});c.setTooltip(ze.IN_PLACE);let l=Qe.KEEP_EMPTY>0;const d=e.input.bool(je.KEEP_EMPTY,{value:l,onValueChanged:t=>{l=null!=t&&t}});d.setTooltip(ze.KEEP_EMPTY);let h=Qe.NEIGHBORS;const f=e.input.int(je.NEIGHBORS,{value:h,showPlusMinus:!0,min:Je,nullable:!1,onValueChanged:t=>{null!==t&&t>=Je&&(h=t),E()}});f.setTooltip(ze.NEIGHBORS);let p=Xe.EUCLIDEAN;const m=e.input.choice(je.DISTANCE,{value:p,items:[Xe.EUCLIDEAN,Xe.MANHATTAN],onValueChanged:t=>p=null!=t?t:Xe.EUCLIDEAN});m.setTooltip(ze.DISTANCE);let g=r.map((t=>t.name));const y=e.input.columns(je.COLUMNS,{table:n,value:n.columns.byNames(i),onValueChanged:t=>{g=t.map((t=>t.name)),E()},available:i});y.setTooltip(ze.TARGET);let v=a;const w=e.input.columns(je.FEATURES,{value:n.columns.byNames(a),table:n,onValueChanged:t=>{v=t.map((t=>t.name)),v.length>0?(E(),C.forEach(((t,e)=>t.hidden=!v.includes(e)))):b()},available:a});w.setTooltip(ze.FEATURES);const b=()=>{_.getButton(je.RUN).disabled=!0,c.root.hidden=!0,d.root.hidden=!0,f.root.hidden=!0,I.hidden=!0,S.hidden=!0},E=()=>{_.getButton(je.RUN).disabled=null===f.value||f.value<Je,I.hidden=!1,c.root.hidden=!1,f.root.hidden=!1,m.root.hidden=!1,d.root.hidden=!Ze(g,v,s),1===v.length&&g.forEach((e=>{v[0]===e&&(b(),t.shell.warning(`${Be.ONE_FEATURE_SELECTED} the column '${e}'`))})),g.length<1&&b()},A=new Map,C=new Map,S=e.divV([]);S.style.overflow="auto",a.forEach((t=>{const r=function(t){switch(t){case o.COLUMN_TYPE.STRING:case o.COLUMN_TYPE.DATE_TIME:return{defaultWeight:Qe.WEIGHT,defaultMetric:Ke.ONE_HOT,availableMetrics:[Ke.ONE_HOT]};case o.COLUMN_TYPE.INT:case o.COLUMN_TYPE.FLOAT:case o.COLUMN_TYPE.QNUM:return{defaultWeight:Qe.WEIGHT,defaultMetric:Ke.DIFFERENCE,availableMetrics:[Ke.DIFFERENCE,Ke.ONE_HOT]};default:throw new Error(Be.UNSUPPORTED_COLUMN_TYPE)}}(n.col(t).type);A.set(t,{weight:r.defaultWeight,type:r.defaultMetric});const i=e.input.choice(t,{value:r.defaultMetric,items:r.availableMetrics,onValueChanged:e=>{var n;const o=null!==(n=A.get(t))&&void 0!==n?n:{weight:r.defaultWeight,type:r.defaultMetric};o.type=null!=e?e:r.defaultMetric,A.set(t,o)}});i.root.style.width="50%",i.setTooltip(ze.METRIC),i.root.hidden=!0;const a=o.Property.fromOptions({name:t.length<qe?t:t.slice(0,qe).concat("..."),inputType:"Float",min:0,max:10,showSlider:!0,step:1}),s=e.input.forProperty(a);s.value=r.defaultWeight,s.onChanged.subscribe((e=>{var n;const o=null!==(n=A.get(t))&&void 0!==n?n:{weight:r.defaultWeight,type:r.defaultMetric};o.weight=null!=e?e:r.defaultWeight,A.set(t,o)})),e.tooltip.bind(s.captionLabel,t),e.tooltip.bind(s.input,ze.WEIGHT),C.set(t,s.root),S.append(s.root)}));const _=e.dialog({title:je.KNN_IMPUTER,helpUrl:Ye});t.shell.v.root.appendChild(_.root),S.hidden=!0,d.root.hidden=!Ze(g,v,s);const N=e.icons.settings((()=>{S.hidden=!S.hidden}),ze.METRIC_SETTINGS),I=e.divH([m.root,N]);let M,T,O=!1;const P=new Promise(((t,e)=>{M=t,T=e}));return _.addButton(je.RUN,(()=>{O=!0,_.close(),a.filter((t=>!v.includes(t))).forEach((t=>A.delete(t)));try{const e=function(e,n,r,i,a,s,u){if(s<Je)throw new Error(Be.INCORRECT_NEIGHBORS);if(e.rowCount<2)throw new Error(Be.KNN_NOT_ENOUGH_OF_ROWS);if(0===n.length)throw new Error(Be.KNN_NO_TARGET_COLUMNS);if(0===r.size)throw new Error(Be.KNN_NO_FEATURE_COLUMNS);1===r.size&&n.forEach((t=>{if(r.has(t))throw new Error(`${Be.KNN_NO_FEATURE_COLUMNS} can be used for the column '${t}'`)})),n.forEach((t=>{if(!i.has(t))throw new Error(`${Be.KNN_FAILS}: ${Be.WRONG_PREDICTIONS}`)}));const c=e.columns;n.forEach((t=>{if(!He.includes(c.byName(t).type))throw new Error(Be.UNSUPPORTED_COLUMN_TYPE)})),r.forEach(((t,n)=>{if(!He.includes(e.getCol(n).type))throw new Error(Be.UNSUPPORTED_COLUMN_TYPE)}));const l=new Map;return n.forEach((n=>{const d=c.byName(n),h=$e(d),f=d.length,p=d.getRawData(),m=new Uint16Array(d.categories.length),g=[],y=[],v=[],w=[];r.forEach(((t,e)=>{if(e!==d.name){const n=c.byName(e);switch(g.push(n.getRawData()),y.push($e(n)),t.type){case Ke.DIFFERENCE:v.push(((e,n)=>t.weight*Math.abs(e-n)));break;case Ke.ONE_HOT:v.push(((e,n)=>t.weight*(e===n?0:1)))}}}));const b=g.length,E=new Uint32Array(g.length),A=new Float32Array(g.length);let C=0;const S=new Array(s);let _=0,N=0,I=0,M=0,T=0;const O=(t,e)=>{E.forEach(((n,r)=>{A[r]=v[n](g[n][t],g[n][e])}))},P=a===Xe.EUCLIDEAN?()=>{let t=0;for(let e=0;e<C;++e)t+=A[e]*A[e];return Math.sqrt(t)}:()=>{let t=0;for(let e=0;e<C;++e)t+=Math.abs(A[e]);return Math.sqrt(t)},L=t=>{if(p[t]===h)return!1;for(let e=0;e<C;++e)if(g[E[e]][t]===y[E[e]])return!1;return!0},x=t=>{if((t=>{C=0;for(let e=0;e<b;++e)g[e][t]!==y[e]&&(E[C]=e,++C)})(t),0===C)throw new Error(`${Be.KNN_IMPOSSIBLE_IMPUTATION}: the column "${d.name}", row ${t+1}`);_=0;for(let e=0;e<f;++e)if(L(e)&&e!==t){O(t,e);const n=P();if(_<s)S[_]={index:e,dist:n},++_;else{N=0,I=S[0].dist;for(let t=1;t<_;++t)I<S[t].dist&&(I=S[t].dist,N=t);n<I&&(S[N]={index:e,dist:n})}}if(0===_)throw new Error(`${Be.KNN_IMPOSSIBLE_IMPUTATION}: the column "${d.name}", row ${t+1}`);if(d.type===o.COLUMN_TYPE.STRING)return(()=>{m.forEach(((t,e,n)=>n[e]=0));let t=0;for(t=0;t<_;++t)++m[p[S[t].index]];let e=m[0],n=0;return m.forEach(((t,r)=>{t>e&&(e=t,n=r)})),n})();M=0;for(let t=0;t<_;++t)M+=p[S[t].index];return T=M/_,d.type===o.COLUMN_TYPE.INT?Math.round(T):T};if(u){for(const e of i.get(n))try{p[e]=x(e)}catch(n){w.push(e),n instanceof Error||t.shell.error(Be.CORE_ISSUE)}w.length>0&&l.set(n,w),d.set(0,d.get(0))}else{const r=d.clone();let o=1,a=`${n}(${We})`;for(;e.columns.contains(a);)a=`${n}(${We} ${o})`,++o;r.name=a;const s=r.getRawData();for(const e of i.get(n))try{s[e]=x(e)}catch(n){w.push(e),n instanceof Error||t.shell.error(Be.CORE_ISSUE)}w.length>0&&l.set(a,w),r.set(0,r.get(0)),e.columns.add(r)}})),l}(n,g,A,s,p,h,u);l||function(t,e){e.forEach(((e,n)=>{const r=t.col(n);if(null!==r){if(!He.includes(r.type))throw new Error(Be.UNSUPPORTED_COLUMN_TYPE);const t=function(t){switch(t.type){case o.COLUMN_TYPE.STRING:case o.COLUMN_TYPE.DATE_TIME:return function(t){const e=$e(t),n=t.getRawData(),r=n.length;for(let o=0;o<r;++o)if(n[o]!==e)return t.get(o);throw new Error(Be.EMPTY_COLUMN)}(t);case o.COLUMN_TYPE.INT:case o.COLUMN_TYPE.FLOAT:case o.COLUMN_TYPE.QNUM:return t.stats.avg;default:throw new Error(Be.UNSUPPORTED_COLUMN_TYPE)}}(r);e.forEach((e=>r.set(e,t)))}}))}(n,e),M()}catch(e){e instanceof Error?t.shell.error(`${Be.KNN_FAILS}: ${e.message}`):t.shell.error(`${Be.KNN_FAILS}: ${Be.CORE_ISSUE}`),T(e)}}),void 0,ze.RUN),_.add(y).add(w).add(I).add(S).add(f).add(c).add(d).show().onClose.subscribe((()=>!O&&M())),P}))}class or extends Kn{constructor(t={}){super(t),this.similarityThresholdInput=e.input.int("Similarity Threshold",{value:80}),this.maxIterationsInput=e.input.int("Max Iterations",{value:5}),this.useWebGPUInput=e.input.bool("Use WebGPU",{value:!1}),this.inflateInput=e.input.float("Inflation Factor",{value:Nn}),this.minClusterSizeInput=e.input.int("Min Cluster Size",{value:5}),mn().then((t=>{t?(this.useWebGPUInput.setTooltip(`Use webGPU for MCL calculation (${t})`),this.useWebGPUInput.value=!0):(this.useWebGPUInput.value=!1,this.useWebGPUInput.setTooltip("WebGPU is not available"),this.useWebGPUInput.enabled=!1)}))}getEditor(){return e.div([this.tableInput.root,this.columnsInputRoot,this.columnParamsEditorRoot,this.aggregationMethodInput.root,this.similarityThresholdInput.root,this.inflateInput.root,this.maxIterationsInput.root,this.minClusterSizeInput.root,this.useWebGPUInput.root],{style:{minWidth:"420px"},classes:"ui-form"})}getInput(){const t=super.getInput();return t.similarityThreshold=this.similarityThresholdInput.value,t.maxIterations=this.maxIterationsInput.value,t.useWebGPU=this.useWebGPUInput.value??!1,t.inflateFactor=this.inflateInput.value??Nn,t.minClusterSize=this.minClusterSizeInput.value??5,t}async applyInput(t){await super.applyInput(t),this.similarityThresholdInput.value=t.similarityThreshold,this.maxIterationsInput.value=t.maxIterations,this.useWebGPUInput.value=t.useWebGPU,this.inflateInput.value=t.inflateFactor,this.minClusterSizeInput.value=t.minClusterSize}get params(){return{table:this.tableInput.value,columns:this.columnsInput.value,methodName:this.methodInput.value,preprocessingFunctions:this.columnOptEditors.map((t=>t.preProcessingFunction)),distanceMetrics:this.columnOptEditors.map((t=>t.similarityMetricInput.value)),weights:this.columnOptEditors.map((t=>t.weight)),preprocessingFuncArgs:this.columnOptEditors.map((t=>t.preprocessingFunctionSettings)),aggreaggregationMethod:this.aggregationMethodInput.value,threshold:this.similarityThresholdInput.value,maxIterations:this.maxIterationsInput.value??5,useWebGPU:this.useWebGPUInput.value??!1,inflateFactor:this.inflateInput.value??Nn,minClusterSize:this.minClusterSizeInput.value??5}}}class ir{constructor(t,e,n,r,i,a){this.sc=t,this.from=e,this.to=n,this.shortLineThreshold=r,this.width=i,this.color=a,this.renderFlag=!1,this.renderSub=o.debounce(t.onAfterDrawScene,200).subscribe((()=>{if(this.renderFlag)return void(this.renderFlag=!1);this.renderFlag=!0;const e=t.onBeforeDrawScene.subscribe((t=>{this.render(),e.unsubscribe()}));setTimeout((()=>{this.sc.invalidateCanvas()}))})),t.subs.push(this.renderSub)}render(){const t=this.sc.dataFrame.getCol(this.sc.props.xColumnName),e=this.sc.dataFrame.getCol(this.sc.props.yColumnName),n=this.sc.filter,r=new Array(this.sc.dataFrame.rowCount).fill(null).map(((r,o)=>t.isNone(o)||e.isNone(o)||!n.get(o)?null:this.sc.pointToScreen(o))),o=this.sc.canvas.getContext("2d");if(!o)return;o.strokeStyle=`rgba(${this.color}, 0.3)`,o.lineWidth=this.width;const i=this.shortLineThreshold*this.shortLineThreshold;for(let t=0;t<this.from.length;t++){o.beginPath();const e=this.from[t],n=this.to[t];if(r[e]&&r[n]){const t=r[e],a=r[n],s=a.x-t.x,u=a.y-t.y;if(s*s+u*u<i)continue;o.moveTo(t.x,t.y),o.lineTo(a.x,a.y),o.stroke(),o.closePath()}}}destroy(){this.renderSub.unsubscribe()}}class ar extends o.JsViewer{constructor(){super(),this.initPromise=Promise.resolve(),this.initialized=!1,this.reseolver=()=>{},this.scratchCallTimer=null,this.mclProps=this.string("mclProps",null,{includeInLayout:!1,userEditable:!1,nullable:!0}),this.lines=this.string("lines",null,{includeInLayout:!1,userEditable:!1,nullable:!0}),this.scProps=this.string("scProps",null,{includeInLayout:!1,userEditable:!1,nullable:!0}),this.initPromise=new Promise((t=>{this.reseolver=t}))}onFrameAttached(e){if(e.rowCount>65535)throw new Error("MCL viewer supports only dataframes with less than 65535 rows");this.sc=e.plot.scatter({showXAxis:!1,showYAxis:!1,showXSelector:!1,showYSelector:!1,title:"MCL"}),this.root.appendChild(this.sc.root),this.subs.push(t.events.onCurrentObjectChanged.subscribe((e=>{this.sc&&t.shell.o===this&&setTimeout((()=>{t.shell.o=this.sc}))}))),this.subs.push(o.debounce(this.sc.onPropertyValueChanged,1e3).subscribe((t=>{this.sc&&this.getProperty("scProps").set(this,JSON.stringify(Object.assign({},this.sc.props)))})))}setScProps(){if(!this.sc)return;const t=this.scProps;if(!t)return;const e=this.sc.props;if(t===JSON.stringify(Object.assign({},e)))return;const n=JSON.parse(t);Object.entries(n).forEach((([t,n])=>{e.hasProperty(t)&&e[t]!==n&&(this.sc.props[t]=n)}))}onPropertyChanged(t){null!==t&&("scProps"===t.name?this.setScProps():"lines"===t.name?this.decodeLines():"mclProps"===t.name&&(this.scratchCallTimer&&clearTimeout(this.scratchCallTimer),this.scratchCallTimer=setTimeout((()=>{this.initFromScratch()}),300)))}async initFromScratch(){if(!this.mclProps||!this.sc||!this.dataFrame||this.initialized)return;if(this.lines)return void this.decodeLines();const r=JSON.parse(this.mclProps),i=r.cols.map((t=>this.dataFrame.columns.byName(t))),a=r.preprocessingFuncs.map((t=>t?o.Func.byName(t):null)),s=await async function(r,i,a,s,u,c,l,d=80,h=10,f=!1,p=2,m=5,g){let y=null,v=g;v||(y=t.shell.tableView(r.name)??t.shell.addTableView(r),v=y.scatterPlot({showXAxis:!1,showYAxis:!1,showXSelector:!1,showYSelector:!1,title:"MCL"})),e.setUpdateIndicator(v.root,!0);const w=[],b=[];for(let t=0;t<c.length;++t){const e=c[t];if(e){const n=e.inputs[0].name,r=e.inputs[1].name,{entries:o,options:s}=await e.apply({[n]:i[t],[r]:a[t],...l[t]??{}});b.push({entries:o,options:s}),w.push(s??{})}else{const e=i[t].toList(),n={};b.push({entries:e,options:n}),w.push(n)}}const E=function(t,e,r,o,i,a,s=10,u=!1,c=2){const l=new Worker(new URL(n.p+n.u(980),n.b));let d;return l.postMessage({data:t,threshold:e,weights:r,aggregationMethod:o,distanceFns:i,distanceFnArgs:a,maxIterations:s,useWebGPU:u,inflate:c}),{promise:new Promise(((t,e)=>{d=t,l.onmessage=e=>{setTimeout((()=>l.terminate()),100),t(e.data.res)},l.onerror=t=>{setTimeout((()=>l.terminate()),100),e(t)}})),terminate:()=>{try{d(null),l.terminate()}catch(t){console.error(t)}}}}(b.map((t=>t.entries)),d,s,u,a,w,h,f,p),A=t.events.onViewerClosed.subscribe((t=>{t.args.viewer?.props?.title===v.props.title&&v.type===t.args?.viewer?.type&&(A.unsubscribe(),E.terminate())})),C=await E.promise;if(!C)return;const S=r.columns.getUnusedName("Cluster (MCL)"),_=r.columns.getUnusedName("EmbedX (MCL)"),N=r.columns.getUnusedName("EmbedY (MCL)"),I={};C.clusters.forEach((t=>{I[t]||(I[t]=0),I[t]++}));const M=new Uint32Array(C.embedX.length);for(let t=0;t<C.is.length;t++)M[C.is[t]]++,M[C.js[t]]++;const T=r.columns.getUnusedName("Cluster size (MCL)"),O=r.columns.getUnusedName("Connectivity (MCL)"),P=r.columns.addNewFloat(_);P.init((t=>C.embedX[t]));const L=r.columns.addNewFloat(N);L.init((t=>C.embedY[t]));const x=r.columns.addNewString(S);x.init((t=>I[C.clusters[t]]>=m?C.clusters[t].toString():"-1"));const F={"-1":o.Color.setAlpha(o.Color.lightBlue,100)};x.setTag(o.TAGS.COLOR_CODING_CATEGORICAL,JSON.stringify(F)),x.temp[o.TAGS.COLOR_CODING_CATEGORICAL]=F;const R=r.columns.addNewInt(T);R.init((t=>I[C.clusters[t]]));const D=r.columns.addNewInt(O);D.init((t=>M[t])),v.props.xColumnName=_,v.props.yColumnName=N,v.props.colorColumnName=S,v.props.markerDefaultSize=6,A.unsubscribe();const U=[],k=[],G=new Map;for(let t=0;t<C.is.length;t++){let e=C.clusters[C.is[t]],n=C.clusters[C.js[t]];if(e===n){U.push(C.is[t]),k.push(C.js[t]);continue}if(e>n){const t=e;e=n,n=t}let r=G.get(e);r||(r=new Map,G.set(e,r));let o=r.get(n);o||(o=0),o>=20||(o++,r.set(n,o),U.push(C.is[t]),k.push(C.js[t]))}return e.setUpdateIndicator(v.root,!1),{sc:v,embedXCol:P,embedYCol:L,clusterCol:x,clusterCounterCol:R,connectivityCol:D,i:U,j:k}}(this.dataFrame,i,r.metrics,r.weights,r.aggregationMethod,a,r.preprocessingFuncArgs,r.threshold,r.maxIterations,r.useWebGPU,r.inflate,r.minClusterSize,this.sc);return s?this.dataFrame.getTag(".script")?(this.linesRenderer?.destroy(),this.linesRenderer=new ir(this.sc,s.i,s.j,6,.75,"128,128,128"),this.initialized=!0,void this.reseolver()):void this.encodeLines(s.i,s.j):void 0}decodeLines(){if(!this.lines)return;const t=this.lines.length;if(t%2!=0)throw new Error("Invalid lines string");const e=new Array(t/2).fill(null).map(((t,e)=>this.lines.charCodeAt(2*e))),n=new Array(t/2).fill(null).map(((t,e)=>this.lines.charCodeAt(2*e+1)));this.linesRenderer?.destroy(),this.linesRenderer=new ir(this.sc,e,n,6,.75,"128,128,128"),this.initialized=!0,this.reseolver()}encodeLines(t,e){const n=new Array(t.length).fill(null).map(((n,r)=>`${String.fromCharCode(t[r])}${String.fromCharCode(e[r])}`)).join("");this.getProperty("lines").set(this,n)}}var sr=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{u(r.next(t))}catch(t){i(t)}}function s(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,s)}u((r=r.apply(t,e||[])).next())}))};function ur(t,e){const n=t.length;if(n!==e.length-1)throw new Error("Incorrect parameters count");const r=t.byIndex(0),i=r.length,a=new Float32Array(i);let s=r.getRawData();const u=e[n];let c=e[0];for(let t=0;t<i;++t)a[t]=u+c*s[t];for(let r=1;r<n;++r){s=t.byIndex(r).getRawData(),c=e[r];for(let t=0;t<i;++t)a[t]+=c*s[t]}return o.Column.fromFloat32Array(t.getUnusedName("prediction"),a,i)}const cr=(t,e)=>e<=t?Math.min(10,e):Math.min(10,t);var lr;!function(t){t[t.MAX_SAMLPES=1e5]="MAX_SAMLPES",t[t.MAX_FEATURES=1e3]="MAX_FEATURES"}(lr||(lr={}));class dr{static isApplicable(t,e){for(const e of t)if(!e.matches("numerical"))return!1;return!!e.matches("numerical")}static isInteractive(t,e){return t.length<=lr.MAX_FEATURES&&e.length<=lr.MAX_SAMLPES}constructor(t){if(this.specn=null,t)try{const e=new Uint32Array(t.buffer,0,2),n=e[0],r=e[1],i=new Uint8Array(t.buffer,8,n),a=o.DataFrame.fromByteArray(i),s=a.rowCount,u=a.columns,c=u.length,l=new Uint8Array(t.buffer,8+n,r),d=o.DataFrame.fromByteArray(l);if(c<3)throw new Error("incorrect columns count");const h=u.byName(ve.FEATURES).toList(),f=new Float32Array(s);f.set(u.byName(ve.REGR_COEFS).getRawData());const p=c-2,m=new Array(p);for(let t=0;t<p;++t)m[t]=new Float32Array(s),m[t].set(u.byIndex(t+2).getRawData());this.specn={params:f,loadings:m,names:h,dim:s-1,components:c-2,scores:d}}catch(t){throw new Error(`Failed to load model: ${t instanceof Error?t.message:"the platform issue"}`)}}fit(t,e,n){return r=this,i=void 0,s=function*(){const r=yield ke({table:o.DataFrame.fromColumns([e]),features:t,predict:e,components:n,names:void 0}),i=t.names();i.push("_");const a=this.getRegrCoeffs(t,e,r.regressionCoefficients),s=this.getLoadings(n,r.xLoadings);this.specn={names:i,params:a,loadings:s,components:n,dim:t.length,scores:this.getScoresDf(r)},this.computeExplVars(e.length,n,r.yLoadings)},new((a=void 0)||(a=Promise))((function(t,e){function n(t){try{u(s.next(t))}catch(t){e(t)}}function o(t){try{u(s.throw(t))}catch(t){e(t)}}function u(e){var r;e.done?t(e.value):(r=e.value,r instanceof a?r:new a((function(t){t(r)}))).then(n,o)}u((s=s.apply(r,i||[])).next())}));var r,i,a,s}getLoadings(t,e){const n=Array(t),r=e[0].length+1;for(let o=0;o<t;++o)n[o]=new Float32Array(r),n[o].set(e[o].getRawData());return n}getRegrCoeffs(t,e,n){const r=t.length,o=new Float32Array(r+1),i=n.getRawData();let a=0;for(let e=0;e<r;++e)o[e]=i[e],a+=i[e]*t.byIndex(e).stats.avg;return o[r]=e.stats.avg-a,o}computeExplVars(t,e,n){if(null===this.specn)throw new Error("Failed to compute explained variances");const r=n.getRawData(),o=this.specn.loadings[0].length-1;let i=Math.pow(r[0],2)/t;this.specn.loadings[0][o]=i;for(let n=1;n<e;++n)i+=Math.pow(r[n],2)/t,this.specn.loadings[n][o]=i}toBytes(){if(null===this.specn)throw new Error("Failed to pack untrained model");const t=o.DataFrame.fromColumns([o.Column.fromStrings(ve.FEATURES,this.specn.names),o.Column.fromFloat32Array(ve.REGR_COEFS,this.specn.params)]);this.specn.loadings.forEach(((e,n)=>t.columns.add(o.Column.fromFloat32Array(`${ve.XLOADING}${n+1}`,e))));const e=t.toByteArray(),n=e.length,r=this.specn.scores.toByteArray(),i=r.length,a=n+i+8,s=new Uint8Array(64*(Math.ceil(a/64)+1)),u=new Uint32Array(s.buffer,0,2);return u[0]=n,u[1]=i,s.set(e,8),s.set(r,8+n),s}predict(t){if(null===this.specn)throw new Error("Predicting failed: model is not trained");return ur(t,this.specn.params)}loadingsParamsViewers(){if(null===this.specn)throw new Error("Failed to create loadings and parameters viewers: untrained model");const t=[],e=this.specn.dim,n=o.DataFrame.fromColumns([o.Column.fromStrings(ve.FEATURES,this.specn.names.slice(0,-1)),o.Column.fromFloat32Array(ve.REGR_COEFS,this.specn.params,e)]),r=n.columns,i=r.length,a=this.specn.components;return this.specn.loadings.forEach(((t,r)=>n.columns.add(o.Column.fromFloat32Array(`${ve.XLOADING}${r+1}`,t,e)))),t.push(o.Viewer.scatterPlot(n,{title:ve.LOADINGS,xColumnName:r.byIndex(i).name,yColumnName:r.byIndex(i+(a>1?1:0)).name,markerType:o.MARKER_TYPE.CIRCLE,labelFormColumnNames:[ve.FEATURES],help:be.LOADINGS})),t.push(o.Viewer.barChart(n,{title:ve.REGR_COEFS,splitColumnName:ve.FEATURES,valueColumnName:ve.REGR_COEFS,valueAggrType:o.AGG.AVG,help:be.COEFFS,showValueSelector:!1,showStackSelector:!1})),t}explVarsViewer(){if(null===this.specn)throw new Error("Failed to create exaplained variances viewer: untrained model");const t=this.specn.components,e=this.specn.dim,n=new Array(t),r=new Float32Array(t);n[0]=`${Ae.COMP} 1`,r[0]=this.specn.loadings[0][e];for(let o=1;o<t;++o)n[o]=`${Ae.COMPS} ${o+1}`,r[o]=this.specn.loadings[o][e];return o.Viewer.barChart(o.DataFrame.fromColumns([o.Column.fromStrings(Ae.COMPS,n),o.Column.fromFloat32Array(ve.EXPL_VAR,r)]),{title:ve.EXPL_VAR,splitColumnName:Ae.COMPS,valueColumnName:ve.EXPL_VAR,valueAggrType:o.AGG.AVG,help:be.EXPL_VARS,showCategorySelector:!1,showStackSelector:!1,showValueSelector:!1})}viewers(){if(null===this.specn)throw new Error("Failed to create viewers: untrained model");const t=this.loadingsParamsViewers();return t.push(this.explVarsViewer(),this.getScoresScatter()),t}getScoresDf(t){const e=t.tScores,n=t.uScores;return e.forEach(((t,e)=>t.name=`${ve.XSCORE}${e+1}`)),n.forEach(((t,e)=>t.name=`${ve.YSCORE}${e+1}`)),o.DataFrame.fromColumns(e.concat(n))}getScoresScatter(){if(null===this.specn)throw new Error("Failed to create scores scatter: untrained model");const t=this.specn.scores.columns.names(),e=o.Viewer.scatterPlot(this.specn.scores,{title:ve.SCORES,xColumnName:t[0],yColumnName:t[1],markerType:o.MARKER_TYPE.CIRCLE,help:be.SCORES,showViewerFormulaLines:!0});return e.meta.formulaLines.addAll(Ue(t)),e}}var hr=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{u(r.next(t))}catch(t){i(t)}}function s(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,s)}u((r=r.apply(t,e||[])).next())}))};const fr="Avg-s",pr="Stddev-s";var mr;!function(t){t[t.MAX_SAMLPES=5e4]="MAX_SAMLPES",t[t.MAX_FEATURES=100]="MAX_FEATURES"}(mr||(mr={}));class gr{static isApplicable(t,e){for(const e of t)if(!e.matches("numerical"))return!1;return e.type===o.COLUMN_TYPE.STRING}static isInteractive(t,e){return t.length<=mr.MAX_FEATURES&&e.length<=mr.MAX_SAMLPES}constructor(t,e){if(this.params=void 0,this.classesCount=1,this.featuresCount=1,void 0!==t){const e=t.featuresCount,n=t.classesCount;if(e<1)throw new Error("Incorrect features count");if(n<1)throw new Error("Incorrect classes count");const r=e+1;this.avgs=new Float32Array(r),this.stdevs=new Float32Array(r),this.categories=new Array(r),this.featuresCount=e,this.classesCount=n}else{if(void 0===e)throw new Error("Softmax classifier not initialized");try{const t=new Uint32Array(e.buffer,0,1)[0],n=new Uint8Array(e.buffer,4,t),r=o.DataFrame.fromByteArray(n),i=r.columns,a=i.length;if(a<3)throw new Error("incorrect columns count");this.classesCount=a-2,this.featuresCount=r.rowCount-1;const s=this.classesCount;this.params=new Array(s),this.categories=new Array(r.rowCount);for(let t=0;t<s;++t){const e=i.byIndex(t);if(this.categories[t]=e.name,e.type!==o.COLUMN_TYPE.FLOAT)throw new Error(`Incorrect input column type. Expected: float, passed: ${e.type}`);this.params[t]=e.getRawData()}const u=i.byName(fr);if(u.type!==o.COLUMN_TYPE.FLOAT)throw new Error("incorrect average values column type");this.avgs=u.getRawData();const c=i.byName(pr);if(c.type!==o.COLUMN_TYPE.FLOAT)throw new Error("incorrect standard deviations column type");this.stdevs=c.getRawData()}catch(t){throw new Error(`Failed to load model: ${t instanceof Error?t.message:"the platform issue"}`)}}}toBytes(){if(void 0===this.params)throw new Error("Non-trained model");const t=this.classesCount,e=new Array(t+2);for(let n=0;n<t;++n)e[n]=o.Column.fromFloat32Array(this.categories[n],this.params[n]);e[t]=o.Column.fromFloat32Array(fr,this.avgs),e[t+1]=o.Column.fromFloat32Array(pr,this.stdevs);const n=o.DataFrame.fromColumns(e).toByteArray(),r=n.length,i=new Uint8Array(r+4);return new Uint32Array(i.buffer,0,1)[0]=r,i.set(n,4),i}fit(t,e){return hr(this,arguments,void 0,(function*(t,e,n=1,r=100,i=.1,a=.001){if(t.length!==this.featuresCount)throw new Error("Training failes - incorrect features count");if(n<=0||r<1||i<=0||a<=0)throw new Error("Training failes - incorrect fitting hyperparameters");this.extractStats(t);const s=e.length,u=e.categories.length,c=e.categories;for(let t=0;t<u;++t)this.categories[t]=c[t];try{const c=function(t,e,n,r,o,i,a,s,u,c,l){return g(EDA,"fitSoftmax",[t,e,n,r,o,i,a,s,u,c,l])}(t,o.Column.fromFloat32Array("avgs",this.avgs,this.featuresCount),o.Column.fromFloat32Array("stdevs",this.stdevs,this.featuresCount),o.Column.fromInt32Array("targets",e.getRawData(),s),u,r,n,i,a,this.featuresCount+1,u).columns;this.params=new Array(u);for(let t=0;t<u;++t)this.params[t]=c.byIndex(t).getRawData()}catch(o){try{this.params=yield this.fitSoftmaxParams(t,e,r,n,i,a)}catch(t){throw new Error("Training failes")}}if(void 0===this.params)throw new Error("Training failes")}))}extractStats(t){let e=0;for(const n of t){if(n.type!==o.COLUMN_TYPE.INT&&n.type!==o.COLUMN_TYPE.FLOAT)throw new Error("Training failes - incorrect features type");this.avgs[e]=n.stats.avg,this.stdevs[e]=n.stats.stdev,++e}}normalized(t){const e=t.byIndex(0).length,n=new Array(e);for(let t=0;t<e;++t)n[t]=new Float32Array(this.featuresCount);let r=0;for(const i of t){if(i.type!==o.COLUMN_TYPE.INT&&i.type!==o.COLUMN_TYPE.FLOAT)throw new Error("Training failes - incorrect features type");const t=i.getRawData(),a=this.avgs[r],s=this.stdevs[r];if(s>0)for(let o=0;o<e;++o)n[o][r]=(t[o]-a)/s;else for(let t=0;t<e;++t)n[t][r]=0;++r}return n}transposed(t){const e=t.byIndex(0).length,n=this.featuresCount,r=new Array(n);for(let t=0;t<n;++t)r[t]=new Float32Array(e);let i=0;for(const n of t){if(n.type!==o.COLUMN_TYPE.INT&&n.type!==o.COLUMN_TYPE.FLOAT)throw new Error("Training failes - incorrect features type");const t=n.getRawData(),a=this.avgs[i],s=this.stdevs[i];if(s>0)for(let n=0;n<e;++n)r[i][n]=(t[n]-a)/s;else for(let t=0;t<e;++t)r[i][t]=0;++i}return r}preprocessedTargets(t){if(t.type!==o.COLUMN_TYPE.STRING)throw new Error("Training failes - incorrect target type");const e=this.classesCount,n=t.length,r=t.getRawData(),i=new Array(n),a=new Uint32Array(e).fill(0);for(let t=0;t<n;++t)i[t]=new Uint8Array(e).fill(0);for(let t=0;t<n;++t)i[t][r[t]]=1,++a[r[t]];return{oneHot:i,weights:a}}predict(t){if(void 0===this.params)throw new Error("Non-trained model");if(t.length!==this.featuresCount)throw new Error("Predcition fails: incorrect features count");const e=this.normalized(t),n=e.length,r=this.featuresCount,i=this.classesCount;let a,s;const u=new Float32Array(i);let c,l,d;const h=new Array(n);for(let t=0;t<n;++t){a=e[t],c=0;for(let t=0;t<i;++t){s=this.params[t],c=s[r];for(let t=0;t<r;++t)c+=s[t]*a[t];u[t]=Math.exp(c)}l=u[0],d=0;for(let t=1;t<i;++t)l<u[t]&&(l=u[t],d=t);h[t]=this.categories[d]}return o.Column.fromStrings("predicted",h)}fitSoftmaxParams(t,e,r,o,i,a){return hr(this,void 0,void 0,(function*(){const s=this.preprocessedTargets(e);return new Promise(((u,c)=>{const l=new Worker(new URL(n.p+n.u(501),n.b));l.postMessage({features:this.normalized(t),transposed:this.transposed(t),oneHot:s.oneHot,classesWeights:s.weights,targetRaw:e.getRawData(),iterations:r,rate:o,penalty:i,tolerance:a}),l.onmessage=function(t){l.terminate(),u(t.data.params),console.log(`Loss: ${t.data.loss}`)}}))}))}}var yr,vr,wr;!function(t){t[t.ITERATIONS=20]="ITERATIONS",t[t.ETA=.3]="ETA",t[t.MAX_DEPTH=6]="MAX_DEPTH",t[t.LAMBDA=1]="LAMBDA",t[t.ALPHA=0]="ALPHA"}(yr||(yr={})),function(t){t[t.SAMLPES_HIGH=1e5]="SAMLPES_HIGH",t[t.SAMLPES_MID=5e4]="SAMLPES_MID",t[t.SAMPLES_LOW=1e4]="SAMPLES_LOW",t[t.FEATURES_HIGH=10]="FEATURES_HIGH",t[t.FEATURES_MID=20]="FEATURES_MID",t[t.FEATURES_LOW=100]="FEATURES_LOW"}(vr||(vr={})),function(t){t[t.MODEL=1e7]="MODEL",t[t.UTILS=1]="UTILS",t[t.PACK=128]="PACK",t[t.SIZE=4]="SIZE"}(wr||(wr={}));const br=o.FLOAT_NULL;var Er;!function(t){t.PREDICT="Prediction",t.TYPE="Type",t.PARAMS="Params count",t.CATS="Categories",t.CATS_SIZE="Categories size"}(Er||(Er={}));class Ar{static isApplicable(t,e){for(const e of t)if(!e.matches("numerical"))return!1;return!(!e.matches("numerical")&&!e.matches("string"))}static isInteractive(t,e){const n=t.length,r=e.length;return r<=vr.SAMPLES_LOW?n<=vr.FEATURES_LOW:r<=vr.SAMLPES_MID?n<=vr.FEATURES_MID:r<=vr.SAMLPES_HIGH&&n<=vr.FEATURES_HIGH}constructor(t){var e;if(this.modelParams=void 0,this.targetType=void 0,this.targetCategories=void 0,t)try{let n=0;const r=new Uint32Array(t.buffer,n,1)[0];n+=wr.SIZE;const i=o.DataFrame.fromByteArray(new Uint8Array(t.buffer,n,r));n+=r,this.targetType=i.get(Er.TYPE,0);const a=i.get(Er.PARAMS,0),s=i.get(Er.CATS_SIZE,0);if(s>0){const r=o.DataFrame.fromByteArray(new Uint8Array(t.buffer,n,s));this.targetCategories=null===(e=r.col(Er.CATS))||void 0===e?void 0:e.toList()}n+=s,n=4*Math.ceil(n/4),this.modelParams=new Int32Array(t.buffer,n,a)}catch(t){throw new Error(`Failed to load model: ${t instanceof Error?t.message:"the platform issue"}`)}}fit(t,e){return r=this,i=arguments,s=function*(t,e,r=yr.ITERATIONS,i=yr.ETA,a=yr.MAX_DEPTH,s=yr.LAMBDA,u=yr.ALPHA){this.targetType=e.type,this.targetType===o.COLUMN_TYPE.STRING&&(this.targetCategories=e.categories),this.modelParams=yield async function(t,e,r,o,i,a,s,u,c,l){return new Promise(((d,h)=>{const f=e.length,p=t.length,m=new Float32Array(f*p);let g,y;for(let e=0;e<p;++e){y=t.byIndex(e).getRawData(),g=e*f;for(let t=0;t<f;++t)m[t+g]=y[t]}const v=new Worker(new URL(n.p+n.u(990),n.b));v.postMessage({features:m,target:e.getRawData(),samplesCount:f,featuresCount:p,modelReserve:c,utilsLength:l,iterations:o,eta:i,maxDepth:a,lambda:s,alpha:u,missingValue:r}),v.onmessage=function(t){v.terminate(),d(t.data.params)}}))}(t,e,br,r,i,a,s,u,wr.MODEL,wr.UTILS)},new((a=void 0)||(a=Promise))((function(t,e){function n(t){try{u(s.next(t))}catch(t){e(t)}}function o(t){try{u(s.throw(t))}catch(t){e(t)}}function u(e){var r;e.done?t(e.value):(r=e.value,r instanceof a?r:new a((function(t){t(r)}))).then(n,o)}u((s=s.apply(r,i||[])).next())}));var r,i,a,s}predict(t){if(void 0===this.modelParams)throw new Error("Failed to apply non-trained model");const e=function(t,e,n){const r=t.byIndex(0).length,o=t.length,i=n.length;let a=XGBoostModule.HEAPF32;const s=XGBoostModule.HEAP32,u=XGBoostModule._malloc(r*o*4),c=XGBoostModule._malloc(4*r),l=XGBoostModule._malloc(4*i);for(let e=0;e<o;++e){const n=t.byIndex(e).getRawData();for(let t=0;t<r;++t)a[u/4+t+e*r]=n[t]}for(let t=0;t<i;++t)s[l/4+t]=n[t];XGBoostModule._predict(u,r,o,e,l,i,c,r),a=XGBoostModule.HEAPF32;const d=new Float32Array(r);for(let t=0;t<r;++t)d[t]=a[c/4+t];return XGBoostModule._free(u),XGBoostModule._free(c),XGBoostModule._free(l),d}(t,br,this.modelParams);switch(this.targetType){case o.COLUMN_TYPE.STRING:return this.stringColPrediction(e);case o.COLUMN_TYPE.INT:return this.intColPrediction(e);case o.COLUMN_TYPE.BIG_INT:return this.bigIntColPrediction(e);default:return o.Column.fromFloat32Array(Er.PREDICT,e)}}toBytes(){if(void 0===this.modelParams||void 0===this.targetType)throw new Error("Failed to pack non-trained model");const t=void 0!==this.targetCategories?o.DataFrame.fromColumns([o.Column.fromList(o.COLUMN_TYPE.STRING,Er.CATS,this.targetCategories)]).toByteArray():void 0,e=void 0!==t?t.length:0,n=this.modelParams.length*this.modelParams.BYTES_PER_ELEMENT,r=o.DataFrame.fromColumns([o.Column.fromStrings(Er.TYPE,[this.targetType]),o.Column.fromInt32Array(Er.PARAMS,new Int32Array([this.modelParams.length])),o.Column.fromInt32Array(Er.CATS_SIZE,new Int32Array([e]))]).toByteArray(),i=r.length,a=64*Math.ceil((wr.SIZE+i+e+n+wr.PACK)/64),s=new Uint8Array(a);let u=0;return new Uint32Array(s.buffer,u,1)[0]=i,u+=wr.SIZE,s.set(r,u),u+=i,e>0&&s.set(t,u),u+=e,u=4*Math.ceil(u/4),s.set(new Uint8Array(this.modelParams.buffer),u),s}stringColPrediction(t){const e=t.length;if(void 0===this.targetCategories)throw new Error("Predicting fails: undefined categories");const n=new Array(e),r=this.targetCategories.length-1;for(let o=0;o<e;++o)n[o]=this.targetCategories[(i=Math.round(t[o]),Math.max(0,Math.min(i,r)))];var i;return o.Column.fromList(o.COLUMN_TYPE.STRING,Er.PREDICT,n)}intColPrediction(t){const e=t.length,n=new Int32Array(e);for(let r=0;r<e;++r)n[r]=Math.round(t[r]);return o.Column.fromInt32Array(Er.PREDICT,n,e)}bigIntColPrediction(t){const e=t.length,n=new BigInt64Array(e);for(let r=0;r<e;++r)n[r]=BigInt(Math.round(t[r]));return o.Column.fromBigInt64Array(Er.PREDICT,n)}}var Cr=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{u(r.next(t))}catch(t){i(t)}}function s(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,s)}u((r=r.apply(t,e||[])).next())}))};const Sr=new o.Package;function _r(){t.shell.info(Sr.webRoot)}function Nr(){return Cr(this,void 0,void 0,(function*(){yield async function(){await initEDA()}(),yield async function(){await initXGBoostModule()}()}))}function Ir(t,e,n,r,i){return Cr(this,void 0,void 0,(function*(){const a=e.getRawData(),s=n.getRawData(),u=yield fn(a,s,r,i),c=t.columns.getUnusedName("Cluster (DBSCAN)"),l=o.Column.fromInt32Array(c,u);return t.columns.add(l),l}))}function Mr(e,r,i,a,s){return Cr(this,void 0,void 0,(function*(){try{const u=yield function(t,e,r,i,a){return J(this,void 0,void 0,(function*(){X(e,r);const s=t.rowCount,u=function(t){const e=[];for(const n of t)n.stats.stdev>0&&n.stats.missingValueCount<1&&e.push(n);return o.DataFrame.fromColumns(e)}(e),c=u.columns.length;if(0===c){const t=[];for(let e=0;e<r;++e)t.push(o.Column.fromFloat32Array(`${e+1}`,new Float32Array(s).fill(0)));return o.DataFrame.fromColumns(t)}const l=c<r?r-c:0,d=Math.min(r,c);let h;if(c>W)h=yield G(0,e,d);else{const t=yield async function(t,e,r){return new Promise(((t,o)=>{const i=new Worker(new URL(n.p+n.u(860),n.b));i.postMessage(U(EDA.principalComponentAnalysis.arguments,[e,r,1,0])),i.onmessage=function(e){i.terminate(),0===e.data.callResult?t(k(EDA.principalComponentAnalysis,e.data)):t(-1)}}))}(0,e,d);h=-1!==t?Q(t,i,a):yield G(0,e,d)}if(void 0===h)throw new Error("Failed to compute PCA");h=Q(h,i,a);const f=h.columns,p=f.length;for(let t=0;t<l;++t)f.add(o.Column.fromFloat32Array(`${p+t+1}`,new Float32Array(s).fill(0)));return h}))}(e,r,i,a,s);if(function(t,e){for(const t of e.toList())t.name="PC"+t.name}(0,u.columns),null===e.id)t.shell.addTableView(u);else{const t=e.columns;for(const e of u.columns)e.name=t.getUnusedName(e.name),t.add(e)}}catch(e){t.shell.warning(`Failed to compute PCA: ${e instanceof Error?e.message:"platform issue"}`)}}))}function Tr(e,n,r,i){return Cr(this,void 0,void 0,(function*(){const a=e.dataFrame;if(null===a)return;const s=yield Ir(a,e,n,r,i);a.changeColumnType(s,"string");const u=[e.name,n.name],c=t.shell.tableView(a.name);if(c)for(const t of c.viewers)if(t instanceof o.ScatterPlotViewer&&u.includes(t.props.xColumnName)&&u.includes(t.props.yColumnName))return void(t.props.colorColumnName=s.name)}))}function Or(t,e){const n=t.stats.max-t.stats.min;return{entries:t.toList(),options:{range:n}}}function Pr(t,e){return{entries:t.toList(),options:{}}}function Lr(){return Cr(this,void 0,void 0,(function*(){const r=new Kn,i=e.dialog("Dimensionality reduction").add(r.getEditor()).onOK((()=>Cr(this,void 0,void 0,(function*(){const i=r.getParams();0!==i.columns.length&&(yield async function(r,i,a,s,u,c,l,d=!0,h=!1,f={preprocessingFuncArgs:[]},p={},m=null,g={}){const y={showXAxis:!1,showYAxis:!1,showXSelector:!1,showYSelector:!1};if(i.length!==s.length||i.length!==c.length||i.length!==u.length||i.length!==f.preprocessingFuncArgs.length)throw new Error("columns, metrics and preprocessing functions, weights and function argumentsmust have the same length");const v=d?p.tableView??t.shell.tableView(r.name)??t.shell.addTableView(r):null,w=async()=>{const w=o.TaskBarProgressIndicator.create(`Initializing ${p.scatterPlotName??"dimensionality reduction"} ...`);let b;try{const E=function(t){const e=["Embed_X","Embed_Y"],n=t.columns.names().filter((t=>t.includes(e[0]))).length+1;return e.map((t=>`${t}_${n}`))}(r);function A(t,n,s){let u=null,c=null;r.columns.names().includes(E[0])?(u=r.columns.byName(E[0]),c=r.columns.byName(E[1])):(u=r.columns.add(o.Column.float(E[0],r.rowCount)),c=r.columns.add(o.Column.float(E[1],r.rowCount)),d&&!b&&(b=v.scatterPlot({...y,x:E[0],y:E[1],title:p.scatterPlotName??er(i,a)}))),p[Tn]&&(b?.root&&e.setUpdateIndicator(b.root,!1),u.init((t=>s[0]?s[0][t]:void 0)),c.init((t=>s[1]?s[1][t]:void 0)));const l=t/n*100;w.update(l,`Running ${p.scatterPlotName??"dimensionality reduction"}... ${l.toFixed(0)}%`)}async function C(){r.columns.add(o.Column.float(E[0],r.rowCount)),r.columns.add(o.Column.float(E[1],r.rowCount));let h=null;d&&(b=v.scatterPlot({...y,x:E[0],y:E[1],title:p.scatterPlotName??er(i,a)}),e.setUpdateIndicator(b.root,!0));const m=t.events.onViewerClosed.subscribe((e=>{const n=e.args.viewer;n?.getOptions()?.look?.title&&b?.getOptions()?.look?.title&&n?.getOptions()?.look?.title===b?.getOptions()?.look?.title&&(t.events.fireCustomEvent(Zn,{}),m.unsubscribe(),h?.(),w.close())})),g=new Promise((async(e,r)=>{try{h=e;const r=[];for(let t=0;t<c.length;++t){const e=c[t];if(f.distanceFnArgs||(f.distanceFnArgs=[]),e){const n=e.inputs[0].name,o=e.inputs[1].name,{entries:a,options:u}=await e.apply({[n]:i[t],[o]:s[t],...f.preprocessingFuncArgs[t]??{}});r.push({entries:a,options:u}),f.distanceFnArgs.push(u)}else{const e=i[t].toList(),n={};r.push({entries:e,options:n}),f.distanceFnArgs.push(n)}}e(await async function(e,r,o,i,a,s,u){let c=await async function(e,r,o,i,a,s,u){if(!s.distanceFnArgs)throw new Error("options.distanceFnArgs must be defined");if(e.length!==r.length||e.length!==s.distanceFnArgs.length||e.length!==i.length)throw new Error("data, metrics and options and weights must have the same length");return new Promise((function(c,l){const d=new Worker(new URL(n.p+n.u(234),n.b));d.postMessage({columnsData:e,distanceMetrics:r,method:o,options:s,weights:i,aggregationMethod:a});const h=t.events.onCustomEvent(Zn).subscribe((()=>{try{d?.terminate()}finally{h.unsubscribe()}}));d.onmessage=({data:{error:t,embedding:e,epochNum:n,epochsLength:r}})=>{tr(n)||tr(r)?(h.unsubscribe(),t?l(t):c(e),setTimeout((()=>d.terminate()),100)):u&&u(n,r,e)}}))}(e,o,r,i,a,s,u);return c=c.map((t=>function(t){const e=t.length;let n=0,r=0;for(let o=0;o<e;++o)n+=t[o],r+=Math.pow(t[o],2);const o=n/e,i=1/Math.sqrt(r/e-Math.pow(o,2));for(let n=0;n<e;++n)t[n]=(t[n]-o)*i;return t}(t))),c}(r.map((t=>t.entries)),a,s,u,l,f,p[Mn]?void 0:A))}catch(t){r(t)}})),C=await g;return w.close(),m.unsubscribe(),C}const S=await C();if(h&&S){const _=o.TaskBarProgressIndicator.create("Clustering embeddings ...");try{const N=await fn(S[0],S[1],f.dbScanEpsilon??.01,f.dbScanMinPts??4),I=r.columns.getUnusedName("Cluster (DBSCAN)");r.columns.addNewString(I).init((t=>N[t].toString())),b&&(b.props.colorColumnName=I)}catch(M){t.shell.error("Clustering embeddings failed"),console.error(M)}finally{_.close()}}if(S){const T=r.columns.byName(E[0]),O=r.columns.byName(E[1]);if(T.init((t=>S[0][t])),O.init((t=>S[1][t])),m)try{const P=m.inputs[0].name,L=m.inputs[1].name;await m.prepare({[P]:T,[L]:O,...g}).call(!0)}catch(x){t.shell.error("Post-processing failed"),console.error(x)}if(b)return e.setUpdateIndicator(b.root,!1),b.helpUrl="/help/compute/sequence-space",b}}catch(F){t.shell.error("Dimensionality reduction failed"),console.error(F),w.close(),b&&e.setUpdateIndicator(b.root,!1)}};return new Promise((async(t,n)=>{try{if(p.fastRowCount&&r.rowCount>p.fastRowCount&&!p[Mn])e.dialog().add(e.divText("Analysis might take several minutes. Do you want to continue?")).onOK((async()=>{try{const e=await w();t(e)}catch(t){n(t)}})).onCancel((()=>t(void 0))).show();else{const e=await w();t(e)}}catch(t){n(t)}}))}(i.table,i.columns,i.methodName,i.distanceMetrics,i.weights,i.preprocessingFunctions,i.aggreaggregationMethod,!!i.plotEmbeddings,!!i.clusterEmbeddings,i.options,{fastRowCount:1e4},i.postProcessingFunction,i.postProcessingFunctionArgs))})))).show();i.helpUrl="https://datagrok.ai/help/explore/dim-reduction.md";const a=()=>{const t=r.columnsInput.value,e=i.getButton("OK");e&&(t&&0!==t.length?e.classList.remove("disabled"):e.classList.add("disabled"))};i.history((()=>({editorSettings:r.getStringInput()})),(t=>r.applyStringInput(t.editorSettings))),r.onColumnsChanged.subscribe((()=>{try{a()}catch(t){console.error(t)}})),a()}))}function xr(n){try{const t=new or;e.dialog("Markov clustering").add(t.getEditor()).onOK((()=>Cr(this,void 0,void 0,(function*(){const e=t.params;return n.func.prepare({df:e.table,cols:e.columns,metrics:e.distanceMetrics,weights:e.weights,aggregationMethod:e.aggreaggregationMethod,preprocessingFuncs:e.preprocessingFunctions,preprocessingFuncArgs:e.preprocessingFuncArgs,threshold:e.threshold,maxIterations:e.maxIterations,useWebGPU:e.useWebGPU,inflate:e.inflateFactor,minClusterSize:e.minClusterSize}).call(!0)})))).show().history((()=>({editorSettings:t.getStringInput()})),(e=>t.applyStringInput(e.editorSettings)))}catch(e){const n=e instanceof Error?e.message:e.toString(),r=e instanceof Error?e.stack:void 0;t.shell.error(`Get region editor error: ${n}`),Sr.logger.error(n,void 0,r)}}function Fr(e,n,r,o,i,a,s){return Cr(this,arguments,void 0,(function*(e,n,r,o,i,a,s,u=80,c=10,l=!1,d=0,h=5){var f;const p=null!==(f=t.shell.tableView(e.name))&&void 0!==f?f:t.shell.addTableView(e),m=JSON.stringify({cols:n.map((t=>t.name)),metrics:r,weights:o,aggregationMethod:i,preprocessingFuncs:a.map((t=>{var e;return null!==(e=null==t?void 0:t.name)&&void 0!==e?e:null})),preprocessingFuncArgs:s,threshold:u,maxIterations:c,useWebGPU:l,inflate:d,minClusterSize:null!=h?h:5});return p.addViewer("MCL",{mclProps:m})}))}function Rr(){return new ar}function Dr(t,e,n,r,o){return Cr(this,void 0,void 0,(function*(){return yield ke({table:t,features:e,predict:n,components:r,names:o})}))}function Ur(){return Cr(this,void 0,void 0,(function*(){yield Ge(ge.COMPUTE_COMPONENTS)}))}function kr(){return Cr(this,void 0,void 0,(function*(){yield Ge(ge.PERFORM_MVA)}))}function Gr(){return Cr(this,void 0,void 0,(function*(){yield function(){return Fe(this,void 0,void 0,(function*(){t.shell.addTableView(o.DataFrame.fromColumns([o.Column.fromStrings("model",["alfaromeo","audi","bmw","chevrolet","dodge1","dodge2","honda1","honda2","isuzu","jaguar","mazda","mercedes","mercury","mitsubishi","nissan1","nissan2","peugot","plymouth","porsche","saab","subaru","toyota1","toyota2","toyota3","toyota4","volkswagen1","volkswagen2","volvo1","volvo2","volvo3"]),o.Column.fromInt32Array("diesel",new Int32Array([0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,1,0,1,1,0,0,0,1])),o.Column.fromInt32Array("turbo",new Int32Array([0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,1,1])),o.Column.fromInt32Array("two.doors",new Int32Array([1,0,1,0,1,0,1,0,0,0,0,0,1,1,0,1,0,0,1,0,0,1,0,1,0,1,0,0,0,0])),o.Column.fromInt32Array("hatchback",new Int32Array([1,0,0,0,1,1,1,0,0,0,0,0,1,1,0,0,1,0,0,0,0,1,0,1,0,0,0,0,0,0])),o.Column.fromFloat32Array("wheel.base",new Float32Array([94.5,105.80000305175781,101.19999694824219,94.5,93.69999694824219,93.69999694824219,93.69999694824219,96.5,94.30000305175781,113,93.0999984741211,115.5999984741211,102.69999694824219,93.69999694824219,94.5,94.5,93.69999694824219,114.19999694824219,89.5,99.0999984741211,97.19999694824219,95.69999694824219,95.69999694824219,98.4000015258789,102.4000015258789,97.30000305175781,100.4000015258789,104.30000305175781,109.0999984741211,109.0999984741211])),o.Column.fromFloat32Array("length",new Float32Array([171.1999969482422,192.6999969482422,176.8000030517578,158.8000030517578,157.3000030517578,157.3000030517578,150,175.39999389648438,170.6999969482422,199.60000610351562,166.8000030517578,202.60000610351562,178.39999389648438,157.3000030517578,170.1999969482422,165.3000030517578,157.3000030517578,198.89999389648438,168.89999389648438,186.60000610351562,172,158.6999969482422,166.3000030517578,176.1999969482422,175.60000610351562,171.6999969482422,180.1999969482422,188.8000030517578,188.8000030517578,188.8000030517578])),o.Column.fromFloat32Array("width",new Float32Array([65.5,71.4000015258789,64.80000305175781,63.599998474121094,63.79999923706055,63.79999923706055,64,65.19999694824219,61.79999923706055,69.5999984741211,64.19999694824219,71.69999694824219,68,64.4000015258789,63.79999923706055,63.79999923706055,63.79999923706055,68.4000015258789,65,66.5,65.4000015258789,63.599998474121094,64.4000015258789,65.5999984741211,66.5,65.5,66.9000015258789,67.19999694824219,68.80000305175781,68.9000015258789])),o.Column.fromFloat32Array("height",new Float32Array([52.400001525878906,55.70000076293945,54.29999923706055,52,50.79999923706055,50.599998474121094,52.599998474121094,54.099998474121094,53.5,52.79999923706055,54.099998474121094,56.29999923706055,54.79999923706055,50.79999923706055,53.5,54.5,50.599998474121094,58.70000076293945,51.599998474121094,56.099998474121094,52.5,54.5,53,52,54.900001525878906,55.70000076293945,55.099998474121094,56.20000076293945,55.5,55.5])),o.Column.fromInt32Array("curb.weight",new Int32Array([2823,2844,2395,1909,2128,1967,1956,2304,2337,4066,1950,3770,2910,1918,2024,1951,1967,3430,2800,2695,2190,1985,2275,2551,2480,2261,2661,2912,3049,3217])),o.Column.fromInt32Array("eng.size",new Int32Array([152,136,108,90,98,90,92,110,111,258,91,183,140,92,97,97,90,152,194,121,108,92,110,146,110,97,136,141,141,145])),o.Column.fromInt32Array("horsepower",new Int32Array([154,110,101,70,102,68,76,86,78,176,68,123,175,68,69,69,68,95,207,110,82,62,56,116,73,52,110,114,160,106])),o.Column.fromInt32Array("peak.rpm",new Int32Array([5e3,5500,5800,5400,5500,5500,6e3,5800,4800,4750,5e3,4350,5e3,5500,5200,5200,5500,4150,5900,5250,4400,4800,4500,4800,4500,4800,5500,5400,5300,4800])),o.Column.fromInt32Array("symbol",new Int32Array([1,1,2,0,1,1,1,0,0,0,1,-1,1,2,1,1,1,0,3,2,0,1,0,2,-1,2,0,-2,-1,-1])),o.Column.fromInt32Array("city.mpg",new Int32Array([19,19,23,38,24,31,30,27,24,15,31,22,19,37,31,31,31,25,17,21,28,35,34,24,30,37,19,23,19,26])),o.Column.fromInt32Array("highway.mpg",new Int32Array([26,25,29,43,30,38,34,33,29,19,38,25,24,41,37,37,38,25,25,28,33,39,36,30,33,46,24,28,25,27])),o.Column.fromInt32Array("price",new Int32Array([16500,17710,16430,6575,7957,6229,7129,8845,6785,35550,7395,31600,16503,5389,7349,7299,6229,13860,37028,12170,7775,5348,7898,9989,10698,7775,13295,12940,19045,22470]))])),t.shell.windows.help.visible=!0,t.shell.windows.help.showHelp(e.markdown(Pe)),t.shell.windows.showContextPanel=!1,t.shell.windows.showProperties=!1,yield Ge(ge.DEMO)}))}()}))}function Br(t,e,n){return Cr(this,void 0,void 0,(function*(){return de(yield ce({gamma:n,kernel:tt},t,e))}))}function Vr(t,e){return Cr(this,void 0,void 0,(function*(){return yield fe(t,e)}))}function Wr(t,e){return Cr(this,void 0,void 0,(function*(){return pe(t,e)}))}function jr(t,e){return Cr(this,void 0,void 0,(function*(){return me(t)}))}function Yr(t,e,n,r){return Cr(this,void 0,void 0,(function*(){return le(0,r)}))}function zr(t,e,n,r){return Cr(this,void 0,void 0,(function*(){return de(yield ce({gamma:n,kernel:nt,sigma:r},t,e))}))}function qr(t,e){return Cr(this,void 0,void 0,(function*(){return yield fe(t,e)}))}function Hr(t,e){return Cr(this,void 0,void 0,(function*(){return pe(t,e)}))}function $r(t,e){return Cr(this,void 0,void 0,(function*(){return me(t)}))}function Kr(t,e,n,r){return Cr(this,void 0,void 0,(function*(){return le(0,r)}))}function Xr(t,e,n,r,o){return Cr(this,void 0,void 0,(function*(){return de(yield ce({gamma:n,kernel:et,cParam:r,dParam:o},t,e))}))}function Qr(t,e){return Cr(this,void 0,void 0,(function*(){return yield fe(t,e)}))}function Jr(t,e){return Cr(this,void 0,void 0,(function*(){return pe(t,e)}))}function Zr(t,e){return Cr(this,void 0,void 0,(function*(){return me(t)}))}function to(t,e,n,r){return Cr(this,void 0,void 0,(function*(){return le(0,r)}))}function eo(t,e,n,r,o){return Cr(this,void 0,void 0,(function*(){return de(yield ce({gamma:n,kernel:rt,kappa:r,theta:o},t,e))}))}function no(t,e){return Cr(this,void 0,void 0,(function*(){return yield fe(t,e)}))}function ro(t,e){return Cr(this,void 0,void 0,(function*(){return pe(t,e)}))}function oo(t,e){return Cr(this,void 0,void 0,(function*(){return me(t)}))}function io(t,e,n,r){return Cr(this,void 0,void 0,(function*(){return le(0,r)}))}function ao(){dn()}function so(){rr()}function uo(t){return Cr(this,void 0,void 0,(function*(){yield rr(t)}))}function co(t,e){return Cr(this,void 0,void 0,(function*(){const n=t.columns,r=yield function(t,e){return sr(this,void 0,void 0,(function*(){const n=t.length,r=e.length,i=e.stats.avg,a=e.stats.stdev,s=new Float32Array(n+1).fill(0);if(s[n]=i,0===a||1===r)return s;try{const r=[],u=[],c=new Float32Array(n),l=new Float32Array(n);let d=0,h=0;for(const e of t){const t=e.stats;t.stdev>0&&(r.push(d),u.push(e),c[h]=t.avg,l[h]=t.stdev,++h),++d}if(0===h)return s;const f=function(t,e,n,r,o,i,a){return g(EDA,"fitLinearRegressionParamsWithDataNormalizing",[t,e,n,r,o,i,a])}(o.DataFrame.fromColumns(u).columns,o.Column.fromFloat32Array("xAvgs",c,h),o.Column.fromFloat32Array("xStdevs",l,h),e,i,a,h+1).getRawData();for(let t=0;t<h;++t)s[r[t]]=f[t];s[n]=f[h]}catch(r){const i=yield function(t,e,n){return sr(this,void 0,void 0,(function*(){return(yield ke({table:o.DataFrame.fromColumns([e]),features:t,predict:e,components:n,names:void 0})).regressionCoefficients.getRawData()}))}(t,e,cr(t.length,e.length));let a=0;for(let e=0;e<n;++e)s[e]=i[e],a+=i[e]*t.byIndex(e).stats.avg;s[n]-=a}return s}))}(n,e);return new Uint8Array(r.buffer)}))}function lo(t,e){const n=t.columns,r=new Float32Array(e.buffer);return o.DataFrame.fromColumns([ur(n,r)])}function ho(t,e){for(const e of t.columns)if(!e.matches("numerical"))return!1;return e.matches("numerical")}function fo(t,e){return t.rowCount<=1e5}function po(t,e,n,r,o,i){return Cr(this,void 0,void 0,(function*(){const a=t.columns,s=new gr({classesCount:e.categories.length,featuresCount:a.length});return yield s.fit(a,e,n,r,o,i),s.toBytes()}))}function mo(t,e){const n=t.columns,r=new gr(void 0,e);return o.DataFrame.fromColumns([r.predict(n)])}function go(t,e){return gr.isApplicable(t.columns,e)}function yo(t,e){return gr.isInteractive(t.columns,e)}function vo(t,e,n){return Cr(this,void 0,void 0,(function*(){const r=t.columns,o=new dr;return yield o.fit(r,e,Math.min(n,r.length)),o.toBytes()}))}function wo(t,e){const n=new dr(e);return o.DataFrame.fromColumns([n.predict(t.columns)])}function bo(t,e){return dr.isApplicable(t.columns,e)}function Eo(t,e,n,r){return Cr(this,void 0,void 0,(function*(){return new dr(r).viewers().map((t=>t.root))}))}function Ao(t,e){return dr.isInteractive(t.columns,e)}function Co(t,e,n,r,o,i,a){return Cr(this,void 0,void 0,(function*(){const s=t.columns,u=new Ar;return yield u.fit(s,e,n,r,o,i,a),u.toBytes()}))}function So(t,e){const n=new Ar(e);return o.DataFrame.fromColumns([n.predict(t.columns)])}function _o(t,e){return Ar.isInteractive(t.columns,e)}function No(t,e){return Ar.isApplicable(t.columns,e)}})(),eda=r})();
|
|
2
2
|
//# sourceMappingURL=package.js.map
|