A simple Particle Swarm Optimization algorithm implementation from scratch
This repository contains a simple PSO implementation to play with.
cd
to the cloned folder.pyenv install 3.8.0
in your terminal for installing the required python.poetry config virtualenvs.in-project true
poetry install
source .venv/bin/activate
python main.py
If everything goes well, it will create a file called animation.gif
in the examples
folder.
Run python main.py --help
to check the parameter reference
usage: main.py [-h] [-f F] [-p N_PARTICLES] [-w W] [-c1 C1] [-c2 C2]
[-s N_STEPS] [-r [RANGE [RANGE ...]]] [-v FPS] [-o FILEPATH]
[-rd SEED]
Parser for animation generator
optional arguments:
-h, --help show this help message and exit
-f F Function to optimize. Has to be defined in
src/functions.py. Currently availables: "beale",
"rosenbrock", "rastrigin" and "beale"
-p N_PARTICLES Number of articles
-w W Inertia coefficient
-c1 C1 Cognitive coefficient
-c2 C2 Social coefficient
-s N_STEPS Number of optimization steps
-r [RANGE [RANGE ...]]
Range of plot and initialization
-v FPS Frames per second in the output animation
-o FILEPATH Output gif file path
-rd SEED Random seed
python main.py -f bowl -p 100 -s 50 -w 0.3 -c1 0.4 -c2 0.2 -o examples/bowl.gif
python main.py -f rosenbrock -p 100 -s 50 -w 1.3 -c1 0.4 -c2 0.7 -o examples/rosenbrock.gif
python main.py -f rastrigin -p 100 -s 50 -w 0.5 -c1 0.75 -c2 1.0 -o examples/rastrigin.gif
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
python main.py -f beale -p 100 -s 50 -w 1.3 -c1 1.0 -c2 0.6 -o examples/beale.gif
Feel free to send issues or pull requests if you want to collaborate.
This repository is licensed under MIT license. More info in the LICENSE
file. Copyright (c) 2020 Iván Vallés Pérez