🕸️ Community Detection in Graphs
A Python project for analyzing network structures and detecting communities using various algorithms such as Louvain, Leiden, Infomap, and others.
The project supports both directed and undirected graphs, computes network statistics, detects communities, and exports comparative evaluation results.
📁 Project Structure
community-detection/
├── cd_benchmark/ # Core modules for analysis, detection, statistics, visualization
├── run/ # Executable scripts (entry points)
├── data/ # Input graph datasets
├── examples/ # Example usage scripts and visualizations
├── requirements.txt # Python dependencies
├── pyproject.toml # Package configuration
├── README.md # Project documentation
Getting Started
Installation
Option 1: Install from PyPI (coming soon)
pip install cd-benchmark
Option 2: Install from source
git clone https://github.com/rpritr/network-community-detection-benchmark.git
cd community-detection
pip install -e .
Option 3: Development setup
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
Quick Start
After installation, you can use the package in your Python code:
from cd_benchmark.analysis import CommunityAnalysis
import networkx as nx
# Create or load your graph
G = nx.karate_club_graph()
# Run community detection
ca = CommunityAnalysis(graph=G)
results = ca.run(algorithms=["Louvain", "Leiden", "Infomap"])
print(results)
Run Examples
python -m run.run_statistics
Or run the full benchmarking with configurable algorithms:
python -m run.run_analysis
🔧 Features
- Load graphs from edge list text files (directed or undirected)
- Compute network statistics:
- Node and edge count
- Largest WCC/SCC components
- Clustering coefficient
- Graph density, diameter, and radius
- Community detection algorithms:
- Louvain
- Leiden
- Infomap
- Walktrap
- Girvan-Newman
- Greedy modularity
- Label Propagation
- Fast Label Propagation
- Graph visualization (with Matplotlib / NetworkX)
- Export results to CSV for analysis and comparison
Community Analysis
You can instantiate and run custom analyses as follows:
from cd_benchmark.analysis import CommunityAnalysis
ca = CommunityAnalysis(graph=G) # or file="data/graph.txt"
df = ca.run(algorithms=["Louvain", "Infomap"])
Supported algorithms:
["Louvain", "Leiden", "Infomap", "Girvan Newman", "Greedy Modularity", "Walktrap", "Label Propagation", "Fast Label Propagation"]
Community Benchmark
You can run a full benchmark on 100 iterations as follows:
from cd_benchmark.benchmark import CommunityBenchmark
cb = CommunityBenchmark(graph=G) # or file="data/graph.txt"
df = cb.run()
cb.summarize()
cb.plot_all() # plot and export analysis graphs
Sample Datasets
Example graph format (cit-Patents.txt):
Node1 Node2
12 14
15 17
...
Each line represents a directed edge in the network.
Dependencies
Install all required packages from requirements.txt:
Note: Some community detection methods in
cdlibmay require additional system-level libraries such asgraph-toolorinfomap.
Author
Robi Pritržnik (2025)
🔗 pritrznik.si
📧 Contact: robi@pritrznik.si
License
This project is intended for research and educational purposes only.
Feel free to fork and extend under appropriate attribution.
Dataset Source
Sample networks in this project are based on the SNAP collection:
Leskovec, J., & Krevl, A. (2014). SNAP Datasets: Stanford Large Network Dataset Collection. Retrieved from http://snap.stanford.edu/data
Notes on AI Assistance Disclosure
Parts of this project ( code refactoring and documentation) were developed with the assistance of ChatGPT, based on the GPT-4o model (OpenAI, August 2025).
Metadata
Release files for cd-benchmark 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cd_benchmark-0.1.1.tar.gz | 67.8 MB | Without provenance | Details for cd_benchmark-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cd_benchmark-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for cd_benchmark-0.1.1-py3-none-any.whl |
Total release size: 67.8 MB
Release files / cd_benchmark-0.1.1.tar.gz
| Download URL | cd_benchmark-0.1.1.tar.gz |
|---|---|
| Size | 67.8 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bf142d73819d0234c3938146a373e7db1c2b746d8b3857a842639e9cd128e1be
|
|
BLAKE2b-256 checksum How to use checksums |
166e7758b306d5a9e7129cf6fe78e8ee9876cab297f11fd3abe8a31a7d3bbaf4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.7
|
Release files / cd_benchmark-0.1.1-py3-none-any.whl
| Download URL | cd_benchmark-0.1.1-py3-none-any.whl |
|---|---|
| Size | 13.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e8c086d0d93d5b3db217342965338d4f381337f2374eafff6a7456ecb098e01f
|
|
BLAKE2b-256 checksum How to use checksums |
57c5c58a22489ba644ae168695eddc27f9d938e83e27509daf9cc4cb38a0a919
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.7
|
Security for cd-benchmark 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.