@turf/clusters-kmeans
Advanced tools
Comparing version 5.1.5 to 6.0.0
47
index.js
@@ -1,6 +0,6 @@ | ||
import clone from '@turf/clone'; | ||
import { collectionOf } from '@turf/invariant'; | ||
import { coordAll, featureEach } from '@turf/meta'; | ||
import skmeans from 'skmeans'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var clone_1 = require("@turf/clone"); | ||
var meta_1 = require("@turf/meta"); | ||
var skmeans = require("skmeans"); | ||
/** | ||
@@ -28,31 +28,19 @@ * Takes a set of {@link Point|points} and partition them into clusters using the k-mean . | ||
function clustersKmeans(points, options) { | ||
// Optional parameters | ||
options = options || {}; | ||
if (typeof options !== 'object') throw new Error('options is invalid'); | ||
var numberOfClusters = options.numberOfClusters; | ||
var mutate = options.mutate; | ||
// Input validation | ||
collectionOf(points, 'Point', 'Input must contain Points'); | ||
if (options === void 0) { options = {}; } | ||
// Default Params | ||
var count = points.features.length; | ||
numberOfClusters = numberOfClusters || Math.round(Math.sqrt(count / 2)); | ||
options.numberOfClusters = options.numberOfClusters || Math.round(Math.sqrt(count / 2)); | ||
// numberOfClusters can't be greater than the number of points | ||
// fallbacks to count | ||
if (numberOfClusters > count) numberOfClusters = count; | ||
if (options.numberOfClusters > count) | ||
options.numberOfClusters = count; | ||
// Clone points to prevent any mutations (enabled by default) | ||
if (mutate === false || mutate === undefined) points = clone(points, true); | ||
if (options.mutate !== true) | ||
points = clone_1.default(points); | ||
// collect points coordinates | ||
var data = coordAll(points); | ||
var data = meta_1.coordAll(points); | ||
// create seed to avoid skmeans to drift | ||
var initialCentroids = data.slice(0, numberOfClusters); | ||
var initialCentroids = data.slice(0, options.numberOfClusters); | ||
// create skmeans clusters | ||
var skmeansResult = skmeans(data, numberOfClusters, initialCentroids); | ||
var skmeansResult = skmeans(data, options.numberOfClusters, initialCentroids); | ||
// store centroids {clusterId: [number, number]} | ||
@@ -63,5 +51,4 @@ var centroids = {}; | ||
}); | ||
// add associated cluster number | ||
featureEach(points, function (point, index) { | ||
meta_1.featureEach(points, function (point, index) { | ||
var clusterId = skmeansResult.idxs[index]; | ||
@@ -71,6 +58,4 @@ point.properties.cluster = clusterId; | ||
}); | ||
return points; | ||
} | ||
export default clustersKmeans; | ||
exports.default = clustersKmeans; |
{ | ||
"name": "@turf/clusters-kmeans", | ||
"version": "5.1.5", | ||
"version": "6.0.0", | ||
"description": "turf clusters-kmeans module", | ||
"main": "main.js", | ||
"module": "main.es.js", | ||
"types": "index.d.ts", | ||
"main": "index", | ||
"files": [ | ||
"index.js", | ||
"index.d.ts", | ||
"main.js", | ||
"main.es.js" | ||
"index.ts" | ||
], | ||
"scripts": { | ||
"pretest": "rollup -c ../../rollup.config.js", | ||
"test": "node -r @std/esm test.js", | ||
"posttest": "node -r @std/esm ../../scripts/validate-es5-dependencies.js", | ||
"bench": "node -r @std/esm bench.js", | ||
"prepare": "tsc", | ||
"pretest": "tsc", | ||
"test": "node test.js", | ||
"bench": "node bench.js", | ||
"docs": "node ../../scripts/generate-readmes" | ||
@@ -46,5 +42,5 @@ }, | ||
"@std/esm": "*", | ||
"@turf/centroid": "^5.1.5", | ||
"@turf/clusters": "^5.1.5", | ||
"@turf/random": "^5.1.5", | ||
"@turf/centroid": "*", | ||
"@turf/clusters": "*", | ||
"@turf/random": "*", | ||
"benchmark": "*", | ||
@@ -60,12 +56,8 @@ "chromatism": "*", | ||
"dependencies": { | ||
"@turf/clone": "^5.1.5", | ||
"@turf/helpers": "^5.1.5", | ||
"@turf/invariant": "^5.1.5", | ||
"@turf/meta": "^5.1.5", | ||
"@turf/clone": "6.x", | ||
"@turf/helpers": "6.x", | ||
"@turf/invariant": "6.x", | ||
"@turf/meta": "6.x", | ||
"skmeans": "0.9.7" | ||
}, | ||
"@std/esm": { | ||
"esm": "js", | ||
"cjs": true | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10280
5
119
1
+ Added@turf/clone@6.5.0(transitive)
+ Added@turf/helpers@6.5.0(transitive)
+ Added@turf/invariant@6.5.0(transitive)
+ Added@turf/meta@6.5.0(transitive)
- Removed@turf/clone@5.1.5(transitive)
- Removed@turf/helpers@5.1.5(transitive)
- Removed@turf/invariant@5.2.0(transitive)
- Removed@turf/meta@5.2.0(transitive)
Updated@turf/clone@6.x
Updated@turf/helpers@6.x
Updated@turf/invariant@6.x
Updated@turf/meta@6.x