xy-scale 1.2.4 → 1.2.6

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:()=>f,descaleArrayObj:()=>p,parseProductionX:()=>u,parseTrainingXY:()=>i});const t=({arrObj:e,repeat:r={},minmaxRange:t=[0,1],groups:i={},prevConfig:u=null})=>{const p=[...e],f=p.length,c=p[0];if(0===f)return{scaledOutput:[],scaledConfig:{}};let l={};const m=u&&o(u);if(m)s(u,{minmaxRange:t,repeat:r,groups:i,firstRow:c}),l={...u};else{const e=Object.keys(c),n=e.map((e=>r.hasOwnProperty(e)?Math.max(r[e],1):1)),a=n.reduce(((e,r)=>e+r),0);l={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<l.inputKeyNames.length;e++)for(let r=0;r<l.repeatedKeyNames[e];r++)l.outputKeyNames[s++]=l.inputKeyNames[e];o(l)}n(l.groups);for(const e of l.inputKeyNames){const r=typeof c[e];if(m){if(!l.inputTypes.hasOwnProperty(e))throw new Error(`Error: A new unknown inputType property "${e}" found.`);if(l.inputTypes[e]!==r)throw new Error(`Error: Current inputType of property "${e}" is not the same as in the prevConfig inputType.`);continue}l.inputTypes[e]=r,"string"===r&&(l.uniqueStrIdx[e]={});const t=a(e,l.groups);t?l.groupMinMax[t]={min:1/0,max:-1/0}:(l.min[e]=1/0,l.max[e]=-1/0)}for(const e of p)for(const r of l.inputKeyNames){let t=e[r];if("string"===l.inputTypes[r]){const n=l.uniqueStrIdx[r];n.hasOwnProperty(t)||(n[t]=Object.keys(n).length),t=n[t],e[r]=t}else"boolean"===l.inputTypes[r]&&(e[r]=Number(t));const n=a(r,l.groups);n?(l.groupMinMax[n].min=Math.min(l.groupMinMax[n].min,t),l.groupMinMax[n].max=Math.max(l.groupMinMax[n].max,t)):(l.min[r]=Math.min(l.min[r],t),l.max[r]=Math.max(l.max[r],t))}const g=new Array(f);for(let e=0;e<f;e++){const r=p[e],t=new Array(l.outputKeyNames.length);let n=0;for(let e=0;e<l.inputKeyNames.length;e++){const o=l.inputKeyNames[e],s=r[o],i=a(o,l.groups);let u,p;i?(u=l.groupMinMax[i].min,p=l.groupMinMax[i].max):(u=l.min[o],p=l.max[o]);const f=p!==u?l.rangeMin+(s-u)/(p-u)*(l.rangeMax-l.rangeMin):l.rangeMin,c=l.repeatedKeyNames[e];for(let e=0;e<c;e++)t[n++]=f}g[e]=t}return{scaledOutput:g,scaledConfig:l}},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:f,inputKeyNames:c,outputKeyNames:l,repeatedKeyNames:m}=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(f))throw new Error("groups must be an object.");if(!Array.isArray(c))throw new Error("inputKeyNames must be an array.");if(!Array.isArray(l))throw new Error("outputKeyNames must be an array.");if(!Array.isArray(m))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:f="",state:c={}})=>{let l=[],m=[];for(let r=0;r<e.length;r++){if(!s(e[r]))continue;const t=o({objRow:e,index:r,state:c}),n=a({objRow:e,index:r,state:c});null!=t&&null!=n&&(l.push(t),m.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,m);l=e,m=r}let{scaledOutput:g,scaledConfig:y}=t({arrObj:l,repeat:n,groups:i,minmaxRange:p}),{scaledOutput:h,scaledConfig:d}=t({arrObj:m,repeat:n,groups:i,minmaxRange:p});const w=Math.floor(g.length*r);let b=g.slice(0,w),x=h.slice(0,w),M=g.slice(w),O=h.slice(w);if(f){let e;if("oversample"===f)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"!==f)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:M,testY:O,configX:y,configY:d}},u=({arrObj:e,repeat:r,xCallbackFunc:n,validateRows:a=e=>e,groups:o,shuffle:s=!1,minmaxRange:i,state:u={},prevConfig:p})=>{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:c,scaledConfig:l}=t({arrObj:f,repeat:r,groups:o,minmaxRange:i,prevConfig:p});return{X:c,configX:l,keyNamesX}},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 f=0;for(const c of Object.keys(n)){const l=i[c],m=n[c],g=a[c],y=s[c],h=o[c],d=t.filter((e=>e===c)).length;let w=0;for(let r=0;r<d;r++)w+=e[f++];const b=w/d;let x;if("normalization"===l?x=b*(g-m)+m:"standardization"===l&&(x=b*h+y),"string"===u[c]){const e=Object.keys(p[c]).find((e=>p[c][e]===x));x=void 0!==e?e:x}r[c]=x}return r}))},f=(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:()=>f,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 f=[...e],m=f.length,c=f[0],l="object"==typeof p&&null!==p;if(0===m)return{scaledOutput:[],scaledConfig:{}};let g={};const y=u&&o(u);if(y)s(u,{minmaxRange:t,repeat:r,groups:i,firstRow:c}),g={...u};else{const e=Object.keys(c),n=e.map((e=>r.hasOwnProperty(e)?Math.max(r[e],1):1)),a=n.reduce(((e,r)=>e+r),0);g={arrObjLen:m,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 c[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 f)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(m);for(let e=0;e<m;e++){const r=f[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 f=p!==u?g.rangeMin+(s-u)/(p-u)*(g.rangeMax-g.rangeMin):g.rangeMin,m=g.repeatedKeyNames[e];for(let e=0;e<m;e++)t[n++]=f}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:f,inputKeyNames:m,outputKeyNames:c,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(f))throw new Error("groups must be an object.");if(!Array.isArray(m))throw new Error("inputKeyNames must be an array.");if(!Array.isArray(c))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:f="",state:m={},customMinMaxRanges:c})=>{let l=[],g=[];for(let r=0;r<e.length;r++){if(!s(e[r]))continue;const t=o({objRow:e,index:r,state:m}),n=a({objRow:e,index:r,state:m});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}),{scaledOutput:d,scaledConfig:w}=t({arrObj:g,repeat:n,groups:i,minmaxRange:p});const b=Math.floor(y.length*r);let x=y.slice(0,b),M=d.slice(0,b),O=y.slice(b),j=d.slice(b);if(f){let e;if("oversample"===f)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,M),x=e.X,M=e.Y;else{if("undersample"!==f)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,M),x=e.X,M=e.Y}}return{trainX:x,trainY:M,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:f})=>{let m=[];for(let r=0;r<e.length;r++){if(!a(e[r]))continue;const t=n({objRow:e,index:r,state:u});t&&m.push(t)}s&&(m=(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})(m));const{scaledOutput:c,scaledConfig:l}=t({arrObj:m,repeat:r,groups:o,minmaxRange:i,prevConfig:p});return{X:c,configX:l,keyNamesX}},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 f=0;for(const m of Object.keys(n)){const c=i[m],l=n[m],g=a[m],y=s[m],h=o[m],d=t.filter((e=>e===m)).length;let w=0;for(let r=0;r<d;r++)w+=e[f++];const b=w/d;let x;if("normalization"===c?x=b*(g-l)+l:"standardization"===c&&(x=b*h+y),"string"===u[m]){const e=Object.keys(p[m]).find((e=>p[m][e]===x));x=void 0!==e?e:x}r[m]=x}return r}))},f=(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.2.4",
3
+ "version": "1.2.6",
4
4
  "main": "./index.js",
5
5
  "type": "module",
6
6
  "scripts": {
package/src/datasets.js CHANGED
@@ -13,7 +13,8 @@ export const parseTrainingXY = ({
13
13
  shuffle = false,
14
14
  minmaxRange,
15
15
  balancing = '',
16
- state = {}
16
+ state = {},
17
+ customMinMaxRanges
17
18
  }) => {
18
19
  let X = [];
19
20
  let Y = [];
@@ -105,7 +106,8 @@ export const parseProductionX = ({
105
106
  shuffle = false,
106
107
  minmaxRange,
107
108
  state = {},
108
- prevConfig
109
+ prevConfig,
110
+ customMinMaxRanges
109
111
  }) => {
110
112
  let X = [];
111
113
 
package/src/scale.js CHANGED
@@ -1,10 +1,11 @@
1
- export const scaleArrayObj = ({ arrObj, repeat = {}, minmaxRange = [0, 1], groups = {}, prevConfig = null }) => {
1
+ export const scaleArrayObj = ({ arrObj, repeat = {}, minmaxRange = [0, 1], groups = {}, prevConfig = null, customMinMaxRanges = null }) => {
2
2
 
3
3
  const arrObjClone = [...arrObj]
4
- const n = arrObjClone.length;
4
+ const arrObjLen = arrObjClone.length;
5
5
  const firstRow = arrObjClone[0]
6
+ const validCustomMinMaxRanges = typeof customMinMaxRanges === 'object' && customMinMaxRanges !== null
6
7
 
7
- if (n === 0) {
8
+ if (arrObjLen === 0) {
8
9
  return {
9
10
  scaledOutput: [],
10
11
  scaledConfig: {}
@@ -31,6 +32,7 @@ export const scaleArrayObj = ({ arrObj, repeat = {}, minmaxRange = [0, 1], group
31
32
  const countRepeatedKeyNames = repeatedKeyNames.reduce((sum, rep) => sum + rep, 0);
32
33
 
33
34
  config = {
35
+ arrObjLen,
34
36
  rangeMin: minmaxRange[0],
35
37
  rangeMax: minmaxRange[1],
36
38
  inputTypes: {},
@@ -43,7 +45,7 @@ export const scaleArrayObj = ({ arrObj, repeat = {}, minmaxRange = [0, 1], group
43
45
  inputKeyNames,
44
46
  outputKeyNames: new Array(countRepeatedKeyNames),
45
47
  repeatedKeyNames,
46
- }
48
+ }
47
49
 
48
50
  let keyNamesIdx = 0;
49
51
 
@@ -62,6 +64,7 @@ export const scaleArrayObj = ({ arrObj, repeat = {}, minmaxRange = [0, 1], group
62
64
  for (const key of config.inputKeyNames) {
63
65
 
64
66
  const firstType = typeof firstRow[key]
67
+ const thisGroup = findGroup(key, config.groups);
65
68
 
66
69
  if(isValidPrevConfig)
67
70
  {
@@ -84,15 +87,27 @@ export const scaleArrayObj = ({ arrObj, repeat = {}, minmaxRange = [0, 1], group
84
87
  if (firstType === 'string') {
85
88
  config.uniqueStrIdx[key] = {};
86
89
  }
87
-
88
- const thisGroup = findGroup(key, config.groups);
89
-
90
- if (thisGroup) {
91
- config.groupMinMax[thisGroup] = { min: Infinity, max: -Infinity };
92
- } else
90
+
91
+ if(validCustomMinMaxRanges && customMinMaxRanges.hasOwnProperty(key))
93
92
  {
94
- config.min[key] = Infinity;
95
- config.max[key] = -Infinity;
93
+ if (thisGroup)
94
+ {
95
+ config.groupMinMax[thisGroup] = customMinMaxRanges[key]
96
+ }
97
+ else
98
+ {
99
+ config.min[key] = customMinMaxRanges[key].min;
100
+ config.max[key] = -customMinMaxRanges[key].max;
101
+ }
102
+ }
103
+ else {
104
+ if (thisGroup) {
105
+ config.groupMinMax[thisGroup] = { min: Infinity, max: -Infinity };
106
+ }
107
+ else {
108
+ config.min[key] = Infinity;
109
+ config.max[key] = -Infinity;
110
+ }
96
111
  }
97
112
  }
98
113
 
@@ -113,18 +128,22 @@ export const scaleArrayObj = ({ arrObj, repeat = {}, minmaxRange = [0, 1], group
113
128
 
114
129
  const thisGroup = findGroup(key, config.groups);
115
130
 
116
- if (thisGroup) {
117
- config.groupMinMax[thisGroup].min = Math.min(config.groupMinMax[thisGroup].min, value);
118
- config.groupMinMax[thisGroup].max = Math.max(config.groupMinMax[thisGroup].max, value);
119
- } else {
120
- config.min[key] = Math.min(config.min[key], value);
121
- config.max[key] = Math.max(config.max[key], value);
131
+ if(validCustomMinMaxRanges === false || (validCustomMinMaxRanges && !customMinMaxRanges.hasOwnProperty(key)))
132
+ {
133
+ if (thisGroup) {
134
+ config.groupMinMax[thisGroup].min = Math.min(config.groupMinMax[thisGroup].min, value);
135
+ config.groupMinMax[thisGroup].max = Math.max(config.groupMinMax[thisGroup].max, value);
136
+ } else {
137
+ config.min[key] = Math.min(config.min[key], value);
138
+ config.max[key] = Math.max(config.max[key], value);
139
+ }
122
140
  }
141
+
123
142
  }
124
143
  }
125
144
 
126
- const scaledOutput = new Array(n);
127
- for (let i = 0; i < n; i++) {
145
+ const scaledOutput = new Array(arrObjLen);
146
+ for (let i = 0; i < arrObjLen; i++) {
128
147
  const obj = arrObjClone[i];
129
148
  const scaledRow = new Array(config.outputKeyNames.length);
130
149
  let idx = 0;
package/test/test.js CHANGED
@@ -64,7 +64,8 @@ const test = async () => {
64
64
  close: 20
65
65
  },
66
66
  minmaxRange: [-1, 1],
67
- balancing: 'oversample'
67
+ balancing: 'oversample',
68
+ customMinMaxRanges: {}
68
69
  });
69
70
 
70
71