vtraag / leidenalg

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

Is there a way to do a non-diagonal coupling for multiplex via time_slices_to_layers #52

Closed ulgenklc closed 3 years ago

ulgenklc commented 3 years ago

Hi

I'm trying out different configurations for interlayer edges using leidenalg, on k layers and n nodes let's say.

My question is, is there a way to add interlayer edges to the slice graph such that nodes are not only coupled with their future and past selves but also other node's future and/or past selves i.e. non-diagonal coupling?

Thank you

Ülgen

vtraag commented 3 years ago

Yes, you can do this using the general function slices_to_layers, in which you can specify a coupling graph, indicating (the nodes of) which graph should be connected to (the nodes of) which other graph. See https://leidenalg.readthedocs.io/en/stable/multiplex.html#slices-to-layers for a more detailed explanation. If anything remains unclear, or if you have any other questions, let me know!

ulgenklc commented 3 years ago

Hello again

I still am not sure how slices_to_layers would help. I get that it would help if I wanted to couple the snapshots(just to not get confused with the slice&layer terminology, I'm going to use snapshots) without any chronological order but that's not what I want to do. I still want to keep the consecutive ordering of the coupling graph the same G_coupling = ig.Graph.Formula('1 -- 2 -- 3') which yields me the diagonal coupling.

However, I want to add interlayer edges between node x in time layer 1(snapshot 1) and node y in time layer 2(snapshot 2) as well as the interlayer edges between node x in time layer 1 and node x in time layer 2, non-diagonal coupling i.e. I want to gain full control over the interlayer edges between consecutive snapshots so that the picture in the documentation looks something like this for example-- on top of the dashed edges in the original picture, I want to add red ones too into the graph.

Screen Shot 2020-11-16 at 1 38 52 PM

In other words, I want to be able to pass a 2d-matrix for every interlayer edge instead of a constant, and a list(two cases which I know how to handle as I explained in the above two bullet points). This is probably possible via igraph(by passing one big supra-adjacency matrix), but I don't know how it would translate into your package.

Sorry to bug you over and over again!

Thank you

Ülgen

vtraag commented 3 years ago

Sorry, I think I may have misunderstood your original question!

This is unfortunately not possible using any of the implemented methods. That is, you should construct all the appropriate graphs (i.e. intercoupling and other layers graphs) yourself. The methods of optimization will work correctly regardless.

You might want to explore the source code of slices_to_layers for some inspiration how to generate the appropriate layers graphs for your usecase.