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_temporal order of list of membership #156

Closed p-dre closed 6 months ago

p-dre commented 8 months ago

Hi, I have two questions about my code below. In what order is the list of membership. For example, if I use g.get_vertex_dataframe()['name'] as vertex_id_attr='name', does the assignment come in that order? The second question is about the number of communities over time. If I understand the algorithm correctly, does this remain the same across layers?

graph_list = []
for edges_df, i in zip(edges_month_list, range(0,edges['time'].max())):
    edges_with_weights = list(zip(edges_df['Source'], edges_df['Target'],edges_df['weight'],edges_df['time']))
    g = Graph.TupleList(edges_with_weights, directed=True, edge_attrs=['weight', 'time'])
    graph_list.append(g)

communities, improvment = la.find_partition_temporal(graph_list, la.RBConfigurationVertexPartition, interslice_weight=1, 
                                                     vertex_id_attr='name',  weight_attr='weight', n_iterations= 2,
                                                     seed=123, resolution_parameter=1)
vtraag commented 6 months ago

The order of the nodes is unaffected. The communities object is simply a list of the membership for each individual graph as provided in graph_list. The order of the membership is identical to the order of the nodes in each graph in graph_list. The vertex_id_attr is only used to link nodes from one slice to another slice.

The number of communities is fixed for the entire temporal graph. That is, it detects communities across all temporal slices all at once. Each time slice may then contain different clusters of course. If a node is assigned to cluster 1 in slice 1 and also in slice 2, the node has then stayed in the same community. Hopefully this clarifies things? If not, perhaps the documentation at https://leidenalg.readthedocs.io/en/stable/multiplex.html provides more clarity.