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
import networkx as nx

graph = nx.read_adjlist("path/to/graph.adjlist")

clustering = TauClustering(
    graph,
    population_size=80,
    max_generations=250,
)
membership, modularity_history = clustering.run()

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

Need detailed per-generation metrics? Call run(track_stats=True) to receive (membership, modularity_history, generation_stats) where generation_stats is a list of dictionaries containing time and fitness diagnostics.


### Graph input

`TauClustering` accepts either an `igraph.Graph` or a `networkx.Graph` instance. Nodes are
internally remapped to contiguous integers to maximise igraph performance. If your data
resides on disk, load it into memory first (for example with `nx.read_adjlist`) before
initializing `TauClustering`.

---

## 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:

```bash
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

pip install -r requirements-dev.txt
make lint
make test

To build local distributions:

make build

Continuous Integration

  • GitHub Actions run lint, tests, and package builds on pushes and pull requests.
  • Set the CODECOV_TOKEN secret to upload coverage reports.

Publishing

  1. Bump the version in setup.cfg/pyproject.toml and commit.
  2. Tag the release with git tag vX.Y.Z && git push --tags.
  3. Run the Publish Package workflow (defaults to TestPyPI). For PyPI, supply the pypi input and ensure PYPI_API_TOKEN is set. Use TEST_PYPI_API_TOKEN for dry runs.

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.1.7.tar.gz (15.8 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.1.7-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tau_community_detection-1.1.7.tar.gz
  • Upload date:
  • Size: 15.8 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.1.7.tar.gz
Algorithm Hash digest
SHA256 cb02ae4da1986a18e2b9d59beb2957cb979b3074e7d1106bc9be66030a51ef33
MD5 5ffe403b42290c3b5a109aa03e12cb93
BLAKE2b-256 8a74f089d0e4b74e913254c4b5df0ac1b6a2ae233aad2d03836d9369adbb5edd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tau_community_detection-1.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 cac0a7a660bfc49137e9b3cf00748cbd33d5900ac35aff548e4ea0042a5cdc58
MD5 0398088c6069834b4bc50e35b1b04349
BLAKE2b-256 541c9b9222228b72386cfbac8c4b1a4e1a2545e704b8f480093416707c2d12bb

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