xy-scale 1.2.9 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
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:()=>c,descaleArrayObj:()=>p,parseProductionX:()=>u,parseTrainingXY:()=>i});const t=({arrObj:e,repeat:r={},minmaxRange:t=[0,1],groups:i={},prevConfig:u=null,customMinMaxRanges:p=null})=>{const c=[...e],f=c.length,m=c[0],l="object"==typeof p&&null!==p;if(0===f)return{scaledOutput:[],scaledConfig:{}};let g={};const y=u&&o(u);if(y)s(u,{minmaxRange:t,repeat:r,groups:i,firstRow:m}),g={...u};else{const e=Object.keys(m),n=e.map((e=>r.hasOwnProperty(e)?Math.max(r[e],1):1)),a=n.reduce(((e,r)=>e+r),0);g={arrObjLen:f,rangeMin:t[0],rangeMax:t[1],inputTypes:{},min:{},max:{},uniqueStrIdx:{},groupMinMax:{},repeat:r,groups:i,inputKeyNames:e,outputKeyNames:new Array(a),repeatedKeyNames:n};let s=0;for(let e=0;e<g.inputKeyNames.length;e++)for(let r=0;r<g.repeatedKeyNames[e];r++)g.outputKeyNames[s++]=g.inputKeyNames[e];o(g)}n(g.groups);for(const e of g.inputKeyNames){const r=typeof m[e],t=a(e,g.groups);if(y){if(!g.inputTypes.hasOwnProperty(e))throw new Error(`Error: A new unknown inputType property "${e}" found.`);if(g.inputTypes[e]!==r)throw new Error(`Error: Current inputType of property "${e}" is not the same as in the prevConfig inputType.`)}else g.inputTypes[e]=r,"string"===r&&(g.uniqueStrIdx[e]={}),l&&p.hasOwnProperty(e)?t?g.groupMinMax[t]=p[e]:(g.min[e]=p[e].min,g.max[e]=p[e].max):t?g.groupMinMax[t]={min:1/0,max:-1/0}:(g.min[e]=1/0,g.max[e]=-1/0)}for(const e of c)for(const r of g.inputKeyNames){let t=e[r];if("string"===g.inputTypes[r]){const n=g.uniqueStrIdx[r];n.hasOwnProperty(t)||(n[t]=Object.keys(n).length),t=n[t],e[r]=t}else"boolean"===g.inputTypes[r]&&(e[r]=Number(t));const n=a(r,g.groups);(!1===l||l&&!p.hasOwnProperty(r))&&(n?(g.groupMinMax[n].min=Math.min(g.groupMinMax[n].min,t),g.groupMinMax[n].max=Math.max(g.groupMinMax[n].max,t)):(g.min[r]=Math.min(g.min[r],t),g.max[r]=Math.max(g.max[r],t)))}const h=new Array(f);for(let e=0;e<f;e++){const r=c[e],t=new Array(g.outputKeyNames.length);let n=0;for(let e=0;e<g.inputKeyNames.length;e++){const o=g.inputKeyNames[e],s=r[o],i=a(o,g.groups);let u,p;i?(u=g.groupMinMax[i].min,p=g.groupMinMax[i].max):(u=g.min[o],p=g.max[o]);const c=p!==u?g.rangeMin+(s-u)/(p-u)*(g.rangeMax-g.rangeMin):g.rangeMin,f=g.repeatedKeyNames[e];for(let e=0;e<f;e++)t[n++]=c}h[e]=t}return{scaledOutput:h,scaledConfig:g}},n=e=>{const r=new Set,t=[];for(const[n,a]of Object.entries(e))r.add(n),t.push(n),a.forEach((e=>{r.add(e),t.push(e)}));if(r.size!==t.length)throw new Error("Duplicate value found between properties in validateUniqueProperties function.")},a=(e,r)=>{for(const[t,n]of Object.entries(r))if(n.includes(e))return t;return null},o=e=>{if(!e)return!1;const r=["rangeMin","rangeMax","inputTypes","min","max","uniqueStrIdx","groupMinMax","repeat","groups","inputKeyNames","outputKeyNames","repeatedKeyNames"];for(const t of r)if(!e.hasOwnProperty(t))throw new Error(`Missing key "${t}" in config.`);const{rangeMin:t,rangeMax:n,inputTypes:a,min:o,max:s,uniqueStrIdx:i,groupMinMax:u,repeat:p,groups:c,inputKeyNames:f,outputKeyNames:m,repeatedKeyNames:l}=e;if("number"!=typeof t||"number"!=typeof n)throw new Error("rangeMin and rangeMax must be numbers.");if(t>=n)throw new Error("rangeMin must be less than rangeMax.");const g=e=>"object"==typeof e&&null!==e&&!Array.isArray(e);if(!g(a))throw new Error("inputTypes must be an object.");if(!g(o))throw new Error("min must be an object.");if(!g(s))throw new Error("max must be an object.");if(!g(i))throw new Error("uniqueStrIdx must be an object.");if(!g(u))throw new Error("groupMinMax must be an object.");if(!g(p))throw new Error("repeat must be an object.");if(!g(c))throw new Error("groups must be an object.");if(!Array.isArray(f))throw new Error("inputKeyNames must be an array.");if(!Array.isArray(m))throw new Error("outputKeyNames must be an array.");if(!Array.isArray(l))throw new Error("repeatedKeyNames must be an array.");return!0},s=(e,{minmaxRange:r,repeat:t,groups:n,firstRow:a})=>{if(e.rangeMin!==r[0]||e.rangeMax!==r[1])throw new Error('"prevConfig.minmaxRange" is not equal "minmaxRange".');if(JSON.stringify(e.inputKeyNames)!==JSON.stringify(Object.keys(a)))throw new Error('"prevConfig.inputKeyNames" structure does not match "Object.keys(firstRow)" structure. The order of keys is important.');if(JSON.stringify(e.repeat)!==JSON.stringify(t))throw new Error('"prevConfig.repeat" structure does not match "repeat" structure. The order of keys is important.');if(JSON.stringify(e.groups)!==JSON.stringify(n))throw new Error('"prevConfig.groups" structure does not match "groups" structure. The order of keys is important.');return!0},i=({arrObj:e,trainingSplit:r=.8,repeat:n,yCallbackFunc:a,xCallbackFunc:o,validateRows:s=e=>e,groups:i,shuffle:u=!1,minmaxRange:p,balancing:c="",state:f={},customMinMaxRanges:m})=>{let l=[],g=[];for(let r=0;r<e.length;r++){if(!s(e[r]))continue;const t=o({objRow:e,index:r,state:f}),n=a({objRow:e,index:r,state:f});null!=t&&null!=n&&(l.push(t),g.push(n))}if(u){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]))}})(l,g);l=e,g=r}let{scaledOutput:y,scaledConfig:h}=t({arrObj:l,repeat:n,groups:i,minmaxRange:p,customMinMaxRanges:m}),{scaledOutput:d,scaledConfig:w}=t({arrObj:g,repeat:n,groups:i,minmaxRange:p,customMinMaxRanges:m});const M=Math.floor(y.length*r);let x=y.slice(0,M),b=d.slice(0,M),O=y.slice(M),j=d.slice(M);if(c){let e;if("oversample"===c)e=((e,r)=>{const t={},n={};r.forEach(((a,o)=>{t[a]||(t[a]=0,n[a]=[]),t[a]++,n[a].push([e[o],r[o]])}));const a=Math.max(...Object.values(t)),o=[],s=[];return Object.keys(n).forEach((e=>{const r=n[e],t=r.length;for(let e=0;e<a;e++){const n=r[e%t];o.push(n[0]),s.push(n[1])}})),{X:o,Y:s}})(x,b),x=e.X,b=e.Y;else{if("undersample"!==c)throw Error('balancing argument only accepts "false", "oversample" and "undersample". Defaults to "false".');e=((e,r)=>{const t={},n={};r.forEach(((a,o)=>{t[a]||(t[a]=0,n[a]=[]),t[a]++,n[a].push([e[o],r[o]])}));const a=Math.min(...Object.values(t)),o=[],s=[];return Object.keys(n).forEach((e=>{const r=n[e];for(let e=0;e<a;e++){const t=r[e];o.push(t[0]),s.push(t[1])}})),{X:o,Y:s}})(x,b),x=e.X,b=e.Y}}return{trainX:x,trainY:b,testX:O,testY:j,configX:h,configY:w}},u=({arrObj:e,repeat:r,xCallbackFunc:n,validateRows:a=e=>e,groups:o,shuffle:s=!1,minmaxRange:i,state:u={},prevConfig:p,customMinMaxRanges:c})=>{let f=[];for(let r=0;r<e.length;r++){if(!a(e[r]))continue;const t=n({objRow:e,index:r,state:u});t&&f.push(t)}s&&(f=(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})(f));const{scaledOutput:m,scaledConfig:l}=t({arrObj:f,repeat:r,groups:o,minmaxRange:i,prevConfig:p,customMinMaxRanges:c});return{X:m,configX:l}},p=({scaled:e,config:r,keyNames:t})=>{const{min:n,max:a,std:o,mean:s,approach:i,inputTypes:u,uniqueStringIndexes:p}=r;return e.map((e=>{const r={};let c=0;for(const f of Object.keys(n)){const m=i[f],l=n[f],g=a[f],y=s[f],h=o[f],d=t.filter((e=>e===f)).length;let w=0;for(let r=0;r<d;r++)w+=e[c++];const M=w/d;let x;if("normalization"===m?x=M*(g-l)+l:"standardization"===m&&(x=M*h+y),"string"===u[f]){const e=Object.keys(p[f]).find((e=>p[f][e]===x));x=void 0!==e?e:x}r[f]=x}return r}))},c=(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})();
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:()=>p,parseProductionX:()=>u,parseTrainingXY:()=>i});const t=({arrObj:e,repeat:r={},minmaxRange:t=[0,1],groups:i={},prevConfig:u=null,customMinMaxRanges:p=null})=>{const m=[...e],f=m.length,l=m[0],c="object"==typeof p&&null!==p;if(0===f)return{scaledOutput:[],scaledConfig:{}};let g={};const h=u&&o(u);if(h)s(u,{minmaxRange:t,repeat:r,groups:i,firstRow:l}),g={...u};else{const e=Object.keys(l),n=e.map((e=>r.hasOwnProperty(e)?Math.max(r[e],1):1)),a=n.reduce(((e,r)=>e+r),0);g={arrObjLen:f,rangeMin:t[0],rangeMax:t[1],inputTypes:{},min:{},max:{},groupMinMax:{},repeat:r,groups:i,inputKeyNames:e,outputKeyNames:new Array(a),repeatedKeyNames:n};let s=0;for(let e=0;e<g.inputKeyNames.length;e++)for(let r=0;r<g.repeatedKeyNames[e];r++)g.outputKeyNames[s++]=g.inputKeyNames[e];o(g)}n(g.groups);const y=["number","boolean"];for(const e of g.inputKeyNames){const r=typeof l[e],t=a(e,g.groups);if(!y.includes(r))throw new Error(`Invalid input type "${r}" provided for key "${e}". Only accepting `);if(h){if(!g.inputTypes.hasOwnProperty(e))throw new Error(`Error: A new unknown inputType property "${e}" found.`);if(g.inputTypes[e]!==r)throw new Error(`Error: Current inputType of property "${e}" is not the same as in the prevConfig inputType.`)}else g.inputTypes[e]=r,c&&p.hasOwnProperty(e)?t?g.groupMinMax[t]=p[e]:(g.min[e]=p[e].min,g.max[e]=p[e].max):t?g.groupMinMax[t]={min:1/0,max:-1/0}:(g.min[e]=1/0,g.max[e]=-1/0)}for(const e of m)for(const r of g.inputKeyNames){let t=e[r];"boolean"===g.inputTypes[r]&&(e[r]=Number(t));const n=a(r,g.groups);(!1===c||c&&!p.hasOwnProperty(r))&&(n?(g.groupMinMax[n].min=Math.min(g.groupMinMax[n].min,t),g.groupMinMax[n].max=Math.max(g.groupMinMax[n].max,t)):(g.min[r]=Math.min(g.min[r],t),g.max[r]=Math.max(g.max[r],t)))}const M=new Array(f);for(let e=0;e<f;e++){const r=m[e],t=new Array(g.outputKeyNames.length);let n=0;for(let e=0;e<g.inputKeyNames.length;e++){const o=g.inputKeyNames[e],s=r[o],i=a(o,g.groups);let u,p;i?(u=g.groupMinMax[i].min,p=g.groupMinMax[i].max):(u=g.min[o],p=g.max[o]);const m=p!==u?g.rangeMin+(s-u)/(p-u)*(g.rangeMax-g.rangeMin):g.rangeMin,f=g.repeatedKeyNames[e];for(let e=0;e<f;e++)t[n++]=m}M[e]=t}return{scaledOutput:M,scaledConfig:g}},n=e=>{const r=new Set,t=[];for(const[n,a]of Object.entries(e))r.add(n),t.push(n),a.forEach((e=>{r.add(e),t.push(e)}));if(r.size!==t.length)throw new Error("Duplicate value found between properties in validateUniqueProperties function.")},a=(e,r)=>{for(const[t,n]of Object.entries(r))if(n.includes(e))return t;return null},o=e=>{if(!e)return!1;const r=["rangeMin","rangeMax","inputTypes","min","max","groupMinMax","repeat","groups","inputKeyNames","outputKeyNames","repeatedKeyNames"];for(const t of r)if(!e.hasOwnProperty(t))throw new Error(`Missing key "${t}" in config.`);const{rangeMin:t,rangeMax:n,inputTypes:a,min:o,max:s,groupMinMax:i,repeat:u,groups:p,inputKeyNames:m,outputKeyNames:f,repeatedKeyNames:l}=e;if("number"!=typeof t||"number"!=typeof n)throw new Error("rangeMin and rangeMax must be numbers.");if(t>=n)throw new Error("rangeMin must be less than rangeMax.");const c=e=>"object"==typeof e&&null!==e&&!Array.isArray(e);if(!c(a))throw new Error("inputTypes must be an object.");if(!c(o))throw new Error("min must be an object.");if(!c(s))throw new Error("max must be an object.");if(!c(i))throw new Error("groupMinMax must be an object.");if(!c(u))throw new Error("repeat must be an object.");if(!c(p))throw new Error("groups must be an object.");if(!Array.isArray(m))throw new Error("inputKeyNames must be an array.");if(!Array.isArray(f))throw new Error("outputKeyNames must be an array.");if(!Array.isArray(l))throw new Error("repeatedKeyNames must be an array.");return!0},s=(e,{minmaxRange:r,repeat:t,groups:n,firstRow:a})=>{if(e.rangeMin!==r[0]||e.rangeMax!==r[1])throw new Error('"prevConfig.minmaxRange" is not equal "minmaxRange".');if(JSON.stringify(e.inputKeyNames)!==JSON.stringify(Object.keys(a)))throw new Error('"prevConfig.inputKeyNames" structure does not match "Object.keys(firstRow)" structure. The order of keys is important.');if(JSON.stringify(e.repeat)!==JSON.stringify(t))throw new Error('"prevConfig.repeat" structure does not match "repeat" structure. The order of keys is important.');if(JSON.stringify(e.groups)!==JSON.stringify(n))throw new Error('"prevConfig.groups" structure does not match "groups" structure. The order of keys is important.');return!0},i=({arrObj:e,trainingSplit:r=.8,repeat:n,yCallbackFunc:a=e=>e,xCallbackFunc:o=e=>e,validateRows:s=()=>!0,groups:i,shuffle:u=!1,minmaxRange:p,balancing:m="",state:f={},customMinMaxRanges:l})=>{let c=[],g=[];for(let r=0;r<e.length;r++){if(!s(e[r]))continue;const t=o({objRow:e,index:r,state:f}),n=a({objRow:e,index:r,state:f});null!=t&&null!=n&&(c.push(t),g.push(n))}if(u){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]))}})(c,g);c=e,g=r}let{scaledOutput:h,scaledConfig:y}=t({arrObj:c,repeat:n,groups:i,minmaxRange:p,customMinMaxRanges:l}),{scaledOutput:M,scaledConfig:w}=t({arrObj:g,repeat:n,groups:i,minmaxRange:p,customMinMaxRanges:l});const d=Math.floor(h.length*r);let b=h.slice(0,d),x=M.slice(0,d),O=h.slice(d),j=M.slice(d);if(m){let e;if("oversample"===m)e=((e,r)=>{const t={},n={};r.forEach(((a,o)=>{t[a]||(t[a]=0,n[a]=[]),t[a]++,n[a].push([e[o],r[o]])}));const a=Math.max(...Object.values(t)),o=[],s=[];return Object.keys(n).forEach((e=>{const r=n[e],t=r.length;for(let e=0;e<a;e++){const n=r[e%t];o.push(n[0]),s.push(n[1])}})),{X:o,Y:s}})(b,x),b=e.X,x=e.Y;else{if("undersample"!==m)throw Error('balancing argument only accepts "false", "oversample" and "undersample". Defaults to "false".');e=((e,r)=>{const t={},n={};r.forEach(((a,o)=>{t[a]||(t[a]=0,n[a]=[]),t[a]++,n[a].push([e[o],r[o]])}));const a=Math.min(...Object.values(t)),o=[],s=[];return Object.keys(n).forEach((e=>{const r=n[e];for(let e=0;e<a;e++){const t=r[e];o.push(t[0]),s.push(t[1])}})),{X:o,Y:s}})(b,x),b=e.X,x=e.Y}}return{trainX:b,trainY:x,testX:O,testY:j,configX:y,configY:w}},u=({arrObj:e,repeat:r,xCallbackFunc:n=e=>e,validateRows:a=()=>!0,groups:o,shuffle:s=!1,minmaxRange:i,state:u={},prevConfig:p,customMinMaxRanges:m})=>{let f=[];for(let r=0;r<e.length;r++){if(!a(e[r]))continue;const t=n({objRow:e,index:r,state:u});null!=t&&!1!==t&&f.push(t)}s&&(f=(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})(f));const{scaledOutput:l,scaledConfig:c}=t({arrObj:f,repeat:r,groups:o,minmaxRange:i,prevConfig:p,customMinMaxRanges:m});return{X:l,configX:c}},p=(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/index.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import { parseTrainingXY, parseProductionX } from "./src/datasets.js"
2
- import { descaleArrayObj } from "./src/descale.js"
3
2
  import {arrayToTimesteps } from "./src/timeSteps.js"
4
3
 
5
- export { parseTrainingXY, parseProductionX, descaleArrayObj, arrayToTimesteps }
4
+ export { parseTrainingXY, parseProductionX, arrayToTimesteps }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xy-scale",
3
- "version": "1.2.9",
3
+ "version": "1.3.1",
4
4
  "main": "./index.js",
5
5
  "type": "module",
6
6
  "scripts": {
package/src/datasets.js CHANGED
@@ -6,9 +6,9 @@ export const parseTrainingXY = ({
6
6
  arrObj,
7
7
  trainingSplit = 0.8,
8
8
  repeat,
9
- yCallbackFunc,
10
- xCallbackFunc,
11
- validateRows = row => row,
9
+ yCallbackFunc = row => row,
10
+ xCallbackFunc = row => row,
11
+ validateRows = () => true,
12
12
  groups,
13
13
  shuffle = false,
14
14
  minmaxRange,
@@ -27,7 +27,7 @@ export const parseTrainingXY = ({
27
27
  const parsedX = xCallbackFunc({ objRow: arrObj, index: x, state})
28
28
  const parsedY = yCallbackFunc({ objRow: arrObj, index: x, state})
29
29
 
30
- if (parsedX !== undefined && parsedX !== null && parsedY !== undefined && parsedY !== null) {
30
+ if (typeof parsedX !== 'undefined' && parsedX !== null && typeof parsedY !== 'undefined' && parsedY !== null) {
31
31
  X.push(parsedX)
32
32
  Y.push(parsedY)
33
33
  }
@@ -63,26 +63,26 @@ export const parseTrainingXY = ({
63
63
 
64
64
 
65
65
  if(balancing)
66
+ {
67
+ let balance
68
+
69
+ if(balancing === 'oversample')
66
70
  {
67
- let balance
68
-
69
- if(balancing === 'oversample')
70
- {
71
- balance = oversampleXY(trainX, trainY)
72
- trainX = balance.X
73
- trainY = balance.Y
74
- }
75
- else if(balancing === 'undersample')
76
- {
77
- balance = undersampleXY(trainX, trainY)
78
- trainX = balance.X
79
- trainY = balance.Y
80
- }
81
- else
82
- {
83
- throw Error('balancing argument only accepts "false", "oversample" and "undersample". Defaults to "false".')
84
- }
71
+ balance = oversampleXY(trainX, trainY)
72
+ trainX = balance.X
73
+ trainY = balance.Y
74
+ }
75
+ else if(balancing === 'undersample')
76
+ {
77
+ balance = undersampleXY(trainX, trainY)
78
+ trainX = balance.X
79
+ trainY = balance.Y
80
+ }
81
+ else
82
+ {
83
+ throw Error('balancing argument only accepts "false", "oversample" and "undersample". Defaults to "false".')
85
84
  }
85
+ }
86
86
 
87
87
 
88
88
  // Split into training and testing sets
@@ -100,8 +100,8 @@ export const parseTrainingXY = ({
100
100
  export const parseProductionX = ({
101
101
  arrObj,
102
102
  repeat,
103
- xCallbackFunc,
104
- validateRows = row => row,
103
+ xCallbackFunc = row => row,
104
+ validateRows = () => true,
105
105
  groups,
106
106
  shuffle = false,
107
107
  minmaxRange,
@@ -117,7 +117,7 @@ export const parseProductionX = ({
117
117
 
118
118
  const parsedX = xCallbackFunc({ objRow: arrObj, index: x, state})
119
119
 
120
- if (parsedX) {
120
+ if (typeof parsedX !== 'undefined' && parsedX !== null && parsedX !== false) {
121
121
  X.push(parsedX)
122
122
  }
123
123
  }
package/src/scale.js CHANGED
@@ -38,7 +38,6 @@ export const scaleArrayObj = ({ arrObj, repeat = {}, minmaxRange = [0, 1], group
38
38
  inputTypes: {},
39
39
  min: {},
40
40
  max: {},
41
- uniqueStrIdx: {},
42
41
  groupMinMax: {},
43
42
  repeat,
44
43
  groups,
@@ -61,11 +60,19 @@ export const scaleArrayObj = ({ arrObj, repeat = {}, minmaxRange = [0, 1], group
61
60
 
62
61
  validateUniqueProperties(config.groups);
63
62
 
63
+ const validInputTypes = ['number', 'boolean']
64
+
64
65
  for (const key of config.inputKeyNames) {
65
66
 
66
67
  const firstType = typeof firstRow[key]
67
68
  const thisGroup = findGroup(key, config.groups);
68
69
 
70
+
71
+ if(!validInputTypes.includes(firstType))
72
+ {
73
+ throw new Error(`Invalid input type "${firstType}" provided for key "${key}". Only accepting `)
74
+ }
75
+
69
76
  if(isValidPrevConfig)
70
77
  {
71
78
  if(!config.inputTypes.hasOwnProperty(key))
@@ -83,10 +90,6 @@ export const scaleArrayObj = ({ arrObj, repeat = {}, minmaxRange = [0, 1], group
83
90
  }
84
91
 
85
92
  config.inputTypes[key] = firstType;
86
-
87
- if (firstType === 'string') {
88
- config.uniqueStrIdx[key] = {};
89
- }
90
93
 
91
94
  if(validCustomMinMaxRanges && customMinMaxRanges.hasOwnProperty(key))
92
95
  {
@@ -115,14 +118,7 @@ export const scaleArrayObj = ({ arrObj, repeat = {}, minmaxRange = [0, 1], group
115
118
  for (const key of config.inputKeyNames) {
116
119
  let value = obj[key];
117
120
 
118
- if (config.inputTypes[key] === 'string') {
119
- const uniqueIndexes = config.uniqueStrIdx[key];
120
- if (!uniqueIndexes.hasOwnProperty(value)) {
121
- uniqueIndexes[value] = Object.keys(uniqueIndexes).length;
122
- }
123
- value = uniqueIndexes[value];
124
- obj[key] = value;
125
- } else if (config.inputTypes[key] === 'boolean') {
121
+ if (config.inputTypes[key] === 'boolean') {
126
122
  obj[key] = Number(value);
127
123
  }
128
124
 
@@ -226,7 +222,6 @@ const validateConfig = config => {
226
222
  "inputTypes",
227
223
  "min",
228
224
  "max",
229
- "uniqueStrIdx",
230
225
  "groupMinMax",
231
226
  "repeat",
232
227
  "groups",
@@ -248,7 +243,6 @@ const validateConfig = config => {
248
243
  inputTypes,
249
244
  min,
250
245
  max,
251
- uniqueStrIdx,
252
246
  groupMinMax,
253
247
  repeat,
254
248
  groups,
@@ -277,9 +271,6 @@ const validateConfig = config => {
277
271
  if (!isPlainObject(max)) {
278
272
  throw new Error("max must be an object.");
279
273
  }
280
- if (!isPlainObject(uniqueStrIdx)) {
281
- throw new Error("uniqueStrIdx must be an object.");
282
- }
283
274
  if (!isPlainObject(groupMinMax)) {
284
275
  throw new Error("groupMinMax must be an object.");
285
276
  }
package/test/test.js CHANGED
@@ -5,7 +5,8 @@ import * as tf from '@tensorflow/tfjs-node'
5
5
 
6
6
  const test = async () => {
7
7
 
8
- const myArray = (await loadFile({fileName: '1d-spy.json', pathName: 'datasets'})) //file in /datasets/1d-spy.json
8
+ const myArray = (await loadFile({fileName: '1d-spy.json', pathName: 'datasets'}))
9
+ .map(({open, high, low, close}) => ({open, high, low, close})) //file in /datasets/1d-spy.json
9
10
 
10
11
  //callback function used to prepare X before scaling
11
12
  const xCallbackFunc = ({ objRow, index }) => {
@@ -15,10 +16,9 @@ const test = async () => {
15
16
  //returning null or undefined will exclude current row X and Y from training
16
17
  if(typeof prev === 'undefined') return null
17
18
 
18
- const { open, high, low, close, volume, date } = curr
19
+ const { open, high, low, close } = curr
19
20
 
20
21
  return {
21
- date,
22
22
  open,
23
23
  high,
24
24
  low,
package/src/descale.js DELETED
@@ -1,53 +0,0 @@
1
- export const descaleArrayObj = ({ scaled, config, keyNames }) => {
2
-
3
- const { min, max, std, mean, approach, inputTypes, uniqueStringIndexes } = config;
4
-
5
- // Initialize the descaled output array
6
- const descaledOutput = scaled.map(scaledRow => {
7
- const originalObj = {};
8
- let idx = 0;
9
-
10
- for (const key of Object.keys(min)) {
11
- // Determine the scaling approach for the current key
12
- const keyApproach = approach[key];
13
- const minValue = min[key];
14
- const maxValue = max[key];
15
- const meanValue = mean[key];
16
- const stdValue = std[key];
17
-
18
- // Get the weight for this key from the keyNames
19
- const keyWeight = keyNames.filter(k => k === key).length;
20
-
21
- // Reconstruct the original value from the scaled values
22
- let summedValue = 0;
23
- for (let w = 0; w < keyWeight; w++) {
24
- summedValue += scaledRow[idx++];
25
- }
26
- const avgScaledValue = summedValue / keyWeight;
27
-
28
- // Descale based on approach
29
- let descaledValue;
30
- if (keyApproach === 'normalization') {
31
- descaledValue = avgScaledValue * (maxValue - minValue) + minValue;
32
- } else if (keyApproach === 'standardization') {
33
- descaledValue = avgScaledValue * stdValue + meanValue;
34
- }
35
-
36
- // Handle string keys if necessary
37
- if (inputTypes[key] === 'string') {
38
- const reverseUniqueIndex = Object.keys(uniqueStringIndexes[key]).find(
39
- k => uniqueStringIndexes[key][k] === descaledValue
40
- );
41
- descaledValue = reverseUniqueIndex !== undefined ? reverseUniqueIndex : descaledValue;
42
- }
43
-
44
- originalObj[key] = descaledValue;
45
- }
46
-
47
- return originalObj;
48
- });
49
-
50
- return descaledOutput;
51
- };
52
-
53
-