w-cluster 1.0.42 → 1.0.43
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 +2 -2
- package/dist/w-cluster.umd.js +1 -1
- package/dist/w-cluster.umd.js.map +1 -1
- package/docs/DenseMatrix.html +1 -1
- package/docs/DistancePair.html +1 -1
- package/docs/LowerTriangle.html +1 -1
- package/docs/Rec.html +1 -1
- package/docs/Reco.html +1 -1
- package/docs/WCluster.mjs.html +19 -1
- 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 +172 -15
- package/docs/index.html +1 -1
- package/docs/k-medoids_alternating.mjs.html +1 -1
- package/docs/k-medoids_arrayadapter.mjs.html +1 -1
- package/docs/k-medoids_dynmsc.mjs.html +1 -1
- package/docs/k-medoids_fastermsc.mjs.html +1 -1
- package/docs/k-medoids_fasterpam.mjs.html +3 -3
- package/docs/k-medoids_fastmsc.mjs.html +1 -1
- package/docs/k-medoids_fastpam1.mjs.html +1 -1
- package/docs/k-medoids_initialization.mjs.html +1 -1
- package/docs/k-medoids_pam.mjs.html +4 -4
- package/docs/k-medoids_pammedsil.mjs.html +1 -1
- package/docs/k-medoids_pamsil.mjs.html +2 -2
- package/docs/k-medoids_par_fasterpam.mjs.html +2 -2
- package/docs/k-medoids_par_silhouette.mjs.html +1 -1
- package/docs/k-medoids_silhouette.mjs.html +3 -3
- package/docs/k-medoids_util.mjs.html +1 -1
- package/package.json +1 -1
- package/src/WCluster.mjs +18 -0
- package/src/k-medoids/fasterpam.mjs +2 -2
- package/src/k-medoids/pam.mjs +3 -3
- package/src/k-medoids/pamsil.mjs +1 -1
- package/src/k-medoids/par_fasterpam.mjs +1 -1
- package/src/k-medoids/silhouette.mjs +2 -2
|
@@ -62,7 +62,7 @@ import { shuffle } from './initialization.mjs';
|
|
|
62
62
|
* @param med - the list of medoids (mutated in place)
|
|
63
63
|
* @param maxiter - the maximum number of iterations allowed
|
|
64
64
|
* @param rng - random number generator for shuffling the input data
|
|
65
|
-
* @returns { loss, assi, nIter, nSwaps }
|
|
65
|
+
* @returns {Object} { loss, assi, nIter, nSwaps }
|
|
66
66
|
*
|
|
67
67
|
* Panics (throws) when the dissimilarity matrix is not square, or k is 0 or larger than N.
|
|
68
68
|
*/
|
|
@@ -121,7 +121,7 @@ export function par_fasterpam(mat, med, maxiter, rng = Math.random) {
|
|
|
121
121
|
<br class="clear">
|
|
122
122
|
|
|
123
123
|
<footer>
|
|
124
|
-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on
|
|
124
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Fri Oct 16 2026 11:52:32 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
125
125
|
</footer>
|
|
126
126
|
|
|
127
127
|
<script>prettyPrint();</script>
|
|
@@ -113,7 +113,7 @@ export function par_silhouette(mat, assi) {
|
|
|
113
113
|
<br class="clear">
|
|
114
114
|
|
|
115
115
|
<footer>
|
|
116
|
-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on
|
|
116
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Fri Oct 16 2026 11:52:32 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
117
117
|
</footer>
|
|
118
118
|
|
|
119
119
|
<script>prettyPrint();</script>
|
|
@@ -57,7 +57,7 @@ import { arrayAdapter } from './arrayadapter.mjs';
|
|
|
57
57
|
* @param mat - a pairwise distance matrix
|
|
58
58
|
* @param assi - the cluster assignment
|
|
59
59
|
* @param samples - whether to keep the individual samples, or not
|
|
60
|
-
* @returns { sil, samples } where sil is the average silhouette and samples are
|
|
60
|
+
* @returns {Object} { sil, samples } where sil is the average silhouette and samples are
|
|
61
61
|
* the individual silhouette values (empty [] if samples = false)
|
|
62
62
|
*/
|
|
63
63
|
export function silhouette(mat, assi, samples = false) {
|
|
@@ -121,7 +121,7 @@ export function silhouette(mat, assi, samples = false) {
|
|
|
121
121
|
* @param mat - a pairwise distance matrix
|
|
122
122
|
* @param meds - the medoid list
|
|
123
123
|
* @param samples - whether to keep the individual samples, or not
|
|
124
|
-
* @returns { sil, samples } where sil is the average medoid silhouette and
|
|
124
|
+
* @returns {Object} { sil, samples } where sil is the average medoid silhouette and
|
|
125
125
|
* samples are the individual values (empty [] if samples = false)
|
|
126
126
|
*/
|
|
127
127
|
export function medoid_silhouette(mat, meds, samples = false) {
|
|
@@ -180,7 +180,7 @@ export function checked_div(x, y) {
|
|
|
180
180
|
<br class="clear">
|
|
181
181
|
|
|
182
182
|
<footer>
|
|
183
|
-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on
|
|
183
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Fri Oct 16 2026 11:52:32 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
184
184
|
</footer>
|
|
185
185
|
|
|
186
186
|
<script>prettyPrint();</script>
|
|
@@ -122,7 +122,7 @@ export function choose_medoid_within_partition(mat, assi, med, m) {
|
|
|
122
122
|
<br class="clear">
|
|
123
123
|
|
|
124
124
|
<footer>
|
|
125
|
-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on
|
|
125
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Fri Oct 16 2026 11:52:32 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
126
126
|
</footer>
|
|
127
127
|
|
|
128
128
|
<script>prettyPrint();</script>
|
package/package.json
CHANGED
package/src/WCluster.mjs
CHANGED
|
@@ -11,6 +11,15 @@ import WClusterCore from './WClusterCore.mjs'
|
|
|
11
11
|
* @param {Number} [opt.nCompNIPALS=2] 輸入指定降維的維度整數,不能超過數據的維度(各列有效元素數量),預設2
|
|
12
12
|
* @return {Promise} 回傳Promise,resolve回傳指定維數數值的陣列,reject回傳錯誤訊息
|
|
13
13
|
* @example
|
|
14
|
+
*
|
|
15
|
+
* let mat = [
|
|
16
|
+
* [40, 50, 60],
|
|
17
|
+
* [50, 70, 60],
|
|
18
|
+
* [80, 70, 90],
|
|
19
|
+
* [50, 60, 80]
|
|
20
|
+
* ]
|
|
21
|
+
* let resMat = await WCluster.PCA(mat, { nCompNIPALS: 2 })
|
|
22
|
+
* console.log(resMat)
|
|
14
23
|
*/
|
|
15
24
|
async function PCA(data, opt = {}) {
|
|
16
25
|
return WPCAMat(data, opt)
|
|
@@ -31,6 +40,15 @@ async function PCA(data, opt = {}) {
|
|
|
31
40
|
* @param {Number} [opt.seed] 輸入k-means隨機初始化種子整數,僅於mode為'k-means'時生效,給定則分群結果可重現,未提供時為隨機初始化
|
|
32
41
|
* @return {Promise} 回傳Promise,resolve回傳分群後結果物件,keys代表分群有使用到的欄位,ginds代表分群後的指標陣列,gltdt代表分群後的物件陣列,gmat代表分群後的數據陣列(usePCA為true時為PCA降維後數據,可例如取最左2欄代表x,y繪製二維分佈圖;usePCA為false時為原始數據),reject回傳錯誤訊息
|
|
33
42
|
* @example
|
|
43
|
+
*
|
|
44
|
+
* let mat = [
|
|
45
|
+
* [40, 50, 60],
|
|
46
|
+
* [50, 70, 60],
|
|
47
|
+
* [80, 70, 90],
|
|
48
|
+
* [50, 60, 80]
|
|
49
|
+
* ]
|
|
50
|
+
* let res = await WCluster.cluster(mat, { mode: 'k-medoids', kNumber: 2, nCompNIPALS: 2 })
|
|
51
|
+
* console.log(res.ginds)
|
|
34
52
|
*/
|
|
35
53
|
async function cluster(data, opt = {}) {
|
|
36
54
|
try {
|
|
@@ -13,7 +13,7 @@ import { shuffle } from './initialization.mjs';
|
|
|
13
13
|
* @param mat - a pairwise distance matrix
|
|
14
14
|
* @param med - the list of medoids (mutated in place)
|
|
15
15
|
* @param maxiter - the maximum number of iterations allowed
|
|
16
|
-
* @returns { loss, assi, nIter, nSwaps }
|
|
16
|
+
* @returns {Object} { loss, assi, nIter, nSwaps }
|
|
17
17
|
*
|
|
18
18
|
* Panics (throws) when the dissimilarity matrix is not square, or k is 0 or larger than N.
|
|
19
19
|
*/
|
|
@@ -67,7 +67,7 @@ export function fasterpam(mat, med, maxiter) {
|
|
|
67
67
|
* @param med - the list of medoids (mutated in place)
|
|
68
68
|
* @param maxiter - the maximum number of iterations allowed
|
|
69
69
|
* @param rng - random number generator for shuffling the input data
|
|
70
|
-
* @returns { loss, assi, nIter, nSwaps }
|
|
70
|
+
* @returns {Object} { loss, assi, nIter, nSwaps }
|
|
71
71
|
*/
|
|
72
72
|
export function rand_fasterpam(mat, med, maxiter, rng = Math.random) {
|
|
73
73
|
mat = arrayAdapter(mat);
|
package/src/k-medoids/pam.mjs
CHANGED
|
@@ -11,7 +11,7 @@ import { initial_assignment, do_swap } from './fasterpam.mjs';
|
|
|
11
11
|
* @param mat - a pairwise distance matrix
|
|
12
12
|
* @param med - the list of medoids (mutated in place)
|
|
13
13
|
* @param maxiter - the maximum number of iterations allowed
|
|
14
|
-
* @returns { loss, assi, nIter, nSwaps }
|
|
14
|
+
* @returns {Object} { loss, assi, nIter, nSwaps }
|
|
15
15
|
*/
|
|
16
16
|
export function pam_swap(mat, med, maxiter) {
|
|
17
17
|
mat = arrayAdapter(mat);
|
|
@@ -27,7 +27,7 @@ export function pam_swap(mat, med, maxiter) {
|
|
|
27
27
|
*
|
|
28
28
|
* @param mat - a pairwise distance matrix
|
|
29
29
|
* @param k - the number of medoids to pick
|
|
30
|
-
* @returns { loss, assi, meds }
|
|
30
|
+
* @returns {Object} { loss, assi, meds }
|
|
31
31
|
*/
|
|
32
32
|
export function pam_build(mat, k) {
|
|
33
33
|
mat = arrayAdapter(mat);
|
|
@@ -51,7 +51,7 @@ export function pam_build(mat, k) {
|
|
|
51
51
|
* @param mat - a pairwise distance matrix
|
|
52
52
|
* @param k - the number of medoids to pick
|
|
53
53
|
* @param maxiter - the maximum number of iterations allowed
|
|
54
|
-
* @returns { loss, assi, meds, nIter, nSwaps }
|
|
54
|
+
* @returns {Object} { loss, assi, meds, nIter, nSwaps }
|
|
55
55
|
*/
|
|
56
56
|
export function pam(mat, k, maxiter) {
|
|
57
57
|
mat = arrayAdapter(mat);
|
package/src/k-medoids/pamsil.mjs
CHANGED
|
@@ -47,7 +47,7 @@ export function pamsil_swap(mat, med, maxiter) {
|
|
|
47
47
|
|
|
48
48
|
/**
|
|
49
49
|
* Main optimization function of PAMSIL, not exposed (use pamsil_swap or pamsil).
|
|
50
|
-
* @returns {
|
|
50
|
+
* @returns {Array<number>} [loss, n_iter, n_swaps]
|
|
51
51
|
*/
|
|
52
52
|
function pamsil_optimize(mat, med, assi, maxiter) {
|
|
53
53
|
const n = mat.len(), k = med.length;
|
|
@@ -15,7 +15,7 @@ import { shuffle } from './initialization.mjs';
|
|
|
15
15
|
* @param med - the list of medoids (mutated in place)
|
|
16
16
|
* @param maxiter - the maximum number of iterations allowed
|
|
17
17
|
* @param rng - random number generator for shuffling the input data
|
|
18
|
-
* @returns { loss, assi, nIter, nSwaps }
|
|
18
|
+
* @returns {Object} { loss, assi, nIter, nSwaps }
|
|
19
19
|
*
|
|
20
20
|
* Panics (throws) when the dissimilarity matrix is not square, or k is 0 or larger than N.
|
|
21
21
|
*/
|
|
@@ -10,7 +10,7 @@ import { arrayAdapter } from './arrayadapter.mjs';
|
|
|
10
10
|
* @param mat - a pairwise distance matrix
|
|
11
11
|
* @param assi - the cluster assignment
|
|
12
12
|
* @param samples - whether to keep the individual samples, or not
|
|
13
|
-
* @returns { sil, samples } where sil is the average silhouette and samples are
|
|
13
|
+
* @returns {Object} { sil, samples } where sil is the average silhouette and samples are
|
|
14
14
|
* the individual silhouette values (empty [] if samples = false)
|
|
15
15
|
*/
|
|
16
16
|
export function silhouette(mat, assi, samples = false) {
|
|
@@ -74,7 +74,7 @@ export function silhouette(mat, assi, samples = false) {
|
|
|
74
74
|
* @param mat - a pairwise distance matrix
|
|
75
75
|
* @param meds - the medoid list
|
|
76
76
|
* @param samples - whether to keep the individual samples, or not
|
|
77
|
-
* @returns { sil, samples } where sil is the average medoid silhouette and
|
|
77
|
+
* @returns {Object} { sil, samples } where sil is the average medoid silhouette and
|
|
78
78
|
* samples are the individual values (empty [] if samples = false)
|
|
79
79
|
*/
|
|
80
80
|
export function medoid_silhouette(mat, meds, samples = false) {
|