A package for fast community detection in graphs using the Louvain method with Numba optimization.
Project description
Louvain-Numba
Louvain-Numba is a Python library for community detection in graphs using the Louvain method with Numba optimization. This library leverages Numba to accelerate the community detection process, making it suitable for large-scale graphs.
Features
- Efficient community detection using the Louvain method
- Optimized with Numba for high performance
- Supports various graph input types (NetworkX, NumPy arrays, SciPy sparse matrices)
- Generates hierarchical community structures
Installation
You can install Louvain-Numba via pip:
pip install louvain-numba
Or using Poetry:
poetry add louvain-numba
Usage
Basic Usage
import networkx as nx
import louvain_numba as lvn
# Create a random graph
G = nx.random_partition_graph([100, 100, 100], 0.1, 0.01)
# Find the best partition
partition = lvn.best_partition(G)
print("Best partition:", partition)
# Calculate modularity
modularity = lvn.modularity(partition, G)
print("Modularity:", modularity)
Specify prefered number of clusters
import networkx as nx
import louvain_numba as lvn
# Create a random graph
G = nx.random_partition_graph([100, 100, 100], 0.1, 0.01)
# Find the best partition
partition = lvn.best_partition(G, n_clusters=(7, 10))
print("Best partition:", partition)
# Calculate modularity
modularity = lvn.modularity(partition, G)
print("Modularity:", modularity)
Full Hierarchy
import networkx as nx
import louvain_numba as lvn
# Create a random graph
G = nx.random_partition_graph([100, 100, 100], 0.1, 0.01)
# Generate full hierarchy of partitions
for level, (partition, modularity) in enumerate(lvn.find_partitions(G, return_modularity=True)):
print(f"Level {level}:")
print("Partition:", partition)
print("Modularity:", modularity)
Contributing
Contributions are welcome! If you have any suggestions, bug reports, or feature requests, please open an issue or submit a pull request on GitHub. License
This project is licensed under the MIT License. See the LICENSE file for details.
Acknowledgements
This library was inspired by the cylouvain package and leverages Numba for performance optimization.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file louvain-numba-0.0.1.tar.gz
.
File metadata
- Download URL: louvain-numba-0.0.1.tar.gz
- Upload date:
- Size: 7.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.12 CPython/3.10.12 Linux/6.5.0-41-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | afd227b3c886c1cb0fd935ca4478fef29cf6ffd209d8d49cfdde86ebc373f8e4 |
|
MD5 | ff916cd112e7930d83dff089157d5527 |
|
BLAKE2b-256 | b52517921438f0dc634a6a5ec4961b75c9d5fcd72039a29f516ae92ec2773814 |
File details
Details for the file louvain_numba-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: louvain_numba-0.0.1-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.12 CPython/3.10.12 Linux/6.5.0-41-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 278135f8c46586889f8ac6c9246df998d6b7907d5b032d8f740d653586a57937 |
|
MD5 | bf57bcc2c9d9c3ff49848b6e5261705c |
|
BLAKE2b-256 | 61281052336e0f2a2cd213ee919df130fd2de1721450b057bffef2d5c72d609e |