Detectors¶
Every detector takes a graph and returns a partition as dict[node, community]. Isolated nodes are assigned community -1.
pymocd.scale
¶
scale(
graph: Any,
pop_size: int = 100,
num_gens: int = 50,
cross_rate: float = 0.1,
mut_rate: float = 0.1,
gap: int = 10,
beta: float = 0.05,
adaptive_stop: bool = False,
conv_pval: float = 0.1,
) -> typing.Any
scale — optimized MMCoMO variant (sparse-CSR similarity, Rayon-parallel,
union-refined Pareto front). Returns the label-free-selected member of the
merged rank-1 front. Isolated nodes get -1.
pymocd.hpmocd
¶
hpmocd(graph: Any) -> builtins.dict[builtins.int, builtins.int]
Run HP-MOCD (NSGA-II) with defaults. For tuning, use the HpMocd class.
Returns dict[node, community]. Isolated nodes get -1.
pymocd.HpMocd
¶
NSGA-II multi-objective community detection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
networkx.Graph or DiGraph. |
required | |
debug_level
|
0 silent, 1+ logs every 10 generations. |
required | |
pop_size
|
NSGA-II population size. |
required | |
num_gens
|
number of generations. |
required | |
cross_rate
|
crossover probability. |
required | |
mut_rate
|
mutation probability. |
required | |
objectives
|
optional list of callables |
required |
generate_pareto_front
¶
generate_pareto_front() -> builtins.list[
tuple[
builtins.dict[builtins.int, builtins.int], builtins.list[builtins.float]
]
]
Return all non-dominated solutions as [(partition, objectives), ...].
Objective order matches the configured objectives (or intra/inter).
run
¶
run() -> builtins.dict[builtins.int, builtins.int]
Run and return the best partition (max-Q from the Pareto front).
Isolated nodes get community -1.
set_objectives
¶
set_objectives(objectives: list) -> None
Replace the objectives. Empty list reverts to built-in intra/inter.
set_on_generation
¶
set_on_generation(callback: Optional[Any]) -> None
Register per-generation callback (gen, num_gens, front_size) -> None.
Pass None to clear.
pymocd.mmcomo
¶
mmcomo(
graph: Any,
pop_size: int = 100,
num_gens: int = 50,
cross_rate: float = 0.1,
mut_rate: float = 0.1,
gap: int = 10,
beta: float = 0.05,
) -> typing.Any
MMCoMO macro-micro co-evolutionary detector (Zhang et al.); returns the max-modularity member of the merged rank-1 front. Isolated nodes get -1.
pymocd.mocd_q
¶
mocd_q(
graph: Any,
pop_size: int = 100,
num_gens: int = 100,
cross_rate: float = 0.9,
mut_rate: float = 0.1,
) -> builtins.dict[builtins.int, builtins.int]
Run Shi-MOCD (Shi, Yan, Cai, Wu 2012) — PESA-II over Shi's decomposed-modularity objectives (intra/inter). Returns the max-modularity member of the Pareto front (MOCD-Q selection, Shi Eq. 3.8).
Defaults: pop=100, gen=100, C_R=0.9, M_R=0.1; pass Shi's own
(e.g. cross_rate=0.6, mut_rate=0.4) via kwargs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
Any
|
networkx.Graph or igraph.Graph (integer node ids). |
required |
Returns:
| Type | Description |
|---|---|
dict[int, int]
|
|
pymocd.mocd_d
¶
mocd_d(
graph: Any,
pop_size: int = 100,
num_gens: int = 100,
cross_rate: float = 0.9,
mut_rate: float = 0.1,
rand_networks: int = 3,
) -> builtins.dict[builtins.int, builtins.int]
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 degree-preserving random control fronts.
Returns:
| Type | Description |
|---|---|
dict[int, int]
|
|
pymocd.moga_net
¶
moga_net(
graph: Any,
pop_size: int = 300,
num_gens: int = 30,
cross_rate: float = 0.8,
mut_rate: float = 0.2,
r: float = 2.0,
alpha: float = 1.0,
) -> builtins.dict[builtins.int, builtins.int]
Run MOGA-Net (Pizzuti, IEEE TEC 16(3):418–430, 2012) — NSGA-II over the (Community Score, Community Fitness) bi-objective. Returns the max-modularity member of the rank-1 Pareto front (Pizzuti Sec. V-E).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
Any
|
networkx.Graph or igraph.Graph (integer node ids). |
required |
r
|
float
|
Community Score power-mean exponent (resolution knob; higher helps at high mixing). Pizzuti default 2. |
2.0
|
alpha
|
float
|
Community Fitness exponent (larger → smaller communities). Pizzuti default 1. |
1.0
|
Returns:
| Type | Description |
|---|---|
dict[int, int]
|
|
pymocd.ccm
¶
ccm(
graph: Any,
pop_size: int = 200,
num_gens: int = 100,
cross_rate: float = 0.8,
mut_rate: float = 0.014705882352941176,
r: float = 1.0,
alpha: float = 1.0,
divisions: int = 12,
) -> builtins.dict[builtins.int, builtins.int]
Run NSGA-III-CCM (Shaik, Ravi & Deb, SN Computer Science 2:13, 2021) — NSGA-III over the three maximized objectives (Community Score, Community Fitness, Modularity). Returns the max-modularity member of the rank-1 Pareto front (the paper's recommended ground-truth-free decision rule).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
Any
|
networkx.Graph or igraph.Graph (integer node ids). |
required |
r
|
float
|
Community Score power-mean exponent (Shaik default 1). |
1.0
|
alpha
|
float
|
Community Fitness exponent (Shaik default 1). |
1.0
|
divisions
|
int
|
Das–Dennis reference-point granularity |
12
|
Returns:
| Type | Description |
|---|---|
dict[int, int]
|
|
pymocd.krm
¶
krm(
graph: Any,
pop_size: int = 100,
num_gens: int = 100,
cross_rate: float = 0.8,
mut_rate: float = 0.029411764705882353,
divisions: int = 12,
) -> builtins.dict[builtins.int, builtins.int]
Run NSGA-III-KRM (Shaik, Ravi & Deb, SN Computer Science 2:13, 2021) — NSGA-III over (Kernel-K-Means, Ratio-Cut, Modularity); KKM & Ratio-Cut minimized, Modularity maximized. Returns the max-modularity member of the rank-1 Pareto front (the paper's recommended ground-truth-free decision rule).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
Any
|
networkx.Graph or igraph.Graph (integer node ids). |
required |
divisions
|
int
|
Das–Dennis reference-point granularity |
12
|
Returns:
| Type | Description |
|---|---|
dict[int, int]
|
|