learning_model 1.0.43 → 1.0.46

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.
@@ -0,0 +1,32 @@
1
+ import * as tf from '@tensorflow/tfjs';
2
+ import { io } from '@tensorflow/tfjs-core';
3
+
4
+ class DataManager {
5
+ private labelMap: { [key: string]: number } = {};
6
+ private labelIndex: number = 0;
7
+ private data: { label: number, values: number[] }[] = [];
8
+
9
+ async addData(label: string, values: number[]): Promise<void> {
10
+ if (!(label in this.labelMap)) {
11
+ this.labelMap[label] = this.labelIndex++;
12
+ }
13
+ const numericLabel = this.labelMap[label];
14
+ this.data.push({ label: numericLabel, values });
15
+ }
16
+
17
+ convertToTensors() {
18
+ const xs = this.data.map(d => d.values);
19
+ const ys = this.data.map(d => d.label);
20
+
21
+ const xsTensor = tf.tensor2d(xs, [xs.length, xs[0].length], 'float32');
22
+ const ysTensor = tf.tensor1d(ys, 'float32');
23
+
24
+ return { xs: xsTensor, ys: ysTensor };
25
+ }
26
+
27
+ getLabelMap() {
28
+ return this.labelMap;
29
+ }
30
+ }
31
+
32
+ export default DataManager;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "learning_model",
3
- "version": "1.0.43",
3
+ "version": "1.0.46",
4
4
  "description": "learning model develop",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",