python-louvain icon indicating copy to clipboard operation
python-louvain copied to clipboard

Is there some problem about the algorithm of modularity in function __modularity.

Open Green-16 opened this issue 3 years ago • 0 comments

I think there is some point than is not very well about the function __modularity. I think the result should write as the below, in the article, the denominator of the function should be 2m. There is a 2 missing.

def __modularity(status, resolution):
    """
    Fast compute the modularity of the partition of the graph using
    status precomputed
    """
    links = float(status.total_weight)
    result = 0.
    for community in set(status.node2com.values()):
        in_degree = status.internals.get(community, 0.)
        degree = status.degrees.get(community, 0.)
        if links > 0:
            result += in_degree * resolution / links -  ((degree / (2. * links)) ** 2)
    return result

The code bellow is what I want to say:

result += in_degree * resolution / (2. * links) - ((degree / (2. * links)) ** 2)

https://github.com/taynaud/python-louvain/blob/638804ae636dc65306900ef6518ca0a1c9202566/community/community_louvain.py#L552

Green-16 avatar Aug 25 '22 08:08 Green-16