w-cluster 1.0.11 → 1.0.12
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/README.md +32 -14
- package/dist/w-cluster.umd.js +2 -2
- package/dist/w-cluster.umd.js.map +1 -1
- package/dist/w-cluster.wk.umd.js +1 -1
- package/docs/WCluster.mjs.html +31 -13
- package/docs/examples/ex-PCA.html +1 -1
- package/docs/examples/ex-cluster-webworker.html +1 -1
- package/docs/examples/ex-cluster.html +1 -1
- package/docs/global.html +3 -3
- package/docs/index.html +1 -1
- package/g-PCA-nodeworker.mjs +22 -5
- package/g-PCA.mjs +22 -5
- package/g-cluster-nodeworker.mjs +13 -21
- package/g-cluster.mjs +8 -9
- package/package.json +1 -1
- package/src/WCluster.mjs +30 -12
- package/src/WClusterCore.mjs +8 -8
- package/src/WPCAMat.mjs +26 -6
- package/test/PCA.test.mjs +4 -4
- package/test/cluster.test.mjs +54 -2
package/g-cluster.mjs
CHANGED
|
@@ -23,12 +23,12 @@ async function testCluster() {
|
|
|
23
23
|
// ],
|
|
24
24
|
// "gmat": [
|
|
25
25
|
// [
|
|
26
|
-
// [
|
|
26
|
+
// [ 31.31672176507748, 0.2183960452169238 ]
|
|
27
27
|
// ],
|
|
28
28
|
// [
|
|
29
|
-
// [
|
|
30
|
-
// [
|
|
31
|
-
// [
|
|
29
|
+
// [ -22.27637140016484, -4.7649452046492735 ],
|
|
30
|
+
// [ -9.12778006150881, 12.303870466192656 ],
|
|
31
|
+
// [ 0.08742969659617117, -7.757321306760306 ]
|
|
32
32
|
// ]
|
|
33
33
|
// ],
|
|
34
34
|
// "gltdt": [
|
|
@@ -67,12 +67,12 @@ async function testCluster() {
|
|
|
67
67
|
// ],
|
|
68
68
|
// "gmat": [
|
|
69
69
|
// [
|
|
70
|
-
// [
|
|
70
|
+
// [ 31.31672176507748, 0.2183960452169238 ]
|
|
71
71
|
// ],
|
|
72
72
|
// [
|
|
73
|
-
// [
|
|
74
|
-
// [
|
|
75
|
-
// [
|
|
73
|
+
// [ -22.27637140016484, -4.7649452046492735 ],
|
|
74
|
+
// [ -9.12778006150881, 12.303870466192656 ],
|
|
75
|
+
// [ 0.08742969659617117, -7.757321306760306 ]
|
|
76
76
|
// ]
|
|
77
77
|
// ],
|
|
78
78
|
// "gltdt": [
|
|
@@ -94,4 +94,3 @@ testCluster()
|
|
|
94
94
|
})
|
|
95
95
|
|
|
96
96
|
//node --experimental-modules --es-module-specifier-resolution=node g-cluster.mjs
|
|
97
|
-
|
package/package.json
CHANGED
package/src/WCluster.mjs
CHANGED
|
@@ -58,10 +58,28 @@ async function cluster(data, opt = {}) {
|
|
|
58
58
|
* let resMat = await WCluster.PCA(mat, { nCompNIPALS: 2 })
|
|
59
59
|
* console.log(resMat)
|
|
60
60
|
* // => [
|
|
61
|
-
* //
|
|
62
|
-
* //
|
|
63
|
-
* //
|
|
64
|
-
* //
|
|
61
|
+
* // [ -22.27637140016484, -4.7649452046492735 ],
|
|
62
|
+
* // [ -9.12778006150881, 12.303870466192656 ],
|
|
63
|
+
* // [ 31.31672176507748, 0.2183960452169238 ],
|
|
64
|
+
* // [ 0.08742969659617117, -7.757321306760306 ]
|
|
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
|
+
* // [ -22.27637140016484, -4.7649452046492735 ],
|
|
80
|
+
* // [ -9.12778006150881, 12.303870466192656 ],
|
|
81
|
+
* // [ 31.31672176507748, 0.2183960452169238 ],
|
|
82
|
+
* // [ 0.08742969659617117, -7.757321306760306 ]
|
|
65
83
|
* // ]
|
|
66
84
|
*
|
|
67
85
|
* }
|
|
@@ -92,12 +110,12 @@ async function cluster(data, opt = {}) {
|
|
|
92
110
|
* // ],
|
|
93
111
|
* // "gmat": [
|
|
94
112
|
* // [
|
|
95
|
-
* // [
|
|
113
|
+
* // [ 31.31672176507748, 0.2183960452169238 ]
|
|
96
114
|
* // ],
|
|
97
115
|
* // [
|
|
98
|
-
* // [
|
|
99
|
-
* // [
|
|
100
|
-
* // [
|
|
116
|
+
* // [ -22.27637140016484, -4.7649452046492735 ],
|
|
117
|
+
* // [ -9.12778006150881, 12.303870466192656 ],
|
|
118
|
+
* // [ 0.08742969659617117, -7.757321306760306 ]
|
|
101
119
|
* // ]
|
|
102
120
|
* // ],
|
|
103
121
|
* // "gltdt": [
|
|
@@ -136,12 +154,12 @@ async function cluster(data, opt = {}) {
|
|
|
136
154
|
* // ],
|
|
137
155
|
* // "gmat": [
|
|
138
156
|
* // [
|
|
139
|
-
* // [
|
|
157
|
+
* // [ 31.31672176507748, 0.2183960452169238 ]
|
|
140
158
|
* // ],
|
|
141
159
|
* // [
|
|
142
|
-
* // [
|
|
143
|
-
* // [
|
|
144
|
-
* // [
|
|
160
|
+
* // [ -22.27637140016484, -4.7649452046492735 ],
|
|
161
|
+
* // [ -9.12778006150881, 12.303870466192656 ],
|
|
162
|
+
* // [ 0.08742969659617117, -7.757321306760306 ]
|
|
145
163
|
* // ]
|
|
146
164
|
* // ],
|
|
147
165
|
* // "gltdt": [
|
package/src/WClusterCore.mjs
CHANGED
|
@@ -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
|
-
|
|
121
|
-
|
|
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
|
@@ -18,7 +18,7 @@ function WPCAMat(data, opt = {}) {
|
|
|
18
18
|
//scale
|
|
19
19
|
let scale = get(opt, 'scale')
|
|
20
20
|
if (!isbol(scale)) {
|
|
21
|
-
scale =
|
|
21
|
+
scale = false //true: divide by the standard deviation
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
//nCompNIPALS
|
|
@@ -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
|
-
//
|
|
49
|
-
let
|
|
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
|
-
//
|
|
52
|
-
let
|
|
61
|
+
//predict
|
|
62
|
+
let tf = pca.predict(data)
|
|
63
|
+
// console.log('tf', tf)
|
|
53
64
|
|
|
54
65
|
//res
|
|
55
|
-
let res =
|
|
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
|
-
[
|
|
15
|
-
[
|
|
16
|
-
[
|
|
17
|
-
[
|
|
14
|
+
[-22.27637140016484, -4.7649452046492735],
|
|
15
|
+
[-9.12778006150881, 12.303870466192656],
|
|
16
|
+
[31.31672176507748, 0.2183960452169238],
|
|
17
|
+
[0.08742969659617117, -7.757321306760306]
|
|
18
18
|
]
|
|
19
19
|
|
|
20
20
|
it(`should return '${JSON.stringify(clmat)}' when input ${JSON.stringify(mat)}, { nCompNIPALS: 2 }`, async function() {
|
package/test/cluster.test.mjs
CHANGED
|
@@ -12,7 +12,33 @@ describe(`cluster`, function() {
|
|
|
12
12
|
[80, 70, 90],
|
|
13
13
|
[50, 60, 80]
|
|
14
14
|
]
|
|
15
|
-
let clmat = {
|
|
15
|
+
let clmat = {
|
|
16
|
+
'keys': null,
|
|
17
|
+
'ginds': [
|
|
18
|
+
[2],
|
|
19
|
+
[0, 1, 3]
|
|
20
|
+
],
|
|
21
|
+
'gmat': [
|
|
22
|
+
[
|
|
23
|
+
[31.31672176507748, 0.2183960452169238]
|
|
24
|
+
],
|
|
25
|
+
[
|
|
26
|
+
[-22.27637140016484, -4.7649452046492735],
|
|
27
|
+
[-9.12778006150881, 12.303870466192656],
|
|
28
|
+
[0.08742969659617117, -7.757321306760306]
|
|
29
|
+
]
|
|
30
|
+
],
|
|
31
|
+
'gltdt': [
|
|
32
|
+
[
|
|
33
|
+
[80, 70, 90]
|
|
34
|
+
],
|
|
35
|
+
[
|
|
36
|
+
[40, 50, 60],
|
|
37
|
+
[50, 70, 60],
|
|
38
|
+
[50, 60, 80]
|
|
39
|
+
]
|
|
40
|
+
]
|
|
41
|
+
}
|
|
16
42
|
|
|
17
43
|
it(`should return '${JSON.stringify(clmat)}' when input ${JSON.stringify(mat)}, { mode, kNumber: 2, nCompNIPALS: 2 }`, async function() {
|
|
18
44
|
let r = await WCluster.cluster(mat, { mode, kNumber: 2, nCompNIPALS: 2 })
|
|
@@ -25,7 +51,33 @@ describe(`cluster`, function() {
|
|
|
25
51
|
{ name: 'Paul', a: 80, b: 70, c: 90 },
|
|
26
52
|
{ name: 'Fawcett', a: 50, b: 60, c: 80 },
|
|
27
53
|
]
|
|
28
|
-
let clltdt = {
|
|
54
|
+
let clltdt = {
|
|
55
|
+
'keys': ['a', 'b', 'c'],
|
|
56
|
+
'ginds': [
|
|
57
|
+
[2],
|
|
58
|
+
[0, 1, 3]
|
|
59
|
+
],
|
|
60
|
+
'gmat': [
|
|
61
|
+
[
|
|
62
|
+
[31.31672176507748, 0.2183960452169238]
|
|
63
|
+
],
|
|
64
|
+
[
|
|
65
|
+
[-22.27637140016484, -4.7649452046492735],
|
|
66
|
+
[-9.12778006150881, 12.303870466192656],
|
|
67
|
+
[0.08742969659617117, -7.757321306760306]
|
|
68
|
+
]
|
|
69
|
+
],
|
|
70
|
+
'gltdt': [
|
|
71
|
+
[
|
|
72
|
+
{ 'name': 'Paul', 'a': 80, 'b': 70, 'c': 90 }
|
|
73
|
+
],
|
|
74
|
+
[
|
|
75
|
+
{ 'name': 'Cameron', 'a': 40, 'b': 50, 'c': 60 },
|
|
76
|
+
{ 'name': 'Buckley', 'a': 50, 'b': 70, 'c': 60 },
|
|
77
|
+
{ 'name': 'Fawcett', 'a': 50, 'b': 60, 'c': 80 }
|
|
78
|
+
]
|
|
79
|
+
]
|
|
80
|
+
}
|
|
29
81
|
|
|
30
82
|
it(`should return '${JSON.stringify(clltdt)}' when input ${JSON.stringify(ltdt)}, { mode, kNumber: 2, nCompNIPALS: 2 }`, async function() {
|
|
31
83
|
let r = await WCluster.cluster(ltdt, { mode, kNumber: 2, nCompNIPALS: 2 })
|