Modularity maximization and GenLouvain implementation in python

Question:

I have a temporal multilayer network that I want to find communities by using modularity maximization.

I was wondering if there is an equivalent version of Matlab GenLouvain in Python for maximizing modularity in community detection?

Preliminary search yielded this library, but the corresponding GitHub repository is gone.

https://pypi.org/project/louvain/

There are several other algorithms, such as Leiden algorithm (https://www.nature.com/articles/s41598-019-41695-z) for maximizing modularity with python implementation (https://github.com/vtraag/leidenalg) but I am trying to explore my options at the moment and run different solvers on the supra-modularity matrix I have. So, I want to start with the good old GenLouvain and then compare different solvers with python implementation.

Does anyone have any suggestions?

Asked By: Ulgen

||

Answers:

i currently use CPMVertexPartion from leidenalg to analyse my networks. by varying the resolution parameter i can find maximum modularity Q.
my network is dense, beta approx >10, and modularity can improve up to 0.5

Answered By: PeterP

It’s been a while I posted this question but as given above I found out the leidenalg is the best implementation in Python for Multilayer Modularity Maximization(MMM) with the improvement of intermediate refinement step, handling arbitrarily disconnected communities appropriately.

Here’s a piece of code I use to implement MMM with the configuration null model.

def leiden(self, G, interslice, resolution):
    ## G: the appropriate igraph as explained in the documentation
    ## interslice: float, interlayer edge weights for the diagonal coupling of consecutive layers
    ## resolution: float, spatial resolution parameter
    
    layers, interslice_layer, G_full = la.time_slices_to_layers(G, interslice_weight = interslice)
    
    partitions = [la.RBConfigurationVertexPartition(H, 
                                        weights = 'weight', 
                                        resolution_parameter = resolution) for H in layers]

    ## resolution parameter below has to be 0 to recover the original multilayer modularity equation
    interslice_partition = la.RBConfigurationVertexPartition(interslice_layer, 
                                                             weights = 'weight',
                                                             resolution_parameter = 0)
                                                 
    optimiser = la.Optimiser()
    
    diff = optimiser.optimise_partition_multiplex(partitions + [interslice_partition])

    return(partitions, interslice_partition)

Having said that, MMM is not the greatest approach to perform dynamic community detection. There are more temporal community detection tools in the literature that is utilizing random walks, stochastic block models, tensor factorization methods one should check.

Answered By: Ulgen

There is now a Python reimplementation of GenLouvain called PyGenStability available here. It optimizes Markov Stability (a generalization of Modularity) with the Louvain or Leiden algorithms.

Answered By: Alex B
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.