Describe the bug
This was reported at https://stackoverflow.com/q/76226275/695132
cluster_leading_eigen() produces a merges matrix in which the indices refer to clusters, not vertices. However, functions that convert to dendrograms still assume that these are vertex IDs, leading to wrong output.
The reason for this sort of output from cluster_leading_eigen() is that the algorithm generates splits (not merges) and produces a dendrogram that is incomplete from below (not incomplete from above, like in the case when we use other algorithms on disconnected graphs).
It seems to me that since the interpretation of the merges matrix returned by cluster_leading_eigen() is different than in the case of other community detection functions, it would be useful not to call it merges (also in the C core) and not to store it in $merges.
To reproduce
g <- make_graph(c(1,5, 1,6, 6,5, 5,4, 2,4, 4,3, 2,3), directed=F)
cl <- cluster_leading_eigen(g)
plot_dendrogram(cl)
Notice the incorrect dendrogram.
For reference, these are the produced clusters:
> groups(cl)
$`1`
[1] 1 5 6
$`2`
[1] 2 3 4
This is the produced merges matrix:
> merges(cl)
[,1] [,2]
[1,] 1 2
Here 1 and 2 are community indices, not vertex indices.
Additional information
To further illustrate what it means for the dendrogram to be incomplete from below, here's the visualization I use in Mathematica:
It's essentially a dendrogram of communities, not of individual vertices.
Version information
R version 4.2.2 (2022-10-31)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Mojave 10.14.6
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] igraph_1.4.99.9005
loaded via a namespace (and not attached):
[1] compiler_4.2.2 magrittr_2.0.3 cli_3.6.1 parallel_4.2.2
[5] tools_4.2.2 rstudioapi_0.14 Rcpp_1.0.10 nlme_3.1-162
[9] ape_5.7-1 grid_4.2.2 digest_0.6.31 rlang_1.1.0
[13] pkgconfig_2.0.3 lattice_0.21-8
Describe the bug
This was reported at https://stackoverflow.com/q/76226275/695132
cluster_leading_eigen()produces amergesmatrix in which the indices refer to clusters, not vertices. However, functions that convert to dendrograms still assume that these are vertex IDs, leading to wrong output.The reason for this sort of output from
cluster_leading_eigen()is that the algorithm generates splits (not merges) and produces a dendrogram that is incomplete from below (not incomplete from above, like in the case when we use other algorithms on disconnected graphs).It seems to me that since the interpretation of the merges matrix returned by
cluster_leading_eigen()is different than in the case of other community detection functions, it would be useful not to call itmerges(also in the C core) and not to store it in$merges.To reproduce
Notice the incorrect dendrogram.
For reference, these are the produced clusters:
This is the produced merges matrix:
Here
1and2are community indices, not vertex indices.Additional information
To further illustrate what it means for the dendrogram to be incomplete from below, here's the visualization I use in Mathematica:
It's essentially a dendrogram of communities, not of individual vertices.
Version information