A list,

Particle swarm optimization is derived from Complex Adaptive System (CAS). CAS theory was formally put forward in 1994. Members in CAS are called subjects. For example, in a bird system, each bird is called a subject. The agent is adaptive, it can communicate with the environment and other agents, and according to the process of communication “learn” or “accumulate experience” change its structure and behavior. The evolution or evolution of the whole system includes: the creation of new levels (birthing); The emergence of differentiation and diversity (birds in a flock breaking up into many small groups); The emergence of new themes (birds constantly discover new foods as they search for food). Therefore, the subject in CAS system has four basic characteristics (these characteristics are the basis of the development and change of particle swarm optimization algorithm) : First, the subject is active and active. The main body and the environment and other main body are mutual influence, interaction, this influence is the main power of system development and change. The influence of environment is macroscopical, the influence between subjects is microscopical, macroscopical and microscopical should be combined organically. Finally, the whole system may be affected by some random factors. Particle swarm optimization is based on the research of a CAS system, the social system of birds. Particle Swarm Optimization (PSO) was first proposed by Eberhart and Kennedy in 1995, and its basic concept was derived from the study of the foraging behavior of birds. Consider this scenario: a group of birds are randomly searching for food. There is only one piece of food in the area. None of the birds know where the food is, but they know how far it is from the current location. So what’s the optimal strategy for finding food? The simplest and most effective method is to search the area around the bird that is currently closest to the food. PSO algorithm is inspired by the behavior characteristics of this species and used to solve optimization problems. In PSO, the potential solution of each optimization problem can be imagined as a point in the D-dimensional search space, which we call a Particle. All particles have a Fitness Value determined by the objective function, and each Particle has a velocity that determines the direction and distance they fly. The particles then follow the current optimal particle through the solution space. Reynolds’ study of bird flight found that. The bird is tracking only a limited number of its neighbors but the overall result is that the whole flock seems to be under the control of one center. That complex global behavior is caused by the interaction of simple rules.

Ii. Source code

Clear CLC %% parameter initialization x_range=[- 50.50]; % parameter x range y_range=[- 50.50]; Range = [x_range;y_range]; % parameter range (composition matrix) Max_V =0.2*(range(:,2)-range(:,1)); % Maximum speed is within the range of variation10% ~20%
n=2; % The dimension of the function to be optimized. In this example, there are only x and y independent variables, so2

PSOparams= [25 2000 24 2 2 0.9 0.4 1500 1e-25 250 NaN 0 0]; %% Particle swarm optimization pso_Trelea_vectorized('Rosenbrock',n,Max_V,range,0,PSOparams) % calls the PSO core module % goplotpso.m %default plotting script used in PSO functions
%
% this script is not a function,
% it is a plugin for the main PSO routine (pso_Trelea_vectorized)
% so it shares all the same variables, be careful with variable names
% when making your own plugin



% setup figure, change this for your own machine

 clf
 set(gcf,'Position'[651    31   626   474]); % this is the computer dependent part
 %set(gcf,'Position'[743    33   853   492]);
 set(gcf,'Doublebuffer'.'on');
               
% particle plot, upper right
 subplot('position'[7..6..27..32.]);
 set(gcf,'color'.'k')

 plot3(pos(:,1),pos(:,D),out,'b.'.'Markersize'.7)
 
 hold on
 plot3(pbest(:,1),pbest(:,D),pbestval,'g.'.'Markersize'.7);
 plot3(gbest(1),gbest(D),gbestval,'r.'.'Markersize'.25);
 
 % crosshairs
 offx = max(abs(min(min(pbest(:,1)),min(pos(:,1)))),...
            abs(max(max(pbest(:,1)),max(pos(:,1)))));
 
 offy = max(abs(min(min(pbest(:,D)),min(pos(:,D)))),...
            abs(min(max(pbest(:,D)),max(pos(:,D)))));
 plot3([gbest(1)-offx; gbest(1)+offx],...
       [gbest(D);gbest(D)],...
       [gbestval;gbestval],...
       'r-.');
 plot3([gbest(1); gbest(1)],...
       [gbest(D)-offy;gbest(D)+offy],...
       [gbestval;gbestval],...
       'r-.');
    
 hold off
 
 xlabel('Dimension 1'.'color'.'y')
 ylabel(['Dimension ',num2str(D)],'color'.'y')
 zlabel('Cost'.'color'.'y')
 
 title('Particle Dynamics'.'color'.'w'.'fontweight'.'bold')
 
 set(gca,'Xcolor'.'y')
 set(gca,'Ycolor'.'y')
 set(gca,'Zcolor'.'y')
 set(gca,'color'.'k')
            
 % camera control
 view(2)
 try
   axis([gbest(1)-offx,gbest(1)+offx,gbest(D)-offy,gbest(D)+offy]);
 catch
   axis([VR(1.1),VR(1.2),VR(D,1),VR(D,2)]);
 end
 
% error plot, left side
 subplot('position'[0.1.0.1.475..825.]);
  semilogy(tr(find(~isnan(tr))),'color'.'m'.'linewidth'.2)
  %plot(tr(find(~isnan(tr))),'color'.'m'.'linewidth'.2)
  xlabel('epoch'.'color'.'y')
  ylabel('gbest val.'.'color'.'y')
  
  if D==1
     titstr1=sprintf(['%11.6g = %s([%9.6g])'],...
                gbestval,strrep(functname,'_'.\ '_'),gbest(1));
  elseif D==2
     titstr1=sprintf(['% s([%9.6g, %9.6g])'],...
                gbestval,strrep(functname,'_'.\ '_'),gbest(1),gbest(2));
  elseif D==3
     titstr1=sprintf(['% s([%9.6g, %9.6g, %9.6g])'],...
                gbestval,strrep(functname,'_'.\ '_'),gbest(1),gbest(2),gbest(3));
  else
     titstr1=sprintf([G = %s([%g])],...
                gbestval,strrep(functname,'_'.\ '_'),D);
  end
  title(titstr1,'color'.'m'.'fontweight'.'bold');
  
  grid on
%  axis tight

  set(gca,'Xcolor'.'y')
  set(gca,'Ycolor'.'y')
  set(gca,'Zcolor'.'y')
  set(gca,'color'.'k')

  set(gca,'YMinorGrid'.'off')
  
% text box in lower right
% doing it this way so I can format each line any way I want
subplot('position'[62..1..29..4.]);
  clear titstr
  if trelea==0
       PSOtype  = 'Common PSO';
       xtraname = 'Inertia Weight : ';
       xtraval  = num2str(iwt(length(iwt)));
       
     elseif trelea==2 | trelea==1
       
       PSOtype  = (['Trelea Type ',num2str(trelea)]);
       xtraname = ' ';
       xtraval  = ' ';
       
     elseif trelea==3
       PSOtype  = (['Clerc Type 1"']);
       xtraname = '\chi value : ';
       xtraval  = num2str(chi);

  end
  if isnan(errgoal)
    errgoalstr='Unconstrained';
  else
    errgoalstr=num2str(errgoal);
  end
  if minmax==1
     minmaxstr = ['Maximize to : '];
  elseif minmax==0
     minmaxstr = ['Minimize to : '];
  else
     minmaxstr = ['Target to : '];
  end
  
  if rstflg==1
     rststat1 = 'Environment Change';
     rststat2 = ' ';
  else
     rststat1 = ' ';
     rststat2 = ' ';
  end
  
  titstr={'PSO Model: ',PSOtype; .'Dimensions : ',num2str(D); .'# of particles : ',num2str(ps); . minmaxstr ,errgoalstr; .'Function : '      ,strrep(functname,'_'.\ '_'); . xtraname ,xtraval; . rststat1 ,rststat2}; text(1..1,[titstr{1.1},titstr{1.2}].'color'.'g'.'fontweight'.'bold');
  hold on
  text(1..9.,[titstr{2.1},titstr{2.2}].'color'.'m');
  text(1..8.,[titstr{3.1},titstr{3.2}].'color'.'m');
  text(1..7.,[titstr{4.1}].'color'.'w');
  text(55..7.,[titstr{4.2}].'color'.'m');
  text(1..6.,[titstr{5.1},titstr{5.2}].'color'.'m');
  text(1... 5,[titstr{6.1},titstr{6.2}].'color'.'w'.'fontweight'.'bold');
  text(1..4.,[titstr{7.1},titstr{7.2}].'color'.'r'.'fontweight'.'bold');
  
  % if we are training a neural net, show a few more parameters
  if strcmp('pso_neteval',functname)
    % net is passed from trainpso to pso_Trelea_vectorized in case you are
    % wondering where that structure comes from
    hiddlyrstr = [];  
    for lyrcnt=1:length(net.layers)
       TF{lyrcnt} = net.layers{lyrcnt}.transferFcn;
       Sn(lyrcnt) = net.layers{lyrcnt}.dimensions;
       hiddlyrstr = [hiddlyrstr,', ',TF{lyrcnt}];
    end
    hiddlyrstr = hiddlyrstr(3:end);
  
    text(0.1.35.['#neur/lyr = [ ',num2str(net.inputs{1}.size),' '. num2str(Sn),' ]'].'color'.'c'.'fontweight'.'normal'.'fontsize'.10);   
    text(0.1.275.['Lyr Fcn: ',hiddlyrstr],...
       'color'.'c'.'fontweight'.'normal'.'fontsize'.9);
       
  end
  
  
  legstr = {'Green = Personal Bests'; .'Blue = Current Positions'; .'Red = Global Best'};
  text(1..0.025,legstr{1},'color'.'g');
  text(1..-.05,legstr{2},'color'.'b');
  text(1..- 125.,legstr{3},'color'.'r');
  
  hold off

  set(gca,'color'.'k');
  set(gca,'visible'.'off');
  
  drawnow
Copy the code

3. Operation results

Fourth, note

Version: 2014 a