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

community_louvain with negative weights yields uncorrect calculation of modularity #64

Closed
CarloNicolini opened this issue Oct 24, 2018 · 2 comments

Comments

@CarloNicolini
Copy link
Contributor

Checking with the original code of community_louvain I've found a bug in the 'negative_asym' treatment of negative weights.

The original code of community_louvain reads:
W1 = -W * (W < 0)
when one is building the matrix of negative weights, while in the bctpy version the minus is forgotten:

W1 = W * (W < 0)

I suggest to fix this issue that results in wrong computation of the modularity.

@CarloNicolini
Copy link
Contributor Author

Additionally there is another bug when the matrix B0 is computed.
Its correct formula is

B0 = W0 - gamma * np.outer(np.sum(W0, axis=1), np.sum(W0, axis=0)) / s0

while in the current version the formula is wrong:

B0 = W0 - gamma * np.outer(np.sum(W0, axis=1), np.sum(W, axis=0)) / s0

Finally I would like to point out that the output modularity is normalized twice when using either the 'negative_sym' or 'negative_asym' options. The output value of modularity q must be remultiplied back by the value of s.

@aestrivex
Copy link
Owner

Fixed in #65

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants