Particle swarm algorithm (particle SWARMOPTIMIZATION,PSO) proposed by Kennedy and Eberhart in 1995, the algorithm simulates the behavior of bird colony flying foraging, and the group achieves the optimal goal through collective collaboration, which is based on the swarm Optimization method of intelligence. Similar to the genetic algorithm, but also a group based on the iteration, but there is no genetic algorithm for crossover and mutation, but the particles in the solution space following the best particle search. The advantage of PSO is that it is easy to implement and has a profound intelligence background, which is suitable for scientific research, especially suitable for engineering application, and there are not many parameters to be adjusted.
Basic PSO algorithm
In D-dimensional space, there are n particles;
Particle i position: xi= (xi1,xi2,... XiD), the XI generation into the adaptive function f (xi) to find the appropriate value;
Particle i velocity: vi= (vi1,vi2,... ViD)
Particle I experienced the best position: pbesti= (pi1,pi2,... PiD)
The best place the population has ever experienced: gbest= (g1,g2,... GD)
Particle swarm algorithm Key parameters:
(1) Particle swarm size n: General 20-50
(2) The Inertia weight value w: generally is [0.8,1.2], may fix also may change dynamically
(3) Accelerated constants (learning factors) C1 and C2: General Settings C1=c2
(4) Particle maximum velocity Vmax: Control range [-vmax,vmax]
(5) Stop criterion: Maximum number of iterations, calculation precision or maximum stagnation step of optimal solution
(6) Boundary condition Processing: for example, by setting the maximum position of xmax and Vmax.
The minimum value of the function f (x,y) =3cos (XY) +x+y^2 is evaluated by particle swarm algorithm, where the range of x is [ -4,4] for the -4,4],y value range.
%%% the minimum value of the function f (x,y) =3cos (XY) +x+y^2, where x is scoped to [ -4,4] for the -4,4],y value. % particle number n=100% d=2% Iteration number t=200% learning factor c1=c2=1.5% inertia weight maximum is wmax=0.8 inertia weight minimum is wmin=0.4% position maximum is xmax=4, position minimum is xmin=-4% The maximum velocity is vmax=1, and the minimum velocity is vmin=-1%%%%%% particle swarm algorithm for function extremum%%%%%%%%%%%%%%%%%%%%%%%% initialization%%%%%%%%%%%%%%%%%% Clear all; % clears all variables close to all; % clear Figure CLC; % clear screen n=100; % particle number d=2; % particle dimension t=200; % maximum iteration number c1=1.5; % learning factor C1 c2=1.5; % learning factor C2 wmax=0.8; % inertia weight maximum value wmin=0.4; % Inertia weight minimum value xmax=4; % position maximum value xmin=-4; % position minimum value vmax=1; % speed maximum vmin=-1;
% speed minimum%%%%%% initialize population (position and velocity)%%%%%%%%%%%%%%%%%% X=rand (n,d) * (xmax-xmin) +xmin;
V=rand (n,d) * (vmax-vmin) +vmin;
%%%%%% initialized individual optimal position and optimal value%%%%%%%%%%%%%%%%%% p=x;
Pbest=ones (n,1); For I=1:n pbest (i) =func4 (x (i,:)); end%%%%%% initializes the global optimal position and optimal value%%%%%%%%%%%%%%%%%% g=ones (1,d); gbest=inf; for I=1:n if (p
Best (i) <gbest) g=p (i,:);
Gbest=pbest (i);
End-end Gb=ones (1,t); %%%%%% iteration by formula until the precision or iteration is met%%%%%%%%%%%%%%%%%% for I=1:t for j=1:n%%%%%% Update individual optimal position and optimal value%%%%%%%%%%%%%%%%%% if(Func4 (X (J,:) <pbest (j))) p (J,:) =x (J,:);
Pbest (j) =func4 (X (J,:));
End%%%%%% Update global optimal position and optimal value%%%%%%%%%%%%%%%%%% if (Pbest (j) <gbest) G=p (J,:);
Gbest=pbest (j);
End%%%%%% calculates the dynamic inertia weight value%%%%%%%%%%%%%%%%%% w=wmax-(wmax-wmin) *i/t;
%%%%%% update position and Velocity%%%%%%%%%%%%%%%%%% V (j,:) =w*v (J,:) +c1*rand* (P (J,:)-X (J,:)) +c2*rand* (j,:));
X (J,:) =x (J,:) +v (J,:); Processing of%%%%%% boundary conditions%%%%%%%%%%%%%%%%%% for ii=1:d%%%%%%% just started writing wrong here.%%%%%%%%%%%%%%% if (V (j,ii) >vmax) |
(V (j,ii) <vmin) v (j,ii) =rand* (vmax-vmin) +vmin; End if (x (j,ii) >xmax) |
(x (J,II) <xmin) x (j,ii) =rand* (xmax-xmin) +xmin;
End-end%%%%%% records the global optimal value%%%%%%%%%%%%%%%%%% GB (i) =gbest;
Disp (i); End%%%%%% output optimal value%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% disp (' optimal individual ') disp (g); % optimal individual disp (' optimal value ') disp (GB (end)); % optimal value%%%%%% drawing%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Figure Plot (GB);
Xlabel (' iterative times ');
Ylabel (' fitness value ');
Title (' Adaptive Evolution curve ');
%%%%%%% solves functions%%%%%%%%%%%%%%%%%% function
value=func4 (x)
Value=3*cos (x (1) *x (2)) +x (1) +x (2) ^2;
End