JuliaStats / Clustering.jl

A Julia package for data clustering
Other
353 stars 117 forks source link

Adjacency-constrained hierarchical clustering? #230

Open biona001 opened 2 years ago

biona001 commented 2 years ago

Hello, thank you for the great package. This is a question rather than a bug report.

I wonder if this package supports adjacency-constrained clustering? Given distance matrix, I want to ensure that my clusters are all "contiguous"

For example, hclust(1 .- cor(x)) results in non-continuous members:

julia> x = rand(5, 5)

julia> cutree(hclust(1 .- cor(x)), k = 2)
5-element Vector{Int64}:
 1
 1
 2
 1
 1

I need something like 1, 1, 2, 2, 2 where cluster members are contiguous and increasing.

Thank you in advance.

biona001 commented 1 year ago

I think I have a rough idea how to do this. Basically, at each merge step, I will only consider merge 2 clusters if they are adjacent and has the smallest distance.

If someone can briefly walk me through the logic of the code, I will love to add this as an option to the package. I will also try to decipher the package myself, of course.