Skip to content

YashSax/Particle-Swarm-Visualizer

Repository files navigation

Particle-Swarm-Visualizer

Particle Swarm Optimization Visualizer using p5.js! View at: https://yashsax.github.io/Particle-Swarm-Visualizer/

What is Particle Swarm Optimization?

Particle Swarm Optimization (PSO) is a bio-inspired machine learning algorithm that optimizes solutions to a problem by iteratively updating many candidate solutions, or particles, over time.

As it was initially intented to simulate social behavior, PSO exhibits behavior strikingly similar to that of a flock of birds or a school of fish. The main benefits of using PSO include its computational efficiency and its ability to easily parallelize.

Learn more about PSO here: https://en.wikipedia.org/wiki/Particle_swarm_optimization

Part 1: Cursor Following

Cursor_Following.mp4

The first part is a cursor-following visualization. Each of the individual particles try to minimize the distance between themselves and the red circle, their particle's velocity governed by three simple rules:

  1. Each particle has an inertia that, like in the physical world, specifies its resistance to changing directions.
  2. Each particle is drawn, with a certain coefficient c1, to the best (highest reward) position it's discovered.
  3. Each particle is also drawn, with a certain coefficient c2, to the best (highest reward) position the swarm, as a whole, has discovered.

Part 2: Linear Regression

LinReg.1.mp4

The second part is a implementation of simple linear regression. In the previous example, the reward of a particle was calculated by the euclidian distance between it and the target. In this case, the algorithm uses RMSE (Root Mean Squared Error) to determine how well a line fits a particular set of points. Each particle has an associated slope and y-intercept, analagous to how each particle had a (x,y) location in the cursor-following example

What do the Hyperparameters Mean?

Hyperparameters, unlike the individual (x,y) velocities of the individual particles, dictate how the swarm, as a whole, operates.

Inertia: Inertia represents a particle's willingness to change direction. A low inertia leads to sharper turns, and vice versa.
Personal Best Coefficient: How much a particle is drawn to the best solution its discovered so far. Too high of a personal best coefficient leads to excess wandering, and the swarm might not converge or take a long time to converge.
Global Best Coefficient: How much a particle is drawn to the best solution the swarm has discovered so far. If this is too high, particles will converge prematurely. If this is too low, then particles will wander aimlessly.

About

Particle Swarm Optimization Visualizer using p5.js!

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors