feat(arch): replace single-level Louvain with multi-level Leiden community detection
The previous community detection ran a single local-moving pass with no aggregation or refinement, so it fragmented graphs into hundreds of tiny, sometimes internally-disconnected clusters (e.g. 275 on a mid-size repo). Implement the Leiden algorithm (Traag, Waltman & van Eck 2019, arXiv:1810.08473): local moving (fast, queue-based) -> refinement -> graph aggregation, repeated until the partition can no longer be coarsened. The refinement phase re-derives each community bottom-up from singletons, merging only along edges, which guarantees every reported community is internally connected. Aggregation seeds each level from the prior move-phase partition so coarse structure carries over. A resolution parameter controls granularity. Internals use a CSR graph (cbm_lg_t); self-loops are folded into the weighted degree rather than materialised, so the modularity gain uses degree for the null model and the adjacency for connectivity. cbm_louvain is preserved as a thin wrapper over cbm_leiden(resolution=1.0) for API compatibility. Tests: multi-level collapse (32-node clique chain -> few connected communities), resolution control (path graph granularity), and a connectivity checker proving the refinement guarantee; existing Louvain tests still pass. Closes #57
M
Martin Vogel committed
955b87d3fd31552bbd8885b63f6e6194c50c50ff
Parent: eb50569