Repository navigation
Count self-loops in modularity and Louvain as networkx does - #18
Merged
Merged
Conversation
modularity counted a self-loop once in its node's degree and as half an internal edge, so 2m was short by one per loop. It now adds 2 to the degree and 1 to L_c; the new test matches networkx 3.7 (0.22 on a triangle with a pendant self-looped node). The four optimizers built their first-level adjacency with a self-loop at its plain weight, while aggregation stores internal edges at twice their weight. They now start a self-loop at twice its weight so both levels use one convention. Graphs without self-loops are unaffected. Checked with cargo fmt, clippy -D warnings and cargo test --all-features. Claude-Session: https://claude.ai/code/session_01UJZpXWnaKuGTdguKe8WFFv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
modularitycounted a self-loop once in its node's degree and as half an internal edge. It now follows networkx: twice in the degree, once as an internal edge. A test pins the networkx 3.7 value (0.22) on a small graph with a self-loop.Louvain and connectivity-refined Louvain, weighted and unweighted, started a self-loop at its plain weight while their aggregation step stores internal edges at twice their weight. All four now start self-loops at twice their weight. Graphs without self-loops are unaffected.
https://claude.ai/code/session_01UJZpXWnaKuGTdguKe8WFFv