twokeys 1.0.3 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +193 -0
- package/dist/index.d.ts +193 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/package.json +43 -7
- package/README.md +0 -241
- package/bower.json +0 -23
- package/dist/twokeys-amd.coffee +0 -651
- package/dist/twokeys-amd.js +0 -1077
- package/dist/twokeys.js +0 -1145
- package/dist/twokeys.min.js +0 -4
- package/index.js +0 -1
- package/src/twokeys.coffee +0 -651
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use strict';Object.defineProperty(exports,'__esModule',{value:true});function R(b=100){return Math.floor(Math.random()*b)}function E(b=1e3,t=100){let n=[];for(let e=0;e<b;e++)n.push(R(t));return n}function _(b=2,t=100){let n=[];for(let e=0;e<b;e++)n.push(Math.floor(Math.random()*(t/10)%t));return n}function f(b=1e3,t=2,n=100){let e=[];for(let r=0;r<b;r++)e.push(_(t,n));return e}var g=class{data;constructor(t={}){this.data={original:t.data??E()};}sorted(){return this.data.sorted||(this.data.sorted=this.getSorted(this.data.original)),this.data.sorted}getSorted(t){return [...t].sort((n,e)=>n>e?1:n===e?0:-1)}median(){return this.sorted(),this.data.median===void 0&&(this.data.median=this.getMedian(this.data.sorted)),this.data.medianDepth===void 0&&(this.data.medianDepth=this.getMedianDepth(this.data.sorted)),{datum:this.data.median,depth:this.data.medianDepth}}getMedianDepth(t,n=0){return t.length?n+(t.length+1)/2:NaN}getMedian(t){let n=t.length;if(!n)return NaN;if(n===1)return t[0];let e=Math.floor(n/2);return n%2===0?(t[e-1]+t[e])/2:t[e]}mean(){return this.data.mean===void 0&&(this.data.mean=this.getMean(this.data.original)),this.data.mean}getMean(t){if(!t.length)return NaN;let n=0;for(let e of t)n+=e;return n/t.length}mode(){return this.data.mode||(this.sorted(),this.data.mode=this.getMode(this.data.sorted)),this.data.mode}getMode(t){if(!t.length)return {count:0,data:[]};let n={},e=0;for(let i of t)n[i]=(n[i]||0)+1,n[i]>e&&(e=n[i]);let r=[];for(let[i,s]of Object.entries(n))s===e&&r.push(Number(i));return {count:e,data:r.sort((i,s)=>i-s)}}extremes(){return this.data.extremes||(this.sorted(),this.data.extremes=this.getExtremes(this.data.sorted)),this.data.extremes}getExtremes(t){return t.length?[t[0],t[t.length-1]]:[]}counts(){return this.data.counts||(this.sorted(),this.data.counts=this.getCounts(this.data.sorted)),this.data.counts}getCounts(t){let n=new Map;for(let r of t)n.set(r,(n.get(r)||0)+1);let e=[];for(let[r,i]of n)e.push([r,i]);return e.sort((r,i)=>r[0]-i[0])}hinges(){return this.data.hinges||(this.sorted(),this.data.hinges=this.getHinges(this.data.sorted)),this.data.hinges}getHinges(t,n=2,e=[]){let r=[...t],i=r.length,s=n;if(s%2!==0&&s++,i<=s||s<=0)return e;let m=Math.floor(i/s),h=Math.floor(i/m)-1;for(let a=0;a<=h;a++){let o=r.slice(a*m,a*m+m);e.push({datum:this.getMedian(o),depth:this.getMedianDepth(o,a*m)});}return e}iqr(){return this.data.iqr===void 0&&(this.hinges(),this.data.iqr=this.getIQR(this.data.hinges)),this.data.iqr}getIQR(t){let n=t[0]?.datum,e=t[1]?.datum;return n===void 0||e===void 0?NaN:Math.abs(n-e)}fences(){return this.data.fences||(this.median(),this.iqr(),this.data.fences=this.getFences()),this.data.fences}getFences(t=1.5){let n=this.data.median,e=this.data.iqr;if(n===void 0||e===void 0||isNaN(e))return [];let r=e*t;return [n-r,n+r]}outer(){return this.data.outer||(this.median(),this.iqr(),this.data.outer=this.getOuter()),this.data.outer}getOuter(t=1.5){let n=this.data.median,e=this.data.iqr;if(n===void 0||e===void 0||isNaN(e))return [];let r=2*e*t;return [n-r,n+r]}outside(){return this.data.outside||(this.outer(),this.data.outside=this.getOutside()),this.data.outside}getOutside(){let t=[],n=this.data.sorted,e=this.data.outer;if(!e||e.length===0)return [];let r=Math.min(...e),i=Math.max(...e);for(let s of n)(s>i||s<r)&&t.push(s);return t}inside(){return this.data.inside||(this.fences(),this.data.inside=this.getInside()),this.data.inside}getInside(){let t=[],n=this.data.sorted,e=this.data.fences;if(!e||e.length===0)return [];let r=Math.min(...e),i=Math.max(...e);for(let s of n)s<i&&s>r&&t.push(s);return t}outliers(){return this.data.outliers||(this.fences(),this.data.outliers=this.getOutliers()),this.data.outliers}getOutliers(){let t=[],n=this.data.sorted,e=this.data.fences;if(e.length===0)return [];let r=Math.min(...e),i=Math.max(...e);for(let s of n)(s>i||s<r)&&t.push(s);return t}ranked(){return this.data.ranked||(this.sorted(),this.data.ranked=this.getRanked(this.data.sorted)),this.data.ranked}getRanked(t,n=true){let e={},r={},i=t.length,s=[],m=NaN,h=[],a=()=>{m=NaN,h=[];};for(let d=0;d<t.length;d++){let u=t[d];if(!n)e[u]={rank:d+1,peers:0},r[u]={rank:i-d,peers:0};else {let c=d+1,l=d-1;u===t[l]?(!isNaN(m)&&h.length===0?(h.push(u),s.push(h),a()):(h.push(u),m=l),u!==t[c]&&(s.push(h),a())):u!==t[c]?h.length>0?(s.push(h),a()):s.push(u):h.push(u);}}let o=0;for(let d=0;d<s.length;d++){let u=s[d];if(typeof u=="number")r[u]={rank:d+1+o,peers:0},e[u]={rank:i-d-o,peers:0};else if(Array.isArray(u)){o+=u.length;let c=u[0];r[c]={rank:d+1+o,peers:u.length},e[c]={rank:i-d-o,peers:u.length};}else o+=1;}return {up:e,down:r,groups:{down:[...s],up:[...s].reverse()}}}adjacent(){return this.data.adjacent||(this.fences(),this.data.adjacent=this.getAdjacent(this.data.sorted,this.data.fences)),this.data.adjacent}getAdjacent(t,n){if(n.length===0)return [];let e=n[0],r=[],i=n[1],s=[];for(let m of t)m>e&&r.push(m),m<i&&s.push(m);return r.sort((m,h)=>m-h),s.sort((m,h)=>m-h),[r[0],s[s.length-1]]}binned(t=NaN){return this.data.binned||(this.sorted(),this.extremes(),this.data.binned=this.getBinned(this.data.sorted,t)),this.data.binned}getBinned(t,n=10,e=NaN,r=true){let i={},s=t.length,m=r?0:1;if(s===0)return {bins:0,width:NaN,binned:{}};let h=this.data.extremes,a=e;if(h&&isNaN(a)&&h.length===2){a=(h[1]-h[0])/(Math.log(t.length)/Math.LN2),a=Math.floor(a);let d=true;for(let u of t)if(u%1!==0){d=false;break}d&&(a=Math.floor(a));}let o=Math.floor(h[1]/a)+1;(!o||o<1)&&(o=1);for(let d of t){let u=Math.floor((d-m)/a);i[u]||(i[u]={from:u*a+m,to:(u+1)*a+m-1,data:[]}),i[u].data.push(d);}return {bins:o,width:a,binned:i}}logs(){return this.data.logs||(this.data.logs=this.getLogs(this.data.original)),this.data.logs}getLogs(t){return t.map(n=>Math.log(n))}roots(){return this.data.roots||(this.data.roots=this.getRoots(this.data.original)),this.data.roots}getRoots(t){return t.map(n=>Math.sqrt(n))}inverse(){return this.data.inverse||(this.data.inverse=this.getInverse(this.data.original)),this.data.inverse}getInverse(t){return t.map(n=>1/n)}hanning(){return this.data.hanning||(this.data.hanning=this.getSkipMeans(this.data.original)),this.data.hanning}getSkipMeans(t){let n=[];for(let e=0;e<t.length;e++)e!==0&&e!==t.length-1&&n.push((t[e]+t[e+1])/2);return n.unshift(t[0]),n.push(t[t.length-1]),n}smooth(){return this.data.smooth||(this.sorted(),this.data.smooth=this.getSmooth(this.data.original)),this.data.rough=this.getRough(this.data.original,this.data.smooth),this.data.smooth}getRough(t,n){let e=[];for(let r=0;r<t.length;r++)e.push(t[r]-n[r]);return e}getSmooth(t,n=3){let e=[...t];return e=this.smoothMedian(e,n),e=this.smoothExtremes(e,-1),e=this.smoothSplit(e,2),e=this.smoothMedian(e,n),e=this.smoothExtremes(e,-1),e=this.smoothMedian(e,n),e}smoothExtremes(t,n=1,e=0,r="both"){let i=t.length;if(i<=2)return [...t];let s=[...t];for(let m=e;m<n||n===-1;m++){let h=false;if(r==="both"||r==="head"){let a=s[0],o=s[1],d=s[2],u=o-2*(d-o),c=a<=o?o<=u?o:a<=u?u:a:a<=u?a:o<=u?u:o;s[0]!==c&&(s[0]=c,h=true);}if(r==="both"||r==="tail"){let a=s[i-3],o=s[i-2],d=s[i-1],u=o-2*(a-o),c=d<=o?o<=u?o:d<=u?u:d:d<=u?d:o<=u?u:o;s[i-1]!==c&&(s[i-1]=c,h=true);}if(n===-1&&!h)break}return s}smoothSplit(t,n=2,e=0){let r=[...t],i=t.length;for(let s=e;s<n||n===-1;s++){let m=false;for(let h=2;h<i-1;h++){let a=r[h],o=r[h-1],d=r[h-2],u=r[h+1];if(a===o&&(o>d&&a>u||o<d&&a<u)){let c=this.smoothExtremes(r.slice(0,h)),l=this.smoothExtremes(r.slice(h));r=c.concat(l),m=true;}}if(n===-1&&!m)return r}return r}smoothMedian(t,n=1,e=0){let r=t,i=t.length;if(i<=2)return [...t];for(let s=e;s<n||n===-1;s++){let m=new Array(i);m[0]=r[0],m[i-1]=r[i-1];let h=false;for(let a=1;a<i-1;a++){let o=r[a],d=Math.min(Math.max(r[a-1],o),r[a+1]);m[a]=d,d!==o&&(h=true);}if(n===-1&&!h)return r;r=m;}return r}jitter(t,n=1,e=NaN,r=1,i=NaN,s=0){let m=s+1,h=[...t];if(m<=n){let a=[];for(let o of h){let d=i;!d&&!isNaN(d)&&(d=(1+Math.floor(o/10))*(Math.random()>.5?1:-1));let u=o+Math.floor(Math.random()*r*d);!isNaN(e)&&u<e&&(u=e),a.push(u);}return this.jitter(a,n,e,r,i,m)}return h}trimean(){let t=this.median(),n=this.hinges();return n.length<2?t.datum:(n[0].datum+2*t.datum+n[1].datum)/4}letterValues(){this.sorted();let t=this.data.sorted.length;if(t<2)return [];let n=["M","F","E","D","C","B","A","Z","Y","X","W","V","U","T","S"],e=[],r=(t+1)/2,i=this.median().datum;e.push({letter:"M",depth:r,lower:i,upper:i,mid:i,spread:0});let s=r,m=1;for(;s>1&&m<n.length&&(s=Math.floor((Math.floor(s)+1)/2),!(s<1));){let h=Math.ceil(s)-1,a=t-Math.ceil(s);if(h<0||a>=t||h>=a)break;let o=this.data.sorted[h],d=this.data.sorted[a],u=(o+d)/2,c=d-o;e.push({letter:n[m],depth:s,lower:o,upper:d,mid:u,spread:c}),m++;}return e}rough(){return this.data.rough||this.smooth(),this.data.rough||[]}stemLeaf(t=1){this.sorted();let n=this.data.sorted;if(!n.length)return {stems:[],leaves:{},display:[]};let e=Math.pow(10,t),r=new Map;for(let a of n){let o=Math.floor(a/e),d=Math.abs(Math.round(a%e));r.has(o)||r.set(o,[]),r.get(o).push(d);}let i=Array.from(r.keys()).sort((a,o)=>a-o),s=[],m={},h=[];for(let a of i){let o=String(a);s.push(o);let d=r.get(a).sort((u,c)=>u-c).map(String);m[o]=d,h.push(`${o.padStart(4)} | ${d.join(" ")}`);}return {stems:s,leaves:m,display:h}}midSummaries(){return this.letterValues().map(({depth:n,mid:e,spread:r})=>({depth:n,mid:e,spread:r}))}describe(){return this.data.description={original:this.data.original,summary:{median:this.median(),mean:this.mean(),mode:this.mode(),hinges:this.hinges(),adjacent:this.adjacent(),outliers:this.outliers(),outer:this.outer(),outside:this.outside(),inside:this.inside(),extremes:this.extremes(),iqr:this.iqr(),fences:this.fences()},smooths:{smooth:this.smooth(),hanning:this.hanning()},transforms:{logs:this.logs(),roots:this.roots(),inverse:this.inverse()},counts:this.counts(),sorted:this.sorted(),ranked:this.ranked(),binned:this.binned()},this.data.description}},p=class{data;dimension;count;constructor(t={}){typeof t=="number"?(this.count=t,this.dimension=2,this.data={original:f(this.count,this.dimension)}):(this.dimension=t.dimensionality??2,this.count=t.count??100,this.data={original:t.data??f(this.count,this.dimension)});}describe(){return this.data.description={original:this.data.original},this.data.description}},M=class{smoothed=false;static DEFAULT_MAX_RANDOM_INTEGER=100;static DEFAULT_MIN_RANDOM_INTEGER=0;static DEFAULT_RANDOM_SERIES_COUNT=1e3;static DEFAULT_OUTLIER_MULTIPLE=1.5;static DEFAULT_JITTER_MULTIPLIER=1;static DEFAULT_SPLIT_PASSES=2;static DEFAULT_MAX_RANDOM_DIMENSIONALITY=2;static Series=g;static Points=p;static randomInteger=R;static randomSeries=E;static randomPoint=_;static randomPoints=f},A=M;exports.Points=p;exports.Series=g;exports.Twokeys=M;exports.default=A;//# sourceMappingURL=index.cjs.map
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":["randomInteger","max","randomSeries","count","series","i","randomPoint","dimension","point","randomPoints","points","Series","options","arr","a","b","offset","len","mid","total","num","data","freq","maxCount","val","modes","result","hinges","copy","hingeCount","per","howMany","step","fragment","first","second","multiple","base","iqr","extra","results","sorted","outer","min","fences","ties","up","down","ranked","tiedRank","tiedNumbers","reset","incr","decr","item","usable","low","lows","high","highs","bins","width","includeZero","binned","zeroOffset","extremes","calculatedWidth","areIntegers","binCount","bin","original","smoothed","residuals","x","passes","current","end","pass","changed","third","tmp","median","antepenultimate","penultimate","last","t1","t2","f1","left","right","next","floor","multiplier","weight","nextCurrent","jittered","w","value","med","h","n","letters","medDepth","medValue","depth","letterIdx","lowerIdx","upperIdx","lower","upper","spread","leafDigits","scale","stems","stem","leaf","sortedStems","stemStrings","leavesRecord","display","stemStr","leaves","Points","Twokeys","index_default"],"mappings":"sEAyGA,SAASA,EAAcC,CAAAA,CAAc,GAAA,CAAoC,CACvE,OAAO,IAAA,CAAK,MAAM,IAAA,CAAK,MAAA,EAAO,CAAIA,CAAG,CACvC,CAEA,SAASC,EACPC,CAAAA,CAAgB,GAAA,CAChBF,EAAc,GAAA,CACJ,CACV,IAAMG,CAAAA,CAAmB,EAAC,CAC1B,IAAA,IAASC,EAAI,CAAA,CAAGA,CAAAA,CAAIF,EAAOE,CAAAA,EAAAA,CACzBD,CAAAA,CAAO,IAAA,CAAKJ,CAAAA,CAAcC,CAAG,CAAC,CAAA,CAEhC,OAAOG,CACT,CAEA,SAASE,CAAAA,CACPC,CAAAA,CAAoB,CAAA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C5B,OAAA,IAAA,CAAK,KAAK,WAAA,CAAc,CACtB,SAAU,IAAA,CAAK,IAAA,CAAK,QACtB,CAAA,CACO,IAAA,CAAK,KAAK,WACnB,CACF,EAKakH,CAAAA,CAAN,KAAc,CACZ,QAAA,CAAoB,MAG3B,OAAgB,0BAAA,CAA6B,IAC7C,OAAgB,0BAAA,CAA6B,EAC7C,OAAgB,2BAAA,CAA8B,GAAA,CAC9C,OAAgB,yBAA2B,GAAA,CAC3C,OAAgB,0BAA4B,CAAA,CAC5C,OAAgB,qBAAuB,CAAA,CACvC,OAAgB,iCAAA,CAAoC,CAAA,CAGpD,OAAO,MAAA,CAAShH,CAAAA,CAChB,OAAO,MAAA,CAAS+G,CAAAA,CAGhB,OAAO,aAAA,CAAgB1H,CAAAA,CACvB,OAAO,YAAA,CAAeE,CAAAA,CACtB,OAAO,WAAA,CAAcI,CAAAA,CACrB,OAAO,YAAA,CAAeG,CACxB,EAGOmH,CAAAA,CAAQD","file":"index.cjs","sourcesContent":["/**\n * Twokeys - A small data exploration and manipulation library\n * Named after John Tukey, pioneer of exploratory data analysis (EDA)\n *\n * Features:\n * - Summary statistics (mean, median, mode, quartiles)\n * - Binning (histogram-like grouping)\n * - Smoothing (Hanning filter and median smoothing)\n * - Ranking and ranking analysis\n * - Outlier detection (using Tukey fences)\n * - Data transforms (logarithms, roots, inverses)\n */\n\nexport interface SeriesOptions {\n data?: number[];\n}\n\nexport interface PointsOptions {\n data?: number[][];\n dimensionality?: number;\n count?: number;\n}\n\nexport interface MedianResult {\n datum: number;\n depth: number;\n}\n\nexport interface ModeResult {\n count: number;\n data: number[];\n}\n\nexport interface RankInfo {\n rank: number;\n peers: number;\n}\n\nexport interface RankedResult {\n up: Record<number, RankInfo>;\n down: Record<number, RankInfo>;\n groups: {\n up: (number | number[])[];\n down: (number | number[])[];\n };\n}\n\nexport interface BinnedResult {\n bins: number;\n width: number;\n binned: Record<\n number,\n {\n from: number;\n to: number;\n data: number[];\n }\n >;\n}\n\nexport interface SeriesDescription {\n original: number[];\n summary: {\n median: MedianResult;\n mean: number;\n mode: ModeResult;\n hinges: MedianResult[];\n adjacent: number[];\n outliers: number[];\n outer: number[];\n outside: number[];\n inside: number[];\n extremes: number[];\n iqr: number;\n fences: number[];\n };\n smooths: {\n smooth: number[];\n hanning: number[];\n };\n transforms: {\n logs: number[];\n roots: number[];\n inverse: number[];\n };\n counts: [number, number][];\n sorted: number[];\n ranked: RankedResult;\n binned: BinnedResult;\n}\n\nexport interface PointsDescription {\n original: number[][];\n}\n\n// Constants\nconst DEFAULT_MAX_RANDOM_INTEGER = 100;\nconst DEFAULT_MIN_RANDOM_INTEGER = 0;\nconst DEFAULT_RANDOM_SERIES_COUNT = 1000;\nconst DEFAULT_OUTLIER_MULTIPLE = 1.5;\nconst DEFAULT_JITTER_MULTIPLIER = 1;\nconst DEFAULT_SPLIT_PASSES = 2;\nconst DEFAULT_MAX_RANDOM_DIMENSIONALITY = 2;\n\n// Utility functions\nfunction randomInteger(max: number = DEFAULT_MAX_RANDOM_INTEGER): number {\n return Math.floor(Math.random() * max);\n}\n\nfunction randomSeries(\n count: number = DEFAULT_RANDOM_SERIES_COUNT,\n max: number = DEFAULT_MAX_RANDOM_INTEGER\n): number[] {\n const series: number[] = [];\n for (let i = 0; i < count; i++) {\n series.push(randomInteger(max));\n }\n return series;\n}\n\nfunction randomPoint(\n dimension: number = DEFAULT_MAX_RANDOM_DIMENSIONALITY,\n max: number = DEFAULT_MAX_RANDOM_INTEGER\n): number[] {\n const point: number[] = [];\n for (let i = 0; i < dimension; i++) {\n point.push(Math.floor((Math.random() * (max / 10)) % max));\n }\n return point;\n}\n\nfunction randomPoints(\n count: number = DEFAULT_RANDOM_SERIES_COUNT,\n dimension: number = DEFAULT_MAX_RANDOM_DIMENSIONALITY,\n max: number = DEFAULT_MAX_RANDOM_INTEGER\n): number[][] {\n const points: number[][] = [];\n for (let i = 0; i < count; i++) {\n points.push(randomPoint(dimension, max));\n }\n return points;\n}\n\n/**\n * Series class for 1D data exploration\n */\nexport class Series {\n private data: {\n original: number[];\n sorted?: number[];\n median?: number;\n medianDepth?: number;\n mean?: number;\n mode?: ModeResult;\n extremes?: number[];\n counts?: [number, number][];\n hinges?: MedianResult[];\n iqr?: number;\n fences?: number[];\n outer?: number[];\n outside?: number[];\n inside?: number[];\n outliers?: number[];\n ranked?: RankedResult;\n adjacent?: number[];\n binned?: BinnedResult;\n logs?: number[];\n roots?: number[];\n inverse?: number[];\n hanning?: number[];\n smooth?: number[];\n rough?: number[];\n description?: SeriesDescription;\n };\n\n constructor(options: SeriesOptions = {}) {\n this.data = {\n original: options.data ?? randomSeries(),\n };\n }\n\n // Sort\n sorted(): number[] {\n if (!this.data.sorted) {\n this.data.sorted = this.getSorted(this.data.original);\n }\n return this.data.sorted;\n }\n\n private getSorted(arr: number[]): number[] {\n return [...arr].sort((a, b) => {\n if (a > b) return 1;\n if (a === b) return 0;\n return -1;\n });\n }\n\n // Median\n median(): MedianResult {\n this.sorted();\n if (this.data.median === undefined) {\n this.data.median = this.getMedian(this.data.sorted!);\n }\n if (this.data.medianDepth === undefined) {\n this.data.medianDepth = this.getMedianDepth(this.data.sorted!);\n }\n return {\n datum: this.data.median,\n depth: this.data.medianDepth,\n };\n }\n\n private getMedianDepth(arr: number[], offset: number = 0): number {\n if (!arr.length) return NaN;\n return offset + (arr.length + 1) / 2;\n }\n\n private getMedian(arr: number[]): number {\n const len = arr.length;\n if (!len) return NaN;\n if (len === 1) return arr[0];\n\n const mid = Math.floor(len / 2);\n if (len % 2 === 0) {\n return (arr[mid - 1] + arr[mid]) / 2;\n }\n return arr[mid];\n }\n\n // Mean\n mean(): number {\n if (this.data.mean === undefined) {\n this.data.mean = this.getMean(this.data.original);\n }\n return this.data.mean;\n }\n\n private getMean(arr: number[]): number {\n if (!arr.length) return NaN;\n let total = 0;\n for (const num of arr) {\n total += num;\n }\n return total / arr.length;\n }\n\n // Mode\n mode(): ModeResult {\n if (!this.data.mode) {\n this.sorted();\n this.data.mode = this.getMode(this.data.sorted!);\n }\n return this.data.mode;\n }\n\n private getMode(data: number[]): ModeResult {\n if (!data.length) {\n return { count: 0, data: [] };\n }\n\n // Count frequencies\n const freq: Record<number, number> = {};\n let maxCount = 0;\n\n for (const val of data) {\n freq[val] = (freq[val] || 0) + 1;\n if (freq[val] > maxCount) {\n maxCount = freq[val];\n }\n }\n\n // Find all values with max frequency\n const modes: number[] = [];\n for (const [val, count] of Object.entries(freq)) {\n if (count === maxCount) {\n modes.push(Number(val));\n }\n }\n\n return {\n count: maxCount,\n data: modes.sort((a, b) => a - b),\n };\n }\n\n // Extremes\n extremes(): number[] {\n if (!this.data.extremes) {\n this.sorted();\n this.data.extremes = this.getExtremes(this.data.sorted!);\n }\n return this.data.extremes;\n }\n\n private getExtremes(data: number[]): number[] {\n if (!data.length) return [];\n return [data[0], data[data.length - 1]];\n }\n\n // Counts\n counts(): [number, number][] {\n if (!this.data.counts) {\n this.sorted();\n this.data.counts = this.getCounts(this.data.sorted!);\n }\n return this.data.counts;\n }\n\n private getCounts(data: number[]): [number, number][] {\n const freq = new Map<number, number>();\n for (const val of data) {\n freq.set(val, (freq.get(val) || 0) + 1);\n }\n const result: [number, number][] = [];\n for (const [val, count] of freq) {\n result.push([val, count]);\n }\n return result.sort((a, b) => a[0] - b[0]);\n }\n\n // Hinges (quartiles)\n hinges(): MedianResult[] {\n if (!this.data.hinges) {\n this.sorted();\n this.data.hinges = this.getHinges(this.data.sorted!);\n }\n return this.data.hinges;\n }\n\n private getHinges(\n arr: number[],\n hinges: number = 2,\n result: MedianResult[] = []\n ): MedianResult[] {\n const copy = [...arr];\n const total = copy.length;\n\n let hingeCount = hinges;\n if (hingeCount % 2 !== 0) {\n hingeCount++;\n }\n\n if (total <= hingeCount || hingeCount <= 0) {\n return result;\n }\n\n const per = Math.floor(total / hingeCount);\n const howMany = Math.floor(total / per) - 1;\n\n for (let step = 0; step <= howMany; step++) {\n const fragment = copy.slice(step * per, step * per + per);\n result.push({\n datum: this.getMedian(fragment),\n depth: this.getMedianDepth(fragment, step * per),\n });\n }\n\n return result;\n }\n\n // IQR (Interquartile Range)\n iqr(): number {\n if (this.data.iqr === undefined) {\n this.hinges();\n this.data.iqr = this.getIQR(this.data.hinges!);\n }\n return this.data.iqr;\n }\n\n private getIQR(hinges: MedianResult[]): number {\n const first = hinges[0]?.datum;\n const second = hinges[1]?.datum;\n if (first === undefined || second === undefined) {\n return NaN;\n }\n return Math.abs(first - second);\n }\n\n // Fences\n fences(): number[] {\n if (!this.data.fences) {\n this.median();\n this.iqr();\n this.data.fences = this.getFences();\n }\n return this.data.fences;\n }\n\n private getFences(multiple: number = DEFAULT_OUTLIER_MULTIPLE): number[] {\n const base = this.data.median;\n const iqr = this.data.iqr;\n if (base === undefined || iqr === undefined || isNaN(iqr)) {\n return [];\n }\n const extra = iqr * multiple;\n return [base - extra, base + extra];\n }\n\n // Outer fences\n outer(): number[] {\n if (!this.data.outer) {\n this.median();\n this.iqr();\n this.data.outer = this.getOuter();\n }\n return this.data.outer;\n }\n\n private getOuter(multiple: number = DEFAULT_OUTLIER_MULTIPLE): number[] {\n const base = this.data.median;\n const iqr = this.data.iqr;\n if (base === undefined || iqr === undefined || isNaN(iqr)) {\n return [];\n }\n const extra = 2 * iqr * multiple;\n return [base - extra, base + extra];\n }\n\n // Outside values\n outside(): number[] {\n if (!this.data.outside) {\n this.outer();\n this.data.outside = this.getOutside();\n }\n return this.data.outside;\n }\n\n private getOutside(): number[] {\n const results: number[] = [];\n const sorted = this.data.sorted!;\n const outer = this.data.outer;\n if (!outer || outer.length === 0) return [];\n const min = Math.min(...outer);\n const max = Math.max(...outer);\n for (const num of sorted) {\n if (num > max || num < min) {\n results.push(num);\n }\n }\n return results;\n }\n\n // Inside values\n inside(): number[] {\n if (!this.data.inside) {\n this.fences();\n this.data.inside = this.getInside();\n }\n return this.data.inside;\n }\n\n private getInside(): number[] {\n const results: number[] = [];\n const sorted = this.data.sorted!;\n const fences = this.data.fences;\n if (!fences || fences.length === 0) return [];\n const min = Math.min(...fences);\n const max = Math.max(...fences);\n for (const num of sorted) {\n if (num < max && num > min) {\n results.push(num);\n }\n }\n return results;\n }\n\n // Outliers\n outliers(): number[] {\n if (!this.data.outliers) {\n this.fences();\n this.data.outliers = this.getOutliers();\n }\n return this.data.outliers;\n }\n\n private getOutliers(): number[] {\n const results: number[] = [];\n const sorted = this.data.sorted!;\n const fences = this.data.fences!;\n if (fences.length === 0) return [];\n const min = Math.min(...fences);\n const max = Math.max(...fences);\n for (const num of sorted) {\n if (num > max || num < min) {\n results.push(num);\n }\n }\n return results;\n }\n\n // Ranked\n ranked(): RankedResult {\n if (!this.data.ranked) {\n this.sorted();\n this.data.ranked = this.getRanked(this.data.sorted!);\n }\n return this.data.ranked;\n }\n\n private getRanked(arr: number[], ties: boolean = true): RankedResult {\n const up: Record<number, RankInfo> = {};\n const down: Record<number, RankInfo> = {};\n const total = arr.length;\n const ranked: (number | number[])[] = [];\n\n let tiedRank = NaN;\n let tiedNumbers: number[] = [];\n\n const reset = () => {\n tiedRank = NaN;\n tiedNumbers = [];\n };\n\n for (let i = 0; i < arr.length; i++) {\n const num = arr[i];\n\n if (!ties) {\n up[num] = { rank: i + 1, peers: 0 };\n down[num] = { rank: total - i, peers: 0 };\n } else {\n const incr = i + 1;\n const decr = i - 1;\n\n if (num === arr[decr]) {\n if (!isNaN(tiedRank) && tiedNumbers.length === 0) {\n tiedNumbers.push(num);\n ranked.push(tiedNumbers);\n reset();\n } else {\n tiedNumbers.push(num);\n tiedRank = decr;\n }\n if (num !== arr[incr]) {\n ranked.push(tiedNumbers);\n reset();\n }\n } else {\n if (num !== arr[incr]) {\n if (tiedNumbers.length > 0) {\n ranked.push(tiedNumbers);\n reset();\n } else {\n ranked.push(num);\n }\n } else {\n tiedNumbers.push(num);\n }\n }\n }\n }\n\n let offset = 0;\n for (let i = 0; i < ranked.length; i++) {\n const item = ranked[i];\n if (typeof item === 'number') {\n down[item] = { rank: i + 1 + offset, peers: 0 };\n up[item] = { rank: total - i - offset, peers: 0 };\n } else if (Array.isArray(item)) {\n offset += item.length;\n const usable = item[0];\n down[usable] = { rank: i + 1 + offset, peers: item.length };\n up[usable] = { rank: total - i - offset, peers: item.length };\n } else {\n offset += 1;\n }\n }\n\n return {\n up,\n down,\n groups: {\n down: [...ranked],\n up: [...ranked].reverse(),\n },\n };\n }\n\n // Adjacent\n adjacent(): number[] {\n if (!this.data.adjacent) {\n this.fences();\n this.data.adjacent = this.getAdjacent(this.data.sorted!, this.data.fences!);\n }\n return this.data.adjacent;\n }\n\n private getAdjacent(arr: number[], fences: number[]): number[] {\n if (fences.length === 0) return [];\n\n const low = fences[0];\n const lows: number[] = [];\n const high = fences[1];\n const highs: number[] = [];\n\n for (const val of arr) {\n if (val > low) lows.push(val);\n if (val < high) highs.push(val);\n }\n\n lows.sort((a, b) => a - b);\n highs.sort((a, b) => a - b);\n\n return [lows[0], highs[highs.length - 1]];\n }\n\n // Binned\n binned(bins: number = NaN): BinnedResult {\n if (!this.data.binned) {\n this.sorted();\n this.extremes();\n this.data.binned = this.getBinned(this.data.sorted!, bins);\n }\n return this.data.binned;\n }\n\n private getBinned(\n arr: number[],\n bins: number = 10,\n width: number = NaN,\n includeZero: boolean = true\n ): BinnedResult {\n const binned: Record<number, { from: number; to: number; data: number[] }> = {};\n const total = arr.length;\n const zeroOffset = includeZero ? 0 : 1;\n\n if (total === 0) {\n return { bins: 0, width: NaN, binned: {} };\n }\n\n const extremes = this.data.extremes!;\n let calculatedWidth = width;\n\n if (extremes && isNaN(calculatedWidth) && extremes.length === 2) {\n calculatedWidth = (extremes[1] - extremes[0]) / (Math.log(arr.length) / Math.LN2);\n calculatedWidth = Math.floor(calculatedWidth);\n\n let areIntegers = true;\n for (const item of arr) {\n if (item % 1 !== 0) {\n areIntegers = false;\n break;\n }\n }\n if (areIntegers) {\n calculatedWidth = Math.floor(calculatedWidth);\n }\n }\n\n let binCount = Math.floor(extremes[1] / calculatedWidth) + 1;\n if (!binCount || binCount < 1) {\n binCount = 1;\n }\n\n for (const val of arr) {\n const bin = Math.floor((val - zeroOffset) / calculatedWidth);\n if (!binned[bin]) {\n binned[bin] = {\n from: bin * calculatedWidth + zeroOffset,\n to: (bin + 1) * calculatedWidth + zeroOffset - 1,\n data: [],\n };\n }\n binned[bin].data.push(val);\n }\n\n return {\n bins: binCount,\n width: calculatedWidth,\n binned,\n };\n }\n\n // Transforms\n logs(): number[] {\n if (!this.data.logs) {\n this.data.logs = this.getLogs(this.data.original);\n }\n return this.data.logs;\n }\n\n private getLogs(arr: number[]): number[] {\n return arr.map((val) => Math.log(val));\n }\n\n roots(): number[] {\n if (!this.data.roots) {\n this.data.roots = this.getRoots(this.data.original);\n }\n return this.data.roots;\n }\n\n private getRoots(arr: number[]): number[] {\n return arr.map((val) => Math.sqrt(val));\n }\n\n inverse(): number[] {\n if (!this.data.inverse) {\n this.data.inverse = this.getInverse(this.data.original);\n }\n return this.data.inverse;\n }\n\n private getInverse(arr: number[]): number[] {\n return arr.map((val) => 1 / val);\n }\n\n // Smoothing\n hanning(): number[] {\n if (!this.data.hanning) {\n this.data.hanning = this.getSkipMeans(this.data.original);\n }\n return this.data.hanning;\n }\n\n private getSkipMeans(arr: number[]): number[] {\n const results: number[] = [];\n for (let i = 0; i < arr.length; i++) {\n if (i !== 0 && i !== arr.length - 1) {\n results.push((arr[i] + arr[i + 1]) / 2);\n }\n }\n results.unshift(arr[0]);\n results.push(arr[arr.length - 1]);\n return results;\n }\n\n smooth(): number[] {\n if (!this.data.smooth) {\n this.sorted();\n this.data.smooth = this.getSmooth(this.data.original);\n }\n this.data.rough = this.getRough(this.data.original, this.data.smooth);\n return this.data.smooth;\n }\n\n private getRough(original: number[], smoothed: number[]): number[] {\n const residuals: number[] = [];\n for (let x = 0; x < original.length; x++) {\n residuals.push(original[x] - smoothed[x]);\n }\n return residuals;\n }\n\n private getSmooth(arr: number[], passes: number = 3): number[] {\n let smoothed = [...arr];\n smoothed = this.smoothMedian(smoothed, passes);\n smoothed = this.smoothExtremes(smoothed, -1);\n smoothed = this.smoothSplit(smoothed, 2);\n smoothed = this.smoothMedian(smoothed, passes);\n smoothed = this.smoothExtremes(smoothed, -1);\n smoothed = this.smoothMedian(smoothed, passes);\n return smoothed;\n }\n\n private smoothExtremes(\n arr: number[],\n passes: number = 1,\n current: number = 0,\n end: 'both' | 'head' | 'tail' = 'both'\n ): number[] {\n const len = arr.length;\n if (len <= 2) return [...arr];\n\n const result = [...arr];\n\n for (let pass = current; pass < passes || passes === -1; pass++) {\n let changed = false;\n\n if (end === 'both' || end === 'head') {\n const first = result[0];\n const second = result[1];\n const third = result[2];\n const tmp = second - 2 * (third - second);\n // Median of three: sort and pick middle\n const median =\n first <= second\n ? second <= tmp\n ? second\n : first <= tmp\n ? tmp\n : first\n : first <= tmp\n ? first\n : second <= tmp\n ? tmp\n : second;\n if (result[0] !== median) {\n result[0] = median;\n changed = true;\n }\n }\n\n if (end === 'both' || end === 'tail') {\n const antepenultimate = result[len - 3];\n const penultimate = result[len - 2];\n const last = result[len - 1];\n const tmp = penultimate - 2 * (antepenultimate - penultimate);\n const median =\n last <= penultimate\n ? penultimate <= tmp\n ? penultimate\n : last <= tmp\n ? tmp\n : last\n : last <= tmp\n ? last\n : penultimate <= tmp\n ? tmp\n : penultimate;\n if (result[len - 1] !== median) {\n result[len - 1] = median;\n changed = true;\n }\n }\n\n if (passes === -1 && !changed) {\n break;\n }\n }\n return result;\n }\n\n private smoothSplit(\n arr: number[],\n passes: number = DEFAULT_SPLIT_PASSES,\n current: number = 0\n ): number[] {\n let result = [...arr];\n const len = arr.length;\n\n for (let pass = current; pass < passes || passes === -1; pass++) {\n let changed = false;\n\n for (let i = 2; i < len - 1; i++) {\n const num = result[i];\n const t1 = result[i - 1];\n const t2 = result[i - 2];\n const f1 = result[i + 1];\n\n if (num === t1 && ((t1 > t2 && num > f1) || (t1 < t2 && num < f1))) {\n // Apply smoothExtremes at split point in-place\n const left = this.smoothExtremes(result.slice(0, i));\n const right = this.smoothExtremes(result.slice(i));\n result = left.concat(right);\n changed = true;\n }\n }\n\n if (passes === -1 && !changed) {\n return result;\n }\n }\n return result;\n }\n\n private smoothMedian(arr: number[], passes: number = 1, current: number = 0): number[] {\n let result = arr;\n const len = arr.length;\n if (len <= 2) return [...arr];\n\n for (let pass = current; pass < passes || passes === -1; pass++) {\n const next = new Array<number>(len);\n next[0] = result[0];\n next[len - 1] = result[len - 1];\n\n let changed = false;\n for (let i = 1; i < len - 1; i++) {\n const val = result[i];\n const smoothed = Math.min(Math.max(result[i - 1], val), result[i + 1]);\n next[i] = smoothed;\n if (smoothed !== val) changed = true;\n }\n\n if (passes === -1 && !changed) {\n return result;\n }\n result = next;\n }\n return result;\n }\n\n private jitter(\n arr: number[],\n passes: number = 1,\n floor: number = NaN,\n multiplier: number = DEFAULT_JITTER_MULTIPLIER,\n weight: number = NaN,\n current: number = 0\n ): number[] {\n const nextCurrent = current + 1;\n const copy = [...arr];\n\n if (nextCurrent <= passes) {\n const jittered: number[] = [];\n for (const num of copy) {\n let w = weight;\n if (!w && !isNaN(w)) {\n w = (1 + Math.floor(num / 10)) * (Math.random() > 0.5 ? 1 : -1);\n }\n let value = num + Math.floor(Math.random() * multiplier * w);\n if (!isNaN(floor) && value < floor) {\n value = floor;\n }\n jittered.push(value);\n }\n return this.jitter(jittered, passes, floor, multiplier, weight, nextCurrent);\n }\n return copy;\n }\n\n // Trimean (Tukey's trimean: (Q1 + 2*median + Q3) / 4)\n trimean(): number {\n const med = this.median();\n const h = this.hinges();\n if (h.length < 2) return med.datum;\n return (h[0].datum + 2 * med.datum + h[1].datum) / 4;\n }\n\n // Letter values (depth-based summaries beyond hinges)\n letterValues(): Array<{ letter: string; depth: number; lower: number; upper: number; mid: number; spread: number }> {\n this.sorted();\n const n = this.data.sorted!.length;\n if (n < 2) return [];\n\n const letters = ['M', 'F', 'E', 'D', 'C', 'B', 'A', 'Z', 'Y', 'X', 'W', 'V', 'U', 'T', 'S'];\n const results: Array<{ letter: string; depth: number; lower: number; upper: number; mid: number; spread: number }> = [];\n\n // M = median\n const medDepth = (n + 1) / 2;\n const medValue = this.median().datum;\n results.push({\n letter: 'M',\n depth: medDepth,\n lower: medValue,\n upper: medValue,\n mid: medValue,\n spread: 0,\n });\n\n // Subsequent letter values\n let depth = medDepth;\n let letterIdx = 1;\n\n while (depth > 1 && letterIdx < letters.length) {\n depth = Math.floor((Math.floor(depth) + 1) / 2);\n if (depth < 1) break;\n\n const lowerIdx = Math.ceil(depth) - 1;\n const upperIdx = n - Math.ceil(depth);\n\n if (lowerIdx < 0 || upperIdx >= n || lowerIdx >= upperIdx) break;\n\n const lower = this.data.sorted![lowerIdx];\n const upper = this.data.sorted![upperIdx];\n const mid = (lower + upper) / 2;\n const spread = upper - lower;\n\n results.push({\n letter: letters[letterIdx],\n depth,\n lower,\n upper,\n mid,\n spread,\n });\n\n letterIdx++;\n }\n\n return results;\n }\n\n // Rough (residuals: original - smooth)\n rough(): number[] {\n if (!this.data.rough) {\n this.smooth();\n }\n return this.data.rough || [];\n }\n\n // Stem-and-leaf display (text-based visualization)\n stemLeaf(leafDigits: number = 1): { stems: string[]; leaves: Record<string, string[]>; display: string[] } {\n this.sorted();\n const data = this.data.sorted!;\n if (!data.length) return { stems: [], leaves: {}, display: [] };\n\n const scale = Math.pow(10, leafDigits);\n const stems = new Map<number, number[]>();\n\n for (const val of data) {\n const stem = Math.floor(val / scale);\n const leaf = Math.abs(Math.round(val % scale));\n if (!stems.has(stem)) {\n stems.set(stem, []);\n }\n stems.get(stem)!.push(leaf);\n }\n\n const sortedStems = Array.from(stems.keys()).sort((a, b) => a - b);\n const stemStrings: string[] = [];\n const leavesRecord: Record<string, string[]> = {};\n const display: string[] = [];\n\n for (const stem of sortedStems) {\n const stemStr = String(stem);\n stemStrings.push(stemStr);\n const leaves = stems.get(stem)!.sort((a, b) => a - b).map(String);\n leavesRecord[stemStr] = leaves;\n display.push(`${stemStr.padStart(4)} | ${leaves.join(' ')}`);\n }\n\n return { stems: stemStrings, leaves: leavesRecord, display };\n }\n\n // Mid-summaries (averages of symmetric quantile pairs)\n midSummaries(): Array<{ depth: number; mid: number; spread: number }> {\n const lv = this.letterValues();\n return lv.map(({ depth, mid, spread }) => ({ depth, mid, spread }));\n }\n\n // Describe - full summary\n describe(): SeriesDescription {\n this.data.description = {\n original: this.data.original,\n summary: {\n median: this.median(),\n mean: this.mean(),\n mode: this.mode(),\n hinges: this.hinges(),\n adjacent: this.adjacent(),\n outliers: this.outliers(),\n outer: this.outer(),\n outside: this.outside(),\n inside: this.inside(),\n extremes: this.extremes(),\n iqr: this.iqr(),\n fences: this.fences(),\n },\n smooths: {\n smooth: this.smooth(),\n hanning: this.hanning(),\n },\n transforms: {\n logs: this.logs(),\n roots: this.roots(),\n inverse: this.inverse(),\n },\n counts: this.counts(),\n sorted: this.sorted(),\n ranked: this.ranked(),\n binned: this.binned(),\n };\n return this.data.description;\n }\n}\n\n/**\n * Points class for n-dimensional data exploration\n */\nexport class Points {\n private data: {\n original: number[][];\n description?: PointsDescription;\n };\n private dimension: number;\n private count: number;\n\n constructor(options: PointsOptions | number = {}) {\n if (typeof options === 'number') {\n this.count = options;\n this.dimension = DEFAULT_MAX_RANDOM_DIMENSIONALITY;\n this.data = {\n original: randomPoints(this.count, this.dimension),\n };\n } else {\n this.dimension = options.dimensionality ?? 2;\n this.count = options.count ?? 100;\n this.data = {\n original: options.data ?? randomPoints(this.count, this.dimension),\n };\n }\n }\n\n describe(): PointsDescription {\n this.data.description = {\n original: this.data.original,\n };\n return this.data.description;\n }\n}\n\n/**\n * Main Twokeys class - factory for Series and Points\n */\nexport class Twokeys {\n public smoothed: boolean = false;\n\n // Constants\n static readonly DEFAULT_MAX_RANDOM_INTEGER = DEFAULT_MAX_RANDOM_INTEGER;\n static readonly DEFAULT_MIN_RANDOM_INTEGER = DEFAULT_MIN_RANDOM_INTEGER;\n static readonly DEFAULT_RANDOM_SERIES_COUNT = DEFAULT_RANDOM_SERIES_COUNT;\n static readonly DEFAULT_OUTLIER_MULTIPLE = DEFAULT_OUTLIER_MULTIPLE;\n static readonly DEFAULT_JITTER_MULTIPLIER = DEFAULT_JITTER_MULTIPLIER;\n static readonly DEFAULT_SPLIT_PASSES = DEFAULT_SPLIT_PASSES;\n static readonly DEFAULT_MAX_RANDOM_DIMENSIONALITY = DEFAULT_MAX_RANDOM_DIMENSIONALITY;\n\n // Static factory methods\n static Series = Series;\n static Points = Points;\n\n // Utility methods\n static randomInteger = randomInteger;\n static randomSeries = randomSeries;\n static randomPoint = randomPoint;\n static randomPoints = randomPoints;\n}\n\n// Default export\nexport default Twokeys;\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Twokeys - A small data exploration and manipulation library
|
|
3
|
+
* Named after John Tukey, pioneer of exploratory data analysis (EDA)
|
|
4
|
+
*
|
|
5
|
+
* Features:
|
|
6
|
+
* - Summary statistics (mean, median, mode, quartiles)
|
|
7
|
+
* - Binning (histogram-like grouping)
|
|
8
|
+
* - Smoothing (Hanning filter and median smoothing)
|
|
9
|
+
* - Ranking and ranking analysis
|
|
10
|
+
* - Outlier detection (using Tukey fences)
|
|
11
|
+
* - Data transforms (logarithms, roots, inverses)
|
|
12
|
+
*/
|
|
13
|
+
interface SeriesOptions {
|
|
14
|
+
data?: number[];
|
|
15
|
+
}
|
|
16
|
+
interface PointsOptions {
|
|
17
|
+
data?: number[][];
|
|
18
|
+
dimensionality?: number;
|
|
19
|
+
count?: number;
|
|
20
|
+
}
|
|
21
|
+
interface MedianResult {
|
|
22
|
+
datum: number;
|
|
23
|
+
depth: number;
|
|
24
|
+
}
|
|
25
|
+
interface ModeResult {
|
|
26
|
+
count: number;
|
|
27
|
+
data: number[];
|
|
28
|
+
}
|
|
29
|
+
interface RankInfo {
|
|
30
|
+
rank: number;
|
|
31
|
+
peers: number;
|
|
32
|
+
}
|
|
33
|
+
interface RankedResult {
|
|
34
|
+
up: Record<number, RankInfo>;
|
|
35
|
+
down: Record<number, RankInfo>;
|
|
36
|
+
groups: {
|
|
37
|
+
up: (number | number[])[];
|
|
38
|
+
down: (number | number[])[];
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
interface BinnedResult {
|
|
42
|
+
bins: number;
|
|
43
|
+
width: number;
|
|
44
|
+
binned: Record<number, {
|
|
45
|
+
from: number;
|
|
46
|
+
to: number;
|
|
47
|
+
data: number[];
|
|
48
|
+
}>;
|
|
49
|
+
}
|
|
50
|
+
interface SeriesDescription {
|
|
51
|
+
original: number[];
|
|
52
|
+
summary: {
|
|
53
|
+
median: MedianResult;
|
|
54
|
+
mean: number;
|
|
55
|
+
mode: ModeResult;
|
|
56
|
+
hinges: MedianResult[];
|
|
57
|
+
adjacent: number[];
|
|
58
|
+
outliers: number[];
|
|
59
|
+
outer: number[];
|
|
60
|
+
outside: number[];
|
|
61
|
+
inside: number[];
|
|
62
|
+
extremes: number[];
|
|
63
|
+
iqr: number;
|
|
64
|
+
fences: number[];
|
|
65
|
+
};
|
|
66
|
+
smooths: {
|
|
67
|
+
smooth: number[];
|
|
68
|
+
hanning: number[];
|
|
69
|
+
};
|
|
70
|
+
transforms: {
|
|
71
|
+
logs: number[];
|
|
72
|
+
roots: number[];
|
|
73
|
+
inverse: number[];
|
|
74
|
+
};
|
|
75
|
+
counts: [number, number][];
|
|
76
|
+
sorted: number[];
|
|
77
|
+
ranked: RankedResult;
|
|
78
|
+
binned: BinnedResult;
|
|
79
|
+
}
|
|
80
|
+
interface PointsDescription {
|
|
81
|
+
original: number[][];
|
|
82
|
+
}
|
|
83
|
+
declare function randomInteger(max?: number): number;
|
|
84
|
+
declare function randomSeries(count?: number, max?: number): number[];
|
|
85
|
+
declare function randomPoint(dimension?: number, max?: number): number[];
|
|
86
|
+
declare function randomPoints(count?: number, dimension?: number, max?: number): number[][];
|
|
87
|
+
/**
|
|
88
|
+
* Series class for 1D data exploration
|
|
89
|
+
*/
|
|
90
|
+
declare class Series {
|
|
91
|
+
private data;
|
|
92
|
+
constructor(options?: SeriesOptions);
|
|
93
|
+
sorted(): number[];
|
|
94
|
+
private getSorted;
|
|
95
|
+
median(): MedianResult;
|
|
96
|
+
private getMedianDepth;
|
|
97
|
+
private getMedian;
|
|
98
|
+
mean(): number;
|
|
99
|
+
private getMean;
|
|
100
|
+
mode(): ModeResult;
|
|
101
|
+
private getMode;
|
|
102
|
+
extremes(): number[];
|
|
103
|
+
private getExtremes;
|
|
104
|
+
counts(): [number, number][];
|
|
105
|
+
private getCounts;
|
|
106
|
+
hinges(): MedianResult[];
|
|
107
|
+
private getHinges;
|
|
108
|
+
iqr(): number;
|
|
109
|
+
private getIQR;
|
|
110
|
+
fences(): number[];
|
|
111
|
+
private getFences;
|
|
112
|
+
outer(): number[];
|
|
113
|
+
private getOuter;
|
|
114
|
+
outside(): number[];
|
|
115
|
+
private getOutside;
|
|
116
|
+
inside(): number[];
|
|
117
|
+
private getInside;
|
|
118
|
+
outliers(): number[];
|
|
119
|
+
private getOutliers;
|
|
120
|
+
ranked(): RankedResult;
|
|
121
|
+
private getRanked;
|
|
122
|
+
adjacent(): number[];
|
|
123
|
+
private getAdjacent;
|
|
124
|
+
binned(bins?: number): BinnedResult;
|
|
125
|
+
private getBinned;
|
|
126
|
+
logs(): number[];
|
|
127
|
+
private getLogs;
|
|
128
|
+
roots(): number[];
|
|
129
|
+
private getRoots;
|
|
130
|
+
inverse(): number[];
|
|
131
|
+
private getInverse;
|
|
132
|
+
hanning(): number[];
|
|
133
|
+
private getSkipMeans;
|
|
134
|
+
smooth(): number[];
|
|
135
|
+
private getRough;
|
|
136
|
+
private getSmooth;
|
|
137
|
+
private smoothExtremes;
|
|
138
|
+
private smoothSplit;
|
|
139
|
+
private smoothMedian;
|
|
140
|
+
private jitter;
|
|
141
|
+
trimean(): number;
|
|
142
|
+
letterValues(): Array<{
|
|
143
|
+
letter: string;
|
|
144
|
+
depth: number;
|
|
145
|
+
lower: number;
|
|
146
|
+
upper: number;
|
|
147
|
+
mid: number;
|
|
148
|
+
spread: number;
|
|
149
|
+
}>;
|
|
150
|
+
rough(): number[];
|
|
151
|
+
stemLeaf(leafDigits?: number): {
|
|
152
|
+
stems: string[];
|
|
153
|
+
leaves: Record<string, string[]>;
|
|
154
|
+
display: string[];
|
|
155
|
+
};
|
|
156
|
+
midSummaries(): Array<{
|
|
157
|
+
depth: number;
|
|
158
|
+
mid: number;
|
|
159
|
+
spread: number;
|
|
160
|
+
}>;
|
|
161
|
+
describe(): SeriesDescription;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Points class for n-dimensional data exploration
|
|
165
|
+
*/
|
|
166
|
+
declare class Points {
|
|
167
|
+
private data;
|
|
168
|
+
private dimension;
|
|
169
|
+
private count;
|
|
170
|
+
constructor(options?: PointsOptions | number);
|
|
171
|
+
describe(): PointsDescription;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Main Twokeys class - factory for Series and Points
|
|
175
|
+
*/
|
|
176
|
+
declare class Twokeys {
|
|
177
|
+
smoothed: boolean;
|
|
178
|
+
static readonly DEFAULT_MAX_RANDOM_INTEGER = 100;
|
|
179
|
+
static readonly DEFAULT_MIN_RANDOM_INTEGER = 0;
|
|
180
|
+
static readonly DEFAULT_RANDOM_SERIES_COUNT = 1000;
|
|
181
|
+
static readonly DEFAULT_OUTLIER_MULTIPLE = 1.5;
|
|
182
|
+
static readonly DEFAULT_JITTER_MULTIPLIER = 1;
|
|
183
|
+
static readonly DEFAULT_SPLIT_PASSES = 2;
|
|
184
|
+
static readonly DEFAULT_MAX_RANDOM_DIMENSIONALITY = 2;
|
|
185
|
+
static Series: typeof Series;
|
|
186
|
+
static Points: typeof Points;
|
|
187
|
+
static randomInteger: typeof randomInteger;
|
|
188
|
+
static randomSeries: typeof randomSeries;
|
|
189
|
+
static randomPoint: typeof randomPoint;
|
|
190
|
+
static randomPoints: typeof randomPoints;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export { type BinnedResult, type MedianResult, type ModeResult, Points, type PointsDescription, type PointsOptions, type RankInfo, type RankedResult, Series, type SeriesDescription, type SeriesOptions, Twokeys, Twokeys as default };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Twokeys - A small data exploration and manipulation library
|
|
3
|
+
* Named after John Tukey, pioneer of exploratory data analysis (EDA)
|
|
4
|
+
*
|
|
5
|
+
* Features:
|
|
6
|
+
* - Summary statistics (mean, median, mode, quartiles)
|
|
7
|
+
* - Binning (histogram-like grouping)
|
|
8
|
+
* - Smoothing (Hanning filter and median smoothing)
|
|
9
|
+
* - Ranking and ranking analysis
|
|
10
|
+
* - Outlier detection (using Tukey fences)
|
|
11
|
+
* - Data transforms (logarithms, roots, inverses)
|
|
12
|
+
*/
|
|
13
|
+
interface SeriesOptions {
|
|
14
|
+
data?: number[];
|
|
15
|
+
}
|
|
16
|
+
interface PointsOptions {
|
|
17
|
+
data?: number[][];
|
|
18
|
+
dimensionality?: number;
|
|
19
|
+
count?: number;
|
|
20
|
+
}
|
|
21
|
+
interface MedianResult {
|
|
22
|
+
datum: number;
|
|
23
|
+
depth: number;
|
|
24
|
+
}
|
|
25
|
+
interface ModeResult {
|
|
26
|
+
count: number;
|
|
27
|
+
data: number[];
|
|
28
|
+
}
|
|
29
|
+
interface RankInfo {
|
|
30
|
+
rank: number;
|
|
31
|
+
peers: number;
|
|
32
|
+
}
|
|
33
|
+
interface RankedResult {
|
|
34
|
+
up: Record<number, RankInfo>;
|
|
35
|
+
down: Record<number, RankInfo>;
|
|
36
|
+
groups: {
|
|
37
|
+
up: (number | number[])[];
|
|
38
|
+
down: (number | number[])[];
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
interface BinnedResult {
|
|
42
|
+
bins: number;
|
|
43
|
+
width: number;
|
|
44
|
+
binned: Record<number, {
|
|
45
|
+
from: number;
|
|
46
|
+
to: number;
|
|
47
|
+
data: number[];
|
|
48
|
+
}>;
|
|
49
|
+
}
|
|
50
|
+
interface SeriesDescription {
|
|
51
|
+
original: number[];
|
|
52
|
+
summary: {
|
|
53
|
+
median: MedianResult;
|
|
54
|
+
mean: number;
|
|
55
|
+
mode: ModeResult;
|
|
56
|
+
hinges: MedianResult[];
|
|
57
|
+
adjacent: number[];
|
|
58
|
+
outliers: number[];
|
|
59
|
+
outer: number[];
|
|
60
|
+
outside: number[];
|
|
61
|
+
inside: number[];
|
|
62
|
+
extremes: number[];
|
|
63
|
+
iqr: number;
|
|
64
|
+
fences: number[];
|
|
65
|
+
};
|
|
66
|
+
smooths: {
|
|
67
|
+
smooth: number[];
|
|
68
|
+
hanning: number[];
|
|
69
|
+
};
|
|
70
|
+
transforms: {
|
|
71
|
+
logs: number[];
|
|
72
|
+
roots: number[];
|
|
73
|
+
inverse: number[];
|
|
74
|
+
};
|
|
75
|
+
counts: [number, number][];
|
|
76
|
+
sorted: number[];
|
|
77
|
+
ranked: RankedResult;
|
|
78
|
+
binned: BinnedResult;
|
|
79
|
+
}
|
|
80
|
+
interface PointsDescription {
|
|
81
|
+
original: number[][];
|
|
82
|
+
}
|
|
83
|
+
declare function randomInteger(max?: number): number;
|
|
84
|
+
declare function randomSeries(count?: number, max?: number): number[];
|
|
85
|
+
declare function randomPoint(dimension?: number, max?: number): number[];
|
|
86
|
+
declare function randomPoints(count?: number, dimension?: number, max?: number): number[][];
|
|
87
|
+
/**
|
|
88
|
+
* Series class for 1D data exploration
|
|
89
|
+
*/
|
|
90
|
+
declare class Series {
|
|
91
|
+
private data;
|
|
92
|
+
constructor(options?: SeriesOptions);
|
|
93
|
+
sorted(): number[];
|
|
94
|
+
private getSorted;
|
|
95
|
+
median(): MedianResult;
|
|
96
|
+
private getMedianDepth;
|
|
97
|
+
private getMedian;
|
|
98
|
+
mean(): number;
|
|
99
|
+
private getMean;
|
|
100
|
+
mode(): ModeResult;
|
|
101
|
+
private getMode;
|
|
102
|
+
extremes(): number[];
|
|
103
|
+
private getExtremes;
|
|
104
|
+
counts(): [number, number][];
|
|
105
|
+
private getCounts;
|
|
106
|
+
hinges(): MedianResult[];
|
|
107
|
+
private getHinges;
|
|
108
|
+
iqr(): number;
|
|
109
|
+
private getIQR;
|
|
110
|
+
fences(): number[];
|
|
111
|
+
private getFences;
|
|
112
|
+
outer(): number[];
|
|
113
|
+
private getOuter;
|
|
114
|
+
outside(): number[];
|
|
115
|
+
private getOutside;
|
|
116
|
+
inside(): number[];
|
|
117
|
+
private getInside;
|
|
118
|
+
outliers(): number[];
|
|
119
|
+
private getOutliers;
|
|
120
|
+
ranked(): RankedResult;
|
|
121
|
+
private getRanked;
|
|
122
|
+
adjacent(): number[];
|
|
123
|
+
private getAdjacent;
|
|
124
|
+
binned(bins?: number): BinnedResult;
|
|
125
|
+
private getBinned;
|
|
126
|
+
logs(): number[];
|
|
127
|
+
private getLogs;
|
|
128
|
+
roots(): number[];
|
|
129
|
+
private getRoots;
|
|
130
|
+
inverse(): number[];
|
|
131
|
+
private getInverse;
|
|
132
|
+
hanning(): number[];
|
|
133
|
+
private getSkipMeans;
|
|
134
|
+
smooth(): number[];
|
|
135
|
+
private getRough;
|
|
136
|
+
private getSmooth;
|
|
137
|
+
private smoothExtremes;
|
|
138
|
+
private smoothSplit;
|
|
139
|
+
private smoothMedian;
|
|
140
|
+
private jitter;
|
|
141
|
+
trimean(): number;
|
|
142
|
+
letterValues(): Array<{
|
|
143
|
+
letter: string;
|
|
144
|
+
depth: number;
|
|
145
|
+
lower: number;
|
|
146
|
+
upper: number;
|
|
147
|
+
mid: number;
|
|
148
|
+
spread: number;
|
|
149
|
+
}>;
|
|
150
|
+
rough(): number[];
|
|
151
|
+
stemLeaf(leafDigits?: number): {
|
|
152
|
+
stems: string[];
|
|
153
|
+
leaves: Record<string, string[]>;
|
|
154
|
+
display: string[];
|
|
155
|
+
};
|
|
156
|
+
midSummaries(): Array<{
|
|
157
|
+
depth: number;
|
|
158
|
+
mid: number;
|
|
159
|
+
spread: number;
|
|
160
|
+
}>;
|
|
161
|
+
describe(): SeriesDescription;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Points class for n-dimensional data exploration
|
|
165
|
+
*/
|
|
166
|
+
declare class Points {
|
|
167
|
+
private data;
|
|
168
|
+
private dimension;
|
|
169
|
+
private count;
|
|
170
|
+
constructor(options?: PointsOptions | number);
|
|
171
|
+
describe(): PointsDescription;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Main Twokeys class - factory for Series and Points
|
|
175
|
+
*/
|
|
176
|
+
declare class Twokeys {
|
|
177
|
+
smoothed: boolean;
|
|
178
|
+
static readonly DEFAULT_MAX_RANDOM_INTEGER = 100;
|
|
179
|
+
static readonly DEFAULT_MIN_RANDOM_INTEGER = 0;
|
|
180
|
+
static readonly DEFAULT_RANDOM_SERIES_COUNT = 1000;
|
|
181
|
+
static readonly DEFAULT_OUTLIER_MULTIPLE = 1.5;
|
|
182
|
+
static readonly DEFAULT_JITTER_MULTIPLIER = 1;
|
|
183
|
+
static readonly DEFAULT_SPLIT_PASSES = 2;
|
|
184
|
+
static readonly DEFAULT_MAX_RANDOM_DIMENSIONALITY = 2;
|
|
185
|
+
static Series: typeof Series;
|
|
186
|
+
static Points: typeof Points;
|
|
187
|
+
static randomInteger: typeof randomInteger;
|
|
188
|
+
static randomSeries: typeof randomSeries;
|
|
189
|
+
static randomPoint: typeof randomPoint;
|
|
190
|
+
static randomPoints: typeof randomPoints;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export { type BinnedResult, type MedianResult, type ModeResult, Points, type PointsDescription, type PointsOptions, type RankInfo, type RankedResult, Series, type SeriesDescription, type SeriesOptions, Twokeys, Twokeys as default };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
function R(b=100){return Math.floor(Math.random()*b)}function E(b=1e3,t=100){let n=[];for(let e=0;e<b;e++)n.push(R(t));return n}function _(b=2,t=100){let n=[];for(let e=0;e<b;e++)n.push(Math.floor(Math.random()*(t/10)%t));return n}function f(b=1e3,t=2,n=100){let e=[];for(let r=0;r<b;r++)e.push(_(t,n));return e}var g=class{data;constructor(t={}){this.data={original:t.data??E()};}sorted(){return this.data.sorted||(this.data.sorted=this.getSorted(this.data.original)),this.data.sorted}getSorted(t){return [...t].sort((n,e)=>n>e?1:n===e?0:-1)}median(){return this.sorted(),this.data.median===void 0&&(this.data.median=this.getMedian(this.data.sorted)),this.data.medianDepth===void 0&&(this.data.medianDepth=this.getMedianDepth(this.data.sorted)),{datum:this.data.median,depth:this.data.medianDepth}}getMedianDepth(t,n=0){return t.length?n+(t.length+1)/2:NaN}getMedian(t){let n=t.length;if(!n)return NaN;if(n===1)return t[0];let e=Math.floor(n/2);return n%2===0?(t[e-1]+t[e])/2:t[e]}mean(){return this.data.mean===void 0&&(this.data.mean=this.getMean(this.data.original)),this.data.mean}getMean(t){if(!t.length)return NaN;let n=0;for(let e of t)n+=e;return n/t.length}mode(){return this.data.mode||(this.sorted(),this.data.mode=this.getMode(this.data.sorted)),this.data.mode}getMode(t){if(!t.length)return {count:0,data:[]};let n={},e=0;for(let i of t)n[i]=(n[i]||0)+1,n[i]>e&&(e=n[i]);let r=[];for(let[i,s]of Object.entries(n))s===e&&r.push(Number(i));return {count:e,data:r.sort((i,s)=>i-s)}}extremes(){return this.data.extremes||(this.sorted(),this.data.extremes=this.getExtremes(this.data.sorted)),this.data.extremes}getExtremes(t){return t.length?[t[0],t[t.length-1]]:[]}counts(){return this.data.counts||(this.sorted(),this.data.counts=this.getCounts(this.data.sorted)),this.data.counts}getCounts(t){let n=new Map;for(let r of t)n.set(r,(n.get(r)||0)+1);let e=[];for(let[r,i]of n)e.push([r,i]);return e.sort((r,i)=>r[0]-i[0])}hinges(){return this.data.hinges||(this.sorted(),this.data.hinges=this.getHinges(this.data.sorted)),this.data.hinges}getHinges(t,n=2,e=[]){let r=[...t],i=r.length,s=n;if(s%2!==0&&s++,i<=s||s<=0)return e;let m=Math.floor(i/s),h=Math.floor(i/m)-1;for(let a=0;a<=h;a++){let o=r.slice(a*m,a*m+m);e.push({datum:this.getMedian(o),depth:this.getMedianDepth(o,a*m)});}return e}iqr(){return this.data.iqr===void 0&&(this.hinges(),this.data.iqr=this.getIQR(this.data.hinges)),this.data.iqr}getIQR(t){let n=t[0]?.datum,e=t[1]?.datum;return n===void 0||e===void 0?NaN:Math.abs(n-e)}fences(){return this.data.fences||(this.median(),this.iqr(),this.data.fences=this.getFences()),this.data.fences}getFences(t=1.5){let n=this.data.median,e=this.data.iqr;if(n===void 0||e===void 0||isNaN(e))return [];let r=e*t;return [n-r,n+r]}outer(){return this.data.outer||(this.median(),this.iqr(),this.data.outer=this.getOuter()),this.data.outer}getOuter(t=1.5){let n=this.data.median,e=this.data.iqr;if(n===void 0||e===void 0||isNaN(e))return [];let r=2*e*t;return [n-r,n+r]}outside(){return this.data.outside||(this.outer(),this.data.outside=this.getOutside()),this.data.outside}getOutside(){let t=[],n=this.data.sorted,e=this.data.outer;if(!e||e.length===0)return [];let r=Math.min(...e),i=Math.max(...e);for(let s of n)(s>i||s<r)&&t.push(s);return t}inside(){return this.data.inside||(this.fences(),this.data.inside=this.getInside()),this.data.inside}getInside(){let t=[],n=this.data.sorted,e=this.data.fences;if(!e||e.length===0)return [];let r=Math.min(...e),i=Math.max(...e);for(let s of n)s<i&&s>r&&t.push(s);return t}outliers(){return this.data.outliers||(this.fences(),this.data.outliers=this.getOutliers()),this.data.outliers}getOutliers(){let t=[],n=this.data.sorted,e=this.data.fences;if(e.length===0)return [];let r=Math.min(...e),i=Math.max(...e);for(let s of n)(s>i||s<r)&&t.push(s);return t}ranked(){return this.data.ranked||(this.sorted(),this.data.ranked=this.getRanked(this.data.sorted)),this.data.ranked}getRanked(t,n=true){let e={},r={},i=t.length,s=[],m=NaN,h=[],a=()=>{m=NaN,h=[];};for(let d=0;d<t.length;d++){let u=t[d];if(!n)e[u]={rank:d+1,peers:0},r[u]={rank:i-d,peers:0};else {let c=d+1,l=d-1;u===t[l]?(!isNaN(m)&&h.length===0?(h.push(u),s.push(h),a()):(h.push(u),m=l),u!==t[c]&&(s.push(h),a())):u!==t[c]?h.length>0?(s.push(h),a()):s.push(u):h.push(u);}}let o=0;for(let d=0;d<s.length;d++){let u=s[d];if(typeof u=="number")r[u]={rank:d+1+o,peers:0},e[u]={rank:i-d-o,peers:0};else if(Array.isArray(u)){o+=u.length;let c=u[0];r[c]={rank:d+1+o,peers:u.length},e[c]={rank:i-d-o,peers:u.length};}else o+=1;}return {up:e,down:r,groups:{down:[...s],up:[...s].reverse()}}}adjacent(){return this.data.adjacent||(this.fences(),this.data.adjacent=this.getAdjacent(this.data.sorted,this.data.fences)),this.data.adjacent}getAdjacent(t,n){if(n.length===0)return [];let e=n[0],r=[],i=n[1],s=[];for(let m of t)m>e&&r.push(m),m<i&&s.push(m);return r.sort((m,h)=>m-h),s.sort((m,h)=>m-h),[r[0],s[s.length-1]]}binned(t=NaN){return this.data.binned||(this.sorted(),this.extremes(),this.data.binned=this.getBinned(this.data.sorted,t)),this.data.binned}getBinned(t,n=10,e=NaN,r=true){let i={},s=t.length,m=r?0:1;if(s===0)return {bins:0,width:NaN,binned:{}};let h=this.data.extremes,a=e;if(h&&isNaN(a)&&h.length===2){a=(h[1]-h[0])/(Math.log(t.length)/Math.LN2),a=Math.floor(a);let d=true;for(let u of t)if(u%1!==0){d=false;break}d&&(a=Math.floor(a));}let o=Math.floor(h[1]/a)+1;(!o||o<1)&&(o=1);for(let d of t){let u=Math.floor((d-m)/a);i[u]||(i[u]={from:u*a+m,to:(u+1)*a+m-1,data:[]}),i[u].data.push(d);}return {bins:o,width:a,binned:i}}logs(){return this.data.logs||(this.data.logs=this.getLogs(this.data.original)),this.data.logs}getLogs(t){return t.map(n=>Math.log(n))}roots(){return this.data.roots||(this.data.roots=this.getRoots(this.data.original)),this.data.roots}getRoots(t){return t.map(n=>Math.sqrt(n))}inverse(){return this.data.inverse||(this.data.inverse=this.getInverse(this.data.original)),this.data.inverse}getInverse(t){return t.map(n=>1/n)}hanning(){return this.data.hanning||(this.data.hanning=this.getSkipMeans(this.data.original)),this.data.hanning}getSkipMeans(t){let n=[];for(let e=0;e<t.length;e++)e!==0&&e!==t.length-1&&n.push((t[e]+t[e+1])/2);return n.unshift(t[0]),n.push(t[t.length-1]),n}smooth(){return this.data.smooth||(this.sorted(),this.data.smooth=this.getSmooth(this.data.original)),this.data.rough=this.getRough(this.data.original,this.data.smooth),this.data.smooth}getRough(t,n){let e=[];for(let r=0;r<t.length;r++)e.push(t[r]-n[r]);return e}getSmooth(t,n=3){let e=[...t];return e=this.smoothMedian(e,n),e=this.smoothExtremes(e,-1),e=this.smoothSplit(e,2),e=this.smoothMedian(e,n),e=this.smoothExtremes(e,-1),e=this.smoothMedian(e,n),e}smoothExtremes(t,n=1,e=0,r="both"){let i=t.length;if(i<=2)return [...t];let s=[...t];for(let m=e;m<n||n===-1;m++){let h=false;if(r==="both"||r==="head"){let a=s[0],o=s[1],d=s[2],u=o-2*(d-o),c=a<=o?o<=u?o:a<=u?u:a:a<=u?a:o<=u?u:o;s[0]!==c&&(s[0]=c,h=true);}if(r==="both"||r==="tail"){let a=s[i-3],o=s[i-2],d=s[i-1],u=o-2*(a-o),c=d<=o?o<=u?o:d<=u?u:d:d<=u?d:o<=u?u:o;s[i-1]!==c&&(s[i-1]=c,h=true);}if(n===-1&&!h)break}return s}smoothSplit(t,n=2,e=0){let r=[...t],i=t.length;for(let s=e;s<n||n===-1;s++){let m=false;for(let h=2;h<i-1;h++){let a=r[h],o=r[h-1],d=r[h-2],u=r[h+1];if(a===o&&(o>d&&a>u||o<d&&a<u)){let c=this.smoothExtremes(r.slice(0,h)),l=this.smoothExtremes(r.slice(h));r=c.concat(l),m=true;}}if(n===-1&&!m)return r}return r}smoothMedian(t,n=1,e=0){let r=t,i=t.length;if(i<=2)return [...t];for(let s=e;s<n||n===-1;s++){let m=new Array(i);m[0]=r[0],m[i-1]=r[i-1];let h=false;for(let a=1;a<i-1;a++){let o=r[a],d=Math.min(Math.max(r[a-1],o),r[a+1]);m[a]=d,d!==o&&(h=true);}if(n===-1&&!h)return r;r=m;}return r}jitter(t,n=1,e=NaN,r=1,i=NaN,s=0){let m=s+1,h=[...t];if(m<=n){let a=[];for(let o of h){let d=i;!d&&!isNaN(d)&&(d=(1+Math.floor(o/10))*(Math.random()>.5?1:-1));let u=o+Math.floor(Math.random()*r*d);!isNaN(e)&&u<e&&(u=e),a.push(u);}return this.jitter(a,n,e,r,i,m)}return h}trimean(){let t=this.median(),n=this.hinges();return n.length<2?t.datum:(n[0].datum+2*t.datum+n[1].datum)/4}letterValues(){this.sorted();let t=this.data.sorted.length;if(t<2)return [];let n=["M","F","E","D","C","B","A","Z","Y","X","W","V","U","T","S"],e=[],r=(t+1)/2,i=this.median().datum;e.push({letter:"M",depth:r,lower:i,upper:i,mid:i,spread:0});let s=r,m=1;for(;s>1&&m<n.length&&(s=Math.floor((Math.floor(s)+1)/2),!(s<1));){let h=Math.ceil(s)-1,a=t-Math.ceil(s);if(h<0||a>=t||h>=a)break;let o=this.data.sorted[h],d=this.data.sorted[a],u=(o+d)/2,c=d-o;e.push({letter:n[m],depth:s,lower:o,upper:d,mid:u,spread:c}),m++;}return e}rough(){return this.data.rough||this.smooth(),this.data.rough||[]}stemLeaf(t=1){this.sorted();let n=this.data.sorted;if(!n.length)return {stems:[],leaves:{},display:[]};let e=Math.pow(10,t),r=new Map;for(let a of n){let o=Math.floor(a/e),d=Math.abs(Math.round(a%e));r.has(o)||r.set(o,[]),r.get(o).push(d);}let i=Array.from(r.keys()).sort((a,o)=>a-o),s=[],m={},h=[];for(let a of i){let o=String(a);s.push(o);let d=r.get(a).sort((u,c)=>u-c).map(String);m[o]=d,h.push(`${o.padStart(4)} | ${d.join(" ")}`);}return {stems:s,leaves:m,display:h}}midSummaries(){return this.letterValues().map(({depth:n,mid:e,spread:r})=>({depth:n,mid:e,spread:r}))}describe(){return this.data.description={original:this.data.original,summary:{median:this.median(),mean:this.mean(),mode:this.mode(),hinges:this.hinges(),adjacent:this.adjacent(),outliers:this.outliers(),outer:this.outer(),outside:this.outside(),inside:this.inside(),extremes:this.extremes(),iqr:this.iqr(),fences:this.fences()},smooths:{smooth:this.smooth(),hanning:this.hanning()},transforms:{logs:this.logs(),roots:this.roots(),inverse:this.inverse()},counts:this.counts(),sorted:this.sorted(),ranked:this.ranked(),binned:this.binned()},this.data.description}},p=class{data;dimension;count;constructor(t={}){typeof t=="number"?(this.count=t,this.dimension=2,this.data={original:f(this.count,this.dimension)}):(this.dimension=t.dimensionality??2,this.count=t.count??100,this.data={original:t.data??f(this.count,this.dimension)});}describe(){return this.data.description={original:this.data.original},this.data.description}},M=class{smoothed=false;static DEFAULT_MAX_RANDOM_INTEGER=100;static DEFAULT_MIN_RANDOM_INTEGER=0;static DEFAULT_RANDOM_SERIES_COUNT=1e3;static DEFAULT_OUTLIER_MULTIPLE=1.5;static DEFAULT_JITTER_MULTIPLIER=1;static DEFAULT_SPLIT_PASSES=2;static DEFAULT_MAX_RANDOM_DIMENSIONALITY=2;static Series=g;static Points=p;static randomInteger=R;static randomSeries=E;static randomPoint=_;static randomPoints=f},A=M;export{p as Points,g as Series,M as Twokeys,A as default};//# sourceMappingURL=index.js.map
|
|
2
|
+
//# sourceMappingURL=index.js.map
|