A Python-based Particle Swarm Optimization (PSO) library.
Project description
PySwarms
PySwarms is a simple, Python-based, Particle Swarm Optimization (PSO) library.
Free software: MIT license
Documentation: https://pyswarms.readthedocs.io.
Features
High-level module for Particle Swarm Optimization
Test optimizers using various objective functions
(For Devs): Highly-extensible API for implementing your own techniques
Dependencies
Python 3.4 and above
numpy >= 1.10.4
scipy >= 0.17.0
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.
Basic Usage
To use PySwarms in your project,
import pyswarms
Suppose you 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_func()
, and the necessary optimizer:
from pyswarms.single import GBestPSO
from pyswarms.utils.functions import sphere_func
# Set-up hyperparameters
options = {'c1': 0.5, 'c2': 0.3, 'm':0.9}
# Call instance of PSO
optimizer = GBestPSO(n_particles=10, dims=2, **options)
# Perform optimization
stats = optimizer.optimize(sphere_func, iters=100)
More examples can be seen in the ./examples
folder.
Credits
This project was inspired by the pyswarm module that performs PSO with constrained support. The package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.
History
0.1.0 (2017-07-12)
First release on PyPI.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.