@datagrok/eda 1.2.0 → 1.2.1

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/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,i=(r="undefined"!=typeof document&&document.currentScript?document.currentScript.src:void 0,function(t={}){var e,n,i=void 0!==t?t:{};i.ready=new Promise((function(t,r){e=t,n=r}));var o,s=Object.assign({},i),a="object"==typeof window,u="function"==typeof importScripts,c=("object"==typeof process&&"object"==typeof process.versions&&process.versions.node,"");(a||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&&(o=t=>{var e=new XMLHttpRequest;return e.open("GET",t,!1),e.responseType="arraybuffer",e.send(null),new Uint8Array(e.response)})),i.print||console.log.bind(console);var l,h,d=i.printErr||console.warn.bind(console);Object.assign(i,s),s=null,i.arguments&&i.arguments,i.thisProgram&&i.thisProgram,i.quit&&i.quit,i.wasmBinary&&(l=i.wasmBinary),i.noExitRuntime,"object"!=typeof WebAssembly&&C("no native wasm support detected");var f,p,m,g=!1;function y(){var t=h.buffer;i.HEAP8=f=new Int8Array(t),i.HEAP16=new Int16Array(t),i.HEAP32=new Int32Array(t),i.HEAPU8=p=new Uint8Array(t),i.HEAPU16=new Uint16Array(t),i.HEAPU32=m=new Uint32Array(t),i.HEAPF32=new Float32Array(t),i.HEAPF64=new Float64Array(t)}var v=[],w=[],b=[],E=0,A=null,_=null;function C(t){i.onAbort&&i.onAbort(t),d(t="Aborted("+t+")"),g=!0,t+=". Build with -sASSERTIONS for more info.";var e=new WebAssembly.RuntimeError(t);throw n(e),e}var S,I;function M(t){return t.startsWith("data:application/octet-stream;base64,")}function N(t){try{if(t==S&&l)return new Uint8Array(l);if(o)return o(t);throw"both async and sync fetching of the wasm failed"}catch(t){C(t)}}function x(t,e,n){return function(t){return l||!a&&!u||"function"!=typeof fetch?Promise.resolve().then((function(){return N(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 N(t)}))}(t).then((function(t){return WebAssembly.instantiate(t,e)})).then((function(t){return t})).then(n,(function(t){d("failed to asynchronously prepare wasm: "+t),C(t)}))}function L(t){for(;t.length>0;)t.shift()(i)}function T(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 O(t){var e=h.buffer;try{return h.grow(t-e.byteLength+65535>>>16),y(),1}catch(t){}}function P(t){return i["_"+t]}M(S="wasmDbscan.wasm")||(I=S,S=i.locateFile?i.locateFile(I,c):c+I);var R="undefined"!=typeof TextDecoder?new TextDecoder("utf8"):void 0;function F(t,e,n,r,i){var o={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 i=n+r-1,o=0;o<t.length;++o){var s=t.charCodeAt(o);if(s>=55296&&s<=57343&&(s=65536+((1023&s)<<10)|1023&t.charCodeAt(++o)),s<=127){if(n>=i)break;e[n++]=s}else if(s<=2047){if(n+1>=i)break;e[n++]=192|s>>6,e[n++]=128|63&s}else if(s<=65535){if(n+2>=i)break;e[n++]=224|s>>12,e[n++]=128|s>>6&63,e[n++]=128|63&s}else{if(n+3>=i)break;e[n++]=240|s>>18,e[n++]=128|s>>12&63,e[n++]=128|s>>6&63,e[n++]=128|63&s}}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}},s=P(t),a=[],u=0;if(r)for(var c=0;c<r.length;c++){var l=o[n[c]];l?(0===u&&(u=k()),a[c]=l(r[c])):a[c]=r[c]}var h=s.apply(null,a);return function(t){return 0!==u&&G(u),function(t){return"string"===e?(n=t)?function(t,e,n){for(var r=e+n,i=e;t[i]&&!(i>=r);)++i;if(i-e>16&&t.buffer&&R)return R.decode(t.subarray(e,i));for(var o="";e<i;){var s=t[e++];if(128&s){var a=63&t[e++];if(192!=(224&s)){var u=63&t[e++];if((s=224==(240&s)?(15&s)<<12|a<<6|u:(7&s)<<18|a<<12|u<<6|63&t[e++])<65536)o+=String.fromCharCode(s);else{var c=s-65536;o+=String.fromCharCode(55296|c>>10,56320|1023&c)}}else o+=String.fromCharCode((31&s)<<6|a)}else o+=String.fromCharCode(s)}return o}(p,n,r):"":"boolean"===e?Boolean(t):t;var n,r}(t)}(h)}var D,U={__cxa_throw:function(t,e,n){throw new T(t).init(e,n),t},abort:function(){C("")},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 i=1;i<=4;i*=2){var o=n*(1+.2/i);if(o=Math.min(o,t+100663296),O(Math.min(r,(e=Math.max(t,o))+(65536-e%65536)%65536)))return!0}return!1}},k=(function(){var t,e,r,o,s={env:U,wasi_snapshot_preview1:U};function a(t,e){var n,r=t.exports;return i.asm=r,h=i.asm.memory,y(),i.asm.__indirect_function_table,n=i.asm.__wasm_call_ctors,w.unshift(n),function(){if(E--,i.monitorRunDependencies&&i.monitorRunDependencies(E),0==E&&(null!==A&&(clearInterval(A),A=null),_)){var t=_;_=null,t()}}(),r}if(E++,i.monitorRunDependencies&&i.monitorRunDependencies(E),i.instantiateWasm)try{return i.instantiateWasm(s,a)}catch(t){d("Module.instantiateWasm callback failed with error: "+t),n(t)}(t=l,e=S,r=s,o=function(t){a(t.instance)},t||"function"!=typeof WebAssembly.instantiateStreaming||M(e)||"function"!=typeof fetch?x(e,r,o):fetch(e,{credentials:"same-origin"}).then((function(t){return WebAssembly.instantiateStreaming(t,r).then(o,(function(t){return d("wasm streaming compile failed: "+t),d("falling back to ArrayBuffer instantiation"),x(e,r,o)}))}))).catch(n)}(),i._dbscan=function(){return(i._dbscan=i.asm.dbscan).apply(null,arguments)},i._malloc=function(){return(i._malloc=i.asm.malloc).apply(null,arguments)},i._free=function(){return(i._free=i.asm.free).apply(null,arguments)},function(){return(k=i.asm.stackSave).apply(null,arguments)}),G=function(){return(G=i.asm.stackRestore).apply(null,arguments)},B=function(){return(B=i.asm.stackAlloc).apply(null,arguments)},V=function(){return(V=i.asm.__cxa_is_pointer_type).apply(null,arguments)};function W(){function t(){D||(D=!0,i.calledRun=!0,g||(L(w),e(i),i.onRuntimeInitialized&&i.onRuntimeInitialized(),function(){if(i.postRun)for("function"==typeof i.postRun&&(i.postRun=[i.postRun]);i.postRun.length;)t=i.postRun.shift(),b.unshift(t);var t;L(b)}()))}E>0||(function(){if(i.preRun)for("function"==typeof i.preRun&&(i.preRun=[i.preRun]);i.preRun.length;)t=i.preRun.shift(),v.unshift(t);var t;L(v)}(),E>0||(i.setStatus?(i.setStatus("Running..."),setTimeout((function(){setTimeout((function(){i.setStatus("")}),1),t()}),1)):t()))}if(i.ccall=F,i.cwrap=function(t,e,n,r){var i=!n||n.every((t=>"number"===t||"boolean"===t));return"string"!==e&&i&&!r?P(t):function(){return F(t,e,n,arguments)}},_=function t(){D||W(),D||(_=t)},i.preInit)for("function"==typeof i.preInit&&(i.preInit=[i.preInit]);i.preInit.length>0;)i.preInit.pop()();return W(),t.ready});"object"==typeof exports?t.exports=i:"function"==typeof define&&n.amdO?define([],(function(){return i})):"object"==typeof exports&&(exports.exportCppDbscanLib=i)},7939:(t,e,n)=>{"use strict";n.d(e,{A:()=>a});var r=n(1354),i=n.n(r),o=n(6314),s=n.n(o)()(i());s.push([t.id,".scatter_plot_link {\n position: absolute!important;\n right: 10px;\n}\n\n.cliffs_grid {\n top: 10px;\n}\n\n.show_only_cliffs {\n top: 30px;\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\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,4BAA4B;IAC5B,WAAW;AACf;;AAEA;IACI,SAAS;AACb;;AAEA;IACI,SAAS;AACb;;AAEA;IACI,eAAe;IACf,kBAAkB;IAClB,YAAY;;AAEhB;;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 position: absolute!important;\n right: 10px;\n}\n\n.cliffs_grid {\n top: 10px;\n}\n\n.show_only_cliffs {\n top: 30px;\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\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 a=s},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,i,o){"string"==typeof t&&(t=[[null,t,void 0]]);var s={};if(r)for(var a=0;a<this.length;a++){var u=this[a][0];null!=u&&(s[u]=!0)}for(var c=0;c<t.length;c++){var l=[].concat(t[c]);r&&s[l[0]]||(void 0!==o&&(void 0===l[5]||(l[1]="@layer".concat(l[5].length>0?" ".concat(l[5]):""," {").concat(l[1],"}")),l[5]=o),n&&(l[2]?(l[1]="@media ".concat(l[2]," {").concat(l[1],"}"),l[2]=n):l[2]=n),i&&(l[4]?(l[1]="@supports (".concat(l[4],") {").concat(l[1],"}"),l[4]=i):l[4]="".concat(i)),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)))),i="sourceMappingURL=data:application/json;charset=utf-8;base64,".concat(r),o="/*# ".concat(i," */");return[e].concat([o]).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,i=Array.prototype.slice.call(arguments).slice(1);for(e=0,r=i.length;e<r;e++)if(i[e])for(n in i[e])t[n]=i[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,i=t.size,o={},s=new Float32Array(10*r),a=new Float32Array(3*i);return n=0,t.forEachNode((function(t,e){o[t]=n,s[n]=e.x,s[n+1]=e.y,s[n+2]=0,s[n+3]=0,s[n+4]=0,s[n+5]=0,s[n+6]=1,s[n+7]=1,s[n+8]=e.size||1,s[n+9]=e.fixed?1:0,n+=10})),n=0,t.forEachEdge((function(t,r,i,u,c,l,h){var d=o[i],f=o[u],p=e(t,r,i,u,c,l,h);s[d+6]+=p,s[f+6]+=p,a[n]=d,a[n+1]=f,a[n+2]=p,n+=3})),{nodes:s,edges:a}},e.assignLayoutChanges=function(t,e,n){var r=0;t.updateEachNodeAttributes((function(t,i){return i.x=e[r],i.y=e[r+1],r+=10,n?n(t,i):i}))},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(),i={},o=0,s=0,a=e.length;o<a;o+=10){if(n){var u=Object.assign({},t.getNodeAttributes(r[s]));u.x=e[o],u.y=e[o+1],u=n(r[s],u),i[r[s]]={x:u.x,y:u.y}}else i[r[s]]={x:e[o],y:e[o+1]};s++}return i},e.createWorker=function(t){var e=window.URL||window.webkitURL,n=t.toString(),r=e.createObjectURL(new Blob(["("+n+").call(this);"],{type:"text/javascript"})),i=new Worker(r);return e.revokeObjectURL(r),i}},8903:(t,e,n)=>{var r=n(1736),i=n(8153).Fd,o=n(2561),s=n(1782),a=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=i("getEdgeWeight"in n?n.getEdgeWeight:"weight").fromEntry,l="function"==typeof n.outputReducer?n.outputReducer:null,h=s.assign({},a,n.settings),d=s.validateSettings(h);if(d)throw new Error("graphology-layout-forceatlas2: "+d.message);var f,p=s.graphToByteArrays(e,c);for(f=0;f<u;f++)o(h,p.nodes,p.edges);if(!t)return s.collectLayoutChanges(e,p.nodes);s.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 i,o,s,a,u,c,l,h,d,f,p,m,g,y,v,w,b,E,A,_,C,S,I,M=n.length,N=r.length,x=t.adjustSizes,L=t.barnesHutTheta*t.barnesHutTheta,T=[];for(s=0;s<M;s+=e)n[s+4]=n[s+2],n[s+5]=n[s+3],n[s+2]=0,n[s+3]=0;if(t.outboundAttractionDistribution){for(p=0,s=0;s<M;s+=e)p+=n[s+6];p/=M/e}if(t.barnesHutOptimize){var O,P,R,F=1/0,D=-1/0,U=1/0,k=-1/0;for(s=0;s<M;s+=e)F=Math.min(F,n[s+0]),D=Math.max(D,n[s+0]),U=Math.min(U,n[s+1]),k=Math.max(k,n[s+1]);var G=D-F,B=k-U;for(G>B?k=(U-=(G-B)/2)+G:D=(F-=(B-G)/2)+B,T[0]=-1,T[1]=(F+D)/2,T[2]=(U+k)/2,T[3]=Math.max(D-F,k-U),T[4]=-1,T[5]=-1,T[6]=0,T[7]=0,T[8]=0,i=1,s=0;s<M;s+=e)for(o=0,R=3;;){if(!(T[o+5]>=0)){if(T[o+0]<0){T[o+0]=s;break}if(T[o+5]=9*i,h=T[o+3]/2,T[(d=T[o+5])+0]=-1,T[d+1]=T[o+1]-h,T[d+2]=T[o+2]-h,T[d+3]=h,T[d+4]=d+9,T[d+5]=-1,T[d+6]=0,T[d+7]=0,T[d+8]=0,T[(d+=9)+0]=-1,T[d+1]=T[o+1]-h,T[d+2]=T[o+2]+h,T[d+3]=h,T[d+4]=d+9,T[d+5]=-1,T[d+6]=0,T[d+7]=0,T[d+8]=0,T[(d+=9)+0]=-1,T[d+1]=T[o+1]+h,T[d+2]=T[o+2]-h,T[d+3]=h,T[d+4]=d+9,T[d+5]=-1,T[d+6]=0,T[d+7]=0,T[d+8]=0,T[(d+=9)+0]=-1,T[d+1]=T[o+1]+h,T[d+2]=T[o+2]+h,T[d+3]=h,T[d+4]=T[o+4],T[d+5]=-1,T[d+6]=0,T[d+7]=0,T[d+8]=0,i+=4,O=n[T[o+0]+0]<T[o+1]?n[T[o+0]+1]<T[o+2]?T[o+5]:T[o+5]+9:n[T[o+0]+1]<T[o+2]?T[o+5]+18:T[o+5]+27,T[o+6]=n[T[o+0]+6],T[o+7]=n[T[o+0]+0],T[o+8]=n[T[o+0]+1],T[O+0]=T[o+0],T[o+0]=-1,O===(P=n[s+0]<T[o+1]?n[s+1]<T[o+2]?T[o+5]:T[o+5]+9:n[s+1]<T[o+2]?T[o+5]+18:T[o+5]+27)){if(R--){o=O;continue}R=3;break}T[P+0]=s;break}O=n[s+0]<T[o+1]?n[s+1]<T[o+2]?T[o+5]:T[o+5]+9:n[s+1]<T[o+2]?T[o+5]+18:T[o+5]+27,T[o+7]=(T[o+7]*T[o+6]+n[s+0]*n[s+6])/(T[o+6]+n[s+6]),T[o+8]=(T[o+8]*T[o+6]+n[s+1]*n[s+6])/(T[o+6]+n[s+6]),T[o+6]+=n[s+6],o=O}}if(t.barnesHutOptimize){for(m=t.scalingRatio,s=0;s<M;s+=e)for(o=0;;)if(T[o+5]>=0){if(w=Math.pow(n[s+0]-T[o+7],2)+Math.pow(n[s+1]-T[o+8],2),4*(f=T[o+3])*f/w<L){if(g=n[s+0]-T[o+7],y=n[s+1]-T[o+8],!0===x?w>0?(b=m*n[s+6]*T[o+6]/w,n[s+2]+=g*b,n[s+3]+=y*b):w<0&&(b=-m*n[s+6]*T[o+6]/Math.sqrt(w),n[s+2]+=g*b,n[s+3]+=y*b):w>0&&(b=m*n[s+6]*T[o+6]/w,n[s+2]+=g*b,n[s+3]+=y*b),(o=T[o+4])<0)break;continue}o=T[o+5]}else if((c=T[o+0])>=0&&c!==s&&(w=(g=n[s+0]-n[c+0])*g+(y=n[s+1]-n[c+1])*y,!0===x?w>0?(b=m*n[s+6]*n[c+6]/w,n[s+2]+=g*b,n[s+3]+=y*b):w<0&&(b=-m*n[s+6]*n[c+6]/Math.sqrt(w),n[s+2]+=g*b,n[s+3]+=y*b):w>0&&(b=m*n[s+6]*n[c+6]/w,n[s+2]+=g*b,n[s+3]+=y*b)),(o=T[o+4])<0)break}else for(m=t.scalingRatio,a=0;a<M;a+=e)for(u=0;u<a;u+=e)g=n[a+0]-n[u+0],y=n[a+1]-n[u+1],!0===x?(w=Math.sqrt(g*g+y*y)-n[a+8]-n[u+8])>0?(b=m*n[a+6]*n[u+6]/w/w,n[a+2]+=g*b,n[a+3]+=y*b,n[u+2]-=g*b,n[u+3]-=y*b):w<0&&(b=100*m*n[a+6]*n[u+6],n[a+2]+=g*b,n[a+3]+=y*b,n[u+2]-=g*b,n[u+3]-=y*b):(w=Math.sqrt(g*g+y*y))>0&&(b=m*n[a+6]*n[u+6]/w/w,n[a+2]+=g*b,n[a+3]+=y*b,n[u+2]-=g*b,n[u+3]-=y*b);for(d=t.gravity/t.scalingRatio,m=t.scalingRatio,s=0;s<M;s+=e)b=0,g=n[s+0],y=n[s+1],w=Math.sqrt(Math.pow(g,2)+Math.pow(y,2)),t.strongGravityMode?w>0&&(b=m*n[s+6]*d):w>0&&(b=m*n[s+6]*d/w),n[s+2]-=g*b,n[s+3]-=y*b;for(m=1*(t.outboundAttractionDistribution?p:1),l=0;l<N;l+=3)a=r[l+0],u=r[l+1],h=r[l+2],v=Math.pow(h,t.edgeWeightInfluence),g=n[a+0]-n[u+0],y=n[a+1]-n[u+1],!0===x?(w=Math.sqrt(g*g+y*y)-n[a+8]-n[u+8],t.linLogMode?t.outboundAttractionDistribution?w>0&&(b=-m*v*Math.log(1+w)/w/n[a+6]):w>0&&(b=-m*v*Math.log(1+w)/w):t.outboundAttractionDistribution?w>0&&(b=-m*v/n[a+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[a+6]):w>0&&(b=-m*v*Math.log(1+w)/w):t.outboundAttractionDistribution?(w=1,b=-m*v/n[a+6]):(w=1,b=-m*v)),w>0&&(n[a+2]+=g*b,n[a+3]+=y*b,n[u+2]-=g*b,n[u+3]-=y*b);if(!0===x)for(s=0;s<M;s+=e)1!==n[s+9]&&((E=Math.sqrt(Math.pow(n[s+2],2)+Math.pow(n[s+3],2)))>10&&(n[s+2]=10*n[s+2]/E,n[s+3]=10*n[s+3]/E),A=n[s+6]*Math.sqrt((n[s+4]-n[s+2])*(n[s+4]-n[s+2])+(n[s+5]-n[s+3])*(n[s+5]-n[s+3])),_=Math.sqrt((n[s+4]+n[s+2])*(n[s+4]+n[s+2])+(n[s+5]+n[s+3])*(n[s+5]+n[s+3]))/2,C=.1*Math.log(1+_)/(1+Math.sqrt(A)),S=n[s+0]+n[s+2]*(C/t.slowDown),n[s+0]=S,I=n[s+1]+n[s+3]*(C/t.slowDown),n[s+1]=I);else for(s=0;s<M;s+=e)1!==n[s+9]&&(A=n[s+6]*Math.sqrt((n[s+4]-n[s+2])*(n[s+4]-n[s+2])+(n[s+5]-n[s+3])*(n[s+5]-n[s+3])),_=Math.sqrt((n[s+4]+n[s+2])*(n[s+4]+n[s+2])+(n[s+5]+n[s+3])*(n[s+5]+n[s+3]))/2,C=n[s+7]*Math.log(1+_)/(1+Math.sqrt(A)),n[s+7]=Math.min(1,Math.sqrt(C*(Math.pow(n[s+2],2)+Math.pow(n[s+3],2))/(1+Math.sqrt(A)))),S=n[s+0]+n[s+2]*(C/t.slowDown),n[s+0]=S,I=n[s+1]+n[s+3]*(C/t.slowDown),n[s+1]=I);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 i=function(e){return r(e[t])},o=function(){return r(void 0)};return"string"==typeof t?(n.fromAttributes=i,n.fromGraph=function(t,e){return i(t.getEdgeAttributes(e))},n.fromEntry=function(t,e){return i(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 i=e.extremities(n);return r(t(n,e.getEdgeAttributes(n),i[0],i[1],e.getNodeAttributes(i[0]),e.getNodeAttributes(i[1]),e.isUndirected(n)))},n.fromEntry=function(e,n,i,o,s,a,u){return r(t(e,n,i,o,s,a,u))},n.fromPartialEntry=function(e,n,i,o){return r(t(e,n,i,o))},n.fromMinimalEntry=function(e,n){return r(t(e,n))}):(n.fromAttributes=o,n.fromGraph=o,n.fromEntry=o,n.fromMinimalEntry=o),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 i(t,e,n){return i=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 i=[null];i.push.apply(i,e);var o=new(Function.bind.apply(t,i));return n&&r(o,n.prototype),o},i.apply(null,arguments)}function o(t){var e="function"==typeof Map?new Map:void 0;return o=function(t){if(null===t||(o=t,-1===Function.toString.call(o).indexOf("[native code]")))return t;var o;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,s)}function s(){return i(t,arguments,n(this).constructor)}return s.prototype=Object.create(t.prototype,{constructor:{value:s,enumerable:!1,writable:!0,configurable:!0}}),r(s,t)},o(t)}function s(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}var a=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 i=t._nodes.get(e),o=null;return i?o="mixed"===r?i.out&&i.out[n]||i.undirected&&i.undirected[n]:"directed"===r?i.out&&i.out[n]:i.undirected&&i.undirected[n]:o}function c(e){return"object"===t(e)&&null!==e}function l(t){var e;for(e in t)return!1;return!0}function h(t,e,n){Object.defineProperty(t,e,{enumerable:!1,configurable:!1,writable:!0,value:n})}function d(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&&(a=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 i(n){t.removeListener(e,o),r(n)}function o(){"function"==typeof t.removeListener&&t.removeListener("error",i),n([].slice.call(arguments))}x(t,e,o,{once:!0}),"error"!==e&&function(t,e){"function"==typeof t.on&&x(t,"error",e,{once:!0})}(t,i)}))},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 _(t,e,n,r){var i,o,s,a;if(E(n),void 0===(o=t._events)?(o=t._events=Object.create(null),t._eventsCount=0):(void 0!==o.newListener&&(t.emit("newListener",e,n.listener?n.listener:n),o=t._events),s=o[e]),void 0===s)s=o[e]=n,++t._eventsCount;else if("function"==typeof s?s=o[e]=r?[n,s]:[s,n]:r?s.unshift(n):s.push(n),(i=A(t))>0&&s.length>i&&!s.warned){s.warned=!0;var u=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");u.name="MaxListenersExceededWarning",u.emitter=t,u.type=e,u.count=s.length,a=u,console&&console.warn&&console.warn(a)}return t}function C(){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 S(t,e,n){var r={fired:!1,wrapFn:void 0,target:t,type:e,listener:n},i=C.bind(r);return i.listener=n,r.wrapFn=i,i}function I(t,e,n){var r=t._events;if(void 0===r)return[];var i=r[e];return void 0===i?[]:"function"==typeof i?n?[i.listener||i]:[i]: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}(i):N(i,i.length)}function M(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 N(t,e){for(var n=new Array(e),r=0;r<e;++r)n[r]=t[r];return n}function x(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 i(o){r.once&&t.removeEventListener(e,i),n(o)}))}}function L(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,i=this._events;if(void 0!==i)r=r&&void 0===i.error;else if(!r)return!1;if(r){var o;if(e.length>0&&(o=e[0]),o instanceof Error)throw o;var s=new Error("Unhandled error."+(o?" ("+o.message+")":""));throw s.context=o,s}var a=i[t];if(void 0===a)return!1;if("function"==typeof a)y(a,this,e);else{var u=a.length,c=N(a,u);for(n=0;n<u;++n)y(c[n],this,e)}return!0},w.prototype.addListener=function(t,e){return _(this,t,e,!1)},w.prototype.on=w.prototype.addListener,w.prototype.prependListener=function(t,e){return _(this,t,e,!0)},w.prototype.once=function(t,e){return E(e),this.on(t,S(this,t,e)),this},w.prototype.prependOnceListener=function(t,e){return E(e),this.prependListener(t,S(this,t,e)),this},w.prototype.removeListener=function(t,e){var n,r,i,o,s;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(i=-1,o=n.length-1;o>=0;o--)if(n[o]===e||n[o].listener===e){s=n[o].listener,i=o;break}if(i<0)return this;0===i?n.shift():function(t,e){for(;e+1<t.length;e++)t[e]=t[e+1];t.pop()}(n,i),1===n.length&&(r[t]=n[0]),void 0!==r.removeListener&&this.emit("removeListener",t,s||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 i,o=Object.keys(n);for(r=0;r<o.length;++r)"removeListener"!==(i=o[r])&&this.removeAllListeners(i);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 I(this,t,!0)},w.prototype.rawListeners=function(t){return I(this,t,!1)},w.listenerCount=function(t,e){return"function"==typeof t.listenerCount?t.listenerCount(e):M.call(t,e)},w.prototype.listenerCount=M,w.prototype.eventNames=function(){return this._eventsCount>0?p(this._events):[]},"undefined"!=typeof Symbol&&(L.prototype[Symbol.iterator]=function(){return this}),L.of=function(){var t=arguments,e=t.length,n=0;return new L((function(){return n>=e?{done:!0}:{done:!1,value:t[n++]}}))},L.empty=function(){return new L((function(){return{done:!0}}))},L.fromSequence=function(t){var e=0,n=t.length;return new L((function(){return e>=n?{done:!0}:{done:!1,value:t[e++]}}))},L.is=function(t){return t instanceof L||"object"==typeof t&&null!==t&&"function"==typeof t.next};var T=L,O={};O.ARRAY_BUFFER_SUPPORT="undefined"!=typeof ArrayBuffer,O.SYMBOL_SUPPORT="undefined"!=typeof Symbol;var P=T,R=O,F=R.ARRAY_BUFFER_SUPPORT,D=R.SYMBOL_SUPPORT,U=function(t){var e=function(t){return"string"==typeof t||Array.isArray(t)||F&&ArrayBuffer.isView(t)?P.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,i=r!==1/0?new Array(r):[],o=0,s=k(t);;){if(o===r)return i;if((n=s.next()).done)return o!==e&&(i.length=o),i;i[o++]=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}(o(Error)),V=function(t){function n(e){var r;return(r=t.call(this,e)||this).name="InvalidArgumentsGraphError","function"==typeof Error.captureStackTrace&&Error.captureStackTrace(s(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(s(r),n.prototype.constructor),r}return e(n,t),n}(B),z=function(t){function n(e){var r;return(r=t.call(this,e)||this).name="UsageGraphError","function"==typeof Error.captureStackTrace&&Error.captureStackTrace(s(r),n.prototype.constructor),r}return e(n,t),n}(B);function j(t,e){this.key=t,this.attributes=e,this.clear()}function Y(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,i){this.key=e,this.attributes=i,this.undirected=t,this.source=n,this.target=r}function $(t,e,n,r,i,o,s){var a,u,c,l;if(r=""+r,0===n){if(!(a=t._nodes.get(r)))throw new W("Graph.".concat(e,': could not find the "').concat(r,'" node in the graph.'));c=i,l=o}else if(3===n){if(i=""+i,!(u=t._edges.get(i)))throw new W("Graph.".concat(e,': could not find the "').concat(i,'" edge in the graph.'));var h=u.source.key,d=u.target.key;if(r===h)a=u.target;else{if(r!==d)throw new W("Graph.".concat(e,': the "').concat(r,'" node is not attached to the "').concat(i,'" edge (').concat(h,", ").concat(d,")."));a=u.source}c=o,l=s}else{if(!(u=t._edges.get(r)))throw new W("Graph.".concat(e,': could not find the "').concat(r,'" edge in the graph.'));a=1===n?u.source:u.target,c=i,l=o}return[a,c,l]}j.prototype.clear=function(){this.inDegree=0,this.outDegree=0,this.undirectedDegree=0,this.undirectedLoops=0,this.directedLoops=0,this.in={},this.out={},this.undirected={}},Y.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 i=this.source[t],o=i[r];if(void 0===o)return i[r]=this,void(this.undirected&&n===r||(this.target[e][n]=this));o.previous=this,this.next=o,i[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,i){var o=$(this,e,n,t,r,i),s=o[0],a=o[1];return s.attributes[a]}}},{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,i){var o=$(this,e,n,t,r,i),s=o[0],a=o[1];return s.attributes.hasOwnProperty(a)}}},{name:function(t){return"set".concat(t,"Attribute")},attacher:function(t,e,n){t.prototype[e]=function(t,r,i,o){var s=$(this,e,n,t,r,i,o),a=s[0],u=s[1],c=s[2];return a.attributes[u]=c,this.emit("nodeAttributesUpdated",{key:a.key,type:"set",attributes:a.attributes,name:u}),this}}},{name:function(t){return"update".concat(t,"Attribute")},attacher:function(t,e,n){t.prototype[e]=function(t,r,i,o){var s=$(this,e,n,t,r,i,o),a=s[0],u=s[1],c=s[2];if("function"!=typeof c)throw new V("Graph.".concat(e,": updater should be a function."));var l=a.attributes,h=c(l[u]);return l[u]=h,this.emit("nodeAttributesUpdated",{key:a.key,type:"set",attributes:a.attributes,name:u}),this}}},{name:function(t){return"remove".concat(t,"Attribute")},attacher:function(t,e,n){t.prototype[e]=function(t,r,i){var o=$(this,e,n,t,r,i),s=o[0],a=o[1];return delete s.attributes[a],this.emit("nodeAttributesUpdated",{key:s.key,type:"remove",attributes:s.attributes,name:a}),this}}},{name:function(t){return"replace".concat(t,"Attributes")},attacher:function(t,e,n){t.prototype[e]=function(t,r,i){var o=$(this,e,n,t,r,i),s=o[0],a=o[1];if(!c(a))throw new V("Graph.".concat(e,": provided attributes are not a plain object."));return s.attributes=a,this.emit("nodeAttributesUpdated",{key:s.key,type:"replace",attributes:s.attributes}),this}}},{name:function(t){return"merge".concat(t,"Attributes")},attacher:function(t,e,n){t.prototype[e]=function(t,r,i){var o=$(this,e,n,t,r,i),s=o[0],u=o[1];if(!c(u))throw new V("Graph.".concat(e,": provided attributes are not a plain object."));return a(s.attributes,u),this.emit("nodeAttributesUpdated",{key:s.key,type:"merge",attributes:s.attributes,data:u}),this}}},{name:function(t){return"update".concat(t,"Attributes")},attacher:function(t,e,n){t.prototype[e]=function(t,r,i){var o=$(this,e,n,t,r,i),s=o[0],a=o[1];if("function"!=typeof a)throw new V("Graph.".concat(e,": provided updater is not a function."));return s.attributes=a(s.attributes),this.emit("nodeAttributesUpdated",{key:s.key,type:"update",attributes:s.attributes}),this}}}],X=[{name:function(t){return"get".concat(t,"Attribute")},attacher:function(t,e,n){t.prototype[e]=function(t,r){var i;if("mixed"!==this.type&&"mixed"!==n&&n!==this.type)throw new z("Graph.".concat(e,": cannot find this type of edges in your ").concat(this.type," graph."));if(arguments.length>2){if(this.multi)throw new z("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,s=""+r;if(r=arguments[2],!(i=u(this,o,s,n)))throw new W("Graph.".concat(e,': could not find an edge for the given path ("').concat(o,'" - "').concat(s,'").'))}else{if("mixed"!==n)throw new z("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]}}},{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 z("Graph.".concat(e,": cannot find this type of edges in your ").concat(this.type," graph."));if(arguments.length>1){if(this.multi)throw new z("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,o=""+arguments[1];if(!(r=u(this,i,o,n)))throw new W("Graph.".concat(e,': could not find an edge for the given path ("').concat(i,'" - "').concat(o,'").'))}else{if("mixed"!==n)throw new z("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 i;if("mixed"!==this.type&&"mixed"!==n&&n!==this.type)throw new z("Graph.".concat(e,": cannot find this type of edges in your ").concat(this.type," graph."));if(arguments.length>2){if(this.multi)throw new z("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,s=""+r;if(r=arguments[2],!(i=u(this,o,s,n)))throw new W("Graph.".concat(e,': could not find an edge for the given path ("').concat(o,'" - "').concat(s,'").'))}else{if("mixed"!==n)throw new z("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.hasOwnProperty(r)}}},{name:function(t){return"set".concat(t,"Attribute")},attacher:function(t,e,n){t.prototype[e]=function(t,r,i){var o;if("mixed"!==this.type&&"mixed"!==n&&n!==this.type)throw new z("Graph.".concat(e,": cannot find this type of edges in your ").concat(this.type," graph."));if(arguments.length>3){if(this.multi)throw new z("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 s=""+t,a=""+r;if(r=arguments[2],i=arguments[3],!(o=u(this,s,a,n)))throw new W("Graph.".concat(e,': could not find an edge for the given path ("').concat(s,'" - "').concat(a,'").'))}else{if("mixed"!==n)throw new z("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]=i,this.emit("edgeAttributesUpdated",{key:o.key,type:"set",attributes:o.attributes,name:r}),this}}},{name:function(t){return"update".concat(t,"Attribute")},attacher:function(t,e,n){t.prototype[e]=function(t,r,i){var o;if("mixed"!==this.type&&"mixed"!==n&&n!==this.type)throw new z("Graph.".concat(e,": cannot find this type of edges in your ").concat(this.type," graph."));if(arguments.length>3){if(this.multi)throw new z("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 s=""+t,a=""+r;if(r=arguments[2],i=arguments[3],!(o=u(this,s,a,n)))throw new W("Graph.".concat(e,': could not find an edge for the given path ("').concat(s,'" - "').concat(a,'").'))}else{if("mixed"!==n)throw new z("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 i)throw new V("Graph.".concat(e,": updater should be a function."));return o.attributes[r]=i(o.attributes[r]),this.emit("edgeAttributesUpdated",{key:o.key,type:"set",attributes:o.attributes,name:r}),this}}},{name:function(t){return"remove".concat(t,"Attribute")},attacher:function(t,e,n){t.prototype[e]=function(t,r){var i;if("mixed"!==this.type&&"mixed"!==n&&n!==this.type)throw new z("Graph.".concat(e,": cannot find this type of edges in your ").concat(this.type," graph."));if(arguments.length>2){if(this.multi)throw new z("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,s=""+r;if(r=arguments[2],!(i=u(this,o,s,n)))throw new W("Graph.".concat(e,': could not find an edge for the given path ("').concat(o,'" - "').concat(s,'").'))}else{if("mixed"!==n)throw new z("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 delete i.attributes[r],this.emit("edgeAttributesUpdated",{key:i.key,type:"remove",attributes:i.attributes,name:r}),this}}},{name:function(t){return"replace".concat(t,"Attributes")},attacher:function(t,e,n){t.prototype[e]=function(t,r){var i;if("mixed"!==this.type&&"mixed"!==n&&n!==this.type)throw new z("Graph.".concat(e,": cannot find this type of edges in your ").concat(this.type," graph."));if(arguments.length>2){if(this.multi)throw new z("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,s=""+r;if(r=arguments[2],!(i=u(this,o,s,n)))throw new W("Graph.".concat(e,': could not find an edge for the given path ("').concat(o,'" - "').concat(s,'").'))}else{if("mixed"!==n)throw new z("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(!c(r))throw new V("Graph.".concat(e,": provided attributes are not a plain object."));return i.attributes=r,this.emit("edgeAttributesUpdated",{key:i.key,type:"replace",attributes:i.attributes}),this}}},{name:function(t){return"merge".concat(t,"Attributes")},attacher:function(t,e,n){t.prototype[e]=function(t,r){var i;if("mixed"!==this.type&&"mixed"!==n&&n!==this.type)throw new z("Graph.".concat(e,": cannot find this type of edges in your ").concat(this.type," graph."));if(arguments.length>2){if(this.multi)throw new z("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,s=""+r;if(r=arguments[2],!(i=u(this,o,s,n)))throw new W("Graph.".concat(e,': could not find an edge for the given path ("').concat(o,'" - "').concat(s,'").'))}else{if("mixed"!==n)throw new z("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(!c(r))throw new V("Graph.".concat(e,": provided attributes are not a plain object."));return a(i.attributes,r),this.emit("edgeAttributesUpdated",{key:i.key,type:"merge",attributes:i.attributes,data:r}),this}}},{name:function(t){return"update".concat(t,"Attributes")},attacher:function(t,e,n){t.prototype[e]=function(t,r){var i;if("mixed"!==this.type&&"mixed"!==n&&n!==this.type)throw new z("Graph.".concat(e,": cannot find this type of edges in your ").concat(this.type," graph."));if(arguments.length>2){if(this.multi)throw new z("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,s=""+r;if(r=arguments[2],!(i=u(this,o,s,n)))throw new W("Graph.".concat(e,': could not find an edge for the given path ("').concat(o,'" - "').concat(s,'").'))}else{if("mixed"!==n)throw new z("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 r)throw new V("Graph.".concat(e,": provided updater is not a function."));return i.attributes=r(i.attributes),this.emit("edgeAttributesUpdated",{key:i.key,type:"update",attributes:i.attributes}),this}}}],Q=T,Z=U,J=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=Z(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 i=!1;for(var o in e)if(o!==r){var s=e[o];if(i=n(s.key,s.attributes,s.source.key,s.target.key,s.source.attributes,s.target.attributes,s.undirected),t&&i)return s.key}}function nt(t,e,n,r){var i,o,s,a=!1;for(var u in e)if(u!==r){i=e[u];do{if(o=i.source,s=i.target,a=n(i.key,i.attributes,o.key,s.key,o.attributes,s.attributes,i.undirected),t&&a)return i.key;i=i.next}while(void 0!==i)}}function rt(t,e){var n,r=Object.keys(t),i=r.length,o=0;return new T((function(){do{if(n)n=n.next;else{if(o>=i)return{done:!0};var s=r[o++];if(s===e){n=void 0;continue}n=t[s]}}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 it(t,e,n,r){var i=e[n];if(i){var o=i.source,s=i.target;return r(i.key,i.attributes,o.key,s.key,o.attributes,s.attributes,i.undirected)&&t?i.key:void 0}}function ot(t,e,n,r){var i=e[n];if(i){var o=!1;do{if(o=r(i.key,i.attributes,i.source.key,i.target.key,i.source.attributes,i.target.attributes,i.undirected),t&&o)return i.key;i=i.next}while(void 0!==i)}}function st(t,e){var n=t[e];return void 0!==n.next?new T((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}})):T.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 at(t,e,n,r){if(0!==e.size)for(var i,o,s="mixed"!==n&&n!==e.type,a="undirected"===n,u=!1,c=e._edges.values();!0!==(i=c.next()).done;)if(o=i.value,!s||o.undirected===a){var l=o,h=l.key,d=l.attributes,f=l.source,p=l.target;if(u=r(h,d,f.key,p.key,f.attributes,p.attributes,o.undirected),t&&u)return h}}function ut(t,e,n,r,i,o){var s,a=e?nt:et;if("undirected"!==n){if("out"!==r&&(s=a(t,i.in,o),t&&s))return s;if("in"!==r&&(s=a(t,i.out,o,r?void 0:i.key),t&&s))return s}if("directed"!==n&&(s=a(t,i.undirected,o),t&&s))return s}function ct(t,e,n,r,i,o,s){var a,u=n?ot:it;if("undirected"!==e){if(void 0!==i.in&&"out"!==r&&(a=u(t,i.in,o,s),t&&a))return a;if(void 0!==i.out&&"in"!==r&&(r||i.key!==o)&&(a=u(t,i.out,o,s),t&&a))return a}if("directed"!==e&&void 0!==i.undirected&&(a=u(t,i.undirected,o,s),t&&a))return a}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 ht(){this.A=null,this.B=null}function dt(t,e,n,r,i){for(var o in r){var s=r[o],a=s.source,u=s.target,c=a===n?u:a;if(!e||!e.has(c.key)){var l=i(c.key,c.attributes);if(t&&l)return c.key}}}function ft(t,e,n,r,i){if("mixed"!==e){if("undirected"===e)return dt(t,null,r,r.undirected,i);if("string"==typeof n)return dt(t,null,r,r[n],i)}var o,s=new ht;if("undirected"!==e){if("out"!==n){if(o=dt(t,null,r,r.in,i),t&&o)return o;s.wrap(r.in)}if("in"!==n){if(o=dt(t,s,r,r.out,i),t&&o)return o;s.wrap(r.out)}}if("directed"!==e&&(o=dt(t,s,r,r.undirected,i),t&&o))return o}function pt(t,e,n){var r=Object.keys(n),i=r.length,o=0;return new T((function(){var s=null;do{if(o>=i)return t&&t.wrap(n),{done:!0};var a=n[r[o++]],u=a.source,c=a.target;s=u===e?c:u,t&&t.has(s.key)&&(s=null)}while(null===s);return{done:!1,value:{neighbor:s.key,attributes:s.attributes}}}))}function mt(t,e,n,r,i){for(var o,s,a,u,c,l,h,d=r._nodes.values(),f=r.type;!0!==(o=d.next()).done;){var p=!1;if(s=o.value,"undirected"!==f)for(a in u=s.out){c=u[a];do{if(l=c.target,p=!0,h=i(s.key,l.key,s.attributes,l.attributes,c.key,c.attributes,c.undirected),t&&h)return c;c=c.next}while(c)}if("directed"!==f)for(a in u=s.undirected)if(!(e&&s.key>a)){c=u[a];do{if((l=c.target).key!==a&&(l=c.source),p=!0,h=i(s.key,l.key,s.attributes,l.attributes,c.key,c.attributes,c.undirected),t&&h)return c;c=c.next}while(c)}if(n&&!p&&(h=i(s.key,null,s.attributes,null,null,null,null),t&&h))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.")}ht.prototype.wrap=function(t){null===this.A?this.A=t:null===this.B&&(this.B=t)},ht.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 _t(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 Ct(t,e,n,r,i,o,s,a){if(!r&&"undirected"===t.type)throw new z("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 z("Graph.".concat(e,": you cannot add an undirected edge to a directed graph. Use the #.addEdge or #.addDirectedEdge instead."));if(a&&!c(a))throw new V("Graph.".concat(e,': invalid attributes. Expecting an object but got "').concat(a,'"'));if(o=""+o,s=""+s,a=a||{},!t.allowSelfLoops&&o===s)throw new z("Graph.".concat(e,': source & target are the same ("').concat(o,"\"), thus creating a loop explicitly forbidden by this graph 'allowSelfLoops' option set to false."));var u=t._nodes.get(o),l=t._nodes.get(s);if(!u)throw new W("Graph.".concat(e,': source node "').concat(o,'" not found.'));if(!l)throw new W("Graph.".concat(e,': target node "').concat(s,'" not found.'));var h={key:null,undirected:r,source:o,target:s,attributes:a};if(n)i=t._edgeKeyGenerator();else if(i=""+i,t._edges.has(i))throw new z("Graph.".concat(e,': the "').concat(i,'" edge already exists in the graph.'));if(!t.multi&&(r?void 0!==u.undirected[s]:void 0!==u.out[s]))throw new z("Graph.".concat(e,': an edge linking "').concat(o,'" to "').concat(s,"\" 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 d=new H(r,i,u,l,a);t._edges.set(i,d);var f=o===s;return r?(u.undirectedDegree++,l.undirectedDegree++,f&&(u.undirectedLoops++,t._undirectedSelfLoopCount++)):(u.outDegree++,l.inDegree++,f&&(u.directedLoops++,t._directedSelfLoopCount++)),t.multi?d.attachMulti():d.attach(),r?t._undirectedSize++:t._directedSize++,h.key=i,t.emit("edgeAdded",h),i}function St(t,e,n,r,i,o,s,u,l){if(!r&&"undirected"===t.type)throw new z("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 z("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 h;if(o=""+o,s=""+s,l&&(h=u,u=void 0),!t.allowSelfLoops&&o===s)throw new z("Graph.".concat(e,': source & target are the same ("').concat(o,"\"), thus creating a loop explicitly forbidden by this graph 'allowSelfLoops' option set to false."));var d,f,p=t._nodes.get(o),m=t._nodes.get(s);if(!n&&(d=t._edges.get(i))){if(!(d.source.key===o&&d.target.key===s||r&&d.source.key===s&&d.target.key===o))throw new z("Graph.".concat(e,': inconsistency detected when attempting to merge the "').concat(i,'" edge with "').concat(o,'" source & "').concat(s,'" target vs. ("').concat(d.source.key,'", "').concat(d.target.key,'").'));f=d}if(f||t.multi||!p||(f=r?p.undirected[s]:p.out[s]),f){var g=[f.key,!1,!1,!1];if(l?!h:!u)return g;if(l){var y=f.attributes;f.attributes=h(y),t.emit("edgeAttributesUpdated",{type:"replace",key:f.key,attributes:f.attributes})}else a(f.attributes,u),t.emit("edgeAttributesUpdated",{type:"merge",key:f.key,attributes:f.attributes,data:u});return g}u=u||{},l&&h&&(u=h(u));var v={key:null,undirected:r,source:o,target:s,attributes:u};if(n)i=t._edgeKeyGenerator();else if(i=""+i,t._edges.has(i))throw new z("Graph.".concat(e,': the "').concat(i,'" edge already exists in the graph.'));var w=!1,b=!1;p||(p=_t(t,o,{}),w=!0,o===s&&(m=p,b=!0)),m||(m=_t(t,s,{}),b=!0),d=new H(r,i,p,m,u),t._edges.set(i,d);var E=o===s;return r?(p.undirectedDegree++,m.undirectedDegree++,E&&(p.undirectedLoops++,t._undirectedSelfLoopCount++)):(p.outDegree++,m.inDegree++,E&&(p.directedLoops++,t._directedSelfLoopCount++)),t.multi?d.attachMulti():d.attach(),r?t._undirectedSize++:t._directedSize++,v.key=i,t.emit("edgeAdded",v),[i,!0,w,b]}function It(t,e){t._edges.delete(e.key);var n=e.source,r=e.target,i=e.attributes,o=e.undirected,s=n===r;o?(n.undirectedDegree--,r.undirectedDegree--,s&&(n.undirectedLoops--,t._undirectedSelfLoopCount--)):(n.outDegree--,r.inDegree--,s&&(n.directedLoops--,t._directedSelfLoopCount--)),t.multi?e.detachMulti():e.detach(),o?t._undirectedSize--:t._directedSize--,t.emit("edgeDropped",{key:e.key,attributes:i,source:n.key,target:r.key,undirected:o})}var Mt=function(n){function r(t){var e;if(e=n.call(this)||this,"boolean"!=typeof(t=a({},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?j:"directed"===t.type?Y:q;h(s(e),"NodeDataClass",r);var i="geid_"+wt()+"_",o=0;return h(s(e),"_attributes",{}),h(s(e),"_nodes",new Map),h(s(e),"_edges",new Map),h(s(e),"_directedSize",0),h(s(e),"_undirectedSize",0),h(s(e),"_directedSelfLoopCount",0),h(s(e),"_undirectedSelfLoopCount",0),h(s(e),"_edgeKeyGenerator",(function(){var t;do{t=i+o++}while(e._edges.has(t));return t})),h(s(e),"_options",t),Et.forEach((function(t){return h(s(e),t,e[t])})),d(s(e),"order",(function(){return e._nodes.size})),d(s(e),"size",(function(){return e._edges.size})),d(s(e),"directedSize",(function(){return e._directedSize})),d(s(e),"undirectedSize",(function(){return e._undirectedSize})),d(s(e),"selfLoopCount",(function(){return e._directedSelfLoopCount+e._undirectedSelfLoopCount})),d(s(e),"directedSelfLoopCount",(function(){return e._directedSelfLoopCount})),d(s(e),"undirectedSelfLoopCount",(function(){return e._undirectedSelfLoopCount})),d(s(e),"multi",e._options.multi),d(s(e),"type",e._options.type),d(s(e),"allowSelfLoops",e._options.allowSelfLoops),d(s(e),"implementation",(function(){return"graphology"})),e}e(r,n);var i=r.prototype;return i._resetInstanceCounters=function(){this._directedSize=0,this._undirectedSize=0,this._directedSelfLoopCount=0,this._undirectedSelfLoopCount=0},i.hasNode=function(t){return this._nodes.has(""+t)},i.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 i=this._nodes.get(t);return!!i&&i.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."))},i.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 i=this._nodes.get(t);return!!i&&i.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."))},i.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."))},i.directedEdge=function(t,e){if("undirected"!==this.type){if(t=""+t,e=""+e,this.multi)throw new z("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}},i.undirectedEdge=function(t,e){if("directed"!==this.type){if(t=""+t,e=""+e,this.multi)throw new z("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}},i.edge=function(t,e){if(this.multi)throw new z("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},i.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)},i.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},i.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},i.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},i.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},i.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},i.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},i.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},i.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},i.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},i.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},i.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},i.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},i.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},i.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},i.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},i.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},i.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},i.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},i.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},i.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},i.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},i.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},i.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]},i.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,i=n.target.key;if(t===r)return i;if(t===i)return r;throw new W('Graph.opposite: the "'.concat(t,'" node is not attached to the "').concat(e,'" edge (').concat(r,", ").concat(i,")."))},i.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},i.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},i.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},i.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},i.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 z('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},i.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&&(a(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])},i.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 i=e?e({}):{};return n=new this.NodeDataClass(t,i),this._nodes.set(t,n),this.emit("nodeAdded",{key:t,attributes:i}),[t,!0]},i.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{It(this,e),e=e.next}while(e)}for(var i in n.in){e=n.in[i];do{It(this,e),e=e.next}while(e)}}if("directed"!==this.type)for(var o in n.undirected){e=n.undirected[o];do{It(this,e),e=e.next}while(e)}this._nodes.delete(t),this.emit("nodeDropped",{key:t,attributes:n.attributes})},i.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 It(this,e),this},i.dropDirectedEdge=function(t,e){if(arguments.length<2)throw new z("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 z("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 It(this,n),this},i.dropUndirectedEdge=function(t,e){if(arguments.length<2)throw new z("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 z("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 It(this,n),this},i.clear=function(){this._edges.clear(),this._nodes.clear(),this._resetInstanceCounters(),this.emit("cleared")},i.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")},i.getAttribute=function(t){return this._attributes[t]},i.getAttributes=function(){return this._attributes},i.hasAttribute=function(t){return this._attributes.hasOwnProperty(t)},i.setAttribute=function(t,e){return this._attributes[t]=e,this.emit("attributesUpdated",{type:"set",attributes:this._attributes,name:t}),this},i.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},i.removeAttribute=function(t){return delete this._attributes[t],this.emit("attributesUpdated",{type:"remove",attributes:this._attributes,name:t}),this},i.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},i.mergeAttributes=function(t){if(!c(t))throw new V("Graph.mergeAttributes: provided attributes are not a plain object.");return a(this._attributes,t),this.emit("attributesUpdated",{type:"merge",attributes:this._attributes,data:t}),this},i.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},i.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,i=this._nodes.values();!0!==(n=i.next()).done;)(r=n.value).attributes=t(r.key,r.attributes);this.emit("eachNodeAttributesUpdated",{hints:e||null})},i.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,i,o,s=this._edges.values();!0!==(n=s.next()).done;)i=(r=n.value).source,o=r.target,r.attributes=t(r.key,r.attributes,i.key,o.key,i.attributes,o.attributes,r.undirected);this.emit("eachEdgeAttributesUpdated",{hints:e||null})},i.forEachAdjacencyEntry=function(t){if("function"!=typeof t)throw new V("Graph.forEachAdjacencyEntry: expecting a callback.");mt(!1,!1,!1,this,t)},i.forEachAdjacencyEntryWithOrphans=function(t){if("function"!=typeof t)throw new V("Graph.forEachAdjacencyEntryWithOrphans: expecting a callback.");mt(!1,!1,!0,this,t)},i.forEachAssymetricAdjacencyEntry=function(t){if("function"!=typeof t)throw new V("Graph.forEachAssymetricAdjacencyEntry: expecting a callback.");mt(!1,!0,!1,this,t)},i.forEachAssymetricAdjacencyEntryWithOrphans=function(t){if("function"!=typeof t)throw new V("Graph.forEachAssymetricAdjacencyEntryWithOrphans: expecting a callback.");mt(!1,!0,!0,this,t)},i.nodes=function(){return"function"==typeof Array.from?Array.from(this._nodes.keys()):G(this._nodes.keys(),this._nodes.size)},i.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)},i.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},i.mapNodes=function(t){if("function"!=typeof t)throw new V("Graph.mapNode: expecting a callback.");for(var e,n,r=this._nodes.values(),i=new Array(this.order),o=0;!0!==(e=r.next()).done;)n=e.value,i[o++]=t(n.key,n.attributes);return i},i.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},i.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},i.filterNodes=function(t){if("function"!=typeof t)throw new V("Graph.filterNodes: expecting a callback.");for(var e,n,r=this._nodes.values(),i=[];!0!==(e=r.next()).done;)t((n=e.value).key,n.attributes)&&i.push(n.key);return i},i.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,i=e,o=this._nodes.values();!0!==(n=o.next()).done;)i=t(i,(r=n.value).key,r.attributes);return i},i.nodeEntries=function(){var t=this._nodes.values();return new T((function(){var e=t.next();if(e.done)return e;var n=e.value;return{value:{node:n.key,attributes:n.attributes},done:!1}}))},i.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=a({},e.attributes)),n}(r,t)}));var r=new Array(this._edges.size);return n=0,this._edges.forEach((function(e,i){r[n++]=function(t,e,n){var r={key:e,source:n.source.key,target:n.target.key};return l(n.attributes)||(r.attributes=a({},n.attributes)),"mixed"===t&&n.undirected&&(r.undirected=!0),r}(t.type,i,e)})),{options:{type:this.type,multi:this.multi,allowSelfLoops:this.allowSelfLoops},attributes:this.getAttributes(),nodes:e,edges:r}},i.import=function(t){var e,n,i,o,s,a=this,u=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(t instanceof r)return t.forEachNode((function(t,e){u?a.mergeNode(t,e):a.addNode(t,e)})),t.forEachEdge((function(t,e,n,r,i,o,s){u?s?a.mergeUndirectedEdgeWithKey(t,n,r,e):a.mergeDirectedEdgeWithKey(t,n,r,e):s?a.addUndirectedEdgeWithKey(t,n,r,e):a.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(i=t.nodes,!Array.isArray(i))throw new V("Graph.import: invalid nodes. Expecting an array.");for(e=0,n=i.length;e<n;e++){gt(o=i[e]);var l=o,h=l.key,d=l.attributes;u?this.mergeNode(h,d):this.addNode(h,d)}}if(t.edges){var f=!1;if("undirected"===this.type&&(f=!0),i=t.edges,!Array.isArray(i))throw new V("Graph.import: invalid edges. Expecting an array.");for(e=0,n=i.length;e<n;e++){yt(s=i[e]);var p=s,m=p.source,g=p.target,y=p.attributes,v=p.undirected,w=void 0===v?f:v;"key"in s?(u?w?this.mergeUndirectedEdgeWithKey:this.mergeDirectedEdgeWithKey:w?this.addUndirectedEdgeWithKey:this.addDirectedEdgeWithKey).call(this,s.key,m,g,y):(u?w?this.mergeUndirectedEdge:this.mergeDirectedEdge:w?this.addUndirectedEdge:this.addDirectedEdge).call(this,m,g,y)}}return this},i.nullCopy=function(t){var e=new r(a({},this._options,t));return e.replaceAttributes(a({},this.getAttributes())),e},i.emptyCopy=function(t){var e=this.nullCopy(t);return this._nodes.forEach((function(t,n){var r=a({},t.attributes);t=new e.NodeDataClass(n,r),e._nodes.set(n,t)})),e},i.copy=function(t){if("string"==typeof(t=t||{}).type&&t.type!==this.type&&"mixed"!==t.type)throw new z('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 z("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 z("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),i=this._edges.values();!0!==(e=i.next()).done;)Ct(r,"copy",!1,(n=e.value).undirected,n.key,n.source.key,n.target.key,a({},n.attributes));return r},i.toJSON=function(){return this.export()},i.toString=function(){return"[object Graph]"},i.inspect=function(){var e=this,n={};this._nodes.forEach((function(t,e){n[e]=t.attributes}));var r={},i={};this._edges.forEach((function(t,n){var o,s=t.undirected?"--":"->",a="",u=t.source.key,c=t.target.key;t.undirected&&u>c&&(o=u,u=c,c=o);var l="(".concat(u,")").concat(s,"(").concat(c,")");n.startsWith("geid_")?e.multi&&(void 0===i[l]?i[l]=0:i[l]++,a+="".concat(i[l],". ")):a+="[".concat(n,"]: "),r[a+=l]=t.attributes}));var o={};for(var s in this)this.hasOwnProperty(s)&&!Et.has(s)&&"function"!=typeof this[s]&&"symbol"!==t(s)&&(o[s]=this[s]);return o.attributes=this._attributes,o.nodes=n,o.edges=r,h(o,"constructor",this.constructor),o},r}(m.exports.EventEmitter);"undefined"!=typeof Symbol&&(Mt.prototype[Symbol.for("nodejs.util.inspect.custom")]=Mt.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?Ct:St;t.generateKey?Mt.prototype[n]=function(i,o,s){return r(this,n,!0,"undirected"===(t.type||this.type),null,i,o,s,"update"===e)}:Mt.prototype[n]=function(i,o,s,a){return r(this,n,!1,"undirected"===(t.type||this.type),i,o,s,a,"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)}))}(Mt),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")}))}(Mt),function(t){tt.forEach((function(e){!function(t,e){var n=e.name,r=e.type,i=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,i="undirected"===e?t.undirectedSize:t.directedSize,o=new Array(i),s="undirected"===e,a=t._edges.values(),u=0;!0!==(n=a.next()).done;)(r=n.value).undirected===s&&(o[u++]=r.key);return o}(this,r);if(1===arguments.length){t=""+t;var o=this._nodes.get(t);if(void 0===o)throw new W("Graph.".concat(n,': could not find the "').concat(t,'" node in the graph.'));return function(t,e,n,r){var i=[];return ut(!1,t,e,n,r,(function(t){i.push(t)})),i}(this.multi,"mixed"===r?this.type:r,i,o)}if(2===arguments.length){t=""+t,e=""+e;var s=this._nodes.get(t);if(!s)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,i){var o=[];return ct(!1,t,e,n,r,i,(function(t){o.push(t)})),o}(r,this.multi,i,s,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,i=e.direction,o="forEach"+n[0].toUpperCase()+n.slice(1,-1);t.prototype[o]=function(t,e,n){if("mixed"===r||"mixed"===this.type||r===this.type){if(1===arguments.length)return at(!1,this,r,n=t);if(2===arguments.length){t=""+t,n=e;var s=this._nodes.get(t);if(void 0===s)throw new W("Graph.".concat(o,': could not find the "').concat(t,'" node in the graph.'));return ut(!1,this.multi,"mixed"===r?this.type:r,i,s,n)}if(3===arguments.length){t=""+t,e=""+e;var a=this._nodes.get(t);if(!a)throw new W("Graph.".concat(o,': could not find the "').concat(t,'" source node in the graph.'));if(!this._nodes.has(e))throw new W("Graph.".concat(o,': could not find the "').concat(e,'" target node in the graph.'));return ct(!1,r,this.multi,i,a,e,n)}throw new V("Graph.".concat(o,": too many arguments (expecting 1, 2 or 3 and got ").concat(arguments.length,")."))}};var s="map"+n[0].toUpperCase()+n.slice(1);t.prototype[s]=function(){var t,e=Array.prototype.slice.call(arguments),n=e.pop();if(0===e.length){var i=0;"directed"!==r&&(i+=this.undirectedSize),"undirected"!==r&&(i+=this.directedSize),t=new Array(i);var s=0;e.push((function(e,r,i,o,a,u,c){t[s++]=n(e,r,i,o,a,u,c)}))}else t=[],e.push((function(e,r,i,o,s,a,u){t.push(n(e,r,i,o,s,a,u))}));return this[o].apply(this,e),t};var a="filter"+n[0].toUpperCase()+n.slice(1);t.prototype[a]=function(){var t=Array.prototype.slice.call(arguments),e=t.pop(),n=[];return t.push((function(t,r,i,o,s,a,u){e(t,r,i,o,s,a,u)&&n.push(t)})),this[o].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,i,o,s,a,u){r=t(r,e,n,i,o,s,a,u)})),this[o].apply(this,n),r}}(t,e),function(t,e){var n=e.name,r=e.type,i=e.direction,o="find"+n[0].toUpperCase()+n.slice(1,-1);t.prototype[o]=function(t,e,n){if("mixed"!==r&&"mixed"!==this.type&&r!==this.type)return!1;if(1===arguments.length)return at(!0,this,r,n=t);if(2===arguments.length){t=""+t,n=e;var s=this._nodes.get(t);if(void 0===s)throw new W("Graph.".concat(o,': could not find the "').concat(t,'" node in the graph.'));return ut(!0,this.multi,"mixed"===r?this.type:r,i,s,n)}if(3===arguments.length){t=""+t,e=""+e;var a=this._nodes.get(t);if(!a)throw new W("Graph.".concat(o,': could not find the "').concat(t,'" source node in the graph.'));if(!this._nodes.has(e))throw new W("Graph.".concat(o,': could not find the "').concat(e,'" target node in the graph.'));return ct(!0,r,this.multi,i,a,e,n)}throw new V("Graph.".concat(o,": too many arguments (expecting 1, 2 or 3 and got ").concat(arguments.length,")."))};var s="some"+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,i,o,s,a){return e(t,n,r,i,o,s,a)})),!!this[o].apply(this,t)};var a="every"+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,i,o,s,a){return!e(t,n,r,i,o,s,a)})),!this[o].apply(this,t)}}(t,e),function(t,e){var n=e.name,r=e.type,i=e.direction,o=n.slice(0,-1)+"Entries";t.prototype[o]=function(t,e){if("mixed"!==r&&"mixed"!==this.type&&r!==this.type)return T.empty();if(!arguments.length)return function(t,e){if(0===t.size)return T.empty();var n="mixed"!==e&&e!==t.type,r="undirected"===e,i=t._edges.values();return new T((function(){for(var t,e;;){if((t=i.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(o,': could not find the "').concat(t,'" node in the graph.'));return function(t,e,n){var r=T.empty();return"undirected"!==t&&("out"!==e&&void 0!==n.in&&(r=J(r,rt(n.in))),"in"!==e&&void 0!==n.out&&(r=J(r,rt(n.out,e?void 0:n.key)))),"directed"!==t&&void 0!==n.undirected&&(r=J(r,rt(n.undirected))),r}(r,i,n)}if(2===arguments.length){t=""+t,e=""+e;var s=this._nodes.get(t);if(!s)throw new W("Graph.".concat(o,': could not find the "').concat(t,'" source node in the graph.'));if(!this._nodes.has(e))throw new W("Graph.".concat(o,': could not find the "').concat(e,'" target node in the graph.'));return function(t,e,n,r){var i=T.empty();return"undirected"!==t&&(void 0!==n.in&&"out"!==e&&r in n.in&&(i=J(i,st(n.in,r))),void 0!==n.out&&"in"!==e&&r in n.out&&(e||n.key!==r)&&(i=J(i,st(n.out,r)))),"directed"!==t&&void 0!==n.undirected&&r in n.undirected&&(i=J(i,st(n.undirected,r))),i}(r,i,s,e)}throw new V("Graph.".concat(o,": too many arguments (expecting 0, 1 or 2 and got ").concat(arguments.length,")."))}}(t,e)}))}(Mt),function(t){lt.forEach((function(e){(function(t,e){var n=e.name,r=e.type,i=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,i,e)}})(t,e),function(t,e){var n=e.name,r=e.type,i=e.direction,o="forEach"+n[0].toUpperCase()+n.slice(1,-1);t.prototype[o]=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(o,': could not find the "').concat(t,'" node in the graph.'));ft(!1,"mixed"===r?this.type:r,i,n,e)}};var s="map"+n[0].toUpperCase()+n.slice(1);t.prototype[s]=function(t,e){var n=[];return this[o](t,(function(t,r){n.push(e(t,r))})),n};var a="filter"+n[0].toUpperCase()+n.slice(1);t.prototype[a]=function(t,e){var n=[];return this[o](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[o](t,(function(t,n){r=e(r,t,n)})),r}}(t,e),function(t,e){var n=e.name,r=e.type,i=e.direction,o=n[0].toUpperCase()+n.slice(1,-1),s="find"+o;t.prototype[s]=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(s,': could not find the "').concat(t,'" node in the graph.'));return ft(!0,"mixed"===r?this.type:r,i,n,e)}};var a="some"+o;t.prototype[a]=function(t,e){return!!this[s](t,e)};var u="every"+o;t.prototype[u]=function(t,e){return!this[s](t,(function(t,n){return!e(t,n)}))}}(t,e),function(t,e){var n=e.name,r=e.type,i=e.direction,o=n.slice(0,-1)+"Entries";t.prototype[o]=function(t){if("mixed"!==r&&"mixed"!==this.type&&r!==this.type)return T.empty();t=""+t;var e=this._nodes.get(t);if(void 0===e)throw new W("Graph.".concat(o,': 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=T.empty(),i=new ht;return"undirected"!==t&&("out"!==e&&(r=J(r,pt(i,n,n.in))),"in"!==e&&(r=J(r,pt(i,n,n.out)))),"directed"!==t&&(r=J(r,pt(i,n,n.undirected))),r}("mixed"===r?this.type:r,i,e)}}(t,e)}))}(Mt);var Nt=function(t){function n(e){var n=a({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}(Mt),xt=function(t){function n(e){var n=a({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}(Mt),Lt=function(t){function n(e){var n=a({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}(Mt),Tt=function(t){function n(e){var n=a({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}(Mt),Ot=function(t){function n(e){var n=a({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}(Mt);function Pt(t){t.from=function(e,n){var r=a({},e.options,n),i=new t(r);return i.import(e),i}}return Pt(Mt),Pt(Nt),Pt(xt),Pt(Lt),Pt(Tt),Pt(Ot),Mt.Graph=Mt,Mt.DirectedGraph=Nt,Mt.UndirectedGraph=xt,Mt.MultiGraph=Lt,Mt.MultiDirectedGraph=Tt,Mt.MultiUndirectedGraph=Ot,Mt.InvalidArgumentsGraphError=V,Mt.NotFoundGraphError=W,Mt.UsageGraphError=z,Mt}()},6572:function(t){var e;t.exports=(e=function(t,e){var n=Array.prototype.concat,r=Array.prototype.slice,i=Object.prototype.toString;function o(e,n){var r=e>n?e:n;return t.pow(10,17-~~(t.log(r>0?r:-r)*t.LOG10E))}var s=Array.isArray||function(t){return"[object Array]"===i.call(t)};function a(t){return"[object Function]"===i.call(t)}function u(t){return"number"==typeof t&&t-t==0}function c(){return new c._init(arguments)}function l(){return 0}function h(){return 1}function d(t,e){return t===e?1:0}c.fn=c.prototype,c._init=function(t){if(s(t[0]))if(s(t[0][0])){a(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]=a(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:o,isArray:s,isFunction:a,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 s(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(s(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(i){n[i][r]=t[i][e]}))})),n}for(var r=new Array(t.length),i=0;i<t.length;i++)r[i]=[t[i][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,i,o,a=[];for(s(t[0])||(t=[t]),n=t.length,r=t[0].length,o=0;o<r;o++){for(e=new Array(n),i=0;i<n;i++)e[i]=t[i][o];a.push(e)}return 1===a.length?a[0]:a},c.map=function(t,e,n){var r,i,o,a,u;for(s(t[0])||(t=[t]),i=t.length,o=t[0].length,a=n?t:new Array(i),r=0;r<i;r++)for(a[r]||(a[r]=new Array(o)),u=0;u<o;u++)a[r][u]=e(t[r][u],r,u);return 1===a.length?a[0]:a},c.cumreduce=function(t,e,n){var r,i,o,a,u;for(s(t[0])||(t=[t]),i=t.length,o=t[0].length,a=n?t:new Array(i),r=0;r<i;r++)for(a[r]||(a[r]=new Array(o)),o>0&&(a[r][0]=t[r][0]),u=1;u<o;u++)a[r][u]=e(a[r][u-1],t[r][u]);return 1===a.length?a[0]:a},c.alter=function(t,e){return c.map(t,e,!0)},c.create=function(t,e,n){var r,i,o=new Array(t);for(a(e)&&(n=e,e=t),r=0;r<t;r++)for(o[r]=new Array(e),i=0;i<e;i++)o[r][i]=n(r,i);return o},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,h)},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,d)},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){a(r)||(r=!1);var i,s=[],u=o(t,e),c=(e*u-t*u)/((n-1)*u),l=t;for(i=0;l<=e&&i<n;l=(t*u+c*u*++i)/u)s.push(r?r(l,i):l);return s},c.arange=function(t,n,r){var i,o=[];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(i=t;i<n;i+=r)o.push(i);else for(i=t;i>n;i+=r)o.push(i);return o},c.slice=function(){function t(t,n,r,i){var o,s=[],a=t.length;if(n===e&&r===e&&i===e)return c.copy(t);if(i=i||1,(n=(n=n||0)>=0?n:a+n)===(r=(r=r||t.length)>=0?r:a+r)||0===i)return[];if(n<r&&i<0)return[];if(n>r&&i>0)return[];if(i>0)for(o=n;o<r;o+=i)s.push(t[o]);else for(o=n;o>r;o+=i)s.push(t[o]);return s}return function(e,n){var r,i;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),(i=n.row||{}).start,i.end,i.step):(i=n.row||{},r=n.col||{},t(e,i.start,i.end,i.step).map((function(e){return t(e,r.start,r.end,r.step)})))}}(),c.sliceAssign=function(n,r,i){var o,s;if(u(r.row)){if(u(r.col))return n[r.row][r.col]=i;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,o=c.arange(r.col.start,t.min(n.length,r.col.end),r.col.step);var a=r.row;return o.forEach((function(t,e){n[a][t]=i[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,s=c.arange(r.row.start,t.min(n[0].length,r.row.end),r.row.step);var l=r.col;return s.forEach((function(t,e){n[t][l]=i[e]})),n}return i[0].length===e&&(i=[i]),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,s=c.arange(r.row.start,t.min(n.length,r.row.end),r.row.step),o=c.arange(r.col.start,t.min(n[0].length,r.col.end),r.col.step),s.forEach((function(t,e){o.forEach((function(r,o){n[t][r]=i[e][o]}))})),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),s(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 i(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),i=0,o=e.length;--o>=0;)i+=(n=e[o]-r)*n;return i},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),i=t.mean(r);return e.exp(i)},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=[],i={};for(e=0;e<t.length;e++)i[u=t[e]]?i[u]++:(i[u]=1,n.push(u));var o=n.sort(r),s={},a=1;for(e=0;e<o.length;e++){var u,c=i[u=o[e]],l=(a+(a+c-1))/2;s[u]=l,a+=c}return t.map((function(t){return s[t]}))},t.mode=function(t){var e,n=t.length,i=t.slice().sort(r),o=1,s=0,a=0,u=[];for(e=0;e<n;e++)i[e]===i[e+1]?o++:(o>s?(u=[i[e]],s=o,a=0):o===s&&(u.push(i[e]),a++),o=1);return 0===a?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,i=new Array(r),o=0;o<r;o++)i[o]=e[o]-n;return i},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),i=[],o=n.length-1;o>=0;o--)i.push(e.abs(n[o]-r));return t.mean(i)},t.meddev=function(n){for(var r=t.median(n),i=[],o=n.length-1;o>=0;o--)i.push(e.abs(n[o]-r));return t.median(i)},t.coeffvar=function(e){return t.stdev(e)/t.mean(e)},t.quartiles=function(t){var n=t.length,i=t.slice().sort(r);return[i[e.round(n/4)-1],i[e.round(n/2)-1],i[e.round(3*n/4)-1]]},t.quantiles=function(t,n,o,s){var a,u,c,l,h,d=t.slice().sort(r),f=[n.length],p=t.length;for(void 0===o&&(o=3/8),void 0===s&&(s=3/8),a=0;a<n.length;a++)c=p*(u=n[a])+(o+u*(1-o-s)),l=e.floor(i(c,1,p-1)),h=i(c-l,0,1),f[a]=(1-h)*d[l-1]+h*d[l];return f},t.percentile=function(t,e,n){var i=t.slice().sort(r),o=e*(i.length+(n?1:-1))+(n?0:1),s=parseInt(o),a=o-s;return s+1<i.length?i[s-1]+a*(i[s]-i[s-1]):i[s-1]},t.percentileOfScore=function(t,e,n){var r,i,o=0,s=t.length,a=!1;for("strict"===n&&(a=!0),i=0;i<s;i++)r=t[i],(a&&r<e||!a&&r<=e)&&o++;return o/s},t.histogram=function(n,r){r=r||4;var i,o=t.min(n),s=(t.max(n)-o)/r,a=n.length,u=[];for(i=0;i<r;i++)u[i]=0;for(i=0;i<a;i++)u[e.min(e.floor((n[i]-o)/s),r-1)]+=1;return u},t.covariance=function(e,n){var r,i=t.mean(e),o=t.mean(n),s=e.length,a=new Array(s);for(r=0;r<s;r++)a[r]=(e[r]-i)*(n[r]-o);return t.sum(a)/(s-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 i=t.mean(n),o=t.stdev(n),s=n.length,a=0,u=0;u<s;u++)a+=e.pow((n[u]-i)/o,r);return a/n.length},t.skewness=function(e){return t.stanMoment(e,3)},t.kurtosis=function(e){return t.stanMoment(e,4)-3};var o=t.prototype;!function(e){for(var r=0;r<e.length;r++)!function(e){o[e]=function(r,i){var s=[],a=0,u=this;if(n(r)&&(i=r,r=!1),i)return setTimeout((function(){i.call(u,o[e].call(u,r))})),this;if(this.length>1){for(u=!0===r?this:this.transpose();a<u.length;a++)s[a]=t[e](u[a]);return s}return t[e](this[0],r)}}(e[r])}("cumsum cumprod".split(" ")),function(e){for(var r=0;r<e.length;r++)!function(e){o[e]=function(r,i){var s=[],a=0,u=this;if(n(r)&&(i=r,r=!1),i)return setTimeout((function(){i.call(u,o[e].call(u,r))})),this;if(this.length>1){for("sumrow"!==e&&(u=!0===r?this:this.transpose());a<u.length;a++)s[a]=t[e](u[a]);return!0===r?t[e](t.utils.toVector(s)):s}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){o[e]=function(){var r,i=[],s=0,a=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(a,o[e].apply(a,c))})),this}r=void 0;var l=function(n){return t[e].apply(a,[n].concat(u))};if(this.length>1){for(a=a.transpose();s<a.length;s++)i[s]=l(a[s]);return i}return l(this[0])}}(e[r])}("quantiles percentileOfScore".split(" "))}(e,Math),function(t,e){t.gammaln=function(t){var n,r,i,o=0,s=[76.18009172947146,-86.50532032941678,24.01409824083091,-1.231739572450155,.001208650973866179,-5395239384953e-18],a=1.000000000190015;for(i=(r=n=t)+5.5,i-=(n+.5)*e.log(i);o<6;o++)a+=s[o]/++r;return e.log(2.5066282746310007*a/n)-i},t.loggam=function(t){var n,r,i,o,s,a,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),i=2*e.PI,s=c[9],a=8;a>=0;a--)s*=r,s+=c[a];if(o=s/n+.5*e.log(i)+(n-.5)*e.log(n)-n,t<=7)for(a=1;a<=u;a++)o-=e.log(n-1),n-=1;return o},t.gammafn=function(t){var n,r,i,o,s=[-1.716185138865495,24.76565080557592,-379.80425647094563,629.3311553128184,866.9662027904133,-31451.272968848367,-36144.413418691176,66456.14382024054],a=[-30.8402300119739,315.35062697960416,-1015.1563674902192,-3107.771671572311,22538.11842098015,4755.846277527881,-134659.9598649693,-115132.2596755535],u=!1,c=0,l=0,h=0,d=t;if(t>171.6243769536076)return 1/0;if(d<=0){if(!(o=d%1+36e-17))return 1/0;u=(1&d?-1:1)*e.PI/e.sin(e.PI*o),d=1-d}for(i=d,r=d<1?d++:(d-=c=(0|d)-1)-1,n=0;n<8;++n)h=(h+s[n])*r,l=l*r+a[n];if(o=h/l+1,i<d)o/=i;else if(i>d)for(n=0;n<c;++n)o*=d,d++;return u&&(o=u/o),o},t.gammap=function(e,n){return t.lowRegGamma(e,n)*t.gammafn(e)},t.lowRegGamma=function(n,r){var i,o=t.gammaln(n),s=n,a=1/n,u=a,c=r+1-n,l=1/1e-30,h=1/c,d=h,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++)a+=u*=r/++s;return a*e.exp(-r+n*e.log(r)-o)}for(;f<=p;f++)d*=(h=1/(h=(i=-f*(f-n))*h+(c+=2)))*(l=c+i/l);return 1-d*e.exp(-r+n*e.log(r)-o)},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 i,o,s,a,u=1e-30,c=1,l=n+r,h=n+1,d=n-1,f=1,p=1-l*t/h;for(e.abs(p)<u&&(p=u),a=p=1/p;c<=100&&(p=1+(o=c*(r-c)*t/((d+(i=2*c))*(n+i)))*p,e.abs(p)<u&&(p=u),f=1+o/f,e.abs(f)<u&&(f=u),a*=(p=1/p)*f,p=1+(o=-(n+c)*(l+c)*t/((n+i)*(h+i)))*p,e.abs(p)<u&&(p=u),f=1+o/f,e.abs(f)<u&&(f=u),a*=s=(p=1/p)*f,!(e.abs(s-1)<3e-7));c++);return a},t.gammapinv=function(n,r){var i,o,s,a,u,c,l=0,h=r-1,d=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(h),c=e.exp(h*(u-1)-d),a=n<.5?n:1-n,i=(2.30753+.27061*(o=e.sqrt(-2*e.log(a))))/(1+o*(.99229+.04481*o))-o,n<.5&&(i=-i),i=e.max(.001,r*e.pow(1-1/(9*r)-i/(3*e.sqrt(r)),3))):i=n<(o=1-r*(.253+.12*r))?e.pow(n/o,1/r):1-e.log(1-(n-o)/(1-o));l<12;l++){if(i<=0)return 0;if((i-=o=(s=(t.lowRegGamma(r,i)-n)/(o=r>1?c*e.exp(-(i-h)+h*(e.log(i)-u)):e.exp(-i+h*e.log(i)-d)))/(1-.5*e.min(1,s*((r-1)/i-1))))<=0&&(i=.5*(i+o)),e.abs(o)<1e-8*i)break}return i},t.erf=function(t){var n,r,i,o,s=[-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],a=s.length-1,u=!1,c=0,l=0;for(t<0&&(t=-t,u=!0),r=4*(n=2/(2+t))-2;a>0;a--)i=c,c=r*c-l+s[a],l=i;return o=n*e.exp(-t*t+.5*(s[0]+r*c)-l),u?o-1:1-o},t.erfc=function(e){return 1-t.erf(e)},t.erfcinv=function(n){var r,i,o,s,a=0;if(n>=2)return-100;if(n<=0)return 100;for(s=n<1?n:2-n,r=-.70711*((2.30753+.27061*(o=e.sqrt(-2*e.log(s/2))))/(1+o*(.99229+.04481*o))-o);a<2;a++)r+=(i=t.erfc(r)-s)/(1.1283791670955126*e.exp(-r*r)-r*i);return n<1?r:-r},t.ibetainv=function(n,r,i){var o,s,a,u,c,l,h,d,f,p,m=r-1,g=i-1,y=0;if(n<=0)return 0;if(n>=1)return 1;for(r>=1&&i>=1?(a=n<.5?n:1-n,l=(2.30753+.27061*(u=e.sqrt(-2*e.log(a))))/(1+u*(.99229+.04481*u))-u,n<.5&&(l=-l),h=(l*l-3)/6,d=2/(1/(2*r-1)+1/(2*i-1)),f=l*e.sqrt(h+d)/d-(1/(2*i-1)-1/(2*r-1))*(h+5/6-2/(3*d)),l=r/(r+i*e.exp(2*f))):(o=e.log(r/(r+i)),s=e.log(i/(r+i)),l=n<(u=e.exp(r*o)/r)/(f=u+(c=e.exp(i*s)/i))?e.pow(r*f*n,1/r):1-e.pow(i*f*(1-n),1/i)),p=-t.gammaln(r)-t.gammaln(i)+t.gammaln(r+i);y<10;y++){if(0===l||1===l)return l;if((l-=u=(c=(t.ibeta(l,r,i)-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,i){var o=0===n||1===n?0:e.exp(t.gammaln(r+i)-t.gammaln(r)-t.gammaln(i)+r*e.log(n)+i*e.log(1-n));return!(n<0||n>1)&&(n<(r+1)/(r+i+2)?o*t.betacf(n,r,i)/r:1-o*t.betacf(1-n,i,r)/i)},t.randn=function(n,r){var i,o,s,a,u;if(r||(r=n),n)return t.create(n,r,(function(){return t.randn()}));do{i=t._random_fn(),o=1.7156*(t._random_fn()-.5),u=(s=i-.449871)*s+(a=e.abs(o)+.386595)*(.196*a-.25472*s)}while(u>.27597&&(u>.27846||o*o>-4*e.log(i)*i*i));return o/i},t.randg=function(n,r,i){var o,s,a,u,c,l,h=n;if(i||(i=r),n||(n=1),r)return(l=t.zeros(r,i)).alter((function(){return t.randg(n)})),l;n<1&&(n+=1),o=n-1/3,s=1/e.sqrt(9*o);do{do{u=1+s*(c=t.randn())}while(u<=0);u*=u*u,a=t._random_fn()}while(a>1-.331*e.pow(c,4)&&e.log(a)>.5*c*c+o*(1-u+e.log(u)));if(n==h)return o*u;do{a=t._random_fn()}while(0===a);return e.pow(a,1/h)*o*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,i){for(var o,s=0,a=1,u=1,c=1,l=0,h=0;e.abs((u-h)/u)>i;)h=u,a=c+(o=-(n+l)*(n+r+l)*t/(n+2*l)/(n+2*l+1))*a,u=(s=u+o*s)+(o=(l+=1)*(r-l)*t/(n+2*l-1)/(n+2*l))*u,s/=c=a+o*c,a/=c,u/=c,c=1;return u/n}function r(n,r,i){var o=[.9815606342467192,.9041172563704749,.7699026741943047,.5873179542866175,.3678314989981802,.1252334085114689],s=[.04717533638651183,.10693932599531843,.16007832854334622,.20316742672306592,.2334925365383548,.24914704581340277],a=.5*n;if(a>=8)return 1;var u,c=2*t.normal.cdf(a,0,1,1,0)-1;c=c>=e.exp(-50/i)?e.pow(c,i):0;for(var l=a,h=(8-a)/(u=n>3?2:3),d=l+h,f=0,p=i-1,m=1;m<=u;m++){for(var g=0,y=.5*(d+l),v=.5*(d-l),w=1;w<=12;w++){var b,E=y+v*(6<w?o[(b=12-w+1)-1]:-o[(b=w)-1]),A=E*E;if(A>60)break;var _=2*t.normal.cdf(E,0,1,1,0)*.5-2*t.normal.cdf(E,n,1,1,0)*.5;_>=e.exp(-30/p)&&(g+=_=s[b-1]*e.exp(-.5*A)*e.pow(_,p))}f+=g*=2*v*i/e.sqrt(2*e.PI),l=d,d+=h}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,i){var o=t[e](n,r,i);return o.data=this,o},t[e].prototype.sample=function(n){var r=this._a,i=this._b,o=this._c;return n?t.alter(n,(function(){return t[e].sample(r,i,o)})):t[e].sample(r,i,o)},function(n){for(var r=0;r<n.length;r++)!function(n){t[e].prototype[n]=function(r){var i=this._a,o=this._b,s=this._c;return r||0===r||(r=this.data),"number"!=typeof r?t.fn.map.call(r,(function(r){return t[e][n](r,i,o,s)})):t[e][n](r,i,o,s)}}(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,i){return n>1||n<0?0:1==r&&1==i?1:r<512&&i<512?e.pow(n,r-1)*e.pow(1-n,i-1)/t.betafn(r,i):e.exp((r-1)*e.log(n)+(i-1)*e.log(1-n)-t.betaln(r,i))},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,i){var o;return n<0?0:r<=2?0===n&&r<2?1/0:0===n&&2===r?1:1/t.betafn(r/2,i/2)*e.pow(r/i,r/2)*e.pow(n,r/2-1)*e.pow(1+r/i*n,-(r+i)/2):(o=r*n/(i+n*r),r*(i/(i+n*r))/2*t.binomial.pdf((r-2)/2,(r+i-2)/2,o))},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,i){return n<0?0:0===n&&1===r?1/i:e.exp((r-1)*e.log(n)-n/i-t.gammaln(r)-r*e.log(i))},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,i){return n<=0?0:e.exp(-(r+1)*e.log(n)-i/n-t.gammaln(r)+r*e.log(i))},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,i){return n<0?0:.5+.5*t.erf((e.log(n)-r)/e.sqrt(2*i*i))},inv:function(n,r,i){return e.exp(-1.4142135623730951*i*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,i){return e.abs(i)<1e-14?t.studentt.pdf(n,r):e.abs(n)<1e-14?e.exp(t.gammaln((r+1)/2)-i*i/2-.5*e.log(e.PI*r)-t.gammaln(r/2)):r/n*(t.noncentralt.cdf(n*e.sqrt(1+2/r),r+2,i)-t.noncentralt.cdf(n,r,i))},cdf:function(n,r,i){var o=1e-14;if(e.abs(i)<o)return t.studentt.cdf(n,r);var s=!1;n<0&&(s=!0,i=-i);for(var a=t.normal.cdf(-i,0,1),u=o+1,c=u,l=n*n/(n*n+r),h=0,d=e.exp(-i*i/2),f=e.exp(-i*i/2-.5*e.log(2)-t.gammaln(1.5))*i;h<200||c>o||u>o;)c=u,h>0&&(d*=i*i/(2*h),f*=i*i/(2*(h+.5))),a+=.5*(u=d*t.beta.cdf(l,h+.5,r/2)+f*t.beta.cdf(l,h+1,r/2)),h++;return s?1-a:a}}),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,i){return.5*(1+t.erf((n-r)/e.sqrt(2*i*i)))},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 i=r/2;return t.ibeta((n+e.sqrt(n*n+r))/(2*e.sqrt(n*n+r)),i,i)},inv:function(n,r){var i=t.ibetainv(2*e.min(n,1-n),.5*r,.5);return i=e.sqrt(r*(1-i)/i),n>.5?i:-i},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,i){return 0===i||1===i?r*i===n?1:0:t.combination(r,n)*e.pow(i,n)*e.pow(1-i,r-n)},cdf:function(r,i,o){var s,a=1e-10;if(r<0)return 0;if(r>=i)return 1;if(o<0||o>1||i<=0)return NaN;var u=o,c=(r=e.floor(r))+1,l=i-r,h=c+l,d=e.exp(t.gammaln(h)-t.gammaln(l)-t.gammaln(c)+c*e.log(u)+l*e.log(1-u));return s=u<(c+1)/(h+2)?d*n(u,c,l,a):1-d*n(1-u,l,c,a),e.round(1/a*(1-s))/(1/a)}}),t.extend(t.negbin,{pdf:function(n,r,i){return n===n>>>0&&(n<0?0:t.combination(n+r-1,r-1)*e.pow(1-i,n)*e.pow(i,r))},cdf:function(e,n,r){var i=0,o=0;if(e<0)return 0;for(;o<=e;o++)i+=t.negbin.pdf(o,n,r);return i}}),t.extend(t.hypgeom,{pdf:function(n,r,i,o){if(n!=n|0)return!1;if(n<0||n<i-(r-o))return 0;if(n>o||n>i)return 0;if(2*i>r)return 2*o>r?t.hypgeom.pdf(r-i-o+n,r,r-i,r-o):t.hypgeom.pdf(o-n,r,r-i,o);if(2*o>r)return t.hypgeom.pdf(i-n,r,i,r-o);if(i<o)return t.hypgeom.pdf(n,r,o,i);for(var s=1,a=0,u=0;u<n;u++){for(;s>1&&a<o;)s*=1-i/(r-a),a++;s*=(o-u)*(i-u)/((u+1)*(r-i-o+u+1))}for(;a<o;a++)s*=1-i/(r-a);return e.min(1,e.max(0,s))},cdf:function(n,r,i,o){if(n<0||n<i-(r-o))return 0;if(n>=o||n>=i)return 1;if(2*i>r)return 2*o>r?t.hypgeom.cdf(r-i-o+n,r,r-i,r-o):1-t.hypgeom.cdf(o-n-1,r,r-i,o);if(2*o>r)return 1-t.hypgeom.cdf(i-n-1,r,i,r-o);if(i<o)return t.hypgeom.cdf(n,r,o,i);for(var s=1,a=1,u=0,c=0;c<n;c++){for(;s>1&&u<o;){var l=1-i/(r-u);a*=l,s*=l,u++}s+=a*=(o-c)*(i-c)/((c+1)*(r-i-o+c+1))}for(;u<o;u++)s*=1-i/(r-u);return e.min(1,e.max(0,s))}}),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=[],i=0;if(e<0)return 0;for(;i<=e;i++)r.push(t.poisson.pdf(i,n));return t.sum(r)},mean:function(t){return t},variance:function(t){return t},sampleSmall:function(n){var r=1,i=0,o=e.exp(-n);do{i++,r*=t._random_fn()}while(r>o);return i-1},sampleLarge:function(n){var r,i,o,s,a,u,c,l,h,d,f=n;for(s=e.sqrt(f),a=e.log(f),u=.02483*(c=.931+2.53*s)-.059,l=1.1239+1.1328/(c-3.4),h=.9277-3.6224/(c-2);;){if(i=e.random()-.5,o=e.random(),d=.5-e.abs(i),r=e.floor((2*u/d+c)*i+f+.43),d>=.07&&o<=h)return r;if(!(r<0||d<.013&&o>d)&&e.log(o)+e.log(l)-e.log(u/(d*d)+c)<=r*a-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,i){return r<=n||i<n||i>r?NaN:t<=n?0:t>=r?1:t<=i?e.pow(t-n,2)/((r-n)*(i-n)):1-e.pow(r-t,2)/((r-n)*(r-i))},inv:function(t,n,r,i){return r<=n||i<n||i>r?NaN:t<=(i-n)/(r-n)?n+(r-n)*e.sqrt(t*((i-n)/(r-n))):n+(r-n)*(1-e.sqrt((1-t)*(1-(i-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,i){var o=t._random_fn();return o<(i-n)/(r-n)?n+e.sqrt(o*(r-n)*(i-n)):r-e.sqrt((1-o)*(r-n)*(r-i))},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 i,o=t._random_fn()-.5;return n-r*((i=o)/e.abs(i))*e.log(1-2*e.abs(o))}}),t.extend(t.tukey,{cdf:function(n,i,o){var s=i,a=[.9894009349916499,.9445750230732326,.8656312023878318,.755404408355003,.6178762444026438,.45801677765722737,.2816035507792589,.09501250983763744],u=[.027152459411754096,.062253523938647894,.09515851168249279,.12462897125553388,.14959598881657674,.16915651939500254,.18260341504492358,.1894506104550685];if(n<=0)return 0;if(o<2||s<2)return NaN;if(!Number.isFinite(n))return 1;if(o>25e3)return r(n,1,s);var c,l=.5*o,h=l*e.log(o)-o*e.log(2)-t.gammaln(l),d=l-1,f=.25*o;c=o<=100?1:o<=800?.5:o<=5e3?.25:.125,h+=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=h+d*e.log(y+a[w]*c)-(a[w]*c+y)*f):(w=v-1,b=h+d*e.log(y-a[w]*c)+(a[w]*c-y)*f),b>=-30&&(g+=r(8<v?n*e.sqrt(.5*(a[w]*c+y)):n*e.sqrt(.5*(-a[w]*c+y)),1,s)*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,i){if(i<2||r<2)return NaN;if(n<0||n>1)return NaN;if(0===n)return 0;if(1===n)return 1/0;var o,s=function(t,n,r){var i=.5-.5*t,o=e.sqrt(e.log(1/(i*i))),s=o+((((-453642210148e-16*o-.204231210125)*o-.342242088547)*o-1)*o+.322232421088)/((((.0038560700634*o+.10353775285)*o+.531103462366)*o+.588581570495)*o+.099348462606);r<120&&(s+=(s*s*s+s)/r/4);var a=.8832-.2368*s;return r<120&&(a+=-1.214/r+1.208*s/r),s*(a*e.log(n-1)+1.4142)}(n,r,i),a=t.tukey.cdf(s,r,i)-n;o=a>0?e.max(0,s-1):s+1;for(var u,c=t.tukey.cdf(o,r,i)-n,l=1;l<50;l++)if(u=o-c*(o-s)/(c-a),a=c,s=o,u<0&&(u=0,c=-n),c=t.tukey.cdf(u,r,i)-n,o=u,e.abs(o-s)<1e-4)return u;throw new Error("tukey.inv failed to converge")}})}(e,Math),function(t,e){var n,r,i=Array.prototype.push,o=t.utils.isArray;function s(e){return o(e)||e instanceof t}t.extend({add:function(e,n){return s(n)?(s(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 s(n)?(s(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 s(n)?(s(n[0])||(n=[n]),t.multiply(e,t.inv(n))):t.map(e,(function(t){return t/n}))},multiply:function(e,n){var r,i,o,a,u,c,l,h;if(void 0===e.length&&void 0===n.length)return e*n;if(u=e.length,c=e[0].length,l=t.zeros(u,o=s(n)?n[0].length:c),h=0,s(n)){for(;h<o;h++)for(r=0;r<u;r++){for(a=0,i=0;i<c;i++)a+=e[r][i]*n[i][h];l[r][h]=a}return 1===u&&1===h?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){s(e[0])||(e=[e]),s(n[0])||(n=[n]);for(var r,i,o=1===e[0].length&&1!==e.length?t.transpose(e):e,a=1===n[0].length&&1!==n.length?t.transpose(n):n,u=[],c=0,l=o.length,h=o[0].length;c<l;c++){for(u[c]=[],r=0,i=0;i<h;i++)r+=o[c][i]*a[c][i];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,i=0;for(isNaN(n)&&(n=2),s(t[0])&&(t=t[0]);i<t.length;i++)r+=e.pow(e.abs(t[i]),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++)i.apply(r[n],e[n]);return r},inv:function(e){for(var n,r=e.length,i=e[0].length,o=t.identity(r,i),s=t.gauss_jordan(e,o),a=[],u=0;u<r;u++)for(a[u]=[],n=i;n<s[0].length;n++)a[u][n-i]=s[u][n];return a},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 i=[],o=1;o<e.length;o++){i[o-1]=[];for(var s=0;s<e.length;s++)s<r?i[o-1][s]=e[o][s]:s>r&&(i[o-1][s-1]=e[o][s])}var a=r%2?-1:1;n+=t(i)*e[0][r]*a}return n},gauss_elimination:function(n,r){var i,o,s,a,u=0,c=0,l=n.length,h=n[0].length,d=1,f=0,p=[];for(i=(n=t.aug(n,r))[0].length,u=0;u<l;u++){for(o=n[u][u],c=u,a=u+1;a<h;a++)o<e.abs(n[a][u])&&(o=n[a][u],c=a);if(c!=u)for(a=0;a<i;a++)s=n[u][a],n[u][a]=n[c][a],n[c][a]=s;for(c=u+1;c<l;c++)for(d=n[c][u]/n[u][u],a=u;a<i;a++)n[c][a]=n[c][a]-d*n[u][a]}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][i-1]-f)/n[u][u]}return p},gauss_jordan:function(n,r){var i,o,s,a=t.aug(n,r),u=a.length,c=a[0].length,l=0;for(o=0;o<u;o++){var h=o;for(s=o+1;s<u;s++)e.abs(a[s][o])>e.abs(a[h][o])&&(h=s);var d=a[o];for(a[o]=a[h],a[h]=d,s=o+1;s<u;s++)for(l=a[s][o]/a[o][o],i=o;i<c;i++)a[s][i]-=a[o][i]*l}for(o=u-1;o>=0;o--){for(l=a[o][o],s=0;s<o;s++)for(i=c-1;i>o-1;i--)a[s][i]-=a[o][i]*a[s][o]/l;for(a[o][o]/=l,i=u;i<c;i++)a[o][i]/=l}return a},triaUpSolve:function(e,n){var r,i=e[0].length,o=t.zeros(1,i)[0],s=!1;return null!=n[0].length&&(n=n.map((function(t){return t[0]})),s=!0),t.arange(i-1,-1,-1).forEach((function(s){r=t.arange(s+1,i).map((function(t){return o[t]*e[s][t]})),o[s]=(n[s]-t.sum(r))/e[s][s]})),s?o.map((function(t){return[t]})):o},triaLowSolve:function(e,n){var r,i=e[0].length,o=t.zeros(1,i)[0],s=!1;return null!=n[0].length&&(n=n.map((function(t){return t[0]})),s=!0),t.arange(i).forEach((function(i){r=t.arange(i).map((function(t){return e[i][t]*o[t]})),o[i]=(n[i]-t.sum(r))/e[i][i]})),s?o.map((function(t){return[t]})):o},lu:function(e){var n,r=e.length,i=t.identity(r),o=t.zeros(e.length,e[0].length);return t.arange(r).forEach((function(t){o[0][t]=e[0][t]})),t.arange(1,r).forEach((function(s){t.arange(s).forEach((function(r){n=t.arange(r).map((function(t){return i[s][t]*o[t][r]})),i[s][r]=(e[s][r]-t.sum(n))/o[r][r]})),t.arange(s,r).forEach((function(r){n=t.arange(s).map((function(t){return i[s][t]*o[t][r]})),o[s][r]=e[n.length][r]-t.sum(n)}))})),[i,o]},cholesky:function(n){var r,i=n.length,o=t.zeros(n.length,n[0].length);return t.arange(i).forEach((function(s){r=t.arange(s).map((function(t){return e.pow(o[s][t],2)})),o[s][s]=e.sqrt(n[s][s]-t.sum(r)),t.arange(s+1,i).forEach((function(e){r=t.arange(s).map((function(t){return o[s][t]*o[e][t]})),o[e][s]=(n[s][e]-t.sum(r))/o[s][s]}))})),o},gauss_jacobi:function(n,r,i,o){for(var s,a,u,c,l=0,h=0,d=n.length,f=[],p=[],m=[];l<d;l++)for(f[l]=[],p[l]=[],m[l]=[],h=0;h<d;h++)l>h?(f[l][h]=n[l][h],p[l][h]=m[l][h]=0):l<h?(p[l][h]=n[l][h],f[l][h]=m[l][h]=0):(m[l][h]=n[l][h],f[l][h]=p[l][h]=0);for(u=t.multiply(t.multiply(t.inv(m),t.add(f,p)),-1),a=t.multiply(t.inv(m),r),s=i,c=t.add(t.multiply(u,i),a),l=2;e.abs(t.norm(t.subtract(c,s)))>o;)s=c,c=t.add(t.multiply(u,s),a),l++;return c},gauss_seidel:function(n,r,i,o){for(var s,a,u,c,l,h=0,d=n.length,f=[],p=[],m=[];h<d;h++)for(f[h]=[],p[h]=[],m[h]=[],s=0;s<d;s++)h>s?(f[h][s]=n[h][s],p[h][s]=m[h][s]=0):h<s?(p[h][s]=n[h][s],f[h][s]=m[h][s]=0):(m[h][s]=n[h][s],f[h][s]=p[h][s]=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),a=i,l=t.add(t.multiply(c,i),u),h=2;e.abs(t.norm(t.subtract(l,a)))>o;)a=l,l=t.add(t.multiply(c,a),u),h+=1;return l},SOR:function(n,r,i,o,s){for(var a,u,c,l,h,d=0,f=n.length,p=[],m=[],g=[];d<f;d++)for(p[d]=[],m[d]=[],g[d]=[],a=0;a<f;a++)d>a?(p[d][a]=n[d][a],m[d][a]=g[d][a]=0):d<a?(m[d][a]=n[d][a],p[d][a]=g[d][a]=0):(g[d][a]=n[d][a],p[d][a]=m[d][a]=0);for(l=t.multiply(t.inv(t.add(g,t.multiply(p,s))),t.subtract(t.multiply(g,1-s),t.multiply(m,s))),c=t.multiply(t.multiply(t.inv(t.add(g,t.multiply(p,s))),r),s),u=i,h=t.add(t.multiply(l,i),c),d=2;e.abs(t.norm(t.subtract(h,u)))>o;)u=h,h=t.add(t.multiply(l,u),c),d++;return h},householder:function(n){for(var r,i,o,s,a=n.length,u=n[0].length,c=0,l=[],h=[];c<a-1;c++){for(r=0,s=c+1;s<u;s++)r+=n[s][c]*n[s][c];for(r=(n[c+1][c]>0?-1:1)*e.sqrt(r),i=e.sqrt((r*r-n[c+1][c]*r)/2),(l=t.zeros(a,1))[c+1][0]=(n[c+1][c]-r)/(2*i),o=c+2;o<a;o++)l[o][0]=n[o][c]/(2*i);h=t.subtract(t.identity(a,u),t.multiply(t.multiply(l,t.transpose(l)),2)),n=t.multiply(h,t.multiply(n,h))}return n},QR:(n=t.sum,r=t.arange,function(i){var o,s,a,u=i.length,c=i[0].length,l=t.zeros(c,c);for(i=t.copy(i),s=0;s<c;s++){for(l[s][s]=e.sqrt(n(r(u).map((function(t){return i[t][s]*i[t][s]})))),o=0;o<u;o++)i[o][s]=i[o][s]/l[s][s];for(a=s+1;a<c;a++)for(l[s][a]=n(r(u).map((function(t){return i[t][s]*i[t][a]}))),o=0;o<u;o++)i[o][a]=i[o][a]-i[o][s]*l[s][a]}return[i,l]}),lstsq:function(e,n){var r=!1;void 0===n[0].length&&(n=n.map((function(t){return[t]})),r=!0);var i=t.QR(e),o=i[0],s=i[1],a=e[0].length,u=t.slice(o,{col:{end:a}}),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(i){var o=t.multiply(e[i][n],-1),s=t.slice(e,{row:i}),a=t.multiply(t.slice(e,{row:n}),o);t.sliceAssign(e,{row:i},t.add(s,a));var u=t.slice(r,{row:i}),c=t.multiply(t.slice(r,{row:n}),o);t.sliceAssign(r,{row:i},t.add(u,c))}))})),r}(t.slice(s,{row:{end:a}})),l=t.transpose(u);void 0===l[0].length&&(l=[l]);var h=t.multiply(t.multiply(c,l),n);return void 0===h.length&&(h=[[h]]),r?h.map((function(t){return t[0]})):h},jacobi:function(n){for(var r,i,o,s,a,u,c,l=1,h=n.length,d=t.identity(h,h),f=[];1===l;){for(a=n[0][1],o=0,s=1,r=0;r<h;r++)for(i=0;i<h;i++)r!=i&&a<e.abs(n[r][i])&&(a=e.abs(n[r][i]),o=r,s=i);for(u=n[o][o]===n[s][s]?n[o][s]>0?e.PI/4:-e.PI/4:e.atan(2*n[o][s]/(n[o][o]-n[s][s]))/2,(c=t.identity(h,h))[o][o]=e.cos(u),c[o][s]=-e.sin(u),c[s][o]=e.sin(u),c[s][s]=e.cos(u),d=t.multiply(d,c),n=t.multiply(t.multiply(t.inv(c),n),c),l=0,r=1;r<h;r++)for(i=1;i<h;i++)r!=i&&e.abs(n[r][i])>.001&&(l=1)}for(r=0;r<h;r++)f.push(n[r][r]);return[d,f]},rungekutta:function(t,e,n,r,i,o){var s,a,u;if(2===o)for(;r<=n;)i+=((s=e*t(r,i))+(a=e*t(r+e,i+s)))/2,r+=e;if(4===o)for(;r<=n;)i+=((s=e*t(r,i))+2*(a=e*t(r+e/2,i+s/2))+2*(u=e*t(r+e/2,i+a/2))+e*t(r+e,i+u))/6,r+=e;return i},romberg:function(t,n,r,i){for(var o,s,a,u,c,l=0,h=(r-n)/2,d=[],f=[],p=[];l<i/2;){for(c=t(n),a=n,u=0;a<=r;a+=h,u++)d[u]=a;for(o=d.length,a=1;a<o-1;a++)c+=(a%2!=0?4:2)*t(d[a]);c=h/3*(c+t(r)),p[l]=c,h/=2,l++}for(s=p.length,o=1;1!==s;){for(a=0;a<s-1;a++)f[a]=(e.pow(4,o)*p[a+1]-p[a])/(e.pow(4,o)-1);s=f.length,p=f,f=[],o++}return p},richardson:function(t,n,r,i){function o(t,e){for(var n,r=0,i=t.length;r<i;r++)t[r]===e&&(n=r);return n}for(var s,a,u,c,l,h=e.abs(r-t[o(t,r)+1]),d=0,f=[],p=[];i>=h;)s=o(t,r+i),a=o(t,r),f[d]=(n[s]-2*n[a]+n[2*a-s])/(i*i),i/=2,d++;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 i,o=(n-e)/r,s=t(e),a=[],u=e,c=0,l=1;u<=n;u+=o,c++)a[c]=u;for(i=a.length;l<i-1;l++)s+=(l%2!=0?4:2)*t(a[l]);return o/3*(s+t(n))},hermite:function(t,e,n,r){for(var i,o=t.length,s=0,a=0,u=[],c=[],l=[],h=[];a<o;a++){for(u[a]=1,i=0;i<o;i++)a!=i&&(u[a]*=(r-t[i])/(t[a]-t[i]));for(c[a]=0,i=0;i<o;i++)a!=i&&(c[a]+=1/(t[a]-t[i]));l[a]=(1-2*(r-t[a])*c[a])*(u[a]*u[a]),h[a]=(r-t[a])*(u[a]*u[a]),s+=l[a]*e[a]+h[a]*n[a]}return s},lagrange:function(t,e,n){for(var r,i,o=0,s=0,a=t.length;s<a;s++){for(i=e[s],r=0;r<a;r++)s!=r&&(i*=(n-t[r])/(t[s]-t[r]));o+=i}return o},cubic_spline:function(e,n,r){for(var i,o,s=e.length,a=0,u=[],c=[],l=[],h=[],d=[],f=[];a<s-1;a++)h[a]=e[a+1]-e[a];for(l[0]=0,a=1;a<s-1;a++)l[a]=3/h[a]*(n[a+1]-n[a])-3/h[a-1]*(n[a]-n[a-1]);for(a=1;a<s-1;a++)u[a]=[],c[a]=[],u[a][a-1]=h[a-1],u[a][a]=2*(h[a-1]+h[a]),u[a][a+1]=h[a],c[a][0]=l[a];for(o=t.multiply(t.inv(u),c),i=0;i<s-1;i++)d[i]=(n[i+1]-n[i])/h[i]-h[i]*(o[i+1][0]+2*o[i][0])/3,f[i]=(o[i+1][0]-o[i][0])/(3*h[i]);for(i=0;i<s&&!(e[i]>r);i++);return n[i-=1]+(r-e[i])*d[i]+t.sq(r-e[i])*o[i]+(r-e[i])*t.sq(r-e[i])*f[i]},gauss_quadrature:function(){throw new Error("gauss_quadrature not yet implemented")},PCA:function(e){var n,r,i,o,s,a=e.length,u=e[0].length,c=0,l=[],h=[],d=[],f=[],p=[],m=[],g=[];for(c=0;c<a;c++)l[c]=t.sum(e[c])/u;for(c=0;c<u;c++)for(p[c]=[],n=0;n<a;n++)p[c][n]=e[n][c]-l[n];for(p=t.transpose(p),c=0;c<a;c++)for(m[c]=[],n=0;n<a;n++)m[c][n]=t.dot([p[c]],[p[n]])/(u-1);for(s=(i=t.jacobi(m))[0],h=i[1],g=t.transpose(s),c=0;c<h.length;c++)for(n=c;n<h.length;n++)h[c]<h[n]&&(r=h[c],h[c]=h[n],h[n]=r,d=g[c],g[c]=g[n],g[n]=d);for(o=t.transpose(p),c=0;c<a;c++)for(f[c]=[],n=0;n<o.length;n++)f[c][n]=t.dot([g[c]],[o[n]]);return[e,h,g,f]}}),function(e){for(var n=0;n<e.length;n++)!function(e){t.fn[e]=function(n,r){var i=this;return r?(setTimeout((function(){r.call(i,t.fn[e].call(i,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,i=t.utils.isArray;function o(t,n,r,i){if(t>1||r>1||t<=0||r<=0)throw new Error("Proportions should be greater than 0 and less than 1");var o=(t*n+r*i)/(n+i);return(t-r)/e.sqrt(o*(1-o)*(1/n+1/i))}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,o=n.call(arguments);return i(o[1])?(r=t.zscore(o[0],o[1],o[3]),1===o[2]?t.normal.cdf(-e.abs(r),0,1):2*t.normal.cdf(-e.abs(r),0,1)):o.length>2?(r=t.zscore(o[0],o[1],o[2]),1===o[3]?t.normal.cdf(-e.abs(r),0,1):2*t.normal.cdf(-e.abs(r),0,1)):(r=o[0],1===o[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,i){var o=e.abs(this.zscore(n,i));return 1===r?t.normal.cdf(-o,0,1):2*t.normal.cdf(-o,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 i,o=n.call(arguments);return 5===o.length?(i=e.abs(t.tscore(o[0],o[1],o[2],o[3])),1===o[4]?t.studentt.cdf(-i,o[3]-1):2*t.studentt.cdf(-i,o[3]-1)):r(o[1])?(i=e.abs(o[0]),1==o[2]?t.studentt.cdf(-i,o[1]-1):2*t.studentt.cdf(-i,o[1]-1)):(i=e.abs(t.tscore(o[0],o[1])),1==o[2]?t.studentt.cdf(-i,o[1].length-1):2*t.studentt.cdf(-i,o[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,i,o,s,a,u,c,l,h=n.call(arguments);if(1===h.length){for(a=new Array(h[0].length),c=0;c<h[0].length;c++)a[c]=h[0][c];h=a}for(i=new Array,c=0;c<h.length;c++)i=i.concat(h[c]);for(o=t.mean(i),r=0,c=0;c<h.length;c++)r+=h[c].length*e.pow(t.mean(h[c])-o,2);for(r/=h.length-1,u=0,c=0;c<h.length;c++)for(s=t.mean(h[c]),l=0;l<h[c].length;l++)u+=e.pow(h[c][l]-s,2);return r/(u/(i.length-h.length))},anovaftest:function(){var e,i,o,s,a=n.call(arguments);if(r(a[0]))return 1-t.centralF.cdf(a[0],a[1],a[2]);var u=t.anovafscore(a);for(e=a.length-1,o=0,s=0;s<a.length;s++)o+=a[s].length;return i=o-e-1,1-t.centralF.cdf(u,e,i)},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 i,o,s,a,u,c=n.call(arguments);return r(c[0])?(i=c[0],o=c[1],s=c[2],a=c[3],u=c[4]):(i=t.mean(c[0]),o=t.mean(c[1]),s=c[0].length,a=c[1].length,u=c[2]),e.abs(i-o)/(u*e.sqrt((1/s+1/a)/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 i=r[0],o=r[1];return 1-t.tukey.cdf(e,o,i-o)},tukeyhsd:function(e){for(var n=t.pooledstdev(e),r=e.map((function(e){return t.mean(e)})),i=e.reduce((function(t,e){return t+e.length}),0),o=[],s=0;s<e.length;++s)for(var a=s+1;a<e.length;++a){var u=t.qtest(r[s],r[a],e[s].length,e[a].length,n,i,e.length);o.push([[s,a],u])}return o}}),t.extend({normalci:function(){var r,i=n.call(arguments),o=new Array(2);return r=4===i.length?e.abs(t.normal.inv(i[1]/2,0,1)*i[2]/e.sqrt(i[3])):e.abs(t.normal.inv(i[1]/2,0,1)*t.stdev(i[2])/e.sqrt(i[2].length)),o[0]=i[0]-r,o[1]=i[0]+r,o},tci:function(){var r,i=n.call(arguments),o=new Array(2);return r=4===i.length?e.abs(t.studentt.inv(i[1]/2,i[3]-1)*i[2]/e.sqrt(i[3])):e.abs(t.studentt.inv(i[1]/2,i[2].length-1)*t.stdev(i[2],!0)/e.sqrt(i[2].length)),o[0]=i[0]-r,o[1]=i[0]+r,o},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,i){var s=o(e,n,r,i);return t.ztest(s,1)},twoSidedDifferenceOfProportions:function(e,n,r,i){var s=o(e,n,r,i);return t.ztest(s,2)}})}(e,Math),e.models=function(){function t(t,n){var r=t.length,i=n[0].length-1,o=r-i-1,s=e.lstsq(n,t),a=e.multiply(n,s.map((function(t){return[t]}))).map((function(t){return t[0]})),u=e.subtract(t,a),c=e.mean(t),l=e.sum(a.map((function(t){return Math.pow(t-c,2)}))),h=e.sum(t.map((function(t,e){return Math.pow(t-a[e],2)}))),d=l+h;return{exog:n,endog:t,nobs:r,df_model:i,df_resid:o,coef:s,predict:a,resid:u,ybar:c,SST:d,SSE:l,SSR:h,R2:l/d}}function n(n){var r,i,o=(r=n.exog,i=r[0].length,e.arange(i).map((function(n){var o=e.arange(i).filter((function(t){return t!==n}));return t(e.col(r,n).map((function(t){return t[0]})),e.col(r,o))}))),s=Math.sqrt(n.SSR/n.df_resid),a=o.map((function(t){var e=t.SST,n=t.R2;return s/Math.sqrt(e*(1-n))})),u=n.coef.map((function(t,e){return(t-0)/a[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),h=n.coef.map((function(t,e){var n=l*a[e];return[t-n,t+n]}));return{se:a,t:u,p:c,sigmaHat:s,interval95:h}}return{ols:function(r,i){var o=t(r,i),s=n(o),a=function(t){var n,r,i,o=t.R2/t.df_model/((1-t.R2)/t.df_resid);return{F_statistic:o,pvalue:1-(n=o,r=t.df_model,i=t.df_resid,e.beta.cdf(n/(i/r+n),r/2,i/2))}}(o),u=1-(1-o.R2)*((o.nobs-1)/o.df_resid);return o.t=s,o.f=a,o.adjust_R2=u,o}}}(),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,i,o,s,a;if(t.cols()==n.rows()){if(n.rows()>1){for(s=[],r=0;r<t.rows();r++)for(s[r]=[],i=0;i<n.cols();i++){for(a=0,o=0;o<t.cols();o++)a+=t.toArray()[r][o]*n.toArray()[o][i];s[r][i]=a}return e(s)}for(s=[],r=0;r<t.rows();r++)for(s[r]=[],i=0;i<n.cols();i++){for(a=0,o=0;o<t.cols();o++)a+=t.toArray()[r][o]*n.toArray()[i];s[r][i]=a}return e(s)}},regress:function(t,n){var r=e.xtranspxinv(t),i=t.transpose(),o=e.matrixmult(e(r),i);return e.matrixmult(o,n)},regresst:function(t,n,r){var i=e.regress(t,n),o={anova:{}},s=e.jMatYBar(t,i);o.yBar=s;var a=n.mean();o.anova.residuals=e.residuals(n,s),o.anova.ssr=e.ssr(s,a),o.anova.msr=o.anova.ssr/(t[0].length-1),o.anova.sse=e.sse(n,s),o.anova.mse=o.anova.sse/(n.length-(t[0].length-1)-1),o.anova.sst=e.sst(n,a),o.anova.mst=o.anova.sst/(n.length-1),o.anova.r2=1-o.anova.sse/o.anova.sst,o.anova.r2<0&&(o.anova.r2=0),o.anova.fratio=o.anova.msr/o.anova.mse,o.anova.pvalue=e.anovaftest(o.anova.fratio,t[0].length-1,n.length-(t[0].length-1)-1),o.anova.rmse=Math.sqrt(o.anova.mse),o.anova.r2adj=1-o.anova.mse/o.anova.mst,o.anova.r2adj<0&&(o.anova.r2adj=0),o.stats=new Array(t[0].length);for(var u,c,l,h=e.xtranspxinv(t),d=0;d<i.length;d++)u=Math.sqrt(o.anova.mse*Math.abs(h[d][d])),c=Math.abs(i[d]/u),l=e.ttest(c,n.length-t[0].length-1,r),o.stats[d]=[i[d],u,c,l];return o.regress=i,o},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),i=0;i<t.length;i++){r[i]=new Array(t[i].length);for(var o=0;o<t[i].length;o++)r[i][o]=t[i][o]-n[i][o]}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 o={},s=[],a=0;a<t.length;a++){var u=t[a],c=r.base?u[0]+r.base:u[0],l=o[c]||0,h="".concat(c," ").concat(l);o[c]=l+1;var d=n(h),f={css:u[1],media:u[2],sourceMap:u[3],supports:u[4],layer:u[5]};if(-1!==d)e[d].references++,e[d].updater(f);else{var p=i(f,r);r.byIndex=a,e.splice(a,0,{identifier:h,updater:p,references:1})}s.push(h)}return s}function i(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,i){var o=r(t=t||[],i=i||{});return function(t){t=t||[];for(var s=0;s<o.length;s++){var a=n(o[s]);e[a].references--}for(var u=r(t,i),c=0;c<o.length;c++){var l=n(o[c]);0===e[l].references&&(e[l].updater(),e.splice(l,1))}o=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 i=void 0!==n.layer;i&&(r+="@layer".concat(n.layer.length>0?" ".concat(n.layer):""," {")),r+=n.css,i&&(r+="}"),n.media&&(r+="}"),n.supports&&(r+="}");var o=n.sourceMap;o&&"undefined"!=typeof btoa&&(r+="\n/*# sourceMappingURL=data:application/json;base64,".concat(btoa(unescape(encodeURIComponent(JSON.stringify(o))))," */")),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 i=e[r];if(void 0!==i)return i.exports;var o=e[r]={id:r,loaded:!1,exports:{}};return t[r].call(o.exports,o,o.exports,n),o.loaded=!0,o.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&&(t=e.currentScript.src),!t)){var r=e.getElementsByTagName("script");if(r.length)for(var i=r.length-1;i>-1&&(!t||!/^http(s?):/.test(t));)t=r[i--].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:()=>Cr,MCL:()=>Sr,MCLInitializationFunction:()=>Ir,MVA:()=>xr,PCA:()=>wr,PLS:()=>Mr,_package:()=>mr,anova:()=>Qr,applyLinearKernelSVM:()=>Or,applyLinearRegression:()=>ei,applyPLSRegression:()=>li,applyPolynomialKernelSVM:()=>Wr,applyRBFkernelSVM:()=>Ur,applySigmoidKernelSVM:()=>Hr,applySoftmax:()=>oi,applyXGBooster:()=>mi,dbScan:()=>vr,dbscanPostProcessingFunction:()=>br,demoMultivariateAnalysis:()=>Lr,info:()=>gr,init:()=>yr,isApplicableLinearKernelSVM:()=>Pr,isApplicableLinearRegression:()=>ni,isApplicablePLSRegression:()=>hi,isApplicablePolynomialKernelSVM:()=>zr,isApplicableRBFkernelSVM:()=>kr,isApplicableSigmoidKernelSVM:()=>$r,isApplicableSoftmax:()=>si,isApplicableXGBooster:()=>yi,isInteractiveLinearKernelSVM:()=>Rr,isInteractiveLinearRegression:()=>ri,isInteractivePLSRegression:()=>fi,isInteractivePolynomialKernelSVM:()=>jr,isInteractiveRBFkernelSVM:()=>Gr,isInteractiveSigmoidKernelSVM:()=>Kr,isInteractiveSoftmax:()=>ai,isInteractiveXGBooster:()=>gi,kNNImputation:()=>Zr,kNNImputationForTable:()=>Jr,numberPreprocessingFunction:()=>Er,reduceDimensionality:()=>_r,stringPreprocessingFunction:()=>Ar,topMenuPLS:()=>Nr,trainLinearKernelSVM:()=>Tr,trainLinearRegression:()=>ti,trainPLSRegression:()=>ci,trainPolynomialKernelSVM:()=>Vr,trainRBFkernelSVM:()=>Dr,trainSigmoidKernelSVM:()=>qr,trainSoftmax:()=>ii,trainXGBooster:()=>pi,visualizeLinearKernelSVM:()=>Fr,visualizePLSRegression:()=>di,visualizePolynomialKernelSVM:()=>Yr,visualizeRBFkernelSVM:()=>Br,visualizeSigmoidKernelSVM:()=>Xr});const t=grok,e=ui,i=DG,o={i32:"HEAP32",f32:"HEAPF32"},s={i32:Int32Array,f32:Float32Array},a={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*s[this.type].BYTES_PER_ELEMENT)}isMemoryForBufferAllocated(){return 0!=this.buf}putDataToBuffer(t){if(this.isMemoryForBufferAllocated()){const e=this.type,n=a[e],r=t[o[e]];let i=null;const u=this.data;i="int"==u.type&&"i32"==e||"double"==u.type&&"f32"==e?u.getRawData():new s[e](u.getRawData()),i&&r.set(i,this.buf>>n)}}getDataFromBuffer(t){if(this.toUpdate&&this.isMemoryForBufferAllocated()){const e=this.type,n=t[o[e]],r=this.buf,i=s[e].BYTES_PER_ELEMENT,a=this.data.getRawData();for(let t=0;t<this.numOfRows;t++)a[t]=n[r/i+t]}}freeBuffer(t){this.isMemoryForBufferAllocated()&&(t._free(this.buf),this.buf=0)}}class h 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[o[e]],r=this.buf,i=u[e],a=new s[e](this.numOfRows);for(let t=0;t<a.length;t++)a[t]=n[r/a.BYTES_PER_ELEMENT+t];this.data=i("name",a)}}}class d 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*s[this.type].BYTES_PER_ELEMENT)}isMemoryForBufferAllocated(){return 0!=this.buf}putDataToBuffer(t){if(this.isMemoryForBufferAllocated()){const e=this.type,n=a[e],r=t[o[e]],i=s[e].BYTES_PER_ELEMENT;for(let t=0;t<this.numOfColumns;t++){let o=null;const a=this.data[t];o="int"==a.type&&"i32"==e||"double"==a.type&&"f32"==e?a.getRawData():new s[e](a.getRawData()),null!=o&&r.set(o,this.buf+t*this.numOfRows*i>>n)}}}getDataFromBuffer(t){if(this.toUpdate&&this.isMemoryForBufferAllocated()){const e=this.type,n=t[o[e]],r=this.numOfRows,i=this.numOfColumns,a=new s[e](n.buffer,this.buf,r*i);for(let t=0;t<i;t++){const e=this.data[t].getRawData();for(let n=0;n<r;n++)e[n]=a[n+t*r]}}}freeBuffer(t){this.isMemoryForBufferAllocated()&&(t._free(this.buf),this.buf=0)}}class f extends d{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[o[e]],r=this.numOfRows,i=this.numOfColumns,a=s[e].BYTES_PER_ELEMENT,c=u[e],l=this.buf;for(let t=0;t<i;t++){const i=new s[e](r);for(let e=0;e<r;e++)i[e]=n[l/a+e+t*r];this.data.push(c((t+1).toString(),i))}}}}const p={intColumn:t=>new l(t,"i32"),newIntColumn:t=>new h("i32",t),intColumns:t=>new d(t.toList(),"i32"),newIntColumns:(t,e)=>new f("i32",t,e),floatColumn:t=>new l(t,"f32"),newFloatColumn:t=>new h("f32",t),floatColumns:t=>new d(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],i=r.arguments,o=[];let s=0;for(const t in i){const e=i[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[s]),s++;break;case"newFloatColumns":case"newIntColumns":const t=i[e.numOfRows.ref].data[e.numOfRows.value],r=i[e.numOfColumns.ref].data[e.numOfColumns.value];e.data=p[e.type](t,r);break;case"newFloatColumn":case"newIntColumn":const o=i[e.numOfRows.ref].data[e.numOfRows.value];e.data=p[e.type](o)}o.push(i[t].data)}}const a=function(t,e,n,r){let i;for(const e of r)e.allocateMemoryForBuffer(t);let o=!0;for(const t of r)o&=t.isMemoryForBufferAllocated();if(o){const n=[],o=[];for(const e of r)e.complementArrOfParams(n),e.complementArrOfTypes(o),e.putDataToBuffer(t);const s="number";i=t.ccall(e,s,o,n);for(const e of r)e.getDataFromBuffer(t)}for(const e of r)e.freeBuffer(t);if(null!=i)return i}(t,e,0,o);i._callResult=p.num(a);const u=r.output;if("objects"!=u.type)return m[u.type](i[u.source].data);const c=[];for(const t of u.source)c.push(i[t].data.data);return c}const y="num",v="floatColumn",w="intColumn",b="floatColumns",E="newFloatColumns",A="intColumns",_="newIntColumns",C="newFloatColumn",S="newIntColumn",I="column",M="_callResult",N="numOfRows",x="numOfColumns",L="ref",T="value",O="tableFromColumns",P="objects",R="int",F="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=[],i=0;for(const o in t){const s=t[o],a=s.type;if(o!==M){switch(a){case y:case R:case F:s.data=e[i],i++;break;case w:case v:let r;const o=e[i],u=o.length;r=o.type===R&&a===w||o.type===F&&a===v?o.getRawData().slice(0,u):new D[a](o.getRawData().slice(0,u)),s.data={array:r,numOfRows:u},i++;break;case S:case C:let c=0;n=s[N][L],c=t[n].type===y?t[n].data:t[n].data[s[N][T]],s.data={numOfRows:c},i++;break;case A:case b:let l=[];const h=e[i].byIndex(0).length;for(const t of e[i].toList())t.type===R&&a===w||t.type===F&&a===v?l.push(t.getRawData().slice(0,h)):l.push(new D[a](t.getRawData().slice(0,h)));s.data={arrays:l,numOfRows:h,numOfColumns:l.length},i++;break;case _:case E:let d=0,f=0;n=s[N][L],d=t[n].type===y?t[n].data:t[n].data[s[N][T]],n=s[x][L],f=t[n].type===y?t[n].data:t[n].data[s[x][T]],s.data={numOfRows:d,numOfColumns:f},i++;break;default:return}r.push(s)}}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 i in t){const o=t[i];switch(o.type){case y:case R:case F:case w:case v:case b:case A:break;case C:case S:let t;null==o.name?t=(0).toString():a=o.name,o.column=n[o.type](t,e[r].array);break;case _:case E:let i=[],s=e[r].arrays.length,a=[];if(null==o.names)for(let t=1;t<=s;t++)a.push(t.toString());else a=o.names;for(let t=0;t<s;t++)i.push(n[o.type](a[t],e[r].arrays[t]));o.columns=i}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 R:case F:return t.arguments[e.source];case I:return t.arguments[e.source].column;case O:return DG.DataFrame.fromColumns(t.arguments[e.source].columns);case P:let r=[];for(let i of e.source){let e=t.arguments[i];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 R:case F:case w:case v:case A:case b:break;case S:case C:n.column=null;break;case _:case E:n.columns=null}}}(t.arguments),n}const G=1,B=1e8,V="components must be positive.",W="components must not be greater than features count.",z="dataframe is too big.",j="unsupported column type: ";function Y(t){if(t.type!=i.COLUMN_TYPE.FLOAT&&t.type!=i.COLUMN_TYPE.INT)throw new Error(j+t.type)}function q(t){if(t.stats.missingValueCount>0)throw new Error(`The column '${t.name}' has missing values.`)}function H(t,e){if(function(t,e){if(e<G)throw new Error(V);if(e>t.length)throw new Error(W);for(const e of t)Y(e),q(e)}(t,e),t.length*t.byIndex(0).length>B)throw new Error(z)}var $=function(t,e,n,r){return new(n||(n=Promise))((function(i,o){function s(t){try{u(r.next(t))}catch(t){o(t)}}function a(t){try{u(r.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}u((r=r.apply(t,e||[])).next())}))};var K=function(t,e,n,r){return new(n||(n=Promise))((function(i,o){function s(t){try{u(r.next(t))}catch(t){o(t)}}function a(t){try{u(r.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}u((r=r.apply(t,e||[])).next())}))};const X=0,Q=1,Z=2,J=3,tt=4,et=0,nt=1,rt=2,it=3,ot=4,st=5,at=6,ut=7,ct=0,lt=1,ht=2,dt=3,ft=0,pt=0,mt=1,gt=0,yt=1,vt=0,wt=0,bt=0,Et=0,At="gamma must be strictly positive.",_t="sigma must be strictly positive.",Ct="c must be strictly positive.",St="d must be strictly positive.",It="incorrect kernel.",Mt="labels must be strings of two categories.",Nt="Labels",xt="predicted",Lt="correctness",Tt="Confusion matrix",Ot="mean",Pt="std dev",Rt="alpha",Ft="weight",Dt="Gamma",Ut="Kernel",kt="Kernel params",Gt="Kernel parameter 1",Bt="Kernel parameter 2",Vt="Features count",Wt="Train samples count",zt="Train error, %",jt=["linear","polynomial","RBF","sigmoid"],Yt="Sensitivity",qt="Specificity",Ht="Balanced accuracy",$t="Positive predicitve value",Kt="Negative predicitve value",Xt="prediction",Qt=4,Zt=3,Jt=2,te=0,ee=1,ne=2,re=0,ie=1;function oe(t,e,r){return K(this,void 0,void 0,(function*(){const o=e.columns;if(2!=r.categories.length)throw new Error(Mt);const s=i.Column.float(r.name,r.length);for(let t=0;t<r.length;t++)s.set(t,r.get(t)==r.categories[0]?-1:1,!1);const a=yield function(t,e,r){return K(this,void 0,void 0,(function*(){!function(t){if(t.gamma<=vt)throw new Error(At);switch(t.kernel){case X:return;case Z:if(t.sigma<=wt)throw new Error(_t);return;case Q:if(t.cParam<=bt)throw new Error(Ct);if(t.dParam<=Et)throw new Error(St);return;case J:return;default:throw new Error(It)}}(t);const o=[re,re];switch(t.kernel){case X:break;case Z:o[ft]=t.sigma;break;case Q:o[pt]=t.cParam,o[mt]=t.dParam;break;case J:o[gt]=t.kappa,o[yt]=t.theta;break;default:throw new Error(It)}const s=i.Column.fromList("double",kt,o),a=e.toList(),u=a[0].length+ie,c=a.length+ie,l=tt;let h;const d=async function(t,e,r,i,o,s,a,u){return new Promise(((c,l)=>{const h=new Worker(new URL(n.p+n.u(656),n.b));h.postMessage(U(EDA.trainAndAnalyzeLSSVM.arguments,[t,e,r,i,o,s,a,u])),h.onmessage=function(t){h.terminate(),c(k(EDA.trainAndAnalyzeLSSVM,t.data))}}))}(t.gamma,t.kernel,s,u,c,l,e,r);yield d.then((t=>{h=t}),(t=>{throw new Error(`Error: ${t}`)})),h[nt].name=Ot,h[rt].name=Pt,h[it].name=Rt,h[ot].name=Ft,h[st].name=xt,h[at].name=Lt,h[ut].name=Tt;const f={trainGamma:t.gamma,kernelType:t.kernel,kernelParams:s,trainLabels:r,normalizedTrainData:i.DataFrame.fromColumns(h[et]),means:h[nt],stdDevs:h[rt],modelParams:h[it],modelWeights:h[ot],predictedLabels:h[st],correctness:h[at],confusionMatrix:h[ut],trainError:void 0,featuresCount:a.length,trainSamplesCount:a[0].length};return function(t){const e=t.confusionMatrix.getRawData(),n=e[ct],r=e[dt],i=e[ht],o=e[lt],s=n+o,a=i+r,u=n/s,c=r/a,l=n/(n+i),h=r/(r+o),d=(n+r)/(s+a),f=(u+c)/2;t.sensitivity=u,t.specificity=c,t.balancedAccuracy=f,t.positivePredicitveValue=l,t.negativePredicitveValue=h,t.trainError=100*(1-d)}(f),f}))}(t,o,s);return a.realLabels=r,a}))}function se(t,e){const n=ue(e);return i.Viewer.form(n.modelInfo,{showNavigation:!1}).root}function ae(t){const e=t.normalizedTrainData.columns,n=t.trainSamplesCount,r=t.featuresCount,o=i.DataFrame.fromColumns([t.realLabels]).toByteArray(),s=Qt+o.length+4-o.length%4,a=function(t){const e=t.kernelParams.getRawData();return i.DataFrame.fromColumns([i.Column.fromList("double",Dt,[t.trainGamma]),i.Column.fromStrings(Ut,[jt[t.kernelType]]),i.Column.fromList("double",Gt,[e[0]]),i.Column.fromList("double",Bt,[e[1]]),i.Column.fromList("double",Vt,[t.featuresCount]),i.Column.fromList("double",Wt,[t.trainSamplesCount]),i.Column.fromList("double",zt,[t.trainError]),i.Column.fromList("double",Ht,[t.balancedAccuracy]),i.Column.fromList("double",Yt,[t.sensitivity]),i.Column.fromList("double",qt,[t.specificity]),i.Column.fromList("double",$t,[t.positivePredicitveValue]),i.Column.fromList("double",Kt,[t.negativePredicitveValue])])}(t).toByteArray(),u=Qt+a.length+4-a.length%4,c=new Uint8Array(Qt*(Zt+Jt+n+r+r+n+ie+r+ie+r*n)+s+u),l=c.buffer;let h=0,d=new Int32Array(l,h,Zt);d[te]=t.kernelType,d[ee]=n,d[ne]=r,h+=Zt*Qt;let f=new Float32Array(l,h,Jt);f.set(t.kernelParams.getRawData()),h+=Jt*Qt,f=new Float32Array(l,h,n),f.set(t.trainLabels.getRawData()),h+=n*Qt,f=new Float32Array(l,h,r),f.set(t.means.getRawData()),h+=r*Qt,f=new Float32Array(l,h,r),f.set(t.stdDevs.getRawData()),h+=r*Qt,f=new Float32Array(l,h,n+ie),f.set(t.modelParams.getRawData()),h+=(n+ie)*Qt,f=new Float32Array(l,h,r+ie),f.set(t.modelWeights.getRawData()),h+=(r+ie)*Qt;for(const t of e)f=new Float32Array(l,h,r),f.set(t.getRawData()),h+=r*Qt;return d=new Int32Array(l,h,1),d[0]=o.length,c.set(o,h+Qt),h+=s,d=new Int32Array(l,h,1),d[0]=a.length,c.set(a,h+Qt),h+=u,c}function ue(t){const e=t.buffer;let n=0;const r=new Int32Array(e,n,Zt);n+=Zt*Qt;const o=r[ee],s=r[ne],a=i.Column.fromFloat32Array(kt,new Float32Array(e,n,Jt));n+=Jt*Qt;const u=i.Column.fromFloat32Array(Nt,new Float32Array(e,n,o));n+=o*Qt;const c=i.Column.fromFloat32Array(Ot,new Float32Array(e,n,s));n+=s*Qt;const l=i.Column.fromFloat32Array(Pt,new Float32Array(e,n,s));n+=s*Qt;const h=i.Column.fromFloat32Array(Rt,new Float32Array(e,n,o+ie));n+=(o+ie)*Qt;const d=i.Column.fromFloat32Array(Ft,new Float32Array(e,n,s+ie));n+=(s+ie)*Qt;const f=[];for(let t=0;t<o;t++)f.push(i.Column.fromFloat32Array(t.toString(),new Float32Array(e,n,s))),n+=s*Qt;const p=i.DataFrame.fromColumns(f),m=new Int32Array(e,n,1)[0],g=m+4-m%4;n+=Qt;const y=i.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+=Qt;const b=i.DataFrame.fromByteArray(new Uint8Array(e,n,v));return n+=w,{kernelType:r[te],kernelParams:a,trainLabels:u,realLabels:y,means:c,stdDevs:l,modelParams:h,modelWeights:d,normalizedTrainData:p,modelInfo:b}}function ce(t,e){return K(this,void 0,void 0,(function*(){const r=ue(new Uint8Array(e)),o=yield function(t,e){return K(this,void 0,void 0,(function*(){let r;const i=async function(t,e,r,i,o,s,a,u,c){return new Promise(((l,h)=>{const d=new Worker(new URL(n.p+n.u(763),n.b));d.postMessage(U(EDA.predictByLSSVM.arguments,[t,e,r,i,o,s,a,u,c])),d.onmessage=function(t){d.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 i.then((t=>{r=t}),(t=>{throw new Error(`Error: ${t}`)})),r}))}(r,t.columns),s=i.Column.string(Xt,o.length),a=r.realLabels.categories;for(let t=0;t<s.length;t++)s.set(t,-1==o.get(t)?a[0]:a[1]);return i.DataFrame.fromColumns([s])}))}function le(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 he(t,e){return t.rowCount<=1e3}var de,fe,pe,me,ge,ye,ve,we;!function(t){t[t.COMPUTE_COMPONENTS=0]="COMPUTE_COMPONENTS",t[t.PERFORM_MVA=1]="PERFORM_MVA",t[t.DEMO=2]="DEMO"}(de||(de={})),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"}(fe||(fe={})),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"}(pe||(pe={})),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"}(me||(me={})),function(t){t.PLS="https://datagrok.ai/help/explore/multivariate-analysis/pls#pls-components",t.MVA="https://datagrok.ai/help/explore/multivariate-analysis/pls",t.MODEL="https://datagrok.ai/help/explore/multivariate-analysis/plots/predicted-vs-reference",t.COEFFS="https://datagrok.ai/help/explore/multivariate-analysis/plots/regression-coefficients",t.LOADINGS="https://datagrok.ai/help/explore/multivariate-analysis/plots/loadings",t.EXPL_VARS="https://datagrok.ai/help/explore/multivariate-analysis/plots/explained-variance",t.SCORES="https://datagrok.ai/help/explore/multivariate-analysis/plots/scores"}(ge||(ge={})),function(t){t[t.DEFAULT=3]="DEFAULT",t[t.MIN=1]="MIN"}(ye||(ye={})),function(t){t.PREFIX="PLS",t.SUFFIX="(predicted)",t.COMP="component",t.COMPS="components"}(ve||(ve={})),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"}(we||(we={}));const be="Int",Ee=6,Ae=[.49,.79,.99],_e=1,Ce=200,Se=200;var Ie;!function(t){t.AXIS="#838383",t.CIRCLE="#0000FF"}(Ie||(Ie={}));const Me="# 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",Ne=[{caption:pe.MODEL,text:"Closer to the line means better price prediction."},{caption:pe.SCORES,text:"The latent factor values for each sample reflect the similarities and dissimilarities among observations."},{caption:pe.LOADINGS,text:"The impact of each feature on the latent factors: higher loading means stronger influence."},{caption:pe.REGR_COEFS,text:"Parameters of the obtained linear model: features make different contribution to the prediction."},{caption:pe.EXPL_VAR,text:"How well the latent components fit source data: closer to one means better fit."}],xe=Ne.map((t=>`# ${t.caption}\n\n${t.text}`)).join("\n\n")+`\n\n# Learn more\n \n * [Multivariate analysis](${ge.MVA}),\n * [ANOVA](https://datagrok.ai/help/explore/anova)`;var Le=function(t,e,n,r){return new(n||(n=Promise))((function(i,o){function s(t){try{u(r.next(t))}catch(t){o(t)}}function a(t){try{u(r.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}u((r=r.apply(t,e||[])).next())}))};const Te=Math.min,Oe=Math.max;function Pe(t){const e=[],n=(t,n)=>{e.push({type:"line",formula:t,width:_e,visible:!0,title:" ",min:-n,max:n,color:Ie.CIRCLE})};return t.forEach((r=>{const i="${"+r+"}";e.push({type:"line",formula:`${i} = 0`,width:_e,visible:!0,title:" ",color:Ie.AXIS}),t.forEach((t=>{const e="${"+t+"}";Ae.forEach((t=>{n(e+` = sqrt(${t*t} - ${i} * ${i})`,t),n(e+` = -sqrt(${t*t} - ${i} * ${i})`,t)}))}))})),e}function Re(t){return Le(this,void 0,void 0,(function*(){H(t.features,t.components),Y(t.predict),q(t.predict);const e=yield async function(t,e,r,i){return new Promise(((t,o)=>{const s=new Worker(new URL(n.p+n.u(412),n.b));s.postMessage(U(EDA.partialLeastSquareRegression.arguments,[e,r,i])),s.onmessage=function(e){s.terminate(),t(k(EDA.partialLeastSquareRegression,e.data))}}))}(t.table,t.features,t.predict,t.components);return{prediction:e[we.PREDICTION],regressionCoefficients:e[we.REGR_COEFFS],tScores:e[we.T_SCORES],uScores:e[we.U_SCORES],xLoadings:e[we.X_LOADINGS],yLoadings:e[we.Y_LOADINGS]}}))}function Fe(n){return Le(this,void 0,void 0,(function*(){const r=n===de.DEMO?t.shell.view(pe.BROWSE).preview.table:t.shell.t;if(null===r)return void t.shell.warning(fe.NO_DF);if(0===r.rowCount)return void t.shell.warning(fe.EMPTY_DF);const o=[],s=[],a=[],u=t=>(t.type===i.COLUMN_TYPE.INT||t.type===i.COLUMN_TYPE.FLOAT)&&0===t.stats.missingValueCount;if(r.columns.toList().forEach((t=>{u(t)?(o.push(t.name),s.push(t)):t.type===i.COLUMN_TYPE.STRING&&a.push(t)})),0===o.length)return void t.shell.warning(fe.NO_COLS);if(1===o.length)return void t.shell.warning(fe.ONE_COL);let c=s[s.length-1];const l=e.input.column(pe.PREDICT,{table:r,value:c,onValueChanged:t=>{c=t,v()},filter:t=>u(t)});let h;l.setTooltip(me.PREDICT);const d=e.input.columns(pe.USING,{table:r,available:o});d.onInput.subscribe((()=>v())),d.setTooltip(me.FEATURES);let f=Te(o.length-1,ye.DEFAULT);const p=e.input.forProperty(i.Property.fromOptions({name:pe.COMPONENTS,inputType:be,defaultValue:f,showPlusMinus:!0,min:ye.MIN}));let m,g,y;p.onInput.subscribe((()=>v())),p.setTooltip(me.COMPONENTS),n===de.COMPUTE_COMPONENTS?(m=pe.PLS,g=ge.PLS,y=me.PLS):(m=pe.MVA,g=ge.MVA,y=me.MVA);const v=()=>{var t;d.value=d.value.filter((t=>t!==c)),h=d.value,p.value=Te(Oe(null!==(t=p.value)&&void 0!==t?t:f,ye.MIN),h.length),f=p.value,E.getButton(pe.RUN).disabled=0===h.length||f<=0};let w=a.length>0?a[0]:void 0;const b=e.input.column(pe.NAMES,{table:r,value:w,onValueChanged:()=>{var t;return w=null!==(t=l.value)&&void 0!==t?t:void 0},filter:t=>t.type===i.COLUMN_TYPE.STRING});b.setTooltip(me.NAMES),b.root.hidden=0===a.length||n===de.COMPUTE_COMPONENTS;const E=e.dialog({title:m,helpUrl:g}).add(e.form([l,d,p,b])).addButton(pe.RUN,(()=>Le(this,void 0,void 0,(function*(){E.close(),yield function(n,r){return Le(this,void 0,void 0,(function*(){var o,s;const a=yield Re(n),u=a.tScores,c=n.table.columns,l=n.features,h=l.names(),d=r===de.COMPUTE_COMPONENTS?ve.PREFIX:pe.XSCORE;if(u.forEach(((t,e)=>{t.name=c.getUnusedName(`${d}${e+1}`),c.add(t)})),r===de.COMPUTE_COMPONENTS)return;const f=r===de.DEMO?t.shell.view(pe.BROWSE).preview:t.shell.tableView(n.table.name),p=i.DataFrame.fromColumns([i.Column.fromStrings(pe.FEATURE,h),a.regressionCoefficients]);a.xLoadings.forEach(((t,e)=>{t.name=p.columns.getUnusedName(`${pe.XLOADING}${e+1}`),p.columns.add(t)}));const m=function(t,e,n,r){const o=n.length,s=t.length,a=e.getRawData(),u=new Float32Array(o),c=r.getRawData();let l=n.stats.avg;for(let e=0;e<s;++e)l-=a[e]*t.byIndex(e).stats.avg;for(let t=0;t<o;++t)u[t]=l+c[t];return i.Column.fromFloat32Array("Debiased",u,o)}(l,a.regressionCoefficients,n.predict,a.prediction);m.name=c.getUnusedName(`${n.predict.name} ${ve.SUFFIX}`),c.add(m);const g=f.addViewer(i.Viewer.scatterPlot(n.table,{title:pe.MODEL,xColumnName:n.predict.name,yColumnName:m.name,showRegressionLine:!0,markerType:i.MARKER_TYPE.CIRCLE,labels:null===(o=n.names)||void 0===o?void 0:o.name,help:ge.MODEL}));a.regressionCoefficients.name=pe.REGR_COEFS;const y=f.addViewer(i.Viewer.barChart(p,{title:pe.REGR_COEFS,splitColumnName:pe.FEATURE,valueColumnName:a.regressionCoefficients.name,valueAggrType:i.AGG.AVG,help:ge.COEFFS,showValueSelector:!1,showStackSelector:!1}));a.xLoadings.forEach(((t,e)=>t.name=`${pe.XLOADING}${e+1}`));const v=f.addViewer(i.Viewer.scatterPlot(p,{title:pe.LOADINGS,xColumnName:`${pe.XLOADING}1`,yColumnName:`${pe.XLOADING}${a.xLoadings.length>1?"2":"1"}`,markerType:i.MARKER_TYPE.CIRCLE,labels:pe.FEATURE,help:ge.LOADINGS})),w=u.map((t=>t.name));a.uScores.forEach(((t,e)=>{t.name=c.getUnusedName(`${pe.YSCORE}${e+1}`),c.add(t),w.push(t.name)}));const b=i.Viewer.scatterPlot(n.table,{title:pe.SCORES,xColumnName:u[0].name,yColumnName:u.length>1?u[1].name:a.uScores[0].name,markerType:i.MARKER_TYPE.CIRCLE,labels:null===(s=n.names)||void 0===s?void 0:s.name,help:ge.SCORES,showViewerFormulaLines:!0});b.meta.formulaLines.addAll(Pe(w)),f.addViewer(b);const E=a.yLoadings.getRawData(),A=a.xLoadings.map((t=>t.getRawData())),_=n.table.rowCount,C=h.length,S=n.components,I=new Float32Array(S),M=[],N=[];for(let t=0;t<C;++t)N.push(new Float32Array(S));I[0]=Math.pow(E[0],2)/_,M.push(`1 ${ve.COMP}`),N.forEach(((t,e)=>{t[0]=Math.pow(A[0][e],2)/_}));for(let t=1;t<S;++t)I[t]=I[t-1]+Math.pow(E[t],2)/_,N.forEach(((e,n)=>e[t]=e[t-1]+Math.pow(A[t][n],2)/_)),M.push(`${t+1} ${ve.COMPS}`);const x=i.DataFrame.fromColumns([i.Column.fromStrings(pe.COMPONENTS,M),i.Column.fromFloat32Array(n.predict.name,I)]);N.forEach(((t,e)=>x.columns.add(i.Column.fromFloat32Array(h[e],t))));const L=f.addViewer(i.Viewer.barChart(x,{title:pe.EXPL_VAR,splitColumnName:pe.COMPONENTS,valueColumnName:n.predict.name,valueAggrType:i.AGG.AVG,help:ge.EXPL_VARS,showCategorySelector:!1,showStackSelector:!1}));if(r===de.DEMO){const n=[g,b,v,y,L].map(((t,e)=>({text:Ne[e].text,showNextTo:t.root})));e.hints.addTextHint({title:pe.EXPLORE,pages:n}).helpUrl=ge.MVA,t.shell.windows.help.showHelp(e.markdown(xe))}}))}({table:r,features:i.DataFrame.fromColumns(h).columns,predict:c,components:f,names:w},n)}))),void 0,y).show({x:Ce,y:Se});setTimeout((()=>{d.value=s.filter((t=>t!==c)),h=d.value}),Ee),t.shell.v.append(E.root)}))}var De,Ue=n(6572);function ke(t){if(t<=0||t>=1)throw new Error(De.INCORRECT_SIGNIFICANCE_LEVEL)}function Ge(t){const e=t.size;if(e<=0)throw new Error(De.INCORRECT_SAMPLE_SIZE);return 1===e?0:(t.sumOfSquares-Math.pow(t.sum,2)/e)/(e-1)}function Be(t,e,n=.05){ke(n);const r=Ge(t),i=Ge(e);return 0===i?r===i:r/i<Ue.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. INPUT ERROR.",t.INCORRECT_SIGNIFICANCE_LEVEL="incorrect significance level. It must be from the interval (0, 1). INPUT ERROR.",t.INCORRECT_SAMPLE_SIZE="incorrect size of sample. DATA FACTORIZAING ERROR.",t.NON_EQUAL_VARIANCES="variances are not equal.",t.NON_NORMAL_DISTRIB="non-normal distribution.",t.UNSUPPORTED_COLUMN_TYPE="unsupported column type.",t.INCORRECT_CATEGORIES_COL_TYPE="incorrect categories column type.",t.ANOVA_FAILED_JUST_ONE_CAT="ANOVA filed: there should be at least 2 categories."}(De||(De={}));class Ve{constructor(t,e,n=!1,r=.05){if(this.isNormDistrib=void 0,this.categories=[],t.type!==i.COLUMN_TYPE.STRING)throw new Error;if(t.length!==e.length)throw new Error(De.NON_EQUAL_FACTORS_VALUES_SIZE);this.setStats(t,e,n,r)}isNormal(){return!0}areVarsEqual(t=.05){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(!Be(n,{sum:this.sums[r],sumOfSquares:this.sumsOfSquares[r],size:this.subSampleSizes[r]},t))return!1;return!0}getOneWayAnova(){const t=this.catCount;if(1===t)throw new Error(De.ANOVA_FAILED_JUST_ONE_CAT);let e=0,n=0;const r=this.size;let i=0;for(let r=0;r<t;++r)e+=this.sums[r],n+=this.sumsOfSquares[r],i+=Math.pow(this.sums[r],2)/this.subSampleSizes[r];const o=n-Math.pow(e,2)/r,s=i-Math.pow(e,2)/r,a=o-s,u=t-1,c=r-t,l=s/u,h=a/c,d=l/h;return{ssBn:s,ssWn:a,ssTot:o,dfBn:u,dfWn:c,dfTot:r-1,msBn:l,msWn:h,fStat:d,pValue:1-Ue.centralF.cdf(d,u,c)}}setStats(t,e,n=!1,r=.05){const o=e.type,s=e.length;switch(o){case i.COLUMN_TYPE.INT:case i.COLUMN_TYPE.FLOAT:this.categories=t.categories;const n=this.categories.length;this.catCount=n,this.size=s;const r=e.getRawData(),o=t.getRawData(),a=new Float64Array(n).fill(0),u=new Float64Array(n).fill(0),c=new Int32Array(n).fill(0);for(let t=0;t<s;++t){const e=o[t];a[e]+=r[t],u[e]+=Math.pow(r[t],2),++c[e]}this.sums=a,this.sumsOfSquares=u,this.subSampleSizes=c;break;default:throw new Error(De.UNSUPPORTED_COLUMN_TYPE)}}}var We=function(t,e,n,r){return new(n||(n=Promise))((function(i,o){function s(t){try{u(r.next(t))}catch(t){o(t)}}function a(t){try{u(r.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}u((r=r.apply(t,e||[])).next())}))};function ze(t,e,r,i){return We(this,void 0,void 0,(function*(){return new Promise((function(o,s){const a=new Worker(new URL(n.p+n.u(682),n.b));a.postMessage({embedX:t,embedY:e,minPts:i,epsilon:r}),a.onmessage=({data:{error:t,clusters:e}})=>{a.terminate(),t?s(t):o(e)}}))}))}n(5540);let je=null;function Ye(){return t=this,e=void 0,r=function*(){if(!je&&(je=yield navigator.gpu.requestAdapter(),null==je))return null;const t=yield je.requestAdapterInfo();return t?qe(t.description,qe(t.vendor,"No GPU description available")):null},new((n=void 0)||(n=Promise))((function(i,o){function s(t){try{u(r.next(t))}catch(t){o(t)}}function a(t){try{u(r.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}u((r=r.apply(t,e||[])).next())}));var t,e,n,r}function qe(t,e){return t&&""!=t?t:e}var He,$e,Ke,Xe,Qe,Ze,Je,tn,en;($e=He||(He={})).EUCLIDEAN="EUCLIDEAN",$e.MANHATTAN="MANHATTAN",He.EUCLIDEAN,He.MANHATTAN,(Xe=Ke||(Ke={})).HAMMING="Hamming",Xe.EUCLIDEAN="Euclidean",Xe.MANHATTAN="Manhattan",Xe.TANIMOTO="Tanimoto",Xe.LEVENSTEIN="Levenshtein",Xe.NEEDLEMAN_WUNSCH="Needlemann-Wunsch",Xe.MONOMER_CHEMICAL_DISTANCE="Monomer chemical distance",Xe.SOKAL="Sokal",Xe.COSINE="Cosine",Xe.ASYMMETRIC="Asymmetric",Xe.Difference="Difference",Xe.OneHot="One-Hot",Ke.HAMMING,Ke.EUCLIDEAN,Ke.MANHATTAN,Ke.TANIMOTO,Ke.LEVENSTEIN,Ke.NEEDLEMAN_WUNSCH,Ke.MONOMER_CHEMICAL_DISTANCE,Ke.SOKAL,Ke.COSINE,Ke.ASYMMETRIC,Ke.Difference,Ke.OneHot,Ke.HAMMING,Ke.EUCLIDEAN,Ke.MANHATTAN,Ke.TANIMOTO,Ke.SOKAL,Ke.COSINE,Ke.ASYMMETRIC,Ke.LEVENSTEIN,Ke.NEEDLEMAN_WUNSCH,Ke.MONOMER_CHEMICAL_DISTANCE,Ke.Difference,Ke.OneHot,new Set([Ke.HAMMING,Ke.LEVENSTEIN,Ke.NEEDLEMAN_WUNSCH,Ke.MONOMER_CHEMICAL_DISTANCE,Ke.OneHot]),new Set([Ke.HAMMING,Ke.EUCLIDEAN,Ke.MANHATTAN,Ke.MONOMER_CHEMICAL_DISTANCE,Ke.LEVENSTEIN,Ke.NEEDLEMAN_WUNSCH,Ke.TANIMOTO,Ke.COSINE,Ke.SOKAL,Ke.ASYMMETRIC,Ke.OneHot,Ke.Difference]),new Set([Ke.EUCLIDEAN,Ke.MANHATTAN,Ke.OneHot,Ke.Difference]),new Set([Ke.EUCLIDEAN,Ke.MANHATTAN,Ke.Difference]),new Set([Ke.EUCLIDEAN,Ke.MANHATTAN,Ke.Difference]),new Set([Ke.TANIMOTO,Ke.COSINE,Ke.SOKAL,Ke.ASYMMETRIC]),function(t){t.ADD="ADD",t.SUB="SUB",t.MULT="MULT"}(Qe||(Qe={})),function(t){t.SQUARE="SQUARE",t.INVERSE="INVERSE",t.TRANSPOSE="TRANSPOSE",t.NORM="NORM",t.COLUMN_NORM="COLUMN_NORM"}(Ze||(Ze={})),function(t){t.SCALARMULT="SCALARMULT",t.SCALARADD="SCALARADD",t.SCALARPOW="SCALARPOW"}(Je||(Je={})),Object.prototype.toString,(en=tn||(tn={})).UMAP="UMAP",en.T_SNE="t-SNE",Promise.resolve(),n(934),n(8903);const nn=2,rn="MCL_OPTIONS";i.SEMTYPE.MOLECULE,i.SEMTYPE.MACROMOLECULE;class on{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 sn="bypassLargeDataWarning",an="show-scatterplot-progress";var un,cn;(cn=un||(un={})).EUCLIDEAN="EUCLIDEAN",cn.MANHATTAN="MANHATTAN";const ln=rxjs;var hn=n(5072),dn=n.n(hn),fn=n(7825),pn=n.n(fn),mn=n(7659),gn=n.n(mn),yn=n(5056),vn=n.n(yn),wn=n(540),bn=n.n(wn),En=n(1113),An=n.n(En),_n=n(7939),Cn={};Cn.styleTagTransform=An(),Cn.setAttributes=vn(),Cn.insert=gn().bind(null,"head"),Cn.domAPI=pn(),Cn.insertStyleElement=bn(),dn()(_n.A,Cn),_n.A&&_n.A.locals&&_n.A.locals;class Sn{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"},Ye().then((t=>{t?(this.useWebGPU.tooltip+=` (${t})`,this.useWebGPU.value=!0):(this.useWebGPU.value=!1,this.useWebGPU.disable=!0)}))}}class In{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 Mn{constructor(n={}){this.editorSettings={},this.columnOptEditors=[],this.columnOptEditorsRoot=e.div(),this.columnParamsEditorRoot=e.div(),this.weightsEditorRoot=e.div(),this.columnFunctionsMap={},this.methodsParams={[tn.UMAP]:new Sn,[tn.T_SNE]:new In},this.dbScanParams=new on,this.methodSettingsDivs=[],this.supportedFunctions={},this.methodSettingsAnchor=e.div(),this.plotEmbeddingsInput=e.input.bool("Plot embeddings",{value:!0}),this.aggregationMethodInput=e.input.choice("Aggregation",{value:un.EUCLIDEAN,items:[un.EUCLIDEAN,un.MANHATTAN]}),this.aggregationMethodInput.setTooltip("Aggregation method for combining distances between columns"),this.onColumnsChanged=new ln.Subject,this.editorSettings=n,this.columnParamsEditorAccordion=e.accordion(),i.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")??"",i=t.options.get("supportedUnits")??"",o=t.options.get("supportedDistanceFunctions")??"";this.editorSettings.semtype&&!e.includes(this.editorSettings.semtype)||this.editorSettings.type&&!r.includes(this.editorSettings.type)||this.editorSettings.units&&!i.includes(this.editorSettings.units)||(this.supportedFunctions[n]={func:t,semTypes:e?e.split(","):[],types:r?r.split(","):[],units:i?i.split(","):[],distanceFunctions:o?o.split(","):[]})})),this.postProcessingEditor=new Ln,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:tn.UMAP,items:[tn.UMAP,tn.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,i=this.supportedFunctions[e].units,o=!n.length||t.semType&&n.includes(t.semType),s=!r.length||r.includes(t.type),a=!i.length||t.meta.units&&i.includes(t.meta.units);o&&s&&a&&(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 Nn(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 i=0;const o=e.table(r,(t=>(i++,t&&t.length>0?t:[this.columnOptEditors[Math.floor((i-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"),o.classList.add("ml-dim-reduction-column-editor-table-root"),this.columnOptEditorsRoot.appendChild(o)},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((i=>{const o=t[i],s="string"===o.type?e.input.string(o.uiName,{value:o.value??"",onValueChanged:t=>{o.value=t}}):"boolean"===o.type?e.input.bool(o.uiName,{value:o.value??!1,onValueChanged:t=>{o.value=t}}):e.input.float(o.uiName,{value:o.value,onValueChanged:t=>{o.value=t}});o.disable?(s.enabled=!1,e.tooltip.bind(s.input??s.root,o.disableTooltip??"")):e.tooltip.bind(s.input??s.root,o.tooltip),r.insertBefore(s.root,n),this.methodSettingsDivs.push(s.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 Nn{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[xn(t.func)]=t.func})),this.preprocessingFunctionInput=e.input.choice("Encoding function",{value:xn(this.supportedFunctions[0].func),items:this.supportedFunctions.map((t=>xn(t.func))),onValueChanged:t=>{const n=this.functionsMap[t];this.preprocessingFunctionSettings={},this.hasExtraSettings=n.inputs.length>2;const i=this.supportedFunctions.find((e=>xn(e.func)===t));this.getSimilarityMetricInput(i),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 i=e.h3(this.column.name,{classes:"ml-dim-reduction-column-editor-column-title"});this.colOptEditors=[i,this.preprocessingFunctionInput.root,this.similarityMetricInputRoot,this.weightInput.root],e.tooltip.bind(i,this.column.name),this.colOptEditors.forEach((t=>t.classList.add("ml-dim-reduction-column-editor-input-root")));const o=e.divH(this.colOptEditors,{classes:"ml-dim-reduction-column-editor-root"});this.accordionDiv=e.divV([]),this.editorDiv.appendChild(o),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(),i=await r.buildEditor(e.div());for(let e=2;e<n.inputs.length;e++){const o=n.inputs[e],s=this.preprocessingFunctionSettings[o.name]||r.inputParams[n.inputs[e].name].value||o.defaultValue;s&&(this.preprocessingFunctionSettings[o.name]=s);const a=i.find((t=>t.property.name===o.name));a&&(null!==this.preprocessingFunctionSettings[o.name]&&void 0!==this.preprocessingFunctionSettings[o.name]&&(a.value=this.preprocessingFunctionSettings[o.name]),a.onChanged.subscribe((t=>{this.preprocessingFunctionSettings[o.name]=t})),t.append(a.root))}return t.style.marginBottom="10px",t}}function xn(t){return t.friendlyName??t.name}class Ln{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",i.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),i=await r.buildEditor(e.div());for(let e=2;e<t.inputs.length;e++){const n=t.inputs[e],o=this._postProcessingArgs[n.name]||r.inputParams[t.inputs[e].name].value||n.defaultValue;o&&(this._postProcessingArgs[n.name]=o);const s=i.find((t=>t.property.name===n.name));s&&(s.onChanged.subscribe((t=>{this._postProcessingArgs[n.name]=t})),this._argsElement.append(s.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 Tn="dimensionality-reducer-terminate-event",On=t=>null==t;function Pn(t,e){return`${e} (${t.length>4?`${t.length} columns`:t.map((t=>t.name)).join(", ")})`}var Rn;!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"}(Rn||(Rn={}));const Fn="copy";var Dn;!function(t){t.KNN_IMPUTER="Impute",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"}(Dn||(Dn={}));const Un="/help/transform/missing-values-imputation";var kn;!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 KNN 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"}(kn||(kn={}));const Gn=[i.COLUMN_TYPE.INT,i.COLUMN_TYPE.FLOAT,i.COLUMN_TYPE.STRING,i.COLUMN_TYPE.DATE_TIME,i.COLUMN_TYPE.QNUM];function Bn(t){switch(t.type){case i.COLUMN_TYPE.INT:return i.INT_NULL;case i.COLUMN_TYPE.FLOAT:case i.COLUMN_TYPE.QNUM:case i.COLUMN_TYPE.DATE_TIME:return i.FLOAT_NULL;case i.COLUMN_TYPE.STRING:return t.max;default:throw new Error(Rn.UNSUPPORTED_COLUMN_TYPE)}}var Vn,Wn,zn;!function(t){t.ONE_HOT="One-hot",t.DIFFERENCE="Difference"}(Vn||(Vn={})),function(t){t.EUCLIDEAN="Euclidean",t.MANHATTAN="Manhattan"}(Wn||(Wn={})),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"}(zn||(zn={}));const jn=1;function Yn(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(Rn.FAILS_TO_PREDICT_IMPUTATION_FAILS);for(const r of t){let t=!0;for(const i of e){const e=n.get(i);if(void 0===e)throw new Error(Rn.FAILS_TO_PREDICT_IMPUTATION_FAILS);if(!e.includes(r)){t=!1;break}}if(t)return!0}}return!1}var qn,Hn=function(t,e,n,r){return new(n||(n=Promise))((function(i,o){function s(t){try{u(r.next(t))}catch(t){o(t)}}function a(t){try{u(r.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}u((r=r.apply(t,e||[])).next())}))};function $n(n){return Hn(this,void 0,void 0,(function*(){if(null!=n||(n=t.shell.t),null===n)return void t.shell.warning(Rn.NO_DATAFRAME);const r=[],o=[],s=[];n.columns.toList().filter((t=>Gn.includes(t.type))).forEach((t=>{s.push(t.name),t.stats.missingValueCount>0&&(r.push(t),o.push(t.name))}));const a=function(t){const e=new Map;for(const n of t){if(!Gn.includes(n.type))throw new Error(Rn.UNSUPPORTED_COLUMN_TYPE);if(0===n.stats.missingValueCount)continue;const t=[],r=Bn(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(Rn.NO_MISSING_VALUES);if(1===s.length)return void t.shell.error(Rn.ONE_AVAILABLE_FEATURE);let u=zn.IN_PLACE>0;const c=e.input.bool(Dn.IN_PLACE,{value:u,onValueChanged:t=>{u=null!=t&&t}});c.setTooltip(kn.IN_PLACE);let l=zn.KEEP_EMPTY>0;const h=e.input.bool(Dn.KEEP_EMPTY,{value:l,onValueChanged:t=>{l=null!=t&&t}});h.setTooltip(kn.KEEP_EMPTY);let d=zn.NEIGHBORS;const f=e.input.int(Dn.NEIGHBORS,{value:d,onValueChanged:t=>{null===t?f.value=d:t>=jn?d=t:f.value=d}});f.setTooltip(kn.NEIGHBORS);let p=Wn.EUCLIDEAN;const m=e.input.choice(Dn.DISTANCE,{value:p,items:[Wn.EUCLIDEAN,Wn.MANHATTAN],onValueChanged:t=>p=null!=t?t:Wn.EUCLIDEAN});m.setTooltip(kn.DISTANCE);let g=r.map((t=>t.name));const y=e.input.columns(Dn.COLUMNS,{table:n,value:n.columns.byNames(o),onValueChanged:t=>{g=t.map((t=>t.name)),E()},available:o});y.setTooltip(kn.TARGET);let v=s;const w=e.input.columns(Dn.FEATURES,{value:n.columns.byNames(s),table:n,onValueChanged:t=>{v=t.map((t=>t.name)),v.length>0?(E(),_.forEach(((t,e)=>t.hidden=!v.includes(e)))):b()},available:s});w.setTooltip(kn.FEATURES);const b=()=>{S.getButton(Dn.RUN).disabled=!0,c.root.hidden=!0,h.root.hidden=!0,f.root.hidden=!0,M.hidden=!0,C.hidden=!0},E=()=>{S.getButton(Dn.RUN).disabled=!1,M.hidden=!1,c.root.hidden=!1,f.root.hidden=!1,m.root.hidden=!1,h.root.hidden=!Yn(g,v,a),1===v.length&&g.forEach((e=>{v[0]===e&&(b(),t.shell.warning(`${Rn.ONE_FEATURE_SELECTED} the column '${e}'`))}))},A=new Map,_=new Map,C=e.divV([]);C.style.overflow="auto",s.forEach((t=>{const r=function(t){switch(t){case i.COLUMN_TYPE.STRING:case i.COLUMN_TYPE.DATE_TIME:return{defaultWeight:zn.WEIGHT,defaultMetric:Vn.ONE_HOT,availableMetrics:[Vn.ONE_HOT]};case i.COLUMN_TYPE.INT:case i.COLUMN_TYPE.FLOAT:case i.COLUMN_TYPE.QNUM:return{defaultWeight:zn.WEIGHT,defaultMetric:Vn.DIFFERENCE,availableMetrics:[Vn.DIFFERENCE,Vn.ONE_HOT]};default:throw new Error(Rn.UNSUPPORTED_COLUMN_TYPE)}}(n.col(t).type);A.set(t,{weight:r.defaultWeight,type:r.defaultMetric});const o=e.input.choice(t,{value:r.defaultMetric,items:r.availableMetrics,onValueChanged:e=>{var n;const i=null!==(n=A.get(t))&&void 0!==n?n:{weight:r.defaultWeight,type:r.defaultMetric};i.type=null!=e?e:r.defaultMetric,A.set(t,i)}});o.root.style.width="50%",o.setTooltip(kn.METRIC),o.root.hidden=!0;const s=i.Property.fromOptions({name:t,inputType:"Float",min:0,max:10,showSlider:!0,step:1}),a=e.input.forProperty(s);a.value=r.defaultWeight,a.onChanged.subscribe((e=>{var n;const i=null!==(n=A.get(t))&&void 0!==n?n:{weight:r.defaultWeight,type:r.defaultMetric};i.weight=null!=e?e:r.defaultWeight,A.set(t,i)})),a.setTooltip(kn.WEIGHT);const u=e.divH([o.root,a.root]);_.set(t,u),C.append(u)}));const S=e.dialog({title:Dn.KNN_IMPUTER,helpUrl:Un});t.shell.v.root.appendChild(S.root),C.hidden=!0,h.root.hidden=!Yn(g,v,a);const I=e.icons.settings((()=>{C.hidden=!C.hidden}),kn.METRIC_SETTINGS),M=e.divH([m.root,I]);let N,x,L=!1;const T=new Promise(((t,e)=>{N=t,x=e}));return S.add(y).add(w).add(M).add(C).add(f).add(c).add(h).show().onOK((()=>{L=!0,S.close(),s.filter((t=>!v.includes(t))).forEach((t=>A.delete(t)));try{const e=function(e,n,r,o,s,a,u){if(a<jn)throw new Error(Rn.INCORRECT_NEIGHBORS);if(e.rowCount<2)throw new Error(Rn.KNN_NOT_ENOUGH_OF_ROWS);if(0===n.length)throw new Error(Rn.KNN_NO_TARGET_COLUMNS);if(0===r.size)throw new Error(Rn.KNN_NO_FEATURE_COLUMNS);1===r.size&&n.forEach((t=>{if(r.has(t))throw new Error(`${Rn.KNN_NO_FEATURE_COLUMNS} can be used for the column '${t}'`)})),n.forEach((t=>{if(!o.has(t))throw new Error(`${Rn.KNN_FAILS}: ${Rn.WRONG_PREDICTIONS}`)}));const c=e.columns;n.forEach((t=>{if(!Gn.includes(c.byName(t).type))throw new Error(Rn.UNSUPPORTED_COLUMN_TYPE)})),r.forEach(((t,n)=>{if(!Gn.includes(e.getCol(n).type))throw new Error(Rn.UNSUPPORTED_COLUMN_TYPE)}));const l=new Map;return n.forEach((n=>{const h=c.byName(n),d=Bn(h),f=h.length,p=h.getRawData(),m=new Uint16Array(h.categories.length),g=[],y=[],v=[],w=[];r.forEach(((t,e)=>{if(e!==h.name){const n=c.byName(e);switch(g.push(n.getRawData()),y.push(Bn(n)),t.type){case Vn.DIFFERENCE:v.push(((e,n)=>t.weight*Math.abs(e-n)));break;case Vn.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 _=0;const C=new Array(a);let S=0,I=0,M=0,N=0,x=0;const L=(t,e)=>{E.forEach(((n,r)=>{A[r]=v[n](g[n][t],g[n][e])}))},T=s===Wn.EUCLIDEAN?()=>{let t=0;for(let e=0;e<_;++e)t+=A[e]*A[e];return Math.sqrt(t)}:()=>{let t=0;for(let e=0;e<_;++e)t+=Math.abs(A[e]);return Math.sqrt(t)},O=t=>{if(p[t]===d)return!1;for(let e=0;e<_;++e)if(g[E[e]][t]===y[E[e]])return!1;return!0},P=t=>{if((t=>{_=0;for(let e=0;e<b;++e)g[e][t]!==y[e]&&(E[_]=e,++_)})(t),0===_)throw new Error(`${Rn.KNN_IMPOSSIBLE_IMPUTATION}: the column "${h.name}", row ${t+1}`);S=0;for(let e=0;e<f;++e)if(O(e)&&e!==t){L(t,e);const n=T();if(S<a)C[S]={index:e,dist:n},++S;else{I=0,M=C[0].dist;for(let t=1;t<S;++t)M<C[t].dist&&(M=C[t].dist,I=t);n<M&&(C[I]={index:e,dist:n})}}if(0===S)throw new Error(`${Rn.KNN_IMPOSSIBLE_IMPUTATION}: the column "${h.name}", row ${t+1}`);if(h.type===i.COLUMN_TYPE.STRING)return(()=>{m.forEach(((t,e,n)=>n[e]=0));let t=0;for(t=0;t<S;++t)++m[p[C[t].index]];let e=m[0],n=0;return m.forEach(((t,r)=>{t>e&&(e=t,n=r)})),n})();N=0;for(let t=0;t<S;++t)N+=p[C[t].index];return x=N/S,h.type===i.COLUMN_TYPE.INT?Math.round(x):x};if(u){for(const e of o.get(n))try{p[e]=P(e)}catch(n){w.push(e),n instanceof Error||t.shell.error(Rn.CORE_ISSUE)}w.length>0&&l.set(n,w),h.set(0,h.get(0))}else{const r=h.clone();let i=1,s=`${n}(${Fn})`;for(;e.columns.contains(s);)s=`${n}(${Fn} ${i})`,++i;r.name=s;const a=r.getRawData();for(const e of o.get(n))try{a[e]=P(e)}catch(n){w.push(e),n instanceof Error||t.shell.error(Rn.CORE_ISSUE)}w.length>0&&l.set(s,w),r.set(0,r.get(0)),e.columns.add(r)}})),l}(n,g,A,a,p,d,u);l||function(t,e){e.forEach(((e,n)=>{const r=t.col(n);if(null!==r){if(!Gn.includes(r.type))throw new Error(Rn.UNSUPPORTED_COLUMN_TYPE);const t=function(t){switch(t.type){case i.COLUMN_TYPE.STRING:case i.COLUMN_TYPE.DATE_TIME:return function(t){const e=Bn(t),n=t.getRawData(),r=n.length;for(let i=0;i<r;++i)if(n[i]!==e)return t.get(i);throw new Error(Rn.EMPTY_COLUMN)}(t);case i.COLUMN_TYPE.INT:case i.COLUMN_TYPE.FLOAT:case i.COLUMN_TYPE.QNUM:return t.stats.avg;default:throw new Error(Rn.UNSUPPORTED_COLUMN_TYPE)}}(r);e.forEach((e=>r.set(e,t)))}}))}(n,e),N()}catch(e){e instanceof Error?t.shell.error(`${Rn.KNN_FAILS}: ${e.message}`):t.shell.error(`${Rn.KNN_FAILS}: ${Rn.CORE_ISSUE}`),x(e)}})).onClose.subscribe((()=>!L&&N())),T}))}class Kn extends Mn{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}),Ye().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"})}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 Xn{constructor(t,e=!1){if(this._length=0,this._version=0,this._updateLevel=0,this._selectedCount=0,this._selectedCountVersion=-1,this._selectedIndexesVersion=-1,this._versionedName="",this._versionedNameVersion=-1,this.SHRINK_THRESHOLD=256,"number"==typeof t){const n=t,r=Xn._createBuffer(n);if(e)for(let t=0;t<r.length;t++)r[t]=-1;this._data=r,this._length=n}else{if(!(t instanceof Uint32Array))throw new Error("Invalid constructor");this._data=t,this._length=e}}getRawData(){return this._data}assureGoez(t,e){if(t<0)throw new Error(`${e} should be greater than zero`)}assureInRange(t,e,n,r){if(t<e||t>n)throw new Error(`Argument ${r} (${t}) out of range (${e}, ${n})`)}copy(t,e,n){for(let r=0;r<n;r++)e[r]=t[r]}copyFrom(t){if(this._length!=t._length)throw new Error(`Lengths differ (${this._length} != ${t._length})`);this.copy(t._data,this._data,this.lengthInInts),this._version++}get length(){return this._length}get buffer(){return this._data}set buffer(t){this._data=t,this._version++}get version(){return this._version}set version(t){this._version=t}incrementVersion(t=!0){this._version++}get lengthInInts(){return Math.floor((this._length+31)/32)}get versionedName(){return this._version==this._versionedNameVersion?this._versionedName:""}set versionedName(t){this._versionedName=t,this._versionedNameVersion=this._version}get self(){return this}setLength(t){if(t<0)throw new Error("should be >= 0");if(t==this._length)return;const e=Math.floor((t+31)/32);if(e>this._data.length||e+this.SHRINK_THRESHOLD<this._data.length){const t=new Uint32Array(e);this.copy(this._data,t,e>this._data.length?this._data.length:e),this._data=t}t>this._length&&(this._length%32>0&&(this._data[this.lengthInInts-1]&=(1<<(this._length%32&31))-1),this._data.fill(0,this.lengthInInts,e)),this._length=t,this._version++}static fromAnd(t,e){if(t._length!=e._length)throw new Error(`Lengths differ (${t._length} != ${e._length})`);const n=new Xn(t._length);n._length=t._length,n._data=Xn._createBuffer(n._length),n._version=0;const r=t.lengthInInts;for(let i=0;i<r;i++)n._data[i]=t._data[i]&e._data[i];return n}static _createBuffer(t){return new Uint32Array(Math.floor((t+31)/32))}static fromValues(t){const e=new Xn(t.length);e._version=0;for(let n=0;n<e._length;n++)t[n]&&(e._data[Math.floor(n/32)]|=1<<(n%32&31));return e}static fromSeq(t,e){const n=new Xn(t);for(let r=0;r<t;++r)n.setBit(r,e(r));return n._version=0,n}static fromString(t){return Xn.fromSeq(t.length,(e=>"1"==t.charAt(e)))}static fromUint32Array(t,e){const n=new Xn(t);return n._data=e,n}static fromBytes(t){const e=t.length,n=new Xn(8*e);n._data=new Uint32Array(Math.floor((e+3)/4)),n._length=8*e;let r=0,i=0;for(;e-i>=4;)n._data[r++]=255&t[i]|(255&t[i+1])<<8|(255&t[i+2])<<16|(255&t[i+3])<<24,i+=4;return e-i==3&&(n._data[r]=(255&t[i+2])<<16),e-i==2&&(n._data[r]|=(255&t[i+1])<<8),e-i==1&&(n._data[r]|=255&t[i]),n._version=0,n}toString(){return`${this._length} bits, ${this.countBits(!0)} set`}equals(t){if(this==t)return!0;if(null==t)return!1;if(this._length!=t._length)return!1;if(0==this._length)return!0;for(let e=0;e<this._data.length-1;e++)if(this._data[e]!=t._data[e])return!1;for(let e=8*(this._data.length-1);e<this._length;e++)if(this.getBit(e)!=t.getBit(e))return!1;return!0}clone(){const t=new Xn(0,!1);return t._data=Uint32Array.from(this._data),t._length=this._length,t._version=this._version,t}init(t,e){this.setAll(!1,!1);for(let e=0;e<this._length;e++)t(e)&&(this._data[Math.floor(e/32)]|=1<<(e%32&31));return this.incrementVersion(e),this}invert(t=!0){for(let t=0;t<this._data.length;t++)this._data[t]^=-1;this.incrementVersion(t)}setAll(t,e=!1){const n=t?-1:0,r=this.lengthInInts;for(let t=0;t<r;t++)this._data[t]=n;this.incrementVersion(e)}setIndexes(t,e=!0,n=!0,r=!0){n&&this.setAll(!e,!1);for(const n of t)this.setFast(n,e);this.incrementVersion(r)}everyIndex(t,e=!0){for(const n of t)if(this.getBit(n)!=e)return!1;return!0}anyIndex(t,e=!0){for(const n of t)if(this.getBit(n)==e)return!0;return!1}setWhere(t,e=!0,n=!0,r=!0,i=!0){if(n&&i&&this.setAll(!e,!1),i)for(let n=0;n<this._length;n++)t(n)&&this.setFast(n,e);else for(let n=0;n<this._length;n++)this.setFast(n,t(n)?e:!e);this.incrementVersion(r)}getRange(t,e){this.assureInRange(t,0,this._length-1,"from"),this.assureInRange(e,0,this._length,"to");const n=[];for(let r=t;r<e;++r)n.push(this.getBit(r));return Xn.fromValues(n)}getRangeAsList(t,e){this.assureInRange(t,0,this._length-1,"from"),this.assureInRange(e,0,this._length,"to");const n=[];for(let r=t;r<e;++r)n.push(this.getBit(r));return n}setRange(t,e,n,r=!0){this.assureInRange(t,0,this._length-1,"from"),this.assureInRange(e,0,this._length-1,"to");const i=Math.min(t,e),o=Math.max(t,e);if(n)for(let t=i;t<=o;t++)this.setTrue(t);else for(let t=i;t<=o;t++)this.setFalse(t);return this.incrementVersion(r),this}setRandom(t,e,n=!0){if(t<0||t>this._length)throw new Error("n must be >= 0 && <= Count");t>this._length/2&&this.setRandom(this._length-t,!e),this.setAll(!e);for(let n=0;n<t;){const t=Math.floor(Math.random()*this._length);this.getBit(t)!=e&&(this.setFast(t,e),n++)}this.incrementVersion(n)}and(t,e=!0){if(this._length!=t._length)throw new Error("Array lengths differ.");for(let e=0,n=this.lengthInInts;e<n;e++)this._data[e]&=t._data[e];return this.incrementVersion(e),this}andNot(t,e=!0){if(this._length!=t._length)throw new Error("Array lengths differ.");const n=this.lengthInInts;for(let e=0;e<n;e++)this._data[e]&=~t._data[e];return this.incrementVersion(e),this}notAnd(t,e=!0){if(this._length!=t._length)throw new Error("Array lengths differ.");for(let e=0,n=this.lengthInInts;e<n;e++)this._data[e]=~this._data[e]&t._data[e];return this.incrementVersion(e),this}not(t=!0){for(let t=0,e=this.lengthInInts;t<e;t++)this._data[t]=~this._data[t];return this.incrementVersion(t),this}or(t,e=!0){if(this._length!=t._length)throw new Error("Array lengths differ.");for(let e=0,n=this.lengthInInts;e<n;e++)this._data[e]|=t._data[e];return this.incrementVersion(e),this}xor(t,e=!0){if(this._length!=t._length)throw new Error("Array lengths differ.");for(let e=0,n=this.lengthInInts;e<n;e++)this._data[e]^=t._data[e];return this.incrementVersion(e),this}insertAt(t,e,n=!1){if(this.assureInRange(t,0,this._length,"pos"),0==e)return;const r=this._length;this.setLength(this._length+e);for(let n=r-1;n>=t;n--)this.setBit(n+e,this.getBit(n));for(let r=t;r<t+e;r++)this.setBit(r,n)}removeAt(t,e=1){if(e<0)throw new Error("n cannot be negative");if(this.assureInRange(t,0,this._length-e,"pos"),this.contains(!0))for(let n=t;n<this._length-e;n++)this.setBit(n,this.getBit(n+e));this.setLength(this._length-e)}removeByMask(t,e=!0){if(this._length!=t.length)throw new Error("length != mask.length");if(t==this)this.setLength(t.countBits(!e)),this.setAll(!e);else{let n=0;for(let r=-1;-1!=(r=t.findNext(r,!e));)this.setFast(n++,this.getBit(r));this._length=n,this._version++}return this}getBit(t){return!!(this._data[Math.floor(t/32)]&1<<(31&t))}setBit(t,e,n=!0){this.setFast(t,e),this._version++}setFast(t,e){e?this._data[Math.floor(t/32)]|=1<<(31&t):this._data[Math.floor(t/32)]&=~(1<<(31&t))}setTrue(t){this._data[Math.floor(t/32)]|=1<<(31&t)}setFalse(t){this._data[Math.floor(t/32)]&=~(1<<(31&t))}trueCount(){return this.countBits(!0)}falseCount(){return this.countBits(!1)}countBits(t){if(0==this._length)return 0;if(this._selectedCountVersion!=this._version){this._selectedCount=0;const t=this.lengthInInts;let e=0;for(;e<t-1;e++)for(let t=this._data[e];0!=t;t>>>=8)this._selectedCount+=Xn._onBitCount[255&t];let n=this._data[e];const r=31&this._length;for(0!=r&&(n&=~(4294967295<<r));0!=n;n>>>=8)this._selectedCount+=Xn._onBitCount[255&n];this._selectedCountVersion=this._version}return t?this._selectedCount:this._length-this._selectedCount}countWhere(t){let e=0;if(this.trueCount()==this._length)for(let n=0;n<this._length;n++)e+=t(n)?1:0;else for(let n=-1;-1!=(n=this.findNext(n,!0));)e+=t(n)?1:0;return e}andWithCountBits(t,e){if(0==this._length)return 0;let n=0;const r=this.lengthInInts;let i=0;for(;i<r-1;i++)for(let e=this._data[i]&t._data[i];0!=e;e>>>=8)n+=Xn._onBitCount[255&e];let o=this._data[i]&t._data[i];const s=31&this._length;for(0!=s&&(o&=~(4294967295<<s));0!=o;o>>>=8)n+=Xn._onBitCount[255&o];return e?n:this._length-n}clear(){this.setLength(0)}contains(t){return this.findNext(-1,t)>=0}get allTrue(){return this.countBits(!0)==this._length}get allFalse(){return this.countBits(!1)==this._length}get anyTrue(){return this.countBits(!0)>0}get anyFalse(){return this.countBits(!1)>0}findNext(t,e=!0){if(this.assureInRange(t,-1,this._length,"index"),t>=this._length-1)return-1;let n=31&(t=t<0?0:t+1);const r=this.lengthInInts;for(let i=Math.floor(t/32);i<r;i++){let r=e?this._data[i]:~this._data[i];if(0!=n)r&=4294967295<<n&4294967295,n=0;else if(!e&&-4294967296==r)continue;for(let e=0;0!=r;e+=8,r>>>=8){const n=Xn._firstOnBit[255&r];if(n>=0)return(t=n+32*i+e)>=this._length?-1:t}}return-1}findPrev(t,e=!0){if(0==t)return-1;this.assureInRange(t,-1,this._length,"index");let n=1+(t=t<0?this._length-1:t-1)&31;for(let r=Math.floor(t/32);r>=0;r--){let t=e?this._data[r]:~this._data[r];0!=n&&(t&=~(4294967295<<n),n=0);for(let e=24;0!=t;e-=8,t<<=8){const n=Xn._lastOnBit[t>>>24];if(n>=0)return n+32*r+e}}return-1}}Xn._onBitCount=Int8Array.from([0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,4,5,5,6,5,6,6,7,5,6,6,7,6,7,7,8]),Xn._firstOnBit=Int8Array.from([-1,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,6,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,7,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,6,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0]),Xn._lastOnBit=Int8Array.from([-1,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7]),function(t){t.none="none",t.bold="bold",t.dashed="dashed"}(qn||(qn={}));class Qn{get currentLineId(){return this._currentLineIdx}set currentLineId(t){t!==this._currentLineIdx&&(this._currentLineIdx=t,this.sp.render(this.ctx))}set linesToRender(t){this.updateLines(t),this.sp.render(this.ctx)}set linesVisibility(t){this.visibility=t,this.sp.render(this.ctx)}constructor(t,e,n,r,i=qn.none){var o;this._currentLineIdx=-1,this.lineClicked=new ln.Subject,this.lineHover=new ln.Subject,this.mouseOverLineId=-1,this.arrowWidth=15,this.sp=t,this.xAxisCol=this.sp.dataFrame.columns.byName(e),this.yAxisCol=this.sp.dataFrame.columns.byName(n),this.canvas=this.sp.getInfo().canvas,this.ctx=this.canvas.getContext("2d"),this.currentLineStyle=i,this.updateLines(r),this.visibility=null!==(o=r.visibility)&&void 0!==o?o:new Xn(this.lines.from.length),r.visibility||this.visibility.setAll(!0,!1),r.arrowSize&&(this.arrowWidth=r.arrowSize),this.canvas.onmousedown=t=>{var e;(null===(e=this.lines)||void 0===e?void 0:e.skipMouseOverDetection)&&(this.mouseOverLineId=this.checkCoordsOnLine(t.offsetX,t.offsetY)),-1!==this.mouseOverLineId&&this.lineClicked.next({x:t.clientX,y:t.clientY,id:this.mouseOverLineId,event:t})},this.canvas.onmousemove=t=>{var e;this.mouseOverLineId=(null===(e=this.lines)||void 0===e?void 0:e.skipMouseOverDetection)?-1:this.checkCoordsOnLine(t.offsetX,t.offsetY),-1!==this.mouseOverLineId&&this.lineHover.next({x:t.clientX,y:t.clientY,id:this.mouseOverLineId,event:t})},t.onEvent("d4-before-draw-scene").subscribe((t=>{this.renderLines()}))}updateLines(t){this.lines=t,this.multipleLinesCounts=new Uint8Array(this.lines.from.length),t.skipMultiLineCalculation?this.multipleLinesCounts.fill(0):this.createMultiLinesIndices()}renderLines(){var t,e,n,r,i,o,s,a,u,c,l,h,d,f,p,m,g;const y=this.sp.getOptions().look,v=this.lines.colors||this.lines.widths||this.lines.opacities||this.lines.drawArrowsArr;v||(this.ctx.lineWidth=null!==(t=this.lines.width)&&void 0!==t?t:1,this.ctx.strokeStyle=`rgba(${null!==(e=this.lines.color)&&void 0!==e?e:"0,128,0"},${null!==(n=this.lines.opacity)&&void 0!==n?n:1})`);const w=y.sizeColumnName?this.sp.dataFrame.col(y.sizeColumnName):null,b=this.sp.dataFrame.filter,E=Math.pow(null!==(r=this.lines.shortLineThreshold)&&void 0!==r?r:5,2);for(let t=0;t<this.lines.from.length;t++)if(b.get(this.lines.from[t])&&b.get(this.lines.to[t])&&this.visibility.getBit(t)){let e=0;const{sizeFrom:n,sizeTo:r}=this.getMarkersSizes(y,w,t),b=this.sp.worldToScreen(this.xAxisCol.get(this.lines.from[t]),this.yAxisCol.get(this.lines.from[t]));let A=null==b?void 0:b.x,_=null==b?void 0:b.y;const C=this.sp.worldToScreen(this.xAxisCol.get(this.lines.to[t]),this.yAxisCol.get(this.lines.to[t]));let S=null==C?void 0:C.x,I=null==C?void 0:C.y;const M=Math.min(this.sp.viewBox.width,this.sp.viewBox.height);if(this.ctx.beginPath(),A&&_&&S&&I&&Math.hypot(S-A,I-_)/M>.01){if(v){const e=(null===(i=this.lines.colors)||void 0===i?void 0:i[t])?null===(o=this.lines.colors)||void 0===o?void 0:o[t]:null!==(s=this.lines.color)&&void 0!==s?s:"0,128,0",n=(null===(a=this.lines.opacities)||void 0===a?void 0:a[t])?null===(u=this.lines.opacities)||void 0===u?void 0:u[t]:null!==(c=this.lines.opacity)&&void 0!==c?c:1;this.ctx.strokeStyle=`rgba(${e},${n})`,this.ctx.lineWidth=(null===(l=this.lines.widths)||void 0===l?void 0:l[t])?null===(h=this.lines.widths)||void 0===h?void 0:h[t]:null!==(d=this.lines.width)&&void 0!==d?d:1}t===this._currentLineIdx&&this.toggleCurrentLineStyle(!0);const y=this.multipleLinesCounts[t];let w=null;if(y){e=this.getLineLength(A,_,S,I);const i=this.getPointOnDistance(A,_,S,I,r,e),o=this.getPointOnDistance(S,I,A,_,n,e);A=i.x,_=i.y,S=o.x,I=o.y,w=this.lines.from[t]>this.lines.to[t]?this.findControlPoint(y,A,_,S,I,t):this.findControlPoint(y,S,I,A,_,t),this.ctx.moveTo(A,_),this.ctx.quadraticCurveTo(w.x,w.y,S,I)}else(!this.lines.skipShortLines||Math.pow(S-A,2)+Math.pow(I-_,2)>E)&&(this.ctx.moveTo(A,_),this.ctx.lineTo(S,I));if((null!==(f=this.lines.drawArrows)&&void 0!==f?f:null===(p=this.lines.drawArrowsArr)||void 0===p?void 0:p.getBit(t))&&(e||(e=this.getLineLength(A,_,S,I)),e>this.arrowWidth)){const t=y?null:this.getPointOnDistance(A,_,S,I,r,e),n=y?w.x:A,i=y?w.y:_;this.canvasArrow(this.ctx,null!==(m=null==t?void 0:t.x)&&void 0!==m?m:A,null!==(g=null==t?void 0:t.y)&&void 0!==g?g:_,n,i)}this.ctx.stroke(),this.ctx.closePath(),t===this._currentLineIdx&&this.toggleCurrentLineStyle(!1)}}this.fillLeftBottomRect()}toggleCurrentLineStyle(t){switch(this.currentLineStyle){case qn.bold:t?this.ctx.lineWidth+=2:this.ctx.lineWidth-=2;break;case qn.dashed:t?this.ctx.setLineDash([5,5]):this.ctx.setLineDash([]);break;default:return}}getMarkersSizes(t,e,n){let r=3,i=3;return e?(r=(t.markerMinSize+(t.markerMaxSize-t.markerMinSize)*e.scale(this.lines.from[n]))/2,i=(t.markerMinSize+(t.markerMaxSize-t.markerMinSize)*e.scale(this.lines.to[n]))/2):t.markerDefaultSize&&(r=t.markerDefaultSize/2,i=t.markerDefaultSize/2),{sizeFrom:r,sizeTo:i}}fillLeftBottomRect(){const t=new Path2D;t.rect(this.sp.yAxisBox.minX,this.sp.yAxisBox.maxY,this.sp.yAxisBox.width,this.sp.xAxisBox.height),this.ctx.fillStyle="white",this.ctx.beginPath(),this.ctx.fill(t),this.ctx.closePath()}createMultiLinesIndices(){const t={};for(let e=0;e<this.lines.from.length;e++){let n=0,r=0;this.lines.from[e]<this.lines.to[e]?(n=this.lines.from[e],r=this.lines.to[e]):(n=this.lines.to[e],r=this.lines.from[e]),t[`${n}|${r}`]?(1===t[`${n}|${r}`].length&&(this.multipleLinesCounts[t[`${n}|${r}`][0]]=1,t[`${n}|${r}`].push(1)),this.multipleLinesCounts[e]=++t[`${n}|${r}`][1]):t[`${n}|${r}`]=[e]}}checkCoordsOnLine(t,e){let n=-1,r=null,i=null;const o=this.sp.getOptions().look,s=o.sizeColumnName?this.sp.dataFrame.col(o.sizeColumnName):null,a=this.sp.dataFrame.filter;for(let u=0;u<this.lines.from.length;u++)if(a.get(this.lines.from[u])&&a.get(this.lines.to[u])&&this.visibility.getBit(u)){const{sizeFrom:a,sizeTo:c}=this.getMarkersSizes(o,s,u),l=this.sp.worldToScreen(this.xAxisCol.get(this.lines.from[u]),this.yAxisCol.get(this.lines.from[u])),h=this.sp.worldToScreen(this.xAxisCol.get(this.lines.to[u]),this.yAxisCol.get(this.lines.to[u]));if(this.multipleLinesCounts[u]){const n=this.getLineLength(l.x,l.y,h.x,h.y),r=this.getPointOnDistance(l.x,l.y,h.x,h.y,c,n),o=this.getPointOnDistance(h.x,h.y,null==l?void 0:l.x,null==l?void 0:l.y,a,n),s=this.lines.from[u]>this.lines.to[u]?this.findControlPoint(this.multipleLinesCounts[u],r.x,r.y,o.x,o.y,u):this.findControlPoint(this.multipleLinesCounts[u],o.x,o.y,r.x,r.y,u);i=this.calculateDistToCurveLine(u,t,e,r,o,s)}else i=this.calculateDistToStraightLine(t,e,l,h);(!r&&null!==i&&i<5||r&&null!==i&&i<r)&&(r=i,n=u)}return n}calculateDistToStraightLine(t,e,n,r){const i=Math.min(n.x,r.x),o=Math.max(n.x,r.x),s=Math.min(n.y,r.y),a=Math.max(n.y,r.y);return t>=i-2&&t<=o+2&&e>=s-2&&e<=a+2?this.distToStraightLineSegment(t,e,n,r):null}distToStraightLineSegment(t,e,n,r){const i=(t,e,n,r)=>Math.pow(t-n,2)+Math.pow(e-r,2),o=i(n.x,n.y,r.x,r.y);if(0==o)return i(t,e,n.x,n.y);let s=((t-n.x)*(r.x-n.x)+(e-n.y)*(r.y-n.y))/o;return s=Math.max(0,Math.min(1,s)),i(t,e,n.x+s*(r.x-n.x),n.y+s*(r.y-n.y))}calculateDistToCurveLine(t,e,n,r,i,o){const s=Math.min(r.x,i.x,o.x),a=Math.max(r.x,i.x,o.x),u=Math.min(r.y,i.y,o.y),c=Math.max(r.y,i.y,o.y);if(e>=s-2&&e<=a+2&&n>=u-2&&n<=c+2){const t=a-s,l=c-u;return this.calculateDistToCurveInRect(e,n,r,o,i,t,l)}return null}calculateDistToCurveInRect(t,e,n,r,i,o,s){const a=Math.floor((o+s)/3),u=1/a,c=new Uint32Array(a),l=new Uint32Array(a),h=new Uint32Array(a);let d=null;const f=new Xn(a);for(let o=0;o<c.length;o++){const s=o*u,a=Math.pow(1-s,2)*n.x+2*s*(1-s)*r.x+Math.pow(s,2)*i.x,f=Math.pow(1-s,2)*n.y+2*s*(1-s)*r.y+Math.pow(s,2)*i.y,p=Math.abs(t-a),m=Math.abs(e-f),g=p+m;(!d||d>g)&&(d=g),h[o]=Math.max(p,m),c[o]=a,l[o]=f}for(let t=0;t<c.length;t++)h[t]<d&&f.setBit(t,!0,!1);let p=null;for(let n=-1;-1!==(n=f.findNext(n));){const r=Math.hypot(c[n]-t,l[n]-e);(!p||p>r)&&(p=r)}return p}getLineLength(t,e,n,r){return Math.sqrt(Math.pow(n-t,2)+Math.pow(r-e,2))}getPointOnDistance(t,e,n,r,o,s){const a=n-o*((n-t)/s),u=r-o*((r-e)/s);return new i.Point(a,u)}findControlPoint(t,e,n,r,o,s){const a=e+(r-e)/2,u=n+(o-n)/2;let c=a-e,l=u-n;const h=Math.sqrt(c*c+l*l);c/=h,l/=h;const d=50*Math.ceil(t/2);return t%2==0?new i.Point(a+d/2*l,u-d/2*c):new i.Point(a-d/2*l,u+d/2*c)}canvasArrow(t,e,n,r,i){const o=Math.atan2(r-e,i-n)+Math.PI;t.moveTo(e-this.arrowWidth*Math.sin(o-Math.PI/10),n-this.arrowWidth*Math.cos(o-Math.PI/10)),t.lineTo(e,n),t.lineTo(e-this.arrowWidth*Math.sin(o+Math.PI/10),n-this.arrowWidth*Math.cos(o+Math.PI/10))}}var Zn=function(t,e,n,r){return new(n||(n=Promise))((function(i,o){function s(t){try{u(r.next(t))}catch(t){o(t)}}function a(t){try{u(r.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}u((r=r.apply(t,e||[])).next())}))};function Jn(t,e){const n=t.length;if(n!==e.length-1)throw new Error("Incorrect parameters count");const r=t.byIndex(0),o=r.length,s=new Float32Array(o);let a=r.getRawData();const u=e[n];let c=e[0];for(let t=0;t<o;++t)s[t]=u+c*a[t];for(let r=1;r<n;++r){a=t.byIndex(r).getRawData(),c=e[r];for(let t=0;t<o;++t)s[t]+=c*a[t]}return i.Column.fromFloat32Array(t.getUnusedName("prediction"),s,o)}const tr=(t,e)=>e<=t?Math.min(10,e):Math.min(10,t);var er;!function(t){t[t.MAX_SAMLPES=1e5]="MAX_SAMLPES",t[t.MAX_FEATURES=1e3]="MAX_FEATURES"}(er||(er={}));class nr{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<=er.MAX_FEATURES&&e.length<=er.MAX_SAMLPES}constructor(t){if(this.specn=null,t)try{const e=new Uint32Array(t.buffer,0,2),n=e[0],r=e[1],o=new Uint8Array(t.buffer,8,n),s=i.DataFrame.fromByteArray(o),a=s.rowCount,u=s.columns,c=u.length,l=new Uint8Array(t.buffer,8+n,r),h=i.DataFrame.fromByteArray(l);if(c<3)throw new Error("incorrect columns count");const d=u.byName(pe.FEATURES).toList(),f=new Float32Array(a);f.set(u.byName(pe.REGR_COEFS).getRawData());const p=c-2,m=new Array(p);for(let t=0;t<p;++t)m[t]=new Float32Array(a),m[t].set(u.byIndex(t+2).getRawData());this.specn={params:f,loadings:m,names:d,dim:a-1,components:c-2,scores:h}}catch(t){throw new Error(`Failed to load model: ${t instanceof Error?t.message:"the platform issue"}`)}}fit(t,e,n){return r=this,o=void 0,a=function*(){const r=yield Re({table:i.DataFrame.fromColumns([e]),features:t,predict:e,components:n,names:void 0}),o=t.names();o.push("_");const s=this.getRegrCoeffs(t,e,r.regressionCoefficients),a=this.getLoadings(n,r.xLoadings);this.specn={names:o,params:s,loadings:a,components:n,dim:t.length,scores:this.getScoresDf(r)},this.computeExplVars(e.length,n,r.yLoadings)},new((s=void 0)||(s=Promise))((function(t,e){function n(t){try{u(a.next(t))}catch(t){e(t)}}function i(t){try{u(a.throw(t))}catch(t){e(t)}}function u(e){var r;e.done?t(e.value):(r=e.value,r instanceof s?r:new s((function(t){t(r)}))).then(n,i)}u((a=a.apply(r,o||[])).next())}));var r,o,s,a}getLoadings(t,e){const n=Array(t),r=e[0].length+1;for(let i=0;i<t;++i)n[i]=new Float32Array(r),n[i].set(e[i].getRawData());return n}getRegrCoeffs(t,e,n){const r=t.length,i=new Float32Array(r+1),o=n.getRawData();let s=0;for(let e=0;e<r;++e)i[e]=o[e],s+=o[e]*t.byIndex(e).stats.avg;return i[r]=e.stats.avg-s,i}computeExplVars(t,e,n){if(null===this.specn)throw new Error("Failed to compute explained variances");const r=n.getRawData(),i=this.specn.loadings[0].length-1;let o=Math.pow(r[0],2)/t;this.specn.loadings[0][i]=o;for(let n=1;n<e;++n)o+=Math.pow(r[n],2)/t,this.specn.loadings[n][i]=o}toBytes(){if(null===this.specn)throw new Error("Failed to pack untrained model");const t=i.DataFrame.fromColumns([i.Column.fromStrings(pe.FEATURES,this.specn.names),i.Column.fromFloat32Array(pe.REGR_COEFS,this.specn.params)]);this.specn.loadings.forEach(((e,n)=>t.columns.add(i.Column.fromFloat32Array(`${pe.XLOADING}${n+1}`,e))));const e=t.toByteArray(),n=e.length,r=this.specn.scores.toByteArray(),o=r.length,s=n+o+8,a=new Uint8Array(64*(Math.ceil(s/64)+1)),u=new Uint32Array(a.buffer,0,2);return u[0]=n,u[1]=o,a.set(e,8),a.set(r,8+n),a}predict(t){if(null===this.specn)throw new Error("Predicting failed: model is not trained");return Jn(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=i.DataFrame.fromColumns([i.Column.fromStrings(pe.FEATURES,this.specn.names.slice(0,-1)),i.Column.fromFloat32Array(pe.REGR_COEFS,this.specn.params,e)]),r=n.columns,o=r.length,s=this.specn.components;return this.specn.loadings.forEach(((t,r)=>n.columns.add(i.Column.fromFloat32Array(`${pe.XLOADING}${r+1}`,t,e)))),t.push(i.Viewer.scatterPlot(n,{title:pe.LOADINGS,xColumnName:r.byIndex(o).name,yColumnName:r.byIndex(o+(s>1?1:0)).name,markerType:i.MARKER_TYPE.CIRCLE,labels:pe.FEATURES,help:ge.LOADINGS})),t.push(i.Viewer.barChart(n,{title:pe.REGR_COEFS,splitColumnName:pe.FEATURES,valueColumnName:pe.REGR_COEFS,valueAggrType:i.AGG.AVG,help:ge.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]=`${ve.COMP} 1`,r[0]=this.specn.loadings[0][e];for(let i=1;i<t;++i)n[i]=`${ve.COMPS} ${i+1}`,r[i]=this.specn.loadings[i][e];return i.Viewer.barChart(i.DataFrame.fromColumns([i.Column.fromStrings(ve.COMPS,n),i.Column.fromFloat32Array(pe.EXPL_VAR,r)]),{title:pe.EXPL_VAR,splitColumnName:ve.COMPS,valueColumnName:pe.EXPL_VAR,valueAggrType:i.AGG.AVG,help:ge.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=`${pe.XSCORE}${e+1}`)),n.forEach(((t,e)=>t.name=`${pe.YSCORE}${e+1}`)),i.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=i.Viewer.scatterPlot(this.specn.scores,{title:pe.SCORES,xColumnName:t[0],yColumnName:t[1],markerType:i.MARKER_TYPE.CIRCLE,help:ge.SCORES,showViewerFormulaLines:!0});return e.meta.formulaLines.addAll(Pe(t)),e}}var rr=function(t,e,n,r){return new(n||(n=Promise))((function(i,o){function s(t){try{u(r.next(t))}catch(t){o(t)}}function a(t){try{u(r.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}u((r=r.apply(t,e||[])).next())}))};const ir="Avg-s",or="Stddev-s";var sr;!function(t){t[t.MAX_SAMLPES=5e4]="MAX_SAMLPES",t[t.MAX_FEATURES=100]="MAX_FEATURES"}(sr||(sr={}));class ar{static isApplicable(t,e){for(const e of t)if(!e.matches("numerical"))return!1;return e.type===i.COLUMN_TYPE.STRING}static isInteractive(t,e){return t.length<=sr.MAX_FEATURES&&e.length<=sr.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=i.DataFrame.fromByteArray(n),o=r.columns,s=o.length;if(s<3)throw new Error("incorrect columns count");this.classesCount=s-2,this.featuresCount=r.rowCount-1;const a=this.classesCount;this.params=new Array(a),this.categories=new Array(r.rowCount);for(let t=0;t<a;++t){const e=o.byIndex(t);if(this.categories[t]=e.name,e.type!==i.COLUMN_TYPE.FLOAT)throw new Error(`Incorrect input column type. Expected: float, passed: ${e.type}`);this.params[t]=e.getRawData()}const u=o.byName(ir);if(u.type!==i.COLUMN_TYPE.FLOAT)throw new Error("incorrect average values column type");this.avgs=u.getRawData();const c=o.byName(or);if(c.type!==i.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]=i.Column.fromFloat32Array(this.categories[n],this.params[n]);e[t]=i.Column.fromFloat32Array(ir,this.avgs),e[t+1]=i.Column.fromFloat32Array(or,this.stdevs);const n=i.DataFrame.fromColumns(e).toByteArray(),r=n.length,o=new Uint8Array(r+4);return new Uint32Array(o.buffer,0,1)[0]=r,o.set(n,4),o}fit(t,e){return rr(this,arguments,void 0,(function*(t,e,n=1,r=100,o=.1,s=.001){if(t.length!==this.featuresCount)throw new Error("Training failes - incorrect features count");if(n<=0||r<1||o<=0||s<=0)throw new Error("Training failes - incorrect fitting hyperparameters");this.extractStats(t);const a=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,i,o,s,a,u,c,l){return g(EDA,"fitSoftmax",[t,e,n,r,i,o,s,a,u,c,l])}(t,i.Column.fromFloat32Array("avgs",this.avgs,this.featuresCount),i.Column.fromFloat32Array("stdevs",this.stdevs,this.featuresCount),i.Column.fromInt32Array("targets",e.getRawData(),a),u,r,n,o,s,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(i){try{this.params=yield this.fitSoftmaxParams(t,e,r,n,o,s)}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!==i.COLUMN_TYPE.INT&&n.type!==i.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 o of t){if(o.type!==i.COLUMN_TYPE.INT&&o.type!==i.COLUMN_TYPE.FLOAT)throw new Error("Training failes - incorrect features type");const t=o.getRawData(),s=this.avgs[r],a=this.stdevs[r];if(a>0)for(let i=0;i<e;++i)n[i][r]=(t[i]-s)/a;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 o=0;for(const n of t){if(n.type!==i.COLUMN_TYPE.INT&&n.type!==i.COLUMN_TYPE.FLOAT)throw new Error("Training failes - incorrect features type");const t=n.getRawData(),s=this.avgs[o],a=this.stdevs[o];if(a>0)for(let n=0;n<e;++n)r[o][n]=(t[n]-s)/a;else for(let t=0;t<e;++t)r[o][t]=0;++o}return r}preprocessedTargets(t){if(t.type!==i.COLUMN_TYPE.STRING)throw new Error("Training failes - incorrect target type");const e=this.classesCount,n=t.length,r=t.getRawData(),o=new Array(n),s=new Uint32Array(e).fill(0);for(let t=0;t<n;++t)o[t]=new Uint8Array(e).fill(0);for(let t=0;t<n;++t)o[t][r[t]]=1,++s[r[t]];return{oneHot:o,weights:s}}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,o=this.classesCount;let s,a;const u=new Float32Array(o);let c,l,h;const d=new Array(n);for(let t=0;t<n;++t){s=e[t],c=0;for(let t=0;t<o;++t){a=this.params[t],c=a[r];for(let t=0;t<r;++t)c+=a[t]*s[t];u[t]=Math.exp(c)}l=u[0],h=0;for(let t=1;t<o;++t)l<u[t]&&(l=u[t],h=t);d[t]=this.categories[h]}return i.Column.fromStrings("predicted",d)}fitSoftmaxParams(t,e,r,i,o,s){return rr(this,void 0,void 0,(function*(){const a=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:a.oneHot,classesWeights:a.weights,targetRaw:e.getRawData(),iterations:r,rate:i,penalty:o,tolerance:s}),l.onmessage=function(t){l.terminate(),u(t.data.params),console.log(`Loss: ${t.data.loss}`)}}))}))}}var ur,cr,lr;!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"}(ur||(ur={})),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"}(cr||(cr={})),function(t){t[t.MODEL=1e7]="MODEL",t[t.UTILS=1]="UTILS",t[t.PACK=128]="PACK",t[t.SIZE=4]="SIZE"}(lr||(lr={}));const hr=i.FLOAT_NULL;var dr;!function(t){t.PREDICT="Prediction",t.TYPE="Type",t.PARAMS="Params count",t.CATS="Categories",t.CATS_SIZE="Categories size"}(dr||(dr={}));class fr{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<=cr.SAMPLES_LOW?n<=cr.FEATURES_LOW:r<=cr.SAMLPES_MID?n<=cr.FEATURES_MID:r<=cr.SAMLPES_HIGH&&n<=cr.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+=lr.SIZE;const o=i.DataFrame.fromByteArray(new Uint8Array(t.buffer,n,r));n+=r,this.targetType=o.get(dr.TYPE,0);const s=o.get(dr.PARAMS,0),a=o.get(dr.CATS_SIZE,0);if(a>0){const r=i.DataFrame.fromByteArray(new Uint8Array(t.buffer,n,a));this.targetCategories=null===(e=r.col(dr.CATS))||void 0===e?void 0:e.toList()}n+=a,n=4*Math.ceil(n/4),this.modelParams=new Int32Array(t.buffer,n,s)}catch(t){throw new Error(`Failed to load model: ${t instanceof Error?t.message:"the platform issue"}`)}}fit(t,e){return r=this,o=arguments,a=function*(t,e,r=ur.ITERATIONS,o=ur.ETA,s=ur.MAX_DEPTH,a=ur.LAMBDA,u=ur.ALPHA){this.targetType=e.type,this.targetType===i.COLUMN_TYPE.STRING&&(this.targetCategories=e.categories),this.modelParams=yield async function(t,e,r,i,o,s,a,u,c,l){return new Promise(((h,d)=>{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:i,eta:o,maxDepth:s,lambda:a,alpha:u,missingValue:r}),v.onmessage=function(t){v.terminate(),h(t.data.params)}}))}(t,e,hr,r,o,s,a,u,lr.MODEL,lr.UTILS)},new((s=void 0)||(s=Promise))((function(t,e){function n(t){try{u(a.next(t))}catch(t){e(t)}}function i(t){try{u(a.throw(t))}catch(t){e(t)}}function u(e){var r;e.done?t(e.value):(r=e.value,r instanceof s?r:new s((function(t){t(r)}))).then(n,i)}u((a=a.apply(r,o||[])).next())}));var r,o,s,a}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,i=t.length,o=n.length;let s=XGBoostModule.HEAPF32;const a=XGBoostModule.HEAP32,u=XGBoostModule._malloc(r*i*4),c=XGBoostModule._malloc(4*r),l=XGBoostModule._malloc(4*o);for(let e=0;e<i;++e){const n=t.byIndex(e).getRawData();for(let t=0;t<r;++t)s[u/4+t+e*r]=n[t]}for(let t=0;t<o;++t)a[l/4+t]=n[t];XGBoostModule._predict(u,r,i,e,l,o,c,r),s=XGBoostModule.HEAPF32;const h=new Float32Array(r);for(let t=0;t<r;++t)h[t]=s[c/4+t];return XGBoostModule._free(u),XGBoostModule._free(c),XGBoostModule._free(l),h}(t,hr,this.modelParams);switch(this.targetType){case i.COLUMN_TYPE.STRING:return this.stringColPrediction(e);case i.COLUMN_TYPE.INT:return this.intColPrediction(e);case i.COLUMN_TYPE.BIG_INT:return this.bigIntColPrediction(e);default:return i.Column.fromFloat32Array(dr.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?i.DataFrame.fromColumns([i.Column.fromList(i.COLUMN_TYPE.STRING,dr.CATS,this.targetCategories)]).toByteArray():void 0,e=void 0!==t?t.length:0,n=this.modelParams.length*this.modelParams.BYTES_PER_ELEMENT,r=i.DataFrame.fromColumns([i.Column.fromStrings(dr.TYPE,[this.targetType]),i.Column.fromInt32Array(dr.PARAMS,new Int32Array([this.modelParams.length])),i.Column.fromInt32Array(dr.CATS_SIZE,new Int32Array([e]))]).toByteArray(),o=r.length,s=64*Math.ceil((lr.SIZE+o+e+n+lr.PACK)/64),a=new Uint8Array(s);let u=0;return new Uint32Array(a.buffer,u,1)[0]=o,u+=lr.SIZE,a.set(r,u),u+=o,e>0&&a.set(t,u),u+=e,u=4*Math.ceil(u/4),a.set(new Uint8Array(this.modelParams.buffer),u),a}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 i=0;i<e;++i)n[i]=this.targetCategories[(o=Math.round(t[i]),Math.max(0,Math.min(o,r)))];var o;return i.Column.fromList(i.COLUMN_TYPE.STRING,dr.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 i.Column.fromInt32Array(dr.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 i.Column.fromBigInt64Array(dr.PREDICT,n)}}var pr=function(t,e,n,r){return new(n||(n=Promise))((function(i,o){function s(t){try{u(r.next(t))}catch(t){o(t)}}function a(t){try{u(r.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}u((r=r.apply(t,e||[])).next())}))};const mr=new i.Package;function gr(){t.shell.info(mr.webRoot)}function yr(){return pr(this,void 0,void 0,(function*(){yield async function(){await initEDA()}(),yield async function(){await initXGBoostModule()}()}))}function vr(t,e,n,r,o){return pr(this,void 0,void 0,(function*(){const s=e.getRawData(),a=n.getRawData(),u=yield ze(s,a,r,o),c=t.columns.getUnusedName("Cluster (DBSCAN)"),l=i.Column.fromInt32Array(c,u);return t.columns.add(l),l}))}function wr(e,r,i,o,s){return pr(this,void 0,void 0,(function*(){const a=yield function(t,e,r,i,o){return $(this,void 0,void 0,(function*(){H(e,r);const t=i?1:0,s=o?1:0;return yield async function(t,e,r,i,o){return new Promise(((t,s)=>{const a=new Worker(new URL(n.p+n.u(91),n.b));a.postMessage(U(EDA.principalComponentAnalysis.arguments,[e,r,i,o])),a.onmessage=function(e){a.terminate(),t(k(EDA.principalComponentAnalysis,e.data))}}))}(0,e,r,t,s)}))}(0,r,i,o,s);if(function(t,e){for(const t of e.toList())t.name="PC"+t.name}(0,a.columns),null===e.id)t.shell.addTableView(a);else{const t=e.columns;for(const e of a.columns)e.name=t.getUnusedName(e.name),t.add(e)}}))}function br(e,n,r,o){return pr(this,void 0,void 0,(function*(){const s=e.dataFrame;if(null===s)return;const a=yield vr(s,e,n,r,o);s.changeColumnType(a,"string");const u=[e.name,n.name],c=t.shell.tableView(s.name);if(c)for(const t of c.viewers)if(t instanceof i.ScatterPlotViewer&&u.includes(t.props.xColumnName)&&u.includes(t.props.yColumnName))return void(t.props.colorColumnName=a.name)}))}function Er(t,e){const n=t.stats.max-t.stats.min;return{entries:t.toList(),options:{range:n}}}function Ar(t,e){return{entries:t.toList(),options:{}}}function _r(){return pr(this,void 0,void 0,(function*(){const r=new Mn,o=e.dialog("Dimensionality reduction").add(r.getEditor()).onOK((()=>pr(this,void 0,void 0,(function*(){const o=r.getParams();0!==o.columns.length&&(yield async function(r,o,s,a,u,c,l,h=!0,d=!1,f={preprocessingFuncArgs:[]},p={},m=null,g={}){const y={showXAxis:!1,showYAxis:!1,showXSelector:!1,showYSelector:!1};if(o.length!==a.length||o.length!==c.length||o.length!==u.length||o.length!==f.preprocessingFuncArgs.length)throw new Error("columns, metrics and preprocessing functions, weights and function argumentsmust have the same length");const v=h?p.tableView??t.shell.tableView(r.name)??t.shell.addTableView(r):null,w=async()=>{const w=i.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,a){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(i.Column.float(E[0],r.rowCount)),c=r.columns.add(i.Column.float(E[1],r.rowCount)),h&&!b&&(b=v.scatterPlot({...y,x:E[0],y:E[1],title:p.scatterPlotName??Pn(o,s)}))),p[an]&&(b?.root&&e.setUpdateIndicator(b.root,!1),u.init((t=>a[0]?a[0][t]:void 0)),c.init((t=>a[1]?a[1][t]:void 0)));const l=t/n*100;w.update(l,`Running ${p.scatterPlotName??"dimensionality reduction"}... ${l.toFixed(0)}%`)}async function _(){r.columns.add(i.Column.float(E[0],r.rowCount)),r.columns.add(i.Column.float(E[1],r.rowCount));let d=null;h&&(b=v.scatterPlot({...y,x:E[0],y:E[1],title:p.scatterPlotName??Pn(o,s)}),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(Tn,{}),m.unsubscribe(),d?.(),w.close())})),g=new Promise((async(e,r)=>{try{d=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,i=e.inputs[1].name,{entries:s,options:u}=await e.apply({[n]:o[t],[i]:a[t],...f.preprocessingFuncArgs[t]??{}});r.push({entries:s,options:u}),f.distanceFnArgs.push(u)}else{const e=o[t].toList(),n={};r.push({entries:e,options:n}),f.distanceFnArgs.push(n)}}e(await async function(e,r,i,o,s,a,u){let c=await async function(e,r,i,o,s,a,u){if(!a.distanceFnArgs)throw new Error("options.distanceFnArgs must be defined");if(e.length!==r.length||e.length!==a.distanceFnArgs.length||e.length!==o.length)throw new Error("data, metrics and options and weights must have the same length");return new Promise((function(c,l){const h=new Worker(new URL(n.p+n.u(234),n.b));h.postMessage({columnsData:e,distanceMetrics:r,method:i,options:a,weights:o,aggregationMethod:s});const d=t.events.onCustomEvent(Tn).subscribe((()=>{try{h?.terminate()}finally{d.unsubscribe()}}));h.onmessage=({data:{error:t,embedding:e,epochNum:n,epochsLength:r}})=>{On(n)||On(r)?(d.unsubscribe(),t?l(t):c(e),setTimeout((()=>h.terminate()),100)):u&&u(n,r,e)}}))}(e,i,r,o,s,a,u);return c=c.map((t=>function(t){const e=t.length;let n=0,r=0;for(let i=0;i<e;++i)n+=t[i],r+=Math.pow(t[i],2);const i=n/e,o=1/Math.sqrt(r/e-Math.pow(i,2));for(let n=0;n<e;++n)t[n]=(t[n]-i)*o;return t}(t))),c}(r.map((t=>t.entries)),s,a,u,l,f,p[sn]?void 0:A))}catch(t){r(t)}})),_=await g;return w.close(),m.unsubscribe(),_}const C=await _();if(d&&C){const S=i.TaskBarProgressIndicator.create("Clustering embeddings ...");try{const I=await ze(C[0],C[1],f.dbScanEpsilon??.01,f.dbScanMinPts??4),M=r.columns.getUnusedName("Cluster (DBSCAN)");r.columns.addNewString(M).init((t=>I[t].toString())),b&&(b.props.colorColumnName=M)}catch(N){t.shell.error("Clustering embeddings failed"),console.error(N)}finally{S.close()}}if(C){const x=r.columns.byName(E[0]),L=r.columns.byName(E[1]);if(x.init((t=>C[0][t])),L.init((t=>C[1][t])),m)try{const T=m.inputs[0].name,O=m.inputs[1].name;await m.prepare({[T]:x,[O]:L,...g}).call(!0)}catch(P){t.shell.error("Post-processing failed"),console.error(P)}if(b)return e.setUpdateIndicator(b.root,!1),b.helpUrl="/help/compute/sequence-space",b}}catch(R){t.shell.error("Dimensionality reduction failed"),console.error(R),w.close(),b&&e.setUpdateIndicator(b.root,!1)}};return new Promise((async(t,n)=>{try{if(p.fastRowCount&&r.rowCount>p.fastRowCount&&!p[sn])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)}}))}(o.table,o.columns,o.methodName,o.distanceMetrics,o.weights,o.preprocessingFunctions,o.aggreaggregationMethod,!!o.plotEmbeddings,!!o.clusterEmbeddings,o.options,{fastRowCount:1e4},o.postProcessingFunction,o.postProcessingFunctionArgs))})))).show();o.helpUrl="https://datagrok.ai/help/explore/dim-reduction.md";const s=()=>{const t=r.columnsInput.value,e=o.getButton("OK");e&&(t&&0!==t.length?e.classList.remove("disabled"):e.classList.add("disabled"))};o.history((()=>({editorSettings:r.getStringInput()})),(t=>r.applyStringInput(t.editorSettings))),r.onColumnsChanged.subscribe((()=>{try{s()}catch(t){console.error(t)}})),s()}))}function Cr(n){try{const t=new Kn;e.dialog("Markov clustering").add(t.getEditor()).onOK((()=>pr(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()}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}`),mr.logger.error(n,void 0,r)}}function Sr(e,n,r,o,s,a,u){return pr(this,arguments,void 0,(function*(e,n,r,o,s,a,u,c=80,l=10,h=!1,d=0,f=5){var p;const m=null!==(p=t.shell.tableView(e.name))&&void 0!==p?p:t.shell.addTableView(e),g=JSON.stringify({cols:n.map((t=>t.name)),metrics:r,weights:o,aggregationMethod:s,preprocessingFuncs:a.map((t=>{var e;return null!==(e=null==t?void 0:t.name)&&void 0!==e?e:null})),preprocessingFuncArgs:u,threshold:c,maxIterations:l,useWebGPU:h,inflate:d,minClusterSize:null!=f?f:5});return e.setTag(rn,g),m.addViewer(i.VIEWER.SCATTER_PLOT,{title:"MCL",initializationFunction:"EDA:MCLInitializationFunction"})}))}function Ir(r){return pr(this,void 0,void 0,(function*(){const o=r.dataFrame;if(null===o)throw new Error("Data frame of the scatter plot is null");const s=o.getTag(rn);if(!s)throw new Error("MCL options tag on the dataFrame is not found");const a=JSON.parse(s),u=a.cols.map((t=>o.columns.byName(t))),c=a.preprocessingFuncs.map((t=>t?i.Func.byName(t):null)),l=yield async function(r,o,s,a,u,c,l,h=80,d=10,f=!1,p=2,m=5,g){const y=t.shell.tableView(r.name)??t.shell.addTableView(r),v=g??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:i,options:a}=await e.apply({[n]:o[t],[r]:s[t],...l[t]??{}});b.push({entries:i,options:a}),w.push(a??{})}else{const e=o[t].toList(),n={};b.push({entries:e,options:n}),w.push(n)}}const E=function(t,e,r,i,o,s,a=10,u=!1,c=2){const l=new Worker(new URL(n.p+n.u(980),n.b));let h;return l.postMessage({data:t,threshold:e,weights:r,aggregationMethod:i,distanceFns:o,distanceFnArgs:s,maxIterations:a,useWebGPU:u,inflate:c}),{promise:new Promise(((t,e)=>{h=t,l.onmessage=e=>{setTimeout((()=>l.terminate()),100),t(e.data.res)},l.onerror=t=>{setTimeout((()=>l.terminate()),100),e(t)}})),terminate:()=>{try{h(null),l.terminate()}catch(t){console.error(t)}}}}(b.map((t=>t.entries)),h,a,u,s,w,d,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())})),_=await E.promise;if(!_)return;const C=r.columns.getUnusedName("Cluster (MCL)"),S=r.columns.getUnusedName("EmbedX (MCL)"),I=r.columns.getUnusedName("EmbedY (MCL)"),M={};_.clusters.forEach((t=>{M[t]||(M[t]=0),M[t]++}));const N=new Uint32Array(_.embedX.length);for(let t=0;t<_.is.length;t++)N[_.is[t]]++,N[_.js[t]]++;const x=r.columns.getUnusedName("Cluster size (MCL)"),L=r.columns.getUnusedName("Connectivity (MCL)"),T=r.columns.addNewFloat(S);T.init((t=>_.embedX[t]));const O=r.columns.addNewFloat(I);O.init((t=>_.embedY[t]));const P=r.columns.addNewString(C);P.init((t=>M[_.clusters[t]]>=m?_.clusters[t].toString():"-1"));const R={"-1":i.Color.setAlpha(i.Color.lightBlue,100)};P.setTag(i.TAGS.COLOR_CODING_CATEGORICAL,JSON.stringify(R)),P.temp[i.TAGS.COLOR_CODING_CATEGORICAL]=R;const F=r.columns.addNewInt(x);F.init((t=>M[_.clusters[t]]));const D=r.columns.addNewInt(L);D.init((t=>N[t])),v.props.xColumnName=S,v.props.yColumnName=I,v.props.colorColumnName=C,v.props.markerDefaultSize=6,A.unsubscribe();const U=[],k=[],G=new Map;for(let t=0;t<_.is.length;t++){let e=_.clusters[_.is[t]],n=_.clusters[_.js[t]];if(e===n){U.push(_.is[t]),k.push(_.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 i=r.get(n);i||(i=0),i>=20||(i++,r.set(n,i),U.push(_.is[t]),k.push(_.js[t]))}return new Qn(v,S,I,{from:new Uint32Array(U),to:new Uint32Array(k),drawArrows:!1,opacity:.3,skipMultiLineCalculation:!0,skipShortLines:!0,skipMouseOverDetection:!0,shortLineThreshold:6,width:.75,color:"128,128,128"},qn.none),e.setUpdateIndicator(v.root,!1),{sc:v,embedXCol:T,embedYCol:O,clusterCol:P,clusterCounterCol:F,connectivityCol:D}}(o,u,a.metrics,a.weights,a.aggregationMethod,c,a.preprocessingFuncArgs,a.threshold,a.maxIterations,a.useWebGPU,a.inflate,a.minClusterSize,r);return null==l?void 0:l.sc}))}function Mr(t,e,n,r,i){return pr(this,void 0,void 0,(function*(){return yield Re({table:t,features:e,predict:n,components:r,names:i})}))}function Nr(){return pr(this,void 0,void 0,(function*(){yield Fe(de.COMPUTE_COMPONENTS)}))}function xr(){return pr(this,void 0,void 0,(function*(){yield Fe(de.PERFORM_MVA)}))}function Lr(){return pr(this,void 0,void 0,(function*(){yield function(){return Le(this,void 0,void 0,(function*(){t.shell.addTableView(i.DataFrame.fromColumns([i.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"]),i.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])),i.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])),i.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])),i.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])),i.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])),i.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])),i.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])),i.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])),i.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])),i.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])),i.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])),i.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])),i.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])),i.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])),i.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])),i.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(Me)),t.shell.windows.showContextPanel=!1,t.shell.windows.showProperties=!1,yield Fe(de.DEMO)}))}()}))}function Tr(t,e,n){return pr(this,void 0,void 0,(function*(){return ae(yield oe({gamma:n,kernel:X},t,e))}))}function Or(t,e){return pr(this,void 0,void 0,(function*(){return yield ce(t,e)}))}function Pr(t,e){return pr(this,void 0,void 0,(function*(){return le(t,e)}))}function Rr(t,e){return pr(this,void 0,void 0,(function*(){return he(t)}))}function Fr(t,e,n,r){return pr(this,void 0,void 0,(function*(){return se(0,r)}))}function Dr(t,e,n,r){return pr(this,void 0,void 0,(function*(){return ae(yield oe({gamma:n,kernel:Z,sigma:r},t,e))}))}function Ur(t,e){return pr(this,void 0,void 0,(function*(){return yield ce(t,e)}))}function kr(t,e){return pr(this,void 0,void 0,(function*(){return le(t,e)}))}function Gr(t,e){return pr(this,void 0,void 0,(function*(){return he(t)}))}function Br(t,e,n,r){return pr(this,void 0,void 0,(function*(){return se(0,r)}))}function Vr(t,e,n,r,i){return pr(this,void 0,void 0,(function*(){return ae(yield oe({gamma:n,kernel:Q,cParam:r,dParam:i},t,e))}))}function Wr(t,e){return pr(this,void 0,void 0,(function*(){return yield ce(t,e)}))}function zr(t,e){return pr(this,void 0,void 0,(function*(){return le(t,e)}))}function jr(t,e){return pr(this,void 0,void 0,(function*(){return he(t)}))}function Yr(t,e,n,r){return pr(this,void 0,void 0,(function*(){return se(0,r)}))}function qr(t,e,n,r,i){return pr(this,void 0,void 0,(function*(){return ae(yield oe({gamma:n,kernel:J,kappa:r,theta:i},t,e))}))}function Hr(t,e){return pr(this,void 0,void 0,(function*(){return yield ce(t,e)}))}function $r(t,e){return pr(this,void 0,void 0,(function*(){return le(t,e)}))}function Kr(t,e){return pr(this,void 0,void 0,(function*(){return he(t)}))}function Xr(t,e,n,r){return pr(this,void 0,void 0,(function*(){return se(0,r)}))}function Qr(e,n,r,o,s){!function(e,n,r,o){const s=t.shell.getTableView(e.name);s.addViewer(i.Viewer.boxPlot(i.DataFrame.fromColumns([n,r]))),s.addViewer(i.Viewer.grid(o))}(e,n,r,function(t,e,n=.05,r=!1){ke(n);const o=new Ve(t,e,r,n);if(r){if(!o.areVarsEqual(n))throw new Error(De.NON_EQUAL_VARIANCES);if(!o.isNormal())throw new Error(De.NON_NORMAL_DISTRIB)}const s=o.getOneWayAnova(),a=Ue.centralF.inv(1-n,s.dfBn,s.dfWn);return function(t,e,n,r,o){return i.DataFrame.fromColumns([i.Column.fromStrings("Source of variance",["Between groups","Within groups","Total","",r,"",o]),i.Column.fromList(i.COLUMN_TYPE.FLOAT,"Sum of squares",[t.ssBn,t.ssWn,t.ssTot,null,null,null,null]),i.Column.fromList(i.COLUMN_TYPE.INT,"Degrees of freedom",[t.dfBn,t.dfWn,t.dfTot,null,null,null,null]),i.Column.fromList(i.COLUMN_TYPE.FLOAT,"Mean square",[t.msBn,t.msWn,null,null,null,null,null]),i.Column.fromList(i.COLUMN_TYPE.FLOAT,"F-statistics",[t.fStat,null,null,null,null,null,null]),i.Column.fromList(i.COLUMN_TYPE.FLOAT,"p-value",[t.pValue,null,null,null,null,null,null]),i.Column.fromList(i.COLUMN_TYPE.FLOAT,`${e}-critical value`,[n,null,null,null,null,null,null])])}(s,n,a,`THE NULL HYPOTHESIS: the "${t.name}" \n factor does not produce a significant difference in the "${e.name}" feature.`,"Test result: "+(s.fStat>a?"REJECTED.":"FAILED TO REJECT."))}(n,r,o,s))}function Zr(){$n()}function Jr(t){return pr(this,void 0,void 0,(function*(){yield $n(t)}))}function ti(t,e){return pr(this,void 0,void 0,(function*(){const n=t.columns,r=yield function(t,e){return Zn(this,void 0,void 0,(function*(){const n=t.length,r=e.length,o=e.stats.avg,s=e.stats.stdev,a=new Float32Array(n+1).fill(0);if(a[n]=o,0===s||1===r)return a;try{const r=[],u=[],c=new Float32Array(n),l=new Float32Array(n);let h=0,d=0;for(const e of t){const t=e.stats;t.stdev>0&&(r.push(h),u.push(e),c[d]=t.avg,l[d]=t.stdev,++d),++h}if(0===d)return a;const f=function(t,e,n,r,i,o,s){return g(EDA,"fitLinearRegressionParamsWithDataNormalizing",[t,e,n,r,i,o,s])}(i.DataFrame.fromColumns(u).columns,i.Column.fromFloat32Array("xAvgs",c,d),i.Column.fromFloat32Array("xStdevs",l,d),e,o,s,d+1).getRawData();for(let t=0;t<d;++t)a[r[t]]=f[t];a[n]=f[d]}catch(r){const o=yield function(t,e,n){return Zn(this,void 0,void 0,(function*(){return(yield Re({table:i.DataFrame.fromColumns([e]),features:t,predict:e,components:n,names:void 0})).regressionCoefficients.getRawData()}))}(t,e,tr(t.length,e.length));let s=0;for(let e=0;e<n;++e)a[e]=o[e],s+=o[e]*t.byIndex(e).stats.avg;a[n]-=s}return a}))}(n,e);return new Uint8Array(r.buffer)}))}function ei(t,e){const n=t.columns,r=new Float32Array(e.buffer);return i.DataFrame.fromColumns([Jn(n,r)])}function ni(t,e){for(const e of t.columns)if(!e.matches("numerical"))return!1;return e.matches("numerical")}function ri(t,e){return t.rowCount<=1e5}function ii(t,e,n,r,i,o){return pr(this,void 0,void 0,(function*(){const s=t.columns,a=new ar({classesCount:e.categories.length,featuresCount:s.length});return yield a.fit(s,e,n,r,i,o),a.toBytes()}))}function oi(t,e){const n=t.columns,r=new ar(void 0,e);return i.DataFrame.fromColumns([r.predict(n)])}function si(t,e){return ar.isApplicable(t.columns,e)}function ai(t,e){return ar.isInteractive(t.columns,e)}function ci(t,e,n){return pr(this,void 0,void 0,(function*(){const r=t.columns,i=new nr;return yield i.fit(r,e,Math.min(n,r.length)),i.toBytes()}))}function li(t,e){const n=new nr(e);return i.DataFrame.fromColumns([n.predict(t.columns)])}function hi(t,e){return nr.isApplicable(t.columns,e)}function di(t,e,n,r){return pr(this,void 0,void 0,(function*(){return new nr(r).viewers().map((t=>t.root))}))}function fi(t,e){return nr.isInteractive(t.columns,e)}function pi(t,e,n,r,i,o,s){return pr(this,void 0,void 0,(function*(){const a=t.columns,u=new fr;return yield u.fit(a,e,n,r,i,o,s),u.toBytes()}))}function mi(t,e){const n=new fr(e);return i.DataFrame.fromColumns([n.predict(t.columns)])}function gi(t,e){return fr.isInteractive(t.columns,e)}function yi(t,e){return fr.isApplicable(t.columns,e)}})(),eda=r})();
1
+ var eda;(()=>{var t={5540:(t,e,n)=>{"use strict";t=n.hmd(t);var r,i=(r="undefined"!=typeof document&&document.currentScript?document.currentScript.src:void 0,function(t={}){var e,n,i=void 0!==t?t:{};i.ready=new Promise((function(t,r){e=t,n=r}));var o,s=Object.assign({},i),a="object"==typeof window,u="function"==typeof importScripts,c=("object"==typeof process&&"object"==typeof process.versions&&process.versions.node,"");(a||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&&(o=t=>{var e=new XMLHttpRequest;return e.open("GET",t,!1),e.responseType="arraybuffer",e.send(null),new Uint8Array(e.response)})),i.print||console.log.bind(console);var l,h,d=i.printErr||console.warn.bind(console);Object.assign(i,s),s=null,i.arguments&&i.arguments,i.thisProgram&&i.thisProgram,i.quit&&i.quit,i.wasmBinary&&(l=i.wasmBinary),i.noExitRuntime,"object"!=typeof WebAssembly&&C("no native wasm support detected");var f,p,m,g=!1;function y(){var t=h.buffer;i.HEAP8=f=new Int8Array(t),i.HEAP16=new Int16Array(t),i.HEAP32=new Int32Array(t),i.HEAPU8=p=new Uint8Array(t),i.HEAPU16=new Uint16Array(t),i.HEAPU32=m=new Uint32Array(t),i.HEAPF32=new Float32Array(t),i.HEAPF64=new Float64Array(t)}var v=[],w=[],b=[],E=0,A=null,_=null;function C(t){i.onAbort&&i.onAbort(t),d(t="Aborted("+t+")"),g=!0,t+=". Build with -sASSERTIONS for more info.";var e=new WebAssembly.RuntimeError(t);throw n(e),e}var S,I;function M(t){return t.startsWith("data:application/octet-stream;base64,")}function N(t){try{if(t==S&&l)return new Uint8Array(l);if(o)return o(t);throw"both async and sync fetching of the wasm failed"}catch(t){C(t)}}function x(t,e,n){return function(t){return l||!a&&!u||"function"!=typeof fetch?Promise.resolve().then((function(){return N(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 N(t)}))}(t).then((function(t){return WebAssembly.instantiate(t,e)})).then((function(t){return t})).then(n,(function(t){d("failed to asynchronously prepare wasm: "+t),C(t)}))}function L(t){for(;t.length>0;)t.shift()(i)}function T(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 O(t){var e=h.buffer;try{return h.grow(t-e.byteLength+65535>>>16),y(),1}catch(t){}}function P(t){return i["_"+t]}M(S="wasmDbscan.wasm")||(I=S,S=i.locateFile?i.locateFile(I,c):c+I);var R="undefined"!=typeof TextDecoder?new TextDecoder("utf8"):void 0;function F(t,e,n,r,i){var o={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 i=n+r-1,o=0;o<t.length;++o){var s=t.charCodeAt(o);if(s>=55296&&s<=57343&&(s=65536+((1023&s)<<10)|1023&t.charCodeAt(++o)),s<=127){if(n>=i)break;e[n++]=s}else if(s<=2047){if(n+1>=i)break;e[n++]=192|s>>6,e[n++]=128|63&s}else if(s<=65535){if(n+2>=i)break;e[n++]=224|s>>12,e[n++]=128|s>>6&63,e[n++]=128|63&s}else{if(n+3>=i)break;e[n++]=240|s>>18,e[n++]=128|s>>12&63,e[n++]=128|s>>6&63,e[n++]=128|63&s}}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}},s=P(t),a=[],u=0;if(r)for(var c=0;c<r.length;c++){var l=o[n[c]];l?(0===u&&(u=k()),a[c]=l(r[c])):a[c]=r[c]}var h=s.apply(null,a);return function(t){return 0!==u&&G(u),function(t){return"string"===e?(n=t)?function(t,e,n){for(var r=e+n,i=e;t[i]&&!(i>=r);)++i;if(i-e>16&&t.buffer&&R)return R.decode(t.subarray(e,i));for(var o="";e<i;){var s=t[e++];if(128&s){var a=63&t[e++];if(192!=(224&s)){var u=63&t[e++];if((s=224==(240&s)?(15&s)<<12|a<<6|u:(7&s)<<18|a<<12|u<<6|63&t[e++])<65536)o+=String.fromCharCode(s);else{var c=s-65536;o+=String.fromCharCode(55296|c>>10,56320|1023&c)}}else o+=String.fromCharCode((31&s)<<6|a)}else o+=String.fromCharCode(s)}return o}(p,n,r):"":"boolean"===e?Boolean(t):t;var n,r}(t)}(h)}var D,U={__cxa_throw:function(t,e,n){throw new T(t).init(e,n),t},abort:function(){C("")},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 i=1;i<=4;i*=2){var o=n*(1+.2/i);if(o=Math.min(o,t+100663296),O(Math.min(r,(e=Math.max(t,o))+(65536-e%65536)%65536)))return!0}return!1}},k=(function(){var t,e,r,o,s={env:U,wasi_snapshot_preview1:U};function a(t,e){var n,r=t.exports;return i.asm=r,h=i.asm.memory,y(),i.asm.__indirect_function_table,n=i.asm.__wasm_call_ctors,w.unshift(n),function(){if(E--,i.monitorRunDependencies&&i.monitorRunDependencies(E),0==E&&(null!==A&&(clearInterval(A),A=null),_)){var t=_;_=null,t()}}(),r}if(E++,i.monitorRunDependencies&&i.monitorRunDependencies(E),i.instantiateWasm)try{return i.instantiateWasm(s,a)}catch(t){d("Module.instantiateWasm callback failed with error: "+t),n(t)}(t=l,e=S,r=s,o=function(t){a(t.instance)},t||"function"!=typeof WebAssembly.instantiateStreaming||M(e)||"function"!=typeof fetch?x(e,r,o):fetch(e,{credentials:"same-origin"}).then((function(t){return WebAssembly.instantiateStreaming(t,r).then(o,(function(t){return d("wasm streaming compile failed: "+t),d("falling back to ArrayBuffer instantiation"),x(e,r,o)}))}))).catch(n)}(),i._dbscan=function(){return(i._dbscan=i.asm.dbscan).apply(null,arguments)},i._malloc=function(){return(i._malloc=i.asm.malloc).apply(null,arguments)},i._free=function(){return(i._free=i.asm.free).apply(null,arguments)},function(){return(k=i.asm.stackSave).apply(null,arguments)}),G=function(){return(G=i.asm.stackRestore).apply(null,arguments)},B=function(){return(B=i.asm.stackAlloc).apply(null,arguments)},V=function(){return(V=i.asm.__cxa_is_pointer_type).apply(null,arguments)};function W(){function t(){D||(D=!0,i.calledRun=!0,g||(L(w),e(i),i.onRuntimeInitialized&&i.onRuntimeInitialized(),function(){if(i.postRun)for("function"==typeof i.postRun&&(i.postRun=[i.postRun]);i.postRun.length;)t=i.postRun.shift(),b.unshift(t);var t;L(b)}()))}E>0||(function(){if(i.preRun)for("function"==typeof i.preRun&&(i.preRun=[i.preRun]);i.preRun.length;)t=i.preRun.shift(),v.unshift(t);var t;L(v)}(),E>0||(i.setStatus?(i.setStatus("Running..."),setTimeout((function(){setTimeout((function(){i.setStatus("")}),1),t()}),1)):t()))}if(i.ccall=F,i.cwrap=function(t,e,n,r){var i=!n||n.every((t=>"number"===t||"boolean"===t));return"string"!==e&&i&&!r?P(t):function(){return F(t,e,n,arguments)}},_=function t(){D||W(),D||(_=t)},i.preInit)for("function"==typeof i.preInit&&(i.preInit=[i.preInit]);i.preInit.length>0;)i.preInit.pop()();return W(),t.ready});"object"==typeof exports?t.exports=i:"function"==typeof define&&n.amdO?define([],(function(){return i})):"object"==typeof exports&&(exports.exportCppDbscanLib=i)},7939:(t,e,n)=>{"use strict";n.d(e,{A:()=>a});var r=n(1354),i=n.n(r),o=n(6314),s=n.n(o)()(i());s.push([t.id,".scatter_plot_link {\n position: absolute!important;\n right: 10px;\n}\n\n.cliffs_grid {\n top: 10px;\n}\n\n.show_only_cliffs {\n top: 30px;\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\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,4BAA4B;IAC5B,WAAW;AACf;;AAEA;IACI,SAAS;AACb;;AAEA;IACI,SAAS;AACb;;AAEA;IACI,eAAe;IACf,kBAAkB;IAClB,YAAY;;AAEhB;;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 position: absolute!important;\n right: 10px;\n}\n\n.cliffs_grid {\n top: 10px;\n}\n\n.show_only_cliffs {\n top: 30px;\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\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 a=s},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,i,o){"string"==typeof t&&(t=[[null,t,void 0]]);var s={};if(r)for(var a=0;a<this.length;a++){var u=this[a][0];null!=u&&(s[u]=!0)}for(var c=0;c<t.length;c++){var l=[].concat(t[c]);r&&s[l[0]]||(void 0!==o&&(void 0===l[5]||(l[1]="@layer".concat(l[5].length>0?" ".concat(l[5]):""," {").concat(l[1],"}")),l[5]=o),n&&(l[2]?(l[1]="@media ".concat(l[2]," {").concat(l[1],"}"),l[2]=n):l[2]=n),i&&(l[4]?(l[1]="@supports (".concat(l[4],") {").concat(l[1],"}"),l[4]=i):l[4]="".concat(i)),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)))),i="sourceMappingURL=data:application/json;charset=utf-8;base64,".concat(r),o="/*# ".concat(i," */");return[e].concat([o]).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,i=Array.prototype.slice.call(arguments).slice(1);for(e=0,r=i.length;e<r;e++)if(i[e])for(n in i[e])t[n]=i[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,i=t.size,o={},s=new Float32Array(10*r),a=new Float32Array(3*i);return n=0,t.forEachNode((function(t,e){o[t]=n,s[n]=e.x,s[n+1]=e.y,s[n+2]=0,s[n+3]=0,s[n+4]=0,s[n+5]=0,s[n+6]=1,s[n+7]=1,s[n+8]=e.size||1,s[n+9]=e.fixed?1:0,n+=10})),n=0,t.forEachEdge((function(t,r,i,u,c,l,h){var d=o[i],f=o[u],p=e(t,r,i,u,c,l,h);s[d+6]+=p,s[f+6]+=p,a[n]=d,a[n+1]=f,a[n+2]=p,n+=3})),{nodes:s,edges:a}},e.assignLayoutChanges=function(t,e,n){var r=0;t.updateEachNodeAttributes((function(t,i){return i.x=e[r],i.y=e[r+1],r+=10,n?n(t,i):i}))},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(),i={},o=0,s=0,a=e.length;o<a;o+=10){if(n){var u=Object.assign({},t.getNodeAttributes(r[s]));u.x=e[o],u.y=e[o+1],u=n(r[s],u),i[r[s]]={x:u.x,y:u.y}}else i[r[s]]={x:e[o],y:e[o+1]};s++}return i},e.createWorker=function(t){var e=window.URL||window.webkitURL,n=t.toString(),r=e.createObjectURL(new Blob(["("+n+").call(this);"],{type:"text/javascript"})),i=new Worker(r);return e.revokeObjectURL(r),i}},8903:(t,e,n)=>{var r=n(1736),i=n(8153).Fd,o=n(2561),s=n(1782),a=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=i("getEdgeWeight"in n?n.getEdgeWeight:"weight").fromEntry,l="function"==typeof n.outputReducer?n.outputReducer:null,h=s.assign({},a,n.settings),d=s.validateSettings(h);if(d)throw new Error("graphology-layout-forceatlas2: "+d.message);var f,p=s.graphToByteArrays(e,c);for(f=0;f<u;f++)o(h,p.nodes,p.edges);if(!t)return s.collectLayoutChanges(e,p.nodes);s.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 i,o,s,a,u,c,l,h,d,f,p,m,g,y,v,w,b,E,A,_,C,S,I,M=n.length,N=r.length,x=t.adjustSizes,L=t.barnesHutTheta*t.barnesHutTheta,T=[];for(s=0;s<M;s+=e)n[s+4]=n[s+2],n[s+5]=n[s+3],n[s+2]=0,n[s+3]=0;if(t.outboundAttractionDistribution){for(p=0,s=0;s<M;s+=e)p+=n[s+6];p/=M/e}if(t.barnesHutOptimize){var O,P,R,F=1/0,D=-1/0,U=1/0,k=-1/0;for(s=0;s<M;s+=e)F=Math.min(F,n[s+0]),D=Math.max(D,n[s+0]),U=Math.min(U,n[s+1]),k=Math.max(k,n[s+1]);var G=D-F,B=k-U;for(G>B?k=(U-=(G-B)/2)+G:D=(F-=(B-G)/2)+B,T[0]=-1,T[1]=(F+D)/2,T[2]=(U+k)/2,T[3]=Math.max(D-F,k-U),T[4]=-1,T[5]=-1,T[6]=0,T[7]=0,T[8]=0,i=1,s=0;s<M;s+=e)for(o=0,R=3;;){if(!(T[o+5]>=0)){if(T[o+0]<0){T[o+0]=s;break}if(T[o+5]=9*i,h=T[o+3]/2,T[(d=T[o+5])+0]=-1,T[d+1]=T[o+1]-h,T[d+2]=T[o+2]-h,T[d+3]=h,T[d+4]=d+9,T[d+5]=-1,T[d+6]=0,T[d+7]=0,T[d+8]=0,T[(d+=9)+0]=-1,T[d+1]=T[o+1]-h,T[d+2]=T[o+2]+h,T[d+3]=h,T[d+4]=d+9,T[d+5]=-1,T[d+6]=0,T[d+7]=0,T[d+8]=0,T[(d+=9)+0]=-1,T[d+1]=T[o+1]+h,T[d+2]=T[o+2]-h,T[d+3]=h,T[d+4]=d+9,T[d+5]=-1,T[d+6]=0,T[d+7]=0,T[d+8]=0,T[(d+=9)+0]=-1,T[d+1]=T[o+1]+h,T[d+2]=T[o+2]+h,T[d+3]=h,T[d+4]=T[o+4],T[d+5]=-1,T[d+6]=0,T[d+7]=0,T[d+8]=0,i+=4,O=n[T[o+0]+0]<T[o+1]?n[T[o+0]+1]<T[o+2]?T[o+5]:T[o+5]+9:n[T[o+0]+1]<T[o+2]?T[o+5]+18:T[o+5]+27,T[o+6]=n[T[o+0]+6],T[o+7]=n[T[o+0]+0],T[o+8]=n[T[o+0]+1],T[O+0]=T[o+0],T[o+0]=-1,O===(P=n[s+0]<T[o+1]?n[s+1]<T[o+2]?T[o+5]:T[o+5]+9:n[s+1]<T[o+2]?T[o+5]+18:T[o+5]+27)){if(R--){o=O;continue}R=3;break}T[P+0]=s;break}O=n[s+0]<T[o+1]?n[s+1]<T[o+2]?T[o+5]:T[o+5]+9:n[s+1]<T[o+2]?T[o+5]+18:T[o+5]+27,T[o+7]=(T[o+7]*T[o+6]+n[s+0]*n[s+6])/(T[o+6]+n[s+6]),T[o+8]=(T[o+8]*T[o+6]+n[s+1]*n[s+6])/(T[o+6]+n[s+6]),T[o+6]+=n[s+6],o=O}}if(t.barnesHutOptimize){for(m=t.scalingRatio,s=0;s<M;s+=e)for(o=0;;)if(T[o+5]>=0){if(w=Math.pow(n[s+0]-T[o+7],2)+Math.pow(n[s+1]-T[o+8],2),4*(f=T[o+3])*f/w<L){if(g=n[s+0]-T[o+7],y=n[s+1]-T[o+8],!0===x?w>0?(b=m*n[s+6]*T[o+6]/w,n[s+2]+=g*b,n[s+3]+=y*b):w<0&&(b=-m*n[s+6]*T[o+6]/Math.sqrt(w),n[s+2]+=g*b,n[s+3]+=y*b):w>0&&(b=m*n[s+6]*T[o+6]/w,n[s+2]+=g*b,n[s+3]+=y*b),(o=T[o+4])<0)break;continue}o=T[o+5]}else if((c=T[o+0])>=0&&c!==s&&(w=(g=n[s+0]-n[c+0])*g+(y=n[s+1]-n[c+1])*y,!0===x?w>0?(b=m*n[s+6]*n[c+6]/w,n[s+2]+=g*b,n[s+3]+=y*b):w<0&&(b=-m*n[s+6]*n[c+6]/Math.sqrt(w),n[s+2]+=g*b,n[s+3]+=y*b):w>0&&(b=m*n[s+6]*n[c+6]/w,n[s+2]+=g*b,n[s+3]+=y*b)),(o=T[o+4])<0)break}else for(m=t.scalingRatio,a=0;a<M;a+=e)for(u=0;u<a;u+=e)g=n[a+0]-n[u+0],y=n[a+1]-n[u+1],!0===x?(w=Math.sqrt(g*g+y*y)-n[a+8]-n[u+8])>0?(b=m*n[a+6]*n[u+6]/w/w,n[a+2]+=g*b,n[a+3]+=y*b,n[u+2]-=g*b,n[u+3]-=y*b):w<0&&(b=100*m*n[a+6]*n[u+6],n[a+2]+=g*b,n[a+3]+=y*b,n[u+2]-=g*b,n[u+3]-=y*b):(w=Math.sqrt(g*g+y*y))>0&&(b=m*n[a+6]*n[u+6]/w/w,n[a+2]+=g*b,n[a+3]+=y*b,n[u+2]-=g*b,n[u+3]-=y*b);for(d=t.gravity/t.scalingRatio,m=t.scalingRatio,s=0;s<M;s+=e)b=0,g=n[s+0],y=n[s+1],w=Math.sqrt(Math.pow(g,2)+Math.pow(y,2)),t.strongGravityMode?w>0&&(b=m*n[s+6]*d):w>0&&(b=m*n[s+6]*d/w),n[s+2]-=g*b,n[s+3]-=y*b;for(m=1*(t.outboundAttractionDistribution?p:1),l=0;l<N;l+=3)a=r[l+0],u=r[l+1],h=r[l+2],v=Math.pow(h,t.edgeWeightInfluence),g=n[a+0]-n[u+0],y=n[a+1]-n[u+1],!0===x?(w=Math.sqrt(g*g+y*y)-n[a+8]-n[u+8],t.linLogMode?t.outboundAttractionDistribution?w>0&&(b=-m*v*Math.log(1+w)/w/n[a+6]):w>0&&(b=-m*v*Math.log(1+w)/w):t.outboundAttractionDistribution?w>0&&(b=-m*v/n[a+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[a+6]):w>0&&(b=-m*v*Math.log(1+w)/w):t.outboundAttractionDistribution?(w=1,b=-m*v/n[a+6]):(w=1,b=-m*v)),w>0&&(n[a+2]+=g*b,n[a+3]+=y*b,n[u+2]-=g*b,n[u+3]-=y*b);if(!0===x)for(s=0;s<M;s+=e)1!==n[s+9]&&((E=Math.sqrt(Math.pow(n[s+2],2)+Math.pow(n[s+3],2)))>10&&(n[s+2]=10*n[s+2]/E,n[s+3]=10*n[s+3]/E),A=n[s+6]*Math.sqrt((n[s+4]-n[s+2])*(n[s+4]-n[s+2])+(n[s+5]-n[s+3])*(n[s+5]-n[s+3])),_=Math.sqrt((n[s+4]+n[s+2])*(n[s+4]+n[s+2])+(n[s+5]+n[s+3])*(n[s+5]+n[s+3]))/2,C=.1*Math.log(1+_)/(1+Math.sqrt(A)),S=n[s+0]+n[s+2]*(C/t.slowDown),n[s+0]=S,I=n[s+1]+n[s+3]*(C/t.slowDown),n[s+1]=I);else for(s=0;s<M;s+=e)1!==n[s+9]&&(A=n[s+6]*Math.sqrt((n[s+4]-n[s+2])*(n[s+4]-n[s+2])+(n[s+5]-n[s+3])*(n[s+5]-n[s+3])),_=Math.sqrt((n[s+4]+n[s+2])*(n[s+4]+n[s+2])+(n[s+5]+n[s+3])*(n[s+5]+n[s+3]))/2,C=n[s+7]*Math.log(1+_)/(1+Math.sqrt(A)),n[s+7]=Math.min(1,Math.sqrt(C*(Math.pow(n[s+2],2)+Math.pow(n[s+3],2))/(1+Math.sqrt(A)))),S=n[s+0]+n[s+2]*(C/t.slowDown),n[s+0]=S,I=n[s+1]+n[s+3]*(C/t.slowDown),n[s+1]=I);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 i=function(e){return r(e[t])},o=function(){return r(void 0)};return"string"==typeof t?(n.fromAttributes=i,n.fromGraph=function(t,e){return i(t.getEdgeAttributes(e))},n.fromEntry=function(t,e){return i(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 i=e.extremities(n);return r(t(n,e.getEdgeAttributes(n),i[0],i[1],e.getNodeAttributes(i[0]),e.getNodeAttributes(i[1]),e.isUndirected(n)))},n.fromEntry=function(e,n,i,o,s,a,u){return r(t(e,n,i,o,s,a,u))},n.fromPartialEntry=function(e,n,i,o){return r(t(e,n,i,o))},n.fromMinimalEntry=function(e,n){return r(t(e,n))}):(n.fromAttributes=o,n.fromGraph=o,n.fromEntry=o,n.fromMinimalEntry=o),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 i(t,e,n){return i=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 i=[null];i.push.apply(i,e);var o=new(Function.bind.apply(t,i));return n&&r(o,n.prototype),o},i.apply(null,arguments)}function o(t){var e="function"==typeof Map?new Map:void 0;return o=function(t){if(null===t||(o=t,-1===Function.toString.call(o).indexOf("[native code]")))return t;var o;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,s)}function s(){return i(t,arguments,n(this).constructor)}return s.prototype=Object.create(t.prototype,{constructor:{value:s,enumerable:!1,writable:!0,configurable:!0}}),r(s,t)},o(t)}function s(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}var a=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 i=t._nodes.get(e),o=null;return i?o="mixed"===r?i.out&&i.out[n]||i.undirected&&i.undirected[n]:"directed"===r?i.out&&i.out[n]:i.undirected&&i.undirected[n]:o}function c(e){return"object"===t(e)&&null!==e}function l(t){var e;for(e in t)return!1;return!0}function h(t,e,n){Object.defineProperty(t,e,{enumerable:!1,configurable:!1,writable:!0,value:n})}function d(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&&(a=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 i(n){t.removeListener(e,o),r(n)}function o(){"function"==typeof t.removeListener&&t.removeListener("error",i),n([].slice.call(arguments))}x(t,e,o,{once:!0}),"error"!==e&&function(t,e){"function"==typeof t.on&&x(t,"error",e,{once:!0})}(t,i)}))},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 _(t,e,n,r){var i,o,s,a;if(E(n),void 0===(o=t._events)?(o=t._events=Object.create(null),t._eventsCount=0):(void 0!==o.newListener&&(t.emit("newListener",e,n.listener?n.listener:n),o=t._events),s=o[e]),void 0===s)s=o[e]=n,++t._eventsCount;else if("function"==typeof s?s=o[e]=r?[n,s]:[s,n]:r?s.unshift(n):s.push(n),(i=A(t))>0&&s.length>i&&!s.warned){s.warned=!0;var u=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");u.name="MaxListenersExceededWarning",u.emitter=t,u.type=e,u.count=s.length,a=u,console&&console.warn&&console.warn(a)}return t}function C(){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 S(t,e,n){var r={fired:!1,wrapFn:void 0,target:t,type:e,listener:n},i=C.bind(r);return i.listener=n,r.wrapFn=i,i}function I(t,e,n){var r=t._events;if(void 0===r)return[];var i=r[e];return void 0===i?[]:"function"==typeof i?n?[i.listener||i]:[i]: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}(i):N(i,i.length)}function M(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 N(t,e){for(var n=new Array(e),r=0;r<e;++r)n[r]=t[r];return n}function x(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 i(o){r.once&&t.removeEventListener(e,i),n(o)}))}}function L(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,i=this._events;if(void 0!==i)r=r&&void 0===i.error;else if(!r)return!1;if(r){var o;if(e.length>0&&(o=e[0]),o instanceof Error)throw o;var s=new Error("Unhandled error."+(o?" ("+o.message+")":""));throw s.context=o,s}var a=i[t];if(void 0===a)return!1;if("function"==typeof a)y(a,this,e);else{var u=a.length,c=N(a,u);for(n=0;n<u;++n)y(c[n],this,e)}return!0},w.prototype.addListener=function(t,e){return _(this,t,e,!1)},w.prototype.on=w.prototype.addListener,w.prototype.prependListener=function(t,e){return _(this,t,e,!0)},w.prototype.once=function(t,e){return E(e),this.on(t,S(this,t,e)),this},w.prototype.prependOnceListener=function(t,e){return E(e),this.prependListener(t,S(this,t,e)),this},w.prototype.removeListener=function(t,e){var n,r,i,o,s;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(i=-1,o=n.length-1;o>=0;o--)if(n[o]===e||n[o].listener===e){s=n[o].listener,i=o;break}if(i<0)return this;0===i?n.shift():function(t,e){for(;e+1<t.length;e++)t[e]=t[e+1];t.pop()}(n,i),1===n.length&&(r[t]=n[0]),void 0!==r.removeListener&&this.emit("removeListener",t,s||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 i,o=Object.keys(n);for(r=0;r<o.length;++r)"removeListener"!==(i=o[r])&&this.removeAllListeners(i);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 I(this,t,!0)},w.prototype.rawListeners=function(t){return I(this,t,!1)},w.listenerCount=function(t,e){return"function"==typeof t.listenerCount?t.listenerCount(e):M.call(t,e)},w.prototype.listenerCount=M,w.prototype.eventNames=function(){return this._eventsCount>0?p(this._events):[]},"undefined"!=typeof Symbol&&(L.prototype[Symbol.iterator]=function(){return this}),L.of=function(){var t=arguments,e=t.length,n=0;return new L((function(){return n>=e?{done:!0}:{done:!1,value:t[n++]}}))},L.empty=function(){return new L((function(){return{done:!0}}))},L.fromSequence=function(t){var e=0,n=t.length;return new L((function(){return e>=n?{done:!0}:{done:!1,value:t[e++]}}))},L.is=function(t){return t instanceof L||"object"==typeof t&&null!==t&&"function"==typeof t.next};var T=L,O={};O.ARRAY_BUFFER_SUPPORT="undefined"!=typeof ArrayBuffer,O.SYMBOL_SUPPORT="undefined"!=typeof Symbol;var P=T,R=O,F=R.ARRAY_BUFFER_SUPPORT,D=R.SYMBOL_SUPPORT,U=function(t){var e=function(t){return"string"==typeof t||Array.isArray(t)||F&&ArrayBuffer.isView(t)?P.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,i=r!==1/0?new Array(r):[],o=0,s=k(t);;){if(o===r)return i;if((n=s.next()).done)return o!==e&&(i.length=o),i;i[o++]=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}(o(Error)),V=function(t){function n(e){var r;return(r=t.call(this,e)||this).name="InvalidArgumentsGraphError","function"==typeof Error.captureStackTrace&&Error.captureStackTrace(s(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(s(r),n.prototype.constructor),r}return e(n,t),n}(B),z=function(t){function n(e){var r;return(r=t.call(this,e)||this).name="UsageGraphError","function"==typeof Error.captureStackTrace&&Error.captureStackTrace(s(r),n.prototype.constructor),r}return e(n,t),n}(B);function j(t,e){this.key=t,this.attributes=e,this.clear()}function Y(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,i){this.key=e,this.attributes=i,this.undirected=t,this.source=n,this.target=r}function $(t,e,n,r,i,o,s){var a,u,c,l;if(r=""+r,0===n){if(!(a=t._nodes.get(r)))throw new W("Graph.".concat(e,': could not find the "').concat(r,'" node in the graph.'));c=i,l=o}else if(3===n){if(i=""+i,!(u=t._edges.get(i)))throw new W("Graph.".concat(e,': could not find the "').concat(i,'" edge in the graph.'));var h=u.source.key,d=u.target.key;if(r===h)a=u.target;else{if(r!==d)throw new W("Graph.".concat(e,': the "').concat(r,'" node is not attached to the "').concat(i,'" edge (').concat(h,", ").concat(d,")."));a=u.source}c=o,l=s}else{if(!(u=t._edges.get(r)))throw new W("Graph.".concat(e,': could not find the "').concat(r,'" edge in the graph.'));a=1===n?u.source:u.target,c=i,l=o}return[a,c,l]}j.prototype.clear=function(){this.inDegree=0,this.outDegree=0,this.undirectedDegree=0,this.undirectedLoops=0,this.directedLoops=0,this.in={},this.out={},this.undirected={}},Y.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 i=this.source[t],o=i[r];if(void 0===o)return i[r]=this,void(this.undirected&&n===r||(this.target[e][n]=this));o.previous=this,this.next=o,i[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,i){var o=$(this,e,n,t,r,i),s=o[0],a=o[1];return s.attributes[a]}}},{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,i){var o=$(this,e,n,t,r,i),s=o[0],a=o[1];return s.attributes.hasOwnProperty(a)}}},{name:function(t){return"set".concat(t,"Attribute")},attacher:function(t,e,n){t.prototype[e]=function(t,r,i,o){var s=$(this,e,n,t,r,i,o),a=s[0],u=s[1],c=s[2];return a.attributes[u]=c,this.emit("nodeAttributesUpdated",{key:a.key,type:"set",attributes:a.attributes,name:u}),this}}},{name:function(t){return"update".concat(t,"Attribute")},attacher:function(t,e,n){t.prototype[e]=function(t,r,i,o){var s=$(this,e,n,t,r,i,o),a=s[0],u=s[1],c=s[2];if("function"!=typeof c)throw new V("Graph.".concat(e,": updater should be a function."));var l=a.attributes,h=c(l[u]);return l[u]=h,this.emit("nodeAttributesUpdated",{key:a.key,type:"set",attributes:a.attributes,name:u}),this}}},{name:function(t){return"remove".concat(t,"Attribute")},attacher:function(t,e,n){t.prototype[e]=function(t,r,i){var o=$(this,e,n,t,r,i),s=o[0],a=o[1];return delete s.attributes[a],this.emit("nodeAttributesUpdated",{key:s.key,type:"remove",attributes:s.attributes,name:a}),this}}},{name:function(t){return"replace".concat(t,"Attributes")},attacher:function(t,e,n){t.prototype[e]=function(t,r,i){var o=$(this,e,n,t,r,i),s=o[0],a=o[1];if(!c(a))throw new V("Graph.".concat(e,": provided attributes are not a plain object."));return s.attributes=a,this.emit("nodeAttributesUpdated",{key:s.key,type:"replace",attributes:s.attributes}),this}}},{name:function(t){return"merge".concat(t,"Attributes")},attacher:function(t,e,n){t.prototype[e]=function(t,r,i){var o=$(this,e,n,t,r,i),s=o[0],u=o[1];if(!c(u))throw new V("Graph.".concat(e,": provided attributes are not a plain object."));return a(s.attributes,u),this.emit("nodeAttributesUpdated",{key:s.key,type:"merge",attributes:s.attributes,data:u}),this}}},{name:function(t){return"update".concat(t,"Attributes")},attacher:function(t,e,n){t.prototype[e]=function(t,r,i){var o=$(this,e,n,t,r,i),s=o[0],a=o[1];if("function"!=typeof a)throw new V("Graph.".concat(e,": provided updater is not a function."));return s.attributes=a(s.attributes),this.emit("nodeAttributesUpdated",{key:s.key,type:"update",attributes:s.attributes}),this}}}],X=[{name:function(t){return"get".concat(t,"Attribute")},attacher:function(t,e,n){t.prototype[e]=function(t,r){var i;if("mixed"!==this.type&&"mixed"!==n&&n!==this.type)throw new z("Graph.".concat(e,": cannot find this type of edges in your ").concat(this.type," graph."));if(arguments.length>2){if(this.multi)throw new z("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,s=""+r;if(r=arguments[2],!(i=u(this,o,s,n)))throw new W("Graph.".concat(e,': could not find an edge for the given path ("').concat(o,'" - "').concat(s,'").'))}else{if("mixed"!==n)throw new z("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]}}},{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 z("Graph.".concat(e,": cannot find this type of edges in your ").concat(this.type," graph."));if(arguments.length>1){if(this.multi)throw new z("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,o=""+arguments[1];if(!(r=u(this,i,o,n)))throw new W("Graph.".concat(e,': could not find an edge for the given path ("').concat(i,'" - "').concat(o,'").'))}else{if("mixed"!==n)throw new z("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 i;if("mixed"!==this.type&&"mixed"!==n&&n!==this.type)throw new z("Graph.".concat(e,": cannot find this type of edges in your ").concat(this.type," graph."));if(arguments.length>2){if(this.multi)throw new z("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,s=""+r;if(r=arguments[2],!(i=u(this,o,s,n)))throw new W("Graph.".concat(e,': could not find an edge for the given path ("').concat(o,'" - "').concat(s,'").'))}else{if("mixed"!==n)throw new z("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.hasOwnProperty(r)}}},{name:function(t){return"set".concat(t,"Attribute")},attacher:function(t,e,n){t.prototype[e]=function(t,r,i){var o;if("mixed"!==this.type&&"mixed"!==n&&n!==this.type)throw new z("Graph.".concat(e,": cannot find this type of edges in your ").concat(this.type," graph."));if(arguments.length>3){if(this.multi)throw new z("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 s=""+t,a=""+r;if(r=arguments[2],i=arguments[3],!(o=u(this,s,a,n)))throw new W("Graph.".concat(e,': could not find an edge for the given path ("').concat(s,'" - "').concat(a,'").'))}else{if("mixed"!==n)throw new z("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]=i,this.emit("edgeAttributesUpdated",{key:o.key,type:"set",attributes:o.attributes,name:r}),this}}},{name:function(t){return"update".concat(t,"Attribute")},attacher:function(t,e,n){t.prototype[e]=function(t,r,i){var o;if("mixed"!==this.type&&"mixed"!==n&&n!==this.type)throw new z("Graph.".concat(e,": cannot find this type of edges in your ").concat(this.type," graph."));if(arguments.length>3){if(this.multi)throw new z("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 s=""+t,a=""+r;if(r=arguments[2],i=arguments[3],!(o=u(this,s,a,n)))throw new W("Graph.".concat(e,': could not find an edge for the given path ("').concat(s,'" - "').concat(a,'").'))}else{if("mixed"!==n)throw new z("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 i)throw new V("Graph.".concat(e,": updater should be a function."));return o.attributes[r]=i(o.attributes[r]),this.emit("edgeAttributesUpdated",{key:o.key,type:"set",attributes:o.attributes,name:r}),this}}},{name:function(t){return"remove".concat(t,"Attribute")},attacher:function(t,e,n){t.prototype[e]=function(t,r){var i;if("mixed"!==this.type&&"mixed"!==n&&n!==this.type)throw new z("Graph.".concat(e,": cannot find this type of edges in your ").concat(this.type," graph."));if(arguments.length>2){if(this.multi)throw new z("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,s=""+r;if(r=arguments[2],!(i=u(this,o,s,n)))throw new W("Graph.".concat(e,': could not find an edge for the given path ("').concat(o,'" - "').concat(s,'").'))}else{if("mixed"!==n)throw new z("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 delete i.attributes[r],this.emit("edgeAttributesUpdated",{key:i.key,type:"remove",attributes:i.attributes,name:r}),this}}},{name:function(t){return"replace".concat(t,"Attributes")},attacher:function(t,e,n){t.prototype[e]=function(t,r){var i;if("mixed"!==this.type&&"mixed"!==n&&n!==this.type)throw new z("Graph.".concat(e,": cannot find this type of edges in your ").concat(this.type," graph."));if(arguments.length>2){if(this.multi)throw new z("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,s=""+r;if(r=arguments[2],!(i=u(this,o,s,n)))throw new W("Graph.".concat(e,': could not find an edge for the given path ("').concat(o,'" - "').concat(s,'").'))}else{if("mixed"!==n)throw new z("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(!c(r))throw new V("Graph.".concat(e,": provided attributes are not a plain object."));return i.attributes=r,this.emit("edgeAttributesUpdated",{key:i.key,type:"replace",attributes:i.attributes}),this}}},{name:function(t){return"merge".concat(t,"Attributes")},attacher:function(t,e,n){t.prototype[e]=function(t,r){var i;if("mixed"!==this.type&&"mixed"!==n&&n!==this.type)throw new z("Graph.".concat(e,": cannot find this type of edges in your ").concat(this.type," graph."));if(arguments.length>2){if(this.multi)throw new z("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,s=""+r;if(r=arguments[2],!(i=u(this,o,s,n)))throw new W("Graph.".concat(e,': could not find an edge for the given path ("').concat(o,'" - "').concat(s,'").'))}else{if("mixed"!==n)throw new z("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(!c(r))throw new V("Graph.".concat(e,": provided attributes are not a plain object."));return a(i.attributes,r),this.emit("edgeAttributesUpdated",{key:i.key,type:"merge",attributes:i.attributes,data:r}),this}}},{name:function(t){return"update".concat(t,"Attributes")},attacher:function(t,e,n){t.prototype[e]=function(t,r){var i;if("mixed"!==this.type&&"mixed"!==n&&n!==this.type)throw new z("Graph.".concat(e,": cannot find this type of edges in your ").concat(this.type," graph."));if(arguments.length>2){if(this.multi)throw new z("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,s=""+r;if(r=arguments[2],!(i=u(this,o,s,n)))throw new W("Graph.".concat(e,': could not find an edge for the given path ("').concat(o,'" - "').concat(s,'").'))}else{if("mixed"!==n)throw new z("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 r)throw new V("Graph.".concat(e,": provided updater is not a function."));return i.attributes=r(i.attributes),this.emit("edgeAttributesUpdated",{key:i.key,type:"update",attributes:i.attributes}),this}}}],Q=T,Z=U,J=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=Z(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 i=!1;for(var o in e)if(o!==r){var s=e[o];if(i=n(s.key,s.attributes,s.source.key,s.target.key,s.source.attributes,s.target.attributes,s.undirected),t&&i)return s.key}}function nt(t,e,n,r){var i,o,s,a=!1;for(var u in e)if(u!==r){i=e[u];do{if(o=i.source,s=i.target,a=n(i.key,i.attributes,o.key,s.key,o.attributes,s.attributes,i.undirected),t&&a)return i.key;i=i.next}while(void 0!==i)}}function rt(t,e){var n,r=Object.keys(t),i=r.length,o=0;return new T((function(){do{if(n)n=n.next;else{if(o>=i)return{done:!0};var s=r[o++];if(s===e){n=void 0;continue}n=t[s]}}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 it(t,e,n,r){var i=e[n];if(i){var o=i.source,s=i.target;return r(i.key,i.attributes,o.key,s.key,o.attributes,s.attributes,i.undirected)&&t?i.key:void 0}}function ot(t,e,n,r){var i=e[n];if(i){var o=!1;do{if(o=r(i.key,i.attributes,i.source.key,i.target.key,i.source.attributes,i.target.attributes,i.undirected),t&&o)return i.key;i=i.next}while(void 0!==i)}}function st(t,e){var n=t[e];return void 0!==n.next?new T((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}})):T.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 at(t,e,n,r){if(0!==e.size)for(var i,o,s="mixed"!==n&&n!==e.type,a="undirected"===n,u=!1,c=e._edges.values();!0!==(i=c.next()).done;)if(o=i.value,!s||o.undirected===a){var l=o,h=l.key,d=l.attributes,f=l.source,p=l.target;if(u=r(h,d,f.key,p.key,f.attributes,p.attributes,o.undirected),t&&u)return h}}function ut(t,e,n,r,i,o){var s,a=e?nt:et;if("undirected"!==n){if("out"!==r&&(s=a(t,i.in,o),t&&s))return s;if("in"!==r&&(s=a(t,i.out,o,r?void 0:i.key),t&&s))return s}if("directed"!==n&&(s=a(t,i.undirected,o),t&&s))return s}function ct(t,e,n,r,i,o,s){var a,u=n?ot:it;if("undirected"!==e){if(void 0!==i.in&&"out"!==r&&(a=u(t,i.in,o,s),t&&a))return a;if(void 0!==i.out&&"in"!==r&&(r||i.key!==o)&&(a=u(t,i.out,o,s),t&&a))return a}if("directed"!==e&&void 0!==i.undirected&&(a=u(t,i.undirected,o,s),t&&a))return a}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 ht(){this.A=null,this.B=null}function dt(t,e,n,r,i){for(var o in r){var s=r[o],a=s.source,u=s.target,c=a===n?u:a;if(!e||!e.has(c.key)){var l=i(c.key,c.attributes);if(t&&l)return c.key}}}function ft(t,e,n,r,i){if("mixed"!==e){if("undirected"===e)return dt(t,null,r,r.undirected,i);if("string"==typeof n)return dt(t,null,r,r[n],i)}var o,s=new ht;if("undirected"!==e){if("out"!==n){if(o=dt(t,null,r,r.in,i),t&&o)return o;s.wrap(r.in)}if("in"!==n){if(o=dt(t,s,r,r.out,i),t&&o)return o;s.wrap(r.out)}}if("directed"!==e&&(o=dt(t,s,r,r.undirected,i),t&&o))return o}function pt(t,e,n){var r=Object.keys(n),i=r.length,o=0;return new T((function(){var s=null;do{if(o>=i)return t&&t.wrap(n),{done:!0};var a=n[r[o++]],u=a.source,c=a.target;s=u===e?c:u,t&&t.has(s.key)&&(s=null)}while(null===s);return{done:!1,value:{neighbor:s.key,attributes:s.attributes}}}))}function mt(t,e,n,r,i){for(var o,s,a,u,c,l,h,d=r._nodes.values(),f=r.type;!0!==(o=d.next()).done;){var p=!1;if(s=o.value,"undirected"!==f)for(a in u=s.out){c=u[a];do{if(l=c.target,p=!0,h=i(s.key,l.key,s.attributes,l.attributes,c.key,c.attributes,c.undirected),t&&h)return c;c=c.next}while(c)}if("directed"!==f)for(a in u=s.undirected)if(!(e&&s.key>a)){c=u[a];do{if((l=c.target).key!==a&&(l=c.source),p=!0,h=i(s.key,l.key,s.attributes,l.attributes,c.key,c.attributes,c.undirected),t&&h)return c;c=c.next}while(c)}if(n&&!p&&(h=i(s.key,null,s.attributes,null,null,null,null),t&&h))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.")}ht.prototype.wrap=function(t){null===this.A?this.A=t:null===this.B&&(this.B=t)},ht.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 _t(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 Ct(t,e,n,r,i,o,s,a){if(!r&&"undirected"===t.type)throw new z("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 z("Graph.".concat(e,": you cannot add an undirected edge to a directed graph. Use the #.addEdge or #.addDirectedEdge instead."));if(a&&!c(a))throw new V("Graph.".concat(e,': invalid attributes. Expecting an object but got "').concat(a,'"'));if(o=""+o,s=""+s,a=a||{},!t.allowSelfLoops&&o===s)throw new z("Graph.".concat(e,': source & target are the same ("').concat(o,"\"), thus creating a loop explicitly forbidden by this graph 'allowSelfLoops' option set to false."));var u=t._nodes.get(o),l=t._nodes.get(s);if(!u)throw new W("Graph.".concat(e,': source node "').concat(o,'" not found.'));if(!l)throw new W("Graph.".concat(e,': target node "').concat(s,'" not found.'));var h={key:null,undirected:r,source:o,target:s,attributes:a};if(n)i=t._edgeKeyGenerator();else if(i=""+i,t._edges.has(i))throw new z("Graph.".concat(e,': the "').concat(i,'" edge already exists in the graph.'));if(!t.multi&&(r?void 0!==u.undirected[s]:void 0!==u.out[s]))throw new z("Graph.".concat(e,': an edge linking "').concat(o,'" to "').concat(s,"\" 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 d=new H(r,i,u,l,a);t._edges.set(i,d);var f=o===s;return r?(u.undirectedDegree++,l.undirectedDegree++,f&&(u.undirectedLoops++,t._undirectedSelfLoopCount++)):(u.outDegree++,l.inDegree++,f&&(u.directedLoops++,t._directedSelfLoopCount++)),t.multi?d.attachMulti():d.attach(),r?t._undirectedSize++:t._directedSize++,h.key=i,t.emit("edgeAdded",h),i}function St(t,e,n,r,i,o,s,u,l){if(!r&&"undirected"===t.type)throw new z("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 z("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 h;if(o=""+o,s=""+s,l&&(h=u,u=void 0),!t.allowSelfLoops&&o===s)throw new z("Graph.".concat(e,': source & target are the same ("').concat(o,"\"), thus creating a loop explicitly forbidden by this graph 'allowSelfLoops' option set to false."));var d,f,p=t._nodes.get(o),m=t._nodes.get(s);if(!n&&(d=t._edges.get(i))){if(!(d.source.key===o&&d.target.key===s||r&&d.source.key===s&&d.target.key===o))throw new z("Graph.".concat(e,': inconsistency detected when attempting to merge the "').concat(i,'" edge with "').concat(o,'" source & "').concat(s,'" target vs. ("').concat(d.source.key,'", "').concat(d.target.key,'").'));f=d}if(f||t.multi||!p||(f=r?p.undirected[s]:p.out[s]),f){var g=[f.key,!1,!1,!1];if(l?!h:!u)return g;if(l){var y=f.attributes;f.attributes=h(y),t.emit("edgeAttributesUpdated",{type:"replace",key:f.key,attributes:f.attributes})}else a(f.attributes,u),t.emit("edgeAttributesUpdated",{type:"merge",key:f.key,attributes:f.attributes,data:u});return g}u=u||{},l&&h&&(u=h(u));var v={key:null,undirected:r,source:o,target:s,attributes:u};if(n)i=t._edgeKeyGenerator();else if(i=""+i,t._edges.has(i))throw new z("Graph.".concat(e,': the "').concat(i,'" edge already exists in the graph.'));var w=!1,b=!1;p||(p=_t(t,o,{}),w=!0,o===s&&(m=p,b=!0)),m||(m=_t(t,s,{}),b=!0),d=new H(r,i,p,m,u),t._edges.set(i,d);var E=o===s;return r?(p.undirectedDegree++,m.undirectedDegree++,E&&(p.undirectedLoops++,t._undirectedSelfLoopCount++)):(p.outDegree++,m.inDegree++,E&&(p.directedLoops++,t._directedSelfLoopCount++)),t.multi?d.attachMulti():d.attach(),r?t._undirectedSize++:t._directedSize++,v.key=i,t.emit("edgeAdded",v),[i,!0,w,b]}function It(t,e){t._edges.delete(e.key);var n=e.source,r=e.target,i=e.attributes,o=e.undirected,s=n===r;o?(n.undirectedDegree--,r.undirectedDegree--,s&&(n.undirectedLoops--,t._undirectedSelfLoopCount--)):(n.outDegree--,r.inDegree--,s&&(n.directedLoops--,t._directedSelfLoopCount--)),t.multi?e.detachMulti():e.detach(),o?t._undirectedSize--:t._directedSize--,t.emit("edgeDropped",{key:e.key,attributes:i,source:n.key,target:r.key,undirected:o})}var Mt=function(n){function r(t){var e;if(e=n.call(this)||this,"boolean"!=typeof(t=a({},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?j:"directed"===t.type?Y:q;h(s(e),"NodeDataClass",r);var i="geid_"+wt()+"_",o=0;return h(s(e),"_attributes",{}),h(s(e),"_nodes",new Map),h(s(e),"_edges",new Map),h(s(e),"_directedSize",0),h(s(e),"_undirectedSize",0),h(s(e),"_directedSelfLoopCount",0),h(s(e),"_undirectedSelfLoopCount",0),h(s(e),"_edgeKeyGenerator",(function(){var t;do{t=i+o++}while(e._edges.has(t));return t})),h(s(e),"_options",t),Et.forEach((function(t){return h(s(e),t,e[t])})),d(s(e),"order",(function(){return e._nodes.size})),d(s(e),"size",(function(){return e._edges.size})),d(s(e),"directedSize",(function(){return e._directedSize})),d(s(e),"undirectedSize",(function(){return e._undirectedSize})),d(s(e),"selfLoopCount",(function(){return e._directedSelfLoopCount+e._undirectedSelfLoopCount})),d(s(e),"directedSelfLoopCount",(function(){return e._directedSelfLoopCount})),d(s(e),"undirectedSelfLoopCount",(function(){return e._undirectedSelfLoopCount})),d(s(e),"multi",e._options.multi),d(s(e),"type",e._options.type),d(s(e),"allowSelfLoops",e._options.allowSelfLoops),d(s(e),"implementation",(function(){return"graphology"})),e}e(r,n);var i=r.prototype;return i._resetInstanceCounters=function(){this._directedSize=0,this._undirectedSize=0,this._directedSelfLoopCount=0,this._undirectedSelfLoopCount=0},i.hasNode=function(t){return this._nodes.has(""+t)},i.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 i=this._nodes.get(t);return!!i&&i.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."))},i.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 i=this._nodes.get(t);return!!i&&i.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."))},i.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."))},i.directedEdge=function(t,e){if("undirected"!==this.type){if(t=""+t,e=""+e,this.multi)throw new z("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}},i.undirectedEdge=function(t,e){if("directed"!==this.type){if(t=""+t,e=""+e,this.multi)throw new z("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}},i.edge=function(t,e){if(this.multi)throw new z("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},i.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)},i.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},i.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},i.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},i.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},i.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},i.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},i.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},i.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},i.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},i.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},i.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},i.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},i.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},i.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},i.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},i.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},i.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},i.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},i.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},i.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},i.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},i.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},i.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]},i.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,i=n.target.key;if(t===r)return i;if(t===i)return r;throw new W('Graph.opposite: the "'.concat(t,'" node is not attached to the "').concat(e,'" edge (').concat(r,", ").concat(i,")."))},i.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},i.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},i.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},i.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},i.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 z('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},i.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&&(a(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])},i.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 i=e?e({}):{};return n=new this.NodeDataClass(t,i),this._nodes.set(t,n),this.emit("nodeAdded",{key:t,attributes:i}),[t,!0]},i.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{It(this,e),e=e.next}while(e)}for(var i in n.in){e=n.in[i];do{It(this,e),e=e.next}while(e)}}if("directed"!==this.type)for(var o in n.undirected){e=n.undirected[o];do{It(this,e),e=e.next}while(e)}this._nodes.delete(t),this.emit("nodeDropped",{key:t,attributes:n.attributes})},i.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 It(this,e),this},i.dropDirectedEdge=function(t,e){if(arguments.length<2)throw new z("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 z("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 It(this,n),this},i.dropUndirectedEdge=function(t,e){if(arguments.length<2)throw new z("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 z("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 It(this,n),this},i.clear=function(){this._edges.clear(),this._nodes.clear(),this._resetInstanceCounters(),this.emit("cleared")},i.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")},i.getAttribute=function(t){return this._attributes[t]},i.getAttributes=function(){return this._attributes},i.hasAttribute=function(t){return this._attributes.hasOwnProperty(t)},i.setAttribute=function(t,e){return this._attributes[t]=e,this.emit("attributesUpdated",{type:"set",attributes:this._attributes,name:t}),this},i.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},i.removeAttribute=function(t){return delete this._attributes[t],this.emit("attributesUpdated",{type:"remove",attributes:this._attributes,name:t}),this},i.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},i.mergeAttributes=function(t){if(!c(t))throw new V("Graph.mergeAttributes: provided attributes are not a plain object.");return a(this._attributes,t),this.emit("attributesUpdated",{type:"merge",attributes:this._attributes,data:t}),this},i.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},i.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,i=this._nodes.values();!0!==(n=i.next()).done;)(r=n.value).attributes=t(r.key,r.attributes);this.emit("eachNodeAttributesUpdated",{hints:e||null})},i.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,i,o,s=this._edges.values();!0!==(n=s.next()).done;)i=(r=n.value).source,o=r.target,r.attributes=t(r.key,r.attributes,i.key,o.key,i.attributes,o.attributes,r.undirected);this.emit("eachEdgeAttributesUpdated",{hints:e||null})},i.forEachAdjacencyEntry=function(t){if("function"!=typeof t)throw new V("Graph.forEachAdjacencyEntry: expecting a callback.");mt(!1,!1,!1,this,t)},i.forEachAdjacencyEntryWithOrphans=function(t){if("function"!=typeof t)throw new V("Graph.forEachAdjacencyEntryWithOrphans: expecting a callback.");mt(!1,!1,!0,this,t)},i.forEachAssymetricAdjacencyEntry=function(t){if("function"!=typeof t)throw new V("Graph.forEachAssymetricAdjacencyEntry: expecting a callback.");mt(!1,!0,!1,this,t)},i.forEachAssymetricAdjacencyEntryWithOrphans=function(t){if("function"!=typeof t)throw new V("Graph.forEachAssymetricAdjacencyEntryWithOrphans: expecting a callback.");mt(!1,!0,!0,this,t)},i.nodes=function(){return"function"==typeof Array.from?Array.from(this._nodes.keys()):G(this._nodes.keys(),this._nodes.size)},i.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)},i.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},i.mapNodes=function(t){if("function"!=typeof t)throw new V("Graph.mapNode: expecting a callback.");for(var e,n,r=this._nodes.values(),i=new Array(this.order),o=0;!0!==(e=r.next()).done;)n=e.value,i[o++]=t(n.key,n.attributes);return i},i.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},i.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},i.filterNodes=function(t){if("function"!=typeof t)throw new V("Graph.filterNodes: expecting a callback.");for(var e,n,r=this._nodes.values(),i=[];!0!==(e=r.next()).done;)t((n=e.value).key,n.attributes)&&i.push(n.key);return i},i.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,i=e,o=this._nodes.values();!0!==(n=o.next()).done;)i=t(i,(r=n.value).key,r.attributes);return i},i.nodeEntries=function(){var t=this._nodes.values();return new T((function(){var e=t.next();if(e.done)return e;var n=e.value;return{value:{node:n.key,attributes:n.attributes},done:!1}}))},i.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=a({},e.attributes)),n}(r,t)}));var r=new Array(this._edges.size);return n=0,this._edges.forEach((function(e,i){r[n++]=function(t,e,n){var r={key:e,source:n.source.key,target:n.target.key};return l(n.attributes)||(r.attributes=a({},n.attributes)),"mixed"===t&&n.undirected&&(r.undirected=!0),r}(t.type,i,e)})),{options:{type:this.type,multi:this.multi,allowSelfLoops:this.allowSelfLoops},attributes:this.getAttributes(),nodes:e,edges:r}},i.import=function(t){var e,n,i,o,s,a=this,u=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(t instanceof r)return t.forEachNode((function(t,e){u?a.mergeNode(t,e):a.addNode(t,e)})),t.forEachEdge((function(t,e,n,r,i,o,s){u?s?a.mergeUndirectedEdgeWithKey(t,n,r,e):a.mergeDirectedEdgeWithKey(t,n,r,e):s?a.addUndirectedEdgeWithKey(t,n,r,e):a.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(i=t.nodes,!Array.isArray(i))throw new V("Graph.import: invalid nodes. Expecting an array.");for(e=0,n=i.length;e<n;e++){gt(o=i[e]);var l=o,h=l.key,d=l.attributes;u?this.mergeNode(h,d):this.addNode(h,d)}}if(t.edges){var f=!1;if("undirected"===this.type&&(f=!0),i=t.edges,!Array.isArray(i))throw new V("Graph.import: invalid edges. Expecting an array.");for(e=0,n=i.length;e<n;e++){yt(s=i[e]);var p=s,m=p.source,g=p.target,y=p.attributes,v=p.undirected,w=void 0===v?f:v;"key"in s?(u?w?this.mergeUndirectedEdgeWithKey:this.mergeDirectedEdgeWithKey:w?this.addUndirectedEdgeWithKey:this.addDirectedEdgeWithKey).call(this,s.key,m,g,y):(u?w?this.mergeUndirectedEdge:this.mergeDirectedEdge:w?this.addUndirectedEdge:this.addDirectedEdge).call(this,m,g,y)}}return this},i.nullCopy=function(t){var e=new r(a({},this._options,t));return e.replaceAttributes(a({},this.getAttributes())),e},i.emptyCopy=function(t){var e=this.nullCopy(t);return this._nodes.forEach((function(t,n){var r=a({},t.attributes);t=new e.NodeDataClass(n,r),e._nodes.set(n,t)})),e},i.copy=function(t){if("string"==typeof(t=t||{}).type&&t.type!==this.type&&"mixed"!==t.type)throw new z('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 z("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 z("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),i=this._edges.values();!0!==(e=i.next()).done;)Ct(r,"copy",!1,(n=e.value).undirected,n.key,n.source.key,n.target.key,a({},n.attributes));return r},i.toJSON=function(){return this.export()},i.toString=function(){return"[object Graph]"},i.inspect=function(){var e=this,n={};this._nodes.forEach((function(t,e){n[e]=t.attributes}));var r={},i={};this._edges.forEach((function(t,n){var o,s=t.undirected?"--":"->",a="",u=t.source.key,c=t.target.key;t.undirected&&u>c&&(o=u,u=c,c=o);var l="(".concat(u,")").concat(s,"(").concat(c,")");n.startsWith("geid_")?e.multi&&(void 0===i[l]?i[l]=0:i[l]++,a+="".concat(i[l],". ")):a+="[".concat(n,"]: "),r[a+=l]=t.attributes}));var o={};for(var s in this)this.hasOwnProperty(s)&&!Et.has(s)&&"function"!=typeof this[s]&&"symbol"!==t(s)&&(o[s]=this[s]);return o.attributes=this._attributes,o.nodes=n,o.edges=r,h(o,"constructor",this.constructor),o},r}(m.exports.EventEmitter);"undefined"!=typeof Symbol&&(Mt.prototype[Symbol.for("nodejs.util.inspect.custom")]=Mt.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?Ct:St;t.generateKey?Mt.prototype[n]=function(i,o,s){return r(this,n,!0,"undirected"===(t.type||this.type),null,i,o,s,"update"===e)}:Mt.prototype[n]=function(i,o,s,a){return r(this,n,!1,"undirected"===(t.type||this.type),i,o,s,a,"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)}))}(Mt),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")}))}(Mt),function(t){tt.forEach((function(e){!function(t,e){var n=e.name,r=e.type,i=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,i="undirected"===e?t.undirectedSize:t.directedSize,o=new Array(i),s="undirected"===e,a=t._edges.values(),u=0;!0!==(n=a.next()).done;)(r=n.value).undirected===s&&(o[u++]=r.key);return o}(this,r);if(1===arguments.length){t=""+t;var o=this._nodes.get(t);if(void 0===o)throw new W("Graph.".concat(n,': could not find the "').concat(t,'" node in the graph.'));return function(t,e,n,r){var i=[];return ut(!1,t,e,n,r,(function(t){i.push(t)})),i}(this.multi,"mixed"===r?this.type:r,i,o)}if(2===arguments.length){t=""+t,e=""+e;var s=this._nodes.get(t);if(!s)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,i){var o=[];return ct(!1,t,e,n,r,i,(function(t){o.push(t)})),o}(r,this.multi,i,s,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,i=e.direction,o="forEach"+n[0].toUpperCase()+n.slice(1,-1);t.prototype[o]=function(t,e,n){if("mixed"===r||"mixed"===this.type||r===this.type){if(1===arguments.length)return at(!1,this,r,n=t);if(2===arguments.length){t=""+t,n=e;var s=this._nodes.get(t);if(void 0===s)throw new W("Graph.".concat(o,': could not find the "').concat(t,'" node in the graph.'));return ut(!1,this.multi,"mixed"===r?this.type:r,i,s,n)}if(3===arguments.length){t=""+t,e=""+e;var a=this._nodes.get(t);if(!a)throw new W("Graph.".concat(o,': could not find the "').concat(t,'" source node in the graph.'));if(!this._nodes.has(e))throw new W("Graph.".concat(o,': could not find the "').concat(e,'" target node in the graph.'));return ct(!1,r,this.multi,i,a,e,n)}throw new V("Graph.".concat(o,": too many arguments (expecting 1, 2 or 3 and got ").concat(arguments.length,")."))}};var s="map"+n[0].toUpperCase()+n.slice(1);t.prototype[s]=function(){var t,e=Array.prototype.slice.call(arguments),n=e.pop();if(0===e.length){var i=0;"directed"!==r&&(i+=this.undirectedSize),"undirected"!==r&&(i+=this.directedSize),t=new Array(i);var s=0;e.push((function(e,r,i,o,a,u,c){t[s++]=n(e,r,i,o,a,u,c)}))}else t=[],e.push((function(e,r,i,o,s,a,u){t.push(n(e,r,i,o,s,a,u))}));return this[o].apply(this,e),t};var a="filter"+n[0].toUpperCase()+n.slice(1);t.prototype[a]=function(){var t=Array.prototype.slice.call(arguments),e=t.pop(),n=[];return t.push((function(t,r,i,o,s,a,u){e(t,r,i,o,s,a,u)&&n.push(t)})),this[o].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,i,o,s,a,u){r=t(r,e,n,i,o,s,a,u)})),this[o].apply(this,n),r}}(t,e),function(t,e){var n=e.name,r=e.type,i=e.direction,o="find"+n[0].toUpperCase()+n.slice(1,-1);t.prototype[o]=function(t,e,n){if("mixed"!==r&&"mixed"!==this.type&&r!==this.type)return!1;if(1===arguments.length)return at(!0,this,r,n=t);if(2===arguments.length){t=""+t,n=e;var s=this._nodes.get(t);if(void 0===s)throw new W("Graph.".concat(o,': could not find the "').concat(t,'" node in the graph.'));return ut(!0,this.multi,"mixed"===r?this.type:r,i,s,n)}if(3===arguments.length){t=""+t,e=""+e;var a=this._nodes.get(t);if(!a)throw new W("Graph.".concat(o,': could not find the "').concat(t,'" source node in the graph.'));if(!this._nodes.has(e))throw new W("Graph.".concat(o,': could not find the "').concat(e,'" target node in the graph.'));return ct(!0,r,this.multi,i,a,e,n)}throw new V("Graph.".concat(o,": too many arguments (expecting 1, 2 or 3 and got ").concat(arguments.length,")."))};var s="some"+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,i,o,s,a){return e(t,n,r,i,o,s,a)})),!!this[o].apply(this,t)};var a="every"+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,i,o,s,a){return!e(t,n,r,i,o,s,a)})),!this[o].apply(this,t)}}(t,e),function(t,e){var n=e.name,r=e.type,i=e.direction,o=n.slice(0,-1)+"Entries";t.prototype[o]=function(t,e){if("mixed"!==r&&"mixed"!==this.type&&r!==this.type)return T.empty();if(!arguments.length)return function(t,e){if(0===t.size)return T.empty();var n="mixed"!==e&&e!==t.type,r="undirected"===e,i=t._edges.values();return new T((function(){for(var t,e;;){if((t=i.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(o,': could not find the "').concat(t,'" node in the graph.'));return function(t,e,n){var r=T.empty();return"undirected"!==t&&("out"!==e&&void 0!==n.in&&(r=J(r,rt(n.in))),"in"!==e&&void 0!==n.out&&(r=J(r,rt(n.out,e?void 0:n.key)))),"directed"!==t&&void 0!==n.undirected&&(r=J(r,rt(n.undirected))),r}(r,i,n)}if(2===arguments.length){t=""+t,e=""+e;var s=this._nodes.get(t);if(!s)throw new W("Graph.".concat(o,': could not find the "').concat(t,'" source node in the graph.'));if(!this._nodes.has(e))throw new W("Graph.".concat(o,': could not find the "').concat(e,'" target node in the graph.'));return function(t,e,n,r){var i=T.empty();return"undirected"!==t&&(void 0!==n.in&&"out"!==e&&r in n.in&&(i=J(i,st(n.in,r))),void 0!==n.out&&"in"!==e&&r in n.out&&(e||n.key!==r)&&(i=J(i,st(n.out,r)))),"directed"!==t&&void 0!==n.undirected&&r in n.undirected&&(i=J(i,st(n.undirected,r))),i}(r,i,s,e)}throw new V("Graph.".concat(o,": too many arguments (expecting 0, 1 or 2 and got ").concat(arguments.length,")."))}}(t,e)}))}(Mt),function(t){lt.forEach((function(e){(function(t,e){var n=e.name,r=e.type,i=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,i,e)}})(t,e),function(t,e){var n=e.name,r=e.type,i=e.direction,o="forEach"+n[0].toUpperCase()+n.slice(1,-1);t.prototype[o]=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(o,': could not find the "').concat(t,'" node in the graph.'));ft(!1,"mixed"===r?this.type:r,i,n,e)}};var s="map"+n[0].toUpperCase()+n.slice(1);t.prototype[s]=function(t,e){var n=[];return this[o](t,(function(t,r){n.push(e(t,r))})),n};var a="filter"+n[0].toUpperCase()+n.slice(1);t.prototype[a]=function(t,e){var n=[];return this[o](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[o](t,(function(t,n){r=e(r,t,n)})),r}}(t,e),function(t,e){var n=e.name,r=e.type,i=e.direction,o=n[0].toUpperCase()+n.slice(1,-1),s="find"+o;t.prototype[s]=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(s,': could not find the "').concat(t,'" node in the graph.'));return ft(!0,"mixed"===r?this.type:r,i,n,e)}};var a="some"+o;t.prototype[a]=function(t,e){return!!this[s](t,e)};var u="every"+o;t.prototype[u]=function(t,e){return!this[s](t,(function(t,n){return!e(t,n)}))}}(t,e),function(t,e){var n=e.name,r=e.type,i=e.direction,o=n.slice(0,-1)+"Entries";t.prototype[o]=function(t){if("mixed"!==r&&"mixed"!==this.type&&r!==this.type)return T.empty();t=""+t;var e=this._nodes.get(t);if(void 0===e)throw new W("Graph.".concat(o,': 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=T.empty(),i=new ht;return"undirected"!==t&&("out"!==e&&(r=J(r,pt(i,n,n.in))),"in"!==e&&(r=J(r,pt(i,n,n.out)))),"directed"!==t&&(r=J(r,pt(i,n,n.undirected))),r}("mixed"===r?this.type:r,i,e)}}(t,e)}))}(Mt);var Nt=function(t){function n(e){var n=a({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}(Mt),xt=function(t){function n(e){var n=a({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}(Mt),Lt=function(t){function n(e){var n=a({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}(Mt),Tt=function(t){function n(e){var n=a({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}(Mt),Ot=function(t){function n(e){var n=a({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}(Mt);function Pt(t){t.from=function(e,n){var r=a({},e.options,n),i=new t(r);return i.import(e),i}}return Pt(Mt),Pt(Nt),Pt(xt),Pt(Lt),Pt(Tt),Pt(Ot),Mt.Graph=Mt,Mt.DirectedGraph=Nt,Mt.UndirectedGraph=xt,Mt.MultiGraph=Lt,Mt.MultiDirectedGraph=Tt,Mt.MultiUndirectedGraph=Ot,Mt.InvalidArgumentsGraphError=V,Mt.NotFoundGraphError=W,Mt.UsageGraphError=z,Mt}()},6572:function(t){var e;t.exports=(e=function(t,e){var n=Array.prototype.concat,r=Array.prototype.slice,i=Object.prototype.toString;function o(e,n){var r=e>n?e:n;return t.pow(10,17-~~(t.log(r>0?r:-r)*t.LOG10E))}var s=Array.isArray||function(t){return"[object Array]"===i.call(t)};function a(t){return"[object Function]"===i.call(t)}function u(t){return"number"==typeof t&&t-t==0}function c(){return new c._init(arguments)}function l(){return 0}function h(){return 1}function d(t,e){return t===e?1:0}c.fn=c.prototype,c._init=function(t){if(s(t[0]))if(s(t[0][0])){a(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]=a(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:o,isArray:s,isFunction:a,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 s(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(s(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(i){n[i][r]=t[i][e]}))})),n}for(var r=new Array(t.length),i=0;i<t.length;i++)r[i]=[t[i][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,i,o,a=[];for(s(t[0])||(t=[t]),n=t.length,r=t[0].length,o=0;o<r;o++){for(e=new Array(n),i=0;i<n;i++)e[i]=t[i][o];a.push(e)}return 1===a.length?a[0]:a},c.map=function(t,e,n){var r,i,o,a,u;for(s(t[0])||(t=[t]),i=t.length,o=t[0].length,a=n?t:new Array(i),r=0;r<i;r++)for(a[r]||(a[r]=new Array(o)),u=0;u<o;u++)a[r][u]=e(t[r][u],r,u);return 1===a.length?a[0]:a},c.cumreduce=function(t,e,n){var r,i,o,a,u;for(s(t[0])||(t=[t]),i=t.length,o=t[0].length,a=n?t:new Array(i),r=0;r<i;r++)for(a[r]||(a[r]=new Array(o)),o>0&&(a[r][0]=t[r][0]),u=1;u<o;u++)a[r][u]=e(a[r][u-1],t[r][u]);return 1===a.length?a[0]:a},c.alter=function(t,e){return c.map(t,e,!0)},c.create=function(t,e,n){var r,i,o=new Array(t);for(a(e)&&(n=e,e=t),r=0;r<t;r++)for(o[r]=new Array(e),i=0;i<e;i++)o[r][i]=n(r,i);return o},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,h)},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,d)},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){a(r)||(r=!1);var i,s=[],u=o(t,e),c=(e*u-t*u)/((n-1)*u),l=t;for(i=0;l<=e&&i<n;l=(t*u+c*u*++i)/u)s.push(r?r(l,i):l);return s},c.arange=function(t,n,r){var i,o=[];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(i=t;i<n;i+=r)o.push(i);else for(i=t;i>n;i+=r)o.push(i);return o},c.slice=function(){function t(t,n,r,i){var o,s=[],a=t.length;if(n===e&&r===e&&i===e)return c.copy(t);if(i=i||1,(n=(n=n||0)>=0?n:a+n)===(r=(r=r||t.length)>=0?r:a+r)||0===i)return[];if(n<r&&i<0)return[];if(n>r&&i>0)return[];if(i>0)for(o=n;o<r;o+=i)s.push(t[o]);else for(o=n;o>r;o+=i)s.push(t[o]);return s}return function(e,n){var r,i;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),(i=n.row||{}).start,i.end,i.step):(i=n.row||{},r=n.col||{},t(e,i.start,i.end,i.step).map((function(e){return t(e,r.start,r.end,r.step)})))}}(),c.sliceAssign=function(n,r,i){var o,s;if(u(r.row)){if(u(r.col))return n[r.row][r.col]=i;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,o=c.arange(r.col.start,t.min(n.length,r.col.end),r.col.step);var a=r.row;return o.forEach((function(t,e){n[a][t]=i[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,s=c.arange(r.row.start,t.min(n[0].length,r.row.end),r.row.step);var l=r.col;return s.forEach((function(t,e){n[t][l]=i[e]})),n}return i[0].length===e&&(i=[i]),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,s=c.arange(r.row.start,t.min(n.length,r.row.end),r.row.step),o=c.arange(r.col.start,t.min(n[0].length,r.col.end),r.col.step),s.forEach((function(t,e){o.forEach((function(r,o){n[t][r]=i[e][o]}))})),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),s(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 i(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),i=0,o=e.length;--o>=0;)i+=(n=e[o]-r)*n;return i},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),i=t.mean(r);return e.exp(i)},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=[],i={};for(e=0;e<t.length;e++)i[u=t[e]]?i[u]++:(i[u]=1,n.push(u));var o=n.sort(r),s={},a=1;for(e=0;e<o.length;e++){var u,c=i[u=o[e]],l=(a+(a+c-1))/2;s[u]=l,a+=c}return t.map((function(t){return s[t]}))},t.mode=function(t){var e,n=t.length,i=t.slice().sort(r),o=1,s=0,a=0,u=[];for(e=0;e<n;e++)i[e]===i[e+1]?o++:(o>s?(u=[i[e]],s=o,a=0):o===s&&(u.push(i[e]),a++),o=1);return 0===a?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,i=new Array(r),o=0;o<r;o++)i[o]=e[o]-n;return i},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),i=[],o=n.length-1;o>=0;o--)i.push(e.abs(n[o]-r));return t.mean(i)},t.meddev=function(n){for(var r=t.median(n),i=[],o=n.length-1;o>=0;o--)i.push(e.abs(n[o]-r));return t.median(i)},t.coeffvar=function(e){return t.stdev(e)/t.mean(e)},t.quartiles=function(t){var n=t.length,i=t.slice().sort(r);return[i[e.round(n/4)-1],i[e.round(n/2)-1],i[e.round(3*n/4)-1]]},t.quantiles=function(t,n,o,s){var a,u,c,l,h,d=t.slice().sort(r),f=[n.length],p=t.length;for(void 0===o&&(o=3/8),void 0===s&&(s=3/8),a=0;a<n.length;a++)c=p*(u=n[a])+(o+u*(1-o-s)),l=e.floor(i(c,1,p-1)),h=i(c-l,0,1),f[a]=(1-h)*d[l-1]+h*d[l];return f},t.percentile=function(t,e,n){var i=t.slice().sort(r),o=e*(i.length+(n?1:-1))+(n?0:1),s=parseInt(o),a=o-s;return s+1<i.length?i[s-1]+a*(i[s]-i[s-1]):i[s-1]},t.percentileOfScore=function(t,e,n){var r,i,o=0,s=t.length,a=!1;for("strict"===n&&(a=!0),i=0;i<s;i++)r=t[i],(a&&r<e||!a&&r<=e)&&o++;return o/s},t.histogram=function(n,r){r=r||4;var i,o=t.min(n),s=(t.max(n)-o)/r,a=n.length,u=[];for(i=0;i<r;i++)u[i]=0;for(i=0;i<a;i++)u[e.min(e.floor((n[i]-o)/s),r-1)]+=1;return u},t.covariance=function(e,n){var r,i=t.mean(e),o=t.mean(n),s=e.length,a=new Array(s);for(r=0;r<s;r++)a[r]=(e[r]-i)*(n[r]-o);return t.sum(a)/(s-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 i=t.mean(n),o=t.stdev(n),s=n.length,a=0,u=0;u<s;u++)a+=e.pow((n[u]-i)/o,r);return a/n.length},t.skewness=function(e){return t.stanMoment(e,3)},t.kurtosis=function(e){return t.stanMoment(e,4)-3};var o=t.prototype;!function(e){for(var r=0;r<e.length;r++)!function(e){o[e]=function(r,i){var s=[],a=0,u=this;if(n(r)&&(i=r,r=!1),i)return setTimeout((function(){i.call(u,o[e].call(u,r))})),this;if(this.length>1){for(u=!0===r?this:this.transpose();a<u.length;a++)s[a]=t[e](u[a]);return s}return t[e](this[0],r)}}(e[r])}("cumsum cumprod".split(" ")),function(e){for(var r=0;r<e.length;r++)!function(e){o[e]=function(r,i){var s=[],a=0,u=this;if(n(r)&&(i=r,r=!1),i)return setTimeout((function(){i.call(u,o[e].call(u,r))})),this;if(this.length>1){for("sumrow"!==e&&(u=!0===r?this:this.transpose());a<u.length;a++)s[a]=t[e](u[a]);return!0===r?t[e](t.utils.toVector(s)):s}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){o[e]=function(){var r,i=[],s=0,a=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(a,o[e].apply(a,c))})),this}r=void 0;var l=function(n){return t[e].apply(a,[n].concat(u))};if(this.length>1){for(a=a.transpose();s<a.length;s++)i[s]=l(a[s]);return i}return l(this[0])}}(e[r])}("quantiles percentileOfScore".split(" "))}(e,Math),function(t,e){t.gammaln=function(t){var n,r,i,o=0,s=[76.18009172947146,-86.50532032941678,24.01409824083091,-1.231739572450155,.001208650973866179,-5395239384953e-18],a=1.000000000190015;for(i=(r=n=t)+5.5,i-=(n+.5)*e.log(i);o<6;o++)a+=s[o]/++r;return e.log(2.5066282746310007*a/n)-i},t.loggam=function(t){var n,r,i,o,s,a,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),i=2*e.PI,s=c[9],a=8;a>=0;a--)s*=r,s+=c[a];if(o=s/n+.5*e.log(i)+(n-.5)*e.log(n)-n,t<=7)for(a=1;a<=u;a++)o-=e.log(n-1),n-=1;return o},t.gammafn=function(t){var n,r,i,o,s=[-1.716185138865495,24.76565080557592,-379.80425647094563,629.3311553128184,866.9662027904133,-31451.272968848367,-36144.413418691176,66456.14382024054],a=[-30.8402300119739,315.35062697960416,-1015.1563674902192,-3107.771671572311,22538.11842098015,4755.846277527881,-134659.9598649693,-115132.2596755535],u=!1,c=0,l=0,h=0,d=t;if(t>171.6243769536076)return 1/0;if(d<=0){if(!(o=d%1+36e-17))return 1/0;u=(1&d?-1:1)*e.PI/e.sin(e.PI*o),d=1-d}for(i=d,r=d<1?d++:(d-=c=(0|d)-1)-1,n=0;n<8;++n)h=(h+s[n])*r,l=l*r+a[n];if(o=h/l+1,i<d)o/=i;else if(i>d)for(n=0;n<c;++n)o*=d,d++;return u&&(o=u/o),o},t.gammap=function(e,n){return t.lowRegGamma(e,n)*t.gammafn(e)},t.lowRegGamma=function(n,r){var i,o=t.gammaln(n),s=n,a=1/n,u=a,c=r+1-n,l=1/1e-30,h=1/c,d=h,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++)a+=u*=r/++s;return a*e.exp(-r+n*e.log(r)-o)}for(;f<=p;f++)d*=(h=1/(h=(i=-f*(f-n))*h+(c+=2)))*(l=c+i/l);return 1-d*e.exp(-r+n*e.log(r)-o)},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 i,o,s,a,u=1e-30,c=1,l=n+r,h=n+1,d=n-1,f=1,p=1-l*t/h;for(e.abs(p)<u&&(p=u),a=p=1/p;c<=100&&(p=1+(o=c*(r-c)*t/((d+(i=2*c))*(n+i)))*p,e.abs(p)<u&&(p=u),f=1+o/f,e.abs(f)<u&&(f=u),a*=(p=1/p)*f,p=1+(o=-(n+c)*(l+c)*t/((n+i)*(h+i)))*p,e.abs(p)<u&&(p=u),f=1+o/f,e.abs(f)<u&&(f=u),a*=s=(p=1/p)*f,!(e.abs(s-1)<3e-7));c++);return a},t.gammapinv=function(n,r){var i,o,s,a,u,c,l=0,h=r-1,d=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(h),c=e.exp(h*(u-1)-d),a=n<.5?n:1-n,i=(2.30753+.27061*(o=e.sqrt(-2*e.log(a))))/(1+o*(.99229+.04481*o))-o,n<.5&&(i=-i),i=e.max(.001,r*e.pow(1-1/(9*r)-i/(3*e.sqrt(r)),3))):i=n<(o=1-r*(.253+.12*r))?e.pow(n/o,1/r):1-e.log(1-(n-o)/(1-o));l<12;l++){if(i<=0)return 0;if((i-=o=(s=(t.lowRegGamma(r,i)-n)/(o=r>1?c*e.exp(-(i-h)+h*(e.log(i)-u)):e.exp(-i+h*e.log(i)-d)))/(1-.5*e.min(1,s*((r-1)/i-1))))<=0&&(i=.5*(i+o)),e.abs(o)<1e-8*i)break}return i},t.erf=function(t){var n,r,i,o,s=[-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],a=s.length-1,u=!1,c=0,l=0;for(t<0&&(t=-t,u=!0),r=4*(n=2/(2+t))-2;a>0;a--)i=c,c=r*c-l+s[a],l=i;return o=n*e.exp(-t*t+.5*(s[0]+r*c)-l),u?o-1:1-o},t.erfc=function(e){return 1-t.erf(e)},t.erfcinv=function(n){var r,i,o,s,a=0;if(n>=2)return-100;if(n<=0)return 100;for(s=n<1?n:2-n,r=-.70711*((2.30753+.27061*(o=e.sqrt(-2*e.log(s/2))))/(1+o*(.99229+.04481*o))-o);a<2;a++)r+=(i=t.erfc(r)-s)/(1.1283791670955126*e.exp(-r*r)-r*i);return n<1?r:-r},t.ibetainv=function(n,r,i){var o,s,a,u,c,l,h,d,f,p,m=r-1,g=i-1,y=0;if(n<=0)return 0;if(n>=1)return 1;for(r>=1&&i>=1?(a=n<.5?n:1-n,l=(2.30753+.27061*(u=e.sqrt(-2*e.log(a))))/(1+u*(.99229+.04481*u))-u,n<.5&&(l=-l),h=(l*l-3)/6,d=2/(1/(2*r-1)+1/(2*i-1)),f=l*e.sqrt(h+d)/d-(1/(2*i-1)-1/(2*r-1))*(h+5/6-2/(3*d)),l=r/(r+i*e.exp(2*f))):(o=e.log(r/(r+i)),s=e.log(i/(r+i)),l=n<(u=e.exp(r*o)/r)/(f=u+(c=e.exp(i*s)/i))?e.pow(r*f*n,1/r):1-e.pow(i*f*(1-n),1/i)),p=-t.gammaln(r)-t.gammaln(i)+t.gammaln(r+i);y<10;y++){if(0===l||1===l)return l;if((l-=u=(c=(t.ibeta(l,r,i)-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,i){var o=0===n||1===n?0:e.exp(t.gammaln(r+i)-t.gammaln(r)-t.gammaln(i)+r*e.log(n)+i*e.log(1-n));return!(n<0||n>1)&&(n<(r+1)/(r+i+2)?o*t.betacf(n,r,i)/r:1-o*t.betacf(1-n,i,r)/i)},t.randn=function(n,r){var i,o,s,a,u;if(r||(r=n),n)return t.create(n,r,(function(){return t.randn()}));do{i=t._random_fn(),o=1.7156*(t._random_fn()-.5),u=(s=i-.449871)*s+(a=e.abs(o)+.386595)*(.196*a-.25472*s)}while(u>.27597&&(u>.27846||o*o>-4*e.log(i)*i*i));return o/i},t.randg=function(n,r,i){var o,s,a,u,c,l,h=n;if(i||(i=r),n||(n=1),r)return(l=t.zeros(r,i)).alter((function(){return t.randg(n)})),l;n<1&&(n+=1),o=n-1/3,s=1/e.sqrt(9*o);do{do{u=1+s*(c=t.randn())}while(u<=0);u*=u*u,a=t._random_fn()}while(a>1-.331*e.pow(c,4)&&e.log(a)>.5*c*c+o*(1-u+e.log(u)));if(n==h)return o*u;do{a=t._random_fn()}while(0===a);return e.pow(a,1/h)*o*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,i){for(var o,s=0,a=1,u=1,c=1,l=0,h=0;e.abs((u-h)/u)>i;)h=u,a=c+(o=-(n+l)*(n+r+l)*t/(n+2*l)/(n+2*l+1))*a,u=(s=u+o*s)+(o=(l+=1)*(r-l)*t/(n+2*l-1)/(n+2*l))*u,s/=c=a+o*c,a/=c,u/=c,c=1;return u/n}function r(n,r,i){var o=[.9815606342467192,.9041172563704749,.7699026741943047,.5873179542866175,.3678314989981802,.1252334085114689],s=[.04717533638651183,.10693932599531843,.16007832854334622,.20316742672306592,.2334925365383548,.24914704581340277],a=.5*n;if(a>=8)return 1;var u,c=2*t.normal.cdf(a,0,1,1,0)-1;c=c>=e.exp(-50/i)?e.pow(c,i):0;for(var l=a,h=(8-a)/(u=n>3?2:3),d=l+h,f=0,p=i-1,m=1;m<=u;m++){for(var g=0,y=.5*(d+l),v=.5*(d-l),w=1;w<=12;w++){var b,E=y+v*(6<w?o[(b=12-w+1)-1]:-o[(b=w)-1]),A=E*E;if(A>60)break;var _=2*t.normal.cdf(E,0,1,1,0)*.5-2*t.normal.cdf(E,n,1,1,0)*.5;_>=e.exp(-30/p)&&(g+=_=s[b-1]*e.exp(-.5*A)*e.pow(_,p))}f+=g*=2*v*i/e.sqrt(2*e.PI),l=d,d+=h}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,i){var o=t[e](n,r,i);return o.data=this,o},t[e].prototype.sample=function(n){var r=this._a,i=this._b,o=this._c;return n?t.alter(n,(function(){return t[e].sample(r,i,o)})):t[e].sample(r,i,o)},function(n){for(var r=0;r<n.length;r++)!function(n){t[e].prototype[n]=function(r){var i=this._a,o=this._b,s=this._c;return r||0===r||(r=this.data),"number"!=typeof r?t.fn.map.call(r,(function(r){return t[e][n](r,i,o,s)})):t[e][n](r,i,o,s)}}(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,i){return n>1||n<0?0:1==r&&1==i?1:r<512&&i<512?e.pow(n,r-1)*e.pow(1-n,i-1)/t.betafn(r,i):e.exp((r-1)*e.log(n)+(i-1)*e.log(1-n)-t.betaln(r,i))},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,i){var o;return n<0?0:r<=2?0===n&&r<2?1/0:0===n&&2===r?1:1/t.betafn(r/2,i/2)*e.pow(r/i,r/2)*e.pow(n,r/2-1)*e.pow(1+r/i*n,-(r+i)/2):(o=r*n/(i+n*r),r*(i/(i+n*r))/2*t.binomial.pdf((r-2)/2,(r+i-2)/2,o))},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,i){return n<0?0:0===n&&1===r?1/i:e.exp((r-1)*e.log(n)-n/i-t.gammaln(r)-r*e.log(i))},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,i){return n<=0?0:e.exp(-(r+1)*e.log(n)-i/n-t.gammaln(r)+r*e.log(i))},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,i){return n<0?0:.5+.5*t.erf((e.log(n)-r)/e.sqrt(2*i*i))},inv:function(n,r,i){return e.exp(-1.4142135623730951*i*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,i){return e.abs(i)<1e-14?t.studentt.pdf(n,r):e.abs(n)<1e-14?e.exp(t.gammaln((r+1)/2)-i*i/2-.5*e.log(e.PI*r)-t.gammaln(r/2)):r/n*(t.noncentralt.cdf(n*e.sqrt(1+2/r),r+2,i)-t.noncentralt.cdf(n,r,i))},cdf:function(n,r,i){var o=1e-14;if(e.abs(i)<o)return t.studentt.cdf(n,r);var s=!1;n<0&&(s=!0,i=-i);for(var a=t.normal.cdf(-i,0,1),u=o+1,c=u,l=n*n/(n*n+r),h=0,d=e.exp(-i*i/2),f=e.exp(-i*i/2-.5*e.log(2)-t.gammaln(1.5))*i;h<200||c>o||u>o;)c=u,h>0&&(d*=i*i/(2*h),f*=i*i/(2*(h+.5))),a+=.5*(u=d*t.beta.cdf(l,h+.5,r/2)+f*t.beta.cdf(l,h+1,r/2)),h++;return s?1-a:a}}),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,i){return.5*(1+t.erf((n-r)/e.sqrt(2*i*i)))},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 i=r/2;return t.ibeta((n+e.sqrt(n*n+r))/(2*e.sqrt(n*n+r)),i,i)},inv:function(n,r){var i=t.ibetainv(2*e.min(n,1-n),.5*r,.5);return i=e.sqrt(r*(1-i)/i),n>.5?i:-i},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,i){return 0===i||1===i?r*i===n?1:0:t.combination(r,n)*e.pow(i,n)*e.pow(1-i,r-n)},cdf:function(r,i,o){var s,a=1e-10;if(r<0)return 0;if(r>=i)return 1;if(o<0||o>1||i<=0)return NaN;var u=o,c=(r=e.floor(r))+1,l=i-r,h=c+l,d=e.exp(t.gammaln(h)-t.gammaln(l)-t.gammaln(c)+c*e.log(u)+l*e.log(1-u));return s=u<(c+1)/(h+2)?d*n(u,c,l,a):1-d*n(1-u,l,c,a),e.round(1/a*(1-s))/(1/a)}}),t.extend(t.negbin,{pdf:function(n,r,i){return n===n>>>0&&(n<0?0:t.combination(n+r-1,r-1)*e.pow(1-i,n)*e.pow(i,r))},cdf:function(e,n,r){var i=0,o=0;if(e<0)return 0;for(;o<=e;o++)i+=t.negbin.pdf(o,n,r);return i}}),t.extend(t.hypgeom,{pdf:function(n,r,i,o){if(n!=n|0)return!1;if(n<0||n<i-(r-o))return 0;if(n>o||n>i)return 0;if(2*i>r)return 2*o>r?t.hypgeom.pdf(r-i-o+n,r,r-i,r-o):t.hypgeom.pdf(o-n,r,r-i,o);if(2*o>r)return t.hypgeom.pdf(i-n,r,i,r-o);if(i<o)return t.hypgeom.pdf(n,r,o,i);for(var s=1,a=0,u=0;u<n;u++){for(;s>1&&a<o;)s*=1-i/(r-a),a++;s*=(o-u)*(i-u)/((u+1)*(r-i-o+u+1))}for(;a<o;a++)s*=1-i/(r-a);return e.min(1,e.max(0,s))},cdf:function(n,r,i,o){if(n<0||n<i-(r-o))return 0;if(n>=o||n>=i)return 1;if(2*i>r)return 2*o>r?t.hypgeom.cdf(r-i-o+n,r,r-i,r-o):1-t.hypgeom.cdf(o-n-1,r,r-i,o);if(2*o>r)return 1-t.hypgeom.cdf(i-n-1,r,i,r-o);if(i<o)return t.hypgeom.cdf(n,r,o,i);for(var s=1,a=1,u=0,c=0;c<n;c++){for(;s>1&&u<o;){var l=1-i/(r-u);a*=l,s*=l,u++}s+=a*=(o-c)*(i-c)/((c+1)*(r-i-o+c+1))}for(;u<o;u++)s*=1-i/(r-u);return e.min(1,e.max(0,s))}}),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=[],i=0;if(e<0)return 0;for(;i<=e;i++)r.push(t.poisson.pdf(i,n));return t.sum(r)},mean:function(t){return t},variance:function(t){return t},sampleSmall:function(n){var r=1,i=0,o=e.exp(-n);do{i++,r*=t._random_fn()}while(r>o);return i-1},sampleLarge:function(n){var r,i,o,s,a,u,c,l,h,d,f=n;for(s=e.sqrt(f),a=e.log(f),u=.02483*(c=.931+2.53*s)-.059,l=1.1239+1.1328/(c-3.4),h=.9277-3.6224/(c-2);;){if(i=e.random()-.5,o=e.random(),d=.5-e.abs(i),r=e.floor((2*u/d+c)*i+f+.43),d>=.07&&o<=h)return r;if(!(r<0||d<.013&&o>d)&&e.log(o)+e.log(l)-e.log(u/(d*d)+c)<=r*a-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,i){return r<=n||i<n||i>r?NaN:t<=n?0:t>=r?1:t<=i?e.pow(t-n,2)/((r-n)*(i-n)):1-e.pow(r-t,2)/((r-n)*(r-i))},inv:function(t,n,r,i){return r<=n||i<n||i>r?NaN:t<=(i-n)/(r-n)?n+(r-n)*e.sqrt(t*((i-n)/(r-n))):n+(r-n)*(1-e.sqrt((1-t)*(1-(i-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,i){var o=t._random_fn();return o<(i-n)/(r-n)?n+e.sqrt(o*(r-n)*(i-n)):r-e.sqrt((1-o)*(r-n)*(r-i))},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 i,o=t._random_fn()-.5;return n-r*((i=o)/e.abs(i))*e.log(1-2*e.abs(o))}}),t.extend(t.tukey,{cdf:function(n,i,o){var s=i,a=[.9894009349916499,.9445750230732326,.8656312023878318,.755404408355003,.6178762444026438,.45801677765722737,.2816035507792589,.09501250983763744],u=[.027152459411754096,.062253523938647894,.09515851168249279,.12462897125553388,.14959598881657674,.16915651939500254,.18260341504492358,.1894506104550685];if(n<=0)return 0;if(o<2||s<2)return NaN;if(!Number.isFinite(n))return 1;if(o>25e3)return r(n,1,s);var c,l=.5*o,h=l*e.log(o)-o*e.log(2)-t.gammaln(l),d=l-1,f=.25*o;c=o<=100?1:o<=800?.5:o<=5e3?.25:.125,h+=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=h+d*e.log(y+a[w]*c)-(a[w]*c+y)*f):(w=v-1,b=h+d*e.log(y-a[w]*c)+(a[w]*c-y)*f),b>=-30&&(g+=r(8<v?n*e.sqrt(.5*(a[w]*c+y)):n*e.sqrt(.5*(-a[w]*c+y)),1,s)*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,i){if(i<2||r<2)return NaN;if(n<0||n>1)return NaN;if(0===n)return 0;if(1===n)return 1/0;var o,s=function(t,n,r){var i=.5-.5*t,o=e.sqrt(e.log(1/(i*i))),s=o+((((-453642210148e-16*o-.204231210125)*o-.342242088547)*o-1)*o+.322232421088)/((((.0038560700634*o+.10353775285)*o+.531103462366)*o+.588581570495)*o+.099348462606);r<120&&(s+=(s*s*s+s)/r/4);var a=.8832-.2368*s;return r<120&&(a+=-1.214/r+1.208*s/r),s*(a*e.log(n-1)+1.4142)}(n,r,i),a=t.tukey.cdf(s,r,i)-n;o=a>0?e.max(0,s-1):s+1;for(var u,c=t.tukey.cdf(o,r,i)-n,l=1;l<50;l++)if(u=o-c*(o-s)/(c-a),a=c,s=o,u<0&&(u=0,c=-n),c=t.tukey.cdf(u,r,i)-n,o=u,e.abs(o-s)<1e-4)return u;throw new Error("tukey.inv failed to converge")}})}(e,Math),function(t,e){var n,r,i=Array.prototype.push,o=t.utils.isArray;function s(e){return o(e)||e instanceof t}t.extend({add:function(e,n){return s(n)?(s(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 s(n)?(s(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 s(n)?(s(n[0])||(n=[n]),t.multiply(e,t.inv(n))):t.map(e,(function(t){return t/n}))},multiply:function(e,n){var r,i,o,a,u,c,l,h;if(void 0===e.length&&void 0===n.length)return e*n;if(u=e.length,c=e[0].length,l=t.zeros(u,o=s(n)?n[0].length:c),h=0,s(n)){for(;h<o;h++)for(r=0;r<u;r++){for(a=0,i=0;i<c;i++)a+=e[r][i]*n[i][h];l[r][h]=a}return 1===u&&1===h?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){s(e[0])||(e=[e]),s(n[0])||(n=[n]);for(var r,i,o=1===e[0].length&&1!==e.length?t.transpose(e):e,a=1===n[0].length&&1!==n.length?t.transpose(n):n,u=[],c=0,l=o.length,h=o[0].length;c<l;c++){for(u[c]=[],r=0,i=0;i<h;i++)r+=o[c][i]*a[c][i];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,i=0;for(isNaN(n)&&(n=2),s(t[0])&&(t=t[0]);i<t.length;i++)r+=e.pow(e.abs(t[i]),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++)i.apply(r[n],e[n]);return r},inv:function(e){for(var n,r=e.length,i=e[0].length,o=t.identity(r,i),s=t.gauss_jordan(e,o),a=[],u=0;u<r;u++)for(a[u]=[],n=i;n<s[0].length;n++)a[u][n-i]=s[u][n];return a},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 i=[],o=1;o<e.length;o++){i[o-1]=[];for(var s=0;s<e.length;s++)s<r?i[o-1][s]=e[o][s]:s>r&&(i[o-1][s-1]=e[o][s])}var a=r%2?-1:1;n+=t(i)*e[0][r]*a}return n},gauss_elimination:function(n,r){var i,o,s,a,u=0,c=0,l=n.length,h=n[0].length,d=1,f=0,p=[];for(i=(n=t.aug(n,r))[0].length,u=0;u<l;u++){for(o=n[u][u],c=u,a=u+1;a<h;a++)o<e.abs(n[a][u])&&(o=n[a][u],c=a);if(c!=u)for(a=0;a<i;a++)s=n[u][a],n[u][a]=n[c][a],n[c][a]=s;for(c=u+1;c<l;c++)for(d=n[c][u]/n[u][u],a=u;a<i;a++)n[c][a]=n[c][a]-d*n[u][a]}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][i-1]-f)/n[u][u]}return p},gauss_jordan:function(n,r){var i,o,s,a=t.aug(n,r),u=a.length,c=a[0].length,l=0;for(o=0;o<u;o++){var h=o;for(s=o+1;s<u;s++)e.abs(a[s][o])>e.abs(a[h][o])&&(h=s);var d=a[o];for(a[o]=a[h],a[h]=d,s=o+1;s<u;s++)for(l=a[s][o]/a[o][o],i=o;i<c;i++)a[s][i]-=a[o][i]*l}for(o=u-1;o>=0;o--){for(l=a[o][o],s=0;s<o;s++)for(i=c-1;i>o-1;i--)a[s][i]-=a[o][i]*a[s][o]/l;for(a[o][o]/=l,i=u;i<c;i++)a[o][i]/=l}return a},triaUpSolve:function(e,n){var r,i=e[0].length,o=t.zeros(1,i)[0],s=!1;return null!=n[0].length&&(n=n.map((function(t){return t[0]})),s=!0),t.arange(i-1,-1,-1).forEach((function(s){r=t.arange(s+1,i).map((function(t){return o[t]*e[s][t]})),o[s]=(n[s]-t.sum(r))/e[s][s]})),s?o.map((function(t){return[t]})):o},triaLowSolve:function(e,n){var r,i=e[0].length,o=t.zeros(1,i)[0],s=!1;return null!=n[0].length&&(n=n.map((function(t){return t[0]})),s=!0),t.arange(i).forEach((function(i){r=t.arange(i).map((function(t){return e[i][t]*o[t]})),o[i]=(n[i]-t.sum(r))/e[i][i]})),s?o.map((function(t){return[t]})):o},lu:function(e){var n,r=e.length,i=t.identity(r),o=t.zeros(e.length,e[0].length);return t.arange(r).forEach((function(t){o[0][t]=e[0][t]})),t.arange(1,r).forEach((function(s){t.arange(s).forEach((function(r){n=t.arange(r).map((function(t){return i[s][t]*o[t][r]})),i[s][r]=(e[s][r]-t.sum(n))/o[r][r]})),t.arange(s,r).forEach((function(r){n=t.arange(s).map((function(t){return i[s][t]*o[t][r]})),o[s][r]=e[n.length][r]-t.sum(n)}))})),[i,o]},cholesky:function(n){var r,i=n.length,o=t.zeros(n.length,n[0].length);return t.arange(i).forEach((function(s){r=t.arange(s).map((function(t){return e.pow(o[s][t],2)})),o[s][s]=e.sqrt(n[s][s]-t.sum(r)),t.arange(s+1,i).forEach((function(e){r=t.arange(s).map((function(t){return o[s][t]*o[e][t]})),o[e][s]=(n[s][e]-t.sum(r))/o[s][s]}))})),o},gauss_jacobi:function(n,r,i,o){for(var s,a,u,c,l=0,h=0,d=n.length,f=[],p=[],m=[];l<d;l++)for(f[l]=[],p[l]=[],m[l]=[],h=0;h<d;h++)l>h?(f[l][h]=n[l][h],p[l][h]=m[l][h]=0):l<h?(p[l][h]=n[l][h],f[l][h]=m[l][h]=0):(m[l][h]=n[l][h],f[l][h]=p[l][h]=0);for(u=t.multiply(t.multiply(t.inv(m),t.add(f,p)),-1),a=t.multiply(t.inv(m),r),s=i,c=t.add(t.multiply(u,i),a),l=2;e.abs(t.norm(t.subtract(c,s)))>o;)s=c,c=t.add(t.multiply(u,s),a),l++;return c},gauss_seidel:function(n,r,i,o){for(var s,a,u,c,l,h=0,d=n.length,f=[],p=[],m=[];h<d;h++)for(f[h]=[],p[h]=[],m[h]=[],s=0;s<d;s++)h>s?(f[h][s]=n[h][s],p[h][s]=m[h][s]=0):h<s?(p[h][s]=n[h][s],f[h][s]=m[h][s]=0):(m[h][s]=n[h][s],f[h][s]=p[h][s]=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),a=i,l=t.add(t.multiply(c,i),u),h=2;e.abs(t.norm(t.subtract(l,a)))>o;)a=l,l=t.add(t.multiply(c,a),u),h+=1;return l},SOR:function(n,r,i,o,s){for(var a,u,c,l,h,d=0,f=n.length,p=[],m=[],g=[];d<f;d++)for(p[d]=[],m[d]=[],g[d]=[],a=0;a<f;a++)d>a?(p[d][a]=n[d][a],m[d][a]=g[d][a]=0):d<a?(m[d][a]=n[d][a],p[d][a]=g[d][a]=0):(g[d][a]=n[d][a],p[d][a]=m[d][a]=0);for(l=t.multiply(t.inv(t.add(g,t.multiply(p,s))),t.subtract(t.multiply(g,1-s),t.multiply(m,s))),c=t.multiply(t.multiply(t.inv(t.add(g,t.multiply(p,s))),r),s),u=i,h=t.add(t.multiply(l,i),c),d=2;e.abs(t.norm(t.subtract(h,u)))>o;)u=h,h=t.add(t.multiply(l,u),c),d++;return h},householder:function(n){for(var r,i,o,s,a=n.length,u=n[0].length,c=0,l=[],h=[];c<a-1;c++){for(r=0,s=c+1;s<u;s++)r+=n[s][c]*n[s][c];for(r=(n[c+1][c]>0?-1:1)*e.sqrt(r),i=e.sqrt((r*r-n[c+1][c]*r)/2),(l=t.zeros(a,1))[c+1][0]=(n[c+1][c]-r)/(2*i),o=c+2;o<a;o++)l[o][0]=n[o][c]/(2*i);h=t.subtract(t.identity(a,u),t.multiply(t.multiply(l,t.transpose(l)),2)),n=t.multiply(h,t.multiply(n,h))}return n},QR:(n=t.sum,r=t.arange,function(i){var o,s,a,u=i.length,c=i[0].length,l=t.zeros(c,c);for(i=t.copy(i),s=0;s<c;s++){for(l[s][s]=e.sqrt(n(r(u).map((function(t){return i[t][s]*i[t][s]})))),o=0;o<u;o++)i[o][s]=i[o][s]/l[s][s];for(a=s+1;a<c;a++)for(l[s][a]=n(r(u).map((function(t){return i[t][s]*i[t][a]}))),o=0;o<u;o++)i[o][a]=i[o][a]-i[o][s]*l[s][a]}return[i,l]}),lstsq:function(e,n){var r=!1;void 0===n[0].length&&(n=n.map((function(t){return[t]})),r=!0);var i=t.QR(e),o=i[0],s=i[1],a=e[0].length,u=t.slice(o,{col:{end:a}}),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(i){var o=t.multiply(e[i][n],-1),s=t.slice(e,{row:i}),a=t.multiply(t.slice(e,{row:n}),o);t.sliceAssign(e,{row:i},t.add(s,a));var u=t.slice(r,{row:i}),c=t.multiply(t.slice(r,{row:n}),o);t.sliceAssign(r,{row:i},t.add(u,c))}))})),r}(t.slice(s,{row:{end:a}})),l=t.transpose(u);void 0===l[0].length&&(l=[l]);var h=t.multiply(t.multiply(c,l),n);return void 0===h.length&&(h=[[h]]),r?h.map((function(t){return t[0]})):h},jacobi:function(n){for(var r,i,o,s,a,u,c,l=1,h=n.length,d=t.identity(h,h),f=[];1===l;){for(a=n[0][1],o=0,s=1,r=0;r<h;r++)for(i=0;i<h;i++)r!=i&&a<e.abs(n[r][i])&&(a=e.abs(n[r][i]),o=r,s=i);for(u=n[o][o]===n[s][s]?n[o][s]>0?e.PI/4:-e.PI/4:e.atan(2*n[o][s]/(n[o][o]-n[s][s]))/2,(c=t.identity(h,h))[o][o]=e.cos(u),c[o][s]=-e.sin(u),c[s][o]=e.sin(u),c[s][s]=e.cos(u),d=t.multiply(d,c),n=t.multiply(t.multiply(t.inv(c),n),c),l=0,r=1;r<h;r++)for(i=1;i<h;i++)r!=i&&e.abs(n[r][i])>.001&&(l=1)}for(r=0;r<h;r++)f.push(n[r][r]);return[d,f]},rungekutta:function(t,e,n,r,i,o){var s,a,u;if(2===o)for(;r<=n;)i+=((s=e*t(r,i))+(a=e*t(r+e,i+s)))/2,r+=e;if(4===o)for(;r<=n;)i+=((s=e*t(r,i))+2*(a=e*t(r+e/2,i+s/2))+2*(u=e*t(r+e/2,i+a/2))+e*t(r+e,i+u))/6,r+=e;return i},romberg:function(t,n,r,i){for(var o,s,a,u,c,l=0,h=(r-n)/2,d=[],f=[],p=[];l<i/2;){for(c=t(n),a=n,u=0;a<=r;a+=h,u++)d[u]=a;for(o=d.length,a=1;a<o-1;a++)c+=(a%2!=0?4:2)*t(d[a]);c=h/3*(c+t(r)),p[l]=c,h/=2,l++}for(s=p.length,o=1;1!==s;){for(a=0;a<s-1;a++)f[a]=(e.pow(4,o)*p[a+1]-p[a])/(e.pow(4,o)-1);s=f.length,p=f,f=[],o++}return p},richardson:function(t,n,r,i){function o(t,e){for(var n,r=0,i=t.length;r<i;r++)t[r]===e&&(n=r);return n}for(var s,a,u,c,l,h=e.abs(r-t[o(t,r)+1]),d=0,f=[],p=[];i>=h;)s=o(t,r+i),a=o(t,r),f[d]=(n[s]-2*n[a]+n[2*a-s])/(i*i),i/=2,d++;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 i,o=(n-e)/r,s=t(e),a=[],u=e,c=0,l=1;u<=n;u+=o,c++)a[c]=u;for(i=a.length;l<i-1;l++)s+=(l%2!=0?4:2)*t(a[l]);return o/3*(s+t(n))},hermite:function(t,e,n,r){for(var i,o=t.length,s=0,a=0,u=[],c=[],l=[],h=[];a<o;a++){for(u[a]=1,i=0;i<o;i++)a!=i&&(u[a]*=(r-t[i])/(t[a]-t[i]));for(c[a]=0,i=0;i<o;i++)a!=i&&(c[a]+=1/(t[a]-t[i]));l[a]=(1-2*(r-t[a])*c[a])*(u[a]*u[a]),h[a]=(r-t[a])*(u[a]*u[a]),s+=l[a]*e[a]+h[a]*n[a]}return s},lagrange:function(t,e,n){for(var r,i,o=0,s=0,a=t.length;s<a;s++){for(i=e[s],r=0;r<a;r++)s!=r&&(i*=(n-t[r])/(t[s]-t[r]));o+=i}return o},cubic_spline:function(e,n,r){for(var i,o,s=e.length,a=0,u=[],c=[],l=[],h=[],d=[],f=[];a<s-1;a++)h[a]=e[a+1]-e[a];for(l[0]=0,a=1;a<s-1;a++)l[a]=3/h[a]*(n[a+1]-n[a])-3/h[a-1]*(n[a]-n[a-1]);for(a=1;a<s-1;a++)u[a]=[],c[a]=[],u[a][a-1]=h[a-1],u[a][a]=2*(h[a-1]+h[a]),u[a][a+1]=h[a],c[a][0]=l[a];for(o=t.multiply(t.inv(u),c),i=0;i<s-1;i++)d[i]=(n[i+1]-n[i])/h[i]-h[i]*(o[i+1][0]+2*o[i][0])/3,f[i]=(o[i+1][0]-o[i][0])/(3*h[i]);for(i=0;i<s&&!(e[i]>r);i++);return n[i-=1]+(r-e[i])*d[i]+t.sq(r-e[i])*o[i]+(r-e[i])*t.sq(r-e[i])*f[i]},gauss_quadrature:function(){throw new Error("gauss_quadrature not yet implemented")},PCA:function(e){var n,r,i,o,s,a=e.length,u=e[0].length,c=0,l=[],h=[],d=[],f=[],p=[],m=[],g=[];for(c=0;c<a;c++)l[c]=t.sum(e[c])/u;for(c=0;c<u;c++)for(p[c]=[],n=0;n<a;n++)p[c][n]=e[n][c]-l[n];for(p=t.transpose(p),c=0;c<a;c++)for(m[c]=[],n=0;n<a;n++)m[c][n]=t.dot([p[c]],[p[n]])/(u-1);for(s=(i=t.jacobi(m))[0],h=i[1],g=t.transpose(s),c=0;c<h.length;c++)for(n=c;n<h.length;n++)h[c]<h[n]&&(r=h[c],h[c]=h[n],h[n]=r,d=g[c],g[c]=g[n],g[n]=d);for(o=t.transpose(p),c=0;c<a;c++)for(f[c]=[],n=0;n<o.length;n++)f[c][n]=t.dot([g[c]],[o[n]]);return[e,h,g,f]}}),function(e){for(var n=0;n<e.length;n++)!function(e){t.fn[e]=function(n,r){var i=this;return r?(setTimeout((function(){r.call(i,t.fn[e].call(i,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,i=t.utils.isArray;function o(t,n,r,i){if(t>1||r>1||t<=0||r<=0)throw new Error("Proportions should be greater than 0 and less than 1");var o=(t*n+r*i)/(n+i);return(t-r)/e.sqrt(o*(1-o)*(1/n+1/i))}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,o=n.call(arguments);return i(o[1])?(r=t.zscore(o[0],o[1],o[3]),1===o[2]?t.normal.cdf(-e.abs(r),0,1):2*t.normal.cdf(-e.abs(r),0,1)):o.length>2?(r=t.zscore(o[0],o[1],o[2]),1===o[3]?t.normal.cdf(-e.abs(r),0,1):2*t.normal.cdf(-e.abs(r),0,1)):(r=o[0],1===o[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,i){var o=e.abs(this.zscore(n,i));return 1===r?t.normal.cdf(-o,0,1):2*t.normal.cdf(-o,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 i,o=n.call(arguments);return 5===o.length?(i=e.abs(t.tscore(o[0],o[1],o[2],o[3])),1===o[4]?t.studentt.cdf(-i,o[3]-1):2*t.studentt.cdf(-i,o[3]-1)):r(o[1])?(i=e.abs(o[0]),1==o[2]?t.studentt.cdf(-i,o[1]-1):2*t.studentt.cdf(-i,o[1]-1)):(i=e.abs(t.tscore(o[0],o[1])),1==o[2]?t.studentt.cdf(-i,o[1].length-1):2*t.studentt.cdf(-i,o[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,i,o,s,a,u,c,l,h=n.call(arguments);if(1===h.length){for(a=new Array(h[0].length),c=0;c<h[0].length;c++)a[c]=h[0][c];h=a}for(i=new Array,c=0;c<h.length;c++)i=i.concat(h[c]);for(o=t.mean(i),r=0,c=0;c<h.length;c++)r+=h[c].length*e.pow(t.mean(h[c])-o,2);for(r/=h.length-1,u=0,c=0;c<h.length;c++)for(s=t.mean(h[c]),l=0;l<h[c].length;l++)u+=e.pow(h[c][l]-s,2);return r/(u/(i.length-h.length))},anovaftest:function(){var e,i,o,s,a=n.call(arguments);if(r(a[0]))return 1-t.centralF.cdf(a[0],a[1],a[2]);var u=t.anovafscore(a);for(e=a.length-1,o=0,s=0;s<a.length;s++)o+=a[s].length;return i=o-e-1,1-t.centralF.cdf(u,e,i)},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 i,o,s,a,u,c=n.call(arguments);return r(c[0])?(i=c[0],o=c[1],s=c[2],a=c[3],u=c[4]):(i=t.mean(c[0]),o=t.mean(c[1]),s=c[0].length,a=c[1].length,u=c[2]),e.abs(i-o)/(u*e.sqrt((1/s+1/a)/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 i=r[0],o=r[1];return 1-t.tukey.cdf(e,o,i-o)},tukeyhsd:function(e){for(var n=t.pooledstdev(e),r=e.map((function(e){return t.mean(e)})),i=e.reduce((function(t,e){return t+e.length}),0),o=[],s=0;s<e.length;++s)for(var a=s+1;a<e.length;++a){var u=t.qtest(r[s],r[a],e[s].length,e[a].length,n,i,e.length);o.push([[s,a],u])}return o}}),t.extend({normalci:function(){var r,i=n.call(arguments),o=new Array(2);return r=4===i.length?e.abs(t.normal.inv(i[1]/2,0,1)*i[2]/e.sqrt(i[3])):e.abs(t.normal.inv(i[1]/2,0,1)*t.stdev(i[2])/e.sqrt(i[2].length)),o[0]=i[0]-r,o[1]=i[0]+r,o},tci:function(){var r,i=n.call(arguments),o=new Array(2);return r=4===i.length?e.abs(t.studentt.inv(i[1]/2,i[3]-1)*i[2]/e.sqrt(i[3])):e.abs(t.studentt.inv(i[1]/2,i[2].length-1)*t.stdev(i[2],!0)/e.sqrt(i[2].length)),o[0]=i[0]-r,o[1]=i[0]+r,o},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,i){var s=o(e,n,r,i);return t.ztest(s,1)},twoSidedDifferenceOfProportions:function(e,n,r,i){var s=o(e,n,r,i);return t.ztest(s,2)}})}(e,Math),e.models=function(){function t(t,n){var r=t.length,i=n[0].length-1,o=r-i-1,s=e.lstsq(n,t),a=e.multiply(n,s.map((function(t){return[t]}))).map((function(t){return t[0]})),u=e.subtract(t,a),c=e.mean(t),l=e.sum(a.map((function(t){return Math.pow(t-c,2)}))),h=e.sum(t.map((function(t,e){return Math.pow(t-a[e],2)}))),d=l+h;return{exog:n,endog:t,nobs:r,df_model:i,df_resid:o,coef:s,predict:a,resid:u,ybar:c,SST:d,SSE:l,SSR:h,R2:l/d}}function n(n){var r,i,o=(r=n.exog,i=r[0].length,e.arange(i).map((function(n){var o=e.arange(i).filter((function(t){return t!==n}));return t(e.col(r,n).map((function(t){return t[0]})),e.col(r,o))}))),s=Math.sqrt(n.SSR/n.df_resid),a=o.map((function(t){var e=t.SST,n=t.R2;return s/Math.sqrt(e*(1-n))})),u=n.coef.map((function(t,e){return(t-0)/a[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),h=n.coef.map((function(t,e){var n=l*a[e];return[t-n,t+n]}));return{se:a,t:u,p:c,sigmaHat:s,interval95:h}}return{ols:function(r,i){var o=t(r,i),s=n(o),a=function(t){var n,r,i,o=t.R2/t.df_model/((1-t.R2)/t.df_resid);return{F_statistic:o,pvalue:1-(n=o,r=t.df_model,i=t.df_resid,e.beta.cdf(n/(i/r+n),r/2,i/2))}}(o),u=1-(1-o.R2)*((o.nobs-1)/o.df_resid);return o.t=s,o.f=a,o.adjust_R2=u,o}}}(),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,i,o,s,a;if(t.cols()==n.rows()){if(n.rows()>1){for(s=[],r=0;r<t.rows();r++)for(s[r]=[],i=0;i<n.cols();i++){for(a=0,o=0;o<t.cols();o++)a+=t.toArray()[r][o]*n.toArray()[o][i];s[r][i]=a}return e(s)}for(s=[],r=0;r<t.rows();r++)for(s[r]=[],i=0;i<n.cols();i++){for(a=0,o=0;o<t.cols();o++)a+=t.toArray()[r][o]*n.toArray()[i];s[r][i]=a}return e(s)}},regress:function(t,n){var r=e.xtranspxinv(t),i=t.transpose(),o=e.matrixmult(e(r),i);return e.matrixmult(o,n)},regresst:function(t,n,r){var i=e.regress(t,n),o={anova:{}},s=e.jMatYBar(t,i);o.yBar=s;var a=n.mean();o.anova.residuals=e.residuals(n,s),o.anova.ssr=e.ssr(s,a),o.anova.msr=o.anova.ssr/(t[0].length-1),o.anova.sse=e.sse(n,s),o.anova.mse=o.anova.sse/(n.length-(t[0].length-1)-1),o.anova.sst=e.sst(n,a),o.anova.mst=o.anova.sst/(n.length-1),o.anova.r2=1-o.anova.sse/o.anova.sst,o.anova.r2<0&&(o.anova.r2=0),o.anova.fratio=o.anova.msr/o.anova.mse,o.anova.pvalue=e.anovaftest(o.anova.fratio,t[0].length-1,n.length-(t[0].length-1)-1),o.anova.rmse=Math.sqrt(o.anova.mse),o.anova.r2adj=1-o.anova.mse/o.anova.mst,o.anova.r2adj<0&&(o.anova.r2adj=0),o.stats=new Array(t[0].length);for(var u,c,l,h=e.xtranspxinv(t),d=0;d<i.length;d++)u=Math.sqrt(o.anova.mse*Math.abs(h[d][d])),c=Math.abs(i[d]/u),l=e.ttest(c,n.length-t[0].length-1,r),o.stats[d]=[i[d],u,c,l];return o.regress=i,o},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),i=0;i<t.length;i++){r[i]=new Array(t[i].length);for(var o=0;o<t[i].length;o++)r[i][o]=t[i][o]-n[i][o]}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 o={},s=[],a=0;a<t.length;a++){var u=t[a],c=r.base?u[0]+r.base:u[0],l=o[c]||0,h="".concat(c," ").concat(l);o[c]=l+1;var d=n(h),f={css:u[1],media:u[2],sourceMap:u[3],supports:u[4],layer:u[5]};if(-1!==d)e[d].references++,e[d].updater(f);else{var p=i(f,r);r.byIndex=a,e.splice(a,0,{identifier:h,updater:p,references:1})}s.push(h)}return s}function i(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,i){var o=r(t=t||[],i=i||{});return function(t){t=t||[];for(var s=0;s<o.length;s++){var a=n(o[s]);e[a].references--}for(var u=r(t,i),c=0;c<o.length;c++){var l=n(o[c]);0===e[l].references&&(e[l].updater(),e.splice(l,1))}o=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 i=void 0!==n.layer;i&&(r+="@layer".concat(n.layer.length>0?" ".concat(n.layer):""," {")),r+=n.css,i&&(r+="}"),n.media&&(r+="}"),n.supports&&(r+="}");var o=n.sourceMap;o&&"undefined"!=typeof btoa&&(r+="\n/*# sourceMappingURL=data:application/json;base64,".concat(btoa(unescape(encodeURIComponent(JSON.stringify(o))))," */")),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 i=e[r];if(void 0!==i)return i.exports;var o=e[r]={id:r,loaded:!1,exports:{}};return t[r].call(o.exports,o,o.exports,n),o.loaded=!0,o.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&&(t=e.currentScript.src),!t)){var r=e.getElementsByTagName("script");if(r.length)for(var i=r.length-1;i>-1&&(!t||!/^http(s?):/.test(t));)t=r[i--].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:()=>Cr,MCL:()=>Sr,MCLInitializationFunction:()=>Ir,MVA:()=>xr,PCA:()=>wr,PLS:()=>Mr,_package:()=>mr,anova:()=>Qr,applyLinearKernelSVM:()=>Or,applyLinearRegression:()=>ei,applyPLSRegression:()=>li,applyPolynomialKernelSVM:()=>Wr,applyRBFkernelSVM:()=>Ur,applySigmoidKernelSVM:()=>Hr,applySoftmax:()=>oi,applyXGBooster:()=>mi,dbScan:()=>vr,dbscanPostProcessingFunction:()=>br,demoMultivariateAnalysis:()=>Lr,info:()=>gr,init:()=>yr,isApplicableLinearKernelSVM:()=>Pr,isApplicableLinearRegression:()=>ni,isApplicablePLSRegression:()=>hi,isApplicablePolynomialKernelSVM:()=>zr,isApplicableRBFkernelSVM:()=>kr,isApplicableSigmoidKernelSVM:()=>$r,isApplicableSoftmax:()=>si,isApplicableXGBooster:()=>yi,isInteractiveLinearKernelSVM:()=>Rr,isInteractiveLinearRegression:()=>ri,isInteractivePLSRegression:()=>fi,isInteractivePolynomialKernelSVM:()=>jr,isInteractiveRBFkernelSVM:()=>Gr,isInteractiveSigmoidKernelSVM:()=>Kr,isInteractiveSoftmax:()=>ai,isInteractiveXGBooster:()=>gi,kNNImputation:()=>Zr,kNNImputationForTable:()=>Jr,numberPreprocessingFunction:()=>Er,reduceDimensionality:()=>_r,stringPreprocessingFunction:()=>Ar,topMenuPLS:()=>Nr,trainLinearKernelSVM:()=>Tr,trainLinearRegression:()=>ti,trainPLSRegression:()=>ci,trainPolynomialKernelSVM:()=>Vr,trainRBFkernelSVM:()=>Dr,trainSigmoidKernelSVM:()=>qr,trainSoftmax:()=>ii,trainXGBooster:()=>pi,visualizeLinearKernelSVM:()=>Fr,visualizePLSRegression:()=>di,visualizePolynomialKernelSVM:()=>Yr,visualizeRBFkernelSVM:()=>Br,visualizeSigmoidKernelSVM:()=>Xr});const t=grok,e=ui,i=DG,o={i32:"HEAP32",f32:"HEAPF32"},s={i32:Int32Array,f32:Float32Array},a={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*s[this.type].BYTES_PER_ELEMENT)}isMemoryForBufferAllocated(){return 0!=this.buf}putDataToBuffer(t){if(this.isMemoryForBufferAllocated()){const e=this.type,n=a[e],r=t[o[e]];let i=null;const u=this.data;i="int"==u.type&&"i32"==e||"double"==u.type&&"f32"==e?u.getRawData():new s[e](u.getRawData()),i&&r.set(i,this.buf>>n)}}getDataFromBuffer(t){if(this.toUpdate&&this.isMemoryForBufferAllocated()){const e=this.type,n=t[o[e]],r=this.buf,i=s[e].BYTES_PER_ELEMENT,a=this.data.getRawData();for(let t=0;t<this.numOfRows;t++)a[t]=n[r/i+t]}}freeBuffer(t){this.isMemoryForBufferAllocated()&&(t._free(this.buf),this.buf=0)}}class h 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[o[e]],r=this.buf,i=u[e],a=new s[e](this.numOfRows);for(let t=0;t<a.length;t++)a[t]=n[r/a.BYTES_PER_ELEMENT+t];this.data=i("name",a)}}}class d 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*s[this.type].BYTES_PER_ELEMENT)}isMemoryForBufferAllocated(){return 0!=this.buf}putDataToBuffer(t){if(this.isMemoryForBufferAllocated()){const e=this.type,n=a[e],r=t[o[e]],i=s[e].BYTES_PER_ELEMENT;for(let t=0;t<this.numOfColumns;t++){let o=null;const a=this.data[t];o="int"==a.type&&"i32"==e||"double"==a.type&&"f32"==e?a.getRawData():new s[e](a.getRawData()),null!=o&&r.set(o,this.buf+t*this.numOfRows*i>>n)}}}getDataFromBuffer(t){if(this.toUpdate&&this.isMemoryForBufferAllocated()){const e=this.type,n=t[o[e]],r=this.numOfRows,i=this.numOfColumns,a=new s[e](n.buffer,this.buf,r*i);for(let t=0;t<i;t++){const e=this.data[t].getRawData();for(let n=0;n<r;n++)e[n]=a[n+t*r]}}}freeBuffer(t){this.isMemoryForBufferAllocated()&&(t._free(this.buf),this.buf=0)}}class f extends d{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[o[e]],r=this.numOfRows,i=this.numOfColumns,a=s[e].BYTES_PER_ELEMENT,c=u[e],l=this.buf;for(let t=0;t<i;t++){const i=new s[e](r);for(let e=0;e<r;e++)i[e]=n[l/a+e+t*r];this.data.push(c((t+1).toString(),i))}}}}const p={intColumn:t=>new l(t,"i32"),newIntColumn:t=>new h("i32",t),intColumns:t=>new d(t.toList(),"i32"),newIntColumns:(t,e)=>new f("i32",t,e),floatColumn:t=>new l(t,"f32"),newFloatColumn:t=>new h("f32",t),floatColumns:t=>new d(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],i=r.arguments,o=[];let s=0;for(const t in i){const e=i[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[s]),s++;break;case"newFloatColumns":case"newIntColumns":const t=i[e.numOfRows.ref].data[e.numOfRows.value],r=i[e.numOfColumns.ref].data[e.numOfColumns.value];e.data=p[e.type](t,r);break;case"newFloatColumn":case"newIntColumn":const o=i[e.numOfRows.ref].data[e.numOfRows.value];e.data=p[e.type](o)}o.push(i[t].data)}}const a=function(t,e,n,r){let i;for(const e of r)e.allocateMemoryForBuffer(t);let o=!0;for(const t of r)o&=t.isMemoryForBufferAllocated();if(o){const n=[],o=[];for(const e of r)e.complementArrOfParams(n),e.complementArrOfTypes(o),e.putDataToBuffer(t);const s="number";i=t.ccall(e,s,o,n);for(const e of r)e.getDataFromBuffer(t)}for(const e of r)e.freeBuffer(t);if(null!=i)return i}(t,e,0,o);i._callResult=p.num(a);const u=r.output;if("objects"!=u.type)return m[u.type](i[u.source].data);const c=[];for(const t of u.source)c.push(i[t].data.data);return c}const y="num",v="floatColumn",w="intColumn",b="floatColumns",E="newFloatColumns",A="intColumns",_="newIntColumns",C="newFloatColumn",S="newIntColumn",I="column",M="_callResult",N="numOfRows",x="numOfColumns",L="ref",T="value",O="tableFromColumns",P="objects",R="int",F="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=[],i=0;for(const o in t){const s=t[o],a=s.type;if(o!==M){switch(a){case y:case R:case F:s.data=e[i],i++;break;case w:case v:let r;const o=e[i],u=o.length;r=o.type===R&&a===w||o.type===F&&a===v?o.getRawData().slice(0,u):new D[a](o.getRawData().slice(0,u)),s.data={array:r,numOfRows:u},i++;break;case S:case C:let c=0;n=s[N][L],c=t[n].type===y?t[n].data:t[n].data[s[N][T]],s.data={numOfRows:c},i++;break;case A:case b:let l=[];const h=e[i].byIndex(0).length;for(const t of e[i].toList())t.type===R&&a===w||t.type===F&&a===v?l.push(t.getRawData().slice(0,h)):l.push(new D[a](t.getRawData().slice(0,h)));s.data={arrays:l,numOfRows:h,numOfColumns:l.length},i++;break;case _:case E:let d=0,f=0;n=s[N][L],d=t[n].type===y?t[n].data:t[n].data[s[N][T]],n=s[x][L],f=t[n].type===y?t[n].data:t[n].data[s[x][T]],s.data={numOfRows:d,numOfColumns:f},i++;break;default:return}r.push(s)}}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 i in t){const o=t[i];switch(o.type){case y:case R:case F:case w:case v:case b:case A:break;case C:case S:let t;null==o.name?t=(0).toString():a=o.name,o.column=n[o.type](t,e[r].array);break;case _:case E:let i=[],s=e[r].arrays.length,a=[];if(null==o.names)for(let t=1;t<=s;t++)a.push(t.toString());else a=o.names;for(let t=0;t<s;t++)i.push(n[o.type](a[t],e[r].arrays[t]));o.columns=i}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 R:case F:return t.arguments[e.source];case I:return t.arguments[e.source].column;case O:return DG.DataFrame.fromColumns(t.arguments[e.source].columns);case P:let r=[];for(let i of e.source){let e=t.arguments[i];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 R:case F:case w:case v:case A:case b:break;case S:case C:n.column=null;break;case _:case E:n.columns=null}}}(t.arguments),n}const G=1,B=1e8,V="components must be positive.",W="components must not be greater than features count.",z="dataframe is too big.",j="unsupported column type: ";function Y(t){if(t.type!=i.COLUMN_TYPE.FLOAT&&t.type!=i.COLUMN_TYPE.INT)throw new Error(j+t.type)}function q(t){if(t.stats.missingValueCount>0)throw new Error(`The column '${t.name}' has missing values.`)}function H(t,e){if(function(t,e){if(e<G)throw new Error(V);if(e>t.length)throw new Error(W);for(const e of t)Y(e),q(e)}(t,e),t.length*t.byIndex(0).length>B)throw new Error(z)}var $=function(t,e,n,r){return new(n||(n=Promise))((function(i,o){function s(t){try{u(r.next(t))}catch(t){o(t)}}function a(t){try{u(r.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}u((r=r.apply(t,e||[])).next())}))};var K=function(t,e,n,r){return new(n||(n=Promise))((function(i,o){function s(t){try{u(r.next(t))}catch(t){o(t)}}function a(t){try{u(r.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}u((r=r.apply(t,e||[])).next())}))};const X=0,Q=1,Z=2,J=3,tt=4,et=0,nt=1,rt=2,it=3,ot=4,st=5,at=6,ut=7,ct=0,lt=1,ht=2,dt=3,ft=0,pt=0,mt=1,gt=0,yt=1,vt=0,wt=0,bt=0,Et=0,At="gamma must be strictly positive.",_t="sigma must be strictly positive.",Ct="c must be strictly positive.",St="d must be strictly positive.",It="incorrect kernel.",Mt="labels must be strings of two categories.",Nt="Labels",xt="predicted",Lt="correctness",Tt="Confusion matrix",Ot="mean",Pt="std dev",Rt="alpha",Ft="weight",Dt="Gamma",Ut="Kernel",kt="Kernel params",Gt="Kernel parameter 1",Bt="Kernel parameter 2",Vt="Features count",Wt="Train samples count",zt="Train error, %",jt=["linear","polynomial","RBF","sigmoid"],Yt="Sensitivity",qt="Specificity",Ht="Balanced accuracy",$t="Positive predicitve value",Kt="Negative predicitve value",Xt="prediction",Qt=4,Zt=3,Jt=2,te=0,ee=1,ne=2,re=0,ie=1;function oe(t,e,r){return K(this,void 0,void 0,(function*(){const o=e.columns;if(2!=r.categories.length)throw new Error(Mt);const s=i.Column.float(r.name,r.length);for(let t=0;t<r.length;t++)s.set(t,r.get(t)==r.categories[0]?-1:1,!1);const a=yield function(t,e,r){return K(this,void 0,void 0,(function*(){!function(t){if(t.gamma<=vt)throw new Error(At);switch(t.kernel){case X:return;case Z:if(t.sigma<=wt)throw new Error(_t);return;case Q:if(t.cParam<=bt)throw new Error(Ct);if(t.dParam<=Et)throw new Error(St);return;case J:return;default:throw new Error(It)}}(t);const o=[re,re];switch(t.kernel){case X:break;case Z:o[ft]=t.sigma;break;case Q:o[pt]=t.cParam,o[mt]=t.dParam;break;case J:o[gt]=t.kappa,o[yt]=t.theta;break;default:throw new Error(It)}const s=i.Column.fromList("double",kt,o),a=e.toList(),u=a[0].length+ie,c=a.length+ie,l=tt;let h;const d=async function(t,e,r,i,o,s,a,u){return new Promise(((c,l)=>{const h=new Worker(new URL(n.p+n.u(656),n.b));h.postMessage(U(EDA.trainAndAnalyzeLSSVM.arguments,[t,e,r,i,o,s,a,u])),h.onmessage=function(t){h.terminate(),c(k(EDA.trainAndAnalyzeLSSVM,t.data))}}))}(t.gamma,t.kernel,s,u,c,l,e,r);yield d.then((t=>{h=t}),(t=>{throw new Error(`Error: ${t}`)})),h[nt].name=Ot,h[rt].name=Pt,h[it].name=Rt,h[ot].name=Ft,h[st].name=xt,h[at].name=Lt,h[ut].name=Tt;const f={trainGamma:t.gamma,kernelType:t.kernel,kernelParams:s,trainLabels:r,normalizedTrainData:i.DataFrame.fromColumns(h[et]),means:h[nt],stdDevs:h[rt],modelParams:h[it],modelWeights:h[ot],predictedLabels:h[st],correctness:h[at],confusionMatrix:h[ut],trainError:void 0,featuresCount:a.length,trainSamplesCount:a[0].length};return function(t){const e=t.confusionMatrix.getRawData(),n=e[ct],r=e[dt],i=e[ht],o=e[lt],s=n+o,a=i+r,u=n/s,c=r/a,l=n/(n+i),h=r/(r+o),d=(n+r)/(s+a),f=(u+c)/2;t.sensitivity=u,t.specificity=c,t.balancedAccuracy=f,t.positivePredicitveValue=l,t.negativePredicitveValue=h,t.trainError=100*(1-d)}(f),f}))}(t,o,s);return a.realLabels=r,a}))}function se(t,e){const n=ue(e);return i.Viewer.form(n.modelInfo,{showNavigation:!1}).root}function ae(t){const e=t.normalizedTrainData.columns,n=t.trainSamplesCount,r=t.featuresCount,o=i.DataFrame.fromColumns([t.realLabels]).toByteArray(),s=Qt+o.length+4-o.length%4,a=function(t){const e=t.kernelParams.getRawData();return i.DataFrame.fromColumns([i.Column.fromList("double",Dt,[t.trainGamma]),i.Column.fromStrings(Ut,[jt[t.kernelType]]),i.Column.fromList("double",Gt,[e[0]]),i.Column.fromList("double",Bt,[e[1]]),i.Column.fromList("double",Vt,[t.featuresCount]),i.Column.fromList("double",Wt,[t.trainSamplesCount]),i.Column.fromList("double",zt,[t.trainError]),i.Column.fromList("double",Ht,[t.balancedAccuracy]),i.Column.fromList("double",Yt,[t.sensitivity]),i.Column.fromList("double",qt,[t.specificity]),i.Column.fromList("double",$t,[t.positivePredicitveValue]),i.Column.fromList("double",Kt,[t.negativePredicitveValue])])}(t).toByteArray(),u=Qt+a.length+4-a.length%4,c=new Uint8Array(Qt*(Zt+Jt+n+r+r+n+ie+r+ie+r*n)+s+u),l=c.buffer;let h=0,d=new Int32Array(l,h,Zt);d[te]=t.kernelType,d[ee]=n,d[ne]=r,h+=Zt*Qt;let f=new Float32Array(l,h,Jt);f.set(t.kernelParams.getRawData()),h+=Jt*Qt,f=new Float32Array(l,h,n),f.set(t.trainLabels.getRawData()),h+=n*Qt,f=new Float32Array(l,h,r),f.set(t.means.getRawData()),h+=r*Qt,f=new Float32Array(l,h,r),f.set(t.stdDevs.getRawData()),h+=r*Qt,f=new Float32Array(l,h,n+ie),f.set(t.modelParams.getRawData()),h+=(n+ie)*Qt,f=new Float32Array(l,h,r+ie),f.set(t.modelWeights.getRawData()),h+=(r+ie)*Qt;for(const t of e)f=new Float32Array(l,h,r),f.set(t.getRawData()),h+=r*Qt;return d=new Int32Array(l,h,1),d[0]=o.length,c.set(o,h+Qt),h+=s,d=new Int32Array(l,h,1),d[0]=a.length,c.set(a,h+Qt),h+=u,c}function ue(t){const e=t.buffer;let n=0;const r=new Int32Array(e,n,Zt);n+=Zt*Qt;const o=r[ee],s=r[ne],a=i.Column.fromFloat32Array(kt,new Float32Array(e,n,Jt));n+=Jt*Qt;const u=i.Column.fromFloat32Array(Nt,new Float32Array(e,n,o));n+=o*Qt;const c=i.Column.fromFloat32Array(Ot,new Float32Array(e,n,s));n+=s*Qt;const l=i.Column.fromFloat32Array(Pt,new Float32Array(e,n,s));n+=s*Qt;const h=i.Column.fromFloat32Array(Rt,new Float32Array(e,n,o+ie));n+=(o+ie)*Qt;const d=i.Column.fromFloat32Array(Ft,new Float32Array(e,n,s+ie));n+=(s+ie)*Qt;const f=[];for(let t=0;t<o;t++)f.push(i.Column.fromFloat32Array(t.toString(),new Float32Array(e,n,s))),n+=s*Qt;const p=i.DataFrame.fromColumns(f),m=new Int32Array(e,n,1)[0],g=m+4-m%4;n+=Qt;const y=i.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+=Qt;const b=i.DataFrame.fromByteArray(new Uint8Array(e,n,v));return n+=w,{kernelType:r[te],kernelParams:a,trainLabels:u,realLabels:y,means:c,stdDevs:l,modelParams:h,modelWeights:d,normalizedTrainData:p,modelInfo:b}}function ce(t,e){return K(this,void 0,void 0,(function*(){const r=ue(new Uint8Array(e)),o=yield function(t,e){return K(this,void 0,void 0,(function*(){let r;const i=async function(t,e,r,i,o,s,a,u,c){return new Promise(((l,h)=>{const d=new Worker(new URL(n.p+n.u(763),n.b));d.postMessage(U(EDA.predictByLSSVM.arguments,[t,e,r,i,o,s,a,u,c])),d.onmessage=function(t){d.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 i.then((t=>{r=t}),(t=>{throw new Error(`Error: ${t}`)})),r}))}(r,t.columns),s=i.Column.string(Xt,o.length),a=r.realLabels.categories;for(let t=0;t<s.length;t++)s.set(t,-1==o.get(t)?a[0]:a[1]);return i.DataFrame.fromColumns([s])}))}function le(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 he(t,e){return t.rowCount<=1e3}var de,fe,pe,me,ge,ye,ve,we;!function(t){t[t.COMPUTE_COMPONENTS=0]="COMPUTE_COMPONENTS",t[t.PERFORM_MVA=1]="PERFORM_MVA",t[t.DEMO=2]="DEMO"}(de||(de={})),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"}(fe||(fe={})),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"}(pe||(pe={})),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"}(me||(me={})),function(t){t.PLS="https://datagrok.ai/help/explore/multivariate-analysis/pls#pls-components",t.MVA="https://datagrok.ai/help/explore/multivariate-analysis/pls",t.MODEL="https://datagrok.ai/help/explore/multivariate-analysis/plots/predicted-vs-reference",t.COEFFS="https://datagrok.ai/help/explore/multivariate-analysis/plots/regression-coefficients",t.LOADINGS="https://datagrok.ai/help/explore/multivariate-analysis/plots/loadings",t.EXPL_VARS="https://datagrok.ai/help/explore/multivariate-analysis/plots/explained-variance",t.SCORES="https://datagrok.ai/help/explore/multivariate-analysis/plots/scores"}(ge||(ge={})),function(t){t[t.DEFAULT=3]="DEFAULT",t[t.MIN=1]="MIN"}(ye||(ye={})),function(t){t.PREFIX="PLS",t.SUFFIX="(predicted)",t.COMP="component",t.COMPS="components"}(ve||(ve={})),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"}(we||(we={}));const be="Int",Ee=6,Ae=[.49,.79,.99],_e=1,Ce=200,Se=200;var Ie;!function(t){t.AXIS="#838383",t.CIRCLE="#0000FF"}(Ie||(Ie={}));const Me="# 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",Ne=[{caption:pe.MODEL,text:"Closer to the line means better price prediction."},{caption:pe.SCORES,text:"The latent factor values for each sample reflect the similarities and dissimilarities among observations."},{caption:pe.LOADINGS,text:"The impact of each feature on the latent factors: higher loading means stronger influence."},{caption:pe.REGR_COEFS,text:"Parameters of the obtained linear model: features make different contribution to the prediction."},{caption:pe.EXPL_VAR,text:"How well the latent components fit source data: closer to one means better fit."}],xe=Ne.map((t=>`# ${t.caption}\n\n${t.text}`)).join("\n\n")+`\n\n# Learn more\n \n * [Multivariate analysis](${ge.MVA}),\n * [ANOVA](https://datagrok.ai/help/explore/anova)`;var Le=function(t,e,n,r){return new(n||(n=Promise))((function(i,o){function s(t){try{u(r.next(t))}catch(t){o(t)}}function a(t){try{u(r.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}u((r=r.apply(t,e||[])).next())}))};const Te=Math.min,Oe=Math.max;function Pe(t){const e=[],n=(t,n)=>{e.push({type:"line",formula:t,width:_e,visible:!0,title:" ",min:-n,max:n,color:Ie.CIRCLE})};return t.forEach((r=>{const i="${"+r+"}";e.push({type:"line",formula:`${i} = 0`,width:_e,visible:!0,title:" ",color:Ie.AXIS}),t.forEach((t=>{const e="${"+t+"}";Ae.forEach((t=>{n(e+` = sqrt(${t*t} - ${i} * ${i})`,t),n(e+` = -sqrt(${t*t} - ${i} * ${i})`,t)}))}))})),e}function Re(t){return Le(this,void 0,void 0,(function*(){H(t.features,t.components),Y(t.predict),q(t.predict);const e=yield async function(t,e,r,i){return new Promise(((t,o)=>{const s=new Worker(new URL(n.p+n.u(412),n.b));s.postMessage(U(EDA.partialLeastSquareRegression.arguments,[e,r,i])),s.onmessage=function(e){s.terminate(),t(k(EDA.partialLeastSquareRegression,e.data))}}))}(t.table,t.features,t.predict,t.components);return{prediction:e[we.PREDICTION],regressionCoefficients:e[we.REGR_COEFFS],tScores:e[we.T_SCORES],uScores:e[we.U_SCORES],xLoadings:e[we.X_LOADINGS],yLoadings:e[we.Y_LOADINGS]}}))}function Fe(n){return Le(this,void 0,void 0,(function*(){const r=n===de.DEMO?t.shell.view(pe.BROWSE).preview.table:t.shell.t;if(null===r)return void t.shell.warning(fe.NO_DF);if(0===r.rowCount)return void t.shell.warning(fe.EMPTY_DF);const o=[],s=[],a=[],u=t=>(t.type===i.COLUMN_TYPE.INT||t.type===i.COLUMN_TYPE.FLOAT)&&0===t.stats.missingValueCount;if(r.columns.toList().forEach((t=>{u(t)?(o.push(t.name),s.push(t)):t.type===i.COLUMN_TYPE.STRING&&a.push(t)})),0===o.length)return void t.shell.warning(fe.NO_COLS);if(1===o.length)return void t.shell.warning(fe.ONE_COL);let c=s[s.length-1];const l=e.input.column(pe.PREDICT,{table:r,value:c,onValueChanged:t=>{c=t,v()},filter:t=>u(t)});let h;l.setTooltip(me.PREDICT);const d=e.input.columns(pe.USING,{table:r,available:o});d.onInput.subscribe((()=>v())),d.setTooltip(me.FEATURES);let f=Te(o.length-1,ye.DEFAULT);const p=e.input.forProperty(i.Property.fromOptions({name:pe.COMPONENTS,inputType:be,defaultValue:f,showPlusMinus:!0,min:ye.MIN}));let m,g,y;p.onInput.subscribe((()=>v())),p.setTooltip(me.COMPONENTS),n===de.COMPUTE_COMPONENTS?(m=pe.PLS,g=ge.PLS,y=me.PLS):(m=pe.MVA,g=ge.MVA,y=me.MVA);const v=()=>{var t;d.value=d.value.filter((t=>t!==c)),h=d.value,p.value=Te(Oe(null!==(t=p.value)&&void 0!==t?t:f,ye.MIN),h.length),f=p.value,E.getButton(pe.RUN).disabled=0===h.length||f<=0};let w=a.length>0?a[0]:void 0;const b=e.input.column(pe.NAMES,{table:r,value:w,onValueChanged:()=>{var t;return w=null!==(t=l.value)&&void 0!==t?t:void 0},filter:t=>t.type===i.COLUMN_TYPE.STRING});b.setTooltip(me.NAMES),b.root.hidden=0===a.length||n===de.COMPUTE_COMPONENTS;const E=e.dialog({title:m,helpUrl:g}).add(e.form([l,d,p,b])).addButton(pe.RUN,(()=>Le(this,void 0,void 0,(function*(){E.close(),yield function(n,r){return Le(this,void 0,void 0,(function*(){var o,s;const a=yield Re(n),u=a.tScores,c=n.table.columns,l=n.features,h=l.names(),d=r===de.COMPUTE_COMPONENTS?ve.PREFIX:pe.XSCORE;if(u.forEach(((t,e)=>{t.name=c.getUnusedName(`${d}${e+1}`),c.add(t)})),r===de.COMPUTE_COMPONENTS)return;const f=r===de.DEMO?t.shell.view(pe.BROWSE).preview:t.shell.tableView(n.table.name),p=i.DataFrame.fromColumns([i.Column.fromStrings(pe.FEATURE,h),a.regressionCoefficients]);a.xLoadings.forEach(((t,e)=>{t.name=p.columns.getUnusedName(`${pe.XLOADING}${e+1}`),p.columns.add(t)}));const m=function(t,e,n,r){const o=n.length,s=t.length,a=e.getRawData(),u=new Float32Array(o),c=r.getRawData();let l=n.stats.avg;for(let e=0;e<s;++e)l-=a[e]*t.byIndex(e).stats.avg;for(let t=0;t<o;++t)u[t]=l+c[t];return i.Column.fromFloat32Array("Debiased",u,o)}(l,a.regressionCoefficients,n.predict,a.prediction);m.name=c.getUnusedName(`${n.predict.name} ${ve.SUFFIX}`),c.add(m);const g=f.addViewer(i.Viewer.scatterPlot(n.table,{title:pe.MODEL,xColumnName:n.predict.name,yColumnName:m.name,showRegressionLine:!0,markerType:i.MARKER_TYPE.CIRCLE,labels:null===(o=n.names)||void 0===o?void 0:o.name,help:ge.MODEL}));a.regressionCoefficients.name=pe.REGR_COEFS;const y=f.addViewer(i.Viewer.barChart(p,{title:pe.REGR_COEFS,splitColumnName:pe.FEATURE,valueColumnName:a.regressionCoefficients.name,valueAggrType:i.AGG.AVG,help:ge.COEFFS,showValueSelector:!1,showStackSelector:!1}));a.xLoadings.forEach(((t,e)=>t.name=`${pe.XLOADING}${e+1}`));const v=f.addViewer(i.Viewer.scatterPlot(p,{title:pe.LOADINGS,xColumnName:`${pe.XLOADING}1`,yColumnName:`${pe.XLOADING}${a.xLoadings.length>1?"2":"1"}`,markerType:i.MARKER_TYPE.CIRCLE,labels:pe.FEATURE,help:ge.LOADINGS})),w=u.map((t=>t.name));a.uScores.forEach(((t,e)=>{t.name=c.getUnusedName(`${pe.YSCORE}${e+1}`),c.add(t),w.push(t.name)}));const b=i.Viewer.scatterPlot(n.table,{title:pe.SCORES,xColumnName:u[0].name,yColumnName:u.length>1?u[1].name:a.uScores[0].name,markerType:i.MARKER_TYPE.CIRCLE,labels:null===(s=n.names)||void 0===s?void 0:s.name,help:ge.SCORES,showViewerFormulaLines:!0});b.meta.formulaLines.addAll(Pe(w)),f.addViewer(b);const E=a.yLoadings.getRawData(),A=a.xLoadings.map((t=>t.getRawData())),_=n.table.rowCount,C=h.length,S=n.components,I=new Float32Array(S),M=[],N=[];for(let t=0;t<C;++t)N.push(new Float32Array(S));I[0]=Math.pow(E[0],2)/_,M.push(`1 ${ve.COMP}`),N.forEach(((t,e)=>{t[0]=Math.pow(A[0][e],2)/_}));for(let t=1;t<S;++t)I[t]=I[t-1]+Math.pow(E[t],2)/_,N.forEach(((e,n)=>e[t]=e[t-1]+Math.pow(A[t][n],2)/_)),M.push(`${t+1} ${ve.COMPS}`);const x=i.DataFrame.fromColumns([i.Column.fromStrings(pe.COMPONENTS,M),i.Column.fromFloat32Array(n.predict.name,I)]);N.forEach(((t,e)=>x.columns.add(i.Column.fromFloat32Array(h[e],t))));const L=f.addViewer(i.Viewer.barChart(x,{title:pe.EXPL_VAR,splitColumnName:pe.COMPONENTS,valueColumnName:n.predict.name,valueAggrType:i.AGG.AVG,help:ge.EXPL_VARS,showCategorySelector:!1,showStackSelector:!1}));if(r===de.DEMO){const n=[g,b,v,y,L].map(((t,e)=>({text:Ne[e].text,showNextTo:t.root})));e.hints.addTextHint({title:pe.EXPLORE,pages:n}).helpUrl=ge.MVA,t.shell.windows.help.showHelp(e.markdown(xe))}}))}({table:r,features:i.DataFrame.fromColumns(h).columns,predict:c,components:f,names:w},n)}))),void 0,y).show({x:Ce,y:Se});setTimeout((()=>{d.value=s.filter((t=>t!==c)),h=d.value}),Ee),t.shell.v.append(E.root)}))}var De,Ue=n(6572);function ke(t){if(t<=0||t>=1)throw new Error(De.INCORRECT_SIGNIFICANCE_LEVEL)}function Ge(t){const e=t.size;if(e<=0)throw new Error(De.INCORRECT_SAMPLE_SIZE);return 1===e?0:(t.sumOfSquares-Math.pow(t.sum,2)/e)/(e-1)}function Be(t,e,n=.05){ke(n);const r=Ge(t),i=Ge(e);return 0===i?r===i:r/i<Ue.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. INPUT ERROR.",t.INCORRECT_SIGNIFICANCE_LEVEL="incorrect significance level. It must be from the interval (0, 1). INPUT ERROR.",t.INCORRECT_SAMPLE_SIZE="incorrect size of sample. DATA FACTORIZAING ERROR.",t.NON_EQUAL_VARIANCES="variances are not equal.",t.NON_NORMAL_DISTRIB="non-normal distribution.",t.UNSUPPORTED_COLUMN_TYPE="unsupported column type.",t.INCORRECT_CATEGORIES_COL_TYPE="incorrect categories column type.",t.ANOVA_FAILED_JUST_ONE_CAT="ANOVA filed: there should be at least 2 categories."}(De||(De={}));class Ve{constructor(t,e,n=!1,r=.05){if(this.isNormDistrib=void 0,this.categories=[],t.type!==i.COLUMN_TYPE.STRING)throw new Error;if(t.length!==e.length)throw new Error(De.NON_EQUAL_FACTORS_VALUES_SIZE);this.setStats(t,e,n,r)}isNormal(){return!0}areVarsEqual(t=.05){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(!Be(n,{sum:this.sums[r],sumOfSquares:this.sumsOfSquares[r],size:this.subSampleSizes[r]},t))return!1;return!0}getOneWayAnova(){const t=this.catCount;if(1===t)throw new Error(De.ANOVA_FAILED_JUST_ONE_CAT);let e=0,n=0;const r=this.size;let i=0;for(let r=0;r<t;++r)e+=this.sums[r],n+=this.sumsOfSquares[r],i+=Math.pow(this.sums[r],2)/this.subSampleSizes[r];const o=n-Math.pow(e,2)/r,s=i-Math.pow(e,2)/r,a=o-s,u=t-1,c=r-t,l=s/u,h=a/c,d=l/h;return{ssBn:s,ssWn:a,ssTot:o,dfBn:u,dfWn:c,dfTot:r-1,msBn:l,msWn:h,fStat:d,pValue:1-Ue.centralF.cdf(d,u,c)}}setStats(t,e,n=!1,r=.05){const o=e.type,s=e.length;switch(o){case i.COLUMN_TYPE.INT:case i.COLUMN_TYPE.FLOAT:this.categories=t.categories;const n=this.categories.length;this.catCount=n,this.size=s;const r=e.getRawData(),o=t.getRawData(),a=new Float64Array(n).fill(0),u=new Float64Array(n).fill(0),c=new Int32Array(n).fill(0);for(let t=0;t<s;++t){const e=o[t];a[e]+=r[t],u[e]+=Math.pow(r[t],2),++c[e]}this.sums=a,this.sumsOfSquares=u,this.subSampleSizes=c;break;default:throw new Error(De.UNSUPPORTED_COLUMN_TYPE)}}}var We=function(t,e,n,r){return new(n||(n=Promise))((function(i,o){function s(t){try{u(r.next(t))}catch(t){o(t)}}function a(t){try{u(r.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}u((r=r.apply(t,e||[])).next())}))};function ze(t,e,r,i){return We(this,void 0,void 0,(function*(){return new Promise((function(o,s){const a=new Worker(new URL(n.p+n.u(682),n.b));a.postMessage({embedX:t,embedY:e,minPts:i,epsilon:r}),a.onmessage=({data:{error:t,clusters:e}})=>{a.terminate(),t?s(t):o(e)}}))}))}n(5540);let je=null;function Ye(){return t=this,e=void 0,r=function*(){if(!je&&(je=yield navigator.gpu.requestAdapter(),null==je))return null;const t=yield je.requestAdapterInfo();return t?qe(t.description,qe(t.vendor,"No GPU description available")):null},new((n=void 0)||(n=Promise))((function(i,o){function s(t){try{u(r.next(t))}catch(t){o(t)}}function a(t){try{u(r.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}u((r=r.apply(t,e||[])).next())}));var t,e,n,r}function qe(t,e){return t&&""!=t?t:e}var He,$e,Ke,Xe,Qe,Ze,Je,tn,en;($e=He||(He={})).EUCLIDEAN="EUCLIDEAN",$e.MANHATTAN="MANHATTAN",He.EUCLIDEAN,He.MANHATTAN,(Xe=Ke||(Ke={})).HAMMING="Hamming",Xe.EUCLIDEAN="Euclidean",Xe.MANHATTAN="Manhattan",Xe.TANIMOTO="Tanimoto",Xe.LEVENSTEIN="Levenshtein",Xe.NEEDLEMAN_WUNSCH="Needlemann-Wunsch",Xe.MONOMER_CHEMICAL_DISTANCE="Monomer chemical distance",Xe.SOKAL="Sokal",Xe.COSINE="Cosine",Xe.ASYMMETRIC="Asymmetric",Xe.Difference="Difference",Xe.OneHot="One-Hot",Ke.HAMMING,Ke.EUCLIDEAN,Ke.MANHATTAN,Ke.TANIMOTO,Ke.LEVENSTEIN,Ke.NEEDLEMAN_WUNSCH,Ke.MONOMER_CHEMICAL_DISTANCE,Ke.SOKAL,Ke.COSINE,Ke.ASYMMETRIC,Ke.Difference,Ke.OneHot,Ke.HAMMING,Ke.EUCLIDEAN,Ke.MANHATTAN,Ke.TANIMOTO,Ke.SOKAL,Ke.COSINE,Ke.ASYMMETRIC,Ke.LEVENSTEIN,Ke.NEEDLEMAN_WUNSCH,Ke.MONOMER_CHEMICAL_DISTANCE,Ke.Difference,Ke.OneHot,new Set([Ke.HAMMING,Ke.LEVENSTEIN,Ke.NEEDLEMAN_WUNSCH,Ke.MONOMER_CHEMICAL_DISTANCE,Ke.OneHot]),new Set([Ke.HAMMING,Ke.EUCLIDEAN,Ke.MANHATTAN,Ke.MONOMER_CHEMICAL_DISTANCE,Ke.LEVENSTEIN,Ke.NEEDLEMAN_WUNSCH,Ke.TANIMOTO,Ke.COSINE,Ke.SOKAL,Ke.ASYMMETRIC,Ke.OneHot,Ke.Difference]),new Set([Ke.EUCLIDEAN,Ke.MANHATTAN,Ke.OneHot,Ke.Difference]),new Set([Ke.EUCLIDEAN,Ke.MANHATTAN,Ke.Difference]),new Set([Ke.EUCLIDEAN,Ke.MANHATTAN,Ke.Difference]),new Set([Ke.TANIMOTO,Ke.COSINE,Ke.SOKAL,Ke.ASYMMETRIC]),function(t){t.ADD="ADD",t.SUB="SUB",t.MULT="MULT"}(Qe||(Qe={})),function(t){t.SQUARE="SQUARE",t.INVERSE="INVERSE",t.TRANSPOSE="TRANSPOSE",t.NORM="NORM",t.COLUMN_NORM="COLUMN_NORM"}(Ze||(Ze={})),function(t){t.SCALARMULT="SCALARMULT",t.SCALARADD="SCALARADD",t.SCALARPOW="SCALARPOW"}(Je||(Je={})),Object.prototype.toString,(en=tn||(tn={})).UMAP="UMAP",en.T_SNE="t-SNE",Promise.resolve(),n(934),n(8903);const nn=2,rn="MCL_OPTIONS";i.SEMTYPE.MOLECULE,i.SEMTYPE.MACROMOLECULE;class on{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 sn="bypassLargeDataWarning",an="show-scatterplot-progress";var un,cn;(cn=un||(un={})).EUCLIDEAN="EUCLIDEAN",cn.MANHATTAN="MANHATTAN";const ln=rxjs;var hn=n(5072),dn=n.n(hn),fn=n(7825),pn=n.n(fn),mn=n(7659),gn=n.n(mn),yn=n(5056),vn=n.n(yn),wn=n(540),bn=n.n(wn),En=n(1113),An=n.n(En),_n=n(7939),Cn={};Cn.styleTagTransform=An(),Cn.setAttributes=vn(),Cn.insert=gn().bind(null,"head"),Cn.domAPI=pn(),Cn.insertStyleElement=bn(),dn()(_n.A,Cn),_n.A&&_n.A.locals&&_n.A.locals;class Sn{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"},Ye().then((t=>{t?(this.useWebGPU.tooltip+=` (${t})`,this.useWebGPU.value=!0):(this.useWebGPU.value=!1,this.useWebGPU.disable=!0)}))}}class In{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 Mn{constructor(n={}){this.editorSettings={},this.columnOptEditors=[],this.columnOptEditorsRoot=e.div(),this.columnParamsEditorRoot=e.div(),this.weightsEditorRoot=e.div(),this.columnFunctionsMap={},this.methodsParams={[tn.UMAP]:new Sn,[tn.T_SNE]:new In},this.dbScanParams=new on,this.methodSettingsDivs=[],this.supportedFunctions={},this.methodSettingsAnchor=e.div(),this.plotEmbeddingsInput=e.input.bool("Plot embeddings",{value:!0}),this.aggregationMethodInput=e.input.choice("Aggregation",{value:un.EUCLIDEAN,items:[un.EUCLIDEAN,un.MANHATTAN]}),this.aggregationMethodInput.setTooltip("Aggregation method for combining distances between columns"),this.onColumnsChanged=new ln.Subject,this.editorSettings=n,this.columnParamsEditorAccordion=e.accordion(),i.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")??"",i=t.options.get("supportedUnits")??"",o=t.options.get("supportedDistanceFunctions")??"";this.editorSettings.semtype&&!e.includes(this.editorSettings.semtype)||this.editorSettings.type&&!r.includes(this.editorSettings.type)||this.editorSettings.units&&!i.includes(this.editorSettings.units)||(this.supportedFunctions[n]={func:t,semTypes:e?e.split(","):[],types:r?r.split(","):[],units:i?i.split(","):[],distanceFunctions:o?o.split(","):[]})})),this.postProcessingEditor=new Ln,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:tn.UMAP,items:[tn.UMAP,tn.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,i=this.supportedFunctions[e].units,o=!n.length||t.semType&&n.includes(t.semType),s=!r.length||r.includes(t.type),a=!i.length||t.meta.units&&i.includes(t.meta.units);o&&s&&a&&(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 Nn(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 i=0;const o=e.table(r,(t=>(i++,t&&t.length>0?t:[this.columnOptEditors[Math.floor((i-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"),o.classList.add("ml-dim-reduction-column-editor-table-root"),this.columnOptEditorsRoot.appendChild(o)},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((i=>{const o=t[i],s="string"===o.type?e.input.string(o.uiName,{value:o.value??"",onValueChanged:t=>{o.value=t}}):"boolean"===o.type?e.input.bool(o.uiName,{value:o.value??!1,onValueChanged:t=>{o.value=t}}):e.input.float(o.uiName,{value:o.value,onValueChanged:t=>{o.value=t}});o.disable?(s.enabled=!1,e.tooltip.bind(s.input??s.root,o.disableTooltip??"")):e.tooltip.bind(s.input??s.root,o.tooltip),r.insertBefore(s.root,n),this.methodSettingsDivs.push(s.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 Nn{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[xn(t.func)]=t.func})),this.preprocessingFunctionInput=e.input.choice("Encoding function",{value:xn(this.supportedFunctions[0].func),items:this.supportedFunctions.map((t=>xn(t.func))),onValueChanged:t=>{const n=this.functionsMap[t];this.preprocessingFunctionSettings={},this.hasExtraSettings=n.inputs.length>2;const i=this.supportedFunctions.find((e=>xn(e.func)===t));this.getSimilarityMetricInput(i),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 i=e.h3(this.column.name,{classes:"ml-dim-reduction-column-editor-column-title"});this.colOptEditors=[i,this.preprocessingFunctionInput.root,this.similarityMetricInputRoot,this.weightInput.root],e.tooltip.bind(i,this.column.name),this.colOptEditors.forEach((t=>t.classList.add("ml-dim-reduction-column-editor-input-root")));const o=e.divH(this.colOptEditors,{classes:"ml-dim-reduction-column-editor-root"});this.accordionDiv=e.divV([]),this.editorDiv.appendChild(o),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(),i=await r.buildEditor(e.div());for(let e=2;e<n.inputs.length;e++){const o=n.inputs[e],s=this.preprocessingFunctionSettings[o.name]||r.inputParams[n.inputs[e].name].value||o.defaultValue;s&&(this.preprocessingFunctionSettings[o.name]=s);const a=i.find((t=>t.property.name===o.name));a&&(null!==this.preprocessingFunctionSettings[o.name]&&void 0!==this.preprocessingFunctionSettings[o.name]&&(a.value=this.preprocessingFunctionSettings[o.name]),a.onChanged.subscribe((t=>{this.preprocessingFunctionSettings[o.name]=t})),t.append(a.root))}return t.style.marginBottom="10px",t}}function xn(t){return t.friendlyName??t.name}class Ln{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",i.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),i=await r.buildEditor(e.div());for(let e=2;e<t.inputs.length;e++){const n=t.inputs[e],o=this._postProcessingArgs[n.name]||r.inputParams[t.inputs[e].name].value||n.defaultValue;o&&(this._postProcessingArgs[n.name]=o);const s=i.find((t=>t.property.name===n.name));s&&(s.onChanged.subscribe((t=>{this._postProcessingArgs[n.name]=t})),this._argsElement.append(s.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 Tn="dimensionality-reducer-terminate-event",On=t=>null==t;function Pn(t,e){return`${e} (${t.length>4?`${t.length} columns`:t.map((t=>t.name)).join(", ")})`}var Rn;!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"}(Rn||(Rn={}));const Fn="copy";var Dn;!function(t){t.KNN_IMPUTER="Impute",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"}(Dn||(Dn={}));const Un="/help/explore/missing-values-imputation";var kn;!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 KNN 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"}(kn||(kn={}));const Gn=[i.COLUMN_TYPE.INT,i.COLUMN_TYPE.FLOAT,i.COLUMN_TYPE.STRING,i.COLUMN_TYPE.DATE_TIME,i.COLUMN_TYPE.QNUM];function Bn(t){switch(t.type){case i.COLUMN_TYPE.INT:return i.INT_NULL;case i.COLUMN_TYPE.FLOAT:case i.COLUMN_TYPE.QNUM:case i.COLUMN_TYPE.DATE_TIME:return i.FLOAT_NULL;case i.COLUMN_TYPE.STRING:return t.max;default:throw new Error(Rn.UNSUPPORTED_COLUMN_TYPE)}}var Vn,Wn,zn;!function(t){t.ONE_HOT="One-hot",t.DIFFERENCE="Difference"}(Vn||(Vn={})),function(t){t.EUCLIDEAN="Euclidean",t.MANHATTAN="Manhattan"}(Wn||(Wn={})),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"}(zn||(zn={}));const jn=1;function Yn(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(Rn.FAILS_TO_PREDICT_IMPUTATION_FAILS);for(const r of t){let t=!0;for(const i of e){const e=n.get(i);if(void 0===e)throw new Error(Rn.FAILS_TO_PREDICT_IMPUTATION_FAILS);if(!e.includes(r)){t=!1;break}}if(t)return!0}}return!1}var qn,Hn=function(t,e,n,r){return new(n||(n=Promise))((function(i,o){function s(t){try{u(r.next(t))}catch(t){o(t)}}function a(t){try{u(r.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}u((r=r.apply(t,e||[])).next())}))};function $n(n){return Hn(this,void 0,void 0,(function*(){if(null!=n||(n=t.shell.t),null===n)return void t.shell.warning(Rn.NO_DATAFRAME);const r=[],o=[],s=[];n.columns.toList().filter((t=>Gn.includes(t.type))).forEach((t=>{const e=t.stats.missingValueCount;e!==t.length&&(s.push(t.name),e>0&&(r.push(t),o.push(t.name)))}));const a=function(t){const e=new Map;for(const n of t){if(!Gn.includes(n.type))throw new Error(Rn.UNSUPPORTED_COLUMN_TYPE);if(0===n.stats.missingValueCount)continue;const t=[],r=Bn(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(Rn.NO_MISSING_VALUES);if(1===s.length)return void t.shell.error(Rn.ONE_AVAILABLE_FEATURE);let u=zn.IN_PLACE>0;const c=e.input.bool(Dn.IN_PLACE,{value:u,onValueChanged:t=>{u=null!=t&&t}});c.setTooltip(kn.IN_PLACE);let l=zn.KEEP_EMPTY>0;const h=e.input.bool(Dn.KEEP_EMPTY,{value:l,onValueChanged:t=>{l=null!=t&&t}});h.setTooltip(kn.KEEP_EMPTY);let d=zn.NEIGHBORS;const f=e.input.int(Dn.NEIGHBORS,{value:d,showPlusMinus:!0,min:jn,nullable:!1,onValueChanged:t=>{null!==t&&t>=jn&&(d=t),E()}});f.setTooltip(kn.NEIGHBORS);let p=Wn.EUCLIDEAN;const m=e.input.choice(Dn.DISTANCE,{value:p,items:[Wn.EUCLIDEAN,Wn.MANHATTAN],onValueChanged:t=>p=null!=t?t:Wn.EUCLIDEAN});m.setTooltip(kn.DISTANCE);let g=r.map((t=>t.name));const y=e.input.columns(Dn.COLUMNS,{table:n,value:n.columns.byNames(o),onValueChanged:t=>{g=t.map((t=>t.name)),E()},available:o});y.setTooltip(kn.TARGET);let v=s;const w=e.input.columns(Dn.FEATURES,{value:n.columns.byNames(s),table:n,onValueChanged:t=>{v=t.map((t=>t.name)),v.length>0?(E(),_.forEach(((t,e)=>t.hidden=!v.includes(e)))):b()},available:s});w.setTooltip(kn.FEATURES);const b=()=>{S.getButton(Dn.RUN).disabled=!0,c.root.hidden=!0,h.root.hidden=!0,f.root.hidden=!0,M.hidden=!0,C.hidden=!0},E=()=>{S.getButton(Dn.RUN).disabled=null===f.value||f.value<jn,M.hidden=!1,c.root.hidden=!1,f.root.hidden=!1,m.root.hidden=!1,h.root.hidden=!Yn(g,v,a),1===v.length&&g.forEach((e=>{v[0]===e&&(b(),t.shell.warning(`${Rn.ONE_FEATURE_SELECTED} the column '${e}'`))})),g.length<1&&b()},A=new Map,_=new Map,C=e.divV([]);C.style.overflow="auto",s.forEach((t=>{const r=function(t){switch(t){case i.COLUMN_TYPE.STRING:case i.COLUMN_TYPE.DATE_TIME:return{defaultWeight:zn.WEIGHT,defaultMetric:Vn.ONE_HOT,availableMetrics:[Vn.ONE_HOT]};case i.COLUMN_TYPE.INT:case i.COLUMN_TYPE.FLOAT:case i.COLUMN_TYPE.QNUM:return{defaultWeight:zn.WEIGHT,defaultMetric:Vn.DIFFERENCE,availableMetrics:[Vn.DIFFERENCE,Vn.ONE_HOT]};default:throw new Error(Rn.UNSUPPORTED_COLUMN_TYPE)}}(n.col(t).type);A.set(t,{weight:r.defaultWeight,type:r.defaultMetric});const o=e.input.choice(t,{value:r.defaultMetric,items:r.availableMetrics,onValueChanged:e=>{var n;const i=null!==(n=A.get(t))&&void 0!==n?n:{weight:r.defaultWeight,type:r.defaultMetric};i.type=null!=e?e:r.defaultMetric,A.set(t,i)}});o.root.style.width="50%",o.setTooltip(kn.METRIC),o.root.hidden=!0;const s=i.Property.fromOptions({name:t,inputType:"Float",min:0,max:10,showSlider:!0,step:1}),a=e.input.forProperty(s);a.value=r.defaultWeight,a.onChanged.subscribe((e=>{var n;const i=null!==(n=A.get(t))&&void 0!==n?n:{weight:r.defaultWeight,type:r.defaultMetric};i.weight=null!=e?e:r.defaultWeight,A.set(t,i)})),a.setTooltip(kn.WEIGHT);const u=e.divH([o.root,a.root]);_.set(t,u),C.append(u)}));const S=e.dialog({title:Dn.KNN_IMPUTER,helpUrl:Un});t.shell.v.root.appendChild(S.root),C.hidden=!0,h.root.hidden=!Yn(g,v,a);const I=e.icons.settings((()=>{C.hidden=!C.hidden}),kn.METRIC_SETTINGS),M=e.divH([m.root,I]);let N,x,L=!1;const T=new Promise(((t,e)=>{N=t,x=e}));return S.addButton(Dn.RUN,(()=>{L=!0,S.close(),s.filter((t=>!v.includes(t))).forEach((t=>A.delete(t)));try{const e=function(e,n,r,o,s,a,u){if(a<jn)throw new Error(Rn.INCORRECT_NEIGHBORS);if(e.rowCount<2)throw new Error(Rn.KNN_NOT_ENOUGH_OF_ROWS);if(0===n.length)throw new Error(Rn.KNN_NO_TARGET_COLUMNS);if(0===r.size)throw new Error(Rn.KNN_NO_FEATURE_COLUMNS);1===r.size&&n.forEach((t=>{if(r.has(t))throw new Error(`${Rn.KNN_NO_FEATURE_COLUMNS} can be used for the column '${t}'`)})),n.forEach((t=>{if(!o.has(t))throw new Error(`${Rn.KNN_FAILS}: ${Rn.WRONG_PREDICTIONS}`)}));const c=e.columns;n.forEach((t=>{if(!Gn.includes(c.byName(t).type))throw new Error(Rn.UNSUPPORTED_COLUMN_TYPE)})),r.forEach(((t,n)=>{if(!Gn.includes(e.getCol(n).type))throw new Error(Rn.UNSUPPORTED_COLUMN_TYPE)}));const l=new Map;return n.forEach((n=>{const h=c.byName(n),d=Bn(h),f=h.length,p=h.getRawData(),m=new Uint16Array(h.categories.length),g=[],y=[],v=[],w=[];r.forEach(((t,e)=>{if(e!==h.name){const n=c.byName(e);switch(g.push(n.getRawData()),y.push(Bn(n)),t.type){case Vn.DIFFERENCE:v.push(((e,n)=>t.weight*Math.abs(e-n)));break;case Vn.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 _=0;const C=new Array(a);let S=0,I=0,M=0,N=0,x=0;const L=(t,e)=>{E.forEach(((n,r)=>{A[r]=v[n](g[n][t],g[n][e])}))},T=s===Wn.EUCLIDEAN?()=>{let t=0;for(let e=0;e<_;++e)t+=A[e]*A[e];return Math.sqrt(t)}:()=>{let t=0;for(let e=0;e<_;++e)t+=Math.abs(A[e]);return Math.sqrt(t)},O=t=>{if(p[t]===d)return!1;for(let e=0;e<_;++e)if(g[E[e]][t]===y[E[e]])return!1;return!0},P=t=>{if((t=>{_=0;for(let e=0;e<b;++e)g[e][t]!==y[e]&&(E[_]=e,++_)})(t),0===_)throw new Error(`${Rn.KNN_IMPOSSIBLE_IMPUTATION}: the column "${h.name}", row ${t+1}`);S=0;for(let e=0;e<f;++e)if(O(e)&&e!==t){L(t,e);const n=T();if(S<a)C[S]={index:e,dist:n},++S;else{I=0,M=C[0].dist;for(let t=1;t<S;++t)M<C[t].dist&&(M=C[t].dist,I=t);n<M&&(C[I]={index:e,dist:n})}}if(0===S)throw new Error(`${Rn.KNN_IMPOSSIBLE_IMPUTATION}: the column "${h.name}", row ${t+1}`);if(h.type===i.COLUMN_TYPE.STRING)return(()=>{m.forEach(((t,e,n)=>n[e]=0));let t=0;for(t=0;t<S;++t)++m[p[C[t].index]];let e=m[0],n=0;return m.forEach(((t,r)=>{t>e&&(e=t,n=r)})),n})();N=0;for(let t=0;t<S;++t)N+=p[C[t].index];return x=N/S,h.type===i.COLUMN_TYPE.INT?Math.round(x):x};if(u){for(const e of o.get(n))try{p[e]=P(e)}catch(n){w.push(e),n instanceof Error||t.shell.error(Rn.CORE_ISSUE)}w.length>0&&l.set(n,w),h.set(0,h.get(0))}else{const r=h.clone();let i=1,s=`${n}(${Fn})`;for(;e.columns.contains(s);)s=`${n}(${Fn} ${i})`,++i;r.name=s;const a=r.getRawData();for(const e of o.get(n))try{a[e]=P(e)}catch(n){w.push(e),n instanceof Error||t.shell.error(Rn.CORE_ISSUE)}w.length>0&&l.set(s,w),r.set(0,r.get(0)),e.columns.add(r)}})),l}(n,g,A,a,p,d,u);l||function(t,e){e.forEach(((e,n)=>{const r=t.col(n);if(null!==r){if(!Gn.includes(r.type))throw new Error(Rn.UNSUPPORTED_COLUMN_TYPE);const t=function(t){switch(t.type){case i.COLUMN_TYPE.STRING:case i.COLUMN_TYPE.DATE_TIME:return function(t){const e=Bn(t),n=t.getRawData(),r=n.length;for(let i=0;i<r;++i)if(n[i]!==e)return t.get(i);throw new Error(Rn.EMPTY_COLUMN)}(t);case i.COLUMN_TYPE.INT:case i.COLUMN_TYPE.FLOAT:case i.COLUMN_TYPE.QNUM:return t.stats.avg;default:throw new Error(Rn.UNSUPPORTED_COLUMN_TYPE)}}(r);e.forEach((e=>r.set(e,t)))}}))}(n,e),N()}catch(e){e instanceof Error?t.shell.error(`${Rn.KNN_FAILS}: ${e.message}`):t.shell.error(`${Rn.KNN_FAILS}: ${Rn.CORE_ISSUE}`),x(e)}})),S.add(y).add(w).add(M).add(C).add(f).add(c).add(h).show().onClose.subscribe((()=>!L&&N())),T}))}class Kn extends Mn{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}),Ye().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"})}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 Xn{constructor(t,e=!1){if(this._length=0,this._version=0,this._updateLevel=0,this._selectedCount=0,this._selectedCountVersion=-1,this._selectedIndexesVersion=-1,this._versionedName="",this._versionedNameVersion=-1,this.SHRINK_THRESHOLD=256,"number"==typeof t){const n=t,r=Xn._createBuffer(n);if(e)for(let t=0;t<r.length;t++)r[t]=-1;this._data=r,this._length=n}else{if(!(t instanceof Uint32Array))throw new Error("Invalid constructor");this._data=t,this._length=e}}getRawData(){return this._data}assureGoez(t,e){if(t<0)throw new Error(`${e} should be greater than zero`)}assureInRange(t,e,n,r){if(t<e||t>n)throw new Error(`Argument ${r} (${t}) out of range (${e}, ${n})`)}copy(t,e,n){for(let r=0;r<n;r++)e[r]=t[r]}copyFrom(t){if(this._length!=t._length)throw new Error(`Lengths differ (${this._length} != ${t._length})`);this.copy(t._data,this._data,this.lengthInInts),this._version++}get length(){return this._length}get buffer(){return this._data}set buffer(t){this._data=t,this._version++}get version(){return this._version}set version(t){this._version=t}incrementVersion(t=!0){this._version++}get lengthInInts(){return Math.floor((this._length+31)/32)}get versionedName(){return this._version==this._versionedNameVersion?this._versionedName:""}set versionedName(t){this._versionedName=t,this._versionedNameVersion=this._version}get self(){return this}setLength(t){if(t<0)throw new Error("should be >= 0");if(t==this._length)return;const e=Math.floor((t+31)/32);if(e>this._data.length||e+this.SHRINK_THRESHOLD<this._data.length){const t=new Uint32Array(e);this.copy(this._data,t,e>this._data.length?this._data.length:e),this._data=t}t>this._length&&(this._length%32>0&&(this._data[this.lengthInInts-1]&=(1<<(this._length%32&31))-1),this._data.fill(0,this.lengthInInts,e)),this._length=t,this._version++}static fromAnd(t,e){if(t._length!=e._length)throw new Error(`Lengths differ (${t._length} != ${e._length})`);const n=new Xn(t._length);n._length=t._length,n._data=Xn._createBuffer(n._length),n._version=0;const r=t.lengthInInts;for(let i=0;i<r;i++)n._data[i]=t._data[i]&e._data[i];return n}static _createBuffer(t){return new Uint32Array(Math.floor((t+31)/32))}static fromValues(t){const e=new Xn(t.length);e._version=0;for(let n=0;n<e._length;n++)t[n]&&(e._data[Math.floor(n/32)]|=1<<(n%32&31));return e}static fromSeq(t,e){const n=new Xn(t);for(let r=0;r<t;++r)n.setBit(r,e(r));return n._version=0,n}static fromString(t){return Xn.fromSeq(t.length,(e=>"1"==t.charAt(e)))}static fromUint32Array(t,e){const n=new Xn(t);return n._data=e,n}static fromBytes(t){const e=t.length,n=new Xn(8*e);n._data=new Uint32Array(Math.floor((e+3)/4)),n._length=8*e;let r=0,i=0;for(;e-i>=4;)n._data[r++]=255&t[i]|(255&t[i+1])<<8|(255&t[i+2])<<16|(255&t[i+3])<<24,i+=4;return e-i==3&&(n._data[r]=(255&t[i+2])<<16),e-i==2&&(n._data[r]|=(255&t[i+1])<<8),e-i==1&&(n._data[r]|=255&t[i]),n._version=0,n}toString(){return`${this._length} bits, ${this.countBits(!0)} set`}equals(t){if(this==t)return!0;if(null==t)return!1;if(this._length!=t._length)return!1;if(0==this._length)return!0;for(let e=0;e<this._data.length-1;e++)if(this._data[e]!=t._data[e])return!1;for(let e=8*(this._data.length-1);e<this._length;e++)if(this.getBit(e)!=t.getBit(e))return!1;return!0}clone(){const t=new Xn(0,!1);return t._data=Uint32Array.from(this._data),t._length=this._length,t._version=this._version,t}init(t,e){this.setAll(!1,!1);for(let e=0;e<this._length;e++)t(e)&&(this._data[Math.floor(e/32)]|=1<<(e%32&31));return this.incrementVersion(e),this}invert(t=!0){for(let t=0;t<this._data.length;t++)this._data[t]^=-1;this.incrementVersion(t)}setAll(t,e=!1){const n=t?-1:0,r=this.lengthInInts;for(let t=0;t<r;t++)this._data[t]=n;this.incrementVersion(e)}setIndexes(t,e=!0,n=!0,r=!0){n&&this.setAll(!e,!1);for(const n of t)this.setFast(n,e);this.incrementVersion(r)}everyIndex(t,e=!0){for(const n of t)if(this.getBit(n)!=e)return!1;return!0}anyIndex(t,e=!0){for(const n of t)if(this.getBit(n)==e)return!0;return!1}setWhere(t,e=!0,n=!0,r=!0,i=!0){if(n&&i&&this.setAll(!e,!1),i)for(let n=0;n<this._length;n++)t(n)&&this.setFast(n,e);else for(let n=0;n<this._length;n++)this.setFast(n,t(n)?e:!e);this.incrementVersion(r)}getRange(t,e){this.assureInRange(t,0,this._length-1,"from"),this.assureInRange(e,0,this._length,"to");const n=[];for(let r=t;r<e;++r)n.push(this.getBit(r));return Xn.fromValues(n)}getRangeAsList(t,e){this.assureInRange(t,0,this._length-1,"from"),this.assureInRange(e,0,this._length,"to");const n=[];for(let r=t;r<e;++r)n.push(this.getBit(r));return n}setRange(t,e,n,r=!0){this.assureInRange(t,0,this._length-1,"from"),this.assureInRange(e,0,this._length-1,"to");const i=Math.min(t,e),o=Math.max(t,e);if(n)for(let t=i;t<=o;t++)this.setTrue(t);else for(let t=i;t<=o;t++)this.setFalse(t);return this.incrementVersion(r),this}setRandom(t,e,n=!0){if(t<0||t>this._length)throw new Error("n must be >= 0 && <= Count");t>this._length/2&&this.setRandom(this._length-t,!e),this.setAll(!e);for(let n=0;n<t;){const t=Math.floor(Math.random()*this._length);this.getBit(t)!=e&&(this.setFast(t,e),n++)}this.incrementVersion(n)}and(t,e=!0){if(this._length!=t._length)throw new Error("Array lengths differ.");for(let e=0,n=this.lengthInInts;e<n;e++)this._data[e]&=t._data[e];return this.incrementVersion(e),this}andNot(t,e=!0){if(this._length!=t._length)throw new Error("Array lengths differ.");const n=this.lengthInInts;for(let e=0;e<n;e++)this._data[e]&=~t._data[e];return this.incrementVersion(e),this}notAnd(t,e=!0){if(this._length!=t._length)throw new Error("Array lengths differ.");for(let e=0,n=this.lengthInInts;e<n;e++)this._data[e]=~this._data[e]&t._data[e];return this.incrementVersion(e),this}not(t=!0){for(let t=0,e=this.lengthInInts;t<e;t++)this._data[t]=~this._data[t];return this.incrementVersion(t),this}or(t,e=!0){if(this._length!=t._length)throw new Error("Array lengths differ.");for(let e=0,n=this.lengthInInts;e<n;e++)this._data[e]|=t._data[e];return this.incrementVersion(e),this}xor(t,e=!0){if(this._length!=t._length)throw new Error("Array lengths differ.");for(let e=0,n=this.lengthInInts;e<n;e++)this._data[e]^=t._data[e];return this.incrementVersion(e),this}insertAt(t,e,n=!1){if(this.assureInRange(t,0,this._length,"pos"),0==e)return;const r=this._length;this.setLength(this._length+e);for(let n=r-1;n>=t;n--)this.setBit(n+e,this.getBit(n));for(let r=t;r<t+e;r++)this.setBit(r,n)}removeAt(t,e=1){if(e<0)throw new Error("n cannot be negative");if(this.assureInRange(t,0,this._length-e,"pos"),this.contains(!0))for(let n=t;n<this._length-e;n++)this.setBit(n,this.getBit(n+e));this.setLength(this._length-e)}removeByMask(t,e=!0){if(this._length!=t.length)throw new Error("length != mask.length");if(t==this)this.setLength(t.countBits(!e)),this.setAll(!e);else{let n=0;for(let r=-1;-1!=(r=t.findNext(r,!e));)this.setFast(n++,this.getBit(r));this._length=n,this._version++}return this}getBit(t){return!!(this._data[Math.floor(t/32)]&1<<(31&t))}setBit(t,e,n=!0){this.setFast(t,e),this._version++}setFast(t,e){e?this._data[Math.floor(t/32)]|=1<<(31&t):this._data[Math.floor(t/32)]&=~(1<<(31&t))}setTrue(t){this._data[Math.floor(t/32)]|=1<<(31&t)}setFalse(t){this._data[Math.floor(t/32)]&=~(1<<(31&t))}trueCount(){return this.countBits(!0)}falseCount(){return this.countBits(!1)}countBits(t){if(0==this._length)return 0;if(this._selectedCountVersion!=this._version){this._selectedCount=0;const t=this.lengthInInts;let e=0;for(;e<t-1;e++)for(let t=this._data[e];0!=t;t>>>=8)this._selectedCount+=Xn._onBitCount[255&t];let n=this._data[e];const r=31&this._length;for(0!=r&&(n&=~(4294967295<<r));0!=n;n>>>=8)this._selectedCount+=Xn._onBitCount[255&n];this._selectedCountVersion=this._version}return t?this._selectedCount:this._length-this._selectedCount}countWhere(t){let e=0;if(this.trueCount()==this._length)for(let n=0;n<this._length;n++)e+=t(n)?1:0;else for(let n=-1;-1!=(n=this.findNext(n,!0));)e+=t(n)?1:0;return e}andWithCountBits(t,e){if(0==this._length)return 0;let n=0;const r=this.lengthInInts;let i=0;for(;i<r-1;i++)for(let e=this._data[i]&t._data[i];0!=e;e>>>=8)n+=Xn._onBitCount[255&e];let o=this._data[i]&t._data[i];const s=31&this._length;for(0!=s&&(o&=~(4294967295<<s));0!=o;o>>>=8)n+=Xn._onBitCount[255&o];return e?n:this._length-n}clear(){this.setLength(0)}contains(t){return this.findNext(-1,t)>=0}get allTrue(){return this.countBits(!0)==this._length}get allFalse(){return this.countBits(!1)==this._length}get anyTrue(){return this.countBits(!0)>0}get anyFalse(){return this.countBits(!1)>0}findNext(t,e=!0){if(this.assureInRange(t,-1,this._length,"index"),t>=this._length-1)return-1;let n=31&(t=t<0?0:t+1);const r=this.lengthInInts;for(let i=Math.floor(t/32);i<r;i++){let r=e?this._data[i]:~this._data[i];if(0!=n)r&=4294967295<<n&4294967295,n=0;else if(!e&&-4294967296==r)continue;for(let e=0;0!=r;e+=8,r>>>=8){const n=Xn._firstOnBit[255&r];if(n>=0)return(t=n+32*i+e)>=this._length?-1:t}}return-1}findPrev(t,e=!0){if(0==t)return-1;this.assureInRange(t,-1,this._length,"index");let n=1+(t=t<0?this._length-1:t-1)&31;for(let r=Math.floor(t/32);r>=0;r--){let t=e?this._data[r]:~this._data[r];0!=n&&(t&=~(4294967295<<n),n=0);for(let e=24;0!=t;e-=8,t<<=8){const n=Xn._lastOnBit[t>>>24];if(n>=0)return n+32*r+e}}return-1}}Xn._onBitCount=Int8Array.from([0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,4,5,5,6,5,6,6,7,5,6,6,7,6,7,7,8]),Xn._firstOnBit=Int8Array.from([-1,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,6,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,7,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,6,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0]),Xn._lastOnBit=Int8Array.from([-1,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7]),function(t){t.none="none",t.bold="bold",t.dashed="dashed"}(qn||(qn={}));class Qn{get currentLineId(){return this._currentLineIdx}set currentLineId(t){t!==this._currentLineIdx&&(this._currentLineIdx=t,this.sp.render(this.ctx))}set linesToRender(t){this.updateLines(t),this.sp.render(this.ctx)}set linesVisibility(t){this.visibility=t,this.sp.render(this.ctx)}constructor(t,e,n,r,i=qn.none){var o;this._currentLineIdx=-1,this.lineClicked=new ln.Subject,this.lineHover=new ln.Subject,this.mouseOverLineId=-1,this.arrowWidth=15,this.sp=t,this.xAxisCol=this.sp.dataFrame.columns.byName(e),this.yAxisCol=this.sp.dataFrame.columns.byName(n),this.canvas=this.sp.getInfo().canvas,this.ctx=this.canvas.getContext("2d"),this.currentLineStyle=i,this.updateLines(r),this.visibility=null!==(o=r.visibility)&&void 0!==o?o:new Xn(this.lines.from.length),r.visibility||this.visibility.setAll(!0,!1),r.arrowSize&&(this.arrowWidth=r.arrowSize),this.canvas.onmousedown=t=>{var e;(null===(e=this.lines)||void 0===e?void 0:e.skipMouseOverDetection)&&(this.mouseOverLineId=this.checkCoordsOnLine(t.offsetX,t.offsetY)),-1!==this.mouseOverLineId&&this.lineClicked.next({x:t.clientX,y:t.clientY,id:this.mouseOverLineId,event:t})},this.canvas.onmousemove=t=>{var e;this.mouseOverLineId=(null===(e=this.lines)||void 0===e?void 0:e.skipMouseOverDetection)?-1:this.checkCoordsOnLine(t.offsetX,t.offsetY),-1!==this.mouseOverLineId&&this.lineHover.next({x:t.clientX,y:t.clientY,id:this.mouseOverLineId,event:t})},t.onEvent("d4-before-draw-scene").subscribe((t=>{this.renderLines()}))}updateLines(t){this.lines=t,this.multipleLinesCounts=new Uint8Array(this.lines.from.length),t.skipMultiLineCalculation?this.multipleLinesCounts.fill(0):this.createMultiLinesIndices()}renderLines(){var t,e,n,r,i,o,s,a,u,c,l,h,d,f,p,m,g;const y=this.sp.getOptions().look,v=this.lines.colors||this.lines.widths||this.lines.opacities||this.lines.drawArrowsArr;v||(this.ctx.lineWidth=null!==(t=this.lines.width)&&void 0!==t?t:1,this.ctx.strokeStyle=`rgba(${null!==(e=this.lines.color)&&void 0!==e?e:"0,128,0"},${null!==(n=this.lines.opacity)&&void 0!==n?n:1})`);const w=y.sizeColumnName?this.sp.dataFrame.col(y.sizeColumnName):null,b=this.sp.dataFrame.filter,E=Math.pow(null!==(r=this.lines.shortLineThreshold)&&void 0!==r?r:5,2);for(let t=0;t<this.lines.from.length;t++)if(b.get(this.lines.from[t])&&b.get(this.lines.to[t])&&this.visibility.getBit(t)){let e=0;const{sizeFrom:n,sizeTo:r}=this.getMarkersSizes(y,w,t),b=this.sp.worldToScreen(this.xAxisCol.get(this.lines.from[t]),this.yAxisCol.get(this.lines.from[t]));let A=null==b?void 0:b.x,_=null==b?void 0:b.y;const C=this.sp.worldToScreen(this.xAxisCol.get(this.lines.to[t]),this.yAxisCol.get(this.lines.to[t]));let S=null==C?void 0:C.x,I=null==C?void 0:C.y;const M=Math.min(this.sp.viewBox.width,this.sp.viewBox.height);if(this.ctx.beginPath(),A&&_&&S&&I&&Math.hypot(S-A,I-_)/M>.01){if(v){const e=(null===(i=this.lines.colors)||void 0===i?void 0:i[t])?null===(o=this.lines.colors)||void 0===o?void 0:o[t]:null!==(s=this.lines.color)&&void 0!==s?s:"0,128,0",n=(null===(a=this.lines.opacities)||void 0===a?void 0:a[t])?null===(u=this.lines.opacities)||void 0===u?void 0:u[t]:null!==(c=this.lines.opacity)&&void 0!==c?c:1;this.ctx.strokeStyle=`rgba(${e},${n})`,this.ctx.lineWidth=(null===(l=this.lines.widths)||void 0===l?void 0:l[t])?null===(h=this.lines.widths)||void 0===h?void 0:h[t]:null!==(d=this.lines.width)&&void 0!==d?d:1}t===this._currentLineIdx&&this.toggleCurrentLineStyle(!0);const y=this.multipleLinesCounts[t];let w=null;if(y){e=this.getLineLength(A,_,S,I);const i=this.getPointOnDistance(A,_,S,I,r,e),o=this.getPointOnDistance(S,I,A,_,n,e);A=i.x,_=i.y,S=o.x,I=o.y,w=this.lines.from[t]>this.lines.to[t]?this.findControlPoint(y,A,_,S,I,t):this.findControlPoint(y,S,I,A,_,t),this.ctx.moveTo(A,_),this.ctx.quadraticCurveTo(w.x,w.y,S,I)}else(!this.lines.skipShortLines||Math.pow(S-A,2)+Math.pow(I-_,2)>E)&&(this.ctx.moveTo(A,_),this.ctx.lineTo(S,I));if((null!==(f=this.lines.drawArrows)&&void 0!==f?f:null===(p=this.lines.drawArrowsArr)||void 0===p?void 0:p.getBit(t))&&(e||(e=this.getLineLength(A,_,S,I)),e>this.arrowWidth)){const t=y?null:this.getPointOnDistance(A,_,S,I,r,e),n=y?w.x:A,i=y?w.y:_;this.canvasArrow(this.ctx,null!==(m=null==t?void 0:t.x)&&void 0!==m?m:A,null!==(g=null==t?void 0:t.y)&&void 0!==g?g:_,n,i)}this.ctx.stroke(),this.ctx.closePath(),t===this._currentLineIdx&&this.toggleCurrentLineStyle(!1)}}this.fillLeftBottomRect()}toggleCurrentLineStyle(t){switch(this.currentLineStyle){case qn.bold:t?this.ctx.lineWidth+=2:this.ctx.lineWidth-=2;break;case qn.dashed:t?this.ctx.setLineDash([5,5]):this.ctx.setLineDash([]);break;default:return}}getMarkersSizes(t,e,n){let r=3,i=3;return e?(r=(t.markerMinSize+(t.markerMaxSize-t.markerMinSize)*e.scale(this.lines.from[n]))/2,i=(t.markerMinSize+(t.markerMaxSize-t.markerMinSize)*e.scale(this.lines.to[n]))/2):t.markerDefaultSize&&(r=t.markerDefaultSize/2,i=t.markerDefaultSize/2),{sizeFrom:r,sizeTo:i}}fillLeftBottomRect(){const t=new Path2D;t.rect(this.sp.yAxisBox.minX,this.sp.yAxisBox.maxY,this.sp.yAxisBox.width,this.sp.xAxisBox.height),this.ctx.fillStyle="white",this.ctx.beginPath(),this.ctx.fill(t),this.ctx.closePath()}createMultiLinesIndices(){const t={};for(let e=0;e<this.lines.from.length;e++){let n=0,r=0;this.lines.from[e]<this.lines.to[e]?(n=this.lines.from[e],r=this.lines.to[e]):(n=this.lines.to[e],r=this.lines.from[e]),t[`${n}|${r}`]?(1===t[`${n}|${r}`].length&&(this.multipleLinesCounts[t[`${n}|${r}`][0]]=1,t[`${n}|${r}`].push(1)),this.multipleLinesCounts[e]=++t[`${n}|${r}`][1]):t[`${n}|${r}`]=[e]}}checkCoordsOnLine(t,e){let n=-1,r=null,i=null;const o=this.sp.getOptions().look,s=o.sizeColumnName?this.sp.dataFrame.col(o.sizeColumnName):null,a=this.sp.dataFrame.filter;for(let u=0;u<this.lines.from.length;u++)if(a.get(this.lines.from[u])&&a.get(this.lines.to[u])&&this.visibility.getBit(u)){const{sizeFrom:a,sizeTo:c}=this.getMarkersSizes(o,s,u),l=this.sp.worldToScreen(this.xAxisCol.get(this.lines.from[u]),this.yAxisCol.get(this.lines.from[u])),h=this.sp.worldToScreen(this.xAxisCol.get(this.lines.to[u]),this.yAxisCol.get(this.lines.to[u]));if(this.multipleLinesCounts[u]){const n=this.getLineLength(l.x,l.y,h.x,h.y),r=this.getPointOnDistance(l.x,l.y,h.x,h.y,c,n),o=this.getPointOnDistance(h.x,h.y,null==l?void 0:l.x,null==l?void 0:l.y,a,n),s=this.lines.from[u]>this.lines.to[u]?this.findControlPoint(this.multipleLinesCounts[u],r.x,r.y,o.x,o.y,u):this.findControlPoint(this.multipleLinesCounts[u],o.x,o.y,r.x,r.y,u);i=this.calculateDistToCurveLine(u,t,e,r,o,s)}else i=this.calculateDistToStraightLine(t,e,l,h);(!r&&null!==i&&i<5||r&&null!==i&&i<r)&&(r=i,n=u)}return n}calculateDistToStraightLine(t,e,n,r){const i=Math.min(n.x,r.x),o=Math.max(n.x,r.x),s=Math.min(n.y,r.y),a=Math.max(n.y,r.y);return t>=i-2&&t<=o+2&&e>=s-2&&e<=a+2?this.distToStraightLineSegment(t,e,n,r):null}distToStraightLineSegment(t,e,n,r){const i=(t,e,n,r)=>Math.pow(t-n,2)+Math.pow(e-r,2),o=i(n.x,n.y,r.x,r.y);if(0==o)return i(t,e,n.x,n.y);let s=((t-n.x)*(r.x-n.x)+(e-n.y)*(r.y-n.y))/o;return s=Math.max(0,Math.min(1,s)),i(t,e,n.x+s*(r.x-n.x),n.y+s*(r.y-n.y))}calculateDistToCurveLine(t,e,n,r,i,o){const s=Math.min(r.x,i.x,o.x),a=Math.max(r.x,i.x,o.x),u=Math.min(r.y,i.y,o.y),c=Math.max(r.y,i.y,o.y);if(e>=s-2&&e<=a+2&&n>=u-2&&n<=c+2){const t=a-s,l=c-u;return this.calculateDistToCurveInRect(e,n,r,o,i,t,l)}return null}calculateDistToCurveInRect(t,e,n,r,i,o,s){const a=Math.floor((o+s)/3),u=1/a,c=new Uint32Array(a),l=new Uint32Array(a),h=new Uint32Array(a);let d=null;const f=new Xn(a);for(let o=0;o<c.length;o++){const s=o*u,a=Math.pow(1-s,2)*n.x+2*s*(1-s)*r.x+Math.pow(s,2)*i.x,f=Math.pow(1-s,2)*n.y+2*s*(1-s)*r.y+Math.pow(s,2)*i.y,p=Math.abs(t-a),m=Math.abs(e-f),g=p+m;(!d||d>g)&&(d=g),h[o]=Math.max(p,m),c[o]=a,l[o]=f}for(let t=0;t<c.length;t++)h[t]<d&&f.setBit(t,!0,!1);let p=null;for(let n=-1;-1!==(n=f.findNext(n));){const r=Math.hypot(c[n]-t,l[n]-e);(!p||p>r)&&(p=r)}return p}getLineLength(t,e,n,r){return Math.sqrt(Math.pow(n-t,2)+Math.pow(r-e,2))}getPointOnDistance(t,e,n,r,o,s){const a=n-o*((n-t)/s),u=r-o*((r-e)/s);return new i.Point(a,u)}findControlPoint(t,e,n,r,o,s){const a=e+(r-e)/2,u=n+(o-n)/2;let c=a-e,l=u-n;const h=Math.sqrt(c*c+l*l);c/=h,l/=h;const d=50*Math.ceil(t/2);return t%2==0?new i.Point(a+d/2*l,u-d/2*c):new i.Point(a-d/2*l,u+d/2*c)}canvasArrow(t,e,n,r,i){const o=Math.atan2(r-e,i-n)+Math.PI;t.moveTo(e-this.arrowWidth*Math.sin(o-Math.PI/10),n-this.arrowWidth*Math.cos(o-Math.PI/10)),t.lineTo(e,n),t.lineTo(e-this.arrowWidth*Math.sin(o+Math.PI/10),n-this.arrowWidth*Math.cos(o+Math.PI/10))}}var Zn=function(t,e,n,r){return new(n||(n=Promise))((function(i,o){function s(t){try{u(r.next(t))}catch(t){o(t)}}function a(t){try{u(r.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}u((r=r.apply(t,e||[])).next())}))};function Jn(t,e){const n=t.length;if(n!==e.length-1)throw new Error("Incorrect parameters count");const r=t.byIndex(0),o=r.length,s=new Float32Array(o);let a=r.getRawData();const u=e[n];let c=e[0];for(let t=0;t<o;++t)s[t]=u+c*a[t];for(let r=1;r<n;++r){a=t.byIndex(r).getRawData(),c=e[r];for(let t=0;t<o;++t)s[t]+=c*a[t]}return i.Column.fromFloat32Array(t.getUnusedName("prediction"),s,o)}const tr=(t,e)=>e<=t?Math.min(10,e):Math.min(10,t);var er;!function(t){t[t.MAX_SAMLPES=1e5]="MAX_SAMLPES",t[t.MAX_FEATURES=1e3]="MAX_FEATURES"}(er||(er={}));class nr{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<=er.MAX_FEATURES&&e.length<=er.MAX_SAMLPES}constructor(t){if(this.specn=null,t)try{const e=new Uint32Array(t.buffer,0,2),n=e[0],r=e[1],o=new Uint8Array(t.buffer,8,n),s=i.DataFrame.fromByteArray(o),a=s.rowCount,u=s.columns,c=u.length,l=new Uint8Array(t.buffer,8+n,r),h=i.DataFrame.fromByteArray(l);if(c<3)throw new Error("incorrect columns count");const d=u.byName(pe.FEATURES).toList(),f=new Float32Array(a);f.set(u.byName(pe.REGR_COEFS).getRawData());const p=c-2,m=new Array(p);for(let t=0;t<p;++t)m[t]=new Float32Array(a),m[t].set(u.byIndex(t+2).getRawData());this.specn={params:f,loadings:m,names:d,dim:a-1,components:c-2,scores:h}}catch(t){throw new Error(`Failed to load model: ${t instanceof Error?t.message:"the platform issue"}`)}}fit(t,e,n){return r=this,o=void 0,a=function*(){const r=yield Re({table:i.DataFrame.fromColumns([e]),features:t,predict:e,components:n,names:void 0}),o=t.names();o.push("_");const s=this.getRegrCoeffs(t,e,r.regressionCoefficients),a=this.getLoadings(n,r.xLoadings);this.specn={names:o,params:s,loadings:a,components:n,dim:t.length,scores:this.getScoresDf(r)},this.computeExplVars(e.length,n,r.yLoadings)},new((s=void 0)||(s=Promise))((function(t,e){function n(t){try{u(a.next(t))}catch(t){e(t)}}function i(t){try{u(a.throw(t))}catch(t){e(t)}}function u(e){var r;e.done?t(e.value):(r=e.value,r instanceof s?r:new s((function(t){t(r)}))).then(n,i)}u((a=a.apply(r,o||[])).next())}));var r,o,s,a}getLoadings(t,e){const n=Array(t),r=e[0].length+1;for(let i=0;i<t;++i)n[i]=new Float32Array(r),n[i].set(e[i].getRawData());return n}getRegrCoeffs(t,e,n){const r=t.length,i=new Float32Array(r+1),o=n.getRawData();let s=0;for(let e=0;e<r;++e)i[e]=o[e],s+=o[e]*t.byIndex(e).stats.avg;return i[r]=e.stats.avg-s,i}computeExplVars(t,e,n){if(null===this.specn)throw new Error("Failed to compute explained variances");const r=n.getRawData(),i=this.specn.loadings[0].length-1;let o=Math.pow(r[0],2)/t;this.specn.loadings[0][i]=o;for(let n=1;n<e;++n)o+=Math.pow(r[n],2)/t,this.specn.loadings[n][i]=o}toBytes(){if(null===this.specn)throw new Error("Failed to pack untrained model");const t=i.DataFrame.fromColumns([i.Column.fromStrings(pe.FEATURES,this.specn.names),i.Column.fromFloat32Array(pe.REGR_COEFS,this.specn.params)]);this.specn.loadings.forEach(((e,n)=>t.columns.add(i.Column.fromFloat32Array(`${pe.XLOADING}${n+1}`,e))));const e=t.toByteArray(),n=e.length,r=this.specn.scores.toByteArray(),o=r.length,s=n+o+8,a=new Uint8Array(64*(Math.ceil(s/64)+1)),u=new Uint32Array(a.buffer,0,2);return u[0]=n,u[1]=o,a.set(e,8),a.set(r,8+n),a}predict(t){if(null===this.specn)throw new Error("Predicting failed: model is not trained");return Jn(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=i.DataFrame.fromColumns([i.Column.fromStrings(pe.FEATURES,this.specn.names.slice(0,-1)),i.Column.fromFloat32Array(pe.REGR_COEFS,this.specn.params,e)]),r=n.columns,o=r.length,s=this.specn.components;return this.specn.loadings.forEach(((t,r)=>n.columns.add(i.Column.fromFloat32Array(`${pe.XLOADING}${r+1}`,t,e)))),t.push(i.Viewer.scatterPlot(n,{title:pe.LOADINGS,xColumnName:r.byIndex(o).name,yColumnName:r.byIndex(o+(s>1?1:0)).name,markerType:i.MARKER_TYPE.CIRCLE,labels:pe.FEATURES,help:ge.LOADINGS})),t.push(i.Viewer.barChart(n,{title:pe.REGR_COEFS,splitColumnName:pe.FEATURES,valueColumnName:pe.REGR_COEFS,valueAggrType:i.AGG.AVG,help:ge.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]=`${ve.COMP} 1`,r[0]=this.specn.loadings[0][e];for(let i=1;i<t;++i)n[i]=`${ve.COMPS} ${i+1}`,r[i]=this.specn.loadings[i][e];return i.Viewer.barChart(i.DataFrame.fromColumns([i.Column.fromStrings(ve.COMPS,n),i.Column.fromFloat32Array(pe.EXPL_VAR,r)]),{title:pe.EXPL_VAR,splitColumnName:ve.COMPS,valueColumnName:pe.EXPL_VAR,valueAggrType:i.AGG.AVG,help:ge.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=`${pe.XSCORE}${e+1}`)),n.forEach(((t,e)=>t.name=`${pe.YSCORE}${e+1}`)),i.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=i.Viewer.scatterPlot(this.specn.scores,{title:pe.SCORES,xColumnName:t[0],yColumnName:t[1],markerType:i.MARKER_TYPE.CIRCLE,help:ge.SCORES,showViewerFormulaLines:!0});return e.meta.formulaLines.addAll(Pe(t)),e}}var rr=function(t,e,n,r){return new(n||(n=Promise))((function(i,o){function s(t){try{u(r.next(t))}catch(t){o(t)}}function a(t){try{u(r.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}u((r=r.apply(t,e||[])).next())}))};const ir="Avg-s",or="Stddev-s";var sr;!function(t){t[t.MAX_SAMLPES=5e4]="MAX_SAMLPES",t[t.MAX_FEATURES=100]="MAX_FEATURES"}(sr||(sr={}));class ar{static isApplicable(t,e){for(const e of t)if(!e.matches("numerical"))return!1;return e.type===i.COLUMN_TYPE.STRING}static isInteractive(t,e){return t.length<=sr.MAX_FEATURES&&e.length<=sr.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=i.DataFrame.fromByteArray(n),o=r.columns,s=o.length;if(s<3)throw new Error("incorrect columns count");this.classesCount=s-2,this.featuresCount=r.rowCount-1;const a=this.classesCount;this.params=new Array(a),this.categories=new Array(r.rowCount);for(let t=0;t<a;++t){const e=o.byIndex(t);if(this.categories[t]=e.name,e.type!==i.COLUMN_TYPE.FLOAT)throw new Error(`Incorrect input column type. Expected: float, passed: ${e.type}`);this.params[t]=e.getRawData()}const u=o.byName(ir);if(u.type!==i.COLUMN_TYPE.FLOAT)throw new Error("incorrect average values column type");this.avgs=u.getRawData();const c=o.byName(or);if(c.type!==i.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]=i.Column.fromFloat32Array(this.categories[n],this.params[n]);e[t]=i.Column.fromFloat32Array(ir,this.avgs),e[t+1]=i.Column.fromFloat32Array(or,this.stdevs);const n=i.DataFrame.fromColumns(e).toByteArray(),r=n.length,o=new Uint8Array(r+4);return new Uint32Array(o.buffer,0,1)[0]=r,o.set(n,4),o}fit(t,e){return rr(this,arguments,void 0,(function*(t,e,n=1,r=100,o=.1,s=.001){if(t.length!==this.featuresCount)throw new Error("Training failes - incorrect features count");if(n<=0||r<1||o<=0||s<=0)throw new Error("Training failes - incorrect fitting hyperparameters");this.extractStats(t);const a=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,i,o,s,a,u,c,l){return g(EDA,"fitSoftmax",[t,e,n,r,i,o,s,a,u,c,l])}(t,i.Column.fromFloat32Array("avgs",this.avgs,this.featuresCount),i.Column.fromFloat32Array("stdevs",this.stdevs,this.featuresCount),i.Column.fromInt32Array("targets",e.getRawData(),a),u,r,n,o,s,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(i){try{this.params=yield this.fitSoftmaxParams(t,e,r,n,o,s)}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!==i.COLUMN_TYPE.INT&&n.type!==i.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 o of t){if(o.type!==i.COLUMN_TYPE.INT&&o.type!==i.COLUMN_TYPE.FLOAT)throw new Error("Training failes - incorrect features type");const t=o.getRawData(),s=this.avgs[r],a=this.stdevs[r];if(a>0)for(let i=0;i<e;++i)n[i][r]=(t[i]-s)/a;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 o=0;for(const n of t){if(n.type!==i.COLUMN_TYPE.INT&&n.type!==i.COLUMN_TYPE.FLOAT)throw new Error("Training failes - incorrect features type");const t=n.getRawData(),s=this.avgs[o],a=this.stdevs[o];if(a>0)for(let n=0;n<e;++n)r[o][n]=(t[n]-s)/a;else for(let t=0;t<e;++t)r[o][t]=0;++o}return r}preprocessedTargets(t){if(t.type!==i.COLUMN_TYPE.STRING)throw new Error("Training failes - incorrect target type");const e=this.classesCount,n=t.length,r=t.getRawData(),o=new Array(n),s=new Uint32Array(e).fill(0);for(let t=0;t<n;++t)o[t]=new Uint8Array(e).fill(0);for(let t=0;t<n;++t)o[t][r[t]]=1,++s[r[t]];return{oneHot:o,weights:s}}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,o=this.classesCount;let s,a;const u=new Float32Array(o);let c,l,h;const d=new Array(n);for(let t=0;t<n;++t){s=e[t],c=0;for(let t=0;t<o;++t){a=this.params[t],c=a[r];for(let t=0;t<r;++t)c+=a[t]*s[t];u[t]=Math.exp(c)}l=u[0],h=0;for(let t=1;t<o;++t)l<u[t]&&(l=u[t],h=t);d[t]=this.categories[h]}return i.Column.fromStrings("predicted",d)}fitSoftmaxParams(t,e,r,i,o,s){return rr(this,void 0,void 0,(function*(){const a=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:a.oneHot,classesWeights:a.weights,targetRaw:e.getRawData(),iterations:r,rate:i,penalty:o,tolerance:s}),l.onmessage=function(t){l.terminate(),u(t.data.params),console.log(`Loss: ${t.data.loss}`)}}))}))}}var ur,cr,lr;!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"}(ur||(ur={})),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"}(cr||(cr={})),function(t){t[t.MODEL=1e7]="MODEL",t[t.UTILS=1]="UTILS",t[t.PACK=128]="PACK",t[t.SIZE=4]="SIZE"}(lr||(lr={}));const hr=i.FLOAT_NULL;var dr;!function(t){t.PREDICT="Prediction",t.TYPE="Type",t.PARAMS="Params count",t.CATS="Categories",t.CATS_SIZE="Categories size"}(dr||(dr={}));class fr{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<=cr.SAMPLES_LOW?n<=cr.FEATURES_LOW:r<=cr.SAMLPES_MID?n<=cr.FEATURES_MID:r<=cr.SAMLPES_HIGH&&n<=cr.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+=lr.SIZE;const o=i.DataFrame.fromByteArray(new Uint8Array(t.buffer,n,r));n+=r,this.targetType=o.get(dr.TYPE,0);const s=o.get(dr.PARAMS,0),a=o.get(dr.CATS_SIZE,0);if(a>0){const r=i.DataFrame.fromByteArray(new Uint8Array(t.buffer,n,a));this.targetCategories=null===(e=r.col(dr.CATS))||void 0===e?void 0:e.toList()}n+=a,n=4*Math.ceil(n/4),this.modelParams=new Int32Array(t.buffer,n,s)}catch(t){throw new Error(`Failed to load model: ${t instanceof Error?t.message:"the platform issue"}`)}}fit(t,e){return r=this,o=arguments,a=function*(t,e,r=ur.ITERATIONS,o=ur.ETA,s=ur.MAX_DEPTH,a=ur.LAMBDA,u=ur.ALPHA){this.targetType=e.type,this.targetType===i.COLUMN_TYPE.STRING&&(this.targetCategories=e.categories),this.modelParams=yield async function(t,e,r,i,o,s,a,u,c,l){return new Promise(((h,d)=>{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:i,eta:o,maxDepth:s,lambda:a,alpha:u,missingValue:r}),v.onmessage=function(t){v.terminate(),h(t.data.params)}}))}(t,e,hr,r,o,s,a,u,lr.MODEL,lr.UTILS)},new((s=void 0)||(s=Promise))((function(t,e){function n(t){try{u(a.next(t))}catch(t){e(t)}}function i(t){try{u(a.throw(t))}catch(t){e(t)}}function u(e){var r;e.done?t(e.value):(r=e.value,r instanceof s?r:new s((function(t){t(r)}))).then(n,i)}u((a=a.apply(r,o||[])).next())}));var r,o,s,a}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,i=t.length,o=n.length;let s=XGBoostModule.HEAPF32;const a=XGBoostModule.HEAP32,u=XGBoostModule._malloc(r*i*4),c=XGBoostModule._malloc(4*r),l=XGBoostModule._malloc(4*o);for(let e=0;e<i;++e){const n=t.byIndex(e).getRawData();for(let t=0;t<r;++t)s[u/4+t+e*r]=n[t]}for(let t=0;t<o;++t)a[l/4+t]=n[t];XGBoostModule._predict(u,r,i,e,l,o,c,r),s=XGBoostModule.HEAPF32;const h=new Float32Array(r);for(let t=0;t<r;++t)h[t]=s[c/4+t];return XGBoostModule._free(u),XGBoostModule._free(c),XGBoostModule._free(l),h}(t,hr,this.modelParams);switch(this.targetType){case i.COLUMN_TYPE.STRING:return this.stringColPrediction(e);case i.COLUMN_TYPE.INT:return this.intColPrediction(e);case i.COLUMN_TYPE.BIG_INT:return this.bigIntColPrediction(e);default:return i.Column.fromFloat32Array(dr.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?i.DataFrame.fromColumns([i.Column.fromList(i.COLUMN_TYPE.STRING,dr.CATS,this.targetCategories)]).toByteArray():void 0,e=void 0!==t?t.length:0,n=this.modelParams.length*this.modelParams.BYTES_PER_ELEMENT,r=i.DataFrame.fromColumns([i.Column.fromStrings(dr.TYPE,[this.targetType]),i.Column.fromInt32Array(dr.PARAMS,new Int32Array([this.modelParams.length])),i.Column.fromInt32Array(dr.CATS_SIZE,new Int32Array([e]))]).toByteArray(),o=r.length,s=64*Math.ceil((lr.SIZE+o+e+n+lr.PACK)/64),a=new Uint8Array(s);let u=0;return new Uint32Array(a.buffer,u,1)[0]=o,u+=lr.SIZE,a.set(r,u),u+=o,e>0&&a.set(t,u),u+=e,u=4*Math.ceil(u/4),a.set(new Uint8Array(this.modelParams.buffer),u),a}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 i=0;i<e;++i)n[i]=this.targetCategories[(o=Math.round(t[i]),Math.max(0,Math.min(o,r)))];var o;return i.Column.fromList(i.COLUMN_TYPE.STRING,dr.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 i.Column.fromInt32Array(dr.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 i.Column.fromBigInt64Array(dr.PREDICT,n)}}var pr=function(t,e,n,r){return new(n||(n=Promise))((function(i,o){function s(t){try{u(r.next(t))}catch(t){o(t)}}function a(t){try{u(r.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}u((r=r.apply(t,e||[])).next())}))};const mr=new i.Package;function gr(){t.shell.info(mr.webRoot)}function yr(){return pr(this,void 0,void 0,(function*(){yield async function(){await initEDA()}(),yield async function(){await initXGBoostModule()}()}))}function vr(t,e,n,r,o){return pr(this,void 0,void 0,(function*(){const s=e.getRawData(),a=n.getRawData(),u=yield ze(s,a,r,o),c=t.columns.getUnusedName("Cluster (DBSCAN)"),l=i.Column.fromInt32Array(c,u);return t.columns.add(l),l}))}function wr(e,r,i,o,s){return pr(this,void 0,void 0,(function*(){const a=yield function(t,e,r,i,o){return $(this,void 0,void 0,(function*(){H(e,r);const t=i?1:0,s=o?1:0;return yield async function(t,e,r,i,o){return new Promise(((t,s)=>{const a=new Worker(new URL(n.p+n.u(91),n.b));a.postMessage(U(EDA.principalComponentAnalysis.arguments,[e,r,i,o])),a.onmessage=function(e){a.terminate(),t(k(EDA.principalComponentAnalysis,e.data))}}))}(0,e,r,t,s)}))}(0,r,i,o,s);if(function(t,e){for(const t of e.toList())t.name="PC"+t.name}(0,a.columns),null===e.id)t.shell.addTableView(a);else{const t=e.columns;for(const e of a.columns)e.name=t.getUnusedName(e.name),t.add(e)}}))}function br(e,n,r,o){return pr(this,void 0,void 0,(function*(){const s=e.dataFrame;if(null===s)return;const a=yield vr(s,e,n,r,o);s.changeColumnType(a,"string");const u=[e.name,n.name],c=t.shell.tableView(s.name);if(c)for(const t of c.viewers)if(t instanceof i.ScatterPlotViewer&&u.includes(t.props.xColumnName)&&u.includes(t.props.yColumnName))return void(t.props.colorColumnName=a.name)}))}function Er(t,e){const n=t.stats.max-t.stats.min;return{entries:t.toList(),options:{range:n}}}function Ar(t,e){return{entries:t.toList(),options:{}}}function _r(){return pr(this,void 0,void 0,(function*(){const r=new Mn,o=e.dialog("Dimensionality reduction").add(r.getEditor()).onOK((()=>pr(this,void 0,void 0,(function*(){const o=r.getParams();0!==o.columns.length&&(yield async function(r,o,s,a,u,c,l,h=!0,d=!1,f={preprocessingFuncArgs:[]},p={},m=null,g={}){const y={showXAxis:!1,showYAxis:!1,showXSelector:!1,showYSelector:!1};if(o.length!==a.length||o.length!==c.length||o.length!==u.length||o.length!==f.preprocessingFuncArgs.length)throw new Error("columns, metrics and preprocessing functions, weights and function argumentsmust have the same length");const v=h?p.tableView??t.shell.tableView(r.name)??t.shell.addTableView(r):null,w=async()=>{const w=i.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,a){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(i.Column.float(E[0],r.rowCount)),c=r.columns.add(i.Column.float(E[1],r.rowCount)),h&&!b&&(b=v.scatterPlot({...y,x:E[0],y:E[1],title:p.scatterPlotName??Pn(o,s)}))),p[an]&&(b?.root&&e.setUpdateIndicator(b.root,!1),u.init((t=>a[0]?a[0][t]:void 0)),c.init((t=>a[1]?a[1][t]:void 0)));const l=t/n*100;w.update(l,`Running ${p.scatterPlotName??"dimensionality reduction"}... ${l.toFixed(0)}%`)}async function _(){r.columns.add(i.Column.float(E[0],r.rowCount)),r.columns.add(i.Column.float(E[1],r.rowCount));let d=null;h&&(b=v.scatterPlot({...y,x:E[0],y:E[1],title:p.scatterPlotName??Pn(o,s)}),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(Tn,{}),m.unsubscribe(),d?.(),w.close())})),g=new Promise((async(e,r)=>{try{d=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,i=e.inputs[1].name,{entries:s,options:u}=await e.apply({[n]:o[t],[i]:a[t],...f.preprocessingFuncArgs[t]??{}});r.push({entries:s,options:u}),f.distanceFnArgs.push(u)}else{const e=o[t].toList(),n={};r.push({entries:e,options:n}),f.distanceFnArgs.push(n)}}e(await async function(e,r,i,o,s,a,u){let c=await async function(e,r,i,o,s,a,u){if(!a.distanceFnArgs)throw new Error("options.distanceFnArgs must be defined");if(e.length!==r.length||e.length!==a.distanceFnArgs.length||e.length!==o.length)throw new Error("data, metrics and options and weights must have the same length");return new Promise((function(c,l){const h=new Worker(new URL(n.p+n.u(234),n.b));h.postMessage({columnsData:e,distanceMetrics:r,method:i,options:a,weights:o,aggregationMethod:s});const d=t.events.onCustomEvent(Tn).subscribe((()=>{try{h?.terminate()}finally{d.unsubscribe()}}));h.onmessage=({data:{error:t,embedding:e,epochNum:n,epochsLength:r}})=>{On(n)||On(r)?(d.unsubscribe(),t?l(t):c(e),setTimeout((()=>h.terminate()),100)):u&&u(n,r,e)}}))}(e,i,r,o,s,a,u);return c=c.map((t=>function(t){const e=t.length;let n=0,r=0;for(let i=0;i<e;++i)n+=t[i],r+=Math.pow(t[i],2);const i=n/e,o=1/Math.sqrt(r/e-Math.pow(i,2));for(let n=0;n<e;++n)t[n]=(t[n]-i)*o;return t}(t))),c}(r.map((t=>t.entries)),s,a,u,l,f,p[sn]?void 0:A))}catch(t){r(t)}})),_=await g;return w.close(),m.unsubscribe(),_}const C=await _();if(d&&C){const S=i.TaskBarProgressIndicator.create("Clustering embeddings ...");try{const I=await ze(C[0],C[1],f.dbScanEpsilon??.01,f.dbScanMinPts??4),M=r.columns.getUnusedName("Cluster (DBSCAN)");r.columns.addNewString(M).init((t=>I[t].toString())),b&&(b.props.colorColumnName=M)}catch(N){t.shell.error("Clustering embeddings failed"),console.error(N)}finally{S.close()}}if(C){const x=r.columns.byName(E[0]),L=r.columns.byName(E[1]);if(x.init((t=>C[0][t])),L.init((t=>C[1][t])),m)try{const T=m.inputs[0].name,O=m.inputs[1].name;await m.prepare({[T]:x,[O]:L,...g}).call(!0)}catch(P){t.shell.error("Post-processing failed"),console.error(P)}if(b)return e.setUpdateIndicator(b.root,!1),b.helpUrl="/help/compute/sequence-space",b}}catch(R){t.shell.error("Dimensionality reduction failed"),console.error(R),w.close(),b&&e.setUpdateIndicator(b.root,!1)}};return new Promise((async(t,n)=>{try{if(p.fastRowCount&&r.rowCount>p.fastRowCount&&!p[sn])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)}}))}(o.table,o.columns,o.methodName,o.distanceMetrics,o.weights,o.preprocessingFunctions,o.aggreaggregationMethod,!!o.plotEmbeddings,!!o.clusterEmbeddings,o.options,{fastRowCount:1e4},o.postProcessingFunction,o.postProcessingFunctionArgs))})))).show();o.helpUrl="https://datagrok.ai/help/explore/dim-reduction.md";const s=()=>{const t=r.columnsInput.value,e=o.getButton("OK");e&&(t&&0!==t.length?e.classList.remove("disabled"):e.classList.add("disabled"))};o.history((()=>({editorSettings:r.getStringInput()})),(t=>r.applyStringInput(t.editorSettings))),r.onColumnsChanged.subscribe((()=>{try{s()}catch(t){console.error(t)}})),s()}))}function Cr(n){try{const t=new Kn;e.dialog("Markov clustering").add(t.getEditor()).onOK((()=>pr(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()}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}`),mr.logger.error(n,void 0,r)}}function Sr(e,n,r,o,s,a,u){return pr(this,arguments,void 0,(function*(e,n,r,o,s,a,u,c=80,l=10,h=!1,d=0,f=5){var p;const m=null!==(p=t.shell.tableView(e.name))&&void 0!==p?p:t.shell.addTableView(e),g=JSON.stringify({cols:n.map((t=>t.name)),metrics:r,weights:o,aggregationMethod:s,preprocessingFuncs:a.map((t=>{var e;return null!==(e=null==t?void 0:t.name)&&void 0!==e?e:null})),preprocessingFuncArgs:u,threshold:c,maxIterations:l,useWebGPU:h,inflate:d,minClusterSize:null!=f?f:5});return e.setTag(rn,g),m.addViewer(i.VIEWER.SCATTER_PLOT,{title:"MCL",initializationFunction:"EDA:MCLInitializationFunction"})}))}function Ir(r){return pr(this,void 0,void 0,(function*(){const o=r.dataFrame;if(null===o)throw new Error("Data frame of the scatter plot is null");const s=o.getTag(rn);if(!s)throw new Error("MCL options tag on the dataFrame is not found");const a=JSON.parse(s),u=a.cols.map((t=>o.columns.byName(t))),c=a.preprocessingFuncs.map((t=>t?i.Func.byName(t):null)),l=yield async function(r,o,s,a,u,c,l,h=80,d=10,f=!1,p=2,m=5,g){const y=t.shell.tableView(r.name)??t.shell.addTableView(r),v=g??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:i,options:a}=await e.apply({[n]:o[t],[r]:s[t],...l[t]??{}});b.push({entries:i,options:a}),w.push(a??{})}else{const e=o[t].toList(),n={};b.push({entries:e,options:n}),w.push(n)}}const E=function(t,e,r,i,o,s,a=10,u=!1,c=2){const l=new Worker(new URL(n.p+n.u(980),n.b));let h;return l.postMessage({data:t,threshold:e,weights:r,aggregationMethod:i,distanceFns:o,distanceFnArgs:s,maxIterations:a,useWebGPU:u,inflate:c}),{promise:new Promise(((t,e)=>{h=t,l.onmessage=e=>{setTimeout((()=>l.terminate()),100),t(e.data.res)},l.onerror=t=>{setTimeout((()=>l.terminate()),100),e(t)}})),terminate:()=>{try{h(null),l.terminate()}catch(t){console.error(t)}}}}(b.map((t=>t.entries)),h,a,u,s,w,d,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())})),_=await E.promise;if(!_)return;const C=r.columns.getUnusedName("Cluster (MCL)"),S=r.columns.getUnusedName("EmbedX (MCL)"),I=r.columns.getUnusedName("EmbedY (MCL)"),M={};_.clusters.forEach((t=>{M[t]||(M[t]=0),M[t]++}));const N=new Uint32Array(_.embedX.length);for(let t=0;t<_.is.length;t++)N[_.is[t]]++,N[_.js[t]]++;const x=r.columns.getUnusedName("Cluster size (MCL)"),L=r.columns.getUnusedName("Connectivity (MCL)"),T=r.columns.addNewFloat(S);T.init((t=>_.embedX[t]));const O=r.columns.addNewFloat(I);O.init((t=>_.embedY[t]));const P=r.columns.addNewString(C);P.init((t=>M[_.clusters[t]]>=m?_.clusters[t].toString():"-1"));const R={"-1":i.Color.setAlpha(i.Color.lightBlue,100)};P.setTag(i.TAGS.COLOR_CODING_CATEGORICAL,JSON.stringify(R)),P.temp[i.TAGS.COLOR_CODING_CATEGORICAL]=R;const F=r.columns.addNewInt(x);F.init((t=>M[_.clusters[t]]));const D=r.columns.addNewInt(L);D.init((t=>N[t])),v.props.xColumnName=S,v.props.yColumnName=I,v.props.colorColumnName=C,v.props.markerDefaultSize=6,A.unsubscribe();const U=[],k=[],G=new Map;for(let t=0;t<_.is.length;t++){let e=_.clusters[_.is[t]],n=_.clusters[_.js[t]];if(e===n){U.push(_.is[t]),k.push(_.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 i=r.get(n);i||(i=0),i>=20||(i++,r.set(n,i),U.push(_.is[t]),k.push(_.js[t]))}return new Qn(v,S,I,{from:new Uint32Array(U),to:new Uint32Array(k),drawArrows:!1,opacity:.3,skipMultiLineCalculation:!0,skipShortLines:!0,skipMouseOverDetection:!0,shortLineThreshold:6,width:.75,color:"128,128,128"},qn.none),e.setUpdateIndicator(v.root,!1),{sc:v,embedXCol:T,embedYCol:O,clusterCol:P,clusterCounterCol:F,connectivityCol:D}}(o,u,a.metrics,a.weights,a.aggregationMethod,c,a.preprocessingFuncArgs,a.threshold,a.maxIterations,a.useWebGPU,a.inflate,a.minClusterSize,r);return null==l?void 0:l.sc}))}function Mr(t,e,n,r,i){return pr(this,void 0,void 0,(function*(){return yield Re({table:t,features:e,predict:n,components:r,names:i})}))}function Nr(){return pr(this,void 0,void 0,(function*(){yield Fe(de.COMPUTE_COMPONENTS)}))}function xr(){return pr(this,void 0,void 0,(function*(){yield Fe(de.PERFORM_MVA)}))}function Lr(){return pr(this,void 0,void 0,(function*(){yield function(){return Le(this,void 0,void 0,(function*(){t.shell.addTableView(i.DataFrame.fromColumns([i.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"]),i.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])),i.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])),i.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])),i.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])),i.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])),i.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])),i.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])),i.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])),i.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])),i.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])),i.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])),i.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])),i.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])),i.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])),i.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])),i.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(Me)),t.shell.windows.showContextPanel=!1,t.shell.windows.showProperties=!1,yield Fe(de.DEMO)}))}()}))}function Tr(t,e,n){return pr(this,void 0,void 0,(function*(){return ae(yield oe({gamma:n,kernel:X},t,e))}))}function Or(t,e){return pr(this,void 0,void 0,(function*(){return yield ce(t,e)}))}function Pr(t,e){return pr(this,void 0,void 0,(function*(){return le(t,e)}))}function Rr(t,e){return pr(this,void 0,void 0,(function*(){return he(t)}))}function Fr(t,e,n,r){return pr(this,void 0,void 0,(function*(){return se(0,r)}))}function Dr(t,e,n,r){return pr(this,void 0,void 0,(function*(){return ae(yield oe({gamma:n,kernel:Z,sigma:r},t,e))}))}function Ur(t,e){return pr(this,void 0,void 0,(function*(){return yield ce(t,e)}))}function kr(t,e){return pr(this,void 0,void 0,(function*(){return le(t,e)}))}function Gr(t,e){return pr(this,void 0,void 0,(function*(){return he(t)}))}function Br(t,e,n,r){return pr(this,void 0,void 0,(function*(){return se(0,r)}))}function Vr(t,e,n,r,i){return pr(this,void 0,void 0,(function*(){return ae(yield oe({gamma:n,kernel:Q,cParam:r,dParam:i},t,e))}))}function Wr(t,e){return pr(this,void 0,void 0,(function*(){return yield ce(t,e)}))}function zr(t,e){return pr(this,void 0,void 0,(function*(){return le(t,e)}))}function jr(t,e){return pr(this,void 0,void 0,(function*(){return he(t)}))}function Yr(t,e,n,r){return pr(this,void 0,void 0,(function*(){return se(0,r)}))}function qr(t,e,n,r,i){return pr(this,void 0,void 0,(function*(){return ae(yield oe({gamma:n,kernel:J,kappa:r,theta:i},t,e))}))}function Hr(t,e){return pr(this,void 0,void 0,(function*(){return yield ce(t,e)}))}function $r(t,e){return pr(this,void 0,void 0,(function*(){return le(t,e)}))}function Kr(t,e){return pr(this,void 0,void 0,(function*(){return he(t)}))}function Xr(t,e,n,r){return pr(this,void 0,void 0,(function*(){return se(0,r)}))}function Qr(e,n,r,o,s){!function(e,n,r,o){const s=t.shell.getTableView(e.name);s.addViewer(i.Viewer.boxPlot(i.DataFrame.fromColumns([n,r]))),s.addViewer(i.Viewer.grid(o))}(e,n,r,function(t,e,n=.05,r=!1){ke(n);const o=new Ve(t,e,r,n);if(r){if(!o.areVarsEqual(n))throw new Error(De.NON_EQUAL_VARIANCES);if(!o.isNormal())throw new Error(De.NON_NORMAL_DISTRIB)}const s=o.getOneWayAnova(),a=Ue.centralF.inv(1-n,s.dfBn,s.dfWn);return function(t,e,n,r,o){return i.DataFrame.fromColumns([i.Column.fromStrings("Source of variance",["Between groups","Within groups","Total","",r,"",o]),i.Column.fromList(i.COLUMN_TYPE.FLOAT,"Sum of squares",[t.ssBn,t.ssWn,t.ssTot,null,null,null,null]),i.Column.fromList(i.COLUMN_TYPE.INT,"Degrees of freedom",[t.dfBn,t.dfWn,t.dfTot,null,null,null,null]),i.Column.fromList(i.COLUMN_TYPE.FLOAT,"Mean square",[t.msBn,t.msWn,null,null,null,null,null]),i.Column.fromList(i.COLUMN_TYPE.FLOAT,"F-statistics",[t.fStat,null,null,null,null,null,null]),i.Column.fromList(i.COLUMN_TYPE.FLOAT,"p-value",[t.pValue,null,null,null,null,null,null]),i.Column.fromList(i.COLUMN_TYPE.FLOAT,`${e}-critical value`,[n,null,null,null,null,null,null])])}(s,n,a,`THE NULL HYPOTHESIS: the "${t.name}" \n factor does not produce a significant difference in the "${e.name}" feature.`,"Test result: "+(s.fStat>a?"REJECTED.":"FAILED TO REJECT."))}(n,r,o,s))}function Zr(){$n()}function Jr(t){return pr(this,void 0,void 0,(function*(){yield $n(t)}))}function ti(t,e){return pr(this,void 0,void 0,(function*(){const n=t.columns,r=yield function(t,e){return Zn(this,void 0,void 0,(function*(){const n=t.length,r=e.length,o=e.stats.avg,s=e.stats.stdev,a=new Float32Array(n+1).fill(0);if(a[n]=o,0===s||1===r)return a;try{const r=[],u=[],c=new Float32Array(n),l=new Float32Array(n);let h=0,d=0;for(const e of t){const t=e.stats;t.stdev>0&&(r.push(h),u.push(e),c[d]=t.avg,l[d]=t.stdev,++d),++h}if(0===d)return a;const f=function(t,e,n,r,i,o,s){return g(EDA,"fitLinearRegressionParamsWithDataNormalizing",[t,e,n,r,i,o,s])}(i.DataFrame.fromColumns(u).columns,i.Column.fromFloat32Array("xAvgs",c,d),i.Column.fromFloat32Array("xStdevs",l,d),e,o,s,d+1).getRawData();for(let t=0;t<d;++t)a[r[t]]=f[t];a[n]=f[d]}catch(r){const o=yield function(t,e,n){return Zn(this,void 0,void 0,(function*(){return(yield Re({table:i.DataFrame.fromColumns([e]),features:t,predict:e,components:n,names:void 0})).regressionCoefficients.getRawData()}))}(t,e,tr(t.length,e.length));let s=0;for(let e=0;e<n;++e)a[e]=o[e],s+=o[e]*t.byIndex(e).stats.avg;a[n]-=s}return a}))}(n,e);return new Uint8Array(r.buffer)}))}function ei(t,e){const n=t.columns,r=new Float32Array(e.buffer);return i.DataFrame.fromColumns([Jn(n,r)])}function ni(t,e){for(const e of t.columns)if(!e.matches("numerical"))return!1;return e.matches("numerical")}function ri(t,e){return t.rowCount<=1e5}function ii(t,e,n,r,i,o){return pr(this,void 0,void 0,(function*(){const s=t.columns,a=new ar({classesCount:e.categories.length,featuresCount:s.length});return yield a.fit(s,e,n,r,i,o),a.toBytes()}))}function oi(t,e){const n=t.columns,r=new ar(void 0,e);return i.DataFrame.fromColumns([r.predict(n)])}function si(t,e){return ar.isApplicable(t.columns,e)}function ai(t,e){return ar.isInteractive(t.columns,e)}function ci(t,e,n){return pr(this,void 0,void 0,(function*(){const r=t.columns,i=new nr;return yield i.fit(r,e,Math.min(n,r.length)),i.toBytes()}))}function li(t,e){const n=new nr(e);return i.DataFrame.fromColumns([n.predict(t.columns)])}function hi(t,e){return nr.isApplicable(t.columns,e)}function di(t,e,n,r){return pr(this,void 0,void 0,(function*(){return new nr(r).viewers().map((t=>t.root))}))}function fi(t,e){return nr.isInteractive(t.columns,e)}function pi(t,e,n,r,i,o,s){return pr(this,void 0,void 0,(function*(){const a=t.columns,u=new fr;return yield u.fit(a,e,n,r,i,o,s),u.toBytes()}))}function mi(t,e){const n=new fr(e);return i.DataFrame.fromColumns([n.predict(t.columns)])}function gi(t,e){return fr.isInteractive(t.columns,e)}function yi(t,e){return fr.isApplicable(t.columns,e)}})(),eda=r})();
2
2
  //# sourceMappingURL=package.js.map