Skip to main content
pymocd logo

Multi-Objective Community Detection Algorithms

PyPI Publish Rust Compilation PyPI - Version PyPI - License

pymocd is a Python library, powered by a Rust backend, for multi-objective evolutionary community detection in complex networks. The evolutionary core is written in Rust and exposed through PyO3, giving it a large speed advantage over pure-Python implementations while staying a drop-in for the NetworkX / igraph ecosystem, making it well-suited to large-scale graphs.

Read the Documentation for detailed guidance and usage instructions.


Getting started

pip install pymocd
import networkx as nx
import pymocd

G = nx.karate_club_graph()          # any NetworkX / igraph graph, integer node ids
communities = pymocd.scale(G)       # -> dict[node, community]

[!IMPORTANT] Graphs must be in NetworkX or igraph compatible format with integer node ids. Isolated nodes are assigned community -1.

Every detector returns a single crisp partition as dict[node, community].

Algorithms

pymocd ships eight detectors. SCALE and HP-MOCD are the library's own contributions; the remaining six are faithful re-implementations of published baselines (the original authors released no code).

API Algorithm Objectives & engine Solution selection Year
scale SCALE (Santos, in prep.) KKM / ratio-cut bi-objective, sparse macro–micro co-evolutionary NSGA-II (near-linear, no dense kernel) label-free SBM/MDL description length 2026
hpmocd HP-MOCD (Santos et al.) decomposed modularity, parallel NSGA-II max modularity Q 2025
mmcomo MMCoMO (Zhang et al.) kernel k-means + ratio cut, macro/micro co-evolutionary NSGA-II max Q (front via mmcomo_fronts) 2023
ccm CCM (Shaik et al.) score + fitness + modularity, NSGA-III max Q 2021
krm KRM (Shaik et al.) kernel k-means + ratio cut + modularity, NSGA-III max Q 2021
mocd_q Shi-MOCD (Shi et al.) decomposed modularity, PESA-II max Q 2012
mocd_d Shi-MOCD (Shi et al.) decomposed modularity, PESA-II max-min distance to random nets 2012
moga_net MOGA-Net (Pizzuti) community score + fitness, NSGA-II max Q 2009

SCALE is the recommended crisp detector: it co-evolves a macro population of medoid community centres with a micro population of per-node labels over the kernel k-means / ratio-cut bi-objective, bridged by a sparse similarity carried on the graph's edges rather than a dense n×n kernel — so memory is O(n+m) and it scales to graphs the dense macro–micro baseline cannot build. The merged rank-1 front is enriched by a union refinement, and one partition is returned with no ground truth by minimising a label-free microcanonical SBM description length.

Usage

import pymocd

# Recommended detectors (defaults work out of the box)
part = pymocd.scale(G)            # SCALE, sparse co-evolution + SBM/MDL selection
part = pymocd.hpmocd(G)           # HP-MOCD

# Baselines (sensible defaults; pop_size / num_gens / rates are tunable kwargs)
part = pymocd.mocd_q(G)           # Shi-MOCD, max-modularity selection
part = pymocd.mocd_d(G)           # Shi-MOCD, max-min-distance selection
part = pymocd.moga_net(G)         # MOGA-Net (Pizzuti)
part = pymocd.ccm(G)              # NSGA-III CCM (Shaik et al.)
part = pymocd.krm(G)              # NSGA-III KRM (Shaik et al.)
part = pymocd.mmcomo(G)           # MMCoMO (Zhang et al.), macro/micro co-evolution

# All return dict[node, community]; isolated nodes -> -1

scale accepts the same evolutionary kwargs as mmcomo (pop_size=100, num_gens=50, cross_rate=0.1, mut_rate=0.1, gap=10, beta=0.05) plus adaptive_stop=False / conv_pval=0.1 — with adaptive_stop=True the search self-terminates once a Welch t-test detects a convergence plateau and num_gens becomes only a safety ceiling.

The Pareto frontier of some algorithms is exposed for inspection:

fronts = pymocd.scale_fronts(G)      # list[dict[node, community]]
fronts = pymocd.mmcomo_fronts(G)     # list[dict[node, community]]

Helpers:

pymocd.max_cores(8)                  # set Rayon thread pool (first call wins)

# Fast native ground-truth agreement metrics between two {node: community}
# dicts, computed over their shared nodes (exact AMI, matches scikit-learn):
nmi, ami, ari, f1 = pymocd.gt_metrics(partition, gt)
pymocd.nmi(partition, gt)            # or each metric individually
pymocd.ami(partition, gt)
pymocd.ari(partition, gt)
pymocd.f1(partition, gt)             # pairwise F1

Contributing

Contributions are welcome, open an issue or a pull request for features, bug fixes, or improvements. This project is licensed under GPL-3.0 or later.


Citation

If you use any algorithm in your research, please cite:

@article{Santos2025,
  author    = {Santos, Guilherme O. and Vieira, Lucas S. and Rossetti, Giulio and Ferreira, Carlos H. G. and Moreira, Gladston J. P.},
  title     = {A high-performance evolutionary multiobjective community detection algorithm},
  journal   = {Social Network Analysis and Mining},
  year      = {2025},
  volume    = {15},
  number    = {1},
  pages     = {110},
  doi       = {10.1007/s13278-025-01519-7},
  url       = {https://doi.org/10.1007/s13278-025-01519-7},
  issn      = {1869-5469},
  date      = {2025-11-18}
}

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pymocd-5.0.1.tar.gz (1.3 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pymocd-5.0.1-cp313-cp313-win_amd64.whl (600.6 kB view details)

Uploaded CPython 3.13Windows x86-64

pymocd-5.0.1-cp313-cp313-manylinux_2_34_x86_64.whl (700.5 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

pymocd-5.0.1-cp313-cp313-macosx_11_0_arm64.whl (616.2 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pymocd-5.0.1-cp312-cp312-win_amd64.whl (600.9 kB view details)

Uploaded CPython 3.12Windows x86-64

pymocd-5.0.1-cp312-cp312-manylinux_2_34_x86_64.whl (701.0 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

pymocd-5.0.1-cp312-cp312-macosx_11_0_arm64.whl (616.4 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pymocd-5.0.1-cp311-cp311-win_amd64.whl (601.8 kB view details)

Uploaded CPython 3.11Windows x86-64

pymocd-5.0.1-cp311-cp311-manylinux_2_34_x86_64.whl (701.6 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

pymocd-5.0.1-cp311-cp311-macosx_11_0_arm64.whl (620.9 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pymocd-5.0.1-cp310-cp310-win_amd64.whl (603.2 kB view details)

Uploaded CPython 3.10Windows x86-64

pymocd-5.0.1-cp310-cp310-manylinux_2_34_x86_64.whl (700.8 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

pymocd-5.0.1-cp310-cp310-macosx_11_0_arm64.whl (622.1 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file pymocd-5.0.1.tar.gz.

File metadata

  • Download URL: pymocd-5.0.1.tar.gz
  • Upload date:
  • Size: 1.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.10.20

File hashes

Hashes for pymocd-5.0.1.tar.gz
Algorithm Hash digest
SHA256 6102fdebbf3fe158c674160ecd845248bcd6f0295c97ee766dd56b7b5285449e
MD5 9163d44e49454f47f9203dde457712f9
BLAKE2b-256 550db02ab0e3c7d5726682dd707fbe7fd80aee8f4d8389a8a869f6427245fe49

See more details on using hashes here.

File details

Details for the file pymocd-5.0.1-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: pymocd-5.0.1-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 600.6 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.10.20

File hashes

Hashes for pymocd-5.0.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 2f144bcb2ba528f11c9fb50fd1102c156e0b5ccf0b2e1c57a631f0001aa78ebb
MD5 4b3534f49a9ee8f34f8bf0d8e25a1778
BLAKE2b-256 7994f2d8992ef1fa94179c4039ac52ba03e62e6d817d74c911fb979e50aa0247

See more details on using hashes here.

File details

Details for the file pymocd-5.0.1-cp313-cp313-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for pymocd-5.0.1-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 a28bdd7bd5acc0833fb991adf8d87617e0fbd5d67710558f8bbf5b95ea8ca1fb
MD5 080c2753291bee771aa8d317ec00fb31
BLAKE2b-256 8fcf89009ff6471697c926d818dd5e716319d81f6791baac822d5351fb1d1649

See more details on using hashes here.

File details

Details for the file pymocd-5.0.1-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pymocd-5.0.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 56836a06b159304f5d7d2d1b311d853999500592a3408ffedbf29099ee76c69c
MD5 8a4a9cac69fc5e9c95f15c0defb21fb0
BLAKE2b-256 0cb09251d567dc50270fcb6fac3e4523e98ef15e6f4fc3762a21e62e38884fa5

See more details on using hashes here.

File details

Details for the file pymocd-5.0.1-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: pymocd-5.0.1-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 600.9 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.10.20

File hashes

Hashes for pymocd-5.0.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 680fa954c19fa78071931fd041c0962c77417ee7b2a4f8d6dd2765cc3f346a8c
MD5 5ab178c0ca146b14570bdbd1d296a576
BLAKE2b-256 484a0fc4e439486e62d398daebea0f9073a0443a05485f059e7f79a521a5c4ee

See more details on using hashes here.

File details

Details for the file pymocd-5.0.1-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for pymocd-5.0.1-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 8626b0a9865c91812e5d79b7a419f2bca75a91186ff0b3801081527ff4e59d1b
MD5 2e028af9804c3a2dea4d86ca18e72095
BLAKE2b-256 add336110fc865650cb29e6ab4ec79e9466a6322cbb8fac4f58bec94edffbe67

See more details on using hashes here.

File details

Details for the file pymocd-5.0.1-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pymocd-5.0.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cee8615b686cc450093dd5fd71eb179cd7dafd0a8aeb4d592f8568ef590dd571
MD5 72c9a935bd85e951293a1c5315437599
BLAKE2b-256 6de5bf1d50b57b0dfa6698d267ca53508e0abdd431fe9f7cbcdf86d4e2c29042

See more details on using hashes here.

File details

Details for the file pymocd-5.0.1-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: pymocd-5.0.1-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 601.8 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.10.20

File hashes

Hashes for pymocd-5.0.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 d18b1b90361d8b1105a5a2e747d4c10eb795f56df36369ddc9e09b71a175522a
MD5 d86d884605fe88fc4013899413f10857
BLAKE2b-256 10ebabef315f574deb536afa034bfd5d4f440a26fdc2ef160780583e4c5e0fd1

See more details on using hashes here.

File details

Details for the file pymocd-5.0.1-cp311-cp311-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for pymocd-5.0.1-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 18ad5f19e5c90dfa1e88a5135a01a8e0f6c80b169b0d73fc6220019f14037fd6
MD5 b281321e88516d484ab811ba5c522fd2
BLAKE2b-256 564b39e2668bf70d9944bfd961880eb2a35f3e9de1bfa4f692941ff352354b7c

See more details on using hashes here.

File details

Details for the file pymocd-5.0.1-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pymocd-5.0.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 65a9c812f9f4cf7b36c47c4ac61748fce37b90197f547c2102c68547b6b5f2f1
MD5 b2dfb89c3176d19e494b122151771a84
BLAKE2b-256 6dd630a97cc7f32483caf574db34dc6ea3bc1f1a289ab66e4c4327a676a36738

See more details on using hashes here.

File details

Details for the file pymocd-5.0.1-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: pymocd-5.0.1-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 603.2 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.10.20

File hashes

Hashes for pymocd-5.0.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 f1305ab35170e4c1f8e20cd32d1e4060aefee6b557a236ceb921b2e52d700d38
MD5 cc7c61d281be7fa4f9ec18144b9d38fd
BLAKE2b-256 1821c31fcf386bc0e7e216fa87625675ceb7e0e121d4ca64f5167633528d2a8c

See more details on using hashes here.

File details

Details for the file pymocd-5.0.1-cp310-cp310-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for pymocd-5.0.1-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 82b1936b607094a050077e27e34d90f16e16f6f3120937b5a9c38efa6238a25a
MD5 eacf459524400a921a9486e65cfdd9c3
BLAKE2b-256 ffe40033c2b75c29d2142260a49186a290904762487d8a3be6ca521acf8446a1

See more details on using hashes here.

File details

Details for the file pymocd-5.0.1-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pymocd-5.0.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c5871f61deac0b652ab7023148c75b9c7419cde4d9d2e8e3e8be3ab0a5e43218
MD5 6fdf86f49087ba39b9f001966620b371
BLAKE2b-256 395cb779f22ab5901b0922a32f33f38920bc53b1b80d6e470795848ea04ca5e3

See more details on using hashes here.

Release history Release notifications | RSS feed

5.1.0

13 files

This release

5.0.1 This release

13 files

4.0.0

13 files

3.0.0

16 files

2.0.2

16 files

2.0.0

16 files

1.5.1

16 files

1.5.0

16 files

1.3.0

16 files

1.2.5

16 files

1.1.3

16 files

1.0.3

16 files

1.0.1

16 files

1.0.0

16 files

0.2.0

16 files

0.1.0

16 files

0.0.1

16 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page