Skip to main content

A Python-based Particle Swarm Optimization (PSO) library.

Project description

PySwarms

https://img.shields.io/pypi/v/pyswarms.svg https://img.shields.io/travis/ljvmiranda921/pyswarms.svg Documentation Status Updates

PySwarms is a simple, Python-based, Particle Swarm Optimization (PSO) library.

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyswarms-0.1.1.tar.gz (13.3 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page