Hedonic
hedonic is a Python library for hedonic community detection on
igraph graphs. Its Game wrapper exposes one API for
both ordinary partitions and overlapping community covers.
The native Leiden implementation is provided by the lucas-igraph dependency;
Hedonic 0.1.1 installs lucas-igraph==1.0.0.4 automatically.
Installation
The released package supports Python 3.12 and newer:
python -m pip install hedonic
With uv:
uv add hedonic
Quick start
import igraph as ig
from hedonic import Game
graph = Game(ig.Graph.Famous("Zachary"))
# Disjoint partition: one community per vertex.
partition = graph.community_hedonic(
resolution=graph.density(),
max_memberships=1,
n_iterations=-1,
)
print(partition.membership)
# Overlapping cover: a vertex may belong to up to four communities.
cover = graph.community_hedonic(
resolution=graph.density(),
max_memberships=4,
n_iterations=-1,
)
print(cover)
community_hedonic returns an igraph.VertexClustering when
max_memberships=1 and an igraph.VertexCover when the cap is greater than
one. Overlapping warm starts accept a flat or per-vertex nested
initial_membership; disjoint warm starts use flat labels.
The native no-change stop is not a standalone mathematical certificate. Audit the returned memberships independently when a certificate is required.
Useful options include:
local_move_only=Truefor the hedonic local-moving phase, orFalsefor the full Leiden refinement and aggregation pipeline;n_iterations=-1(the default) to run until the native no-change stopping condition;allow_isolation,edge_weights,seed, andbetato control the model;resolutionto select the CPM resolution parameter.
For reproducible overlapping experiments, use an undirected, loopless graph with finite weights and explicitly record the resolution, membership cap, initialization, and seed used for each run.
Experiments
Install the optional experiment dependencies to use the experiment drivers:
python -m pip install "hedonic[experiments]"
hedonic-exp list
hedonic-exp smoke
The hedonic-exp commands cover small smoke checks, synthetic disjoint
experiments, overlapping diagnostics, and reproducible benchmark pipelines.
Experiment data paths can be configured with the TOML files under configs/
or with the documented HEDONIC_*_DIR environment variables.
Development
git clone https://github.com/lucaslopes/hedonic-game.git
cd hedonic-game
uv sync --extra experiments
uv run --with pytest pytest -q
uv build --no-sources
The public API is intentionally small:
from hedonic import Game
Research manuscripts, private evidence, and manuscript-only configuration are
kept outside the public main publication boundary.
Releases and publishing
Hedonic versions are independent from the four-component release identity of
the native lucas-igraph dependency. A dependency update can therefore be a
normal Hedonic patch release without changing the community_hedonic call
pattern.
Pushes to public main run tests and save wheel/sdist artifacts. After that
exact commit passes, a matching version tag publishes those saved artifacts
using scripts/release.sh; publication does not rebuild the package. See
the release guide. Credentials must be supplied through the configured secret or a
hidden interactive environment variable; never put a PyPI token directly in a
shell command, README, commit, or issue.
License
This project is distributed under the GNU General Public License, version 3 or later. See LICENSE for the complete terms.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hedonic-0.1.1.tar.gz.
File metadata
- Download URL: hedonic-0.1.1.tar.gz
- Upload date:
- Size: 188.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.12.13 {"installer":{"name":"uv","version":"0.12.13","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c3f483e006c034278e80fd214206c0c4b5f66cdff4f102ebe88338daa73e61c7
|
|
| MD5 |
6b9b8031bd3a61c927a6a62c79605f7c
|
|
| BLAKE2b-256 |
7c9c0bb8a0cbc65661a913304f98f8cf508b814c6e986d112d452f164d9ec20d
|
File details
Details for the file hedonic-0.1.1-py3-none-any.whl.
File metadata
- Download URL: hedonic-0.1.1-py3-none-any.whl
- Upload date:
- Size: 207.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.12.13 {"installer":{"name":"uv","version":"0.12.13","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
08d920ce365f0c230e657d4efe16663be2bc8d7eb939d3a8135bab2aa0434db5
|
|
| MD5 |
b77560337452f5bdd0f0392837be8495
|
|
| BLAKE2b-256 |
118cd71f139694bfede644de0a7780ec8d280f28089b8db2c32970cb256a4b89
|