Skip to content

Fix false-alarm community hierarchy check (issue #33)#45

Merged
raphasouthall merged 1 commit into
mainfrom
fix/hierarchy-check-resolution-aware
Jun 3, 2026
Merged

Fix false-alarm community hierarchy check (issue #33)#45
raphasouthall merged 1 commit into
mainfrom
fix/hierarchy-check-resolution-aware

Conversation

@raphasouthall
Copy link
Copy Markdown
Owner

Problem

detect_communities asserted Q(fine) > Q(coarse) and logged "Community hierarchy sanity check failed" on every build where it didn't hold — including the current healthy state (Qc=0.339, Qf=0.281, 7 coarse / 11 fine).

Why the assertion is unsound

Newman modularity is resolution-dependent and maximised at a single scale, so a finer partition scores lower at the implicit γ=1 by construction. A healthy refinement can therefore never satisfy Q(fine) > Q(coarse) at γ=1 — the check fired on every good build.

Measured generalized modularity Q_γ of the actual coarse/fine partitions across γ on the live (post-threshold) matrix:

γ Q_coarse Q_fine fine > coarse?
0.5 0.529 0.424 no
1.0 0.339 0.281 no
1.5 0.150 0.138 no
2.0 -0.039 -0.005 YES
2.5 -0.228 -0.148 YES

The fine partition only overtakes coarse at γ ≈ 2.0 = BETA_FINE — exactly its design resolution. So the partition is fine; the check was comparing at the wrong scale.

Fix

Replace the assertion with _hierarchy_health_warning(n_coarse, n_fine, q_coarse, q_fine), which tests what issue #33 actually cares about:

Returns None when healthy. Pure function, unit-tested in isolation.

Tests

New TestHierarchyHealthWarning: healthy hierarchy is silent, inverted counts warn, weak structure warns, equal counts OK. Full suite: 563 passed.

detect_communities asserted Q(fine) > Q(coarse) and logged a "sanity check
failed" warning on every build where it didn't hold. That assertion is
mathematically unsound: Newman modularity is resolution-dependent and maximised
at a single scale, so a finer partition scores LOWER at the implicit gamma=1 by
construction. Measured the generalized modularity Q_gamma of the actual coarse
and fine partitions across gamma: coarse wins for all gamma < 2, fine overtakes
at gamma ~ 2.0 == BETA_FINE. So a healthy refinement ALWAYS "failed" the check.

Replace with _hierarchy_health_warning(), which tests the real failure mode
issue #33 is about — the fine level collapsing into FEWER communities than
coarse (n_fine < n_coarse) — plus a MIN_HEALTHY_Q floor catching near-random
partitions. Returns None when healthy. Unit-tested in isolation.
@raphasouthall raphasouthall merged commit 3aa2d86 into main Jun 3, 2026
@raphasouthall raphasouthall deleted the fix/hierarchy-check-resolution-aware branch June 3, 2026 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant