vtraag / leidenalg

Implementation of the Leiden algorithm for various quality functions to be used with igraph in Python.
GNU General Public License v3.0
575 stars 77 forks source link

Negative links and Bipartite #122

Closed kalthwaini closed 1 year ago

kalthwaini commented 1 year ago

Is it possible to perform a community detection on negative links and bipartite as well? Is there a working example for this?

Thanks!

ragibson commented 1 year ago

Yes, see the package documentation. That is the best resource for these sorts of simple questions.

There are explicit sections discussing negative links and discussing bipartite networks. Both of them contain examples.

kalthwaini commented 1 year ago

My question is about having "negative links" and "bipartite" at the same time. The links you have provided does not contain any example for this simple question

ragibson commented 1 year ago

I see, for negative links and bipartite simultaneously I believe you can iterate the multiplex constructions for the negative link handling and the bipartite handling. The optimiser's optimise_partition_multiplex basically iterates across the passed partitions in sequence and optimizes the quality functions multiplied by the layer weights (with a shared membership).

As a first step, the correspondence for CPM from the documentation

We then create three different layers: (1) all nodes have node_size = 1 and all relevant links; (2) only nodes of class 0 have node_size = 1 and no links; (3) only nodes of class 1 have nodesize = 1 and no links. [Add] the first with resolution parameter \gamma{01}, and the others with resolution parameters \gamma_{01} - \gamma0 and \gamma{01} - \gamma_1, but the latter two with a layer weight of -1 while the first layer has layer weight 1. [...] Hence detecting communities with these three layers corresponds to detecting communities in bipartite networks.

could be repeated for the positive and negative edge weight subgraphs and then you could optimize all six partitions simultaneously to achieve what you want.

ragibson commented 1 year ago

Actually, I suppose CPM already handles negative weights, so the example for bipartite networks should work directly.

You would need to iterate the constructions for the other quality functions that only support non-negative weights though.

vtraag commented 1 year ago

I have nothing else to add to what @ragibson already said (thanks for answering!). Indeed you don't need to treat negative links separately for CPM, so you can directly apply the bipartite option.