Skip to content

Commit 24a30ae

Browse files
authored
Merge pull request JuliaStats#286 from lwabeke/master
dbscan(): drop num points > num dimensions check it is not necessary
2 parents 7a675b9 + 27983b8 commit 24a30ae

File tree

5 files changed

+47
-4
lines changed

5 files changed

+47
-4
lines changed

src/dbscan.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ function dbscan(points::AbstractMatrix, radius::Real;
101101
if metric !== nothing
102102
# points are point coordinates
103103
dim, num_points = size(points)
104-
num_points <= dim && throw(ArgumentError("points has $dim rows and $num_points columns. Must be a D x N matric with D < N"))
105104
kdtree = KDTree(points, metric; nntree_kwargs...)
106105
data = (kdtree, points)
107106
else

test/affprop.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ using Clustering
66
using LinearAlgebra
77
using Random, StableRNGs
88
using Statistics
9-
include("test_helpers.jl")
109

1110
@testset "affinityprop() (affinity propagation)" begin
1211

test/dbscan.jl

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using Test
22
using Clustering
33
using Distances
4-
include("test_helpers.jl")
54

65
@testset "dbscan() (DBSCAN clustering)" begin
76

@@ -14,6 +13,51 @@ include("test_helpers.jl")
1413
@test @inferred(dbscan(randn(2, 2), 0.5, metric=nothing, min_neighbors=1)) isa DbscanResult
1514
end
1615

16+
@testset "Simple 2D tests" begin
17+
X = [10.0 0.0 10.5
18+
0.0 10.0 0.1]
19+
20+
@testset "n=3 samples" begin
21+
X3 = X
22+
23+
R = dbscan(X3, 20)
24+
@test nclusters(R) == 1
25+
26+
R = dbscan(X3, 1.0)
27+
@test nclusters(R) == 2
28+
29+
R = dbscan(X3, 0.1)
30+
@test nclusters(R) == 3
31+
end
32+
33+
@testset "n=2 samples" begin
34+
X2 = X[:, 1:2]
35+
36+
R = dbscan(X2, 20)
37+
@test nclusters(R) == 1
38+
39+
R = dbscan(X2, 1.0)
40+
@test nclusters(R) == 2
41+
end
42+
43+
@testset "n=1 samples" begin
44+
X1 = X[:, 1:1]
45+
46+
R = dbscan(X1, 20)
47+
@test nclusters(R) == 1
48+
49+
R = dbscan(X1, 1.0)
50+
@test nclusters(R) == 1
51+
end
52+
53+
@testset "n=0 samples" begin
54+
X0 = X[:, 1:0]
55+
56+
R = dbscan(X0, 20)
57+
@test nclusters(R) == 0
58+
end
59+
end
60+
1761
@testset "clustering synthetic data with 3 clusters" begin
1862
Random.seed!(34568)
1963

test/kmedoids.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using Test
22
using Distances
33
using Clustering
4-
include("test_helpers.jl")
54

65
@testset "kmedoids() (k-medoids)" begin
76

test/runtests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ using SparseArrays
66
using StableRNGs
77
using Statistics
88

9+
include("test_helpers.jl")
10+
911
tests = ["seeding",
1012
"kmeans",
1113
"kmedoids",

0 commit comments

Comments
 (0)