feat(clustering): Leiden community detection (well-connected communities) - #8
Closed
seilat wants to merge 2 commits into
Closed
feat(clustering): Leiden community detection (well-connected communities)#8seilat wants to merge 2 commits into
seilat wants to merge 2 commits into
Conversation
…unities) Builds on Louvain (E2): - E2.0: extract package-private CommunityAggregation (compact / numberOfCommunities / degree-conserving aggregate that compacts labels internally) and refactor LouvainClustering to use it. Behaviour-preserving: Louvain's 17 tests stay green. The internal compaction removes the implicit 'caller must pass compact labels' coupling flagged in review, so Leiden can aggregate its non-compact refined partitions safely. - E2.1: LeidenClustering implementing ClusteringAlgorithm<V>. Multilevel local-moving + a refinement phase whose sub-communities grow only along edges (so each is connected), aggregation over the refined partition, and a final connected-components split that guarantees every reported community is connected -- the property Louvain lacks. Non-negative/zero-weight guards mirror Louvain. - E2.2: 16 tests incl. the headline everyCommunityIsConnected oracle (ConnectivityInspector per induced subgraph, structured + 30 random graphs), clique/ring/complete/weighted parity, determinism, edge cases, and a modularity-vs-Louvain comparison (competitive within 0.02; Leiden trades a sliver of modularity for guaranteed connectivity). 33/33 clustering tests pass; checkstyle + javadoc clean. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Leiden vs Louvain vs LabelPropagation vs GreedyModularity on planted partitions. Leiden costs ~1.4-1.5x Louvain (refinement + connectivity-split passes) while staying 7-9x faster than GreedyModularity; scaling parallels Louvain. Cost (ms/op): 125-node Louvain 0.28 / Leiden 0.42; 500-node Louvain 3.05 / Leiden 4.17. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Owner
Author
|
Superseded by #9 — Louvain + Leiden combined into a single clustering PR. |
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.
Self-review PR (fork only — not upstream; stacked on the Louvain branch, holds for
jgrapht-dev).What (Workstream E2, stacked on #7)
CommunityAggregation(compact / numberOfCommunities /degree-conserving
aggregatethat compacts labels internally) and refactorLouvainClusteringonto it. Behaviour-preserving: Louvain's 17 tests stay green. Internal compaction removes the
implicit "caller passes compact labels" coupling flagged in the Louvain review, so Leiden can
aggregate its non-compact refined partitions safely.
LeidenClustering implements ClusteringAlgorithm<V>. Multilevel local-moving +refinement (sub-communities grow only along edges → each connected) + aggregation over the
refined partition + a final connected-components split that guarantees every reported community
is connected — the property Louvain lacks (Traag-Waltman-van Eck 2019).
everyCommunityIsConnectedoracle (ConnectivityInspectorper induced subgraph, structured + 30 random graphs).
Verification
ConnectivityInspector.Honest scope notes
guaranteed connectivity (worst observed gap on random graphs: 4×10⁻⁴; test allows 0.02).
singletons each level rather than seeding from the previous partition; the refinement gate is
connectivity + positive gain rather than the resolution-parametrised well-connected test. The
connectivity guarantee is enforced unconditionally by the final connected-components split.
resolutionconstructor parameter deferred.Review focus
CommunityAggregation.aggregateinternal compaction + degree conservation🤖 Generated with Claude Code