Connected Path Graph Clustering
A library for algorithms for the connected k-center problem (as described in [1]). In this problem setting, the input consists of a point set $P$ and a desired number of centers $k$, along with a connectivity graph $G = (P,E)$. The goal is to partition $P$ into (at most) $k$ clusters $C_1, \ldots, C_k$, such that, for every $i$, the subgraph of $G$ induced by $C_i$ is connected.
As of now, only an algorithm for path graphs is implemented. A path graph is a graph whose connected components are simple paths. This algorithm was developed by Johanna Hillebrand and implemented by Julius Mann.
References
[1] Drexler, L., Eube, J., Luo, K., Reineccius, D., Röglin, H., Schmidt, M., & Wargalla, J. (2024). Connected k-center and k-diameter clustering. Algorithmica, 86(11), 3425-3464.
Installation
pip install connected_k_center
Usage
The estimator expects a number $k$ of desired clusters and (optionally) a string that specifies the metric. Possible values are "rmse" (default), "euclidean" and "manhattan".
The fit method expects two arguments: A 2d numpy array of dimension $n\times d$ (where n is the number points and d the dimension they live in), and a numpy array of integers, specifying connected component IDs. If there is only one connected component, this argument can be omitted.
from connected_k_center import PathCKC
X = [
[0., 1.,
[1., 0.],
[2., 1.],
[1., 1.],
[2., 0.],
[3., 1.],
]
cids = [0,0,0,0,0,0]
pckc = PathCKC(n_clusters=2, metric="euclidean")
pckc.fit(X, cids)
print(pckc.optimal_radius_) # 1.4142135623730951
print(pckc.cluster_centers_indices_) # [1,5]
print(pckc.labels_) # [1,1,1,1,1,5]
The package also provides a read_instance method, that expects a path to a csv file where each line contains the coordinates of a point, and the order of the points determines the ordering along the path. A new connected component is indicated by a blank line. It returns a tuple (X, cids).
from connected_k_center import PathKCK, read_instance
(X, cids) = read_instance("path/to/csv")
pckc = PathCKC(n_clusters=2, metric="euclidean")
pckc.fit(X, cids)
print(pckc.optimal_radius_) # 1.4142135623730951
print(pckc.cluster_centers_indices_) # [1,5]
print(pckc.labels_) # [1,1,1,1,1,5]
Development
Install poetry
curl -sSL https://install.python-poetry.org | python3 -
Install clang
sudo apt-get install clang
Set clang variables
export CXX=/usr/bin/clang++
export CC=/usr/bin/clang
Install the package
poetry install
If the installation does not work and you do not see the C++ output, you can build the package to see the stack trace
poetry build
Run the tests
poetry run python -m unittest discover tests -v
Metadata
Release files for connected-k-center 0.3.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 |
|---|---|---|---|---|
| connected_k_center-0.3.0.tar.gz | 14.1 kB | Without provenance | Details for connected_k_center-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| connected_k_center-0.3.0-cp310-cp310-manylinux_2_39_x86_64.whl | CPython 3.10 | CPython 3.10 | Linux glibc 2.39+ x86-64 | Details for connected_k_center-0.3.0-cp310-cp310-manylinux_2_39_x86_64.whl |
Total release size: 324.2 kB
Release files / connected_k_center-0.3.0.tar.gz
| Download URL | connected_k_center-0.3.0.tar.gz |
|---|---|
| Size | 14.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8561601265bac7ef4c50be0f74a5d54f69a29b8d5850b565ff6b31410225d4a5
|
|
BLAKE2b-256 checksum How to use checksums |
6eab1a953aeb72959c4ae54d49ca269bb45f1b918d686d88253aef66ef860aed
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.3.2 CPython/3.10.21 Linux/6.17.0-1022-azure
|
Release files / connected_k_center-0.3.0-cp310-cp310-manylinux_2_39_x86_64.whl
| Download URL | connected_k_center-0.3.0-cp310-cp310-manylinux_2_39_x86_64.whl |
|---|---|
| Size | 310.1 kB |
| Tags | CPython 3.10 Linux glibc 2.39+ x86-64 |
|
SHA-256 checksum How to use checksums |
266391f26f8ab9d83122610260f659e5c9d1c0b5c6b395a0306c4626884ca7d1
|
|
BLAKE2b-256 checksum How to use checksums |
e8cfc2e57d45d3ced206aed78730dbc2f991213f14a53f22a0b02040654dce72
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.3.2 CPython/3.10.21 Linux/6.17.0-1022-azure
|
Security for connected-k-center 0.3.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.