Repository navigation
Fix: Correct community color assignment in Girvan-Newman community detection. - #7644
Conversation
dschult
left a comment
There was a problem hiding this comment.
Thanks for this! It looks like it was a simple mistake that ended up not affecting the plots in the gallery. (notice that all nodes in each community have the same color)
But it is a mistake nevertheless.
Can you get rid of all the changes except removing the 0 from line 34?
(even the new comment "# fix here" shouldn't be there)
I think the other changes are probably being done automatically by your IDE which has different settings for handling "whitespace" and type-checking than our package.
|
The unnecessary whitespace and comment were also removed to adhere to the existing style guidelines. Request: Please review and merge this PR, as it addresses the issue while ensuring the code remains clean and consistent with the project's style guidelines. |
|
Why the change to the tools directory? |
|
The change in the tools directory was due to the usage of |
rossbar
left a comment
There was a problem hiding this comment.
I took the liberty of reverting the changes to the tooling to unstick what I think is otherwise a very straightforward and uncontroversial fix. Thanks @prathamesh901 !
This pull request addresses a bug in the Girvan-Newman community detection visualization code. The issue was caused by the incorrect assignment of node colors to communities. Specifically, the number of colors used for community visualization was being calculated based on the size of the first community (len(communities[0])) rather than the total number of communities (len(communities)).
Problem:
The function create_community_node_colors(graph, communities) was incorrectly assigning colors because it calculated number_of_colors based on the size of the first community. This resulted in fewer colors being assigned to nodes, especially in cases where the first community was smaller than the total number of communities. Consequently, some nodes in different communities were not being visually distinguished by different colors.
Fix:
The solution is to modify the calculation of number_of_colors to reflect the total number of communities rather than the size of the first one. This ensures that each community gets a unique color in the visualization.
Old code:
number_of_colors = len(communities[0])Updated code:
number_of_colors = len(communities)This fix ensures that the number of colors corresponds to the number of communities, thereby enhancing the clarity and accuracy of the community visualization.
Testing:
I have run the community detection visualization after applying this fix and verified that each community now receives a distinct color, even when the number of nodes in the first community is smaller than the total number of communities.
Visual checks were conducted to confirm the color differentiation across all communities in the graph.
Result:
With this change, the community visualization now correctly displays a unique color for each detected community, making it easier to visually distinguish between different communities in the Girvan-Newman algorithm results.