Skip to main content

PyApso

PyApso is an implementation of the Adaptive Particle Swarm Optimization (APSO) algorithm and designed for solving continuous, multi-objective, and multi-dimensional optimization problems.


Installation

Install the package using pip:

pip install pyapso

Or from source:

git clone https://github.com/smohamadabedy/pyapso.git
cd pyapso
pip install .

Features

ADAPTIVE - key parameters: (inertia weight, avg weight) Continuous optimization support Single and multi-objective fitness evaluation Constraint-aware evolution Batch evaluation and parallel execution Excel and JSON logging Custom callbacks and visualizations

Usage

from pyapso import APSO
import numpy as np

def fitness(x):
    return np.sum(x**2)

if __name__ == "__main__":
    best, score, history, hd = APSO(
        objective_function=fitness,
        dim=1,
        bounds=([-10], [10]),
        num_particles=100,
        max_iter=10,
        verbose = 1,live_plot=False,folder="results_folder",save_prefix="results_file"
    ).run()    
            
    print("Best solution:", best)
    print("Best score:", score)

    # Save optimization history (JSON,CSV)
    hd.save()

    # Plot optimization history
    hd.plot()

Modes

apso.run("avg", c1=1.8, c2=1.8, w_min=0.5, w_max=0.9)

"avg" mode adapts the inertia weight dynamically between w_min and w_max using swarm behavior.

apso.run("inertia",c1=1.8, c2=1.8, inertia=0.05)

"inertia" mode adapts a fixed inertia weight throughout the optimization (default).

💡 Tip:

  • A higher c1 encourages particles to explore their own search path.
  • A higher c2 encourages convergence to the global best.
  • Lower inertia means the swarm is more reactive and less explorative.

Examples

You can find runnable demos in the examples/ directory:

examples/
├── demo_1.py    # 5D Rastrigin function
├── demo_2.py    # 3D constrained benchmark
├── demo_3.py    # 2D McCormick function

Run an example:

python examples/demo_2.py

Metadata

Release files for PyApso 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for PyApso 1.1.0
File Size Uploaded
pyapso-1.1.0.tar.gz 8.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for PyApso 1.1.0
File Interpreter ABI Platform
pyapso-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 16.7 kB

Release files / pyapso-1.1.0.tar.gz

Download URL pyapso-1.1.0.tar.gz
Size 8.7 kB
Tags Source
SHA-256 checksum
How to use checksums
be4dec5f9dacde055e05e59858973a383c5aafe148d532a842d96f20c3e49986
BLAKE2b-256 checksum
How to use checksums
8ec99543f66238597358216069565826780f3194049ebe7fb345cab7d1039965
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.6

Release files / pyapso-1.1.0-py3-none-any.whl

Download URL pyapso-1.1.0-py3-none-any.whl
Size 8.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f72b210f845ab13a6cf478b2af23294cef3a2c2eb4367464313ac15a9c3405b6
BLAKE2b-256 checksum
How to use checksums
2a8e9a8067d43f42f7c6e084c4a491f4743a8c4f89a70cd25040fadc18da87b4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.6

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page