Skip to content

ljvmiranda921/pyswarms

Repository files navigation

PySwarms Logo


PyPI Version Build Status Documentation Status Code Health Updates Python versions License Citation

PySwarms is a an extensible research toolkit for particle swarm optimization (PSO) in Python.

Features

  • High-level module for Particle Swarm Optimization. For a list of all optimizers, check this link.
  • Test optimizers using various objective functions
  • (For Devs and Researchers): Highly-extensible API for implementing your own techniques
  • Easy API built on matplotlib to create animations like these:
3d particle plot cost history plot

Dependencies

  • numpy >= 1.13.0
  • scipy >= 0.17.0
  • matplotlib >= 1.3.1

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 https://github.com/ljvmiranda921/pyswarms.git

and then run

$ python setup.py install

Basic Usage

To use PySwarms in your project,

import pyswarms as ps

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:

import pyswarms as ps
from pyswarms.utils.functions import single_obj as fx

# Set-up hyperparameters
options = {'c1': 0.5, 'c2': 0.3, 'w':0.9}

# Call instance of PSO
optimizer = ps.single.GlobalBestPSO(n_particles=10, dimensions=2, options=options)

# Perform optimization
stats = optimizer.optimize(fx.sphere_func, iters=100)

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.

Cite us

Are you using PySwarms in your project or research? Please cite us!

@article{PySwarms2017,
    author = "Lester James V. Miranda",
    year = 2017,
    title = "PySwarms, a research-toolkit for Particle Swarm Optimization in Python",
    doi = {10.5281/zenodo.986300},
    url = {https://zenodo.org/badge/latestdoi/97002861}
}

Others

Like it? Love it? Leave us a star on Github to show your appreciation!