In the second stage of an iteration, the weighted graph from the first stage is transformed into a new weighted graph, where each community is presented by a node. The link weight between two nodes \(h\)  and \(g\)  equals the sum of weights of all links between communities \(h\)  and \(g\)  in the graph from the first stage. Furthermore, the weight of a self-loop of node \(g\)  in the new graph equals the sum of weights of all intra-community links in cluster \(g\)  of the graph from the previous stage. The new graph is provided to the first stage in the next iteration. The algorithm stops when modularity \(m\)  cannot be increased further. The time complexity of the Louvain method is linear in the number of links \(O(L)\)  on sparse graphs [1]}.
