xy-scale 1.4.37 → 1.4.38

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xy-scale",
3
- "version": "1.4.37",
3
+ "version": "1.4.38",
4
4
  "main": "./index.js",
5
5
  "type": "module",
6
6
  "scripts": {
package/src/datasets.js CHANGED
@@ -316,9 +316,7 @@ export const parseTrainingXY = ({
316
316
  keyNames: xKeys,
317
317
  };
318
318
 
319
- const configY = {
320
- keyNames: yKeys,
321
- };
319
+
322
320
 
323
321
  for (let idx = 0; idx < xLen; idx++) {
324
322
  const rowObj = X[idx];
@@ -341,12 +339,33 @@ export const parseTrainingXY = ({
341
339
  flatX[idx] = flatRow;
342
340
  }
343
341
 
342
+ const toLabelKey = value => Array.isArray(value)
343
+ ? JSON.stringify(value)
344
+ : String(value);
345
+
346
+ const initLabelCounts = keyNames =>
347
+ Object.fromEntries(
348
+ keyNames.map(keyName => [keyName, ({})])
349
+ );
350
+
351
+ const configY = {
352
+ keyNames: yKeys,
353
+ labelCounts: initLabelCounts(yKeys),
354
+ };
355
+
344
356
  for (let idx = 0; idx < yLen; idx++) {
345
357
  const rowObj = Y[idx];
346
358
  const flatRow = new Array(yKeys.length);
347
359
 
348
360
  for (let j = 0; j < yKeys.length; j++) {
349
- flatRow[j] = rowObj[yKeys[j]];
361
+ const keyName = yKeys[j];
362
+ const value = rowObj[keyName];
363
+
364
+ flatRow[j] = value;
365
+
366
+ const labelKey = toLabelKey(value);
367
+ configY.labelCounts[keyName][labelKey] =
368
+ (configY.labelCounts[keyName][labelKey] ?? 0) + 1;
350
369
  }
351
370
 
352
371
  flatY[idx] = flatRow;
package/test/test.js CHANGED
@@ -37,6 +37,7 @@ const test = async () => {
37
37
  testX,
38
38
  testY,
39
39
  configX,
40
+ configY
40
41
  } = parseTrainingXY({
41
42
  arrObj,
42
43
  trainingSplit: 0.50,
@@ -61,6 +62,7 @@ const test = async () => {
61
62
  console.log('row_1', {features: trainX[0], labels: trainY[0]})
62
63
 
63
64
  console.log(trainY.length, trainX.length)
65
+ console.log(configY)
64
66
 
65
67
  const timeSteps = arrayToTimesteps(trainX, 10)
66
68
 
@@ -87,13 +89,15 @@ const xCallbackFunc = ({ objRow, index }) => {
87
89
  //callback function used to prepare Y before flattening
88
90
  const yCallbackFunc = ({ objRow, index }) => {
89
91
 
92
+ const curr = objRow[index]
90
93
  const next = objRow[index + 1]
91
94
 
92
95
  //returning null or undefined will exclude current row X and Y from training
93
96
  if (typeof next === 'undefined') return null
94
97
 
95
98
  return {
96
- result: Number(next.close > next.open) //the output shoud must be an array to preserve the key->value order
99
+ label_1: Number(next.close > next.open),
100
+ label_2: Number(next.close > curr.close)
97
101
  }
98
102
  }
99
103