Skip to main content

Build Status License: GPL v3 Supported Python version Stable Version

K-Min-Sum-Radii

kMSR provides various implementations to solve the k-Min-Sum-Radii problem. The k-Min-Sum-Radii problem is a clustering problem that aims to minimize the sum of the radii of the clusters. Given a set of points, the aim is to find $k$ balls such that the the sum of the radii of the balls is minimized. The package provides the following algorithms:

  • fpt-heuristic: The algorithm is an heuristic version of what is described in this paper. In practice, this works well for clusters that are not too separated. The algorithm uses the parameters epsilon, n_u, and num_test_radii to control the trade-off between the quality of the solution and the runtime. Increase n_u for a more accurate solution, which will however require more computation time.
  • heuristic: The algorithm is a simple heuristic that explores all possible combinations for the first cluster, and then selects the remaining centers as the points farthest from the radius of the first cluster. This algorithm works well in practice but it is not practical for large datasets.
  • gonzalez: This is the standard Gonzalez algorithm for $k$-center.
  • kmeans: This is the k-means++ algorithm for $k$-means.

Although the last two algorithms are not specifically designed for the k-Min-Sum-Radii problem, they serve as useful baselines for comparing the performance of other algorithms. Additionally, an optimization has been integrated into all algorithms: intersecting balls are merged at the end, resulting in a more cost-effective solution.

For computing the minimum enclosing circle of a set of points we use the miniball header for C++. Their code has not been changed.

You can try kMSR out on our Clustering Toolkit!

Installation

We highly recommend to install OpenMP. Parts of the code are parallelized and will be much faster. However, on Windows and MacOS the code also works without OpenMP. Nonetheless, the code was written for Linux and will achieve the best performance there.

On Linux, you can use the following command:

# Alpine
sudo apk add openmp-dev libgomp
# Ubuntu
sudo apt-get install libomp-dev libgomp1
# Debian
sudo apt-get install gcc libomp-dev libomp5 libgomp1
# ArchLinux
sudo pacman -S openmp
ln -s libomp.so libomp.so.5

We have tested this on docker, so it might be a little different on your system.

On MacOS, you can use the following command:

 brew install llvm libomp

However, it might be that MacOS does not find the installed library. In build_extension.py, the paths are set manually. If it does not work for you, please clone the repository and run poetry build. You will see a message in red if your OpenMP is not found.

Then, you can install the package via pip:

pip install kmsr

Example

from kmsr import KMSR
from kmsr.plot import plot_multiple_results
from sklearn.datasets import make_blobs
from time import time

points, ground_truth = make_blobs(
    n_samples=100,
    n_features=2,
    centers=2,
    cluster_std=0.6,
    shuffle=True,
    random_state=42,
)

labels = []
centers = []
radii = []
titles = []
for algo in ["FPT-heuristic", "Heuristic", "Gonzalez", "KMeans"]:
    kmsr = KMSR(
        n_clusters=5,
        algorithm=algo,
        epsilon=0.5,
        n_u=10000,
        n_test_radii=10,
        random_state=42,
    )
    start = time()
    kmsr.fit(points)
    end = time() - start
    labels.append(kmsr.labels_)
    centers.append(kmsr.cluster_centers_)
    radii.append(kmsr.cluster_radii_)
    titles.append(f"{algo}: {sum(kmsr.cluster_radii_):.3f}, Time: {end:.3f}s")

plot_multiple_results(
    points,
    clusters=labels,
    centers=centers,
    radii=radii,
    title=titles,
)

Comparison of the Different Methods for kMSR

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

Citation

If you use this code, please cite the following bachelor thesis:

N. Lenßen, "Experimentelle Analyse von Min-Sum-Radii Approximationsalgorithmen". Bachelorarbeit, Heinrich-Heine-Universität Düsseldorf, 2024.

Moreover, depending on the selection of the algorithm parameter, you should also cite the following paper for algorithm='fpt-heuristic':

L. Drexler, A. Hennes, A. Lahiri, M. Schmidt, and J. Wargalla, "Approximating Fair K-Min-Sum-Radii in Euclidean Space," in Lecture notes in computer science, 2023, pp. 119–133. doi: 10.1007/978-3-031-49815-2_9.

the following paper for algorithm='gonzalez':

T. F. Gonzalez, "Clustering to minimize the maximum intercluster distance," Theoretical Computer Science, vol. 38, pp. 293–306, Jan. 1985, doi: 10.1016/0304-3975(85)90224-5.

and the following paper for algorithm='kmeans':

D. Arthur and S. Vassilvitskii, "k-means++: the advantages of careful seeding," Symposium on Discrete Algorithms, pp. 1027–1035, Jan. 2007, doi: 10.5555/1283383.1283494.

Metadata

Release files for kmsr 0.1.8

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

Source distribution (sdist)

Source distribution for kmsr 0.1.8
File Size Uploaded Provenance Actions
kmsr-0.1.8.tar.gz 393.6 kB With provenance Details for kmsr-0.1.8.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for kmsr 0.1.8
File Actions
kmsr-0.1.8-cp315-cp315-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl CPython 3.15 CPython 3.15 Linux glibc 2.28+ x86-64, Linux glibc 2.24+ x86-64 Details for kmsr-0.1.8-cp315-cp315-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
kmsr-0.1.8-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.24+ x86-64, Linux glibc 2.28+ x86-64 Details for kmsr-0.1.8-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
kmsr-0.1.8-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.24+ x86-64, Linux glibc 2.28+ x86-64 Details for kmsr-0.1.8-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
kmsr-0.1.8-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.24+ x86-64, Linux glibc 2.28+ x86-64 Details for kmsr-0.1.8-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Total release size: 3.8 MB

Release files / kmsr-0.1.8.tar.gz

Download URL kmsr-0.1.8.tar.gz
Size 393.6 kB
Tags Source
SHA-256 checksum
How to use checksums
b3b942c2617f1f27e0ef1349b1b5ffb8d4095a2cb6036053dc5c7ca5e0ee30bf
BLAKE2b-256 checksum
How to use checksums
776aa57679e7579bd2eca14a211a739573907cd0a0596412bad6df44f26fc407
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.

Transparency log

Release files / kmsr-0.1.8-cp315-cp315-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Download URL kmsr-0.1.8-cp315-cp315-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Size 854.2 kB
Tags CPython 3.15 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
9ca51a03b7f2f03c15f520da3ac9545c591e427f290991b4796723b01465a3ed
BLAKE2b-256 checksum
How to use checksums
481a9d47a4a992a0627bd6bce2a8bd7af845248628580f6059d8a6a982f61974
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.

Transparency log

Release files / kmsr-0.1.8-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Download URL kmsr-0.1.8-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Size 853.4 kB
Tags CPython 3.14 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
313bfd7e9f116794293f8f20743a409b22d954f3ebe235ea20a8e30d553ac35c
BLAKE2b-256 checksum
How to use checksums
38243de77ebc377e906d84579e610b809c66d6c611aad52354119c8c48245ffc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.

Transparency log

Release files / kmsr-0.1.8-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Download URL kmsr-0.1.8-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Size 853.4 kB
Tags CPython 3.13 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
8c31c97dfcaad96b772f233971439ffeae32d4e3b1d739b8ced2010e3c98fb41
BLAKE2b-256 checksum
How to use checksums
a99568134b0cd1e446f08eece4a397883d6d071b1ce9a9897239c5f0e6208e2d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.

Transparency log

Release files / kmsr-0.1.8-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Download URL kmsr-0.1.8-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Size 853.2 kB
Tags CPython 3.12 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
91bf214dc0de00447d722d678f0a5dbbcd9cba2af7c860eb66acac81a63aa47c
BLAKE2b-256 checksum
How to use checksums
8f975d9537c3ec94cd5e0d0d5161bc44c9d2ccf7f6cdfd94bcc31a355ff91eef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.

Transparency log

Security for kmsr 0.1.8

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.

Full provenance

All 5 files in this release have been uploaded with provenance metadata.

Select from 5 files

Attestation for kmsr-0.1.8.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.

Transparency log

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