Skip to content

Commit a1bc906

Browse files
committed
dbscan(): all passing any kwargs to KDTree()
instead of restricting to leafsize=
1 parent 4638959 commit a1bc906

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

src/dbscan.jl

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,9 @@ function _dbs_expand_cluster!(D::AbstractMatrix{T}, # distance matrix
135135
end
136136

137137
"""
138-
dbscan(points::AbstractMatrix, radius::Real,
139-
[leafsize], [min_neighbors], [min_cluster_size]) -> Vector{DbscanCluster}
138+
dbscan(points::AbstractMatrix, radius::Real;
139+
[min_neighbors], [min_cluster_size],
140+
[nntree_kwargs...]) -> Vector{DbscanCluster}
140141
141142
Cluster `points` using the DBSCAN (density-based spatial clustering of
142143
applications with noise) algorithm.
@@ -147,15 +148,14 @@ applications with noise) algorithm.
147148
- `radius::Real`: query radius
148149
149150
Optional keyword arguments to control the algorithm:
150-
- `leafsize::Int` (defaults to 20): the number of points binned in each
151-
leaf node in the `KDTree`
152-
- `min_neighbors::Int` (defaults to 1): the minimum number of a *core* point
151+
- `min_neighbors::Integer` (defaults to 1): the minimum number of a *core* point
153152
neighbors
154-
- `min_cluster_size::Int` (defaults to 1): the minimum number of points in
153+
- `min_cluster_size::Integer` (defaults to 1): the minimum number of points in
155154
a valid cluster
155+
- `nntree_kwargs`: parameters (like `leafsize`) for the `KDTree` contructor
156156
157-
# Example
158-
``` julia
157+
## Example
158+
```julia
159159
points = randn(3, 10000)
160160
# DBSCAN clustering, clusters with less than 20 points will be discarded:
161161
clusters = dbscan(points, 0.05, min_neighbors = 3, min_cluster_size = 20)
@@ -171,15 +171,19 @@ clusters = dbscan(points, 0.05, min_neighbors = 3, min_cluster_size = 20)
171171
(Still) Use DBSCAN"*, ACM Transactions on Database Systems,
172172
Vol.42(3)3, pp. 1--21, https://doi.org/10.1145/3068335
173173
"""
174-
function dbscan(points::AbstractMatrix, radius::Real; leafsize::Int = 20, kwargs ...)
175-
kdtree = KDTree(points; leafsize=leafsize)
176-
return _dbscan(kdtree, points, radius; kwargs ...)
174+
function dbscan(points::AbstractMatrix, radius::Real;
175+
min_neighbors::Integer = 1, min_cluster_size::Integer = 1,
176+
nntree_kwargs...)
177+
kdtree = KDTree(points; nntree_kwargs...)
178+
return _dbscan(kdtree, points, radius;
179+
min_neighbors=min_neighbors,
180+
min_cluster_size=min_cluster_size)
177181
end
178182

179183

180184
# An implementation of DBSCAN algorithm that keeps track of both the core and boundary points
181185
function _dbscan(kdtree::KDTree, points::AbstractMatrix, radius::Real;
182-
min_neighbors::Int = 1, min_cluster_size::Int = 1)
186+
min_neighbors::Integer = 1, min_cluster_size::Integer = 1)
183187
dim, num_points = size(points)
184188
num_points <= dim && throw(ArgumentError("points has $dim rows and $num_points columns. Must be a D x N matric with D < N"))
185189
0 <= radius || throw(ArgumentError("radius $radius must be ≥ 0"))

0 commit comments

Comments
 (0)