Module centrality
Expand description
Centrality analysis on the behavioural coupling graph.
Promotes the SoC-style coupling_centrality_v1 primitive (a bare
COUNT(*) of Fisher-significant partners, materialised in
code_health::run_code_health) to a first-class analysis with four
per-file scores:
- degree: count of Fisher-significant coupling partners (the
primitive
code_healthalready used; kept as the network-science baseline so the new analysis subsumes the old behaviour). - weighted-degree: sum of edge
degreeweights (the100 * shared / average_revsratio fromCouplingRow) over all Fisher-significant partners. Captures “this file is coupled to N partners strongly”, not just “to N partners”. - pagerank: power-iteration
PageRankwith damping 0.85, weighted by the same edge degrees. Captures “this file is coupled to other well-coupled files” — the recursive influence signal. - eigenvector: power-iteration eigenvector centrality, also
weighted. Same family as
PageRankbut no damping factor — converges faster on the connected component and complementsPageRank’s bias toward dangling nodes.
All four are computed in one pass on a hash-adjacency
representation (no petgraph graph construction overhead — the
coupling graph is sparse, edges already de-duplicated by
(entity_a, entity_b) lexicographic ordering).
§Why these four
Skipped: betweenness (O(V·E) via Brandes — ~3.5B ops on a
linux-kernel-scale 70k-node coupling graph), closeness (O(V³)
— infeasible). PageRank + eigenvector together cover the
“influence in a recursive-trust sense” axis that betweenness
approximates more expensively.
Power iteration is the chosen numeric kernel for both PageRank and
eigenvector centrality because:
- It needs no external linear-algebra crate (no
nalgebra/ndarray-linalgtransitive bloat — both pull in BLAS-shaped dep trees for a single matrix-vector multiply). - The coupling graph’s spectral gap is large in practice (~10-15 iterations to converge to 1e-6 on the codelore-self ~600-edge graph; ~30 on the linux-kernel-scale one).
- The graph is undirected so the dominant eigenvector is guaranteed positive (Perron-Frobenius), no sign-flip handling.
§Research basis
- Degree centrality: classical network-analysis primitive (see e.g. Newman 2010 §7.1).
- Weighted degree: same primitive over the change-coupling weight
space;
CodeLore-specific instantiation. PageRank: Brin & Page 1998. Damping 0.85 is the canonical default.- Eigenvector centrality: Bonacich 1972.
See docs/research-foundations.md entry “centrality” for the
grounded write-up.
Structs§
- Centrality
Row - One row per file appearing in at least one Fisher-significant coupling pair. Files with zero coupling partners are omitted (degree 0 across every variant — would just be noise).
Functions§
- compute_
centrality - Pure-function core of
run_centrality: takes coupling pairs + returns per-file centrality scores. Split out for direct unit-test access without needing aFactsDb. - from_
coupling_ pairs - Convenience: rebuild centrality directly from a
CouplingRowslice for in-memory orchestration (e.g.code_healthconsumes the same pairs to compute coupling centrality alongside its other inputs; without this helper it would either pay a double-run_couplingcost or carry SQL-side state). The error path is unreachable on the in-memory branch — the trait signature keeps callers honest. - run_
centrality - Compute the four centrality scores per file on the Fisher-significant coupling graph.