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

Time Slices to Layers Returns Uniform Account Count Across All Layers, #172

Closed p-dre closed 4 months ago

p-dre commented 4 months ago

If I use the time_slices_to_layers I get the same number of accounts for each layer at time t which does not correspond to the number of nodes in the graph object. It is also the same number of accounts as in the whole graph. This leads to the problem that I later get the same list from partition[i].membership at every point in time. It may be worth mentioning that I have manually limited the number of communities

graph_list
[<igraph.Graph at 0x7f197a121b50>,
 <igraph.Graph at 0x7f197a122e50>,
 <igraph.Graph at 0x7f197a122d50>,
 <igraph.Graph at 0x7f197a122b50>]

layers, interslice_layer, G_full = la.time_slices_to_layers(
    graph_list,
    interslice_weight=1, vertex_id_attr='name',  weight_attr='weight'
)

layers[0].vcount() 
134884

G_full.vcount()
134884

initial_memberships = np.random.choice(3, len(layers[0].vs["name"]))
partitions = []
for index, H in enumerate(layers):
        partition = la.RBConfigurationVertexPartition(H, initial_membership=initial_memberships,  resolution_parameter=1)
        partitions.append(partition)

interslice_partition = la.CPMVertexPartition(interslice_layer, resolution_parameter=0,
                                         node_sizes='node_size', weights='weight', initial_membership=initial_memberships)

optimiser = la.Optimiser()
optimiser.consider_empty_community = False
diff = optimiser.optimise_partition_multiplex(partitions + [interslice_partition], n_iterations =1)

len(partitions[0].membership)
134884
p-dre commented 4 months ago

It took me some time to find out that this is not wrong but that I had not yet done the step of assigning to the partitions as in find_partition_temporal

membership = {(v['slice'], v['name']): m for v, m in zip(G_full.vs, partitions[0].membership)}

membership_time_slices = []
for  H in graph_list:
    membership_slice = [membership[(v['slice'], v['name'])] for v in H.vs]
    membership_time_slices.append(list(membership_slice))