feat(clustering): Louvain community detection - #7
Closed
seilat wants to merge 2 commits into
Closed
Conversation
Add LouvainClustering implementing ClusteringAlgorithm<V> in org.jgrapht.alg.clustering: alternating local-moving and aggregation phases that greedily maximise modularity, with weighted/self-loop handling and modularity conventions matching UndirectedModularityMeasurer (reused for getModularity()). Constructors mirror LabelPropagationClustering ((graph), (graph, rng), (graph, rng, tolerance)). - 15 JUnit5 tests: cliques->2, ring->3, complete->1 (Q=0), weighted, seed determinism, single/empty/isolated, self-loops, random partition-validity, getModularity vs measurer, beats all-singletons. - JMH benchmark (perf/clustering) vs LabelPropagation and GreedyModularity on planted-partition graphs; export the new perf package(s) in the surefire argLine, matching the existing per-package pattern. checkstyle clean (etc/jgrapht_checks.xml); javadoc clean. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…weights Adversarial review follow-ups on the Louvain PR: - Zero-weight edges (2m == 0) made getModularity() return NaN because the modularity guard tested edgeSet().isEmpty() rather than the actual total weight. Guard on totalWeight > 0 instead; return 0 otherwise. - Reject negative edge weights with IllegalArgumentException at compute time (modularity is undefined for negative weights), documented on the class. - Replace the circular getModularityMatchesMeasurer test (getModularity delegates to the measurer) with a pinned exact value Q = 11/26 for the two-K4-plus-bridge graph; add regressions for zero-weight (no NaN) and negative-weight (throws). 17/17 tests pass; checkstyle clean. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This was referenced May 30, 2026
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 for upstream; Louvain holds for a
jgrapht-devsignal first per project cadence).What
LouvainClustering<V,E>inorg.jgrapht.alg.clustering, implementingClusteringAlgorithm<V>.Alternating local-moving + aggregation phases greedily maximising modularity; weighted/self-loop
aware; modularity conventions match
UndirectedModularityMeasurer(reused forgetModularity()).Constructors mirror
LabelPropagationClustering:(graph),(graph, rng),(graph, rng, tolerance).Tests — 15/15 green
cliques→2, ring→3, complete→1 (Q=0), weighted, seed determinism, single/empty/isolated,
self-loops, random partition-validity ×20,
getModularityvs measurer, beats all-singletons.Benchmark (
perf/clustering, planted partitions, in-process forks=0)Louvain ≈ LabelPropagation cost while directly optimising modularity; 5–10× faster than
GreedyModularity and scales far better.
pom.xmlexports the newperf.clusteringpackage(s)in the surefire argLine (matches the documented per-package pattern).
Gates
checkstyle clean (
etc/jgrapht_checks.xml), javadoc clean. Companion/clustering/visualization added in jgrapht-algo-visualization (separate repo). Dev-list draft prepared.
Review focus
UndirectedModularityMeasurerRandom🤖 Generated with Claude Code