@thi.ng/k-means 0.6.25 → 0.6.27

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.
Files changed (3) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +31 -19
  3. package/package.json +10 -10
package/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2023-08-22T14:39:27Z
3
+ - **Last updated**: 2023-08-27T11:20:59Z
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.
package/README.md CHANGED
@@ -77,37 +77,47 @@ A selection:
77
77
 
78
78
  [Generated API docs](https://docs.thi.ng/umbrella/k-means/)
79
79
 
80
- Example usage:
80
+ Example usage: Clustering cities by lat/lon location
81
81
 
82
- ```ts
83
- import { kmeans, meansLatLon } from "@thi.ng/k-means";
82
+ ```ts tangle:export/readme.ts
84
83
  import { HAVERSINE_LATLON } from "@thi.ng/distance";
84
+ import { kmeans, meansLatLon } from "@thi.ng/k-means";
85
85
 
86
- // data from: https://simplemaps.com/data/world-cities
86
+ // data sourced from:
87
+ // https://github.com/OpenDataFormats/worldcities/blob/master/src/data/cities.json
87
88
  const cities = [
88
- { id: "berlin", latlon: [52.5167, 13.3833] },
89
- { id: "boston", latlon: [42.3188, -71.0846] },
90
- { id: "detroit", latlon: [42.3834, -83.1024] },
91
- { id: "kyoto", latlon: [35.0111, 135.7669] },
92
- { id: "london", latlon: [51.5072, -0.1275] },
93
- { id: "new york", latlon: [40.6943, -73.9249] },
94
- { id: "osaka", latlon: [34.6936, 135.5019] },
95
- { id: "paris", latlon: [48.8566, 2.3522] },
96
- { id: "philadelphia", latlon: [40.0077, -75.1339] },
97
- { id: "tokyo", latlon: [35.6897, 139.6922] },
98
- { id: "vienna", latlon: [48.2083, 16.3731] },
89
+ { id: "anchorage", latlon: [61.21806, -149.90028] },
90
+ { id: "berlin", latlon: [52.52437, 13.41053] },
91
+ { id: "boston", latlon: [42.35843, -71.05977] },
92
+ { id: "calgary", latlon: [51.05011, -114.08529] },
93
+ { id: "cape town", latlon: [-33.92584, 18.42322] },
94
+ { id: "detroit", latlon: [42.33143, -83.04575] },
95
+ { id: "harare", latlon: [-17.82772, 31.05337] },
96
+ { id: "london", latlon: [51.50853, -0.12574] },
97
+ { id: "manila", latlon: [14.6042, 120.9822] },
98
+ { id: "nairobi", latlon: [-1.28333, 36.81667] },
99
+ { id: "new york", latlon: [40.71427, -74.00597] },
100
+ { id: "paris", latlon: [48.85341, 2.3488] },
101
+ { id: "philadelphia", latlon: [39.95233, -75.16379] },
102
+ { id: "portland", latlon: [45.52345, -122.67621] },
103
+ { id: "seoul", latlon: [37.566, 126.9784] },
104
+ { id: "shanghai", latlon: [31.22222, 121.45806] },
105
+ { id: "tokyo", latlon: [35.6895, 139.69171] },
106
+ { id: "vancouver", latlon: [49.24966, -123.11934] },
107
+ { id: "vienna", latlon: [48.20849, 16.37208] },
108
+ { id: "windhoek", latlon: [-22.55941, 17.08323] },
99
109
  ];
100
110
 
101
111
  // cluster based on lat/lon
102
112
  const clusters = kmeans(
103
- 3,
113
+ 5,
104
114
  cities.map((x) => x.latlon),
105
115
  {
106
116
  // custom centroid calc for geo locations
107
117
  // https://docs.thi.ng/umbrella/k-means/functions/meansLatLon.html
108
118
  strategy: meansLatLon,
109
119
  // custom distance function for geo location (default: DIST_SQ)
110
- dist: HAVERSINE_LATLON
120
+ dist: HAVERSINE_LATLON,
111
121
  }
112
122
  );
113
123
 
@@ -116,9 +126,11 @@ for (let c of clusters) {
116
126
  console.log(c.items.map((i) => cities[i].id));
117
127
  }
118
128
 
119
- // [ 'boston', 'detroit', 'new york', 'philadelphia' ]
120
- // [ 'kyoto', 'osaka', 'tokyo' ]
129
+ // [ 'manila', 'seoul', 'shanghai', 'tokyo' ]
121
130
  // [ 'berlin', 'london', 'paris', 'vienna' ]
131
+ // [ 'boston', 'detroit', 'new york', 'philadelphia' ]
132
+ // [ 'cape town', 'harare', 'nairobi', 'windhoek' ]
133
+ // [ 'anchorage', 'calgary', 'portland', 'vancouver' ]
122
134
  ```
123
135
 
124
136
  ## Authors
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/k-means",
3
- "version": "0.6.25",
3
+ "version": "0.6.27",
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",
@@ -34,19 +34,19 @@
34
34
  "test": "testament test"
35
35
  },
36
36
  "dependencies": {
37
- "@thi.ng/api": "^8.9.4",
38
- "@thi.ng/distance": "^2.4.10",
39
- "@thi.ng/errors": "^2.3.4",
40
- "@thi.ng/random": "^3.6.2",
41
- "@thi.ng/vectors": "^7.7.8"
37
+ "@thi.ng/api": "^8.9.5",
38
+ "@thi.ng/distance": "^2.4.12",
39
+ "@thi.ng/errors": "^2.3.5",
40
+ "@thi.ng/random": "^3.6.3",
41
+ "@thi.ng/vectors": "^7.7.10"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@microsoft/api-extractor": "^7.36.4",
45
- "@thi.ng/testament": "^0.3.22",
45
+ "@thi.ng/testament": "^0.3.23",
46
46
  "rimraf": "^5.0.1",
47
47
  "tools": "^0.0.1",
48
- "typedoc": "^0.24.8",
49
- "typescript": "^5.1.6"
48
+ "typedoc": "^0.25.0",
49
+ "typescript": "^5.2.2"
50
50
  },
51
51
  "keywords": [
52
52
  "cluster",
@@ -82,5 +82,5 @@
82
82
  "status": "beta",
83
83
  "year": 2021
84
84
  },
85
- "gitHead": "74cfe3fb8de5bfcbfc1109e67604541cbd7b77aa\n"
85
+ "gitHead": "5929dd20497668496af13415cdf784a4d6f69aa3\n"
86
86
  }