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.6.0.tar.gz (430.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.6.0-py3-none-any.whl (432.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for kmeanssa_ng-0.6.0.tar.gz
Algorithm Hash digest
SHA256 5ec9db7703cf4fdec2afed52812d5963cff06a5ad604b28afd32b39444605e90
MD5 018782dcc812fb830293983151411a69
BLAKE2b-256 a5d938c657b2fef173a0af4d8bf799cb8b09bb36d5296aa70d2613ce02eafe12

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for kmeanssa_ng-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d9392515c4b9bd3ddd0fed02500df93a0fd306286b175abe68ef9f7c13fe2d12
MD5 b896e7645adebc6b21d3c16ae0a0decd
BLAKE2b-256 9b0f3f0b9d110e495aeaf1085be9360c7115ca10349cc0ddd68e9bd2f72febe5

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