项目作者: ivallesp

项目描述 :
A simple Particle Swarm Optimization algorithm implementation from scratch
高级语言: Python
项目地址: git://github.com/ivallesp/PSO.git
创建时间: 2020-02-02T01:46:50Z
项目社区:https://github.com/ivallesp/PSO

开源协议:MIT License

下载


PSO - Particle Swarm Optimization

This repository contains a simple PSO implementation to play with.

Getting started

  1. Install pyenv and poetry in your system following the linked official guides.
  2. Open a terminal, clone this repository and cd to the cloned folder.
  3. Run pyenv install 3.8.0 in your terminal for installing the required python.
    version
  4. Configure poetry with poetry config virtualenvs.in-project true
  5. Create the virtual environment with poetry install
  6. Activate the environment with source .venv/bin/activate
  7. Try the algorithm with the default parameters python main.py

If everything goes well, it will create a file called animation.gif in the examples
folder.

Parameters

Run python main.py --help to check the parameter reference

  1. usage: main.py [-h] [-f F] [-p N_PARTICLES] [-w W] [-c1 C1] [-c2 C2]
  2. [-s N_STEPS] [-r [RANGE [RANGE ...]]] [-v FPS] [-o FILEPATH]
  3. [-rd SEED]
  4. Parser for animation generator
  5. optional arguments:
  6. -h, --help show this help message and exit
  7. -f F Function to optimize. Has to be defined in
  8. src/functions.py. Currently availables: "beale",
  9. "rosenbrock", "rastrigin" and "beale"
  10. -p N_PARTICLES Number of articles
  11. -w W Inertia coefficient
  12. -c1 C1 Cognitive coefficient
  13. -c2 C2 Social coefficient
  14. -s N_STEPS Number of optimization steps
  15. -r [RANGE [RANGE ...]]
  16. Range of plot and initialization
  17. -v FPS Frames per second in the output animation
  18. -o FILEPATH Output gif file path
  19. -rd SEED Random seed

Examples

Bowl function

  1. python main.py -f bowl -p 100 -s 50 -w 0.3 -c1 0.4 -c2 0.2 -o examples/bowl.gif

Rosenbrock function

  1. python main.py -f rosenbrock -p 100 -s 50 -w 1.3 -c1 0.4 -c2 0.7 -o examples/rosenbrock.gif

Rastrigin function

  1. python main.py -f rastrigin -p 100 -s 50 -w 0.5 -c1 0.75 -c2 1.0 -o examples/rastrigin.gif

Levi N.13 function

  1. python main.py -f levi_13 -p 100 -s 50 -w 1.0 -c1 1.0 -c2 1.5 -r -4 4 -o examples/levi_13.gif

Beale function

  1. python main.py -f beale -p 100 -s 50 -w 1.3 -c1 1.0 -c2 0.6 -o examples/beale.gif

References

Contribution

Feel free to send issues or pull requests if you want to collaborate.

License

This repository is licensed under MIT license. More info in the LICENSE file. Copyright (c) 2020 Iván Vallés Pérez