/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/modelscript@2.4.0/build/modelscript.umd.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.modelscript={})}(this,(function(exports){"use strict";var global$1="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},lookup=[],revLookup=[],Arr="undefined"!=typeof Uint8Array?Uint8Array:Array,inited=!1;function init(){inited=!0;for(var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",e=0;e<64;++e)lookup[e]=t[e],revLookup[t.charCodeAt(e)]=e;revLookup["-".charCodeAt(0)]=62,revLookup["_".charCodeAt(0)]=63}function toByteArray(t){var e,r,n,i,o,s;inited||init();var a=t.length;if(a%4>0)throw new Error("Invalid string. Length must be a multiple of 4");o="="===t[a-2]?2:"="===t[a-1]?1:0,s=new Arr(3*a/4-o),n=o>0?a-4:a;var u=0;for(e=0,r=0;e<n;e+=4,r+=3)i=revLookup[t.charCodeAt(e)]<<18|revLookup[t.charCodeAt(e+1)]<<12|revLookup[t.charCodeAt(e+2)]<<6|revLookup[t.charCodeAt(e+3)],s[u++]=i>>16&255,s[u++]=i>>8&255,s[u++]=255&i;return 2===o?(i=revLookup[t.charCodeAt(e)]<<2|revLookup[t.charCodeAt(e+1)]>>4,s[u++]=255&i):1===o&&(i=revLookup[t.charCodeAt(e)]<<10|revLookup[t.charCodeAt(e+1)]<<4|revLookup[t.charCodeAt(e+2)]>>2,s[u++]=i>>8&255,s[u++]=255&i),s}function tripletToBase64(t){return lookup[t>>18&63]+lookup[t>>12&63]+lookup[t>>6&63]+lookup[63&t]}function encodeChunk(t,e,r){for(var n,i=[],o=e;o<r;o+=3)n=(t[o]<<16)+(t[o+1]<<8)+t[o+2],i.push(tripletToBase64(n));return i.join("")}function fromByteArray(t){var e;inited||init();for(var r=t.length,n=r%3,i="",o=[],s=16383,a=0,u=r-n;a<u;a+=s)o.push(encodeChunk(t,a,a+s>u?u:a+s));return 1===n?(e=t[r-1],i+=lookup[e>>2],i+=lookup[e<<4&63],i+="=="):2===n&&(e=(t[r-2]<<8)+t[r-1],i+=lookup[e>>10],i+=lookup[e>>4&63],i+=lookup[e<<2&63],i+="="),o.push(i),o.join("")}function read(t,e,r,n,i){var o,s,a=8*i-n-1,u=(1<<a)-1,h=u>>1,c=-7,l=r?i-1:0,f=r?-1:1,m=t[e+l];for(l+=f,o=m&(1<<-c)-1,m>>=-c,c+=a;c>0;o=256*o+t[e+l],l+=f,c-=8);for(s=o&(1<<-c)-1,o>>=-c,c+=n;c>0;s=256*s+t[e+l],l+=f,c-=8);if(0===o)o=1-h;else{if(o===u)return s?NaN:1/0*(m?-1:1);s+=Math.pow(2,n),o-=h}return(m?-1:1)*s*Math.pow(2,o-n)}function write(t,e,r,n,i,o){var s,a,u,h=8*o-i-1,c=(1<<h)-1,l=c>>1,f=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,m=n?0:o-1,p=n?1:-1,d=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(a=isNaN(e)?1:0,s=c):(s=Math.floor(Math.log(e)/Math.LN2),e*(u=Math.pow(2,-s))<1&&(s--,u*=2),(e+=s+l>=1?f/u:f*Math.pow(2,1-l))*u>=2&&(s++,u/=2),s+l>=c?(a=0,s=c):s+l>=1?(a=(e*u-1)*Math.pow(2,i),s+=l):(a=e*Math.pow(2,l-1)*Math.pow(2,i),s=0));i>=8;t[r+m]=255&a,m+=p,a/=256,i-=8);for(s=s<<i|a,h+=i;h>0;t[r+m]=255&s,m+=p,s/=256,h-=8);t[r+m-p]|=128*d}var toString={}.toString,isArray=Array.isArray||function(t){return"[object Array]"==toString.call(t)},INSPECT_MAX_BYTES=50;function kMaxLength(){return Buffer.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function createBuffer(t,e){if(kMaxLength()<e)throw new RangeError("Invalid typed array length");return Buffer.TYPED_ARRAY_SUPPORT?(t=new Uint8Array(e)).__proto__=Buffer.prototype:(null===t&&(t=new Buffer(e)),t.length=e),t}function Buffer(t,e,r){if(!(Buffer.TYPED_ARRAY_SUPPORT||this instanceof Buffer))return new Buffer(t,e,r);if("number"==typeof t){if("string"==typeof e)throw new Error("If encoding is specified then the first argument must be a string");return allocUnsafe(this,t)}return from(this,t,e,r)}function from(t,e,r,n){if("number"==typeof e)throw new TypeError('"value" argument must not be a number');return"undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer?fromArrayBuffer(t,e,r,n):"string"==typeof e?fromString(t,e,r):fromObject(t,e)}function assertSize(t){if("number"!=typeof t)throw new TypeError('"size" argument must be a number');if(t<0)throw new RangeError('"size" argument must not be negative')}function alloc(t,e,r,n){return assertSize(e),e<=0?createBuffer(t,e):void 0!==r?"string"==typeof n?createBuffer(t,e).fill(r,n):createBuffer(t,e).fill(r):createBuffer(t,e)}function allocUnsafe(t,e){if(assertSize(e),t=createBuffer(t,e<0?0:0|checked(e)),!Buffer.TYPED_ARRAY_SUPPORT)for(var r=0;r<e;++r)t[r]=0;return t}function fromString(t,e,r){if("string"==typeof r&&""!==r||(r="utf8"),!Buffer.isEncoding(r))throw new TypeError('"encoding" must be a valid string encoding');var n=0|byteLength(e,r),i=(t=createBuffer(t,n)).write(e,r);return i!==n&&(t=t.slice(0,i)),t}function fromArrayLike(t,e){var r=e.length<0?0:0|checked(e.length);t=createBuffer(t,r);for(var n=0;n<r;n+=1)t[n]=255&e[n];return t}function fromArrayBuffer(t,e,r,n){if(e.byteLength,r<0||e.byteLength<r)throw new RangeError("'offset' is out of bounds");if(e.byteLength<r+(n||0))throw new RangeError("'length' is out of bounds");return e=void 0===r&&void 0===n?new Uint8Array(e):void 0===n?new Uint8Array(e,r):new Uint8Array(e,r,n),Buffer.TYPED_ARRAY_SUPPORT?(t=e).__proto__=Buffer.prototype:t=fromArrayLike(t,e),t}function fromObject(t,e){if(internalIsBuffer(e)){var r=0|checked(e.length);return 0===(t=createBuffer(t,r)).length||e.copy(t,0,0,r),t}if(e){if("undefined"!=typeof ArrayBuffer&&e.buffer instanceof ArrayBuffer||"length"in e)return"number"!=typeof e.length||isnan(e.length)?createBuffer(t,0):fromArrayLike(t,e);if("Buffer"===e.type&&isArray(e.data))return fromArrayLike(t,e.data)}throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}function checked(t){if(t>=kMaxLength())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+kMaxLength().toString(16)+" bytes");return 0|t}function internalIsBuffer(t){return!(null==t||!t._isBuffer)}function byteLength(t,e){if(internalIsBuffer(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var r=t.length;if(0===r)return 0;for(var n=!1;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":case void 0:return utf8ToBytes(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return base64ToBytes(t).length;default:if(n)return utf8ToBytes(t).length;e=(""+e).toLowerCase(),n=!0}}function slowToString(t,e,r){var n=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return hexSlice(this,e,r);case"utf8":case"utf-8":return utf8Slice(this,e,r);case"ascii":return asciiSlice(this,e,r);case"latin1":case"binary":return latin1Slice(this,e,r);case"base64":return base64Slice(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return utf16leSlice(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function swap(t,e,r){var n=t[e];t[e]=t[r],t[r]=n}function bidirectionalIndexOf(t,e,r,n,i){if(0===t.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,isNaN(r)&&(r=i?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(i)return-1;r=t.length-1}else if(r<0){if(!i)return-1;r=0}if("string"==typeof e&&(e=Buffer.from(e,n)),internalIsBuffer(e))return 0===e.length?-1:arrayIndexOf(t,e,r,n,i);if("number"==typeof e)return e&=255,Buffer.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):arrayIndexOf(t,[e],r,n,i);throw new TypeError("val must be string, number or Buffer")}function arrayIndexOf(t,e,r,n,i){var o,s=1,a=t.length,u=e.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return-1;s=2,a/=2,u/=2,r/=2}function h(t,e){return 1===s?t[e]:t.readUInt16BE(e*s)}if(i){var c=-1;for(o=r;o<a;o++)if(h(t,o)===h(e,-1===c?0:o-c)){if(-1===c&&(c=o),o-c+1===u)return c*s}else-1!==c&&(o-=o-c),c=-1}else for(r+u>a&&(r=a-u),o=r;o>=0;o--){for(var l=!0,f=0;f<u;f++)if(h(t,o+f)!==h(e,f)){l=!1;break}if(l)return o}return-1}function hexWrite(t,e,r,n){r=Number(r)||0;var i=t.length-r;n?(n=Number(n))>i&&(n=i):n=i;var o=e.length;if(o%2!=0)throw new TypeError("Invalid hex string");n>o/2&&(n=o/2);for(var s=0;s<n;++s){var a=parseInt(e.substr(2*s,2),16);if(isNaN(a))return s;t[r+s]=a}return s}function utf8Write(t,e,r,n){return blitBuffer(utf8ToBytes(e,t.length-r),t,r,n)}function asciiWrite(t,e,r,n){return blitBuffer(asciiToBytes(e),t,r,n)}function latin1Write(t,e,r,n){return asciiWrite(t,e,r,n)}function base64Write(t,e,r,n){return blitBuffer(base64ToBytes(e),t,r,n)}function ucs2Write(t,e,r,n){return blitBuffer(utf16leToBytes(e,t.length-r),t,r,n)}function base64Slice(t,e,r){return 0===e&&r===t.length?fromByteArray(t):fromByteArray(t.slice(e,r))}function utf8Slice(t,e,r){r=Math.min(t.length,r);for(var n=[],i=e;i<r;){var o,s,a,u,h=t[i],c=null,l=h>239?4:h>223?3:h>191?2:1;if(i+l<=r)switch(l){case 1:h<128&&(c=h);break;case 2:128==(192&(o=t[i+1]))&&(u=(31&h)<<6|63&o)>127&&(c=u);break;case 3:o=t[i+1],s=t[i+2],128==(192&o)&&128==(192&s)&&(u=(15&h)<<12|(63&o)<<6|63&s)>2047&&(u<55296||u>57343)&&(c=u);break;case 4:o=t[i+1],s=t[i+2],a=t[i+3],128==(192&o)&&128==(192&s)&&128==(192&a)&&(u=(15&h)<<18|(63&o)<<12|(63&s)<<6|63&a)>65535&&u<1114112&&(c=u)}null===c?(c=65533,l=1):c>65535&&(c-=65536,n.push(c>>>10&1023|55296),c=56320|1023&c),n.push(c),i+=l}return decodeCodePointsArray(n)}Buffer.TYPED_ARRAY_SUPPORT=void 0===global$1.TYPED_ARRAY_SUPPORT||global$1.TYPED_ARRAY_SUPPORT,Buffer.poolSize=8192,Buffer._augment=function(t){return t.__proto__=Buffer.prototype,t},Buffer.from=function(t,e,r){return from(null,t,e,r)},Buffer.TYPED_ARRAY_SUPPORT&&(Buffer.prototype.__proto__=Uint8Array.prototype,Buffer.__proto__=Uint8Array),Buffer.alloc=function(t,e,r){return alloc(null,t,e,r)},Buffer.allocUnsafe=function(t){return allocUnsafe(null,t)},Buffer.allocUnsafeSlow=function(t){return allocUnsafe(null,t)},Buffer.isBuffer=isBuffer,Buffer.compare=function(t,e){if(!internalIsBuffer(t)||!internalIsBuffer(e))throw new TypeError("Arguments must be Buffers");if(t===e)return 0;for(var r=t.length,n=e.length,i=0,o=Math.min(r,n);i<o;++i)if(t[i]!==e[i]){r=t[i],n=e[i];break}return r<n?-1:n<r?1:0},Buffer.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},Buffer.concat=function(t,e){if(!isArray(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return Buffer.alloc(0);var r;if(void 0===e)for(e=0,r=0;r<t.length;++r)e+=t[r].length;var n=Buffer.allocUnsafe(e),i=0;for(r=0;r<t.length;++r){var o=t[r];if(!internalIsBuffer(o))throw new TypeError('"list" argument must be an Array of Buffers');o.copy(n,i),i+=o.length}return n},Buffer.byteLength=byteLength,Buffer.prototype._isBuffer=!0,Buffer.prototype.swap16=function(){var t=this.length;if(t%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var e=0;e<t;e+=2)swap(this,e,e+1);return this},Buffer.prototype.swap32=function(){var t=this.length;if(t%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var e=0;e<t;e+=4)swap(this,e,e+3),swap(this,e+1,e+2);return this},Buffer.prototype.swap64=function(){var t=this.length;if(t%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var e=0;e<t;e+=8)swap(this,e,e+7),swap(this,e+1,e+6),swap(this,e+2,e+5),swap(this,e+3,e+4);return this},Buffer.prototype.toString=function(){var t=0|this.length;return 0===t?"":0===arguments.length?utf8Slice(this,0,t):slowToString.apply(this,arguments)},Buffer.prototype.equals=function(t){if(!internalIsBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t||0===Buffer.compare(this,t)},Buffer.prototype.inspect=function(){var t="",e=INSPECT_MAX_BYTES;return this.length>0&&(t=this.toString("hex",0,e).match(/.{2}/g).join(" "),this.length>e&&(t+=" ... ")),"<Buffer "+t+">"},Buffer.prototype.compare=function(t,e,r,n,i){if(!internalIsBuffer(t))throw new TypeError("Argument must be a Buffer");if(void 0===e&&(e=0),void 0===r&&(r=t?t.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),e<0||r>t.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&e>=r)return 0;if(n>=i)return-1;if(e>=r)return 1;if(this===t)return 0;for(var o=(i>>>=0)-(n>>>=0),s=(r>>>=0)-(e>>>=0),a=Math.min(o,s),u=this.slice(n,i),h=t.slice(e,r),c=0;c<a;++c)if(u[c]!==h[c]){o=u[c],s=h[c];break}return o<s?-1:s<o?1:0},Buffer.prototype.includes=function(t,e,r){return-1!==this.indexOf(t,e,r)},Buffer.prototype.indexOf=function(t,e,r){return bidirectionalIndexOf(this,t,e,r,!0)},Buffer.prototype.lastIndexOf=function(t,e,r){return bidirectionalIndexOf(this,t,e,r,!1)},Buffer.prototype.write=function(t,e,r,n){if(void 0===e)n="utf8",r=this.length,e=0;else if(void 0===r&&"string"==typeof e)n=e,r=this.length,e=0;else{if(!isFinite(e))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");e|=0,isFinite(r)?(r|=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}var i=this.length-e;if((void 0===r||r>i)&&(r=i),t.length>0&&(r<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var o=!1;;)switch(n){case"hex":return hexWrite(this,t,e,r);case"utf8":case"utf-8":return utf8Write(this,t,e,r);case"ascii":return asciiWrite(this,t,e,r);case"latin1":case"binary":return latin1Write(this,t,e,r);case"base64":return base64Write(this,t,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return ucs2Write(this,t,e,r);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),o=!0}},Buffer.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var MAX_ARGUMENTS_LENGTH=4096;function decodeCodePointsArray(t){var e=t.length;if(e<=MAX_ARGUMENTS_LENGTH)return String.fromCharCode.apply(String,t);for(var r="",n=0;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=MAX_ARGUMENTS_LENGTH));return r}function asciiSlice(t,e,r){var n="";r=Math.min(t.length,r);for(var i=e;i<r;++i)n+=String.fromCharCode(127&t[i]);return n}function latin1Slice(t,e,r){var n="";r=Math.min(t.length,r);for(var i=e;i<r;++i)n+=String.fromCharCode(t[i]);return n}function hexSlice(t,e,r){var n=t.length;(!e||e<0)&&(e=0),(!r||r<0||r>n)&&(r=n);for(var i="",o=e;o<r;++o)i+=toHex(t[o]);return i}function utf16leSlice(t,e,r){for(var n=t.slice(e,r),i="",o=0;o<n.length;o+=2)i+=String.fromCharCode(n[o]+256*n[o+1]);return i}function checkOffset(t,e,r){if(t%1!=0||t<0)throw new RangeError("offset is not uint");if(t+e>r)throw new RangeError("Trying to access beyond buffer length")}function checkInt(t,e,r,n,i,o){if(!internalIsBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||e<o)throw new RangeError('"value" argument is out of bounds');if(r+n>t.length)throw new RangeError("Index out of range")}function objectWriteUInt16(t,e,r,n){e<0&&(e=65535+e+1);for(var i=0,o=Math.min(t.length-r,2);i<o;++i)t[r+i]=(e&255<<8*(n?i:1-i))>>>8*(n?i:1-i)}function objectWriteUInt32(t,e,r,n){e<0&&(e=4294967295+e+1);for(var i=0,o=Math.min(t.length-r,4);i<o;++i)t[r+i]=e>>>8*(n?i:3-i)&255}function checkIEEE754(t,e,r,n,i,o){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function writeFloat(t,e,r,n,i){return i||checkIEEE754(t,e,r,4,34028234663852886e22,-34028234663852886e22),write(t,e,r,n,23,4),r+4}function writeDouble(t,e,r,n,i){return i||checkIEEE754(t,e,r,8,17976931348623157e292,-17976931348623157e292),write(t,e,r,n,52,8),r+8}Buffer.prototype.slice=function(t,e){var r,n=this.length;if((t=~~t)<0?(t+=n)<0&&(t=0):t>n&&(t=n),(e=void 0===e?n:~~e)<0?(e+=n)<0&&(e=0):e>n&&(e=n),e<t&&(e=t),Buffer.TYPED_ARRAY_SUPPORT)(r=this.subarray(t,e)).__proto__=Buffer.prototype;else{var i=e-t;r=new Buffer(i,void 0);for(var o=0;o<i;++o)r[o]=this[o+t]}return r},Buffer.prototype.readUIntLE=function(t,e,r){t|=0,e|=0,r||checkOffset(t,e,this.length);for(var n=this[t],i=1,o=0;++o<e&&(i*=256);)n+=this[t+o]*i;return n},Buffer.prototype.readUIntBE=function(t,e,r){t|=0,e|=0,r||checkOffset(t,e,this.length);for(var n=this[t+--e],i=1;e>0&&(i*=256);)n+=this[t+--e]*i;return n},Buffer.prototype.readUInt8=function(t,e){return e||checkOffset(t,1,this.length),this[t]},Buffer.prototype.readUInt16LE=function(t,e){return e||checkOffset(t,2,this.length),this[t]|this[t+1]<<8},Buffer.prototype.readUInt16BE=function(t,e){return e||checkOffset(t,2,this.length),this[t]<<8|this[t+1]},Buffer.prototype.readUInt32LE=function(t,e){return e||checkOffset(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},Buffer.prototype.readUInt32BE=function(t,e){return e||checkOffset(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},Buffer.prototype.readIntLE=function(t,e,r){t|=0,e|=0,r||checkOffset(t,e,this.length);for(var n=this[t],i=1,o=0;++o<e&&(i*=256);)n+=this[t+o]*i;return n>=(i*=128)&&(n-=Math.pow(2,8*e)),n},Buffer.prototype.readIntBE=function(t,e,r){t|=0,e|=0,r||checkOffset(t,e,this.length);for(var n=e,i=1,o=this[t+--n];n>0&&(i*=256);)o+=this[t+--n]*i;return o>=(i*=128)&&(o-=Math.pow(2,8*e)),o},Buffer.prototype.readInt8=function(t,e){return e||checkOffset(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},Buffer.prototype.readInt16LE=function(t,e){e||checkOffset(t,2,this.length);var r=this[t]|this[t+1]<<8;return 32768&r?4294901760|r:r},Buffer.prototype.readInt16BE=function(t,e){e||checkOffset(t,2,this.length);var r=this[t+1]|this[t]<<8;return 32768&r?4294901760|r:r},Buffer.prototype.readInt32LE=function(t,e){return e||checkOffset(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},Buffer.prototype.readInt32BE=function(t,e){return e||checkOffset(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},Buffer.prototype.readFloatLE=function(t,e){return e||checkOffset(t,4,this.length),read(this,t,!0,23,4)},Buffer.prototype.readFloatBE=function(t,e){return e||checkOffset(t,4,this.length),read(this,t,!1,23,4)},Buffer.prototype.readDoubleLE=function(t,e){return e||checkOffset(t,8,this.length),read(this,t,!0,52,8)},Buffer.prototype.readDoubleBE=function(t,e){return e||checkOffset(t,8,this.length),read(this,t,!1,52,8)},Buffer.prototype.writeUIntLE=function(t,e,r,n){(t=+t,e|=0,r|=0,n)||checkInt(this,t,e,r,Math.pow(2,8*r)-1,0);var i=1,o=0;for(this[e]=255&t;++o<r&&(i*=256);)this[e+o]=t/i&255;return e+r},Buffer.prototype.writeUIntBE=function(t,e,r,n){(t=+t,e|=0,r|=0,n)||checkInt(this,t,e,r,Math.pow(2,8*r)-1,0);var i=r-1,o=1;for(this[e+i]=255&t;--i>=0&&(o*=256);)this[e+i]=t/o&255;return e+r},Buffer.prototype.writeUInt8=function(t,e,r){return t=+t,e|=0,r||checkInt(this,t,e,1,255,0),Buffer.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},Buffer.prototype.writeUInt16LE=function(t,e,r){return t=+t,e|=0,r||checkInt(this,t,e,2,65535,0),Buffer.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):objectWriteUInt16(this,t,e,!0),e+2},Buffer.prototype.writeUInt16BE=function(t,e,r){return t=+t,e|=0,r||checkInt(this,t,e,2,65535,0),Buffer.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):objectWriteUInt16(this,t,e,!1),e+2},Buffer.prototype.writeUInt32LE=function(t,e,r){return t=+t,e|=0,r||checkInt(this,t,e,4,4294967295,0),Buffer.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):objectWriteUInt32(this,t,e,!0),e+4},Buffer.prototype.writeUInt32BE=function(t,e,r){return t=+t,e|=0,r||checkInt(this,t,e,4,4294967295,0),Buffer.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):objectWriteUInt32(this,t,e,!1),e+4},Buffer.prototype.writeIntLE=function(t,e,r,n){if(t=+t,e|=0,!n){var i=Math.pow(2,8*r-1);checkInt(this,t,e,r,i-1,-i)}var o=0,s=1,a=0;for(this[e]=255&t;++o<r&&(s*=256);)t<0&&0===a&&0!==this[e+o-1]&&(a=1),this[e+o]=(t/s|0)-a&255;return e+r},Buffer.prototype.writeIntBE=function(t,e,r,n){if(t=+t,e|=0,!n){var i=Math.pow(2,8*r-1);checkInt(this,t,e,r,i-1,-i)}var o=r-1,s=1,a=0;for(this[e+o]=255&t;--o>=0&&(s*=256);)t<0&&0===a&&0!==this[e+o+1]&&(a=1),this[e+o]=(t/s|0)-a&255;return e+r},Buffer.prototype.writeInt8=function(t,e,r){return t=+t,e|=0,r||checkInt(this,t,e,1,127,-128),Buffer.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[e]=255&t,e+1},Buffer.prototype.writeInt16LE=function(t,e,r){return t=+t,e|=0,r||checkInt(this,t,e,2,32767,-32768),Buffer.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):objectWriteUInt16(this,t,e,!0),e+2},Buffer.prototype.writeInt16BE=function(t,e,r){return t=+t,e|=0,r||checkInt(this,t,e,2,32767,-32768),Buffer.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):objectWriteUInt16(this,t,e,!1),e+2},Buffer.prototype.writeInt32LE=function(t,e,r){return t=+t,e|=0,r||checkInt(this,t,e,4,2147483647,-2147483648),Buffer.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):objectWriteUInt32(this,t,e,!0),e+4},Buffer.prototype.writeInt32BE=function(t,e,r){return t=+t,e|=0,r||checkInt(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),Buffer.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):objectWriteUInt32(this,t,e,!1),e+4},Buffer.prototype.writeFloatLE=function(t,e,r){return writeFloat(this,t,e,!0,r)},Buffer.prototype.writeFloatBE=function(t,e,r){return writeFloat(this,t,e,!1,r)},Buffer.prototype.writeDoubleLE=function(t,e,r){return writeDouble(this,t,e,!0,r)},Buffer.prototype.writeDoubleBE=function(t,e,r){return writeDouble(this,t,e,!1,r)},Buffer.prototype.copy=function(t,e,r,n){if(r||(r=0),n||0===n||(n=this.length),e>=t.length&&(e=t.length),e||(e=0),n>0&&n<r&&(n=r),n===r)return 0;if(0===t.length||0===this.length)return 0;if(e<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e<n-r&&(n=t.length-e+r);var i,o=n-r;if(this===t&&r<e&&e<n)for(i=o-1;i>=0;--i)t[i+e]=this[i+r];else if(o<1e3||!Buffer.TYPED_ARRAY_SUPPORT)for(i=0;i<o;++i)t[i+e]=this[i+r];else Uint8Array.prototype.set.call(t,this.subarray(r,r+o),e);return o},Buffer.prototype.fill=function(t,e,r,n){if("string"==typeof t){if("string"==typeof e?(n=e,e=0,r=this.length):"string"==typeof r&&(n=r,r=this.length),1===t.length){var i=t.charCodeAt(0);i<256&&(t=i)}if(void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!Buffer.isEncoding(n))throw new TypeError("Unknown encoding: "+n)}else"number"==typeof t&&(t&=255);if(e<0||this.length<e||this.length<r)throw new RangeError("Out of range index");if(r<=e)return this;var o;if(e>>>=0,r=void 0===r?this.length:r>>>0,t||(t=0),"number"==typeof t)for(o=e;o<r;++o)this[o]=t;else{var s=internalIsBuffer(t)?t:utf8ToBytes(new Buffer(t,n).toString()),a=s.length;for(o=0;o<r-e;++o)this[o+e]=s[o%a]}return this};var INVALID_BASE64_RE=/[^+\/0-9A-Za-z-_]/g;function base64clean(t){if((t=stringtrim(t).replace(INVALID_BASE64_RE,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}function stringtrim(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}function toHex(t){return t<16?"0"+t.toString(16):t.toString(16)}function utf8ToBytes(t,e){var r;e=e||1/0;for(var n=t.length,i=null,o=[],s=0;s<n;++s){if((r=t.charCodeAt(s))>55295&&r<57344){if(!i){if(r>56319){(e-=3)>-1&&o.push(239,191,189);continue}if(s+1===n){(e-=3)>-1&&o.push(239,191,189);continue}i=r;continue}if(r<56320){(e-=3)>-1&&o.push(239,191,189),i=r;continue}r=65536+(i-55296<<10|r-56320)}else i&&(e-=3)>-1&&o.push(239,191,189);if(i=null,r<128){if((e-=1)<0)break;o.push(r)}else if(r<2048){if((e-=2)<0)break;o.push(r>>6|192,63&r|128)}else if(r<65536){if((e-=3)<0)break;o.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;o.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return o}function asciiToBytes(t){for(var e=[],r=0;r<t.length;++r)e.push(255&t.charCodeAt(r));return e}function utf16leToBytes(t,e){for(var r,n,i,o=[],s=0;s<t.length&&!((e-=2)<0);++s)n=(r=t.charCodeAt(s))>>8,i=r%256,o.push(i),o.push(n);return o}function base64ToBytes(t){return toByteArray(base64clean(t))}function blitBuffer(t,e,r,n){for(var i=0;i<n&&!(i+r>=e.length||i>=t.length);++i)e[i+r]=t[i];return i}function isnan(t){return t!=t}function isBuffer(t){return null!=t&&(!!t._isBuffer||isFastBuffer(t)||isSlowBuffer(t))}function isFastBuffer(t){return!!t.constructor&&"function"==typeof t.constructor.isBuffer&&t.constructor.isBuffer(t)}function isSlowBuffer(t){return"function"==typeof t.readFloatLE&&"function"==typeof t.slice&&isFastBuffer(t.slice(0,0))}function defaultSetTimout(){throw new Error("setTimeout has not been defined")}function defaultClearTimeout(){throw new Error("clearTimeout has not been defined")}var cachedSetTimeout=defaultSetTimout,cachedClearTimeout=defaultClearTimeout;function runTimeout(t){if(cachedSetTimeout===setTimeout)return setTimeout(t,0);if((cachedSetTimeout===defaultSetTimout||!cachedSetTimeout)&&setTimeout)return cachedSetTimeout=setTimeout,setTimeout(t,0);try{return cachedSetTimeout(t,0)}catch(e){try{return cachedSetTimeout.call(null,t,0)}catch(e){return cachedSetTimeout.call(this,t,0)}}}function runClearTimeout(t){if(cachedClearTimeout===clearTimeout)return clearTimeout(t);if((cachedClearTimeout===defaultClearTimeout||!cachedClearTimeout)&&clearTimeout)return cachedClearTimeout=clearTimeout,clearTimeout(t);try{return cachedClearTimeout(t)}catch(e){try{return cachedClearTimeout.call(null,t)}catch(e){return cachedClearTimeout.call(this,t)}}}"function"==typeof global$1.setTimeout&&(cachedSetTimeout=setTimeout),"function"==typeof global$1.clearTimeout&&(cachedClearTimeout=clearTimeout);var queue=[],draining=!1,currentQueue,queueIndex=-1;function cleanUpNextTick(){draining&&currentQueue&&(draining=!1,currentQueue.length?queue=currentQueue.concat(queue):queueIndex=-1,queue.length&&drainQueue())}function drainQueue(){if(!draining){var t=runTimeout(cleanUpNextTick);draining=!0;for(var e=queue.length;e;){for(currentQueue=queue,queue=[];++queueIndex<e;)currentQueue&&currentQueue[queueIndex].run();queueIndex=-1,e=queue.length}currentQueue=null,draining=!1,runClearTimeout(t)}}function nextTick(t){var e=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)e[r-1]=arguments[r];queue.push(new Item(t,e)),1!==queue.length||draining||runTimeout(drainQueue)}function Item(t,e){this.fun=t,this.array=e}Item.prototype.run=function(){this.fun.apply(null,this.array)};var title="browser",platform="browser",browser=!0,env={},argv=[],version="",versions={},release={},config={};function noop(){}var on=noop,addListener=noop,once=noop,off=noop,removeListener=noop,removeAllListeners=noop,emit=noop;function binding(t){throw new Error("process.binding is not supported")}function cwd(){return"/"}function chdir(t){throw new Error("process.chdir is not supported")}function umask(){return 0}var performance=global$1.performance||{},performanceNow=performance.now||performance.mozNow||performance.msNow||performance.oNow||performance.webkitNow||function(){return(new Date).getTime()};function hrtime(t){var e=.001*performanceNow.call(performance),r=Math.floor(e),n=Math.floor(e%1*1e9);return t&&(r-=t[0],(n-=t[1])<0&&(r--,n+=1e9)),[r,n]}var startTime=new Date;function uptime(){return(new Date-startTime)/1e3}var process={nextTick:nextTick,title:title,browser:browser,env:env,argv:argv,version:version,versions:versions,on:on,addListener:addListener,once:once,off:off,removeListener:removeListener,removeAllListeners:removeAllListeners,emit:emit,binding:binding,cwd:cwd,chdir:chdir,umask:umask,hrtime:hrtime,platform:platform,release:release,config:config,uptime:uptime},hasFetch=isFunction(global$1.fetch)&&isFunction(global$1.ReadableStream),_blobConstructor,xhr;function blobConstructor(){if(void 0!==_blobConstructor)return _blobConstructor;try{new global$1.Blob([new ArrayBuffer(1)]),_blobConstructor=!0}catch(t){_blobConstructor=!1}return _blobConstructor}function checkTypeSupport(t){xhr||(xhr=new global$1.XMLHttpRequest).open("GET",global$1.location.host?"/":"https://example.com");try{return xhr.responseType=t,xhr.responseType===t}catch(t){return!1}}var haveArrayBuffer=void 0!==global$1.ArrayBuffer,haveSlice=haveArrayBuffer&&isFunction(global$1.ArrayBuffer.prototype.slice),arraybuffer=haveArrayBuffer&&checkTypeSupport("arraybuffer"),msstream=!hasFetch&&haveSlice&&checkTypeSupport("ms-stream"),mozchunkedarraybuffer=!hasFetch&&haveArrayBuffer&&checkTypeSupport("moz-chunked-arraybuffer"),overrideMimeType=isFunction(xhr.overrideMimeType),vbArray=isFunction(global$1.VBArray),inherits;function isFunction(t){return"function"==typeof t}xhr=null,inherits="function"==typeof Object.create?function(t,e){t.super_=e,t.prototype=Object.create(e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}})}:function(t,e){t.super_=e;var r=function(){};r.prototype=e.prototype,t.prototype=new r,t.prototype.constructor=t};var inherits$1=inherits,formatRegExp=/%[sdj%]/g;function format(t){if(!isString(t)){for(var e=[],r=0;r<arguments.length;r++)e.push(inspect(arguments[r]));return e.join(" ")}r=1;for(var n=arguments,i=n.length,o=String(t).replace(formatRegExp,(function(t){if("%%"===t)return"%";if(r>=i)return t;switch(t){case"%s":return String(n[r++]);case"%d":return Number(n[r++]);case"%j":try{return JSON.stringify(n[r++])}catch(t){return"[Circular]"}default:return t}})),s=n[r];r<i;s=n[++r])isNull(s)||!isObject(s)?o+=" "+s:o+=" "+inspect(s);return o}function deprecate(t,e){if(isUndefined(global$1.process))return function(){return deprecate(t,e).apply(this,arguments)};var r=!1;return function(){return r||(console.error(e),r=!0),t.apply(this,arguments)}}var debugs={},debugEnviron;function debuglog(t){if(isUndefined(debugEnviron)&&(debugEnviron=""),t=t.toUpperCase(),!debugs[t])if(new RegExp("\\b"+t+"\\b","i").test(debugEnviron)){debugs[t]=function(){var e=format.apply(null,arguments);console.error("%s %d: %s",t,0,e)}}else debugs[t]=function(){};return debugs[t]}function inspect(t,e){var r={seen:[],stylize:stylizeNoColor};return arguments.length>=3&&(r.depth=arguments[2]),arguments.length>=4&&(r.colors=arguments[3]),isBoolean(e)?r.showHidden=e:e&&_extend(r,e),isUndefined(r.showHidden)&&(r.showHidden=!1),isUndefined(r.depth)&&(r.depth=2),isUndefined(r.colors)&&(r.colors=!1),isUndefined(r.customInspect)&&(r.customInspect=!0),r.colors&&(r.stylize=stylizeWithColor),formatValue(r,t,r.depth)}function stylizeWithColor(t,e){var r=inspect.styles[e];return r?"["+inspect.colors[r][0]+"m"+t+"["+inspect.colors[r][1]+"m":t}function stylizeNoColor(t,e){return t}function arrayToHash(t){var e={};return t.forEach((function(t,r){e[t]=!0})),e}function formatValue(t,e,r){if(t.customInspect&&e&&isFunction$1(e.inspect)&&e.inspect!==inspect&&(!e.constructor||e.constructor.prototype!==e)){var n=e.inspect(r,t);return isString(n)||(n=formatValue(t,n,r)),n}var i=formatPrimitive(t,e);if(i)return i;var o=Object.keys(e),s=arrayToHash(o);if(t.showHidden&&(o=Object.getOwnPropertyNames(e)),isError(e)&&(o.indexOf("message")>=0||o.indexOf("description")>=0))return formatError(e);if(0===o.length){if(isFunction$1(e)){var a=e.name?": "+e.name:"";return t.stylize("[Function"+a+"]","special")}if(isRegExp(e))return t.stylize(RegExp.prototype.toString.call(e),"regexp");if(isDate(e))return t.stylize(Date.prototype.toString.call(e),"date");if(isError(e))return formatError(e)}var u,h="",c=!1,l=["{","}"];(isArray$1(e)&&(c=!0,l=["[","]"]),isFunction$1(e))&&(h=" [Function"+(e.name?": "+e.name:"")+"]");return isRegExp(e)&&(h=" "+RegExp.prototype.toString.call(e)),isDate(e)&&(h=" "+Date.prototype.toUTCString.call(e)),isError(e)&&(h=" "+formatError(e)),0!==o.length||c&&0!=e.length?r<0?isRegExp(e)?t.stylize(RegExp.prototype.toString.call(e),"regexp"):t.stylize("[Object]","special"):(t.seen.push(e),u=c?formatArray(t,e,r,s,o):o.map((function(n){return formatProperty(t,e,r,s,n,c)})),t.seen.pop(),reduceToSingleString(u,h,l)):l[0]+h+l[1]}function formatPrimitive(t,e){if(isUndefined(e))return t.stylize("undefined","undefined");if(isString(e)){var r="'"+JSON.stringify(e).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return t.stylize(r,"string")}return isNumber(e)?t.stylize(""+e,"number"):isBoolean(e)?t.stylize(""+e,"boolean"):isNull(e)?t.stylize("null","null"):void 0}function formatError(t){return"["+Error.prototype.toString.call(t)+"]"}function formatArray(t,e,r,n,i){for(var o=[],s=0,a=e.length;s<a;++s)hasOwnProperty(e,String(s))?o.push(formatProperty(t,e,r,n,String(s),!0)):o.push("");return i.forEach((function(i){i.match(/^\d+$/)||o.push(formatProperty(t,e,r,n,i,!0))})),o}function formatProperty(t,e,r,n,i,o){var s,a,u;if((u=Object.getOwnPropertyDescriptor(e,i)||{value:e[i]}).get?a=u.set?t.stylize("[Getter/Setter]","special"):t.stylize("[Getter]","special"):u.set&&(a=t.stylize("[Setter]","special")),hasOwnProperty(n,i)||(s="["+i+"]"),a||(t.seen.indexOf(u.value)<0?(a=isNull(r)?formatValue(t,u.value,null):formatValue(t,u.value,r-1)).indexOf("\n")>-1&&(a=o?a.split("\n").map((function(t){return"  "+t})).join("\n").substr(2):"\n"+a.split("\n").map((function(t){return"   "+t})).join("\n")):a=t.stylize("[Circular]","special")),isUndefined(s)){if(o&&i.match(/^\d+$/))return a;(s=JSON.stringify(""+i)).match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(s=s.substr(1,s.length-2),s=t.stylize(s,"name")):(s=s.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),s=t.stylize(s,"string"))}return s+": "+a}function reduceToSingleString(t,e,r){return t.reduce((function(t,e){return e.indexOf("\n"),t+e.replace(/\u001b\[\d\d?m/g,"").length+1}),0)>60?r[0]+(""===e?"":e+"\n ")+" "+t.join(",\n  ")+" "+r[1]:r[0]+e+" "+t.join(", ")+" "+r[1]}function isArray$1(t){return Array.isArray(t)}function isBoolean(t){return"boolean"==typeof t}function isNull(t){return null===t}function isNullOrUndefined(t){return null==t}function isNumber(t){return"number"==typeof t}function isString(t){return"string"==typeof t}function isSymbol(t){return"symbol"==typeof t}function isUndefined(t){return void 0===t}function isRegExp(t){return isObject(t)&&"[object RegExp]"===objectToString(t)}function isObject(t){return"object"==typeof t&&null!==t}function isDate(t){return isObject(t)&&"[object Date]"===objectToString(t)}function isError(t){return isObject(t)&&("[object Error]"===objectToString(t)||t instanceof Error)}function isFunction$1(t){return"function"==typeof t}function isPrimitive(t){return null===t||"boolean"==typeof t||"number"==typeof t||"string"==typeof t||"symbol"==typeof t||void 0===t}function isBuffer$1(t){return isBuffer(t)}function objectToString(t){return Object.prototype.toString.call(t)}function pad(t){return t<10?"0"+t.toString(10):t.toString(10)}inspect.colors={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]},inspect.styles={special:"cyan",number:"yellow",boolean:"yellow",undefined:"grey",null:"bold",string:"green",date:"magenta",regexp:"red"};var months=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function timestamp(){var t=new Date,e=[pad(t.getHours()),pad(t.getMinutes()),pad(t.getSeconds())].join(":");return[t.getDate(),months[t.getMonth()],e].join(" ")}function log(){console.log("%s - %s",timestamp(),format.apply(null,arguments))}function _extend(t,e){if(!e||!isObject(e))return t;for(var r=Object.keys(e),n=r.length;n--;)t[r[n]]=e[r[n]];return t}function hasOwnProperty(t,e){return Object.prototype.hasOwnProperty.call(t,e)}var util={inherits:inherits$1,_extend:_extend,log:log,isBuffer:isBuffer$1,isPrimitive:isPrimitive,isFunction:isFunction$1,isError:isError,isDate:isDate,isObject:isObject,isRegExp:isRegExp,isUndefined:isUndefined,isSymbol:isSymbol,isString:isString,isNumber:isNumber,isNullOrUndefined:isNullOrUndefined,isNull:isNull,isBoolean:isBoolean,isArray:isArray$1,inspect:inspect,deprecate:deprecate,format:format,debuglog:debuglog},util$1=Object.freeze({format:format,deprecate:deprecate,debuglog:debuglog,inspect:inspect,isArray:isArray$1,isBoolean:isBoolean,isNull:isNull,isNullOrUndefined:isNullOrUndefined,isNumber:isNumber,isString:isString,isSymbol:isSymbol,isUndefined:isUndefined,isRegExp:isRegExp,isObject:isObject,isDate:isDate,isError:isError,isFunction:isFunction$1,isPrimitive:isPrimitive,isBuffer:isBuffer$1,log:log,inherits:inherits$1,_extend:_extend,default:util}),domain;function EventHandlers(){}function EventEmitter(){EventEmitter.init.call(this)}function $getMaxListeners(t){return void 0===t._maxListeners?EventEmitter.defaultMaxListeners:t._maxListeners}function emitNone(t,e,r){if(e)t.call(r);else for(var n=t.length,i=arrayClone(t,n),o=0;o<n;++o)i[o].call(r)}function emitOne(t,e,r,n){if(e)t.call(r,n);else for(var i=t.length,o=arrayClone(t,i),s=0;s<i;++s)o[s].call(r,n)}function emitTwo(t,e,r,n,i){if(e)t.call(r,n,i);else for(var o=t.length,s=arrayClone(t,o),a=0;a<o;++a)s[a].call(r,n,i)}function emitThree(t,e,r,n,i,o){if(e)t.call(r,n,i,o);else for(var s=t.length,a=arrayClone(t,s),u=0;u<s;++u)a[u].call(r,n,i,o)}function emitMany(t,e,r,n){if(e)t.apply(r,n);else for(var i=t.length,o=arrayClone(t,i),s=0;s<i;++s)o[s].apply(r,n)}function _addListener(t,e,r,n){var i,o,s;if("function"!=typeof r)throw new TypeError('"listener" argument must be a function');if((o=t._events)?(o.newListener&&(t.emit("newListener",e,r.listener?r.listener:r),o=t._events),s=o[e]):(o=t._events=new EventHandlers,t._eventsCount=0),s){if("function"==typeof s?s=o[e]=n?[r,s]:[s,r]:n?s.unshift(r):s.push(r),!s.warned&&(i=$getMaxListeners(t))&&i>0&&s.length>i){s.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+e+" listeners added. Use emitter.setMaxListeners() to increase limit");a.name="MaxListenersExceededWarning",a.emitter=t,a.type=e,a.count=s.length,emitWarning(a)}}else s=o[e]=r,++t._eventsCount;return t}function emitWarning(t){"function"==typeof console.warn?console.warn(t):console.log(t)}function _onceWrap(t,e,r){var n=!1;function i(){t.removeListener(e,i),n||(n=!0,r.apply(t,arguments))}return i.listener=r,i}function listenerCount(t){var e=this._events;if(e){var r=e[t];if("function"==typeof r)return 1;if(r)return r.length}return 0}function spliceOne(t,e){for(var r=e,n=r+1,i=t.length;n<i;r+=1,n+=1)t[r]=t[n];t.pop()}function arrayClone(t,e){for(var r=new Array(e);e--;)r[e]=t[e];return r}function unwrapListeners(t){for(var e=new Array(t.length),r=0;r<e.length;++r)e[r]=t[r].listener||t[r];return e}EventHandlers.prototype=Object.create(null),EventEmitter.EventEmitter=EventEmitter,EventEmitter.usingDomains=!1,EventEmitter.prototype.domain=void 0,EventEmitter.prototype._events=void 0,EventEmitter.prototype._maxListeners=void 0,EventEmitter.defaultMaxListeners=10,EventEmitter.init=function(){this.domain=null,EventEmitter.usingDomains&&domain.active&&domain.Domain,this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=new EventHandlers,this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},EventEmitter.prototype.setMaxListeners=function(t){if("number"!=typeof t||t<0||isNaN(t))throw new TypeError('"n" argument must be a positive number');return this._maxListeners=t,this},EventEmitter.prototype.getMaxListeners=function(){return $getMaxListeners(this)},EventEmitter.prototype.emit=function(t){var e,r,n,i,o,s,a,u="error"===t;if(s=this._events)u=u&&null==s.error;else if(!u)return!1;if(a=this.domain,u){if(e=arguments[1],!a){if(e instanceof Error)throw e;var h=new Error('Uncaught, unspecified "error" event. ('+e+")");throw h.context=e,h}return e||(e=new Error('Uncaught, unspecified "error" event')),e.domainEmitter=this,e.domain=a,e.domainThrown=!1,a.emit("error",e),!1}if(!(r=s[t]))return!1;var c="function"==typeof r;switch(n=arguments.length){case 1:emitNone(r,c,this);break;case 2:emitOne(r,c,this,arguments[1]);break;case 3:emitTwo(r,c,this,arguments[1],arguments[2]);break;case 4:emitThree(r,c,this,arguments[1],arguments[2],arguments[3]);break;default:for(i=new Array(n-1),o=1;o<n;o++)i[o-1]=arguments[o];emitMany(r,c,this,i)}return!0},EventEmitter.prototype.addListener=function(t,e){return _addListener(this,t,e,!1)},EventEmitter.prototype.on=EventEmitter.prototype.addListener,EventEmitter.prototype.prependListener=function(t,e){return _addListener(this,t,e,!0)},EventEmitter.prototype.once=function(t,e){if("function"!=typeof e)throw new TypeError('"listener" argument must be a function');return this.on(t,_onceWrap(this,t,e)),this},EventEmitter.prototype.prependOnceListener=function(t,e){if("function"!=typeof e)throw new TypeError('"listener" argument must be a function');return this.prependListener(t,_onceWrap(this,t,e)),this},EventEmitter.prototype.removeListener=function(t,e){var r,n,i,o,s;if("function"!=typeof e)throw new TypeError('"listener" argument must be a function');if(!(n=this._events))return this;if(!(r=n[t]))return this;if(r===e||r.listener&&r.listener===e)0==--this._eventsCount?this._events=new EventHandlers:(delete n[t],n.removeListener&&this.emit("removeListener",t,r.listener||e));else if("function"!=typeof r){for(i=-1,o=r.length;o-- >0;)if(r[o]===e||r[o].listener&&r[o].listener===e){s=r[o].listener,i=o;break}if(i<0)return this;if(1===r.length){if(r[0]=void 0,0==--this._eventsCount)return this._events=new EventHandlers,this;delete n[t]}else spliceOne(r,i);n.removeListener&&this.emit("removeListener",t,s||e)}return this},EventEmitter.prototype.removeAllListeners=function(t){var e,r;if(!(r=this._events))return this;if(!r.removeListener)return 0===arguments.length?(this._events=new EventHandlers,this._eventsCount=0):r[t]&&(0==--this._eventsCount?this._events=new EventHandlers:delete r[t]),this;if(0===arguments.length){for(var n,i=Object.keys(r),o=0;o<i.length;++o)"removeListener"!==(n=i[o])&&this.removeAllListeners(n);return this.removeAllListeners("removeListener"),this._events=new EventHandlers,this._eventsCount=0,this}if("function"==typeof(e=r[t]))this.removeListener(t,e);else if(e)do{this.removeListener(t,e[e.length-1])}while(e[0]);return this},EventEmitter.prototype.listeners=function(t){var e,r=this._events;return r&&(e=r[t])?"function"==typeof e?[e.listener||e]:unwrapListeners(e):[]},EventEmitter.listenerCount=function(t,e){return"function"==typeof t.listenerCount?t.listenerCount(e):listenerCount.call(t,e)},EventEmitter.prototype.listenerCount=listenerCount,EventEmitter.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]};var events=Object.freeze({default:EventEmitter,EventEmitter:EventEmitter});function BufferList(){this.head=null,this.tail=null,this.length=0}BufferList.prototype.push=function(t){var e={data:t,next:null};this.length>0?this.tail.next=e:this.head=e,this.tail=e,++this.length},BufferList.prototype.unshift=function(t){var e={data:t,next:this.head};0===this.length&&(this.tail=e),this.head=e,++this.length},BufferList.prototype.shift=function(){if(0!==this.length){var t=this.head.data;return 1===this.length?this.head=this.tail=null:this.head=this.head.next,--this.length,t}},BufferList.prototype.clear=function(){this.head=this.tail=null,this.length=0},BufferList.prototype.join=function(t){if(0===this.length)return"";for(var e=this.head,r=""+e.data;e=e.next;)r+=t+e.data;return r},BufferList.prototype.concat=function(t){if(0===this.length)return Buffer.alloc(0);if(1===this.length)return this.head.data;for(var e=Buffer.allocUnsafe(t>>>0),r=this.head,n=0;r;)r.data.copy(e,n),n+=r.data.length,r=r.next;return e};var isBufferEncoding=Buffer.isEncoding||function(t){switch(t&&t.toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":case"raw":return!0;default:return!1}};function assertEncoding(t){if(t&&!isBufferEncoding(t))throw new Error("Unknown encoding: "+t)}function StringDecoder(t){switch(this.encoding=(t||"utf8").toLowerCase().replace(/[-_]/,""),assertEncoding(t),this.encoding){case"utf8":this.surrogateSize=3;break;case"ucs2":case"utf16le":this.surrogateSize=2,this.detectIncompleteChar=utf16DetectIncompleteChar;break;case"base64":this.surrogateSize=3,this.detectIncompleteChar=base64DetectIncompleteChar;break;default:return void(this.write=passThroughWrite)}this.charBuffer=new Buffer(6),this.charReceived=0,this.charLength=0}function passThroughWrite(t){return t.toString(this.encoding)}function utf16DetectIncompleteChar(t){this.charReceived=t.length%2,this.charLength=this.charReceived?2:0}function base64DetectIncompleteChar(t){this.charReceived=t.length%3,this.charLength=this.charReceived?3:0}StringDecoder.prototype.write=function(t){for(var e="";this.charLength;){var r=t.length>=this.charLength-this.charReceived?this.charLength-this.charReceived:t.length;if(t.copy(this.charBuffer,this.charReceived,0,r),this.charReceived+=r,this.charReceived<this.charLength)return"";if(t=t.slice(r,t.length),!((i=(e=this.charBuffer.slice(0,this.charLength).toString(this.encoding)).charCodeAt(e.length-1))>=55296&&i<=56319)){if(this.charReceived=this.charLength=0,0===t.length)return e;break}this.charLength+=this.surrogateSize,e=""}this.detectIncompleteChar(t);var n=t.length;this.charLength&&(t.copy(this.charBuffer,0,t.length-this.charReceived,n),n-=this.charReceived);var i;n=(e+=t.toString(this.encoding,0,n)).length-1;if((i=e.charCodeAt(n))>=55296&&i<=56319){var o=this.surrogateSize;return this.charLength+=o,this.charReceived+=o,this.charBuffer.copy(this.charBuffer,o,0,o),t.copy(this.charBuffer,0,0,o),e.substring(0,n)}return e},StringDecoder.prototype.detectIncompleteChar=function(t){for(var e=t.length>=3?3:t.length;e>0;e--){var r=t[t.length-e];if(1==e&&r>>5==6){this.charLength=2;break}if(e<=2&&r>>4==14){this.charLength=3;break}if(e<=3&&r>>3==30){this.charLength=4;break}}this.charReceived=e},StringDecoder.prototype.end=function(t){var e="";if(t&&t.length&&(e=this.write(t)),this.charReceived){var r=this.charReceived,n=this.charBuffer,i=this.encoding;e+=n.slice(0,r).toString(i)}return e},Readable.ReadableState=ReadableState;var debug=debuglog("stream");function prependListener(t,e,r){if("function"==typeof t.prependListener)return t.prependListener(e,r);t._events&&t._events[e]?Array.isArray(t._events[e])?t._events[e].unshift(r):t._events[e]=[r,t._events[e]]:t.on(e,r)}function listenerCount$1(t,e){return t.listeners(e).length}function ReadableState(t,e){t=t||{},this.objectMode=!!t.objectMode,e instanceof Duplex&&(this.objectMode=this.objectMode||!!t.readableObjectMode);var r=t.highWaterMark,n=this.objectMode?16:16384;this.highWaterMark=r||0===r?r:n,this.highWaterMark=~~this.highWaterMark,this.buffer=new BufferList,this.length=0,this.pipes=null,this.pipesCount=0,this.flowing=null,this.ended=!1,this.endEmitted=!1,this.reading=!1,this.sync=!0,this.needReadable=!1,this.emittedReadable=!1,this.readableListening=!1,this.resumeScheduled=!1,this.defaultEncoding=t.defaultEncoding||"utf8",this.ranOut=!1,this.awaitDrain=0,this.readingMore=!1,this.decoder=null,this.encoding=null,t.encoding&&(this.decoder=new StringDecoder(t.encoding),this.encoding=t.encoding)}function Readable(t){if(!(this instanceof Readable))return new Readable(t);this._readableState=new ReadableState(t,this),this.readable=!0,t&&"function"==typeof t.read&&(this._read=t.read),EventEmitter.call(this)}function readableAddChunk(t,e,r,n,i){var o=chunkInvalid(e,r);if(o)t.emit("error",o);else if(null===r)e.reading=!1,onEofChunk(t,e);else if(e.objectMode||r&&r.length>0)if(e.ended&&!i){var s=new Error("stream.push() after EOF");t.emit("error",s)}else if(e.endEmitted&&i){var a=new Error("stream.unshift() after end event");t.emit("error",a)}else{var u;!e.decoder||i||n||(r=e.decoder.write(r),u=!e.objectMode&&0===r.length),i||(e.reading=!1),u||(e.flowing&&0===e.length&&!e.sync?(t.emit("data",r),t.read(0)):(e.length+=e.objectMode?1:r.length,i?e.buffer.unshift(r):e.buffer.push(r),e.needReadable&&emitReadable(t))),maybeReadMore(t,e)}else i||(e.reading=!1);return needMoreData(e)}function needMoreData(t){return!t.ended&&(t.needReadable||t.length<t.highWaterMark||0===t.length)}inherits$1(Readable,EventEmitter),Readable.prototype.push=function(t,e){var r=this._readableState;return r.objectMode||"string"!=typeof t||(e=e||r.defaultEncoding)!==r.encoding&&(t=Buffer.from(t,e),e=""),readableAddChunk(this,r,t,e,!1)},Readable.prototype.unshift=function(t){return readableAddChunk(this,this._readableState,t,"",!0)},Readable.prototype.isPaused=function(){return!1===this._readableState.flowing},Readable.prototype.setEncoding=function(t){return this._readableState.decoder=new StringDecoder(t),this._readableState.encoding=t,this};var MAX_HWM=8388608;function computeNewHighWaterMark(t){return t>=MAX_HWM?t=MAX_HWM:(t--,t|=t>>>1,t|=t>>>2,t|=t>>>4,t|=t>>>8,t|=t>>>16,t++),t}function howMuchToRead(t,e){return t<=0||0===e.length&&e.ended?0:e.objectMode?1:t!=t?e.flowing&&e.length?e.buffer.head.data.length:e.length:(t>e.highWaterMark&&(e.highWaterMark=computeNewHighWaterMark(t)),t<=e.length?t:e.ended?e.length:(e.needReadable=!0,0))}function chunkInvalid(t,e){var r=null;return isBuffer(e)||"string"==typeof e||null==e||t.objectMode||(r=new TypeError("Invalid non-string/buffer chunk")),r}function onEofChunk(t,e){if(!e.ended){if(e.decoder){var r=e.decoder.end();r&&r.length&&(e.buffer.push(r),e.length+=e.objectMode?1:r.length)}e.ended=!0,emitReadable(t)}}function emitReadable(t){var e=t._readableState;e.needReadable=!1,e.emittedReadable||(debug("emitReadable",e.flowing),e.emittedReadable=!0,e.sync?nextTick(emitReadable_,t):emitReadable_(t))}function emitReadable_(t){debug("emit readable"),t.emit("readable"),flow(t)}function maybeReadMore(t,e){e.readingMore||(e.readingMore=!0,nextTick(maybeReadMore_,t,e))}function maybeReadMore_(t,e){for(var r=e.length;!e.reading&&!e.flowing&&!e.ended&&e.length<e.highWaterMark&&(debug("maybeReadMore read 0"),t.read(0),r!==e.length);)r=e.length;e.readingMore=!1}function pipeOnDrain(t){return function(){var e=t._readableState;debug("pipeOnDrain",e.awaitDrain),e.awaitDrain&&e.awaitDrain--,0===e.awaitDrain&&t.listeners("data").length&&(e.flowing=!0,flow(t))}}function nReadingNextTick(t){debug("readable nexttick read 0"),t.read(0)}function resume(t,e){e.resumeScheduled||(e.resumeScheduled=!0,nextTick(resume_,t,e))}function resume_(t,e){e.reading||(debug("resume read 0"),t.read(0)),e.resumeScheduled=!1,e.awaitDrain=0,t.emit("resume"),flow(t),e.flowing&&!e.reading&&t.read(0)}function flow(t){var e=t._readableState;for(debug("flow",e.flowing);e.flowing&&null!==t.read(););}function fromList(t,e){return 0===e.length?null:(e.objectMode?r=e.buffer.shift():!t||t>=e.length?(r=e.decoder?e.buffer.join(""):1===e.buffer.length?e.buffer.head.data:e.buffer.concat(e.length),e.buffer.clear()):r=fromListPartial(t,e.buffer,e.decoder),r);var r}function fromListPartial(t,e,r){var n;return t<e.head.data.length?(n=e.head.data.slice(0,t),e.head.data=e.head.data.slice(t)):n=t===e.head.data.length?e.shift():r?copyFromBufferString(t,e):copyFromBuffer(t,e),n}function copyFromBufferString(t,e){var r=e.head,n=1,i=r.data;for(t-=i.length;r=r.next;){var o=r.data,s=t>o.length?o.length:t;if(s===o.length?i+=o:i+=o.slice(0,t),0===(t-=s)){s===o.length?(++n,r.next?e.head=r.next:e.head=e.tail=null):(e.head=r,r.data=o.slice(s));break}++n}return e.length-=n,i}function copyFromBuffer(t,e){var r=Buffer.allocUnsafe(t),n=e.head,i=1;for(n.data.copy(r),t-=n.data.length;n=n.next;){var o=n.data,s=t>o.length?o.length:t;if(o.copy(r,r.length-t,0,s),0===(t-=s)){s===o.length?(++i,n.next?e.head=n.next:e.head=e.tail=null):(e.head=n,n.data=o.slice(s));break}++i}return e.length-=i,r}function endReadable(t){var e=t._readableState;if(e.length>0)throw new Error('"endReadable()" called on non-empty stream');e.endEmitted||(e.ended=!0,nextTick(endReadableNT,e,t))}function endReadableNT(t,e){t.endEmitted||0!==t.length||(t.endEmitted=!0,e.readable=!1,e.emit("end"))}function forEach(t,e){for(var r=0,n=t.length;r<n;r++)e(t[r],r)}function indexOf(t,e){for(var r=0,n=t.length;r<n;r++)if(t[r]===e)return r;return-1}function nop(){}function WriteReq(t,e,r){this.chunk=t,this.encoding=e,this.callback=r,this.next=null}function WritableState(t,e){Object.defineProperty(this,"buffer",{get:deprecate((function(){return this.getBuffer()}),"_writableState.buffer is deprecated. Use _writableState.getBuffer instead.")}),t=t||{},this.objectMode=!!t.objectMode,e instanceof Duplex&&(this.objectMode=this.objectMode||!!t.writableObjectMode);var r=t.highWaterMark,n=this.objectMode?16:16384;this.highWaterMark=r||0===r?r:n,this.highWaterMark=~~this.highWaterMark,this.needDrain=!1,this.ending=!1,this.ended=!1,this.finished=!1;var i=!1===t.decodeStrings;this.decodeStrings=!i,this.defaultEncoding=t.defaultEncoding||"utf8",this.length=0,this.writing=!1,this.corked=0,this.sync=!0,this.bufferProcessing=!1,this.onwrite=function(t){onwrite(e,t)},this.writecb=null,this.writelen=0,this.bufferedRequest=null,this.lastBufferedRequest=null,this.pendingcb=0,this.prefinished=!1,this.errorEmitted=!1,this.bufferedRequestCount=0,this.corkedRequestsFree=new CorkedRequest(this)}function Writable(t){if(!(this instanceof Writable||this instanceof Duplex))return new Writable(t);this._writableState=new WritableState(t,this),this.writable=!0,t&&("function"==typeof t.write&&(this._write=t.write),"function"==typeof t.writev&&(this._writev=t.writev)),EventEmitter.call(this)}function writeAfterEnd(t,e){var r=new Error("write after end");t.emit("error",r),nextTick(e,r)}function validChunk(t,e,r,n){var i=!0,o=!1;return null===r?o=new TypeError("May not write null values to stream"):Buffer.isBuffer(r)||"string"==typeof r||void 0===r||e.objectMode||(o=new TypeError("Invalid non-string/buffer chunk")),o&&(t.emit("error",o),nextTick(n,o),i=!1),i}function decodeChunk(t,e,r){return t.objectMode||!1===t.decodeStrings||"string"!=typeof e||(e=Buffer.from(e,r)),e}function writeOrBuffer(t,e,r,n,i){r=decodeChunk(e,r,n),Buffer.isBuffer(r)&&(n="buffer");var o=e.objectMode?1:r.length;e.length+=o;var s=e.length<e.highWaterMark;if(s||(e.needDrain=!0),e.writing||e.corked){var a=e.lastBufferedRequest;e.lastBufferedRequest=new WriteReq(r,n,i),a?a.next=e.lastBufferedRequest:e.bufferedRequest=e.lastBufferedRequest,e.bufferedRequestCount+=1}else doWrite(t,e,!1,o,r,n,i);return s}function doWrite(t,e,r,n,i,o,s){e.writelen=n,e.writecb=s,e.writing=!0,e.sync=!0,r?t._writev(i,e.onwrite):t._write(i,o,e.onwrite),e.sync=!1}function onwriteError(t,e,r,n,i){--e.pendingcb,r?nextTick(i,n):i(n),t._writableState.errorEmitted=!0,t.emit("error",n)}function onwriteStateUpdate(t){t.writing=!1,t.writecb=null,t.length-=t.writelen,t.writelen=0}function onwrite(t,e){var r=t._writableState,n=r.sync,i=r.writecb;if(onwriteStateUpdate(r),e)onwriteError(t,r,n,e,i);else{var o=needFinish(r);o||r.corked||r.bufferProcessing||!r.bufferedRequest||clearBuffer(t,r),n?nextTick(afterWrite,t,r,o,i):afterWrite(t,r,o,i)}}function afterWrite(t,e,r,n){r||onwriteDrain(t,e),e.pendingcb--,n(),finishMaybe(t,e)}function onwriteDrain(t,e){0===e.length&&e.needDrain&&(e.needDrain=!1,t.emit("drain"))}function clearBuffer(t,e){e.bufferProcessing=!0;var r=e.bufferedRequest;if(t._writev&&r&&r.next){var n=e.bufferedRequestCount,i=new Array(n),o=e.corkedRequestsFree;o.entry=r;for(var s=0;r;)i[s]=r,r=r.next,s+=1;doWrite(t,e,!0,e.length,i,"",o.finish),e.pendingcb++,e.lastBufferedRequest=null,o.next?(e.corkedRequestsFree=o.next,o.next=null):e.corkedRequestsFree=new CorkedRequest(e)}else{for(;r;){var a=r.chunk,u=r.encoding,h=r.callback;if(doWrite(t,e,!1,e.objectMode?1:a.length,a,u,h),r=r.next,e.writing)break}null===r&&(e.lastBufferedRequest=null)}e.bufferedRequestCount=0,e.bufferedRequest=r,e.bufferProcessing=!1}function needFinish(t){return t.ending&&0===t.length&&null===t.bufferedRequest&&!t.finished&&!t.writing}function prefinish(t,e){e.prefinished||(e.prefinished=!0,t.emit("prefinish"))}function finishMaybe(t,e){var r=needFinish(e);return r&&(0===e.pendingcb?(prefinish(t,e),e.finished=!0,t.emit("finish")):prefinish(t,e)),r}function endWritable(t,e,r){e.ending=!0,finishMaybe(t,e),r&&(e.finished?nextTick(r):t.once("finish",r)),e.ended=!0,t.writable=!1}function CorkedRequest(t){var e=this;this.next=null,this.entry=null,this.finish=function(r){var n=e.entry;for(e.entry=null;n;){var i=n.callback;t.pendingcb--,i(r),n=n.next}t.corkedRequestsFree?t.corkedRequestsFree.next=e:t.corkedRequestsFree=e}}Readable.prototype.read=function(t){debug("read",t),t=parseInt(t,10);var e=this._readableState,r=t;if(0!==t&&(e.emittedReadable=!1),0===t&&e.needReadable&&(e.length>=e.highWaterMark||e.ended))return debug("read: emitReadable",e.length,e.ended),0===e.length&&e.ended?endReadable(this):emitReadable(this),null;if(0===(t=howMuchToRead(t,e))&&e.ended)return 0===e.length&&endReadable(this),null;var n,i=e.needReadable;return debug("need readable",i),(0===e.length||e.length-t<e.highWaterMark)&&debug("length less than watermark",i=!0),e.ended||e.reading?debug("reading or ended",i=!1):i&&(debug("do read"),e.reading=!0,e.sync=!0,0===e.length&&(e.needReadable=!0),this._read(e.highWaterMark),e.sync=!1,e.reading||(t=howMuchToRead(r,e))),null===(n=t>0?fromList(t,e):null)?(e.needReadable=!0,t=0):e.length-=t,0===e.length&&(e.ended||(e.needReadable=!0),r!==t&&e.ended&&endReadable(this)),null!==n&&this.emit("data",n),n},Readable.prototype._read=function(t){this.emit("error",new Error("not implemented"))},Readable.prototype.pipe=function(t,e){var r=this,n=this._readableState;switch(n.pipesCount){case 0:n.pipes=t;break;case 1:n.pipes=[n.pipes,t];break;default:n.pipes.push(t)}n.pipesCount+=1,debug("pipe count=%d opts=%j",n.pipesCount,e);var i=!e||!1!==e.end?s:h;function o(t){debug("onunpipe"),t===r&&h()}function s(){debug("onend"),t.end()}n.endEmitted?nextTick(i):r.once("end",i),t.on("unpipe",o);var a=pipeOnDrain(r);t.on("drain",a);var u=!1;function h(){debug("cleanup"),t.removeListener("close",m),t.removeListener("finish",p),t.removeListener("drain",a),t.removeListener("error",f),t.removeListener("unpipe",o),r.removeListener("end",s),r.removeListener("end",h),r.removeListener("data",l),u=!0,!n.awaitDrain||t._writableState&&!t._writableState.needDrain||a()}var c=!1;function l(e){debug("ondata"),c=!1,!1!==t.write(e)||c||((1===n.pipesCount&&n.pipes===t||n.pipesCount>1&&-1!==indexOf(n.pipes,t))&&!u&&(debug("false write response, pause",r._readableState.awaitDrain),r._readableState.awaitDrain++,c=!0),r.pause())}function f(e){debug("onerror",e),d(),t.removeListener("error",f),0===listenerCount$1(t,"error")&&t.emit("error",e)}function m(){t.removeListener("finish",p),d()}function p(){debug("onfinish"),t.removeListener("close",m),d()}function d(){debug("unpipe"),r.unpipe(t)}return r.on("data",l),prependListener(t,"error",f),t.once("close",m),t.once("finish",p),t.emit("pipe",r),n.flowing||(debug("pipe resume"),r.resume()),t},Readable.prototype.unpipe=function(t){var e=this._readableState;if(0===e.pipesCount)return this;if(1===e.pipesCount)return t&&t!==e.pipes||(t||(t=e.pipes),e.pipes=null,e.pipesCount=0,e.flowing=!1,t&&t.emit("unpipe",this)),this;if(!t){var r=e.pipes,n=e.pipesCount;e.pipes=null,e.pipesCount=0,e.flowing=!1;for(var i=0;i<n;i++)r[i].emit("unpipe",this);return this}var o=indexOf(e.pipes,t);return-1===o||(e.pipes.splice(o,1),e.pipesCount-=1,1===e.pipesCount&&(e.pipes=e.pipes[0]),t.emit("unpipe",this)),this},Readable.prototype.on=function(t,e){var r=EventEmitter.prototype.on.call(this,t,e);if("data"===t)!1!==this._readableState.flowing&&this.resume();else if("readable"===t){var n=this._readableState;n.endEmitted||n.readableListening||(n.readableListening=n.needReadable=!0,n.emittedReadable=!1,n.reading?n.length&&emitReadable(this,n):nextTick(nReadingNextTick,this))}return r},Readable.prototype.addListener=Readable.prototype.on,Readable.prototype.resume=function(){var t=this._readableState;return t.flowing||(debug("resume"),t.flowing=!0,resume(this,t)),this},Readable.prototype.pause=function(){return debug("call pause flowing=%j",this._readableState.flowing),!1!==this._readableState.flowing&&(debug("pause"),this._readableState.flowing=!1,this.emit("pause")),this},Readable.prototype.wrap=function(t){var e=this._readableState,r=!1,n=this;for(var i in t.on("end",(function(){if(debug("wrapped end"),e.decoder&&!e.ended){var t=e.decoder.end();t&&t.length&&n.push(t)}n.push(null)})),t.on("data",(function(i){(debug("wrapped data"),e.decoder&&(i=e.decoder.write(i)),e.objectMode&&null==i)||(e.objectMode||i&&i.length)&&(n.push(i)||(r=!0,t.pause()))})),t)void 0===this[i]&&"function"==typeof t[i]&&(this[i]=function(e){return function(){return t[e].apply(t,arguments)}}(i));return forEach(["error","close","destroy","pause","resume"],(function(e){t.on(e,n.emit.bind(n,e))})),n._read=function(e){debug("wrapped _read",e),r&&(r=!1,t.resume())},n},Readable._fromList=fromList,Writable.WritableState=WritableState,inherits$1(Writable,EventEmitter),WritableState.prototype.getBuffer=function(){for(var t=this.bufferedRequest,e=[];t;)e.push(t),t=t.next;return e},Writable.prototype.pipe=function(){this.emit("error",new Error("Cannot pipe, not readable"))},Writable.prototype.write=function(t,e,r){var n=this._writableState,i=!1;return"function"==typeof e&&(r=e,e=null),Buffer.isBuffer(t)?e="buffer":e||(e=n.defaultEncoding),"function"!=typeof r&&(r=nop),n.ended?writeAfterEnd(this,r):validChunk(this,n,t,r)&&(n.pendingcb++,i=writeOrBuffer(this,n,t,e,r)),i},Writable.prototype.cork=function(){this._writableState.corked++},Writable.prototype.uncork=function(){var t=this._writableState;t.corked&&(t.corked--,t.writing||t.corked||t.finished||t.bufferProcessing||!t.bufferedRequest||clearBuffer(this,t))},Writable.prototype.setDefaultEncoding=function(t){if("string"==typeof t&&(t=t.toLowerCase()),!(["hex","utf8","utf-8","ascii","binary","base64","ucs2","ucs-2","utf16le","utf-16le","raw"].indexOf((t+"").toLowerCase())>-1))throw new TypeError("Unknown encoding: "+t);return this._writableState.defaultEncoding=t,this},Writable.prototype._write=function(t,e,r){r(new Error("not implemented"))},Writable.prototype._writev=null,Writable.prototype.end=function(t,e,r){var n=this._writableState;"function"==typeof t?(r=t,t=null,e=null):"function"==typeof e&&(r=e,e=null),null!=t&&this.write(t,e),n.corked&&(n.corked=1,this.uncork()),n.ending||n.finished||endWritable(this,n,r)},inherits$1(Duplex,Readable);for(var keys=Object.keys(Writable.prototype),v=0;v<keys.length;v++){var method=keys[v];Duplex.prototype[method]||(Duplex.prototype[method]=Writable.prototype[method])}function Duplex(t){if(!(this instanceof Duplex))return new Duplex(t);Readable.call(this,t),Writable.call(this,t),t&&!1===t.readable&&(this.readable=!1),t&&!1===t.writable&&(this.writable=!1),this.allowHalfOpen=!0,t&&!1===t.allowHalfOpen&&(this.allowHalfOpen=!1),this.once("end",onend)}function onend(){this.allowHalfOpen||this._writableState.ended||nextTick(onEndNT,this)}function onEndNT(t){t.end()}function TransformState(t){this.afterTransform=function(e,r){return afterTransform(t,e,r)},this.needTransform=!1,this.transforming=!1,this.writecb=null,this.writechunk=null,this.writeencoding=null}function afterTransform(t,e,r){var n=t._transformState;n.transforming=!1;var i=n.writecb;if(!i)return t.emit("error",new Error("no writecb in Transform class"));n.writechunk=null,n.writecb=null,null!=r&&t.push(r),i(e);var o=t._readableState;o.reading=!1,(o.needReadable||o.length<o.highWaterMark)&&t._read(o.highWaterMark)}function Transform(t){if(!(this instanceof Transform))return new Transform(t);Duplex.call(this,t),this._transformState=new TransformState(this);var e=this;this._readableState.needReadable=!0,this._readableState.sync=!1,t&&("function"==typeof t.transform&&(this._transform=t.transform),"function"==typeof t.flush&&(this._flush=t.flush)),this.once("prefinish",(function(){"function"==typeof this._flush?this._flush((function(t){done(e,t)})):done(e)}))}function done(t,e){if(e)return t.emit("error",e);var r=t._writableState,n=t._transformState;if(r.length)throw new Error("Calling transform done when ws.length != 0");if(n.transforming)throw new Error("Calling transform done when still transforming");return t.push(null)}function PassThrough(t){if(!(this instanceof PassThrough))return new PassThrough(t);Transform.call(this,t)}function Stream(){EventEmitter.call(this)}inherits$1(Transform,Duplex),Transform.prototype.push=function(t,e){return this._transformState.needTransform=!1,Duplex.prototype.push.call(this,t,e)},Transform.prototype._transform=function(t,e,r){throw new Error("Not implemented")},Transform.prototype._write=function(t,e,r){var n=this._transformState;if(n.writecb=r,n.writechunk=t,n.writeencoding=e,!n.transforming){var i=this._readableState;(n.needTransform||i.needReadable||i.length<i.highWaterMark)&&this._read(i.highWaterMark)}},Transform.prototype._read=function(t){var e=this._transformState;null!==e.writechunk&&e.writecb&&!e.transforming?(e.transforming=!0,this._transform(e.writechunk,e.writeencoding,e.afterTransform)):e.needTransform=!0},inherits$1(PassThrough,Transform),PassThrough.prototype._transform=function(t,e,r){r(null,t)},inherits$1(Stream,EventEmitter),Stream.Readable=Readable,Stream.Writable=Writable,Stream.Duplex=Duplex,Stream.Transform=Transform,Stream.PassThrough=PassThrough,Stream.Stream=Stream,Stream.prototype.pipe=function(t,e){var r=this;function n(e){t.writable&&!1===t.write(e)&&r.pause&&r.pause()}function i(){r.readable&&r.resume&&r.resume()}r.on("data",n),t.on("drain",i),t._isStdio||e&&!1===e.end||(r.on("end",s),r.on("close",a));var o=!1;function s(){o||(o=!0,t.end())}function a(){o||(o=!0,"function"==typeof t.destroy&&t.destroy())}function u(t){if(h(),0===EventEmitter.listenerCount(this,"error"))throw t}function h(){r.removeListener("data",n),t.removeListener("drain",i),r.removeListener("end",s),r.removeListener("close",a),r.removeListener("error",u),t.removeListener("error",u),r.removeListener("end",h),r.removeListener("close",h),t.removeListener("close",h)}return r.on("error",u),t.on("error",u),r.on("end",h),r.on("close",h),t.on("close",h),t.emit("pipe",r),t};var stream=Object.freeze({default:Stream,Readable:Readable,Writable:Writable,Duplex:Duplex,Transform:Transform,PassThrough:PassThrough,Stream:Stream}),rStates={UNSENT:0,OPENED:1,HEADERS_RECEIVED:2,LOADING:3,DONE:4};function IncomingMessage(t,e,r){var n,i=this;if(Readable.call(i),i._mode=r,i.headers={},i.rawHeaders=[],i.trailers={},i.rawTrailers=[],i.on("end",(function(){nextTick((function(){i.emit("close")}))})),"fetch"===r){i._fetchResponse=e,i.url=e.url,i.statusCode=e.status,i.statusMessage=e.statusText;for(var o,s,a=e.headers[Symbol.iterator]();o=(s=a.next()).value,!s.done;)i.headers[o[0].toLowerCase()]=o[1],i.rawHeaders.push(o[0],o[1]);var u=e.body.getReader();(n=function(){u.read().then((function(t){i._destroyed||(t.done?i.push(null):(i.push(new Buffer(t.value)),n()))}))})()}else{if(i._xhr=t,i._pos=0,i.url=t.responseURL,i.statusCode=t.status,i.statusMessage=t.statusText,t.getAllResponseHeaders().split(/\r?\n/).forEach((function(t){var e=t.match(/^([^:]+):\s*(.*)/);if(e){var r=e[1].toLowerCase();"set-cookie"===r?(void 0===i.headers[r]&&(i.headers[r]=[]),i.headers[r].push(e[2])):void 0!==i.headers[r]?i.headers[r]+=", "+e[2]:i.headers[r]=e[2],i.rawHeaders.push(e[1],e[2])}})),i._charset="x-user-defined",!overrideMimeType){var h=i.rawHeaders["mime-type"];if(h){var c=h.match(/;\s*charset=([^;])(;|$)/);c&&(i._charset=c[1].toLowerCase())}i._charset||(i._charset="utf-8")}}}function toArrayBuffer(t){if(t instanceof Uint8Array){if(0===t.byteOffset&&t.byteLength===t.buffer.byteLength)return t.buffer;if("function"==typeof t.buffer.slice)return t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength)}if(isBuffer(t)){for(var e=new Uint8Array(t.length),r=t.length,n=0;n<r;n++)e[n]=t[n];return e.buffer}throw new Error("Argument must be a Buffer")}function decideMode(t,e){return hasFetch&&e?"fetch":mozchunkedarraybuffer?"moz-chunked-arraybuffer":msstream?"ms-stream":arraybuffer&&t?"arraybuffer":vbArray&&t?"text:vbarray":"text"}function ClientRequest(t){var e,r=this;Writable.call(r),r._opts=t,r._body=[],r._headers={},t.auth&&r.setHeader("Authorization","Basic "+new Buffer(t.auth).toString("base64")),Object.keys(t.headers).forEach((function(e){r.setHeader(e,t.headers[e])}));var n=!0;if("disable-fetch"===t.mode)n=!1,e=!0;else if("prefer-streaming"===t.mode)e=!1;else if("allow-wrong-content-type"===t.mode)e=!overrideMimeType;else{if(t.mode&&"default"!==t.mode&&"prefer-fast"!==t.mode)throw new Error("Invalid value for opts.mode");e=!0}r._mode=decideMode(e,n),r.on("finish",(function(){r._onFinish()}))}inherits$1(IncomingMessage,Readable),IncomingMessage.prototype._read=function(){},IncomingMessage.prototype._onXHRProgress=function(){var t=this,e=t._xhr,r=null;switch(t._mode){case"text:vbarray":if(e.readyState!==rStates.DONE)break;try{r=new global$1.VBArray(e.responseBody).toArray()}catch(t){}if(null!==r){t.push(new Buffer(r));break}case"text":try{r=e.responseText}catch(e){t._mode="text:vbarray";break}if(r.length>t._pos){var n=r.substr(t._pos);if("x-user-defined"===t._charset){for(var i=new Buffer(n.length),o=0;o<n.length;o++)i[o]=255&n.charCodeAt(o);t.push(i)}else t.push(n,t._charset);t._pos=r.length}break;case"arraybuffer":if(e.readyState!==rStates.DONE||!e.response)break;r=e.response,t.push(new Buffer(new Uint8Array(r)));break;case"moz-chunked-arraybuffer":if(r=e.response,e.readyState!==rStates.LOADING||!r)break;t.push(new Buffer(new Uint8Array(r)));break;case"ms-stream":if(r=e.response,e.readyState!==rStates.LOADING)break;var s=new global$1.MSStreamReader;s.onprogress=function(){s.result.byteLength>t._pos&&(t.push(new Buffer(new Uint8Array(s.result.slice(t._pos)))),t._pos=s.result.byteLength)},s.onload=function(){t.push(null)},s.readAsArrayBuffer(r)}t._xhr.readyState===rStates.DONE&&"ms-stream"!==t._mode&&t.push(null)},inherits$1(ClientRequest,Writable);var unsafeHeaders=["accept-charset","accept-encoding","access-control-request-headers","access-control-request-method","connection","content-length","cookie","cookie2","date","dnt","expect","host","keep-alive","origin","referer","te","trailer","transfer-encoding","upgrade","user-agent","via"];function statusValid(t){try{var e=t.status;return null!==e&&0!==e}catch(t){return!1}}ClientRequest.prototype.setHeader=function(t,e){var r=t.toLowerCase();-1===unsafeHeaders.indexOf(r)&&(this._headers[r]={name:t,value:e})},ClientRequest.prototype.getHeader=function(t){return this._headers[t.toLowerCase()].value},ClientRequest.prototype.removeHeader=function(t){delete this._headers[t.toLowerCase()]},ClientRequest.prototype._onFinish=function(){var t=this;if(!t._destroyed){var e,r=t._opts,n=t._headers;if("POST"!==r.method&&"PUT"!==r.method&&"PATCH"!==r.method||(e=blobConstructor()?new global$1.Blob(t._body.map((function(t){return toArrayBuffer(t)})),{type:(n["content-type"]||{}).value||""}):Buffer.concat(t._body).toString()),"fetch"===t._mode){var i=Object.keys(n).map((function(t){return[n[t].name,n[t].value]}));global$1.fetch(t._opts.url,{method:t._opts.method,headers:i,body:e,mode:"cors",credentials:r.withCredentials?"include":"same-origin"}).then((function(e){t._fetchResponse=e,t._connect()}),(function(e){t.emit("error",e)}))}else{var o=t._xhr=new global$1.XMLHttpRequest;try{o.open(t._opts.method,t._opts.url,!0)}catch(e){return void nextTick((function(){t.emit("error",e)}))}"responseType"in o&&(o.responseType=t._mode.split(":")[0]),"withCredentials"in o&&(o.withCredentials=!!r.withCredentials),"text"===t._mode&&"overrideMimeType"in o&&o.overrideMimeType("text/plain; charset=x-user-defined"),Object.keys(n).forEach((function(t){o.setRequestHeader(n[t].name,n[t].value)})),t._response=null,o.onreadystatechange=function(){switch(o.readyState){case rStates.LOADING:case rStates.DONE:t._onXHRProgress()}},"moz-chunked-arraybuffer"===t._mode&&(o.onprogress=function(){t._onXHRProgress()}),o.onerror=function(){t._destroyed||t.emit("error",new Error("XHR error"))};try{o.send(e)}catch(e){return void nextTick((function(){t.emit("error",e)}))}}}},ClientRequest.prototype._onXHRProgress=function(){var t=this;statusValid(t._xhr)&&!t._destroyed&&(t._response||t._connect(),t._response._onXHRProgress())},ClientRequest.prototype._connect=function(){var t=this;t._destroyed||(t._response=new IncomingMessage(t._xhr,t._fetchResponse,t._mode),t.emit("response",t._response))},ClientRequest.prototype._write=function(t,e,r){this._body.push(t),r()},ClientRequest.prototype.abort=ClientRequest.prototype.destroy=function(){var t=this;t._destroyed=!0,t._response&&(t._response._destroyed=!0),t._xhr&&t._xhr.abort()},ClientRequest.prototype.end=function(t,e,r){"function"==typeof t&&(r=t,t=void 0),Writable.prototype.end.call(this,t,e,r)},ClientRequest.prototype.flushHeaders=function(){},ClientRequest.prototype.setTimeout=function(){},ClientRequest.prototype.setNoDelay=function(){},ClientRequest.prototype.setSocketKeepAlive=function(){};
/*! https://mths.be/punycode v1.4.1 by @mathias */
var maxInt=2147483647,base=36,tMin=1,tMax=26,skew=38,damp=700,initialBias=72,initialN=128,delimiter="-",regexNonASCII=/[^\x20-\x7E]/,regexSeparators=/[\x2E\u3002\uFF0E\uFF61]/g,errors={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},baseMinusTMin=base-tMin,floor=Math.floor,stringFromCharCode=String.fromCharCode;function error(t){throw new RangeError(errors[t])}function map(t,e){for(var r=t.length,n=[];r--;)n[r]=e(t[r]);return n}function mapDomain(t,e){var r=t.split("@"),n="";return r.length>1&&(n=r[0]+"@",t=r[1]),n+map((t=t.replace(regexSeparators,".")).split("."),e).join(".")}function ucs2decode(t){for(var e,r,n=[],i=0,o=t.length;i<o;)(e=t.charCodeAt(i++))>=55296&&e<=56319&&i<o?56320==(64512&(r=t.charCodeAt(i++)))?n.push(((1023&e)<<10)+(1023&r)+65536):(n.push(e),i--):n.push(e);return n}function digitToBasic(t,e){return t+22+75*(t<26)-((0!=e)<<5)}function adapt(t,e,r){var n=0;for(t=r?floor(t/damp):t>>1,t+=floor(t/e);t>baseMinusTMin*tMax>>1;n+=base)t=floor(t/baseMinusTMin);return floor(n+(baseMinusTMin+1)*t/(t+skew))}function encode(t){var e,r,n,i,o,s,a,u,h,c,l,f,m,p,d,g=[];for(f=(t=ucs2decode(t)).length,e=initialN,r=0,o=initialBias,s=0;s<f;++s)(l=t[s])<128&&g.push(stringFromCharCode(l));for(n=i=g.length,i&&g.push(delimiter);n<f;){for(a=maxInt,s=0;s<f;++s)(l=t[s])>=e&&l<a&&(a=l);for(a-e>floor((maxInt-r)/(m=n+1))&&error("overflow"),r+=(a-e)*m,e=a,s=0;s<f;++s)if((l=t[s])<e&&++r>maxInt&&error("overflow"),l==e){for(u=r,h=base;!(u<(c=h<=o?tMin:h>=o+tMax?tMax:h-o));h+=base)d=u-c,p=base-c,g.push(stringFromCharCode(digitToBasic(c+d%p,0))),u=floor(d/p);g.push(stringFromCharCode(digitToBasic(u,0))),o=adapt(r,m,n==i),r=0,++n}++r,++e}return g.join("")}function toASCII(t){return mapDomain(t,(function(t){return regexNonASCII.test(t)?"xn--"+encode(t):t}))}function hasOwnProperty$1(t,e){return Object.prototype.hasOwnProperty.call(t,e)}var isArray$2=Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)};function stringifyPrimitive(t){switch(typeof t){case"string":return t;case"boolean":return t?"true":"false";case"number":return isFinite(t)?t:"";default:return""}}function stringify(t,e,r,n){return e=e||"&",r=r||"=",null===t&&(t=void 0),"object"==typeof t?map$1(objectKeys(t),(function(n){var i=encodeURIComponent(stringifyPrimitive(n))+r;return isArray$2(t[n])?map$1(t[n],(function(t){return i+encodeURIComponent(stringifyPrimitive(t))})).join(e):i+encodeURIComponent(stringifyPrimitive(t[n]))})).join(e):n?encodeURIComponent(stringifyPrimitive(n))+r+encodeURIComponent(stringifyPrimitive(t)):""}function map$1(t,e){if(t.map)return t.map(e);for(var r=[],n=0;n<t.length;n++)r.push(e(t[n],n));return r}var objectKeys=Object.keys||function(t){var e=[];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.push(r);return e};function parse(t,e,r,n){e=e||"&",r=r||"=";var i={};if("string"!=typeof t||0===t.length)return i;var o=/\+/g;t=t.split(e);var s=1e3;n&&"number"==typeof n.maxKeys&&(s=n.maxKeys);var a=t.length;s>0&&a>s&&(a=s);for(var u=0;u<a;++u){var h,c,l,f,m=t[u].replace(o,"%20"),p=m.indexOf(r);p>=0?(h=m.substr(0,p),c=m.substr(p+1)):(h=m,c=""),l=decodeURIComponent(h),f=decodeURIComponent(c),hasOwnProperty$1(i,l)?isArray$2(i[l])?i[l].push(f):i[l]=[i[l],f]:i[l]=f}return i}function Url(){this.protocol=null,this.slashes=null,this.auth=null,this.host=null,this.port=null,this.hostname=null,this.hash=null,this.search=null,this.query=null,this.pathname=null,this.path=null,this.href=null}var protocolPattern=/^([a-z0-9.+-]+:)/i,portPattern=/:[0-9]*$/,simplePathPattern=/^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,delims=["<",">",'"',"`"," ","\r","\n","\t"],unwise=["{","}","|","\\","^","`"].concat(delims),autoEscape=["'"].concat(unwise),nonHostChars=["%","/","?",";","#"].concat(autoEscape),hostEndingChars=["/","?","#"],hostnameMaxLen=255,hostnamePartPattern=/^[+a-z0-9A-Z_-]{0,63}$/,hostnamePartStart=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,unsafeProtocol={javascript:!0,"javascript:":!0},hostlessProtocol={javascript:!0,"javascript:":!0},slashedProtocol={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0};function urlParse(t,e,r){if(t&&isObject(t)&&t instanceof Url)return t;var n=new Url;return n.parse(t,e,r),n}function parse$1(t,e,r,n){if(!isString(e))throw new TypeError("Parameter 'url' must be a string, not "+typeof e);var i=e.indexOf("?"),o=-1!==i&&i<e.indexOf("#")?"?":"#",s=e.split(o);s[0]=s[0].replace(/\\/g,"/");var a=e=s.join(o);if(a=a.trim(),!n&&1===e.split("#").length){var u=simplePathPattern.exec(a);if(u)return t.path=a,t.href=a,t.pathname=u[1],u[2]?(t.search=u[2],t.query=r?parse(t.search.substr(1)):t.search.substr(1)):r&&(t.search="",t.query={}),t}var h,c,l,f,m=protocolPattern.exec(a);if(m){var p=(m=m[0]).toLowerCase();t.protocol=p,a=a.substr(m.length)}if(n||m||a.match(/^\/\/[^@\/]+@[^@\/]+/)){var d="//"===a.substr(0,2);!d||m&&hostlessProtocol[m]||(a=a.substr(2),t.slashes=!0)}if(!hostlessProtocol[m]&&(d||m&&!slashedProtocol[m])){var g,v,w=-1;for(h=0;h<hostEndingChars.length;h++)-1!==(c=a.indexOf(hostEndingChars[h]))&&(-1===w||c<w)&&(w=c);for(-1!==(v=-1===w?a.lastIndexOf("@"):a.lastIndexOf("@",w))&&(g=a.slice(0,v),a=a.slice(v+1),t.auth=decodeURIComponent(g)),w=-1,h=0;h<nonHostChars.length;h++)-1!==(c=a.indexOf(nonHostChars[h]))&&(-1===w||c<w)&&(w=c);-1===w&&(w=a.length),t.host=a.slice(0,w),a=a.slice(w),parseHost(t),t.hostname=t.hostname||"";var y="["===t.hostname[0]&&"]"===t.hostname[t.hostname.length-1];if(!y){var b=t.hostname.split(/\./);for(h=0,l=b.length;h<l;h++){var x=b[h];if(x&&!x.match(hostnamePartPattern)){for(var M="",_=0,$=x.length;_<$;_++)x.charCodeAt(_)>127?M+="x":M+=x[_];if(!M.match(hostnamePartPattern)){var S=b.slice(0,h),R=b.slice(h+1),E=x.match(hostnamePartStart);E&&(S.push(E[1]),R.unshift(E[2])),R.length&&(a="/"+R.join(".")+a),t.hostname=S.join(".");break}}}}t.hostname.length>hostnameMaxLen?t.hostname="":t.hostname=t.hostname.toLowerCase(),y||(t.hostname=toASCII(t.hostname)),f=t.port?":"+t.port:"";var C=t.hostname||"";t.host=C+f,t.href+=t.host,y&&(t.hostname=t.hostname.substr(1,t.hostname.length-2),"/"!==a[0]&&(a="/"+a))}if(!unsafeProtocol[p])for(h=0,l=autoEscape.length;h<l;h++){var k=autoEscape[h];if(-1!==a.indexOf(k)){var A=encodeURIComponent(k);A===k&&(A=escape(k)),a=a.split(k).join(A)}}var T=a.indexOf("#");-1!==T&&(t.hash=a.substr(T),a=a.slice(0,T));var O=a.indexOf("?");if(-1!==O?(t.search=a.substr(O),t.query=a.substr(O+1),r&&(t.query=parse(t.query)),a=a.slice(0,O)):r&&(t.search="",t.query={}),a&&(t.pathname=a),slashedProtocol[p]&&t.hostname&&!t.pathname&&(t.pathname="/"),t.pathname||t.search){f=t.pathname||"";var I=t.search||"";t.path=f+I}return t.href=format$1(t),t}function format$1(t){var e=t.auth||"";e&&(e=(e=encodeURIComponent(e)).replace(/%3A/i,":"),e+="@");var r=t.protocol||"",n=t.pathname||"",i=t.hash||"",o=!1,s="";t.host?o=e+t.host:t.hostname&&(o=e+(-1===t.hostname.indexOf(":")?t.hostname:"["+this.hostname+"]"),t.port&&(o+=":"+t.port)),t.query&&isObject(t.query)&&Object.keys(t.query).length&&(s=stringify(t.query));var a=t.search||s&&"?"+s||"";return r&&":"!==r.substr(-1)&&(r+=":"),t.slashes||(!r||slashedProtocol[r])&&!1!==o?(o="//"+(o||""),n&&"/"!==n.charAt(0)&&(n="/"+n)):o||(o=""),i&&"#"!==i.charAt(0)&&(i="#"+i),a&&"?"!==a.charAt(0)&&(a="?"+a),r+o+(n=n.replace(/[?#]/g,(function(t){return encodeURIComponent(t)})))+(a=a.replace("#","%23"))+i}function parseHost(t){var e=t.host,r=portPattern.exec(e);r&&(":"!==(r=r[0])&&(t.port=r.substr(1)),e=e.substr(0,e.length-r.length)),e&&(t.hostname=e)}function request(t,e){"string"==typeof t&&(t=urlParse(t));var r=-1===global$1.location.protocol.search(/^https?:$/)?"http:":"",n=t.protocol||r,i=t.hostname||t.host,o=t.port,s=t.path||"/";i&&-1!==i.indexOf(":")&&(i="["+i+"]"),t.url=(i?n+"//"+i:"")+(o?":"+o:"")+s,t.method=(t.method||"GET").toUpperCase(),t.headers=t.headers||{};var a=new ClientRequest(t);return e&&a.on("response",e),a}function get(t,e){var r=request(t,e);return r.end(),r}function Agent(){}Url.prototype.parse=function(t,e,r){return parse$1(this,t,e,r)},Url.prototype.format=function(){return format$1(this)},Url.prototype.resolve=function(t){return this.resolveObject(urlParse(t,!1,!0)).format()},Url.prototype.resolveObject=function(t){if(isString(t)){var e=new Url;e.parse(t,!1,!0),t=e}for(var r,n=new Url,i=Object.keys(this),o=0;o<i.length;o++){var s=i[o];n[s]=this[s]}if(n.hash=t.hash,""===t.href)return n.href=n.format(),n;if(t.slashes&&!t.protocol){for(var a=Object.keys(t),u=0;u<a.length;u++){var h=a[u];"protocol"!==h&&(n[h]=t[h])}return slashedProtocol[n.protocol]&&n.hostname&&!n.pathname&&(n.path=n.pathname="/"),n.href=n.format(),n}if(t.protocol&&t.protocol!==n.protocol){if(!slashedProtocol[t.protocol]){for(var c=Object.keys(t),l=0;l<c.length;l++){var f=c[l];n[f]=t[f]}return n.href=n.format(),n}if(n.protocol=t.protocol,t.host||hostlessProtocol[t.protocol])n.pathname=t.pathname;else{for(r=(t.pathname||"").split("/");r.length&&!(t.host=r.shift()););t.host||(t.host=""),t.hostname||(t.hostname=""),""!==r[0]&&r.unshift(""),r.length<2&&r.unshift(""),n.pathname=r.join("/")}if(n.search=t.search,n.query=t.query,n.host=t.host||"",n.auth=t.auth,n.hostname=t.hostname||t.host,n.port=t.port,n.pathname||n.search){var m=n.pathname||"",p=n.search||"";n.path=m+p}return n.slashes=n.slashes||t.slashes,n.href=n.format(),n}var d,g=n.pathname&&"/"===n.pathname.charAt(0),v=t.host||t.pathname&&"/"===t.pathname.charAt(0),w=v||g||n.host&&t.pathname,y=w,b=n.pathname&&n.pathname.split("/")||[],x=n.protocol&&!slashedProtocol[n.protocol];if(r=t.pathname&&t.pathname.split("/")||[],x&&(n.hostname="",n.port=null,n.host&&(""===b[0]?b[0]=n.host:b.unshift(n.host)),n.host="",t.protocol&&(t.hostname=null,t.port=null,t.host&&(""===r[0]?r[0]=t.host:r.unshift(t.host)),t.host=null),w=w&&(""===r[0]||""===b[0])),v)n.host=t.host||""===t.host?t.host:n.host,n.hostname=t.hostname||""===t.hostname?t.hostname:n.hostname,n.search=t.search,n.query=t.query,b=r;else if(r.length)b||(b=[]),b.pop(),b=b.concat(r),n.search=t.search,n.query=t.query;else if(!isNullOrUndefined(t.search))return x&&(n.hostname=n.host=b.shift(),(d=!!(n.host&&n.host.indexOf("@")>0)&&n.host.split("@"))&&(n.auth=d.shift(),n.host=n.hostname=d.shift())),n.search=t.search,n.query=t.query,isNull(n.pathname)&&isNull(n.search)||(n.path=(n.pathname?n.pathname:"")+(n.search?n.search:"")),n.href=n.format(),n;if(!b.length)return n.pathname=null,n.search?n.path="/"+n.search:n.path=null,n.href=n.format(),n;for(var M=b.slice(-1)[0],_=(n.host||t.host||b.length>1)&&("."===M||".."===M)||""===M,$=0,S=b.length;S>=0;S--)"."===(M=b[S])?b.splice(S,1):".."===M?(b.splice(S,1),$++):$&&(b.splice(S,1),$--);if(!w&&!y)for(;$--;$)b.unshift("..");!w||""===b[0]||b[0]&&"/"===b[0].charAt(0)||b.unshift(""),_&&"/"!==b.join("/").substr(-1)&&b.push("");var R=""===b[0]||b[0]&&"/"===b[0].charAt(0);return x&&(n.hostname=n.host=R?"":b.length?b.shift():"",(d=!!(n.host&&n.host.indexOf("@")>0)&&n.host.split("@"))&&(n.auth=d.shift(),n.host=n.hostname=d.shift())),(w=w||n.host&&b.length)&&!R&&b.unshift(""),b.length?n.pathname=b.join("/"):(n.pathname=null,n.path=null),isNull(n.pathname)&&isNull(n.search)||(n.path=(n.pathname?n.pathname:"")+(n.search?n.search:"")),n.auth=t.auth||n.auth,n.slashes=n.slashes||t.slashes,n.href=n.format(),n},Url.prototype.parseHost=function(){return parseHost(this)},Agent.defaultMaxSockets=4;var METHODS=["CHECKOUT","CONNECT","COPY","DELETE","GET","HEAD","LOCK","M-SEARCH","MERGE","MKACTIVITY","MKCOL","MOVE","NOTIFY","OPTIONS","PATCH","POST","PROPFIND","PROPPATCH","PURGE","PUT","REPORT","SEARCH","SUBSCRIBE","TRACE","UNLOCK","UNSUBSCRIBE"],STATUS_CODES={100:"Continue",101:"Switching Protocols",102:"Processing",200:"OK",201:"Created",202:"Accepted",203:"Non-Authoritative Information",204:"No Content",205:"Reset Content",206:"Partial Content",207:"Multi-Status",300:"Multiple Choices",301:"Moved Permanently",302:"Moved Temporarily",303:"See Other",304:"Not Modified",305:"Use Proxy",307:"Temporary Redirect",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Time-out",409:"Conflict",410:"Gone",411:"Length Required",412:"Precondition Failed",413:"Request Entity Too Large",414:"Request-URI Too Large",415:"Unsupported Media Type",416:"Requested Range Not Satisfiable",417:"Expectation Failed",418:"I'm a teapot",422:"Unprocessable Entity",423:"Locked",424:"Failed Dependency",425:"Unordered Collection",426:"Upgrade Required",428:"Precondition Required",429:"Too Many Requests",431:"Request Header Fields Too Large",500:"Internal Server Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Gateway Time-out",505:"HTTP Version Not Supported",506:"Variant Also Negotiates",507:"Insufficient Storage",509:"Bandwidth Limit Exceeded",510:"Not Extended",511:"Network Authentication Required"},http={request:request,get:get,Agent:Agent,METHODS:METHODS,STATUS_CODES:STATUS_CODES},http$1=Object.freeze({request:request,get:get,Agent:Agent,METHODS:METHODS,STATUS_CODES:STATUS_CODES,default:http}),commonjsGlobal="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function commonjsRequire(){throw new Error("Dynamic requires are not currently supported by rollup-plugin-commonjs")}function unwrapExports(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function createCommonjsModule(t,e){return t(e={exports:{}},e.exports),e.exports}var validUrl=createCommonjsModule((function(t){!function(t){t.exports.is_uri=r,t.exports.is_http_uri=n,t.exports.is_https_uri=i,t.exports.is_web_uri=o,t.exports.isUri=r,t.exports.isHttpUri=n,t.exports.isHttpsUri=i,t.exports.isWebUri=o;var e=function(t){return t.match(/(?:([^:\/?#]+):)?(?:\/\/([^\/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?/)};function r(t){if(t&&!/[^a-z0-9\:\/\?\#\[\]\@\!\$\&\'\(\)\*\+\,\;\=\.\-\_\~\%]/i.test(t)&&!/%[^0-9a-f]/i.test(t)&&!/%[0-9a-f](:?[^0-9a-f]|$)/i.test(t)){var r,n,i,o,s,a="",u="";if(a=(r=e(t))[1],n=r[2],i=r[3],o=r[4],s=r[5],a&&a.length&&i.length>=0){if(n&&n.length){if(0!==i.length&&!/^\//.test(i))return}else if(/^\/\//.test(i))return;if(/^[a-z][a-z0-9\+\-\.]*$/.test(a.toLowerCase()))return u+=a+":",n&&n.length&&(u+="//"+n),u+=i,o&&o.length&&(u+="?"+o),s&&s.length&&(u+="#"+s),u}}}function n(t,n){if(r(t)){var i,o,s,a,u="",h="",c="",l="";if(u=(i=e(t))[1],h=i[2],o=i[3],s=i[4],a=i[5],u){if(n){if("https"!=u.toLowerCase())return}else if("http"!=u.toLowerCase())return;if(h)return/:(\d+)$/.test(h)&&(c=h.match(/:(\d+)$/)[0],h=h.replace(/:\d+$/,"")),l+=u+":",l+="//"+h,c&&(l+=c),l+=o,s&&s.length&&(l+="?"+s),a&&a.length&&(l+="#"+a),l}}}function i(t){return n(t,!0)}function o(t){return n(t)||i(t)}}(t)})),_endianness;function endianness(){if(void 0===_endianness){var t=new ArrayBuffer(2),e=new Uint8Array(t),r=new Uint16Array(t);if(e[0]=1,e[1]=2,258===r[0])_endianness="BE";else{if(513!==r[0])throw new Error("unable to figure out endianess");_endianness="LE"}}return _endianness}function hostname(){return void 0!==global$1.location?global$1.location.hostname:""}function loadavg(){return[]}function uptime$1(){return 0}function freemem(){return Number.MAX_VALUE}function totalmem(){return Number.MAX_VALUE}function cpus(){return[]}function type(){return"Browser"}function release$1(){return void 0!==global$1.navigator?global$1.navigator.appVersion:""}function networkInterfaces(){}function getNetworkInterfaces(){}function arch(){return"javascript"}function platform$1(){return"browser"}function tmpDir(){return"/tmp"}var tmpdir=tmpDir,EOL="\n",os={EOL:EOL,tmpdir:tmpdir,tmpDir:tmpDir,networkInterfaces:networkInterfaces,getNetworkInterfaces:getNetworkInterfaces,release:release$1,type:type,cpus:cpus,totalmem:totalmem,freemem:freemem,uptime:uptime$1,loadavg:loadavg,hostname:hostname,endianness:endianness},os$1=Object.freeze({endianness:endianness,hostname:hostname,loadavg:loadavg,uptime:uptime$1,freemem:freemem,totalmem:totalmem,cpus:cpus,type:type,release:release$1,networkInterfaces:networkInterfaces,getNetworkInterfaces:getNetworkInterfaces,arch:arch,platform:platform$1,tmpDir:tmpDir,tmpdir:tmpdir,EOL:EOL,default:os}),isUtf8=createCommonjsModule((function(t,e){t.exports=function(t){for(var e=0;e<t.length;)if(9==t[e]||10==t[e]||13==t[e]||32<=t[e]&&t[e]<=126)e+=1;else if(194<=t[e]&&t[e]<=223&&128<=t[e+1]&&t[e+1]<=191)e+=2;else if(224==t[e]&&160<=t[e+1]&&t[e+1]<=191&&128<=t[e+2]&&t[e+2]<=191||(225<=t[e]&&t[e]<=236||238==t[e]||239==t[e])&&128<=t[e+1]&&t[e+1]<=191&&128<=t[e+2]&&t[e+2]<=191||237==t[e]&&128<=t[e+1]&&t[e+1]<=159&&128<=t[e+2]&&t[e+2]<=191)e+=3;else{if(!(240==t[e]&&144<=t[e+1]&&t[e+1]<=191&&128<=t[e+2]&&t[e+2]<=191&&128<=t[e+3]&&t[e+3]<=191||241<=t[e]&&t[e]<=243&&128<=t[e+1]&&t[e+1]<=191&&128<=t[e+2]&&t[e+2]<=191&&128<=t[e+3]&&t[e+3]<=191||244==t[e]&&128<=t[e+1]&&t[e+1]<=143&&128<=t[e+2]&&t[e+2]<=191&&128<=t[e+3]&&t[e+3]<=191))return!1;e+=4}return!0}})),util$2=util$1&&util||util$1,require$$0=stream&&Stream||stream,Transform$1=require$$0.Transform;function ctor(t,e){if(util$2.inherits(r,Transform$1),"function"==typeof t&&(e=t,t={}),"function"!=typeof e)throw new Error("transform function required");function r(e){if(!(this instanceof r))return new r(e);Transform$1.call(this,e),this._firstChunk=!0,this._transformCalled=!1,this._minSize=t.minSize}return r.prototype._transform=function(t,r,n){return this._enc=r,this._firstChunk?(this._firstChunk=!1,null==this._minSize?(e.call(this,t,r,n),void(this._transformCalled=!0)):(this._buffer=t,void n())):null==this._minSize?(this.push(t),void n()):this._buffer.length<this._minSize?(this._buffer=Buffer.concat([this._buffer,t]),void n()):this._buffer.length>=this._minSize?(e.call(this,this._buffer.slice(),r,function(){this.push(t),n()}.bind(this)),this._transformCalled=!0,void(this._buffer=!1)):(this.push(t),void n())},r.prototype._flush=function(t){this._buffer?this._transformCalled?(this.push(this._buffer),t()):e.call(this,this._buffer.slice(),this._enc,t):t()},r}var firstChunkStream=function(){return ctor.apply(ctor,arguments)()},ctor_1=ctor;firstChunkStream.ctor=ctor_1;var stripBom_1=createCommonjsModule((function(t){var e=t.exports=function(t){return"string"==typeof t?t.replace(/^\ufeff/g,""):isBuffer(t)&&isUtf8(t)&&239===t[0]&&187===t[1]&&191===t[2]?t.slice(3):t};e.stream=function(){return firstChunkStream({minSize:3},(function(t,r,n){this.push(e(t)),n()}))}})),numExp=/^[0-9]+$/,defParam=function(t){var e={constructResult:!0,delimiter:",",ignoreColumns:[],includeColumns:[],quote:'"',trim:!0,checkType:!1,toArrayString:!1,ignoreEmpty:!1,workerNum:getEnv("CSV_WORKER",1),fork:!1,noheader:!1,headers:null,flatKeys:!1,maxRowLength:0,checkColumn:!1,escape:'"',colParser:{},_columnConv:[],_headerType:[],_headerTitle:[],_headerFlag:[],_headers:null,_needFilterRow:!1};for(var r in t||(t={}),t)t.hasOwnProperty(r)&&(e[r]=t[r]);return e.ignoreColumns.length>0&&!numExp.test(e.ignoreColumns.join(""))&&(e._postIgnoreColumns=!0),e.includeColumns.length>0&&!numExp.test(e.includeColumns.join(""))&&(e._postIncludeColumns=!0),(e.ignoreColumns.length||e.includeColumns.length)&&(e._needFilterRow=!0,e._postIgnoreColumns||e.ignoreColumns.sort((function(t,e){return e-t}))),e};function getEnv(t,e){return process.env[t]?process.env[t]:e}var require$$0$1=os$1&&os||os$1,eol=require$$0$1.EOL,getEol=function(t,e){if(!e.eol&&t)for(var r=0,n=t.length;r<n;r++){if("\r"===t[r])return"\n"===t[r+1]?e.eol="\r\n":t[r+1]&&(e.eol="\r"),e.eol;if("\n"===t[r])return e.eol="\n",e.eol}return e.eol},fileline=function(t,e){var r=getEol(t,e),n=t.split(r),i=n.pop();return{lines:n,partial:i}},getDelimiter_1=getDelimiter,defaulDelimiters=[",","|","\t",";",":"];function getDelimiter(t,e){var r;if("auto"===e.delimiter)r=defaulDelimiters;else{if(!(e.delimiter instanceof Array))return e.delimiter;r=e.delimiter}var n=0,i=",";return r.forEach((function(e){var r=t.split(e).length;r>n&&(i=e,n=r)})),i}var filterRow=function(t,e){if(e.ignoreColumns instanceof Array&&e.ignoreColumns.length>0)for(var r=0,n=e.ignoreColumns.length;r<n;r++)e.ignoreColumns[r]>=0&&t.splice(e.ignoreColumns[r],1);if(e.includeColumns instanceof Array&&e.includeColumns.length>0){for(var i=[],o=0,s=e.includeColumns.length;o<s;o++)e.includeColumns[o]>=0&&i.push(t[e.includeColumns[o]]);t=i}return t},rowSplit=function(t,e){if(""===t)return{cols:[],closed:!0};var r=e.quote,n=e.trim,i=e.escape;(e.delimiter instanceof Array||"auto"===e.delimiter.toLowerCase())&&(e.delimiter=getDelimiter_1(t,e));var o=e.delimiter,s=t.split(o);if("off"===r)return{cols:s,closed:!0};for(var a=[],u=!1,h="",c=0,l=s.length;c<l;c++){var f=s[c];!u&&n&&(f=f.trim());var m=f.length;if(u)isQuoteClose(f,e)?(u=!1,h=_escapeQuote(h+=o+(f=f.substr(0,m-1)),r,i),n&&(h=h.trimRight()),a.push(h),h=""):h+=o+f;else{if(isQuoteOpen(f,e)){if(isQuoteClose(f=f.substr(1),e)){f=_escapeQuote(f=f.substring(0,f.length-1),r,i),a.push(f);continue}u=!0,h+=f;continue}a.push(f)}}return!u&&e._needFilterRow&&(a=filterRow(a,e)),{cols:a,closed:!u}};function isQuoteOpen(t,e){var r=e.quote,n=e.escape;return t[0]===r&&(t[1]!==r||t[1]===n&&(t[2]===r||2===t.length))}function isQuoteClose(t,e){for(var r=e.quote,n=0,i=t.length-1,o=e.escape;t[i]===r||t[i]===o;)i--,n++;return n%2!=0}var cachedRegExp={};function _escapeQuote(t,e,r){var n="es|"+e+"|"+r;void 0===cachedRegExp[n]&&(cachedRegExp[n]=new RegExp("\\"+r+"\\"+e,"g"));var i=cachedRegExp[n];return t.replace(i,e)}var csvline=function(t,e){for(var r=[],n="";t.length;){var i=n+t.shift(),o=rowSplit(i,e);o.closed?(r.push(o.cols),n=""):n=i+(getEol(i,e)||"\n")}return{lines:r,partial:n}},fileLineToCSVLine=function(t,e){var r=t.lines,n=csvline(r,e);return{lines:n.lines,partial:n.partial+t.partial}},explicitTypes=["number","string"];function Parser(t,e,r,n){this.name=void 0===t?"Default":t,this.regExp=null,this.type="",this.processSafe=n,void 0!==e&&(this.regExp="string"==typeof e?new RegExp(e):e),void 0!==r&&(this.parse=r)}Parser.prototype.convertType=function(t){var e=this.type;if("number"===e){var r=parseFloat(t);return isNaN(r)?0:r}if(this.param&&this.param.checkType&&""===e){var n=t.trim();if(""===n)return n;if(!isNaN(n))return parseFloat(n);if(5===n.length&&"false"===n.toLowerCase())return!1;if(4===n.length&&"true"===n.toLowerCase())return!0;if(!("{"===n[0]&&"}"===n[n.length-1]||"["===n[0]&&"]"===n[n.length-1]))return t;try{return JSON.parse(n)}catch(e){return t}}return t},Parser.prototype.setParam=function(t){this.param=t},Parser.prototype.test=function(t){return this.regExp&&this.regExp.test(t)},Parser.prototype.parse=function(t){t.resultRow[t.head]=t.item},Parser.prototype.getHeadStr=function(){if(this.headStr)return this.headStr;var t=this.head;return this.headStr=t.replace(this.regExp,""),this.headStr||(this.headStr="Unknown Header"),this.getHeadStr()},Parser.prototype.getHead=function(){return this.head},Parser.prototype.initHead=function(t){this.head=t;var e=t.replace(this.regExp,""),r=e.split("#!");if(1===r.length)this.headStr=r[0];else{var n=r.shift();explicitTypes.indexOf(n.toLowerCase())>-1?(this.type=n,this.headStr=r.join("#!")):this.headStr=e}this.headStr||(this.headStr=e||"Unknown Head")},Parser.prototype.clone=function(){var t=Object.create(this),e=new Parser;for(var r in t)e[r]=t[r];return e},Parser.prototype.getName=function(){return this.name};var parser=Parser,parser_array={name:"array",processSafe:!0,regExp:/^\*array\*/,parserFunc:function(t){var e=t.head.replace(this.regExp,"");void 0===t.resultRow[e]&&(t.resultRow[e]=[]),t.resultRow[e].push(t.item)}},arrReg=/\[([0-9]*)\]/;function processHead(t,e,r,n){for(var i,o,s;e.length>1;)i=e.shift(),(o=!n&&i.match(r))?(void 0===t[i.replace(o[0],"")]&&(t[i.replace(o[0],"")]=[]),s=o[1],t=t[i.replace(o[0],"")],""===s&&(s=t.length),t[s]||(t[s]={}),t=t[s]):(void 0===t[i]&&(t[i]={}),t=t[i]);return t}var parser_json={name:"json",processSafe:!0,regExp:/^\*json\*/,parserFunc:function(t){var e,r,n,i=this.getHeadStr(),o=t.config&&t.config.flatKeys?[i]:i.split("."),s=processHead(t.resultRow,o,arrReg,t.config&&t.config.flatKeys);if(n=o.shift(),e=(!t.config||!t.config.flatKeys)&&n.match(arrReg))try{s[n=n.replace(e[0],"")]&&s[n]instanceof Array||(s[n]=[]),s[n]?(""===(r=e[1])&&(r=s[n].length),s[n][r]=t.item):t.resultRow[i]=t.item}catch(e){t.resultRow[i]=t.item}else"string"==typeof s?t.resultRow[i]=t.item:s[n]=t.item}},parser_omit={name:"omit",regExp:/^\*omit\*/,processSafe:!0,parserFunc:function(){}},parser_jsonarray={name:"jsonarray",processSafe:!0,regExp:/^\*jsonarray\*/,parserFunc:function(t){for(var e=t.head.replace(this.regExp,"").split("."),r=t.resultRow;e.length>1;){var n=e.shift();void 0===r[n]&&(r[n]={}),r=r[n]}var i=e.shift();void 0===r[i]&&(r[i]=[]),r[i].push(t.item)}},parser_flat={name:"flat",processSafe:!0,regExp:/^\*flat\*/,parserFunc:function(t){var e=this.getHeadStr(),r=t.item;t.resultRow[e]=r}},defaultParsers=[parser_array,parser_json,parser_omit,parser_jsonarray,parser_flat],registeredParsers=[];function registerParser(t){t instanceof parser&&-1===registeredParsers.indexOf(t)&&registeredParsers.push(t)}function getParser(t,e){var r,n;return t=t||"",registeredParsers.forEach((function(e){e.test(t)&&(n=e)})),n?(r=n.clone()).head=t:r=function(t){var e;return registeredParsers.forEach((function(r){r.getName()===t&&(e=r)})),e?e.clone():new parser}("json"),r.setParam(e),r.initHead(t),r}function addParser(t,e,r){registerParser(new parser(t,e,r,!1))}function initParsers(t,e){var r=[];return t.forEach((function(t){r.push(getParser(t,e))})),r}defaultParsers.forEach((function(t){addParser(t.name,t.regExp,t.parserFunc,t.processSafe)}));var addParser_1=addParser,initParsers_1=initParsers,getParser_1=getParser,parserMgr={addParser:addParser_1,initParsers:initParsers_1,getParser:getParser_1},CSVError_1=CSVError;function CSVError(t,e,r){Error.call(this,""),this.err=t,this.line=e,this.extra=r,this.message="Error: "+t+". JSON Line number: "+e+(r?" near: "+r:""),this.name="CSV Error"}util$2.inherits(CSVError,Error),CSVError.prototype.toString=function(){return JSON.stringify([this.err,this.line,this.extra])},CSVError.column_mismatched=function(t,e){return new CSVError("column_mismatched",t,e)},CSVError.unclosed_quote=function(t,e){return new CSVError("unclosed_quote",t,e)},CSVError.fromArray=function(t){return new CSVError(t[0],t[1],t[2])};var freeGlobal="object"==typeof commonjsGlobal&&commonjsGlobal&&commonjsGlobal.Object===Object&&commonjsGlobal,_freeGlobal=freeGlobal,freeSelf="object"==typeof self&&self&&self.Object===Object&&self,root=_freeGlobal||freeSelf||Function("return this")(),_root=root,Symbol$1=_root.Symbol,_Symbol=Symbol$1,objectProto=Object.prototype,hasOwnProperty$2=objectProto.hasOwnProperty,nativeObjectToString=objectProto.toString,symToStringTag=_Symbol?_Symbol.toStringTag:void 0;function getRawTag(t){var e=hasOwnProperty$2.call(t,symToStringTag),r=t[symToStringTag];try{t[symToStringTag]=void 0}catch(t){}var n=nativeObjectToString.call(t);return e?t[symToStringTag]=r:delete t[symToStringTag],n}var _getRawTag=getRawTag,objectProto$1=Object.prototype,nativeObjectToString$1=objectProto$1.toString;function objectToString$1(t){return nativeObjectToString$1.call(t)}var _objectToString=objectToString$1,nullTag="[object Null]",undefinedTag="[object Undefined]",symToStringTag$1=_Symbol?_Symbol.toStringTag:void 0;function baseGetTag(t){return null==t?void 0===t?undefinedTag:nullTag:symToStringTag$1&&symToStringTag$1 in Object(t)?_getRawTag(t):_objectToString(t)}var _baseGetTag=baseGetTag;function isObject$1(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}var isObject_1=isObject$1,asyncTag="[object AsyncFunction]",funcTag="[object Function]",genTag="[object GeneratorFunction]",proxyTag="[object Proxy]";function isFunction$2(t){if(!isObject_1(t))return!1;var e=_baseGetTag(t);return e==funcTag||e==genTag||e==asyncTag||e==proxyTag}var isFunction_1=isFunction$2,coreJsData=_root["__core-js_shared__"],_coreJsData=coreJsData,maskSrcKey=(uid=/[^.]+$/.exec(_coreJsData&&_coreJsData.keys&&_coreJsData.keys.IE_PROTO||""),uid?"Symbol(src)_1."+uid:""),uid;function isMasked(t){return!!maskSrcKey&&maskSrcKey in t}var _isMasked=isMasked,funcProto=Function.prototype,funcToString=funcProto.toString;function toSource(t){if(null!=t){try{return funcToString.call(t)}catch(t){}try{return t+""}catch(t){}}return""}var _toSource=toSource,reRegExpChar=/[\\^$.*+?()[\]{}|]/g,reIsHostCtor=/^\[object .+?Constructor\]$/,funcProto$1=Function.prototype,objectProto$2=Object.prototype,funcToString$1=funcProto$1.toString,hasOwnProperty$3=objectProto$2.hasOwnProperty,reIsNative=RegExp("^"+funcToString$1.call(hasOwnProperty$3).replace(reRegExpChar,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function baseIsNative(t){return!(!isObject_1(t)||_isMasked(t))&&(isFunction_1(t)?reIsNative:reIsHostCtor).test(_toSource(t))}var _baseIsNative=baseIsNative;function getValue(t,e){return null==t?void 0:t[e]}var _getValue=getValue;function getNative(t,e){var r=_getValue(t,e);return _baseIsNative(r)?r:void 0}var _getNative=getNative,defineProperty=function(){try{var t=_getNative(Object,"defineProperty");return t({},"",{}),t}catch(t){}}(),_defineProperty=defineProperty;function baseAssignValue(t,e,r){"__proto__"==e&&_defineProperty?_defineProperty(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r}var _baseAssignValue=baseAssignValue;function eq(t,e){return t===e||t!=t&&e!=e}var eq_1=eq,objectProto$3=Object.prototype,hasOwnProperty$4=objectProto$3.hasOwnProperty;function assignValue(t,e,r){var n=t[e];hasOwnProperty$4.call(t,e)&&eq_1(n,r)&&(void 0!==r||e in t)||_baseAssignValue(t,e,r)}var _assignValue=assignValue,isArray$3=Array.isArray,isArray_1=isArray$3;function isObjectLike(t){return null!=t&&"object"==typeof t}var isObjectLike_1=isObjectLike,symbolTag="[object Symbol]";function isSymbol$1(t){return"symbol"==typeof t||isObjectLike_1(t)&&_baseGetTag(t)==symbolTag}var isSymbol_1=isSymbol$1,reIsDeepProp=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,reIsPlainProp=/^\w*$/;function isKey(t,e){if(isArray_1(t))return!1;var r=typeof t;return!("number"!=r&&"symbol"!=r&&"boolean"!=r&&null!=t&&!isSymbol_1(t))||(reIsPlainProp.test(t)||!reIsDeepProp.test(t)||null!=e&&t in Object(e))}var _isKey=isKey,nativeCreate=_getNative(Object,"create"),_nativeCreate=nativeCreate;function hashClear(){this.__data__=_nativeCreate?_nativeCreate(null):{},this.size=0}var _hashClear=hashClear;function hashDelete(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e}var _hashDelete=hashDelete,HASH_UNDEFINED="__lodash_hash_undefined__",objectProto$4=Object.prototype,hasOwnProperty$5=objectProto$4.hasOwnProperty;function hashGet(t){var e=this.__data__;if(_nativeCreate){var r=e[t];return r===HASH_UNDEFINED?void 0:r}return hasOwnProperty$5.call(e,t)?e[t]:void 0}var _hashGet=hashGet,objectProto$5=Object.prototype,hasOwnProperty$6=objectProto$5.hasOwnProperty;function hashHas(t){var e=this.__data__;return _nativeCreate?void 0!==e[t]:hasOwnProperty$6.call(e,t)}var _hashHas=hashHas,HASH_UNDEFINED$1="__lodash_hash_undefined__";function hashSet(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=_nativeCreate&&void 0===e?HASH_UNDEFINED$1:e,this}var _hashSet=hashSet;function Hash(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}Hash.prototype.clear=_hashClear,Hash.prototype.delete=_hashDelete,Hash.prototype.get=_hashGet,Hash.prototype.has=_hashHas,Hash.prototype.set=_hashSet;var _Hash=Hash;function listCacheClear(){this.__data__=[],this.size=0}var _listCacheClear=listCacheClear;function assocIndexOf(t,e){for(var r=t.length;r--;)if(eq_1(t[r][0],e))return r;return-1}var _assocIndexOf=assocIndexOf,arrayProto=Array.prototype,splice=arrayProto.splice;function listCacheDelete(t){var e=this.__data__,r=_assocIndexOf(e,t);return!(r<0)&&(r==e.length-1?e.pop():splice.call(e,r,1),--this.size,!0)}var _listCacheDelete=listCacheDelete;function listCacheGet(t){var e=this.__data__,r=_assocIndexOf(e,t);return r<0?void 0:e[r][1]}var _listCacheGet=listCacheGet;function listCacheHas(t){return _assocIndexOf(this.__data__,t)>-1}var _listCacheHas=listCacheHas;function listCacheSet(t,e){var r=this.__data__,n=_assocIndexOf(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=e,this}var _listCacheSet=listCacheSet;function ListCache(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}ListCache.prototype.clear=_listCacheClear,ListCache.prototype.delete=_listCacheDelete,ListCache.prototype.get=_listCacheGet,ListCache.prototype.has=_listCacheHas,ListCache.prototype.set=_listCacheSet;var _ListCache=ListCache,Map$1=_getNative(_root,"Map"),_Map=Map$1;function mapCacheClear(){this.size=0,this.__data__={hash:new _Hash,map:new(_Map||_ListCache),string:new _Hash}}var _mapCacheClear=mapCacheClear;function isKeyable(t){var e=typeof t;return"string"==e||"number"==e||"symbol"==e||"boolean"==e?"__proto__"!==t:null===t}var _isKeyable=isKeyable;function getMapData(t,e){var r=t.__data__;return _isKeyable(e)?r["string"==typeof e?"string":"hash"]:r.map}var _getMapData=getMapData;function mapCacheDelete(t){var e=_getMapData(this,t).delete(t);return this.size-=e?1:0,e}var _mapCacheDelete=mapCacheDelete;function mapCacheGet(t){return _getMapData(this,t).get(t)}var _mapCacheGet=mapCacheGet;function mapCacheHas(t){return _getMapData(this,t).has(t)}var _mapCacheHas=mapCacheHas;function mapCacheSet(t,e){var r=_getMapData(this,t),n=r.size;return r.set(t,e),this.size+=r.size==n?0:1,this}var _mapCacheSet=mapCacheSet;function MapCache(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}MapCache.prototype.clear=_mapCacheClear,MapCache.prototype.delete=_mapCacheDelete,MapCache.prototype.get=_mapCacheGet,MapCache.prototype.has=_mapCacheHas,MapCache.prototype.set=_mapCacheSet;var _MapCache=MapCache,FUNC_ERROR_TEXT="Expected a function";function memoize(t,e){if("function"!=typeof t||null!=e&&"function"!=typeof e)throw new TypeError(FUNC_ERROR_TEXT);var r=function(){var n=arguments,i=e?e.apply(this,n):n[0],o=r.cache;if(o.has(i))return o.get(i);var s=t.apply(this,n);return r.cache=o.set(i,s)||o,s};return r.cache=new(memoize.Cache||_MapCache),r}memoize.Cache=_MapCache;var memoize_1=memoize,MAX_MEMOIZE_SIZE=500;function memoizeCapped(t){var e=memoize_1(t,(function(t){return r.size===MAX_MEMOIZE_SIZE&&r.clear(),t})),r=e.cache;return e}var _memoizeCapped=memoizeCapped,rePropName=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,reEscapeChar=/\\(\\)?/g,stringToPath=_memoizeCapped((function(t){var e=[];return 46===t.charCodeAt(0)&&e.push(""),t.replace(rePropName,(function(t,r,n,i){e.push(n?i.replace(reEscapeChar,"$1"):r||t)})),e})),_stringToPath=stringToPath;function arrayMap(t,e){for(var r=-1,n=null==t?0:t.length,i=Array(n);++r<n;)i[r]=e(t[r],r,t);return i}var _arrayMap=arrayMap,INFINITY=1/0,symbolProto=_Symbol?_Symbol.prototype:void 0,symbolToString=symbolProto?symbolProto.toString:void 0;function baseToString(t){if("string"==typeof t)return t;if(isArray_1(t))return _arrayMap(t,baseToString)+"";if(isSymbol_1(t))return symbolToString?symbolToString.call(t):"";var e=t+"";return"0"==e&&1/t==-INFINITY?"-0":e}var _baseToString=baseToString;function toString$1(t){return null==t?"":_baseToString(t)}var toString_1=toString$1;function castPath(t,e){return isArray_1(t)?t:_isKey(t,e)?[t]:_stringToPath(toString_1(t))}var _castPath=castPath,MAX_SAFE_INTEGER=9007199254740991,reIsUint=/^(?:0|[1-9]\d*)$/;function isIndex(t,e){var r=typeof t;return!!(e=null==e?MAX_SAFE_INTEGER:e)&&("number"==r||"symbol"!=r&&reIsUint.test(t))&&t>-1&&t%1==0&&t<e}var _isIndex=isIndex,INFINITY$1=1/0;function toKey(t){if("string"==typeof t||isSymbol_1(t))return t;var e=t+"";return"0"==e&&1/t==-INFINITY$1?"-0":e}var _toKey=toKey;function baseSet(t,e,r,n){if(!isObject_1(t))return t;for(var i=-1,o=(e=_castPath(e,t)).length,s=o-1,a=t;null!=a&&++i<o;){var u=_toKey(e[i]),h=r;if(i!=s){var c=a[u];void 0===(h=n?n(c,u,a):void 0)&&(h=isObject_1(c)?c:_isIndex(e[i+1])?[]:{})}_assignValue(a,u,h),a=a[u]}return t}var _baseSet=baseSet;function set(t,e,r){return null==t?t:_baseSet(t,e,r)}var set_1=set,numReg=/^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?$/,linesToJson=function(t,e,r){if(e._needParseJson){if(e._headers||(e._headers=[]),!e.parseRules){var n=e._headers;e.parseRules=parserMgr.initParsers(n,e)}return processRows(t,e,r)}return justReturnRows(t,e,r)};function justReturnRows(t,e,r){for(var n=[],i=0,o=t.length;i<o;i++)n.push({err:null,json:{},index:r++,row:t[i]});return n}function processRows(t,e,r){for(var n=[],i=0,o=t.length;i<o;i++){var s=processRow(t[i],e,r++);s&&n.push(s)}return n}function processRow(t,e,r){var n=e.parseRules;if(e.checkColumn&&t.length!==n.length)return{err:CSVError_1.column_mismatched(r)};var i=convertRowToJson(t,e._headers,e);return i?{json:i,index:r,row:t}:null}function convertRowToJson(t,e,r){for(var n=!1,i={},o=0,s=t.length;o<s;o++){var a,u;if(u=t[o],!r.ignoreEmpty||""!==u){n=!0,(a=e[o])&&""!==a||(a=e[o]="field"+(o+1));var h=getConvFunc(a,o,r);if(h){var c=h(u,a,i,t,o);void 0!==c&&setPath(i,a,c)}else{var l=getFlag(a,o,r);if("omit"===l)continue;r.checkType&&(u=checkType(u,a,o,r)(u));var f=getTitle(a,o,r);"flat"===l||r.flatKeys?i[f]=u:setPath(i,f,u)}}}return!!n&&i}var builtInConv={string:stringType,number:numberType,omit:function(){}};function getConvFunc(t,e,r){if(void 0!==r._columnConv[e])return r._columnConv[e];var n=r.colParser[t];if(void 0===n)return r._columnConv[e]=!1;if("string"==typeof n){n=n.trim().toLowerCase();var i=builtInConv[n];return r._columnConv[e]=i||!1}return r._columnConv[e]="function"==typeof n&&n}function setPath(t,e,r){var n=set_1;1===e.split(".").length?t[e]=r:n(t,e,r)}function getFlag(t,e,r){return"string"==typeof r._headerFlag[e]?r._headerFlag[e]:t.indexOf("*omit*")>-1?r._headerFlag[e]="omit":t.indexOf("*flat*")>-1?r._headerFlag[e]="flat":r._headerFlag[e]=""}function getTitle(t,e,r){if(r._headerTitle[e])return r._headerTitle[e];getFlag(t,e,r);var n=t.replace("*flat*","").replace("string#!","").replace("number#!","");return r._headerTitle[e]=n}function checkType(t,e,r,n){return n._headerType[r]?n._headerType[r]:e.indexOf("number#!")>-1?n._headerType[r]=numberType:e.indexOf("string#!")>-1?n._headerType[r]=stringType:n.checkType?n._headerType[r]=dynamicType:n._headerType[r]=stringType}function numberType(t){var e=parseFloat(t);return isNaN(e)?t:e}function stringType(t){return t.toString()}function dynamicType(t){var e=t.trim();return""===e?stringType(t):numReg.test(e)?numberType(t):5===e.length&&"false"===e.toLowerCase()||4===e.length&&"true"===e.toLowerCase()?booleanType(t):"{"===e[0]&&"}"===e[e.length-1]||"["===e[0]&&"]"===e[e.length-1]?jsonType(t):stringType(t)}function booleanType(t){var e=t.trim();return 5!==e.length||"false"!==e.toLowerCase()}function jsonType(t){try{return JSON.parse(t)}catch(e){return t}}var lodash=createCommonjsModule((function(t,e){(function(){var r,n="Expected a function",i="__lodash_hash_undefined__",o="__lodash_placeholder__",s=16,a=32,u=64,h=128,c=256,l=1/0,f=9007199254740991,m=NaN,p=4294967295,d=[["ary",h],["bind",1],["bindKey",2],["curry",8],["curryRight",s],["flip",512],["partial",a],["partialRight",u],["rearg",c]],g="[object Arguments]",v="[object Array]",w="[object Boolean]",y="[object Date]",b="[object Error]",x="[object Function]",M="[object GeneratorFunction]",_="[object Map]",$="[object Number]",S="[object Object]",R="[object Promise]",E="[object RegExp]",C="[object Set]",k="[object String]",A="[object Symbol]",T="[object WeakMap]",O="[object ArrayBuffer]",I="[object DataView]",D="[object Float32Array]",P="[object Float64Array]",V="[object Int8Array]",j="[object Int16Array]",L="[object Int32Array]",N="[object Uint8Array]",B="[object Uint8ClampedArray]",F="[object Uint16Array]",z="[object Uint32Array]",q=/\b__p \+= '';/g,U=/\b(__p \+=) '' \+/g,W=/(__e\(.*?\)|\b__t\)) \+\n'';/g,H=/&(?:amp|lt|gt|quot|#39);/g,Y=/[&<>"']/g,G=RegExp(H.source),K=RegExp(Y.source),X=/<%-([\s\S]+?)%>/g,J=/<%([\s\S]+?)%>/g,Q=/<%=([\s\S]+?)%>/g,Z=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,tt=/^\w*$/,et=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,rt=/[\\^$.*+?()[\]{}|]/g,nt=RegExp(rt.source),it=/^\s+|\s+$/g,ot=/^\s+/,st=/\s+$/,at=/\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,ut=/\{\n\/\* \[wrapped with (.+)\] \*/,ht=/,? & /,ct=/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g,lt=/\\(\\)?/g,ft=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,mt=/\w*$/,pt=/^[-+]0x[0-9a-f]+$/i,dt=/^0b[01]+$/i,gt=/^\[object .+?Constructor\]$/,vt=/^0o[0-7]+$/i,wt=/^(?:0|[1-9]\d*)$/,yt=/[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g,bt=/($^)/,xt=/['\n\r\u2028\u2029\\]/g,Mt="\\ud800-\\udfff",_t="\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff",$t="\\u2700-\\u27bf",St="a-z\\xdf-\\xf6\\xf8-\\xff",Rt="A-Z\\xc0-\\xd6\\xd8-\\xde",Et="\\ufe0e\\ufe0f",Ct="\\xac\\xb1\\xd7\\xf7\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf\\u2000-\\u206f \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000",kt="['’]",At="["+Mt+"]",Tt="["+Ct+"]",Ot="["+_t+"]",It="\\d+",Dt="["+$t+"]",Pt="["+St+"]",Vt="[^"+Mt+Ct+It+$t+St+Rt+"]",jt="\\ud83c[\\udffb-\\udfff]",Lt="[^"+Mt+"]",Nt="(?:\\ud83c[\\udde6-\\uddff]){2}",Bt="[\\ud800-\\udbff][\\udc00-\\udfff]",Ft="["+Rt+"]",zt="\\u200d",qt="(?:"+Pt+"|"+Vt+")",Ut="(?:"+Ft+"|"+Vt+")",Wt="(?:['’](?:d|ll|m|re|s|t|ve))?",Ht="(?:['’](?:D|LL|M|RE|S|T|VE))?",Yt="(?:"+Ot+"|"+jt+")"+"?",Gt="["+Et+"]?",Kt=Gt+Yt+("(?:"+zt+"(?:"+[Lt,Nt,Bt].join("|")+")"+Gt+Yt+")*"),Xt="(?:"+[Dt,Nt,Bt].join("|")+")"+Kt,Jt="(?:"+[Lt+Ot+"?",Ot,Nt,Bt,At].join("|")+")",Qt=RegExp(kt,"g"),Zt=RegExp(Ot,"g"),te=RegExp(jt+"(?="+jt+")|"+Jt+Kt,"g"),ee=RegExp([Ft+"?"+Pt+"+"+Wt+"(?="+[Tt,Ft,"$"].join("|")+")",Ut+"+"+Ht+"(?="+[Tt,Ft+qt,"$"].join("|")+")",Ft+"?"+qt+"+"+Wt,Ft+"+"+Ht,"\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])","\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])",It,Xt].join("|"),"g"),re=RegExp("["+zt+Mt+_t+Et+"]"),ne=/[a-z][A-Z]|[A-Z]{2,}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/,ie=["Array","Buffer","DataView","Date","Error","Float32Array","Float64Array","Function","Int8Array","Int16Array","Int32Array","Map","Math","Object","Promise","RegExp","Set","String","Symbol","TypeError","Uint8Array","Uint8ClampedArray","Uint16Array","Uint32Array","WeakMap","_","clearTimeout","isFinite","parseInt","setTimeout"],oe=-1,se={};se[D]=se[P]=se[V]=se[j]=se[L]=se[N]=se[B]=se[F]=se[z]=!0,se[g]=se[v]=se[O]=se[w]=se[I]=se[y]=se[b]=se[x]=se[_]=se[$]=se[S]=se[E]=se[C]=se[k]=se[T]=!1;var ae={};ae[g]=ae[v]=ae[O]=ae[I]=ae[w]=ae[y]=ae[D]=ae[P]=ae[V]=ae[j]=ae[L]=ae[_]=ae[$]=ae[S]=ae[E]=ae[C]=ae[k]=ae[A]=ae[N]=ae[B]=ae[F]=ae[z]=!0,ae[b]=ae[x]=ae[T]=!1;var ue={"\\":"\\","'":"'","\n":"n","\r":"r","\u2028":"u2028","\u2029":"u2029"},he=parseFloat,ce=parseInt,le="object"==typeof commonjsGlobal&&commonjsGlobal&&commonjsGlobal.Object===Object&&commonjsGlobal,fe="object"==typeof self&&self&&self.Object===Object&&self,me=le||fe||Function("return this")(),pe=e&&!e.nodeType&&e,de=pe&&t&&!t.nodeType&&t,ge=de&&de.exports===pe,ve=ge&&le.process,we=function(){try{var t=de&&de.require&&de.require("util").types;return t||ve&&ve.binding&&ve.binding("util")}catch(t){}}(),ye=we&&we.isArrayBuffer,be=we&&we.isDate,xe=we&&we.isMap,Me=we&&we.isRegExp,_e=we&&we.isSet,$e=we&&we.isTypedArray;function Se(t,e,r){switch(r.length){case 0:return t.call(e);case 1:return t.call(e,r[0]);case 2:return t.call(e,r[0],r[1]);case 3:return t.call(e,r[0],r[1],r[2])}return t.apply(e,r)}function Re(t,e,r,n){for(var i=-1,o=null==t?0:t.length;++i<o;){var s=t[i];e(n,s,r(s),t)}return n}function Ee(t,e){for(var r=-1,n=null==t?0:t.length;++r<n&&!1!==e(t[r],r,t););return t}function Ce(t,e){for(var r=null==t?0:t.length;r--&&!1!==e(t[r],r,t););return t}function ke(t,e){for(var r=-1,n=null==t?0:t.length;++r<n;)if(!e(t[r],r,t))return!1;return!0}function Ae(t,e){for(var r=-1,n=null==t?0:t.length,i=0,o=[];++r<n;){var s=t[r];e(s,r,t)&&(o[i++]=s)}return o}function Te(t,e){return!!(null==t?0:t.length)&&Fe(t,e,0)>-1}function Oe(t,e,r){for(var n=-1,i=null==t?0:t.length;++n<i;)if(r(e,t[n]))return!0;return!1}function Ie(t,e){for(var r=-1,n=null==t?0:t.length,i=Array(n);++r<n;)i[r]=e(t[r],r,t);return i}function De(t,e){for(var r=-1,n=e.length,i=t.length;++r<n;)t[i+r]=e[r];return t}function Pe(t,e,r,n){var i=-1,o=null==t?0:t.length;for(n&&o&&(r=t[++i]);++i<o;)r=e(r,t[i],i,t);return r}function Ve(t,e,r,n){var i=null==t?0:t.length;for(n&&i&&(r=t[--i]);i--;)r=e(r,t[i],i,t);return r}function je(t,e){for(var r=-1,n=null==t?0:t.length;++r<n;)if(e(t[r],r,t))return!0;return!1}var Le=We("length");function Ne(t,e,r){var n;return r(t,(function(t,r,i){if(e(t,r,i))return n=r,!1})),n}function Be(t,e,r,n){for(var i=t.length,o=r+(n?1:-1);n?o--:++o<i;)if(e(t[o],o,t))return o;return-1}function Fe(t,e,r){return e==e?function(t,e,r){var n=r-1,i=t.length;for(;++n<i;)if(t[n]===e)return n;return-1}(t,e,r):Be(t,qe,r)}function ze(t,e,r,n){for(var i=r-1,o=t.length;++i<o;)if(n(t[i],e))return i;return-1}function qe(t){return t!=t}function Ue(t,e){var r=null==t?0:t.length;return r?Ge(t,e)/r:m}function We(t){return function(e){return null==e?r:e[t]}}function He(t){return function(e){return null==t?r:t[e]}}function Ye(t,e,r,n,i){return i(t,(function(t,i,o){r=n?(n=!1,t):e(r,t,i,o)})),r}function Ge(t,e){for(var n,i=-1,o=t.length;++i<o;){var s=e(t[i]);s!==r&&(n=n===r?s:n+s)}return n}function Ke(t,e){for(var r=-1,n=Array(t);++r<t;)n[r]=e(r);return n}function Xe(t){return function(e){return t(e)}}function Je(t,e){return Ie(e,(function(e){return t[e]}))}function Qe(t,e){return t.has(e)}function Ze(t,e){for(var r=-1,n=t.length;++r<n&&Fe(e,t[r],0)>-1;);return r}function tr(t,e){for(var r=t.length;r--&&Fe(e,t[r],0)>-1;);return r}var er=He({"À":"A","Á":"A","Â":"A","Ã":"A","Ä":"A","Å":"A","à":"a","á":"a","â":"a","ã":"a","ä":"a","å":"a","Ç":"C","ç":"c","Ð":"D","ð":"d","È":"E","É":"E","Ê":"E","Ë":"E","è":"e","é":"e","ê":"e","ë":"e","Ì":"I","Í":"I","Î":"I","Ï":"I","ì":"i","í":"i","î":"i","ï":"i","Ñ":"N","ñ":"n","Ò":"O","Ó":"O","Ô":"O","Õ":"O","Ö":"O","Ø":"O","ò":"o","ó":"o","ô":"o","õ":"o","ö":"o","ø":"o","Ù":"U","Ú":"U","Û":"U","Ü":"U","ù":"u","ú":"u","û":"u","ü":"u","Ý":"Y","ý":"y","ÿ":"y","Æ":"Ae","æ":"ae","Þ":"Th","þ":"th","ß":"ss","Ā":"A","Ă":"A","Ą":"A","ā":"a","ă":"a","ą":"a","Ć":"C","Ĉ":"C","Ċ":"C","Č":"C","ć":"c","ĉ":"c","ċ":"c","č":"c","Ď":"D","Đ":"D","ď":"d","đ":"d","Ē":"E","Ĕ":"E","Ė":"E","Ę":"E","Ě":"E","ē":"e","ĕ":"e","ė":"e","ę":"e","ě":"e","Ĝ":"G","Ğ":"G","Ġ":"G","Ģ":"G","ĝ":"g","ğ":"g","ġ":"g","ģ":"g","Ĥ":"H","Ħ":"H","ĥ":"h","ħ":"h","Ĩ":"I","Ī":"I","Ĭ":"I","Į":"I","İ":"I","ĩ":"i","ī":"i","ĭ":"i","į":"i","ı":"i","Ĵ":"J","ĵ":"j","Ķ":"K","ķ":"k","ĸ":"k","Ĺ":"L","Ļ":"L","Ľ":"L","Ŀ":"L","Ł":"L","ĺ":"l","ļ":"l","ľ":"l","ŀ":"l","ł":"l","Ń":"N","Ņ":"N","Ň":"N","Ŋ":"N","ń":"n","ņ":"n","ň":"n","ŋ":"n","Ō":"O","Ŏ":"O","Ő":"O","ō":"o","ŏ":"o","ő":"o","Ŕ":"R","Ŗ":"R","Ř":"R","ŕ":"r","ŗ":"r","ř":"r","Ś":"S","Ŝ":"S","Ş":"S","Š":"S","ś":"s","ŝ":"s","ş":"s","š":"s","Ţ":"T","Ť":"T","Ŧ":"T","ţ":"t","ť":"t","ŧ":"t","Ũ":"U","Ū":"U","Ŭ":"U","Ů":"U","Ű":"U","Ų":"U","ũ":"u","ū":"u","ŭ":"u","ů":"u","ű":"u","ų":"u","Ŵ":"W","ŵ":"w","Ŷ":"Y","ŷ":"y","Ÿ":"Y","Ź":"Z","Ż":"Z","Ž":"Z","ź":"z","ż":"z","ž":"z","Ĳ":"IJ","ĳ":"ij","Œ":"Oe","œ":"oe","ŉ":"'n","ſ":"s"}),rr=He({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"});function nr(t){return"\\"+ue[t]}function ir(t){return re.test(t)}function or(t){var e=-1,r=Array(t.size);return t.forEach((function(t,n){r[++e]=[n,t]})),r}function sr(t,e){return function(r){return t(e(r))}}function ar(t,e){for(var r=-1,n=t.length,i=0,s=[];++r<n;){var a=t[r];a!==e&&a!==o||(t[r]=o,s[i++]=r)}return s}function ur(t,e){return"__proto__"==e?r:t[e]}function hr(t){var e=-1,r=Array(t.size);return t.forEach((function(t){r[++e]=t})),r}function cr(t){var e=-1,r=Array(t.size);return t.forEach((function(t){r[++e]=[t,t]})),r}function lr(t){return ir(t)?function(t){var e=te.lastIndex=0;for(;te.test(t);)++e;return e}(t):Le(t)}function fr(t){return ir(t)?function(t){return t.match(te)||[]}(t):function(t){return t.split("")}(t)}var mr=He({"&amp;":"&","&lt;":"<","&gt;":">","&quot;":'"',"&#39;":"'"});var pr=function t(e){var Mt=(e=null==e?me:pr.defaults(me.Object(),e,pr.pick(me,ie))).Array,_t=e.Date,$t=e.Error,St=e.Function,Rt=e.Math,Et=e.Object,Ct=e.RegExp,kt=e.String,At=e.TypeError,Tt=Mt.prototype,Ot=St.prototype,It=Et.prototype,Dt=e["__core-js_shared__"],Pt=Ot.toString,Vt=It.hasOwnProperty,jt=0,Lt=function(){var t=/[^.]+$/.exec(Dt&&Dt.keys&&Dt.keys.IE_PROTO||"");return t?"Symbol(src)_1."+t:""}(),Nt=It.toString,Bt=Pt.call(Et),Ft=me._,zt=Ct("^"+Pt.call(Vt).replace(rt,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),qt=ge?e.Buffer:r,Ut=e.Symbol,Wt=e.Uint8Array,Ht=qt?qt.allocUnsafe:r,Yt=sr(Et.getPrototypeOf,Et),Gt=Et.create,Kt=It.propertyIsEnumerable,Xt=Tt.splice,Jt=Ut?Ut.isConcatSpreadable:r,te=Ut?Ut.iterator:r,re=Ut?Ut.toStringTag:r,ue=function(){try{var t=lo(Et,"defineProperty");return t({},"",{}),t}catch(t){}}(),le=e.clearTimeout!==me.clearTimeout&&e.clearTimeout,fe=_t&&_t.now!==me.Date.now&&_t.now,pe=e.setTimeout!==me.setTimeout&&e.setTimeout,de=Rt.ceil,ve=Rt.floor,we=Et.getOwnPropertySymbols,Le=qt?qt.isBuffer:r,He=e.isFinite,dr=Tt.join,gr=sr(Et.keys,Et),vr=Rt.max,wr=Rt.min,yr=_t.now,br=e.parseInt,xr=Rt.random,Mr=Tt.reverse,_r=lo(e,"DataView"),$r=lo(e,"Map"),Sr=lo(e,"Promise"),Rr=lo(e,"Set"),Er=lo(e,"WeakMap"),Cr=lo(Et,"create"),kr=Er&&new Er,Ar={},Tr=jo(_r),Or=jo($r),Ir=jo(Sr),Dr=jo(Rr),Pr=jo(Er),Vr=Ut?Ut.prototype:r,jr=Vr?Vr.valueOf:r,Lr=Vr?Vr.toString:r;function Nr(t){if(ta(t)&&!qs(t)&&!(t instanceof qr)){if(t instanceof zr)return t;if(Vt.call(t,"__wrapped__"))return Lo(t)}return new zr(t)}var Br=function(){function t(){}return function(e){if(!Zs(e))return{};if(Gt)return Gt(e);t.prototype=e;var n=new t;return t.prototype=r,n}}();function Fr(){}function zr(t,e){this.__wrapped__=t,this.__actions__=[],this.__chain__=!!e,this.__index__=0,this.__values__=r}function qr(t){this.__wrapped__=t,this.__actions__=[],this.__dir__=1,this.__filtered__=!1,this.__iteratees__=[],this.__takeCount__=p,this.__views__=[]}function Ur(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function Wr(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function Hr(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function Yr(t){var e=-1,r=null==t?0:t.length;for(this.__data__=new Hr;++e<r;)this.add(t[e])}function Gr(t){var e=this.__data__=new Wr(t);this.size=e.size}function Kr(t,e){var r=qs(t),n=!r&&zs(t),i=!r&&!n&&Ys(t),o=!r&&!n&&!i&&ua(t),s=r||n||i||o,a=s?Ke(t.length,kt):[],u=a.length;for(var h in t)!e&&!Vt.call(t,h)||s&&("length"==h||i&&("offset"==h||"parent"==h)||o&&("buffer"==h||"byteLength"==h||"byteOffset"==h)||yo(h,u))||a.push(h);return a}function Xr(t){var e=t.length;return e?t[Gn(0,e-1)]:r}function Jr(t,e){return Do(ki(t),an(e,0,t.length))}function Qr(t){return Do(ki(t))}function Zr(t,e,n){(n!==r&&!Ns(t[e],n)||n===r&&!(e in t))&&on(t,e,n)}function tn(t,e,n){var i=t[e];Vt.call(t,e)&&Ns(i,n)&&(n!==r||e in t)||on(t,e,n)}function en(t,e){for(var r=t.length;r--;)if(Ns(t[r][0],e))return r;return-1}function rn(t,e,r,n){return fn(t,(function(t,i,o){e(n,t,r(t),o)})),n}function nn(t,e){return t&&Ai(e,Aa(e),t)}function on(t,e,r){"__proto__"==e&&ue?ue(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r}function sn(t,e){for(var n=-1,i=e.length,o=Mt(i),s=null==t;++n<i;)o[n]=s?r:Sa(t,e[n]);return o}function an(t,e,n){return t==t&&(n!==r&&(t=t<=n?t:n),e!==r&&(t=t>=e?t:e)),t}function un(t,e,n,i,o,s){var a,u=1&e,h=2&e,c=4&e;if(n&&(a=o?n(t,i,o,s):n(t)),a!==r)return a;if(!Zs(t))return t;var l=qs(t);if(l){if(a=function(t){var e=t.length,r=new t.constructor(e);e&&"string"==typeof t[0]&&Vt.call(t,"index")&&(r.index=t.index,r.input=t.input);return r}(t),!u)return ki(t,a)}else{var f=po(t),m=f==x||f==M;if(Ys(t))return _i(t,u);if(f==S||f==g||m&&!o){if(a=h||m?{}:vo(t),!u)return h?function(t,e){return Ai(t,mo(t),e)}(t,function(t,e){return t&&Ai(e,Ta(e),t)}(a,t)):function(t,e){return Ai(t,fo(t),e)}(t,nn(a,t))}else{if(!ae[f])return o?t:{};a=function(t,e,r){var n=t.constructor;switch(e){case O:return $i(t);case w:case y:return new n(+t);case I:return function(t,e){var r=e?$i(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.byteLength)}(t,r);case D:case P:case V:case j:case L:case N:case B:case F:case z:return Si(t,r);case _:return new n;case $:case k:return new n(t);case E:return function(t){var e=new t.constructor(t.source,mt.exec(t));return e.lastIndex=t.lastIndex,e}(t);case C:return new n;case A:return i=t,jr?Et(jr.call(i)):{}}var i}(t,f,u)}}s||(s=new Gr);var p=s.get(t);if(p)return p;if(s.set(t,a),oa(t))return t.forEach((function(r){a.add(un(r,e,n,r,t,s))})),a;if(ea(t))return t.forEach((function(r,i){a.set(i,un(r,e,n,i,t,s))})),a;var d=l?r:(c?h?io:no:h?Ta:Aa)(t);return Ee(d||t,(function(r,i){d&&(r=t[i=r]),tn(a,i,un(r,e,n,i,t,s))})),a}function hn(t,e,n){var i=n.length;if(null==t)return!i;for(t=Et(t);i--;){var o=n[i],s=e[o],a=t[o];if(a===r&&!(o in t)||!s(a))return!1}return!0}function cn(t,e,i){if("function"!=typeof t)throw new At(n);return Ao((function(){t.apply(r,i)}),e)}function ln(t,e,r,n){var i=-1,o=Te,s=!0,a=t.length,u=[],h=e.length;if(!a)return u;r&&(e=Ie(e,Xe(r))),n?(o=Oe,s=!1):e.length>=200&&(o=Qe,s=!1,e=new Yr(e));t:for(;++i<a;){var c=t[i],l=null==r?c:r(c);if(c=n||0!==c?c:0,s&&l==l){for(var f=h;f--;)if(e[f]===l)continue t;u.push(c)}else o(e,l,n)||u.push(c)}return u}Nr.templateSettings={escape:X,evaluate:J,interpolate:Q,variable:"",imports:{_:Nr}},Nr.prototype=Fr.prototype,Nr.prototype.constructor=Nr,zr.prototype=Br(Fr.prototype),zr.prototype.constructor=zr,qr.prototype=Br(Fr.prototype),qr.prototype.constructor=qr,Ur.prototype.clear=function(){this.__data__=Cr?Cr(null):{},this.size=0},Ur.prototype.delete=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},Ur.prototype.get=function(t){var e=this.__data__;if(Cr){var n=e[t];return n===i?r:n}return Vt.call(e,t)?e[t]:r},Ur.prototype.has=function(t){var e=this.__data__;return Cr?e[t]!==r:Vt.call(e,t)},Ur.prototype.set=function(t,e){var n=this.__data__;return this.size+=this.has(t)?0:1,n[t]=Cr&&e===r?i:e,this},Wr.prototype.clear=function(){this.__data__=[],this.size=0},Wr.prototype.delete=function(t){var e=this.__data__,r=en(e,t);return!(r<0)&&(r==e.length-1?e.pop():Xt.call(e,r,1),--this.size,!0)},Wr.prototype.get=function(t){var e=this.__data__,n=en(e,t);return n<0?r:e[n][1]},Wr.prototype.has=function(t){return en(this.__data__,t)>-1},Wr.prototype.set=function(t,e){var r=this.__data__,n=en(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=e,this},Hr.prototype.clear=function(){this.size=0,this.__data__={hash:new Ur,map:new($r||Wr),string:new Ur}},Hr.prototype.delete=function(t){var e=ho(this,t).delete(t);return this.size-=e?1:0,e},Hr.prototype.get=function(t){return ho(this,t).get(t)},Hr.prototype.has=function(t){return ho(this,t).has(t)},Hr.prototype.set=function(t,e){var r=ho(this,t),n=r.size;return r.set(t,e),this.size+=r.size==n?0:1,this},Yr.prototype.add=Yr.prototype.push=function(t){return this.__data__.set(t,i),this},Yr.prototype.has=function(t){return this.__data__.has(t)},Gr.prototype.clear=function(){this.__data__=new Wr,this.size=0},Gr.prototype.delete=function(t){var e=this.__data__,r=e.delete(t);return this.size=e.size,r},Gr.prototype.get=function(t){return this.__data__.get(t)},Gr.prototype.has=function(t){return this.__data__.has(t)},Gr.prototype.set=function(t,e){var r=this.__data__;if(r instanceof Wr){var n=r.__data__;if(!$r||n.length<199)return n.push([t,e]),this.size=++r.size,this;r=this.__data__=new Hr(n)}return r.set(t,e),this.size=r.size,this};var fn=Ii(bn),mn=Ii(xn,!0);function pn(t,e){var r=!0;return fn(t,(function(t,n,i){return r=!!e(t,n,i)})),r}function dn(t,e,n){for(var i=-1,o=t.length;++i<o;){var s=t[i],a=e(s);if(null!=a&&(u===r?a==a&&!aa(a):n(a,u)))var u=a,h=s}return h}function gn(t,e){var r=[];return fn(t,(function(t,n,i){e(t,n,i)&&r.push(t)})),r}function vn(t,e,r,n,i){var o=-1,s=t.length;for(r||(r=wo),i||(i=[]);++o<s;){var a=t[o];e>0&&r(a)?e>1?vn(a,e-1,r,n,i):De(i,a):n||(i[i.length]=a)}return i}var wn=Di(),yn=Di(!0);function bn(t,e){return t&&wn(t,e,Aa)}function xn(t,e){return t&&yn(t,e,Aa)}function Mn(t,e){return Ae(e,(function(e){return Xs(t[e])}))}function _n(t,e){for(var n=0,i=(e=yi(e,t)).length;null!=t&&n<i;)t=t[Vo(e[n++])];return n&&n==i?t:r}function $n(t,e,r){var n=e(t);return qs(t)?n:De(n,r(t))}function Sn(t){return null==t?t===r?"[object Undefined]":"[object Null]":re&&re in Et(t)?function(t){var e=Vt.call(t,re),n=t[re];try{t[re]=r}catch(t){}var i=Nt.call(t);e?t[re]=n:delete t[re];return i}(t):function(t){return Nt.call(t)}(t)}function Rn(t,e){return t>e}function En(t,e){return null!=t&&Vt.call(t,e)}function Cn(t,e){return null!=t&&e in Et(t)}function kn(t,e,n){for(var i=n?Oe:Te,o=t[0].length,s=t.length,a=s,u=Mt(s),h=1/0,c=[];a--;){var l=t[a];a&&e&&(l=Ie(l,Xe(e))),h=wr(l.length,h),u[a]=!n&&(e||o>=120&&l.length>=120)?new Yr(a&&l):r}l=t[0];var f=-1,m=u[0];t:for(;++f<o&&c.length<h;){var p=l[f],d=e?e(p):p;if(p=n||0!==p?p:0,!(m?Qe(m,d):i(c,d,n))){for(a=s;--a;){var g=u[a];if(!(g?Qe(g,d):i(t[a],d,n)))continue t}m&&m.push(d),c.push(p)}}return c}function An(t,e,n){var i=null==(t=Co(t,e=yi(e,t)))?t:t[Vo(Ko(e))];return null==i?r:Se(i,t,n)}function Tn(t){return ta(t)&&Sn(t)==g}function On(t,e,n,i,o){return t===e||(null==t||null==e||!ta(t)&&!ta(e)?t!=t&&e!=e:function(t,e,n,i,o,s){var a=qs(t),u=qs(e),h=a?v:po(t),c=u?v:po(e),l=(h=h==g?S:h)==S,f=(c=c==g?S:c)==S,m=h==c;if(m&&Ys(t)){if(!Ys(e))return!1;a=!0,l=!1}if(m&&!l)return s||(s=new Gr),a||ua(t)?eo(t,e,n,i,o,s):function(t,e,r,n,i,o,s){switch(r){case I:if(t.byteLength!=e.byteLength||t.byteOffset!=e.byteOffset)return!1;t=t.buffer,e=e.buffer;case O:return!(t.byteLength!=e.byteLength||!o(new Wt(t),new Wt(e)));case w:case y:case $:return Ns(+t,+e);case b:return t.name==e.name&&t.message==e.message;case E:case k:return t==e+"";case _:var a=or;case C:var u=1&n;if(a||(a=hr),t.size!=e.size&&!u)return!1;var h=s.get(t);if(h)return h==e;n|=2,s.set(t,e);var c=eo(a(t),a(e),n,i,o,s);return s.delete(t),c;case A:if(jr)return jr.call(t)==jr.call(e)}return!1}(t,e,h,n,i,o,s);if(!(1&n)){var p=l&&Vt.call(t,"__wrapped__"),d=f&&Vt.call(e,"__wrapped__");if(p||d){var x=p?t.value():t,M=d?e.value():e;return s||(s=new Gr),o(x,M,n,i,s)}}if(!m)return!1;return s||(s=new Gr),function(t,e,n,i,o,s){var a=1&n,u=no(t),h=u.length,c=no(e),l=c.length;if(h!=l&&!a)return!1;var f=h;for(;f--;){var m=u[f];if(!(a?m in e:Vt.call(e,m)))return!1}var p=s.get(t);if(p&&s.get(e))return p==e;var d=!0;s.set(t,e),s.set(e,t);var g=a;for(;++f<h;){var v=t[m=u[f]],w=e[m];if(i)var y=a?i(w,v,m,e,t,s):i(v,w,m,t,e,s);if(!(y===r?v===w||o(v,w,n,i,s):y)){d=!1;break}g||(g="constructor"==m)}if(d&&!g){var b=t.constructor,x=e.constructor;b==x||!("constructor"in t)||!("constructor"in e)||"function"==typeof b&&b instanceof b&&"function"==typeof x&&x instanceof x||(d=!1)}return s.delete(t),s.delete(e),d}(t,e,n,i,o,s)}(t,e,n,i,On,o))}function In(t,e,n,i){var o=n.length,s=o,a=!i;if(null==t)return!s;for(t=Et(t);o--;){var u=n[o];if(a&&u[2]?u[1]!==t[u[0]]:!(u[0]in t))return!1}for(;++o<s;){var h=(u=n[o])[0],c=t[h],l=u[1];if(a&&u[2]){if(c===r&&!(h in t))return!1}else{var f=new Gr;if(i)var m=i(c,l,h,t,e,f);if(!(m===r?On(l,c,3,i,f):m))return!1}}return!0}function Dn(t){return!(!Zs(t)||(e=t,Lt&&Lt in e))&&(Xs(t)?zt:gt).test(jo(t));var e}function Pn(t){return"function"==typeof t?t:null==t?ru:"object"==typeof t?qs(t)?Fn(t[0],t[1]):Bn(t):lu(t)}function Vn(t){if(!$o(t))return gr(t);var e=[];for(var r in Et(t))Vt.call(t,r)&&"constructor"!=r&&e.push(r);return e}function jn(t){if(!Zs(t))return function(t){var e=[];if(null!=t)for(var r in Et(t))e.push(r);return e}(t);var e=$o(t),r=[];for(var n in t)("constructor"!=n||!e&&Vt.call(t,n))&&r.push(n);return r}function Ln(t,e){return t<e}function Nn(t,e){var r=-1,n=Ws(t)?Mt(t.length):[];return fn(t,(function(t,i,o){n[++r]=e(t,i,o)})),n}function Bn(t){var e=co(t);return 1==e.length&&e[0][2]?Ro(e[0][0],e[0][1]):function(r){return r===t||In(r,t,e)}}function Fn(t,e){return xo(t)&&So(e)?Ro(Vo(t),e):function(n){var i=Sa(n,t);return i===r&&i===e?Ra(n,t):On(e,i,3)}}function zn(t,e,n,i,o){t!==e&&wn(e,(function(s,a){if(Zs(s))o||(o=new Gr),function(t,e,n,i,o,s,a){var u=ur(t,n),h=ur(e,n),c=a.get(h);if(c)return void Zr(t,n,c);var l=s?s(u,h,n+"",t,e,a):r,f=l===r;if(f){var m=qs(h),p=!m&&Ys(h),d=!m&&!p&&ua(h);l=h,m||p||d?qs(u)?l=u:Hs(u)?l=ki(u):p?(f=!1,l=_i(h,!0)):d?(f=!1,l=Si(h,!0)):l=[]:na(h)||zs(h)?(l=u,zs(u)?l=ga(u):(!Zs(u)||i&&Xs(u))&&(l=vo(h))):f=!1}f&&(a.set(h,l),o(l,h,i,s,a),a.delete(h));Zr(t,n,l)}(t,e,a,n,zn,i,o);else{var u=i?i(ur(t,a),s,a+"",t,e,o):r;u===r&&(u=s),Zr(t,a,u)}}),Ta)}function qn(t,e){var n=t.length;if(n)return yo(e+=e<0?n:0,n)?t[e]:r}function Un(t,e,r){var n=-1;e=Ie(e.length?e:[ru],Xe(uo()));var i=Nn(t,(function(t,r,i){var o=Ie(e,(function(e){return e(t)}));return{criteria:o,index:++n,value:t}}));return function(t,e){var r=t.length;for(t.sort(e);r--;)t[r]=t[r].value;return t}(i,(function(t,e){return function(t,e,r){var n=-1,i=t.criteria,o=e.criteria,s=i.length,a=r.length;for(;++n<s;){var u=Ri(i[n],o[n]);if(u)return n>=a?u:u*("desc"==r[n]?-1:1)}return t.index-e.index}(t,e,r)}))}function Wn(t,e,r){for(var n=-1,i=e.length,o={};++n<i;){var s=e[n],a=_n(t,s);r(a,s)&&Zn(o,yi(s,t),a)}return o}function Hn(t,e,r,n){var i=n?ze:Fe,o=-1,s=e.length,a=t;for(t===e&&(e=ki(e)),r&&(a=Ie(t,Xe(r)));++o<s;)for(var u=0,h=e[o],c=r?r(h):h;(u=i(a,c,u,n))>-1;)a!==t&&Xt.call(a,u,1),Xt.call(t,u,1);return t}function Yn(t,e){for(var r=t?e.length:0,n=r-1;r--;){var i=e[r];if(r==n||i!==o){var o=i;yo(i)?Xt.call(t,i,1):li(t,i)}}return t}function Gn(t,e){return t+ve(xr()*(e-t+1))}function Kn(t,e){var r="";if(!t||e<1||e>f)return r;do{e%2&&(r+=t),(e=ve(e/2))&&(t+=t)}while(e);return r}function Xn(t,e){return To(Eo(t,e,ru),t+"")}function Jn(t){return Xr(Na(t))}function Qn(t,e){var r=Na(t);return Do(r,an(e,0,r.length))}function Zn(t,e,n,i){if(!Zs(t))return t;for(var o=-1,s=(e=yi(e,t)).length,a=s-1,u=t;null!=u&&++o<s;){var h=Vo(e[o]),c=n;if(o!=a){var l=u[h];(c=i?i(l,h,u):r)===r&&(c=Zs(l)?l:yo(e[o+1])?[]:{})}tn(u,h,c),u=u[h]}return t}var ti=kr?function(t,e){return kr.set(t,e),t}:ru,ei=ue?function(t,e){return ue(t,"toString",{configurable:!0,enumerable:!1,value:Za(e),writable:!0})}:ru;function ri(t){return Do(Na(t))}function ni(t,e,r){var n=-1,i=t.length;e<0&&(e=-e>i?0:i+e),(r=r>i?i:r)<0&&(r+=i),i=e>r?0:r-e>>>0,e>>>=0;for(var o=Mt(i);++n<i;)o[n]=t[n+e];return o}function ii(t,e){var r;return fn(t,(function(t,n,i){return!(r=e(t,n,i))})),!!r}function oi(t,e,r){var n=0,i=null==t?n:t.length;if("number"==typeof e&&e==e&&i<=2147483647){for(;n<i;){var o=n+i>>>1,s=t[o];null!==s&&!aa(s)&&(r?s<=e:s<e)?n=o+1:i=o}return i}return si(t,e,ru,r)}function si(t,e,n,i){e=n(e);for(var o=0,s=null==t?0:t.length,a=e!=e,u=null===e,h=aa(e),c=e===r;o<s;){var l=ve((o+s)/2),f=n(t[l]),m=f!==r,p=null===f,d=f==f,g=aa(f);if(a)var v=i||d;else v=c?d&&(i||m):u?d&&m&&(i||!p):h?d&&m&&!p&&(i||!g):!p&&!g&&(i?f<=e:f<e);v?o=l+1:s=l}return wr(s,4294967294)}function ai(t,e){for(var r=-1,n=t.length,i=0,o=[];++r<n;){var s=t[r],a=e?e(s):s;if(!r||!Ns(a,u)){var u=a;o[i++]=0===s?0:s}}return o}function ui(t){return"number"==typeof t?t:aa(t)?m:+t}function hi(t){if("string"==typeof t)return t;if(qs(t))return Ie(t,hi)+"";if(aa(t))return Lr?Lr.call(t):"";var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}function ci(t,e,r){var n=-1,i=Te,o=t.length,s=!0,a=[],u=a;if(r)s=!1,i=Oe;else if(o>=200){var h=e?null:Ki(t);if(h)return hr(h);s=!1,i=Qe,u=new Yr}else u=e?[]:a;t:for(;++n<o;){var c=t[n],l=e?e(c):c;if(c=r||0!==c?c:0,s&&l==l){for(var f=u.length;f--;)if(u[f]===l)continue t;e&&u.push(l),a.push(c)}else i(u,l,r)||(u!==a&&u.push(l),a.push(c))}return a}function li(t,e){return null==(t=Co(t,e=yi(e,t)))||delete t[Vo(Ko(e))]}function fi(t,e,r,n){return Zn(t,e,r(_n(t,e)),n)}function mi(t,e,r,n){for(var i=t.length,o=n?i:-1;(n?o--:++o<i)&&e(t[o],o,t););return r?ni(t,n?0:o,n?o+1:i):ni(t,n?o+1:0,n?i:o)}function pi(t,e){var r=t;return r instanceof qr&&(r=r.value()),Pe(e,(function(t,e){return e.func.apply(e.thisArg,De([t],e.args))}),r)}function di(t,e,r){var n=t.length;if(n<2)return n?ci(t[0]):[];for(var i=-1,o=Mt(n);++i<n;)for(var s=t[i],a=-1;++a<n;)a!=i&&(o[i]=ln(o[i]||s,t[a],e,r));return ci(vn(o,1),e,r)}function gi(t,e,n){for(var i=-1,o=t.length,s=e.length,a={};++i<o;){var u=i<s?e[i]:r;n(a,t[i],u)}return a}function vi(t){return Hs(t)?t:[]}function wi(t){return"function"==typeof t?t:ru}function yi(t,e){return qs(t)?t:xo(t,e)?[t]:Po(va(t))}var bi=Xn;function xi(t,e,n){var i=t.length;return n=n===r?i:n,!e&&n>=i?t:ni(t,e,n)}var Mi=le||function(t){return me.clearTimeout(t)};function _i(t,e){if(e)return t.slice();var r=t.length,n=Ht?Ht(r):new t.constructor(r);return t.copy(n),n}function $i(t){var e=new t.constructor(t.byteLength);return new Wt(e).set(new Wt(t)),e}function Si(t,e){var r=e?$i(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.length)}function Ri(t,e){if(t!==e){var n=t!==r,i=null===t,o=t==t,s=aa(t),a=e!==r,u=null===e,h=e==e,c=aa(e);if(!u&&!c&&!s&&t>e||s&&a&&h&&!u&&!c||i&&a&&h||!n&&h||!o)return 1;if(!i&&!s&&!c&&t<e||c&&n&&o&&!i&&!s||u&&n&&o||!a&&o||!h)return-1}return 0}function Ei(t,e,r,n){for(var i=-1,o=t.length,s=r.length,a=-1,u=e.length,h=vr(o-s,0),c=Mt(u+h),l=!n;++a<u;)c[a]=e[a];for(;++i<s;)(l||i<o)&&(c[r[i]]=t[i]);for(;h--;)c[a++]=t[i++];return c}function Ci(t,e,r,n){for(var i=-1,o=t.length,s=-1,a=r.length,u=-1,h=e.length,c=vr(o-a,0),l=Mt(c+h),f=!n;++i<c;)l[i]=t[i];for(var m=i;++u<h;)l[m+u]=e[u];for(;++s<a;)(f||i<o)&&(l[m+r[s]]=t[i++]);return l}function ki(t,e){var r=-1,n=t.length;for(e||(e=Mt(n));++r<n;)e[r]=t[r];return e}function Ai(t,e,n,i){var o=!n;n||(n={});for(var s=-1,a=e.length;++s<a;){var u=e[s],h=i?i(n[u],t[u],u,n,t):r;h===r&&(h=t[u]),o?on(n,u,h):tn(n,u,h)}return n}function Ti(t,e){return function(r,n){var i=qs(r)?Re:rn,o=e?e():{};return i(r,t,uo(n,2),o)}}function Oi(t){return Xn((function(e,n){var i=-1,o=n.length,s=o>1?n[o-1]:r,a=o>2?n[2]:r;for(s=t.length>3&&"function"==typeof s?(o--,s):r,a&&bo(n[0],n[1],a)&&(s=o<3?r:s,o=1),e=Et(e);++i<o;){var u=n[i];u&&t(e,u,i,s)}return e}))}function Ii(t,e){return function(r,n){if(null==r)return r;if(!Ws(r))return t(r,n);for(var i=r.length,o=e?i:-1,s=Et(r);(e?o--:++o<i)&&!1!==n(s[o],o,s););return r}}function Di(t){return function(e,r,n){for(var i=-1,o=Et(e),s=n(e),a=s.length;a--;){var u=s[t?a:++i];if(!1===r(o[u],u,o))break}return e}}function Pi(t){return function(e){var n=ir(e=va(e))?fr(e):r,i=n?n[0]:e.charAt(0),o=n?xi(n,1).join(""):e.slice(1);return i[t]()+o}}function Vi(t){return function(e){return Pe(Xa(za(e).replace(Qt,"")),t,"")}}function ji(t){return function(){var e=arguments;switch(e.length){case 0:return new t;case 1:return new t(e[0]);case 2:return new t(e[0],e[1]);case 3:return new t(e[0],e[1],e[2]);case 4:return new t(e[0],e[1],e[2],e[3]);case 5:return new t(e[0],e[1],e[2],e[3],e[4]);case 6:return new t(e[0],e[1],e[2],e[3],e[4],e[5]);case 7:return new t(e[0],e[1],e[2],e[3],e[4],e[5],e[6])}var r=Br(t.prototype),n=t.apply(r,e);return Zs(n)?n:r}}function Li(t){return function(e,n,i){var o=Et(e);if(!Ws(e)){var s=uo(n,3);e=Aa(e),n=function(t){return s(o[t],t,o)}}var a=t(e,n,i);return a>-1?o[s?e[a]:a]:r}}function Ni(t){return ro((function(e){var i=e.length,o=i,s=zr.prototype.thru;for(t&&e.reverse();o--;){var a=e[o];if("function"!=typeof a)throw new At(n);if(s&&!u&&"wrapper"==so(a))var u=new zr([],!0)}for(o=u?o:i;++o<i;){var h=so(a=e[o]),c="wrapper"==h?oo(a):r;u=c&&Mo(c[0])&&424==c[1]&&!c[4].length&&1==c[9]?u[so(c[0])].apply(u,c[3]):1==a.length&&Mo(a)?u[h]():u.thru(a)}return function(){var t=arguments,r=t[0];if(u&&1==t.length&&qs(r))return u.plant(r).value();for(var n=0,o=i?e[n].apply(this,t):r;++n<i;)o=e[n].call(this,o);return o}}))}function Bi(t,e,n,i,o,s,a,u,c,l){var f=e&h,m=1&e,p=2&e,d=24&e,g=512&e,v=p?r:ji(t);return function h(){for(var w=arguments.length,y=Mt(w),b=w;b--;)y[b]=arguments[b];if(d)var x=ao(h),M=function(t,e){for(var r=t.length,n=0;r--;)t[r]===e&&++n;return n}(y,x);if(i&&(y=Ei(y,i,o,d)),s&&(y=Ci(y,s,a,d)),w-=M,d&&w<l){var _=ar(y,x);return Yi(t,e,Bi,h.placeholder,n,y,_,u,c,l-w)}var $=m?n:this,S=p?$[t]:t;return w=y.length,u?y=function(t,e){var n=t.length,i=wr(e.length,n),o=ki(t);for(;i--;){var s=e[i];t[i]=yo(s,n)?o[s]:r}return t}(y,u):g&&w>1&&y.reverse(),f&&c<w&&(y.length=c),this&&this!==me&&this instanceof h&&(S=v||ji(S)),S.apply($,y)}}function Fi(t,e){return function(r,n){return function(t,e,r,n){return bn(t,(function(t,i,o){e(n,r(t),i,o)})),n}(r,t,e(n),{})}}function zi(t,e){return function(n,i){var o;if(n===r&&i===r)return e;if(n!==r&&(o=n),i!==r){if(o===r)return i;"string"==typeof n||"string"==typeof i?(n=hi(n),i=hi(i)):(n=ui(n),i=ui(i)),o=t(n,i)}return o}}function qi(t){return ro((function(e){return e=Ie(e,Xe(uo())),Xn((function(r){var n=this;return t(e,(function(t){return Se(t,n,r)}))}))}))}function Ui(t,e){var n=(e=e===r?" ":hi(e)).length;if(n<2)return n?Kn(e,t):e;var i=Kn(e,de(t/lr(e)));return ir(e)?xi(fr(i),0,t).join(""):i.slice(0,t)}function Wi(t){return function(e,n,i){return i&&"number"!=typeof i&&bo(e,n,i)&&(n=i=r),e=fa(e),n===r?(n=e,e=0):n=fa(n),function(t,e,r,n){for(var i=-1,o=vr(de((e-t)/(r||1)),0),s=Mt(o);o--;)s[n?o:++i]=t,t+=r;return s}(e,n,i=i===r?e<n?1:-1:fa(i),t)}}function Hi(t){return function(e,r){return"string"==typeof e&&"string"==typeof r||(e=da(e),r=da(r)),t(e,r)}}function Yi(t,e,n,i,o,s,h,c,l,f){var m=8&e;e|=m?a:u,4&(e&=~(m?u:a))||(e&=-4);var p=[t,e,o,m?s:r,m?h:r,m?r:s,m?r:h,c,l,f],d=n.apply(r,p);return Mo(t)&&ko(d,p),d.placeholder=i,Oo(d,t,e)}function Gi(t){var e=Rt[t];return function(t,r){if(t=da(t),r=null==r?0:wr(ma(r),292)){var n=(va(t)+"e").split("e");return+((n=(va(e(n[0]+"e"+(+n[1]+r)))+"e").split("e"))[0]+"e"+(+n[1]-r))}return e(t)}}var Ki=Rr&&1/hr(new Rr([,-0]))[1]==l?function(t){return new Rr(t)}:au;function Xi(t){return function(e){var r=po(e);return r==_?or(e):r==C?cr(e):function(t,e){return Ie(e,(function(e){return[e,t[e]]}))}(e,t(e))}}function Ji(t,e,i,l,f,m,p,d){var g=2&e;if(!g&&"function"!=typeof t)throw new At(n);var v=l?l.length:0;if(v||(e&=-97,l=f=r),p=p===r?p:vr(ma(p),0),d=d===r?d:ma(d),v-=f?f.length:0,e&u){var w=l,y=f;l=f=r}var b=g?r:oo(t),x=[t,e,i,l,f,w,y,m,p,d];if(b&&function(t,e){var r=t[1],n=e[1],i=r|n,s=i<131,a=n==h&&8==r||n==h&&r==c&&t[7].length<=e[8]||384==n&&e[7].length<=e[8]&&8==r;if(!s&&!a)return t;1&n&&(t[2]=e[2],i|=1&r?0:4);var u=e[3];if(u){var l=t[3];t[3]=l?Ei(l,u,e[4]):u,t[4]=l?ar(t[3],o):e[4]}(u=e[5])&&(l=t[5],t[5]=l?Ci(l,u,e[6]):u,t[6]=l?ar(t[5],o):e[6]);(u=e[7])&&(t[7]=u);n&h&&(t[8]=null==t[8]?e[8]:wr(t[8],e[8]));null==t[9]&&(t[9]=e[9]);t[0]=e[0],t[1]=i}(x,b),t=x[0],e=x[1],i=x[2],l=x[3],f=x[4],!(d=x[9]=x[9]===r?g?0:t.length:vr(x[9]-v,0))&&24&e&&(e&=-25),e&&1!=e)M=8==e||e==s?function(t,e,n){var i=ji(t);return function o(){for(var s=arguments.length,a=Mt(s),u=s,h=ao(o);u--;)a[u]=arguments[u];var c=s<3&&a[0]!==h&&a[s-1]!==h?[]:ar(a,h);return(s-=c.length)<n?Yi(t,e,Bi,o.placeholder,r,a,c,r,r,n-s):Se(this&&this!==me&&this instanceof o?i:t,this,a)}}(t,e,d):e!=a&&33!=e||f.length?Bi.apply(r,x):function(t,e,r,n){var i=1&e,o=ji(t);return function e(){for(var s=-1,a=arguments.length,u=-1,h=n.length,c=Mt(h+a),l=this&&this!==me&&this instanceof e?o:t;++u<h;)c[u]=n[u];for(;a--;)c[u++]=arguments[++s];return Se(l,i?r:this,c)}}(t,e,i,l);else var M=function(t,e,r){var n=1&e,i=ji(t);return function e(){return(this&&this!==me&&this instanceof e?i:t).apply(n?r:this,arguments)}}(t,e,i);return Oo((b?ti:ko)(M,x),t,e)}function Qi(t,e,n,i){return t===r||Ns(t,It[n])&&!Vt.call(i,n)?e:t}function Zi(t,e,n,i,o,s){return Zs(t)&&Zs(e)&&(s.set(e,t),zn(t,e,r,Zi,s),s.delete(e)),t}function to(t){return na(t)?r:t}function eo(t,e,n,i,o,s){var a=1&n,u=t.length,h=e.length;if(u!=h&&!(a&&h>u))return!1;var c=s.get(t);if(c&&s.get(e))return c==e;var l=-1,f=!0,m=2&n?new Yr:r;for(s.set(t,e),s.set(e,t);++l<u;){var p=t[l],d=e[l];if(i)var g=a?i(d,p,l,e,t,s):i(p,d,l,t,e,s);if(g!==r){if(g)continue;f=!1;break}if(m){if(!je(e,(function(t,e){if(!Qe(m,e)&&(p===t||o(p,t,n,i,s)))return m.push(e)}))){f=!1;break}}else if(p!==d&&!o(p,d,n,i,s)){f=!1;break}}return s.delete(t),s.delete(e),f}function ro(t){return To(Eo(t,r,Uo),t+"")}function no(t){return $n(t,Aa,fo)}function io(t){return $n(t,Ta,mo)}var oo=kr?function(t){return kr.get(t)}:au;function so(t){for(var e=t.name+"",r=Ar[e],n=Vt.call(Ar,e)?r.length:0;n--;){var i=r[n],o=i.func;if(null==o||o==t)return i.name}return e}function ao(t){return(Vt.call(Nr,"placeholder")?Nr:t).placeholder}function uo(){var t=Nr.iteratee||nu;return t=t===nu?Pn:t,arguments.length?t(arguments[0],arguments[1]):t}function ho(t,e){var r=t.__data__;return function(t){var e=typeof t;return"string"==e||"number"==e||"symbol"==e||"boolean"==e?"__proto__"!==t:null===t}(e)?r["string"==typeof e?"string":"hash"]:r.map}function co(t){for(var e=Aa(t),r=e.length;r--;){var n=e[r],i=t[n];e[r]=[n,i,So(i)]}return e}function lo(t,e){var n=function(t,e){return null==t?r:t[e]}(t,e);return Dn(n)?n:r}var fo=we?function(t){return null==t?[]:(t=Et(t),Ae(we(t),(function(e){return Kt.call(t,e)})))}:pu,mo=we?function(t){for(var e=[];t;)De(e,fo(t)),t=Yt(t);return e}:pu,po=Sn;function go(t,e,r){for(var n=-1,i=(e=yi(e,t)).length,o=!1;++n<i;){var s=Vo(e[n]);if(!(o=null!=t&&r(t,s)))break;t=t[s]}return o||++n!=i?o:!!(i=null==t?0:t.length)&&Qs(i)&&yo(s,i)&&(qs(t)||zs(t))}function vo(t){return"function"!=typeof t.constructor||$o(t)?{}:Br(Yt(t))}function wo(t){return qs(t)||zs(t)||!!(Jt&&t&&t[Jt])}function yo(t,e){var r=typeof t;return!!(e=null==e?f:e)&&("number"==r||"symbol"!=r&&wt.test(t))&&t>-1&&t%1==0&&t<e}function bo(t,e,r){if(!Zs(r))return!1;var n=typeof e;return!!("number"==n?Ws(r)&&yo(e,r.length):"string"==n&&e in r)&&Ns(r[e],t)}function xo(t,e){if(qs(t))return!1;var r=typeof t;return!("number"!=r&&"symbol"!=r&&"boolean"!=r&&null!=t&&!aa(t))||(tt.test(t)||!Z.test(t)||null!=e&&t in Et(e))}function Mo(t){var e=so(t),r=Nr[e];if("function"!=typeof r||!(e in qr.prototype))return!1;if(t===r)return!0;var n=oo(r);return!!n&&t===n[0]}(_r&&po(new _r(new ArrayBuffer(1)))!=I||$r&&po(new $r)!=_||Sr&&po(Sr.resolve())!=R||Rr&&po(new Rr)!=C||Er&&po(new Er)!=T)&&(po=function(t){var e=Sn(t),n=e==S?t.constructor:r,i=n?jo(n):"";if(i)switch(i){case Tr:return I;case Or:return _;case Ir:return R;case Dr:return C;case Pr:return T}return e});var _o=Dt?Xs:du;function $o(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||It)}function So(t){return t==t&&!Zs(t)}function Ro(t,e){return function(n){return null!=n&&(n[t]===e&&(e!==r||t in Et(n)))}}function Eo(t,e,n){return e=vr(e===r?t.length-1:e,0),function(){for(var r=arguments,i=-1,o=vr(r.length-e,0),s=Mt(o);++i<o;)s[i]=r[e+i];i=-1;for(var a=Mt(e+1);++i<e;)a[i]=r[i];return a[e]=n(s),Se(t,this,a)}}function Co(t,e){return e.length<2?t:_n(t,ni(e,0,-1))}var ko=Io(ti),Ao=pe||function(t,e){return me.setTimeout(t,e)},To=Io(ei);function Oo(t,e,r){var n=e+"";return To(t,function(t,e){var r=e.length;if(!r)return t;var n=r-1;return e[n]=(r>1?"& ":"")+e[n],e=e.join(r>2?", ":" "),t.replace(at,"{\n/* [wrapped with "+e+"] */\n")}(n,function(t,e){return Ee(d,(function(r){var n="_."+r[0];e&r[1]&&!Te(t,n)&&t.push(n)})),t.sort()}(function(t){var e=t.match(ut);return e?e[1].split(ht):[]}(n),r)))}function Io(t){var e=0,n=0;return function(){var i=yr(),o=16-(i-n);if(n=i,o>0){if(++e>=800)return arguments[0]}else e=0;return t.apply(r,arguments)}}function Do(t,e){var n=-1,i=t.length,o=i-1;for(e=e===r?i:e;++n<e;){var s=Gn(n,o),a=t[s];t[s]=t[n],t[n]=a}return t.length=e,t}var Po=function(t){var e=Is(t,(function(t){return 500===r.size&&r.clear(),t})),r=e.cache;return e}((function(t){var e=[];return 46===t.charCodeAt(0)&&e.push(""),t.replace(et,(function(t,r,n,i){e.push(n?i.replace(lt,"$1"):r||t)})),e}));function Vo(t){if("string"==typeof t||aa(t))return t;var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}function jo(t){if(null!=t){try{return Pt.call(t)}catch(t){}try{return t+""}catch(t){}}return""}function Lo(t){if(t instanceof qr)return t.clone();var e=new zr(t.__wrapped__,t.__chain__);return e.__actions__=ki(t.__actions__),e.__index__=t.__index__,e.__values__=t.__values__,e}var No=Xn((function(t,e){return Hs(t)?ln(t,vn(e,1,Hs,!0)):[]})),Bo=Xn((function(t,e){var n=Ko(e);return Hs(n)&&(n=r),Hs(t)?ln(t,vn(e,1,Hs,!0),uo(n,2)):[]})),Fo=Xn((function(t,e){var n=Ko(e);return Hs(n)&&(n=r),Hs(t)?ln(t,vn(e,1,Hs,!0),r,n):[]}));function zo(t,e,r){var n=null==t?0:t.length;if(!n)return-1;var i=null==r?0:ma(r);return i<0&&(i=vr(n+i,0)),Be(t,uo(e,3),i)}function qo(t,e,n){var i=null==t?0:t.length;if(!i)return-1;var o=i-1;return n!==r&&(o=ma(n),o=n<0?vr(i+o,0):wr(o,i-1)),Be(t,uo(e,3),o,!0)}function Uo(t){return(null==t?0:t.length)?vn(t,1):[]}function Wo(t){return t&&t.length?t[0]:r}var Ho=Xn((function(t){var e=Ie(t,vi);return e.length&&e[0]===t[0]?kn(e):[]})),Yo=Xn((function(t){var e=Ko(t),n=Ie(t,vi);return e===Ko(n)?e=r:n.pop(),n.length&&n[0]===t[0]?kn(n,uo(e,2)):[]})),Go=Xn((function(t){var e=Ko(t),n=Ie(t,vi);return(e="function"==typeof e?e:r)&&n.pop(),n.length&&n[0]===t[0]?kn(n,r,e):[]}));function Ko(t){var e=null==t?0:t.length;return e?t[e-1]:r}var Xo=Xn(Jo);function Jo(t,e){return t&&t.length&&e&&e.length?Hn(t,e):t}var Qo=ro((function(t,e){var r=null==t?0:t.length,n=sn(t,e);return Yn(t,Ie(e,(function(t){return yo(t,r)?+t:t})).sort(Ri)),n}));function Zo(t){return null==t?t:Mr.call(t)}var ts=Xn((function(t){return ci(vn(t,1,Hs,!0))})),es=Xn((function(t){var e=Ko(t);return Hs(e)&&(e=r),ci(vn(t,1,Hs,!0),uo(e,2))})),rs=Xn((function(t){var e=Ko(t);return e="function"==typeof e?e:r,ci(vn(t,1,Hs,!0),r,e)}));function ns(t){if(!t||!t.length)return[];var e=0;return t=Ae(t,(function(t){if(Hs(t))return e=vr(t.length,e),!0})),Ke(e,(function(e){return Ie(t,We(e))}))}function is(t,e){if(!t||!t.length)return[];var n=ns(t);return null==e?n:Ie(n,(function(t){return Se(e,r,t)}))}var os=Xn((function(t,e){return Hs(t)?ln(t,e):[]})),ss=Xn((function(t){return di(Ae(t,Hs))})),as=Xn((function(t){var e=Ko(t);return Hs(e)&&(e=r),di(Ae(t,Hs),uo(e,2))})),us=Xn((function(t){var e=Ko(t);return e="function"==typeof e?e:r,di(Ae(t,Hs),r,e)})),hs=Xn(ns);var cs=Xn((function(t){var e=t.length,n=e>1?t[e-1]:r;return n="function"==typeof n?(t.pop(),n):r,is(t,n)}));function ls(t){var e=Nr(t);return e.__chain__=!0,e}function fs(t,e){return e(t)}var ms=ro((function(t){var e=t.length,n=e?t[0]:0,i=this.__wrapped__,o=function(e){return sn(e,t)};return!(e>1||this.__actions__.length)&&i instanceof qr&&yo(n)?((i=i.slice(n,+n+(e?1:0))).__actions__.push({func:fs,args:[o],thisArg:r}),new zr(i,this.__chain__).thru((function(t){return e&&!t.length&&t.push(r),t}))):this.thru(o)}));var ps=Ti((function(t,e,r){Vt.call(t,r)?++t[r]:on(t,r,1)}));var ds=Li(zo),gs=Li(qo);function vs(t,e){return(qs(t)?Ee:fn)(t,uo(e,3))}function ws(t,e){return(qs(t)?Ce:mn)(t,uo(e,3))}var ys=Ti((function(t,e,r){Vt.call(t,r)?t[r].push(e):on(t,r,[e])}));var bs=Xn((function(t,e,r){var n=-1,i="function"==typeof e,o=Ws(t)?Mt(t.length):[];return fn(t,(function(t){o[++n]=i?Se(e,t,r):An(t,e,r)})),o})),xs=Ti((function(t,e,r){on(t,r,e)}));function Ms(t,e){return(qs(t)?Ie:Nn)(t,uo(e,3))}var _s=Ti((function(t,e,r){t[r?0:1].push(e)}),(function(){return[[],[]]}));var $s=Xn((function(t,e){if(null==t)return[];var r=e.length;return r>1&&bo(t,e[0],e[1])?e=[]:r>2&&bo(e[0],e[1],e[2])&&(e=[e[0]]),Un(t,vn(e,1),[])})),Ss=fe||function(){return me.Date.now()};function Rs(t,e,n){return e=n?r:e,e=t&&null==e?t.length:e,Ji(t,h,r,r,r,r,e)}function Es(t,e){var i;if("function"!=typeof e)throw new At(n);return t=ma(t),function(){return--t>0&&(i=e.apply(this,arguments)),t<=1&&(e=r),i}}var Cs=Xn((function(t,e,r){var n=1;if(r.length){var i=ar(r,ao(Cs));n|=a}return Ji(t,n,e,r,i)})),ks=Xn((function(t,e,r){var n=3;if(r.length){var i=ar(r,ao(ks));n|=a}return Ji(e,n,t,r,i)}));function As(t,e,i){var o,s,a,u,h,c,l=0,f=!1,m=!1,p=!0;if("function"!=typeof t)throw new At(n);function d(e){var n=o,i=s;return o=s=r,l=e,u=t.apply(i,n)}function g(t){var n=t-c;return c===r||n>=e||n<0||m&&t-l>=a}function v(){var t=Ss();if(g(t))return w(t);h=Ao(v,function(t){var r=e-(t-c);return m?wr(r,a-(t-l)):r}(t))}function w(t){return h=r,p&&o?d(t):(o=s=r,u)}function y(){var t=Ss(),n=g(t);if(o=arguments,s=this,c=t,n){if(h===r)return function(t){return l=t,h=Ao(v,e),f?d(t):u}(c);if(m)return h=Ao(v,e),d(c)}return h===r&&(h=Ao(v,e)),u}return e=da(e)||0,Zs(i)&&(f=!!i.leading,a=(m="maxWait"in i)?vr(da(i.maxWait)||0,e):a,p="trailing"in i?!!i.trailing:p),y.cancel=function(){h!==r&&Mi(h),l=0,o=c=s=h=r},y.flush=function(){return h===r?u:w(Ss())},y}var Ts=Xn((function(t,e){return cn(t,1,e)})),Os=Xn((function(t,e,r){return cn(t,da(e)||0,r)}));function Is(t,e){if("function"!=typeof t||null!=e&&"function"!=typeof e)throw new At(n);var r=function(){var n=arguments,i=e?e.apply(this,n):n[0],o=r.cache;if(o.has(i))return o.get(i);var s=t.apply(this,n);return r.cache=o.set(i,s)||o,s};return r.cache=new(Is.Cache||Hr),r}function Ds(t){if("function"!=typeof t)throw new At(n);return function(){var e=arguments;switch(e.length){case 0:return!t.call(this);case 1:return!t.call(this,e[0]);case 2:return!t.call(this,e[0],e[1]);case 3:return!t.call(this,e[0],e[1],e[2])}return!t.apply(this,e)}}Is.Cache=Hr;var Ps=bi((function(t,e){var r=(e=1==e.length&&qs(e[0])?Ie(e[0],Xe(uo())):Ie(vn(e,1),Xe(uo()))).length;return Xn((function(n){for(var i=-1,o=wr(n.length,r);++i<o;)n[i]=e[i].call(this,n[i]);return Se(t,this,n)}))})),Vs=Xn((function(t,e){var n=ar(e,ao(Vs));return Ji(t,a,r,e,n)})),js=Xn((function(t,e){var n=ar(e,ao(js));return Ji(t,u,r,e,n)})),Ls=ro((function(t,e){return Ji(t,c,r,r,r,e)}));function Ns(t,e){return t===e||t!=t&&e!=e}var Bs=Hi(Rn),Fs=Hi((function(t,e){return t>=e})),zs=Tn(function(){return arguments}())?Tn:function(t){return ta(t)&&Vt.call(t,"callee")&&!Kt.call(t,"callee")},qs=Mt.isArray,Us=ye?Xe(ye):function(t){return ta(t)&&Sn(t)==O};function Ws(t){return null!=t&&Qs(t.length)&&!Xs(t)}function Hs(t){return ta(t)&&Ws(t)}var Ys=Le||du,Gs=be?Xe(be):function(t){return ta(t)&&Sn(t)==y};function Ks(t){if(!ta(t))return!1;var e=Sn(t);return e==b||"[object DOMException]"==e||"string"==typeof t.message&&"string"==typeof t.name&&!na(t)}function Xs(t){if(!Zs(t))return!1;var e=Sn(t);return e==x||e==M||"[object AsyncFunction]"==e||"[object Proxy]"==e}function Js(t){return"number"==typeof t&&t==ma(t)}function Qs(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=f}function Zs(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}function ta(t){return null!=t&&"object"==typeof t}var ea=xe?Xe(xe):function(t){return ta(t)&&po(t)==_};function ra(t){return"number"==typeof t||ta(t)&&Sn(t)==$}function na(t){if(!ta(t)||Sn(t)!=S)return!1;var e=Yt(t);if(null===e)return!0;var r=Vt.call(e,"constructor")&&e.constructor;return"function"==typeof r&&r instanceof r&&Pt.call(r)==Bt}var ia=Me?Xe(Me):function(t){return ta(t)&&Sn(t)==E};var oa=_e?Xe(_e):function(t){return ta(t)&&po(t)==C};function sa(t){return"string"==typeof t||!qs(t)&&ta(t)&&Sn(t)==k}function aa(t){return"symbol"==typeof t||ta(t)&&Sn(t)==A}var ua=$e?Xe($e):function(t){return ta(t)&&Qs(t.length)&&!!se[Sn(t)]};var ha=Hi(Ln),ca=Hi((function(t,e){return t<=e}));function la(t){if(!t)return[];if(Ws(t))return sa(t)?fr(t):ki(t);if(te&&t[te])return function(t){for(var e,r=[];!(e=t.next()).done;)r.push(e.value);return r}(t[te]());var e=po(t);return(e==_?or:e==C?hr:Na)(t)}function fa(t){return t?(t=da(t))===l||t===-1/0?17976931348623157e292*(t<0?-1:1):t==t?t:0:0===t?t:0}function ma(t){var e=fa(t),r=e%1;return e==e?r?e-r:e:0}function pa(t){return t?an(ma(t),0,p):0}function da(t){if("number"==typeof t)return t;if(aa(t))return m;if(Zs(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=Zs(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=t.replace(it,"");var r=dt.test(t);return r||vt.test(t)?ce(t.slice(2),r?2:8):pt.test(t)?m:+t}function ga(t){return Ai(t,Ta(t))}function va(t){return null==t?"":hi(t)}var wa=Oi((function(t,e){if($o(e)||Ws(e))Ai(e,Aa(e),t);else for(var r in e)Vt.call(e,r)&&tn(t,r,e[r])})),ya=Oi((function(t,e){Ai(e,Ta(e),t)})),ba=Oi((function(t,e,r,n){Ai(e,Ta(e),t,n)})),xa=Oi((function(t,e,r,n){Ai(e,Aa(e),t,n)})),Ma=ro(sn);var _a=Xn((function(t,e){t=Et(t);var n=-1,i=e.length,o=i>2?e[2]:r;for(o&&bo(e[0],e[1],o)&&(i=1);++n<i;)for(var s=e[n],a=Ta(s),u=-1,h=a.length;++u<h;){var c=a[u],l=t[c];(l===r||Ns(l,It[c])&&!Vt.call(t,c))&&(t[c]=s[c])}return t})),$a=Xn((function(t){return t.push(r,Zi),Se(Ia,r,t)}));function Sa(t,e,n){var i=null==t?r:_n(t,e);return i===r?n:i}function Ra(t,e){return null!=t&&go(t,e,Cn)}var Ea=Fi((function(t,e,r){null!=e&&"function"!=typeof e.toString&&(e=Nt.call(e)),t[e]=r}),Za(ru)),Ca=Fi((function(t,e,r){null!=e&&"function"!=typeof e.toString&&(e=Nt.call(e)),Vt.call(t,e)?t[e].push(r):t[e]=[r]}),uo),ka=Xn(An);function Aa(t){return Ws(t)?Kr(t):Vn(t)}function Ta(t){return Ws(t)?Kr(t,!0):jn(t)}var Oa=Oi((function(t,e,r){zn(t,e,r)})),Ia=Oi((function(t,e,r,n){zn(t,e,r,n)})),Da=ro((function(t,e){var r={};if(null==t)return r;var n=!1;e=Ie(e,(function(e){return e=yi(e,t),n||(n=e.length>1),e})),Ai(t,io(t),r),n&&(r=un(r,7,to));for(var i=e.length;i--;)li(r,e[i]);return r}));var Pa=ro((function(t,e){return null==t?{}:function(t,e){return Wn(t,e,(function(e,r){return Ra(t,r)}))}(t,e)}));function Va(t,e){if(null==t)return{};var r=Ie(io(t),(function(t){return[t]}));return e=uo(e),Wn(t,r,(function(t,r){return e(t,r[0])}))}var ja=Xi(Aa),La=Xi(Ta);function Na(t){return null==t?[]:Je(t,Aa(t))}var Ba=Vi((function(t,e,r){return e=e.toLowerCase(),t+(r?Fa(e):e)}));function Fa(t){return Ka(va(t).toLowerCase())}function za(t){return(t=va(t))&&t.replace(yt,er).replace(Zt,"")}var qa=Vi((function(t,e,r){return t+(r?"-":"")+e.toLowerCase()})),Ua=Vi((function(t,e,r){return t+(r?" ":"")+e.toLowerCase()})),Wa=Pi("toLowerCase");var Ha=Vi((function(t,e,r){return t+(r?"_":"")+e.toLowerCase()}));var Ya=Vi((function(t,e,r){return t+(r?" ":"")+Ka(e)}));var Ga=Vi((function(t,e,r){return t+(r?" ":"")+e.toUpperCase()})),Ka=Pi("toUpperCase");function Xa(t,e,n){return t=va(t),(e=n?r:e)===r?function(t){return ne.test(t)}(t)?function(t){return t.match(ee)||[]}(t):function(t){return t.match(ct)||[]}(t):t.match(e)||[]}var Ja=Xn((function(t,e){try{return Se(t,r,e)}catch(t){return Ks(t)?t:new $t(t)}})),Qa=ro((function(t,e){return Ee(e,(function(e){e=Vo(e),on(t,e,Cs(t[e],t))})),t}));function Za(t){return function(){return t}}var tu=Ni(),eu=Ni(!0);function ru(t){return t}function nu(t){return Pn("function"==typeof t?t:un(t,1))}var iu=Xn((function(t,e){return function(r){return An(r,t,e)}})),ou=Xn((function(t,e){return function(r){return An(t,r,e)}}));function su(t,e,r){var n=Aa(e),i=Mn(e,n);null!=r||Zs(e)&&(i.length||!n.length)||(r=e,e=t,t=this,i=Mn(e,Aa(e)));var o=!(Zs(r)&&"chain"in r&&!r.chain),s=Xs(t);return Ee(i,(function(r){var n=e[r];t[r]=n,s&&(t.prototype[r]=function(){var e=this.__chain__;if(o||e){var r=t(this.__wrapped__);return(r.__actions__=ki(this.__actions__)).push({func:n,args:arguments,thisArg:t}),r.__chain__=e,r}return n.apply(t,De([this.value()],arguments))})})),t}function au(){}var uu=qi(Ie),hu=qi(ke),cu=qi(je);function lu(t){return xo(t)?We(Vo(t)):function(t){return function(e){return _n(e,t)}}(t)}var fu=Wi(),mu=Wi(!0);function pu(){return[]}function du(){return!1}var gu=zi((function(t,e){return t+e}),0),vu=Gi("ceil"),wu=zi((function(t,e){return t/e}),1),yu=Gi("floor");var bu,xu=zi((function(t,e){return t*e}),1),Mu=Gi("round"),_u=zi((function(t,e){return t-e}),0);return Nr.after=function(t,e){if("function"!=typeof e)throw new At(n);return t=ma(t),function(){if(--t<1)return e.apply(this,arguments)}},Nr.ary=Rs,Nr.assign=wa,Nr.assignIn=ya,Nr.assignInWith=ba,Nr.assignWith=xa,Nr.at=Ma,Nr.before=Es,Nr.bind=Cs,Nr.bindAll=Qa,Nr.bindKey=ks,Nr.castArray=function(){if(!arguments.length)return[];var t=arguments[0];return qs(t)?t:[t]},Nr.chain=ls,Nr.chunk=function(t,e,n){e=(n?bo(t,e,n):e===r)?1:vr(ma(e),0);var i=null==t?0:t.length;if(!i||e<1)return[];for(var o=0,s=0,a=Mt(de(i/e));o<i;)a[s++]=ni(t,o,o+=e);return a},Nr.compact=function(t){for(var e=-1,r=null==t?0:t.length,n=0,i=[];++e<r;){var o=t[e];o&&(i[n++]=o)}return i},Nr.concat=function(){var t=arguments.length;if(!t)return[];for(var e=Mt(t-1),r=arguments[0],n=t;n--;)e[n-1]=arguments[n];return De(qs(r)?ki(r):[r],vn(e,1))},Nr.cond=function(t){var e=null==t?0:t.length,r=uo();return t=e?Ie(t,(function(t){if("function"!=typeof t[1])throw new At(n);return[r(t[0]),t[1]]})):[],Xn((function(r){for(var n=-1;++n<e;){var i=t[n];if(Se(i[0],this,r))return Se(i[1],this,r)}}))},Nr.conforms=function(t){return function(t){var e=Aa(t);return function(r){return hn(r,t,e)}}(un(t,1))},Nr.constant=Za,Nr.countBy=ps,Nr.create=function(t,e){var r=Br(t);return null==e?r:nn(r,e)},Nr.curry=function t(e,n,i){var o=Ji(e,8,r,r,r,r,r,n=i?r:n);return o.placeholder=t.placeholder,o},Nr.curryRight=function t(e,n,i){var o=Ji(e,s,r,r,r,r,r,n=i?r:n);return o.placeholder=t.placeholder,o},Nr.debounce=As,Nr.defaults=_a,Nr.defaultsDeep=$a,Nr.defer=Ts,Nr.delay=Os,Nr.difference=No,Nr.differenceBy=Bo,Nr.differenceWith=Fo,Nr.drop=function(t,e,n){var i=null==t?0:t.length;return i?ni(t,(e=n||e===r?1:ma(e))<0?0:e,i):[]},Nr.dropRight=function(t,e,n){var i=null==t?0:t.length;return i?ni(t,0,(e=i-(e=n||e===r?1:ma(e)))<0?0:e):[]},Nr.dropRightWhile=function(t,e){return t&&t.length?mi(t,uo(e,3),!0,!0):[]},Nr.dropWhile=function(t,e){return t&&t.length?mi(t,uo(e,3),!0):[]},Nr.fill=function(t,e,n,i){var o=null==t?0:t.length;return o?(n&&"number"!=typeof n&&bo(t,e,n)&&(n=0,i=o),function(t,e,n,i){var o=t.length;for((n=ma(n))<0&&(n=-n>o?0:o+n),(i=i===r||i>o?o:ma(i))<0&&(i+=o),i=n>i?0:pa(i);n<i;)t[n++]=e;return t}(t,e,n,i)):[]},Nr.filter=function(t,e){return(qs(t)?Ae:gn)(t,uo(e,3))},Nr.flatMap=function(t,e){return vn(Ms(t,e),1)},Nr.flatMapDeep=function(t,e){return vn(Ms(t,e),l)},Nr.flatMapDepth=function(t,e,n){return n=n===r?1:ma(n),vn(Ms(t,e),n)},Nr.flatten=Uo,Nr.flattenDeep=function(t){return(null==t?0:t.length)?vn(t,l):[]},Nr.flattenDepth=function(t,e){return(null==t?0:t.length)?vn(t,e=e===r?1:ma(e)):[]},Nr.flip=function(t){return Ji(t,512)},Nr.flow=tu,Nr.flowRight=eu,Nr.fromPairs=function(t){for(var e=-1,r=null==t?0:t.length,n={};++e<r;){var i=t[e];n[i[0]]=i[1]}return n},Nr.functions=function(t){return null==t?[]:Mn(t,Aa(t))},Nr.functionsIn=function(t){return null==t?[]:Mn(t,Ta(t))},Nr.groupBy=ys,Nr.initial=function(t){return(null==t?0:t.length)?ni(t,0,-1):[]},Nr.intersection=Ho,Nr.intersectionBy=Yo,Nr.intersectionWith=Go,Nr.invert=Ea,Nr.invertBy=Ca,Nr.invokeMap=bs,Nr.iteratee=nu,Nr.keyBy=xs,Nr.keys=Aa,Nr.keysIn=Ta,Nr.map=Ms,Nr.mapKeys=function(t,e){var r={};return e=uo(e,3),bn(t,(function(t,n,i){on(r,e(t,n,i),t)})),r},Nr.mapValues=function(t,e){var r={};return e=uo(e,3),bn(t,(function(t,n,i){on(r,n,e(t,n,i))})),r},Nr.matches=function(t){return Bn(un(t,1))},Nr.matchesProperty=function(t,e){return Fn(t,un(e,1))},Nr.memoize=Is,Nr.merge=Oa,Nr.mergeWith=Ia,Nr.method=iu,Nr.methodOf=ou,Nr.mixin=su,Nr.negate=Ds,Nr.nthArg=function(t){return t=ma(t),Xn((function(e){return qn(e,t)}))},Nr.omit=Da,Nr.omitBy=function(t,e){return Va(t,Ds(uo(e)))},Nr.once=function(t){return Es(2,t)},Nr.orderBy=function(t,e,n,i){return null==t?[]:(qs(e)||(e=null==e?[]:[e]),qs(n=i?r:n)||(n=null==n?[]:[n]),Un(t,e,n))},Nr.over=uu,Nr.overArgs=Ps,Nr.overEvery=hu,Nr.overSome=cu,Nr.partial=Vs,Nr.partialRight=js,Nr.partition=_s,Nr.pick=Pa,Nr.pickBy=Va,Nr.property=lu,Nr.propertyOf=function(t){return function(e){return null==t?r:_n(t,e)}},Nr.pull=Xo,Nr.pullAll=Jo,Nr.pullAllBy=function(t,e,r){return t&&t.length&&e&&e.length?Hn(t,e,uo(r,2)):t},Nr.pullAllWith=function(t,e,n){return t&&t.length&&e&&e.length?Hn(t,e,r,n):t},Nr.pullAt=Qo,Nr.range=fu,Nr.rangeRight=mu,Nr.rearg=Ls,Nr.reject=function(t,e){return(qs(t)?Ae:gn)(t,Ds(uo(e,3)))},Nr.remove=function(t,e){var r=[];if(!t||!t.length)return r;var n=-1,i=[],o=t.length;for(e=uo(e,3);++n<o;){var s=t[n];e(s,n,t)&&(r.push(s),i.push(n))}return Yn(t,i),r},Nr.rest=function(t,e){if("function"!=typeof t)throw new At(n);return Xn(t,e=e===r?e:ma(e))},Nr.reverse=Zo,Nr.sampleSize=function(t,e,n){return e=(n?bo(t,e,n):e===r)?1:ma(e),(qs(t)?Jr:Qn)(t,e)},Nr.set=function(t,e,r){return null==t?t:Zn(t,e,r)},Nr.setWith=function(t,e,n,i){return i="function"==typeof i?i:r,null==t?t:Zn(t,e,n,i)},Nr.shuffle=function(t){return(qs(t)?Qr:ri)(t)},Nr.slice=function(t,e,n){var i=null==t?0:t.length;return i?(n&&"number"!=typeof n&&bo(t,e,n)?(e=0,n=i):(e=null==e?0:ma(e),n=n===r?i:ma(n)),ni(t,e,n)):[]},Nr.sortBy=$s,Nr.sortedUniq=function(t){return t&&t.length?ai(t):[]},Nr.sortedUniqBy=function(t,e){return t&&t.length?ai(t,uo(e,2)):[]},Nr.split=function(t,e,n){return n&&"number"!=typeof n&&bo(t,e,n)&&(e=n=r),(n=n===r?p:n>>>0)?(t=va(t))&&("string"==typeof e||null!=e&&!ia(e))&&!(e=hi(e))&&ir(t)?xi(fr(t),0,n):t.split(e,n):[]},Nr.spread=function(t,e){if("function"!=typeof t)throw new At(n);return e=null==e?0:vr(ma(e),0),Xn((function(r){var n=r[e],i=xi(r,0,e);return n&&De(i,n),Se(t,this,i)}))},Nr.tail=function(t){var e=null==t?0:t.length;return e?ni(t,1,e):[]},Nr.take=function(t,e,n){return t&&t.length?ni(t,0,(e=n||e===r?1:ma(e))<0?0:e):[]},Nr.takeRight=function(t,e,n){var i=null==t?0:t.length;return i?ni(t,(e=i-(e=n||e===r?1:ma(e)))<0?0:e,i):[]},Nr.takeRightWhile=function(t,e){return t&&t.length?mi(t,uo(e,3),!1,!0):[]},Nr.takeWhile=function(t,e){return t&&t.length?mi(t,uo(e,3)):[]},Nr.tap=function(t,e){return e(t),t},Nr.throttle=function(t,e,r){var i=!0,o=!0;if("function"!=typeof t)throw new At(n);return Zs(r)&&(i="leading"in r?!!r.leading:i,o="trailing"in r?!!r.trailing:o),As(t,e,{leading:i,maxWait:e,trailing:o})},Nr.thru=fs,Nr.toArray=la,Nr.toPairs=ja,Nr.toPairsIn=La,Nr.toPath=function(t){return qs(t)?Ie(t,Vo):aa(t)?[t]:ki(Po(va(t)))},Nr.toPlainObject=ga,Nr.transform=function(t,e,r){var n=qs(t),i=n||Ys(t)||ua(t);if(e=uo(e,4),null==r){var o=t&&t.constructor;r=i?n?new o:[]:Zs(t)&&Xs(o)?Br(Yt(t)):{}}return(i?Ee:bn)(t,(function(t,n,i){return e(r,t,n,i)})),r},Nr.unary=function(t){return Rs(t,1)},Nr.union=ts,Nr.unionBy=es,Nr.unionWith=rs,Nr.uniq=function(t){return t&&t.length?ci(t):[]},Nr.uniqBy=function(t,e){return t&&t.length?ci(t,uo(e,2)):[]},Nr.uniqWith=function(t,e){return e="function"==typeof e?e:r,t&&t.length?ci(t,r,e):[]},Nr.unset=function(t,e){return null==t||li(t,e)},Nr.unzip=ns,Nr.unzipWith=is,Nr.update=function(t,e,r){return null==t?t:fi(t,e,wi(r))},Nr.updateWith=function(t,e,n,i){return i="function"==typeof i?i:r,null==t?t:fi(t,e,wi(n),i)},Nr.values=Na,Nr.valuesIn=function(t){return null==t?[]:Je(t,Ta(t))},Nr.without=os,Nr.words=Xa,Nr.wrap=function(t,e){return Vs(wi(e),t)},Nr.xor=ss,Nr.xorBy=as,Nr.xorWith=us,Nr.zip=hs,Nr.zipObject=function(t,e){return gi(t||[],e||[],tn)},Nr.zipObjectDeep=function(t,e){return gi(t||[],e||[],Zn)},Nr.zipWith=cs,Nr.entries=ja,Nr.entriesIn=La,Nr.extend=ya,Nr.extendWith=ba,su(Nr,Nr),Nr.add=gu,Nr.attempt=Ja,Nr.camelCase=Ba,Nr.capitalize=Fa,Nr.ceil=vu,Nr.clamp=function(t,e,n){return n===r&&(n=e,e=r),n!==r&&(n=(n=da(n))==n?n:0),e!==r&&(e=(e=da(e))==e?e:0),an(da(t),e,n)},Nr.clone=function(t){return un(t,4)},Nr.cloneDeep=function(t){return un(t,5)},Nr.cloneDeepWith=function(t,e){return un(t,5,e="function"==typeof e?e:r)},Nr.cloneWith=function(t,e){return un(t,4,e="function"==typeof e?e:r)},Nr.conformsTo=function(t,e){return null==e||hn(t,e,Aa(e))},Nr.deburr=za,Nr.defaultTo=function(t,e){return null==t||t!=t?e:t},Nr.divide=wu,Nr.endsWith=function(t,e,n){t=va(t),e=hi(e);var i=t.length,o=n=n===r?i:an(ma(n),0,i);return(n-=e.length)>=0&&t.slice(n,o)==e},Nr.eq=Ns,Nr.escape=function(t){return(t=va(t))&&K.test(t)?t.replace(Y,rr):t},Nr.escapeRegExp=function(t){return(t=va(t))&&nt.test(t)?t.replace(rt,"\\$&"):t},Nr.every=function(t,e,n){var i=qs(t)?ke:pn;return n&&bo(t,e,n)&&(e=r),i(t,uo(e,3))},Nr.find=ds,Nr.findIndex=zo,Nr.findKey=function(t,e){return Ne(t,uo(e,3),bn)},Nr.findLast=gs,Nr.findLastIndex=qo,Nr.findLastKey=function(t,e){return Ne(t,uo(e,3),xn)},Nr.floor=yu,Nr.forEach=vs,Nr.forEachRight=ws,Nr.forIn=function(t,e){return null==t?t:wn(t,uo(e,3),Ta)},Nr.forInRight=function(t,e){return null==t?t:yn(t,uo(e,3),Ta)},Nr.forOwn=function(t,e){return t&&bn(t,uo(e,3))},Nr.forOwnRight=function(t,e){return t&&xn(t,uo(e,3))},Nr.get=Sa,Nr.gt=Bs,Nr.gte=Fs,Nr.has=function(t,e){return null!=t&&go(t,e,En)},Nr.hasIn=Ra,Nr.head=Wo,Nr.identity=ru,Nr.includes=function(t,e,r,n){t=Ws(t)?t:Na(t),r=r&&!n?ma(r):0;var i=t.length;return r<0&&(r=vr(i+r,0)),sa(t)?r<=i&&t.indexOf(e,r)>-1:!!i&&Fe(t,e,r)>-1},Nr.indexOf=function(t,e,r){var n=null==t?0:t.length;if(!n)return-1;var i=null==r?0:ma(r);return i<0&&(i=vr(n+i,0)),Fe(t,e,i)},Nr.inRange=function(t,e,n){return e=fa(e),n===r?(n=e,e=0):n=fa(n),function(t,e,r){return t>=wr(e,r)&&t<vr(e,r)}(t=da(t),e,n)},Nr.invoke=ka,Nr.isArguments=zs,Nr.isArray=qs,Nr.isArrayBuffer=Us,Nr.isArrayLike=Ws,Nr.isArrayLikeObject=Hs,Nr.isBoolean=function(t){return!0===t||!1===t||ta(t)&&Sn(t)==w},Nr.isBuffer=Ys,Nr.isDate=Gs,Nr.isElement=function(t){return ta(t)&&1===t.nodeType&&!na(t)},Nr.isEmpty=function(t){if(null==t)return!0;if(Ws(t)&&(qs(t)||"string"==typeof t||"function"==typeof t.splice||Ys(t)||ua(t)||zs(t)))return!t.length;var e=po(t);if(e==_||e==C)return!t.size;if($o(t))return!Vn(t).length;for(var r in t)if(Vt.call(t,r))return!1;return!0},Nr.isEqual=function(t,e){return On(t,e)},Nr.isEqualWith=function(t,e,n){var i=(n="function"==typeof n?n:r)?n(t,e):r;return i===r?On(t,e,r,n):!!i},Nr.isError=Ks,Nr.isFinite=function(t){return"number"==typeof t&&He(t)},Nr.isFunction=Xs,Nr.isInteger=Js,Nr.isLength=Qs,Nr.isMap=ea,Nr.isMatch=function(t,e){return t===e||In(t,e,co(e))},Nr.isMatchWith=function(t,e,n){return n="function"==typeof n?n:r,In(t,e,co(e),n)},Nr.isNaN=function(t){return ra(t)&&t!=+t},Nr.isNative=function(t){if(_o(t))throw new $t("Unsupported core-js use. Try https://npms.io/search?q=ponyfill.");return Dn(t)},Nr.isNil=function(t){return null==t},Nr.isNull=function(t){return null===t},Nr.isNumber=ra,Nr.isObject=Zs,Nr.isObjectLike=ta,Nr.isPlainObject=na,Nr.isRegExp=ia,Nr.isSafeInteger=function(t){return Js(t)&&t>=-9007199254740991&&t<=f},Nr.isSet=oa,Nr.isString=sa,Nr.isSymbol=aa,Nr.isTypedArray=ua,Nr.isUndefined=function(t){return t===r},Nr.isWeakMap=function(t){return ta(t)&&po(t)==T},Nr.isWeakSet=function(t){return ta(t)&&"[object WeakSet]"==Sn(t)},Nr.join=function(t,e){return null==t?"":dr.call(t,e)},Nr.kebabCase=qa,Nr.last=Ko,Nr.lastIndexOf=function(t,e,n){var i=null==t?0:t.length;if(!i)return-1;var o=i;return n!==r&&(o=(o=ma(n))<0?vr(i+o,0):wr(o,i-1)),e==e?function(t,e,r){for(var n=r+1;n--;)if(t[n]===e)return n;return n}(t,e,o):Be(t,qe,o,!0)},Nr.lowerCase=Ua,Nr.lowerFirst=Wa,Nr.lt=ha,Nr.lte=ca,Nr.max=function(t){return t&&t.length?dn(t,ru,Rn):r},Nr.maxBy=function(t,e){return t&&t.length?dn(t,uo(e,2),Rn):r},Nr.mean=function(t){return Ue(t,ru)},Nr.meanBy=function(t,e){return Ue(t,uo(e,2))},Nr.min=function(t){return t&&t.length?dn(t,ru,Ln):r},Nr.minBy=function(t,e){return t&&t.length?dn(t,uo(e,2),Ln):r},Nr.stubArray=pu,Nr.stubFalse=du,Nr.stubObject=function(){return{}},Nr.stubString=function(){return""},Nr.stubTrue=function(){return!0},Nr.multiply=xu,Nr.nth=function(t,e){return t&&t.length?qn(t,ma(e)):r},Nr.noConflict=function(){return me._===this&&(me._=Ft),this},Nr.noop=au,Nr.now=Ss,Nr.pad=function(t,e,r){t=va(t);var n=(e=ma(e))?lr(t):0;if(!e||n>=e)return t;var i=(e-n)/2;return Ui(ve(i),r)+t+Ui(de(i),r)},Nr.padEnd=function(t,e,r){t=va(t);var n=(e=ma(e))?lr(t):0;return e&&n<e?t+Ui(e-n,r):t},Nr.padStart=function(t,e,r){t=va(t);var n=(e=ma(e))?lr(t):0;return e&&n<e?Ui(e-n,r)+t:t},Nr.parseInt=function(t,e,r){return r||null==e?e=0:e&&(e=+e),br(va(t).replace(ot,""),e||0)},Nr.random=function(t,e,n){if(n&&"boolean"!=typeof n&&bo(t,e,n)&&(e=n=r),n===r&&("boolean"==typeof e?(n=e,e=r):"boolean"==typeof t&&(n=t,t=r)),t===r&&e===r?(t=0,e=1):(t=fa(t),e===r?(e=t,t=0):e=fa(e)),t>e){var i=t;t=e,e=i}if(n||t%1||e%1){var o=xr();return wr(t+o*(e-t+he("1e-"+((o+"").length-1))),e)}return Gn(t,e)},Nr.reduce=function(t,e,r){var n=qs(t)?Pe:Ye,i=arguments.length<3;return n(t,uo(e,4),r,i,fn)},Nr.reduceRight=function(t,e,r){var n=qs(t)?Ve:Ye,i=arguments.length<3;return n(t,uo(e,4),r,i,mn)},Nr.repeat=function(t,e,n){return e=(n?bo(t,e,n):e===r)?1:ma(e),Kn(va(t),e)},Nr.replace=function(){var t=arguments,e=va(t[0]);return t.length<3?e:e.replace(t[1],t[2])},Nr.result=function(t,e,n){var i=-1,o=(e=yi(e,t)).length;for(o||(o=1,t=r);++i<o;){var s=null==t?r:t[Vo(e[i])];s===r&&(i=o,s=n),t=Xs(s)?s.call(t):s}return t},Nr.round=Mu,Nr.runInContext=t,Nr.sample=function(t){return(qs(t)?Xr:Jn)(t)},Nr.size=function(t){if(null==t)return 0;if(Ws(t))return sa(t)?lr(t):t.length;var e=po(t);return e==_||e==C?t.size:Vn(t).length},Nr.snakeCase=Ha,Nr.some=function(t,e,n){var i=qs(t)?je:ii;return n&&bo(t,e,n)&&(e=r),i(t,uo(e,3))},Nr.sortedIndex=function(t,e){return oi(t,e)},Nr.sortedIndexBy=function(t,e,r){return si(t,e,uo(r,2))},Nr.sortedIndexOf=function(t,e){var r=null==t?0:t.length;if(r){var n=oi(t,e);if(n<r&&Ns(t[n],e))return n}return-1},Nr.sortedLastIndex=function(t,e){return oi(t,e,!0)},Nr.sortedLastIndexBy=function(t,e,r){return si(t,e,uo(r,2),!0)},Nr.sortedLastIndexOf=function(t,e){if(null==t?0:t.length){var r=oi(t,e,!0)-1;if(Ns(t[r],e))return r}return-1},Nr.startCase=Ya,Nr.startsWith=function(t,e,r){return t=va(t),r=null==r?0:an(ma(r),0,t.length),e=hi(e),t.slice(r,r+e.length)==e},Nr.subtract=_u,Nr.sum=function(t){return t&&t.length?Ge(t,ru):0},Nr.sumBy=function(t,e){return t&&t.length?Ge(t,uo(e,2)):0},Nr.template=function(t,e,n){var i=Nr.templateSettings;n&&bo(t,e,n)&&(e=r),t=va(t),e=ba({},e,i,Qi);var o,s,a=ba({},e.imports,i.imports,Qi),u=Aa(a),h=Je(a,u),c=0,l=e.interpolate||bt,f="__p += '",m=Ct((e.escape||bt).source+"|"+l.source+"|"+(l===Q?ft:bt).source+"|"+(e.evaluate||bt).source+"|$","g"),p="//# sourceURL="+("sourceURL"in e?e.sourceURL:"lodash.templateSources["+ ++oe+"]")+"\n";t.replace(m,(function(e,r,n,i,a,u){return n||(n=i),f+=t.slice(c,u).replace(xt,nr),r&&(o=!0,f+="' +\n__e("+r+") +\n'"),a&&(s=!0,f+="';\n"+a+";\n__p += '"),n&&(f+="' +\n((__t = ("+n+")) == null ? '' : __t) +\n'"),c=u+e.length,e})),f+="';\n";var d=e.variable;d||(f="with (obj) {\n"+f+"\n}\n"),f=(s?f.replace(q,""):f).replace(U,"$1").replace(W,"$1;"),f="function("+(d||"obj")+") {\n"+(d?"":"obj || (obj = {});\n")+"var __t, __p = ''"+(o?", __e = _.escape":"")+(s?", __j = Array.prototype.join;\nfunction print() { __p += __j.call(arguments, '') }\n":";\n")+f+"return __p\n}";var g=Ja((function(){return St(u,p+"return "+f).apply(r,h)}));if(g.source=f,Ks(g))throw g;return g},Nr.times=function(t,e){if((t=ma(t))<1||t>f)return[];var r=p,n=wr(t,p);e=uo(e),t-=p;for(var i=Ke(n,e);++r<t;)e(r);return i},Nr.toFinite=fa,Nr.toInteger=ma,Nr.toLength=pa,Nr.toLower=function(t){return va(t).toLowerCase()},Nr.toNumber=da,Nr.toSafeInteger=function(t){return t?an(ma(t),-9007199254740991,f):0===t?t:0},Nr.toString=va,Nr.toUpper=function(t){return va(t).toUpperCase()},Nr.trim=function(t,e,n){if((t=va(t))&&(n||e===r))return t.replace(it,"");if(!t||!(e=hi(e)))return t;var i=fr(t),o=fr(e);return xi(i,Ze(i,o),tr(i,o)+1).join("")},Nr.trimEnd=function(t,e,n){if((t=va(t))&&(n||e===r))return t.replace(st,"");if(!t||!(e=hi(e)))return t;var i=fr(t);return xi(i,0,tr(i,fr(e))+1).join("")},Nr.trimStart=function(t,e,n){if((t=va(t))&&(n||e===r))return t.replace(ot,"");if(!t||!(e=hi(e)))return t;var i=fr(t);return xi(i,Ze(i,fr(e))).join("")},Nr.truncate=function(t,e){var n=30,i="...";if(Zs(e)){var o="separator"in e?e.separator:o;n="length"in e?ma(e.length):n,i="omission"in e?hi(e.omission):i}var s=(t=va(t)).length;if(ir(t)){var a=fr(t);s=a.length}if(n>=s)return t;var u=n-lr(i);if(u<1)return i;var h=a?xi(a,0,u).join(""):t.slice(0,u);if(o===r)return h+i;if(a&&(u+=h.length-u),ia(o)){if(t.slice(u).search(o)){var c,l=h;for(o.global||(o=Ct(o.source,va(mt.exec(o))+"g")),o.lastIndex=0;c=o.exec(l);)var f=c.index;h=h.slice(0,f===r?u:f)}}else if(t.indexOf(hi(o),u)!=u){var m=h.lastIndexOf(o);m>-1&&(h=h.slice(0,m))}return h+i},Nr.unescape=function(t){return(t=va(t))&&G.test(t)?t.replace(H,mr):t},Nr.uniqueId=function(t){var e=++jt;return va(t)+e},Nr.upperCase=Ga,Nr.upperFirst=Ka,Nr.each=vs,Nr.eachRight=ws,Nr.first=Wo,su(Nr,(bu={},bn(Nr,(function(t,e){Vt.call(Nr.prototype,e)||(bu[e]=t)})),bu),{chain:!1}),Nr.VERSION="4.17.10",Ee(["bind","bindKey","curry","curryRight","partial","partialRight"],(function(t){Nr[t].placeholder=Nr})),Ee(["drop","take"],(function(t,e){qr.prototype[t]=function(n){n=n===r?1:vr(ma(n),0);var i=this.__filtered__&&!e?new qr(this):this.clone();return i.__filtered__?i.__takeCount__=wr(n,i.__takeCount__):i.__views__.push({size:wr(n,p),type:t+(i.__dir__<0?"Right":"")}),i},qr.prototype[t+"Right"]=function(e){return this.reverse()[t](e).reverse()}})),Ee(["filter","map","takeWhile"],(function(t,e){var r=e+1,n=1==r||3==r;qr.prototype[t]=function(t){var e=this.clone();return e.__iteratees__.push({iteratee:uo(t,3),type:r}),e.__filtered__=e.__filtered__||n,e}})),Ee(["head","last"],(function(t,e){var r="take"+(e?"Right":"");qr.prototype[t]=function(){return this[r](1).value()[0]}})),Ee(["initial","tail"],(function(t,e){var r="drop"+(e?"":"Right");qr.prototype[t]=function(){return this.__filtered__?new qr(this):this[r](1)}})),qr.prototype.compact=function(){return this.filter(ru)},qr.prototype.find=function(t){return this.filter(t).head()},qr.prototype.findLast=function(t){return this.reverse().find(t)},qr.prototype.invokeMap=Xn((function(t,e){return"function"==typeof t?new qr(this):this.map((function(r){return An(r,t,e)}))})),qr.prototype.reject=function(t){return this.filter(Ds(uo(t)))},qr.prototype.slice=function(t,e){t=ma(t);var n=this;return n.__filtered__&&(t>0||e<0)?new qr(n):(t<0?n=n.takeRight(-t):t&&(n=n.drop(t)),e!==r&&(n=(e=ma(e))<0?n.dropRight(-e):n.take(e-t)),n)},qr.prototype.takeRightWhile=function(t){return this.reverse().takeWhile(t).reverse()},qr.prototype.toArray=function(){return this.take(p)},bn(qr.prototype,(function(t,e){var n=/^(?:filter|find|map|reject)|While$/.test(e),i=/^(?:head|last)$/.test(e),o=Nr[i?"take"+("last"==e?"Right":""):e],s=i||/^find/.test(e);o&&(Nr.prototype[e]=function(){var e=this.__wrapped__,a=i?[1]:arguments,u=e instanceof qr,h=a[0],c=u||qs(e),l=function(t){var e=o.apply(Nr,De([t],a));return i&&f?e[0]:e};c&&n&&"function"==typeof h&&1!=h.length&&(u=c=!1);var f=this.__chain__,m=!!this.__actions__.length,p=s&&!f,d=u&&!m;if(!s&&c){e=d?e:new qr(this);var g=t.apply(e,a);return g.__actions__.push({func:fs,args:[l],thisArg:r}),new zr(g,f)}return p&&d?t.apply(this,a):(g=this.thru(l),p?i?g.value()[0]:g.value():g)})})),Ee(["pop","push","shift","sort","splice","unshift"],(function(t){var e=Tt[t],r=/^(?:push|sort|unshift)$/.test(t)?"tap":"thru",n=/^(?:pop|shift)$/.test(t);Nr.prototype[t]=function(){var t=arguments;if(n&&!this.__chain__){var i=this.value();return e.apply(qs(i)?i:[],t)}return this[r]((function(r){return e.apply(qs(r)?r:[],t)}))}})),bn(qr.prototype,(function(t,e){var r=Nr[e];if(r){var n=r.name+"";(Ar[n]||(Ar[n]=[])).push({name:e,func:r})}})),Ar[Bi(r,2).name]=[{name:"wrapper",func:r}],qr.prototype.clone=function(){var t=new qr(this.__wrapped__);return t.__actions__=ki(this.__actions__),t.__dir__=this.__dir__,t.__filtered__=this.__filtered__,t.__iteratees__=ki(this.__iteratees__),t.__takeCount__=this.__takeCount__,t.__views__=ki(this.__views__),t},qr.prototype.reverse=function(){if(this.__filtered__){var t=new qr(this);t.__dir__=-1,t.__filtered__=!0}else(t=this.clone()).__dir__*=-1;return t},qr.prototype.value=function(){var t=this.__wrapped__.value(),e=this.__dir__,r=qs(t),n=e<0,i=r?t.length:0,o=function(t,e,r){var n=-1,i=r.length;for(;++n<i;){var o=r[n],s=o.size;switch(o.type){case"drop":t+=s;break;case"dropRight":e-=s;break;case"take":e=wr(e,t+s);break;case"takeRight":t=vr(t,e-s)}}return{start:t,end:e}}(0,i,this.__views__),s=o.start,a=o.end,u=a-s,h=n?a:s-1,c=this.__iteratees__,l=c.length,f=0,m=wr(u,this.__takeCount__);if(!r||!n&&i==u&&m==u)return pi(t,this.__actions__);var p=[];t:for(;u--&&f<m;){for(var d=-1,g=t[h+=e];++d<l;){var v=c[d],w=v.iteratee,y=v.type,b=w(g);if(2==y)g=b;else if(!b){if(1==y)continue t;break t}}p[f++]=g}return p},Nr.prototype.at=ms,Nr.prototype.chain=function(){return ls(this)},Nr.prototype.commit=function(){return new zr(this.value(),this.__chain__)},Nr.prototype.next=function(){this.__values__===r&&(this.__values__=la(this.value()));var t=this.__index__>=this.__values__.length;return{done:t,value:t?r:this.__values__[this.__index__++]}},Nr.prototype.plant=function(t){for(var e,n=this;n instanceof Fr;){var i=Lo(n);i.__index__=0,i.__values__=r,e?o.__wrapped__=i:e=i;var o=i;n=n.__wrapped__}return o.__wrapped__=t,e},Nr.prototype.reverse=function(){var t=this.__wrapped__;if(t instanceof qr){var e=t;return this.__actions__.length&&(e=new qr(this)),(e=e.reverse()).__actions__.push({func:fs,args:[Zo],thisArg:r}),new zr(e,this.__chain__)}return this.thru(Zo)},Nr.prototype.toJSON=Nr.prototype.valueOf=Nr.prototype.value=function(){return pi(this.__wrapped__,this.__actions__)},Nr.prototype.first=Nr.prototype.head,te&&(Nr.prototype[te]=function(){return this}),Nr}();de?((de.exports=pr)._=pr,pe._=pr):me._=pr}).call(commonjsGlobal)})),__dirname="/Users/yawjosephetse/Developer/github/repetere/modelscript/node_modules/csvtojson/libs/core",empty={},empty$1=Object.freeze({default:empty}),require$$0$2=empty$1&&empty||empty$1,workerMgr_1=workerMgr,eom="",eom1="",eom2="";function workerMgr(){require$$0$2.spawn;var t={initWorker:function(t,i){e=[],r=0,n=null;for(var o=0;o<t;o++)e.push(new Worker(i))},sendWorker:function i(o,s,a,u){if(e.length>0){var h=e.shift();r++,h.parse(o,s,(function(o){e.push(h),u(o,s),r--,null===n&&0===r?t.drain():n&&(i.apply(this,n),n=null)})),nextTick(a)}else n=[o,s,a,u]},setParams:function(t){e.forEach((function(e){e.setParams(t)}))},drain:function(){},isRunning:function(){return r>0},destroyWorker:function(){e.forEach((function(t){t.destroy()}))}},e=[],r=0,n=null;return t}function Worker(t){var e=require$$0$2.spawn;this.cp=e(process.execPath,[__dirname+"/worker.js"],{env:{child:!0},stdio:["pipe","pipe",2,"ipc"]}),this.setParams(t),this.cp.on("message",this.onChildMsg.bind(this)),this.buffer="";var r=this;this.cp.stdout.on("data",(function(t){for(var e=t.toString("utf8"),n=(r.buffer+e).split(eom);n.length>1;)r.onChildMsg(n.shift());r.buffer=n[0]}))}Worker.prototype.setParams=function(t){var e="0"+JSON.stringify(t);this.sendMsg(e)},Worker.prototype.onChildMsg=function(t){if(t){var e=t[0],r=t.substr(1);switch(e){case"0":if(this.cbLine){var n=r.split("|"),i=parseInt(n[0]),o=n[1];this.cbLine(i,o)}break;case"1":if(this.cbResult){var s=r.split(eom1);s.pop();var a=[];s.forEach((function(t){var e=t.split(eom2);a.push({index:e[0],row:e[1],err:e[2]?CSVError_1.fromArray(JSON.parse(e[2])):null,json:e[3]})})),this.cbResult(a)}}}},Worker.prototype.parse=function(t,e,r){this.cbResult=r;var n="1"+e+"|"+t;this.sendMsg(n)},Worker.prototype.destroy=function(){this.cp.kill()},Worker.prototype.sendMsg=function(t){this.cp.stdin.write(t+eom,"utf8")};var Transform$2=require$$0.Transform,eol$1=require$$0$1.EOL,workerMgr$1=null;function Converter(t,e){return Transform$2.call(this,e),this._options=e||{},this.param=defParam(t),this.param._options=this._options,this.started=!1,this.recordNum=0,this.lineNumber=0,this._csvLineBuffer="",this.lastIndex=0,this.param.forked&&(this.param.forked=!1,this.workerNum=2),this.flushCb=null,this.processEnd=!1,this.sequenceBuffer=[],this._needJson=null,this._needEmitResult=null,this._needEmitFinalResult=null,this._needEmitHeader=null,this._needEmitJson=null,this._needPush=null,this._needEmitCsv=null,this._csvTransf=null,this.finalResult=[],this.on("error",emitDone(this)),this.on("end",emitDone(this)),this.initWorker(),nextTick(function(){null===this._needEmitFinalResult&&(this._needEmitFinalResult=this.listeners("end_parsed").length>0),null===this._needEmitResult&&(this._needEmitResult=this.listeners("record_parsed").length>0),null===this._needEmitJson&&(this._needEmitJson=this.listeners("json").length>0),null===this._needEmitHeader&&(this._needEmitHeader=this.listeners("header").length>0),null===this._needEmitCsv&&(this._needEmitCsv=this.listeners("csv").length>0),null===this._needJson&&(this._needJson=this._needEmitJson||this._needEmitFinalResult||this._needEmitResult||this.transform||this._options.objectMode),null===this._needPush&&(this._needPush=this.listeners("data").length>0||this.listeners("readable").length>0),this.param._needParseJson=this._needJson||this._needPush}.bind(this)),this}function emitDone(t){return function(e){t._hasDone||(t._hasDone=!0,nextTick((function(){t.emit("done",e)})))}}function bufFromString(t){var e=Buffer.byteLength(t),r=Buffer.allocUnsafe?Buffer.allocUnsafe(e):new Buffer(e);return r.write(t),r}function configIgnoreIncludeColumns(t){if(t._postIgnoreColumns){for(var e=0;e<t.ignoreColumns.length;e++){var r=t.ignoreColumns[e];if("string"==typeof r){var n=t._headers.indexOf(r);t.ignoreColumns[e]=n>-1?n:-1}}t.ignoreColumns.sort((function(t,e){return e-t}))}if(t._postIncludeColumns)for(e=0;e<t.includeColumns.length;e++){var i=t.includeColumns[e];if("string"==typeof i){n=t._headers.indexOf(i);t.includeColumns[e]=n>-1?n:-1}}t.ignoreColumns=lodash.uniq(t.ignoreColumns),t.includeColumns=lodash.uniq(t.includeColumns)}util$2.inherits(Converter,Transform$2),Converter.prototype._transform=function(t,e,r){var n=(t=this.prepareData(t)).length-1,i=null;if(128&t[n]){for(;128==(192&t[n]);)n--;n--}if(n!=t.length-1){i=t.slice(n+1),t=t.slice(0,n+1);var o=r,s=this;r=function(){s._csvLineBuffer?s._csvLineBuffer=Buffer.concat([bufFromString(s._csvLineBuffer,"utf8"),i]):s._csvLineBuffer=i,o()}}t=t.toString("utf8"),!1===this.started&&(this.started=!0,t=stripBom_1(t),this.param.toArrayString&&this._needPush&&this.push("["+eol$1,"utf8"));s=this;this.preProcessRaw(t,(function(t){t&&t.length>0?s.processData(t,r):r()}))},Converter.prototype.prepareData=function(t){return this._csvLineBuffer&&this._csvLineBuffer.length>0?("string"==typeof this._csvLineBuffer&&(this._csvLineBuffer=bufFromString(this._csvLineBuffer)),Buffer.concat([this._csvLineBuffer,t])):t},Converter.prototype.setPartialData=function(t){this._csvLineBuffer=t},Converter.prototype.processData=function(t,e){var r=this.param;r.ignoreEmpty&&!r._headers&&(t=t.trimLeft());var n=fileline(t,this.param);if(n.lines.length>0)if(this.preProcessLine&&"function"==typeof this.preProcessLine&&(n.lines=this._preProcessLines(n.lines,this.lastIndex)),r._headers)if(r.workerNum<=1){var i=fileLineToCSVLine(n,r);this.setPartialData(i.partial);var o=linesToJson(i.lines,r,this.recordNum);this.processResult(o),this.lastIndex+=o.length,this.recordNum+=o.length,e()}else this.workerProcess(n,e);else this.processHead(n,e);else this.setPartialData(n.partial),e()},Converter.prototype._preProcessLines=function(t,e){for(var r=[],n=0,i=t.length;n<i;n++){var o=this.preProcessLine(t[n],e+n+1);"string"==typeof o?r.push(o):(r.push(t[n]),this.emit("error",new Error("preProcessLine should return a string but got: "+JSON.stringify(o))))}return r},Converter.prototype.initWorker=function(){var t=this.param.workerNum-1;t>0&&(workerMgr$1=workerMgr_1,this.workerMgr=workerMgr$1(),this.workerMgr.initWorker(t,this.param))},Converter.prototype.preRawData=function(t){return this.preProcessRaw=t,this},Converter.prototype.preFileLine=function(t){return this.preProcessLine=t,this},Converter.prototype.workerProcess=function(t,e){var r=this,n=t,i=this.getEol();this.setPartialData(n.partial),this.workerMgr.sendWorker(n.lines.join(i)+i,this.lastIndex,e,(function(t,e){var n,i=r.sequenceBuffer[0];if(i.idx===e){i.result=t;for(var o=[];r.sequenceBuffer[0]&&r.sequenceBuffer[0].result;)n=r.sequenceBuffer.shift(),o=o.concat(n.result);r.processResult(o),r.recordNum+=o.length}else for(var s=0,a=r.sequenceBuffer.length;s<a;s++)if((n=r.sequenceBuffer[s]).idx===e){n.result=t;break}})),this.sequenceBuffer.push({idx:this.lastIndex,result:null}),this.lastIndex+=n.lines.length},Converter.prototype.processHead=function(t,e){var r=this.param;if(r._headers)return e();r._needFilterRow=!1;var n=t.lines,i="",o=[];if(!r.noheader)for(;n.length;){var s=i+n.shift(),a=rowSplit(s,r);if(a.closed){o=a.cols,i="";break}i=s+this.getEol()}if(r._needFilterRow=!0,!r.noheader&&0===o.length)return this.setPartialData(i),e();r.noheader?r.headers?r._headers=r.headers:r._headers=[]:r.headers?r._headers=r.headers:r._headers=o,configIgnoreIncludeColumns(r),r._headers=filterRow(r._headers,r),this._needEmitHeader&&this.param._headers&&this.emit("header",this.param._headers);n=fileLineToCSVLine(t,r);this.setPartialData(n.partial),this.param.workerNum>1&&this.workerMgr.setParams(r);var u=linesToJson(n.lines,r,0);this.processResult(u),this.lastIndex+=u.length,this.recordNum+=u.length,e()},Converter.prototype.processResult=function(t){for(var e=0,r=t.length;e<r;e++){var n=t[e];n.err?this.emit("error",n.err):this.emitResult(n)}},Converter.prototype.emitResult=function(t){var e=t.index,r=(this.param,t.row),n=t.json,i=null,o=null;"string"==typeof n?o=n:i=n,null===i&&this._needJson&&(i=JSON.parse(o),"string"==typeof r&&(r=JSON.parse(r))),this.transform&&"function"==typeof this.transform&&(this.transform(i,r,e),o=null),this._needEmitJson&&this.emit("json",i,e),this._needEmitCsv&&("string"==typeof r&&(r=JSON.parse(r)),this.emit("csv",r,e)),this.param.constructResult&&this._needEmitFinalResult&&this.finalResult.push(i),this._needEmitResult&&this.emit("record_parsed",i,r,e),this.param.toArrayString&&e>0&&this._needPush&&this.push(","+eol$1),this._options&&this._options.objectMode?this.push(i):this._needPush&&(null===o&&(o=JSON.stringify(i)),this.push(this.param.toArrayString?o:o+eol$1,"utf8"))},Converter.prototype.preProcessRaw=function(t,e){e(t)},Converter.prototype.preProcessLine=function(t,e){return t},Converter.prototype._flush=function(t){var e=this;if(this.flushCb=function(){e.emit("end_parsed",e.finalResult),e.workerMgr&&e.workerMgr.destroyWorker(),t(),e._needPush||e.emit("end")},this._csvLineBuffer.length>0){var r=this.getEol();this._csvLineBuffer[this._csvLineBuffer.length-1]!==r&&(this._csvLineBuffer+=r),this.processData(this._csvLineBuffer,function(){this.checkAndFlush()}.bind(this))}else this.checkAndFlush()},Converter.prototype.checkAndFlush=function(){0!==this._csvLineBuffer.length&&this.emit("error",CSVError_1.unclosed_quote(this.recordNum,this._csvLineBuffer),this._csvLineBuffer),this.param.toArrayString&&this._needPush&&this.push(eol$1+"]","utf8"),this.workerMgr&&this.workerMgr.isRunning()?this.workerMgr.drain=function(){this.flushCb()}.bind(this):this.flushCb()},Converter.prototype.getEol=function(t){if(!this.param.eol&&t){for(var e=0,r=t.length;e<r;e++){if("\r"===t[e])return"\n"===t[e+1]?this.param.eol="\r\n":this.param.eol="\r",this.param.eol;if("\n"===t[e])return this.param.eol="\n",this.param.eol}this.param.eol=eol$1}return this.param.eol||eol$1},Converter.prototype.fromFile=function(t,e,r){var n=require$$0$2,i=null;return"object"==typeof e&&void 0===r&&(r=e,e=null),this.wrapCallback(e,(function(){i&&i.destroy&&i.destroy()})),n.exists(t,function(e){e?(i=n.createReadStream(t,r)).pipe(this):this.emit("error",new Error("File not exists"))}.bind(this)),this},Converter.prototype.fromStream=function(t,e){return e&&"function"==typeof e&&this.wrapCallback(e),t.pipe(this),this},Converter.prototype.transf=function(t){return this.transform=t,this},Converter.prototype.fromString=function(t,e){return"string"!=typeof t&&e&&"function"==typeof e?e(new Error("Passed CSV Data is not a string.")):(e&&"function"==typeof e&&this.wrapCallback(e,(function(){})),nextTick(function(){this.end(t)}.bind(this)),this)},Converter.prototype.wrapCallback=function(t,e){void 0===e&&(e=function(){}),t&&"function"==typeof t&&this.once("end_parsed",function(e){this.hasError||t(null,e)}.bind(this)),this.once("error",function(r){this.hasError=!0,t&&"function"==typeof t&&t(r),e()}.bind(this))};var Converter_1=Converter,core=createCommonjsModule((function(t){t.exports=function(e,r){return new t.exports.Converter(e,r)},t.exports.Converter=Converter_1})),core_1=core.Converter,http$2=http$1&&http||http$1;function startWebServer(t){var e={port:(t=t||{}).port||"8801",urlpath:t.urlpath||"/parseCSV"},r=http$2.createServer();return r.on("request",(function(t,r){t.url===e.urlpath&&"POST"===t.method?t.pipe(new Converter_1({constructResult:!1})).pipe(r):r.end("Please post data to: "+e.urlpath)})),r.listen(e.port),console.log("CSV Web Server Listen On:"+e.port),console.log("POST to "+e.urlpath+" with CSV data to get parsed."),r}var startWebServer_1=startWebServer,webServer={startWebServer:startWebServer_1},web=webServer;function _initConverter(){var t=new Converter_1,e=!1,r=process.stdout;return t.on("record_parsed",(function(t){e&&r.write(",\n"),r.write(JSON.stringify(t)),!1===e&&(e=!0)})),r.write("[\n"),t.on("end_parsed",(function(){r.write("\n]")})),t.on("error",(function(t){console.error(t),process.exit(-1)})),t}function convertFile(t){_initConverter().from(t)}function convertString(t){_initConverter().from(t)}var convertFile_1=convertFile,convertString_1=convertString,main$1={convertFile:convertFile_1,convertString:convertString_1},cli=main$1,web$1=web,cli$1=cli,interfaces={web:web$1,cli:cli$1},core$1=core,csv2json=core,interfaces$1=interfaces;csv2json.core=core$1,csv2json.interfaces=interfaces$1;var csvtojson=csv2json;async function loadCSVURI(t,e){const r=(t.search("https","gi"),get);return new Promise(((n,i)=>{const o=[],s=Object.assign({checkType:!0},e),a=r(t,(t=>{csvtojson(s).fromStream(t).on("json",(t=>{o.push(t)})).on("error",(t=>i(t))).on("done",(t=>t?i(t):n(o)))}));a.on("error",i)}))}async function loadCSV(t,e){return validUrl.isUri(t)?loadCSVURI(t,e):new Promise(((r,n)=>{const i=[],o=Object.assign({checkType:!0},e);csvtojson(o).fromFile(t).on("json",(t=>{i.push(t)})).on("error",(t=>n(t))).on("done",(t=>t?n(t):r(i)))}))}async function loadTSV(t,e){return loadCSV(t,Object.assign({checkType:!0},e,{delimiter:"\t"}))}var csvUtils=Object.freeze({loadCSVURI:loadCSVURI,loadCSV:loadCSV,loadTSV:loadTSV});Symbol.species||(Symbol.species=Symbol.for("@@species"));class LuDecomposition$$1{constructor(t){var e,r,n,i,o,s,a,u,h,c=(t=WrapperMatrix2D.checkMatrix(t)).clone(),l=c.rows,f=c.columns,m=new Array(l),p=1;for(e=0;e<l;e++)m[e]=e;for(u=new Array(l),r=0;r<f;r++){for(e=0;e<l;e++)u[e]=c.get(e,r);for(e=0;e<l;e++){for(h=Math.min(e,r),o=0,n=0;n<h;n++)o+=c.get(e,n)*u[n];u[e]-=o,c.set(e,r,u[e])}for(i=r,e=r+1;e<l;e++)Math.abs(u[e])>Math.abs(u[i])&&(i=e);if(i!==r){for(n=0;n<f;n++)s=c.get(i,n),c.set(i,n,c.get(r,n)),c.set(r,n,s);a=m[i],m[i]=m[r],m[r]=a,p=-p}if(r<l&&0!==c.get(r,r))for(e=r+1;e<l;e++)c.set(e,r,c.get(e,r)/c.get(r,r))}this.LU=c,this.pivotVector=m,this.pivotSign=p}isSingular(){for(var t=this.LU,e=t.columns,r=0;r<e;r++)if(0===t[r][r])return!0;return!1}solve(t){t=Matrix.checkMatrix(t);var e=this.LU;if(e.rows!==t.rows)throw new Error("Invalid matrix dimensions");if(this.isSingular())throw new Error("LU matrix is singular");var r,n,i,o=t.columns,s=t.subMatrixRow(this.pivotVector,0,o-1),a=e.columns;for(i=0;i<a;i++)for(r=i+1;r<a;r++)for(n=0;n<o;n++)s[r][n]-=s[i][n]*e[r][i];for(i=a-1;i>=0;i--){for(n=0;n<o;n++)s[i][n]/=e[i][i];for(r=0;r<i;r++)for(n=0;n<o;n++)s[r][n]-=s[i][n]*e[r][i]}return s}get determinant(){var t=this.LU;if(!t.isSquare())throw new Error("Matrix must be square");for(var e=this.pivotSign,r=t.columns,n=0;n<r;n++)e*=t[n][n];return e}get lowerTriangularMatrix(){for(var t=this.LU,e=t.rows,r=t.columns,n=new Matrix(e,r),i=0;i<e;i++)for(var o=0;o<r;o++)n[i][o]=i>o?t[i][o]:i===o?1:0;return n}get upperTriangularMatrix(){for(var t=this.LU,e=t.rows,r=t.columns,n=new Matrix(e,r),i=0;i<e;i++)for(var o=0;o<r;o++)n[i][o]=i<=o?t[i][o]:0;return n}get pivotPermutationVector(){return this.pivotVector.slice()}}function hypotenuse(t,e){var r=0;return Math.abs(t)>Math.abs(e)?(r=e/t,Math.abs(t)*Math.sqrt(1+r*r)):0!==e?(r=t/e,Math.abs(e)*Math.sqrt(1+r*r)):0}function getFilled2DArray(t,e,r){for(var n=new Array(t),i=0;i<t;i++){n[i]=new Array(e);for(var o=0;o<e;o++)n[i][o]=r}return n}class SingularValueDecomposition$$1{constructor(t,e={}){var r=(t=WrapperMatrix2D.checkMatrix(t)).rows,n=t.columns,i=Math.min(r,n);const{computeLeftSingularVectors:o=!0,computeRightSingularVectors:s=!0,autoTranspose:a=!1}=e;var u,h=Boolean(o),c=Boolean(s),l=!1;if(r<n)if(a){r=(u=t.transpose()).rows,n=u.columns,l=!0;var f=h;h=c,c=f}else u=t.clone(),console.warn("Computing SVD on a matrix with more columns than rows. Consider enabling autoTranspose");else u=t.clone();var m,p,d,g,v,w,y,b,x,M,_,$,S,R,E,C,k,A,T,O,I,D=new Array(Math.min(r+1,n)),P=getFilled2DArray(r,i,0),V=getFilled2DArray(n,n,0),j=new Array(n),L=new Array(r),N=Math.min(r-1,n),B=Math.max(0,Math.min(n-2,r));for(d=0,M=Math.max(N,B);d<M;d++){if(d<N){for(D[d]=0,m=d;m<r;m++)D[d]=hypotenuse(D[d],u[m][d]);if(0!==D[d]){for(u[d][d]<0&&(D[d]=-D[d]),m=d;m<r;m++)u[m][d]/=D[d];u[d][d]+=1}D[d]=-D[d]}for(p=d+1;p<n;p++){if(d<N&&0!==D[d]){for(v=0,m=d;m<r;m++)v+=u[m][d]*u[m][p];for(v=-v/u[d][d],m=d;m<r;m++)u[m][p]+=v*u[m][d]}j[p]=u[d][p]}if(h&&d<N)for(m=d;m<r;m++)P[m][d]=u[m][d];if(d<B){for(j[d]=0,m=d+1;m<n;m++)j[d]=hypotenuse(j[d],j[m]);if(0!==j[d]){for(j[d+1]<0&&(j[d]=0-j[d]),m=d+1;m<n;m++)j[m]/=j[d];j[d+1]+=1}if(j[d]=-j[d],d+1<r&&0!==j[d]){for(m=d+1;m<r;m++)L[m]=0;for(p=d+1;p<n;p++)for(m=d+1;m<r;m++)L[m]+=j[p]*u[m][p];for(p=d+1;p<n;p++)for(v=-j[p]/j[d+1],m=d+1;m<r;m++)u[m][p]+=v*L[m]}if(c)for(m=d+1;m<n;m++)V[m][d]=j[m]}}if(g=Math.min(n,r+1),N<n&&(D[N]=u[N][N]),r<g&&(D[g-1]=0),B+1<g&&(j[B]=u[B][g-1]),j[g-1]=0,h){for(p=N;p<i;p++){for(m=0;m<r;m++)P[m][p]=0;P[p][p]=1}for(d=N-1;d>=0;d--)if(0!==D[d]){for(p=d+1;p<i;p++){for(v=0,m=d;m<r;m++)v+=P[m][d]*P[m][p];for(v=-v/P[d][d],m=d;m<r;m++)P[m][p]+=v*P[m][d]}for(m=d;m<r;m++)P[m][d]=-P[m][d];for(P[d][d]=1+P[d][d],m=0;m<d-1;m++)P[m][d]=0}else{for(m=0;m<r;m++)P[m][d]=0;P[d][d]=1}}if(c)for(d=n-1;d>=0;d--){if(d<B&&0!==j[d])for(p=d+1;p<n;p++){for(v=0,m=d+1;m<n;m++)v+=V[m][d]*V[m][p];for(v=-v/V[d+1][d],m=d+1;m<n;m++)V[m][p]+=v*V[m][d]}for(m=0;m<n;m++)V[m][d]=0;V[d][d]=1}for(var F=g-1,z=Number.EPSILON;g>0;){for(d=g-2;d>=-1&&-1!==d;d--)if(Math.abs(j[d])<=z*(Math.abs(D[d])+Math.abs(D[d+1]))){j[d]=0;break}if(d===g-2)_=4;else{for(w=g-1;w>=d&&w!==d;w--)if(v=(w!==g?Math.abs(j[w]):0)+(w!==d+1?Math.abs(j[w-1]):0),Math.abs(D[w])<=z*v){D[w]=0;break}w===d?_=3:w===g-1?_=1:(_=2,d=w)}switch(d++,_){case 1:for(y=j[g-2],j[g-2]=0,p=g-2;p>=d;p--)if(v=hypotenuse(D[p],y),b=D[p]/v,x=y/v,D[p]=v,p!==d&&(y=-x*j[p-1],j[p-1]=b*j[p-1]),c)for(m=0;m<n;m++)v=b*V[m][p]+x*V[m][g-1],V[m][g-1]=-x*V[m][p]+b*V[m][g-1],V[m][p]=v;break;case 2:for(y=j[d-1],j[d-1]=0,p=d;p<g;p++)if(v=hypotenuse(D[p],y),b=D[p]/v,x=y/v,D[p]=v,y=-x*j[p],j[p]=b*j[p],h)for(m=0;m<r;m++)v=b*P[m][p]+x*P[m][d-1],P[m][d-1]=-x*P[m][p]+b*P[m][d-1],P[m][p]=v;break;case 3:for($=Math.max(Math.abs(D[g-1]),Math.abs(D[g-2]),Math.abs(j[g-2]),Math.abs(D[d]),Math.abs(j[d])),S=D[g-1]/$,R=D[g-2]/$,E=j[g-2]/$,C=D[d]/$,k=j[d]/$,T=S*E*(S*E),O=0,0===(A=((R+S)*(R-S)+E*E)/2)&&0===T||(O=Math.sqrt(A*A+T),A<0&&(O=-O),O=T/(A+O)),y=(C+S)*(C-S)+O,I=C*k,p=d;p<g-1;p++){if(b=y/(v=hypotenuse(y,I)),x=I/v,p!==d&&(j[p-1]=v),y=b*D[p]+x*j[p],j[p]=b*j[p]-x*D[p],I=x*D[p+1],D[p+1]=b*D[p+1],c)for(m=0;m<n;m++)v=b*V[m][p]+x*V[m][p+1],V[m][p+1]=-x*V[m][p]+b*V[m][p+1],V[m][p]=v;if(b=y/(v=hypotenuse(y,I)),x=I/v,D[p]=v,y=b*j[p]+x*D[p+1],D[p+1]=-x*j[p]+b*D[p+1],I=x*j[p+1],j[p+1]=b*j[p+1],h&&p<r-1)for(m=0;m<r;m++)v=b*P[m][p]+x*P[m][p+1],P[m][p+1]=-x*P[m][p]+b*P[m][p+1],P[m][p]=v}j[g-2]=y;break;case 4:if(D[d]<=0&&(D[d]=D[d]<0?-D[d]:0,c))for(m=0;m<=F;m++)V[m][d]=-V[m][d];for(;d<F&&!(D[d]>=D[d+1]);){if(v=D[d],D[d]=D[d+1],D[d+1]=v,c&&d<n-1)for(m=0;m<n;m++)v=V[m][d+1],V[m][d+1]=V[m][d],V[m][d]=v;if(h&&d<r-1)for(m=0;m<r;m++)v=P[m][d+1],P[m][d+1]=P[m][d],P[m][d]=v;d++}g--}}if(l){var q=V;V=P,P=q}this.m=r,this.n=n,this.s=D,this.U=P,this.V=V}solve(t){var e,r=t,n=this.threshold,i=this.s.length,o=Matrix.zeros(i,i);for(e=0;e<i;e++)Math.abs(this.s[e])<=n?o[e][e]=0:o[e][e]=1/this.s[e];var s,a,u,h=this.U,c=this.rightSingularVectors,l=c.mmul(o),f=c.rows,m=h.length,p=Matrix.zeros(f,m);for(e=0;e<f;e++)for(s=0;s<m;s++){for(u=0,a=0;a<i;a++)u+=l[e][a]*h[s][a];p[e][s]=u}return p.mmul(r)}solveForDiagonal(t){return this.solve(Matrix.diag(t))}inverse(){var t,e,r=this.V,n=this.threshold,i=r.length,o=r[0].length,s=new Matrix(i,this.s.length);for(t=0;t<i;t++)for(e=0;e<o;e++)Math.abs(this.s[e])>n?s[t][e]=r[t][e]/this.s[e]:s[t][e]=0;var a,u,h=this.U,c=h.length,l=h[0].length,f=new Matrix(i,c);for(t=0;t<i;t++)for(e=0;e<c;e++){for(u=0,a=0;a<l;a++)u+=s[t][a]*h[e][a];f[t][e]=u}return f}get condition(){return this.s[0]/this.s[Math.min(this.m,this.n)-1]}get norm2(){return this.s[0]}get rank(){for(var t=Math.max(this.m,this.n)*this.s[0]*Number.EPSILON,e=0,r=this.s,n=0,i=r.length;n<i;n++)r[n]>t&&e++;return e}get diagonal(){return this.s}get threshold(){return Number.EPSILON/2*Math.max(this.m,this.n)*this.s[0]}get leftSingularVectors(){return Matrix.isMatrix(this.U)||(this.U=new Matrix(this.U)),this.U}get rightSingularVectors(){return Matrix.isMatrix(this.V)||(this.V=new Matrix(this.V)),this.V}get diagonalMatrix(){return Matrix.diag(this.s)}}function max(t){if(!Array.isArray(t))throw new Error("input must be an array");if(0===t.length)throw new Error("input must not be empty");for(var e=t[0],r=1;r<t.length;r++)t[r]>e&&(e=t[r]);return e}function min(t){if(!Array.isArray(t))throw new Error("input must be an array");if(0===t.length)throw new Error("input must not be empty");for(var e=t[0],r=1;r<t.length;r++)t[r]<e&&(e=t[r]);return e}function rescale(t,e={}){if(!Array.isArray(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");let r;if(void 0!==e.output){if(!Array.isArray(e.output))throw new TypeError("output option must be an array if specified");r=e.output}else r=new Array(t.length);const n=min(t),i=max(t);if(n===i)throw new RangeError("minimum and maximum input values are equal. Cannot rescale a constant array");const{min:o=(e.autoMinMax?n:0),max:s=(e.autoMinMax?i:1)}=e;if(o>=s)throw new RangeError("min option must be smaller than max option");const a=(s-o)/(i-n);for(var u=0;u<t.length;u++)r[u]=(t[u]-n)*a+o;return r}function checkRowIndex(t,e,r){var n=r?t.rows:t.rows-1;if(e<0||e>n)throw new RangeError("Row index out of range")}function checkColumnIndex(t,e,r){var n=r?t.columns:t.columns-1;if(e<0||e>n)throw new RangeError("Column index out of range")}function checkRowVector(t,e){if(e.to1DArray&&(e=e.to1DArray()),e.length!==t.columns)throw new RangeError("vector size must be the same as the number of columns");return e}function checkColumnVector(t,e){if(e.to1DArray&&(e=e.to1DArray()),e.length!==t.rows)throw new RangeError("vector size must be the same as the number of rows");return e}function checkIndices(t,e,r){return{row:checkRowIndices(t,e),column:checkColumnIndices(t,r)}}function checkRowIndices(t,e){if("object"!=typeof e)throw new TypeError("unexpected type for row indices");if(e.some((e=>e<0||e>=t.rows)))throw new RangeError("row indices are out of range");return Array.isArray(e)||(e=Array.from(e)),e}function checkColumnIndices(t,e){if("object"!=typeof e)throw new TypeError("unexpected type for column indices");var r=e.some((e=>e<0||e>=t.columns));if(r)throw new RangeError("column indices are out of range");return Array.isArray(e)||(e=Array.from(e)),e}function checkRange(t,e,r,n,i){if(5!==arguments.length)throw new TypeError("Invalid argument type");if(Array.from(arguments).slice(1).some((function(t){return"number"!=typeof t})))throw new TypeError("Invalid argument type");if(e>r||n>i||e<0||e>=t.rows||r<0||r>=t.rows||n<0||n>=t.columns||i<0||i>=t.columns)throw new RangeError("Submatrix indices are out of range")}function sumByRow(t){for(var e=Matrix.zeros(t.rows,1),r=0;r<t.rows;++r)for(var n=0;n<t.columns;++n)e.set(r,0,e.get(r,0)+t.get(r,n));return e}function sumByColumn(t){for(var e=Matrix.zeros(1,t.columns),r=0;r<t.rows;++r)for(var n=0;n<t.columns;++n)e.set(0,n,e.get(0,n)+t.get(r,n));return e}function sumAll(t){for(var e=0,r=0;r<t.rows;r++)for(var n=0;n<t.columns;n++)e+=t.get(r,n);return e}class BaseView extends(AbstractMatrix()){constructor(t,e,r){super(),this.matrix=t,this.rows=e,this.columns=r}static get[Symbol.species](){return Matrix}}class MatrixTransposeView extends BaseView{constructor(t){super(t,t.columns,t.rows)}set(t,e,r){return this.matrix.set(e,t,r),this}get(t,e){return this.matrix.get(e,t)}}class MatrixRowView extends BaseView{constructor(t,e){super(t,1,t.columns),this.row=e}set(t,e,r){return this.matrix.set(this.row,e,r),this}get(t,e){return this.matrix.get(this.row,e)}}class MatrixSubView extends BaseView{constructor(t,e,r,n,i){checkRange(t,e,r,n,i),super(t,r-e+1,i-n+1),this.startRow=e,this.startColumn=n}set(t,e,r){return this.matrix.set(this.startRow+t,this.startColumn+e,r),this}get(t,e){return this.matrix.get(this.startRow+t,this.startColumn+e)}}class MatrixSelectionView extends BaseView{constructor(t,e,r){var n=checkIndices(t,e,r);super(t,n.row.length,n.column.length),this.rowIndices=n.row,this.columnIndices=n.column}set(t,e,r){return this.matrix.set(this.rowIndices[t],this.columnIndices[e],r),this}get(t,e){return this.matrix.get(this.rowIndices[t],this.columnIndices[e])}}class MatrixRowSelectionView extends BaseView{constructor(t,e){super(t,(e=checkRowIndices(t,e)).length,t.columns),this.rowIndices=e}set(t,e,r){return this.matrix.set(this.rowIndices[t],e,r),this}get(t,e){return this.matrix.get(this.rowIndices[t],e)}}class MatrixColumnSelectionView extends BaseView{constructor(t,e){e=checkColumnIndices(t,e),super(t,t.rows,e.length),this.columnIndices=e}set(t,e,r){return this.matrix.set(t,this.columnIndices[e],r),this}get(t,e){return this.matrix.get(t,this.columnIndices[e])}}class MatrixColumnView extends BaseView{constructor(t,e){super(t,t.rows,1),this.column=e}set(t,e,r){return this.matrix.set(t,this.column,r),this}get(t){return this.matrix.get(t,this.column)}}class MatrixFlipRowView extends BaseView{constructor(t){super(t,t.rows,t.columns)}set(t,e,r){return this.matrix.set(this.rows-t-1,e,r),this}get(t,e){return this.matrix.get(this.rows-t-1,e)}}class MatrixFlipColumnView extends BaseView{constructor(t){super(t,t.rows,t.columns)}set(t,e,r){return this.matrix.set(t,this.columns-e-1,r),this}get(t,e){return this.matrix.get(t,this.columns-e-1)}}function AbstractMatrix(t){void 0===t&&(t=Object);class e extends t{static get[Symbol.species](){return this}static from1DArray(t,e,r){if(t*e!==r.length)throw new RangeError("Data length does not match given dimensions");for(var n=new this(t,e),i=0;i<t;i++)for(var o=0;o<e;o++)n.set(i,o,r[i*e+o]);return n}static rowVector(t){for(var e=new this(1,t.length),r=0;r<t.length;r++)e.set(0,r,t[r]);return e}static columnVector(t){for(var e=new this(t.length,1),r=0;r<t.length;r++)e.set(r,0,t[r]);return e}static empty(t,e){return new this(t,e)}static zeros(t,e){return this.empty(t,e).fill(0)}static ones(t,e){return this.empty(t,e).fill(1)}static rand(t,e,r){void 0===r&&(r=Math.random);for(var n=this.empty(t,e),i=0;i<t;i++)for(var o=0;o<e;o++)n.set(i,o,r());return n}static randInt(t,e,r,n){void 0===r&&(r=1e3),void 0===n&&(n=Math.random);for(var i=this.empty(t,e),o=0;o<t;o++)for(var s=0;s<e;s++){var a=Math.floor(n()*r);i.set(o,s,a)}return i}static eye(t,e,r){void 0===e&&(e=t),void 0===r&&(r=1);for(var n=Math.min(t,e),i=this.zeros(t,e),o=0;o<n;o++)i.set(o,o,r);return i}static diag(t,e,r){var n=t.length;void 0===e&&(e=n),void 0===r&&(r=e);for(var i=Math.min(n,e,r),o=this.zeros(e,r),s=0;s<i;s++)o.set(s,s,t[s]);return o}static min(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);for(var r=t.rows,n=t.columns,i=new this(r,n),o=0;o<r;o++)for(var s=0;s<n;s++)i.set(o,s,Math.min(t.get(o,s),e.get(o,s)));return i}static max(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);for(var r=t.rows,n=t.columns,i=new this(r,n),o=0;o<r;o++)for(var s=0;s<n;s++)i.set(o,s,Math.max(t.get(o,s),e.get(o,s)));return i}static checkMatrix(t){return e.isMatrix(t)?t:new this(t)}static isMatrix(t){return null!=t&&"Matrix"===t.klass}get size(){return this.rows*this.columns}apply(t){if("function"!=typeof t)throw new TypeError("callback must be a function");for(var e=this.rows,r=this.columns,n=0;n<e;n++)for(var i=0;i<r;i++)t.call(this,n,i);return this}to1DArray(){for(var t=new Array(this.size),e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)t[e*this.columns+r]=this.get(e,r);return t}to2DArray(){for(var t=new Array(this.rows),e=0;e<this.rows;e++){t[e]=new Array(this.columns);for(var r=0;r<this.columns;r++)t[e][r]=this.get(e,r)}return t}isRowVector(){return 1===this.rows}isColumnVector(){return 1===this.columns}isVector(){return 1===this.rows||1===this.columns}isSquare(){return this.rows===this.columns}isSymmetric(){if(this.isSquare()){for(var t=0;t<this.rows;t++)for(var e=0;e<=t;e++)if(this.get(t,e)!==this.get(e,t))return!1;return!0}return!1}set(t,e,r){throw new Error("set method is unimplemented")}get(t,e){throw new Error("get method is unimplemented")}repeat(t,e){t=t||1,e=e||1;for(var r=new this.constructor[Symbol.species](this.rows*t,this.columns*e),n=0;n<t;n++)for(var i=0;i<e;i++)r.setSubMatrix(this,this.rows*n,this.columns*i);return r}fill(t){for(var e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)this.set(e,r,t);return this}neg(){return this.mulS(-1)}getRow(t){checkRowIndex(this,t);for(var e=new Array(this.columns),r=0;r<this.columns;r++)e[r]=this.get(t,r);return e}getRowVector(t){return this.constructor.rowVector(this.getRow(t))}setRow(t,e){checkRowIndex(this,t),e=checkRowVector(this,e);for(var r=0;r<this.columns;r++)this.set(t,r,e[r]);return this}swapRows(t,e){checkRowIndex(this,t),checkRowIndex(this,e);for(var r=0;r<this.columns;r++){var n=this.get(t,r);this.set(t,r,this.get(e,r)),this.set(e,r,n)}return this}getColumn(t){checkColumnIndex(this,t);for(var e=new Array(this.rows),r=0;r<this.rows;r++)e[r]=this.get(r,t);return e}getColumnVector(t){return this.constructor.columnVector(this.getColumn(t))}setColumn(t,e){checkColumnIndex(this,t),e=checkColumnVector(this,e);for(var r=0;r<this.rows;r++)this.set(r,t,e[r]);return this}swapColumns(t,e){checkColumnIndex(this,t),checkColumnIndex(this,e);for(var r=0;r<this.rows;r++){var n=this.get(r,t);this.set(r,t,this.get(r,e)),this.set(r,e,n)}return this}addRowVector(t){t=checkRowVector(this,t);for(var e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t[r]);return this}subRowVector(t){t=checkRowVector(this,t);for(var e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t[r]);return this}mulRowVector(t){t=checkRowVector(this,t);for(var e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t[r]);return this}divRowVector(t){t=checkRowVector(this,t);for(var e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t[r]);return this}addColumnVector(t){t=checkColumnVector(this,t);for(var e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t[e]);return this}subColumnVector(t){t=checkColumnVector(this,t);for(var e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t[e]);return this}mulColumnVector(t){t=checkColumnVector(this,t);for(var e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t[e]);return this}divColumnVector(t){t=checkColumnVector(this,t);for(var e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t[e]);return this}mulRow(t,e){checkRowIndex(this,t);for(var r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)*e);return this}mulColumn(t,e){checkColumnIndex(this,t);for(var r=0;r<this.rows;r++)this.set(r,t,this.get(r,t)*e);return this}max(){for(var t=this.get(0,0),e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)this.get(e,r)>t&&(t=this.get(e,r));return t}maxIndex(){for(var t=this.get(0,0),e=[0,0],r=0;r<this.rows;r++)for(var n=0;n<this.columns;n++)this.get(r,n)>t&&(t=this.get(r,n),e[0]=r,e[1]=n);return e}min(){for(var t=this.get(0,0),e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)this.get(e,r)<t&&(t=this.get(e,r));return t}minIndex(){for(var t=this.get(0,0),e=[0,0],r=0;r<this.rows;r++)for(var n=0;n<this.columns;n++)this.get(r,n)<t&&(t=this.get(r,n),e[0]=r,e[1]=n);return e}maxRow(t){checkRowIndex(this,t);for(var e=this.get(t,0),r=1;r<this.columns;r++)this.get(t,r)>e&&(e=this.get(t,r));return e}maxRowIndex(t){checkRowIndex(this,t);for(var e=this.get(t,0),r=[t,0],n=1;n<this.columns;n++)this.get(t,n)>e&&(e=this.get(t,n),r[1]=n);return r}minRow(t){checkRowIndex(this,t);for(var e=this.get(t,0),r=1;r<this.columns;r++)this.get(t,r)<e&&(e=this.get(t,r));return e}minRowIndex(t){checkRowIndex(this,t);for(var e=this.get(t,0),r=[t,0],n=1;n<this.columns;n++)this.get(t,n)<e&&(e=this.get(t,n),r[1]=n);return r}maxColumn(t){checkColumnIndex(this,t);for(var e=this.get(0,t),r=1;r<this.rows;r++)this.get(r,t)>e&&(e=this.get(r,t));return e}maxColumnIndex(t){checkColumnIndex(this,t);for(var e=this.get(0,t),r=[0,t],n=1;n<this.rows;n++)this.get(n,t)>e&&(e=this.get(n,t),r[0]=n);return r}minColumn(t){checkColumnIndex(this,t);for(var e=this.get(0,t),r=1;r<this.rows;r++)this.get(r,t)<e&&(e=this.get(r,t));return e}minColumnIndex(t){checkColumnIndex(this,t);for(var e=this.get(0,t),r=[0,t],n=1;n<this.rows;n++)this.get(n,t)<e&&(e=this.get(n,t),r[0]=n);return r}diag(){for(var t=Math.min(this.rows,this.columns),e=new Array(t),r=0;r<t;r++)e[r]=this.get(r,r);return e}sum(t){switch(t){case"row":return sumByRow(this);case"column":return sumByColumn(this);default:return sumAll(this)}}mean(){return this.sum()/this.size}prod(){for(var t=1,e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)t*=this.get(e,r);return t}norm(t="frobenius"){var e=0;if("max"===t)return this.max();if("frobenius"===t){for(var r=0;r<this.rows;r++)for(var n=0;n<this.columns;n++)e+=this.get(r,n)*this.get(r,n);return Math.sqrt(e)}throw new RangeError(`unknown norm type: ${t}`)}cumulativeSum(){for(var t=0,e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)t+=this.get(e,r),this.set(e,r,t);return this}dot(t){e.isMatrix(t)&&(t=t.to1DArray());var r=this.to1DArray();if(r.length!==t.length)throw new RangeError("vectors do not have the same size");for(var n=0,i=0;i<r.length;i++)n+=r[i]*t[i];return n}mmul(t){t=this.constructor.checkMatrix(t),this.columns!==t.rows&&console.warn("Number of columns of left matrix are not equal to number of rows of right matrix.");for(var e=this.rows,r=this.columns,n=t.columns,i=new this.constructor[Symbol.species](e,n),o=new Array(r),s=0;s<n;s++){for(var a=0;a<r;a++)o[a]=t.get(a,s);for(var u=0;u<e;u++){var h=0;for(a=0;a<r;a++)h+=this.get(u,a)*o[a];i.set(u,s,h)}}return i}strassen2x2(t){var e=new this.constructor[Symbol.species](2,2);const r=this.get(0,0),n=t.get(0,0),i=this.get(0,1),o=t.get(0,1),s=this.get(1,0),a=t.get(1,0),u=this.get(1,1),h=t.get(1,1),c=(r+u)*(n+h),l=(s+u)*n,f=r*(o-h),m=u*(a-n),p=(r+i)*h,d=c+m-p+(i-u)*(a+h),g=f+p,v=l+m,w=c-l+f+(s-r)*(n+o);return e.set(0,0,d),e.set(0,1,g),e.set(1,0,v),e.set(1,1,w),e}strassen3x3(t){var e=new this.constructor[Symbol.species](3,3);const r=this.get(0,0),n=this.get(0,1),i=this.get(0,2),o=this.get(1,0),s=this.get(1,1),a=this.get(1,2),u=this.get(2,0),h=this.get(2,1),c=this.get(2,2),l=t.get(0,0),f=t.get(0,1),m=t.get(0,2),p=t.get(1,0),d=t.get(1,1),g=t.get(1,2),v=t.get(2,0),w=t.get(2,1),y=t.get(2,2),b=(r-o)*(-f+d),x=(-r+o+s)*(l-f+d),M=(o+s)*(-l+f),_=r*l,$=(-r+u+h)*(l-m+g),S=(-r+u)*(m-g),R=(u+h)*(-l+m),E=(-i+h+c)*(d+v-w),C=(i-c)*(d-w),k=i*v,A=(h+c)*(-v+w),T=(-i+s+a)*(g+v-y),O=(i-a)*(g-y),I=(s+a)*(-v+y),D=_+k+n*p,P=(r+n+i-o-s-h-c)*d+x+M+_+E+k+A,V=_+$+R+(r+n+i-s-a-u-h)*g+k+T+I,j=b+s*(-l+f+p-d-g-v+y)+x+_+k+T+O,L=b+x+M+_+a*w,N=k+T+O+I+o*m,B=_+$+S+h*(-l+m+p-d-g-v+w)+E+C+k,F=E+C+k+A+u*f,z=_+$+S+R+c*y;return e.set(0,0,D),e.set(0,1,P),e.set(0,2,V),e.set(1,0,j),e.set(1,1,L),e.set(1,2,N),e.set(2,0,B),e.set(2,1,F),e.set(2,2,z),e}mmulStrassen(t){var r=this.clone(),n=r.rows,i=r.columns,o=t.rows,s=t.columns;function a(t,r,n){var i=t.rows,o=t.columns;if(i===r&&o===n)return t;var s=e.zeros(r,n);return s=s.setSubMatrix(t,0,0)}i!==o&&console.warn(`Multiplying ${n} x ${i} and ${o} x ${s} matrix: dimensions do not match.`);var u=Math.max(n,o),h=Math.max(i,s);return function t(r,n,i,o){if(i<=512||o<=512)return r.mmul(n);i%2==1&&o%2==1?(r=a(r,i+1,o+1),n=a(n,i+1,o+1)):i%2==1?(r=a(r,i+1,o),n=a(n,i+1,o)):o%2==1&&(r=a(r,i,o+1),n=a(n,i,o+1));var s=parseInt(r.rows/2),u=parseInt(r.columns/2),h=r.subMatrix(0,s-1,0,u-1),c=n.subMatrix(0,s-1,0,u-1),l=r.subMatrix(0,s-1,u,r.columns-1),f=n.subMatrix(0,s-1,u,n.columns-1),m=r.subMatrix(s,r.rows-1,0,u-1),p=n.subMatrix(s,n.rows-1,0,u-1),d=r.subMatrix(s,r.rows-1,u,r.columns-1),g=n.subMatrix(s,n.rows-1,u,n.columns-1),v=t(e.add(h,d),e.add(c,g),s,u),w=t(e.add(m,d),c,s,u),y=t(h,e.sub(f,g),s,u),b=t(d,e.sub(p,c),s,u),x=t(e.add(h,l),g,s,u),M=t(e.sub(m,h),e.add(c,f),s,u),_=t(e.sub(l,d),e.add(p,g),s,u),$=e.add(v,b);$.sub(x),$.add(_);var S=e.add(y,x),R=e.add(w,b),E=e.sub(v,w);E.add(y),E.add(M);var C=e.zeros(2*$.rows,2*$.columns);return(C=(C=(C=(C=C.setSubMatrix($,0,0)).setSubMatrix(S,$.rows,0)).setSubMatrix(R,0,$.columns)).setSubMatrix(E,$.rows,$.columns)).subMatrix(0,i-1,0,o-1)}(r=a(r,u,h),t=a(t,u,h),u,h)}scaleRows(t,e){if((t=void 0===t?0:t)>=(e=void 0===e?1:e))throw new RangeError("min should be strictly smaller than max");for(var r=this.constructor.empty(this.rows,this.columns),n=0;n<this.rows;n++){var i=rescale(this.getRow(n),{min:t,max:e});r.setRow(n,i)}return r}scaleColumns(t,e){if((t=void 0===t?0:t)>=(e=void 0===e?1:e))throw new RangeError("min should be strictly smaller than max");for(var r=this.constructor.empty(this.rows,this.columns),n=0;n<this.columns;n++){var i=rescale(this.getColumn(n),{min:t,max:e});r.setColumn(n,i)}return r}kroneckerProduct(t){t=this.constructor.checkMatrix(t);for(var e=this.rows,r=this.columns,n=t.rows,i=t.columns,o=new this.constructor[Symbol.species](e*n,r*i),s=0;s<e;s++)for(var a=0;a<r;a++)for(var u=0;u<n;u++)for(var h=0;h<i;h++)o[n*s+u][i*a+h]=this.get(s,a)*t.get(u,h);return o}transpose(){for(var t=new this.constructor[Symbol.species](this.columns,this.rows),e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)t.set(r,e,this.get(e,r));return t}sortRows(t){void 0===t&&(t=r);for(var e=0;e<this.rows;e++)this.setRow(e,this.getRow(e).sort(t));return this}sortColumns(t){void 0===t&&(t=r);for(var e=0;e<this.columns;e++)this.setColumn(e,this.getColumn(e).sort(t));return this}subMatrix(t,e,r,n){checkRange(this,t,e,r,n);for(var i=new this.constructor[Symbol.species](e-t+1,n-r+1),o=t;o<=e;o++)for(var s=r;s<=n;s++)i[o-t][s-r]=this.get(o,s);return i}subMatrixRow(t,e,r){if(void 0===e&&(e=0),void 0===r&&(r=this.columns-1),e>r||e<0||e>=this.columns||r<0||r>=this.columns)throw new RangeError("Argument out of range");for(var n=new this.constructor[Symbol.species](t.length,r-e+1),i=0;i<t.length;i++)for(var o=e;o<=r;o++){if(t[i]<0||t[i]>=this.rows)throw new RangeError("Row index out of range: "+t[i]);n.set(i,o-e,this.get(t[i],o))}return n}subMatrixColumn(t,e,r){if(void 0===e&&(e=0),void 0===r&&(r=this.rows-1),e>r||e<0||e>=this.rows||r<0||r>=this.rows)throw new RangeError("Argument out of range");for(var n=new this.constructor[Symbol.species](r-e+1,t.length),i=0;i<t.length;i++)for(var o=e;o<=r;o++){if(t[i]<0||t[i]>=this.columns)throw new RangeError("Column index out of range: "+t[i]);n.set(o-e,i,this.get(o,t[i]))}return n}setSubMatrix(t,e,r){checkRange(this,e,e+(t=this.constructor.checkMatrix(t)).rows-1,r,r+t.columns-1);for(var n=0;n<t.rows;n++)for(var i=0;i<t.columns;i++)this[e+n][r+i]=t.get(n,i);return this}selection(t,e){for(var r=checkIndices(this,t,e),n=new this.constructor[Symbol.species](t.length,e.length),i=0;i<r.row.length;i++)for(var o=r.row[i],s=0;s<r.column.length;s++){var a=r.column[s];n[i][s]=this.get(o,a)}return n}trace(){for(var t=Math.min(this.rows,this.columns),e=0,r=0;r<t;r++)e+=this.get(r,r);return e}transposeView(){return new MatrixTransposeView(this)}rowView(t){return checkRowIndex(this,t),new MatrixRowView(this,t)}columnView(t){return checkColumnIndex(this,t),new MatrixColumnView(this,t)}flipRowView(){return new MatrixFlipRowView(this)}flipColumnView(){return new MatrixFlipColumnView(this)}subMatrixView(t,e,r,n){return new MatrixSubView(this,t,e,r,n)}selectionView(t,e){return new MatrixSelectionView(this,t,e)}rowSelectionView(t){return new MatrixRowSelectionView(this,t)}columnSelectionView(t){return new MatrixColumnSelectionView(this,t)}det(){var t,e,r,n,i,o;if(this.isSquare())return 2===this.columns?(t=this.get(0,0),e=this.get(0,1),r=this.get(1,0),t*this.get(1,1)-e*r):3===this.columns?(n=this.selectionView([1,2],[1,2]),i=this.selectionView([1,2],[0,2]),o=this.selectionView([1,2],[0,1]),t=this.get(0,0),e=this.get(0,1),r=this.get(0,2),t*n.det()-e*i.det()+r*o.det()):new LuDecomposition$$1(this).determinant;throw Error("Determinant can only be calculated for a square matrix.")}pseudoInverse(t){void 0===t&&(t=Number.EPSILON);for(var e=new SingularValueDecomposition$$1(this,{autoTranspose:!0}),r=e.leftSingularVectors,n=e.rightSingularVectors,i=e.diagonal,o=0;o<i.length;o++)Math.abs(i[o])>t?i[o]=1/i[o]:i[o]=0;return i=this.constructor[Symbol.species].diag(i),n.mmul(i.mmul(r.transposeView()))}clone(){for(var t=new this.constructor[Symbol.species](this.rows,this.columns),e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)t.set(e,r,this.get(e,r));return t}}function r(t,e){return t-e}e.prototype.klass="Matrix",e.random=e.rand,e.diagonal=e.diag,e.prototype.diagonal=e.prototype.diag,e.identity=e.eye,e.prototype.negate=e.prototype.neg,e.prototype.tensorProduct=e.prototype.kroneckerProduct,e.prototype.determinant=e.prototype.det;var n,i="\n(function %name%(matrix, %args%) {\n    var newMatrix = new this[Symbol.species](matrix);\n    return newMatrix.%name%(%args%);\n})\n",o=i,s=eval;for(var a of[["+","add"],["-","sub","subtract"],["*","mul","multiply"],["/","div","divide"],["%","mod","modulus"],["&","and"],["|","or"],["^","xor"],["<<","leftShift"],[">>","signPropagatingRightShift"],[">>>","rightShift","zeroFillRightShift"]]){var u=s(S("\n(function %name%(value) {\n    if (typeof value === 'number') return this.%name%S(value);\n    return this.%name%M(value);\n})\n",{name:a[1],op:a[0]})),h=s(S("\n(function %name%S(value) {\n    for (var i = 0; i < this.rows; i++) {\n        for (var j = 0; j < this.columns; j++) {\n            this.set(i, j, this.get(i, j) %op% value);\n        }\n    }\n    return this;\n})\n",{name:a[1]+"S",op:a[0]})),c=s(S("\n(function %name%M(matrix) {\n    matrix = this.constructor.checkMatrix(matrix);\n    if (this.rows !== matrix.rows ||\n        this.columns !== matrix.columns) {\n        throw new RangeError('Matrices dimensions must be equal');\n    }\n    for (var i = 0; i < this.rows; i++) {\n        for (var j = 0; j < this.columns; j++) {\n            this.set(i, j, this.get(i, j) %op% matrix.get(i, j));\n        }\n    }\n    return this;\n})\n",{name:a[1]+"M",op:a[0]})),l=s(S("\n(function %name%(matrix, value) {\n    var newMatrix = new this[Symbol.species](matrix);\n    return newMatrix.%name%(value);\n})\n",{name:a[1]}));for(n=1;n<a.length;n++)e.prototype[a[n]]=u,e.prototype[a[n]+"S"]=h,e.prototype[a[n]+"M"]=c,e[a[n]]=l}var f=[["~","not"]];for(var m of(["abs","acos","acosh","asin","asinh","atan","atanh","cbrt","ceil","clz32","cos","cosh","exp","expm1","floor","fround","log","log1p","log10","log2","round","sign","sin","sinh","sqrt","tan","tanh","trunc"].forEach((function(t){f.push(["Math."+t,t])})),f)){var p=s(S("\n(function %name%() {\n    for (var i = 0; i < this.rows; i++) {\n        for (var j = 0; j < this.columns; j++) {\n            this.set(i, j, %method%(this.get(i, j)));\n        }\n    }\n    return this;\n})\n",{name:m[1],method:m[0]})),d=s(S("\n(function %name%(matrix) {\n    var newMatrix = new this[Symbol.species](matrix);\n    return newMatrix.%name%();\n})\n",{name:m[1]}));for(n=1;n<m.length;n++)e.prototype[m[n]]=p,e[m[n]]=d}for(var g of[["Math.pow",1,"pow"]]){var v="arg0";for(n=1;n<g[1];n++)v+=`, arg${n}`;if(1!==g[1]){var w=s(S("\n(function %name%(%args%) {\n    for (var i = 0; i < this.rows; i++) {\n        for (var j = 0; j < this.columns; j++) {\n            this.set(i, j, %method%(this.get(i, j), %args%));\n        }\n    }\n    return this;\n})\n",{name:g[2],method:g[0],args:v})),y=s(S(i,{name:g[2],args:v}));for(n=2;n<g.length;n++)e.prototype[g[n]]=w,e[g[n]]=y}else{var b={name:g[2],args:v,method:g[0]},x=s(S("\n(function %name%(value) {\n    if (typeof value === 'number') return this.%name%S(value);\n    return this.%name%M(value);\n})\n",b)),M=s(S("\n(function %name%S(value) {\n    for (var i = 0; i < this.rows; i++) {\n        for (var j = 0; j < this.columns; j++) {\n            this.set(i, j, %method%(this.get(i, j), value));\n        }\n    }\n    return this;\n})\n",b)),_=s(S("\n(function %name%M(matrix) {\n    matrix = this.constructor.checkMatrix(matrix);\n    if (this.rows !== matrix.rows ||\n        this.columns !== matrix.columns) {\n        throw new RangeError('Matrices dimensions must be equal');\n    }\n    for (var i = 0; i < this.rows; i++) {\n        for (var j = 0; j < this.columns; j++) {\n            this.set(i, j, %method%(this.get(i, j), matrix.get(i, j)));\n        }\n    }\n    return this;\n})\n",b)),$=s(S(o,b));for(n=2;n<g.length;n++)e.prototype[g[n]]=x,e.prototype[g[n]+"M"]=_,e.prototype[g[n]+"S"]=M,e[g[n]]=$}}function S(t,e){for(var r in e)t=t.replace(new RegExp("%"+r+"%","g"),e[r]);return t}return e}class Matrix extends(AbstractMatrix(Array)){constructor(t,e){var r;if(1===arguments.length&&"number"==typeof t)return new Array(t);if(Matrix.isMatrix(t))return t.clone();if(Number.isInteger(t)&&t>0){if(super(t),!(Number.isInteger(e)&&e>0))throw new TypeError("nColumns must be a positive integer");for(r=0;r<t;r++)this[r]=new Array(e)}else{if(!Array.isArray(t))throw new TypeError("First argument must be a positive number or an array");{const n=t;if(t=n.length,"number"!=typeof(e=n[0].length)||0===e)throw new TypeError("Data must be a 2D array with at least one element");for(super(t),r=0;r<t;r++){if(n[r].length!==e)throw new RangeError("Inconsistent array dimensions");this[r]=[].concat(n[r])}}}return this.rows=t,this.columns=e,this}set(t,e,r){return this[t][e]=r,this}get(t,e){return this[t][e]}removeRow(t){if(checkRowIndex(this,t),1===this.rows)throw new RangeError("A matrix cannot have less than one row");return this.splice(t,1),this.rows-=1,this}addRow(t,e){return void 0===e&&(e=t,t=this.rows),checkRowIndex(this,t,!0),e=checkRowVector(this,e,!0),this.splice(t,0,e),this.rows+=1,this}removeColumn(t){if(checkColumnIndex(this,t),1===this.columns)throw new RangeError("A matrix cannot have less than one column");for(var e=0;e<this.rows;e++)this[e].splice(t,1);return this.columns-=1,this}addColumn(t,e){void 0===e&&(e=t,t=this.columns),checkColumnIndex(this,t,!0),e=checkColumnVector(this,e);for(var r=0;r<this.rows;r++)this[r].splice(t,0,e[r]);return this.columns+=1,this}}class WrapperMatrix1D extends(AbstractMatrix()){constructor(t,e={}){const{rows:r=1}=e;if(t.length%r!=0)throw new Error("the data length is not divisible by the number of rows");super(),this.rows=r,this.columns=t.length/r,this.data=t}set(t,e,r){var n=this._calculateIndex(t,e);return this.data[n]=r,this}get(t,e){var r=this._calculateIndex(t,e);return this.data[r]}_calculateIndex(t,e){return t*this.columns+e}static get[Symbol.species](){return Matrix}}class WrapperMatrix2D extends(AbstractMatrix()){constructor(t){super(),this.data=t,this.rows=t.length,this.columns=t[0].length}set(t,e,r){return this.data[t][e]=r,this}get(t,e){return this.data[t][e]}static get[Symbol.species](){return Matrix}}function mean(t){if(!Array.isArray(t))throw new Error("input must be an array");if(0===t.length)throw new Error("input must not be empty");for(var e=0,r=0;r<t.length;r++)e+=t[r];return e/t.length}function toDiscreteDistribution(t,e){for(var r=new Array(e).fill(0),n=0;n<t.length;++n)r[t[n]]+=1/t.length;return Matrix.rowVector(r)}function giniImpurity(t){if(0===t.length)return 0;for(var e=toDiscreteDistribution(t,getNumberOfClasses(t))[0],r=0,n=0;n<e.length;++n)r+=e[n]*e[n];return 1-r}function getNumberOfClasses(t){return t.filter((function(t,e,r){return r.indexOf(t)===e})).length}function giniGain(t,e){for(var r=0,n=["greater","lesser"],i=0;i<n.length;++i){var o=e[n[i]];r+=giniImpurity(o)*o.length/t.length}return giniImpurity(t)-r}function squaredError(t){for(var e=t.length,r=mean(t),n=0,i=0;i<e;++i){var o=t[i];n+=(o-r)*(o-r)}return n}function regressionError(t,e){for(var r=0,n=["greater","lesser"],i=0;i<n.length;++i){r+=squaredError(e[n[i]])}return r}function matrixSplitter(t,e,r,n){for(var i=[],o=[],s=[],a=[],u=0;u<t.rows;++u)t[u][r]<n?(i.push(t[u]),s.push(e[u])):(o.push(t[u]),a.push(e[u]));return{greaterX:o,greaterY:a,lesserX:i,lesserY:s}}function mean$1(t,e){return(t+e)/2}function zip(t,e){if(t.length!==e.length)throw new TypeError("Error on zip: the size of a: "+t.length+" is different from b: "+e.length);for(var r=new Array(t.length),n=0;n<t.length;++n)r[n]=[t[n],e[n]];return r}const gainFunctions={gini:giniGain,regression:regressionError},splitFunctions={mean:mean$1};class TreeNode{constructor(t){this.kind=t.kind,this.gainFunction=t.gainFunction,this.splitFunction=t.splitFunction,this.minNumSamples=t.minNumSamples,this.maxDepth=t.maxDepth}bestSplit(t,e){for(var r,n,i="classifier"===this.kind?-1/0:1/0,o="classifier"===this.kind?(t,e)=>t>e:(t,e)=>t<e,s=0;s<t.rows;++s)for(var a=t[s],u=this.featureSplit(a,e),h=0;h<u.length;++h){var c=u[h],l=this.split(a,e,c),f=gainFunctions[this.gainFunction](e,l);o(f,i)&&(r=s,n=c,i=f)}return{maxGain:i,maxColumn:r,maxValue:n}}split(t,e,r){for(var n=[],i=[],o=0;o<t.length;++o)t[o]<r?n.push(e[o]):i.push(e[o]);return{greater:i,lesser:n}}featureSplit(t,e){var r=[],n=zip(t,e);n.sort((function(t,e){return t[0]-e[0]}));for(var i=1;i<n.length;++i)n[i-1][1]!==n[i][1]&&r.push(splitFunctions[this.splitFunction](n[i-1][0],n[i][0]));return r}calculatePrediction(t){if("classifier"===this.kind){if(this.distribution=toDiscreteDistribution(t,getNumberOfClasses(t)),0===this.distribution.columns)throw new TypeError("Error on calculate the prediction")}else this.distribution=mean(t)}train(t,e,r,n){if(t.rows<=this.minNumSamples)this.calculatePrediction(e);else{void 0===n&&(n=0);var i=t.transpose(),o=this.bestSplit(i,e);this.splitValue=o.maxValue,this.splitColumn=o.maxColumn,this.gain=o.maxGain;var s=matrixSplitter(t,e,this.splitColumn,this.splitValue);if(r<this.maxDepth&&this.gain>.01&&this.gain!==n&&s.lesserX.length>0&&s.greaterX.length>0){this.left=new TreeNode(this),this.right=new TreeNode(this);var a=new Matrix(s.lesserX),u=new Matrix(s.greaterX);this.left.train(a,s.lesserY,r+1,this.gain),this.right.train(u,s.greaterY,r+1,this.gain)}else this.calculatePrediction(e)}}classify(t){return this.right&&this.left?t[this.splitColumn]<this.splitValue?this.left.classify(t):this.right.classify(t):this.distribution}setNodeParameters(t){void 0!==t.distribution?this.distribution=t.distribution.constructor===Array?new Matrix(t.distribution):t.distribution:(this.distribution=void 0,this.splitValue=t.splitValue,this.splitColumn=t.splitColumn,this.gain=t.gain,this.left=new TreeNode(this),this.right=new TreeNode(this),t.left!=={}&&this.left.setNodeParameters(t.left),t.right!=={}&&this.right.setNodeParameters(t.right))}}const defaultOptions={gainFunction:"gini",splitFunction:"mean",minNumSamples:3,maxDepth:1/0};class DecisionTreeClassifier{constructor(t,e){!0===t?(this.options=e.options,this.root=new TreeNode(e.options),this.root.setNodeParameters(e.root)):(this.options=Object.assign({},defaultOptions,t),this.options.kind="classifier")}train(t,e){this.root=new TreeNode(this.options),t=Matrix.checkMatrix(t),this.root.train(t,e,0,null)}predict(t){t=Matrix.checkMatrix(t);for(var e=new Array(t.rows),r=0;r<t.rows;++r)e[r]=this.root.classify(t.getRow(r)).maxRowIndex(0)[1];return e}toJSON(){return{options:this.options,root:this.root,name:"DTClassifier"}}static load(t){if("DTClassifier"!==t.name)throw new RangeError("Invalid model: "+t.name);return new DecisionTreeClassifier(!0,t)}}const defaultOptions$1={gainFunction:"regression",splitFunction:"mean",minNumSamples:3,maxDepth:1/0};class DecisionTreeRegression{constructor(t,e){!0===t?(this.options=e.options,this.root=new TreeNode(e.options),this.root.setNodeParameters(e.root)):(this.options=Object.assign({},defaultOptions$1,t),this.options.kind="regression")}train(t,e){this.root=new TreeNode(this.options),void 0===t[0].length&&(t=Matrix.columnVector(t)),t=Matrix.checkMatrix(t),this.root.train(t,e,0)}predict(t){void 0!==t[0]&&void 0===t[0].length&&(t=Matrix.columnVector(t)),t=Matrix.checkMatrix(t);for(var e=new Array(t.rows),r=0;r<t.rows;++r)e[r]=this.root.classify(t.getRow(r));return e}toJSON(){return{options:this.options,root:this.root,name:"DTRegression"}}static load(t){if("DTRegression"!==t.name)throw new RangeError("Invalid model:"+t.name);return new DecisionTreeRegression(!0,t)}}var src=Object.freeze({DecisionTreeClassifier:DecisionTreeClassifier,DecisionTreeRegression:DecisionTreeRegression});class LuDecomposition$$1{constructor(t){var e,r,n,i,o,s,a,u,h,c=(t=WrapperMatrix2D$1.checkMatrix(t)).clone(),l=c.rows,f=c.columns,m=new Array(l),p=1;for(e=0;e<l;e++)m[e]=e;for(u=new Array(l),r=0;r<f;r++){for(e=0;e<l;e++)u[e]=c.get(e,r);for(e=0;e<l;e++){for(h=Math.min(e,r),o=0,n=0;n<h;n++)o+=c.get(e,n)*u[n];u[e]-=o,c.set(e,r,u[e])}for(i=r,e=r+1;e<l;e++)Math.abs(u[e])>Math.abs(u[i])&&(i=e);if(i!==r){for(n=0;n<f;n++)s=c.get(i,n),c.set(i,n,c.get(r,n)),c.set(r,n,s);a=m[i],m[i]=m[r],m[r]=a,p=-p}if(r<l&&0!==c.get(r,r))for(e=r+1;e<l;e++)c.set(e,r,c.get(e,r)/c.get(r,r))}this.LU=c,this.pivotVector=m,this.pivotSign=p}isSingular(){for(var t=this.LU,e=t.columns,r=0;r<e;r++)if(0===t[r][r])return!0;return!1}solve(t){t=Matrix$1.checkMatrix(t);var e=this.LU;if(e.rows!==t.rows)throw new Error("Invalid matrix dimensions");if(this.isSingular())throw new Error("LU matrix is singular");var r,n,i,o=t.columns,s=t.subMatrixRow(this.pivotVector,0,o-1),a=e.columns;for(i=0;i<a;i++)for(r=i+1;r<a;r++)for(n=0;n<o;n++)s[r][n]-=s[i][n]*e[r][i];for(i=a-1;i>=0;i--){for(n=0;n<o;n++)s[i][n]/=e[i][i];for(r=0;r<i;r++)for(n=0;n<o;n++)s[r][n]-=s[i][n]*e[r][i]}return s}get determinant(){var t=this.LU;if(!t.isSquare())throw new Error("Matrix must be square");for(var e=this.pivotSign,r=t.columns,n=0;n<r;n++)e*=t[n][n];return e}get lowerTriangularMatrix(){for(var t=this.LU,e=t.rows,r=t.columns,n=new Matrix$1(e,r),i=0;i<e;i++)for(var o=0;o<r;o++)n[i][o]=i>o?t[i][o]:i===o?1:0;return n}get upperTriangularMatrix(){for(var t=this.LU,e=t.rows,r=t.columns,n=new Matrix$1(e,r),i=0;i<e;i++)for(var o=0;o<r;o++)n[i][o]=i<=o?t[i][o]:0;return n}get pivotPermutationVector(){return this.pivotVector.slice()}}function hypotenuse$1(t,e){var r=0;return Math.abs(t)>Math.abs(e)?(r=e/t,Math.abs(t)*Math.sqrt(1+r*r)):0!==e?(r=t/e,Math.abs(e)*Math.sqrt(1+r*r)):0}function getFilled2DArray$1(t,e,r){for(var n=new Array(t),i=0;i<t;i++){n[i]=new Array(e);for(var o=0;o<e;o++)n[i][o]=r}return n}class SingularValueDecomposition$$1{constructor(t,e={}){var r=(t=WrapperMatrix2D$1.checkMatrix(t)).rows,n=t.columns;const{computeLeftSingularVectors:i=!0,computeRightSingularVectors:o=!0,autoTranspose:s=!1}=e;var a,u=Boolean(i),h=Boolean(o),c=!1;if(r<n)if(s){r=(a=t.transpose()).rows,n=a.columns,c=!0;var l=u;u=h,h=l}else a=t.clone(),console.warn("Computing SVD on a matrix with more columns than rows. Consider enabling autoTranspose");else a=t.clone();var f=Math.min(r,n),m=Math.min(r+1,n),p=new Array(m),d=getFilled2DArray$1(r,f,0),g=getFilled2DArray$1(n,n,0),v=new Array(n),w=new Array(r),y=new Array(m);for(let t=0;t<m;t++)y[t]=t;var b=Math.min(r-1,n),x=Math.max(0,Math.min(n-2,r)),M=Math.max(b,x);for(let t=0;t<M;t++){if(t<b){p[t]=0;for(let e=t;e<r;e++)p[t]=hypotenuse$1(p[t],a[e][t]);if(0!==p[t]){a[t][t]<0&&(p[t]=-p[t]);for(let e=t;e<r;e++)a[e][t]/=p[t];a[t][t]+=1}p[t]=-p[t]}for(let e=t+1;e<n;e++){if(t<b&&0!==p[t]){let n=0;for(let i=t;i<r;i++)n+=a[i][t]*a[i][e];n=-n/a[t][t];for(let i=t;i<r;i++)a[i][e]+=n*a[i][t]}v[e]=a[t][e]}if(u&&t<b)for(let e=t;e<r;e++)d[e][t]=a[e][t];if(t<x){v[t]=0;for(let e=t+1;e<n;e++)v[t]=hypotenuse$1(v[t],v[e]);if(0!==v[t]){v[t+1]<0&&(v[t]=0-v[t]);for(let e=t+1;e<n;e++)v[e]/=v[t];v[t+1]+=1}if(v[t]=-v[t],t+1<r&&0!==v[t]){for(let e=t+1;e<r;e++)w[e]=0;for(let e=t+1;e<r;e++)for(let r=t+1;r<n;r++)w[e]+=v[r]*a[e][r];for(let e=t+1;e<n;e++){let n=-v[e]/v[t+1];for(let i=t+1;i<r;i++)a[i][e]+=n*w[i]}}if(h)for(let e=t+1;e<n;e++)g[e][t]=v[e]}}let _=Math.min(n,r+1);if(b<n&&(p[b]=a[b][b]),r<_&&(p[_-1]=0),x+1<_&&(v[x]=a[x][_-1]),v[_-1]=0,u){for(let t=b;t<f;t++){for(let e=0;e<r;e++)d[e][t]=0;d[t][t]=1}for(let t=b-1;t>=0;t--)if(0!==p[t]){for(let e=t+1;e<f;e++){let n=0;for(let i=t;i<r;i++)n+=d[i][t]*d[i][e];n=-n/d[t][t];for(let i=t;i<r;i++)d[i][e]+=n*d[i][t]}for(let e=t;e<r;e++)d[e][t]=-d[e][t];d[t][t]=1+d[t][t];for(let e=0;e<t-1;e++)d[e][t]=0}else{for(let e=0;e<r;e++)d[e][t]=0;d[t][t]=1}}if(h)for(let t=n-1;t>=0;t--){if(t<x&&0!==v[t])for(let e=t+1;e<n;e++){let r=0;for(let i=t+1;i<n;i++)r+=g[i][t]*g[i][e];r=-r/g[t+1][t];for(let i=t+1;i<n;i++)g[i][e]+=r*g[i][t]}for(let e=0;e<n;e++)g[e][t]=0;g[t][t]=1}for(var $=_-1,S=Number.EPSILON;_>0;){let t,e;for(t=_-2;t>=-1&&-1!==t;t--){const e=Number.MIN_VALUE+S*Math.abs(p[t]+Math.abs(p[t+1]));if(Math.abs(v[t])<=e||Number.isNaN(v[t])){v[t]=0;break}}if(t===_-2)e=4;else{let r;for(r=_-1;r>=t&&r!==t;r--){let e=(r!==_?Math.abs(v[r]):0)+(r!==t+1?Math.abs(v[r-1]):0);if(Math.abs(p[r])<=S*e){p[r]=0;break}}r===t?e=3:r===_-1?e=1:(e=2,t=r)}switch(t++,e){case 1:{let e=v[_-2];v[_-2]=0;for(let r=_-2;r>=t;r--){let i=hypotenuse$1(p[r],e),o=p[r]/i,s=e/i;if(p[r]=i,r!==t&&(e=-s*v[r-1],v[r-1]=o*v[r-1]),h)for(let t=0;t<n;t++)i=o*g[t][r]+s*g[t][_-1],g[t][_-1]=-s*g[t][r]+o*g[t][_-1],g[t][r]=i}break}case 2:{let e=v[t-1];v[t-1]=0;for(let n=t;n<_;n++){let i=hypotenuse$1(p[n],e),o=p[n]/i,s=e/i;if(p[n]=i,e=-s*v[n],v[n]=o*v[n],u)for(let e=0;e<r;e++)i=o*d[e][n]+s*d[e][t-1],d[e][t-1]=-s*d[e][n]+o*d[e][t-1],d[e][n]=i}break}case 3:{const e=Math.max(Math.abs(p[_-1]),Math.abs(p[_-2]),Math.abs(v[_-2]),Math.abs(p[t]),Math.abs(v[t])),i=p[_-1]/e,o=p[_-2]/e,s=v[_-2]/e,a=p[t]/e,c=v[t]/e,l=((o+i)*(o-i)+s*s)/2,f=i*s*(i*s);let m=0;0===l&&0===f||(m=l<0?0-Math.sqrt(l*l+f):Math.sqrt(l*l+f),m=f/(l+m));let w=(a+i)*(a-i)+m,y=a*c;for(let e=t;e<_-1;e++){let i=hypotenuse$1(w,y);0===i&&(i=Number.MIN_VALUE);let o=w/i,s=y/i;if(e!==t&&(v[e-1]=i),w=o*p[e]+s*v[e],v[e]=o*v[e]-s*p[e],y=s*p[e+1],p[e+1]=o*p[e+1],h)for(let t=0;t<n;t++)i=o*g[t][e]+s*g[t][e+1],g[t][e+1]=-s*g[t][e]+o*g[t][e+1],g[t][e]=i;if(i=hypotenuse$1(w,y),0===i&&(i=Number.MIN_VALUE),o=w/i,s=y/i,p[e]=i,w=o*v[e]+s*p[e+1],p[e+1]=-s*v[e]+o*p[e+1],y=s*v[e+1],v[e+1]=o*v[e+1],u&&e<r-1)for(let t=0;t<r;t++)i=o*d[t][e]+s*d[t][e+1],d[t][e+1]=-s*d[t][e]+o*d[t][e+1],d[t][e]=i}v[_-2]=w;break}case 4:if(p[t]<=0&&(p[t]=p[t]<0?-p[t]:0,h))for(let e=0;e<=$;e++)g[e][t]=-g[e][t];for(;t<$&&!(p[t]>=p[t+1]);){let e=p[t];if(p[t]=p[t+1],p[t+1]=e,h&&t<n-1)for(let r=0;r<n;r++)e=g[r][t+1],g[r][t+1]=g[r][t],g[r][t]=e;if(u&&t<r-1)for(let n=0;n<r;n++)e=d[n][t+1],d[n][t+1]=d[n][t],d[n][t]=e;t++}_--}}if(c){var R=g;g=d,d=R}this.m=r,this.n=n,this.s=p,this.U=d,this.V=g}solve(t){var e=t,r=this.threshold,n=this.s.length,i=Matrix$1.zeros(n,n);for(let t=0;t<n;t++)Math.abs(this.s[t])<=r?i[t][t]=0:i[t][t]=1/this.s[t];var o=this.U,s=this.rightSingularVectors,a=s.mmul(i),u=s.rows,h=o.length,c=Matrix$1.zeros(u,h);for(let t=0;t<u;t++)for(let e=0;e<h;e++){let r=0;for(let i=0;i<n;i++)r+=a[t][i]*o[e][i];c[t][e]=r}return c.mmul(e)}solveForDiagonal(t){return this.solve(Matrix$1.diag(t))}inverse(){var t=this.V,e=this.threshold,r=t.length,n=t[0].length,i=new Matrix$1(r,this.s.length);for(let o=0;o<r;o++)for(let r=0;r<n;r++)Math.abs(this.s[r])>e?i[o][r]=t[o][r]/this.s[r]:i[o][r]=0;var o=this.U,s=o.length,a=o[0].length,u=new Matrix$1(r,s);for(let t=0;t<r;t++)for(let e=0;e<s;e++){let r=0;for(let n=0;n<a;n++)r+=i[t][n]*o[e][n];u[t][e]=r}return u}get condition(){return this.s[0]/this.s[Math.min(this.m,this.n)-1]}get norm2(){return this.s[0]}get rank(){for(var t=Math.max(this.m,this.n)*this.s[0]*Number.EPSILON,e=0,r=this.s,n=0,i=r.length;n<i;n++)r[n]>t&&e++;return e}get diagonal(){return this.s}get threshold(){return Number.EPSILON/2*Math.max(this.m,this.n)*this.s[0]}get leftSingularVectors(){return Matrix$1.isMatrix(this.U)||(this.U=new Matrix$1(this.U)),this.U}get rightSingularVectors(){return Matrix$1.isMatrix(this.V)||(this.V=new Matrix$1(this.V)),this.V}get diagonalMatrix(){return Matrix$1.diag(this.s)}}function checkRowIndex$1(t,e,r){var n=r?t.rows:t.rows-1;if(e<0||e>n)throw new RangeError("Row index out of range")}function checkColumnIndex$1(t,e,r){var n=r?t.columns:t.columns-1;if(e<0||e>n)throw new RangeError("Column index out of range")}function checkRowVector$1(t,e){if(e.to1DArray&&(e=e.to1DArray()),e.length!==t.columns)throw new RangeError("vector size must be the same as the number of columns");return e}function checkColumnVector$1(t,e){if(e.to1DArray&&(e=e.to1DArray()),e.length!==t.rows)throw new RangeError("vector size must be the same as the number of rows");return e}function checkIndices$1(t,e,r){return{row:checkRowIndices$1(t,e),column:checkColumnIndices$1(t,r)}}function checkRowIndices$1(t,e){if("object"!=typeof e)throw new TypeError("unexpected type for row indices");if(e.some((e=>e<0||e>=t.rows)))throw new RangeError("row indices are out of range");return Array.isArray(e)||(e=Array.from(e)),e}function checkColumnIndices$1(t,e){if("object"!=typeof e)throw new TypeError("unexpected type for column indices");var r=e.some((e=>e<0||e>=t.columns));if(r)throw new RangeError("column indices are out of range");return Array.isArray(e)||(e=Array.from(e)),e}function checkRange$1(t,e,r,n,i){if(5!==arguments.length)throw new RangeError("expected 4 arguments");if(checkNumber("startRow",e),checkNumber("endRow",r),checkNumber("startColumn",n),checkNumber("endColumn",i),e>r||n>i||e<0||e>=t.rows||r<0||r>=t.rows||n<0||n>=t.columns||i<0||i>=t.columns)throw new RangeError("Submatrix indices are out of range")}function sumByRow$1(t){for(var e=Matrix$1.zeros(t.rows,1),r=0;r<t.rows;++r)for(var n=0;n<t.columns;++n)e.set(r,0,e.get(r,0)+t.get(r,n));return e}function sumByColumn$1(t){for(var e=Matrix$1.zeros(1,t.columns),r=0;r<t.rows;++r)for(var n=0;n<t.columns;++n)e.set(0,n,e.get(0,n)+t.get(r,n));return e}function sumAll$1(t){for(var e=0,r=0;r<t.rows;r++)for(var n=0;n<t.columns;n++)e+=t.get(r,n);return e}function checkNumber(t,e){if("number"!=typeof e)throw new TypeError(`${t} must be a number`)}class BaseView$1 extends(AbstractMatrix$1()){constructor(t,e,r){super(),this.matrix=t,this.rows=e,this.columns=r}static get[Symbol.species](){return Matrix$1}}class MatrixTransposeView$1 extends BaseView$1{constructor(t){super(t,t.columns,t.rows)}set(t,e,r){return this.matrix.set(e,t,r),this}get(t,e){return this.matrix.get(e,t)}}class MatrixRowView$1 extends BaseView$1{constructor(t,e){super(t,1,t.columns),this.row=e}set(t,e,r){return this.matrix.set(this.row,e,r),this}get(t,e){return this.matrix.get(this.row,e)}}class MatrixSubView$1 extends BaseView$1{constructor(t,e,r,n,i){checkRange$1(t,e,r,n,i),super(t,r-e+1,i-n+1),this.startRow=e,this.startColumn=n}set(t,e,r){return this.matrix.set(this.startRow+t,this.startColumn+e,r),this}get(t,e){return this.matrix.get(this.startRow+t,this.startColumn+e)}}class MatrixSelectionView$1 extends BaseView$1{constructor(t,e,r){var n=checkIndices$1(t,e,r);super(t,n.row.length,n.column.length),this.rowIndices=n.row,this.columnIndices=n.column}set(t,e,r){return this.matrix.set(this.rowIndices[t],this.columnIndices[e],r),this}get(t,e){return this.matrix.get(this.rowIndices[t],this.columnIndices[e])}}class MatrixRowSelectionView$1 extends BaseView$1{constructor(t,e){super(t,(e=checkRowIndices$1(t,e)).length,t.columns),this.rowIndices=e}set(t,e,r){return this.matrix.set(this.rowIndices[t],e,r),this}get(t,e){return this.matrix.get(this.rowIndices[t],e)}}class MatrixColumnSelectionView$1 extends BaseView$1{constructor(t,e){e=checkColumnIndices$1(t,e),super(t,t.rows,e.length),this.columnIndices=e}set(t,e,r){return this.matrix.set(t,this.columnIndices[e],r),this}get(t,e){return this.matrix.get(t,this.columnIndices[e])}}class MatrixColumnView$1 extends BaseView$1{constructor(t,e){super(t,t.rows,1),this.column=e}set(t,e,r){return this.matrix.set(t,this.column,r),this}get(t){return this.matrix.get(t,this.column)}}class MatrixFlipRowView$1 extends BaseView$1{constructor(t){super(t,t.rows,t.columns)}set(t,e,r){return this.matrix.set(this.rows-t-1,e,r),this}get(t,e){return this.matrix.get(this.rows-t-1,e)}}class MatrixFlipColumnView$1 extends BaseView$1{constructor(t){super(t,t.rows,t.columns)}set(t,e,r){return this.matrix.set(t,this.columns-e-1,r),this}get(t,e){return this.matrix.get(t,this.columns-e-1)}}function AbstractMatrix$1(t){void 0===t&&(t=Object);class e extends t{static get[Symbol.species](){return this}static from1DArray(t,e,r){if(t*e!==r.length)throw new RangeError("Data length does not match given dimensions");for(var n=new this(t,e),i=0;i<t;i++)for(var o=0;o<e;o++)n.set(i,o,r[i*e+o]);return n}static rowVector(t){for(var e=new this(1,t.length),r=0;r<t.length;r++)e.set(0,r,t[r]);return e}static columnVector(t){for(var e=new this(t.length,1),r=0;r<t.length;r++)e.set(r,0,t[r]);return e}static empty(t,e){return new this(t,e)}static zeros(t,e){return this.empty(t,e).fill(0)}static ones(t,e){return this.empty(t,e).fill(1)}static rand(t,e,r){void 0===r&&(r=Math.random);for(var n=this.empty(t,e),i=0;i<t;i++)for(var o=0;o<e;o++)n.set(i,o,r());return n}static randInt(t,e,r,n){void 0===r&&(r=1e3),void 0===n&&(n=Math.random);for(var i=this.empty(t,e),o=0;o<t;o++)for(var s=0;s<e;s++){var a=Math.floor(n()*r);i.set(o,s,a)}return i}static eye(t,e,r){void 0===e&&(e=t),void 0===r&&(r=1);for(var n=Math.min(t,e),i=this.zeros(t,e),o=0;o<n;o++)i.set(o,o,r);return i}static diag(t,e,r){var n=t.length;void 0===e&&(e=n),void 0===r&&(r=e);for(var i=Math.min(n,e,r),o=this.zeros(e,r),s=0;s<i;s++)o.set(s,s,t[s]);return o}static min(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);for(var r=t.rows,n=t.columns,i=new this(r,n),o=0;o<r;o++)for(var s=0;s<n;s++)i.set(o,s,Math.min(t.get(o,s),e.get(o,s)));return i}static max(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);for(var r=t.rows,n=t.columns,i=new this(r,n),o=0;o<r;o++)for(var s=0;s<n;s++)i.set(o,s,Math.max(t.get(o,s),e.get(o,s)));return i}static checkMatrix(t){return e.isMatrix(t)?t:new this(t)}static isMatrix(t){return null!=t&&"Matrix"===t.klass}get size(){return this.rows*this.columns}apply(t){if("function"!=typeof t)throw new TypeError("callback must be a function");for(var e=this.rows,r=this.columns,n=0;n<e;n++)for(var i=0;i<r;i++)t.call(this,n,i);return this}to1DArray(){for(var t=new Array(this.size),e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)t[e*this.columns+r]=this.get(e,r);return t}to2DArray(){for(var t=new Array(this.rows),e=0;e<this.rows;e++){t[e]=new Array(this.columns);for(var r=0;r<this.columns;r++)t[e][r]=this.get(e,r)}return t}isRowVector(){return 1===this.rows}isColumnVector(){return 1===this.columns}isVector(){return 1===this.rows||1===this.columns}isSquare(){return this.rows===this.columns}isSymmetric(){if(this.isSquare()){for(var t=0;t<this.rows;t++)for(var e=0;e<=t;e++)if(this.get(t,e)!==this.get(e,t))return!1;return!0}return!1}set(t,e,r){throw new Error("set method is unimplemented")}get(t,e){throw new Error("get method is unimplemented")}repeat(t,e){t=t||1,e=e||1;for(var r=new this.constructor[Symbol.species](this.rows*t,this.columns*e),n=0;n<t;n++)for(var i=0;i<e;i++)r.setSubMatrix(this,this.rows*n,this.columns*i);return r}fill(t){for(var e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)this.set(e,r,t);return this}neg(){return this.mulS(-1)}getRow(t){checkRowIndex$1(this,t);for(var e=new Array(this.columns),r=0;r<this.columns;r++)e[r]=this.get(t,r);return e}getRowVector(t){return this.constructor.rowVector(this.getRow(t))}setRow(t,e){checkRowIndex$1(this,t),e=checkRowVector$1(this,e);for(var r=0;r<this.columns;r++)this.set(t,r,e[r]);return this}swapRows(t,e){checkRowIndex$1(this,t),checkRowIndex$1(this,e);for(var r=0;r<this.columns;r++){var n=this.get(t,r);this.set(t,r,this.get(e,r)),this.set(e,r,n)}return this}getColumn(t){checkColumnIndex$1(this,t);for(var e=new Array(this.rows),r=0;r<this.rows;r++)e[r]=this.get(r,t);return e}getColumnVector(t){return this.constructor.columnVector(this.getColumn(t))}setColumn(t,e){checkColumnIndex$1(this,t),e=checkColumnVector$1(this,e);for(var r=0;r<this.rows;r++)this.set(r,t,e[r]);return this}swapColumns(t,e){checkColumnIndex$1(this,t),checkColumnIndex$1(this,e);for(var r=0;r<this.rows;r++){var n=this.get(r,t);this.set(r,t,this.get(r,e)),this.set(r,e,n)}return this}addRowVector(t){t=checkRowVector$1(this,t);for(var e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t[r]);return this}subRowVector(t){t=checkRowVector$1(this,t);for(var e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t[r]);return this}mulRowVector(t){t=checkRowVector$1(this,t);for(var e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t[r]);return this}divRowVector(t){t=checkRowVector$1(this,t);for(var e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t[r]);return this}addColumnVector(t){t=checkColumnVector$1(this,t);for(var e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t[e]);return this}subColumnVector(t){t=checkColumnVector$1(this,t);for(var e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t[e]);return this}mulColumnVector(t){t=checkColumnVector$1(this,t);for(var e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t[e]);return this}divColumnVector(t){t=checkColumnVector$1(this,t);for(var e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t[e]);return this}mulRow(t,e){checkRowIndex$1(this,t);for(var r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)*e);return this}mulColumn(t,e){checkColumnIndex$1(this,t);for(var r=0;r<this.rows;r++)this.set(r,t,this.get(r,t)*e);return this}max(){for(var t=this.get(0,0),e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)this.get(e,r)>t&&(t=this.get(e,r));return t}maxIndex(){for(var t=this.get(0,0),e=[0,0],r=0;r<this.rows;r++)for(var n=0;n<this.columns;n++)this.get(r,n)>t&&(t=this.get(r,n),e[0]=r,e[1]=n);return e}min(){for(var t=this.get(0,0),e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)this.get(e,r)<t&&(t=this.get(e,r));return t}minIndex(){for(var t=this.get(0,0),e=[0,0],r=0;r<this.rows;r++)for(var n=0;n<this.columns;n++)this.get(r,n)<t&&(t=this.get(r,n),e[0]=r,e[1]=n);return e}maxRow(t){checkRowIndex$1(this,t);for(var e=this.get(t,0),r=1;r<this.columns;r++)this.get(t,r)>e&&(e=this.get(t,r));return e}maxRowIndex(t){checkRowIndex$1(this,t);for(var e=this.get(t,0),r=[t,0],n=1;n<this.columns;n++)this.get(t,n)>e&&(e=this.get(t,n),r[1]=n);return r}minRow(t){checkRowIndex$1(this,t);for(var e=this.get(t,0),r=1;r<this.columns;r++)this.get(t,r)<e&&(e=this.get(t,r));return e}minRowIndex(t){checkRowIndex$1(this,t);for(var e=this.get(t,0),r=[t,0],n=1;n<this.columns;n++)this.get(t,n)<e&&(e=this.get(t,n),r[1]=n);return r}maxColumn(t){checkColumnIndex$1(this,t);for(var e=this.get(0,t),r=1;r<this.rows;r++)this.get(r,t)>e&&(e=this.get(r,t));return e}maxColumnIndex(t){checkColumnIndex$1(this,t);for(var e=this.get(0,t),r=[0,t],n=1;n<this.rows;n++)this.get(n,t)>e&&(e=this.get(n,t),r[0]=n);return r}minColumn(t){checkColumnIndex$1(this,t);for(var e=this.get(0,t),r=1;r<this.rows;r++)this.get(r,t)<e&&(e=this.get(r,t));return e}minColumnIndex(t){checkColumnIndex$1(this,t);for(var e=this.get(0,t),r=[0,t],n=1;n<this.rows;n++)this.get(n,t)<e&&(e=this.get(n,t),r[0]=n);return r}diag(){for(var t=Math.min(this.rows,this.columns),e=new Array(t),r=0;r<t;r++)e[r]=this.get(r,r);return e}sum(t){switch(t){case"row":return sumByRow$1(this);case"column":return sumByColumn$1(this);default:return sumAll$1(this)}}mean(){return this.sum()/this.size}prod(){for(var t=1,e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)t*=this.get(e,r);return t}norm(t="frobenius"){var e=0;if("max"===t)return this.max();if("frobenius"===t){for(var r=0;r<this.rows;r++)for(var n=0;n<this.columns;n++)e+=this.get(r,n)*this.get(r,n);return Math.sqrt(e)}throw new RangeError(`unknown norm type: ${t}`)}cumulativeSum(){for(var t=0,e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)t+=this.get(e,r),this.set(e,r,t);return this}dot(t){e.isMatrix(t)&&(t=t.to1DArray());var r=this.to1DArray();if(r.length!==t.length)throw new RangeError("vectors do not have the same size");for(var n=0,i=0;i<r.length;i++)n+=r[i]*t[i];return n}mmul(t){t=this.constructor.checkMatrix(t),this.columns!==t.rows&&console.warn("Number of columns of left matrix are not equal to number of rows of right matrix.");for(var e=this.rows,r=this.columns,n=t.columns,i=new this.constructor[Symbol.species](e,n),o=new Array(r),s=0;s<n;s++){for(var a=0;a<r;a++)o[a]=t.get(a,s);for(var u=0;u<e;u++){var h=0;for(a=0;a<r;a++)h+=this.get(u,a)*o[a];i.set(u,s,h)}}return i}strassen2x2(t){var e=new this.constructor[Symbol.species](2,2);const r=this.get(0,0),n=t.get(0,0),i=this.get(0,1),o=t.get(0,1),s=this.get(1,0),a=t.get(1,0),u=this.get(1,1),h=t.get(1,1),c=(r+u)*(n+h),l=(s+u)*n,f=r*(o-h),m=u*(a-n),p=(r+i)*h,d=c+m-p+(i-u)*(a+h),g=f+p,v=l+m,w=c-l+f+(s-r)*(n+o);return e.set(0,0,d),e.set(0,1,g),e.set(1,0,v),e.set(1,1,w),e}strassen3x3(t){var e=new this.constructor[Symbol.species](3,3);const r=this.get(0,0),n=this.get(0,1),i=this.get(0,2),o=this.get(1,0),s=this.get(1,1),a=this.get(1,2),u=this.get(2,0),h=this.get(2,1),c=this.get(2,2),l=t.get(0,0),f=t.get(0,1),m=t.get(0,2),p=t.get(1,0),d=t.get(1,1),g=t.get(1,2),v=t.get(2,0),w=t.get(2,1),y=t.get(2,2),b=(r-o)*(-f+d),x=(-r+o+s)*(l-f+d),M=(o+s)*(-l+f),_=r*l,$=(-r+u+h)*(l-m+g),S=(-r+u)*(m-g),R=(u+h)*(-l+m),E=(-i+h+c)*(d+v-w),C=(i-c)*(d-w),k=i*v,A=(h+c)*(-v+w),T=(-i+s+a)*(g+v-y),O=(i-a)*(g-y),I=(s+a)*(-v+y),D=_+k+n*p,P=(r+n+i-o-s-h-c)*d+x+M+_+E+k+A,V=_+$+R+(r+n+i-s-a-u-h)*g+k+T+I,j=b+s*(-l+f+p-d-g-v+y)+x+_+k+T+O,L=b+x+M+_+a*w,N=k+T+O+I+o*m,B=_+$+S+h*(-l+m+p-d-g-v+w)+E+C+k,F=E+C+k+A+u*f,z=_+$+S+R+c*y;return e.set(0,0,D),e.set(0,1,P),e.set(0,2,V),e.set(1,0,j),e.set(1,1,L),e.set(1,2,N),e.set(2,0,B),e.set(2,1,F),e.set(2,2,z),e}mmulStrassen(t){var r=this.clone(),n=r.rows,i=r.columns,o=t.rows,s=t.columns;function a(t,r,n){var i=t.rows,o=t.columns;if(i===r&&o===n)return t;var s=e.zeros(r,n);return s=s.setSubMatrix(t,0,0)}i!==o&&console.warn(`Multiplying ${n} x ${i} and ${o} x ${s} matrix: dimensions do not match.`);var u=Math.max(n,o),h=Math.max(i,s);return function t(r,n,i,o){if(i<=512||o<=512)return r.mmul(n);i%2==1&&o%2==1?(r=a(r,i+1,o+1),n=a(n,i+1,o+1)):i%2==1?(r=a(r,i+1,o),n=a(n,i+1,o)):o%2==1&&(r=a(r,i,o+1),n=a(n,i,o+1));var s=parseInt(r.rows/2,10),u=parseInt(r.columns/2,10),h=r.subMatrix(0,s-1,0,u-1),c=n.subMatrix(0,s-1,0,u-1),l=r.subMatrix(0,s-1,u,r.columns-1),f=n.subMatrix(0,s-1,u,n.columns-1),m=r.subMatrix(s,r.rows-1,0,u-1),p=n.subMatrix(s,n.rows-1,0,u-1),d=r.subMatrix(s,r.rows-1,u,r.columns-1),g=n.subMatrix(s,n.rows-1,u,n.columns-1),v=t(e.add(h,d),e.add(c,g),s,u),w=t(e.add(m,d),c,s,u),y=t(h,e.sub(f,g),s,u),b=t(d,e.sub(p,c),s,u),x=t(e.add(h,l),g,s,u),M=t(e.sub(m,h),e.add(c,f),s,u),_=t(e.sub(l,d),e.add(p,g),s,u),$=e.add(v,b);$.sub(x),$.add(_);var S=e.add(y,x),R=e.add(w,b),E=e.sub(v,w);E.add(y),E.add(M);var C=e.zeros(2*$.rows,2*$.columns);return(C=(C=(C=(C=C.setSubMatrix($,0,0)).setSubMatrix(S,$.rows,0)).setSubMatrix(R,0,$.columns)).setSubMatrix(E,$.rows,$.columns)).subMatrix(0,i-1,0,o-1)}(r=a(r,u,h),t=a(t,u,h),u,h)}scaleRows(t,e){if((t=void 0===t?0:t)>=(e=void 0===e?1:e))throw new RangeError("min should be strictly smaller than max");for(var r=this.constructor.empty(this.rows,this.columns),n=0;n<this.rows;n++){var i=rescale(this.getRow(n),{min:t,max:e});r.setRow(n,i)}return r}scaleColumns(t,e){if((t=void 0===t?0:t)>=(e=void 0===e?1:e))throw new RangeError("min should be strictly smaller than max");for(var r=this.constructor.empty(this.rows,this.columns),n=0;n<this.columns;n++){var i=rescale(this.getColumn(n),{min:t,max:e});r.setColumn(n,i)}return r}kroneckerProduct(t){t=this.constructor.checkMatrix(t);for(var e=this.rows,r=this.columns,n=t.rows,i=t.columns,o=new this.constructor[Symbol.species](e*n,r*i),s=0;s<e;s++)for(var a=0;a<r;a++)for(var u=0;u<n;u++)for(var h=0;h<i;h++)o[n*s+u][i*a+h]=this.get(s,a)*t.get(u,h);return o}transpose(){for(var t=new this.constructor[Symbol.species](this.columns,this.rows),e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)t.set(r,e,this.get(e,r));return t}sortRows(t){void 0===t&&(t=r);for(var e=0;e<this.rows;e++)this.setRow(e,this.getRow(e).sort(t));return this}sortColumns(t){void 0===t&&(t=r);for(var e=0;e<this.columns;e++)this.setColumn(e,this.getColumn(e).sort(t));return this}subMatrix(t,e,r,n){checkRange$1(this,t,e,r,n);for(var i=new this.constructor[Symbol.species](e-t+1,n-r+1),o=t;o<=e;o++)for(var s=r;s<=n;s++)i[o-t][s-r]=this.get(o,s);return i}subMatrixRow(t,e,r){if(void 0===e&&(e=0),void 0===r&&(r=this.columns-1),e>r||e<0||e>=this.columns||r<0||r>=this.columns)throw new RangeError("Argument out of range");for(var n=new this.constructor[Symbol.species](t.length,r-e+1),i=0;i<t.length;i++)for(var o=e;o<=r;o++){if(t[i]<0||t[i]>=this.rows)throw new RangeError(`Row index out of range: ${t[i]}`);n.set(i,o-e,this.get(t[i],o))}return n}subMatrixColumn(t,e,r){if(void 0===e&&(e=0),void 0===r&&(r=this.rows-1),e>r||e<0||e>=this.rows||r<0||r>=this.rows)throw new RangeError("Argument out of range");for(var n=new this.constructor[Symbol.species](r-e+1,t.length),i=0;i<t.length;i++)for(var o=e;o<=r;o++){if(t[i]<0||t[i]>=this.columns)throw new RangeError(`Column index out of range: ${t[i]}`);n.set(o-e,i,this.get(o,t[i]))}return n}setSubMatrix(t,e,r){checkRange$1(this,e,e+(t=this.constructor.checkMatrix(t)).rows-1,r,r+t.columns-1);for(var n=0;n<t.rows;n++)for(var i=0;i<t.columns;i++)this[e+n][r+i]=t.get(n,i);return this}selection(t,e){for(var r=checkIndices$1(this,t,e),n=new this.constructor[Symbol.species](t.length,e.length),i=0;i<r.row.length;i++)for(var o=r.row[i],s=0;s<r.column.length;s++){var a=r.column[s];n[i][s]=this.get(o,a)}return n}trace(){for(var t=Math.min(this.rows,this.columns),e=0,r=0;r<t;r++)e+=this.get(r,r);return e}transposeView(){return new MatrixTransposeView$1(this)}rowView(t){return checkRowIndex$1(this,t),new MatrixRowView$1(this,t)}columnView(t){return checkColumnIndex$1(this,t),new MatrixColumnView$1(this,t)}flipRowView(){return new MatrixFlipRowView$1(this)}flipColumnView(){return new MatrixFlipColumnView$1(this)}subMatrixView(t,e,r,n){return new MatrixSubView$1(this,t,e,r,n)}selectionView(t,e){return new MatrixSelectionView$1(this,t,e)}rowSelectionView(t){return new MatrixRowSelectionView$1(this,t)}columnSelectionView(t){return new MatrixColumnSelectionView$1(this,t)}det(){var t,e,r,n,i,o;if(this.isSquare())return 2===this.columns?(t=this.get(0,0),e=this.get(0,1),r=this.get(1,0),t*this.get(1,1)-e*r):3===this.columns?(n=this.selectionView([1,2],[1,2]),i=this.selectionView([1,2],[0,2]),o=this.selectionView([1,2],[0,1]),t=this.get(0,0),e=this.get(0,1),r=this.get(0,2),t*n.det()-e*i.det()+r*o.det()):new LuDecomposition$$1(this).determinant;throw Error("Determinant can only be calculated for a square matrix.")}pseudoInverse(t){void 0===t&&(t=Number.EPSILON);for(var e=new SingularValueDecomposition$$1(this,{autoTranspose:!0}),r=e.leftSingularVectors,n=e.rightSingularVectors,i=e.diagonal,o=0;o<i.length;o++)Math.abs(i[o])>t?i[o]=1/i[o]:i[o]=0;return i=this.constructor[Symbol.species].diag(i),n.mmul(i.mmul(r.transposeView()))}clone(){for(var t=new this.constructor[Symbol.species](this.rows,this.columns),e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)t.set(e,r,this.get(e,r));return t}}function r(t,e){return t-e}e.prototype.klass="Matrix",e.random=e.rand,e.diagonal=e.diag,e.prototype.diagonal=e.prototype.diag,e.identity=e.eye,e.prototype.negate=e.prototype.neg,e.prototype.tensorProduct=e.prototype.kroneckerProduct,e.prototype.determinant=e.prototype.det;var n,i="\n(function %name%(matrix, %args%) {\n    var newMatrix = new this[Symbol.species](matrix);\n    return newMatrix.%name%(%args%);\n})\n",o=i,s=eval;for(var a of[["+","add"],["-","sub","subtract"],["*","mul","multiply"],["/","div","divide"],["%","mod","modulus"],["&","and"],["|","or"],["^","xor"],["<<","leftShift"],[">>","signPropagatingRightShift"],[">>>","rightShift","zeroFillRightShift"]]){var u=s(S("\n(function %name%(value) {\n    if (typeof value === 'number') return this.%name%S(value);\n    return this.%name%M(value);\n})\n",{name:a[1],op:a[0]})),h=s(S("\n(function %name%S(value) {\n    for (var i = 0; i < this.rows; i++) {\n        for (var j = 0; j < this.columns; j++) {\n            this.set(i, j, this.get(i, j) %op% value);\n        }\n    }\n    return this;\n})\n",{name:`${a[1]}S`,op:a[0]})),c=s(S("\n(function %name%M(matrix) {\n    matrix = this.constructor.checkMatrix(matrix);\n    if (this.rows !== matrix.rows ||\n        this.columns !== matrix.columns) {\n        throw new RangeError('Matrices dimensions must be equal');\n    }\n    for (var i = 0; i < this.rows; i++) {\n        for (var j = 0; j < this.columns; j++) {\n            this.set(i, j, this.get(i, j) %op% matrix.get(i, j));\n        }\n    }\n    return this;\n})\n",{name:`${a[1]}M`,op:a[0]})),l=s(S("\n(function %name%(matrix, value) {\n    var newMatrix = new this[Symbol.species](matrix);\n    return newMatrix.%name%(value);\n})\n",{name:a[1]}));for(n=1;n<a.length;n++)e.prototype[a[n]]=u,e.prototype[`${a[n]}S`]=h,e.prototype[`${a[n]}M`]=c,e[a[n]]=l}var f=[["~","not"]];for(var m of(["abs","acos","acosh","asin","asinh","atan","atanh","cbrt","ceil","clz32","cos","cosh","exp","expm1","floor","fround","log","log1p","log10","log2","round","sign","sin","sinh","sqrt","tan","tanh","trunc"].forEach((function(t){f.push([`Math.${t}`,t])})),f)){var p=s(S("\n(function %name%() {\n    for (var i = 0; i < this.rows; i++) {\n        for (var j = 0; j < this.columns; j++) {\n            this.set(i, j, %method%(this.get(i, j)));\n        }\n    }\n    return this;\n})\n",{name:m[1],method:m[0]})),d=s(S("\n(function %name%(matrix) {\n    var newMatrix = new this[Symbol.species](matrix);\n    return newMatrix.%name%();\n})\n",{name:m[1]}));for(n=1;n<m.length;n++)e.prototype[m[n]]=p,e[m[n]]=d}for(var g of[["Math.pow",1,"pow"]]){var v="arg0";for(n=1;n<g[1];n++)v+=`, arg${n}`;if(1!==g[1]){var w=s(S("\n(function %name%(%args%) {\n    for (var i = 0; i < this.rows; i++) {\n        for (var j = 0; j < this.columns; j++) {\n            this.set(i, j, %method%(this.get(i, j), %args%));\n        }\n    }\n    return this;\n})\n",{name:g[2],method:g[0],args:v})),y=s(S(i,{name:g[2],args:v}));for(n=2;n<g.length;n++)e.prototype[g[n]]=w,e[g[n]]=y}else{var b={name:g[2],args:v,method:g[0]},x=s(S("\n(function %name%(value) {\n    if (typeof value === 'number') return this.%name%S(value);\n    return this.%name%M(value);\n})\n",b)),M=s(S("\n(function %name%S(value) {\n    for (var i = 0; i < this.rows; i++) {\n        for (var j = 0; j < this.columns; j++) {\n            this.set(i, j, %method%(this.get(i, j), value));\n        }\n    }\n    return this;\n})\n",b)),_=s(S("\n(function %name%M(matrix) {\n    matrix = this.constructor.checkMatrix(matrix);\n    if (this.rows !== matrix.rows ||\n        this.columns !== matrix.columns) {\n        throw new RangeError('Matrices dimensions must be equal');\n    }\n    for (var i = 0; i < this.rows; i++) {\n        for (var j = 0; j < this.columns; j++) {\n            this.set(i, j, %method%(this.get(i, j), matrix.get(i, j)));\n        }\n    }\n    return this;\n})\n",b)),$=s(S(o,b));for(n=2;n<g.length;n++)e.prototype[g[n]]=x,e.prototype[`${g[n]}M`]=_,e.prototype[`${g[n]}S`]=M,e[g[n]]=$}}function S(t,e){for(var r in e)t=t.replace(new RegExp(`%${r}%`,"g"),e[r]);return t}return e}class Matrix$1 extends(AbstractMatrix$1(Array)){constructor(t,e){var r;if(1===arguments.length&&"number"==typeof t)return new Array(t);if(Matrix$1.isMatrix(t))return t.clone();if(Number.isInteger(t)&&t>0){if(super(t),!(Number.isInteger(e)&&e>0))throw new TypeError("nColumns must be a positive integer");for(r=0;r<t;r++)this[r]=new Array(e)}else{if(!Array.isArray(t))throw new TypeError("First argument must be a positive number or an array");{const n=t;if(t=n.length,"number"!=typeof(e=n[0].length)||0===e)throw new TypeError("Data must be a 2D array with at least one element");for(super(t),r=0;r<t;r++){if(n[r].length!==e)throw new RangeError("Inconsistent array dimensions");this[r]=[].concat(n[r])}}}return this.rows=t,this.columns=e,this}set(t,e,r){return this[t][e]=r,this}get(t,e){return this[t][e]}removeRow(t){if(checkRowIndex$1(this,t),1===this.rows)throw new RangeError("A matrix cannot have less than one row");return this.splice(t,1),this.rows-=1,this}addRow(t,e){return void 0===e&&(e=t,t=this.rows),checkRowIndex$1(this,t,!0),e=checkRowVector$1(this,e,!0),this.splice(t,0,e),this.rows+=1,this}removeColumn(t){if(checkColumnIndex$1(this,t),1===this.columns)throw new RangeError("A matrix cannot have less than one column");for(var e=0;e<this.rows;e++)this[e].splice(t,1);return this.columns-=1,this}addColumn(t,e){void 0===e&&(e=t,t=this.columns),checkColumnIndex$1(this,t,!0),e=checkColumnVector$1(this,e);for(var r=0;r<this.rows;r++)this[r].splice(t,0,e[r]);return this.columns+=1,this}}class WrapperMatrix1D$1 extends(AbstractMatrix$1()){constructor(t,e={}){const{rows:r=1}=e;if(t.length%r!=0)throw new Error("the data length is not divisible by the number of rows");super(),this.rows=r,this.columns=t.length/r,this.data=t}set(t,e,r){var n=this._calculateIndex(t,e);return this.data[n]=r,this}get(t,e){var r=this._calculateIndex(t,e);return this.data[r]}_calculateIndex(t,e){return t*this.columns+e}static get[Symbol.species](){return Matrix$1}}class WrapperMatrix2D$1 extends(AbstractMatrix$1()){constructor(t){super(),this.data=t,this.rows=t.length,this.columns=t[0].length}set(t,e,r){return this.data[t][e]=r,this}get(t,e){return this.data[t][e]}static get[Symbol.species](){return Matrix$1}}function wrap$1(t,e){if(Array.isArray(t))return t[0]&&Array.isArray(t[0])?new WrapperMatrix2D$1(t):new WrapperMatrix1D$1(t,e);throw new Error("the argument is not an array")}class QrDecomposition$$1{constructor(t){var e,r,n,i,o=(t=WrapperMatrix2D$1.checkMatrix(t)).clone(),s=t.rows,a=t.columns,u=new Array(a);for(n=0;n<a;n++){var h=0;for(e=n;e<s;e++)h=hypotenuse$1(h,o.get(e,n));if(0!==h){for(o.get(n,n)<0&&(h=-h),e=n;e<s;e++)o.set(e,n,o.get(e,n)/h);for(o.set(n,n,o.get(n,n)+1),r=n+1;r<a;r++){for(i=0,e=n;e<s;e++)i+=o.get(e,n)*o.get(e,r);for(i=-i/o.get(n,n),e=n;e<s;e++)o.set(e,r,o.get(e,r)+i*o.get(e,n))}}u[n]=-h}this.QR=o,this.Rdiag=u}solve(t){t=Matrix$1.checkMatrix(t);var e=this.QR,r=e.rows;if(t.rows!==r)throw new Error("Matrix row dimensions must agree");if(!this.isFullRank())throw new Error("Matrix is rank deficient");var n,i,o,s,a=t.columns,u=t.clone(),h=e.columns;for(o=0;o<h;o++)for(i=0;i<a;i++){for(s=0,n=o;n<r;n++)s+=e[n][o]*u[n][i];for(s=-s/e[o][o],n=o;n<r;n++)u[n][i]+=s*e[n][o]}for(o=h-1;o>=0;o--){for(i=0;i<a;i++)u[o][i]/=this.Rdiag[o];for(n=0;n<o;n++)for(i=0;i<a;i++)u[n][i]-=u[o][i]*e[n][o]}return u.subMatrix(0,h-1,0,a-1)}isFullRank(){for(var t=this.QR.columns,e=0;e<t;e++)if(0===this.Rdiag[e])return!1;return!0}get upperTriangularMatrix(){var t,e,r=this.QR,n=r.columns,i=new Matrix$1(n,n);for(t=0;t<n;t++)for(e=0;e<n;e++)i[t][e]=t<e?r[t][e]:t===e?this.Rdiag[t]:0;return i}get orthogonalMatrix(){var t,e,r,n,i=this.QR,o=i.rows,s=i.columns,a=new Matrix$1(o,s);for(r=s-1;r>=0;r--){for(t=0;t<o;t++)a[t][r]=0;for(a[r][r]=1,e=r;e<s;e++)if(0!==i[r][r]){for(n=0,t=r;t<o;t++)n+=i[t][r]*a[t][e];for(n=-n/i[r][r],t=r;t<o;t++)a[t][e]+=n*i[t][r]}}return a}}function inverse$$1(t,e=!1){return t=WrapperMatrix2D$1.checkMatrix(t),e?new SingularValueDecomposition$$1(t).inverse():solve$$1(t,Matrix$1.eye(t.rows))}function solve$$1(t,e,r=!1){return t=WrapperMatrix2D$1.checkMatrix(t),e=WrapperMatrix2D$1.checkMatrix(e),r?new SingularValueDecomposition$$1(t).solve(e):t.isSquare()?new LuDecomposition$$1(t).solve(e):new QrDecomposition$$1(t).solve(e)}function xrange(t,e){for(var r=[],n=0;n<t;n++)n!==e&&r.push(n);return r}function dependenciesOneRow(t,e,r,n=1e-9,i=1e-9){if(t>i)return new Array(e.rows+1).fill(0);for(var o=e.addRow(r,[0]),s=0;s<o.rows;s++)Math.abs(o.get(s,0))<n&&o.set(s,0,0);return o.to1DArray()}function linearDependencies(t,e={}){const{thresholdValue:r=1e-9,thresholdError:n=1e-9}=e;for(var i=t.rows,o=new Matrix$1(i,i),s=0;s<i;s++){var a=Matrix$1.columnVector(t.getRow(s)),u=t.subMatrixRow(xrange(i,s)).transposeView(),h=new SingularValueDecomposition$$1(u).solve(a),c=max(Matrix$1.sub(a,u.mmul(h)).abs().to1DArray());o.setRow(s,dependenciesOneRow(c,h,s,r,n))}return o}class EigenvalueDecomposition$$1{constructor(t,e={}){const{assumeSymmetric:r=!1}=e;if(!(t=WrapperMatrix2D$1.checkMatrix(t)).isSquare())throw new Error("Matrix is not a square matrix");var n,i,o=t.columns,s=getFilled2DArray$1(o,o,0),a=new Array(o),u=new Array(o),h=t;if(!!r||t.isSymmetric()){for(n=0;n<o;n++)for(i=0;i<o;i++)s[n][i]=h.get(n,i);tred2$1(o,u,a,s),tql2$1(o,u,a,s)}else{var c=getFilled2DArray$1(o,o,0),l=new Array(o);for(i=0;i<o;i++)for(n=0;n<o;n++)c[n][i]=h.get(n,i);orthes$1(o,c,l,s),hqr2$1(o,u,a,s,c)}this.n=o,this.e=u,this.d=a,this.V=s}get realEigenvalues(){return this.d}get imaginaryEigenvalues(){return this.e}get eigenvectorMatrix(){return Matrix$1.isMatrix(this.V)||(this.V=new Matrix$1(this.V)),this.V}get diagonalMatrix(){var t,e,r=this.n,n=this.e,i=this.d,o=new Matrix$1(r,r);for(t=0;t<r;t++){for(e=0;e<r;e++)o[t][e]=0;o[t][t]=i[t],n[t]>0?o[t][t+1]=n[t]:n[t]<0&&(o[t][t-1]=n[t])}return o}}function tred2$1(t,e,r,n){var i,o,s,a,u,h,c,l;for(u=0;u<t;u++)r[u]=n[t-1][u];for(a=t-1;a>0;a--){for(l=0,s=0,h=0;h<a;h++)l+=Math.abs(r[h]);if(0===l)for(e[a]=r[a-1],u=0;u<a;u++)r[u]=n[a-1][u],n[a][u]=0,n[u][a]=0;else{for(h=0;h<a;h++)r[h]/=l,s+=r[h]*r[h];for(i=r[a-1],o=Math.sqrt(s),i>0&&(o=-o),e[a]=l*o,s-=i*o,r[a-1]=i-o,u=0;u<a;u++)e[u]=0;for(u=0;u<a;u++){for(i=r[u],n[u][a]=i,o=e[u]+n[u][u]*i,h=u+1;h<=a-1;h++)o+=n[h][u]*r[h],e[h]+=n[h][u]*i;e[u]=o}for(i=0,u=0;u<a;u++)e[u]/=s,i+=e[u]*r[u];for(c=i/(s+s),u=0;u<a;u++)e[u]-=c*r[u];for(u=0;u<a;u++){for(i=r[u],o=e[u],h=u;h<=a-1;h++)n[h][u]-=i*e[h]+o*r[h];r[u]=n[a-1][u],n[a][u]=0}}r[a]=s}for(a=0;a<t-1;a++){if(n[t-1][a]=n[a][a],n[a][a]=1,0!==(s=r[a+1])){for(h=0;h<=a;h++)r[h]=n[h][a+1]/s;for(u=0;u<=a;u++){for(o=0,h=0;h<=a;h++)o+=n[h][a+1]*n[h][u];for(h=0;h<=a;h++)n[h][u]-=o*r[h]}}for(h=0;h<=a;h++)n[h][a+1]=0}for(u=0;u<t;u++)r[u]=n[t-1][u],n[t-1][u]=0;n[t-1][t-1]=1,e[0]=0}function tql2$1(t,e,r,n){var i,o,s,a,u,h,c,l,f,m,p,d,g,v,w,y;for(s=1;s<t;s++)e[s-1]=e[s];e[t-1]=0;var b=0,x=0,M=Number.EPSILON;for(h=0;h<t;h++){for(x=Math.max(x,Math.abs(r[h])+Math.abs(e[h])),c=h;c<t&&!(Math.abs(e[c])<=M*x);)c++;if(c>h)do{for(i=r[h],f=hypotenuse$1(l=(r[h+1]-i)/(2*e[h]),1),l<0&&(f=-f),r[h]=e[h]/(l+f),r[h+1]=e[h]*(l+f),m=r[h+1],o=i-r[h],s=h+2;s<t;s++)r[s]-=o;for(b+=o,l=r[c],d=p=1,g=p,v=e[h+1],w=0,y=0,s=c-1;s>=h;s--)for(g=d,d=p,y=w,i=p*e[s],o=p*l,f=hypotenuse$1(l,e[s]),e[s+1]=w*f,w=e[s]/f,l=(p=l/f)*r[s]-w*i,r[s+1]=o+w*(p*i+w*r[s]),u=0;u<t;u++)o=n[u][s+1],n[u][s+1]=w*n[u][s]+p*o,n[u][s]=p*n[u][s]-w*o;l=-w*y*g*v*e[h]/m,e[h]=w*l,r[h]=p*l}while(Math.abs(e[h])>M*x);r[h]=r[h]+b,e[h]=0}for(s=0;s<t-1;s++){for(u=s,l=r[s],a=s+1;a<t;a++)r[a]<l&&(u=a,l=r[a]);if(u!==s)for(r[u]=r[s],r[s]=l,a=0;a<t;a++)l=n[a][s],n[a][s]=n[a][u],n[a][u]=l}}function orthes$1(t,e,r,n){var i,o,s,a,u,h,c,l=t-1;for(h=1;h<=l-1;h++){for(c=0,a=h;a<=l;a++)c+=Math.abs(e[a][h-1]);if(0!==c){for(s=0,a=l;a>=h;a--)r[a]=e[a][h-1]/c,s+=r[a]*r[a];for(o=Math.sqrt(s),r[h]>0&&(o=-o),s-=r[h]*o,r[h]=r[h]-o,u=h;u<t;u++){for(i=0,a=l;a>=h;a--)i+=r[a]*e[a][u];for(i/=s,a=h;a<=l;a++)e[a][u]-=i*r[a]}for(a=0;a<=l;a++){for(i=0,u=l;u>=h;u--)i+=r[u]*e[a][u];for(i/=s,u=h;u<=l;u++)e[a][u]-=i*r[u]}r[h]=c*r[h],e[h][h-1]=c*o}}for(a=0;a<t;a++)for(u=0;u<t;u++)n[a][u]=a===u?1:0;for(h=l-1;h>=1;h--)if(0!==e[h][h-1]){for(a=h+1;a<=l;a++)r[a]=e[a][h-1];for(u=h;u<=l;u++){for(o=0,a=h;a<=l;a++)o+=r[a]*n[a][u];for(o=o/r[h]/e[h][h-1],a=h;a<=l;a++)n[a][u]+=o*r[a]}}}function hqr2$1(t,e,r,n,i){var o,s,a,u,h,c,l,f,m,p,d,g,v,w,y,b=t-1,x=t-1,M=Number.EPSILON,_=0,$=0,S=0,R=0,E=0,C=0,k=0,A=0;for(o=0;o<t;o++)for((o<0||o>x)&&(r[o]=i[o][o],e[o]=0),s=Math.max(o-1,0);s<t;s++)$+=Math.abs(i[o][s]);for(;b>=0;){for(u=b;u>0&&(0===(C=Math.abs(i[u-1][u-1])+Math.abs(i[u][u]))&&(C=$),!(Math.abs(i[u][u-1])<M*C));)u--;if(u===b)i[b][b]=i[b][b]+_,r[b]=i[b][b],e[b]=0,b--,A=0;else if(u===b-1){if(l=i[b][b-1]*i[b-1][b],R=(S=(i[b-1][b-1]-i[b][b])/2)*S+l,k=Math.sqrt(Math.abs(R)),i[b][b]=i[b][b]+_,i[b-1][b-1]=i[b-1][b-1]+_,f=i[b][b],R>=0){for(k=S>=0?S+k:S-k,r[b-1]=f+k,r[b]=r[b-1],0!==k&&(r[b]=f-l/k),e[b-1]=0,e[b]=0,S=(f=i[b][b-1])/(C=Math.abs(f)+Math.abs(k)),R=k/C,S/=E=Math.sqrt(S*S+R*R),R/=E,s=b-1;s<t;s++)k=i[b-1][s],i[b-1][s]=R*k+S*i[b][s],i[b][s]=R*i[b][s]-S*k;for(o=0;o<=b;o++)k=i[o][b-1],i[o][b-1]=R*k+S*i[o][b],i[o][b]=R*i[o][b]-S*k;for(o=0;o<=x;o++)k=n[o][b-1],n[o][b-1]=R*k+S*n[o][b],n[o][b]=R*n[o][b]-S*k}else r[b-1]=f+S,r[b]=f+S,e[b-1]=k,e[b]=-k;b-=2,A=0}else{if(f=i[b][b],m=0,l=0,u<b&&(m=i[b-1][b-1],l=i[b][b-1]*i[b-1][b]),10===A){for(_+=f,o=0;o<=b;o++)i[o][o]-=f;f=m=.75*(C=Math.abs(i[b][b-1])+Math.abs(i[b-1][b-2])),l=-.4375*C*C}if(30===A&&(C=(C=(m-f)/2)*C+l)>0){for(C=Math.sqrt(C),m<f&&(C=-C),C=f-l/((m-f)/2+C),o=0;o<=b;o++)i[o][o]-=C;_+=C,f=m=l=.964}for(A+=1,h=b-2;h>=u&&(S=((E=f-(k=i[h][h]))*(C=m-k)-l)/i[h+1][h]+i[h][h+1],R=i[h+1][h+1]-k-E-C,E=i[h+2][h+1],S/=C=Math.abs(S)+Math.abs(R)+Math.abs(E),R/=C,E/=C,h!==u)&&!(Math.abs(i[h][h-1])*(Math.abs(R)+Math.abs(E))<M*(Math.abs(S)*(Math.abs(i[h-1][h-1])+Math.abs(k)+Math.abs(i[h+1][h+1]))));)h--;for(o=h+2;o<=b;o++)i[o][o-2]=0,o>h+2&&(i[o][o-3]=0);for(a=h;a<=b-1&&(w=a!==b-1,a!==h&&(S=i[a][a-1],R=i[a+1][a-1],E=w?i[a+2][a-1]:0,0!==(f=Math.abs(S)+Math.abs(R)+Math.abs(E))&&(S/=f,R/=f,E/=f)),0!==f);a++)if(C=Math.sqrt(S*S+R*R+E*E),S<0&&(C=-C),0!==C){for(a!==h?i[a][a-1]=-C*f:u!==h&&(i[a][a-1]=-i[a][a-1]),f=(S+=C)/C,m=R/C,k=E/C,R/=S,E/=S,s=a;s<t;s++)S=i[a][s]+R*i[a+1][s],w&&(S+=E*i[a+2][s],i[a+2][s]=i[a+2][s]-S*k),i[a][s]=i[a][s]-S*f,i[a+1][s]=i[a+1][s]-S*m;for(o=0;o<=Math.min(b,a+3);o++)S=f*i[o][a]+m*i[o][a+1],w&&(S+=k*i[o][a+2],i[o][a+2]=i[o][a+2]-S*E),i[o][a]=i[o][a]-S,i[o][a+1]=i[o][a+1]-S*R;for(o=0;o<=x;o++)S=f*n[o][a]+m*n[o][a+1],w&&(S+=k*n[o][a+2],n[o][a+2]=n[o][a+2]-S*E),n[o][a]=n[o][a]-S,n[o][a+1]=n[o][a+1]-S*R}}}if(0!==$){for(b=t-1;b>=0;b--)if(S=r[b],0===(R=e[b]))for(u=b,i[b][b]=1,o=b-1;o>=0;o--){for(l=i[o][o]-S,E=0,s=u;s<=b;s++)E+=i[o][s]*i[s][b];if(e[o]<0)k=l,C=E;else if(u=o,0===e[o]?i[o][b]=0!==l?-E/l:-E/(M*$):(f=i[o][o+1],m=i[o+1][o],c=(f*C-k*E)/(R=(r[o]-S)*(r[o]-S)+e[o]*e[o]),i[o][b]=c,i[o+1][b]=Math.abs(f)>Math.abs(k)?(-E-l*c)/f:(-C-m*c)/k),M*(c=Math.abs(i[o][b]))*c>1)for(s=o;s<=b;s++)i[s][b]=i[s][b]/c}else if(R<0)for(u=b-1,Math.abs(i[b][b-1])>Math.abs(i[b-1][b])?(i[b-1][b-1]=R/i[b][b-1],i[b-1][b]=-(i[b][b]-S)/i[b][b-1]):(y=cdiv$1(0,-i[b-1][b],i[b-1][b-1]-S,R),i[b-1][b-1]=y[0],i[b-1][b]=y[1]),i[b][b-1]=0,i[b][b]=1,o=b-2;o>=0;o--){for(p=0,d=0,s=u;s<=b;s++)p+=i[o][s]*i[s][b-1],d+=i[o][s]*i[s][b];if(l=i[o][o]-S,e[o]<0)k=l,E=p,C=d;else if(u=o,0===e[o]?(y=cdiv$1(-p,-d,l,R),i[o][b-1]=y[0],i[o][b]=y[1]):(f=i[o][o+1],m=i[o+1][o],g=(r[o]-S)*(r[o]-S)+e[o]*e[o]-R*R,v=2*(r[o]-S)*R,0===g&&0===v&&(g=M*$*(Math.abs(l)+Math.abs(R)+Math.abs(f)+Math.abs(m)+Math.abs(k))),y=cdiv$1(f*E-k*p+R*d,f*C-k*d-R*p,g,v),i[o][b-1]=y[0],i[o][b]=y[1],Math.abs(f)>Math.abs(k)+Math.abs(R)?(i[o+1][b-1]=(-p-l*i[o][b-1]+R*i[o][b])/f,i[o+1][b]=(-d-l*i[o][b]-R*i[o][b-1])/f):(y=cdiv$1(-E-m*i[o][b-1],-C-m*i[o][b],k,R),i[o+1][b-1]=y[0],i[o+1][b]=y[1])),M*(c=Math.max(Math.abs(i[o][b-1]),Math.abs(i[o][b])))*c>1)for(s=o;s<=b;s++)i[s][b-1]=i[s][b-1]/c,i[s][b]=i[s][b]/c}for(o=0;o<t;o++)if(o<0||o>x)for(s=o;s<t;s++)n[o][s]=i[o][s];for(s=t-1;s>=0;s--)for(o=0;o<=x;o++){for(k=0,a=0;a<=Math.min(s,x);a++)k+=n[o][a]*i[a][s];n[o][s]=k}}}function cdiv$1(t,e,r,n){var i,o;return Math.abs(r)>Math.abs(n)?[(t+(i=n/r)*e)/(o=r+i*n),(e-i*t)/o]:[((i=r/n)*t+e)/(o=n+i*r),(i*e-t)/o]}class CholeskyDecomposition$$1{constructor(t){if(!(t=WrapperMatrix2D$1.checkMatrix(t)).isSymmetric())throw new Error("Matrix is not symmetric");var e,r,n,i=t,o=i.rows,s=new Matrix$1(o,o),a=!0;for(r=0;r<o;r++){var u=s[r],h=0;for(n=0;n<r;n++){var c=s[n],l=0;for(e=0;e<n;e++)l+=c[e]*u[e];u[n]=l=(i.get(r,n)-l)/s[n][n],h+=l*l}for(a&=(h=i.get(r,r)-h)>0,s[r][r]=Math.sqrt(Math.max(h,0)),n=r+1;n<o;n++)s[r][n]=0}if(!a)throw new Error("Matrix is not positive definite");this.L=s}solve(t){t=WrapperMatrix2D$1.checkMatrix(t);var e=this.L,r=e.rows;if(t.rows!==r)throw new Error("Matrix dimensions do not match");var n,i,o,s=t.columns,a=t.clone();for(o=0;o<r;o++)for(i=0;i<s;i++){for(n=0;n<o;n++)a[o][i]-=a[n][i]*e[o][n];a[o][i]/=e[o][o]}for(o=r-1;o>=0;o--)for(i=0;i<s;i++){for(n=o+1;n<r;n++)a[o][i]-=a[n][i]*e[n][o];a[o][i]/=e[o][o]}return a}get lowerTriangularMatrix(){return this.L}}var require$$0$3=Object.freeze({default:Matrix$1,Matrix:Matrix$1,abstractMatrix:AbstractMatrix$1,wrap:wrap$1,WrapperMatrix2D:WrapperMatrix2D$1,WrapperMatrix1D:WrapperMatrix1D$1,solve:solve$$1,inverse:inverse$$1,linearDependencies:linearDependencies,SingularValueDecomposition:SingularValueDecomposition$$1,SVD:SingularValueDecomposition$$1,EigenvalueDecomposition:EigenvalueDecomposition$$1,EVD:EigenvalueDecomposition$$1,CholeskyDecomposition:CholeskyDecomposition$$1,CHO:CholeskyDecomposition$$1,LuDecomposition:LuDecomposition$$1,LU:LuDecomposition$$1,QrDecomposition:QrDecomposition$$1,QR:QrDecomposition$$1}),random=createCommonjsModule((function(t){!function(e){var r="Random",n="function"!=typeof Math.imul||-5!==Math.imul(4294967295,5)?function(t,e){var r=65535&t,n=65535&e;return r*n+((t>>>16&65535)*n+r*(e>>>16&65535)<<16>>>0)|0}:Math.imul,i="function"==typeof String.prototype.repeat&&"xxx"==="x".repeat(3)?function(t,e){return t.repeat(e)}:function(t,e){for(var r="";e>0;)1&e&&(r+=t),e>>=1,t+=t;return r};function o(t){if(!(this instanceof o))return new o(t);if(null==t)t=o.engines.nativeMath;else if("function"!=typeof t)throw new TypeError("Expected engine to be a function, got "+typeof t);this.engine=t}var s,a,u=o.prototype;function h(t){return function(){return t}}function c(t,e){return 0===e?t:function(r){return t(r)+e}}function l(t){var e=+t;return e<0?Math.ceil(e):Math.floor(e)}function f(t,e){return t<0?Math.max(t+e,0):Math.min(t,e)}function m(){}o.engines={nativeMath:function(){return 4294967296*Math.random()|0},mt19937:function(t){function e(t){for(var e=0,r=0;(0|e)<227;e=e+1|0)r=2147483648&t[e]|2147483647&t[e+1|0],t[e]=t[e+397|0]^r>>>1^(1&r?2567483615:0);for(;(0|e)<623;e=e+1|0)r=2147483648&t[e]|2147483647&t[e+1|0],t[e]=t[e-227|0]^r>>>1^(1&r?2567483615:0);r=2147483648&t[623]|2147483647&t[0],t[623]=t[396]^r>>>1^(1&r?2567483615:0)}return function(){var r=new t(624),i=0,s=0;function a(){(0|i)>=624&&(e(r),i=0);var t=r[i];return i=i+1|0,s+=1,0|function(t){return t^=t>>>11,t^=t<<7&2636928640,(t^=t<<15&4022730752)^t>>>18}(t)}return a.getUseCount=function(){return s},a.discard=function(t){for(s+=t,(0|i)>=624&&(e(r),i=0);t-i>624;)t-=624-i,e(r),i=0;return i=i+t|0,a},a.seed=function(t){var e=0;r[0]=e=0|t;for(var o=1;o<624;o=o+1|0)r[o]=e=n(e^e>>>30,1812433253)+o|0;return i=624,s=0,a},a.seedWithArray=function(t){return a.seed(19650218),function(t,e){for(var r=1,i=0,o=e.length,s=0|Math.max(o,624),a=0|t[0];(0|s)>0;--s)t[r]=a=(t[r]^n(a^a>>>30,1664525))+(0|e[i])+(0|i)|0,++i,(0|(r=r+1|0))>623&&(t[0]=t[623],r=1),i>=o&&(i=0);for(s=623;(0|s)>0;--s)t[r]=a=(t[r]^n(a^a>>>30,1566083941))-r|0,(0|(r=r+1|0))>623&&(t[0]=t[623],r=1);t[0]=2147483648}(r,t),a},a.autoSeed=function(){return a.seedWithArray(o.generateEntropyArray())},a}}("function"==typeof Int32Array?Int32Array:Array),browserCrypto:"undefined"!=typeof crypto&&"function"==typeof crypto.getRandomValues&&"function"==typeof Int32Array?(s=null,a=128,function(){return a>=128&&(null===s&&(s=new Int32Array(128)),crypto.getRandomValues(s),a=0),0|s[a++]}):null},o.generateEntropyArray=function(){for(var t=[],e=o.engines.nativeMath,r=0;r<16;++r)t[r]=0|e();return t.push(0|(new Date).getTime()),t},o.int32=function(t){return 0|t()},u.int32=function(){return o.int32(this.engine)},o.uint32=function(t){return t()>>>0},u.uint32=function(){return o.uint32(this.engine)},o.uint53=function(t){return 4294967296*(2097151&t())+(t()>>>0)},u.uint53=function(){return o.uint53(this.engine)},o.uint53Full=function(t){for(;;){var e=0|t();if(!(2097152&e))return 4294967296*(2097151&e)+(t()>>>0);if(2097152==(4194303&e)&&!(0|t()))return 9007199254740992}},u.uint53Full=function(){return o.uint53Full(this.engine)},o.int53=function(t){var e=0|t();return 4294967296*(2097151&e)+(t()>>>0)+(2097152&e?-9007199254740992:0)},u.int53=function(){return o.int53(this.engine)},o.int53Full=function(t){for(;;){var e=0|t();if(!(4194304&e))return 4294967296*(2097151&e)+(t()>>>0)+(2097152&e?-9007199254740992:0);if(4194304==(8388607&e)&&!(0|t()))return 9007199254740992}},u.int53Full=function(){return o.int53Full(this.engine)},o.integer=function(){function t(t){return!(t+1&t)}function e(e){return t(e)?(r=e,function(t){return t()&r}):function(t){var e=t+1,r=e*Math.floor(4294967296/e);return function(t){var n=0;do{n=t()>>>0}while(n>=r);return n%e}}(e);var r}function r(e){var r,n=e+1;if(!(0|n)){var i=(n/4294967296|0)-1;if(t(i))return r=i,function(t){return 4294967296*(t()&r)+(t()>>>0)}}return function(t){var e=t*Math.floor(9007199254740992/t);return function(r){var n=0;do{n=4294967296*(2097151&r())+(r()>>>0)}while(n>=e);return n%t}}(n)}function n(t,e){return function(r){var n=0;do{var i=0|r();n=4294967296*(2097151&i)+(r()>>>0)+(2097152&i?-9007199254740992:0)}while(n<t||n>e);return n}}return function(t,i){if(t=Math.floor(t),i=Math.floor(i),t<-9007199254740992||!isFinite(t))throw new RangeError("Expected min to be at least -9007199254740992");if(i>9007199254740992||!isFinite(i))throw new RangeError("Expected max to be at most 9007199254740992");var s=i-t;return s<=0||!isFinite(s)?h(t):4294967295===s?0===t?o.uint32:c(o.int32,t+2147483648):s<4294967295?c(e(s),t):9007199254740991===s?c(o.uint53,t):s<9007199254740991?c(r(s),t):i-1-t==9007199254740991?c(o.uint53Full,t):-9007199254740992===t&&9007199254740992===i?o.int53Full:-9007199254740992===t&&9007199254740991===i?o.int53:-9007199254740991===t&&9007199254740992===i?c(o.int53,1):9007199254740992===i?c(n(t-1,i-1),1):n(t,i)}}(),u.integer=function(t,e){return o.integer(t,e)(this.engine)},o.realZeroToOneInclusive=function(t){return o.uint53Full(t)/9007199254740992},u.realZeroToOneInclusive=function(){return o.realZeroToOneInclusive(this.engine)},o.realZeroToOneExclusive=function(t){return o.uint53(t)/9007199254740992},u.realZeroToOneExclusive=function(){return o.realZeroToOneExclusive(this.engine)},o.real=function(t,e,r){if(!isFinite(t))throw new RangeError("Expected left to be a finite number");if(!isFinite(e))throw new RangeError("Expected right to be a finite number");return c((n=r?o.realZeroToOneInclusive:o.realZeroToOneExclusive,1==(i=e-t)?n:0===i?function(){return 0}:function(t){return n(t)*i}),t);var n,i},u.real=function(t,e,r){return o.real(t,e,r)(this.engine)},o.bool=function(){function t(t){return!(1&~t())}function e(t,e){return function(r){return t(r)<e}}return function(r,n){return null==n?null==r?t:function(t){if(t<=0)return h(!1);if(t>=1)return h(!0);var r=4294967296*t;return r%1==0?e(o.int32,r-2147483648|0):e(o.uint53,Math.round(9007199254740992*t))}(r):r<=0?h(!1):r>=n?h(!0):e(o.integer(0,n-1),r)}}(),u.bool=function(t,e){return o.bool(t,e)(this.engine)},o.pick=function(t,e,r,n){var i=e.length,s=null==r?0:f(l(r),i),a=void 0===n?i:f(l(n),i);if(!(s>=a))return e[o.integer(s,a-1)(t)]},u.pick=function(t,e,r){return o.pick(this.engine,t,e,r)};var p,d,g,v,w=Array.prototype.slice;o.picker=function(t,e,r){var n=w.call(t,e,r);if(!n.length)return m;var i=o.integer(0,n.length-1);return function(t){return n[i(t)]}},o.shuffle=function(t,e,r){var n=e.length;if(n){null==r&&(r=0);for(var i=n-1>>>0;i>r;--i){var s=o.integer(0,i)(t);if(i!==s){var a=e[i];e[i]=e[s],e[s]=a}}}return e},u.shuffle=function(t){return o.shuffle(this.engine,t)},o.sample=function(t,e,r){if(r<0||r>e.length||!isFinite(r))throw new RangeError("Expected sampleSize to be within 0 and the length of the population");if(0===r)return[];var n=w.call(e),i=n.length;if(i===r)return o.shuffle(t,n,0);var s=i-r;return o.shuffle(t,n,s-1).slice(s)},u.sample=function(t,e){return o.sample(this.engine,t,e)},o.die=function(t){return o.integer(1,t)},u.die=function(t){return o.die(t)(this.engine)},o.dice=function(t,e){var r=o.die(t);return function(t){var n=[];n.length=e;for(var i=0;i<e;++i)n[i]=r(t);return n}},u.dice=function(t,e){return o.dice(t,e)(this.engine)},o.uuid4=function(){function t(t,e){return i("0",e-t.length)+t}return function(e){var r=e()>>>0,n=0|e(),i=0|e(),o=e()>>>0;return t(r.toString(16),8)+"-"+t((65535&n).toString(16),4)+"-"+t((n>>4&4095|16384).toString(16),4)+"-"+t((16383&i|32768).toString(16),4)+"-"+t((i>>4&65535).toString(16),4)+t(o.toString(16),8)}}(),u.uuid4=function(){return o.uuid4(this.engine)},o.string=function(t){null==t&&(t="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-");var e=t.length;if(!e)throw new Error("Expected pool not to be an empty string");var r=o.integer(0,e-1);return function(e,n){for(var i="",o=0;o<n;++o){var s=r(e);i+=t.charAt(s)}return i}},u.string=function(t,e){return o.string(e)(this.engine,t)},o.hex=(p="0123456789abcdef",d=o.string(p),g=o.string(p.toUpperCase()),function(t){return t?g:d}),u.hex=function(t,e){return o.hex(e)(this.engine,t)},o.date=function(t,e){if(!(t instanceof Date))throw new TypeError("Expected start to be a Date, got "+typeof t);if(!(e instanceof Date))throw new TypeError("Expected end to be a Date, got "+typeof e);var r=o.integer(t.getTime(),e.getTime());return function(t){return new Date(r(t))}},u.date=function(t,e){return o.date(t,e)(this.engine)},"function"==typeof commonjsRequire?t.exports=o:(v=e[r],o.noConflict=function(){return e[r]=v,this},e[r]=o)}(commonjsGlobal)}));function checkFloat(t){return t>0&&t<=1}function examplesBaggingWithReplacement(t,e,r){var n=random.engines.mt19937(),i=random.integer(0,t.rows-1);if(void 0===r)n=n.autoSeed();else{if(!Number.isInteger(r))throw new RangeError(`Expected seed must be undefined or integer not ${r}`);n=n.seed(r)}for(var o=new Array(t.rows),s=new Array(t.rows),a=0;a<t.rows;++a){var u=i(n);o[a]=t[u],s[a]=e[u]}return{X:new Matrix$1(o),y:s}}function featureBagging(t,e,r,n){if(t.columns<e)throw new RangeError("N should be less or equal to the number of columns of X");var i=random.integer(0,t.columns-1),o=random.engines.mt19937();if(void 0===n)o=o.autoSeed();else{if(!Number.isInteger(n))throw new RangeError(`Expected seed must be undefined or integer not ${n}`);o=o.seed(n)}var s=new Matrix$1(t.rows,e);if(r)for(var a=new Array(e),u=0;u<e;++u){var h=i(o);a[u]=h,s.setColumn(u,t.getColumn(h))}else{for(a=new Set,h=i(o),u=0;u<e;++u){for(;a.has(h);)h=i(o);s.setColumn(u,t.getColumn(h)),a.add(h)}a=Array.from(a)}return{X:s,usedIndex:a}}class RandomForestBase{constructor(t,e){if(!0===t){this.replacement=e.replacement,this.maxFeatures=e.maxFeatures,this.nEstimators=e.nEstimators,this.treeOptions=e.treeOptions,this.isClassifier=e.isClassifier,this.seed=e.seed,this.n=e.n,this.indexes=e.indexes,this.useSampleBagging=e.useSampleBagging;var r=this.isClassifier?DecisionTreeClassifier:DecisionTreeRegression;this.estimators=e.estimators.map((t=>r.load(t)))}else this.replacement=t.replacement,this.maxFeatures=t.maxFeatures,this.nEstimators=t.nEstimators,this.treeOptions=t.treeOptions,this.isClassifier=t.isClassifier,this.seed=t.seed,this.useSampleBagging=t.useSampleBagging}train(t,e){if(t=Matrix$1.checkMatrix(t),this.maxFeatures=this.maxFeatures||t.columns,checkFloat(this.maxFeatures))this.n=Math.floor(t.columns*this.maxFeatures);else{if(!Number.isInteger(this.maxFeatures))throw new RangeError(`Cannot process the maxFeatures parameter ${this.maxFeatures}`);if(this.maxFeatures>t.columns)throw new RangeError(`The maxFeatures parameter should be less than ${t.columns}`);this.n=this.maxFeatures}if(this.isClassifier)var r=DecisionTreeClassifier;else r=DecisionTreeRegression;this.estimators=new Array(this.nEstimators),this.indexes=new Array(this.nEstimators);for(var n=0;n<this.nEstimators;++n){var i=this.useSampleBagging?examplesBaggingWithReplacement(t,e,this.seed):{X:t,y:e},o=i.X,s=i.y;o=(i=featureBagging(o,this.n,this.replacement,this.seed)).X,this.indexes[n]=i.usedIndex,this.estimators[n]=new r(this.treeOptions),this.estimators[n].train(o,s)}}selection(t){throw new Error("Abstract method 'selection' not implemented!")}predict(t){var e=new Array(this.nEstimators);t=Matrix$1.checkMatrix(t);for(var r=0;r<this.nEstimators;++r){var n=t.columnSelectionView(this.indexes[r]);e[r]=this.estimators[r].predict(n)}e=new WrapperMatrix2D$1(e).transposeView();var i=new Array(e.rows);for(r=0;r<e.rows;++r)i[r]=this.selection(e.getRow(r));return i}toJSON(){return{indexes:this.indexes,n:this.n,replacement:this.replacement,maxFeatures:this.maxFeatures,nEstimators:this.nEstimators,treeOptions:this.treeOptions,isClassifier:this.isClassifier,seed:this.seed,estimators:this.estimators.map((t=>t.toJSON())),useSampleBagging:this.useSampleBagging}}}const defaultOptions$2={maxFeatures:1,replacement:!0,nEstimators:10,seed:42,useSampleBagging:!1};class RandomForestClassifier extends RandomForestBase{constructor(t,e){!0===t?super(!0,e.baseModel):((t=Object.assign({},defaultOptions$2,t)).isClassifier=!0,super(t))}selection(t){return mode(t)}toJSON(){return{baseModel:super.toJSON(),name:"RFClassifier"}}static load(t){if("RFClassifier"!==t.name)throw new RangeError(`Invalid model: ${t.name}`);return new RandomForestClassifier(!0,t)}}function mode(t){return t.sort(((e,r)=>t.filter((t=>t===e)).length-t.filter((t=>t===r)).length)).pop()}var medianQuickselect_min=createCommonjsModule((function(t){!function(){function e(t){for(var e=0,i=t.length-1,o=void 0,s=void 0,a=void 0,u=n(e,i);;){if(i<=e)return t[u];if(i==e+1)return t[e]>t[i]&&r(t,e,i),t[u];for(t[o=n(e,i)]>t[i]&&r(t,o,i),t[e]>t[i]&&r(t,e,i),t[o]>t[e]&&r(t,o,e),r(t,o,e+1),s=e+1,a=i;;){do{s++}while(t[e]>t[s]);do{a--}while(t[a]>t[e]);if(a<s)break;r(t,s,a)}r(t,e,a),a<=u&&(e=s),a>=u&&(i=a-1)}}var r=function(t,e,r){var n;return n=[t[r],t[e]],t[e]=n[0],t[r]=n[1],n},n=function(t,e){return~~((t+e)/2)};t.exports?t.exports=e:window.median=e}()}));function median(t){if(!Array.isArray(t))throw new Error("input must be an array");if(0===t.length)throw new Error("input must not be empty");return medianQuickselect_min(t.slice())}const selectionMethods={mean:mean,median:median},defaultOptions$3={maxFeatures:1,replacement:!1,nEstimators:10,treeOptions:{},selectionMethod:"mean",seed:42,useSampleBagging:!1};class RandomForestRegression extends RandomForestBase{constructor(t,e){if(!0===t)super(!0,e.baseModel),this.selectionMethod=e.selectionMethod;else{if("mean"!==(t=Object.assign({},defaultOptions$3,t)).selectionMethod&&"median"!==t.selectionMethod)throw new RangeError(`Unsupported selection method ${t.selectionMethod}`);t.isClassifier=!1,super(t),this.selectionMethod=t.selectionMethod}}selection(t){return selectionMethods[this.selectionMethod](t)}toJSON(){return{baseModel:super.toJSON(),selectionMethod:this.selectionMethod,name:"RFRegression"}}static load(t){if("RFRegression"!==t.name)throw new RangeError(`Invalid model: ${t.name}`);return new RandomForestRegression(!0,t)}}var src$1=Object.freeze({RandomForestClassifier:RandomForestClassifier,RandomForestRegression:RandomForestRegression});Symbol.species||(Symbol.species=Symbol.for("@@species"));class LuDecomposition$$1{constructor(t){var e,r,n,i,o,s,a,u,h,c=(t=WrapperMatrix2D$2.checkMatrix(t)).clone(),l=c.rows,f=c.columns,m=new Array(l),p=1;for(e=0;e<l;e++)m[e]=e;for(u=new Array(l),r=0;r<f;r++){for(e=0;e<l;e++)u[e]=c.get(e,r);for(e=0;e<l;e++){for(h=Math.min(e,r),o=0,n=0;n<h;n++)o+=c.get(e,n)*u[n];u[e]-=o,c.set(e,r,u[e])}for(i=r,e=r+1;e<l;e++)Math.abs(u[e])>Math.abs(u[i])&&(i=e);if(i!==r){for(n=0;n<f;n++)s=c.get(i,n),c.set(i,n,c.get(r,n)),c.set(r,n,s);a=m[i],m[i]=m[r],m[r]=a,p=-p}if(r<l&&0!==c.get(r,r))for(e=r+1;e<l;e++)c.set(e,r,c.get(e,r)/c.get(r,r))}this.LU=c,this.pivotVector=m,this.pivotSign=p}isSingular(){for(var t=this.LU,e=t.columns,r=0;r<e;r++)if(0===t[r][r])return!0;return!1}solve(t){t=Matrix$2.checkMatrix(t);var e=this.LU;if(e.rows!==t.rows)throw new Error("Invalid matrix dimensions");if(this.isSingular())throw new Error("LU matrix is singular");var r,n,i,o=t.columns,s=t.subMatrixRow(this.pivotVector,0,o-1),a=e.columns;for(i=0;i<a;i++)for(r=i+1;r<a;r++)for(n=0;n<o;n++)s[r][n]-=s[i][n]*e[r][i];for(i=a-1;i>=0;i--){for(n=0;n<o;n++)s[i][n]/=e[i][i];for(r=0;r<i;r++)for(n=0;n<o;n++)s[r][n]-=s[i][n]*e[r][i]}return s}get determinant(){var t=this.LU;if(!t.isSquare())throw new Error("Matrix must be square");for(var e=this.pivotSign,r=t.columns,n=0;n<r;n++)e*=t[n][n];return e}get lowerTriangularMatrix(){for(var t=this.LU,e=t.rows,r=t.columns,n=new Matrix$2(e,r),i=0;i<e;i++)for(var o=0;o<r;o++)n[i][o]=i>o?t[i][o]:i===o?1:0;return n}get upperTriangularMatrix(){for(var t=this.LU,e=t.rows,r=t.columns,n=new Matrix$2(e,r),i=0;i<e;i++)for(var o=0;o<r;o++)n[i][o]=i<=o?t[i][o]:0;return n}get pivotPermutationVector(){return this.pivotVector.slice()}}function hypotenuse$2(t,e){var r=0;return Math.abs(t)>Math.abs(e)?(r=e/t,Math.abs(t)*Math.sqrt(1+r*r)):0!==e?(r=t/e,Math.abs(e)*Math.sqrt(1+r*r)):0}function getFilled2DArray$2(t,e,r){for(var n=new Array(t),i=0;i<t;i++){n[i]=new Array(e);for(var o=0;o<e;o++)n[i][o]=r}return n}class SingularValueDecomposition$$1{constructor(t,e={}){var r=(t=WrapperMatrix2D$2.checkMatrix(t)).rows,n=t.columns,i=Math.min(r,n);const{computeLeftSingularVectors:o=!0,computeRightSingularVectors:s=!0,autoTranspose:a=!1}=e;var u,h=Boolean(o),c=Boolean(s),l=!1;if(r<n)if(a){r=(u=t.transpose()).rows,n=u.columns,l=!0;var f=h;h=c,c=f}else u=t.clone(),console.warn("Computing SVD on a matrix with more columns than rows. Consider enabling autoTranspose");else u=t.clone();var m,p,d,g,v,w,y,b,x,M,_,$,S,R,E,C,k,A,T,O,I,D=new Array(Math.min(r+1,n)),P=getFilled2DArray$2(r,i,0),V=getFilled2DArray$2(n,n,0),j=new Array(n),L=new Array(r),N=Math.min(r-1,n),B=Math.max(0,Math.min(n-2,r));for(d=0,M=Math.max(N,B);d<M;d++){if(d<N){for(D[d]=0,m=d;m<r;m++)D[d]=hypotenuse$2(D[d],u[m][d]);if(0!==D[d]){for(u[d][d]<0&&(D[d]=-D[d]),m=d;m<r;m++)u[m][d]/=D[d];u[d][d]+=1}D[d]=-D[d]}for(p=d+1;p<n;p++){if(d<N&&0!==D[d]){for(v=0,m=d;m<r;m++)v+=u[m][d]*u[m][p];for(v=-v/u[d][d],m=d;m<r;m++)u[m][p]+=v*u[m][d]}j[p]=u[d][p]}if(h&&d<N)for(m=d;m<r;m++)P[m][d]=u[m][d];if(d<B){for(j[d]=0,m=d+1;m<n;m++)j[d]=hypotenuse$2(j[d],j[m]);if(0!==j[d]){for(j[d+1]<0&&(j[d]=0-j[d]),m=d+1;m<n;m++)j[m]/=j[d];j[d+1]+=1}if(j[d]=-j[d],d+1<r&&0!==j[d]){for(m=d+1;m<r;m++)L[m]=0;for(p=d+1;p<n;p++)for(m=d+1;m<r;m++)L[m]+=j[p]*u[m][p];for(p=d+1;p<n;p++)for(v=-j[p]/j[d+1],m=d+1;m<r;m++)u[m][p]+=v*L[m]}if(c)for(m=d+1;m<n;m++)V[m][d]=j[m]}}if(g=Math.min(n,r+1),N<n&&(D[N]=u[N][N]),r<g&&(D[g-1]=0),B+1<g&&(j[B]=u[B][g-1]),j[g-1]=0,h){for(p=N;p<i;p++){for(m=0;m<r;m++)P[m][p]=0;P[p][p]=1}for(d=N-1;d>=0;d--)if(0!==D[d]){for(p=d+1;p<i;p++){for(v=0,m=d;m<r;m++)v+=P[m][d]*P[m][p];for(v=-v/P[d][d],m=d;m<r;m++)P[m][p]+=v*P[m][d]}for(m=d;m<r;m++)P[m][d]=-P[m][d];for(P[d][d]=1+P[d][d],m=0;m<d-1;m++)P[m][d]=0}else{for(m=0;m<r;m++)P[m][d]=0;P[d][d]=1}}if(c)for(d=n-1;d>=0;d--){if(d<B&&0!==j[d])for(p=d+1;p<n;p++){for(v=0,m=d+1;m<n;m++)v+=V[m][d]*V[m][p];for(v=-v/V[d+1][d],m=d+1;m<n;m++)V[m][p]+=v*V[m][d]}for(m=0;m<n;m++)V[m][d]=0;V[d][d]=1}for(var F=g-1,z=Number.EPSILON;g>0;){for(d=g-2;d>=-1&&-1!==d;d--)if(Math.abs(j[d])<=z*(Math.abs(D[d])+Math.abs(D[d+1]))){j[d]=0;break}if(d===g-2)_=4;else{for(w=g-1;w>=d&&w!==d;w--)if(v=(w!==g?Math.abs(j[w]):0)+(w!==d+1?Math.abs(j[w-1]):0),Math.abs(D[w])<=z*v){D[w]=0;break}w===d?_=3:w===g-1?_=1:(_=2,d=w)}switch(d++,_){case 1:for(y=j[g-2],j[g-2]=0,p=g-2;p>=d;p--)if(v=hypotenuse$2(D[p],y),b=D[p]/v,x=y/v,D[p]=v,p!==d&&(y=-x*j[p-1],j[p-1]=b*j[p-1]),c)for(m=0;m<n;m++)v=b*V[m][p]+x*V[m][g-1],V[m][g-1]=-x*V[m][p]+b*V[m][g-1],V[m][p]=v;break;case 2:for(y=j[d-1],j[d-1]=0,p=d;p<g;p++)if(v=hypotenuse$2(D[p],y),b=D[p]/v,x=y/v,D[p]=v,y=-x*j[p],j[p]=b*j[p],h)for(m=0;m<r;m++)v=b*P[m][p]+x*P[m][d-1],P[m][d-1]=-x*P[m][p]+b*P[m][d-1],P[m][p]=v;break;case 3:for($=Math.max(Math.abs(D[g-1]),Math.abs(D[g-2]),Math.abs(j[g-2]),Math.abs(D[d]),Math.abs(j[d])),S=D[g-1]/$,R=D[g-2]/$,E=j[g-2]/$,C=D[d]/$,k=j[d]/$,T=S*E*(S*E),O=0,0===(A=((R+S)*(R-S)+E*E)/2)&&0===T||(O=Math.sqrt(A*A+T),A<0&&(O=-O),O=T/(A+O)),y=(C+S)*(C-S)+O,I=C*k,p=d;p<g-1;p++){if(b=y/(v=hypotenuse$2(y,I)),x=I/v,p!==d&&(j[p-1]=v),y=b*D[p]+x*j[p],j[p]=b*j[p]-x*D[p],I=x*D[p+1],D[p+1]=b*D[p+1],c)for(m=0;m<n;m++)v=b*V[m][p]+x*V[m][p+1],V[m][p+1]=-x*V[m][p]+b*V[m][p+1],V[m][p]=v;if(b=y/(v=hypotenuse$2(y,I)),x=I/v,D[p]=v,y=b*j[p]+x*D[p+1],D[p+1]=-x*j[p]+b*D[p+1],I=x*j[p+1],j[p+1]=b*j[p+1],h&&p<r-1)for(m=0;m<r;m++)v=b*P[m][p]+x*P[m][p+1],P[m][p+1]=-x*P[m][p]+b*P[m][p+1],P[m][p]=v}j[g-2]=y;break;case 4:if(D[d]<=0&&(D[d]=D[d]<0?-D[d]:0,c))for(m=0;m<=F;m++)V[m][d]=-V[m][d];for(;d<F&&!(D[d]>=D[d+1]);){if(v=D[d],D[d]=D[d+1],D[d+1]=v,c&&d<n-1)for(m=0;m<n;m++)v=V[m][d+1],V[m][d+1]=V[m][d],V[m][d]=v;if(h&&d<r-1)for(m=0;m<r;m++)v=P[m][d+1],P[m][d+1]=P[m][d],P[m][d]=v;d++}g--}}if(l){var q=V;V=P,P=q}this.m=r,this.n=n,this.s=D,this.U=P,this.V=V}solve(t){var e,r=t,n=this.threshold,i=this.s.length,o=Matrix$2.zeros(i,i);for(e=0;e<i;e++)Math.abs(this.s[e])<=n?o[e][e]=0:o[e][e]=1/this.s[e];var s,a,u,h=this.U,c=this.rightSingularVectors,l=c.mmul(o),f=c.rows,m=h.length,p=Matrix$2.zeros(f,m);for(e=0;e<f;e++)for(s=0;s<m;s++){for(u=0,a=0;a<i;a++)u+=l[e][a]*h[s][a];p[e][s]=u}return p.mmul(r)}solveForDiagonal(t){return this.solve(Matrix$2.diag(t))}inverse(){var t,e,r=this.V,n=this.threshold,i=r.length,o=r[0].length,s=new Matrix$2(i,this.s.length);for(t=0;t<i;t++)for(e=0;e<o;e++)Math.abs(this.s[e])>n?s[t][e]=r[t][e]/this.s[e]:s[t][e]=0;var a,u,h=this.U,c=h.length,l=h[0].length,f=new Matrix$2(i,c);for(t=0;t<i;t++)for(e=0;e<c;e++){for(u=0,a=0;a<l;a++)u+=s[t][a]*h[e][a];f[t][e]=u}return f}get condition(){return this.s[0]/this.s[Math.min(this.m,this.n)-1]}get norm2(){return this.s[0]}get rank(){for(var t=Math.max(this.m,this.n)*this.s[0]*Number.EPSILON,e=0,r=this.s,n=0,i=r.length;n<i;n++)r[n]>t&&e++;return e}get diagonal(){return this.s}get threshold(){return Number.EPSILON/2*Math.max(this.m,this.n)*this.s[0]}get leftSingularVectors(){return Matrix$2.isMatrix(this.U)||(this.U=new Matrix$2(this.U)),this.U}get rightSingularVectors(){return Matrix$2.isMatrix(this.V)||(this.V=new Matrix$2(this.V)),this.V}get diagonalMatrix(){return Matrix$2.diag(this.s)}}function checkRowIndex$2(t,e,r){var n=r?t.rows:t.rows-1;if(e<0||e>n)throw new RangeError("Row index out of range")}function checkColumnIndex$2(t,e,r){var n=r?t.columns:t.columns-1;if(e<0||e>n)throw new RangeError("Column index out of range")}function checkRowVector$2(t,e){if(e.to1DArray&&(e=e.to1DArray()),e.length!==t.columns)throw new RangeError("vector size must be the same as the number of columns");return e}function checkColumnVector$2(t,e){if(e.to1DArray&&(e=e.to1DArray()),e.length!==t.rows)throw new RangeError("vector size must be the same as the number of rows");return e}function checkIndices$2(t,e,r){return{row:checkRowIndices$2(t,e),column:checkColumnIndices$2(t,r)}}function checkRowIndices$2(t,e){if("object"!=typeof e)throw new TypeError("unexpected type for row indices");if(e.some((e=>e<0||e>=t.rows)))throw new RangeError("row indices are out of range");return Array.isArray(e)||(e=Array.from(e)),e}function checkColumnIndices$2(t,e){if("object"!=typeof e)throw new TypeError("unexpected type for column indices");var r=e.some((e=>e<0||e>=t.columns));if(r)throw new RangeError("column indices are out of range");return Array.isArray(e)||(e=Array.from(e)),e}function checkRange$2(t,e,r,n,i){if(5!==arguments.length)throw new TypeError("Invalid argument type");if(Array.from(arguments).slice(1).some((function(t){return"number"!=typeof t})))throw new TypeError("Invalid argument type");if(e>r||n>i||e<0||e>=t.rows||r<0||r>=t.rows||n<0||n>=t.columns||i<0||i>=t.columns)throw new RangeError("Submatrix indices are out of range")}function sumByRow$2(t){for(var e=Matrix$2.zeros(t.rows,1),r=0;r<t.rows;++r)for(var n=0;n<t.columns;++n)e.set(r,0,e.get(r,0)+t.get(r,n));return e}function sumByColumn$2(t){for(var e=Matrix$2.zeros(1,t.columns),r=0;r<t.rows;++r)for(var n=0;n<t.columns;++n)e.set(0,n,e.get(0,n)+t.get(r,n));return e}function sumAll$2(t){for(var e=0,r=0;r<t.rows;r++)for(var n=0;n<t.columns;n++)e+=t.get(r,n);return e}class BaseView$2 extends(AbstractMatrix$2()){constructor(t,e,r){super(),this.matrix=t,this.rows=e,this.columns=r}static get[Symbol.species](){return Matrix$2}}class MatrixTransposeView$2 extends BaseView$2{constructor(t){super(t,t.columns,t.rows)}set(t,e,r){return this.matrix.set(e,t,r),this}get(t,e){return this.matrix.get(e,t)}}class MatrixRowView$2 extends BaseView$2{constructor(t,e){super(t,1,t.columns),this.row=e}set(t,e,r){return this.matrix.set(this.row,e,r),this}get(t,e){return this.matrix.get(this.row,e)}}class MatrixSubView$2 extends BaseView$2{constructor(t,e,r,n,i){checkRange$2(t,e,r,n,i),super(t,r-e+1,i-n+1),this.startRow=e,this.startColumn=n}set(t,e,r){return this.matrix.set(this.startRow+t,this.startColumn+e,r),this}get(t,e){return this.matrix.get(this.startRow+t,this.startColumn+e)}}class MatrixSelectionView$2 extends BaseView$2{constructor(t,e,r){var n=checkIndices$2(t,e,r);super(t,n.row.length,n.column.length),this.rowIndices=n.row,this.columnIndices=n.column}set(t,e,r){return this.matrix.set(this.rowIndices[t],this.columnIndices[e],r),this}get(t,e){return this.matrix.get(this.rowIndices[t],this.columnIndices[e])}}class MatrixRowSelectionView$2 extends BaseView$2{constructor(t,e){super(t,(e=checkRowIndices$2(t,e)).length,t.columns),this.rowIndices=e}set(t,e,r){return this.matrix.set(this.rowIndices[t],e,r),this}get(t,e){return this.matrix.get(this.rowIndices[t],e)}}class MatrixColumnSelectionView$2 extends BaseView$2{constructor(t,e){e=checkColumnIndices$2(t,e),super(t,t.rows,e.length),this.columnIndices=e}set(t,e,r){return this.matrix.set(t,this.columnIndices[e],r),this}get(t,e){return this.matrix.get(t,this.columnIndices[e])}}class MatrixColumnView$2 extends BaseView$2{constructor(t,e){super(t,t.rows,1),this.column=e}set(t,e,r){return this.matrix.set(t,this.column,r),this}get(t){return this.matrix.get(t,this.column)}}class MatrixFlipRowView$2 extends BaseView$2{constructor(t){super(t,t.rows,t.columns)}set(t,e,r){return this.matrix.set(this.rows-t-1,e,r),this}get(t,e){return this.matrix.get(this.rows-t-1,e)}}class MatrixFlipColumnView$2 extends BaseView$2{constructor(t){super(t,t.rows,t.columns)}set(t,e,r){return this.matrix.set(t,this.columns-e-1,r),this}get(t,e){return this.matrix.get(t,this.columns-e-1)}}function AbstractMatrix$2(t){void 0===t&&(t=Object);class e extends t{static get[Symbol.species](){return this}static from1DArray(t,e,r){if(t*e!==r.length)throw new RangeError("Data length does not match given dimensions");for(var n=new this(t,e),i=0;i<t;i++)for(var o=0;o<e;o++)n.set(i,o,r[i*e+o]);return n}static rowVector(t){for(var e=new this(1,t.length),r=0;r<t.length;r++)e.set(0,r,t[r]);return e}static columnVector(t){for(var e=new this(t.length,1),r=0;r<t.length;r++)e.set(r,0,t[r]);return e}static empty(t,e){return new this(t,e)}static zeros(t,e){return this.empty(t,e).fill(0)}static ones(t,e){return this.empty(t,e).fill(1)}static rand(t,e,r){void 0===r&&(r=Math.random);for(var n=this.empty(t,e),i=0;i<t;i++)for(var o=0;o<e;o++)n.set(i,o,r());return n}static randInt(t,e,r,n){void 0===r&&(r=1e3),void 0===n&&(n=Math.random);for(var i=this.empty(t,e),o=0;o<t;o++)for(var s=0;s<e;s++){var a=Math.floor(n()*r);i.set(o,s,a)}return i}static eye(t,e,r){void 0===e&&(e=t),void 0===r&&(r=1);for(var n=Math.min(t,e),i=this.zeros(t,e),o=0;o<n;o++)i.set(o,o,r);return i}static diag(t,e,r){var n=t.length;void 0===e&&(e=n),void 0===r&&(r=e);for(var i=Math.min(n,e,r),o=this.zeros(e,r),s=0;s<i;s++)o.set(s,s,t[s]);return o}static min(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);for(var r=t.rows,n=t.columns,i=new this(r,n),o=0;o<r;o++)for(var s=0;s<n;s++)i.set(o,s,Math.min(t.get(o,s),e.get(o,s)));return i}static max(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);for(var r=t.rows,n=t.columns,i=new this(r,n),o=0;o<r;o++)for(var s=0;s<n;s++)i.set(o,s,Math.max(t.get(o,s),e.get(o,s)));return i}static checkMatrix(t){return e.isMatrix(t)?t:new this(t)}static isMatrix(t){return null!=t&&"Matrix"===t.klass}get size(){return this.rows*this.columns}apply(t){if("function"!=typeof t)throw new TypeError("callback must be a function");for(var e=this.rows,r=this.columns,n=0;n<e;n++)for(var i=0;i<r;i++)t.call(this,n,i);return this}to1DArray(){for(var t=new Array(this.size),e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)t[e*this.columns+r]=this.get(e,r);return t}to2DArray(){for(var t=new Array(this.rows),e=0;e<this.rows;e++){t[e]=new Array(this.columns);for(var r=0;r<this.columns;r++)t[e][r]=this.get(e,r)}return t}isRowVector(){return 1===this.rows}isColumnVector(){return 1===this.columns}isVector(){return 1===this.rows||1===this.columns}isSquare(){return this.rows===this.columns}isSymmetric(){if(this.isSquare()){for(var t=0;t<this.rows;t++)for(var e=0;e<=t;e++)if(this.get(t,e)!==this.get(e,t))return!1;return!0}return!1}set(t,e,r){throw new Error("set method is unimplemented")}get(t,e){throw new Error("get method is unimplemented")}repeat(t,e){t=t||1,e=e||1;for(var r=new this.constructor[Symbol.species](this.rows*t,this.columns*e),n=0;n<t;n++)for(var i=0;i<e;i++)r.setSubMatrix(this,this.rows*n,this.columns*i);return r}fill(t){for(var e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)this.set(e,r,t);return this}neg(){return this.mulS(-1)}getRow(t){checkRowIndex$2(this,t);for(var e=new Array(this.columns),r=0;r<this.columns;r++)e[r]=this.get(t,r);return e}getRowVector(t){return this.constructor.rowVector(this.getRow(t))}setRow(t,e){checkRowIndex$2(this,t),e=checkRowVector$2(this,e);for(var r=0;r<this.columns;r++)this.set(t,r,e[r]);return this}swapRows(t,e){checkRowIndex$2(this,t),checkRowIndex$2(this,e);for(var r=0;r<this.columns;r++){var n=this.get(t,r);this.set(t,r,this.get(e,r)),this.set(e,r,n)}return this}getColumn(t){checkColumnIndex$2(this,t);for(var e=new Array(this.rows),r=0;r<this.rows;r++)e[r]=this.get(r,t);return e}getColumnVector(t){return this.constructor.columnVector(this.getColumn(t))}setColumn(t,e){checkColumnIndex$2(this,t),e=checkColumnVector$2(this,e);for(var r=0;r<this.rows;r++)this.set(r,t,e[r]);return this}swapColumns(t,e){checkColumnIndex$2(this,t),checkColumnIndex$2(this,e);for(var r=0;r<this.rows;r++){var n=this.get(r,t);this.set(r,t,this.get(r,e)),this.set(r,e,n)}return this}addRowVector(t){t=checkRowVector$2(this,t);for(var e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t[r]);return this}subRowVector(t){t=checkRowVector$2(this,t);for(var e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t[r]);return this}mulRowVector(t){t=checkRowVector$2(this,t);for(var e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t[r]);return this}divRowVector(t){t=checkRowVector$2(this,t);for(var e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t[r]);return this}addColumnVector(t){t=checkColumnVector$2(this,t);for(var e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t[e]);return this}subColumnVector(t){t=checkColumnVector$2(this,t);for(var e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t[e]);return this}mulColumnVector(t){t=checkColumnVector$2(this,t);for(var e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t[e]);return this}divColumnVector(t){t=checkColumnVector$2(this,t);for(var e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t[e]);return this}mulRow(t,e){checkRowIndex$2(this,t);for(var r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)*e);return this}mulColumn(t,e){checkColumnIndex$2(this,t);for(var r=0;r<this.rows;r++)this.set(r,t,this.get(r,t)*e);return this}max(){for(var t=this.get(0,0),e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)this.get(e,r)>t&&(t=this.get(e,r));return t}maxIndex(){for(var t=this.get(0,0),e=[0,0],r=0;r<this.rows;r++)for(var n=0;n<this.columns;n++)this.get(r,n)>t&&(t=this.get(r,n),e[0]=r,e[1]=n);return e}min(){for(var t=this.get(0,0),e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)this.get(e,r)<t&&(t=this.get(e,r));return t}minIndex(){for(var t=this.get(0,0),e=[0,0],r=0;r<this.rows;r++)for(var n=0;n<this.columns;n++)this.get(r,n)<t&&(t=this.get(r,n),e[0]=r,e[1]=n);return e}maxRow(t){checkRowIndex$2(this,t);for(var e=this.get(t,0),r=1;r<this.columns;r++)this.get(t,r)>e&&(e=this.get(t,r));return e}maxRowIndex(t){checkRowIndex$2(this,t);for(var e=this.get(t,0),r=[t,0],n=1;n<this.columns;n++)this.get(t,n)>e&&(e=this.get(t,n),r[1]=n);return r}minRow(t){checkRowIndex$2(this,t);for(var e=this.get(t,0),r=1;r<this.columns;r++)this.get(t,r)<e&&(e=this.get(t,r));return e}minRowIndex(t){checkRowIndex$2(this,t);for(var e=this.get(t,0),r=[t,0],n=1;n<this.columns;n++)this.get(t,n)<e&&(e=this.get(t,n),r[1]=n);return r}maxColumn(t){checkColumnIndex$2(this,t);for(var e=this.get(0,t),r=1;r<this.rows;r++)this.get(r,t)>e&&(e=this.get(r,t));return e}maxColumnIndex(t){checkColumnIndex$2(this,t);for(var e=this.get(0,t),r=[0,t],n=1;n<this.rows;n++)this.get(n,t)>e&&(e=this.get(n,t),r[0]=n);return r}minColumn(t){checkColumnIndex$2(this,t);for(var e=this.get(0,t),r=1;r<this.rows;r++)this.get(r,t)<e&&(e=this.get(r,t));return e}minColumnIndex(t){checkColumnIndex$2(this,t);for(var e=this.get(0,t),r=[0,t],n=1;n<this.rows;n++)this.get(n,t)<e&&(e=this.get(n,t),r[0]=n);return r}diag(){for(var t=Math.min(this.rows,this.columns),e=new Array(t),r=0;r<t;r++)e[r]=this.get(r,r);return e}sum(t){switch(t){case"row":return sumByRow$2(this);case"column":return sumByColumn$2(this);default:return sumAll$2(this)}}mean(){return this.sum()/this.size}prod(){for(var t=1,e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)t*=this.get(e,r);return t}norm(t="frobenius"){var e=0;if("max"===t)return this.max();if("frobenius"===t){for(var r=0;r<this.rows;r++)for(var n=0;n<this.columns;n++)e+=this.get(r,n)*this.get(r,n);return Math.sqrt(e)}throw new RangeError(`unknown norm type: ${t}`)}cumulativeSum(){for(var t=0,e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)t+=this.get(e,r),this.set(e,r,t);return this}dot(t){e.isMatrix(t)&&(t=t.to1DArray());var r=this.to1DArray();if(r.length!==t.length)throw new RangeError("vectors do not have the same size");for(var n=0,i=0;i<r.length;i++)n+=r[i]*t[i];return n}mmul(t){t=this.constructor.checkMatrix(t),this.columns!==t.rows&&console.warn("Number of columns of left matrix are not equal to number of rows of right matrix.");for(var e=this.rows,r=this.columns,n=t.columns,i=new this.constructor[Symbol.species](e,n),o=new Array(r),s=0;s<n;s++){for(var a=0;a<r;a++)o[a]=t.get(a,s);for(var u=0;u<e;u++){var h=0;for(a=0;a<r;a++)h+=this.get(u,a)*o[a];i.set(u,s,h)}}return i}strassen2x2(t){var e=new this.constructor[Symbol.species](2,2);const r=this.get(0,0),n=t.get(0,0),i=this.get(0,1),o=t.get(0,1),s=this.get(1,0),a=t.get(1,0),u=this.get(1,1),h=t.get(1,1),c=(r+u)*(n+h),l=(s+u)*n,f=r*(o-h),m=u*(a-n),p=(r+i)*h,d=c+m-p+(i-u)*(a+h),g=f+p,v=l+m,w=c-l+f+(s-r)*(n+o);return e.set(0,0,d),e.set(0,1,g),e.set(1,0,v),e.set(1,1,w),e}strassen3x3(t){var e=new this.constructor[Symbol.species](3,3);const r=this.get(0,0),n=this.get(0,1),i=this.get(0,2),o=this.get(1,0),s=this.get(1,1),a=this.get(1,2),u=this.get(2,0),h=this.get(2,1),c=this.get(2,2),l=t.get(0,0),f=t.get(0,1),m=t.get(0,2),p=t.get(1,0),d=t.get(1,1),g=t.get(1,2),v=t.get(2,0),w=t.get(2,1),y=t.get(2,2),b=(r-o)*(-f+d),x=(-r+o+s)*(l-f+d),M=(o+s)*(-l+f),_=r*l,$=(-r+u+h)*(l-m+g),S=(-r+u)*(m-g),R=(u+h)*(-l+m),E=(-i+h+c)*(d+v-w),C=(i-c)*(d-w),k=i*v,A=(h+c)*(-v+w),T=(-i+s+a)*(g+v-y),O=(i-a)*(g-y),I=(s+a)*(-v+y),D=_+k+n*p,P=(r+n+i-o-s-h-c)*d+x+M+_+E+k+A,V=_+$+R+(r+n+i-s-a-u-h)*g+k+T+I,j=b+s*(-l+f+p-d-g-v+y)+x+_+k+T+O,L=b+x+M+_+a*w,N=k+T+O+I+o*m,B=_+$+S+h*(-l+m+p-d-g-v+w)+E+C+k,F=E+C+k+A+u*f,z=_+$+S+R+c*y;return e.set(0,0,D),e.set(0,1,P),e.set(0,2,V),e.set(1,0,j),e.set(1,1,L),e.set(1,2,N),e.set(2,0,B),e.set(2,1,F),e.set(2,2,z),e}mmulStrassen(t){var r=this.clone(),n=r.rows,i=r.columns,o=t.rows,s=t.columns;function a(t,r,n){var i=t.rows,o=t.columns;if(i===r&&o===n)return t;var s=e.zeros(r,n);return s=s.setSubMatrix(t,0,0)}i!==o&&console.warn(`Multiplying ${n} x ${i} and ${o} x ${s} matrix: dimensions do not match.`);var u=Math.max(n,o),h=Math.max(i,s);return function t(r,n,i,o){if(i<=512||o<=512)return r.mmul(n);i%2==1&&o%2==1?(r=a(r,i+1,o+1),n=a(n,i+1,o+1)):i%2==1?(r=a(r,i+1,o),n=a(n,i+1,o)):o%2==1&&(r=a(r,i,o+1),n=a(n,i,o+1));var s=parseInt(r.rows/2),u=parseInt(r.columns/2),h=r.subMatrix(0,s-1,0,u-1),c=n.subMatrix(0,s-1,0,u-1),l=r.subMatrix(0,s-1,u,r.columns-1),f=n.subMatrix(0,s-1,u,n.columns-1),m=r.subMatrix(s,r.rows-1,0,u-1),p=n.subMatrix(s,n.rows-1,0,u-1),d=r.subMatrix(s,r.rows-1,u,r.columns-1),g=n.subMatrix(s,n.rows-1,u,n.columns-1),v=t(e.add(h,d),e.add(c,g),s,u),w=t(e.add(m,d),c,s,u),y=t(h,e.sub(f,g),s,u),b=t(d,e.sub(p,c),s,u),x=t(e.add(h,l),g,s,u),M=t(e.sub(m,h),e.add(c,f),s,u),_=t(e.sub(l,d),e.add(p,g),s,u),$=e.add(v,b);$.sub(x),$.add(_);var S=e.add(y,x),R=e.add(w,b),E=e.sub(v,w);E.add(y),E.add(M);var C=e.zeros(2*$.rows,2*$.columns);return(C=(C=(C=(C=C.setSubMatrix($,0,0)).setSubMatrix(S,$.rows,0)).setSubMatrix(R,0,$.columns)).setSubMatrix(E,$.rows,$.columns)).subMatrix(0,i-1,0,o-1)}(r=a(r,u,h),t=a(t,u,h),u,h)}scaleRows(t,e){if((t=void 0===t?0:t)>=(e=void 0===e?1:e))throw new RangeError("min should be strictly smaller than max");for(var r=this.constructor.empty(this.rows,this.columns),n=0;n<this.rows;n++){var i=rescale(this.getRow(n),{min:t,max:e});r.setRow(n,i)}return r}scaleColumns(t,e){if((t=void 0===t?0:t)>=(e=void 0===e?1:e))throw new RangeError("min should be strictly smaller than max");for(var r=this.constructor.empty(this.rows,this.columns),n=0;n<this.columns;n++){var i=rescale(this.getColumn(n),{min:t,max:e});r.setColumn(n,i)}return r}kroneckerProduct(t){t=this.constructor.checkMatrix(t);for(var e=this.rows,r=this.columns,n=t.rows,i=t.columns,o=new this.constructor[Symbol.species](e*n,r*i),s=0;s<e;s++)for(var a=0;a<r;a++)for(var u=0;u<n;u++)for(var h=0;h<i;h++)o[n*s+u][i*a+h]=this.get(s,a)*t.get(u,h);return o}transpose(){for(var t=new this.constructor[Symbol.species](this.columns,this.rows),e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)t.set(r,e,this.get(e,r));return t}sortRows(t){void 0===t&&(t=r);for(var e=0;e<this.rows;e++)this.setRow(e,this.getRow(e).sort(t));return this}sortColumns(t){void 0===t&&(t=r);for(var e=0;e<this.columns;e++)this.setColumn(e,this.getColumn(e).sort(t));return this}subMatrix(t,e,r,n){checkRange$2(this,t,e,r,n);for(var i=new this.constructor[Symbol.species](e-t+1,n-r+1),o=t;o<=e;o++)for(var s=r;s<=n;s++)i[o-t][s-r]=this.get(o,s);return i}subMatrixRow(t,e,r){if(void 0===e&&(e=0),void 0===r&&(r=this.columns-1),e>r||e<0||e>=this.columns||r<0||r>=this.columns)throw new RangeError("Argument out of range");for(var n=new this.constructor[Symbol.species](t.length,r-e+1),i=0;i<t.length;i++)for(var o=e;o<=r;o++){if(t[i]<0||t[i]>=this.rows)throw new RangeError("Row index out of range: "+t[i]);n.set(i,o-e,this.get(t[i],o))}return n}subMatrixColumn(t,e,r){if(void 0===e&&(e=0),void 0===r&&(r=this.rows-1),e>r||e<0||e>=this.rows||r<0||r>=this.rows)throw new RangeError("Argument out of range");for(var n=new this.constructor[Symbol.species](r-e+1,t.length),i=0;i<t.length;i++)for(var o=e;o<=r;o++){if(t[i]<0||t[i]>=this.columns)throw new RangeError("Column index out of range: "+t[i]);n.set(o-e,i,this.get(o,t[i]))}return n}setSubMatrix(t,e,r){checkRange$2(this,e,e+(t=this.constructor.checkMatrix(t)).rows-1,r,r+t.columns-1);for(var n=0;n<t.rows;n++)for(var i=0;i<t.columns;i++)this[e+n][r+i]=t.get(n,i);return this}selection(t,e){for(var r=checkIndices$2(this,t,e),n=new this.constructor[Symbol.species](t.length,e.length),i=0;i<r.row.length;i++)for(var o=r.row[i],s=0;s<r.column.length;s++){var a=r.column[s];n[i][s]=this.get(o,a)}return n}trace(){for(var t=Math.min(this.rows,this.columns),e=0,r=0;r<t;r++)e+=this.get(r,r);return e}transposeView(){return new MatrixTransposeView$2(this)}rowView(t){return checkRowIndex$2(this,t),new MatrixRowView$2(this,t)}columnView(t){return checkColumnIndex$2(this,t),new MatrixColumnView$2(this,t)}flipRowView(){return new MatrixFlipRowView$2(this)}flipColumnView(){return new MatrixFlipColumnView$2(this)}subMatrixView(t,e,r,n){return new MatrixSubView$2(this,t,e,r,n)}selectionView(t,e){return new MatrixSelectionView$2(this,t,e)}rowSelectionView(t){return new MatrixRowSelectionView$2(this,t)}columnSelectionView(t){return new MatrixColumnSelectionView$2(this,t)}det(){var t,e,r,n,i,o;if(this.isSquare())return 2===this.columns?(t=this.get(0,0),e=this.get(0,1),r=this.get(1,0),t*this.get(1,1)-e*r):3===this.columns?(n=this.selectionView([1,2],[1,2]),i=this.selectionView([1,2],[0,2]),o=this.selectionView([1,2],[0,1]),t=this.get(0,0),e=this.get(0,1),r=this.get(0,2),t*n.det()-e*i.det()+r*o.det()):new LuDecomposition$$1(this).determinant;throw Error("Determinant can only be calculated for a square matrix.")}pseudoInverse(t){void 0===t&&(t=Number.EPSILON);for(var e=new SingularValueDecomposition$$1(this,{autoTranspose:!0}),r=e.leftSingularVectors,n=e.rightSingularVectors,i=e.diagonal,o=0;o<i.length;o++)Math.abs(i[o])>t?i[o]=1/i[o]:i[o]=0;return i=this.constructor[Symbol.species].diag(i),n.mmul(i.mmul(r.transposeView()))}clone(){for(var t=new this.constructor[Symbol.species](this.rows,this.columns),e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)t.set(e,r,this.get(e,r));return t}}function r(t,e){return t-e}e.prototype.klass="Matrix",e.random=e.rand,e.diagonal=e.diag,e.prototype.diagonal=e.prototype.diag,e.identity=e.eye,e.prototype.negate=e.prototype.neg,e.prototype.tensorProduct=e.prototype.kroneckerProduct,e.prototype.determinant=e.prototype.det;var n,i="\n(function %name%(matrix, %args%) {\n    var newMatrix = new this[Symbol.species](matrix);\n    return newMatrix.%name%(%args%);\n})\n",o=i,s=eval;for(var a of[["+","add"],["-","sub","subtract"],["*","mul","multiply"],["/","div","divide"],["%","mod","modulus"],["&","and"],["|","or"],["^","xor"],["<<","leftShift"],[">>","signPropagatingRightShift"],[">>>","rightShift","zeroFillRightShift"]]){var u=s(S("\n(function %name%(value) {\n    if (typeof value === 'number') return this.%name%S(value);\n    return this.%name%M(value);\n})\n",{name:a[1],op:a[0]})),h=s(S("\n(function %name%S(value) {\n    for (var i = 0; i < this.rows; i++) {\n        for (var j = 0; j < this.columns; j++) {\n            this.set(i, j, this.get(i, j) %op% value);\n        }\n    }\n    return this;\n})\n",{name:a[1]+"S",op:a[0]})),c=s(S("\n(function %name%M(matrix) {\n    matrix = this.constructor.checkMatrix(matrix);\n    if (this.rows !== matrix.rows ||\n        this.columns !== matrix.columns) {\n        throw new RangeError('Matrices dimensions must be equal');\n    }\n    for (var i = 0; i < this.rows; i++) {\n        for (var j = 0; j < this.columns; j++) {\n            this.set(i, j, this.get(i, j) %op% matrix.get(i, j));\n        }\n    }\n    return this;\n})\n",{name:a[1]+"M",op:a[0]})),l=s(S("\n(function %name%(matrix, value) {\n    var newMatrix = new this[Symbol.species](matrix);\n    return newMatrix.%name%(value);\n})\n",{name:a[1]}));for(n=1;n<a.length;n++)e.prototype[a[n]]=u,e.prototype[a[n]+"S"]=h,e.prototype[a[n]+"M"]=c,e[a[n]]=l}var f=[["~","not"]];for(var m of(["abs","acos","acosh","asin","asinh","atan","atanh","cbrt","ceil","clz32","cos","cosh","exp","expm1","floor","fround","log","log1p","log10","log2","round","sign","sin","sinh","sqrt","tan","tanh","trunc"].forEach((function(t){f.push(["Math."+t,t])})),f)){var p=s(S("\n(function %name%() {\n    for (var i = 0; i < this.rows; i++) {\n        for (var j = 0; j < this.columns; j++) {\n            this.set(i, j, %method%(this.get(i, j)));\n        }\n    }\n    return this;\n})\n",{name:m[1],method:m[0]})),d=s(S("\n(function %name%(matrix) {\n    var newMatrix = new this[Symbol.species](matrix);\n    return newMatrix.%name%();\n})\n",{name:m[1]}));for(n=1;n<m.length;n++)e.prototype[m[n]]=p,e[m[n]]=d}for(var g of[["Math.pow",1,"pow"]]){var v="arg0";for(n=1;n<g[1];n++)v+=`, arg${n}`;if(1!==g[1]){var w=s(S("\n(function %name%(%args%) {\n    for (var i = 0; i < this.rows; i++) {\n        for (var j = 0; j < this.columns; j++) {\n            this.set(i, j, %method%(this.get(i, j), %args%));\n        }\n    }\n    return this;\n})\n",{name:g[2],method:g[0],args:v})),y=s(S(i,{name:g[2],args:v}));for(n=2;n<g.length;n++)e.prototype[g[n]]=w,e[g[n]]=y}else{var b={name:g[2],args:v,method:g[0]},x=s(S("\n(function %name%(value) {\n    if (typeof value === 'number') return this.%name%S(value);\n    return this.%name%M(value);\n})\n",b)),M=s(S("\n(function %name%S(value) {\n    for (var i = 0; i < this.rows; i++) {\n        for (var j = 0; j < this.columns; j++) {\n            this.set(i, j, %method%(this.get(i, j), value));\n        }\n    }\n    return this;\n})\n",b)),_=s(S("\n(function %name%M(matrix) {\n    matrix = this.constructor.checkMatrix(matrix);\n    if (this.rows !== matrix.rows ||\n        this.columns !== matrix.columns) {\n        throw new RangeError('Matrices dimensions must be equal');\n    }\n    for (var i = 0; i < this.rows; i++) {\n        for (var j = 0; j < this.columns; j++) {\n            this.set(i, j, %method%(this.get(i, j), matrix.get(i, j)));\n        }\n    }\n    return this;\n})\n",b)),$=s(S(o,b));for(n=2;n<g.length;n++)e.prototype[g[n]]=x,e.prototype[g[n]+"M"]=_,e.prototype[g[n]+"S"]=M,e[g[n]]=$}}function S(t,e){for(var r in e)t=t.replace(new RegExp("%"+r+"%","g"),e[r]);return t}return e}class Matrix$2 extends(AbstractMatrix$2(Array)){constructor(t,e){var r;if(1===arguments.length&&"number"==typeof t)return new Array(t);if(Matrix$2.isMatrix(t))return t.clone();if(Number.isInteger(t)&&t>0){if(super(t),!(Number.isInteger(e)&&e>0))throw new TypeError("nColumns must be a positive integer");for(r=0;r<t;r++)this[r]=new Array(e)}else{if(!Array.isArray(t))throw new TypeError("First argument must be a positive number or an array");{const n=t;if(t=n.length,"number"!=typeof(e=n[0].length)||0===e)throw new TypeError("Data must be a 2D array with at least one element");for(super(t),r=0;r<t;r++){if(n[r].length!==e)throw new RangeError("Inconsistent array dimensions");this[r]=[].concat(n[r])}}}return this.rows=t,this.columns=e,this}set(t,e,r){return this[t][e]=r,this}get(t,e){return this[t][e]}removeRow(t){if(checkRowIndex$2(this,t),1===this.rows)throw new RangeError("A matrix cannot have less than one row");return this.splice(t,1),this.rows-=1,this}addRow(t,e){return void 0===e&&(e=t,t=this.rows),checkRowIndex$2(this,t,!0),e=checkRowVector$2(this,e,!0),this.splice(t,0,e),this.rows+=1,this}removeColumn(t){if(checkColumnIndex$2(this,t),1===this.columns)throw new RangeError("A matrix cannot have less than one column");for(var e=0;e<this.rows;e++)this[e].splice(t,1);return this.columns-=1,this}addColumn(t,e){void 0===e&&(e=t,t=this.columns),checkColumnIndex$2(this,t,!0),e=checkColumnVector$2(this,e);for(var r=0;r<this.rows;r++)this[r].splice(t,0,e[r]);return this.columns+=1,this}}class WrapperMatrix1D$2 extends(AbstractMatrix$2()){constructor(t,e={}){const{rows:r=1}=e;if(t.length%r!=0)throw new Error("the data length is not divisible by the number of rows");super(),this.rows=r,this.columns=t.length/r,this.data=t}set(t,e,r){var n=this._calculateIndex(t,e);return this.data[n]=r,this}get(t,e){var r=this._calculateIndex(t,e);return this.data[r]}_calculateIndex(t,e){return t*this.columns+e}static get[Symbol.species](){return Matrix$2}}class WrapperMatrix2D$2 extends(AbstractMatrix$2()){constructor(t){super(),this.data=t,this.rows=t.length,this.columns=t[0].length}set(t,e,r){return this.data[t][e]=r,this}get(t,e){return this.data[t][e]}static get[Symbol.species](){return Matrix$2}}function wrap$2(t,e){if(Array.isArray(t))return t[0]&&Array.isArray(t[0])?new WrapperMatrix2D$2(t):new WrapperMatrix1D$2(t,e);throw new Error("the argument is not an array")}class QrDecomposition$$1{constructor(t){var e,r,n,i,o=(t=WrapperMatrix2D$2.checkMatrix(t)).clone(),s=t.rows,a=t.columns,u=new Array(a);for(n=0;n<a;n++){var h=0;for(e=n;e<s;e++)h=hypotenuse$2(h,o.get(e,n));if(0!==h){for(o.get(n,n)<0&&(h=-h),e=n;e<s;e++)o.set(e,n,o.get(e,n)/h);for(o.set(n,n,o.get(n,n)+1),r=n+1;r<a;r++){for(i=0,e=n;e<s;e++)i+=o.get(e,n)*o.get(e,r);for(i=-i/o.get(n,n),e=n;e<s;e++)o.set(e,r,o.get(e,r)+i*o.get(e,n))}}u[n]=-h}this.QR=o,this.Rdiag=u}solve(t){t=Matrix$2.checkMatrix(t);var e=this.QR,r=e.rows;if(t.rows!==r)throw new Error("Matrix row dimensions must agree");if(!this.isFullRank())throw new Error("Matrix is rank deficient");var n,i,o,s,a=t.columns,u=t.clone(),h=e.columns;for(o=0;o<h;o++)for(i=0;i<a;i++){for(s=0,n=o;n<r;n++)s+=e[n][o]*u[n][i];for(s=-s/e[o][o],n=o;n<r;n++)u[n][i]+=s*e[n][o]}for(o=h-1;o>=0;o--){for(i=0;i<a;i++)u[o][i]/=this.Rdiag[o];for(n=0;n<o;n++)for(i=0;i<a;i++)u[n][i]-=u[o][i]*e[n][o]}return u.subMatrix(0,h-1,0,a-1)}isFullRank(){for(var t=this.QR.columns,e=0;e<t;e++)if(0===this.Rdiag[e])return!1;return!0}get upperTriangularMatrix(){var t,e,r=this.QR,n=r.columns,i=new Matrix$2(n,n);for(t=0;t<n;t++)for(e=0;e<n;e++)i[t][e]=t<e?r[t][e]:t===e?this.Rdiag[t]:0;return i}get orthogonalMatrix(){var t,e,r,n,i=this.QR,o=i.rows,s=i.columns,a=new Matrix$2(o,s);for(r=s-1;r>=0;r--){for(t=0;t<o;t++)a[t][r]=0;for(a[r][r]=1,e=r;e<s;e++)if(0!==i[r][r]){for(n=0,t=r;t<o;t++)n+=i[t][r]*a[t][e];for(n=-n/i[r][r],t=r;t<o;t++)a[t][e]+=n*i[t][r]}}return a}}function inverse$$1(t,e=!1){return t=WrapperMatrix2D$2.checkMatrix(t),e?new SingularValueDecomposition$$1(t).inverse():solve$$1(t,Matrix$2.eye(t.rows))}function solve$$1(t,e,r=!1){return t=WrapperMatrix2D$2.checkMatrix(t),e=WrapperMatrix2D$2.checkMatrix(e),r?new SingularValueDecomposition$$1(t).solve(e):t.isSquare()?new LuDecomposition$$1(t).solve(e):new QrDecomposition$$1(t).solve(e)}class EigenvalueDecomposition$$1{constructor(t,e={}){const{assumeSymmetric:r=!1}=e;if(!(t=WrapperMatrix2D$2.checkMatrix(t)).isSquare())throw new Error("Matrix is not a square matrix");var n,i,o=t.columns,s=getFilled2DArray$2(o,o,0),a=new Array(o),u=new Array(o),h=t;if(!!r||t.isSymmetric()){for(n=0;n<o;n++)for(i=0;i<o;i++)s[n][i]=h.get(n,i);tred2$2(o,u,a,s),tql2$2(o,u,a,s)}else{var c=getFilled2DArray$2(o,o,0),l=new Array(o);for(i=0;i<o;i++)for(n=0;n<o;n++)c[n][i]=h.get(n,i);orthes$2(o,c,l,s),hqr2$2(o,u,a,s,c)}this.n=o,this.e=u,this.d=a,this.V=s}get realEigenvalues(){return this.d}get imaginaryEigenvalues(){return this.e}get eigenvectorMatrix(){return Matrix$2.isMatrix(this.V)||(this.V=new Matrix$2(this.V)),this.V}get diagonalMatrix(){var t,e,r=this.n,n=this.e,i=this.d,o=new Matrix$2(r,r);for(t=0;t<r;t++){for(e=0;e<r;e++)o[t][e]=0;o[t][t]=i[t],n[t]>0?o[t][t+1]=n[t]:n[t]<0&&(o[t][t-1]=n[t])}return o}}function tred2$2(t,e,r,n){var i,o,s,a,u,h,c,l;for(u=0;u<t;u++)r[u]=n[t-1][u];for(a=t-1;a>0;a--){for(l=0,s=0,h=0;h<a;h++)l+=Math.abs(r[h]);if(0===l)for(e[a]=r[a-1],u=0;u<a;u++)r[u]=n[a-1][u],n[a][u]=0,n[u][a]=0;else{for(h=0;h<a;h++)r[h]/=l,s+=r[h]*r[h];for(i=r[a-1],o=Math.sqrt(s),i>0&&(o=-o),e[a]=l*o,s-=i*o,r[a-1]=i-o,u=0;u<a;u++)e[u]=0;for(u=0;u<a;u++){for(i=r[u],n[u][a]=i,o=e[u]+n[u][u]*i,h=u+1;h<=a-1;h++)o+=n[h][u]*r[h],e[h]+=n[h][u]*i;e[u]=o}for(i=0,u=0;u<a;u++)e[u]/=s,i+=e[u]*r[u];for(c=i/(s+s),u=0;u<a;u++)e[u]-=c*r[u];for(u=0;u<a;u++){for(i=r[u],o=e[u],h=u;h<=a-1;h++)n[h][u]-=i*e[h]+o*r[h];r[u]=n[a-1][u],n[a][u]=0}}r[a]=s}for(a=0;a<t-1;a++){if(n[t-1][a]=n[a][a],n[a][a]=1,0!==(s=r[a+1])){for(h=0;h<=a;h++)r[h]=n[h][a+1]/s;for(u=0;u<=a;u++){for(o=0,h=0;h<=a;h++)o+=n[h][a+1]*n[h][u];for(h=0;h<=a;h++)n[h][u]-=o*r[h]}}for(h=0;h<=a;h++)n[h][a+1]=0}for(u=0;u<t;u++)r[u]=n[t-1][u],n[t-1][u]=0;n[t-1][t-1]=1,e[0]=0}function tql2$2(t,e,r,n){var i,o,s,a,u,h,c,l,f,m,p,d,g,v,w,y;for(s=1;s<t;s++)e[s-1]=e[s];e[t-1]=0;var b=0,x=0,M=Number.EPSILON;for(h=0;h<t;h++){for(x=Math.max(x,Math.abs(r[h])+Math.abs(e[h])),c=h;c<t&&!(Math.abs(e[c])<=M*x);)c++;if(c>h)do{for(i=r[h],f=hypotenuse$2(l=(r[h+1]-i)/(2*e[h]),1),l<0&&(f=-f),r[h]=e[h]/(l+f),r[h+1]=e[h]*(l+f),m=r[h+1],o=i-r[h],s=h+2;s<t;s++)r[s]-=o;for(b+=o,l=r[c],d=p=1,g=p,v=e[h+1],w=0,y=0,s=c-1;s>=h;s--)for(g=d,d=p,y=w,i=p*e[s],o=p*l,f=hypotenuse$2(l,e[s]),e[s+1]=w*f,w=e[s]/f,l=(p=l/f)*r[s]-w*i,r[s+1]=o+w*(p*i+w*r[s]),u=0;u<t;u++)o=n[u][s+1],n[u][s+1]=w*n[u][s]+p*o,n[u][s]=p*n[u][s]-w*o;l=-w*y*g*v*e[h]/m,e[h]=w*l,r[h]=p*l}while(Math.abs(e[h])>M*x);r[h]=r[h]+b,e[h]=0}for(s=0;s<t-1;s++){for(u=s,l=r[s],a=s+1;a<t;a++)r[a]<l&&(u=a,l=r[a]);if(u!==s)for(r[u]=r[s],r[s]=l,a=0;a<t;a++)l=n[a][s],n[a][s]=n[a][u],n[a][u]=l}}function orthes$2(t,e,r,n){var i,o,s,a,u,h,c,l=t-1;for(h=1;h<=l-1;h++){for(c=0,a=h;a<=l;a++)c+=Math.abs(e[a][h-1]);if(0!==c){for(s=0,a=l;a>=h;a--)r[a]=e[a][h-1]/c,s+=r[a]*r[a];for(o=Math.sqrt(s),r[h]>0&&(o=-o),s-=r[h]*o,r[h]=r[h]-o,u=h;u<t;u++){for(i=0,a=l;a>=h;a--)i+=r[a]*e[a][u];for(i/=s,a=h;a<=l;a++)e[a][u]-=i*r[a]}for(a=0;a<=l;a++){for(i=0,u=l;u>=h;u--)i+=r[u]*e[a][u];for(i/=s,u=h;u<=l;u++)e[a][u]-=i*r[u]}r[h]=c*r[h],e[h][h-1]=c*o}}for(a=0;a<t;a++)for(u=0;u<t;u++)n[a][u]=a===u?1:0;for(h=l-1;h>=1;h--)if(0!==e[h][h-1]){for(a=h+1;a<=l;a++)r[a]=e[a][h-1];for(u=h;u<=l;u++){for(o=0,a=h;a<=l;a++)o+=r[a]*n[a][u];for(o=o/r[h]/e[h][h-1],a=h;a<=l;a++)n[a][u]+=o*r[a]}}}function hqr2$2(t,e,r,n,i){var o,s,a,u,h,c,l,f,m,p,d,g,v,w,y,b=t-1,x=t-1,M=Number.EPSILON,_=0,$=0,S=0,R=0,E=0,C=0,k=0,A=0;for(o=0;o<t;o++)for((o<0||o>x)&&(r[o]=i[o][o],e[o]=0),s=Math.max(o-1,0);s<t;s++)$+=Math.abs(i[o][s]);for(;b>=0;){for(u=b;u>0&&(0===(C=Math.abs(i[u-1][u-1])+Math.abs(i[u][u]))&&(C=$),!(Math.abs(i[u][u-1])<M*C));)u--;if(u===b)i[b][b]=i[b][b]+_,r[b]=i[b][b],e[b]=0,b--,A=0;else if(u===b-1){if(l=i[b][b-1]*i[b-1][b],R=(S=(i[b-1][b-1]-i[b][b])/2)*S+l,k=Math.sqrt(Math.abs(R)),i[b][b]=i[b][b]+_,i[b-1][b-1]=i[b-1][b-1]+_,f=i[b][b],R>=0){for(k=S>=0?S+k:S-k,r[b-1]=f+k,r[b]=r[b-1],0!==k&&(r[b]=f-l/k),e[b-1]=0,e[b]=0,S=(f=i[b][b-1])/(C=Math.abs(f)+Math.abs(k)),R=k/C,S/=E=Math.sqrt(S*S+R*R),R/=E,s=b-1;s<t;s++)k=i[b-1][s],i[b-1][s]=R*k+S*i[b][s],i[b][s]=R*i[b][s]-S*k;for(o=0;o<=b;o++)k=i[o][b-1],i[o][b-1]=R*k+S*i[o][b],i[o][b]=R*i[o][b]-S*k;for(o=0;o<=x;o++)k=n[o][b-1],n[o][b-1]=R*k+S*n[o][b],n[o][b]=R*n[o][b]-S*k}else r[b-1]=f+S,r[b]=f+S,e[b-1]=k,e[b]=-k;b-=2,A=0}else{if(f=i[b][b],m=0,l=0,u<b&&(m=i[b-1][b-1],l=i[b][b-1]*i[b-1][b]),10===A){for(_+=f,o=0;o<=b;o++)i[o][o]-=f;f=m=.75*(C=Math.abs(i[b][b-1])+Math.abs(i[b-1][b-2])),l=-.4375*C*C}if(30===A&&(C=(C=(m-f)/2)*C+l)>0){for(C=Math.sqrt(C),m<f&&(C=-C),C=f-l/((m-f)/2+C),o=0;o<=b;o++)i[o][o]-=C;_+=C,f=m=l=.964}for(A+=1,h=b-2;h>=u&&(S=((E=f-(k=i[h][h]))*(C=m-k)-l)/i[h+1][h]+i[h][h+1],R=i[h+1][h+1]-k-E-C,E=i[h+2][h+1],S/=C=Math.abs(S)+Math.abs(R)+Math.abs(E),R/=C,E/=C,h!==u)&&!(Math.abs(i[h][h-1])*(Math.abs(R)+Math.abs(E))<M*(Math.abs(S)*(Math.abs(i[h-1][h-1])+Math.abs(k)+Math.abs(i[h+1][h+1]))));)h--;for(o=h+2;o<=b;o++)i[o][o-2]=0,o>h+2&&(i[o][o-3]=0);for(a=h;a<=b-1&&(w=a!==b-1,a!==h&&(S=i[a][a-1],R=i[a+1][a-1],E=w?i[a+2][a-1]:0,0!==(f=Math.abs(S)+Math.abs(R)+Math.abs(E))&&(S/=f,R/=f,E/=f)),0!==f);a++)if(C=Math.sqrt(S*S+R*R+E*E),S<0&&(C=-C),0!==C){for(a!==h?i[a][a-1]=-C*f:u!==h&&(i[a][a-1]=-i[a][a-1]),f=(S+=C)/C,m=R/C,k=E/C,R/=S,E/=S,s=a;s<t;s++)S=i[a][s]+R*i[a+1][s],w&&(S+=E*i[a+2][s],i[a+2][s]=i[a+2][s]-S*k),i[a][s]=i[a][s]-S*f,i[a+1][s]=i[a+1][s]-S*m;for(o=0;o<=Math.min(b,a+3);o++)S=f*i[o][a]+m*i[o][a+1],w&&(S+=k*i[o][a+2],i[o][a+2]=i[o][a+2]-S*E),i[o][a]=i[o][a]-S,i[o][a+1]=i[o][a+1]-S*R;for(o=0;o<=x;o++)S=f*n[o][a]+m*n[o][a+1],w&&(S+=k*n[o][a+2],n[o][a+2]=n[o][a+2]-S*E),n[o][a]=n[o][a]-S,n[o][a+1]=n[o][a+1]-S*R}}}if(0!==$){for(b=t-1;b>=0;b--)if(S=r[b],0===(R=e[b]))for(u=b,i[b][b]=1,o=b-1;o>=0;o--){for(l=i[o][o]-S,E=0,s=u;s<=b;s++)E+=i[o][s]*i[s][b];if(e[o]<0)k=l,C=E;else if(u=o,0===e[o]?i[o][b]=0!==l?-E/l:-E/(M*$):(f=i[o][o+1],m=i[o+1][o],c=(f*C-k*E)/(R=(r[o]-S)*(r[o]-S)+e[o]*e[o]),i[o][b]=c,i[o+1][b]=Math.abs(f)>Math.abs(k)?(-E-l*c)/f:(-C-m*c)/k),M*(c=Math.abs(i[o][b]))*c>1)for(s=o;s<=b;s++)i[s][b]=i[s][b]/c}else if(R<0)for(u=b-1,Math.abs(i[b][b-1])>Math.abs(i[b-1][b])?(i[b-1][b-1]=R/i[b][b-1],i[b-1][b]=-(i[b][b]-S)/i[b][b-1]):(y=cdiv$2(0,-i[b-1][b],i[b-1][b-1]-S,R),i[b-1][b-1]=y[0],i[b-1][b]=y[1]),i[b][b-1]=0,i[b][b]=1,o=b-2;o>=0;o--){for(p=0,d=0,s=u;s<=b;s++)p+=i[o][s]*i[s][b-1],d+=i[o][s]*i[s][b];if(l=i[o][o]-S,e[o]<0)k=l,E=p,C=d;else if(u=o,0===e[o]?(y=cdiv$2(-p,-d,l,R),i[o][b-1]=y[0],i[o][b]=y[1]):(f=i[o][o+1],m=i[o+1][o],g=(r[o]-S)*(r[o]-S)+e[o]*e[o]-R*R,v=2*(r[o]-S)*R,0===g&&0===v&&(g=M*$*(Math.abs(l)+Math.abs(R)+Math.abs(f)+Math.abs(m)+Math.abs(k))),y=cdiv$2(f*E-k*p+R*d,f*C-k*d-R*p,g,v),i[o][b-1]=y[0],i[o][b]=y[1],Math.abs(f)>Math.abs(k)+Math.abs(R)?(i[o+1][b-1]=(-p-l*i[o][b-1]+R*i[o][b])/f,i[o+1][b]=(-d-l*i[o][b]-R*i[o][b-1])/f):(y=cdiv$2(-E-m*i[o][b-1],-C-m*i[o][b],k,R),i[o+1][b-1]=y[0],i[o+1][b]=y[1])),M*(c=Math.max(Math.abs(i[o][b-1]),Math.abs(i[o][b])))*c>1)for(s=o;s<=b;s++)i[s][b-1]=i[s][b-1]/c,i[s][b]=i[s][b]/c}for(o=0;o<t;o++)if(o<0||o>x)for(s=o;s<t;s++)n[o][s]=i[o][s];for(s=t-1;s>=0;s--)for(o=0;o<=x;o++){for(k=0,a=0;a<=Math.min(s,x);a++)k+=n[o][a]*i[a][s];n[o][s]=k}}}function cdiv$2(t,e,r,n){var i,o;return Math.abs(r)>Math.abs(n)?[(t+(i=n/r)*e)/(o=r+i*n),(e-i*t)/o]:[((i=r/n)*t+e)/(o=n+i*r),(i*e-t)/o]}class CholeskyDecomposition$$1{constructor(t){if(!(t=WrapperMatrix2D$2.checkMatrix(t)).isSymmetric())throw new Error("Matrix is not symmetric");var e,r,n,i=t,o=i.rows,s=new Matrix$2(o,o),a=!0;for(r=0;r<o;r++){var u=s[r],h=0;for(n=0;n<r;n++){var c=s[n],l=0;for(e=0;e<n;e++)l+=c[e]*u[e];u[n]=l=(i.get(r,n)-l)/s[n][n],h+=l*l}for(a&=(h=i.get(r,r)-h)>0,s[r][r]=Math.sqrt(Math.max(h,0)),n=r+1;n<o;n++)s[r][n]=0}if(!a)throw new Error("Matrix is not positive definite");this.L=s}solve(t){t=WrapperMatrix2D$2.checkMatrix(t);var e=this.L,r=e.rows;if(t.rows!==r)throw new Error("Matrix dimensions do not match");var n,i,o,s=t.columns,a=t.clone();for(o=0;o<r;o++)for(i=0;i<s;i++){for(n=0;n<o;n++)a[o][i]-=a[n][i]*e[o][n];a[o][i]/=e[o][o]}for(o=r-1;o>=0;o--)for(i=0;i<s;i++){for(n=o+1;n<r;n++)a[o][i]-=a[n][i]*e[n][o];a[o][i]/=e[o][o]}return a}get lowerTriangularMatrix(){return this.L}}var src$2=Object.freeze({default:Matrix$2,Matrix:Matrix$2,abstractMatrix:AbstractMatrix$2,wrap:wrap$2,WrapperMatrix2D:WrapperMatrix2D$2,WrapperMatrix1D:WrapperMatrix1D$2,solve:solve$$1,inverse:inverse$$1,SingularValueDecomposition:SingularValueDecomposition$$1,SVD:SingularValueDecomposition$$1,EigenvalueDecomposition:EigenvalueDecomposition$$1,EVD:EigenvalueDecomposition$$1,CholeskyDecomposition:CholeskyDecomposition$$1,CHO:CholeskyDecomposition$$1,LuDecomposition:LuDecomposition$$1,LU:LuDecomposition$$1,QrDecomposition:QrDecomposition$$1,QR:QrDecomposition$$1}),array=createCommonjsModule((function(t,e){function r(t,e){return t-e}e.sum=function(t){for(var e=0,r=0;r<t.length;r++)e+=t[r];return e},e.max=function(t){for(var e=t[0],r=t.length,n=1;n<r;n++)t[n]>e&&(e=t[n]);return e},e.min=function(t){for(var e=t[0],r=t.length,n=1;n<r;n++)t[n]<e&&(e=t[n]);return e},e.minMax=function(t){for(var e=t[0],r=t[0],n=t.length,i=1;i<n;i++)t[i]<e&&(e=t[i]),t[i]>r&&(r=t[i]);return{min:e,max:r}},e.arithmeticMean=function(t){for(var e=0,r=t.length,n=0;n<r;n++)e+=t[n];return e/r},e.mean=e.arithmeticMean,e.geometricMean=function(t){for(var e=1,r=t.length,n=0;n<r;n++)e*=t[n];return Math.pow(e,1/r)},e.logMean=function(t){for(var e=0,r=t.length,n=0;n<r;n++)e+=Math.log(t[n]);return e/r},e.grandMean=function(t,e){for(var r=0,n=0,i=t.length,o=0;o<i;o++)r+=e[o]*t[o],n+=e[o];return r/n},e.truncatedMean=function(t,e,n){void 0===n&&(n=!1),n||(t=[].concat(t).sort(r));for(var i=t.length,o=Math.floor(i*e),s=0,a=o;a<i-o;a++)s+=t[a];return s/(i-2*o)},e.harmonicMean=function(t){for(var e=0,r=t.length,n=0;n<r;n++){if(0===t[n])throw new RangeError("value at index "+n+"is zero");e+=1/t[n]}return r/e},e.contraHarmonicMean=function(t){for(var e=0,r=0,n=t.length,i=0;i<n;i++)e+=t[i]*t[i],r+=t[i];if(r<0)throw new RangeError("sum of values is negative");return e/r},e.median=function(t,e){void 0===e&&(e=!1),e||(t=[].concat(t).sort(r));var n=t.length,i=Math.floor(n/2);return n%2==0?.5*(t[i-1]+t[i]):t[i]},e.variance=function(t,r){void 0===r&&(r=!0);for(var n=e.mean(t),i=0,o=t.length,s=0;s<o;s++){var a=t[s]-n;i+=a*a}return r?i/(o-1):i/o},e.standardDeviation=function(t,r){return Math.sqrt(e.variance(t,r))},e.standardError=function(t){return e.standardDeviation(t)/Math.sqrt(t.length)},e.robustMeanAndStdev=function(t){var e=0,n=t.length,i=0;for(i=0;i<n;i++)e+=t[i];e/=n;var o=new Array(n);for(i=0;i<n;i++)o[i]=Math.abs(t[i]-e);return o.sort(r),{mean:e,stdev:n%2==1?o[(n-1)/2]/.6745:.5*(o[n/2]+o[n/2-1])/.6745}},e.quartiles=function(t,n){void 0===n&&(n=!1),n||(t=[].concat(t).sort(r));var i=t.length/4;return{q1:t[Math.ceil(i)-1],q2:e.median(t,!0),q3:t[Math.ceil(3*i)-1]}},e.pooledStandardDeviation=function(t,r){return Math.sqrt(e.pooledVariance(t,r))},e.pooledVariance=function(t,r){void 0===r&&(r=!0);for(var n=0,i=0,o=t.length,s=0;s<o;s++){var a=t[s],u=e.variance(a);n+=(a.length-1)*u,i+=r?a.length-1:a.length}return n/i},e.mode=function(t){var e,r=t.length,n=new Array(r);for(e=0;e<r;e++)n[e]=0;var i=new Array(r),o=0;for(e=0;e<r;e++){var s=i.indexOf(t[e]);s>=0?n[s]++:(i[o]=t[e],n[o]=1,o++)}var a=0,u=0;for(e=0;e<o;e++)n[e]>a&&(a=n[e],u=e);return i[u]},e.covariance=function(t,r,n){void 0===n&&(n=!0);var i=e.mean(t),o=e.mean(r);if(t.length!==r.length)throw"Vectors do not have the same dimensions";for(var s=0,a=t.length,u=0;u<a;u++){s+=(t[u]-i)*(r[u]-o)}return n?s/(a-1):s/a},e.skewness=function(t,r){void 0===r&&(r=!0);for(var n=e.mean(t),i=0,o=0,s=t.length,a=0;a<s;a++){var u=t[a]-n;i+=u*u,o+=u*u*u}var h=i/s,c=o/s/Math.pow(h,1.5);return r?Math.sqrt(s*(s-1))/(s-2)*c:c},e.kurtosis=function(t,r){void 0===r&&(r=!0);for(var n=e.mean(t),i=t.length,o=0,s=0,a=0;a<i;a++){var u=t[a]-n;o+=u*u,s+=u*u*u*u}var h=o/i;if(r){var c=o/(i-1);return i*(i+1)/((i-1)*(i-2)*(i-3))*(s/(c*c))-3*((i-1)*(i-1)/((i-2)*(i-3)))}return s/i/(h*h)-3},e.entropy=function(t,e){void 0===e&&(e=0);for(var r=0,n=t.length,i=0;i<n;i++)r+=t[i]*Math.log(t[i]+e);return-r},e.weightedMean=function(t,e){for(var r=0,n=t.length,i=0;i<n;i++)r+=t[i]*e[i];return r},e.weightedStandardDeviation=function(t,r){return Math.sqrt(e.weightedVariance(t,r))},e.weightedVariance=function(t,r){for(var n=e.weightedMean(t,r),i=0,o=t.length,s=0,a=0,u=0;u<o;u++){var h=t[u]-n,c=r[u];i+=c*(h*h),a+=c,s+=c*c}return i*(a/(a*a-s))},e.center=function(t,r){void 0===r&&(r=!1);var n=t;r||(n=[].concat(t));for(var i=e.mean(n),o=n.length,s=0;s<o;s++)n[s]-=i},e.standardize=function(t,r,n){void 0===r&&(r=e.standardDeviation(t)),void 0===n&&(n=!1);for(var i=t.length,o=n?t:new Array(i),s=0;s<i;s++)o[s]=t[s]/r;return o},e.cumulativeSum=function(t){var e=t.length,r=new Array(e);r[0]=t[0];for(var n=1;n<e;n++)r[n]=r[n-1]+t[n];return r}})),array_1=array.sum,array_2=array.max,array_3=array.min,array_4=array.minMax,array_5=array.arithmeticMean,array_6=array.mean,array_7=array.geometricMean,array_8=array.logMean,array_9=array.grandMean,array_10=array.truncatedMean,array_11=array.harmonicMean,array_12=array.contraHarmonicMean,array_13=array.median,array_14=array.variance,array_15=array.standardDeviation,array_16=array.standardError,array_17=array.robustMeanAndStdev,array_18=array.quartiles,array_19=array.pooledStandardDeviation,array_20=array.pooledVariance,array_21=array.mode,array_22=array.covariance,array_23=array.skewness,array_24=array.kurtosis,array_25=array.entropy,array_26=array.weightedMean,array_27=array.weightedStandardDeviation,array_28=array.weightedVariance,array_29=array.center,array_30=array.standardize,array_31=array.cumulativeSum,matrix=createCommonjsModule((function(t,e){function r(t,e){return t-e}e.max=function(t){for(var e=-1/0,r=0;r<t.length;r++)for(var n=0;n<t[r].length;n++)t[r][n]>e&&(e=t[r][n]);return e},e.min=function(t){for(var e=1/0,r=0;r<t.length;r++)for(var n=0;n<t[r].length;n++)t[r][n]<e&&(e=t[r][n]);return e},e.minMax=function(t){for(var e=1/0,r=-1/0,n=0;n<t.length;n++)for(var i=0;i<t[n].length;i++)t[n][i]<e&&(e=t[n][i]),t[n][i]>r&&(r=t[n][i]);return{min:e,max:r}},e.entropy=function(t,e){void 0===e&&(e=0);for(var r=0,n=t.length,i=t[0].length,o=0;o<n;o++)for(var s=0;s<i;s++)r+=t[o][s]*Math.log(t[o][s]+e);return-r},e.mean=function(t,e){void 0===e&&(e=0);var r,n,i,o,s=t.length,a=t[0].length;if(-1===e){for(r=[0],n=s*a,i=0;i<s;i++)for(o=0;o<a;o++)r[0]+=t[i][o];r[0]/=n}else if(0===e)for(r=new Array(a),n=s,o=0;o<a;o++){for(r[o]=0,i=0;i<s;i++)r[o]+=t[i][o];r[o]/=n}else{if(1!==e)throw new Error("Invalid dimension");for(r=new Array(s),n=a,o=0;o<s;o++){for(r[o]=0,i=0;i<a;i++)r[o]+=t[o][i];r[o]/=n}}return r},e.sum=function(t,e){void 0===e&&(e=0);var r,n,i,o=t.length,s=t[0].length;if(-1===e)for(r=[0],n=0;n<o;n++)for(i=0;i<s;i++)r[0]+=t[n][i];else if(0===e)for(r=new Array(s),i=0;i<s;i++)for(r[i]=0,n=0;n<o;n++)r[i]+=t[n][i];else{if(1!==e)throw new Error("Invalid dimension");for(r=new Array(o),i=0;i<o;i++)for(r[i]=0,n=0;n<s;n++)r[i]+=t[i][n]}return r},e.product=function(t,e){void 0===e&&(e=0);var r,n,i,o=t.length,s=t[0].length;if(-1===e)for(r=[1],n=0;n<o;n++)for(i=0;i<s;i++)r[0]*=t[n][i];else if(0===e)for(r=new Array(s),i=0;i<s;i++)for(r[i]=1,n=0;n<o;n++)r[i]*=t[n][i];else{if(1!==e)throw new Error("Invalid dimension");for(r=new Array(o),i=0;i<o;i++)for(r[i]=1,n=0;n<s;n++)r[i]*=t[i][n]}return r},e.standardDeviation=function(t,r,n){for(var i=e.variance(t,r,n),o=i.length,s=0;s<o;s++)i[s]=Math.sqrt(i[s]);return i},e.variance=function(t,r,n){void 0===n&&(n=!0),r=r||e.mean(t);var i=t.length;if(0===i)return[];for(var o=t[0].length,s=new Array(o),a=0;a<o;a++){for(var u=0,h=0,c=0,l=0;l<i;l++)u+=c=t[l][a]-r[a],h+=c*c;s[a]=n?(h-u*u/i)/(i-1):(h-u*u/i)/i}return s},e.median=function(t){for(var e=t.length,n=t[0].length,i=new Array(n),o=0;o<n;o++){for(var s=new Array(e),a=0;a<e;a++)s[a]=t[a][o];s.sort(r);var u=s.length;i[o]=u%2==0?.5*(s[u/2]+s[u/2-1]):s[Math.floor(u/2)]}return i},e.mode=function(t){var e,r,n=t.length,i=t[0].length,o=new Array(i);for(e=0;e<i;e++){for(var s=new Array(n),a=0;a<n;a++)s[a]=0;var u=new Array(n),h=0;for(r=0;r<n;r++){var c=u.indexOf(t[r][e]);c>=0?s[c]++:(u[h]=t[r][e],s[h]=1,h++)}var l=0,f=0;for(r=0;r<h;r++)s[r]>l&&(l=s[r],f=r);o[e]=u[f]}return o},e.skewness=function(t,r){void 0===r&&(r=!0);for(var n=e.mean(t),i=t.length,o=n.length,s=new Array(o),a=0;a<o;a++){for(var u=0,h=0,c=0;c<i;c++){var l=t[c][a]-n[a];u+=l*l,h+=l*l*l}var f=u/i,m=h/i/Math.pow(f,1.5);if(r){var p=Math.sqrt(i*(i-1)),d=i-2;s[a]=p/d*m}else s[a]=m}return s},e.kurtosis=function(t,r){void 0===r&&(r=!0);for(var n=e.mean(t),i=t.length,o=t[0].length,s=new Array(o),a=0;a<o;a++){for(var u=0,h=0,c=0;c<i;c++){var l=t[c][a]-n[a];u+=l*l,h+=l*l*l*l}var f=u/i,m=h/i;if(r){var p=u/(i-1),d=i*(i+1)/((i-1)*(i-2)*(i-3)),g=h/(p*p),v=(i-1)*(i-1)/((i-2)*(i-3));s[a]=d*g-3*v}else s[a]=m/(f*f)-3}return s},e.standardError=function(t){for(var r=t.length,n=e.standardDeviation(t),i=n.length,o=new Array(i),s=Math.sqrt(r),a=0;a<i;a++)o[a]=n[a]/s;return o},e.covariance=function(t,r){return e.scatter(t,void 0,r)},e.scatter=function(t,r,n){void 0===n&&(n=0),void 0===r&&(0===n?r=t.length-1:1===n&&(r=t[0].length-1));var i=e.mean(t,n),o=t.length;if(0===o)return[[]];var s,a,u,h,c,l=t[0].length;if(0===n){for(s=new Array(l),a=0;a<l;a++)s[a]=new Array(l);for(a=0;a<l;a++)for(u=a;u<l;u++){for(h=0,c=0;c<o;c++)h+=(t[c][u]-i[u])*(t[c][a]-i[a]);h/=r,s[a][u]=h,s[u][a]=h}}else{if(1!==n)throw new Error("Invalid dimension");for(s=new Array(o),a=0;a<o;a++)s[a]=new Array(o);for(a=0;a<o;a++)for(u=a;u<o;u++){for(h=0,c=0;c<l;c++)h+=(t[u][c]-i[u])*(t[a][c]-i[a]);h/=r,s[a][u]=h,s[u][a]=h}}return s},e.correlation=function(t){var r,n,i=e.mean(t),o=e.standardDeviation(t,!0,i),s=e.zScores(t,i,o),a=t.length,u=t[0].length,h=new Array(u);for(r=0;r<u;r++)h[r]=new Array(u);for(r=0;r<u;r++)for(n=r;n<u;n++){for(var c=0,l=0,f=s.length;l<f;l++)c+=s[l][n]*s[l][r];c/=a-1,h[r][n]=c,h[n][r]=c}return h},e.zScores=function(t,r,n){return r=r||e.mean(t),void 0===n&&(n=e.standardDeviation(t,!0,r)),e.standardize(e.center(t,r,!1),n,!0)},e.center=function(t,r,n){r=r||e.mean(t);var i,o,s,a=t,u=t.length;if(!n)for(a=new Array(u),i=0;i<u;i++)a[i]=new Array(t[i].length);for(i=0;i<u;i++){var h=a[i];for(o=0,s=h.length;o<s;o++)h[o]=t[i][o]-r[o]}return a},e.standardize=function(t,r,n){void 0===r&&(r=e.standardDeviation(t));var i,o,s,a=t,u=t.length;if(!n)for(a=new Array(u),i=0;i<u;i++)a[i]=new Array(t[i].length);for(i=0;i<u;i++){var h=a[i],c=t[i];for(o=0,s=h.length;o<s;o++)0===r[o]||isNaN(r[o])||(h[o]=c[o]/r[o])}return a},e.weightedVariance=function(t,r){var n=e.mean(t),i=t.length;if(0===i)return[];for(var o=t[0].length,s=new Array(o),a=0;a<o;a++){for(var u=0,h=0,c=0,l=0;l<i;l++){var f=t[l][a]-n[a],m=r[l];u+=m*(f*f),c+=m,h+=m*m}s[a]=u*(c/(c*c-h))}return s},e.weightedMean=function(t,e,r){void 0===r&&(r=0);var n=t.length;if(0===n)return[];var i,o,s,a,u,h,c=t[0].length;if(0===r){for(i=new Array(c),o=0;o<c;o++)i[o]=0;for(o=0;o<n;o++)for(h=t[o],u=e[o],a=0;a<c;a++)i[a]+=h[a]*u}else{if(1!==r)throw new Error("Invalid dimension");for(i=new Array(n),o=0;o<n;o++)i[o]=0;for(a=0;a<n;a++)for(h=t[a],u=e[a],o=0;o<c;o++)i[a]+=h[o]*u}var l=array.sum(e);if(0!==l)for(o=0,s=i.length;o<s;o++)i[o]/=l;return i},e.weightedCovariance=function(t,r,n,i){i=i||0,n=n||e.weightedMean(t,r,i);for(var o=0,s=0,a=0,u=r.length;a<u;a++)o+=r[a],s+=r[a]*r[a];var h=o/(o*o-s);return e.weightedScatter(t,r,n,h,i)},e.weightedScatter=function(t,r,n,i,o){o=o||0,n=n||e.weightedMean(t,r,o),void 0===i&&(i=1);var s=t.length;if(0===s)return[[]];var a,u,h,c,l,f=t[0].length;if(0===o){for(a=new Array(f),u=0;u<f;u++)a[u]=new Array(f);for(u=0;u<f;u++)for(h=u;h<f;h++){for(l=0,c=0;c<s;c++)l+=r[c]*(t[c][h]-n[h])*(t[c][u]-n[u]);a[u][h]=l*i,a[h][u]=l*i}}else{if(1!==o)throw new Error("Invalid dimension");for(a=new Array(s),u=0;u<s;u++)a[u]=new Array(s);for(u=0;u<s;u++)for(h=u;h<s;h++){for(l=0,c=0;c<f;c++)l+=r[c]*(t[h][c]-n[h])*(t[u][c]-n[u]);a[u][h]=l*i,a[h][u]=l*i}}return a}})),matrix_1=matrix.max,matrix_2=matrix.min,matrix_3=matrix.minMax,matrix_4=matrix.entropy,matrix_5=matrix.mean,matrix_6=matrix.sum,matrix_7=matrix.product,matrix_8=matrix.standardDeviation,matrix_9=matrix.variance,matrix_10=matrix.median,matrix_11=matrix.mode,matrix_12=matrix.skewness,matrix_13=matrix.kurtosis,matrix_14=matrix.standardError,matrix_15=matrix.covariance,matrix_16=matrix.scatter,matrix_17=matrix.correlation,matrix_18=matrix.zScores,matrix_19=matrix.center,matrix_20=matrix.standardize,matrix_21=matrix.weightedVariance,matrix_22=matrix.weightedMean,matrix_23=matrix.weightedCovariance,matrix_24=matrix.weightedScatter;const Matrix$3=src$2.Matrix,EVD=src$2.EVD,SVD=src$2.SVD,mean$2=matrix.mean,stdev=matrix.standardDeviation,defaultOptions$4={isCovarianceMatrix:!1,center:!0,scale:!1};class PCA{constructor(t,e){if(!0===t){const t=e;return this.center=t.center,this.scale=t.scale,this.means=t.means,this.stdevs=t.stdevs,this.U=Matrix$3.checkMatrix(t.U),void(this.S=t.S)}if(e=Object.assign({},defaultOptions$4,e),this.center=!1,this.scale=!1,this.means=null,this.stdevs=null,e.isCovarianceMatrix)this._computeFromCovarianceMatrix(t);else if("boolean"==typeof e.useCovarianceMatrix?e.useCovarianceMatrix:t.length>t[0].length){const r=(t=this._adjust(t,e)).transposeView().mmul(t).div(t.rows-1);this._computeFromCovarianceMatrix(r)}else{t=this._adjust(t,e);var r=new SVD(t,{computeLeftSingularVectors:!1,computeRightSingularVectors:!0,autoTranspose:!0});this.U=r.rightSingularVectors;const i=r.diagonal,o=new Array(i.length);for(var n=0;n<i.length;n++)o[n]=i[n]*i[n]/(t.length-1);this.S=o}}static load(t){if("PCA"!==t.name)throw new RangeError("Invalid model: "+t.name);return new PCA(!0,t)}predict(t,e={}){const{nComponents:r=this.U.columns}=e;t=new Matrix$3(t),this.center&&(t.subRowVector(this.means),this.scale&&t.divRowVector(this.stdevs));var n=t.mmul(this.U);return n.subMatrix(0,n.rows-1,0,r-1)}getExplainedVariance(){for(var t=0,e=0;e<this.S.length;e++)t+=this.S[e];return this.S.map((e=>e/t))}getCumulativeVariance(){for(var t=this.getExplainedVariance(),e=1;e<t.length;e++)t[e]+=t[e-1];return t}getEigenvectors(){return this.U}getEigenvalues(){return this.S}getStandardDeviations(){return this.S.map((t=>Math.sqrt(t)))}getLoadings(){return this.U.transpose()}toJSON(){return{name:"PCA",center:this.center,scale:this.scale,means:this.means,stdevs:this.stdevs,U:this.U,S:this.S}}_adjust(t,e){if(this.center=!!e.center,this.scale=!!e.scale,t=new Matrix$3(t),this.center){const e=mean$2(t),n=this.scale?stdev(t,e,!0):null;if(this.means=e,t.subRowVector(e),this.scale){for(var r=0;r<n.length;r++)if(0===n[r])throw new RangeError("Cannot scale the dataset (standard deviation is zero at index "+r);this.stdevs=n,t.divRowVector(n)}}return t}_computeFromCovarianceMatrix(t){const e=new EVD(t,{assumeSymmetric:!0});this.U=e.eigenvectorMatrix;for(var r=0;r<this.U.length;r++)this.U[r].reverse();this.S=e.realEigenvalues.reverse()}}var pca=PCA;function squaredEuclidean(t,e){for(var r=0,n=0;n<t.length;n++)r+=(t[n]-e[n])*(t[n]-e[n]);return r}function euclidean(t,e){return Math.sqrt(squaredEuclidean(t,e))}var euclidean_1=euclidean;euclidean.squared=squaredEuclidean;var heap=createCommonjsModule((function(t,e){(function(){var e,r,n,i,o,s,a,u,h,c,l,f,m,p,d;n=Math.floor,c=Math.min,r=function(t,e){return t<e?-1:t>e?1:0},h=function(t,e,i,o,s){var a;if(null==i&&(i=0),null==s&&(s=r),i<0)throw new Error("lo must be non-negative");for(null==o&&(o=t.length);i<o;)s(e,t[a=n((i+o)/2)])<0?o=a:i=a+1;return[].splice.apply(t,[i,i-i].concat(e)),e},s=function(t,e,n){return null==n&&(n=r),t.push(e),p(t,0,t.length-1,n)},o=function(t,e){var n,i;return null==e&&(e=r),n=t.pop(),t.length?(i=t[0],t[0]=n,d(t,0,e)):i=n,i},u=function(t,e,n){var i;return null==n&&(n=r),i=t[0],t[0]=e,d(t,0,n),i},a=function(t,e,n){var i;return null==n&&(n=r),t.length&&n(t[0],e)<0&&(e=(i=[t[0],e])[0],t[0]=i[1],d(t,0,n)),e},i=function(t,e){var i,o,s,a,u,h;for(null==e&&(e=r),u=[],o=0,s=(a=function(){h=[];for(var e=0,r=n(t.length/2);0<=r?e<r:e>r;0<=r?e++:e--)h.push(e);return h}.apply(this).reverse()).length;o<s;o++)i=a[o],u.push(d(t,i,e));return u},m=function(t,e,n){var i;if(null==n&&(n=r),-1!==(i=t.indexOf(e)))return p(t,0,i,n),d(t,i,n)},l=function(t,e,n){var o,s,u,h,c;if(null==n&&(n=r),!(s=t.slice(0,e)).length)return s;for(i(s,n),u=0,h=(c=t.slice(e)).length;u<h;u++)o=c[u],a(s,o,n);return s.sort(n).reverse()},f=function(t,e,n){var s,a,u,l,f,m,p,d,g;if(null==n&&(n=r),10*e<=t.length){if(!(u=t.slice(0,e).sort(n)).length)return u;for(a=u[u.length-1],l=0,m=(p=t.slice(e)).length;l<m;l++)n(s=p[l],a)<0&&(h(u,s,0,null,n),u.pop(),a=u[u.length-1]);return u}for(i(t,n),g=[],f=0,d=c(e,t.length);0<=d?f<d:f>d;0<=d?++f:--f)g.push(o(t,n));return g},p=function(t,e,n,i){var o,s,a;for(null==i&&(i=r),o=t[n];n>e&&i(o,s=t[a=n-1>>1])<0;)t[n]=s,n=a;return t[n]=o},d=function(t,e,n){var i,o,s,a,u;for(null==n&&(n=r),o=t.length,u=e,s=t[e],i=2*e+1;i<o;)(a=i+1)<o&&!(n(t[i],t[a])<0)&&(i=a),t[e]=t[i],i=2*(e=i)+1;return t[e]=s,p(t,u,e,n)},e=function(){function t(t){this.cmp=null!=t?t:r,this.nodes=[]}return t.push=s,t.pop=o,t.replace=u,t.pushpop=a,t.heapify=i,t.updateItem=m,t.nlargest=l,t.nsmallest=f,t.prototype.push=function(t){return s(this.nodes,t,this.cmp)},t.prototype.pop=function(){return o(this.nodes,this.cmp)},t.prototype.peek=function(){return this.nodes[0]},t.prototype.contains=function(t){return-1!==this.nodes.indexOf(t)},t.prototype.replace=function(t){return u(this.nodes,t,this.cmp)},t.prototype.pushpop=function(t){return a(this.nodes,t,this.cmp)},t.prototype.heapify=function(){return i(this.nodes,this.cmp)},t.prototype.updateItem=function(t){return m(this.nodes,t,this.cmp)},t.prototype.clear=function(){return this.nodes=[]},t.prototype.empty=function(){return 0===this.nodes.length},t.prototype.size=function(){return this.nodes.length},t.prototype.clone=function(){var e;return(e=new t).nodes=this.nodes.slice(0),e},t.prototype.toArray=function(){return this.nodes.slice(0)},t.prototype.insert=t.prototype.push,t.prototype.top=t.prototype.peek,t.prototype.front=t.prototype.peek,t.prototype.has=t.prototype.contains,t.prototype.copy=t.prototype.clone,t}(),t.exports=e}).call(commonjsGlobal)})),heap$1=heap;function Cluster(){this.children=[],this.distance=-1,this.index=[]}Cluster.prototype.cut=function(t){if(t<0)throw new RangeError("Threshold too small");var e=new Cluster;e.children=this.children,e.distance=this.distance,e.index=this.index;for(var r=[e],n=[];r.length>0;){var i=r.shift();t>=i.distance?n.push(i):r=r.concat(i.children)}return n},Cluster.prototype.group=function(t){if(!Number.isInteger(t)||t<1)throw new RangeError("Number of groups must be a positive integer");const e=new heap$1((function(t,e){return e.distance-t.distance}));for(e.push(this);e.size()<t;){var r=e.pop();if(0===r.children.length)break;r.children.forEach((t=>e.push(t)))}var n=new Cluster;return n.children=e.toArray(),n.distance=this.distance,n},Cluster.prototype.traverse=function(t){!function t(e,r){if(r(e),e.children)for(var n=e.children.length-1;n>=0;n--)t(e.children[n],r)}(this,t)};var Cluster_1=Cluster;function ClusterLeaf(t){Cluster_1.call(this),this.index=t,this.distance=0,this.children=[]}util$2.inherits(ClusterLeaf,Cluster_1);var ClusterLeaf_1=ClusterLeaf;function distanceMatrix(t,e){const r=t.length;let n=Array.from({length:r}).map((()=>Array.from({length:r})));for(let i=0;i<r;i++)for(let r=0;r<=i;r++)n[i][r]=e(t[i],t[r]);for(let t=0;t<r;t++)for(let e=t+1;e<r;e++)n[t][e]=n[e][t];return n}var src$3=distanceMatrix;function simpleLink(t,e,r){for(var n=1e101,i=0;i<t.length;i++)for(var o=0;o<e.length;o++){var s=r[t[i]][e[o]];n=Math.min(s,n)}return n}function completeLink(t,e,r){for(var n=-1,i=0;i<t.length;i++)for(var o=0;o<e.length;o++){var s=r[t[i]][e[o]];n=Math.max(s,n)}return n}function averageLink(t,e,r){for(var n=0,i=0;i<t.length;i++)for(var o=0;o<e.length;o++)n+=r[t[i]][e[o]];return n/(t.length*e.length)}function centroidLink(t,e,r){for(var n=new Array(t.length*e.length),i=0;i<t.length;i++)for(var o=0;o<e.length;o++)n[i*e.length+o]=r[t[i]][e[o]];return median$1(n)}function wardLink(t,e,r){return centroidLink(t,e,r)*t.length*e.length/(t.length+e.length)}function compareNumbers(t,e){return t-e}function median$1(t,e){void 0===e&&(e=!1),e||(t=[].concat(t).sort(compareNumbers));var r=t.length,n=Math.floor(r/2);return r%2==0?.5*(t[n-1]+t[n]):t[n]}var defaultOptions$5={disFunc:euclidean_1,kind:"single",isDistanceMatrix:!1};function agnes(t,e){e=Object.assign({},defaultOptions$5,e);var r=t.length,n=t;if(e.isDistanceMatrix||(n=src$3(t,e.disFunc)),"string"==typeof e.kind)switch(e.kind){case"single":e.kind=simpleLink;break;case"complete":e.kind=completeLink;break;case"average":e.kind=averageLink;break;case"centroid":e.kind=centroidLink;break;case"ward":e.kind=wardLink;break;default:throw new RangeError("Unknown kind of similarity")}else if("function"!=typeof e.kind)throw new TypeError("Undefined kind of similarity");for(var i=new Array(r),o=0;o<n.length;o++)i[o]=new ClusterLeaf_1(o);for(var s=1e6,a={},u=0;i.length>1;){a={},s=1e6;for(var h=0;h<i.length;h++)for(var c=h+1;c<i.length;c++){var l,f;if(i[h]instanceof ClusterLeaf_1)l=[i[h].index];else{l=new Array(i[h].index.length);for(var m=0;m<l.length;m++)l[m]=i[h].index[m].index}if(i[c]instanceof ClusterLeaf_1)f=[i[c].index];else{f=new Array(i[c].index.length);for(var p=0;p<f.length;p++)f[p]=i[c].index[p].index}(u=e.kind(l,f,n).toFixed(4))in a?a[u].push([i[h],i[c]]):a[u]=[[i[h],i[c]]],s=Math.min(u,s)}for(var d,g=a[s.toFixed(4)],v=new Array(g.length),w=0;g.length>0;){d=g.shift();for(var y=0;y<g.length;y++){if(g[y].filter((function(t){return-1!==d.indexOf(t)})).length>0){var b=g[y].filter((function(t){return-1===d.indexOf(t)}));d=d.concat(b),g.splice(y--,1)}}v[w++]=d}v.length=w;for(var x=0;x<v.length;x++){var M=new Cluster_1;M.children=v[x].concat(),M.distance=s,M.index=new Array(r);for(var _=0,$=0;$<v[x].length;$++)v[x][$]instanceof ClusterLeaf_1?M.index[_++]=v[x][$]:(_+=v[x][$].index.length,M.index=v[x][$].index.concat(M.index)),i.splice(i.indexOf(v[x][$]),1);M.index.length=_,i.push(M)}}return i[0]}var agnes_1=agnes;function simpleLink$1(t,e,r){for(var n=1e101,i=0;i<t.length;i++)for(var o=i;o<e.length;o++){var s=r(t[i],e[o]);n=Math.min(s,n)}return n}function completeLink$1(t,e,r){for(var n=-1,i=0;i<t.length;i++)for(var o=i;o<e.length;o++){var s=r(t[i],e[o]);n=Math.max(s,n)}return n}function averageLink$1(t,e,r){for(var n=0,i=0;i<t.length;i++)for(var o=0;o<e.length;o++)n+=r(t[i],e[o]);return n/(t.length*e.length)}function centroidLink$1(t,e,r){for(var n=0,i=0,o=0,s=0,a=0;a<t.length;a++)n+=t[a][0],i+=t[a][1];for(var u=0;u<e.length;u++)o+=e[u][0],s+=e[u][1];return r([n/=t.length,i/=t.length],[o/=e.length,s/=e.length])}function wardLink$1(t,e,r){for(var n=0,i=0,o=0,s=0,a=0;a<t.length;a++)n+=t[a][0],i+=t[a][1];for(var u=0;u<e.length;u++)o+=e[u][0],s+=e[u][1];return r([n/=t.length,i/=t.length],[o/=e.length,s/=e.length])*t.length*e.length/(t.length+e.length)}function diff(t,e,r){for(var n={d:0,p:0},i=new Array(t[0].length),o=0;o<t[0].length;o++)i[o]=e[t[0][o]];for(var s,a,u=new Array(t[1].length),h=0;h<t[1].length;h++)u[h]=e[t[1][h]];for(var c=0;c<i.length;c++){s=0;for(var l=0;l<i.length;l++)c!==l&&(s+=r(i[c],i[l]));s/=i.length-1,a=0;for(var f=0;f<u.length;f++)a+=r(i[c],u[f]);s-(a/=u.length)>n.d&&(n.d=s-a,n.p=c)}return n}var defaultOptions$6={dist:euclidean_1,kind:"single"};function intrDist(t,e,r){for(var n=0,i=0,o=0;o<t.length;o++)for(var s=o;s<t.length;s++)n+=r(e[t[o].index],e[t[s].index]),i++;return n/i}function diana(t,e){if("string"==typeof(e=Object.assign({},defaultOptions$6,e)).kind)switch(e.kind){case"single":e.kind=simpleLink$1;break;case"complete":e.kind=completeLink$1;break;case"average":e.kind=averageLink$1;break;case"centroid":e.kind=centroidLink$1;break;case"ward":e.kind=wardLink$1;break;default:throw new RangeError("Unknown kind of similarity")}else if("function"!=typeof e.kind)throw new TypeError("Undefined kind of similarity");var r,n,i,o,s,a=new Cluster_1;a.children=new Array(t.length),a.index=new Array(t.length);for(var u=0;u<t.length;u++)a.children[u]=new ClusterLeaf_1(u),a.index[u]=new ClusterLeaf_1(u);a.distance=intrDist(a.index,t,e.dist);for(var h=[a];h.length>0;){n=0,i=0;for(var c=0;c<h.length;c++){r=0;for(var l=0;l<h[c].length;l++)for(var f=l+1;f<h[c].length;f++)r=Math.max(e.dist(t[h[c].index[l].index],t[h[c].index[f].index]),r);r>n&&(n=r,i=c)}if(n=0,2===h[i].index.length)h[i].children=[h[i].index[0],h[i].index[1]],h[i].distance=e.dist(t[h[i].index[0].index],t[h[i].index[1].index]);else if(3===h[i].index.length){h[i].children=[h[i].index[0],h[i].index[1],h[i].index[2]];var m=[e.dist(t[h[i].index[0].index],t[h[i].index[1].index]),e.dist(t[h[i].index[1].index],t[h[i].index[2].index])];h[i].distance=(m[0]+m[1])/2}else{for(var p=new Cluster_1,d=new Cluster_1,g=[new Array(h[i].index.length),[]],v=0;v<g[0].length;v++)g[0][v]=v;for(var w=0;w<g[0].length;w++){o=0;for(var y=0;y<g[0].length;y++)w!==y&&(o+=e.dist(t[h[i].index[g[0][y]].index],t[h[i].index[g[0][w]].index]));(o/=g[0].length-1)>n&&(n=o,s=w)}for(g[1]=[s],g[0].splice(s,1),o=diff(g,t,e.dist);o.d>0;)g[1].push(g[0][o.p]),g[0].splice(o.p,1),o=diff(g,t,e.dist);var b=new Array(g[0].length);p.index=new Array(g[0].length);for(var x=0;x<b.length;x++)b[x]=t[h[i].index[g[0][x]].index],p.index[x]=h[i].index[g[0][x]],p.children[x]=h[i].index[g[0][x]];var M=new Array(g[1].length);d.index=new Array(g[1].length);for(var _=0;_<M.length;_++)M[_]=t[h[i].index[g[1][_]].index],d.index[_]=h[i].index[g[1][_]],d.children[_]=h[i].index[g[1][_]];p.distance=intrDist(p.index,t,e.dist),d.distance=intrDist(d.index,t,e.dist),h.push(p),h.push(d),h[i].children=[p,d]}h.splice(i,1)}return a}var diana_1=diana,agnes$1=agnes_1,diana$1=diana_1,src$4={agnes:agnes$1,diana:diana$1};const squaredDistance=euclidean_1.squared,defaultOptions$7={distanceFunction:squaredDistance,similarityFunction:!1,returnVector:!1};function nearestVector(t,e,r){const n=(r=r||defaultOptions$7).distanceFunction||defaultOptions$7.distanceFunction,i=r.similarityFunction||defaultOptions$7.similarityFunction,o=r.returnVector||defaultOptions$7.returnVector;var s=-1;if("function"==typeof i)for(var a=Number.MIN_VALUE,u=0;u<t.length;u++){var h=i(e,t[u]);h>a&&(a=h,s=u)}else{if("function"!=typeof n)throw new Error("A similarity or distance function it's required");for(var c=Number.MAX_VALUE,l=0;l<t.length;l++){var f=n(e,t[l]);f<c&&(c=f,s=l)}}return o?t[s]:s}var src$5=nearestVector;function calculateDistanceMatrix(t,e){for(var r=new Array(t.length),n=0;n<t.length;++n)for(var i=n;i<t.length;++i){r[n]||(r[n]=new Array(t.length)),r[i]||(r[i]=new Array(t.length));const o=e(t[n],t[i]);r[n][i]=o,r[i][n]=o}return r}function updateClusterID(t,e,r,n){for(var i=0;i<t.length;i++)r[i]=src$5(e,t[i],{distanceFunction:n});return r}function updateCenters(t,e,r){const n=t[0].length;for(var i=new Array(r),o=new Array(r),s=0;s<r;s++){i[s]=new Array(n),o[s]=0;for(var a=0;a<n;a++)i[s][a]=0}for(var u=0;u<t.length;u++){o[e[u]]++;for(var h=0;h<n;h++)i[e[u]][h]+=t[u][h]}for(var c=0;c<r;c++)for(var l=0;l<n;l++)i[c][l]/=o[c];return i}function converged(t,e,r,n){for(var i=0;i<t.length;i++)if(r(t[i],e[i])>n)return!1;return!0}var updateClusterID_1=updateClusterID,updateCenters_1=updateCenters,calculateDistanceMatrix_1=calculateDistanceMatrix,converged_1=converged,utils={updateClusterID:updateClusterID_1,updateCenters:updateCenters_1,calculateDistanceMatrix:calculateDistanceMatrix_1,converged:converged_1},Picker=createCommonjsModule((function(t){(function(e){var r;(r=t.exports?t.exports:this.RandomSelection={}).Picker=function(t){this._originalOptions=t,this._remainingOptions=[]},r.Picker.prototype={pick:function(){0===this._remainingOptions.length&&(this._remainingOptions=function(t){for(var e=[],r=0;r<t.length;r++)e.push(t[r]);return e}(this._originalOptions));var t=Math.floor(Math.random()*this._remainingOptions.length);return this._remainingOptions.splice(t,1)[0]}}}).call(commonjsGlobal)}));const Picker$1=Picker.Picker;function random$1(t,e){const r=new Picker$1(t);for(var n=new Array(e),i=0;i<e;++i)n[i]=r.pick();return n}function mostDistant(t,e,r){var n=new Array(e);if(n[0]=Math.floor(Math.random()*t.length),e>1){for(var i={dist:-1,index:-1},o=0;o<t.length;++o)r[n[0]][o]>i.dist&&(i.dist=r[n[0]][o],i.index=o);if(n[1]=i.index,e>2)for(var s=2;s<e;++s){for(var a={dist:-1,index:-1},u=0;u<t.length;++u){for(var h={dist:Number.MAX_VALUE,index:-1},c=0;c<s;++c)r[c][u]<h.dist&&-1===n.indexOf(u)&&(h={dist:r[c][u],index:u});h.dist!==Number.MAX_VALUE&&h.dist>a.dist&&(a=Object.assign({},h))}n[s]=a.index}}return n.map((e=>t[e]))}var random_1=random$1,mostDistant_1=mostDistant,initialization={random:random_1,mostDistant:mostDistant_1};const distanceSymbol=Symbol("distance");function KMeansResult(t,e,r,n,i){this.clusters=t,this.centroids=e,this.converged=r,this.iterations=n,this[distanceSymbol]=i}KMeansResult.prototype.nearest=function(t){var e=new Array(t.length),r=this.centroids.map((function(t){return t.centroid}));return utils.updateClusterID(t,r,e,this[distanceSymbol])},KMeansResult.prototype.computeInformation=function(t){for(var e=this.centroids.map((function(t){return{centroid:t,error:0,size:0}})),r=0;r<t.length;r++)e[this.clusters[r]].error+=this[distanceSymbol](t[r],this.centroids[this.clusters[r]]),e[this.clusters[r]].size++;for(var n=0;n<this.centroids.length;n++)e[n].error/=e[n].size;return new KMeansResult(this.clusters,e,this.converged,this.iterations,this[distanceSymbol])};var KMeansResult_1=KMeansResult;const squaredDistance$1=euclidean_1.squared,defaultOptions$8={maxIterations:100,tolerance:1e-6,withIterations:!1,initialization:"mostDistant",distanceFunction:squaredDistance$1};function step(t,e,r,n,i,o){r=utils.updateClusterID(e,t,r,i.distanceFunction);var s=utils.updateCenters(e,r,n),a=utils.converged(s,t,i.distanceFunction,i.tolerance);return new KMeansResult_1(r,s,a,o,i.distanceFunction)}function*kmeansGenerator(t,e,r,n,i){for(var o,s=!1,a=0;!s&&a<i.maxIterations;)o=step(t,e,r,n,i,++a),yield o.computeInformation(e),s=o.converged,t=o.centroids}function kmeans(t,e,r){if(r=Object.assign({},defaultOptions$8,r),e<=0||e>t.length||!Number.isInteger(e))throw new Error("K should be a positive integer bigger than the number of points");var n;if(Array.isArray(r.initialization)){if(r.initialization.length!==e)throw new Error("The initial centers should have the same length as K");n=r.initialization}else switch(r.initialization){case"random":n=initialization.random(t,e);break;case"mostDistant":n=initialization.mostDistant(t,e,utils.calculateDistanceMatrix(t,r.distanceFunction));break;default:throw new Error('Unknown initialization method: "'+r.initialization+'"')}0===r.maxIterations&&(r.maxIterations=Number.MAX_VALUE);var i=new Array(t.length);if(r.withIterations)return kmeansGenerator(n,t,i,e,r);for(var o,s=!1,a=0;!s&&a<r.maxIterations;)s=(o=step(n,t,i,e,r,++a)).converged,n=o.centroids;return o.computeInformation(t)}var kmeans_1=kmeans;const squaredEuclidean$1=euclidean_1.squared,defaultOptions$9={sigma:1};class GaussianKernel{constructor(t){t=Object.assign({},defaultOptions$9,t),this.sigma=t.sigma,this.divisor=2*t.sigma*t.sigma}compute(t,e){const r=squaredEuclidean$1(t,e);return Math.exp(-r/this.divisor)}}var gaussianKernel=GaussianKernel;const defaultOptions$a={degree:1,constant:1,scale:1};class PolynomialKernel{constructor(t){t=Object.assign({},defaultOptions$a,t),this.degree=t.degree,this.constant=t.constant,this.scale=t.scale}compute(t,e){for(var r=0,n=0;n<t.length;n++)r+=t[n]*e[n];return Math.pow(this.scale*r+this.constant,this.degree)}}var polynomialKernel=PolynomialKernel;const defaultOptions$b={sigma:1,degree:1};class ANOVAKernel{constructor(t){t=Object.assign({},defaultOptions$b,t),this.sigma=t.sigma,this.degree=t.degree}compute(t,e){for(var r=0,n=Math.min(t.length,e.length),i=1;i<=n;++i)r+=Math.pow(Math.exp(-this.sigma*Math.pow(Math.pow(t[i-1],i)-Math.pow(e[i-1],i),2)),this.degree);return r}}var anovaKernel=ANOVAKernel;const squaredEuclidean$2=euclidean_1.squared,defaultOptions$c={sigma:1};class CauchyKernel{constructor(t){t=Object.assign({},defaultOptions$c,t),this.sigma=t.sigma}compute(t,e){return 1/(1+squaredEuclidean$2(t,e)/(this.sigma*this.sigma))}}var cauchyKernel=CauchyKernel;const defaultOptions$d={sigma:1};class ExponentialKernel{constructor(t){t=Object.assign({},defaultOptions$d,t),this.sigma=t.sigma,this.divisor=2*t.sigma*t.sigma}compute(t,e){const r=euclidean_1(t,e);return Math.exp(-r/this.divisor)}}var exponentialKernel=ExponentialKernel;class HistogramIntersectionKernel{compute(t,e){for(var r=Math.min(t.length,e.length),n=0,i=0;i<r;++i)n+=Math.min(t[i],e[i]);return n}}var histogramIntersectionKernel=HistogramIntersectionKernel;const defaultOptions$e={sigma:1};class LaplacianKernel{constructor(t){t=Object.assign({},defaultOptions$e,t),this.sigma=t.sigma}compute(t,e){const r=euclidean_1(t,e);return Math.exp(-r/this.sigma)}}var laplacianKernel=LaplacianKernel;const squaredEuclidean$3=euclidean_1.squared,defaultOptions$f={constant:1};class MultiquadraticKernel{constructor(t){t=Object.assign({},defaultOptions$f,t),this.constant=t.constant}compute(t,e){return Math.sqrt(squaredEuclidean$3(t,e)+this.constant*this.constant)}}var multiquadraticKernel=MultiquadraticKernel;const squaredEuclidean$4=euclidean_1.squared,defaultOptions$g={constant:1};class RationalQuadraticKernel{constructor(t){t=Object.assign({},defaultOptions$g,t),this.constant=t.constant}compute(t,e){const r=squaredEuclidean$4(t,e);return 1-r/(r+this.constant)}}var rationalQuadraticKernel=RationalQuadraticKernel;const defaultOptions$h={alpha:.01,constant:-Math.E};class SigmoidKernel{constructor(t){t=Object.assign({},defaultOptions$h,t),this.alpha=t.alpha,this.constant=t.constant}compute(t,e){for(var r=0,n=0;n<t.length;n++)r+=t[n]*e[n];return Math.tanh(this.alpha*r+this.constant)}}var sigmoidKernel=SigmoidKernel;const Matrix$4=require$$0$3.Matrix,kernelType={gaussian:gaussianKernel,rbf:gaussianKernel,polynomial:polynomialKernel,poly:polynomialKernel,anova:anovaKernel,cauchy:cauchyKernel,exponential:exponentialKernel,histogram:histogramIntersectionKernel,min:histogramIntersectionKernel,laplacian:laplacianKernel,multiquadratic:multiquadraticKernel,rational:rationalQuadraticKernel,sigmoid:sigmoidKernel,mlp:sigmoidKernel};class Kernel{constructor(t,e){if(this.kernelType=t,"linear"!==t)if("string"==typeof t){t=t.toLowerCase();var r=kernelType[t];if(!r)throw new Error("unsupported kernel type: "+t);this.kernelFunction=new r(e)}else{if("object"!=typeof t||"function"!=typeof t.compute)throw new TypeError("first argument must be a valid kernel type or instance");this.kernelFunction=t}}compute(t,e){if(void 0===e&&(e=t),"linear"===this.kernelType)return new Matrix$4(t).mmul(new Matrix$4(e).transposeView());const r=new Matrix$4(t.length,e.length);var n,i;if(t===e)for(n=0;n<t.length;n++)for(i=n;i<t.length;i++)r[n][i]=r[i][n]=this.kernelFunction.compute(t[n],t[i]);else for(n=0;n<t.length;n++)for(i=0;i<e.length;i++)r[n][i]=this.kernelFunction.compute(t[n],e[i]);return r}}var kernel=Kernel,array$1=array,matrix$1=matrix,mlStat={array:array$1,matrix:matrix$1};const stat=mlStat.array;var defaultOptions$i={C:1,tol:1e-4,maxPasses:10,maxIterations:1e4,kernel:"linear",alphaTol:1e-6,random:Math.random,whitening:!0};function SVM(t){this.options=Object.assign({},defaultOptions$i,t),this.kernel=new kernel(this.options.kernel,this.options.kernelOptions),this.b=0}SVM.prototype.train=function(t,e){if(t.length!==e.length)throw new Error("Features and labels should have the same length");if(t.length<2)throw new Error("Cannot train with less than 2 observations");if(this._trained=!1,this._loaded=!1,this.N=e.length,this.D=t[0].length,this.options.whitening){this.X=new Array(this.N);for(var r=0;r<this.N;r++)this.X[r]=new Array(this.D);this.minMax=new Array(this.D);for(var n=0;n<this.D;n++){var i=new Array(this.N);for(r=0;r<this.N;r++)i[r]=t[r][n];for(this.minMax[n]=stat.minMax(i),r=0;r<this.N;r++)this.X[r][n]=(t[r][n]-this.minMax[n].min)/(this.minMax[n].max-this.minMax[n].min)}}else this.X=t;this.Y=e,this.b=0,this.W=void 0;var o=this.kernel.compute(this.X),s=e.length,a=new Array(s).fill(0);this.alphas=a;for(var u=0;u<s;u++)a[u]=0;for(var h=0,c=0,l=0,f=0,m=0,p=0,d=0,g=0,v=0,w=0,y=0;f<this.options.maxPasses&&l<this.options.maxIterations;){var b=0;for(r=0;r<s;r++)if(m=this._marginOnePrecomputed(r,o)-e[r],e[r]*m<-this.options.tol&&a[r]<this.options.C||e[r]*m>this.options.tol&&a[r]>0){for(n=r;n===r;)n=Math.floor(this.options.random()*s);if(p=this._marginOnePrecomputed(n,o)-e[n],d=a[r],g=a[n],e[r]===e[n]?(v=Math.max(0,d+g-this.options.C),w=Math.min(this.options.C,d+g)):(v=Math.max(0,g-d),w=Math.min(this.options.C,this.options.C+g+d)),Math.abs(v-w)<1e-4)continue;if((y=2*o[r][n]-o[r][r]-o[n][n])>=0)continue;var x=a[n]-e[n]*(m-p)/y;if(x>w?x=w:x<v&&(x=v),Math.abs(g-x)<.001)continue;a[n]=x,a[r]=a[r]+e[r]*e[n]*(g-x),h=this.b-m-e[r]*(a[r]-d)*o[r][r]-e[n]*(a[n]-g)*o[r][n],c=this.b-p-e[r]*(a[r]-d)*o[r][n]-e[n]*(a[n]-g)*o[n][n],this.b=(h+c)/2,a[r]<this.options.C&&a[r]>0&&(this.b=h),a[n]<this.options.C&&a[n]>0&&(this.b=c),b+=1}l++,0===b?f+=1:f=0}if(l===this.options.maxIterations)throw new Error("max iterations reached");if(this.iterations=l,"linear"===this.options.kernel){this.W=new Array(this.D);for(var M=0;M<this.D;M++){this.W[M]=0;for(var _=0;_<s;_++)this.W[M]+=e[_]*a[_]*this.X[_][M]}}var $=[],S=[],R=[];for(this._supportVectorIdx=[],r=0;r<this.N;r++)this.alphas[r]>this.options.alphaTol&&($.push(this.X[r]),S.push(e[r]),R.push(this.alphas[r]),this._supportVectorIdx.push(r));this.X=$,this.Y=S,this.N=$.length,this.alphas=R,this._trained=!0},SVM.prototype.predictOne=function(t){return this.marginOne(t)>0?1:-1},SVM.prototype.predict=function(t){if(!this._trained&&!this._loaded)throw new Error("Cannot predict, you need to train the SVM first");return Array.isArray(t)&&Array.isArray(t[0])?t.map(this.predictOne.bind(this)):this.predictOne(t)},SVM.prototype.marginOne=function(t,e){this.options.whitening&&!e&&(t=this._applyWhitening(t));var r,n=this.b;if("linear"===this.options.kernel&&this.W)for(r=0;r<this.W.length;r++)n+=this.W[r]*t[r];else for(r=0;r<this.N;r++)n+=this.alphas[r]*this.Y[r]*this.kernel.compute([t],[this.X[r]])[0][0];return n},SVM.prototype._marginOnePrecomputed=function(t,e){var r,n=this.b;for(r=0;r<this.N;r++)n+=this.alphas[r]*this.Y[r]*e[t][r];return n},SVM.prototype.margin=function(t){return Array.isArray(t)?t.map(this.marginOne.bind(this)):this.marginOne(t)},SVM.prototype.supportVectors=function(){if(!this._trained&&!this._loaded)throw new Error("Cannot get support vectors, you need to train the SVM first");if(this._loaded&&"linear"===this.options.kernel)throw new Error("Cannot get support vectors from saved linear model, you need to train the SVM to have them");return this._supportVectorIdx},SVM.load=function(t){this._loaded=!0,this._trained=!1;var e=new SVM(t.options);return"linear"===t.options.kernel?(e.W=t.W.slice(),e.D=e.W.length):(e.X=t.X.slice(),e.Y=t.Y.slice(),e.alphas=t.alphas.slice(),e.N=e.X.length,e.D=e.X[0].length),e.minMax=t.minMax,e.b=t.b,e._loaded=!0,e._trained=!1,e},SVM.prototype.toJSON=function(){if(!this._trained&&!this._loaded)throw new Error("Cannot export, you need to train the SVM first");var t={};return t.options=Object.assign({},this.options),t.b=this.b,t.minMax=this.minMax,"linear"===t.options.kernel?t.W=this.W.slice():(t.X=this.X.slice(),t.Y=this.Y.slice(),t.alphas=this.alphas.slice()),t},SVM.prototype._applyWhitening=function(t){if(!this.minMax)throw new Error("Could not apply whitening");for(var e=new Array(t.length),r=0;r<t.length;r++)e[r]=(t[r]-this.minMax[r].min)/(this.minMax[r].max-this.minMax[r].min);return e};var svm=SVM;Symbol.species||(Symbol.species=Symbol.for("@@species"));class LuDecomposition$$1{constructor(t){var e,r,n,i,o,s,a,u,h,c=(t=WrapperMatrix2D$3.checkMatrix(t)).clone(),l=c.rows,f=c.columns,m=new Array(l),p=1;for(e=0;e<l;e++)m[e]=e;for(u=new Array(l),r=0;r<f;r++){for(e=0;e<l;e++)u[e]=c.get(e,r);for(e=0;e<l;e++){for(h=Math.min(e,r),o=0,n=0;n<h;n++)o+=c.get(e,n)*u[n];u[e]-=o,c.set(e,r,u[e])}for(i=r,e=r+1;e<l;e++)Math.abs(u[e])>Math.abs(u[i])&&(i=e);if(i!==r){for(n=0;n<f;n++)s=c.get(i,n),c.set(i,n,c.get(r,n)),c.set(r,n,s);a=m[i],m[i]=m[r],m[r]=a,p=-p}if(r<l&&0!==c.get(r,r))for(e=r+1;e<l;e++)c.set(e,r,c.get(e,r)/c.get(r,r))}this.LU=c,this.pivotVector=m,this.pivotSign=p}isSingular(){for(var t=this.LU,e=t.columns,r=0;r<e;r++)if(0===t[r][r])return!0;return!1}solve(t){t=Matrix$5.checkMatrix(t);var e=this.LU;if(e.rows!==t.rows)throw new Error("Invalid matrix dimensions");if(this.isSingular())throw new Error("LU matrix is singular");var r,n,i,o=t.columns,s=t.subMatrixRow(this.pivotVector,0,o-1),a=e.columns;for(i=0;i<a;i++)for(r=i+1;r<a;r++)for(n=0;n<o;n++)s[r][n]-=s[i][n]*e[r][i];for(i=a-1;i>=0;i--){for(n=0;n<o;n++)s[i][n]/=e[i][i];for(r=0;r<i;r++)for(n=0;n<o;n++)s[r][n]-=s[i][n]*e[r][i]}return s}get determinant(){var t=this.LU;if(!t.isSquare())throw new Error("Matrix must be square");for(var e=this.pivotSign,r=t.columns,n=0;n<r;n++)e*=t[n][n];return e}get lowerTriangularMatrix(){for(var t=this.LU,e=t.rows,r=t.columns,n=new Matrix$5(e,r),i=0;i<e;i++)for(var o=0;o<r;o++)n[i][o]=i>o?t[i][o]:i===o?1:0;return n}get upperTriangularMatrix(){for(var t=this.LU,e=t.rows,r=t.columns,n=new Matrix$5(e,r),i=0;i<e;i++)for(var o=0;o<r;o++)n[i][o]=i<=o?t[i][o]:0;return n}get pivotPermutationVector(){return this.pivotVector.slice()}}function hypotenuse$3(t,e){var r=0;return Math.abs(t)>Math.abs(e)?(r=e/t,Math.abs(t)*Math.sqrt(1+r*r)):0!==e?(r=t/e,Math.abs(e)*Math.sqrt(1+r*r)):0}function getFilled2DArray$3(t,e,r){for(var n=new Array(t),i=0;i<t;i++){n[i]=new Array(e);for(var o=0;o<e;o++)n[i][o]=r}return n}class SingularValueDecomposition$$1{constructor(t,e={}){var r=(t=WrapperMatrix2D$3.checkMatrix(t)).rows,n=t.columns,i=Math.min(r,n);const{computeLeftSingularVectors:o=!0,computeRightSingularVectors:s=!0,autoTranspose:a=!1}=e;var u,h=Boolean(o),c=Boolean(s),l=!1;if(r<n)if(a){r=(u=t.transpose()).rows,n=u.columns,l=!0;var f=h;h=c,c=f}else u=t.clone(),console.warn("Computing SVD on a matrix with more columns than rows. Consider enabling autoTranspose");else u=t.clone();var m,p,d,g,v,w,y,b,x,M,_,$,S,R,E,C,k,A,T,O,I,D=new Array(Math.min(r+1,n)),P=getFilled2DArray$3(r,i,0),V=getFilled2DArray$3(n,n,0),j=new Array(n),L=new Array(r),N=Math.min(r-1,n),B=Math.max(0,Math.min(n-2,r));for(d=0,M=Math.max(N,B);d<M;d++){if(d<N){for(D[d]=0,m=d;m<r;m++)D[d]=hypotenuse$3(D[d],u[m][d]);if(0!==D[d]){for(u[d][d]<0&&(D[d]=-D[d]),m=d;m<r;m++)u[m][d]/=D[d];u[d][d]+=1}D[d]=-D[d]}for(p=d+1;p<n;p++){if(d<N&&0!==D[d]){for(v=0,m=d;m<r;m++)v+=u[m][d]*u[m][p];for(v=-v/u[d][d],m=d;m<r;m++)u[m][p]+=v*u[m][d]}j[p]=u[d][p]}if(h&&d<N)for(m=d;m<r;m++)P[m][d]=u[m][d];if(d<B){for(j[d]=0,m=d+1;m<n;m++)j[d]=hypotenuse$3(j[d],j[m]);if(0!==j[d]){for(j[d+1]<0&&(j[d]=0-j[d]),m=d+1;m<n;m++)j[m]/=j[d];j[d+1]+=1}if(j[d]=-j[d],d+1<r&&0!==j[d]){for(m=d+1;m<r;m++)L[m]=0;for(p=d+1;p<n;p++)for(m=d+1;m<r;m++)L[m]+=j[p]*u[m][p];for(p=d+1;p<n;p++)for(v=-j[p]/j[d+1],m=d+1;m<r;m++)u[m][p]+=v*L[m]}if(c)for(m=d+1;m<n;m++)V[m][d]=j[m]}}if(g=Math.min(n,r+1),N<n&&(D[N]=u[N][N]),r<g&&(D[g-1]=0),B+1<g&&(j[B]=u[B][g-1]),j[g-1]=0,h){for(p=N;p<i;p++){for(m=0;m<r;m++)P[m][p]=0;P[p][p]=1}for(d=N-1;d>=0;d--)if(0!==D[d]){for(p=d+1;p<i;p++){for(v=0,m=d;m<r;m++)v+=P[m][d]*P[m][p];for(v=-v/P[d][d],m=d;m<r;m++)P[m][p]+=v*P[m][d]}for(m=d;m<r;m++)P[m][d]=-P[m][d];for(P[d][d]=1+P[d][d],m=0;m<d-1;m++)P[m][d]=0}else{for(m=0;m<r;m++)P[m][d]=0;P[d][d]=1}}if(c)for(d=n-1;d>=0;d--){if(d<B&&0!==j[d])for(p=d+1;p<n;p++){for(v=0,m=d+1;m<n;m++)v+=V[m][d]*V[m][p];for(v=-v/V[d+1][d],m=d+1;m<n;m++)V[m][p]+=v*V[m][d]}for(m=0;m<n;m++)V[m][d]=0;V[d][d]=1}for(var F=g-1,z=Number.EPSILON;g>0;){for(d=g-2;d>=-1&&-1!==d;d--)if(Math.abs(j[d])<=z*(Math.abs(D[d])+Math.abs(D[d+1]))){j[d]=0;break}if(d===g-2)_=4;else{for(w=g-1;w>=d&&w!==d;w--)if(v=(w!==g?Math.abs(j[w]):0)+(w!==d+1?Math.abs(j[w-1]):0),Math.abs(D[w])<=z*v){D[w]=0;break}w===d?_=3:w===g-1?_=1:(_=2,d=w)}switch(d++,_){case 1:for(y=j[g-2],j[g-2]=0,p=g-2;p>=d;p--)if(v=hypotenuse$3(D[p],y),b=D[p]/v,x=y/v,D[p]=v,p!==d&&(y=-x*j[p-1],j[p-1]=b*j[p-1]),c)for(m=0;m<n;m++)v=b*V[m][p]+x*V[m][g-1],V[m][g-1]=-x*V[m][p]+b*V[m][g-1],V[m][p]=v;break;case 2:for(y=j[d-1],j[d-1]=0,p=d;p<g;p++)if(v=hypotenuse$3(D[p],y),b=D[p]/v,x=y/v,D[p]=v,y=-x*j[p],j[p]=b*j[p],h)for(m=0;m<r;m++)v=b*P[m][p]+x*P[m][d-1],P[m][d-1]=-x*P[m][p]+b*P[m][d-1],P[m][p]=v;break;case 3:for($=Math.max(Math.abs(D[g-1]),Math.abs(D[g-2]),Math.abs(j[g-2]),Math.abs(D[d]),Math.abs(j[d])),S=D[g-1]/$,R=D[g-2]/$,E=j[g-2]/$,C=D[d]/$,k=j[d]/$,T=S*E*(S*E),O=0,0===(A=((R+S)*(R-S)+E*E)/2)&&0===T||(O=Math.sqrt(A*A+T),A<0&&(O=-O),O=T/(A+O)),y=(C+S)*(C-S)+O,I=C*k,p=d;p<g-1;p++){if(b=y/(v=hypotenuse$3(y,I)),x=I/v,p!==d&&(j[p-1]=v),y=b*D[p]+x*j[p],j[p]=b*j[p]-x*D[p],I=x*D[p+1],D[p+1]=b*D[p+1],c)for(m=0;m<n;m++)v=b*V[m][p]+x*V[m][p+1],V[m][p+1]=-x*V[m][p]+b*V[m][p+1],V[m][p]=v;if(b=y/(v=hypotenuse$3(y,I)),x=I/v,D[p]=v,y=b*j[p]+x*D[p+1],D[p+1]=-x*j[p]+b*D[p+1],I=x*j[p+1],j[p+1]=b*j[p+1],h&&p<r-1)for(m=0;m<r;m++)v=b*P[m][p]+x*P[m][p+1],P[m][p+1]=-x*P[m][p]+b*P[m][p+1],P[m][p]=v}j[g-2]=y;break;case 4:if(D[d]<=0&&(D[d]=D[d]<0?-D[d]:0,c))for(m=0;m<=F;m++)V[m][d]=-V[m][d];for(;d<F&&!(D[d]>=D[d+1]);){if(v=D[d],D[d]=D[d+1],D[d+1]=v,c&&d<n-1)for(m=0;m<n;m++)v=V[m][d+1],V[m][d+1]=V[m][d],V[m][d]=v;if(h&&d<r-1)for(m=0;m<r;m++)v=P[m][d+1],P[m][d+1]=P[m][d],P[m][d]=v;d++}g--}}if(l){var q=V;V=P,P=q}this.m=r,this.n=n,this.s=D,this.U=P,this.V=V}solve(t){var e,r=t,n=this.threshold,i=this.s.length,o=Matrix$5.zeros(i,i);for(e=0;e<i;e++)Math.abs(this.s[e])<=n?o[e][e]=0:o[e][e]=1/this.s[e];var s,a,u,h=this.U,c=this.rightSingularVectors,l=c.mmul(o),f=c.rows,m=h.length,p=Matrix$5.zeros(f,m);for(e=0;e<f;e++)for(s=0;s<m;s++){for(u=0,a=0;a<i;a++)u+=l[e][a]*h[s][a];p[e][s]=u}return p.mmul(r)}solveForDiagonal(t){return this.solve(Matrix$5.diag(t))}inverse(){var t,e,r=this.V,n=this.threshold,i=r.length,o=r[0].length,s=new Matrix$5(i,this.s.length);for(t=0;t<i;t++)for(e=0;e<o;e++)Math.abs(this.s[e])>n?s[t][e]=r[t][e]/this.s[e]:s[t][e]=0;var a,u,h=this.U,c=h.length,l=h[0].length,f=new Matrix$5(i,c);for(t=0;t<i;t++)for(e=0;e<c;e++){for(u=0,a=0;a<l;a++)u+=s[t][a]*h[e][a];f[t][e]=u}return f}get condition(){return this.s[0]/this.s[Math.min(this.m,this.n)-1]}get norm2(){return this.s[0]}get rank(){for(var t=Math.max(this.m,this.n)*this.s[0]*Number.EPSILON,e=0,r=this.s,n=0,i=r.length;n<i;n++)r[n]>t&&e++;return e}get diagonal(){return this.s}get threshold(){return Number.EPSILON/2*Math.max(this.m,this.n)*this.s[0]}get leftSingularVectors(){return Matrix$5.isMatrix(this.U)||(this.U=new Matrix$5(this.U)),this.U}get rightSingularVectors(){return Matrix$5.isMatrix(this.V)||(this.V=new Matrix$5(this.V)),this.V}get diagonalMatrix(){return Matrix$5.diag(this.s)}}function checkRowIndex$3(t,e,r){var n=r?t.rows:t.rows-1;if(e<0||e>n)throw new RangeError("Row index out of range")}function checkColumnIndex$3(t,e,r){var n=r?t.columns:t.columns-1;if(e<0||e>n)throw new RangeError("Column index out of range")}function checkRowVector$3(t,e){if(e.to1DArray&&(e=e.to1DArray()),e.length!==t.columns)throw new RangeError("vector size must be the same as the number of columns");return e}function checkColumnVector$3(t,e){if(e.to1DArray&&(e=e.to1DArray()),e.length!==t.rows)throw new RangeError("vector size must be the same as the number of rows");return e}function checkIndices$3(t,e,r){return{row:checkRowIndices$3(t,e),column:checkColumnIndices$3(t,r)}}function checkRowIndices$3(t,e){if("object"!=typeof e)throw new TypeError("unexpected type for row indices");if(e.some((e=>e<0||e>=t.rows)))throw new RangeError("row indices are out of range");return Array.isArray(e)||(e=Array.from(e)),e}function checkColumnIndices$3(t,e){if("object"!=typeof e)throw new TypeError("unexpected type for column indices");var r=e.some((e=>e<0||e>=t.columns));if(r)throw new RangeError("column indices are out of range");return Array.isArray(e)||(e=Array.from(e)),e}function checkRange$3(t,e,r,n,i){if(5!==arguments.length)throw new TypeError("Invalid argument type");if(Array.from(arguments).slice(1).some((function(t){return"number"!=typeof t})))throw new TypeError("Invalid argument type");if(e>r||n>i||e<0||e>=t.rows||r<0||r>=t.rows||n<0||n>=t.columns||i<0||i>=t.columns)throw new RangeError("Submatrix indices are out of range")}function sumByRow$3(t){for(var e=Matrix$5.zeros(t.rows,1),r=0;r<t.rows;++r)for(var n=0;n<t.columns;++n)e.set(r,0,e.get(r,0)+t.get(r,n));return e}function sumByColumn$3(t){for(var e=Matrix$5.zeros(1,t.columns),r=0;r<t.rows;++r)for(var n=0;n<t.columns;++n)e.set(0,n,e.get(0,n)+t.get(r,n));return e}function sumAll$3(t){for(var e=0,r=0;r<t.rows;r++)for(var n=0;n<t.columns;n++)e+=t.get(r,n);return e}class BaseView$3 extends(AbstractMatrix$3()){constructor(t,e,r){super(),this.matrix=t,this.rows=e,this.columns=r}static get[Symbol.species](){return Matrix$5}}class MatrixTransposeView$3 extends BaseView$3{constructor(t){super(t,t.columns,t.rows)}set(t,e,r){return this.matrix.set(e,t,r),this}get(t,e){return this.matrix.get(e,t)}}class MatrixRowView$3 extends BaseView$3{constructor(t,e){super(t,1,t.columns),this.row=e}set(t,e,r){return this.matrix.set(this.row,e,r),this}get(t,e){return this.matrix.get(this.row,e)}}class MatrixSubView$3 extends BaseView$3{constructor(t,e,r,n,i){checkRange$3(t,e,r,n,i),super(t,r-e+1,i-n+1),this.startRow=e,this.startColumn=n}set(t,e,r){return this.matrix.set(this.startRow+t,this.startColumn+e,r),this}get(t,e){return this.matrix.get(this.startRow+t,this.startColumn+e)}}class MatrixSelectionView$3 extends BaseView$3{constructor(t,e,r){var n=checkIndices$3(t,e,r);super(t,n.row.length,n.column.length),this.rowIndices=n.row,this.columnIndices=n.column}set(t,e,r){return this.matrix.set(this.rowIndices[t],this.columnIndices[e],r),this}get(t,e){return this.matrix.get(this.rowIndices[t],this.columnIndices[e])}}class MatrixRowSelectionView$3 extends BaseView$3{constructor(t,e){super(t,(e=checkRowIndices$3(t,e)).length,t.columns),this.rowIndices=e}set(t,e,r){return this.matrix.set(this.rowIndices[t],e,r),this}get(t,e){return this.matrix.get(this.rowIndices[t],e)}}class MatrixColumnSelectionView$3 extends BaseView$3{constructor(t,e){e=checkColumnIndices$3(t,e),super(t,t.rows,e.length),this.columnIndices=e}set(t,e,r){return this.matrix.set(t,this.columnIndices[e],r),this}get(t,e){return this.matrix.get(t,this.columnIndices[e])}}class MatrixColumnView$3 extends BaseView$3{constructor(t,e){super(t,t.rows,1),this.column=e}set(t,e,r){return this.matrix.set(t,this.column,r),this}get(t){return this.matrix.get(t,this.column)}}class MatrixFlipRowView$3 extends BaseView$3{constructor(t){super(t,t.rows,t.columns)}set(t,e,r){return this.matrix.set(this.rows-t-1,e,r),this}get(t,e){return this.matrix.get(this.rows-t-1,e)}}class MatrixFlipColumnView$3 extends BaseView$3{constructor(t){super(t,t.rows,t.columns)}set(t,e,r){return this.matrix.set(t,this.columns-e-1,r),this}get(t,e){return this.matrix.get(t,this.columns-e-1)}}function AbstractMatrix$3(t){void 0===t&&(t=Object);class e extends t{static get[Symbol.species](){return this}static from1DArray(t,e,r){if(t*e!==r.length)throw new RangeError("Data length does not match given dimensions");for(var n=new this(t,e),i=0;i<t;i++)for(var o=0;o<e;o++)n.set(i,o,r[i*e+o]);return n}static rowVector(t){for(var e=new this(1,t.length),r=0;r<t.length;r++)e.set(0,r,t[r]);return e}static columnVector(t){for(var e=new this(t.length,1),r=0;r<t.length;r++)e.set(r,0,t[r]);return e}static empty(t,e){return new this(t,e)}static zeros(t,e){return this.empty(t,e).fill(0)}static ones(t,e){return this.empty(t,e).fill(1)}static rand(t,e,r){void 0===r&&(r=Math.random);for(var n=this.empty(t,e),i=0;i<t;i++)for(var o=0;o<e;o++)n.set(i,o,r());return n}static randInt(t,e,r,n){void 0===r&&(r=1e3),void 0===n&&(n=Math.random);for(var i=this.empty(t,e),o=0;o<t;o++)for(var s=0;s<e;s++){var a=Math.floor(n()*r);i.set(o,s,a)}return i}static eye(t,e,r){void 0===e&&(e=t),void 0===r&&(r=1);for(var n=Math.min(t,e),i=this.zeros(t,e),o=0;o<n;o++)i.set(o,o,r);return i}static diag(t,e,r){var n=t.length;void 0===e&&(e=n),void 0===r&&(r=e);for(var i=Math.min(n,e,r),o=this.zeros(e,r),s=0;s<i;s++)o.set(s,s,t[s]);return o}static min(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);for(var r=t.rows,n=t.columns,i=new this(r,n),o=0;o<r;o++)for(var s=0;s<n;s++)i.set(o,s,Math.min(t.get(o,s),e.get(o,s)));return i}static max(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);for(var r=t.rows,n=t.columns,i=new this(r,n),o=0;o<r;o++)for(var s=0;s<n;s++)i.set(o,s,Math.max(t.get(o,s),e.get(o,s)));return i}static checkMatrix(t){return e.isMatrix(t)?t:new this(t)}static isMatrix(t){return null!=t&&"Matrix"===t.klass}get size(){return this.rows*this.columns}apply(t){if("function"!=typeof t)throw new TypeError("callback must be a function");for(var e=this.rows,r=this.columns,n=0;n<e;n++)for(var i=0;i<r;i++)t.call(this,n,i);return this}to1DArray(){for(var t=new Array(this.size),e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)t[e*this.columns+r]=this.get(e,r);return t}to2DArray(){for(var t=new Array(this.rows),e=0;e<this.rows;e++){t[e]=new Array(this.columns);for(var r=0;r<this.columns;r++)t[e][r]=this.get(e,r)}return t}isRowVector(){return 1===this.rows}isColumnVector(){return 1===this.columns}isVector(){return 1===this.rows||1===this.columns}isSquare(){return this.rows===this.columns}isSymmetric(){if(this.isSquare()){for(var t=0;t<this.rows;t++)for(var e=0;e<=t;e++)if(this.get(t,e)!==this.get(e,t))return!1;return!0}return!1}set(t,e,r){throw new Error("set method is unimplemented")}get(t,e){throw new Error("get method is unimplemented")}repeat(t,e){t=t||1,e=e||1;for(var r=new this.constructor[Symbol.species](this.rows*t,this.columns*e),n=0;n<t;n++)for(var i=0;i<e;i++)r.setSubMatrix(this,this.rows*n,this.columns*i);return r}fill(t){for(var e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)this.set(e,r,t);return this}neg(){return this.mulS(-1)}getRow(t){checkRowIndex$3(this,t);for(var e=new Array(this.columns),r=0;r<this.columns;r++)e[r]=this.get(t,r);return e}getRowVector(t){return this.constructor.rowVector(this.getRow(t))}setRow(t,e){checkRowIndex$3(this,t),e=checkRowVector$3(this,e);for(var r=0;r<this.columns;r++)this.set(t,r,e[r]);return this}swapRows(t,e){checkRowIndex$3(this,t),checkRowIndex$3(this,e);for(var r=0;r<this.columns;r++){var n=this.get(t,r);this.set(t,r,this.get(e,r)),this.set(e,r,n)}return this}getColumn(t){checkColumnIndex$3(this,t);for(var e=new Array(this.rows),r=0;r<this.rows;r++)e[r]=this.get(r,t);return e}getColumnVector(t){return this.constructor.columnVector(this.getColumn(t))}setColumn(t,e){checkColumnIndex$3(this,t),e=checkColumnVector$3(this,e);for(var r=0;r<this.rows;r++)this.set(r,t,e[r]);return this}swapColumns(t,e){checkColumnIndex$3(this,t),checkColumnIndex$3(this,e);for(var r=0;r<this.rows;r++){var n=this.get(r,t);this.set(r,t,this.get(r,e)),this.set(r,e,n)}return this}addRowVector(t){t=checkRowVector$3(this,t);for(var e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t[r]);return this}subRowVector(t){t=checkRowVector$3(this,t);for(var e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t[r]);return this}mulRowVector(t){t=checkRowVector$3(this,t);for(var e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t[r]);return this}divRowVector(t){t=checkRowVector$3(this,t);for(var e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t[r]);return this}addColumnVector(t){t=checkColumnVector$3(this,t);for(var e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t[e]);return this}subColumnVector(t){t=checkColumnVector$3(this,t);for(var e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t[e]);return this}mulColumnVector(t){t=checkColumnVector$3(this,t);for(var e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t[e]);return this}divColumnVector(t){t=checkColumnVector$3(this,t);for(var e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t[e]);return this}mulRow(t,e){checkRowIndex$3(this,t);for(var r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)*e);return this}mulColumn(t,e){checkColumnIndex$3(this,t);for(var r=0;r<this.rows;r++)this.set(r,t,this.get(r,t)*e);return this}max(){for(var t=this.get(0,0),e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)this.get(e,r)>t&&(t=this.get(e,r));return t}maxIndex(){for(var t=this.get(0,0),e=[0,0],r=0;r<this.rows;r++)for(var n=0;n<this.columns;n++)this.get(r,n)>t&&(t=this.get(r,n),e[0]=r,e[1]=n);return e}min(){for(var t=this.get(0,0),e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)this.get(e,r)<t&&(t=this.get(e,r));return t}minIndex(){for(var t=this.get(0,0),e=[0,0],r=0;r<this.rows;r++)for(var n=0;n<this.columns;n++)this.get(r,n)<t&&(t=this.get(r,n),e[0]=r,e[1]=n);return e}maxRow(t){checkRowIndex$3(this,t);for(var e=this.get(t,0),r=1;r<this.columns;r++)this.get(t,r)>e&&(e=this.get(t,r));return e}maxRowIndex(t){checkRowIndex$3(this,t);for(var e=this.get(t,0),r=[t,0],n=1;n<this.columns;n++)this.get(t,n)>e&&(e=this.get(t,n),r[1]=n);return r}minRow(t){checkRowIndex$3(this,t);for(var e=this.get(t,0),r=1;r<this.columns;r++)this.get(t,r)<e&&(e=this.get(t,r));return e}minRowIndex(t){checkRowIndex$3(this,t);for(var e=this.get(t,0),r=[t,0],n=1;n<this.columns;n++)this.get(t,n)<e&&(e=this.get(t,n),r[1]=n);return r}maxColumn(t){checkColumnIndex$3(this,t);for(var e=this.get(0,t),r=1;r<this.rows;r++)this.get(r,t)>e&&(e=this.get(r,t));return e}maxColumnIndex(t){checkColumnIndex$3(this,t);for(var e=this.get(0,t),r=[0,t],n=1;n<this.rows;n++)this.get(n,t)>e&&(e=this.get(n,t),r[0]=n);return r}minColumn(t){checkColumnIndex$3(this,t);for(var e=this.get(0,t),r=1;r<this.rows;r++)this.get(r,t)<e&&(e=this.get(r,t));return e}minColumnIndex(t){checkColumnIndex$3(this,t);for(var e=this.get(0,t),r=[0,t],n=1;n<this.rows;n++)this.get(n,t)<e&&(e=this.get(n,t),r[0]=n);return r}diag(){for(var t=Math.min(this.rows,this.columns),e=new Array(t),r=0;r<t;r++)e[r]=this.get(r,r);return e}sum(t){switch(t){case"row":return sumByRow$3(this);case"column":return sumByColumn$3(this);default:return sumAll$3(this)}}mean(){return this.sum()/this.size}prod(){for(var t=1,e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)t*=this.get(e,r);return t}norm(t="frobenius"){var e=0;if("max"===t)return this.max();if("frobenius"===t){for(var r=0;r<this.rows;r++)for(var n=0;n<this.columns;n++)e+=this.get(r,n)*this.get(r,n);return Math.sqrt(e)}throw new RangeError(`unknown norm type: ${t}`)}cumulativeSum(){for(var t=0,e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)t+=this.get(e,r),this.set(e,r,t);return this}dot(t){e.isMatrix(t)&&(t=t.to1DArray());var r=this.to1DArray();if(r.length!==t.length)throw new RangeError("vectors do not have the same size");for(var n=0,i=0;i<r.length;i++)n+=r[i]*t[i];return n}mmul(t){t=this.constructor.checkMatrix(t),this.columns!==t.rows&&console.warn("Number of columns of left matrix are not equal to number of rows of right matrix.");for(var e=this.rows,r=this.columns,n=t.columns,i=new this.constructor[Symbol.species](e,n),o=new Array(r),s=0;s<n;s++){for(var a=0;a<r;a++)o[a]=t.get(a,s);for(var u=0;u<e;u++){var h=0;for(a=0;a<r;a++)h+=this.get(u,a)*o[a];i.set(u,s,h)}}return i}strassen2x2(t){var e=new this.constructor[Symbol.species](2,2);const r=this.get(0,0),n=t.get(0,0),i=this.get(0,1),o=t.get(0,1),s=this.get(1,0),a=t.get(1,0),u=this.get(1,1),h=t.get(1,1),c=(r+u)*(n+h),l=(s+u)*n,f=r*(o-h),m=u*(a-n),p=(r+i)*h,d=c+m-p+(i-u)*(a+h),g=f+p,v=l+m,w=c-l+f+(s-r)*(n+o);return e.set(0,0,d),e.set(0,1,g),e.set(1,0,v),e.set(1,1,w),e}strassen3x3(t){var e=new this.constructor[Symbol.species](3,3);const r=this.get(0,0),n=this.get(0,1),i=this.get(0,2),o=this.get(1,0),s=this.get(1,1),a=this.get(1,2),u=this.get(2,0),h=this.get(2,1),c=this.get(2,2),l=t.get(0,0),f=t.get(0,1),m=t.get(0,2),p=t.get(1,0),d=t.get(1,1),g=t.get(1,2),v=t.get(2,0),w=t.get(2,1),y=t.get(2,2),b=(r-o)*(-f+d),x=(-r+o+s)*(l-f+d),M=(o+s)*(-l+f),_=r*l,$=(-r+u+h)*(l-m+g),S=(-r+u)*(m-g),R=(u+h)*(-l+m),E=(-i+h+c)*(d+v-w),C=(i-c)*(d-w),k=i*v,A=(h+c)*(-v+w),T=(-i+s+a)*(g+v-y),O=(i-a)*(g-y),I=(s+a)*(-v+y),D=_+k+n*p,P=(r+n+i-o-s-h-c)*d+x+M+_+E+k+A,V=_+$+R+(r+n+i-s-a-u-h)*g+k+T+I,j=b+s*(-l+f+p-d-g-v+y)+x+_+k+T+O,L=b+x+M+_+a*w,N=k+T+O+I+o*m,B=_+$+S+h*(-l+m+p-d-g-v+w)+E+C+k,F=E+C+k+A+u*f,z=_+$+S+R+c*y;return e.set(0,0,D),e.set(0,1,P),e.set(0,2,V),e.set(1,0,j),e.set(1,1,L),e.set(1,2,N),e.set(2,0,B),e.set(2,1,F),e.set(2,2,z),e}mmulStrassen(t){var r=this.clone(),n=r.rows,i=r.columns,o=t.rows,s=t.columns;function a(t,r,n){var i=t.rows,o=t.columns;if(i===r&&o===n)return t;var s=e.zeros(r,n);return s=s.setSubMatrix(t,0,0)}i!==o&&console.warn(`Multiplying ${n} x ${i} and ${o} x ${s} matrix: dimensions do not match.`);var u=Math.max(n,o),h=Math.max(i,s);return function t(r,n,i,o){if(i<=512||o<=512)return r.mmul(n);i%2==1&&o%2==1?(r=a(r,i+1,o+1),n=a(n,i+1,o+1)):i%2==1?(r=a(r,i+1,o),n=a(n,i+1,o)):o%2==1&&(r=a(r,i,o+1),n=a(n,i,o+1));var s=parseInt(r.rows/2),u=parseInt(r.columns/2),h=r.subMatrix(0,s-1,0,u-1),c=n.subMatrix(0,s-1,0,u-1),l=r.subMatrix(0,s-1,u,r.columns-1),f=n.subMatrix(0,s-1,u,n.columns-1),m=r.subMatrix(s,r.rows-1,0,u-1),p=n.subMatrix(s,n.rows-1,0,u-1),d=r.subMatrix(s,r.rows-1,u,r.columns-1),g=n.subMatrix(s,n.rows-1,u,n.columns-1),v=t(e.add(h,d),e.add(c,g),s,u),w=t(e.add(m,d),c,s,u),y=t(h,e.sub(f,g),s,u),b=t(d,e.sub(p,c),s,u),x=t(e.add(h,l),g,s,u),M=t(e.sub(m,h),e.add(c,f),s,u),_=t(e.sub(l,d),e.add(p,g),s,u),$=e.add(v,b);$.sub(x),$.add(_);var S=e.add(y,x),R=e.add(w,b),E=e.sub(v,w);E.add(y),E.add(M);var C=e.zeros(2*$.rows,2*$.columns);return(C=(C=(C=(C=C.setSubMatrix($,0,0)).setSubMatrix(S,$.rows,0)).setSubMatrix(R,0,$.columns)).setSubMatrix(E,$.rows,$.columns)).subMatrix(0,i-1,0,o-1)}(r=a(r,u,h),t=a(t,u,h),u,h)}scaleRows(t,e){if((t=void 0===t?0:t)>=(e=void 0===e?1:e))throw new RangeError("min should be strictly smaller than max");for(var r=this.constructor.empty(this.rows,this.columns),n=0;n<this.rows;n++){var i=rescale(this.getRow(n),{min:t,max:e});r.setRow(n,i)}return r}scaleColumns(t,e){if((t=void 0===t?0:t)>=(e=void 0===e?1:e))throw new RangeError("min should be strictly smaller than max");for(var r=this.constructor.empty(this.rows,this.columns),n=0;n<this.columns;n++){var i=rescale(this.getColumn(n),{min:t,max:e});r.setColumn(n,i)}return r}kroneckerProduct(t){t=this.constructor.checkMatrix(t);for(var e=this.rows,r=this.columns,n=t.rows,i=t.columns,o=new this.constructor[Symbol.species](e*n,r*i),s=0;s<e;s++)for(var a=0;a<r;a++)for(var u=0;u<n;u++)for(var h=0;h<i;h++)o[n*s+u][i*a+h]=this.get(s,a)*t.get(u,h);return o}transpose(){for(var t=new this.constructor[Symbol.species](this.columns,this.rows),e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)t.set(r,e,this.get(e,r));return t}sortRows(t){void 0===t&&(t=r);for(var e=0;e<this.rows;e++)this.setRow(e,this.getRow(e).sort(t));return this}sortColumns(t){void 0===t&&(t=r);for(var e=0;e<this.columns;e++)this.setColumn(e,this.getColumn(e).sort(t));return this}subMatrix(t,e,r,n){checkRange$3(this,t,e,r,n);for(var i=new this.constructor[Symbol.species](e-t+1,n-r+1),o=t;o<=e;o++)for(var s=r;s<=n;s++)i[o-t][s-r]=this.get(o,s);return i}subMatrixRow(t,e,r){if(void 0===e&&(e=0),void 0===r&&(r=this.columns-1),e>r||e<0||e>=this.columns||r<0||r>=this.columns)throw new RangeError("Argument out of range");for(var n=new this.constructor[Symbol.species](t.length,r-e+1),i=0;i<t.length;i++)for(var o=e;o<=r;o++){if(t[i]<0||t[i]>=this.rows)throw new RangeError("Row index out of range: "+t[i]);n.set(i,o-e,this.get(t[i],o))}return n}subMatrixColumn(t,e,r){if(void 0===e&&(e=0),void 0===r&&(r=this.rows-1),e>r||e<0||e>=this.rows||r<0||r>=this.rows)throw new RangeError("Argument out of range");for(var n=new this.constructor[Symbol.species](r-e+1,t.length),i=0;i<t.length;i++)for(var o=e;o<=r;o++){if(t[i]<0||t[i]>=this.columns)throw new RangeError("Column index out of range: "+t[i]);n.set(o-e,i,this.get(o,t[i]))}return n}setSubMatrix(t,e,r){checkRange$3(this,e,e+(t=this.constructor.checkMatrix(t)).rows-1,r,r+t.columns-1);for(var n=0;n<t.rows;n++)for(var i=0;i<t.columns;i++)this[e+n][r+i]=t.get(n,i);return this}selection(t,e){for(var r=checkIndices$3(this,t,e),n=new this.constructor[Symbol.species](t.length,e.length),i=0;i<r.row.length;i++)for(var o=r.row[i],s=0;s<r.column.length;s++){var a=r.column[s];n[i][s]=this.get(o,a)}return n}trace(){for(var t=Math.min(this.rows,this.columns),e=0,r=0;r<t;r++)e+=this.get(r,r);return e}transposeView(){return new MatrixTransposeView$3(this)}rowView(t){return checkRowIndex$3(this,t),new MatrixRowView$3(this,t)}columnView(t){return checkColumnIndex$3(this,t),new MatrixColumnView$3(this,t)}flipRowView(){return new MatrixFlipRowView$3(this)}flipColumnView(){return new MatrixFlipColumnView$3(this)}subMatrixView(t,e,r,n){return new MatrixSubView$3(this,t,e,r,n)}selectionView(t,e){return new MatrixSelectionView$3(this,t,e)}rowSelectionView(t){return new MatrixRowSelectionView$3(this,t)}columnSelectionView(t){return new MatrixColumnSelectionView$3(this,t)}det(){var t,e,r,n,i,o;if(this.isSquare())return 2===this.columns?(t=this.get(0,0),e=this.get(0,1),r=this.get(1,0),t*this.get(1,1)-e*r):3===this.columns?(n=this.selectionView([1,2],[1,2]),i=this.selectionView([1,2],[0,2]),o=this.selectionView([1,2],[0,1]),t=this.get(0,0),e=this.get(0,1),r=this.get(0,2),t*n.det()-e*i.det()+r*o.det()):new LuDecomposition$$1(this).determinant;throw Error("Determinant can only be calculated for a square matrix.")}pseudoInverse(t){void 0===t&&(t=Number.EPSILON);for(var e=new SingularValueDecomposition$$1(this,{autoTranspose:!0}),r=e.leftSingularVectors,n=e.rightSingularVectors,i=e.diagonal,o=0;o<i.length;o++)Math.abs(i[o])>t?i[o]=1/i[o]:i[o]=0;return i=this.constructor[Symbol.species].diag(i),n.mmul(i.mmul(r.transposeView()))}clone(){for(var t=new this.constructor[Symbol.species](this.rows,this.columns),e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)t.set(e,r,this.get(e,r));return t}}function r(t,e){return t-e}e.prototype.klass="Matrix",e.random=e.rand,e.diagonal=e.diag,e.prototype.diagonal=e.prototype.diag,e.identity=e.eye,e.prototype.negate=e.prototype.neg,e.prototype.tensorProduct=e.prototype.kroneckerProduct,e.prototype.determinant=e.prototype.det;var n,i="\n(function %name%(matrix, %args%) {\n    var newMatrix = new this[Symbol.species](matrix);\n    return newMatrix.%name%(%args%);\n})\n",o=i,s=eval;for(var a of[["+","add"],["-","sub","subtract"],["*","mul","multiply"],["/","div","divide"],["%","mod","modulus"],["&","and"],["|","or"],["^","xor"],["<<","leftShift"],[">>","signPropagatingRightShift"],[">>>","rightShift","zeroFillRightShift"]]){var u=s(S("\n(function %name%(value) {\n    if (typeof value === 'number') return this.%name%S(value);\n    return this.%name%M(value);\n})\n",{name:a[1],op:a[0]})),h=s(S("\n(function %name%S(value) {\n    for (var i = 0; i < this.rows; i++) {\n        for (var j = 0; j < this.columns; j++) {\n            this.set(i, j, this.get(i, j) %op% value);\n        }\n    }\n    return this;\n})\n",{name:a[1]+"S",op:a[0]})),c=s(S("\n(function %name%M(matrix) {\n    matrix = this.constructor.checkMatrix(matrix);\n    if (this.rows !== matrix.rows ||\n        this.columns !== matrix.columns) {\n        throw new RangeError('Matrices dimensions must be equal');\n    }\n    for (var i = 0; i < this.rows; i++) {\n        for (var j = 0; j < this.columns; j++) {\n            this.set(i, j, this.get(i, j) %op% matrix.get(i, j));\n        }\n    }\n    return this;\n})\n",{name:a[1]+"M",op:a[0]})),l=s(S("\n(function %name%(matrix, value) {\n    var newMatrix = new this[Symbol.species](matrix);\n    return newMatrix.%name%(value);\n})\n",{name:a[1]}));for(n=1;n<a.length;n++)e.prototype[a[n]]=u,e.prototype[a[n]+"S"]=h,e.prototype[a[n]+"M"]=c,e[a[n]]=l}var f=[["~","not"]];for(var m of(["abs","acos","acosh","asin","asinh","atan","atanh","cbrt","ceil","clz32","cos","cosh","exp","expm1","floor","fround","log","log1p","log10","log2","round","sign","sin","sinh","sqrt","tan","tanh","trunc"].forEach((function(t){f.push(["Math."+t,t])})),f)){var p=s(S("\n(function %name%() {\n    for (var i = 0; i < this.rows; i++) {\n        for (var j = 0; j < this.columns; j++) {\n            this.set(i, j, %method%(this.get(i, j)));\n        }\n    }\n    return this;\n})\n",{name:m[1],method:m[0]})),d=s(S("\n(function %name%(matrix) {\n    var newMatrix = new this[Symbol.species](matrix);\n    return newMatrix.%name%();\n})\n",{name:m[1]}));for(n=1;n<m.length;n++)e.prototype[m[n]]=p,e[m[n]]=d}for(var g of[["Math.pow",1,"pow"]]){var v="arg0";for(n=1;n<g[1];n++)v+=`, arg${n}`;if(1!==g[1]){var w=s(S("\n(function %name%(%args%) {\n    for (var i = 0; i < this.rows; i++) {\n        for (var j = 0; j < this.columns; j++) {\n            this.set(i, j, %method%(this.get(i, j), %args%));\n        }\n    }\n    return this;\n})\n",{name:g[2],method:g[0],args:v})),y=s(S(i,{name:g[2],args:v}));for(n=2;n<g.length;n++)e.prototype[g[n]]=w,e[g[n]]=y}else{var b={name:g[2],args:v,method:g[0]},x=s(S("\n(function %name%(value) {\n    if (typeof value === 'number') return this.%name%S(value);\n    return this.%name%M(value);\n})\n",b)),M=s(S("\n(function %name%S(value) {\n    for (var i = 0; i < this.rows; i++) {\n        for (var j = 0; j < this.columns; j++) {\n            this.set(i, j, %method%(this.get(i, j), value));\n        }\n    }\n    return this;\n})\n",b)),_=s(S("\n(function %name%M(matrix) {\n    matrix = this.constructor.checkMatrix(matrix);\n    if (this.rows !== matrix.rows ||\n        this.columns !== matrix.columns) {\n        throw new RangeError('Matrices dimensions must be equal');\n    }\n    for (var i = 0; i < this.rows; i++) {\n        for (var j = 0; j < this.columns; j++) {\n            this.set(i, j, %method%(this.get(i, j), matrix.get(i, j)));\n        }\n    }\n    return this;\n})\n",b)),$=s(S(o,b));for(n=2;n<g.length;n++)e.prototype[g[n]]=x,e.prototype[g[n]+"M"]=_,e.prototype[g[n]+"S"]=M,e[g[n]]=$}}function S(t,e){for(var r in e)t=t.replace(new RegExp("%"+r+"%","g"),e[r]);return t}return e}class Matrix$5 extends(AbstractMatrix$3(Array)){constructor(t,e){var r;if(1===arguments.length&&"number"==typeof t)return new Array(t);if(Matrix$5.isMatrix(t))return t.clone();if(Number.isInteger(t)&&t>0){if(super(t),!(Number.isInteger(e)&&e>0))throw new TypeError("nColumns must be a positive integer");for(r=0;r<t;r++)this[r]=new Array(e)}else{if(!Array.isArray(t))throw new TypeError("First argument must be a positive number or an array");{const n=t;if(t=n.length,"number"!=typeof(e=n[0].length)||0===e)throw new TypeError("Data must be a 2D array with at least one element");for(super(t),r=0;r<t;r++){if(n[r].length!==e)throw new RangeError("Inconsistent array dimensions");this[r]=[].concat(n[r])}}}return this.rows=t,this.columns=e,this}set(t,e,r){return this[t][e]=r,this}get(t,e){return this[t][e]}removeRow(t){if(checkRowIndex$3(this,t),1===this.rows)throw new RangeError("A matrix cannot have less than one row");return this.splice(t,1),this.rows-=1,this}addRow(t,e){return void 0===e&&(e=t,t=this.rows),checkRowIndex$3(this,t,!0),e=checkRowVector$3(this,e,!0),this.splice(t,0,e),this.rows+=1,this}removeColumn(t){if(checkColumnIndex$3(this,t),1===this.columns)throw new RangeError("A matrix cannot have less than one column");for(var e=0;e<this.rows;e++)this[e].splice(t,1);return this.columns-=1,this}addColumn(t,e){void 0===e&&(e=t,t=this.columns),checkColumnIndex$3(this,t,!0),e=checkColumnVector$3(this,e);for(var r=0;r<this.rows;r++)this[r].splice(t,0,e[r]);return this.columns+=1,this}}class WrapperMatrix1D$3 extends(AbstractMatrix$3()){constructor(t,e={}){const{rows:r=1}=e;if(t.length%r!=0)throw new Error("the data length is not divisible by the number of rows");super(),this.rows=r,this.columns=t.length/r,this.data=t}set(t,e,r){var n=this._calculateIndex(t,e);return this.data[n]=r,this}get(t,e){var r=this._calculateIndex(t,e);return this.data[r]}_calculateIndex(t,e){return t*this.columns+e}static get[Symbol.species](){return Matrix$5}}class WrapperMatrix2D$3 extends(AbstractMatrix$3()){constructor(t){super(),this.data=t,this.rows=t.length,this.columns=t[0].length}set(t,e,r){return this.data[t][e]=r,this}get(t,e){return this.data[t][e]}static get[Symbol.species](){return Matrix$5}}function separateClasses(t,e){for(var r=t.columns,n=0,i=new Array(1e4),o=0;o<e.length;o++)void 0===i[e[o]]&&(i[e[o]]=0,n++),i[e[o]]++;var s=new Array(n),a=new Array(n);for(o=0;o<n;++o)s[o]=new Matrix$5(i[o],r),a[o]=0;for(o=0;o<t.rows;++o)s[e[o]].setRow(a[e[o]],t.getRow(o)),a[e[o]]++;return s}class GaussianNB{constructor(t,e){t&&(this.means=e.means,this.calculateProbabilities=e.calculateProbabilities)}train(t,e){var r=Math.sqrt(2*Math.PI);if((t=Matrix$5.checkMatrix(t)).rows!==e.length)throw new RangeError("the size of the training set and the training labels must be the same.");var n=separateClasses(t,e),i=new Array(n.length);this.means=new Array(n.length);for(var o=0;o<n.length;++o){var s=mlStat.matrix.mean(n[o]),a=mlStat.matrix.standardDeviation(n[o],s),u=Math.log(n[o].rows/t.rows);i[o]=new Array(s.length+1),i[o][0]=u;for(var h=1;h<s.length+1;++h){var c=a[h-1];i[o][h]=[1/(r*c),-2*c*c]}this.means[o]=s}this.calculateProbabilities=i}predict(t){if(t[0].length===this.calculateProbabilities[0].length)throw new RangeError("the dataset must have the same features as the training set");for(var e=new Array(t.length),r=0;r<e.length;++r)e[r]=getCurrentClass(t[r],this.means,this.calculateProbabilities);return e}toJSON(){return{modelName:"NaiveBayes",means:this.means,calculateProbabilities:this.calculateProbabilities}}static load(t){if("NaiveBayes"!==t.modelName)throw new RangeError("The current model is not a Multinomial Naive Bayes, current model:",t.name);return new GaussianNB(!0,t)}}function getCurrentClass(t,e,r){for(var n=0,i=-1,o=0;o<r.length;++o){for(var s=r[o][0],a=1;a<r[0][1].length+1;++a)s+=calculateLogProbability(t[a-1],e[o][a-1],r[o][a][0],r[o][a][1]);(s=Math.exp(s))>n&&(n=s,i=o)}return i}function calculateLogProbability(t,e,r,n){return t-=e,Math.log(r*Math.exp(t*t/n))}class MultinomialNB{constructor(t){t&&(this.conditionalProbability=Matrix$5.checkMatrix(t.conditionalProbability),this.priorProbability=Matrix$5.checkMatrix(t.priorProbability))}train(t,e){if((t=Matrix$5.checkMatrix(t)).rows!==e.length)throw new RangeError("the size of the training set and the training labels must be the same.");var r=separateClasses(t,e);this.priorProbability=new Matrix$5(r.length,1);for(var n=0;n<r.length;++n)this.priorProbability[n][0]=Math.log(r[n].length/t.rows);var i=t.columns;for(this.conditionalProbability=new Matrix$5(r.length,i),n=0;n<r.length;++n){var o=Matrix$5.checkMatrix(r[n]),s=o.sum()+i;this.conditionalProbability.setRow(n,o.sum("column").add(1).div(s).apply(matrixLog))}}predict(t){t=Matrix$5.checkMatrix(t);for(var e=new Array(t.rows),r=0;r<t.rows;++r){var n=t.getRowVector(r);e[r]=this.conditionalProbability.clone().mulRowVector(n).sum("row").add(this.priorProbability).maxIndex()[0]}return e}toJSON(){return{name:"MultinomialNB",priorProbability:this.priorProbability,conditionalProbability:this.conditionalProbability}}static load(t){if("MultinomialNB"!==t.name)throw new RangeError(`${t.name} is not a Multinomial Naive Bayes`);return new MultinomialNB(t)}}function matrixLog(t,e){this[t][e]=Math.log(this[t][e])}var src$6=Object.freeze({GaussianNB:GaussianNB,MultinomialNB:MultinomialNB});
/*
             * Original code from:
             *
             * k-d Tree JavaScript - V 1.01
             *
             * https://github.com/ubilabs/kd-tree-javascript
             *
             * @author Mircea Pricop <pricop@ubilabs.net>, 2012
             * @author Martin Kleppe <kleppe@ubilabs.net>, 2012
             * @author Ubilabs http://ubilabs.net, 2012
             * @license MIT License <http://www.opensource.org/licenses/mit-license.php>
             */function Node(t,e,r){this.obj=t,this.left=null,this.right=null,this.parent=r,this.dimension=e}class KDTree{constructor(t,e){if(Array.isArray(t)){this.dimensions=new Array(t[0].length);for(var r=0;r<this.dimensions.length;r++)this.dimensions[r]=r;this.root=buildTree(t,0,null,this.dimensions)}else this.dimensions=t.dimensions,this.root=t,restoreParent(this.root);this.metric=e}toJSON(){const t=toJSONImpl(this.root,!0);return t.dimensions=this.dimensions,t}nearest(t,e,r){const n=this.metric,i=this.dimensions;var o;const s=new BinaryHeap((function(t){return-t[1]}));if(r)for(o=0;o<e;o+=1)s.push([null,r]);this.root&&function r(o){const a=i[o.dimension],u=n(t,o.obj),h={};var c,l,f,m;function p(t,r){s.push([t,r]),s.size()>e&&s.pop()}for(m=0;m<i.length;m+=1)m===o.dimension?h[i[m]]=t[i[m]]:h[i[m]]=o.obj[i[m]];l=n(h,o.obj),null!==o.right||null!==o.left?(r(c=null===o.right?o.left:null===o.left?o.right:t[a]<o.obj[a]?o.left:o.right),(s.size()<e||u<s.peek()[1])&&p(o,u),(s.size()<e||Math.abs(l)<s.peek()[1])&&null!==(f=c===o.left?o.right:o.left)&&r(f)):(s.size()<e||u<s.peek()[1])&&p(o,u)}(this.root);const a=[];for(o=0;o<Math.min(e,s.content.length);o+=1)s.content[o][0]&&a.push([s.content[o][0].obj,s.content[o][1]]);return a}}function toJSONImpl(t){const e=new Node(t.obj,t.dimension,null);return t.left&&(e.left=toJSONImpl(t.left)),t.right&&(e.right=toJSONImpl(t.right)),e}function buildTree(t,e,r,n){const i=e%n.length;if(0===t.length)return null;if(1===t.length)return new Node(t[0],i,r);t.sort(((t,e)=>t[n[i]]-e[n[i]]));const o=Math.floor(t.length/2),s=new Node(t[o],i,r);return s.left=buildTree(t.slice(0,o),e+1,s,n),s.right=buildTree(t.slice(o+1),e+1,s,n),s}function restoreParent(t){t.left&&(t.left.parent=t,restoreParent(t.left)),t.right&&(t.right.parent=t,restoreParent(t.right))}class BinaryHeap{constructor(t){this.content=[],this.scoreFunction=t}push(t){this.content.push(t),this.bubbleUp(this.content.length-1)}pop(){var t=this.content[0],e=this.content.pop();return this.content.length>0&&(this.content[0]=e,this.sinkDown(0)),t}peek(){return this.content[0]}size(){return this.content.length}bubbleUp(t){for(var e=this.content[t];t>0;){const r=Math.floor((t+1)/2)-1,n=this.content[r];if(!(this.scoreFunction(e)<this.scoreFunction(n)))break;this.content[r]=e,this.content[t]=n,t=r}}sinkDown(t){for(var e=this.content.length,r=this.content[t],n=this.scoreFunction(r);;){var i=2*(t+1),o=i-1,s=null;if(o<e){var a=this.content[o],u=this.scoreFunction(a);u<n&&(s=o)}if(i<e){var h=this.content[i];this.scoreFunction(h)<(null===s?n:u)&&(s=i)}if(null===s)break;this.content[t]=this.content[s],this.content[s]=r,t=s}}}class KNN{constructor(t,e,r={}){if(!0===t){const t=e;return this.kdTree=new KDTree(t.kdTree,r),this.k=t.k,this.classes=new Set(t.classes),void(this.isEuclidean=t.isEuclidean)}const n=new Set(e),{distance:i=euclidean_1,k:o=n.size+1}=r,s=new Array(t.length);for(var a=0;a<s.length;++a)s[a]=t[a].slice();for(a=0;a<e.length;++a)s[a].push(e[a]);this.kdTree=new KDTree(s,i),this.k=o,this.classes=n,this.isEuclidean=i===euclidean_1}static load(t,e=euclidean_1){if("KNN"!==t.name)throw new Error("invalid model: "+t.name);if(!t.isEuclidean&&e===euclidean_1)throw new Error("a custom distance function was used to create the model. Please provide it again");if(t.isEuclidean&&e!==euclidean_1)throw new Error("the model was created with the default distance function. Do not load it with another one");return new KNN(!0,t,e)}toJSON(){return{name:"KNN",kdTree:this.kdTree,k:this.k,classes:Array.from(this.classes),isEuclidean:this.isEuclidean}}predict(t){if(Array.isArray(t)){if("number"==typeof t[0])return getSinglePrediction(this,t);if(Array.isArray(t[0])&&"number"==typeof t[0][0]){const r=new Array(t.length);for(var e=0;e<t.length;e++)r[e]=getSinglePrediction(this,t[e]);return r}}throw new TypeError("dataset to predict must be an array or a matrix")}}function getSinglePrediction(t,e){var r=t.kdTree.nearest(e,t.k),n={},i=-1,o=-1,s=r[0][0].length-1;for(var a of t.classes)n[a]=0;for(var u=0;u<r.length;++u){var h=r[u][0][s],c=++n[h];c>o&&(i=h,o=c)}return i}var src$7=Object.freeze({default:KNN});function norm(t){return Math.sqrt(t.clone().apply(pow2array).sum())}function pow2array(t,e){return this[t][e]=this[t][e]*this[t][e],this}function initializeMatrices(t,e){if(e)for(var r=0;r<t.length;++r)for(var n=0;n<t[r].length;++n){var i=t[r][n];t[r][n]=null!==i?new Matrix$1(t[r][n]):void 0}else for(r=0;r<t.length;++r)t[r]=new Matrix$1(t[r]);return t}class PLS{constructor(t,e){if(!0===t)this.meanX=e.meanX,this.stdDevX=e.stdDevX,this.meanY=e.meanY,this.stdDevY=e.stdDevY,this.PBQ=Matrix$1.checkMatrix(e.PBQ),this.R2X=e.R2X,this.scale=e.scale,this.scaleMethod=e.scaleMethod,this.tolerance=e.tolerance;else{var{tolerance:r=1e-5,scale:n=!0}=t;this.tolerance=r,this.scale=n,this.latentVectors=t.latentVectors}}train(t,e){if(t=Matrix$1.checkMatrix(t),e=Matrix$1.checkMatrix(e),t.length!==e.length)throw new RangeError("The number of X rows must be equal to the number of Y rows");this.meanX=matrix.mean(t),this.stdDevX=matrix.standardDeviation(t,this.meanX,!0),this.meanY=matrix.mean(e),this.stdDevY=matrix.standardDeviation(e,this.meanY,!0),this.scale&&(t=t.clone().subRowVector(this.meanX).divRowVector(this.stdDevX),e=e.clone().subRowVector(this.meanY).divRowVector(this.stdDevY)),void 0===this.latentVectors&&(this.latentVectors=Math.min(t.length-1,t[0].length));for(var r=t.rows,n=t.columns,i=e.rows,o=e.columns,s=t.clone().mul(t).sum(),a=e.clone().mul(e).sum(),u=this.tolerance,h=this.latentVectors,c=Matrix$1.zeros(r,h),l=Matrix$1.zeros(n,h),f=Matrix$1.zeros(i,h),m=Matrix$1.zeros(o,h),p=Matrix$1.zeros(h,h),d=l.clone(),g=0;norm(e)>u&&g<h;){for(var v=t.transpose(),w=e.transpose(),y=maxSumColIndex(t.clone().mulM(t)),b=maxSumColIndex(e.clone().mulM(e)),x=t.getColumnVector(y),M=e.getColumnVector(b),_=Matrix$1.zeros(r,1);norm(x.clone().sub(_))>u;){var $=v.mmul(M);$.div(norm($)),_=x,x=t.mmul($);var S=w.mmul(x);S.div(norm(S)),M=e.mmul(S)}_=x;var R=v.mmul(_),E=_.transpose().mmul(_)[0][0],C=R.div(E),k=norm(C);C.div(k),_.mul(k),$.mul(k),R=M.transpose().mmul(_),E=_.transpose().mmul(_)[0][0];var A=R.div(E)[0][0];t.sub(_.mmul(C.transpose())),e.sub(_.clone().mul(A).mmul(S.transpose())),c.setColumn(g,_),l.setColumn(g,C),f.setColumn(g,M),m.setColumn(g,S),d.setColumn(g,$),p[g][g]=A,g++}g--,c=c.subMatrix(0,c.rows-1,0,g),l=l.subMatrix(0,l.rows-1,0,g),f=f.subMatrix(0,f.rows-1,0,g),m=m.subMatrix(0,m.rows-1,0,g),d=d.subMatrix(0,d.rows-1,0,g),p=p.subMatrix(0,g,0,g),this.ssqYcal=a,this.E=t,this.F=e,this.T=c,this.P=l,this.U=f,this.Q=m,this.W=d,this.B=p,this.PBQ=l.mmul(p).mmul(m.transpose()),this.R2X=_.transpose().mmul(_).mmul(C.transpose().mmul(C)).div(s)[0][0]}predict(t){var e=Matrix$1.checkMatrix(t);this.scale&&(e=e.subRowVector(this.meanX).divRowVector(this.stdDevX));var r=e.mmul(this.PBQ);return r=r.mulRowVector(this.stdDevY).addRowVector(this.meanY)}getExplainedVariance(){return this.R2X}toJSON(){return{name:"PLS",R2X:this.R2X,meanX:this.meanX,stdDevX:this.stdDevX,meanY:this.meanY,stdDevY:this.stdDevY,PBQ:this.PBQ,tolerance:this.tolerance,scale:this.scale}}static load(t){if("PLS"!==t.name)throw new RangeError("Invalid model: "+t.name);return new PLS(!0,t)}}function maxSumColIndex(t){return t.sum("column").maxIndex()[0]}class KOPLS{constructor(t,e){if(!0===t)this.trainingSet=new Matrix$1(e.trainingSet),this.YLoadingMat=new Matrix$1(e.YLoadingMat),this.SigmaPow=new Matrix$1(e.SigmaPow),this.YScoreMat=new Matrix$1(e.YScoreMat),this.predScoreMat=initializeMatrices(e.predScoreMat,!1),this.YOrthLoadingVec=initializeMatrices(e.YOrthLoadingVec,!1),this.YOrthEigen=e.YOrthEigen,this.YOrthScoreMat=initializeMatrices(e.YOrthScoreMat,!1),this.toNorm=initializeMatrices(e.toNorm,!1),this.TURegressionCoeff=initializeMatrices(e.TURegressionCoeff,!1),this.kernelX=initializeMatrices(e.kernelX,!0),this.kernel=e.kernel,this.orthogonalComp=e.orthogonalComp,this.predictiveComp=e.predictiveComp;else{if(void 0===t.predictiveComponents)throw new RangeError("no predictive components found!");if(void 0===t.orthogonalComponents)throw new RangeError("no orthogonal components found!");if(void 0===t.kernel)throw new RangeError("no kernel found!");this.orthogonalComp=t.orthogonalComponents,this.predictiveComp=t.predictiveComponents,this.kernel=t.kernel}}train(t,e){t=Matrix$1.checkMatrix(t),e=Matrix$1.checkMatrix(e),this.trainingSet=t.clone();var r=this.kernel.compute(t),n=Matrix$1.eye(r.rows,r.rows,1),i=r;(r=new Matrix$1(this.orthogonalComp+1,this.orthogonalComp+1))[0][0]=i;var o=new SingularValueDecomposition$$1(e.transpose().mmul(r[0][0]).mmul(e),{computeLeftSingularVectors:!0,computeRightSingularVectors:!1}),s=o.leftSingularVectors,a=o.diagonalMatrix;s=s.subMatrix(0,s.rows-1,0,this.predictiveComp-1),a=a.subMatrix(0,this.predictiveComp-1,0,this.predictiveComp-1);var u=e.mmul(s),h=new Array(this.orthogonalComp+1),c=new Array(this.orthogonalComp+1),l=new Array(this.orthogonalComp),f=new Array(this.orthogonalComp),m=new Array(this.orthogonalComp),p=new Array(this.orthogonalComp),d=Matrix$1.pow(a,-.5);d.apply((function(t,e){this[t][e]===1/0&&(this[t][e]=0)}));for(var g=0;g<this.orthogonalComp;++g){h[g]=r[0][g].transpose().mmul(u).mmul(d);var v=h[g].transpose();c[g]=inverse$$1(v.mmul(h[g])).mmul(v).mmul(u);var w=(o=new SingularValueDecomposition$$1(v.mmul(Matrix$1.sub(r[g][g],h[g].mmul(v))).mmul(h[g]),{computeLeftSingularVectors:!0,computeRightSingularVectors:!1})).leftSingularVectors,y=o.diagonalMatrix;f[g]=w.subMatrix(0,w.rows-1,0,0),m[g]=y[0][0],l[g]=Matrix$1.sub(r[g][g],h[g].mmul(v)).mmul(h[g]).mmul(f[g]).mul(Math.pow(m[g],-.5));var b=l[g].transpose();p[g]=Matrix$1.sqrt(b.mmul(l[g])),l[g]=l[g].divRowVector(p[g]);var x=Matrix$1.sub(n,l[g].mmul(l[g].transpose()));r[0][g+1]=r[0][g].mmul(x),r[g+1][g+1]=x.mmul(r[g][g]).mmul(x)}var M=h[this.orthogonalComp]=r[0][this.orthogonalComp].transpose().mmul(u).mmul(d),_=M.transpose();c[this.orthogonalComp]=inverse$$1(_.mmul(M)).mmul(_).mmul(u),this.YLoadingMat=s,this.SigmaPow=d,this.YScoreMat=u,this.predScoreMat=h,this.YOrthLoadingVec=f,this.YOrthEigen=m,this.YOrthScoreMat=l,this.toNorm=p,this.TURegressionCoeff=c,this.kernelX=r}predict(t){var e=this.kernel.compute(t,this.trainingSet),r=e;(e=new Matrix$1(this.orthogonalComp+1,this.orthogonalComp+1))[0][0]=r;var n,i=new Array(this.orthogonalComp),o=new Array(this.orthogonalComp);for(n=0;n<this.orthogonalComp;++n){o[n]=e[n][0].mmul(this.YScoreMat).mmul(this.SigmaPow),i[n]=Matrix$1.sub(e[n][n],o[n].mmul(this.predScoreMat[n].transpose())).mmul(this.predScoreMat[n]).mmul(this.YOrthLoadingVec[n]).mul(Math.pow(this.YOrthEigen[n],-.5)),i[n]=i[n].divRowVector(this.toNorm[n]);var s=this.YOrthScoreMat[n].transpose();e[n+1][0]=Matrix$1.sub(e[n][0],i[n].mmul(s).mmul(this.kernelX[0][n].transpose()));var a=Matrix$1.sub(e[n][0],e[n][n].mmul(this.YOrthScoreMat[n]).mmul(s)),u=i[n].mmul(s).mmul(this.kernelX[n][n]),h=u.mmul(this.YOrthScoreMat[n]).mmul(s);e[n+1][n+1]=a.sub(u).add(h)}return o[n]=e[n][0].mmul(this.YScoreMat).mmul(this.SigmaPow),{prediction:o[n].mmul(this.TURegressionCoeff[n]).mmul(this.YLoadingMat.transpose()),predScoreMat:o,predYOrthVectors:i}}toJSON(){return{name:"K-OPLS",YLoadingMat:this.YLoadingMat,SigmaPow:this.SigmaPow,YScoreMat:this.YScoreMat,predScoreMat:this.predScoreMat,YOrthLoadingVec:this.YOrthLoadingVec,YOrthEigen:this.YOrthEigen,YOrthScoreMat:this.YOrthScoreMat,toNorm:this.toNorm,TURegressionCoeff:this.TURegressionCoeff,kernelX:this.kernelX,trainingSet:this.trainingSet,orthogonalComp:this.orthogonalComp,predictiveComp:this.predictiveComp}}static load(t,e){if("K-OPLS"!==t.name)throw new RangeError("Invalid model: "+t.name);if(!e)throw new RangeError("You must provide a kernel for the model!");return t.kernel=e,new KOPLS(!0,t)}}var src$8=Object.freeze({PLS:PLS,KOPLS:KOPLS});class ConfusionMatrix{constructor(t,e){if(t.length!==t[0].length)throw new Error("Confusion matrix must be square");if(e.length!==t.length)throw new Error("Confusion matrix and labels should have the same length");this.labels=e,this.matrix=t}static fromLabels(t,e,r={}){if(e.length!==t.length)throw new Error("predicted and actual must have the same length");let n;n=r.labels?new Set(r.labels):new Set([...t,...e]),n=Array.from(n),r.sort&&n.sort(r.sort);const i=Array.from({length:n.length});for(let t=0;t<i.length;t++)i[t]=new Array(i.length),i[t].fill(0);for(let r=0;r<e.length;r++){const o=n.indexOf(t[r]),s=n.indexOf(e[r]);o>=0&&s>=0&&i[o][s]++}return new ConfusionMatrix(i,n)}getMatrix(){return this.matrix}getLabels(){return this.labels}getTotalCount(){let t=0;for(var e=0;e<this.matrix.length;e++)for(var r=0;r<this.matrix.length;r++)t+=this.matrix[e][r];return t}getTrueCount(){for(var t=0,e=0;e<this.matrix.length;e++)t+=this.matrix[e][e];return t}getFalseCount(){return this.getTotalCount()-this.getTrueCount()}getTruePositiveCount(t){const e=this.getIndex(t);return this.matrix[e][e]}getTrueNegativeCount(t){const e=this.getIndex(t);for(var r=0,n=0;n<this.matrix.length;n++)for(var i=0;i<this.matrix.length;i++)n!==e&&i!==e&&(r+=this.matrix[n][i]);return r}getFalsePositiveCount(t){const e=this.getIndex(t);for(var r=0,n=0;n<this.matrix.length;n++)n!==e&&(r+=this.matrix[n][e]);return r}getFalseNegativeCount(t){const e=this.getIndex(t);for(var r=0,n=0;n<this.matrix.length;n++)n!==e&&(r+=this.matrix[e][n]);return r}getPositiveCount(t){return this.getTruePositiveCount(t)+this.getFalseNegativeCount(t)}getNegativeCount(t){return this.getTrueNegativeCount(t)+this.getFalsePositiveCount(t)}getIndex(t){const e=this.labels.indexOf(t);if(-1===e)throw new Error("The label does not exist");return e}getTruePositiveRate(t){return this.getTruePositiveCount(t)/this.getPositiveCount(t)}getTrueNegativeRate(t){return this.getTrueNegativeCount(t)/this.getNegativeCount(t)}getPositivePredictiveValue(t){const e=this.getTruePositiveCount(t);return e/(e+this.getFalsePositiveCount(t))}getNegativePredictiveValue(t){const e=this.getTrueNegativeCount(t);return e/(e+this.getFalseNegativeCount(t))}getFalseNegativeRate(t){return 1-this.getTruePositiveRate(t)}getFalsePositiveRate(t){return 1-this.getTrueNegativeRate(t)}getFalseDiscoveryRate(t){const e=this.getFalsePositiveCount(t);return e/(e+this.getTruePositiveCount(t))}getFalseOmissionRate(t){const e=this.getFalseNegativeCount(t);return e/(e+this.getTruePositiveCount(t))}getF1Score(t){const e=this.getTruePositiveCount(t);return 2*e/(2*e+this.getFalsePositiveCount(t)+this.getFalseNegativeCount(t))}getMatthewsCorrelationCoefficient(t){const e=this.getTruePositiveCount(t),r=this.getTrueNegativeCount(t),n=this.getFalsePositiveCount(t),i=this.getFalseNegativeCount(t);return(e*r-n*i)/Math.sqrt((e+n)*(e+i)*(r+n)*(r+i))}getInformedness(t){return this.getTruePositiveRate(t)+this.getTrueNegativeRate(t)-1}getMarkedness(t){return this.getPositivePredictiveValue(t)+this.getNegativePredictiveValue(t)-1}getConfusionTable(t){return[[this.getTruePositiveCount(t),this.getFalseNegativeCount(t)],[this.getFalsePositiveCount(t),this.getTrueNegativeCount(t)]]}getAccuracy(){let t=0,e=0;for(var r=0;r<this.matrix.length;r++)for(var n=0;n<this.matrix.length;n++)r===n?t+=this.matrix[r][n]:e+=this.matrix[r][n];return t/(t+e)}getCount(t,e){const r=this.getIndex(t),n=this.getIndex(e);return this.matrix[r][n]}get accuracy(){return this.getAccuracy()}get total(){return this.getTotalCount()}}var src$9=ConfusionMatrix;const defaultOptions$j={mode:"index"};var src$a=function*(t,e,r){r=Object.assign({},defaultOptions$j,r);for(var n,i,o,s=new Array(e),a=new Array(t),u=new Array(e),h=new Array(e+2),c=0;c<e;c++)s[c]=c,u[c]=c<e-t?0:1;for(c=0;c<t;c++)a[c]=e-t+c;for(c=0;c<h.length;c++)h[c]=0===c?e+1:c<=e-t?0:c<=e?c-e+t:-2;function l(){var t,e,r;for(e=1;h[e]<=0;)e++;if(0===h[e-1]){for(t=e-1;1!==t;t--)h[t]=-1;h[e]=0,n=o=0,h[1]=1,i=e-1}else{e>1&&(h[e-1]=0);do{e++}while(h[e]>0);for(r=e-1,t=e;0===h[t];)h[t++]=-1;if(-1===h[t])h[t]=h[r],o=h[r]-1,n=t-1,i=r-1,h[r]=-1;else{if(t===h[0])return 0;h[e]=h[t],o=h[t]-1,h[t]=0,n=e-1,i=t-1}}return 1}if("index"===r.mode)for(yield a.slice();l();)a[o]=s[n],yield a.slice();else{if("mask"!==r.mode)throw new Error("Invalid mode");for(yield u.slice();l();)u[n]=1,u[i]=0,yield u.slice()}};const CV={};function check(t,e){if(t.length!==e.length)throw new Error("features and labels should have the same length")}function initMatrix(t,e){return new Array(t).fill(0).map((()=>new Array(e).fill(0)))}function getDistinct(t){var e=new Set;for(let r=0;r<t.length;r++)e.add(t[r]);return Array.from(e)}function validate(t,e,r,n,i,o,s,a){const{testFeatures:u,trainFeatures:h,testLabels:c,trainLabels:l}=getTrainTest(e,r,i,o);var f;t.prototype.train?(f=new t(n)).train(h,l):f=new t(h,l,n),updateConfusionMatrix(s,c,f.predict(u),a)}function validateWithCallback(t,e,r,n,i,o,s){const{testFeatures:a,trainFeatures:u,testLabels:h,trainLabels:c}=getTrainTest(t,e,r,n);updateConfusionMatrix(i,h,s(u,c,a),o)}function updateConfusionMatrix(t,e,r,n){for(var i=0;i<r.length;i++){const o=n.indexOf(e[i]),s=n.indexOf(r[i]);(o<0||s<0)&&console.warn(`ignore unknown predicted label ${r[i]}`),t[o][s]++}}function getTrainTest(t,e,r,n){return{testFeatures:r.map((function(e){return t[e]})),trainFeatures:n.map((function(e){return t[e]})),testLabels:r.map((function(t){return e[t]})),trainLabels:n.map((function(t){return e[t]}))}}CV.leaveOneOut=function(t,e,r,n){if("function"==typeof r){var i=r;return r=e,e=t,CV.leavePOut(e,r,1,i)}return CV.leavePOut(t,e,r,n,1)},CV.leavePOut=function(t,e,r,n,i){if("function"==typeof n){var o=n;i=r,r=e,e=t}check(e,r);const s=getDistinct(r),a=initMatrix(s.length,s.length);var u=e.length,h=src$a(i,u),c=new Array(u);for(let t=0;t<u;t++)c[t]=t;for(const i of h){var l=c.slice();for(let t=i.length-1;t>=0;t--)l.splice(i[t],1);o?validateWithCallback(e,r,i,l,a,s,o):validate(t,e,r,n,i,l,a,s)}return new src$9(a,s)},CV.kFold=function(t,e,r,n,i){if("function"==typeof n){var o=n;i=r,r=e,e=t}check(e,r);const s=getDistinct(r),a=initMatrix(s.length,s.length);for(var u=e.length,h=new Array(u),c=0;c<u;c++)h[c]=c;for(var l=Math.floor(u/i),f=[],m=[];h.length;){var p=Math.floor(Math.random()*h.length);f.push(h[p]),h.splice(p,1),f.length===l&&(m.push(f),f=[])}for(f.length&&m.push(f),m=m.slice(0,i),c=0;c<m.length;c++){for(var d=m[c],g=[],v=0;v<m.length;v++)v!==c&&(g=g.concat(m[v]));o?validateWithCallback(e,r,d,g,a,s,o):validate(t,e,r,n,d,g,a,s)}return new src$9(a,s)};var src$b=CV,Matrix$6=require$$0$3.Matrix;function sumRow(t){for(var e=Matrix$6.zeros(t.rows,1),r=0;r<t.rows;++r)for(var n=0;n<t.columns;++n)e[r][0]+=t[r][n];return e}function sumCol(t){for(var e=Matrix$6.zeros(1,t.columns),r=0;r<t.rows;++r)for(var n=0;n<t.columns;++n)e[0][n]+=t[r][n];return e}function dictOutputs(t){for(var e={},r={},n=0,i=0;i<t.length;i+=1)void 0===e[t[i]]&&(e[t[i]]=n,r[n]=t[i],n++);return{inputs:e,outputs:r}}var utils$1={dictOutputs:dictOutputs,sumCol:sumCol,sumRow:sumRow};function logistic(t){return 1/(1+Math.exp(-t))}function expELU(t,e){return t<0?e*(Math.exp(t)-1):t}function softExponential(t,e){return e<0?-Math.log(1-e*(t+e))/e:e>0?(Math.exp(e*t)-1)/e+e:t}function softExponentialPrime(t,e){return e<0?1/(1-e*(e+t)):Math.exp(e*t)}const ACTIVATION_FUNCTIONS={tanh:{activation:Math.tanh,derivate:t=>1-t*t},identity:{activation:t=>t,derivate:()=>1},logistic:{activation:logistic,derivate:t=>logistic(t)*(1-logistic(t))},arctan:{activation:Math.atan,derivate:t=>1/(t*t+1)},softsign:{activation:t=>t/(1+Math.abs(t)),derivate:t=>1/((1+Math.abs(t))*(1+Math.abs(t)))},relu:{activation:t=>t<0?0:t,derivate:t=>t<0?0:1},softplus:{activation:t=>Math.log(1+Math.exp(t)),derivate:t=>1/(1+Math.exp(-t))},bent:{activation:t=>(Math.sqrt(t*t+1)-1)/2+t,derivate:t=>t/(2*Math.sqrt(t*t+1))+1},sinusoid:{activation:Math.sin,derivate:Math.cos},sinc:{activation:t=>0===t?1:Math.sin(t)/t,derivate:t=>0===t?0:Math.cos(t)/t-Math.sin(t)/(t*t)},gaussian:{activation:t=>Math.exp(-t*t),derivate:t=>-2*t*Math.exp(-t*t)},"parametric-relu":{activation:(t,e)=>t<0?e*t:t,derivate:(t,e)=>t<0?e:1},"exponential-elu":{activation:expELU,derivate:(t,e)=>t<0?expELU(t,e)+e:1},"soft-exponential":{activation:softExponential,derivate:softExponentialPrime}};var activationFunctions=ACTIVATION_FUNCTIONS,Matrix$7=require$$0$3.Matrix;class Layer{constructor(t){this.inputSize=t.inputSize,this.outputSize=t.outputSize,this.regularization=t.regularization,this.epsilon=t.epsilon,this.activation=t.activation,this.activationParam=t.activationParam;var e=activationFunctions[t.activation],r=e.activation.length,n=r>1?r=>e.activation(r,t.activationParam):e.activation,i=r>1?r=>e.derivate(r,t.activationParam):e.derivate;this.activationFunction=function(t,e){this[t][e]=n(this[t][e])},this.derivate=function(t,e){this[t][e]=i(this[t][e])},t.model?(this.W=Matrix$7.checkMatrix(t.W),this.b=Matrix$7.checkMatrix(t.b)):(this.W=Matrix$7.rand(this.inputSize,this.outputSize),this.b=Matrix$7.zeros(1,this.outputSize),this.W.apply((function(e,r){this[e][r]/=Math.sqrt(t.inputSize)})))}forward(t){var e=t.mmul(this.W).addRowVector(this.b);return e.apply(this.activationFunction),this.a=e.clone(),e}backpropagation(t,e){this.dW=e.transposeView().mmul(t),this.db=utils$1.sumCol(t);var r=e.clone();return t.mmul(this.W.transposeView()).mul(r.apply(this.derivate))}update(){this.dW.add(this.W.clone().mul(this.regularization)),this.W.add(this.dW.mul(-this.epsilon)),this.b.add(this.db.mul(-this.epsilon))}toJSON(){return{model:"Layer",inputSize:this.inputSize,outputSize:this.outputSize,regularization:this.regularization,epsilon:this.epsilon,activation:this.activation,W:this.W,b:this.b}}static load(t){if("Layer"!==t.model)throw new RangeError("the current model is not a Layer model");return new Layer(t)}}var Layer_1=Layer;class OutputLayer extends Layer_1{constructor(t){super(t),this.activationFunction=function(t,e){this[t][e]=Math.exp(this[t][e])}}static load(t){if("Layer"!==t.model)throw new RangeError("the current model is not a Layer model");return new OutputLayer(t)}}var OutputLayer_1=OutputLayer;const Matrix$8=require$$0$3.Matrix;class FeedForwardNeuralNetworks{constructor(t){if((t=t||{}).model){this.hiddenLayers=t.hiddenLayers,this.iterations=t.iterations,this.learningRate=t.learningRate,this.regularization=t.regularization,this.dicts=t.dicts,this.activation=t.activation,this.activationParam=t.activationParam,this.model=new Array(t.layers.length);for(var e=0;e<this.model.length-1;++e)this.model[e]=Layer_1.load(t.layers[e]);this.model[this.model.length-1]=OutputLayer_1.load(t.layers[this.model.length-1])}else this.hiddenLayers=t.hiddenLayers||[10],this.iterations=t.iterations||50,this.learningRate=t.learningRate||.01,this.regularization=t.regularization||.01,this.activation=t.activation||"tanh",this.activationParam=t.activationParam||1,this.activation in Object.keys(activationFunctions)||(this.activation="tanh")}buildNetwork(t,e){var r=this.hiddenLayers.length-1+2;this.model=new Array(r),this.model[0]=new Layer_1({inputSize:t,outputSize:this.hiddenLayers[0],activation:this.activation,activationParam:this.activationParam,regularization:this.regularization,epsilon:this.learningRate});for(var n=1;n<this.hiddenLayers.length;++n)this.model[n]=new Layer_1({inputSize:this.hiddenLayers[n-1],outputSize:this.hiddenLayers[n],activation:this.activation,activationParam:this.activationParam,regularization:this.regularization,epsilon:this.learningRate});this.model[r-1]=new OutputLayer_1({inputSize:this.hiddenLayers[this.hiddenLayers.length-1],outputSize:e,activation:this.activation,activationParam:this.activationParam,regularization:this.regularization,epsilon:this.learningRate})}train(t,e){t=Matrix$8.checkMatrix(t),this.dicts=utils$1.dictOutputs(e);var r=t.columns,n=Object.keys(this.dicts.inputs).length;this.buildNetwork(r,n);for(var i=0;i<this.iterations;++i){var o=this.propagate(t);this.backpropagation(t,e,o)}}propagate(t){for(var e=t,r=0;r<this.model.length;++r)e=this.model[r].forward(e);return e.divColumnVector(utils$1.sumRow(e))}backpropagation(t,e,r){for(var n=0;n<r.length;++n)r[n][this.dicts.inputs[e[n]]]-=1;var i=r;for(n=this.model.length-1;n>=0;--n){var o=n>0?this.model[n-1].a:t;i=this.model[n].backpropagation(i,o)}for(n=0;n<this.model.length;++n)this.model[n].update()}predict(t){t=Matrix$8.checkMatrix(t);for(var e=new Array(t.rows),r=this.propagate(t),n=0;n<t.rows;++n)e[n]=this.dicts.outputs[r.maxRowIndex(n)[1]];return e}toJSON(){for(var t={model:"FNN",hiddenLayers:this.hiddenLayers,iterations:this.iterations,learningRate:this.learningRate,regularization:this.regularization,activation:this.activation,activationParam:this.activationParam,dicts:this.dicts,layers:new Array(this.model.length)},e=0;e<this.model.length;++e)t.layers[e]=this.model[e].toJSON();return t}static load(t){if("FNN"!==t.model)throw new RangeError("the current model is not a feed forward network");return new FeedForwardNeuralNetworks(t)}}var FeedForwardNeuralNetwork=FeedForwardNeuralNetworks;function NodeSquare(t,e,r,n){this.x=t,this.y=e,this.weights=r,this.som=n,this.neighbors={}}NodeSquare.prototype.adjustWeights=function(t,e,r){for(var n=0,i=this.weights.length;n<i;n++)this.weights[n]+=e*r*(t[n]-this.weights[n])},NodeSquare.prototype.getDistance=function(t){return Math.max(Math.abs(this.x-t.x),Math.abs(this.y-t.y))},NodeSquare.prototype.getDistanceTorus=function(t){var e=Math.abs(this.x-t.x),r=Math.abs(this.y-t.y);return Math.max(Math.min(e,this.som.gridDim.x-e),Math.min(r,this.som.gridDim.y-r))},NodeSquare.prototype.getNeighbors=function(t){if(!this.neighbors[t]){var e,r,n,i;if(this.neighbors[t]=new Array(2),this[t]>0?e=this[t]-1:this.som.torus&&(e=this.som.gridDim[t]-1),void 0!==e)"x"===t?(r=e,n=this.y):(r=this.x,n=e),this.neighbors[t][0]=this.som.nodes[r][n];this[t]<this.som.gridDim[t]-1?i=this[t]+1:this.som.torus&&(i=0),void 0!==i&&("x"===t?(r=i,n=this.y):(r=this.x,n=i),this.neighbors[t][1]=this.som.nodes[r][n])}return this.neighbors[t]},NodeSquare.prototype.getPos=function(t,e){var r,n,i=this.getNeighbors(t),o=this.som.distance;i[0]?i[1]?o(e,i[0].weights)<o(e,i[1].weights)?(r=i[0],n=-1):(r=i[1],n=1):(r=i[0],n=-1):(r=i[1],n=1);var s=1-o(e,this.weights),a=1-o(e,r.weights);return.5+.5*((s-a)/(2-s-a))*n},NodeSquare.prototype.getPosition=function(t){return[this.getPos("x",t),this.getPos("y",t)]};var nodeSquare=NodeSquare;function NodeHexagonal(t,e,r,n){nodeSquare.call(this,t,e,r,n),this.hX=t-Math.floor(e/2),this.z=0-this.hX-e}NodeHexagonal.prototype=new nodeSquare,NodeHexagonal.prototype.constructor=NodeHexagonal,NodeHexagonal.prototype.getDistance=function(t){return Math.max(Math.abs(this.hX-t.hX),Math.abs(this.y-t.y),Math.abs(this.z-t.z))},NodeHexagonal.prototype.getDistanceTorus=function(t){var e=Math.abs(this.hX-t.hX),r=Math.abs(this.y-t.y),n=Math.abs(this.z-t.z);return Math.max(Math.min(e,this.som.gridDim.x-e),Math.min(r,this.som.gridDim.y-r),Math.min(n,this.som.gridDim.z-n))},NodeHexagonal.prototype.getPosition=function(){throw new Error("Unimplemented : cannot get position of the points for hexagonal grid")};var nodeHexagonal=NodeHexagonal,defaultOptions$k={fields:3,randomizer:Math.random,distance:squareEuclidean,iterations:10,learningRate:.1,gridType:"rect",torus:!0,method:"random"};function SOM(t,e,r,n){for(var i in this.x=t,this.y=e,r=r||{},this.options={},defaultOptions$k)r.hasOwnProperty(i)?this.options[i]=r[i]:this.options[i]=defaultOptions$k[i];if("number"==typeof this.options.fields)this.numWeights=this.options.fields;else{if(!Array.isArray(this.options.fields))throw new Error("Invalid fields definition");this.numWeights=this.options.fields.length;var o=getConverters(this.options.fields);this.extractor=o.extractor,this.creator=o.creator}if("rect"===this.options.gridType)this.nodeType=nodeSquare,this.gridDim={x:t,y:e};else{this.nodeType=nodeHexagonal;var s=this.x-Math.floor(this.y/2);this.gridDim={x:s,y:this.y,z:-(0-s-this.y)}}if(this.torus=this.options.torus,this.distanceMethod=this.torus?"getDistanceTorus":"getDistance",this.distance=this.options.distance,this.maxDistance=getMaxDistance(this.distance,this.numWeights),!0!==n){if(!(t>0&&e>0))throw new Error("x and y must be positive");this.times={findBMU:0,adjust:0},this.randomizer=this.options.randomizer,this.iterationCount=0,this.iterations=this.options.iterations,this.startLearningRate=this.learningRate=this.options.learningRate,this.mapRadius=Math.floor(Math.max(t,e)/2),this.algorithmMethod=this.options.method,this._initNodes(),this.done=!1}else this.done=!0}function getConverters(t){for(var e=t.length,r=new Array(e),n=new Array(e),i=0;i<e;i++)r[i]=getNormalizer(t[i].range),n[i]=getDenormalizer(t[i].range);return{extractor:function(n){for(var i=new Array(e),o=0;o<e;o++)i[o]=r[o](n[t[o].name]);return i},creator:function(r){for(var i={},o=0;o<e;o++)i[t[o].name]=n[o](r[o]);return i}}}function getNormalizer(t){return function(e){return(e-t[0])/(t[1]-t[0])}}function getDenormalizer(t){return function(e){return t[0]+e*(t[1]-t[0])}}function squareEuclidean(t,e){for(var r=0,n=0,i=t.length;n<i;n++)r+=(t[n]-e[n])*(t[n]-e[n]);return r}function getRandomValue(t,e){return t[Math.floor(e()*t.length)]}function getMaxDistance(t,e){for(var r=new Array(e),n=new Array(e),i=0;i<e;i++)r[i]=0,n[i]=1;return t(r,n)}SOM.load=function loadModel(model,distance){if("SOM"===model.name){var x=model.data.length,y=model.data[0].length;distance?model.options.distance=distance:model.options.distance&&(model.options.distance=eval("("+model.options.distance+")"));var som=new SOM(x,y,model.options,!0);som.nodes=new Array(x);for(var i=0;i<x;i++){som.nodes[i]=new Array(y);for(var j=0;j<y;j++)som.nodes[i][j]=new som.nodeType(i,j,model.data[i][j],som)}return som}throw new Error("expecting a SOM model")},SOM.prototype.export=function(t){if(!this.done)throw new Error("model is not ready yet");var e={name:"SOM"};e.options={fields:this.options.fields,gridType:this.options.gridType,torus:this.options.torus},e.data=new Array(this.x);for(var r=0;r<this.x;r++){e.data[r]=new Array(this.y);for(var n=0;n<this.y;n++)e.data[r][n]=this.nodes[r][n].weights}return t&&(e.options.distance=this.distance.toString()),e},SOM.prototype._initNodes=function(){var t,e,r,n=Date.now();for(this.nodes=new Array(this.x),t=0;t<this.x;t++)for(this.nodes[t]=new Array(this.y),e=0;e<this.y;e++){var i=new Array(this.numWeights);for(r=0;r<this.numWeights;r++)i[r]=this.randomizer();this.nodes[t][e]=new this.nodeType(t,e,i,this)}this.times.initNodes=Date.now()-n},SOM.prototype.setTraining=function(t){if(this.trainingSet)throw new Error("training set has already been set");var e,r=Date.now(),n=t,i=t.length;if(this.extractor)for(n=new Array(i),e=0;e<i;e++)n[e]=this.extractor(t[e]);this.numIterations=this.iterations*i,"random"===this.algorithmMethod?this.timeConstant=this.numIterations/Math.log(this.mapRadius):this.timeConstant=i/Math.log(this.mapRadius),this.trainingSet=n,this.times.setTraining=Date.now()-r},SOM.prototype.trainOne=function(){return!this.done&&(this.numIterations-- >0?("random"===this.algorithmMethod?(t=this.mapRadius*Math.exp(-this.iterationCount/this.timeConstant),e=getRandomValue(this.trainingSet,this.randomizer),this._adjust(e,t),this.learningRate=this.startLearningRate*Math.exp(-this.iterationCount/this.numIterations)):(r=-Math.floor(this.iterationCount/this.trainingSet.length),t=this.mapRadius*Math.exp(r/this.timeConstant),e=this.trainingSet[this.iterationCount%this.trainingSet.length],this._adjust(e,t),(this.iterationCount+1)%this.trainingSet.length==0&&(this.learningRate=this.startLearningRate*Math.exp(r/Math.floor(this.numIterations/this.trainingSet.length)))),this.iterationCount++,!0):(this.done=!0,!1));var t,e,r},SOM.prototype._adjust=function(t,e){var r,n,i,o,s=Date.now(),a=this._findBestMatchingUnit(t),u=Date.now();this.times.findBMU+=u-s;var h=Math.floor(e),c=a.x-h,l=a.x+h,f=a.y-h,m=a.y+h;for(r=c;r<=l;r++){var p=r;for(r<0?p+=this.x:r>=this.x&&(p-=this.x),n=f;n<=m;n++){var d=n;n<0?d+=this.y:n>=this.y&&(d-=this.y),(i=a[this.distanceMethod](this.nodes[p][d]))<e&&(o=Math.exp(-i/(2*e)),this.nodes[p][d].adjustWeights(t,this.learningRate,o))}}this.times.adjust+=Date.now()-u},SOM.prototype.train=function(t){if(!this.done)for(this.setTraining(t);this.trainOne(););},SOM.prototype.getConvertedNodes=function(){for(var t=new Array(this.x),e=0;e<this.x;e++){t[e]=new Array(this.y);for(var r=0;r<this.y;r++){var n=this.nodes[e][r];t[e][r]=this.creator?this.creator(n.weights):n.weights}}return t},SOM.prototype._findBestMatchingUnit=function(t){for(var e,r,n=1/0,i=0;i<this.x;i++)for(var o=0;o<this.y;o++)(r=this.distance(this.nodes[i][o].weights,t))<n&&(n=r,e=this.nodes[i][o]);return e},SOM.prototype.predict=function(t,e){if("boolean"==typeof t&&(e=t,t=null),t||(t=this.trainingSet),Array.isArray(t)&&(Array.isArray(t[0])||"object"==typeof t[0])){var r=this;return t.map((function(t){return r._predict(t,e)}))}return this._predict(t,e)},SOM.prototype._predict=function(t,e){Array.isArray(t)||(t=this.extractor(t));var r=this._findBestMatchingUnit(t),n=[r.x,r.y];return e&&(n[2]=r.getPosition(t)),n},SOM.prototype.getQuantizationError=function(){for(var t=this.getFit(),e=t.length,r=0,n=0;n<e;n++)r+=t[n];return r/e},SOM.prototype.getFit=function(t){t||(t=this.trainingSet);for(var e,r=t.length,n=new Array(r),i=0;i<r;i++)e=this._findBestMatchingUnit(t[i]),n[i]=Math.sqrt(this.distance(t[i],e.weights));return n};var src$c=SOM;function maybeToPrecision(t,e){return t<0?(t=0-t,"number"==typeof e?"- "+t.toPrecision(e):"- "+t.toString()):"number"==typeof e?t.toPrecision(e):t.toString()}function checkArraySize(t,e){if(!Array.isArray(t)||!Array.isArray(e))throw new TypeError("x and y must be arrays");if(t.length!==e.length)throw new RangeError("x and y arrays must have the same length")}class BaseRegression{constructor(){if(new.target===BaseRegression)throw new Error("BaseRegression must be subclassed")}predict(t){if("number"==typeof t)return this._predict(t);if(Array.isArray(t)){const e=new Array(t.length);for(let r=0;r<t.length;r++)e[r]=this._predict(t[r]);return e}throw new TypeError("x must be a number or array")}_predict(){throw new Error("_predict must be implemented")}train(){}toString(){return""}toLaTeX(){return""}score(t,e){if(!Array.isArray(t)||!Array.isArray(e)||t.length!==e.length)throw new Error("x and y must be arrays of the same length");const r=t.length,n=new Array(r);for(let e=0;e<r;e++)n[e]=this._predict(t[e]);let i=0,o=0,s=0,a=0,u=0,h=0,c=0;for(let t=0;t<r;t++)i+=n[t],o+=e[t],u+=n[t]*n[t],h+=e[t]*e[t],c+=n[t]*e[t],0!==e[t]&&(s+=(e[t]-n[t])*(e[t]-n[t])/e[t]),a=(e[t]-n[t])*(e[t]-n[t]);const l=(r*c-i*o)/Math.sqrt((r*u-i*i)*(r*h-o*o));return{r:l,r2:l*l,chi2:s,rmsd:a*a/r}}}class SimpleLinearRegression extends BaseRegression{constructor(t,e){super(),!0===t?(this.slope=e.slope,this.intercept=e.intercept,this.coefficients=[e.intercept,e.slope]):(checkArraySize(t,e),regress(this,t,e))}toJSON(){return{name:"simpleLinearRegression",slope:this.slope,intercept:this.intercept}}_predict(t){return this.slope*t+this.intercept}computeX(t){return(t-this.intercept)/this.slope}toString(t){let e="f(x) = ";if(0!==this.slope){const r=maybeToPrecision(this.slope,t);if(e+=("1"===r?"":r+" * ")+"x",this.intercept){const r=Math.abs(this.intercept);e+=` ${r===this.intercept?"+":"-"} ${maybeToPrecision(r,t)}`}}else e+=maybeToPrecision(this.intercept,t);return e}toLaTeX(t){return this.toString(t)}static load(t){if("simpleLinearRegression"!==t.name)throw new TypeError("not a SLR model");return new SimpleLinearRegression(!0,t)}}function regress(t,e,r){const n=e.length;let i=0,o=0,s=0,a=0;for(let t=0;t<n;t++)i+=e[t],o+=r[t],s+=e[t]*e[t],a+=e[t]*r[t];const u=n*a-i*o;t.slope=u/(n*s-i*i),t.intercept=1/n*o-t.slope*(1/n)*i,t.coefficients=[t.intercept,t.slope]}class PolynomialRegression extends BaseRegression{constructor(t,e,r){super(),!0===t?(this.degree=e.degree,this.powers=e.powers,this.coefficients=e.coefficients):(checkArraySize(t,e),regress$1(this,t,e,r))}_predict(t){let e=0;for(let r=0;r<this.powers.length;r++)e+=this.coefficients[r]*Math.pow(t,this.powers[r]);return e}toJSON(){return{name:"polynomialRegression",degree:this.degree,powers:this.powers,coefficients:this.coefficients}}toString(t){return this._toFormula(t,!1)}toLaTeX(t){return this._toFormula(t,!0)}_toFormula(t,e){let r="^",n="",i=" * ";e&&(r="^{",n="}",i="");let o="",s="";for(let e=0;e<this.coefficients.length;e++)s="",0!==this.coefficients[e]&&(s=0===this.powers[e]?maybeToPrecision(this.coefficients[e],t):1===this.powers[e]?maybeToPrecision(this.coefficients[e],t)+i+"x":maybeToPrecision(this.coefficients[e],t)+i+"x"+r+this.powers[e]+n,this.coefficients[e]>0&&e!==this.coefficients.length-1?s=" + "+s:e!==this.coefficients.length-1&&(s=" "+s)),o=s+o;return"+"===o.charAt(0)&&(o=o.slice(1)),"f(x) = "+o}static load(t){if("polynomialRegression"!==t.name)throw new TypeError("not a polynomial regression model");return new PolynomialRegression(!0,t)}}function regress$1(t,e,r,n){const i=e.length;let o;if(Array.isArray(n))o=n,n=o.length;else{n++,o=new Array(n);for(let t=0;t<n;t++)o[t]=t}const s=new Matrix$1(i,n),a=new Matrix$1([r]);for(let t=0;t<n;t++)for(let r=0;r<i;r++)0===o[t]?s[r][t]=1:s[r][t]=Math.pow(e[r],o[t]);const u=s.transposeView(),h=u.mmul(s),c=u.mmul(a.transposeView());t.degree=n-1,t.powers=o,t.coefficients=solve$$1(h,c).to1DArray()}class ExponentialRegression extends BaseRegression{constructor(t,e){super(),!0===t?(this.A=e.A,this.B=e.B):(checkArraySize(t,e),regress$2(this,t,e))}_predict(t){return this.B*Math.exp(t*this.A)}toJSON(){return{name:"exponentialRegression",A:this.A,B:this.B}}toString(t){return"f(x) = "+maybeToPrecision(this.B,t)+" * e^("+maybeToPrecision(this.A,t)+" * x)"}toLaTeX(t){return this.A>=0?"f(x) = "+maybeToPrecision(this.B,t)+"e^{"+maybeToPrecision(this.A,t)+"x}":"f(x) = \\frac{"+maybeToPrecision(this.B,t)+"}{e^{"+maybeToPrecision(-this.A,t)+"x}}"}static load(t){if("exponentialRegression"!==t.name)throw new TypeError("not a exponential regression model");return new ExponentialRegression(!0,t)}}function regress$2(t,e,r){const n=e.length,i=new Array(n);for(let t=0;t<n;t++)i[t]=Math.log(r[t]);const o=new SimpleLinearRegression(e,i);t.A=o.slope,t.B=Math.exp(o.intercept)}class PowerRegression extends BaseRegression{constructor(t,e){super(),!0===t?(this.A=e.A,this.B=e.B):(checkArraySize(t,e),regress$3(this,t,e))}_predict(t){return this.A*Math.pow(t,this.B)}toJSON(){return{name:"powerRegression",A:this.A,B:this.B}}toString(t){return"f(x) = "+maybeToPrecision(this.A,t)+" * x^"+maybeToPrecision(this.B,t)}toLaTeX(t){return this.B>=0?"f(x) = "+maybeToPrecision(this.A,t)+"x^{"+maybeToPrecision(this.B,t)+"}":"f(x) = \\frac{"+maybeToPrecision(this.A,t)+"}{x^{"+maybeToPrecision(-this.B,t)+"}}"}static load(t){if("powerRegression"!==t.name)throw new TypeError("not a power regression model");return new PowerRegression(!0,t)}}function regress$3(t,e,r){const n=e.length,i=new Array(n),o=new Array(n);for(let t=0;t<n;t++)i[t]=Math.log(e[t]),o[t]=Math.log(r[t]);const s=new SimpleLinearRegression(i,o);t.A=Math.exp(s.intercept),t.B=s.slope}class MultivariateLinearRegression extends BaseRegression{constructor(t,e,r={}){const{intercept:n=!0,statistics:i=!0}=r;if(super(),this.statistics=i,!0===t)this.weights=e.weights,this.inputs=e.inputs,this.outputs=e.outputs,this.intercept=e.intercept;else{t=new Matrix$1(t),n&&t.addColumn(new Array(t.length).fill(1));const r=new SingularValueDecomposition$$1(t,{autoTranspose:!0}).solve(e);if(this.weights=r.to2DArray(),this.inputs=t[0].length,this.outputs=e[0].length,n&&this.inputs--,this.intercept=n,i){const n=t.mmul(r),i=new Matrix$1(e).addM(n.neg()).to2DArray().map((t=>Math.pow(t[0],2))).reduce(((t,e)=>t+e))/(e.length-t.columns);this.stdError=Math.sqrt(i),this.stdErrorMatrix=t.transposeView().mmul(t).pseudoInverse().mul(i),this.stdErrors=this.stdErrorMatrix.diagonal().map((t=>Math.sqrt(t))),this.tStats=this.weights.map(((t,e)=>0===this.stdErrors[e]?0:t[0]/this.stdErrors[e]))}}}predict(t){if(Array.isArray(t)){if("number"==typeof t[0])return this._predict(t);if(Array.isArray(t[0])){const e=new Array(t.length);for(let r=0;r<t.length;r++)e[r]=this._predict(t[r]);return e}}throw new TypeError("x must be a matrix or array of numbers")}_predict(t){const e=new Array(this.outputs);if(this.intercept)for(let t=0;t<this.outputs;t++)e[t]=this.weights[this.inputs][t];else e.fill(0);for(let r=0;r<this.inputs;r++)for(let n=0;n<this.outputs;n++)e[n]+=this.weights[r][n]*t[r];return e}score(){throw new Error("score method is not implemented yet")}toJSON(){return{name:"multivariateLinearRegression",weights:this.weights,inputs:this.inputs,outputs:this.outputs,intercept:this.intercept,summary:this.statistics?{regressionStatistics:{standardError:this.stdError,observations:this.outputs},variables:this.weights.map(((t,e)=>({label:e===this.weights.length-1?"Intercept":`X Variable ${e+1}`,coefficients:t,standardError:this.stdErrors[e],tStat:this.tStats[e]})))}:void 0}}static load(t){if("multivariateLinearRegression"!==t.name)throw new Error("not a MLR model");return new MultivariateLinearRegression(!0,t)}}class PotentialRegression extends BaseRegression{constructor(t,e,r){if(super(),!0===t)this.A=e.A,this.M=e.M;else{if(t.length!==e.length)throw new RangeError("input and output array have a different length");var n=new PolynomialRegression(t,e,[r]);this.A=n.coefficients[0],this.M=r}}_predict(t){return this.A*Math.pow(t,this.M)}toJSON(){return{name:"potentialRegression",A:this.A,M:this.M}}toString(t){return"f(x) = "+maybeToPrecision(this.A,t)+" * x^"+this.M}toLaTeX(t){return this.M>=0?"f(x) = "+maybeToPrecision(this.A,t)+"x^{"+this.M+"}":"f(x) = \\frac{"+maybeToPrecision(this.A,t)+"}{x^{"+-this.M+"}}"}static load(t){if("potentialRegression"!==t.name)throw new TypeError("not a potential regression model");return new PotentialRegression(!0,t)}}const defaultOptions$l={lambda:.1,kernelType:"gaussian",kernelOptions:{},computeCoefficient:!1};class KernelRidgeRegression extends BaseRegression{constructor(t,e,r){if(super(),!0===t)this.alpha=e.alpha,this.inputs=e.inputs,this.kernelType=e.kernelType,this.kernelOptions=e.kernelOptions,this.kernel=new kernel(e.kernelType,e.kernelOptions);else{r=Object.assign({},defaultOptions$l,r);const n=new kernel(r.kernelType,r.kernelOptions),i=n.compute(t),o=t.length;i.add(Matrix$1.eye(o,o).mul(r.lambda)),this.alpha=solve$$1(i,e),this.inputs=t,this.kernelType=r.kernelType,this.kernelOptions=r.kernelOptions,this.kernel=n}}_predict(t){return this.kernel.compute([t],this.inputs).mmul(this.alpha)[0]}toJSON(){return{name:"kernelRidgeRegression",alpha:this.alpha,inputs:this.inputs,kernelType:this.kernelType,kernelOptions:this.kernelOptions}}static load(t){if("kernelRidgeRegression"!==t.name)throw new TypeError("not a KRR model");return new KernelRidgeRegression(!0,t)}}const defaultOptions$m={order:2};class PolynomialFitRegression2D extends BaseRegression{constructor(t,e,r){super(),!0===t?(this.coefficients=Matrix$1.columnVector(e.coefficients),this.order=e.order,e.r&&(this.r=e.r,this.r2=e.r2),e.chi2&&(this.chi2=e.chi2)):(r=Object.assign({},defaultOptions$m,r),this.order=r.order,this.coefficients=[],this.X=t,this.y=e,this.train(this.X,this.y,r))}train(t,e){if(Matrix$1.isMatrix(t)||(t=new Matrix$1(t)),Matrix$1.isMatrix(e)||(e=Matrix$1.columnVector(e)),e.rows!==t.rows&&(e=e.transpose()),2!==t.columns)throw new RangeError("You give X with "+t.columns+" columns and it must be 2");if(t.rows!==e.rows)throw new RangeError("X and y must have the same rows");var r=t.rows,n=(this.order+2)*(this.order+1)/2;this.coefficients=new Array(n);var i=t.getColumnVector(0),o=t.getColumnVector(1),s=1/i.clone().apply(abs).max(),a=1/o.clone().apply(abs).max(),u=1/e.clone().apply(abs).max();i.mulColumn(0,s),o.mulColumn(0,a),e.mulColumn(0,u);for(var h=new Matrix$1(r,n),c=0,l=0;l<=this.order;++l)for(var f=this.order-l,m=0;m<=f;++m){var p=powColVector(i,l).mulColumnVector(powColVector(o,m));h.setColumn(c,p),c++}var d=new SingularValueDecomposition$$1(h.transpose(),{computeLeftSingularVectors:!0,computeRightSingularVectors:!0,autoTranspose:!1}),g=Matrix$1.rowVector(d.diagonal);g=g.apply((function(t,e){this[t][e]>=1e-15?this[t][e]=1/this[t][e]:this[t][e]=0}));var v=Matrix$1.zeros(r,n);for(l=0;l<n;++l)v[l][l]=g[0][l];g=v;var w=d.rightSingularVectors,y=d.leftSingularVectors;for(this.coefficients=y.mmul(g.transpose()).mmul(w.transpose()).mmul(e),c=0,l=0;l<=n;++l)for(f=this.order-l,m=0;m<=f;++m)this.coefficients[c][0]=this.coefficients[c][0]*Math.pow(s,l)*Math.pow(a,m)/u,c++}_predict(t){for(var e=t[0],r=t[1],n=0,i=0,o=0;o<=this.order;o++)for(var s=0;s<=this.order-o;s++)n+=Math.pow(e,o)*Math.pow(r,s)*this.coefficients[i][0],i++;return n}toJSON(){return{name:"polyfit2D",order:this.order,coefficients:this.coefficients}}static load(t){if("polyfit2D"!==t.name)throw new TypeError("not a polyfit2D model");return new PolynomialFitRegression2D(!0,t)}}function powColVector(t,e){for(var r=t.clone(),n=0;n<t.rows;++n)r[n][0]=Math.pow(r[n][0],e);return r}function abs(t,e){this[t][e]=Math.abs(this[t][e])}const median$2=array$1.median;class TheilSenRegression extends BaseRegression{constructor(t,e){super(),!0===t?(this.slope=e.slope,this.intercept=e.intercept,this.coefficients=e.coefficients):(checkArraySize(t,e),theilSen(this,t,e))}toJSON(){return{name:"TheilSenRegression",slope:this.slope,intercept:this.intercept}}_predict(t){return this.slope*t+this.intercept}computeX(t){return(t-this.intercept)/this.slope}toString(t){var e="f(x) = ";if(this.slope){var r=maybeToPrecision(this.slope,t);if(e+=(Math.abs(r-1)<1e-5?"":r+" * ")+"x",this.intercept){var n=Math.abs(this.intercept);e+=" "+(n===this.intercept?"+":"-")+" "+maybeToPrecision(n,t)}}else e+=maybeToPrecision(this.intercept,t);return e}toLaTeX(t){return this.toString(t)}static load(t){if("TheilSenRegression"!==t.name)throw new TypeError("not a Theil-Sen model");return new TheilSenRegression(!0,t)}}function theilSen(t,e,r){let n=e.length,i=new Array(n*n),o=0;for(let t=0;t<n;++t)for(let s=t+1;s<n;++s)e[t]!==e[s]&&(i[o++]=(r[s]-r[t])/(e[s]-e[t]));i.length=o;let s=median$2(i),a=new Array(n);for(let t=0;t<n;++t)a[t]=r[t]-s*e[t];t.slope=s,t.intercept=median$2(a),t.coefficients=[t.intercept,t.slope]}class RobustPolynomialRegression extends BaseRegression{constructor(t,e,r){super(),!0===t?(this.degree=e.degree,this.powers=e.powers,this.coefficients=e.coefficients):(checkArraySize(t,e),robustPolynomial(this,t,e,r))}toJSON(){return{name:"robustPolynomialRegression",degree:this.degree,powers:this.powers,coefficients:this.coefficients}}_predict(t){return predict(t,this.powers,this.coefficients)}toString(t){return this._toFormula(t,!1)}toLaTeX(t){return this._toFormula(t,!0)}_toFormula(t,e){let r="^",n="",i=" * ";e&&(r="^{",n="}",i="");let o="",s="";for(let e=0;e<this.coefficients.length;e++)s="",0!==this.coefficients[e]&&(s=0===this.powers[e]?maybeToPrecision(this.coefficients[e],t):1===this.powers[e]?maybeToPrecision(this.coefficients[e],t)+i+"x":maybeToPrecision(this.coefficients[e],t)+i+"x"+r+this.powers[e]+n,this.coefficients[e]>0&&e!==this.coefficients.length-1?s=" + "+s:e!==this.coefficients.length-1&&(s=" "+s)),o=s+o;return"+"===o.charAt(0)&&(o=o.slice(1)),"f(x) = "+o}static load(t){if("robustPolynomialRegression"!==t.name)throw new TypeError("not a RobustPolynomialRegression model");return new RobustPolynomialRegression(!0,t)}}function robustPolynomial(t,e,r,n){let i=new Array(n);for(let t=0;t<n;t++)i[t]=t;const o=getRandomTuples(e,r,n);for(var s,a=0;a<o.length;a++){for(var u=calcCoefficients(o[a],i),h=e.slice(),c=0;c<e.length;c++)h[c]=r[c]-predict(e[c],i,u),h[c]={residual:h[c]*h[c],coefficients:u};var l=residualsMedian(h);(!s||l.residual<s.residual)&&(s=l)}t.degree=n,t.powers=i,t.coefficients=s.coefficients}function getRandomTuples(t,e,r){for(var n=Math.floor(t.length/r),i=new Array(n),o=0;o<t.length;o++){for(var s=Math.floor(Math.random()*n),a=0;a<t.length;){if(!i[s]){i[s]=[{x:t[o],y:e[o]}];break}if(i[s].length<r){i[s].push({x:t[o],y:e[o]});break}a++,s=(s+1)%n}if(a===t.length)return i}return i}function calcCoefficients(t,e){for(var r=t.slice(),n=t.slice(),i=0;i<r.length;i++){n[i]=[t[i].y],r[i]=new Array(e.length);for(var o=0;o<e.length;o++)r[i][o]=Math.pow(t[i].x,e[o])}return solve$$1(r,n).to1DArray()}function predict(t,e,r){let n=0;for(let i=0;i<e.length;i++)n+=r[i]*Math.pow(t,e[i]);return n}function residualsMedian(t){t.sort(((t,e)=>t.residual-e.residual));var e=t.length,r=Math.floor(e/2);return e%2==0?t[r-1]:t[r]}const NLR={PotentialRegression:PotentialRegression};var src$d=Object.freeze({NLR:NLR,NonLinearRegression:NLR,SimpleLinearRegression:SimpleLinearRegression,SLR:SimpleLinearRegression,PolynomialRegression:PolynomialRegression,ExponentialRegression:ExponentialRegression,PowerRegression:PowerRegression,MultivariateLinearRegression:MultivariateLinearRegression,KernelRidgeRegression:KernelRidgeRegression,KRR:KernelRidgeRegression,PolinomialFitting2D:PolynomialFitRegression2D,TheilSenRegression:TheilSenRegression,RobustPolynomialRegression:RobustPolynomialRegression});function errorCalculation(t,e,r){var n=0;const i=r(e);for(var o=0;o<t.x.length;o++)n+=Math.abs(t.y[o]-i(t.x[o]));return n}function gradientFunction(t,e,r,n,i){const o=r.length,s=t.x.length;for(var a=new Array(o),u=0;u<o;u++){a[u]=new Array(s);var h=r.concat();h[u]+=n;for(var c=i(h),l=0;l<s;l++)a[u][l]=e[l]-c(t.x[l])}return new require$$0$3.Matrix(a)}function matrixFunction(t,e){const r=t.x.length;for(var n=new Array(r),i=0;i<r;i++)n[i]=t.y[i]-e[i];return new require$$0$3.Matrix([n])}function step$1(t,e,r,n,i){var o=require$$0$3.Matrix.eye(e.length).mul(r*n*n),s=t.x.length,a=new Array(s);const u=i(e);for(var h=0;h<s;h++)a[h]=u(t.x[h]);var c=gradientFunction(t,a,e,n,i),l=matrixFunction(t,a).transposeView(),f=require$$0$3.inverse(o.add(c.mmul(c.transposeView())));return(e=(e=new require$$0$3.Matrix([e])).sub(f.mmul(c).mmul(l).mul(n).transposeView())).to1DArray()}function levenbergMarquardt(t,e,r={}){let{maxIterations:n=100,gradientDifference:i=.1,damping:o=0,errorTolerance:s=.01,initialValues:a}=r;if(o<=0)throw new Error("The damping option must be a positive number");if(!t.x||!t.y)throw new Error("The data parameter must have x and y elements");if(!Array.isArray(t.x)||t.x.length<2||!Array.isArray(t.y)||t.y.length<2)throw new Error("The data parameter elements must be an array with more than 2 points");if(t.x.length!==t.y.length)throw new Error("The data parameter elements must have the same size");var u=a||new Array(e.length).fill(1);if(!Array.isArray(u))throw new Error("initialValues must be an array");for(var h=errorCalculation(t,u,e),c=h<=s,l=0;l<n&&!c;l++)c=(h=errorCalculation(t,u=step$1(t,u,o,i,e),e))<=s;return{parameterValues:u,parameterError:h,iterations:l}}var lib=levenbergMarquardt,newArray_1=newArray;function newArray(t,e){t=t||0;for(var r=new Array(t),n=0;n<t;n++)r[n]=e;return r}var binarySearch=function(t,e,r,n,i){var o,s;if(void 0===n)n=0;else if((n|=0)<0||n>=t.length)throw new RangeError("invalid lower bound");if(void 0===i)i=t.length-1;else if((i|=0)<n||i>=t.length)throw new RangeError("invalid upper bound");for(;n<=i;)if((s=+r(t[o=n+(i-n>>1)],e,o,t))<0)n=o+1;else{if(!(s>0))return o;i=o-1}return~n},numberIsNan=Number.isNaN||function(t){return t!=t};function assertNum(t){if("number"!=typeof t||numberIsNan(t))throw new TypeError("Expected a number")}var asc=function(t,e){return assertNum(t),assertNum(e),t-e},desc=function(t,e){return assertNum(t),assertNum(e),e-t},numSort={asc:asc,desc:desc};const sortAsc=numSort.asc,largestPrime=2147483647,primeNumbers=[largestPrime,5,11,23,47,97,197,397,797,1597,3203,6421,12853,25717,51437,102877,205759,411527,823117,1646237,3292489,6584983,13169977,26339969,52679969,105359939,210719881,421439783,842879579,1685759167,433,877,1759,3527,7057,14143,28289,56591,113189,226379,452759,905551,1811107,3622219,7244441,14488931,28977863,57955739,115911563,231823147,463646329,927292699,1854585413,953,1907,3821,7643,15287,30577,61169,122347,244703,489407,978821,1957651,3915341,7830701,15661423,31322867,62645741,125291483,250582987,501165979,1002331963,2004663929,1039,2081,4177,8363,16729,33461,66923,133853,267713,535481,1070981,2141977,4283963,8567929,17135863,34271747,68543509,137087021,274174111,548348231,1096696463,31,67,137,277,557,1117,2237,4481,8963,17929,35863,71741,143483,286973,573953,1147921,2295859,4591721,9183457,18366923,36733847,73467739,146935499,293871013,587742049,1175484103,599,1201,2411,4831,9677,19373,38747,77509,155027,310081,620171,1240361,2480729,4961459,9922933,19845871,39691759,79383533,158767069,317534141,635068283,1270136683,311,631,1277,2557,5119,10243,20507,41017,82037,164089,328213,656429,1312867,2625761,5251529,10503061,21006137,42012281,84024581,168049163,336098327,672196673,1344393353,3,7,17,37,79,163,331,673,1361,2729,5471,10949,21911,43853,87719,175447,350899,701819,1403641,2807303,5614657,11229331,22458671,44917381,89834777,179669557,359339171,718678369,1437356741,43,89,179,359,719,1439,2879,5779,11579,23159,46327,92657,185323,370661,741337,1482707,2965421,5930887,11861791,23723597,47447201,94894427,189788857,379577741,759155483,1518310967,379,761,1523,3049,6101,12203,24407,48817,97649,195311,390647,781301,1562611,3125257,6250537,12501169,25002389,50004791,100009607,200019221,400038451,800076929,1600153859,13,29,59,127,257,521,1049,2099,4201,8419,16843,33703,67409,134837,269683,539389,1078787,2157587,4315183,8630387,17260781,34521589,69043189,138086407,276172823,552345671,1104691373,19,41,83,167,337,677,1361,2729,5471,10949,21911,43853,87719,175447,350899,701819,1403641,2807303,5614657,11229331,22458671,44917381,89834777,179669557,359339171,718678369,1437356741,53,107,223,449,907,1823,3659,7321,14653,29311,58631,117269,234539,469099,938207,1876417,3752839,7505681,15011389,30022781,60045577,120091177,240182359,480364727,960729461,1921458943];function nextPrime(t){let e=binarySearch(primeNumbers,t,sortAsc);return e<0&&(e=~e),primeNumbers[e]}primeNumbers.sort(sortAsc);var nextPrime_1=nextPrime,largestPrime_1=largestPrime,primeFinder={nextPrime:nextPrime_1,largestPrime:largestPrime_1};const nextPrime$1=primeFinder.nextPrime,largestPrime$1=primeFinder.largestPrime,FREE=0,FULL=1,REMOVED=2,defaultInitialCapacity=150,defaultMinLoadFactor=1/6,defaultMaxLoadFactor=2/3;class HashTable{constructor(t={}){if(t instanceof HashTable)return this.table=t.table.slice(),this.values=t.values.slice(),this.state=t.state.slice(),this.minLoadFactor=t.minLoadFactor,this.maxLoadFactor=t.maxLoadFactor,this.distinct=t.distinct,this.freeEntries=t.freeEntries,this.lowWaterMark=t.lowWaterMark,void(this.highWaterMark=t.maxLoadFactor);const e=void 0===t.initialCapacity?defaultInitialCapacity:t.initialCapacity;if(e<0)throw new RangeError(`initial capacity must not be less than zero: ${e}`);const r=void 0===t.minLoadFactor?defaultMinLoadFactor:t.minLoadFactor,n=void 0===t.maxLoadFactor?defaultMaxLoadFactor:t.maxLoadFactor;if(r<0||r>=1)throw new RangeError(`invalid minLoadFactor: ${r}`);if(n<=0||n>=1)throw new RangeError(`invalid maxLoadFactor: ${n}`);if(r>=n)throw new RangeError(`minLoadFactor (${r}) must be smaller than maxLoadFactor (${n})`);let i=e;i=i/n|0,i=nextPrime$1(i),0===i&&(i=1),this.table=newArray_1(i,0),this.values=newArray_1(i,0),this.state=newArray_1(i,0),this.minLoadFactor=r,this.maxLoadFactor=i===largestPrime$1?1:n,this.distinct=0,this.freeEntries=i,this.lowWaterMark=0,this.highWaterMark=chooseHighWaterMark(i,this.maxLoadFactor)}clone(){return new HashTable(this)}get size(){return this.distinct}get(t){const e=this.indexOfKey(t);return e<0?0:this.values[e]}set(t,e){let r=this.indexOfInsertion(t);if(r<0)return r=-r-1,this.values[r]=e,!1;if(this.distinct>this.highWaterMark){const r=chooseGrowCapacity(this.distinct+1,this.minLoadFactor,this.maxLoadFactor);return this.rehash(r),this.set(t,e)}if(this.table[r]=t,this.values[r]=e,this.state[r]===FREE&&this.freeEntries--,this.state[r]=FULL,this.distinct++,this.freeEntries<1){const t=chooseGrowCapacity(this.distinct+1,this.minLoadFactor,this.maxLoadFactor);this.rehash(t)}return!0}remove(t,e){const r=this.indexOfKey(t);return!(r<0)&&(this.state[r]=REMOVED,this.distinct--,e||this.maybeShrinkCapacity(),!0)}delete(t,e){const r=this.indexOfKey(t);return!(r<0)&&(this.state[r]=FREE,this.distinct--,e||this.maybeShrinkCapacity(),!0)}maybeShrinkCapacity(){if(this.distinct<this.lowWaterMark){const t=chooseShrinkCapacity(this.distinct,this.minLoadFactor,this.maxLoadFactor);this.rehash(t)}}containsKey(t){return this.indexOfKey(t)>=0}indexOfKey(t){const e=this.table,r=this.state,n=this.table.length,i=2147483647&t;let o=i%n,s=i%(n-2);for(0===s&&(s=1);r[o]!==FREE&&(r[o]===REMOVED||e[o]!==t);)o-=s,o<0&&(o+=n);return r[o]===FREE?-1:o}containsValue(t){return this.indexOfValue(t)>=0}indexOfValue(t){const e=this.values,r=this.state;for(var n=0;n<r.length;n++)if(r[n]===FULL&&e[n]===t)return n;return-1}indexOfInsertion(t){const e=this.table,r=this.state,n=e.length,i=2147483647&t;let o=i%n,s=i%(n-2);for(0===s&&(s=1);r[o]===FULL&&e[o]!==t;)o-=s,o<0&&(o+=n);if(r[o]===REMOVED){const i=o;for(;r[o]!==FREE&&(r[o]===REMOVED||e[o]!==t);)o-=s,o<0&&(o+=n);r[o]===FREE&&(o=i)}return r[o]===FULL?-o-1:o}ensureCapacity(t){if(this.table.length<t){const e=nextPrime$1(t);this.rehash(e)}}rehash(t){const e=this.table.length;if(t<=this.distinct)throw new Error("Unexpected");const r=this.table,n=this.values,i=this.state,o=newArray_1(t,0),s=newArray_1(t,0),a=newArray_1(t,0);this.lowWaterMark=chooseLowWaterMark(t,this.minLoadFactor),this.highWaterMark=chooseHighWaterMark(t,this.maxLoadFactor),this.table=o,this.values=s,this.state=a,this.freeEntries=t-this.distinct;for(var u=0;u<e;u++)if(i[u]===FULL){var h=r[u],c=this.indexOfInsertion(h);o[c]=h,s[c]=n[u],a[c]=FULL}}forEachKey(t){for(var e=0;e<this.state.length;e++)if(this.state[e]===FULL&&!t(this.table[e]))return!1;return!0}forEachValue(t){for(var e=0;e<this.state.length;e++)if(this.state[e]===FULL&&!t(this.values[e]))return!1;return!0}forEachPair(t){for(var e=0;e<this.state.length;e++)if(this.state[e]===FULL&&!t(this.table[e],this.values[e]))return!1;return!0}}var HashTable_1=HashTable;function chooseLowWaterMark(t,e){return t*e|0}function chooseHighWaterMark(t,e){return Math.min(t-2,t*e|0)}function chooseGrowCapacity(t,e,r){return nextPrime$1(Math.max(t+1,4*t/(3*e+r)|0))}function chooseShrinkCapacity(t,e,r){return nextPrime$1(Math.max(t+1,4*t/(e+3*r)|0))}class SparseMatrix{constructor(t,e,r={}){if(t instanceof SparseMatrix){const e=t;this._init(e.rows,e.columns,e.elements.clone(),e.threshold)}else if(Array.isArray(t)){const s=t;t=s.length,r=e||{},e=s[0].length,this._init(t,e,new HashTable_1(r),r.threshold);for(var n=0;n<t;n++)for(var i=0;i<e;i++){var o=s[n][i];this.threshold&&Math.abs(o)<this.threshold&&(o=0),0!==o&&this.elements.set(n*e+i,s[n][i])}}else this._init(t,e,new HashTable_1(r),r.threshold)}_init(t,e,r,n){this.rows=t,this.columns=e,this.elements=r,this.threshold=n||0}static eye(t=1,e=t){const r=Math.min(t,e),n=new SparseMatrix(t,e,{initialCapacity:r});for(var i=0;i<r;i++)n.set(i,i,1);return n}clone(){return new SparseMatrix(this)}to2DArray(){const t=new Array(this.rows);for(var e=0;e<this.rows;e++){t[e]=new Array(this.columns);for(var r=0;r<this.columns;r++)t[e][r]=this.get(e,r)}return t}isSquare(){return this.rows===this.columns}isSymmetric(){if(!this.isSquare())return!1;var t=!0;return this.forEachNonZero(((e,r,n)=>this.get(r,e)!==n?(t=!1,!1):n)),t}bandWidth(){let t=this.columns,e=-1;return this.forEachNonZero(((r,n,i)=>{let o=r-n;return t=Math.min(t,o),e=Math.max(e,o),i})),e-t}isBanded(t){return this.bandWidth()<=t}get cardinality(){return this.elements.size}get size(){return this.rows*this.columns}get(t,e){return this.elements.get(t*this.columns+e)}set(t,e,r){return this.threshold&&Math.abs(r)<this.threshold&&(r=0),0===r?this.elements.remove(t*this.columns+e):this.elements.set(t*this.columns+e,r),this}mmul(t){this.columns!==t.rows&&console.warn("Number of columns of left matrix are not equal to number of rows of right matrix.");const e=this.rows,r=t.columns,n=new SparseMatrix(e,r);return this.forEachNonZero(((e,r,i)=>(t.forEachNonZero(((t,o,s)=>(r===t&&n.set(e,o,n.get(e,o)+i*s),s))),i))),n}kroneckerProduct(t){const e=this.rows,r=this.columns,n=t.rows,i=t.columns,o=new SparseMatrix(e*n,r*i,{initialCapacity:this.cardinality*t.cardinality});return this.forEachNonZero(((e,r,s)=>(t.forEachNonZero(((t,a,u)=>(o.set(n*e+t,i*r+a,s*u),u))),s))),o}forEachNonZero(t){return this.elements.forEachPair(((e,r)=>{const n=e/this.columns|0,i=e%this.columns;let o=t(n,i,r);return!1!==o&&(this.threshold&&Math.abs(o)<this.threshold&&(o=0),o!==r&&(0===o?this.elements.remove(e,!0):this.elements.set(e,o)),!0)})),this.elements.maybeShrinkCapacity(),this}getNonZeros(){const t=this.cardinality,e=new Array(t),r=new Array(t),n=new Array(t);var i=0;return this.forEachNonZero(((t,o,s)=>(e[i]=t,r[i]=o,n[i]=s,i++,s))),{rows:e,columns:r,values:n}}setThreshold(t){return 0!==t&&t!==this.threshold&&(this.threshold=t,this.forEachNonZero(((t,e,r)=>r))),this}transpose(){let t=new SparseMatrix(this.columns,this.rows,{initialCapacity:this.cardinality});return this.forEachNonZero(((e,r,n)=>(t.set(r,e,n),n))),t}}SparseMatrix.prototype.klass="Matrix",SparseMatrix.identity=SparseMatrix.eye,SparseMatrix.prototype.tensorProduct=SparseMatrix.prototype.kroneckerProduct;var inplaceOperator="\n(function %name%(value) {\n    if (typeof value === 'number') return this.%name%S(value);\n    return this.%name%M(value);\n})\n",inplaceOperatorScalar="\n(function %name%S(value) {\n    this.forEachNonZero((i, j, v) => v %op% value);\n    return this;\n})\n",inplaceOperatorMatrix="\n(function %name%M(matrix) {\n    matrix.forEachNonZero((i, j, v) => {\n        this.set(i, j, this.get(i, j) %op% v);\n        return v;\n    });\n    return this;\n})\n",staticOperator="\n(function %name%(matrix, value) {\n    var newMatrix = new SparseMatrix(matrix);\n    return newMatrix.%name%(value);\n})\n",inplaceMethod="\n(function %name%() {\n    this.forEachNonZero((i, j, v) => %method%(v));\n    return this;\n})\n",staticMethod="\n(function %name%(matrix) {\n    var newMatrix = new SparseMatrix(matrix);\n    return newMatrix.%name%();\n})\n";const operators=[["+","add"],["-","sub","subtract"],["*","mul","multiply"],["/","div","divide"],["%","mod","modulus"],["&","and"],["|","or"],["^","xor"],["<<","leftShift"],[">>","signPropagatingRightShift"],[">>>","rightShift","zeroFillRightShift"]];for(const operator of operators)for(let i=1;i<operator.length;i++)SparseMatrix.prototype[operator[i]]=eval(fillTemplateFunction(inplaceOperator,{name:operator[i],op:operator[0]})),SparseMatrix.prototype[operator[i]+"S"]=eval(fillTemplateFunction(inplaceOperatorScalar,{name:operator[i]+"S",op:operator[0]})),SparseMatrix.prototype[operator[i]+"M"]=eval(fillTemplateFunction(inplaceOperatorMatrix,{name:operator[i]+"M",op:operator[0]})),SparseMatrix[operator[i]]=eval(fillTemplateFunction(staticOperator,{name:operator[i]}));var methods=[["~","not"]];["abs","acos","acosh","asin","asinh","atan","atanh","cbrt","ceil","clz32","cos","cosh","exp","expm1","floor","fround","log","log1p","log10","log2","round","sign","sin","sinh","sqrt","tan","tanh","trunc"].forEach((function(t){methods.push(["Math."+t,t])}));for(const method of methods)for(let i=1;i<method.length;i++)SparseMatrix.prototype[method[i]]=eval(fillTemplateFunction(inplaceMethod,{name:method[i],method:method[0]})),SparseMatrix[method[i]]=eval(fillTemplateFunction(staticMethod,{name:method[i]}));function fillTemplateFunction(t,e){for(const r in e)t=t.replace(new RegExp("%"+r+"%","g"),e[r]);return t}var src$e=Object.freeze({SparseMatrix:SparseMatrix}),additiveSymmetric=function(t,e){for(var r=0,n=t.length,i=0;r<n;r++)i+=(t[r]-e[r])*(t[r]-e[r])*(t[r]+e[r])/(t[r]*e[r]);return 2*i},avg=function(t,e){for(var r=t.length,n=0,i=0,o=0,s=0;s<r;s++)i+=o=Math.abs(t[s]-e[s]),n<o&&(n=o);return(n+i)/2},bhattacharyya=function(t,e){for(var r=t.length,n=0,i=0;i<r;i++)n+=Math.sqrt(t[i]*e[i]);return-Math.log(n)},canberra=function(t,e){for(var r=t.length,n=0,i=0;i<r;i++)n+=Math.abs(t[i]-e[i])/(t[i]+e[i]);return n},chebyshev=function(t,e){for(var r=t.length,n=0,i=0,o=0;o<r;o++)n<(i=Math.abs(t[o]-e[o]))&&(n=i);return n},clark=function(t,e){for(var r=0,n=t.length,i=0;r<n;r++)i+=Math.sqrt((t[r]-e[r])*(t[r]-e[r])/((t[r]+e[r])*(t[r]+e[r])));return 2*i},czekanowski=function(t,e){for(var r=0,n=0,i=0;i<t.length;i++)r+=Math.min(t[i],e[i]),n+=t[i]+e[i];return 2*r/n},czekanowski$1=function(t,e){return 1-czekanowski(t,e)},dice=function(t,e){for(var r=t.length,n=0,i=0,o=0,s=0;s<r;s++)n+=t[s]*t[s],i+=e[s]*e[s],o+=(t[s]-e[s])*(t[s]-e[s]);return o/(n+i)},divergence=function(t,e){for(var r=0,n=t.length,i=0;r<n;r++)i+=(t[r]-e[r])*(t[r]-e[r])/((t[r]+e[r])*(t[r]+e[r]));return 2*i},fidelity=function(t,e){for(var r=t.length,n=0,i=0;i<r;i++)n+=Math.sqrt(t[i]*e[i]);return n},gower=function(t,e){for(var r=t.length,n=0,i=0;i<r;i++)n+=Math.abs(t[i]-e[i]);return n/r},harmonicMean=function(t,e){for(var r=t.length,n=0,i=0;i<r;i++)n+=t[i]*e[i]/(t[i]+e[i]);return 2*n},hellinger=function(t,e){for(var r=t.length,n=0,i=0;i<r;i++)n+=Math.sqrt(t[i]*e[i]);return 2*Math.sqrt(1-n)},innerProduct=function(t,e){for(var r=t.length,n=0,i=0;i<r;i++)n+=t[i]*e[i];return n},intersection=function(t,e){for(var r=t.length,n=0,i=0;i<r;i++)n+=Math.min(t[i],e[i]);return 1-n},jaccard=function(t,e){for(var r=t.length,n=0,i=0,o=0,s=0,a=0;a<r;a++)n+=t[a]*e[a],i+=t[a]*t[a],o+=e[a]*e[a],s+=(t[a]-e[a])*(t[a]-e[a]);return s/(i+o-n)},jeffreys=function(t,e){for(var r=t.length,n=0,i=0;i<r;i++)n+=(t[i]-e[i])*Math.log(t[i]/e[i]);return n},jensenDifference=function(t,e){for(var r=t.length,n=0,i=0;i<r;i++)n+=(t[i]*Math.log(t[i])+e[i]*Math.log(e[i]))/2-(t[i]+e[i])/2*Math.log((t[i]+e[i])/2);return n},jensenShannon=function(t,e){for(var r=t.length,n=0,i=0,o=0;o<r;o++)n+=t[o]*Math.log(2*t[o]/(t[o]+e[o])),i+=e[o]*Math.log(2*e[o]/(t[o]+e[o]));return(n+i)/2},kdivergence=function(t,e){for(var r=t.length,n=0,i=0;i<r;i++)n+=t[i]*Math.log(2*t[i]/(t[i]+e[i]));return n},kulczynski=function(t,e){for(var r=t.length,n=0,i=0,o=0;o<r;o++)n+=Math.abs(t[o]-e[o]),i+=Math.min(t[o],e[o]);return n/i},kullbackLeibler=function(t,e){for(var r=t.length,n=0,i=0;i<r;i++)n+=t[i]*Math.log(t[i]/e[i]);return n},kumarHassebrook=function(t,e){for(var r=t.length,n=0,i=0,o=0,s=0;s<r;s++)n+=t[s]*e[s],i+=t[s]*t[s],o+=e[s]*e[s];return n/(i+o-n)},kumarJohnson=function(t,e){for(var r=t.length,n=0,i=0;i<r;i++)n+=Math.pow(t[i]*t[i]-e[i]*e[i],2)/(2*Math.pow(t[i]*e[i],1.5));return n},lorentzian=function(t,e){for(var r=t.length,n=0,i=0;i<r;i++)n+=Math.log(Math.abs(t[i]-e[i])+1);return n},manhattan=function(t,e){for(var r=0,n=t.length,i=0;r<n;r++)i+=Math.abs(t[r]-e[r]);return i},matusita=function(t,e){for(var r=t.length,n=0,i=0;i<r;i++)n+=Math.sqrt(t[i]*e[i]);return Math.sqrt(2-2*n)},minkowski=function(t,e,r){for(var n=0,i=t.length,o=0;n<i;n++)o+=Math.pow(Math.abs(t[n]-e[n]),r);return Math.pow(o,1/r)},motyka=function(t,e){for(var r=t.length,n=0,i=0,o=0;o<r;o++)n+=Math.min(t[o],e[o]),i+=t[o]+e[o];return 1-n/i},neyman=function(t,e){for(var r=0,n=t.length,i=0;r<n;r++)i+=(t[r]-e[r])*(t[r]-e[r])/t[r];return i},pearson=function(t,e){for(var r=0,n=t.length,i=0;r<n;r++)i+=(t[r]-e[r])*(t[r]-e[r])/e[r];return i},probabilisticSymmetric=function(t,e){for(var r=0,n=t.length,i=0;r<n;r++)i+=(t[r]-e[r])*(t[r]-e[r])/(t[r]+e[r]);return 2*i},ruzicka=function(t,e){for(var r=t.length,n=0,i=0,o=0;o<r;o++)n+=Math.min(t[o],e[o]),i+=Math.max(t[o],e[o]);return n/i},soergel=function(t,e){for(var r=t.length,n=0,i=0,o=0;o<r;o++)n+=Math.abs(t[o]-e[o]),i+=Math.max(t[o],e[o]);return n/i},sorensen=function(t,e){for(var r=t.length,n=0,i=0,o=0;o<r;o++)n+=Math.abs(t[o]-e[o]),i+=t[o]+e[o];return n/i},squared=function(t,e){for(var r=0,n=t.length,i=0;r<n;r++)i+=(t[r]-e[r])*(t[r]-e[r])/(t[r]+e[r]);return i},squaredChord=function(t,e){for(var r=t.length,n=0,i=0;i<r;i++)n+=(Math.sqrt(t[i])-Math.sqrt(e[i]))*(Math.sqrt(t[i])-Math.sqrt(e[i]));return n},taneja=function(t,e){for(var r=t.length,n=0,i=0;i<r;i++)n+=(t[i]+e[i])/2*Math.log((t[i]+e[i])/(2*Math.sqrt(t[i]*e[i])));return n},tanimoto=function(t,e,r){if(r){for(var n=0,i=0,o=0;o<t.length;o++)n+=t[o]&&e[o],i+=t[o]||e[o];return 0===i?1:n/i}for(var s=t.length,a=0,u=0,h=0,c=0;c<s;c++)a+=t[c],u+=e[c],h+=Math.min(t[c],e[c]);return 1-(a+u-2*h)/(a+u-h)},tanimoto$1=function(t,e,r){if(r)return 1-tanimoto(t,e,r);for(var n=t.length,i=0,o=0,s=0,a=0;a<n;a++)i+=t[a],o+=e[a],s+=Math.min(t[a],e[a]);return(i+o-2*s)/(i+o-s)},topsoe=function(t,e){for(var r=t.length,n=0,i=0;i<r;i++)n+=t[i]*Math.log(2*t[i]/(t[i]+e[i]))+e[i]*Math.log(2*e[i]/(t[i]+e[i]));return n};function createTree(t,e,r,n,i,o){if(o=o||.01,!(n-r<(i=i||.16))){for(var s=0,a=0;t[a]<n;a++)t[a]>r&&(s+=e[a]);if(!(s<o)){for(var u=0,h=0;t[h]<n;h++)t[a]>r&&(u+=t[h]*e[h]);if(!((u/=s)-r<1e-5||n-u<1e-5))return u-r<i/4?createTree(t,e,u,n,i,o):n-u<i/4?createTree(t,e,r,u,i,o):{sum:s,center:u,left:createTree(t,e,r,u,i,o),right:createTree(t,e,u,n,i,o)}}}}function S(t,e,r,n,i){return void 0===t||void 0===e?0:n*(r*Math.min(t.sum,e.sum)/Math.max(t.sum,e.sum)+(1-r)*Math.exp(-i*Math.abs(t.center-e.center)))+(1-n)*(S(t.left,e.left,r,n,i)+S(t.right,e.right,r,n,i))}var defaultOptions$n={minWindow:.16,threshold:.01,alpha:.1,beta:.33,gamma:.001};function tree(t,e,r,n,i){for(var o in i=i||{},defaultOptions$n)i.hasOwnProperty(o)||(i[o]=defaultOptions$n[o]);return S(t.sum?t:createTree(t.x,t.y,r,n,i.minWindow,i.threshold),e.sum?e:createTree(e.x,e.y,r,n,i.minWindow,i.threshold),i.alpha,i.beta,i.gamma)}var src$f={calc:tree,createTree:createTree},waveHedges=function(t,e){for(var r=t.length,n=0,i=0;i<r;i++)n+=1-Math.min(t[i],e[i])/Math.max(t[i],e[i]);return n},additiveSymmetric$1=additiveSymmetric,avg$1=avg,bhattacharyya$1=bhattacharyya,canberra$1=canberra,chebyshev$1=chebyshev,clark$1=clark,czekanowski$2=czekanowski$1,dice$1=dice,divergence$1=divergence,euclidean$1=euclidean_1,fidelity$1=fidelity,gower$1=gower,harmonicMean$1=harmonicMean,hellinger$1=hellinger,innerProduct$1=innerProduct,intersection$1=intersection,jaccard$1=jaccard,jeffreys$1=jeffreys,jensenDifference$1=jensenDifference,jensenShannon$1=jensenShannon,kdivergence$1=kdivergence,kulczynski$1=kulczynski,kullbackLeibler$1=kullbackLeibler,kumarHassebrook$1=kumarHassebrook,kumarJohnson$1=kumarJohnson,lorentzian$1=lorentzian,manhattan$1=manhattan,matusita$1=matusita,minkowski$1=minkowski,motyka$1=motyka,neyman$1=neyman,pearson$1=pearson,probabilisticSymmetric$1=probabilisticSymmetric,ruzicka$1=ruzicka,soergel$1=soergel,sorensen$1=sorensen,squared$1=squared,squaredChord$1=squaredChord,squaredEuclidean$5=euclidean_1.squared,taneja$1=taneja,tanimoto$2=tanimoto$1,topsoe$1=topsoe,tree$1=src$f,waveHedges$1=waveHedges,distances={additiveSymmetric:additiveSymmetric$1,avg:avg$1,bhattacharyya:bhattacharyya$1,canberra:canberra$1,chebyshev:chebyshev$1,clark:clark$1,czekanowski:czekanowski$2,dice:dice$1,divergence:divergence$1,euclidean:euclidean$1,fidelity:fidelity$1,gower:gower$1,harmonicMean:harmonicMean$1,hellinger:hellinger$1,innerProduct:innerProduct$1,intersection:intersection$1,jaccard:jaccard$1,jeffreys:jeffreys$1,jensenDifference:jensenDifference$1,jensenShannon:jensenShannon$1,kdivergence:kdivergence$1,kulczynski:kulczynski$1,kullbackLeibler:kullbackLeibler$1,kumarHassebrook:kumarHassebrook$1,kumarJohnson:kumarJohnson$1,lorentzian:lorentzian$1,manhattan:manhattan$1,matusita:matusita$1,minkowski:minkowski$1,motyka:motyka$1,neyman:neyman$1,pearson:pearson$1,probabilisticSymmetric:probabilisticSymmetric$1,ruzicka:ruzicka$1,soergel:soergel$1,sorensen:sorensen$1,squared:squared$1,squaredChord:squaredChord$1,squaredEuclidean:squaredEuclidean$5,taneja:taneja$1,tanimoto:tanimoto$2,topsoe:topsoe$1,tree:tree$1,waveHedges:waveHedges$1},cosine=function(t,e){for(var r=t.length,n=0,i=0,o=0,s=0;s<r;s++)n+=t[s]*e[s],i+=t[s]*t[s],o+=e[s]*e[s];return n/(Math.sqrt(i)*Math.sqrt(o))},dice$2=function(t,e){return 1-dice(t,e)},intersection$2=function(t,e){return 1-intersection(t,e)},jaccard$2=function(t,e){return 1-jaccard(t,e)},kulczynski$2=function(t,e){return 1/kulczynski(t,e)},motyka$2=function(t,e){return 1-motyka(t,e)},stat$1=mlStat.array,pearson$2=function(t,e){for(var r=stat$1.mean(t),n=stat$1.mean(e),i=new Array(t.length),o=new Array(e.length),s=0;s<i.length;s++)i[s]=t[s]-r,o[s]=e[s]-n;return cosine(i,o)},squaredChord$2=function(t,e){return 1-squaredChord(t,e)},cosine$1=cosine,czekanowski$3=czekanowski,dice$3=dice$2,intersection$3=intersection$2,jaccard$3=jaccard$2,kulczynski$3=kulczynski$2,motyka$3=motyka$2,pearson$3=pearson$2,squaredChord$3=squaredChord$2,tanimoto$3=tanimoto,similarities={cosine:cosine$1,czekanowski:czekanowski$3,dice:dice$3,intersection:intersection$3,jaccard:jaccard$3,kulczynski:kulczynski$3,motyka:motyka$3,pearson:pearson$3,squaredChord:squaredChord$3,tanimoto:tanimoto$3},distance=distances,similarity=similarities,src$g={distance:distance,similarity:similarity},xsaddEs5=createCommonjsModule((function(t,e){Object.defineProperty(e,"__esModule",{value:!0});var r=function(){function t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}();var n=1/16777216;var i=function(){function t(){var e=arguments.length<=0||void 0===arguments[0]?Date.now():arguments[0];!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.state=new Uint32Array(4),this.init(e)}return r(t,[{key:"init",value:function(t){this.state[0]=t,this.state[1]=0,this.state[2]=0,this.state[3]=0;for(var e=1;e<8;e++)this.state[3&e]^=e+(r=1812433253,n=this.state[e-1&3]^this.state[e-1&3]>>>30>>>0,i=void 0,i=65535&(r>>>=0),((r-i)*(n>>>=0)>>>0)+i*n>>>0)>>>0;var r,n,i,o;0===(o=this).state[0]&&0===o.state[1]&&0===o.state[2]&&0===o.state[3]&&(o.state[0]=88,o.state[1]=83,o.state[2]=65,o.state[3]=68);for(e=0;e<8;e++)u(this)}},{key:"getUint32",value:function(){return u(this),this.state[3]+this.state[2]>>>0}},{key:"getFloat",value:function(){return(this.getUint32()>>>8)*n}},{key:"random",get:function(){return this._random||(this._random=this.getFloat.bind(this)),this._random}}]),t}();e.default=i;var o=15,s=18,a=11;function u(t){var e=t.state[0];e^=e<<o,e^=e>>>s,e^=t.state[3]<<a,t.state[0]=t.state[1],t.state[1]=t.state[2],t.state[2]=t.state[3],t.state[3]=e}t.exports=e.default}));unwrapExports(xsaddEs5);var acc=t=>{const e=t.cutoffs.length,r=new Array(e);for(var n=0;n<e;n++)r[n]=(t.tn[n]+t.tp[n])/(e-1);return r},err=t=>{const e=t.cutoffs.length,r=new Array(e);for(var n=0;n<e;n++)r[n]=t.fn[n]+t.fp[n]/(e-1);return r},fpr=t=>{const e=t.cutoffs.length,r=new Array(e);for(var n=0;n<e;n++)r[n]=t.fp[n]/t.nNeg;return r},tpr=t=>{const e=t.cutoffs.length,r=new Array(e);for(var n=0;n<e;n++)r[n]=t.tp[n]/t.nPos;return r},fnr=t=>{const e=t.cutoffs.length,r=new Array(e);for(var n=0;n<e;n++)r[n]=t.fn[n]/t.nPos;return r},tnr=t=>{const e=t.cutoffs.length,r=new Array(e);for(var n=0;n<e;n++)r[n]=t.tn[n]/t.nNeg;return r},ppv=t=>{const e=t.cutoffs.length,r=new Array(e);for(var n=0;n<e;n++)r[n]=t.fp[n]+t.tp[n]!==0?t.tp[n]/(t.fp[n]+t.tp[n]):0;return r},npv=t=>{const e=t.cutoffs.length,r=new Array(e);for(var n=0;n<e;n++)r[n]=t.fn[n]+t.tn[n]!==0?t.tn[n]/(t.fn[n]+t.tn[n]):0;return r},pcfall=t=>{const e=t.cutoffs.length,r=new Array(e);for(var n=0;n<e;n++)r[n]=t.fp[n]+t.tp[n]!==0?1-t.tp[n]/(t.fp[n]+t.tp[n]):1;return r},pcmiss=t=>{const e=t.cutoffs.length,r=new Array(e);for(var n=0;n<e;n++)r[n]=t.fn[n]+t.tn[n]!==0?1-t.tn[n]/(t.fn[n]+t.tn[n]):1;return r},lift=t=>{const e=t.cutoffs.length,r=new Array(e);for(var n=0;n<e;n++)r[n]=0!==t.nPosPred[n]?t.tp[n]/t.nPos/(t.nPosPred[n]/t.nSamples):0;return r},rpp=t=>{const e=t.cutoffs.length,r=new Array(e);for(var n=0;n<e;n++)r[n]=t.nPosPred[n]/t.nSamples;return r},rnp=t=>{const e=t.cutoffs.length,r=new Array(e);for(var n=0;n<e;n++)r[n]=t.nNegPred[n]/t.nSamples;return r},threshold=t=>{const e=t.cutoffs.slice();return e[0]=e[1],e},measures={acc:acc,err:err,fpr:fpr,tpr:tpr,fnr:fnr,tnr:tnr,ppv:ppv,npv:npv,pcfall:pcfall,pcmiss:pcmiss,lift:lift,rpp:rpp,rnp:rnp,threshold:threshold};class Performance{constructor(t,e,r){if(r=r||{},t.length!==e.length||t[0].length!==e[0].length)throw new Error("dimensions of prediction and target do not match");const n=t.length,i=t[0].length,o=!r.max,s=[];if(r.all)for(var a=0;a<n;a++)for(var u=0;u<i;u++)s.push({pred:t[a][u],targ:e[a][u]});else{if(n<3||n!==i)throw new Error('When "all" option is false, the prediction matrix must be square and have at least 3 columns');for(a=0;a<n-1;a++)for(u=a+1;u<i;u++)s.push({pred:t[a][u],targ:e[a][u]})}o?s.sort(((t,e)=>t.pred-e.pred)):s.sort(((t,e)=>e.pred-t.pred));const h=this.cutoffs=[o?Number.MIN_VALUE:Number.MAX_VALUE],c=this.fp=[0],l=this.tp=[0];var f=0,m=0,p=s[0].pred,d=0,g=0;for(a=0;a<s.length;a++)s[a].pred!==p&&(h.push(p),c.push(g),l.push(d),p=s[a].pred),s[a].targ?(f++,d++):(m++,g++);h.push(p),c.push(g),l.push(d);const v=h.length,w=this.fn=new Array(v),y=this.tn=new Array(v),b=this.nPosPred=new Array(v),x=this.nNegPred=new Array(v);for(a=0;a<v;a++)w[a]=f-l[a],y[a]=m-c[a],b[a]=l[a]+c[a],x[a]=y[a]+w[a];this.nPos=f,this.nNeg=m,this.nSamples=f+m}getMeasure(t){if("string"!=typeof t)throw new Error("No measure specified");if(!measures[t])throw new Error(`The specified measure (${t}) does not exist`);return measures[t](this)}getAURC(){const t=this.cutoffs.length,e=new Array(t),r=new Array(t);for(var n=0;n<t;n++)e[n]=this.fp[n]/this.nNeg,r[n]=this.tp[n]/this.nPos;var i=0;for(n=1;n<t;n++)i+=.5*(e[n]-e[n-1])*(r[n]+r[n-1]);return i}getAUDC(){const t=this.cutoffs.length,e=new Array(t),r=new Array(t);for(var n=0;n<t;n++)e[n]=this.fn[n]/this.nPos,r[n]=this.fp[n]/this.nNeg;var i=0;for(n=1;n<t;n++)i+=.5*(e[n]+e[n-1])*(r[n]-r[n-1]);return i}getDistribution(t){t=t||{};for(var e=this.cutoffs.length,r=t.xMin||Math.floor(100*this.cutoffs[e-1])/100,n=t.xMax||Math.ceil(100*this.cutoffs[1])/100,i=t.interval||Math.floor((n-r)/20*1e7-1)/1e7,o=[],s=[],a=[],u=[],h=[],c=this.tp[e-1],l=0,f=this.fp[e-1],m=0,p=r,d=e-1;p<=n;p+=i){for(;this.cutoffs[d]<p;)d--;o.push(p);var g=c-l-this.tp[d],v=f-m-this.fp[d];l+=g,m+=v,s.push(v),a.push(g),u.push(100-(f-this.fp[d])/f*100),h.push(100-(c-this.tp[d])/c*100)}return{xLabels:o,interValues:s,intraValues:a,interCumPercent:u,intraCumPercent:h}}}Performance.names={acc:"Accuracy",err:"Error rate",fpr:"False positive rate",tpr:"True positive rate",fnr:"False negative rate",tnr:"True negative rate",ppv:"Positive predictive value",npv:"Negative predictive value",pcfall:"Prediction-conditioned fallout",pcmiss:"Prediction-conditioned miss",lift:"Lift value",rpp:"Rate of positive predictions",rnp:"Rate of negative predictions",threshold:"Threshold"};var src$h=Performance,hasOwn=Object.prototype.hasOwnProperty,toStr=Object.prototype.toString,isArray$4=function(t){return"function"==typeof Array.isArray?Array.isArray(t):"[object Array]"===toStr.call(t)},isPlainObject=function(t){if(!t||"[object Object]"!==toStr.call(t))return!1;var e,r=hasOwn.call(t,"constructor"),n=t.constructor&&t.constructor.prototype&&hasOwn.call(t.constructor.prototype,"isPrototypeOf");if(t.constructor&&!r&&!n)return!1;for(e in t);return void 0===e||hasOwn.call(t,e)},extend=function t(){var e,r,n,i,o,s,a=arguments[0],u=1,h=arguments.length,c=!1;for("boolean"==typeof a&&(c=a,a=arguments[1]||{},u=2),(null==a||"object"!=typeof a&&"function"!=typeof a)&&(a={});u<h;++u)if(null!=(e=arguments[u]))for(r in e)n=a[r],a!==(i=e[r])&&(c&&i&&(isPlainObject(i)||(o=isArray$4(i)))?(o?(o=!1,s=n&&isArray$4(n)?n:[]):s=n&&isPlainObject(n)?n:{},a[r]=t(c,s,i)):void 0!==i&&(a[r]=i));return a},defaultOptions$o={size:1,value:0};function arrayCase(t,e){var r=t.length;"number"==typeof e.size&&(e.size=[e.size,e.size]);var n,i,o=r+e.size[0]+e.size[1];if(e.output){if(e.output.length!==o)throw new RangeError("Wrong output size");n=e.output}else n=new Array(o);if("circular"===e.value)for(i=0;i<o;i++)i<e.size[0]?n[i]=t[(r-e.size[0]%r+i)%r]:i<e.size[0]+r?n[i]=t[i-e.size[0]]:n[i]=t[(i-e.size[0])%r];else if("replicate"===e.value)for(i=0;i<o;i++)i<e.size[0]?n[i]=t[0]:i<e.size[0]+r?n[i]=t[i-e.size[0]]:n[i]=t[r-1];else if("symmetric"===e.value){if(e.size[0]>r||e.size[1]>r)throw new RangeError("expanded value should not be bigger than the data length");for(i=0;i<o;i++)i<e.size[0]?n[i]=t[e.size[0]-1-i]:i<e.size[0]+r?n[i]=t[i-e.size[0]]:n[i]=t[2*r+e.size[0]-i-1]}else for(i=0;i<o;i++)i<e.size[0]?n[i]=e.value:i<e.size[0]+r?n[i]=t[i-e.size[0]]:n[i]=e.value;return n}function matrixCase(t,e){t.length,t[0].length;throw void 0===e.size[0]&&(e.size=[e.size,e.size,e.size,e.size]),new Error("matrix not supported yet, sorry")}function padArray(t,e){if(e=extend({},defaultOptions$o,e),Array.isArray(t))return Array.isArray(t[0])?matrixCase(t,e):arrayCase(t,e);throw new TypeError("data should be an array")}var src$i=padArray,Matrix$9=require$$0$3.Matrix,inverse$4=require$$0$3.inverse,defaultOptions$p={windowSize:5,derivative:1,polynomial:2,pad:"none",padValue:"replicate"};function SavitzkyGolay(t,e,r){if((r=extend({},defaultOptions$p,r)).windowSize%2==0||r.windowSize<5||!Number.isInteger(r.windowSize))throw new RangeError("Invalid window size (should be odd and at least 5 integer number)");if(r.derivative<0||!Number.isInteger(r.derivative))throw new RangeError("Derivative should be a positive integer");if(r.polynomial<1||!Number.isInteger(r.polynomial))throw new RangeError("Polynomial should be a positive integer");var n,i,o=Math.floor(r.windowSize/2);"pre"===r.pad&&(t=src$i(t,{size:o,value:r.padValue}));var s=new Array(t.length-2*o);if(5!==r.windowSize||2!==r.polynomial||1!==r.derivative&&2!==r.derivative){for(var a=Matrix$9.ones(r.windowSize,r.polynomial+1),u=-(r.windowSize-1)/2,h=0;h<a.length;h++)for(var c=0;c<a[h].length;c++)u+1===0&&0===c||(a[h][c]=Math.pow(u+h,c));var l=a.transposeView();n=(n=inverse$4(l.mmul(a)).mmul(l))[r.derivative],i=1}else 1===r.derivative?(n=[-2,-1,0,1,2],i=10):(n=[2,-1,-2,-1,2],i=7);for(var f=i*Math.pow(e,r.derivative),m=o;m<t.length-o;m++){for(var p=0,d=0;d<n.length;d++)p+=n[d]*t[d+m-o]/f;s[m-o]=p}return"post"===r.pad&&(s=src$i(s,{size:o,value:r.padValue})),s}var src$j=SavitzkyGolay,defaultOptions$q={windowSize:9,derivative:0,polynomial:3};function SavitzkyGolay$1(t,e,r){if((r=extend({},defaultOptions$q,r)).windowSize%2==0||r.windowSize<5||!Number.isInteger(r.windowSize))throw new RangeError("Invalid window size (should be odd and at least 5 integer number)");if(r.windowSize>t.length)throw new RangeError("Window size is higher than the data length "+r.windowSize+">"+t.length);if(r.derivative<0||!Number.isInteger(r.derivative))throw new RangeError("Derivative should be a positive integer");if(r.polynomial<1||!Number.isInteger(r.polynomial))throw new RangeError("Polynomial should be a positive integer");r.polynomial>=6&&console.warn("You should not use polynomial grade higher than 5 if you are not sure that your data arises from such a model. Possible polynomial oscillation problems");var n=r.windowSize,i=Math.floor(n/2),o=t.length,s=new Array(o),a=fullWeights(n,r.polynomial,r.derivative),u=0,h=!0;"[object Array]"===Object.prototype.toString.call(e)?h=!1:u=Math.pow(e,r.derivative);for(var c=0;c<i;c++){for(var l=a[i-c-1],f=a[i+c+1],m=0,p=0,d=0;d<n;d++)m+=l[d]*t[d],p+=f[d]*t[o-n+d-1];h?(s[i-c-1]=m/u,s[o-i+c]=p/u):(u=getHs(e,i-c-1,i,r.derivative),s[i-c-1]=m/u,u=getHs(e,o-i+c,i,r.derivative),s[o-i+c]=p/u)}var g=a[i];for(c=n;c<o+1;c++){var v=0;for(d=0;d<n;d++)v+=g[d]*t[d+c-n];h||(u=getHs(e,c-i-1,i,r.derivative)),s[c-i-1]=v/u}return s}function getHs(t,e,r,n){for(var i=0,o=0,s=e-r;s<e+r;s++)s>=0&&s<t.length-1&&(i+=t[s+1]-t[s],o++);return Math.pow(i/o,n)}function GramPoly(t,e,r,n){return r>0?(4*r-2)/(r*(2*e-r+1))*(t*GramPoly(t,e,r-1,n)+n*GramPoly(t,e,r-1,n-1))-(r-1)*(2*e+r)/(r*(2*e-r+1))*GramPoly(t,e,r-2,n):0==r&&0==n?1:0}function GenFact(t,e){var r=1;if(t>=e)for(var n=t-e+1;n<=t;n++)r*=n;return r}function Weight(t,e,r,n,i){for(var o=0,s=0;s<=n;s++)o+=(2*s+1)*(GenFact(2*r,s)/GenFact(2*r+s+1,s+1))*GramPoly(t,r,s,0)*GramPoly(e,r,s,i);return o}function fullWeights(t,e,r){for(var n=new Array(t),i=Math.floor(t/2),o=-i;o<=i;o++){n[o+i]=new Array(t);for(var s=-i;s<=i;s++)n[o+i][s+i]=Weight(s,o,i,e,r)}return n}for(var src$k=SavitzkyGolay$1,ans=new Array(256),i=0;i<256;i++){for(var num=i,c=0;num;)num&=num-1,c++;ans[i]=c}var creator=ans;function count(t){for(var e=0,r=0;r<t.length;r++)e+=creator[255&t[r]]+creator[t[r]>>8&255]+creator[t[r]>>16&255]+creator[t[r]>>24&255];return e}function and(t,e){for(var r=new Array(t.length),n=0;n<t.length;n++)r[n]=t[n]&e[n];return r}function or(t,e){for(var r=new Array(t.length),n=0;n<t.length;n++)r[n]=t[n]|e[n];return r}function xor(t,e){for(var r=new Array(t.length),n=0;n<t.length;n++)r[n]=t[n]^e[n];return r}function not(t){for(var e=new Array(t.length),r=0;r<e.length;r++)e[r]=~t[r];return e}function getBit(t,e){var r=1<<31-e%32;return Boolean(t[e>>5]&r)}function setBit(t,e,r){var n=e>>5,i=1<<31-e%32;return t[n]=r?i|t[n]:~i&t[n],t}function toBinaryString(t){for(var e="",r=0;r<t.length;r++){var n=(t[r]>>>0).toString(2);e+="00000000000000000000000000000000".substr(n.length)+n}return e}function parseBinaryString(t){for(var e=t.length/32,r=new Array(e),n=0;n<e;n++)r[n]=0|parseInt(t.substr(32*n,32),2);return r}function toHexString(t){for(var e="",r=0;r<t.length;r++){var n=(t[r]>>>0).toString(16);e+="00000000".substr(n.length)+n}return e}function parseHexString(t){for(var e=t.length/8,r=new Array(e),n=0;n<e;n++)r[n]=0|parseInt(t.substr(8*n,8),16);return r}function toDebug(t){for(var e=toBinaryString(t),r="",n=0;n<t.length;n++){r+="0000".substr((32*n).toString(16).length)+(32*n).toString(16)+":";for(var i=0;i<32;i+=4)r+=" "+e.substr(32*n+i,4);n<t.length-1&&(r+="\n")}return r}var src$l={count:count,and:and,or:or,xor:xor,not:not,getBit:getBit,setBit:setBit,toBinaryString:toBinaryString,parseBinaryString:parseBinaryString,toHexString:toHexString,parseHexString:parseHexString,toDebug:toDebug};const Stat=mlStat.array;function coordArrayToPoints(t,e){if(t.length%e!=0)throw new RangeError("Dimensions number must be accordance with the size of the array.");for(var r=t.length/e,n=new Array(r),i=0,o=0;o<t.length;o+=e){for(var s=new Array(e),a=0;a<e;++a)s[a]=t[o+a];n[i]=s,i++}return n}function coordArrayToCoordMatrix(t,e){if(t.length%e!=0)throw new RangeError("Dimensions number must be accordance with the size of the array.");for(var r=new Array(e),n=t.length/e,i=0;i<r.length;i++)r[i]=new Array(n);for(i=0;i<t.length;i+=e)for(var o=0;o<e;++o){var s=Math.floor(i/e);r[o][s]=t[i+o]}return r}function coordMatrixToCoordArray(t){for(var e=new Array(t.length*t[0].length),r=0,n=0;n<t[0].length;++n)for(var i=0;i<t.length;++i)e[r]=t[i][n],++r;return e}function transpose(t){for(var e=new Array(t[0].length),r=0;r<e.length;++r)e[r]=new Array(t.length);for(r=0;r<t.length;++r)for(var n=0;n<t[0].length;++n)e[n][r]=t[r][n];return e}function pointsToCoordArray(t){for(var e=new Array(t.length*t[0].length),r=0,n=0;n<t.length;++n)for(var i=0;i<t[0].length;++i)e[r]=t[n][i],++r;return e}function applyDotProduct(t,e){var r,n;t.length<=e.length?(n=t,r=e):(n=e,r=t);for(var i=r.length-n.length+1,o=new Array(i),s=0;s<i;++s){for(var a=0,u=0;u<n.length;++u)a+=n[u]*r[s+u];o[s]=a}return o}function scale(t,e={}){const{min:r,max:n}=e;var i=e.inPlace?t:new Array(t.length),o=Stat.minMax(t);if("number"==typeof n)if("number"==typeof r){let e=(n-r)/(o.max-o.min);for(let n=0;n<i.length;n++)i[n]=(t[n]-o.min)*e+r}else if(0!==o.max){let e=n/o.max;for(let r=0;r<i.length;r++)i[r]=t[r]*e}else e.min=o.min,i=scale(t,e);else if("number"==typeof r)if(0!==o.min){let e=r/o.min;for(let r=0;r<i.length;r++)i[r]=t[r]*e}else e.max=o.max,i=scale(t,e);return i}var ArrayUtils={coordArrayToPoints:coordArrayToPoints,coordArrayToCoordMatrix:coordArrayToCoordMatrix,coordMatrixToCoordArray:coordMatrixToCoordArray,coordMatrixToPoints:transpose,pointsToCoordArray:pointsToCoordArray,pointsToCoordMatrix:transpose,applyDotProduct:applyDotProduct,scale:scale};function getEquallySpacedData(t,e,r={}){var n=t.length;t.length>1&&t[0]>t[1]&&(t=t.slice().reverse(),e=e.slice().reverse());var{from:i=t[0],to:o=t[n-1],variant:s="smooth",numberOfPoints:a=100}=r;if(n!==e.length)throw new RangeError("the x and y vector doesn't have the same size.");if("number"!=typeof i||isNaN(i))throw new RangeError("'from' option must be a number");if("number"!=typeof o||isNaN(o))throw new RangeError("'to' option must be a number");var u=i>o;if(u&&([i,o]=[o,i]),"number"!=typeof a||isNaN(a))throw new RangeError("'numberOfPoints' option must be a number");if(a<1)throw new RangeError("the number of points must be at least 1");var h="slot"===s?getEquallySpacedSlot(t,e,i,o,a):getEquallySpacedSmooth(t,e,i,o,a);return u?h.reverse():h}function getEquallySpacedSmooth(t,e,r,n,i){var o=t.length,s=(n-r)/(i-1),a=s/2,u=new Array(i),h=t[1]-t[0],c=t[o-1]-t[o-2],l=r-a,f=r+a,m=Number.MIN_VALUE,p=0,d=t[0]-h,g=0,v=0,w=0,y=0,b=0,x=0,M=0,_=0;t:for(;;){for(m<=l&&l<=d&&(b=v+($=integral(0,l-m,w,p)));d-f>=0;){var $=integral(0,f-m,w,p);if(x=v+$,u[_++]=(x-b)/s,_===i)break t;l=f,f+=s,b=x}v+=integral(m,d,w,y),m=d,p=g,M<o?(d=t[M],g=e[M],M++):M===o&&(d+=c,g=0),y=-(w=(g-p)/(d-m))*m+p}return u}function getEquallySpacedSlot(t,e,r,n,i){var o=t.length,s=(n-r)/(i-1),a=s/2,u=t[t.length-1]-t[t.length-2],h=r-a,c=new Array(i),l=h,f=h+s,m=-Number.MAX_VALUE,p=0,d=t[0],g=e[0],v=0,w=!0,y=0,b=0,x=1,M=0;t:for(;;){if(m>=d)throw new Error("x must be an increasing serie");for(;m-f>0;){if(w&&(b++,w=!1),c[M]=b<=0?0:y/b,++M===i)break t;l=f,f+=s,y=0,b=0}m>l&&(y+=p,b++),(m===-Number.MAX_VALUE||v>1)&&b--,m=d,p=g,x<o?(d=t[x],g=e[x],x++):(d+=u,g=0,v++)}return c}function integral(t,e,r,n){return.5*r*e*e+n*e-(.5*r*t*t+n*t)}var getEquallySpacedData_1=getEquallySpacedData,integral_1=integral,getEquallySpaced={getEquallySpacedData:getEquallySpacedData_1,integral:integral_1},SNV_1=SNV,Stat$1=mlStat.array;function SNV(t){for(var e=Stat$1.mean(t),r=Stat$1.standardDeviation(t),n=t.slice(),i=0;i<t.length;i++)n[i]=(n[i]-e)/r;return n}var snv={SNV:SNV_1},src$m=createCommonjsModule((function(t,e){t.exports=e=ArrayUtils,e.getEquallySpacedData=getEquallySpaced.getEquallySpacedData,e.SNV=snv.SNV})),src_1$2=src$m.getEquallySpacedData,src_2$2=src$m.SNV,require$$5=src$7&&KNN||src$7,src$n=createCommonjsModule((function(t,e){const r=e;r.PCA=pca,r.HClust=src$4,r.KMeans=kmeans_1,r.SVM=svm,r.NaiveBayes=src$6,r.KNN=require$$5,r.PLS=src$8,r.CrossValidation=src$b,r.ConfusionMatrix=src$9,r.DecisionTreeClassifier=src.DecisionTreeClassifier,r.RandomForestClassifier=src$1.RandomForestClassifier,r.FNN=FeedForwardNeuralNetwork,r.SOM=src$c,r.SimpleLinearRegression=src$d.SimpleLinearRegression,r.PolynomialRegression=src$d.PolynomialRegression,r.MultivariateLinearRegression=src$d.MultivariateLinearRegression,r.PowerRegression=src$d.PowerRegression,r.ExponentialRegression=src$d.ExponentialRegression,r.TheilSenRegression=src$d.TheilSenRegression,r.RobustPolynomialRegression=src$d.RobustPolynomialRegression,r.DesisionTreeRegression=src.DesisionTreeRegression,r.RandomForestRegression=src$1.RandomForestRegression,r.levenbergMarquardt=lib,r.Matrix=require$$0$3.Matrix,r.SVD=require$$0$3.SVD,r.EVD=require$$0$3.EVD,r.CholeskyDecomposition=require$$0$3.CholeskyDecomposition,r.LuDecomposition=require$$0$3.LuDecomposition,r.QrDecomposition=require$$0$3.QrDecomposition,r.SparseMatrix=src$e,r.Kernel=kernel,r.Distance=src$g.distance,r.Similarity=src$g.similarity,r.distanceMatrix=src$3,r.XSadd=xsaddEs5,r.Performance=src$h,r.savitzkyGolay=src$j,r.savitzkyGolayGeneralized=src$k,r.BitArray=src$l,r.HashTable=HashTable_1,r.padArray=src$i,r.binarySearch=binarySearch,r.numSort=numSort,r.ArrayUtils=src$m,r.Regression=src$d,r.MatrixUtil=require$$0$3,r.ArrayStat=mlStat.array,r.MatrixStat=mlStat.matrix})),INFINITY$2=1/0,MAX_SAFE_INTEGER$1=9007199254740991,MAX_INTEGER=17976931348623157e292,NAN=NaN,funcTag$1="[object Function]",genTag$1="[object GeneratorFunction]",symbolTag$1="[object Symbol]",reTrim=/^\s+|\s+$/g,reIsBadHex=/^[-+]0x[0-9a-f]+$/i,reIsBinary=/^0b[01]+$/i,reIsOctal=/^0o[0-7]+$/i,reIsUint$1=/^(?:0|[1-9]\d*)$/,freeParseInt=parseInt,objectProto$6=Object.prototype,objectToString$2=objectProto$6.toString,nativeCeil=Math.ceil,nativeMax=Math.max;function baseRange(t,e,r,n){for(var i=-1,o=nativeMax(nativeCeil((e-t)/(r||1)),0),s=Array(o);o--;)s[n?o:++i]=t,t+=r;return s}function createRange(t){return function(e,r,n){return n&&"number"!=typeof n&&isIterateeCall(e,r,n)&&(r=n=void 0),e=toFinite(e),void 0===r?(r=e,e=0):r=toFinite(r),baseRange(e,r,n=void 0===n?e<r?1:-1:toFinite(n),t)}}function isIndex$1(t,e){return!!(e=null==e?MAX_SAFE_INTEGER$1:e)&&("number"==typeof t||reIsUint$1.test(t))&&t>-1&&t%1==0&&t<e}function isIterateeCall(t,e,r){if(!isObject$2(r))return!1;var n=typeof e;return!!("number"==n?isArrayLike(r)&&isIndex$1(e,r.length):"string"==n&&e in r)&&eq$1(r[e],t)}function eq$1(t,e){return t===e||t!=t&&e!=e}function isArrayLike(t){return null!=t&&isLength(t.length)&&!isFunction$3(t)}function isFunction$3(t){var e=isObject$2(t)?objectToString$2.call(t):"";return e==funcTag$1||e==genTag$1}function isLength(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=MAX_SAFE_INTEGER$1}function isObject$2(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function isObjectLike$1(t){return!!t&&"object"==typeof t}function isSymbol$2(t){return"symbol"==typeof t||isObjectLike$1(t)&&objectToString$2.call(t)==symbolTag$1}function toFinite(t){return t?(t=toNumber(t))===INFINITY$2||t===-INFINITY$2?(t<0?-1:1)*MAX_INTEGER:t==t?t:0:0===t?t:0}function toNumber(t){if("number"==typeof t)return t;if(isSymbol$2(t))return NAN;if(isObject$2(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=isObject$2(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=t.replace(reTrim,"");var r=reIsBinary.test(t);return r||reIsOctal.test(t)?freeParseInt(t.slice(2),r?2:8):reIsBadHex.test(t)?NAN:+t}var range=createRange(),lodash_range=range,INFINITY$3=1/0,MAX_SAFE_INTEGER$2=9007199254740991,MAX_INTEGER$1=17976931348623157e292,NAN$1=NaN,funcTag$2="[object Function]",genTag$2="[object GeneratorFunction]",symbolTag$2="[object Symbol]",reTrim$1=/^\s+|\s+$/g,reIsBadHex$1=/^[-+]0x[0-9a-f]+$/i,reIsBinary$1=/^0b[01]+$/i,reIsOctal$1=/^0o[0-7]+$/i,reIsUint$2=/^(?:0|[1-9]\d*)$/,freeParseInt$1=parseInt,objectProto$7=Object.prototype,objectToString$3=objectProto$7.toString,nativeCeil$1=Math.ceil,nativeMax$1=Math.max;function baseRange$1(t,e,r,n){for(var i=-1,o=nativeMax$1(nativeCeil$1((e-t)/(r||1)),0),s=Array(o);o--;)s[n?o:++i]=t,t+=r;return s}function createRange$1(t){return function(e,r,n){return n&&"number"!=typeof n&&isIterateeCall$1(e,r,n)&&(r=n=void 0),e=toFinite$1(e),void 0===r?(r=e,e=0):r=toFinite$1(r),baseRange$1(e,r,n=void 0===n?e<r?1:-1:toFinite$1(n),t)}}function isIndex$2(t,e){return!!(e=null==e?MAX_SAFE_INTEGER$2:e)&&("number"==typeof t||reIsUint$2.test(t))&&t>-1&&t%1==0&&t<e}function isIterateeCall$1(t,e,r){if(!isObject$3(r))return!1;var n=typeof e;return!!("number"==n?isArrayLike$1(r)&&isIndex$2(e,r.length):"string"==n&&e in r)&&eq$2(r[e],t)}function eq$2(t,e){return t===e||t!=t&&e!=e}function isArrayLike$1(t){return null!=t&&isLength$1(t.length)&&!isFunction$4(t)}function isFunction$4(t){var e=isObject$3(t)?objectToString$3.call(t):"";return e==funcTag$2||e==genTag$2}function isLength$1(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=MAX_SAFE_INTEGER$2}function isObject$3(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function isObjectLike$2(t){return!!t&&"object"==typeof t}function isSymbol$3(t){return"symbol"==typeof t||isObjectLike$2(t)&&objectToString$3.call(t)==symbolTag$2}function toFinite$1(t){return t?(t=toNumber$1(t))===INFINITY$3||t===-INFINITY$3?(t<0?-1:1)*MAX_INTEGER$1:t==t?t:0:0===t?t:0}function toNumber$1(t){if("number"==typeof t)return t;if(isSymbol$3(t))return NAN$1;if(isObject$3(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=isObject$3(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=t.replace(reTrim$1,"");var r=reIsBinary$1.test(t);return r||reIsOctal$1.test(t)?freeParseInt$1(t.slice(2),r?2:8):reIsBadHex$1.test(t)?NAN$1:+t}var rangeRight=createRange$1(!0),lodash_rangeright=rangeRight;const avg$2=src$n.ArrayStat.mean,mean$3=avg$2,sum=src$n.ArrayStat.sum,scale$1=(t,e)=>t.map((r=>(r-avg$2(t))/e)),max$1=t=>t.concat([]).sort(((t,e)=>t<e))[0],min$1=t=>t.concat([]).sort(((t,e)=>t>e))[0],sd=src$n.ArrayStat.standardDeviation;function squaredDifference(t,e){return t.reduce(((t,r,n,i)=>(t.push(Math.pow(e[n]-r,2)),t)),[])}function standardError(t=[],e=[]){if(t.length!==e.length)throw new RangeError("arrays must have the same length");const r=squaredDifference(t,e);return Math.sqrt(sum(r)/(t.length-2))}function standardScore(t=[]){const e=avg$2(t),r=sd(t);return t.map((t=>(t-e)/r))}function coefficientOfDetermination(t=[],e=[]){if(t.length!==e.length)throw new RangeError("arrays must have the same length");const r=mean$3(t),n=sum(t.reduce(((e,n,i)=>(e.push(Math.pow(t[i]-r,2)),e)),[]));return(n-sum(t.reduce(((r,n,i)=>(r.push(Math.pow(t[i]-e[i],2)),r)),[])))/n}function adjustedCoefficentOfDetermination(t={}){const{actuals:e,estimates:r,rSquared:n,independentVariables:i,sampleSize:o}=t,s=n||coefficientOfDetermination(e,r),a=o||e.length;return 1-(a-1)/(a-(i+1))*(1-s)}function coefficientOfCorrelation(t=[],e=[]){if(t.length!==e.length)throw new RangeError("arrays must have the same length");const r=sum(t),n=sum(e),i=t.reduce(((r,n,i)=>r+=t[i]*e[i]),0),o=t.reduce(((t,e)=>t+=e*e),0),s=e.reduce(((t,e)=>t+=e*e),0),a=t.length;return(a*i-r*n)/Math.sqrt((a*o-Math.pow(r,2))*(a*s-Math.pow(n,2)))}function rSquared(t=[],e=[]){return Math.pow(coefficientOfCorrelation(t,e),2)}function pivotVector(t=[]){return t.reduce(((t,e,r)=>(e.forEach(((e,n)=>{0===r?t.push([e]):t[n].push(e)})),t)),[])}function pivotArrays(t=[]){return t.length?t[0].map(((e,r)=>{const n=[];return t.forEach(((e,i)=>{n.push(t[i][r])})),n})):t}const StandardScaler=t=>scale$1(t,sd(t));function StandardScalerTransforms(t=[],e=-1,r=!1,n={}){const i=void 0!==n.average?n.average:avg$2(t),o=void 0!==n.standard_dev?n.standard_dev:sd(t),s=void 0!==n.maximum?n.maximum:max$1(t),a=void 0!==n.minimum?n.minimum:min$1(t),u=t=>{const e=(t-i)/o;return isNaN(e)&&r?e:isNaN(e)&&!1===r?isNaN(o)?t:o:e},h=t.map(u).map((t=>isNaN(t)?e:t));return{components:{average:i,standard_dev:o,maximum:s,minimum:a},scale:u,descale:t=>{const e=t*o+i;return isNaN(e)&&r?e:isNaN(e)&&!1===r?isNaN(o)?t:o:e},values:h}}const MinMaxScaler=t=>scale$1(t,max$1(t)-min$1(t));function MinMaxScalerTransforms(t=[],e=-1,r=!1,n={}){const i=void 0!==n.average?n.average:avg$2(t),o=void 0!==n.standard_dev?n.standard_dev:sd(t),s=void 0!==n.maximum?n.maximum:max$1(t),a=void 0!==n.minimum?n.minimum:min$1(t),u=t=>{const e=(t-i)/(s-a);return isNaN(e)&&r?e:isNaN(e)&&!1===r?isNaN(o)?t:o:e},h=t.map(u).map((t=>isNaN(t)?e:t));return{components:{average:i,standard_dev:o,maximum:s,minimum:a},scale:u,descale:t=>{const e=t*(s-a)+i;return isNaN(e)&&r?e:isNaN(e)&&!1===r?isNaN(o)?t:o:e},values:h}}function approximateZPercentile(t,e=!0){if(t<-6.5)return 0;if(t>6.5)return 1;let r=1,n=0,i=1,o=0,s=Math.exp(-23);for(;Math.abs(i)>s;)i=.3989422804*Math.pow(-1,o)*Math.pow(t,o)/(2*o+1)/Math.pow(2,o)*Math.pow(t,o+1)/r,n+=i,o++,r*=o;return n+=.5,e?1-n:n}function getSafePropertyName(t){return t.replace(/[^\w\s]/gi,"_")}function forecastErrors(t,e){if(t.length!==e.length)throw new Error(`Actuals length (${t.length}) must equal Estimates length (${e.length})`);return t.map(((t,r)=>t-e[r]))}function meanForecastError(t,e){const r=forecastErrors(t,e);return avg$2(r)}function meanAbsoluteDeviation(t,e){const r=forecastErrors(t,e).map((t=>Math.abs(t)));return avg$2(r)}function trackingSignal(t,e){return sum(forecastErrors(t,e))/meanAbsoluteDeviation(t,e)}function meanSquaredError(t,e){const r=forecastErrors(t,e).map((t=>t*t));return avg$2(r)}function MADMeanRatio(t,e){return meanAbsoluteDeviation(t,e)/avg$2(t)}function meanAbsolutePercentageError(t,e){const r=forecastErrors(t,e).map((t=>Math.abs(t))).map(((e,r)=>e/t[r]));return avg$2(r)}const util$3={range:lodash_range,rangeRight:lodash_rangeright,scale:scale$1,avg:avg$2,mean:avg$2,sum:sum,max:max$1,min:min$1,sd:sd,StandardScaler:StandardScaler,StandardScalerTransforms:StandardScalerTransforms,MinMaxScaler:MinMaxScaler,MinMaxScalerTransforms:MinMaxScalerTransforms,LogScaler:t=>t.map(Math.log),ExpScaler:t=>t.map(Math.exp),squaredDifference:squaredDifference,standardError:standardError,coefficientOfDetermination:coefficientOfDetermination,coefficientOfCorrelation:coefficientOfCorrelation,r:coefficientOfCorrelation,rSquared:rSquared,adjustedCoefficentOfDetermination:adjustedCoefficentOfDetermination,rBarSquared:adjustedCoefficentOfDetermination,adjustedRSquared:adjustedCoefficentOfDetermination,pivotVector:pivotVector,pivotArrays:pivotArrays,standardScore:standardScore,zScore:standardScore,approximateZPercentile:approximateZPercentile,getSafePropertyName:getSafePropertyName,forecastErrors:forecastErrors,meanForecastError:meanForecastError,MFE:meanForecastError,meanAbsoluteDeviation:meanAbsoluteDeviation,MAD:meanAbsoluteDeviation,trackingSignal:trackingSignal,TS:trackingSignal,meanSquaredError:meanSquaredError,MSE:meanSquaredError,MADMeanRatio:MADMeanRatio,MMR:MADMeanRatio,meanAbsolutePercentageError:meanAbsolutePercentageError,MAPE:meanAbsolutePercentageError};var fpnode=createCommonjsModule((function(t,e){Object.defineProperty(e,"__esModule",{value:!0});var r=function(){function t(t,e){void 0===t&&(t=null),void 0===e&&(e=null),this.item=t,this.parent=e,this.support=1,this.nextSameItemNode=null,this._children=[]}return Object.defineProperty(t.prototype,"children",{get:function(){return this._children},enumerable:!0,configurable:!0}),t.prototype.upsertChild=function(e,r,n){void 0===n&&(n=1);var i=this.getChild(e);return i?i.support+=n:((i=new t(e,this)).support=n,this._children.push(i),r&&r(i)),i},t.prototype.getChild=function(t){return this._children.find((function(e){return e.item==t}))},t}();e.FPNode=r}));unwrapExports(fpnode);var fpnode_1=fpnode.FPNode,fptree=createCommonjsModule((function(t,e){Object.defineProperty(e,"__esModule",{value:!0});var r=function(){function t(t,e){this.supports=t,this._support=e,this._isInit=!1,this.root=new fpnode.FPNode,this._firstInserted={},this._lastInserted={}}return Object.defineProperty(t.prototype,"headers",{get:function(){return this._headers},enumerable:!0,configurable:!0}),t.prototype.fromTransactions=function(t){var e=this;if(this._isInit)throw new Error("Error building the FPTree");return t.forEach((function(t){var r=t.filter((function(t){return e.supports[JSON.stringify(t)]>=e._support})).sort((function(t,r){var n=e.supports[JSON.stringify(r)]-e.supports[JSON.stringify(t)];return 0==n?JSON.stringify(r).localeCompare(JSON.stringify(t)):n}));e._addItems(r)})),this._headers=this._getHeaderList(),this._isInit=!0,this},t.prototype.fromPrefixPaths=function(t){var e=this;if(this._isInit)throw new Error("Error building the FPTree");return t.forEach((function(t){var r=t.path.filter((function(t){return e.supports[JSON.stringify(t)]>=e._support})).sort((function(t,r){var n=e.supports[JSON.stringify(r)]-e.supports[JSON.stringify(t)];return 0==n?JSON.stringify(r).localeCompare(JSON.stringify(t)):n}));e._addItems(r,t.support)})),this._headers=this._getHeaderList(),this._isInit=!0,this},t.prototype.getConditionalFPTree=function(e){var r=this._firstInserted[JSON.stringify(e)];if(!r)return null;var n=this.supports[JSON.stringify(e)],i={},o=this._getPrefixPaths(r,n,(function(t,e){i[JSON.stringify(t)]=(i[JSON.stringify(t)]||0)+e})),s=new t(i,this._support).fromPrefixPaths(o);return s.root.children.length?s:null},t.prototype.getPrefixPaths=function(t){if(!this._isInit)throw new Error("Error building the FPTree");var e=this._firstInserted[JSON.stringify(t)];return e?this._getPrefixPaths(e,e.support):[]},t.prototype.getPrefixPath=function(t,e){if(!this._isInit)throw new Error("Error building the FPTree");var r=this._getPrefixPath(t,t.support,e);if(0!==r.length)return{support:t.support,path:r}},t.prototype.isSinglePath=function(){if(!this._isInit)throw new Error("Error building the FPTree");return!!this.getSinglePath()},t.prototype.getSinglePath=function(){if(!this._isInit)throw new Error("Error building the FPTree");return this._getSinglePath(this.root)},t.prototype._addItems=function(t,e){var r=this;void 0===e&&(e=1);var n=this.root;t.forEach((function(t){n=n.upsertChild(t,(function(e){var n=JSON.stringify(t);r._updateLastInserted(n,e),r._updateFirstInserted(n,e)}),e)}))},t.prototype._getPrefixPaths=function(t,e,r,n){void 0===n&&(n=[]);var i=this.getPrefixPath(t,r);return i&&n.push(i),t.nextSameItemNode?this._getPrefixPaths(t.nextSameItemNode,e,r,n):n},t.prototype._getPrefixPath=function(t,e,r){return t.parent&&t.parent.parent?(r&&r(t.parent.item,e),[t.parent.item].concat(this._getPrefixPath(t.parent,e,r))):[]},t.prototype._getSinglePath=function(t,e){return void 0===e&&(e=[]),0==t.children.length?e:t.children.length>1?null:(e.push(t.children[0]),this._getSinglePath(t.children[0],e))},t.prototype._updateLastInserted=function(t,e){var r=this._lastInserted[t];r&&(r.nextSameItemNode=e),this._lastInserted[t]=e},t.prototype._updateFirstInserted=function(t,e){this._firstInserted[t]||(this._firstInserted[t]=e)},t.prototype._getHeaderList=function(){var t=this;return Object.keys(this._firstInserted).sort((function(e,r){return t.supports[e]-t.supports[r]})).map((function(t){return JSON.parse(t)}))},t}();e.FPTree=r}));unwrapExports(fptree);var fptree_1=fptree.FPTree,events_1=events&&EventEmitter||events,fpgrowth=createCommonjsModule((function(t,e){var r,n=commonjsGlobal&&commonjsGlobal.__extends||(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])},function(t,e){function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)});Object.defineProperty(e,"__esModule",{value:!0});var i=function(t){function e(e){var r=t.call(this)||this;return r._support=e,r._itemsets=[],r}return n(e,t),e.prototype.exec=function(t,e){var r=this;this._transactions=t,this._support=Math.ceil(this._support*t.length);var n=this._getDistinctItemsCount(this._transactions);return new Promise((function(t,i){var o=new fptree.FPTree(n,r._support).fromTransactions(r._transactions),s=r._fpGrowth(o,r._transactions.length);e&&e(s),t(s)}))},e.prototype._fpGrowth=function(t,e,r){var n=this;return void 0===r&&(r=[]),t.headers.reduce((function(i,o){var s=Math.min(t.supports[JSON.stringify(o)],e),a=r.slice(0);a.push(o),i.push(n._getFrequentItemset(a,s));var u=t.getConditionalFPTree(o);return u?i.concat(n._fpGrowth(u,s,a)):i}),[])},e.prototype._handleSinglePath=function(t,e){return[]},e.prototype._getFrequentItemset=function(t,e){var r={items:t,support:e};return this.emit("data",r),r},e.prototype._getDistinctItemsCount=function(t){return t.reduce((function(t,e){return e.reduce((function(t,e){return t[JSON.stringify(e)]=(t[JSON.stringify(e)]||0)+1,t}),t)}),{})},e}(events_1.EventEmitter);e.FPGrowth=i})),fpg=unwrapExports(fpgrowth),fpgrowth_1=fpgrowth.FPGrowth;const{FPGrowth:FPGrowth}=fpg;function getTransactions(t,e){const r=Object.assign({},{exludeEmptyTranscations:!0},e),n=new Set,i=new Map,o=t.map((t=>([...Object.values(t)].forEach((t=>{n.add(t)})),n.forEach((t=>{if(!i.get(t)){const e=i.size<0?0:parseInt(i.size/2,10);i.set(t,e.toString()),i.set(e.toString(),t)}})),Object.values(t).map((t=>i.get(t))).filter((t=>void 0!==t)))));return{values:n,valuesMap:i,transactions:r.exludeEmptyTranscations?o.filter((t=>t.length)):o}}function assocationRuleLearning(t=[],e){return new Promise(((r,n)=>{try{const i=Object.assign({},{support:.4,minLength:2,summary:!0,valuesMap:new Map},e);new FPGrowth(i.support).exec(t).then((e=>{const n=e.itemsets?e.itemsets:e;i.summary?r(n.map((e=>({items_labels:e.items.map((t=>i.valuesMap.get(t))),items:e.items,support:e.support,support_percent:e.support/t.length}))).filter((t=>t.items.length>1)).sort(((t,e)=>e.support-t.support))):r(e)})).catch(n)}catch(t){n(t)}}))}const calc={getTransactions:getTransactions,assocationRuleLearning:assocationRuleLearning};var exp=Math.exp,ln=Math.log,PI=Math.PI,pow=Math.pow,probabilityDistributions={prng:function(t){void 0===t&&(t=16);for(var e=require$$0$2.randomBytes(t),r=0,n=0;n<t;n++)r+=Number(e[n])/Math.pow(256,n+1);return r},rbeta:function(t,e,r,n){t=this._v(t,"n"),e=this._v(e,"nn",1),r=this._v(r,"nn",1),n=this._v(n,"r",0);for(var i=[],o=0;o<t;o++){var s=this.rgamma(1,e,1)[0],a=this.rgamma(1,r,1)[0];i[o]=n+s/(s+a)}return i},rbinom:function(t,e,r){t=this._v(t,"n"),e=this._v(e,"nni",1),r=this._v(r,"p",.5);for(var n=[],i=0;i<t;i++){for(var o=0,s=0;s<e;s++)this.prng()<r&&o++;n[i]=o}return n},rcauchy:function(t,e,r){t=this._v(t,"n"),e=this._v(e,"r",0),r=this._v(r,"nn",1);for(var n=[],i=0;i<t;i++){var o=r*Math.tan(PI*(this.prng()-.5))+e;n[i]=o}return n},rchisq:function(t,e,r){t=this._v(t,"n"),e=this._v(e,"nn"),r=this._v(r,"r",0);for(var n=[],i=0;i<t;i++){for(var o=r,s=0;s<e;s++)o+=Math.pow(this.rnorm(1)[0],2);n[i]=o}return n},dexp:function(t,e){return t=this._v(t,"r"),e=this._v(e,"pos",1),t<0?0:e*exp(-e*t)},rexp:function(t,e){t=this._v(t,"n"),e=this._v(e,"pos",1);for(var r=[],n=0;n<t;n++)r[n]=-ln(this.prng())/e;return r},rf:function(t,e,r){t=this._v(t,"n"),e=this._v(e,"nn"),r=this._v(r,"nn");for(var n=[],i=0;i<t;i++){var o=this.rchisq(1,e)[0]/e,s=this.rchisq(1,r)[0]/r;n[i]=o/s}return n},rgamma:function(t,e,r){t=this._v(t,"n"),e=this._v(e,"nn"),r=this._v(r,"pos",1);for(var n=ln(4),i=1+ln(4.5),o=1/r,s=[],a=0;a<t;a++){if(e>1)for(var u=Math.sqrt(2*e-1),h=e-n,c=e+u;;){if(!((b=this.prng())<1e-7||g>.9999999)){var l=1-this.prng(),f=ln(b/(1-b))/u,m=b*b*l,p=h+c*f-(y=e*exp(f));if(p+i-4.5*m>=0||p>=ln(m)){var d=y*o;break}}}else if(1==e){for(var g=this.prng();g<=1e-7;)g=this.prng();d=-ln(g)*o}else{for(;;){g=this.prng();var v=(Math.E+e)/Math.E,w=v*g;if(w<=1)var y=Math.pow(w,1/e);else y=-ln((v-w)/e);var b=this.prng();if(w>1){if(b<=Math.pow(y,e-1))break}else if(b<=exp(-y))break}d=y*o}s[a]=d}return s},rint:function(t,e,r,n){if(t=this._v(t,"n"),e=this._v(e,"int"),r=this._v(r,"int"),!1===n){if(++e===r)throw new Error("Minimum value cannot be greater than maximum value. For non-inclusive, minimum and maximum must be separated by at least 2.")}else r++;if(e>r)throw new Error("Minimum value cannot be greater than maximum value. For non-inclusive, minimum and maximum must be separated by at least 2.");for(var i=[],o=this.runif(t,e,r),s=0;s<t;s++)i[s]=Math.floor(o[s]);return i},rlaplace:function(t,e,r){t=this._v(t,"n"),e=this._v(e,"r",0),r=this._v(r,"nn",1);for(var n=[],i=0;i<t;i++){var o=e-r*(this.sample([-1,1])[0]*ln(this.prng()));n[i]=o}return n},rlnorm:function(t,e,r){t=this._v(t,"n"),e=this._v(e,"r",0),r=this._v(r,"nn",1);for(var n=[],i=0;i<t;i++){var o=this.rnorm(1,e,r)[0];n[i]=exp(o)}return n},rnbinom:function(t,e,r,n){if(t=this._v(t,"n"),void 0===e&&(e=1),Math.round(e)!=e)throw new Error("Size must be a whole number");if(e<1)throw new Error("Size must be one or greater");if(void 0!==r&&void 0!==n)throw new Error("You must specify probability or mean, not both");void 0!==n&&(r=e/(e+n)),r=this._v(r,"p");for(var i=[],o=0;o<t;o++){for(var s=0,a=e;a>0;)s++,this.prng()<r&&a--;i[o]=s-1}return i},dnorm:function(t,e,r){return t=this._v(t,"r"),e=this._v(e,"r",0),0===(r=this._v(r,"nn",1))?t===e?1/0:0:1/(r*Math.sqrt(2*PI))*exp(-(t-e)*(t-e)/(2*r*r))},rnorm:function(t,e,r){t=this._v(t,"n"),e=this._v(e,"r",0),r=this._v(r,"nn",1);for(var n=[],i=0;i<t;i++){var o,s,a,u;do{a=(o=2*this.prng()-1)*o+(s=2*this.prng()-1)*s}while(a>1);u=e+r*(u=Math.sqrt(-2*ln(a)/a)*o),n.push(u)}return n},dpois:function(t,e){return t=this._v(t,"nni"),0===(e=this._v(e,"nn"))?0===t?1:0:pow(e,t)*exp(-e)/this._factorial(t)},rpois:function(t,e){t=this._v(t,"n"),e=this._v(e,"pos");for(var r=[],n=0;n<t;n++)if(e<30){var i=exp(-e),o=1,s=0;do{s++,o*=this.prng()}while(o>i);r.push(s-1)}else{o=e/1e4,s=0;for(var a=0;a<1e4;a++)this.prng()<o&&s++;r[n]=s}return r},dunif:function(t,e,r){if(t=this._v(t,"r"),(e=this._v(e,"r",0))>(r=this._v(r,"r",1)))throw new Error("Minimum value cannot be greater than maximum value");return t<e||t>r?0:e===r?1/0:1/(r-e)},runif:function(t,e,r){if(t=this._v(t,"n"),(e=this._v(e,"r",0))>(r=this._v(r,"r",1)))throw new Error("Minimum value cannot be greater than maximum value");for(var n=[],i=0;i<t;i++){var o=e+this.prng()*(r-e);n.push(o)}return n},rword:function(t,e){t=this._v(t,"n");var r=(e=this._v(e,"str","abcdefghijklmnopqrstuvwxyz")).split("");return this.sample(r,t,!0).join("")},sample:function(t,e,r,n){if(t=this._v(t,"a"),e=this._v(e,"n",t.length),void 0===r&&(r=!1),!r&&t.length<e)throw new Error("You cannot select "+e+" items from an array of length "+t.length+" without replacement");if(void 0===n){n=[];for(var i=0;i<t.length;i++)n[i]=1}for(var o=this._getCumulativeProbs(n,t.length),s=[],a=0;a<e;a++){var u=this._sampleOneIndex(o);r?s[a]=t[u]:(s[a]=t.splice(u,1)[0],n.splice(u,1),n.length&&(o=this._getCumulativeProbs(n,t.length)))}return s},visualize:function(data,domID,options){var defaultOptions={lag:1e3,blank:"",inf:"&infin;",loop:!0,conditions:"",arrivalTimes:!1,arrivalSymbol:'<span class="pd-arrival">&#8226;</span>',arrivalFlashTime:.25,significantDigits:0};for(var property in void 0===options&&(options={}),defaultOptions)defaultOptions.hasOwnProperty(property)&&void 0===options[property]&&(options[property]=defaultOptions[property]);var elem=document.getElementById(domID);if(!elem)throw new Error("Unable to find DOM element "+domID);var len=data.length,i=0,format=function(x){var x=data[i];if(options.conditions){if(!/^[x\&\|=0-9\<\>\s\-\.]+$/.test(options.conditions))throw new Error("Bad input sent to options.conditions");if(!0!==eval(options.conditions))return x=options.blank,x}return options.significantDigits&&(x=x.toPrecision(options.significantDigits)),x===1/0&&(x=options.inf),x};if(options.arrivalTimes){var blankOut=function(){setTimeout((function(){elem.innerHTML=options.blank}),options.arrivalFlashTime*options.lag)},cycle=function(){elem.innerHTML=options.arrivalSymbol,blankOut(),++i===len&&(i=0),options.loop||0!==i?setTimeout(cycle,data[i]*options.lag):elem.innerHTML=options.blank};cycle()}else{var update=function(){elem.innerHTML=format(data[i]),++i===len&&(i=0),options.loop||0!==i?setTimeout(update,options.lag):setTimeout((function(){elem.innerHTML=options.blank}),options.lag)};update()}},_getCumulativeProbs:function(t,e){if(void 0===e)throw new Error("An error occurred: len was not sent to _getCumulativeProbs");if(t.length!==e)throw new Error("Probabilities for sample must be same length as the array to sample from");var r=[];if(void 0!==t){if((t=this._v(t,"a")).length!==e)throw new Error("Probabilities array must be the same length as the array you are sampling from");var n=0;t.map(function(t){t=this._v(t,"nn"),n+=t,r.push(n)}.bind(this));for(var i=0;i<r.length;i++)r[i]=r[i]/n;return r}},_sampleOneIndex:function(t){for(var e=this.prng(),r=0;e>t[r];)r++;return r},_factorial:function(t){for(var e=1,r=2;r<=t;r++)e*=r;return e},_v:function(t,e,r){if(null==t&&null!=r)return r;switch(e){case"a":if(!Array.isArray(t)||!t.length)throw new Error("Expected an array of length 1 or greater");return t.slice(0);case"int":if(t!==Number(t))throw new Error("A required parameter is missing or not a number");if(t!==Math.round(t))throw new Error("Parameter must be a whole number");if(t===1/0)throw new Error("Sent 'infinity' as a parameter");return t;case"n":if(void 0===t)throw new Error("You must specify how many values you want");if(t!==Number(t))throw new Error("The number of values must be numeric");if(t!==Math.round(t))throw new Error("The number of values must be a whole number");if(t<1)throw new Error("The number of values must be a whole number of 1 or greater");if(t===1/0)throw new Error("The number of values cannot be infinite ;-)");return t;case"p":if(Number(t)!==t)throw new Error("Probability value is missing or not a number");if(t>1)throw new Error("Probability values cannot be greater than 1");if(t<0)throw new Error("Probability values cannot be less than 0");return t;case"pos":if(Number(t)!==t)throw new Error("A required parameter is missing or not a number");if(t<=0)throw new Error("Parameter must be greater than 0");if(t===1/0)throw new Error("Sent 'infinity' as a parameter");return t;case"r":if(Number(t)!==t)throw new Error("A required parameter is missing or not a number");if(t===1/0)throw new Error("Sent 'infinity' as a parameter");return t;case"nn":if(t!==Number(t))throw new Error("A required parameter is missing or not a number");if(t<0)throw new Error("Parameter cannot be less than 0");if(t===1/0)throw new Error("Sent 'infinity' as a parameter");return t;case"nni":if(t!==Number(t))throw new Error("A required parameter is missing or not a number");if(t!==Math.round(t))throw new Error("Parameter must be a whole number");if(t<0)throw new Error("Parameter cannot be less than zero");if(t===1/0)throw new Error("Sent 'infinity' as a parameter");return t;case"str":if(t!==String(t))throw new Error("A required parameter is missing or not a string");if(0===t.length)throw new Error("Parameter must be at least one character long");return t}},rfml:function(t,e,r,n,i){t=this._v(t,"n"),e=this._v(e,"nni",1),void 0===r&&(r=this.prng),n=this._v(n,"n",1e4),void 0===i&&(i={});for(var o=[],s=0;s<t;s++){var a=0,u=e,h=r();if(0===e)o[s]=0;else{do{this.prng()<h?(u++,i[String(s)+"_"+String(a)]={problems:u,p:h,result:1}):(u--,i[String(s)+"_"+String(a)]={problems:u,p:h,result:-1}),a++}while(u>0&&a<n);a===n&&(a=-1),o[s]=a}}return o},ruf:function(t){t=this._v(t,"n");for(var e=[],r=0;r<t;r++)e[r]=this.rexp(1,this.prng())[0];return e}},probabilityDistributions_1=probabilityDistributions.prng,probabilityDistributions_2=probabilityDistributions.rbeta,probabilityDistributions_3=probabilityDistributions.rbinom,probabilityDistributions_4=probabilityDistributions.rcauchy,probabilityDistributions_5=probabilityDistributions.rchisq,probabilityDistributions_6=probabilityDistributions.dexp,probabilityDistributions_7=probabilityDistributions.rexp,probabilityDistributions_8=probabilityDistributions.rf,probabilityDistributions_9=probabilityDistributions.rgamma,probabilityDistributions_10=probabilityDistributions.rint,probabilityDistributions_11=probabilityDistributions.rlaplace,probabilityDistributions_12=probabilityDistributions.rlnorm,probabilityDistributions_13=probabilityDistributions.rnbinom,probabilityDistributions_14=probabilityDistributions.dnorm,probabilityDistributions_15=probabilityDistributions.rnorm,probabilityDistributions_16=probabilityDistributions.dpois,probabilityDistributions_17=probabilityDistributions.rpois,probabilityDistributions_18=probabilityDistributions.dunif,probabilityDistributions_19=probabilityDistributions.runif,probabilityDistributions_20=probabilityDistributions.rword,probabilityDistributions_21=probabilityDistributions.sample,probabilityDistributions_22=probabilityDistributions.visualize,probabilityDistributions_23=probabilityDistributions._getCumulativeProbs,probabilityDistributions_24=probabilityDistributions._sampleOneIndex,probabilityDistributions_25=probabilityDistributions._factorial,probabilityDistributions_26=probabilityDistributions._v,probabilityDistributions_27=probabilityDistributions.rfml,probabilityDistributions_28=probabilityDistributions.ruf,probabilty=Object.freeze({default:probabilityDistributions,__moduleExports:probabilityDistributions,prng:probabilityDistributions_1,rbeta:probabilityDistributions_2,rbinom:probabilityDistributions_3,rcauchy:probabilityDistributions_4,rchisq:probabilityDistributions_5,dexp:probabilityDistributions_6,rexp:probabilityDistributions_7,rf:probabilityDistributions_8,rgamma:probabilityDistributions_9,rint:probabilityDistributions_10,rlaplace:probabilityDistributions_11,rlnorm:probabilityDistributions_12,rnbinom:probabilityDistributions_13,dnorm:probabilityDistributions_14,rnorm:probabilityDistributions_15,dpois:probabilityDistributions_16,rpois:probabilityDistributions_17,dunif:probabilityDistributions_18,runif:probabilityDistributions_19,rword:probabilityDistributions_20,sample:probabilityDistributions_21,visualize:probabilityDistributions_22,_getCumulativeProbs:probabilityDistributions_23,_sampleOneIndex:probabilityDistributions_24,_factorial:probabilityDistributions_25,_v:probabilityDistributions_26,rfml:probabilityDistributions_27,ruf:probabilityDistributions_28});const PD=Object.assign({},probabilty);Symbol.species||(Symbol.species=Symbol.for("@@species"));class LuDecomposition$$1{constructor(t){var e,r,n,i,o,s,a,u,h,c=(t=WrapperMatrix2D$4.checkMatrix(t)).clone(),l=c.rows,f=c.columns,m=new Array(l),p=1;for(e=0;e<l;e++)m[e]=e;for(u=new Array(l),r=0;r<f;r++){for(e=0;e<l;e++)u[e]=c.get(e,r);for(e=0;e<l;e++){for(h=Math.min(e,r),o=0,n=0;n<h;n++)o+=c.get(e,n)*u[n];u[e]-=o,c.set(e,r,u[e])}for(i=r,e=r+1;e<l;e++)Math.abs(u[e])>Math.abs(u[i])&&(i=e);if(i!==r){for(n=0;n<f;n++)s=c.get(i,n),c.set(i,n,c.get(r,n)),c.set(r,n,s);a=m[i],m[i]=m[r],m[r]=a,p=-p}if(r<l&&0!==c.get(r,r))for(e=r+1;e<l;e++)c.set(e,r,c.get(e,r)/c.get(r,r))}this.LU=c,this.pivotVector=m,this.pivotSign=p}isSingular(){for(var t=this.LU,e=t.columns,r=0;r<e;r++)if(0===t[r][r])return!0;return!1}solve(t){t=Matrix$a.checkMatrix(t);var e=this.LU;if(e.rows!==t.rows)throw new Error("Invalid matrix dimensions");if(this.isSingular())throw new Error("LU matrix is singular");var r,n,i,o=t.columns,s=t.subMatrixRow(this.pivotVector,0,o-1),a=e.columns;for(i=0;i<a;i++)for(r=i+1;r<a;r++)for(n=0;n<o;n++)s[r][n]-=s[i][n]*e[r][i];for(i=a-1;i>=0;i--){for(n=0;n<o;n++)s[i][n]/=e[i][i];for(r=0;r<i;r++)for(n=0;n<o;n++)s[r][n]-=s[i][n]*e[r][i]}return s}get determinant(){var t=this.LU;if(!t.isSquare())throw new Error("Matrix must be square");for(var e=this.pivotSign,r=t.columns,n=0;n<r;n++)e*=t[n][n];return e}get lowerTriangularMatrix(){for(var t=this.LU,e=t.rows,r=t.columns,n=new Matrix$a(e,r),i=0;i<e;i++)for(var o=0;o<r;o++)n[i][o]=i>o?t[i][o]:i===o?1:0;return n}get upperTriangularMatrix(){for(var t=this.LU,e=t.rows,r=t.columns,n=new Matrix$a(e,r),i=0;i<e;i++)for(var o=0;o<r;o++)n[i][o]=i<=o?t[i][o]:0;return n}get pivotPermutationVector(){return this.pivotVector.slice()}}function hypotenuse$4(t,e){var r=0;return Math.abs(t)>Math.abs(e)?(r=e/t,Math.abs(t)*Math.sqrt(1+r*r)):0!==e?(r=t/e,Math.abs(e)*Math.sqrt(1+r*r)):0}function getFilled2DArray$4(t,e,r){for(var n=new Array(t),i=0;i<t;i++){n[i]=new Array(e);for(var o=0;o<e;o++)n[i][o]=r}return n}class SingularValueDecomposition$$1{constructor(t,e={}){var r=(t=WrapperMatrix2D$4.checkMatrix(t)).rows,n=t.columns,i=Math.min(r,n);const{computeLeftSingularVectors:o=!0,computeRightSingularVectors:s=!0,autoTranspose:a=!1}=e;var u,h=Boolean(o),c=Boolean(s),l=!1;if(r<n)if(a){r=(u=t.transpose()).rows,n=u.columns,l=!0;var f=h;h=c,c=f}else u=t.clone(),console.warn("Computing SVD on a matrix with more columns than rows. Consider enabling autoTranspose");else u=t.clone();var m,p,d,g,v,w,y,b,x,M,_,$,S,R,E,C,k,A,T,O,I,D=new Array(Math.min(r+1,n)),P=getFilled2DArray$4(r,i,0),V=getFilled2DArray$4(n,n,0),j=new Array(n),L=new Array(r),N=Math.min(r-1,n),B=Math.max(0,Math.min(n-2,r));for(d=0,M=Math.max(N,B);d<M;d++){if(d<N){for(D[d]=0,m=d;m<r;m++)D[d]=hypotenuse$4(D[d],u[m][d]);if(0!==D[d]){for(u[d][d]<0&&(D[d]=-D[d]),m=d;m<r;m++)u[m][d]/=D[d];u[d][d]+=1}D[d]=-D[d]}for(p=d+1;p<n;p++){if(d<N&&0!==D[d]){for(v=0,m=d;m<r;m++)v+=u[m][d]*u[m][p];for(v=-v/u[d][d],m=d;m<r;m++)u[m][p]+=v*u[m][d]}j[p]=u[d][p]}if(h&&d<N)for(m=d;m<r;m++)P[m][d]=u[m][d];if(d<B){for(j[d]=0,m=d+1;m<n;m++)j[d]=hypotenuse$4(j[d],j[m]);if(0!==j[d]){for(j[d+1]<0&&(j[d]=0-j[d]),m=d+1;m<n;m++)j[m]/=j[d];j[d+1]+=1}if(j[d]=-j[d],d+1<r&&0!==j[d]){for(m=d+1;m<r;m++)L[m]=0;for(p=d+1;p<n;p++)for(m=d+1;m<r;m++)L[m]+=j[p]*u[m][p];for(p=d+1;p<n;p++)for(v=-j[p]/j[d+1],m=d+1;m<r;m++)u[m][p]+=v*L[m]}if(c)for(m=d+1;m<n;m++)V[m][d]=j[m]}}if(g=Math.min(n,r+1),N<n&&(D[N]=u[N][N]),r<g&&(D[g-1]=0),B+1<g&&(j[B]=u[B][g-1]),j[g-1]=0,h){for(p=N;p<i;p++){for(m=0;m<r;m++)P[m][p]=0;P[p][p]=1}for(d=N-1;d>=0;d--)if(0!==D[d]){for(p=d+1;p<i;p++){for(v=0,m=d;m<r;m++)v+=P[m][d]*P[m][p];for(v=-v/P[d][d],m=d;m<r;m++)P[m][p]+=v*P[m][d]}for(m=d;m<r;m++)P[m][d]=-P[m][d];for(P[d][d]=1+P[d][d],m=0;m<d-1;m++)P[m][d]=0}else{for(m=0;m<r;m++)P[m][d]=0;P[d][d]=1}}if(c)for(d=n-1;d>=0;d--){if(d<B&&0!==j[d])for(p=d+1;p<n;p++){for(v=0,m=d+1;m<n;m++)v+=V[m][d]*V[m][p];for(v=-v/V[d+1][d],m=d+1;m<n;m++)V[m][p]+=v*V[m][d]}for(m=0;m<n;m++)V[m][d]=0;V[d][d]=1}for(var F=g-1,z=Number.EPSILON;g>0;){for(d=g-2;d>=-1&&-1!==d;d--)if(Math.abs(j[d])<=z*(Math.abs(D[d])+Math.abs(D[d+1]))){j[d]=0;break}if(d===g-2)_=4;else{for(w=g-1;w>=d&&w!==d;w--)if(v=(w!==g?Math.abs(j[w]):0)+(w!==d+1?Math.abs(j[w-1]):0),Math.abs(D[w])<=z*v){D[w]=0;break}w===d?_=3:w===g-1?_=1:(_=2,d=w)}switch(d++,_){case 1:for(y=j[g-2],j[g-2]=0,p=g-2;p>=d;p--)if(v=hypotenuse$4(D[p],y),b=D[p]/v,x=y/v,D[p]=v,p!==d&&(y=-x*j[p-1],j[p-1]=b*j[p-1]),c)for(m=0;m<n;m++)v=b*V[m][p]+x*V[m][g-1],V[m][g-1]=-x*V[m][p]+b*V[m][g-1],V[m][p]=v;break;case 2:for(y=j[d-1],j[d-1]=0,p=d;p<g;p++)if(v=hypotenuse$4(D[p],y),b=D[p]/v,x=y/v,D[p]=v,y=-x*j[p],j[p]=b*j[p],h)for(m=0;m<r;m++)v=b*P[m][p]+x*P[m][d-1],P[m][d-1]=-x*P[m][p]+b*P[m][d-1],P[m][p]=v;break;case 3:for($=Math.max(Math.abs(D[g-1]),Math.abs(D[g-2]),Math.abs(j[g-2]),Math.abs(D[d]),Math.abs(j[d])),S=D[g-1]/$,R=D[g-2]/$,E=j[g-2]/$,C=D[d]/$,k=j[d]/$,T=S*E*(S*E),O=0,0===(A=((R+S)*(R-S)+E*E)/2)&&0===T||(O=Math.sqrt(A*A+T),A<0&&(O=-O),O=T/(A+O)),y=(C+S)*(C-S)+O,I=C*k,p=d;p<g-1;p++){if(b=y/(v=hypotenuse$4(y,I)),x=I/v,p!==d&&(j[p-1]=v),y=b*D[p]+x*j[p],j[p]=b*j[p]-x*D[p],I=x*D[p+1],D[p+1]=b*D[p+1],c)for(m=0;m<n;m++)v=b*V[m][p]+x*V[m][p+1],V[m][p+1]=-x*V[m][p]+b*V[m][p+1],V[m][p]=v;if(b=y/(v=hypotenuse$4(y,I)),x=I/v,D[p]=v,y=b*j[p]+x*D[p+1],D[p+1]=-x*j[p]+b*D[p+1],I=x*j[p+1],j[p+1]=b*j[p+1],h&&p<r-1)for(m=0;m<r;m++)v=b*P[m][p]+x*P[m][p+1],P[m][p+1]=-x*P[m][p]+b*P[m][p+1],P[m][p]=v}j[g-2]=y;break;case 4:if(D[d]<=0&&(D[d]=D[d]<0?-D[d]:0,c))for(m=0;m<=F;m++)V[m][d]=-V[m][d];for(;d<F&&!(D[d]>=D[d+1]);){if(v=D[d],D[d]=D[d+1],D[d+1]=v,c&&d<n-1)for(m=0;m<n;m++)v=V[m][d+1],V[m][d+1]=V[m][d],V[m][d]=v;if(h&&d<r-1)for(m=0;m<r;m++)v=P[m][d+1],P[m][d+1]=P[m][d],P[m][d]=v;d++}g--}}if(l){var q=V;V=P,P=q}this.m=r,this.n=n,this.s=D,this.U=P,this.V=V}solve(t){var e,r=t,n=this.threshold,i=this.s.length,o=Matrix$a.zeros(i,i);for(e=0;e<i;e++)Math.abs(this.s[e])<=n?o[e][e]=0:o[e][e]=1/this.s[e];var s,a,u,h=this.U,c=this.rightSingularVectors,l=c.mmul(o),f=c.rows,m=h.length,p=Matrix$a.zeros(f,m);for(e=0;e<f;e++)for(s=0;s<m;s++){for(u=0,a=0;a<i;a++)u+=l[e][a]*h[s][a];p[e][s]=u}return p.mmul(r)}solveForDiagonal(t){return this.solve(Matrix$a.diag(t))}inverse(){var t,e,r=this.V,n=this.threshold,i=r.length,o=r[0].length,s=new Matrix$a(i,this.s.length);for(t=0;t<i;t++)for(e=0;e<o;e++)Math.abs(this.s[e])>n?s[t][e]=r[t][e]/this.s[e]:s[t][e]=0;var a,u,h=this.U,c=h.length,l=h[0].length,f=new Matrix$a(i,c);for(t=0;t<i;t++)for(e=0;e<c;e++){for(u=0,a=0;a<l;a++)u+=s[t][a]*h[e][a];f[t][e]=u}return f}get condition(){return this.s[0]/this.s[Math.min(this.m,this.n)-1]}get norm2(){return this.s[0]}get rank(){for(var t=Math.max(this.m,this.n)*this.s[0]*Number.EPSILON,e=0,r=this.s,n=0,i=r.length;n<i;n++)r[n]>t&&e++;return e}get diagonal(){return this.s}get threshold(){return Number.EPSILON/2*Math.max(this.m,this.n)*this.s[0]}get leftSingularVectors(){return Matrix$a.isMatrix(this.U)||(this.U=new Matrix$a(this.U)),this.U}get rightSingularVectors(){return Matrix$a.isMatrix(this.V)||(this.V=new Matrix$a(this.V)),this.V}get diagonalMatrix(){return Matrix$a.diag(this.s)}}function checkRowIndex$4(t,e,r){var n=r?t.rows:t.rows-1;if(e<0||e>n)throw new RangeError("Row index out of range")}function checkColumnIndex$4(t,e,r){var n=r?t.columns:t.columns-1;if(e<0||e>n)throw new RangeError("Column index out of range")}function checkRowVector$4(t,e){if(e.to1DArray&&(e=e.to1DArray()),e.length!==t.columns)throw new RangeError("vector size must be the same as the number of columns");return e}function checkColumnVector$4(t,e){if(e.to1DArray&&(e=e.to1DArray()),e.length!==t.rows)throw new RangeError("vector size must be the same as the number of rows");return e}function checkIndices$4(t,e,r){return{row:checkRowIndices$4(t,e),column:checkColumnIndices$4(t,r)}}function checkRowIndices$4(t,e){if("object"!=typeof e)throw new TypeError("unexpected type for row indices");if(e.some((e=>e<0||e>=t.rows)))throw new RangeError("row indices are out of range");return Array.isArray(e)||(e=Array.from(e)),e}function checkColumnIndices$4(t,e){if("object"!=typeof e)throw new TypeError("unexpected type for column indices");var r=e.some((e=>e<0||e>=t.columns));if(r)throw new RangeError("column indices are out of range");return Array.isArray(e)||(e=Array.from(e)),e}function checkRange$4(t,e,r,n,i){if(5!==arguments.length)throw new TypeError("Invalid argument type");if(Array.from(arguments).slice(1).some((function(t){return"number"!=typeof t})))throw new TypeError("Invalid argument type");if(e>r||n>i||e<0||e>=t.rows||r<0||r>=t.rows||n<0||n>=t.columns||i<0||i>=t.columns)throw new RangeError("Submatrix indices are out of range")}function sumByRow$4(t){for(var e=Matrix$a.zeros(t.rows,1),r=0;r<t.rows;++r)for(var n=0;n<t.columns;++n)e.set(r,0,e.get(r,0)+t.get(r,n));return e}function sumByColumn$4(t){for(var e=Matrix$a.zeros(1,t.columns),r=0;r<t.rows;++r)for(var n=0;n<t.columns;++n)e.set(0,n,e.get(0,n)+t.get(r,n));return e}function sumAll$4(t){for(var e=0,r=0;r<t.rows;r++)for(var n=0;n<t.columns;n++)e+=t.get(r,n);return e}class BaseView$4 extends(AbstractMatrix$4()){constructor(t,e,r){super(),this.matrix=t,this.rows=e,this.columns=r}static get[Symbol.species](){return Matrix$a}}class MatrixTransposeView$4 extends BaseView$4{constructor(t){super(t,t.columns,t.rows)}set(t,e,r){return this.matrix.set(e,t,r),this}get(t,e){return this.matrix.get(e,t)}}class MatrixRowView$4 extends BaseView$4{constructor(t,e){super(t,1,t.columns),this.row=e}set(t,e,r){return this.matrix.set(this.row,e,r),this}get(t,e){return this.matrix.get(this.row,e)}}class MatrixSubView$4 extends BaseView$4{constructor(t,e,r,n,i){checkRange$4(t,e,r,n,i),super(t,r-e+1,i-n+1),this.startRow=e,this.startColumn=n}set(t,e,r){return this.matrix.set(this.startRow+t,this.startColumn+e,r),this}get(t,e){return this.matrix.get(this.startRow+t,this.startColumn+e)}}class MatrixSelectionView$4 extends BaseView$4{constructor(t,e,r){var n=checkIndices$4(t,e,r);super(t,n.row.length,n.column.length),this.rowIndices=n.row,this.columnIndices=n.column}set(t,e,r){return this.matrix.set(this.rowIndices[t],this.columnIndices[e],r),this}get(t,e){return this.matrix.get(this.rowIndices[t],this.columnIndices[e])}}class MatrixRowSelectionView$4 extends BaseView$4{constructor(t,e){super(t,(e=checkRowIndices$4(t,e)).length,t.columns),this.rowIndices=e}set(t,e,r){return this.matrix.set(this.rowIndices[t],e,r),this}get(t,e){return this.matrix.get(this.rowIndices[t],e)}}class MatrixColumnSelectionView$4 extends BaseView$4{constructor(t,e){e=checkColumnIndices$4(t,e),super(t,t.rows,e.length),this.columnIndices=e}set(t,e,r){return this.matrix.set(t,this.columnIndices[e],r),this}get(t,e){return this.matrix.get(t,this.columnIndices[e])}}class MatrixColumnView$4 extends BaseView$4{constructor(t,e){super(t,t.rows,1),this.column=e}set(t,e,r){return this.matrix.set(t,this.column,r),this}get(t){return this.matrix.get(t,this.column)}}class MatrixFlipRowView$4 extends BaseView$4{constructor(t){super(t,t.rows,t.columns)}set(t,e,r){return this.matrix.set(this.rows-t-1,e,r),this}get(t,e){return this.matrix.get(this.rows-t-1,e)}}class MatrixFlipColumnView$4 extends BaseView$4{constructor(t){super(t,t.rows,t.columns)}set(t,e,r){return this.matrix.set(t,this.columns-e-1,r),this}get(t,e){return this.matrix.get(t,this.columns-e-1)}}function AbstractMatrix$4(t){void 0===t&&(t=Object);class e extends t{static get[Symbol.species](){return this}static from1DArray(t,e,r){if(t*e!==r.length)throw new RangeError("Data length does not match given dimensions");for(var n=new this(t,e),i=0;i<t;i++)for(var o=0;o<e;o++)n.set(i,o,r[i*e+o]);return n}static rowVector(t){for(var e=new this(1,t.length),r=0;r<t.length;r++)e.set(0,r,t[r]);return e}static columnVector(t){for(var e=new this(t.length,1),r=0;r<t.length;r++)e.set(r,0,t[r]);return e}static empty(t,e){return new this(t,e)}static zeros(t,e){return this.empty(t,e).fill(0)}static ones(t,e){return this.empty(t,e).fill(1)}static rand(t,e,r){void 0===r&&(r=Math.random);for(var n=this.empty(t,e),i=0;i<t;i++)for(var o=0;o<e;o++)n.set(i,o,r());return n}static randInt(t,e,r,n){void 0===r&&(r=1e3),void 0===n&&(n=Math.random);for(var i=this.empty(t,e),o=0;o<t;o++)for(var s=0;s<e;s++){var a=Math.floor(n()*r);i.set(o,s,a)}return i}static eye(t,e,r){void 0===e&&(e=t),void 0===r&&(r=1);for(var n=Math.min(t,e),i=this.zeros(t,e),o=0;o<n;o++)i.set(o,o,r);return i}static diag(t,e,r){var n=t.length;void 0===e&&(e=n),void 0===r&&(r=e);for(var i=Math.min(n,e,r),o=this.zeros(e,r),s=0;s<i;s++)o.set(s,s,t[s]);return o}static min(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);for(var r=t.rows,n=t.columns,i=new this(r,n),o=0;o<r;o++)for(var s=0;s<n;s++)i.set(o,s,Math.min(t.get(o,s),e.get(o,s)));return i}static max(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);for(var r=t.rows,n=t.columns,i=new this(r,n),o=0;o<r;o++)for(var s=0;s<n;s++)i.set(o,s,Math.max(t.get(o,s),e.get(o,s)));return i}static checkMatrix(t){return e.isMatrix(t)?t:new this(t)}static isMatrix(t){return null!=t&&"Matrix"===t.klass}get size(){return this.rows*this.columns}apply(t){if("function"!=typeof t)throw new TypeError("callback must be a function");for(var e=this.rows,r=this.columns,n=0;n<e;n++)for(var i=0;i<r;i++)t.call(this,n,i);return this}to1DArray(){for(var t=new Array(this.size),e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)t[e*this.columns+r]=this.get(e,r);return t}to2DArray(){for(var t=new Array(this.rows),e=0;e<this.rows;e++){t[e]=new Array(this.columns);for(var r=0;r<this.columns;r++)t[e][r]=this.get(e,r)}return t}isRowVector(){return 1===this.rows}isColumnVector(){return 1===this.columns}isVector(){return 1===this.rows||1===this.columns}isSquare(){return this.rows===this.columns}isSymmetric(){if(this.isSquare()){for(var t=0;t<this.rows;t++)for(var e=0;e<=t;e++)if(this.get(t,e)!==this.get(e,t))return!1;return!0}return!1}set(t,e,r){throw new Error("set method is unimplemented")}get(t,e){throw new Error("get method is unimplemented")}repeat(t,e){t=t||1,e=e||1;for(var r=new this.constructor[Symbol.species](this.rows*t,this.columns*e),n=0;n<t;n++)for(var i=0;i<e;i++)r.setSubMatrix(this,this.rows*n,this.columns*i);return r}fill(t){for(var e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)this.set(e,r,t);return this}neg(){return this.mulS(-1)}getRow(t){checkRowIndex$4(this,t);for(var e=new Array(this.columns),r=0;r<this.columns;r++)e[r]=this.get(t,r);return e}getRowVector(t){return this.constructor.rowVector(this.getRow(t))}setRow(t,e){checkRowIndex$4(this,t),e=checkRowVector$4(this,e);for(var r=0;r<this.columns;r++)this.set(t,r,e[r]);return this}swapRows(t,e){checkRowIndex$4(this,t),checkRowIndex$4(this,e);for(var r=0;r<this.columns;r++){var n=this.get(t,r);this.set(t,r,this.get(e,r)),this.set(e,r,n)}return this}getColumn(t){checkColumnIndex$4(this,t);for(var e=new Array(this.rows),r=0;r<this.rows;r++)e[r]=this.get(r,t);return e}getColumnVector(t){return this.constructor.columnVector(this.getColumn(t))}setColumn(t,e){checkColumnIndex$4(this,t),e=checkColumnVector$4(this,e);for(var r=0;r<this.rows;r++)this.set(r,t,e[r]);return this}swapColumns(t,e){checkColumnIndex$4(this,t),checkColumnIndex$4(this,e);for(var r=0;r<this.rows;r++){var n=this.get(r,t);this.set(r,t,this.get(r,e)),this.set(r,e,n)}return this}addRowVector(t){t=checkRowVector$4(this,t);for(var e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t[r]);return this}subRowVector(t){t=checkRowVector$4(this,t);for(var e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t[r]);return this}mulRowVector(t){t=checkRowVector$4(this,t);for(var e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t[r]);return this}divRowVector(t){t=checkRowVector$4(this,t);for(var e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t[r]);return this}addColumnVector(t){t=checkColumnVector$4(this,t);for(var e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t[e]);return this}subColumnVector(t){t=checkColumnVector$4(this,t);for(var e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t[e]);return this}mulColumnVector(t){t=checkColumnVector$4(this,t);for(var e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t[e]);return this}divColumnVector(t){t=checkColumnVector$4(this,t);for(var e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t[e]);return this}mulRow(t,e){checkRowIndex$4(this,t);for(var r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)*e);return this}mulColumn(t,e){checkColumnIndex$4(this,t);for(var r=0;r<this.rows;r++)this.set(r,t,this.get(r,t)*e);return this}max(){for(var t=this.get(0,0),e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)this.get(e,r)>t&&(t=this.get(e,r));return t}maxIndex(){for(var t=this.get(0,0),e=[0,0],r=0;r<this.rows;r++)for(var n=0;n<this.columns;n++)this.get(r,n)>t&&(t=this.get(r,n),e[0]=r,e[1]=n);return e}min(){for(var t=this.get(0,0),e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)this.get(e,r)<t&&(t=this.get(e,r));return t}minIndex(){for(var t=this.get(0,0),e=[0,0],r=0;r<this.rows;r++)for(var n=0;n<this.columns;n++)this.get(r,n)<t&&(t=this.get(r,n),e[0]=r,e[1]=n);return e}maxRow(t){checkRowIndex$4(this,t);for(var e=this.get(t,0),r=1;r<this.columns;r++)this.get(t,r)>e&&(e=this.get(t,r));return e}maxRowIndex(t){checkRowIndex$4(this,t);for(var e=this.get(t,0),r=[t,0],n=1;n<this.columns;n++)this.get(t,n)>e&&(e=this.get(t,n),r[1]=n);return r}minRow(t){checkRowIndex$4(this,t);for(var e=this.get(t,0),r=1;r<this.columns;r++)this.get(t,r)<e&&(e=this.get(t,r));return e}minRowIndex(t){checkRowIndex$4(this,t);for(var e=this.get(t,0),r=[t,0],n=1;n<this.columns;n++)this.get(t,n)<e&&(e=this.get(t,n),r[1]=n);return r}maxColumn(t){checkColumnIndex$4(this,t);for(var e=this.get(0,t),r=1;r<this.rows;r++)this.get(r,t)>e&&(e=this.get(r,t));return e}maxColumnIndex(t){checkColumnIndex$4(this,t);for(var e=this.get(0,t),r=[0,t],n=1;n<this.rows;n++)this.get(n,t)>e&&(e=this.get(n,t),r[0]=n);return r}minColumn(t){checkColumnIndex$4(this,t);for(var e=this.get(0,t),r=1;r<this.rows;r++)this.get(r,t)<e&&(e=this.get(r,t));return e}minColumnIndex(t){checkColumnIndex$4(this,t);for(var e=this.get(0,t),r=[0,t],n=1;n<this.rows;n++)this.get(n,t)<e&&(e=this.get(n,t),r[0]=n);return r}diag(){for(var t=Math.min(this.rows,this.columns),e=new Array(t),r=0;r<t;r++)e[r]=this.get(r,r);return e}sum(t){switch(t){case"row":return sumByRow$4(this);case"column":return sumByColumn$4(this);default:return sumAll$4(this)}}mean(){return this.sum()/this.size}prod(){for(var t=1,e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)t*=this.get(e,r);return t}norm(t="frobenius"){var e=0;if("max"===t)return this.max();if("frobenius"===t){for(var r=0;r<this.rows;r++)for(var n=0;n<this.columns;n++)e+=this.get(r,n)*this.get(r,n);return Math.sqrt(e)}throw new RangeError(`unknown norm type: ${t}`)}cumulativeSum(){for(var t=0,e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)t+=this.get(e,r),this.set(e,r,t);return this}dot(t){e.isMatrix(t)&&(t=t.to1DArray());var r=this.to1DArray();if(r.length!==t.length)throw new RangeError("vectors do not have the same size");for(var n=0,i=0;i<r.length;i++)n+=r[i]*t[i];return n}mmul(t){t=this.constructor.checkMatrix(t),this.columns!==t.rows&&console.warn("Number of columns of left matrix are not equal to number of rows of right matrix.");for(var e=this.rows,r=this.columns,n=t.columns,i=new this.constructor[Symbol.species](e,n),o=new Array(r),s=0;s<n;s++){for(var a=0;a<r;a++)o[a]=t.get(a,s);for(var u=0;u<e;u++){var h=0;for(a=0;a<r;a++)h+=this.get(u,a)*o[a];i.set(u,s,h)}}return i}strassen2x2(t){var e=new this.constructor[Symbol.species](2,2);const r=this.get(0,0),n=t.get(0,0),i=this.get(0,1),o=t.get(0,1),s=this.get(1,0),a=t.get(1,0),u=this.get(1,1),h=t.get(1,1),c=(r+u)*(n+h),l=(s+u)*n,f=r*(o-h),m=u*(a-n),p=(r+i)*h,d=c+m-p+(i-u)*(a+h),g=f+p,v=l+m,w=c-l+f+(s-r)*(n+o);return e.set(0,0,d),e.set(0,1,g),e.set(1,0,v),e.set(1,1,w),e}strassen3x3(t){var e=new this.constructor[Symbol.species](3,3);const r=this.get(0,0),n=this.get(0,1),i=this.get(0,2),o=this.get(1,0),s=this.get(1,1),a=this.get(1,2),u=this.get(2,0),h=this.get(2,1),c=this.get(2,2),l=t.get(0,0),f=t.get(0,1),m=t.get(0,2),p=t.get(1,0),d=t.get(1,1),g=t.get(1,2),v=t.get(2,0),w=t.get(2,1),y=t.get(2,2),b=(r-o)*(-f+d),x=(-r+o+s)*(l-f+d),M=(o+s)*(-l+f),_=r*l,$=(-r+u+h)*(l-m+g),S=(-r+u)*(m-g),R=(u+h)*(-l+m),E=(-i+h+c)*(d+v-w),C=(i-c)*(d-w),k=i*v,A=(h+c)*(-v+w),T=(-i+s+a)*(g+v-y),O=(i-a)*(g-y),I=(s+a)*(-v+y),D=_+k+n*p,P=(r+n+i-o-s-h-c)*d+x+M+_+E+k+A,V=_+$+R+(r+n+i-s-a-u-h)*g+k+T+I,j=b+s*(-l+f+p-d-g-v+y)+x+_+k+T+O,L=b+x+M+_+a*w,N=k+T+O+I+o*m,B=_+$+S+h*(-l+m+p-d-g-v+w)+E+C+k,F=E+C+k+A+u*f,z=_+$+S+R+c*y;return e.set(0,0,D),e.set(0,1,P),e.set(0,2,V),e.set(1,0,j),e.set(1,1,L),e.set(1,2,N),e.set(2,0,B),e.set(2,1,F),e.set(2,2,z),e}mmulStrassen(t){var r=this.clone(),n=r.rows,i=r.columns,o=t.rows,s=t.columns;function a(t,r,n){var i=t.rows,o=t.columns;if(i===r&&o===n)return t;var s=e.zeros(r,n);return s=s.setSubMatrix(t,0,0)}i!==o&&console.warn(`Multiplying ${n} x ${i} and ${o} x ${s} matrix: dimensions do not match.`);var u=Math.max(n,o),h=Math.max(i,s);return function t(r,n,i,o){if(i<=512||o<=512)return r.mmul(n);i%2==1&&o%2==1?(r=a(r,i+1,o+1),n=a(n,i+1,o+1)):i%2==1?(r=a(r,i+1,o),n=a(n,i+1,o)):o%2==1&&(r=a(r,i,o+1),n=a(n,i,o+1));var s=parseInt(r.rows/2),u=parseInt(r.columns/2),h=r.subMatrix(0,s-1,0,u-1),c=n.subMatrix(0,s-1,0,u-1),l=r.subMatrix(0,s-1,u,r.columns-1),f=n.subMatrix(0,s-1,u,n.columns-1),m=r.subMatrix(s,r.rows-1,0,u-1),p=n.subMatrix(s,n.rows-1,0,u-1),d=r.subMatrix(s,r.rows-1,u,r.columns-1),g=n.subMatrix(s,n.rows-1,u,n.columns-1),v=t(e.add(h,d),e.add(c,g),s,u),w=t(e.add(m,d),c,s,u),y=t(h,e.sub(f,g),s,u),b=t(d,e.sub(p,c),s,u),x=t(e.add(h,l),g,s,u),M=t(e.sub(m,h),e.add(c,f),s,u),_=t(e.sub(l,d),e.add(p,g),s,u),$=e.add(v,b);$.sub(x),$.add(_);var S=e.add(y,x),R=e.add(w,b),E=e.sub(v,w);E.add(y),E.add(M);var C=e.zeros(2*$.rows,2*$.columns);return(C=(C=(C=(C=C.setSubMatrix($,0,0)).setSubMatrix(S,$.rows,0)).setSubMatrix(R,0,$.columns)).setSubMatrix(E,$.rows,$.columns)).subMatrix(0,i-1,0,o-1)}(r=a(r,u,h),t=a(t,u,h),u,h)}scaleRows(t,e){if((t=void 0===t?0:t)>=(e=void 0===e?1:e))throw new RangeError("min should be strictly smaller than max");for(var r=this.constructor.empty(this.rows,this.columns),n=0;n<this.rows;n++){var i=rescale(this.getRow(n),{min:t,max:e});r.setRow(n,i)}return r}scaleColumns(t,e){if((t=void 0===t?0:t)>=(e=void 0===e?1:e))throw new RangeError("min should be strictly smaller than max");for(var r=this.constructor.empty(this.rows,this.columns),n=0;n<this.columns;n++){var i=rescale(this.getColumn(n),{min:t,max:e});r.setColumn(n,i)}return r}kroneckerProduct(t){t=this.constructor.checkMatrix(t);for(var e=this.rows,r=this.columns,n=t.rows,i=t.columns,o=new this.constructor[Symbol.species](e*n,r*i),s=0;s<e;s++)for(var a=0;a<r;a++)for(var u=0;u<n;u++)for(var h=0;h<i;h++)o[n*s+u][i*a+h]=this.get(s,a)*t.get(u,h);return o}transpose(){for(var t=new this.constructor[Symbol.species](this.columns,this.rows),e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)t.set(r,e,this.get(e,r));return t}sortRows(t){void 0===t&&(t=r);for(var e=0;e<this.rows;e++)this.setRow(e,this.getRow(e).sort(t));return this}sortColumns(t){void 0===t&&(t=r);for(var e=0;e<this.columns;e++)this.setColumn(e,this.getColumn(e).sort(t));return this}subMatrix(t,e,r,n){checkRange$4(this,t,e,r,n);for(var i=new this.constructor[Symbol.species](e-t+1,n-r+1),o=t;o<=e;o++)for(var s=r;s<=n;s++)i[o-t][s-r]=this.get(o,s);return i}subMatrixRow(t,e,r){if(void 0===e&&(e=0),void 0===r&&(r=this.columns-1),e>r||e<0||e>=this.columns||r<0||r>=this.columns)throw new RangeError("Argument out of range");for(var n=new this.constructor[Symbol.species](t.length,r-e+1),i=0;i<t.length;i++)for(var o=e;o<=r;o++){if(t[i]<0||t[i]>=this.rows)throw new RangeError("Row index out of range: "+t[i]);n.set(i,o-e,this.get(t[i],o))}return n}subMatrixColumn(t,e,r){if(void 0===e&&(e=0),void 0===r&&(r=this.rows-1),e>r||e<0||e>=this.rows||r<0||r>=this.rows)throw new RangeError("Argument out of range");for(var n=new this.constructor[Symbol.species](r-e+1,t.length),i=0;i<t.length;i++)for(var o=e;o<=r;o++){if(t[i]<0||t[i]>=this.columns)throw new RangeError("Column index out of range: "+t[i]);n.set(o-e,i,this.get(o,t[i]))}return n}setSubMatrix(t,e,r){checkRange$4(this,e,e+(t=this.constructor.checkMatrix(t)).rows-1,r,r+t.columns-1);for(var n=0;n<t.rows;n++)for(var i=0;i<t.columns;i++)this[e+n][r+i]=t.get(n,i);return this}selection(t,e){for(var r=checkIndices$4(this,t,e),n=new this.constructor[Symbol.species](t.length,e.length),i=0;i<r.row.length;i++)for(var o=r.row[i],s=0;s<r.column.length;s++){var a=r.column[s];n[i][s]=this.get(o,a)}return n}trace(){for(var t=Math.min(this.rows,this.columns),e=0,r=0;r<t;r++)e+=this.get(r,r);return e}transposeView(){return new MatrixTransposeView$4(this)}rowView(t){return checkRowIndex$4(this,t),new MatrixRowView$4(this,t)}columnView(t){return checkColumnIndex$4(this,t),new MatrixColumnView$4(this,t)}flipRowView(){return new MatrixFlipRowView$4(this)}flipColumnView(){return new MatrixFlipColumnView$4(this)}subMatrixView(t,e,r,n){return new MatrixSubView$4(this,t,e,r,n)}selectionView(t,e){return new MatrixSelectionView$4(this,t,e)}rowSelectionView(t){return new MatrixRowSelectionView$4(this,t)}columnSelectionView(t){return new MatrixColumnSelectionView$4(this,t)}det(){var t,e,r,n,i,o;if(this.isSquare())return 2===this.columns?(t=this.get(0,0),e=this.get(0,1),r=this.get(1,0),t*this.get(1,1)-e*r):3===this.columns?(n=this.selectionView([1,2],[1,2]),i=this.selectionView([1,2],[0,2]),o=this.selectionView([1,2],[0,1]),t=this.get(0,0),e=this.get(0,1),r=this.get(0,2),t*n.det()-e*i.det()+r*o.det()):new LuDecomposition$$1(this).determinant;throw Error("Determinant can only be calculated for a square matrix.")}pseudoInverse(t){void 0===t&&(t=Number.EPSILON);for(var e=new SingularValueDecomposition$$1(this,{autoTranspose:!0}),r=e.leftSingularVectors,n=e.rightSingularVectors,i=e.diagonal,o=0;o<i.length;o++)Math.abs(i[o])>t?i[o]=1/i[o]:i[o]=0;return i=this.constructor[Symbol.species].diag(i),n.mmul(i.mmul(r.transposeView()))}clone(){for(var t=new this.constructor[Symbol.species](this.rows,this.columns),e=0;e<this.rows;e++)for(var r=0;r<this.columns;r++)t.set(e,r,this.get(e,r));return t}}function r(t,e){return t-e}e.prototype.klass="Matrix",e.random=e.rand,e.diagonal=e.diag,e.prototype.diagonal=e.prototype.diag,e.identity=e.eye,e.prototype.negate=e.prototype.neg,e.prototype.tensorProduct=e.prototype.kroneckerProduct,e.prototype.determinant=e.prototype.det;var n,i="\n(function %name%(matrix, %args%) {\n    var newMatrix = new this[Symbol.species](matrix);\n    return newMatrix.%name%(%args%);\n})\n",o=i,s=eval;for(var a of[["+","add"],["-","sub","subtract"],["*","mul","multiply"],["/","div","divide"],["%","mod","modulus"],["&","and"],["|","or"],["^","xor"],["<<","leftShift"],[">>","signPropagatingRightShift"],[">>>","rightShift","zeroFillRightShift"]]){var u=s(S("\n(function %name%(value) {\n    if (typeof value === 'number') return this.%name%S(value);\n    return this.%name%M(value);\n})\n",{name:a[1],op:a[0]})),h=s(S("\n(function %name%S(value) {\n    for (var i = 0; i < this.rows; i++) {\n        for (var j = 0; j < this.columns; j++) {\n            this.set(i, j, this.get(i, j) %op% value);\n        }\n    }\n    return this;\n})\n",{name:a[1]+"S",op:a[0]})),c=s(S("\n(function %name%M(matrix) {\n    matrix = this.constructor.checkMatrix(matrix);\n    if (this.rows !== matrix.rows ||\n        this.columns !== matrix.columns) {\n        throw new RangeError('Matrices dimensions must be equal');\n    }\n    for (var i = 0; i < this.rows; i++) {\n        for (var j = 0; j < this.columns; j++) {\n            this.set(i, j, this.get(i, j) %op% matrix.get(i, j));\n        }\n    }\n    return this;\n})\n",{name:a[1]+"M",op:a[0]})),l=s(S("\n(function %name%(matrix, value) {\n    var newMatrix = new this[Symbol.species](matrix);\n    return newMatrix.%name%(value);\n})\n",{name:a[1]}));for(n=1;n<a.length;n++)e.prototype[a[n]]=u,e.prototype[a[n]+"S"]=h,e.prototype[a[n]+"M"]=c,e[a[n]]=l}var f=[["~","not"]];for(var m of(["abs","acos","acosh","asin","asinh","atan","atanh","cbrt","ceil","clz32","cos","cosh","exp","expm1","floor","fround","log","log1p","log10","log2","round","sign","sin","sinh","sqrt","tan","tanh","trunc"].forEach((function(t){f.push(["Math."+t,t])})),f)){var p=s(S("\n(function %name%() {\n    for (var i = 0; i < this.rows; i++) {\n        for (var j = 0; j < this.columns; j++) {\n            this.set(i, j, %method%(this.get(i, j)));\n        }\n    }\n    return this;\n})\n",{name:m[1],method:m[0]})),d=s(S("\n(function %name%(matrix) {\n    var newMatrix = new this[Symbol.species](matrix);\n    return newMatrix.%name%();\n})\n",{name:m[1]}));for(n=1;n<m.length;n++)e.prototype[m[n]]=p,e[m[n]]=d}for(var g of[["Math.pow",1,"pow"]]){var v="arg0";for(n=1;n<g[1];n++)v+=`, arg${n}`;if(1!==g[1]){var w=s(S("\n(function %name%(%args%) {\n    for (var i = 0; i < this.rows; i++) {\n        for (var j = 0; j < this.columns; j++) {\n            this.set(i, j, %method%(this.get(i, j), %args%));\n        }\n    }\n    return this;\n})\n",{name:g[2],method:g[0],args:v})),y=s(S(i,{name:g[2],args:v}));for(n=2;n<g.length;n++)e.prototype[g[n]]=w,e[g[n]]=y}else{var b={name:g[2],args:v,method:g[0]},x=s(S("\n(function %name%(value) {\n    if (typeof value === 'number') return this.%name%S(value);\n    return this.%name%M(value);\n})\n",b)),M=s(S("\n(function %name%S(value) {\n    for (var i = 0; i < this.rows; i++) {\n        for (var j = 0; j < this.columns; j++) {\n            this.set(i, j, %method%(this.get(i, j), value));\n        }\n    }\n    return this;\n})\n",b)),_=s(S("\n(function %name%M(matrix) {\n    matrix = this.constructor.checkMatrix(matrix);\n    if (this.rows !== matrix.rows ||\n        this.columns !== matrix.columns) {\n        throw new RangeError('Matrices dimensions must be equal');\n    }\n    for (var i = 0; i < this.rows; i++) {\n        for (var j = 0; j < this.columns; j++) {\n            this.set(i, j, %method%(this.get(i, j), matrix.get(i, j)));\n        }\n    }\n    return this;\n})\n",b)),$=s(S(o,b));for(n=2;n<g.length;n++)e.prototype[g[n]]=x,e.prototype[g[n]+"M"]=_,e.prototype[g[n]+"S"]=M,e[g[n]]=$}}function S(t,e){for(var r in e)t=t.replace(new RegExp("%"+r+"%","g"),e[r]);return t}return e}class Matrix$a extends(AbstractMatrix$4(Array)){constructor(t,e){var r;if(1===arguments.length&&"number"==typeof t)return new Array(t);if(Matrix$a.isMatrix(t))return t.clone();if(Number.isInteger(t)&&t>0){if(super(t),!(Number.isInteger(e)&&e>0))throw new TypeError("nColumns must be a positive integer");for(r=0;r<t;r++)this[r]=new Array(e)}else{if(!Array.isArray(t))throw new TypeError("First argument must be a positive number or an array");{const n=t;if(t=n.length,"number"!=typeof(e=n[0].length)||0===e)throw new TypeError("Data must be a 2D array with at least one element");for(super(t),r=0;r<t;r++){if(n[r].length!==e)throw new RangeError("Inconsistent array dimensions");this[r]=[].concat(n[r])}}}return this.rows=t,this.columns=e,this}set(t,e,r){return this[t][e]=r,this}get(t,e){return this[t][e]}removeRow(t){if(checkRowIndex$4(this,t),1===this.rows)throw new RangeError("A matrix cannot have less than one row");return this.splice(t,1),this.rows-=1,this}addRow(t,e){return void 0===e&&(e=t,t=this.rows),checkRowIndex$4(this,t,!0),e=checkRowVector$4(this,e,!0),this.splice(t,0,e),this.rows+=1,this}removeColumn(t){if(checkColumnIndex$4(this,t),1===this.columns)throw new RangeError("A matrix cannot have less than one column");for(var e=0;e<this.rows;e++)this[e].splice(t,1);return this.columns-=1,this}addColumn(t,e){void 0===e&&(e=t,t=this.columns),checkColumnIndex$4(this,t,!0),e=checkColumnVector$4(this,e);for(var r=0;r<this.rows;r++)this[r].splice(t,0,e[r]);return this.columns+=1,this}}class WrapperMatrix1D$4 extends(AbstractMatrix$4()){constructor(t,e={}){const{rows:r=1}=e;if(t.length%r!=0)throw new Error("the data length is not divisible by the number of rows");super(),this.rows=r,this.columns=t.length/r,this.data=t}set(t,e,r){var n=this._calculateIndex(t,e);return this.data[n]=r,this}get(t,e){var r=this._calculateIndex(t,e);return this.data[r]}_calculateIndex(t,e){return t*this.columns+e}static get[Symbol.species](){return Matrix$a}}class WrapperMatrix2D$4 extends(AbstractMatrix$4()){constructor(t){super(),this.data=t,this.rows=t.length,this.columns=t[0].length}set(t,e,r){return this.data[t][e]=r,this}get(t,e){return this.data[t][e]}static get[Symbol.species](){return Matrix$a}}class LogisticRegressionTwoClasses{constructor(t={}){this.numSteps=t.numSteps||5e5,this.learningRate=t.learningRate||5e-4,this.weights=t.weights?Matrix$a.checkMatrix(t.weights):null}train(t,e){for(var r=Matrix$a.zeros(1,t.columns),n=0;n<this.numSteps;n++){var i=sigmoid(t.mmul(r.transposeView())),o=Matrix$a.columnVector(i).neg().add(e),s=t.transposeView().mmul(o);r=r.add(s.mul(this.learningRate).transposeView())}this.weights=r}testScores(t){var e=sigmoid(t.mmul(this.weights.transposeView()));return(e=Matrix$a.columnVector(e)).to1DArray()}predict(t){var e=sigmoid(t.mmul(this.weights.transposeView()));return(e=Matrix$a.columnVector(e).round()).to1DArray()}static load(t){return new LogisticRegressionTwoClasses(t)}toJSON(){return{numSteps:this.numSteps,learningRate:this.learningRate,weights:this.weights}}}function sigmoid(t){t=t.to1DArray();for(var e=[],r=0;r<t.length;r++)e.push(1/(1+Math.exp(-t[r])));return e}function transformClassesForOneVsAll(t,e){for(var r=t.to1DArray(),n=0;n<r.length;n++)r[n]===e?r[n]=0:r[n]=1;return Matrix$a.columnVector(r)}class LogisticRegression{constructor(t={}){this.numSteps=t.numSteps||5e5,this.learningRate=t.learningRate||5e-4,this.classifiers=t.classifiers||[],this.numberClasses=t.numberClasses||0}train(t,e){this.numberClasses=new Set(e.to1DArray()).size,this.classifiers=new Array(this.numberClasses);for(var r=0;r<this.numberClasses;r++){this.classifiers[r]=new LogisticRegressionTwoClasses({numSteps:this.numSteps,learningRate:this.learningRate});var n=e.clone();n=transformClassesForOneVsAll(n,r),this.classifiers[r].train(t,n)}}predict(t){var e,r=new Array(this.numberClasses).fill(0);for(e=0;e<this.numberClasses;e++)r[e]=this.classifiers[e].testScores(t);var n=new Array(t.rows).fill(0);for(e=0;e<t.rows;e++)for(var i=1e5,o=0;o<this.numberClasses;o++)r[o][e]<i&&(i=r[o][e],n[e]=o);return n}static load(t){if("LogisticRegression"!==t.name)throw new Error("invalid model: "+t.name);const e=new LogisticRegression(t);for(let r=0;r<e.numberClasses;r++)e.classifiers[r]=LogisticRegressionTwoClasses.load(t.classifiers[r]);return e}toJSON(){return{name:"LogisticRegression",numSteps:this.numSteps,learningRate:this.learningRate,numberClasses:this.numberClasses,classifiers:this.classifiers}}}class ReinforcedLearningBase{constructor(t={}){return this.bounds=t.bounds||5,this.getBound=t.getBound||function(t){return t},this.last_selected=[],this.total_reward=0,this.iteration=0,this}learn(){throw new ReferenceError("Missing learn method implementation")}train(){throw new ReferenceError("Missing train method implementation")}predict(){throw new ReferenceError("Missing predict method implementation")}}class UpperConfidenceBound extends ReinforcedLearningBase{constructor(t={}){super(t),this.numbers_of_selections=new Map,this.sums_of_rewards=new Map;for(let t=0;t<this.bounds;t++)this.numbers_of_selections.set(t,0),this.sums_of_rewards.set(t,0);return this}predict(){let t=0,e=0;for(let r=0;r<this.bounds;r++){let n=Infinity;if(this.numbers_of_selections.get(r)>0){n=this.sums_of_rewards.get(r)/this.numbers_of_selections.get(r)+Math.sqrt(1.5*Math.log(this.iteration+1)/this.numbers_of_selections.get(r))}n>e&&(e=n,t=r)}return t}learn(t={}){const{ucbRow:e,getBound:r}=t;let n=this.predict();this.last_selected.push(n),this.numbers_of_selections.set(n,this.numbers_of_selections.get(n)+1);let i=e[r(n)];return this.sums_of_rewards.set(n,this.sums_of_rewards.get(n)+i),this.total_reward=this.total_reward+i,this.iteration++,this}train(t){const{ucbRow:e,getBound:r=this.getBound}=t;if(Array.isArray(e))for(let t in e)this.learn({ucbRow:e[t],getBound:r});else this.learn({ucbRow:e,getBound:r});return this}}class ThompsonSampling extends ReinforcedLearningBase{constructor(t={}){super(t),this.numbers_of_rewards_1=new Map,this.numbers_of_rewards_0=new Map;for(let t=0;t<this.bounds;t++)this.numbers_of_rewards_1.set(t,0),this.numbers_of_rewards_0.set(t,0);return this}predict(){let t=0,e=0;for(let r=0;r<this.bounds;r++){let n=probabilityDistributions.rbeta(1,this.numbers_of_rewards_1.get(r)+1,this.numbers_of_rewards_0.get(r)+1);n>e&&(e=n,t=r)}return t}learn(t={}){const{tsRow:e,getBound:r}=t;let n=this.predict();this.last_selected.push(n);let i=e[r(n)];return 1===i?this.numbers_of_rewards_1.set(n,this.numbers_of_rewards_1.get(n)+1):this.numbers_of_rewards_0.set(n,this.numbers_of_rewards_0.get(n)+1),this.total_reward=this.total_reward+i,this.iteration++,this}train(t){const{tsRow:e,getBound:r=this.getBound}=t;if(Array.isArray(e))for(let t in e)this.learn({tsRow:e[t],getBound:r});else this.learn({tsRow:e,getBound:r});return this}}const mlf=src$1,mlc=src,mln=src$6,{RandomForestRegression:RandomForestRegression$1,RandomForestClassifier:RandomForestClassifier$1}=mlf,{DecisionTreeRegression:DecisionTreeRegression$1,DecisionTreeClassifier:DecisionTreeClassifier$1}=mlc,{GaussianNB:GaussianNB$1}=mln;src$n.Regression=Object.assign({},src$n.Regression),src$n.SL=Object.assign({},src$n.SL),src$n.Stat=Object.assign({},src$n.Stat),src$n.RL=Object.assign({},src$n.RL,{ReinforcedLearningBase:ReinforcedLearningBase,UpperConfidenceBound:UpperConfidenceBound,ThompsonSampling:ThompsonSampling}),src$n.UpperConfidenceBound=UpperConfidenceBound,src$n.ThompsonSampling=ThompsonSampling,src$n.Regression.DecisionTreeRegression=DecisionTreeRegression$1,src$n.Regression.RandomForestRegression=RandomForestRegression$1,src$n.Regression.MultivariateLinearRegression=MultivariateLinearRegression,src$n.SL.GaussianNB=GaussianNB$1,src$n.SL.LogisticRegression=LogisticRegression,src$n.SL.DecisionTreeClassifier=DecisionTreeClassifier$1,src$n.SL.RandomForestClassifier=RandomForestClassifier$1,src$n.Stat.PCA=pca;const ml=src$n,transformConfigMap={scale:"scaleOptions",descale:"descaleOptions",label:"labelOptions",labelEncoder:"labelOptions",labeldecode:"labelOptions",labelDecode:"labelOptions",labelDecoder:"labelOptions",onehot:"oneHotOptions",oneHot:"oneHotOptions",oneHotEncode:"oneHotOptions",oneHotEncoder:"oneHotOptions",reducer:"reducerOptions",reduce:"reducerOptions",merge:"mergeData"};class DataSet{static getTransforms(t={}){return Object.keys(t).reduce(((e,r)=>{const n=t[r],i={name:r,options:{strategy:Array.isArray(n)?n[0]:n}};return Array.isArray(n)&&n.length>1&&(i.options[transformConfigMap[n[0]]]=n[1]),e.push(i),e}),[])}static reverseColumnMatrix(t={}){const{vectors:e,labels:r}=t,n=Array.isArray(r)&&Array.isArray(r[0])?r:r.map((t=>[t]));return e.reduce(((t,e)=>(t.push(e.reduce(((t,r,i)=>(t[n[i][0]]=e[i],t)),{})),t)),[])}static reverseColumnVector(t={}){const{vector:e,labels:r}=t,n=Array.isArray(r)&&Array.isArray(r[0])?r:r.map((t=>[t]));return e.reduce(((t,e)=>(t.push({[n[0][0]]:e}),t)),[])}static encodeObject(t,e){const{labels:r,prefix:n,name:i}=e;return r.reduce(((e,r)=>(e[`${n}${r}`]=r&&t[i]&&t[i].toString()===r.toString()?1:0,e)),{})}static oneHotEncoder(t,e){const r=Object.assign({merge:!0},e),n=r.data||this.columnArray(t,r.columnArrayOptions),i=Array.from(new Set(n).values()),o=r.prefix||`${t}_`,s=n.reduce(((t,e,r,n)=>(i.forEach((r=>{const n=`${o}${r}`,i=e===r?1:0;Array.isArray(t[n])?t[n].push(i):t[n]=[i]})),t)),{});return this.encoders.has(t)&&r.merge?this.encoders.get(t).labels=Array.from(new Set(i.concat(this.encoders.get(t).labels))):this.encoders.set(t,{name:t,labels:i,prefix:o}),s}static oneHotDecoder(t,e){const r=Object.assign({},e),n=r.encoders||this.encoders,i=r.prefix||n.get(t).prefix,o=r.labels||n.get(t).labels;return(r.data||this.oneHotColumnArray(t,r.oneHotColumnArrayOptions)).reduce(((e,r)=>{const n=Object.keys(r).filter((t=>1===r[t]&&(-1!==o.indexOf(t.replace(i,""))||-1!==o.map((t=>String(t))).indexOf(t.replace(i,"")))))[0]||"",s={[t]:n.replace(i,"")};return e.push(s),e}),[])}static selectColumns(t,e={}){return(Object.assign({},e).data||this.data).reduce(((e,r)=>{const n={};return t.forEach((t=>{n[t]=r[t]})),e.push(n),e}),[])}static columnArray(t,e={}){const r=Object.assign({prefilter:()=>!0,filter:()=>!0,replace:{test:void 0,value:void 0},parseInt:!1,parseIntBase:10,parseFloat:!!e.scale,scale:!1},e),n=(r.data||this.data).filter(r.prefilter).reduce(((e,n,i,o)=>{let s=n[t],a="function"==typeof r.replace.test&&r.replace.test(s)?"function"==typeof r.replace.value?r.replace.value(e,n,i,o,t):r.replace.value:s;return r.filter(a)&&(r.parseInt?e.push(parseInt(a,r.parseIntBase)):r.parseFloat?e.push(parseFloat(a)):e.push(a)),e}),[]);if("function"==typeof r.scale)return n.map(r.scale);if(!r.scale)return n;switch(r.scale){case"standard":return util$3.StandardScaler(n);case"log":return util$3.LogScaler(n);case"exp":return util$3.ExpScaler(n);default:return util$3.MinMaxScaler(n)}}static columnMatrix(t=[],e=[]){const r=e.length?{data:e}:{},n=(Array.isArray(t)&&Array.isArray(t[0])?t:t.map((t=>[t,r]))).map((t=>DataSet.columnArray.call(this,...t)));return util$3.pivotArrays(n)}static mapToObject(t=new Map){return Array.from(t.keys()).reduce(((e,r)=>{const n=t.get(r);return n instanceof Map?e[r]=DataSet.mapToObject(n):e[r]="function"==typeof n?`[Function ${n.name}]`:JSON.parse(JSON.stringify(n)),e}),{})}static getBinaryValue(t=""){if(!t)return 0;switch(t){case!1:case"N":case"n":case"NO":case"No":case"no":case"False":case"F":case"f":return 0;default:return 1}}constructor(t=[],e={}){return this.config=Object.assign({debug:!0},e),this.data=[...t],this.labels=new Map,this.encoders=new Map,this.scalers=new Map,this.selectColumns=DataSet.selectColumns,this.columnArray=DataSet.columnArray,this.encodeObject=DataSet.encodeObject,this.oneHotEncoder=DataSet.oneHotEncoder,this.oneHotDecoder=DataSet.oneHotDecoder,this.columnMatrix=DataSet.columnMatrix,this.reverseColumnMatrix=DataSet.reverseColumnMatrix,this.reverseColumnVector=DataSet.reverseColumnVector,this.getTransforms=DataSet.getTransforms,(this.config.labels||this.config.encoders||this.config.scalers)&&this.importFeatures({labels:this.config.labels,encoders:this.config.encoders,scalers:this.config.scalers}),this}exportFeatures(t={}){Object.assign({},t);return{encoders:DataSet.mapToObject(this.encoders),labels:DataSet.mapToObject(this.labels),scalers:DataSet.mapToObject(this.scalers)}}importFeatures(t={}){Object.keys(t.encoders||{}).forEach((e=>{const r=t.encoders[e];this.encoders.set(e,r)})),Object.keys(t.labels||{}).forEach((e=>{const r=t.labels[e],n=Object.keys(r).map((t=>[t,r[t]]));void 0!==r[0]&&void 0!==r[1]&&n.push([0,!1],[!1,0],[null,0],["no",0],["No",0],["NO",0],["F",0],["f",0],["null",0],["",0],[void 0,0],["undefined",0],[1,!0],[!0,1]),this.labels.set(e,new Map(n))})),Object.keys(t.scalers||{}).forEach((e=>{let r;const n=t.scalers[e],{config:i}=n;switch(i.strategy){case"standard":r=util$3.StandardScalerTransforms(void 0,i.nan_value,i.return_nan,n.components),n.scale=r.scale,n.descale=r.descale;break;case"normalize":case"minmax":r=util$3.MinMaxScalerTransforms(void 0,i.nan_value,i.return_nan,n.components),n.scale=r.scale,n.descale=r.descale;break;default:n.scale=Math.log,n.descale=Math.exp}this.scalers.set(e,n)}))}filterColumn(t=()=>!0){return this.data.filter(t)}columnScale(t,e={}){const r="string"==typeof e?{strategy:e}:e,n=Object.assign({strategy:"log",forced_coercion:!1},r);let i,o,s=n.data||this.columnArray(t,n.columnArrayOptions);switch(s=s.filter((t=>void 0!==t)).map(((e,r)=>{if("number"!=typeof e){this.config.debug&&!1===n.forced_coercion&&console.error(TypeError(`Each value must be a number, error at index [${t}][${r}]: <${typeof e}>${e}`));const i=Number(e);if(isNaN(i)&&n.forced_coercion)return 0;if(isNaN(i))throw TypeError(`Only numerical values in (${t}) can be scaled i: ${r} datum: ${e}`);return i}return e})),n.strategy){case"standard":o=util$3.StandardScalerTransforms(s,n.nan_value,n.return_nan),this.scalers.set(t,{name:t,scale:o.scale,descale:o.descale,components:o.components}),i=o.values;break;case"normalize":case"minmax":o=util$3.MinMaxScalerTransforms(s,n.nan_value,n.return_nan),this.scalers.set(t,{name:t,scale:o.scale,descale:o.descale,components:o.components}),i=o.values;break;default:this.scalers.set(t,{name:t,scale:Math.log,descale:Math.exp,components:{average:util$3.avg(s),standard_dev:util$3.sd(s),maximum:util$3.max(s),minimum:util$3.min(s)}}),i=util$3.LogScaler(s)}return this.scalers.get(t).config=n,i}columnDescale(t,e){const r=Object.assign({},e),n=r.data||this.columnArray(t,r.columnArrayOptions),i=this.scalers.get(t).descale;return n.map(i)}labelEncoder(t,e){const r=Object.assign({binary:!1,merge:!0},e),n=r.data||this.columnArray(t,r.columnArrayOptions);let i=Array.from(new Set(n).values()).sort(r.sortFunction);const o=new Map(i.reduce(((t,e,n)=>(r.binary?(0===n&&t.push([0,!1],["0",!1],[1,!0],["1",!0]),t.push([e,DataSet.getBinaryValue(e)])):(t.push([e,n]),t.push([n,e])),t)),[]));this.labels.has(t)&&r.merge?this.labels.set(t,new Map([...this.labels.get(t),...o])):this.labels.set(t,o);return r.binary?n.map(DataSet.getBinaryValue):n.map((t=>o.get(t)))}labelDecode(t,e){const r=Object.assign({},e);return(r.data||this.columnArray(t,r.columnArrayOptions)).map((e=>this.labels.get(t).get(e)))}oneHotColumnArray(t,e){const r=Object.assign({},e),n=r.labels||this.encoders.get(t).labels,i=r.prefix||this.encoders.get(t).prefix;return this.selectColumns(n.map((t=>`${i}${t}`)))}columnReducer(t,e){return{[t]:this.columnArray(e.columnName,e.columnOptions).reduce(e.reducer,[])}}columnMerge(t,e=[]){if(this.data.length!==e.length)throw new RangeError(`Merged data column must have the same length(${e.length}) as the DataSet's length (${this.data.length})`);return{[t]:e}}inverseTransformObject(t,e){const r=Object.assign({removeValues:!1},e),n=[];let i=Object.assign({},t);const o=Object.keys(this.data[0]),s=o.reduce(((e,r)=>(this.scalers.has(r)&&(e[r]=this.scalers.get(r).descale(t[r])),e)),{}),a=o.reduce(((e,r)=>(this.labels.has(r)&&(e[r]=this.labels.get(r).get(t[r])),e)),{}),u=o.reduce(((e,i)=>{if(this.encoders.has(i)){const o=this.oneHotDecoder(i,{data:[t]});e=Object.assign({},e,o[0]),r.removeValues&&n.push(...this.encoders.get(i).labels.map((t=>`${this.encoders.get(i).prefix}${t}`)))}return e}),{});return i=Object.assign(i,s,a,u),r.removeValues&&n.length&&(i=Object.keys(i).reduce(((t,e)=>(-1===n.indexOf(e)&&(t[e]=i[e]),t)),{})),i}transformObject(t,e){const r=Object.assign({removeValues:!1,checkColumnLength:!0},e),n=[],i=[].concat(...Array.from(this.encoders.keys()).map((t=>this.encoders.get(t).labels.map((e=>`${this.encoders.get(t).prefix}${e}`))))),o=this.data.length?Object.keys(this.data[0]):Object.keys(t),s=Object.keys(t).concat(i),a=s.reduce(((t,e)=>(-1===o.indexOf(e)&&-1===i.indexOf(e)&&t.push(e),t)),[]);let u=Object.assign({},t);if(r.checkColumnLength&&o.length!==s.length&&o.length+i.length!==s.length)throw new RangeError(`Object must have the same number of keys (${s.length}) as data in your dataset(${o.length})`);if(r.checkColumnLength&&a.length)throw new ReferenceError(`Object must have identical keys as data in your DataSet. Invalid keys: ${a.join(",")}`);{const e=s.reduce(((e,r)=>(this.scalers.has(r)&&(e[r]=this.scalers.get(r).scale(t[r])),e)),{}),i=s.reduce(((e,r)=>(this.labels.has(r)&&(e[r]=this.labels.get(r).get(t[r])),e)),{}),o=s.reduce(((e,i)=>(this.encoders.has(i)&&(e=Object.assign({},e,this.encodeObject(t,this.encoders.get(i))),r.removeValues&&n.push(i)),e)),{});u=Object.assign(u,e,i,o),r.removeValues&&n.length&&(u=Object.keys(u).reduce(((t,e)=>(-1===n.indexOf(e)&&(t[e]=u[e]),t)),{}))}return u}columnReplace(t,e={}){const r=Object.assign({strategy:"mean",empty:!0,arrayOptions:{parseFloat:!0,filter:t=>t},labelOptions:{}},e);let n,i={test:t=>!t,value:n};switch(r.strategy){case"scale":n=this.columnScale(t,r.scaleOptions),i={test:t=>!0,value:(t,e,r,i)=>n[r]};break;case"descale":n=this.columnDescale(t,r.descaleOptions),i={test:t=>!0,value:(t,e,r,i)=>n[r]};break;case"label":case"labelEncoder":n=this.labelEncoder(t,r.labelOptions),i={test:t=>!0,value:(t,e,r,i)=>n[r]};break;case"labeldecode":case"labelDecode":case"labelDecoder":n=this.labelDecode(t,r.labelOptions),i={test:t=>!0,value:(t,e,r,i)=>n[r]};break;case"onehot":case"oneHot":case"oneHotEncode":case"oneHotEncoder":return n=this.oneHotEncoder(t,r.oneHotOptions),i={test:t=>!0,value:(t,e,r,i)=>n[r]},n;case"reducer":case"reduce":return n=this.columnReducer(t,r.reducerOptions),n;case"merge":return n=this.columnMerge(t,r.mergeData),n;case"parseNumber":return n=this.columnArray(t).map((t=>Number(t))),n;default:n=ml.ArrayStat[r.strategy](this.columnArray(t,r.arrayOptions)),i.value=n}return this.columnArray(t,Object.assign({},{replace:i,scale:e.scale},e.columnOptions))}fitColumns(t={},e={}){const r=Object.assign({returnData:!0,columns:[]},t);t.columns&&!1!==Array.isArray(t.columns)||(r.columns=t.columns?DataSet.getTransforms(t.columns):DataSet.getTransforms(t));const n=r.columns.reduce(((t,e,r,n)=>{let i=this.columnReplace(e.name,e.options);return Array.isArray(i)?(i=i.map((t=>({[e.name]:t}))),t[e.name]=i):Object.keys(i).forEach((e=>{t[e]=i[e].map((t=>({[e]:t})))})),t}),{});if(Object.keys(n)&&Object.keys(n).length){const t=Object.keys(n),e=n[t[0]].reduce(((e,r,i,o)=>{const s={};return t.forEach((t=>{s[t]=n[t][i][t]})),e.push(s),e}),[]);this.data=this.data.map(((t,r)=>Object.assign({},t,e[r])))}return r.returnData?this.data:this}fitInverseTransforms(t={}){const e=Object.assign({returnData:!0},t);return this.data=this.data.map((e=>t.removeValues?this.inverseTransformObject(e,t):Object.assign({},e,this.inverseTransformObject(e,t)))),e.returnData?this.data:this}fitTransforms(t={}){const e=Object.assign({returnData:!0},t);return this.data=this.data.map((e=>t.removeValues?this.transformObject(e,t):Object.assign({},e,this.transformObject(e,t)))),e.returnData?this.data:this}}class ColumnVectorizer{constructor(t={}){return this.data=t.data||[],this.tokens=new Set,this.vectors=[],this.wordMap={},this.wordCountMap={},this.maxFeatures=t.maxFeatures,this.sortedWordCount=[],this.limitedFeatures=[],this.matrix=[],this.replacer=(t="")=>{const e=t.toLowerCase().replace(/[^a-zA-Z]/gi," ");return nlp.PorterStemmer.tokenizeAndStem(e).join(" ")},this}get_tokens(){return Array.from(this.tokens)}get_vector_array(){return this.get_tokens().map((t=>[t]))}fit_transform(t={}){(t.data||this.data).forEach((t=>{const e={};this.replacer(t).split(" ").forEach((t=>{const r=t.toLowerCase();e[r]=e[r]?e[r]+1:1,this.wordCountMap[r]=this.wordCountMap[r]?this.wordCountMap[r]+1:1,this.tokens.add(r)})),this.vectors.push(e)})),this.wordMap=Array.from(this.tokens).reduce(((t,e)=>(t[e]=0,t)),{}),this.sortedWordCount=Object.keys(this.wordCountMap).sort(((t,e)=>this.wordCountMap[e]-this.wordCountMap[t])),this.vectors=this.vectors.map((t=>Object.assign({},this.wordMap,t)));const e=new DataSet(this.vectors);return this.limitedFeatures=this.get_limited_features(t),this.matrix=e.columnMatrix(this.limitedFeatures),this.matrix}get_limited_features(t={}){const e=t.maxFeatures||this.maxFeatures||this.tokens.size;return this.sortedWordCount.slice(0,e).map((t=>[t]))}evaluateString(t=""){const e=this.replacer(t).split(" ").reduce(((t,e)=>(this.tokens.has(e)&&(t[e]=void 0!==t[e]?t[e]+1:1),t)),{});return Object.assign({},this.wordMap,e)}evaluate(t="",e){const r=this.evaluateString(t),n=this.get_limited_features(e);return new DataSet([r]).columnMatrix(n)}}const nlp=Object.assign({ColumnVectorizer:ColumnVectorizer});class GridSearch{constructor(t){this._run_callback=t.run_callback,this._params=[],this._shades=[],this._combinations=[],this._results=[],this._prepare(t.params)}save(t){let e={results:this._results,params:this._params,combinations:this._combinations};require$$0$2.writeFileSync(t,JSON.stringify(e),{encoding:"utf8"})}load(t){let e=require$$0$2.readFileSync(t,"utf8"),r=JSON.parse(e);this._results=r.results,this._params=r.params,this._combinations=r.combinations}clone(t){return Object.assign({},t)}_prepare(t){let e=[];for(let r in t)t.hasOwnProperty(r)&&e.push({name:r,values:t[r]});this._combinations=[{}];for(let t=0;t<e.length;t++){let r=[];for(let n of this._combinations)for(let i=0;i<e[t].values.length;i++){let o=this.clone(n);o[e[t].name]=e[t].values[i],r.push(o)}this._combinations=r}this._params=e}run(){for(let t of this._combinations)this._results.push({params:t,results:this._run_callback(t)})}_createDefaultTable(t,e,r){let n=[];for(let i=0;i<t;i++){let t=[];for(let n=0;n<e;n++)t.push(r);n.push(t)}return n}_findMatchForParam(t,e){for(let r=0;r<t.length;r++){let n=!0;for(let i in t[r])t[r].hasOwnProperty(i)&&(n=n&&e[i]==t[r][i]);if(n)return r}return-1}getTableOfResults(t,e,r){let n=[{}],i=[{}],o=this._params.filter((t=>e.indexOf(t.name)>=0)),s=this._params.filter((e=>t.indexOf(e.name)>=0));for(let t=0;t<o.length;t++){let e=[];for(let r of n)for(let n=0;n<o[t].values.length;n++){let i=this.clone(r);i[o[t].name]=o[t].values[n],e.push(i)}n=e}for(let t=0;t<s.length;t++){let e=[];for(let r of i)for(let n=0;n<s[t].values.length;n++){let i=this.clone(r);i[s[t].name]=s[t].values[n],e.push(i)}i=e}let a=this._createDefaultTable(n.length,i.length,-1);for(let t of this._results){let e=this._findMatchForParam(n,t.params),o=this._findMatchForParam(i,t.params);if(e<0||o<0)continue;let s=r(t);a[e][o]<s&&(a[e][o]=s)}return{rows:n,cols:i,results:a}}_createTitle(t){let e="";for(let r in t)t.hasOwnProperty(r)&&(e+=`${r}=${t[r]},`);return e.substr(0,e.length-1)}_padToWidth(t,e,r){for(r=r||" ";t.length<e;)t+=r;return t}_prepareColorShades(t,e){let r=(e-t)/5;this._shades=[];for(let t=0;t<5;t++)this._shades.push(e-t*r)}_outputValue(t,e){return this._padToWidth(""+t,e)}displayTableOfResults(t,e,r){let n=this.getTableOfResults(t,e,r),i=n.cols.map((t=>this._createTitle(t))),o=n.rows.map((t=>this._createTitle(t))),s=i.map((t=>Math.max(t.length+4,8))),a=0;o.forEach((t=>{a=Math.max(a,t.length+4)}));let u=null,h=null;n.results.forEach((t=>{t.forEach((t=>{(null===u||u>t)&&(u=t),(null===h||h<t)&&(h=t)}))})),this._prepareColorShades(u,h);let c="",l="";c+="| "+this._padToWidth("",a),l+="|-"+this._padToWidth("",a,"-");for(let t=0;t<i.length;t++)c+="| "+this._padToWidth(i[t],s[t]),l+="|-"+this._padToWidth("",s[t],"-");console.log(c),console.log(l);for(let t=0;t<o.length;t++){c="| ",c+=this._padToWidth(o[t],a);for(let e=0;e<i.length;e++)c+="| "+this._outputValue(n.results[t][e],s[e]);console.log(c)}}}var GridSearch_1=GridSearch,grid_search={GridSearch:GridSearch_1};const{GridSearch:GridSearch$1}=grid_search,Matrix$b=ml.Matrix,ConfusionMatrix$1=ml.ConfusionMatrix;function train_test_split(t=[],e={test_size:.2,train_size:.8,random_state:0,return_array:!1,parse_int_train_size:!0}){const r=random.engines.mt19937().seed(e.random_state||0),n=[],i="boolean"!=typeof e.parse_int_train_size||e.parse_int_train_size,o=e.train_size?e.train_size*t.length:(1-(e.test_size||.2))*t.length,s=i?parseInt(o,10):o,a=[].concat(t);for(;n.length<s;){const t=random.integer(0,a.length-1)(r);n.push(a.splice(t,1)[0])}return e.return_array?[n,a]:{train:n,test:a}}function cross_validation_split(t=[],e={folds:3,random_state:0}){const r=random.engines.mt19937().seed(e.random_state||0),n=e.folds||3,i=[],o=[].concat(t),s=parseInt(t.length/(n||3),10);for(let t in lodash_range(n)){const t=[];for(;t.length<s;){const e=random.integer(0,o.length-1)(r);t.push(o.splice(e,1)[0])}i.push(t)}return i}function cross_validate_score(t={}){const e=Object.assign({},{dependentFeatures:[["X"]],independentFeatures:[["Y"]],folds:10,accuracy:"standardError",use_train_x_matrix:!0,use_train_y_matrix:!1,use_train_y_vector:!1,use_estimates_y_vector:!1},t),r=e.classifier,n=e.regression,i=cross_validation_split(e.dataset,{folds:e.folds,random_state:e.random_state}),o=new DataSet(e.testingset),s=o.columnMatrix(e.independentFeatures),a=o.columnMatrix(e.dependentFeatures),u=util$3.pivotVector(s)[0];return i.map((t=>{const i=new DataSet(t),o=i.columnMatrix(e.dependentFeatures),s=i.columnMatrix(e.independentFeatures),h=e.use_train_x_matrix?new Matrix$b(o):o,c=e.use_train_y_matrix?new Matrix$b(s):e.use_train_y_vector?util$3.pivotVector(s)[0]:s;if(n){let t,r;"function"==typeof n.train?(t=n.train(h,c,e.modelOptions),r=n.predict(a)):(t=new n(h,c,e.modelOptions),r=t.predict(a));const i=r;return"standardError"===e.accuracy?util$3.standardError(u,i):util$3.rSquared(u,i)}{let t,n;"function"==typeof r.train?(r.train(h,c,e.modelOptions),n=r.predict(a)):(t=new r(h,c,e.modelOptions),n=t.predict(a));const i=e.use_estimates_y_vector?util$3.pivotVector(n)[0]:n;return ConfusionMatrix$1.fromLabels(u,i).getAccuracy()}}))}function grid_search$1(t={}){const e=Object.assign({},{return_parameters:!1,compare_score:"mean",sortAccuracyScore:"desc",parameters:{}},t),r=e.regression,n=e.classifier,i=!t.sortAccuracyScore&&e.regression?"asc":e.sortAccuracyScore,o=new GridSearch$1({params:e.parameters,run_callback:t=>{e.regression?e.regression=new r(t):e.classifier=new n(t);const i=cross_validate_score(e);return e.compare_score?util$3[e.compare_score](i):i}});o.run();const s="desc"===i?(t,e)=>e.results-t.results:(t,e)=>t.results-e.results,a=o._results.sort(s);return e.return_parameters?a:a[0]}const cross_validation={train_test_split:train_test_split,cross_validation_split:cross_validation_split,kfolds:cross_validation_split,cross_validate_score:cross_validate_score,grid_search:grid_search$1,GridSearch:GridSearch$1},loadCSV$1=loadCSV,loadCSVURI$1=loadCSVURI,preprocessing={DataSet:DataSet},util$4=util$3,cross_validation$1=cross_validation,model_selection=cross_validation,calc$1=calc,ml$1=ml,nlp$1=nlp,csv=csvUtils,PD$1=PD;exports.loadCSV=loadCSV$1,exports.loadCSVURI=loadCSVURI$1,exports.preprocessing=preprocessing,exports.util=util$4,exports.cross_validation=cross_validation$1,exports.model_selection=model_selection,exports.calc=calc$1,exports.ml=ml$1,exports.nlp=nlp$1,exports.csv=csv,exports.PD=PD$1,exports.DataSet=DataSet,Object.defineProperty(exports,"__esModule",{value:!0})}));
//# sourceMappingURL=/sm/41eac2fe9738eca3dfe918266005e56788f7143e002de765c9037ecca8b9fa7c.map