Skip to content

Commit

Permalink
Fix definition of $m$ parameter in docstring of modularity function (
Browse files Browse the repository at this point in the history
…networkx#6990)

* Corrected definition of m parameter

* Cited Louvain paper as in louvain.py

Co-authored-by: Dan Schult <[email protected]>
Co-authored-by: Ross Barnowski <[email protected]>
  • Loading branch information
3 people authored Oct 11, 2023
1 parent c56905d commit 245b36a
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions networkx/algorithms/community/quality.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,10 @@ def modularity(G, communities, weight="weight", resolution=1):
Q = \frac{1}{2m} \sum_{ij} \left( A_{ij} - \gamma\frac{k_ik_j}{2m}\right)
\delta(c_i,c_j)
where $m$ is the number of edges, $A$ is the adjacency matrix of `G`,
$k_i$ is the degree of $i$, $\gamma$ is the resolution parameter,
and $\delta(c_i, c_j)$ is 1 if $i$ and $j$ are in the same community else 0.
where $m$ is the number of edges (or sum of all edge weights as in [5]_),
$A$ is the adjacency matrix of `G`, $k_i$ is the (weighted) degree of $i$,
$\gamma$ is the resolution parameter, and $\delta(c_i, c_j)$ is 1 if $i$ and
$j$ are in the same community else 0.
According to [2]_ (and verified by some algebra) this can be reduced to
Expand Down Expand Up @@ -221,7 +222,9 @@ def modularity(G, communities, weight="weight", resolution=1):
.. [4] M. E. J. Newman, "Equivalence between modularity optimization and
maximum likelihood methods for community detection"
Phys. Rev. E 94, 052315, 2016. https://doi.org/10.1103/PhysRevE.94.052315
.. [5] Blondel, V.D. et al. "Fast unfolding of communities in large
networks" J. Stat. Mech 10008, 1-12 (2008).
https://doi.org/10.1088/1742-5468/2008/10/P10008
"""
if not isinstance(communities, list):
communities = list(communities)
Expand Down

0 comments on commit 245b36a

Please sign in to comment.