Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@turf/clusters-kmeans

Package Overview
Dependencies
Maintainers
4
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@turf/clusters-kmeans - npm Package Compare versions

Comparing version 5.1.5 to 6.0.0

index.ts

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
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc