www.pudn.com > DE(rand1).rar > benchmark_function.m, change:2011-11-19,size:3393b


function y=benchmark_function(x,s) 
 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
[r,c]=size(x); 
y=zeros(r,1); 
 
%%%%%%%%%%%%%%%%%%%%%%%%%   s=1, Sphere   %%%%%%%%%%%%%%%%%%%%%%%%% 
%%%%%  fmin=f(0,0,...)=0 
if(s==1) 
     y=sum(x.^2,2); 
end 
    
%%%%%%%%%%%%%%%%%%%%%%%%%   s=2, Schwefel %%%%%%%%%%%%%%%%%%%%%%%%% 
%%%%%  fmin=f(0,0,...)=0 
if(s==2) 
    for i=1:r 
     add=sum(abs(x(i,:))); 
        f=1; 
       for j=1:c 
           f=f*abs(x(i,j)); 
       end 
       y(i,1)=add+f; 
    end 
end 
     
%%%%%%%%%%%%%%%%%%%%%%%%%   s=3, Rosenbrock %%%%%%%%%%%%%%%%%%%%%%%% 
%%%%%  fmin=f(1,1,...)=0 
if(s==3) 
      add1=100*sum((x(:,2:c)-x(:,1:c-1).^2).^2,2); 
      add2=sum((x(:,1:c-1)-1).^2,2); 
      y=add1+add2; 
end 
     
%%%%%%%%%%%%%%%%%%%%%%%%%   s=4, Rastrigin  %%%%%%%%%%%%%%%%%%%%%%%%% 
%%%%%  fmin=f(0,0,...)=0 
if(s==4) 
      y=sum(x.^2,2)-10*sum(cos(2*pi*x),2)+10*c; 
end 
     
%%%%%%%%%%%%%%%%%%%%%%%%%   s=5, Griewank   %%%%%%%%%%%%%%%%%%%%%%%%% 
%%%%%  fmin=f(0,0,...)=0 
if(s==5) 
    add=sum(x.^2,2); 
    odd=cos(x./repmat(sqrt(1:c),r,1)); 
    for i=1:r 
        f=1; 
       for j=1:c 
           f=f*odd(i,j); 
       end 
       y(i,1)=add(i)/4000-f+1; 
    end 
end 
     
%%%%%%%%%%%%%%%%%%%%%%%%%    s=6, Ackley    %%%%%%%%%%%%%%%%%%%%%%%%% 
%%%%%  fmin=f(0,0,...)=0 
if(s==6) 
    add1=sum(x.^2,2); 
    add2=sum(cos(2*pi*x),2); 
    y=-20*exp(-0.2*sqrt(add1/c))-exp(add2/c)+20+exp(1); 
end 
     
%%%%%%%%%%%%%%%%%%%%%%%%%    s=7, Quarticfunction(Noise) %%%%%%%%%%%%%% 
% regardless the impact of noise, the fmin=f(0,0,...)=0 
if(s==7) 
        add=repmat([1:c],r,1).*x.^4; 
        y=sum(add,2); 
end 
     
%%%%%%%%%%%%%%%%%%%%%%%%%    s=8, Shaffer   %%%%%%%%%%%%%%%%%%%%%%%%% 
%%%%%  fmin=f(0,0...)=0 
if(s==8) 
      add=sum(x.^2,2); 
      y=-0.5+(sin(sqrt(add)).^2-0.5)./(1+0.001*add).^2;   
end 
%%%%%%%%%%%%%%%%%%%%%%%%%    s=9, Schwefel(2)   %%%%%%%%%%%%%%%%%%%%%% 
%%%%%  fmin=f(0,0...)=0     (   -65 <= x <=65   ) 
if(s==9) 
    for i=1:r 
          for j=1:c 
              add=0; 
              for j1=1:j 
                  add=add+x(i,j1); 
              end 
              y(i,1)=y(i,1)+add^2; 
          end 
    end 
end 
     
%%%%%%%%%%%%%%%%%%%%%%%%%     s=10, Axis         %%%%%%%%%%%%%%%%%%%%%% 
%%%%%  fmin=f(0,0...)=0    (   -5.12 <= x <= 5.12   ) 
if(s==10) 
    add=repmat([1:c],r,1).*x.^2; 
    y=sum(add,2);      
end 
                 
%%%%%%%%%%%%%%%%%%%%%%%%%  s=11, Sum of different power   %%%%%%%%%%%%% 
%%%%%  fmin=f(0,0...)=0   (  -1<= x <=1  ) 
if(s==11) 
    add=abs(x).^repmat([2:c+1],r,1); 
    y=sum(add,2); 
end 
                 
%%%%%%%%%%%%%%%%%%%%%%%%%   s=12, Zakharov    %%%%%%%%%%%%%%%%%%%%%%%% 
%%%%%  fmin=f(0,0,...)=0                 
% if(s==12) 
%     add1=sum(x.^2,2); 
%     add2=sum(0.5*repmat([1:c],r,1).*x,2); 
%     y=add1+add2; 
% end 
%              
%%%%%%%%%%%%%%%%%%%%%%%%%   s=13, De Jong     %%%%%%%%%%%%%%%%%%%%%%%% 
%%%%%  fmin=f(0,0,...)=0 
if(s==13) 
    y=sum(repmat([1:c],r,1).*x.^4,2);   
end 
        
%%%%%%%%%%%%%%%%%%%%%%%%%   s=14, Alpine      %%%%%%%%%%%%%%%%%%%%%%%% 
%%%%%  fmin=f(0,0,...)=0 
if(s==14) 
    add=abs(x.*sin(x)+0.1*x); 
    y=sum(add,2); 
end 
             
%%%%%%%%%%%%%%%%%%%%%%%%%   s=15, Rosenbrock %%%%%%%%%%%%%%%%%%%%%%%% 
%%%%%  fmin=f(1,1,...)=0