Skip to main content

Build Status License: MIT Supported Python version Stable Version

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.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for connected-k-center 0.4.0
File Size Uploaded Provenance Actions
connected_k_center-0.4.0.tar.gz 14.6 kB Without provenance Details for connected_k_center-0.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for connected-k-center 0.4.0
File Interpreter ABI Platform Actions
connected_k_center-0.4.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.4.0-cp310-cp310-manylinux_2_39_x86_64.whl

Total release size: 325.2 kB

Release files / connected_k_center-0.4.0.tar.gz

Download URL connected_k_center-0.4.0.tar.gz
Size 14.6 kB
Tags Source
SHA-256 checksum
How to use checksums
13329d4ac4ee1c27390c20b2f563a9780b924b116ceddd497cc508fd953e35e8
BLAKE2b-256 checksum
How to use checksums
e59d6996531ce1688c893b328438286122d620b1c76c5648e29c5b1fd0ac1ac8
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.4.0-cp310-cp310-manylinux_2_39_x86_64.whl

Download URL connected_k_center-0.4.0-cp310-cp310-manylinux_2_39_x86_64.whl
Size 310.6 kB
Tags CPython 3.10 Linux glibc 2.39+ x86-64
SHA-256 checksum
How to use checksums
4965b671e101feeb37636e8f032a66c88c246aa7522759b3e447e8321e02c7a7
BLAKE2b-256 checksum
How to use checksums
e6eb4326afa2cca6a3bae850877dfca90d4bc8a34a59038280aebe44461c644e
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.4.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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page