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.
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyecsago-0.2.1.tar.gz.
File metadata
- Download URL: pyecsago-0.2.1.tar.gz
- Upload date:
- Size: 25.8 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ddb6515b24fd007d50ee6b85eda67e7564d5dde9ab3cbc85b434ab580e439edc
|
|
| MD5 |
13541d47cf14bb47546b1a258a0b46d4
|
|
| BLAKE2b-256 |
c3dd7e5461e5ba2c3f594fbf524a1b1b21b646a6d2f273d7386f469f359fdf0c
|
File details
Details for the file pyecsago-0.2.1-py3-none-any.whl.
File metadata
- Download URL: pyecsago-0.2.1-py3-none-any.whl
- Upload date:
- Size: 46.2 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cdb2569d8f8897a49b129066ce093b10bec0eea2cb0dd80290582bc4364f1484
|
|
| MD5 |
b299579951dd212930ac817afb75ebd5
|
|
| BLAKE2b-256 |
0799ee22b01b5611ef2d85df448eb05202d4441c5aff0887ad55b44673cd68e4
|