Skip to main content

A Python library for Surrogate-Assisted Evolutionary Algorithms (SAEAs)

Project description

saealib

Status: Alpha

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 Optimizer class 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

saealib-0.1.0b3.tar.gz (252.3 kB view details)

Uploaded Source

Built Distribution

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

saealib-0.1.0b3-py3-none-any.whl (77.9 kB view details)

Uploaded Python 3

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

Hashes for saealib-0.1.0b3.tar.gz
Algorithm Hash digest
SHA256 484225e6fd5947fb0886bb11d8019de59b2ab145baf3d23e57cb7b19e1f443fb
MD5 f37b171d10024aa009eac576c0b56781
BLAKE2b-256 2ed9cab5208435158834a11fbb54b38a7a7111abda1bd127d34e8188e9a14b5f

See more details on using hashes here.

Provenance

The following attestation bundles were made for saealib-0.1.0b3.tar.gz:

Publisher: publish.yml on shlka/saealib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for saealib-0.1.0b3-py3-none-any.whl
Algorithm Hash digest
SHA256 2382c19a0b307ca1906852ff074397821b3d81ec9e125238d0c15daa909a0953
MD5 a532eecaa3195966f1e48baf963c7c69
BLAKE2b-256 5238b76b208c2fd78c503e7d2343db6b91b6ee6ca135791e782c3b28b591da23

See more details on using hashes here.

Provenance

The following attestation bundles were made for saealib-0.1.0b3-py3-none-any.whl:

Publisher: publish.yml on shlka/saealib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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