xy-scale 1.3.8 → 1.3.9

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.
@@ -1 +1 @@
1
- var XY_Scale;(()=>{"use strict";var e={d:(t,n)=>{for(var r in n)e.o(n,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:n[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{arrayToTimesteps:()=>l,parseProductionX:()=>u,parseTrainingXY:()=>i});const n=({arrObj:e,repeat:t={},minmaxRange:n,groups:o={},customMinMaxRanges:s=null,excludes:i=new Set})=>{const u=[...e],l=u.length,c=u[0],p="object"==typeof s&&null!==s;if(0===l)return{scaledOutput:[],scaledConfig:{}};const m=Object.keys(c),f=m.map((e=>t.hasOwnProperty(e)?Math.max(t[e],1):1)),g=f.reduce(((e,t)=>e+t),0),d={arrObjLen:l,rangeMin:n[0],rangeMax:n[1],inputTypes:{},min:{},max:{},groupMinMax:{},repeat:t,groups:o,inputKeyNames:m,outputKeyNames:new Array(g),repeatedKeyNames:f};let h=0;for(let e=0;e<d.inputKeyNames.length;e++)for(let t=0;t<d.repeatedKeyNames[e];t++)d.outputKeyNames[h++]=d.inputKeyNames[e];r(d.groups);const x=["number","boolean"];for(const e of d.inputKeyNames){if(i.has(e)){d.inputTypes[e]="excluded";continue}const t=typeof c[e],n=a(e,d.groups);if(!x.includes(t))throw new Error(`Invalid input type "${t}" provided for key "${e}". Only accepting `);d.inputTypes[e]=t,p&&s.hasOwnProperty(e)?n?d.groupMinMax[n]=s[e]:(d.min[e]=s[e].min,d.max[e]=s[e].max):n?d.groupMinMax[n]={min:1/0,max:-1/0}:(d.min[e]=1/0,d.max[e]=-1/0)}for(const e of u)for(const t of d.inputKeyNames){if("excluded"===d.inputTypes[t])continue;let n=e[t];"boolean"===d.inputTypes[t]&&(e[t]=Number(n));const r=a(t,d.groups);(!1===p||p&&!s.hasOwnProperty(t))&&(r?(d.groupMinMax[r].min=Math.min(d.groupMinMax[r].min,n),d.groupMinMax[r].max=Math.max(d.groupMinMax[r].max,n)):(d.min[t]=Math.min(d.min[t],n),d.max[t]=Math.max(d.max[t],n)))}const y=new Array(l);for(let e=0;e<l;e++){const t=u[e],n=new Array(d.outputKeyNames.length);let r=0;for(let e=0;e<d.inputKeyNames.length;e++){const o=d.inputKeyNames[e],s=t[o];if("excluded"===d.inputTypes[o]){n[r++]=s;continue}const i=a(o,d.groups);let u,l;i?(u=d.groupMinMax[i].min,l=d.groupMinMax[i].max):(u=d.min[o],l=d.max[o]);const c=l!==u?d.rangeMin+(s-u)/(l-u)*(d.rangeMax-d.rangeMin):d.rangeMin,p=d.repeatedKeyNames[e];for(let e=0;e<p;e++)n[r++]=c}y[e]=n}return{scaledOutput:y,scaledConfig:d}},r=e=>{const t=new Set,n=[];for(const[r,a]of Object.entries(e))t.add(r),n.push(r),a.forEach((e=>{t.add(e),n.push(e)}));if(t.size!==n.length)throw new Error("Duplicate value found between properties in validateUniqueProperties function.")},a=(e,t)=>{for(const[n,r]of Object.entries(t))if(r.includes(e))return n;return null},o=(e,{min:t=-1/0,max:n=1/0},r)=>{if(!Array.isArray(e))throw new Error(`Invalid property. "${r}" expected an array.`);if(e.length<t)throw new Error(`Invalid property value. Array "${r}" expected at least ${n} items.`);if(e.length>n)throw new Error(`Invalid property value. Array "${r}" expected at max ${n} items.`);return!0},s=e=>(Object.entries(e).forEach(((e,t)=>{if(null==t||Number.isNaN(t))throw new Error(`Invalid value at index ${e}: value is ${t}. Expected a defined, non-null, numeric value.`)})),!0),i=({arrObj:e=[],trainingSplit:t=.8,repeat:r={},yCallbackFunc:a=e=>e,xCallbackFunc:i=e=>e,validateRows:u=()=>!0,groups:l={},shuffle:c=!1,minmaxRange:p=[0,1],balancing:m="",state:f={},customMinMaxRanges:g={},excludes:d=[]})=>{let h=[],x=[];o(e,{min:5},"parseTrainingXY"),s(e[0]);for(let t=0;t<e.length;t++){if(!u({objRow:e,index:t,state:f}))continue;const n=i({objRow:e,index:t,state:f}),r=a({objRow:e,index:t,state:f});null!=n&&null!=r&&(h.push(n),x.push(r))}if(c){const{shuffledX:e,shuffledY:t}=((e,t)=>{if(e.length!==t.length)throw new Error("X and Y arrays must have the same length");const n=Array.from({length:e.length},((e,t)=>t));for(let e=n.length-1;e>0;e--){const t=Math.floor(Math.random()*(e+1));[n[e],n[t]]=[n[t],n[e]]}return{shuffledX:n.map((t=>e[t])),shuffledY:n.map((e=>t[e]))}})(h,x);h=e,x=t}const y=new Set(d);let{scaledOutput:M,scaledConfig:b}=n({arrObj:h,repeat:r,groups:l,minmaxRange:p,customMinMaxRanges:g,excludes:y}),{scaledOutput:w,scaledConfig:O}=n({arrObj:x,repeat:r,groups:l,minmaxRange:p,customMinMaxRanges:g,excludes:y});const v=Math.floor(M.length*t);let j=M.slice(0,v),R=w.slice(0,v),X=M.slice(v),N=w.slice(v);if(m){let e;if("oversample"===m)e=((e,t)=>{const n={},r={};t.forEach(((a,o)=>{n[a]||(n[a]=0,r[a]=[]),n[a]++,r[a].push([e[o],t[o]])}));const a=Math.max(...Object.values(n)),o=[],s=[];return Object.keys(r).forEach((e=>{const t=r[e],n=t.length;for(let e=0;e<a;e++){const r=t[e%n];o.push(r[0]),s.push(r[1])}})),{X:o,Y:s}})(j,R),j=e.X,R=e.Y;else{if("undersample"!==m)throw Error('balancing argument only accepts "false", "oversample" and "undersample". Defaults to "false".');e=((e,t)=>{const n={},r={};t.forEach(((a,o)=>{n[a]||(n[a]=0,r[a]=[]),n[a]++,r[a].push([e[o],t[o]])}));const a=Math.min(...Object.values(n)),o=[],s=[];return Object.keys(r).forEach((e=>{const t=r[e];for(let e=0;e<a;e++){const n=t[e];o.push(n[0]),s.push(n[1])}})),{X:o,Y:s}})(j,R),j=e.X,R=e.Y}}return{trainX:j,trainY:R,testX:X,testY:N,configX:b,configY:O}},u=({arrObj:e=[],repeat:t={},xCallbackFunc:r=e=>e,validateRows:a=()=>!0,groups:i={},shuffle:u=!1,minmaxRange:l=[0,1],state:c={},customMinMaxRanges:p,excludes:m=[]})=>{let f=[];o(e,{min:5},"parseProductionX"),s(e[0]);for(let t=0;t<e.length;t++){if(!a(e[t]))continue;const n=r({objRow:e,index:t,state:c});null!=n&&!1!==n&&f.push(n)}u&&(f=(e=>{const t=[...e];for(let e=t.length-1;e>0;e--){const n=Math.floor(Math.random()*(e+1));[t[e],t[n]]=[t[n],t[e]]}return t})(f));const{scaledOutput:g,scaledConfig:d}=n({arrObj:f,repeat:t,groups:i,minmaxRange:l,customMinMaxRanges:p,excludes:new Set(m)});return{X:g,configX:d}},l=(e,t)=>{if(0===t)return e;if(t<0)throw new Error("timeSteps must be greater than 0");const n=[];for(let r=0;r<=e.length-t;r++)n.push(e.slice(r,r+t));return n};XY_Scale=t})();
1
+ var XY_Scale;(()=>{"use strict";var e={d:(r,t)=>{for(var n in t)e.o(t,n)&&!e.o(r,n)&&Object.defineProperty(r,n,{enumerable:!0,get:t[n]})},o:(e,r)=>Object.prototype.hasOwnProperty.call(e,r),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},r={};e.r(r),e.d(r,{arrayToTimesteps:()=>x,parseProductionX:()=>y,parseTrainingXY:()=>v});const t=({arrObj:e,repeat:r={},minmaxRange:t,groups:s={},customMinMaxRanges:i=null,excludes:a=new Set})=>{const c=[...e],u=c.length,l=c[0],f="object"==typeof i&&null!==i;if(0===u)return{scaledOutput:[],scaledConfig:{}};const h=Object.keys(l),p=h.map((e=>r.hasOwnProperty(e)?Math.max(r[e],1):1)),g=p.reduce(((e,r)=>e+r),0),m={arrObjLen:u,rangeMin:t[0],rangeMax:t[1],inputTypes:{},min:{},max:{},groupMinMax:{},repeat:r,groups:s,inputKeyNames:h,outputKeyNames:new Array(g),repeatedKeyNames:p};let d=0;for(let e=0;e<m.inputKeyNames.length;e++)for(let r=0;r<m.repeatedKeyNames[e];r++)m.outputKeyNames[d++]=m.inputKeyNames[e];n(m.groups);const w=["number","boolean"];for(const e of m.inputKeyNames){if(a.has(e)){m.inputTypes[e]="excluded";continue}const r=typeof l[e],t=o(e,m.groups);if(!w.includes(r))throw new Error(`Invalid input type "${r}" provided for key "${e}". Only accepting `);m.inputTypes[e]=r,f&&i.hasOwnProperty(e)?t?m.groupMinMax[t]=i[e]:(m.min[e]=i[e].min,m.max[e]=i[e].max):t?m.groupMinMax[t]={min:1/0,max:-1/0}:(m.min[e]=1/0,m.max[e]=-1/0)}for(const e of c)for(const r of m.inputKeyNames){if("excluded"===m.inputTypes[r])continue;let t=e[r];"boolean"===m.inputTypes[r]&&(e[r]=Number(t));const n=o(r,m.groups);(!1===f||f&&!i.hasOwnProperty(r))&&(n?(m.groupMinMax[n].min=Math.min(m.groupMinMax[n].min,t),m.groupMinMax[n].max=Math.max(m.groupMinMax[n].max,t)):(m.min[r]=Math.min(m.min[r],t),m.max[r]=Math.max(m.max[r],t)))}const v=new Array(u);for(let e=0;e<u;e++){const r=c[e],t=new Array(m.outputKeyNames.length);let n=0;for(let e=0;e<m.inputKeyNames.length;e++){const s=m.inputKeyNames[e],i=r[s];if("excluded"===m.inputTypes[s]){t[n++]=i;continue}const a=o(s,m.groups);let c,u;a?(c=m.groupMinMax[a].min,u=m.groupMinMax[a].max):(c=m.min[s],u=m.max[s]);const l=u!==c?m.rangeMin+(i-c)/(u-c)*(m.rangeMax-m.rangeMin):m.rangeMin,f=m.repeatedKeyNames[e];for(let e=0;e<f;e++)t[n++]=l}v[e]=t}return{scaledOutput:v,scaledConfig:m}},n=e=>{const r=new Set,t=[];for(const[n,o]of Object.entries(e))r.add(n),t.push(n),o.forEach((e=>{r.add(e),t.push(e)}));if(r.size!==t.length)throw new Error("Duplicate value found between properties in validateUniqueProperties function.")},o=(e,r)=>{for(const[t,n]of Object.entries(r))if(n.includes(e))return t;return null},s=(e,{min:r=-1/0,max:t=1/0},n)=>{if(!Array.isArray(e))throw new Error(`Invalid property. "${n}" expected an array.`);if(e.length<r)throw new Error(`Invalid property value. Array "${n}" expected at least ${t} items.`);if(e.length>t)throw new Error(`Invalid property value. Array "${n}" expected at max ${t} items.`);return!0},i=e=>{for(const[r,t]of Object.entries(e)){if("number"==typeof t&&Number.isNaN(t))throw new Error(`Invalid value at index 0 property "${r}": value is "${t}". Expected a numeric value.`);if(null===t)throw new Error(`Invalid value at index 0 property "${r}": value is "${t}".`)}return!0};var a=1e6,c="[big.js] ",u=c+"Invalid ",l=u+"decimal places",f=u+"rounding mode",h=c+"Division by zero",p={},g=void 0,m=/^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i;function d(e,r,t,n){var o=e.c;if(t===g&&(t=e.constructor.RM),0!==t&&1!==t&&2!==t&&3!==t)throw Error(f);if(r<1)n=3===t&&(n||!!o[0])||0===r&&(1===t&&o[0]>=5||2===t&&(o[0]>5||5===o[0]&&(n||o[1]!==g))),o.length=1,n?(e.e=e.e-r+1,o[0]=1):o[0]=e.e=0;else if(r<o.length){if(n=1===t&&o[r]>=5||2===t&&(o[r]>5||5===o[r]&&(n||o[r+1]!==g||1&o[r-1]))||3===t&&(n||!!o[0]),o.length=r,n)for(;++o[--r]>9;)if(o[r]=0,0===r){++e.e,o.unshift(1);break}for(r=o.length;!o[--r];)o.pop()}return e}function w(e,r,t){var n=e.e,o=e.c.join(""),s=o.length;if(r)o=o.charAt(0)+(s>1?"."+o.slice(1):"")+(n<0?"e":"e+")+n;else if(n<0){for(;++n;)o="0"+o;o="0."+o}else if(n>0)if(++n>s)for(n-=s;n--;)o+="0";else n<s&&(o=o.slice(0,n)+"."+o.slice(n));else s>1&&(o=o.charAt(0)+"."+o.slice(1));return e.s<0&&t?"-"+o:o}p.abs=function(){var e=new this.constructor(this);return e.s=1,e},p.cmp=function(e){var r,t=this,n=t.c,o=(e=new t.constructor(e)).c,s=t.s,i=e.s,a=t.e,c=e.e;if(!n[0]||!o[0])return n[0]?s:o[0]?-i:0;if(s!=i)return s;if(r=s<0,a!=c)return a>c^r?1:-1;for(i=(a=n.length)<(c=o.length)?a:c,s=-1;++s<i;)if(n[s]!=o[s])return n[s]>o[s]^r?1:-1;return a==c?0:a>c^r?1:-1},p.div=function(e){var r=this,t=r.constructor,n=r.c,o=(e=new t(e)).c,s=r.s==e.s?1:-1,i=t.DP;if(i!==~~i||i<0||i>a)throw Error(l);if(!o[0])throw Error(h);if(!n[0])return e.s=s,e.c=[e.e=0],e;var c,u,f,p,m,w=o.slice(),v=c=o.length,y=n.length,x=n.slice(0,c),M=x.length,b=e,E=b.c=[],O=0,j=i+(b.e=r.e-e.e)+1;for(b.s=s,s=j<0?0:j,w.unshift(0);M++<c;)x.push(0);do{for(f=0;f<10;f++){if(c!=(M=x.length))p=c>M?1:-1;else for(m=-1,p=0;++m<c;)if(o[m]!=x[m]){p=o[m]>x[m]?1:-1;break}if(!(p<0))break;for(u=M==c?o:w;M;){if(x[--M]<u[M]){for(m=M;m&&!x[--m];)x[m]=9;--x[m],x[M]+=10}x[M]-=u[M]}for(;!x[0];)x.shift()}E[O++]=p?f:++f,x[0]&&p?x[M]=n[v]||0:x=[n[v]]}while((v++<y||x[0]!==g)&&s--);return E[0]||1==O||(E.shift(),b.e--,j--),O>j&&d(b,j,t.RM,x[0]!==g),b},p.eq=function(e){return 0===this.cmp(e)},p.gt=function(e){return this.cmp(e)>0},p.gte=function(e){return this.cmp(e)>-1},p.lt=function(e){return this.cmp(e)<0},p.lte=function(e){return this.cmp(e)<1},p.minus=p.sub=function(e){var r,t,n,o,s=this,i=s.constructor,a=s.s,c=(e=new i(e)).s;if(a!=c)return e.s=-c,s.plus(e);var u=s.c.slice(),l=s.e,f=e.c,h=e.e;if(!u[0]||!f[0])return f[0]?e.s=-c:u[0]?e=new i(s):e.s=1,e;if(a=l-h){for((o=a<0)?(a=-a,n=u):(h=l,n=f),n.reverse(),c=a;c--;)n.push(0);n.reverse()}else for(t=((o=u.length<f.length)?u:f).length,a=c=0;c<t;c++)if(u[c]!=f[c]){o=u[c]<f[c];break}if(o&&(n=u,u=f,f=n,e.s=-e.s),(c=(t=f.length)-(r=u.length))>0)for(;c--;)u[r++]=0;for(c=r;t>a;){if(u[--t]<f[t]){for(r=t;r&&!u[--r];)u[r]=9;--u[r],u[t]+=10}u[t]-=f[t]}for(;0===u[--c];)u.pop();for(;0===u[0];)u.shift(),--h;return u[0]||(e.s=1,u=[h=0]),e.c=u,e.e=h,e},p.mod=function(e){var r,t=this,n=t.constructor,o=t.s,s=(e=new n(e)).s;if(!e.c[0])throw Error(h);return t.s=e.s=1,r=1==e.cmp(t),t.s=o,e.s=s,r?new n(t):(o=n.DP,s=n.RM,n.DP=n.RM=0,t=t.div(e),n.DP=o,n.RM=s,this.minus(t.times(e)))},p.neg=function(){var e=new this.constructor(this);return e.s=-e.s,e},p.plus=p.add=function(e){var r,t,n,o=this,s=o.constructor;if(e=new s(e),o.s!=e.s)return e.s=-e.s,o.minus(e);var i=o.e,a=o.c,c=e.e,u=e.c;if(!a[0]||!u[0])return u[0]||(a[0]?e=new s(o):e.s=o.s),e;if(a=a.slice(),r=i-c){for(r>0?(c=i,n=u):(r=-r,n=a),n.reverse();r--;)n.push(0);n.reverse()}for(a.length-u.length<0&&(n=u,u=a,a=n),r=u.length,t=0;r;a[r]%=10)t=(a[--r]=a[r]+u[r]+t)/10|0;for(t&&(a.unshift(t),++c),r=a.length;0===a[--r];)a.pop();return e.c=a,e.e=c,e},p.pow=function(e){var r=this,t=new r.constructor("1"),n=t,o=e<0;if(e!==~~e||e<-1e6||e>1e6)throw Error(u+"exponent");for(o&&(e=-e);1&e&&(n=n.times(r)),e>>=1;)r=r.times(r);return o?t.div(n):n},p.prec=function(e,r){if(e!==~~e||e<1||e>a)throw Error(u+"precision");return d(new this.constructor(this),e,r)},p.round=function(e,r){if(e===g)e=0;else if(e!==~~e||e<-a||e>a)throw Error(l);return d(new this.constructor(this),e+this.e+1,r)},p.sqrt=function(){var e,r,t,n=this,o=n.constructor,s=n.s,i=n.e,a=new o("0.5");if(!n.c[0])return new o(n);if(s<0)throw Error(c+"No square root");0===(s=Math.sqrt(+w(n,!0,!0)))||s===1/0?((r=n.c.join("")).length+i&1||(r+="0"),i=((i+1)/2|0)-(i<0||1&i),e=new o(((s=Math.sqrt(r))==1/0?"5e":(s=s.toExponential()).slice(0,s.indexOf("e")+1))+i)):e=new o(s+""),i=e.e+(o.DP+=4);do{t=e,e=a.times(t.plus(n.div(t)))}while(t.c.slice(0,i).join("")!==e.c.slice(0,i).join(""));return d(e,(o.DP-=4)+e.e+1,o.RM)},p.times=p.mul=function(e){var r,t=this,n=t.constructor,o=t.c,s=(e=new n(e)).c,i=o.length,a=s.length,c=t.e,u=e.e;if(e.s=t.s==e.s?1:-1,!o[0]||!s[0])return e.c=[e.e=0],e;for(e.e=c+u,i<a&&(r=o,o=s,s=r,u=i,i=a,a=u),r=new Array(u=i+a);u--;)r[u]=0;for(c=a;c--;){for(a=0,u=i+c;u>c;)a=r[u]+s[c]*o[u-c-1]+a,r[u--]=a%10,a=a/10|0;r[u]=a}for(a?++e.e:r.shift(),c=r.length;!r[--c];)r.pop();return e.c=r,e},p.toExponential=function(e,r){var t=this,n=t.c[0];if(e!==g){if(e!==~~e||e<0||e>a)throw Error(l);for(t=d(new t.constructor(t),++e,r);t.c.length<e;)t.c.push(0)}return w(t,!0,!!n)},p.toFixed=function(e,r){var t=this,n=t.c[0];if(e!==g){if(e!==~~e||e<0||e>a)throw Error(l);for(e=e+(t=d(new t.constructor(t),e+t.e+1,r)).e+1;t.c.length<e;)t.c.push(0)}return w(t,!1,!!n)},p[Symbol.for("nodejs.util.inspect.custom")]=p.toJSON=p.toString=function(){var e=this,r=e.constructor;return w(e,e.e<=r.NE||e.e>=r.PE,!!e.c[0])},p.toNumber=function(){var e=+w(this,!0,!0);if(!0===this.constructor.strict&&!this.eq(e.toString()))throw Error(c+"Imprecise conversion");return e},p.toPrecision=function(e,r){var t=this,n=t.constructor,o=t.c[0];if(e!==g){if(e!==~~e||e<1||e>a)throw Error(u+"precision");for(t=d(new n(t),e,r);t.c.length<e;)t.c.push(0)}return w(t,e<=t.e||t.e<=n.NE||t.e>=n.PE,!!o)},p.valueOf=function(){var e=this,r=e.constructor;if(!0===r.strict)throw Error(c+"valueOf disallowed");return w(e,e.e<=r.NE||e.e>=r.PE,!0)},function e(){function r(t){var n=this;if(!(n instanceof r))return t===g?e():new r(t);if(t instanceof r)n.s=t.s,n.e=t.e,n.c=t.c.slice();else{if("string"!=typeof t){if(!0===r.strict&&"bigint"!=typeof t)throw TypeError(u+"value");t=0===t&&1/t<0?"-0":String(t)}!function(e,r){var t,n,o;if(!m.test(r))throw Error(u+"number");for(e.s="-"==r.charAt(0)?(r=r.slice(1),-1):1,(t=r.indexOf("."))>-1&&(r=r.replace(".","")),(n=r.search(/e/i))>0?(t<0&&(t=n),t+=+r.slice(n+1),r=r.substring(0,n)):t<0&&(t=r.length),o=r.length,n=0;n<o&&"0"==r.charAt(n);)++n;if(n==o)e.c=[e.e=0];else{for(;o>0&&"0"==r.charAt(--o););for(e.e=t-n-1,e.c=[],t=0;n<=o;)e.c[t++]=+r.charAt(n++)}}(n,t)}n.constructor=r}return r.prototype=p,r.DP=20,r.RM=1,r.NE=-7,r.PE=21,r.strict=!1,r.roundDown=0,r.roundHalfUp=1,r.roundHalfEven=2,r.roundUp=3,r}(),Error;const v=({arrObj:e=[],trainingSplit:r=.8,repeat:n={},yCallbackFunc:o=e=>e,xCallbackFunc:a=e=>e,validateRows:c=()=>!0,groups:u={},shuffle:l=!1,minmaxRange:f=[0,1],balancing:h="",state:p={},customMinMaxRanges:g={},excludes:m=[]})=>{let d=[],w=[];s(e,{min:5},"parseTrainingXY"),i(e[0]);for(let r=0;r<e.length;r++){if(!c({objRow:e,index:r,state:p}))continue;const t=a({objRow:e,index:r,state:p}),n=o({objRow:e,index:r,state:p});null!=t&&null!=n&&(d.push(t),w.push(n))}if(l){const{shuffledX:e,shuffledY:r}=((e,r)=>{if(e.length!==r.length)throw new Error("X and Y arrays must have the same length");const t=Array.from({length:e.length},((e,r)=>r));for(let e=t.length-1;e>0;e--){const r=Math.floor(Math.random()*(e+1));[t[e],t[r]]=[t[r],t[e]]}return{shuffledX:t.map((r=>e[r])),shuffledY:t.map((e=>r[e]))}})(d,w);d=e,w=r}const v=new Set(m);let{scaledOutput:y,scaledConfig:x}=t({arrObj:d,repeat:n,groups:u,minmaxRange:f,customMinMaxRanges:g,excludes:v});const M=w.length,b=new Array(M),E={keyNames:Object.keys(w[0])};for(let e=0;e<M;e++)b[e]=Object.values(w[e]);const O=Math.floor(y.length*r);let j=y.slice(0,O),N=b.slice(0,O),R=y.slice(O),P=b.slice(O);if(h){let e;if("oversample"===h)e=((e,r)=>{const t={},n={};r.forEach(((o,s)=>{t[o]||(t[o]=0,n[o]=[]),t[o]++,n[o].push([e[s],r[s]])}));const o=Math.max(...Object.values(t)),s=[],i=[];return Object.keys(n).forEach((e=>{const r=n[e],t=r.length;for(let e=0;e<o;e++){const n=r[e%t];s.push(n[0]),i.push(n[1])}})),{X:s,Y:i}})(j,N),j=e.X,N=e.Y;else{if("undersample"!==h)throw Error('balancing argument only accepts "false", "oversample" and "undersample". Defaults to "false".');e=((e,r)=>{const t={},n={};r.forEach(((o,s)=>{t[o]||(t[o]=0,n[o]=[]),t[o]++,n[o].push([e[s],r[s]])}));const o=Math.min(...Object.values(t)),s=[],i=[];return Object.keys(n).forEach((e=>{const r=n[e];for(let e=0;e<o;e++){const t=r[e];s.push(t[0]),i.push(t[1])}})),{X:s,Y:i}})(j,N),j=e.X,N=e.Y}}return{trainX:j,trainY:N,testX:R,testY:P,configX:x,configY:E}},y=({arrObj:e=[],repeat:r={},xCallbackFunc:n=e=>e,validateRows:o=()=>!0,groups:a={},shuffle:c=!1,minmaxRange:u=[0,1],state:l={},customMinMaxRanges:f,excludes:h=[]})=>{let p=[];s(e,{min:5},"parseProductionX"),i(e[0]);for(let r=0;r<e.length;r++){if(!o(e[r]))continue;const t=n({objRow:e,index:r,state:l});null!=t&&!1!==t&&p.push(t)}c&&(p=(e=>{const r=[...e];for(let e=r.length-1;e>0;e--){const t=Math.floor(Math.random()*(e+1));[r[e],r[t]]=[r[t],r[e]]}return r})(p));const{scaledOutput:g,scaledConfig:m}=t({arrObj:p,repeat:r,groups:a,minmaxRange:u,customMinMaxRanges:f,excludes:new Set(h)});return{X:g,configX:m}},x=(e,r)=>{if(0===r)return e;if(r<0)throw new Error("timeSteps must be greater than 0");const t=[];for(let n=0;n<=e.length-r;n++)t.push(e.slice(n,n+r));return t};XY_Scale=r})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xy-scale",
3
- "version": "1.3.8",
3
+ "version": "1.3.9",
4
4
  "main": "./index.js",
5
5
  "type": "module",
6
6
  "scripts": {
package/src/datasets.js CHANGED
@@ -2,7 +2,6 @@ import { scaleArrayObj } from "./scale.js";
2
2
  import { arrayShuffle, xyArrayShuffle } from "./utilities.js";
3
3
  import { oversampleXY, undersampleXY } from "./balancing.js";
4
4
  import { validateFirstRow, validateArray } from "./validators.js";
5
- import { analizeCorrelation } from "./correlation.js";
6
5
  import { correlation } from "ohlcv-indicators/src/studies/correlation.js";
7
6
 
8
7
  //ADD A PARAM max correlation that will measure the correlation between variables if defined
@@ -21,7 +20,6 @@ export const parseTrainingXY = ({
21
20
  state = {}, //accepted object or classes
22
21
  customMinMaxRanges = {},
23
22
  excludes = [],//each item must be a string
24
- correlation = {}
25
23
  }) => {
26
24
  let X = [];
27
25
  let Y = [];
@@ -29,10 +27,6 @@ export const parseTrainingXY = ({
29
27
  validateArray(arrObj, {min: 5}, 'parseTrainingXY')
30
28
  validateFirstRow(arrObj[0])
31
29
 
32
- const {corrSplit = 0.2, corrExcludes = [], corrThreshold = 0.95} = correlation
33
-
34
- analizeCorrelation({arrObj, corrSplit, corrExcludes: new Set(corrExcludes), corrThreshold})
35
-
36
30
  //if parsedX and parsedY is undefined or null the current row will be excluded from training or production
37
31
  for (let x = 0; x < arrObj.length; x++) {
38
32
 
@@ -1,66 +0,0 @@
1
- import { sum } from "@tensorflow/tfjs-node";
2
-
3
- export const analizeCorrelation = ({arrObj, corrSplit, corrExcludes, corrThreshold}) => {
4
- const n = Math.floor(arrObj.length * corrSplit);
5
- if (n < 2) return [];
6
-
7
- const keys = Object.keys(arrObj[0]).filter(k => !corrExcludes.has(k));
8
- const m = keys.length;
9
-
10
- console.log({m})
11
-
12
- // running sums, sums of squares, and cross‐sums
13
- const sums = new Float64Array(m); // by default Float64Array are filled with 0
14
- const sumsq = new Float64Array(m); // by default Float64Array are filled with 0
15
- const sumxy = Array.from({ length: m }, () => new Float64Array(m));
16
-
17
- // 1 pass: accumulate sums, sumsq, and sumxy[i][j] (i<j)
18
- for (let r = 0; r < n; r++) {
19
- const row = arrObj[r];
20
- for (let i = 0; i < m; i++) {
21
-
22
- const xi = row[keys[i]];
23
-
24
- //errror here, the code neve reaches this part
25
-
26
- sums[i] += xi;
27
- sumsq[i] += xi * xi;
28
- for (let j = i + 1; j < m; j++) {
29
- sumxy[i][j] += xi * row[keys[j]];
30
- }
31
- }
32
- }
33
-
34
- // precompute denominators: n*Σx² − (Σx)²
35
- const denom = new Float64Array(m);
36
- for (let i = 0; i < m; i++) {
37
- denom[i] = n * sumsq[i] - sums[i] * sums[i];
38
- }
39
-
40
- // build result pairs
41
- // collect pairs below/above your threshold
42
- let lowCorrelationPairs = `Low Correlation Pairs (< ${corrThreshold}):`;
43
- let highCorrelationPairs = `High Correlation Pairs (>= ${corrThreshold}):`;
44
-
45
- for (let i = 0; i < m; i++) {
46
- for (let j = i + 1; j < m; j++) {
47
- const cov = n * sumxy[i][j] - sums[i] * sums[j];
48
- const corr = cov / Math.sqrt(denom[i] * denom[j]);
49
- const pair = `\n${keys[i]} - ${keys[j]}: ${corr}`
50
-
51
- if(corr < corrThreshold)
52
- {
53
- lowCorrelationPairs += pair
54
- }
55
- else {
56
- highCorrelationPairs += pair
57
- }
58
- }
59
- }
60
-
61
- console.log(lowCorrelationPairs)
62
- console.log('---')
63
- console.log(highCorrelationPairs)
64
-
65
- return true;
66
- };