CoDeBetHe (Python)
Community Detection with the Bethe Hessian
Pure-Python implementation (NumPy/SciPy, no Julia required) of the spectral community detection algorithms of CoDeBetHe.jl:
- Dall'Amico, Couillet, Tremblay - Revisiting the Bethe-Hessian: improved community detection in sparse heterogeneous graphs (NeurIPS 2019)
- Dall'Amico, Couillet, Tremblay - A unified framework for spectral clustering in sparse graphs (JMLR 2021)
- Dall'Amico, Couillet, Tremblay - Community detection in sparse time-evolving graphs with a dynamical Bethe-Hessian (NeurIPS 2020)
If you use this package, please cite the references above.
pip install codebethe
Static graphs
import numpy as np
from codebethe import matrix_C, create_label_vector, adjacency_matrix_DCSBM, community_detection
n, k, c = 5000, 3, 8.
pi_v = np.ones(k) / k
ℓ = create_label_vector(n, k, pi_v)
θ = np.random.uniform(3, 10, n) ** 4; θ /= θ.mean() # heterogeneous degrees
A = adjacency_matrix_DCSBM(matrix_C(2., c, 0., pi_v), c, ℓ, θ)
res = community_detection(A) # k is estimated if not given
res.ℓ, res.k, res.modularity, res.ζ # labels (0-based), number of classes, modularity, ζ_p
community_detection(A, k=3, ℓ=ℓ).overlap
Time-evolving graphs
from codebethe import adjacency_matrix_DDCSBM, dynamic_community_detection
T, η = 5, 0.7 # number of snapshots, label persistence
AT, ℓ_T = adjacency_matrix_DDCSBM(T, matrix_C(2., c, 0., pi_v), c, η, θ, pi_v)
res = dynamic_community_detection(AT, η, k, ℓ_T=ℓ_T) # approx_embedding=True for large n T
res.ℓ, res.overlap, res.modularity # T x n labels, per-time overlap and modularity
Differences with the Julia package
- Labels are 0-based (
0, ..., k-1); the Julia package uses1, ..., k. - Function names are kept (
community_detection_optimal_BH,dynamic_community_detection_BH), with the shorter aliasescommunity_detectionanddynamic_community_detection.CD_BHreplaces the former PyJulia bridge. - Results are returned as dataclasses (
StaticResult,DynamicResult);overlapisNonewhen no ground truth is given. - Random functions accept a
seed.
Authors
Lorenzo Dall'Amico, Nicolas Tremblay
License
GNU Affero General Public License v3 (see LICENSE), as the original Julia package.
Metadata
Release files for codebethe 0.1.0
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 |
|---|---|---|---|---|
| codebethe-0.1.0.tar.gz | 25.6 kB | Without provenance | Details for codebethe-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| codebethe-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for codebethe-0.1.0-py3-none-any.whl |
Total release size: 50.0 kB
Release files / codebethe-0.1.0.tar.gz
| Download URL | codebethe-0.1.0.tar.gz |
|---|---|
| Size | 25.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b965036852b7359235790a8b512e9bccf0a89dfd473a36fe8a461aff70ff75bf
|
|
BLAKE2b-256 checksum How to use checksums |
7b6054fdeb3b4a91ac4dbe69352bb9be541f108b19dd3b30619222593e6f3f5b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.11
|
Release files / codebethe-0.1.0-py3-none-any.whl
| Download URL | codebethe-0.1.0-py3-none-any.whl |
|---|---|
| Size | 24.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0c0bfaf365655483616495fe9ce73b36f8489b5b449a1e6ccaf45dae791e3082
|
|
BLAKE2b-256 checksum How to use checksums |
11a36a4888b21829cd5db6a1ad5108528263418018d9775554f4d32003282126
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.11
|
Security for codebethe 0.1.0
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.