Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modularity() results differ when called on communities vs with graph + membership #1927

Closed
ashander opened this issue Aug 21, 2020 · 2 comments
Assignees
Labels
stale Issues that have been inactive for a long time; will be closed in the absence of further activity

Comments

@ashander
Copy link

This is similar to an old question on SO but not due to weights.

The two different ways given in ?modularity give different results yet based on the answer to the SO question I don't think this should be the case.

The two different ways to compute modularity given in the help are:

    wtc <- cluster_walktrap(g)
    modularity(wtc)
    # and
    modularity(g, membership(wtc))

For this example these give different results

g2 <- make_graph(c(1,2,2,3,3,1), directed = FALSE)

set.seed(444)
wtc2 <- cluster_walktrap(g2)
modularity(wtc2)
## 0
wtc2
##IGRAPH clustering walktrap, groups: 3, mod: 0
##+ groups:
## $`1`
##  [1] 1
## 
##  $`2`
## [1] 2
##  
##  $`3`
##  [1] 3
modularity(g2, membership(wtc2))
## -0.3333

This is with igraph_1.2.5.

Note

This shows up on much more complicated graphs as well -- this is the simplest case where I could reproduce

@szhorvat szhorvat transferred this issue from igraph/rigraph Jan 10, 2022
@szhorvat
Copy link
Member

This looks like an issue with the Walktrap code in that the returned community structure is not the one with the highest modularity.

Also, Walktrap returns a sequence of modularity values, one for each merge step of the dendrogram. The one for entirely separate vertices is 0, not -0.3333.

Moving to the C core repo, since this is not an R-specific bug.

@stale
Copy link

stale bot commented Mar 13, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale Issues that have been inactive for a long time; will be closed in the absence of further activity label Mar 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Issues that have been inactive for a long time; will be closed in the absence of further activity
Projects
None yet
Development

No branches or pull requests

3 participants