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
    lambda_param=1.0,     # Standard temperature
    beta=1.0,             # Standard drift strength
    step_size=0.1         # Standard step size
)

# Get cluster centers as node IDs (more interpretable)
node_centers = sa.run_interleaved(
    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.5.0.tar.gz (268.1 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.5.0-py3-none-any.whl (262.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: kmeanssa_ng-0.5.0.tar.gz
  • Upload date:
  • Size: 268.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.26.0 CPython/3.12.2 Darwin/25.0.0

File hashes

Hashes for kmeanssa_ng-0.5.0.tar.gz
Algorithm Hash digest
SHA256 572c7f0f1d9e5d53d2e97f8ca275139ab64920dfbb19f2c857d01d52a024e3d1
MD5 f44cb09f0b3d1d1f914881be8c34cd2d
BLAKE2b-256 1ef58533efcbaf126af55e90daac828c8e12cdd180920eabe1caa31a76b9e5a8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kmeanssa_ng-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 262.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.26.0 CPython/3.12.2 Darwin/25.0.0

File hashes

Hashes for kmeanssa_ng-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 49e84ae9f6f0823c563c8044bb1f890bd013c3bf840dfc6aa55c8f0355a2f9c1
MD5 d1e96edad602347274c350b4f2814ee8
BLAKE2b-256 7cc21b4631106c702e4bec16b282341a6c2b1b1244f9b6e32d7419e226230624

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