Clustering.jl icon indicating copy to clipboard operation
Clustering.jl copied to clipboard

AssertionError in kmedoids alg

Open theloni-monk opened this issue 2 years ago • 1 comments

I am trying to use KMedoids to optimize a K-nearest-neighbors classifier. I generated the distance matrix across my classification space but when i run

res = kmedoids(dist_mat, TREE_SIZE)

I get the following error:

"name": "AssertionError",
"message": "AssertionError: !(isempty(grp))",
"stack": "
AssertionError: !(isempty(grp))\n\nStacktrace:\n  
[1] _find_medoid(dist::Matrix{Float32}, grp::Vector{Int64})\n    
    @ Clustering C:\\Users\\TheoA\\.julia\\packages\\Clustering\\tt9vc\\src\\kmedoids.jl:237\n  
[2] _kmedoids!(medoids::Vector{Int64}, dist::Matrix{Float32}, maxiter::Int64, tol::Float64, displevel::Int64)\n    
    @ Clustering C:\\Users\\TheoA\\.julia\\packages\\Clustering\\tt9vc\\src\\kmedoids.jl:148\n  
[3] kmedoids(dist::Matrix{Float32}, k::Int64; init::Symbol, maxiter::Int64, tol::Float64, display::Symbol)\n    
    @ Clustering C:\\Users\\TheoA\\.julia\\packages\\Clustering\\tt9vc\\src\\kmedoids.jl:77\n  
[4] kmedoids(dist::Matrix{Float32}, k::Int64)\n    
    @ Clustering C:\\Users\\TheoA\\.julia\\packages\\Clustering\\tt9vc\\src\\kmedoids.jl:68\n"... the rest of this is related to the julia notebook kernel
}

I'm not sure what might be wrong. I used the following to generate the distance matrix:

function gen_distmatrix(space) #this is gonna be a while
    distmat = zeros(Float32, size(space)[1], size(space)[1])
    for i in CartesianIndices(distmat)
        dist = space[i[1]] - space[i[2]]
        distmat[i] = dist
    end
    return distmat
end

theloni-monk avatar Jul 05 '22 00:07 theloni-monk

This is an old issue, but what was space in your example?

pcjentsch avatar Sep 14 '22 23:09 pcjentsch