vtraag / leidenalg

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

find_partition_multiplex #181

Closed elisabettabiondi closed 1 month ago

elisabettabiondi commented 1 month ago

Thank you, @vtraag. Since I am not able to reopen the issue, I open a new one here. A simple question: Once I run:

optimiser = la.Optimiser()
diff = optimiser.optimise_partition_multiplex([part_pos, part_neg], layer_weights=[1, -1])

how do I get the vertices belonging to each partition?

Hi @elisabettabiondi, you are calling find_partition_multiplex which is expecting to be passed igraph.Graphs, not leidenalg.VertexPartitions. If you look at the example in the documentation at https://leidenalg.readthedocs.io/en/stable/multiplex.html#negative-links, you can see that it uses optimise_partition_multiplex, not find_partition_multiplex.

This should solve your problem. If it doesn't, feel free to re-open the issue!

Originally posted by @vtraag in https://github.com/vtraag/leidenalg/issues/179#issuecomment-2134855565

vtraag commented 1 month ago

Since I am not able to reopen the issue, I open a new one here.

Sorry, my bad. Indeed, you can't re-open it, but I could after commenting. Anyway, doesn't matter, we can continue the discussion here.

Once I run:

optimiser = la.Optimiser()
diff = optimiser.optimise_partition_multiplex([part_pos, part_neg], layer_weights=[1, -1])

You can retrieve the membership from part_pos and part_neg (both contain the same partitioning information). These are objects that are derived from igraph.VertexClustering, see that documentation for more information.

elisabettabiondi commented 1 month ago

Perfect, thank you! Is there a way to force the partition to be of length 2?

elisabettabiondi commented 1 month ago

I found the answer by myself in this previous issue: https://github.com/vtraag/leidenalg/issues/89#issuecomment-964054798

vtraag commented 1 month ago

Great you found the answer!

One additional tip by the way, as explained in the documentation on optimise_partition_multiplex, it might be better to set consider_comms to leidenalg.ALL_COMMS when dealing with negative links.