A simple implementation of classic Particle Swarm Optimization in Python.
- Update the fitFunc function to accurately reflect your fitness function
- Adjust Np and Nd to reflect your fitness function
- Adjust xMin, xMax, vMin, and vMax to reflect your fitness function
- Adjust gBestValue and pBestValue initialization to reflect your fitness function
- Run the code!
fitFunc: User defined fitness function
initPosition: Initializes R with random values
initVelocity: Initializes V with random values
updatePosition: Updates R values based on V
updateVelocity: Updates V values based on gBestPos, pBestPos, w, and chi
udpateFitness: Updates M values based on R
R: Position
V: Velocity
M: Fitness
Np: Number of Probes Nd: Number of Dimensions Nt: Number of Iterations
w: Omega wMin: Omega Minimum Value wMax: Omega Maximum Value
chi: Constriction Factor
xMin: Minimum value for any dimension in R xMax: Maximum value for any dimension in R
vMin: Minimum value for any dimension in V vMax: Maximum value for any dimension in V
gBestValue: Global best fitness value gBestPos: Global best fitness position
pBestValue: Personal best fitness value pBestPos: Personal best fitness position