Skip to main content

K-means clustering on quantum graphs and metric spaces using simulated annealing

Project description

kmeanssa-ng

License: MIT PyPI version Python 3.10+ Documentation Status Pipeline Status Coverage Report Code style: Ruff

K-means clustering on quantum graphs and metric spaces using simulated annealing.

kmeanssa-ng provides tools for clustering data points that exist on complex network structures (quantum graphs) or other metric spaces where standard Euclidean distance does not apply. It uses a simulated annealing approach for robust convergence.

Installation

Install the latest version directly from PyPi:

pip install kmeanssa-ng

Quickstart

Here is a minimal example of clustering points on a quantum graph:

from kmeanssa_ng import generate_sbm, SimulatedAnnealing, MostFrequentNode, KMeansPlusPlus

# Generate a graph with two distinct communities
# Distances are precomputed automatically (precompute=True by default)
graph = generate_sbm(
    sizes=[40, 40],       # Two communities of 40 nodes each
    p=[[0.8, 0.1],        # High intra-community connectivity  
       [0.1, 0.8]],       # Low inter-community connectivity
)

# Sample points uniformly across the graph
points = graph.sample_points(150)

# Run quantum graph specialized simulated annealing
sa = SimulatedAnnealing(
    observations=points,
    k=2,                  # We know there are 2 clusters
    lambda0=1.0,     # Standard temperature
    beta0=1.0,             # Standard drift strength
    step_size=0.1         # Standard step size
)

# Get cluster centers as node IDs (more interpretable)
node_centers = sa.run(
    robust_prop=0.1,                                  # 10% robustness  
    initialization_strategy=KMeansPlusPlus(),         # K-means++ initialization
    robustification_strategy=MostFrequentNode()       # Choose centers as most frequent nodes in clusters
)
print(f"Cluster centers near nodes: {node_centers}")

Documentation

The full documentation, including API reference and tutorials, is available at kmeanssa-ng.readthedocs.io.

Citation

If you use this package in your research, please cite:

@software{kmeanssa_ng,
  author       = {Klutchnikoff, Nicolas and Gavra, Ioana},
  title        = {kmeanssa-ng: K-means Clustering on Quantum Graphs and Metric Spaces},
  year         = {2025},
  url          = {https://plmlab.math.cnrs.fr/nicolas.klutchnikoff/kmeanssa-ng},
  note         = {Python package for k-means clustering using simulated annealing}
}

License

This project is licensed under the MIT License. See the LICENSE file for details.

Project details


Download files

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

Source Distribution

kmeanssa_ng-0.7.0.tar.gz (150.7 kB view details)

Uploaded Source

Built Distribution

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

kmeanssa_ng-0.7.0-py3-none-any.whl (139.0 kB view details)

Uploaded Python 3

File details

Details for the file kmeanssa_ng-0.7.0.tar.gz.

File metadata

  • Download URL: kmeanssa_ng-0.7.0.tar.gz
  • Upload date:
  • Size: 150.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.28.0 CPython/3.11.15 Linux/6.12.0-219.el10.x86_64

File hashes

Hashes for kmeanssa_ng-0.7.0.tar.gz
Algorithm Hash digest
SHA256 e438f333a69ebeac264134c13521afe268b3ec03181ff019f18c37e73922e46a
MD5 12b76a2e3902c9c512cf1a9ab6833054
BLAKE2b-256 ffe00ff989fcdbaa5d1f4915e382614032c3b2730e91e1a0100d28bbb76df705

See more details on using hashes here.

File details

Details for the file kmeanssa_ng-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: kmeanssa_ng-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 139.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.28.0 CPython/3.11.15 Linux/6.12.0-219.el10.x86_64

File hashes

Hashes for kmeanssa_ng-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0556dd824cf68138ff42f9bda30e4128ba7008ca4fa4a4253a7ee6076bc9f4ac
MD5 4aae8065b04389592a7d89d6d072ee41
BLAKE2b-256 36b587b136430cbf17ae726cf7910243cfb6ebcb564fa6d12e284870ad6ff9f0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page