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

bct.community_louvain adjmat must not contain negative weights #63

Closed
vinferrer opened this issue Oct 17, 2018 · 5 comments
Closed

bct.community_louvain adjmat must not contain negative weights #63

vinferrer opened this issue Oct 17, 2018 · 5 comments

Comments

@vinferrer
Copy link

Hi,

I am having a problem with the comunity_louvain function, it says that the adjancency matrix cannot have negative values. If my understanding is correct, there shouldn't be a problem, plus the matlab version allows negative values (this is specified in the help) but the python one doesn't?

Cheers,
Vicente

@vinferrer
Copy link
Author

I saw a previous post commenting the problem but nobody answer him:
#57

@vinferrer
Copy link
Author

I have checked the function, in line 110-111 you have this error message if the adjacency matrix has negative values:

if np.min(W) < -1e-10:
    raise BCTParamError('adjmat must not contain negative weights')

But then for lines 122 to 138 if we select the negative_sym option or the_asym the program should continue:
if B in ('negative_sym', 'negative_asym'):
W0 = W * (W > 0)
s0 = np.sum(W0)
B0 = W0 - gamma * np.outer(np.sum(W0, axis=1), np.sum(W, axis=0)) / s0

    W1 = W * (W < 0)
    s1 = np.sum(W1)
    if s1:
        B1 = (W1 - gamma * np.outer(np.sum(W1, axis=1), np.sum(W1, axis=0))
            / s1)
    else:
        B1 = 0

elif np.min(W) < -1e-10:
    raise BCTParamError("Input connection matrix contains negative "
        'weights but objective function dealing with negative weights '
        'was not selected')

However since you impose first the condition in lines 110-111 the function doesn't execute at all, I think that the condition from line 110-111 should be eliminated, since in lines 122 to 138 this problem is already dealt if the proper objective function isn't chosen.

@CarloNicolini
Copy link
Contributor

I believe you can happily eliminate the lines:

if np.min(W) < -1e-10:
    raise BCTParamError('adjmat must not contain negative weights')

Moreover you need to fix a bit the code, there are a few errors using 'negative_asym' or 'negative_sym'. The value of modularity is normalized by s twice in this case and the calculation of both B0 and B1 are wrong. I'll open a pull request with the fixed code.

@aestrivex
Copy link
Owner

aestrivex commented Oct 24, 2018 via email

@aestrivex
Copy link
Owner

Fixed in PR #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

3 participants