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/g-cluster.mjs CHANGED
@@ -23,12 +23,12 @@ async function testCluster() {
23
23
  // ],
24
24
  // "gmat": [
25
25
  // [
26
- // [ 77.39502404588043, 70.65388036857387 ]
26
+ // [ 31.31672176507748, 0.2183960452169238 ]
27
27
  // ],
28
28
  // [
29
- // [ 36.76572825085965, 50.81184119955175 ],
30
- // [ 50.520478881706346, 69.86935352609807 ],
31
- // [ 55.318768821553576, 58.66492490577632 ]
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
- // [ 77.39502404588043, 70.65388036857387 ]
70
+ // [ 31.31672176507748, 0.2183960452169238 ]
71
71
  // ],
72
72
  // [
73
- // [ 36.76572825085965, 50.81184119955175 ],
74
- // [ 50.520478881706346, 69.86935352609807 ],
75
- // [ 55.318768821553576, 58.66492490577632 ]
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "w-cluster",
3
- "version": "1.0.11",
3
+ "version": "1.0.12",
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,28 @@ 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
+ * // [ -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
- * // [ 77.39502404588043, 70.65388036857387 ]
113
+ * // [ 31.31672176507748, 0.2183960452169238 ]
96
114
  * // ],
97
115
  * // [
98
- * // [ 36.76572825085965, 50.81184119955175 ],
99
- * // [ 50.520478881706346, 69.86935352609807 ],
100
- * // [ 55.318768821553576, 58.66492490577632 ]
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
- * // [ 77.39502404588043, 70.65388036857387 ]
157
+ * // [ 31.31672176507748, 0.2183960452169238 ]
140
158
  * // ],
141
159
  * // [
142
- * // [ 36.76572825085965, 50.81184119955175 ],
143
- * // [ 50.520478881706346, 69.86935352609807 ],
144
- * // [ 55.318768821553576, 58.66492490577632 ]
160
+ * // [ -22.27637140016484, -4.7649452046492735 ],
161
+ * // [ -9.12778006150881, 12.303870466192656 ],
162
+ * // [ 0.08742969659617117, -7.757321306760306 ]
145
163
  * // ]
146
164
  * // ],
147
165
  * // "gltdt": [
@@ -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
@@ -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 = true //true: divide by the standard deviation
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
- //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
+ [-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() {
@@ -12,7 +12,33 @@ describe(`cluster`, function() {
12
12
  [80, 70, 90],
13
13
  [50, 60, 80]
14
14
  ]
15
- let clmat = { 'keys': null, 'ginds': [[2], [0, 1, 3]], 'gltdt': [[[80, 70, 90]], [[40, 50, 60], [50, 70, 60], [50, 60, 80]]], 'gmat': [[[77.39502404588043, 70.65388036857387]], [[36.76572825085965, 50.81184119955175], [50.520478881706346, 69.86935352609807], [55.318768821553576, 58.66492490577632]]] }
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 = { 'keys': ['a', 'b', 'c'], 'ginds': [[2], [0, 1, 3]], 'gltdt': [[{ 'name': 'Paul', 'a': 80, 'b': 70, 'c': 90 }], [{ 'name': 'Cameron', 'a': 40, 'b': 50, 'c': 60 }, { 'name': 'Buckley', 'a': 50, 'b': 70, 'c': 60 }, { 'name': 'Fawcett', 'a': 50, 'b': 60, 'c': 80 }]], 'gmat': [[[77.39502404588043, 70.65388036857387]], [[36.76572825085965, 50.81184119955175], [50.520478881706346, 69.86935352609807], [55.318768821553576, 58.66492490577632]]] }
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 })