Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement @turf/clusters-dbscan module #812

Merged
merged 33 commits into from
Jul 14, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d0d8970
Implement `@turf/clusters-distance` module
DenisCarriere Jun 21, 2017
24cf66d
Update yarn lock
DenisCarriere Jun 21, 2017
8669d30
Update debug file
DenisCarriere Jun 21, 2017
e5fb827
simplified calculation (run almost x2 faster);
stebogit Jul 7, 2017
17ca549
Convert index.js to ES5
DenisCarriere Jul 12, 2017
ed0e48a
Publish new clusters-distance approach
DenisCarriere Jul 12, 2017
88d3953
Add minPoints to tests param
DenisCarriere Jul 12, 2017
cf53d66
Update Typescript tests
DenisCarriere Jul 12, 2017
4636f3a
Merge branch 'master' into clusters-distance
DenisCarriere Jul 12, 2017
0893af2
added units parameter; added parameters validation and throw tests
stebogit Jul 13, 2017
359815a
Suggested DBSCAN implementation for `@turf/clusters-distance` (#840)
stebogit Jul 14, 2017
a14fa69
Update Typescript Defintion (3 outputs)
DenisCarriere Jul 14, 2017
0a60b90
Merge branch 'master' into clusters-distance
DenisCarriere Jul 14, 2017
144ef79
Merge branch 'clusters-distance' of /~https://github.com/Turfjs/turf in…
stebogit Jul 14, 2017
ef76c37
Add geokdbush as reference to repo
DenisCarriere Jul 14, 2017
7bee88f
Single line JSDocs param
DenisCarriere Jul 14, 2017
3eb3d66
Fix tests (results.points)
DenisCarriere Jul 14, 2017
07dea46
Make both index + index.geokdbush work
DenisCarriere Jul 14, 2017
62e4e91
Place Geokdbush to DevDependencies
DenisCarriere Jul 14, 2017
63275fc
Fix noise issue
DenisCarriere Jul 14, 2017
82485d8
Prevent input mutation & add edges
DenisCarriere Jul 14, 2017
8a45889
Major changes
DenisCarriere Jul 14, 2017
c2be7be
Create a set of clusters to colorize
DenisCarriere Jul 14, 2017
01e92de
Define edges with cross
DenisCarriere Jul 14, 2017
01bc50b
Add CentroidFromProperty to tests
DenisCarriere Jul 14, 2017
d3a3166
Updates based on @stebogit comments
DenisCarriere Jul 14, 2017
28436e7
Update Readme
DenisCarriere Jul 14, 2017
d926702
Update benchmark results & drop geokdbush
DenisCarriere Jul 14, 2017
7fe4acf
Add noisePoint.properties fallback incase no props
DenisCarriere Jul 14, 2017
67e9071
Added Array of Features handling
DenisCarriere Jul 14, 2017
e7fb4a8
Update library to clusters-dbscan
DenisCarriere Jul 14, 2017
9bdd634
Rename folder to clusters-dbscan
DenisCarriere Jul 14, 2017
af57608
Update readme to clusters-dbscan
DenisCarriere Jul 14, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
simplified calculation (run almost x2 faster);
removed id attribute from output points;
  • Loading branch information
stebogit committed Jul 7, 2017
commit e5fb82761c6f4218a07d301b8f0bfd1400b9d312
20 changes: 10 additions & 10 deletions packages/turf-clusters-distance/bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ const fixtures = fs.readdirSync(directory).map(filename => {
* Benchmark Results
*
* // Clusters distance
* fiji: 2.345ms
* many-points: 11.023ms
* points-with-properties: 0.178ms
* points1: 0.144ms
* points2: 0.196ms
* fiji x 659,547 ops/sec ±2.59% (84 runs sampled)
* many-points x 8,193 ops/sec ±4.55% (81 runs sampled)
* points-with-properties x 663,783 ops/sec ±1.61% (83 runs sampled)
* points1 x 250,386 ops/sec ±1.53% (88 runs sampled)
* points2 x 166,679 ops/sec ±1.40% (88 runs sampled)
* fiji: 1.692ms
* many-points: 14.448ms
* points-with-properties: 0.164ms
* points1: 0.087ms
* points2: 0.694ms
* fiji x 1,320,371 ops/sec ±1.72% (80 runs sampled)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚗 💨 Zoom Zoom!

* many-points x 14,640 ops/sec ±2.20% (81 runs sampled)
* points-with-properties x 1,257,709 ops/sec ±2.96% (77 runs sampled)
* points1 x 545,118 ops/sec ±1.83% (80 runs sampled)
* points2 x 393,770 ops/sec ±1.73% (83 runs sampled)
*
* // Clusters kmeans
* fiji: 3.236ms
Expand Down
11 changes: 3 additions & 8 deletions packages/turf-clusters-distance/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,12 @@ module.exports = function (points, maxDistance) {
collectionOf(points, 'Point', 'Input must contain Points');

// Create index
const load = points.features.map(function (point, index) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Love it! I think my first approached used the id fields to do the matching, however I might of dropped that workflow mid way and forgot to remove the .map().

@stebogit Good catch!

point.id = index;
return point;
});
const tree = kdbush(load, getX, getY);
const tree = kdbush(points.features, getX, getY);

// Iterate over each untagged Feature
let clusterId = -1;
tree.ids.forEach(function (id) {
const feature = tree.points[id];
const coord = feature.geometry.coordinates;

// Define new clusterId
if (feature.properties.cluster === undefined) {
Expand All @@ -45,9 +40,9 @@ module.exports = function (points, maxDistance) {
} else return;

// Find features around untagged cluster
const around = geokdbush.around(tree, coord[0], coord[1], Infinity, maxDistance);
const around = geokdbush.around(tree, getX(feature), getY(feature), Infinity, maxDistance);
around.forEach(function (feature) {
tree.points[feature.id].properties.cluster = clusterId;
feature.properties.cluster = clusterId;
});
});
return {
Expand Down
18 changes: 6 additions & 12 deletions packages/turf-clusters-distance/test/out/fiji.geojson
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
179.439697265625,
-16.55196172197251
]
},
"id": 0
}
},
{
"type": "Feature",
Expand All @@ -30,8 +29,7 @@
179.01123046874997,
-16.97274101999901
]
},
"id": 1
}
},
{
"type": "Feature",
Expand All @@ -46,8 +44,7 @@
179.505615234375,
-17.035777250427184
]
},
"id": 2
}
},
{
"type": "Feature",
Expand All @@ -62,8 +59,7 @@
180.75805664062497,
-16.41500926733237
]
},
"id": 3
}
},
{
"type": "Feature",
Expand All @@ -78,8 +74,7 @@
181.1865234375,
-16.615137799987075
]
},
"id": 4
}
},
{
"type": "Feature",
Expand All @@ -94,8 +89,7 @@
181.03271484375,
-16.277960306212513
]
},
"id": 5
}
}
]
}
Loading