Skip to content

API reference

Everything below lives in the top-level pymocd namespace. The reference is generated from pymocd.pyi, the type stub that cargo run --bin stub_gen writes from the Rust sources, so every signature and default here is the one the installed package exposes. The docstrings themselves live next to the code, in src/api/ and src/core/algorithms/hpmocd/api.rs.

Two conventions hold throughout:

  • Graphs are NetworkX graphs with integer node ids, or igraph graphs (see Input graphs).
  • Partitions are plain dict[int, int] mapping node to community id. Isolated nodes are assigned community -1.

Detectors

Name Kind Summary
rimpso function rimpso — multi-objective particle swarm optimisation over the Constant Potts Model.
hpmocd function Run HP-MOCD (NSGA-II over Shi's intra/inter objectives) and return the max-modularity member of its rank-1 front.
HpMocd class NSGA-II multi-objective community detection (HP-MOCD) with a configurable budget and optional Python objectives.
cdrme function Run CDRME (Dabaghi-Zarandi, Afkhami & Ashoori, "Community Detection method based on Random walk and Multi objective Evolutionary algorithm in complex networks", Journal of Network and Computer Applications 234:104070, 2025) — softmax-weighted random walks seeded at degree-weighted centres compose a primary community set, a population of stochastic agglomerative merge chains diversifies it under the paper's linkage objective (Eq. 12), and a similarity-driven mutation repairs the weakly attached nodes.
mmcomo function Run MMCoMO (Zhang, Yang, Yang & Zhang, IEEE Computational Intelligence Magazine 18(3):69–86, 2023) — two co-evolving NSGA-II populations, one label-based (micro) and one centre-based (macro), minimizing kernel k-means and ratio cut and coupled through a diffusion-kernel similarity matrix.
ccm function Run NSGA-III-CCM (Shaik, Ravi & Deb, SN Computer Science 2(1):1, 2021) — NSGA-III over the three maximized objectives (Community Score, Community Fitness, Modularity).
krm function Run NSGA-III-KRM (Shaik, Ravi & Deb, SN Computer Science 2(1):1, 2021) — NSGA-III over (Kernel-K-Means, Ratio-Cut, Modularity); KKM & Ratio-Cut minimized, Modularity maximized.
gdpso function Run GDPSO (Cai, Gong, Ma, Ruan, Yuan, Jiao, "Greedy discrete particle swarm optimization for large-scale social network clustering", Information Sciences 316:503–516, 2015) — a swarm of label vectors, each seeded by a short asynchronous label-propagation run, that once per generation turns a sigmoid of the velocity into a binary per-node move mask and offers every masked node an exact single-node modularity move.
mocd_q function Run Shi-MOCD (Shi, Yan, Cai, Wu 2012) — PESA-II over Shi's decomposed-modularity objectives (intra/inter).
mocd_d function Shi-MOCD with the Max-Min Distance (MOCD-D) model selector (Shi et al. 2012, Eqs. 3.9–3.11): returns the Pareto-front member whose (intra, inter) deviates most from rand_networks same-scale Erdős–Rényi control fronts.
moga_net function Run MOGA-Net (Pizzuti, IEEE TEC 16(3):418–430, 2012) — NSGA-II over the (Community Score, Community Fitness) bi-objective.

Pareto fronts

Name Kind Summary
rimpso_fronts function rimpso's archive: the graph's resolution profile.
rimpso_select function Run rimpso's label-free selection rule over partitions produced elsewhere.
hpmocd_fronts function HP-MOCD's rank-1 front, the candidate set hpmocd selects from.
mmcomo_fronts function MMCoMO's merged rank-1 front, the candidate set mmcomo selects from.
ccm_fronts function The rank-1 Pareto front ccm selects from, as a list of partitions.
krm_fronts function The rank-1 Pareto front krm selects from, as a list of partitions.
moga_net_fronts function The rank-1 Pareto front moga_net selects from, as a list of partitions.

Metrics and utilities

Name Kind Summary
gt_metrics function (NMI, AMI, ARI, F1) of a partition against ground truth (gt).
nmi function Normalised mutual information between two {node:community} dicts.
ami function Adjusted mutual information between two {node:community} dicts.
ari function Adjusted Rand index between two {node:community} dicts.
f1 function Pairwise F1 between two {node:community} dicts.
max_cores function Size Rayon's global thread pool.

Benchmark graphs

Name Kind Summary
lfr_graph function LFR benchmark graph with crisp communities, wired to the requested degrees and mixing.

Deprecated aliases

pymocd.mr_mocd, pymocd.mr_mocd_fronts and pymocd.mr_mocd_select are the names RIMPSO carried before it was renamed; pymocd.scale and pymocd.scale_fronts are older still. All five are the same function objects as rimpso, rimpso_fronts and rimpso_select, kept so pinned callers keep working. They emit no warning and are not in the type stub. Use the new names.