Skip to main content

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

Reason this release was yanked:

Published by mistake from v0.1.0b2 CI with incorrect version string. Use v0.1.0b2 instead.

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,
    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
termination = Termination(max_fe(100))  # Stop after 100 function evaluations

# 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.0b1.tar.gz (241.9 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.0b1-py3-none-any.whl (71.0 kB view details)

Uploaded Python 3

File details

Details for the file saealib-0.1.0b1.tar.gz.

File metadata

  • Download URL: saealib-0.1.0b1.tar.gz
  • Upload date:
  • Size: 241.9 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.0b1.tar.gz
Algorithm Hash digest
SHA256 72eae7ee88edf718edd1ae00debdb538bc090c6ab8849f67c254791486e6b2ed
MD5 58400f2329c91f6f9d4d833042b3d2e8
BLAKE2b-256 5b98e71e56f126e8cfa6a72d095932e5fd2305ea287bd0a7ebd9a7d47a8274b7

See more details on using hashes here.

Provenance

The following attestation bundles were made for saealib-0.1.0b1.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.0b1-py3-none-any.whl.

File metadata

  • Download URL: saealib-0.1.0b1-py3-none-any.whl
  • Upload date:
  • Size: 71.0 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.0b1-py3-none-any.whl
Algorithm Hash digest
SHA256 53efdf7df23590f96219eb9af6d888b191c9a8b35209d1227d345b274473618a
MD5 63f476243cf66ec16093b32833dda4b2
BLAKE2b-256 5f58e902b7932ed786c5547fc4ffd2a14a9261bdcc47f98689a615847f8e04c4

See more details on using hashes here.

Provenance

The following attestation bundles were made for saealib-0.1.0b1-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