A Python library for Surrogate-Assisted Evolutionary Algorithms (SAEAs)
Project description
saealib
Status: Active Development (Alpha)
Warning: This project is under active development. APIs are subject to change without notice. Operation is not guaranteed in production environments.
A comprehensive library for Surrogate-Assisted Evolutionary Algorithms (SAEAs) in Python.
Designed for expensive optimization problems where function evaluations are costly, saealib provides a modular framework to combine evolutionary algorithms, surrogate models, and model management strategies.
Documents
https://shlka.github.io/saealib/index.html
Key Features
- Modular Architecture: Easily mix and match Algorithms (e.g., GA), Surrogates (e.g., RBF), and Management Strategies.
- Method Chaining: The
Optimizerclass allows for fluent and readable configuration. - Customizable Components:
- Algorithms: Genetic Algorithms (GA) with various operators.
- Surrogates: Radial Basis Function (RBF) networks with Gaussian kernels.
- Strategies: Individual-based management strategies (e.g., generation-based or pre-selection).
- Operators: Includes BLX-Alpha Crossover, Uniform Mutation, and various Selection methods.
Installation
Requirements
- Python >= 3.10
- numpy
- scipy
Install via pip
pip install saealib
To install the latest beta release explicitly:
pip install saealib==0.1.0b1
Or to install the latest pre-release version:
pip install --pre saealib
Install via uv
uv add saealib
To install the latest beta release explicitly:
uv add saealib==0.1.0b1
Install from source
git clone https://github.com/shlka/saealib.git
cd saealib
pip install .
Or for development (editable mode):
pip install -e .
Quick Start
Here is a simple example of how to use saealib to minimize a Sphere function using a Surrogate-Assisted GA (SAGA) with an RBF model.
import numpy as np
from saealib import (
GA,
Optimizer,
Problem,
RBFsurrogate,
LHSInitializer,
CrossoverBLXAlpha,
MutationUniform,
SequentialSelection,
TruncationSelection,
IndividualBasedStrategy,
Termination,
max_fe,
f_target,
gaussian_kernel
)
# 1. Define the Objective Function (e.g., Sphere Function)
def sphere(x):
return np.sum(x**2)
# 2. Setup the Optimization Problem
dim = 5
problem = Problem(
func=sphere,
dim=dim,
n_obj=1,
weight=np.array([-1.0]), # -1.0 implies minimization
lb=[-5.0] * dim, # Lower bounds
ub=[5.0] * dim, # Upper bounds
)
# 3. Configure Components
# Initialization: Latin Hypercube Sampling
initializer = LHSInitializer(
n_init_archive=5 * dim, # Initial samples for the surrogate
n_init_population=4 * dim, # Initial population size
seed=42,
)
# Algorithm: Genetic Algorithm
algorithm = GA(
crossover=CrossoverBLXAlpha(crossover_rate=0.7, alpha=0.4),
mutation=MutationUniform(mutation_rate=0.3),
parent_selection=SequentialSelection(),
survivor_selection=TruncationSelection(),
)
# Surrogate Model: RBF with Gaussian Kernel
surrogate = RBFsurrogate(gaussian_kernel, dim)
# Strategy: Individual-Based Management
# evaluation_ratio=0.1: Ratio of offspring selected for true objective evaluation
strategy = IndividualBasedStrategy(evaluation_ratio=0.1)
# Termination Criterion
# Conditions compose with & (AND), | (OR), and ~ (NOT).
# Here: stop after 100 evaluations OR once the objective reaches the target.
termination = Termination(max_fe(100) | f_target(1e-6))
# 4. Build and Run the Optimizer
opt = (
Optimizer(problem)
.set_initializer(initializer)
.set_algorithm(algorithm)
.set_termination(termination)
.set_surrogate(surrogate)
.set_strategy(strategy)
)
print("Starting optimization...")
opt.run()
print("Optimization finished.")
Architecture Overview
saealib is built around the Optimizer class which orchestrates the interaction between:
- Problem: Defines the objective function, constraints, and bounds.
- Algorithm: The evolutionary search engine (e.g., GA).
- Surrogate: The approximate model used to replace expensive evaluations.
- Strategy: Decides when to use the surrogate and when to use the real function (e.g., Pre-selection, Generation control).
- Initializer: Generates the initial dataset.
Contributing
Contributions are welcome! Please refer to CONTRIBUTING.md for guidelines on how to contribute to this project.
License
MIT License (Assuming standard open source license, please verify)
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 saealib-0.1.0b3.tar.gz.
File metadata
- Download URL: saealib-0.1.0b3.tar.gz
- Upload date:
- Size: 252.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
484225e6fd5947fb0886bb11d8019de59b2ab145baf3d23e57cb7b19e1f443fb
|
|
| MD5 |
f37b171d10024aa009eac576c0b56781
|
|
| BLAKE2b-256 |
2ed9cab5208435158834a11fbb54b38a7a7111abda1bd127d34e8188e9a14b5f
|
Provenance
The following attestation bundles were made for saealib-0.1.0b3.tar.gz:
Publisher:
publish.yml on shlka/saealib
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
saealib-0.1.0b3.tar.gz -
Subject digest:
484225e6fd5947fb0886bb11d8019de59b2ab145baf3d23e57cb7b19e1f443fb - Sigstore transparency entry: 1754847500
- Sigstore integration time:
-
Permalink:
shlka/saealib@d1e9880127d8d3491fd74d5f70f5635a03c8ca0a -
Branch / Tag:
refs/tags/v0.1.0b3 - Owner: https://github.com/shlka
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d1e9880127d8d3491fd74d5f70f5635a03c8ca0a -
Trigger Event:
push
-
Statement type:
File details
Details for the file saealib-0.1.0b3-py3-none-any.whl.
File metadata
- Download URL: saealib-0.1.0b3-py3-none-any.whl
- Upload date:
- Size: 77.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2382c19a0b307ca1906852ff074397821b3d81ec9e125238d0c15daa909a0953
|
|
| MD5 |
a532eecaa3195966f1e48baf963c7c69
|
|
| BLAKE2b-256 |
5238b76b208c2fd78c503e7d2343db6b91b6ee6ca135791e782c3b28b591da23
|
Provenance
The following attestation bundles were made for saealib-0.1.0b3-py3-none-any.whl:
Publisher:
publish.yml on shlka/saealib
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
saealib-0.1.0b3-py3-none-any.whl -
Subject digest:
2382c19a0b307ca1906852ff074397821b3d81ec9e125238d0c15daa909a0953 - Sigstore transparency entry: 1754847507
- Sigstore integration time:
-
Permalink:
shlka/saealib@d1e9880127d8d3491fd74d5f70f5635a03c8ca0a -
Branch / Tag:
refs/tags/v0.1.0b3 - Owner: https://github.com/shlka
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d1e9880127d8d3491fd74d5f70f5635a03c8ca0a -
Trigger Event:
push
-
Statement type: