taynaud / python-louvain

Louvain Community Detection
BSD 3-Clause "New" or "Revised" License
964 stars 200 forks source link

How does 'best_partition' handle a mix of negative and positive weights? #64

Closed jolespin closed 4 years ago

jolespin commented 4 years ago

I want to create a graph where the weights range continuously from -1 to 1. How does your louvain algorithm handle negative weights? Does it force them into everything into the positive realm? For example, -1 to 1 would be forced into 0 and 2? In particular, I'm using correlation values as weights so 0 should be a weight of 0 while negative 1 should represent repulsive forces and 1 should represent attractive forces.

taynaud commented 4 years ago

Handling negative weights is complicated. Louvain algorithm assumes weights as positive and consider that the higher the weight, the stronger the link. It optimises modularity that depends on node degree and multiply degree: what is the meaning of a degree of -1 in this case, how two negative degree are multiplied...

See https://github.com/taynaud/python-louvain/issues/1

I close this as a duplicate.

Thanks

jolespin commented 4 years ago

I’m using correlation as edge weight which ranges from -1 to 1. A negative weight means nodes have an inverse relationship in their individual abundance values.