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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

connected_k_center-0.2.1.tar.gz (14.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

connected_k_center-0.2.1-cp310-cp310-manylinux_2_39_x86_64.whl (310.0 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.39+ x86-64

File details

Details for the file connected_k_center-0.2.1.tar.gz.

File metadata

  • Download URL: connected_k_center-0.2.1.tar.gz
  • Upload date:
  • Size: 14.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.10.21 Linux/6.17.0-1022-azure

File hashes

Hashes for connected_k_center-0.2.1.tar.gz
Algorithm Hash digest
SHA256 f0984c93e722faec658c3964bf11755057034e11bb6d519f725f5cf6a6fc7da8
MD5 6d5f3a614441b2fa7293ac4a82d8e07c
BLAKE2b-256 7f8567ee9ba36f71e053584c49fdcbb324e30ed4bc3e8a231acdd3368782c7f7

See more details on using hashes here.

File details

Details for the file connected_k_center-0.2.1-cp310-cp310-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for connected_k_center-0.2.1-cp310-cp310-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 1cebc87b15e9bf6416f6dd53b8912da130f3f20c040c494ec34f92d7e45ef3a4
MD5 c1e23a9a527a4b336d1dfec39c1e4280
BLAKE2b-256 173a2ba05df99c19da661664c09100ba80360372d2538100fcc5e667e7982f44

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 files

0.2.0

2 files

0.1

2 files

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