Skip to main content

A Python Library for Particle Swarm Intelligence

Project description

pyticle

A Python Library for Particle Swarm Intelligence

Build Status

This package implements the Particle Swarm Optimization (PSO) algorithm in pure python. The only thing you need to is installing the package and call it with the right parameters!

PSO is an interactive meta-heuristic algorithm that uses "particles" as a candidates for solutions. The goal is to move the particles towards the global/local minimum in each iteration.

Installation

Simply install this package by running the following command:

pip install pyticle 

Usage

To minimize the 2D function my_func in range [-15, 10] using 100 particles via 80 iterations:

from pyticle.swarm_optimization import SwarmOptimization
optimizer = SwarmOptimization(cost_func=my_func, particle_num=100, omega_start=1, omega_end=0.0,
 coef=[2.0, 2.0], low_bound=-15.0, high_bound=10,
 boundary_strategy='random', var_size=2, max_iter_num=80, elite_rate=0.1)
optimizer.optimize()

Demo

In this section, you can see the results of using this package for two simple 2D benchmarks. To run the benchmarks, run:

from pyticle.demo_run import demo_run
demo_run()

The Sphere Function

Here is the evolution of 100 particles in 100 iterations to find the minimum of the Sphere function:

Here is the changes in the minimum, average, and maximum values of the cost function of all particles over time:

The Ackley Function

Same as the previous example, this is the evolution of 100 particles in 100 iterations to find the minimum of the Ackley function:

Here is the changes in the minimum, average, and maximum values of the cost function of all particles over time:

Contribution

You are very welcome to contribute to this project with your code (as pull-requests), mention the bugs or ask for new features (as GitHub Issues), or just tell your friends about it!

You can also directly contact me by email.  

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

pyticle-0.0.3.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

pyticle-0.0.3-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file pyticle-0.0.3.tar.gz.

File metadata

  • Download URL: pyticle-0.0.3.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.3

File hashes

Hashes for pyticle-0.0.3.tar.gz
Algorithm Hash digest
SHA256 5ac0a42f421e11e07eae24198a90c52b86aa07393b434e3c605053988a620ce1
MD5 3be3627e0a0e3556466f7ea09bb835c6
BLAKE2b-256 f9481db7e12610139ded43b00b9805597a61f647118a1f709232853072942c9b

See more details on using hashes here.

File details

Details for the file pyticle-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: pyticle-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.3

File hashes

Hashes for pyticle-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 673ccdbe812c4d459faaf31269f46d3a27ead3e524a34b38a41bbf870f093296
MD5 b15934a9092163d00f2bfc51e40f1e72
BLAKE2b-256 e38bde68c21ee688a24a2aa399762c675d45dd0bfe2a73f3c87d97b7df2e80e0

See more details on using hashes here.

Supported by

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