PySwarms is an extensible research toolkit for particle swarm optimization (PSO) in Python.
It is intended for swarm intelligence researchers, practitioners, and students who prefer a high-level declarative interface for implementing PSO in their problems. PySwarms enables basic optimization with PSO and interaction with swarm optimizations. Check out more features below!
Free software: MIT license
Python versions: 3.5 and above
Features
High-level module for Particle Swarm Optimization. For a list of all optimizers, check this link.
Built-in objective functions to test optimization algorithms.
Plotting environment for cost histories and particle movement.
Hyperparameter search tools to optimize swarm behaviour.
(For Devs and Researchers): Highly-extensible API for implementing your own techniques.
Installation
To install PySwarms, run this command in your terminal:
$ pip install pyswarms
This is the preferred method to install PySwarms, as it will always install the most recent stable release.
In case you want to install the bleeding-edge version, clone this repo:
$ git clone -b development https://github.com/ljvmiranda921/pyswarms.git
and then run
$ cd pyswarms
$ python setup.py install
Running in a Vagrant Box
To run PySwarms in a Vagrant Box, install Vagrant by going to https://www.vagrantup.com/downloads.html and downloading the proper packaged from the Hashicorp website.
Afterward, run the following command in the project directory:
$ vagrant provision
$ vagrant up
$ vagrant ssh
Now you're ready to develop your contributions in a premade virtual environment.
Basic Usage
PySwarms provides a high-level implementation of various particle swarm optimization algorithms. Thus, it aims to be user-friendly and customizable. In addition, supporting modules can be used to help you in your optimization problem.
Optimizing a sphere function
You can import PySwarms as any other Python module,
import pyswarms as ps
Suppose we want to find the minima of f(x) = x^2 using global best PSO, simply import the built-in sphere function, pyswarms.utils.functions.sphere(), and the necessary optimizer:
import pyswarms as ps
from pyswarms