@thi.ng/k-means 0.6.87 → 0.6.89

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/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2024-04-23T07:02:18Z
3
+ - **Last updated**: 2024-06-21T19:34:38Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
@@ -9,6 +9,12 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
9
9
  **Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
10
10
  and/or version bumps of transitive dependencies.
11
11
 
12
+ ### [0.6.89](https://github.com/thi-ng/umbrella/tree/@thi.ng/k-means@0.6.89) (2024-06-21)
13
+
14
+ #### ♻️ Refactoring
15
+
16
+ - enforce uniform naming convention of internal functions ([56992b2](https://github.com/thi-ng/umbrella/commit/56992b2))
17
+
12
18
  ### [0.6.85](https://github.com/thi-ng/umbrella/tree/@thi.ng/k-means@0.6.85) (2024-04-20)
13
19
 
14
20
  #### ♻️ Refactoring
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  [![Mastodon Follow](https://img.shields.io/mastodon/follow/109331703950160316?domain=https%3A%2F%2Fmastodon.thi.ng&style=social)](https://mastodon.thi.ng/@toxi)
8
8
 
9
9
  > [!NOTE]
10
- > This is one of 192 standalone projects, maintained as part
10
+ > This is one of 193 standalone projects, maintained as part
11
11
  > of the [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo
12
12
  > and anti-framework.
13
13
  >
@@ -59,7 +59,7 @@ For Node.js REPL:
59
59
  const kmeans = await import("@thi.ng/k-means");
60
60
  ```
61
61
 
62
- Package sizes (brotli'd, pre-treeshake): ESM: 868 bytes
62
+ Package sizes (brotli'd, pre-treeshake): ESM: 870 bytes
63
63
 
64
64
  ## Dependencies
65
65
 
package/kmeans.js CHANGED
@@ -23,20 +23,18 @@ const kmeans = (k, samples, opts) => {
23
23
  const clusters = new Uint32Array(num).fill(k);
24
24
  let update = true;
25
25
  while (update && maxIter-- > 0) {
26
- update = assign(samples, centroids, clusters, dist);
27
- if (!update)
28
- break;
26
+ update = __assign(samples, centroids, clusters, dist);
27
+ if (!update) break;
29
28
  for (let i = 0; i < k; i++) {
30
29
  const impl = strategy(dim);
31
30
  for (let j = 0; j < num; j++) {
32
31
  i === clusters[j] && impl.update(samples[j]);
33
32
  }
34
33
  const centroid = impl.finish();
35
- if (centroid)
36
- centroids[i] = centroid;
34
+ if (centroid) centroids[i] = centroid;
37
35
  }
38
36
  }
39
- return buildClusters(centroids, clusters);
37
+ return __buildClusters(centroids, clusters);
40
38
  };
41
39
  const initKmeanspp = (k, samples, dist = DIST_SQ, rnd = SYSTEM) => {
42
40
  const num = samples.length;
@@ -53,8 +51,7 @@ const initKmeanspp = (k, samples, dist = DIST_SQ, rnd = SYSTEM) => {
53
51
  psum += d;
54
52
  return d;
55
53
  });
56
- if (!psum)
57
- break;
54
+ if (!psum) break;
58
55
  let id;
59
56
  do {
60
57
  id = weightedRandom(indices, probs, rnd)();
@@ -64,7 +61,7 @@ const initKmeanspp = (k, samples, dist = DIST_SQ, rnd = SYSTEM) => {
64
61
  }
65
62
  return centroidIDs;
66
63
  };
67
- const assign = (samples, centroids, assignments, dist) => {
64
+ const __assign = (samples, centroids, assignments, dist) => {
68
65
  let update = false;
69
66
  for (let i = samples.length; i-- > 0; ) {
70
67
  const id = argmin(samples[i], centroids, dist);
@@ -75,7 +72,7 @@ const assign = (samples, centroids, assignments, dist) => {
75
72
  }
76
73
  return update;
77
74
  };
78
- const buildClusters = (centroids, assignments) => {
75
+ const __buildClusters = (centroids, assignments) => {
79
76
  const clusters = [];
80
77
  for (let i = 0, n = assignments.length; i < n; i++) {
81
78
  const id = assignments[i];
@@ -116,11 +113,9 @@ const meansLatLon = () => {
116
113
  n++;
117
114
  },
118
115
  finish: () => {
119
- if (!n)
120
- return;
116
+ if (!n) return;
121
117
  lat /= n;
122
- if (lat > 180)
123
- lat -= 360;
118
+ if (lat > 180) lat -= 360;
124
119
  lon /= n;
125
120
  return [lat, lon];
126
121
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/k-means",
3
- "version": "0.6.87",
3
+ "version": "0.6.89",
4
4
  "description": "Configurable k-means & k-medians (with k-means++ initialization) for n-D vectors",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -10,7 +10,7 @@
10
10
  "type": "git",
11
11
  "url": "https://github.com/thi-ng/umbrella.git"
12
12
  },
13
- "homepage": "https://github.com/thi-ng/umbrella/tree/develop/packages/k-means#readme",
13
+ "homepage": "https://thi.ng/k-means",
14
14
  "funding": [
15
15
  {
16
16
  "type": "github",
@@ -36,17 +36,17 @@
36
36
  "tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
37
37
  },
38
38
  "dependencies": {
39
- "@thi.ng/api": "^8.11.1",
40
- "@thi.ng/distance": "^2.4.72",
41
- "@thi.ng/errors": "^2.5.6",
42
- "@thi.ng/random": "^3.7.5",
43
- "@thi.ng/vectors": "^7.10.30"
39
+ "@thi.ng/api": "^8.11.3",
40
+ "@thi.ng/distance": "^2.4.74",
41
+ "@thi.ng/errors": "^2.5.8",
42
+ "@thi.ng/random": "^3.8.1",
43
+ "@thi.ng/vectors": "^7.11.0"
44
44
  },
45
45
  "devDependencies": {
46
- "@microsoft/api-extractor": "^7.43.0",
47
- "esbuild": "^0.20.2",
48
- "typedoc": "^0.25.12",
49
- "typescript": "^5.4.3"
46
+ "@microsoft/api-extractor": "^7.47.0",
47
+ "esbuild": "^0.21.5",
48
+ "typedoc": "^0.25.13",
49
+ "typescript": "^5.5.2"
50
50
  },
51
51
  "keywords": [
52
52
  "cluster",
@@ -83,5 +83,5 @@
83
83
  "status": "beta",
84
84
  "year": 2021
85
85
  },
86
- "gitHead": "aed3421c21044c005fbcb7cc37965ccf85a870d2\n"
86
+ "gitHead": "154c95cf9d6bab32174498ec3b5b5d87e42be7f9\n"
87
87
  }