unweighted graph returns error
matei-ionita opened this issue · 5 comments
When supplying an unweighted graph (for example, the output of igraph::graph_from_adj_list
) I get:
Error in find_partition(graph, igraph::E(graph)$weight, resolution, n.iterations) :
Not compatible with requested type: [type=NULL; target=double].
This is fixed if I manually set all weights to 1. It would be nice if this were the default behavior for unweighted graphs. Otherwise great implementation!
Thanks for using leidenAlg!
When supplying an unweighted graph (for example, the output of igraph::graph_from_adj_list)
Could you give me an example, saved as an RDS file perhaps? This sounds like something we could fix.
Thanks, Evan
Hi Evan. Here's a quick example. Works fine if you un-comment the third line, returns error otherwise.
adj_list <- list("1"=c(2,3), "2"=c(1), "3"=c(1), "4"=c(5), "5"=c(4))
gr <- igraph::graph_from_adj_list(adj_list, mode = "all")
# igraph::E(gr)$weight <- rep(1, 3)
leidenAlg::leiden.community(gr)
Thanks @matei-ionita, I'll have a look later in the week
I have something here: #3
The following now runs as you would expect:
adj_list <- list("1"=c(2,3), "2"=c(1), "3"=c(1), "4"=c(5), "5"=c(4))
gr <- igraph::graph_from_adj_list(adj_list, mode = "all")
leidenAlg::leiden.community(gr)
My only remaining question is....is there any rationale at all for throwing an error if a user inputs an unweighted graph? My understanding is that the leiden algorithm will handle the case of all edge weights being the same.
Would a warning be useful along with making all edge weights = 1?
Let me know what you think. I'm happy with the current behavior of course, and we could re-release.
Thanks, Evan
Thinking about this more, I think think that the fix is right. I don't think a warning is necessary either.
adj_list <- list("1"=c(2,3), "2"=c(1), "3"=c(1), "4"=c(5), "5"=c(4))
gr <- igraph::graph_from_adj_list(adj_list, mode = "all")
igraph::is_weighted(gr) ## FALSE
leidenAlg::leiden.community(gr)
$membership
[1] 0 0 0 1 1
Levels: 0 1
$dendrogram
NULL
$algorithm
[1] "leiden"
$resolution
[1] 1
$n.iter
[1] 2
$names
NULL
attr(,"class")
[1] "fakeCommunities"
That should be work, I think.
I'll close the issue and re-version. Let me know if there's more here
Thanks for the issue! Best, Evan