Skip to content

Commit

Permalink
Merge pull request #286 from lwabeke/master
Browse files Browse the repository at this point in the history
dbscan(): drop num points > num dimensions check

it is not necessary
  • Loading branch information
alyst authored Jan 5, 2025
2 parents 7a675b9 + 27983b8 commit 24a30ae
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 4 deletions.
1 change: 0 additions & 1 deletion src/dbscan.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ function dbscan(points::AbstractMatrix, radius::Real;
if metric !== nothing
# points are point coordinates
dim, num_points = size(points)
num_points <= dim && throw(ArgumentError("points has $dim rows and $num_points columns. Must be a D x N matric with D < N"))
kdtree = KDTree(points, metric; nntree_kwargs...)
data = (kdtree, points)
else
Expand Down
1 change: 0 additions & 1 deletion test/affprop.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ using Clustering
using LinearAlgebra
using Random, StableRNGs
using Statistics
include("test_helpers.jl")

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

Expand Down
46 changes: 45 additions & 1 deletion test/dbscan.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Test
using Clustering
using Distances
include("test_helpers.jl")

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

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

@testset "Simple 2D tests" begin
X = [10.0 0.0 10.5
0.0 10.0 0.1]

@testset "n=3 samples" begin
X3 = X

R = dbscan(X3, 20)
@test nclusters(R) == 1

R = dbscan(X3, 1.0)
@test nclusters(R) == 2

R = dbscan(X3, 0.1)
@test nclusters(R) == 3
end

@testset "n=2 samples" begin
X2 = X[:, 1:2]

R = dbscan(X2, 20)
@test nclusters(R) == 1

R = dbscan(X2, 1.0)
@test nclusters(R) == 2
end

@testset "n=1 samples" begin
X1 = X[:, 1:1]

R = dbscan(X1, 20)
@test nclusters(R) == 1

R = dbscan(X1, 1.0)
@test nclusters(R) == 1
end

@testset "n=0 samples" begin
X0 = X[:, 1:0]

R = dbscan(X0, 20)
@test nclusters(R) == 0
end
end

@testset "clustering synthetic data with 3 clusters" begin
Random.seed!(34568)

Expand Down
1 change: 0 additions & 1 deletion test/kmedoids.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Test
using Distances
using Clustering
include("test_helpers.jl")

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

Expand Down
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ using SparseArrays
using StableRNGs
using Statistics

include("test_helpers.jl")

tests = ["seeding",
"kmeans",
"kmedoids",
Expand Down

0 comments on commit 24a30ae

Please sign in to comment.