Skip to main content

Adaptive Particle Swarm Optimization for continuous, multi-objective, and multidimensional problems

Project description

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

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

pyapso-1.1.0.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

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

pyapso-1.1.0-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file pyapso-1.1.0.tar.gz.

File metadata

  • Download URL: pyapso-1.1.0.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.6

File hashes

Hashes for pyapso-1.1.0.tar.gz
Algorithm Hash digest
SHA256 be4dec5f9dacde055e05e59858973a383c5aafe148d532a842d96f20c3e49986
MD5 f977142f4ce2fecd5242736f84624c5c
BLAKE2b-256 8ec99543f66238597358216069565826780f3194049ebe7fb345cab7d1039965

See more details on using hashes here.

File details

Details for the file pyapso-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: pyapso-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.6

File hashes

Hashes for pyapso-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f72b210f845ab13a6cf478b2af23294cef3a2c2eb4367464313ac15a9c3405b6
MD5 b879e96a7cc24078a1451e155bdb57e4
BLAKE2b-256 2a8e9a8067d43f42f7c6e084c4a491f4743a8c4f89a70cd25040fadc18da87b4

See more details on using hashes here.

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