Skip to main content

Python implementation of the evolutionary clustering ECSAGO - Evolutionary Clustering with Self Adaptive Genetic Operators

Project description

pyecsago

Python implementation of ECSAGO (Evolutionary Clustering with Self-Adaptive Genetic Operators), a robust evolutionary clustering algorithm that automatically discovers the number of clusters in data while being resistant to noise.

ECSAGO vs K-Means

Features

  • Automatic cluster detection — no need to specify k in advance
  • Noise-robust density-based fitness function (RBF kernel weights)
  • Self-adaptive operators via HAEA (Hybrid Adaptive Evolutionary Algorithm)
  • Deterministic Crowding for niche maintenance
  • MDE refinement (Maximal Density Estimator) for prototype center/spread convergence
  • GPU acceleration — optional CUDA support via CuPy

Installation

CPU only:

pip install pyecsago

With CUDA support:

pip install pyecsago[cuda]

From source

git clone https://github.com/pwnaoj/pyecsago
cd pyecsago
pip install .

Quick start

import numpy as np
from pyecsago import ECSAGO

# Sample data: 3 Gaussian clusters
data = np.vstack([
    np.random.randn(100, 2) + [0, 0],
    np.random.randn(100, 2) + [5, 5],
    np.random.randn(100, 2) + [10, 0],
])

config = {
    "population_size": 100,
    "weight_threshold": 0.3,
    "max_generations": 30,
    "iterations": 10,
    "extraction_type": {2: 0.25},   # PROPORTION_MAX with 25% threshold
    "k": 13.8,
    "use_cuda": False,
}

ecsago = ECSAGO(config)
results = ecsago.run(data)

prototypes = results["refined_prototypes"]
labels = results["cluster_assignments"]

print(f"Clusters found: {len(prototypes)}")

Step-by-step usage

For finer control you can invoke each stage independently:

ecsago = ECSAGO(config)

# 1. Load data
ecsago.context.set_data(data)

# 2. Evolve the population
ecsago.evolve()

# 3. Extract prototypes
prototypes = ecsago.extract_prototypes(
    extraction_type={2: 0.25},
    k=13.8,
)

# 4. Refine with MDE
refined = ecsago.refine_prototypes(
    prototypes=prototypes,
    iterations=10,
    k=13.8,
)

Configuration

All parameters are passed as a dictionary to ECSAGO(config).

Parameter Type Description
population_size int Number of individuals in the evolutionary population
weight_threshold float Threshold for weight binarization (0–1)
max_generations int Maximum number of evolutionary generations
iterations int Number of MDE refinement iterations
extraction_type dict Extraction method — key is the type (0–4), value is the threshold
k float Chi-squared factor for minimum inter-prototype distance
use_cuda bool Enable CUDA/GPU acceleration via CuPy

Extraction types

Key Method Threshold meaning
0 ABSOLUTE_VALUE Absolute fitness threshold (auto-calculated)
1 PROPORTION_AVG Proportion of average fitness
2 PROPORTION_MAX Proportion of maximum fitness
3 PROPORTION_MEDIAN Proportion of median fitness
4 MINIMUM_DENSITY Based on minimum density

Output

ecsago.run(data) returns a dictionary:

Key Description
final_population Full evolved population
prototypes Extracted prototypes (before refinement)
refined_prototypes Refined prototypes (after MDE)
cluster_assignments Cluster label for each data point

Each prototype is an ECSAGOIndividual with attributes genome (center), sigma2 (spread), and fitness.

Architecture

pyecsago/
├── core/               # Abstract base classes and exceptions
├── implementations/
│   └── ecsago/         # ECSAGO algorithm, context, individual, population
├── strategies/
│   ├── evolution/      # Evolution strategy (HAEA + Deterministic Crowding)
│   ├── extraction/     # Prototype extraction (fitness, niche, composite)
│   ├── fitness/        # Fitness calculation (CPU and CUDA)
│   ├── niching/        # Deterministic Crowding
│   ├── operators/      # Genetic operators (mutation, crossover, HAEA)
│   └── refinement/     # MDE refinement (CPU and CUDA)
└── utils/              # Data type strategies, compatibility, utilities

License

pyecsago was created by Joan Sebastian Tamayo Rivera. It is licensed under the terms of the MIT license.

References

  • León, E. "Scalable and Adaptive Evolutionary Clustering for Noisy and Dynamic Data"
  • León, E., Nasraoui, O., & Gómez, J. "ECSAGO: Evolutionary Clustering with Self-Adaptive Genetic Operators"
  • Gómez, J. "Self Adaptation of Operator Rates for Multimodal Optimization"
  • Tamayo, J. "GPU/CUDA-Based Parallelization of the ECSAGO Evolutionary Algorithm"

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

pyecsago-0.1.0.tar.gz (30.4 kB view details)

Uploaded Source

Built Distribution

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

pyecsago-0.1.0-py3-none-any.whl (52.0 kB view details)

Uploaded Python 3

File details

Details for the file pyecsago-0.1.0.tar.gz.

File metadata

  • Download URL: pyecsago-0.1.0.tar.gz
  • Upload date:
  • Size: 30.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for pyecsago-0.1.0.tar.gz
Algorithm Hash digest
SHA256 979dde3e019209eaf6e09da729574f1bda498c283fcfa2cc40c99fb0c55c15ac
MD5 e310389e6c645fa6e6c4364b001002d8
BLAKE2b-256 14a3be3f7af5e357de521acaa4e3bcb5b2b6be76392d721ec426d51578b0aec5

See more details on using hashes here.

File details

Details for the file pyecsago-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pyecsago-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 52.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for pyecsago-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 11ae807a9143dacb88220e9cf66cbaae31ca6707ade434eea84f0f85bf9a3a5a
MD5 dbd29c1dc75f9b7471c6a21e55789c7d
BLAKE2b-256 1280ee5695ba55ac72a70d06df7b8e856a3a763e9714a56608c0f9a3ad636d8c

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