w-cluster 1.0.10 → 1.0.13

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.
@@ -19,27 +19,105 @@ async function testCluster() {
19
19
  // => {
20
20
  // "keys": null,
21
21
  // "ginds": [
22
- // [ 2 ],
23
- // [ 0, 1, 3 ]
22
+ // [ 0, 1, 3 ],
23
+ // [ 2 ]
24
24
  // ],
25
25
  // "gmat": [
26
26
  // [
27
- // [ 77.39502404588043, 70.65388036857387 ]
27
+ // [ -1.704002697669786, 0.43087564048799354 ],
28
+ // [ -0.2509699164590232, -1.1519035967558147 ],
29
+ // [ -0.03633718671228592, 0.48858292291798827 ]
28
30
  // ],
29
31
  // [
30
- // [ 36.76572825085965, 50.81184119955175 ],
31
- // [ 50.520478881706346, 69.86935352609807 ],
32
- // [ 55.318768821553576, 58.66492490577632 ]
32
+ // [ 1.9913098008410954, 0.23244503334983269 ]
33
33
  // ]
34
34
  // ],
35
35
  // "gltdt": [
36
36
  // [
37
+ // [ 40, 50, 60 ],
38
+ // [ 50, 70, 60 ],
39
+ // [ 50, 60, 80 ]
40
+ // ],
41
+ // [
37
42
  // [ 80, 70, 90 ]
43
+ // ]
44
+ // ]
45
+ // }
46
+
47
+ let mat2 = [
48
+ [1040, 50, 60],
49
+ [1050, 70, 60],
50
+ [1080, 70, 90],
51
+ [1050, 60, 80]
52
+ ]
53
+ console.log('mat2', mat2)
54
+ // => mat [ [ 1040, 50, 60 ], [ 1050, 70, 60 ], [ 1080, 70, 90 ], [ 1050, 60, 80 ] ]
55
+
56
+ let resMat2 = await WCluster.cluster(mat2, { mode, kNumber: 2, nCompNIPALS: 2 })
57
+ console.log(JSON.stringify(resMat2, null, 2))
58
+ // => {
59
+ // "keys": null,
60
+ // "ginds": [
61
+ // [ 0, 1, 3 ],
62
+ // [ 2 ]
63
+ // ],
64
+ // "gmat": [
65
+ // [
66
+ // [ -1.704002697669786, 0.43087564048799354 ],
67
+ // [ -0.2509699164590232, -1.1519035967558147 ],
68
+ // [ -0.03633718671228592, 0.48858292291798827 ]
38
69
  // ],
39
70
  // [
40
- // [ 40, 50, 60 ],
41
- // [ 50, 70, 60 ],
42
- // [ 50, 60, 80 ],
71
+ // [ 1.9913098008410954, 0.23244503334983269 ]
72
+ // ]
73
+ // ],
74
+ // "gltdt": [
75
+ // [
76
+ // [ 1040, 50, 60 ],
77
+ // [ 1050, 70, 60 ],
78
+ // [ 1050, 60, 80 ]
79
+ // ],
80
+ // [
81
+ // [ 1080, 70, 90 ]
82
+ // ]
83
+ // ]
84
+ // }
85
+
86
+ let mat3 = [
87
+ [11040, 50, 60],
88
+ [13050, 70, 60],
89
+ [15080, 70, 90],
90
+ [17050, 60, 80]
91
+ ]
92
+ console.log('mat3', mat3)
93
+ // => mat [ [ 11040, 50, 60 ], [ 13050, 70, 60 ], [ 15080, 70, 90 ], [ 17050, 60, 80 ] ]
94
+
95
+ let resMat3 = await WCluster.cluster(mat3, { mode, kNumber: 2, nCompNIPALS: 2 })
96
+ console.log(JSON.stringify(resMat3, null, 2))
97
+ // => {
98
+ // "keys": null,
99
+ // "ginds": [
100
+ // [ 1, 2, 3 ],
101
+ // [ 0 ]
102
+ // ],
103
+ // "gmat": [
104
+ // [
105
+ // [ -0.3950941652793108, -1.0977355294143445 ],
106
+ // [ 1.3430199944041517, -0.17213692267477554 ],
107
+ // [ 0.912039727864449, 0.778996024938299 ]
108
+ // ],
109
+ // [
110
+ // [ -1.8599655569892897, 0.4908764271508211 ]
111
+ // ]
112
+ // ],
113
+ // "gltdt": [
114
+ // [
115
+ // [ 13050, 70, 60 ],
116
+ // [ 15080, 70, 90 ],
117
+ // [ 17050, 60, 80 ]
118
+ // ],
119
+ // [
120
+ // [ 11040, 50, 60 ]
43
121
  // ]
44
122
  // ]
45
123
  // }
@@ -63,35 +141,27 @@ async function testCluster() {
63
141
  // => {
64
142
  // "keys": [ "a", "b", "c" ],
65
143
  // "ginds": [
66
- // [ 2 ],
67
- // [ 0, 1, 3 ]
144
+ // [ 0, 1, 3 ],
145
+ // [ 2 ]
68
146
  // ],
69
147
  // "gmat": [
70
148
  // [
71
- // [ 77.39502404588043, 70.65388036857387 ]
149
+ // [ -1.704002697669786, 0.43087564048799354 ],
150
+ // [ -0.2509699164590232, -1.1519035967558147 ],
151
+ // [ -0.03633718671228592, 0.48858292291798827 ]
72
152
  // ],
73
153
  // [
74
- // [ 36.76572825085965, 50.81184119955175 ],
75
- // [ 50.520478881706346, 69.86935352609807 ],
76
- // [ 55.318768821553576, 58.66492490577632 ]
154
+ // [ 1.9913098008410954, 0.23244503334983269 ]
77
155
  // ]
78
156
  // ],
79
157
  // "gltdt": [
80
158
  // [
81
- // {
82
- // "name": "Paul", "a": 80, "b": 70, "c": 90
83
- // }
159
+ // { "name": "Cameron", "a": 40, "b": 50, "c": 60 },
160
+ // { "name": "Buckley", "a": 50, "b": 70, "c": 60 },
161
+ // { "name": "Fawcett", "a": 50, "b": 60, "c": 80 }
84
162
  // ],
85
163
  // [
86
- // {
87
- // "name": "Cameron", "a": 40, "b": 50, "c": 60
88
- // },
89
- // {
90
- // "name": "Buckley", "a": 50, "b": 70, "c": 60
91
- // },
92
- // {
93
- // "name": "Fawcett", "a": 50, "b": 60, "c": 80
94
- // }
164
+ // { "name": "Paul", "a": 80, "b": 70, "c": 90 }
95
165
  // ]
96
166
  // ]
97
167
  // }
package/g-cluster.mjs CHANGED
@@ -18,27 +18,105 @@ async function testCluster() {
18
18
  // => {
19
19
  // "keys": null,
20
20
  // "ginds": [
21
- // [ 2 ],
22
- // [ 0, 1, 3 ]
21
+ // [ 0, 1, 3 ],
22
+ // [ 2 ]
23
23
  // ],
24
24
  // "gmat": [
25
25
  // [
26
- // [ 77.39502404588043, 70.65388036857387 ]
26
+ // [ -1.704002697669786, 0.43087564048799354 ],
27
+ // [ -0.2509699164590232, -1.1519035967558147 ],
28
+ // [ -0.03633718671228592, 0.48858292291798827 ]
27
29
  // ],
28
30
  // [
29
- // [ 36.76572825085965, 50.81184119955175 ],
30
- // [ 50.520478881706346, 69.86935352609807 ],
31
- // [ 55.318768821553576, 58.66492490577632 ]
31
+ // [ 1.9913098008410954, 0.23244503334983269 ]
32
32
  // ]
33
33
  // ],
34
34
  // "gltdt": [
35
35
  // [
36
- // [ 80, 70, 90 ]
37
- // ],
38
- // [
39
36
  // [ 40, 50, 60 ],
40
37
  // [ 50, 70, 60 ],
41
38
  // [ 50, 60, 80 ]
39
+ // ],
40
+ // [
41
+ // [ 80, 70, 90 ]
42
+ // ]
43
+ // ]
44
+ // }
45
+
46
+ let mat2 = [
47
+ [1040, 50, 60],
48
+ [1050, 70, 60],
49
+ [1080, 70, 90],
50
+ [1050, 60, 80]
51
+ ]
52
+ console.log('mat2', mat2)
53
+ // => mat [ [ 1040, 50, 60 ], [ 1050, 70, 60 ], [ 1080, 70, 90 ], [ 1050, 60, 80 ] ]
54
+
55
+ let resMat2 = await WCluster.cluster(mat2, { mode, kNumber: 2, nCompNIPALS: 2 })
56
+ console.log(JSON.stringify(resMat2, null, 2))
57
+ // => {
58
+ // "keys": null,
59
+ // "ginds": [
60
+ // [ 0, 1, 3 ],
61
+ // [ 2 ]
62
+ // ],
63
+ // "gmat": [
64
+ // [
65
+ // [ -1.704002697669786, 0.43087564048799354 ],
66
+ // [ -0.2509699164590232, -1.1519035967558147 ],
67
+ // [ -0.03633718671228592, 0.48858292291798827 ]
68
+ // ],
69
+ // [
70
+ // [ 1.9913098008410954, 0.23244503334983269 ]
71
+ // ]
72
+ // ],
73
+ // "gltdt": [
74
+ // [
75
+ // [ 1040, 50, 60 ],
76
+ // [ 1050, 70, 60 ],
77
+ // [ 1050, 60, 80 ]
78
+ // ],
79
+ // [
80
+ // [ 1080, 70, 90 ]
81
+ // ]
82
+ // ]
83
+ // }
84
+
85
+ let mat3 = [
86
+ [11040, 50, 60],
87
+ [13050, 70, 60],
88
+ [15080, 70, 90],
89
+ [17050, 60, 80]
90
+ ]
91
+ console.log('mat3', mat3)
92
+ // => mat [ [ 11040, 50, 60 ], [ 13050, 70, 60 ], [ 15080, 70, 90 ], [ 17050, 60, 80 ] ]
93
+
94
+ let resMat3 = await WCluster.cluster(mat3, { mode, kNumber: 2, nCompNIPALS: 2 })
95
+ console.log(JSON.stringify(resMat3, null, 2))
96
+ // => {
97
+ // "keys": null,
98
+ // "ginds": [
99
+ // [ 1, 2, 3 ],
100
+ // [ 0 ]
101
+ // ],
102
+ // "gmat": [
103
+ // [
104
+ // [ -0.3950941652793108, -1.0977355294143445 ],
105
+ // [ 1.3430199944041517, -0.17213692267477554 ],
106
+ // [ 0.912039727864449, 0.778996024938299 ]
107
+ // ],
108
+ // [
109
+ // [ -1.8599655569892897, 0.4908764271508211 ]
110
+ // ]
111
+ // ],
112
+ // "gltdt": [
113
+ // [
114
+ // [ 13050, 70, 60 ],
115
+ // [ 15080, 70, 90 ],
116
+ // [ 17050, 60, 80 ]
117
+ // ],
118
+ // [
119
+ // [ 11040, 50, 60 ]
42
120
  // ]
43
121
  // ]
44
122
  // }
@@ -62,27 +140,27 @@ async function testCluster() {
62
140
  // => {
63
141
  // "keys": [ "a", "b", "c" ],
64
142
  // "ginds": [
65
- // [ 2 ],
66
- // [ 0, 1, 3 ]
143
+ // [ 0, 1, 3 ],
144
+ // [ 2 ]
67
145
  // ],
68
146
  // "gmat": [
69
147
  // [
70
- // [ 77.39502404588043, 70.65388036857387 ]
148
+ // [ -1.704002697669786, 0.43087564048799354 ],
149
+ // [ -0.2509699164590232, -1.1519035967558147 ],
150
+ // [ -0.03633718671228592, 0.48858292291798827 ]
71
151
  // ],
72
152
  // [
73
- // [ 36.76572825085965, 50.81184119955175 ],
74
- // [ 50.520478881706346, 69.86935352609807 ],
75
- // [ 55.318768821553576, 58.66492490577632 ]
153
+ // [ 1.9913098008410954, 0.23244503334983269 ]
76
154
  // ]
77
155
  // ],
78
156
  // "gltdt": [
79
157
  // [
80
- // { "name": "Paul", "a": 80, "b": 70, "c": 90 }
81
- // ],
82
- // [
83
158
  // { "name": "Cameron", "a": 40, "b": 50, "c": 60 },
84
159
  // { "name": "Buckley", "a": 50, "b": 70, "c": 60 },
85
160
  // { "name": "Fawcett", "a": 50, "b": 60, "c": 80 }
161
+ // ],
162
+ // [
163
+ // { "name": "Paul", "a": 80, "b": 70, "c": 90 }
86
164
  // ]
87
165
  // ]
88
166
  // }
@@ -94,4 +172,3 @@ testCluster()
94
172
  })
95
173
 
96
174
  //node --experimental-modules --es-module-specifier-resolution=node g-cluster.mjs
97
-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "w-cluster",
3
- "version": "1.0.10",
3
+ "version": "1.0.13",
4
4
  "main": "dist/w-cluster.umd.js",
5
5
  "dependencies": {
6
6
  "lodash": "^4.17.21",
package/src/WCluster.mjs CHANGED
@@ -58,10 +58,46 @@ async function cluster(data, opt = {}) {
58
58
  * let resMat = await WCluster.PCA(mat, { nCompNIPALS: 2 })
59
59
  * console.log(resMat)
60
60
  * // => [
61
- * // [ 36.76572825085965, 50.81184119955175, 61.992939427698765 ],
62
- * // [ 50.520478881706346, 69.86935352609807, 59.679283942385844 ],
63
- * // [ 77.39502404588043, 70.65388036857387, 91.60517102143689 ],
64
- * // [ 55.318768821553576, 58.66492490577632, 76.7226056084785 ]
61
+ * // [ -1.704002697669786, 0.43087564048799354 ],
62
+ * // [ -0.2509699164590232, -1.1519035967558147 ],
63
+ * // [ 1.9913098008410954, 0.23244503334983269 ],
64
+ * // [ -0.03633718671228592, 0.48858292291798827 ]
65
+ * // ]
66
+ *
67
+ * let mat2 = [
68
+ * [1040, 50, 60],
69
+ * [1050, 70, 60],
70
+ * [1080, 70, 90],
71
+ * [1050, 60, 80]
72
+ * ]
73
+ * console.log('mat2', mat2)
74
+ * // => mat [ [ 1040, 50, 60 ], [ 1050, 70, 60 ], [ 1080, 70, 90 ], [ 1050, 60, 80 ] ]
75
+ *
76
+ * let resMat2 = await WCluster.PCA(mat2, { nCompNIPALS: 2 })
77
+ * console.log(resMat2)
78
+ * // => [
79
+ * // [ -1.704002697669786, 0.43087564048799354 ],
80
+ * // [ -0.2509699164590232, -1.1519035967558147 ],
81
+ * // [ 1.9913098008410954, 0.23244503334983269 ],
82
+ * // [ -0.03633718671228592, 0.48858292291798827 ]
83
+ * // ]
84
+ *
85
+ * let mat3 = [
86
+ * [11040, 50, 60],
87
+ * [13050, 70, 60],
88
+ * [15080, 70, 90],
89
+ * [17050, 60, 80]
90
+ * ]
91
+ * console.log('mat3', mat3)
92
+ * // => mat [ [ 11040, 50, 60 ], [ 13050, 70, 60 ], [ 15080, 70, 90 ], [ 17050, 60, 80 ] ]
93
+ *
94
+ * let resMat3 = await WCluster.PCA(mat3, { nCompNIPALS: 2 })
95
+ * console.log(resMat3)
96
+ * // => [
97
+ * // [ -1.8599655569892897, 0.4908764271508211 ],
98
+ * // [ -0.3950941652793108, -1.0977355294143445 ],
99
+ * // [ 1.3430199944041517, -0.17213692267477554 ],
100
+ * // [ 0.912039727864449, 0.778996024938299 ]
65
101
  * // ]
66
102
  *
67
103
  * }
@@ -87,27 +123,105 @@ async function cluster(data, opt = {}) {
87
123
  * // => {
88
124
  * // "keys": null,
89
125
  * // "ginds": [
90
- * // [ 2 ],
91
- * // [ 0, 1, 3 ]
126
+ * // [ 0, 1, 3 ],
127
+ * // [ 2 ]
92
128
  * // ],
93
129
  * // "gmat": [
94
130
  * // [
95
- * // [ 77.39502404588043, 70.65388036857387 ]
131
+ * // [ -1.704002697669786, 0.43087564048799354 ],
132
+ * // [ -0.2509699164590232, -1.1519035967558147 ],
133
+ * // [ -0.03633718671228592, 0.48858292291798827 ]
96
134
  * // ],
97
135
  * // [
98
- * // [ 36.76572825085965, 50.81184119955175 ],
99
- * // [ 50.520478881706346, 69.86935352609807 ],
100
- * // [ 55.318768821553576, 58.66492490577632 ]
136
+ * // [ 1.9913098008410954, 0.23244503334983269 ]
101
137
  * // ]
102
138
  * // ],
103
139
  * // "gltdt": [
104
140
  * // [
105
- * // [ 80, 70, 90 ]
106
- * // ],
107
- * // [
108
141
  * // [ 40, 50, 60 ],
109
142
  * // [ 50, 70, 60 ],
110
143
  * // [ 50, 60, 80 ]
144
+ * // ],
145
+ * // [
146
+ * // [ 80, 70, 90 ]
147
+ * // ]
148
+ * // ]
149
+ * // }
150
+ *
151
+ * let mat2 = [
152
+ * [1040, 50, 60],
153
+ * [1050, 70, 60],
154
+ * [1080, 70, 90],
155
+ * [1050, 60, 80]
156
+ * ]
157
+ * console.log('mat2', mat2)
158
+ * // => mat [ [ 1040, 50, 60 ], [ 1050, 70, 60 ], [ 1080, 70, 90 ], [ 1050, 60, 80 ] ]
159
+ *
160
+ * let resMat2 = await WCluster.cluster(mat2, { mode, kNumber: 2, nCompNIPALS: 2 })
161
+ * console.log(JSON.stringify(resMat2, null, 2))
162
+ * // => {
163
+ * // "keys": null,
164
+ * // "ginds": [
165
+ * // [ 0, 1, 3 ],
166
+ * // [ 2 ]
167
+ * // ],
168
+ * // "gmat": [
169
+ * // [
170
+ * // [ -1.704002697669786, 0.43087564048799354 ],
171
+ * // [ -0.2509699164590232, -1.1519035967558147 ],
172
+ * // [ -0.03633718671228592, 0.48858292291798827 ]
173
+ * // ],
174
+ * // [
175
+ * // [ 1.9913098008410954, 0.23244503334983269 ]
176
+ * // ]
177
+ * // ],
178
+ * // "gltdt": [
179
+ * // [
180
+ * // [ 1040, 50, 60 ],
181
+ * // [ 1050, 70, 60 ],
182
+ * // [ 1050, 60, 80 ]
183
+ * // ],
184
+ * // [
185
+ * // [ 1080, 70, 90 ]
186
+ * // ]
187
+ * // ]
188
+ * // }
189
+ *
190
+ * let mat3 = [
191
+ * [11040, 50, 60],
192
+ * [13050, 70, 60],
193
+ * [15080, 70, 90],
194
+ * [17050, 60, 80]
195
+ * ]
196
+ * console.log('mat3', mat3)
197
+ * // => mat [ [ 11040, 50, 60 ], [ 13050, 70, 60 ], [ 15080, 70, 90 ], [ 17050, 60, 80 ] ]
198
+ *
199
+ * let resMat3 = await WCluster.cluster(mat3, { mode, kNumber: 2, nCompNIPALS: 2 })
200
+ * console.log(JSON.stringify(resMat3, null, 2))
201
+ * // => {
202
+ * // "keys": null,
203
+ * // "ginds": [
204
+ * // [ 1, 2, 3 ],
205
+ * // [ 0 ]
206
+ * // ],
207
+ * // "gmat": [
208
+ * // [
209
+ * // [ -0.3950941652793108, -1.0977355294143445 ],
210
+ * // [ 1.3430199944041517, -0.17213692267477554 ],
211
+ * // [ 0.912039727864449, 0.778996024938299 ]
212
+ * // ],
213
+ * // [
214
+ * // [ -1.8599655569892897, 0.4908764271508211 ]
215
+ * // ]
216
+ * // ],
217
+ * // "gltdt": [
218
+ * // [
219
+ * // [ 13050, 70, 60 ],
220
+ * // [ 15080, 70, 90 ],
221
+ * // [ 17050, 60, 80 ]
222
+ * // ],
223
+ * // [
224
+ * // [ 11040, 50, 60 ]
111
225
  * // ]
112
226
  * // ]
113
227
  * // }
@@ -131,27 +245,27 @@ async function cluster(data, opt = {}) {
131
245
  * // => {
132
246
  * // "keys": [ "a", "b", "c" ],
133
247
  * // "ginds": [
134
- * // [ 2 ],
135
- * // [ 0, 1, 3 ]
248
+ * // [ 0, 1, 3 ],
249
+ * // [ 2 ]
136
250
  * // ],
137
251
  * // "gmat": [
138
252
  * // [
139
- * // [ 77.39502404588043, 70.65388036857387 ]
253
+ * // [ -1.704002697669786, 0.43087564048799354 ],
254
+ * // [ -0.2509699164590232, -1.1519035967558147 ],
255
+ * // [ -0.03633718671228592, 0.48858292291798827 ]
140
256
  * // ],
141
257
  * // [
142
- * // [ 36.76572825085965, 50.81184119955175 ],
143
- * // [ 50.520478881706346, 69.86935352609807 ],
144
- * // [ 55.318768821553576, 58.66492490577632 ]
258
+ * // [ 1.9913098008410954, 0.23244503334983269 ]
145
259
  * // ]
146
260
  * // ],
147
261
  * // "gltdt": [
148
262
  * // [
149
- * // { "name": "Paul", "a": 80, "b": 70, "c": 90 }
150
- * // ],
151
- * // [
152
263
  * // { "name": "Cameron", "a": 40, "b": 50, "c": 60 },
153
264
  * // { "name": "Buckley", "a": 50, "b": 70, "c": 60 },
154
265
  * // { "name": "Fawcett", "a": 50, "b": 60, "c": 80 }
266
+ * // ],
267
+ * // [
268
+ * // { "name": "Paul", "a": 80, "b": 70, "c": 90 }
155
269
  * // ]
156
270
  * // ]
157
271
  * // }
@@ -1,7 +1,7 @@
1
1
  import get from 'lodash/get'
2
2
  import each from 'lodash/each'
3
3
  import size from 'lodash/size'
4
- import take from 'lodash/take'
4
+ // import take from 'lodash/take'
5
5
  import map from 'lodash/map'
6
6
  import values from 'lodash/values'
7
7
  import dtpick from 'wsemi/src/dtpick.mjs'
@@ -68,7 +68,7 @@ function WClusterCore(data, opt = {}) {
68
68
  nCompNIPALS = 2
69
69
  }
70
70
  nCompNIPALS = cint(nCompNIPALS)
71
- console.log('nCompNIPALS', nCompNIPALS)
71
+ // console.log('nCompNIPALS', nCompNIPALS)
72
72
 
73
73
  //mode, 由WDataCluster檢核與給予預設值
74
74
  let mode = get(opt, 'mode')
@@ -115,12 +115,12 @@ function WClusterCore(data, opt = {}) {
115
115
  //WPCAMat
116
116
  let pcad = WPCAMat(mat, { nCompNIPALS })
117
117
 
118
- //保留維度
119
- pcad = map(pcad, (v) => {
120
- v = take(v, nCompNIPALS)
121
- return v
122
- })
123
- // console.log('pcad', pcad)
118
+ // //reduce
119
+ // pcad = map(pcad, (v) => {
120
+ // v = take(v, nCompNIPALS)
121
+ // return v
122
+ // })
123
+ // // console.log('pcad', pcad)
124
124
 
125
125
  //WClusterMat
126
126
  let ginds = WClusterMat(pcad, { kNumber, mode })
package/src/WPCAMat.mjs CHANGED
@@ -44,15 +44,35 @@ function WPCAMat(data, opt = {}) {
44
44
  //pca
45
45
  let method = 'NIPALS' //SVD NIPALS
46
46
  let pca = new PCA(data, { method, scale, nCompNIPALS })
47
+ // console.log('pca', pca)
47
48
 
48
- //transform
49
- let tf = pca.predict(data)
49
+ // //getEigenvalues
50
+ // let eiva = pca.getEigenvalues()
51
+ // // console.log('eiva', eiva)
52
+
53
+ // //getEigenvectors
54
+ // let eivt = pca.getEigenvectors()
55
+ // // console.log('eivt', eivt)
56
+
57
+ // //getCumulativeVariance
58
+ // let cmv = pca.getCumulativeVariance()
59
+ // // console.log('cmv', cmv)
50
60
 
51
- //inverse_transform
52
- let itf = pca.invert(tf)
61
+ //predict
62
+ let tf = pca.predict(data)
63
+ // console.log('tf', tf)
53
64
 
54
65
  //res
55
- let res = itf.toJSON()
66
+ let res = tf.toJSON()
67
+ // console.log('res', res)
68
+
69
+ // //invert
70
+ // let itf = pca.invert(tf)
71
+ // console.log('itf', itf)
72
+
73
+ // //res
74
+ // let res = itf.toJSON()
75
+ // // console.log('res', res)
56
76
 
57
77
  return res
58
78
  }
package/test/PCA.test.mjs CHANGED
@@ -11,10 +11,10 @@ describe(`PCA`, function() {
11
11
  [50, 60, 80]
12
12
  ]
13
13
  let clmat = [
14
- [36.76572825085965, 50.81184119955175, 61.992939427698765],
15
- [50.520478881706346, 69.86935352609807, 59.679283942385844],
16
- [77.39502404588043, 70.65388036857387, 91.60517102143689],
17
- [55.318768821553576, 58.66492490577632, 76.7226056084785]
14
+ [-1.704002697669786, 0.43087564048799354],
15
+ [-0.2509699164590232, -1.1519035967558147],
16
+ [1.9913098008410954, 0.23244503334983269],
17
+ [-0.03633718671228592, 0.48858292291798827]
18
18
  ]
19
19
 
20
20
  it(`should return '${JSON.stringify(clmat)}' when input ${JSON.stringify(mat)}, { nCompNIPALS: 2 }`, async function() {
@@ -22,6 +22,42 @@ describe(`PCA`, function() {
22
22
  assert.strict.deepStrictEqual(r, clmat)
23
23
  })
24
24
 
25
+ let mat2 = [
26
+ [40, 50, 60],
27
+ [50, 70, 60],
28
+ [80, 70, 90],
29
+ [50, 60, 80]
30
+ ]
31
+ let clmat2 = [
32
+ [-1.704002697669786, 0.43087564048799354],
33
+ [-0.2509699164590232, -1.1519035967558147],
34
+ [1.9913098008410954, 0.23244503334983269],
35
+ [-0.03633718671228592, 0.48858292291798827]
36
+ ]
37
+
38
+ it(`should return '${JSON.stringify(clmat2)}' when input ${JSON.stringify(mat2)}, { nCompNIPALS: 2 }`, async function() {
39
+ let r = await WCluster.PCA(mat2, { nCompNIPALS: 2 })
40
+ assert.strict.deepStrictEqual(r, clmat2)
41
+ })
42
+
43
+ let mat3 = [
44
+ [40, 50, 60],
45
+ [50, 70, 60],
46
+ [80, 70, 90],
47
+ [50, 60, 80]
48
+ ]
49
+ let clmat3 = [
50
+ [-1.704002697669786, 0.43087564048799354],
51
+ [-0.2509699164590232, -1.1519035967558147],
52
+ [1.9913098008410954, 0.23244503334983269],
53
+ [-0.03633718671228592, 0.48858292291798827]
54
+ ]
55
+
56
+ it(`should return '${JSON.stringify(clmat3)}' when input ${JSON.stringify(mat3)}, { nCompNIPALS: 2 }`, async function() {
57
+ let r = await WCluster.PCA(mat3, { nCompNIPALS: 2 })
58
+ assert.strict.deepStrictEqual(r, clmat3)
59
+ })
60
+
25
61
  it(`should return 'Error: data is not eff. array' when input 123`, async function() {
26
62
  let r = ''
27
63
  await WCluster.PCA(123)