meanap.pipeline.modularity¶
Consensus-clustering modularity, port of mod_consensus_cluster_iterate.m.
Runs Louvain community detection (louvain.py) many times, builds a
consensus co-classification matrix (Lancichinetti & Fortunato 2012), and
repeats on the thresholded consensus matrix until it becomes block-diagonal
(stable partition).
Not bit-reproducible against MATLAB. Louvain’s local-moving phase visits
nodes in a random order each pass (randperm in MATLAB, a different RNG
stream than Python’s), so the specific community labels and even the
partition itself can differ between MATLAB and Python runs — same situation
as Step 3’s probabilistic thresholding. What’s expected to match is
quality: modularity Q should land in a similar range, and consensus
clustering should still converge to a stable, block-diagonal partition.
Functions
|
Co-classification matrix: fraction of partitions where i, j share a module. |
True if |
|
|
Returns (Ci, Q, num_repeats): consensus community affiliation + modularity. |
- meanap.pipeline.modularity.consensus_coclassify(partitions)[source]¶
Co-classification matrix: fraction of partitions where i, j share a module.
- Parameters:
partitions (list[ndarray])
- Return type:
ndarray
- meanap.pipeline.modularity.consensuscheck(d)[source]¶
True if
dis binary (only 0s and 1s) and symmetric (block-diagonal).- Parameters:
d (ndarray)
- Return type:
bool
- meanap.pipeline.modularity.mod_consensus_cluster_iterate(adj_m, threshold=0.4, rep_num=50, rng=None, max_outer_iterations=50)[source]¶
Returns (Ci, Q, num_repeats): consensus community affiliation + modularity.
max_outer_iterationsis a safety cap not present in MATLAB (which loops unconditionally until block-diagonal) — consensus clustering on real data converges in a handful of iterations; this just prevents a pathological input from hanging forever.- Parameters:
adj_m (ndarray)
threshold (float)
rep_num (int)
rng (Generator | None)
max_outer_iterations (int)
- Return type:
tuple[ndarray, float, int]