I’m trying to do a hierarchical clustering of a matrix, and I’m running into a weird problem. Using Distances.jl
, I’m doing dm = pairwise(Jaccard(), my_matrix)
, and then hclust(dm)
from Clustering.jl
. But I’m getting
julia> rowclust = hclust(rowdm)
ERROR: ArgumentError: Distance matrix should be symmetric.
When I use issymetric
from LinearAlgebra
, sure enough
julia> issymmetric(rowdm)
false
But I’m pretty sure pairwise
from Distances should always return a symmetric matrix when the distance function is metric (which Jaccard is), and when I looked for which element is mismatched
julia> for i in 1:size(rowdm, 1), j in 1:size(rowdm, 2)
j<i && continue
if rowdm[i,j] !== rowdm[j, i]
@info "mismatch!" i, j, rowdm[i,j], rowdm[j,i]
end
end
julia>
They all seem to be correct. Am I misunderstanding what a symmetric matrix is? And how this function of Distances.jl works? For what it’s worth, I’m trying to cluster along both columns and rows of my matrix, and the former works as expected. I also haven’t been able to come up with a MWE that throws the same error.
EDIT: Euclidean()
distance for the rows seems to work