Skip to main content

Community detection via Louvain/Leiden + Genetic Algorithm

Project description

TAU Community Detection

PyPI License: MIT Python 3.10+

tau-community-detection implements TAU, an evolutionary community detection algorithm that couples genetic search with Leiden refinements. It is designed for scalable graph clustering with configurable hyper-parameters and multiprocessing support.


Highlights

  • Evolutionary search: Maintains a population of candidate partitions and applies crossover/mutation tailored for graph clustering.
  • Leiden optimisation: Refines every candidate with Leiden to ensure modularity gains.
  • Multiprocessing aware: Utilises worker pools for population optimisation.
  • Deterministic options: Accepts a user-specified random seed for reproducibility.
  • Simple API: Access everything through the TauClustering class.

Installation

The project targets Python 3.10 or newer (required for slot-based dataclasses).

pip install tau-community-detection

To work from a clone, install the package in editable mode inside a virtual environment:

git clone https://github.com/HillelCharbit/community_TAU.git
cd community_TAU
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
pip install -e .

Quick Start (Python API)

from tau_community_detection import TauClustering

clustering = TauClustering(
    graph_source="path/to/graph.adjlist",
    population_size=80,
    max_generation=250,
)
membership, modularity_history = clustering.run()

print("community for node 0:", membership[0])
print("best modularity:", modularity_history[-1])

Graph input

TauClustering accepts either an igraph/NetworkX graph object or the path to an adjacency list that NetworkX can parse (see nx.read_adjlist). Nodes are internally remapped to contiguous integers to maximise igraph performance.


Example Script

The repository ships with a runnable example that uses the bundled src/tau_community_detection/examples/example.graph file. To execute it from the project root:

python3 src/tau_community_detection/run_clustering.py

The script prints the detected membership vector and the modularity score history.

Note: multiprocessing may be restricted inside some sandboxed environments. Run the example on a local machine for best results.


Configuration

All algorithm hyper-parameters live on the TauConfig dataclass. You can pass a custom configuration instance to TauClustering or adjust attributes on the default one. Key fields include:

  • population_size: number of partitions maintained per generation.
  • max_generations: upper bound on evolutionary iterations.
  • elite_fraction / immigrant_fraction: govern selection pressure.
  • stopping_generations / stopping_jaccard: convergence checks based on membership stability.
  • random_seed: makes runs reproducible across processes.

See src/tau_community_detection/config.py for the complete list.


Development Workflow

  • Format imports and style according to your preferred tooling (no formatter is enforced).
  • Validate new changes by executing the example script or custom experiments.
  • When contributing, ensure dependency pins remain compatible with Python 3.10+.

Pull requests are welcome—please include context on parameter changes or performance observations when proposing algorithmic tweaks.


License

Released under the MIT License. See LICENSE for details.

Project details


Download files

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

Source Distribution

tau_community_detection-1.0.2.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

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

tau_community_detection-1.0.2-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

Details for the file tau_community_detection-1.0.2.tar.gz.

File metadata

  • Download URL: tau_community_detection-1.0.2.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for tau_community_detection-1.0.2.tar.gz
Algorithm Hash digest
SHA256 1d1303e4ebfab99885bfb539f1aa5f798c5780c3cc07e66e988017267cd1aecf
MD5 42643e4bd899a4c01ee27b478945370f
BLAKE2b-256 a04f4def96c12f522735cd418dbfc8955d9cf439ecd568a14ea350640bee2b1b

See more details on using hashes here.

File details

Details for the file tau_community_detection-1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for tau_community_detection-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4eebad3b29a32384db16a5175d15b1bd740b816e3a7c5ade46c5cca8ef2f74a1
MD5 7de58e2e8652b4f644fcda853416d025
BLAKE2b-256 823139be3e8cf6db0d96b2a1b04aefdabaa815d15ca9371b7c7d3add7dc8dd08

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page