Introduction: Particle Swarm OptimizationAlgorithm(PSO) the most classic version is the gbest-Global version and lbest-local version, which are also defined as standard by one of the inventors in 2007, it suggests that particle swarm algorithms that people will improve in the future should be compared when comparing the advantages and disadvantages of algorithms (indeed, most of us now only implement the gbest version, because it is easy, lbest is relatively difficult), because the two methods are very typical, the former has an advantage in the convergence speed, but it is easy to fall into local minimization, because once a better point is found, everyone rushed over. The latter has an advantage in searching for the global optimal solution, but the convergence speed is slow, because once you define your neighbor, only the optimal solution of the neighbor will affect your running track, the most information except the neighbors must be iterated and transmitted to you.
Therefore, when implementing the latter, we need to connect all the particles in the population with the "neighbor ring. In fact, the global version is a special case of the neighbor version, because once your neighbor is half the number of particles in the population, they are all connected ~~~ The number of neighbors determines a tradeoff between the particle swarm's search speed (exploitation-development capability) and the ability to search for the global optimal solution (exploration capability ~~~
"Neighbor ring" is a name defined by myself: it is a ring first, but each individual in the ring (in the PSO is a particle) can define the number of neighbors. For each individual, there is only one neighbor-ring
Gbest lbest
Gbest speed update formula:
Lbest speed update formula:
In terms of implementation, compared with the gbest version, the difference is only the PGD or PID in the obtained speed formula. The former only requires comparing each particle, however, in the latter case, you can obtain the local optimal solution of each particle in its neighbor range, that is, find the "best" solution in the neighbor, which is a bit painful, it is mainly to connect the headers and tails into a ring ~~~
The day before yesterdayCodeThe implementation of a sentence is relatively clever ~~~ Where,Lbest_ldw_numNumber of custom neighbors.IIs the first particle.P_numIs the number of particles.P_fitnessIs to compare the evaluation indicators.
For specific parameter meanings, seeThe C language implements the labeling PSO algorithm.
/* Update the neighbor extreme position of each particle lbest */For (j =-lbest_ldw_num; j <= lbest_ldw_num; j ++) {/* neighbor extreme position of a particle */If (swarm. particle [(I + J) + p_num) % p_num]. p_fitness <swarm. particle [swarm. lbestindex [I]. p_fitness) swarm. lbestindex [I] = (I + J) + p_num) % p_num ;}
This statement "((I + J) + p_num) % p_numIt processes the negative numbers of the header and tail and the number greater than the number of particle swarm.
PS: record a feeling in the code writing process to warn yourself: "low coupling, high cohesion, including variables and functions" is not implemented.Program"(It may only be file modularization, and pseudo modularization ~~~ This will hurt scalability ~~~