⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fdrpso.m

📁 code for fitness distance ratio PSO
💻 M
字号:
function out=fdrpso(functchc,D,Maxgen,epochtime,Rmax,Rmin,Stop_criteria)
% FDR PSO  112
global initial_flag EpochtimeArr tr FE_success_runs success_runs M O
global result_type
% ------Parameter Settings-----
C1=1; C2=1; C3=2;
NP=25;Xmax(1:D)=Rmax;Xmin(1:D)=Rmin;
Vmax = 0.25*(Xmax - Xmin);Wt=1.2;
%------------------------------
%---------- Initialization of swarm -------------
for count_p = 1:NP
    for count_d= 1:D
        X(count_p,count_d) = rand;
        V(count_p,count_d) = rand;
        p_best(count_p,count_d) = X(count_p,count_d);
    end
end
%------------------------------

% ----------  Decreasing inertia weight ----------
for t=1:Maxgen
W(t)=(Wt-0.4)*(Maxgen-t)./(Maxgen+0.4);
end
%--------------------------

%-------------Evaluate fitness value pbest and gbest of all particles
for count_p = 1:NP
            for count_d= 1:D
               xy(count_d)=X(count_p,count_d);
            end
        current_fitness(count_p)=BENCH_FUNCS(xy,functchc);
end 
   p_best_fitness=current_fitness;
   
    [g_best_val,g_best_index] = min(current_fitness);
    for count_d = 1:D
      g_best(count_d) = X(g_best_index,count_d);
    end
%-----------------------------------------------
%--------------- Find the Particle Which Maximizes the FDR
 for j=1:NP
                for i=1:NP
                       if abs(sum(p_best(j) - X(i)))~=0
                                FDR(j,i)=(p_best_fitness(j)-current_fitness(i))./abs(sum(p_best(j) - X(i)));
                        end
                 end
            end

             [fdr_max_val,fdr_best_index] = max(max(FDR));
%-------------------            

if epochtime ==1
    tic;
end
%-------- Main routine starts ---------------
for count_g = 1:Maxgen
% ----------  Velocity and Possition Updation ---------------------------
           for count_p = 1:NP
                   for count_d= 1:D 
 V(count_p,count_d)=W(count_g)*V(count_p,count_d)+C1*rand*(p_best(count_p,count_d)-X(count_p,count_d))+C2*rand*(g_best(count_d)-X(count_p,count_d))+C3*rand*(p_best(fdr_best_index,count_d)-X(count_p,count_d));
 V(count_p,count_d)=min(Vmax(count_d),max(-Vmax(count_d),V(count_p,count_d)));
%  X(count_p,count_d)=min(Xmax(count_d),max(-Xmin(count_d),(X(count_p,count_d)+V(count_p,count_d))  )     );
                    X(count_p,count_d)=X(count_p,count_d)+V(count_p,count_d);
                  end
           end 
             
%------------------------------------------------------------------------
             
 % -------- Computing f(xi) ---------
    for count_p = 1:NP   
         if( X(count_p,:) > Xmin & X(count_p,:) < Xmax)
                for count_d= 1:D
                     xy(count_d)=X(count_p,count_d);
                end
              current_fitness(count_p)=BENCH_FUNCS(xy,functchc);
         end   
    end
    
% -------- updating pbest---------    
    for count_p = 1:NP
        for count_d= 1:D
          xy(count_d)=p_best(count_p,count_d);
        end
       p_best_fitness(count_p)=BENCH_FUNCS(xy,functchc);        
        
            if current_fitness(count_p)< p_best_fitness(count_p)
                     p_best_fitness(count_p) = current_fitness(count_p);
                        for count_d = 1:D
                            p_best(count_p,count_d) = X(count_p,count_d);
                        end
           end
    end
%-----------------------------
%--------- Updating gbest------------
      for count_d= 1:D
          xy(count_d)=g_best(count_d);
      end
       g_best_fitness(count_g)=BENCH_FUNCS(xy,functchc);        
 
       [g_best_val,g_best_index] = min(p_best_fitness);
       if g_best_val < g_best_fitness(count_g)
           g_best_fitness(count_g)=g_best_val;
           for count_d = 1:D
                   g_best(count_d) = p_best(g_best_index,count_d);
           end        
       end
%---------------------------------------   

%--------------- Find the Particle Which Maximizes the FDR
 for j=1:NP
                for i=1:NP
                       if abs(sum(p_best(j) - X(i)))~=0
                                FDR(j,i)=(p_best_fitness(j)-current_fitness(i))./abs(sum(p_best(j) - X(i)));
                        end
                 end
            end

             [fdr_max_val,fdr_best_index] = max(max(FDR));
%----------------------------------------------------------            

           % -------- Stop criteria ---------
             if g_best_fitness(count_g) <Stop_criteria   
             disp('Stop criteria');
             success_runs= success_runs+1;
             FE_success_runs(success_runs)=g_best_fitness(count_g);
                break
             end
           %---------------------------------
end
if epochtime ==1
    EpochtimeArr(tr)=toc;
end

for n=count_g:Maxgen
    g_best_fitness(n)=g_best_fitness(count_g);
end


Value=g_best;

if result_type==1
    out=g_best_fitness;
    FitnessFDRPSO=g_best_fitness(Maxgen)
else
    out=g_best_fitness(Maxgen);
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -