@thi.ng/k-means 0.6.94 → 0.7.0
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 +10 -1
- package/README.md +1 -1
- package/api.d.ts +7 -2
- package/kmeans.js +1 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2024-07-
|
|
3
|
+
- **Last updated**: 2024-07-25T11:43:52Z
|
|
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,15 @@ 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.7.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/k-means@0.7.0) (2024-07-25)
|
|
13
|
+
|
|
14
|
+
#### 🚀 Features
|
|
15
|
+
|
|
16
|
+
- update `KMeansOpts.initial` ([f70073d](https://github.com/thi-ng/umbrella/commit/f70073d))
|
|
17
|
+
- support custom init functions
|
|
18
|
+
- add KMeansInit type alias
|
|
19
|
+
- update handling in `kmeans()`
|
|
20
|
+
|
|
12
21
|
### [0.6.89](https://github.com/thi-ng/umbrella/tree/@thi.ng/k-means@0.6.89) (2024-06-21)
|
|
13
22
|
|
|
14
23
|
#### ♻️ Refactoring
|
package/README.md
CHANGED
package/api.d.ts
CHANGED
|
@@ -5,9 +5,10 @@ import type { ReadonlyVec, Vec } from "@thi.ng/vectors";
|
|
|
5
5
|
export interface KMeansOpts {
|
|
6
6
|
/**
|
|
7
7
|
* Array of initial centroids (i.e. indices of selected points in `samples`
|
|
8
|
-
* array given to {@link kmeans}).
|
|
8
|
+
* array given to {@link kmeans}) or a function producing such. If omitted,
|
|
9
|
+
* {@link initKmeanspp} is used as default.
|
|
9
10
|
*/
|
|
10
|
-
initial: number[]
|
|
11
|
+
initial: number[] | KMeansInit<ReadonlyVec>;
|
|
11
12
|
/**
|
|
12
13
|
* Distance function/metric to use for finding nearest centroid.
|
|
13
14
|
*/
|
|
@@ -25,6 +26,10 @@ export interface KMeansOpts {
|
|
|
25
26
|
*/
|
|
26
27
|
strategy: CentroidStrategy;
|
|
27
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* k-means initialization function, e.g. {@link initKmeanspp}.
|
|
31
|
+
*/
|
|
32
|
+
export type KMeansInit<T extends ReadonlyVec> = (k: number, samples: T[], dist?: IDistance<ReadonlyVec>, rnd?: IRandom) => number[];
|
|
28
33
|
export type CentroidStrategy = Fn<number, {
|
|
29
34
|
update: Fn<ReadonlyVec, void>;
|
|
30
35
|
finish: Fn0<Maybe<Vec>>;
|
package/kmeans.js
CHANGED
|
@@ -16,7 +16,7 @@ const kmeans = (k, samples, opts) => {
|
|
|
16
16
|
};
|
|
17
17
|
const num = samples.length;
|
|
18
18
|
const dim = samples[0].length;
|
|
19
|
-
const centroidIDs = initial
|
|
19
|
+
const centroidIDs = Array.isArray(initial) ? initial : initial ? initial(k, samples, dist, rnd) : initKmeanspp(k, samples, dist, rnd);
|
|
20
20
|
assert(centroidIDs.length > 0, `missing initial centroids`);
|
|
21
21
|
k = centroidIDs.length;
|
|
22
22
|
const centroids = centroidIDs.map((i) => samples[i]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/k-means",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
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",
|
|
@@ -37,10 +37,10 @@
|
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@thi.ng/api": "^8.11.7",
|
|
40
|
-
"@thi.ng/distance": "^2.4.
|
|
40
|
+
"@thi.ng/distance": "^2.4.80",
|
|
41
41
|
"@thi.ng/errors": "^2.5.13",
|
|
42
|
-
"@thi.ng/random": "^4.0.
|
|
43
|
-
"@thi.ng/vectors": "^7.11.
|
|
42
|
+
"@thi.ng/random": "^4.0.1",
|
|
43
|
+
"@thi.ng/vectors": "^7.11.6"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@microsoft/api-extractor": "^7.47.0",
|
|
@@ -83,5 +83,5 @@
|
|
|
83
83
|
"status": "beta",
|
|
84
84
|
"year": 2021
|
|
85
85
|
},
|
|
86
|
-
"gitHead": "
|
|
86
|
+
"gitHead": "ec052b25dff4db6c4d1748e946c38fb5cf403dbf\n"
|
|
87
87
|
}
|