Delta modularity calculation (generalized)

🚨 This page is a work in progress. TODO: explain why this is needed.

Here we generalize the delta modularity calculation presented in the previous section for the case where we move a vertex from any community (not just a singleton community) to any other community . We proceed by removing from the old community and putting it into its own singleton community. The latter is done, so that the derived Louvain modularity difference formula can be reused, which is only applicable to the case where one moves a vertex from a singleton community to any other community. With this more generalized equation, we fill the gap caused by the absence of this formula in the original Louvain paper. While we do not employ this generalized formula in the actual implementation, it still might be useful for other applications.

First, we calculate the modularity difference when removing a vertex from its old community (not required to be a singleton community) and inserting it into its own singleton community . As before, we prohibit self-loops in the original graph, hence . We won’t be as elaborate this time due to the rationale being very similar:

We bring together this equation with the one from the previous section and obtain the following generalized formula for the modularity difference when moving a vertex from its previous community to any other community . This is done by first moving from into its own singleton community , then moving it from there into the target community :

Finally, for the generalized formula, we have


The delta modularity calculation for removing from a singleton community can be derived from this formula by assuming that is a singleton community. As we do not allow self-loops, . Moreover, the sum of the weights of edges incident to vertices in is equal to the vertex degree: , which gives us:

which is indeed the formula derived here.