clear all  , format short g
n=10;  %dimension of the Rosenbrock
N=20; % sample size
alph=0.1;
N_el=round(0.1*N);  % elite sample

rel=0.001 ; % relative error use 0.0001  for large dimensions
 

%######################################################################################################
 sig= 0.1*ones(1,n); m=3+5*rand(1,n); 
R_best=inf; R=nan; r=0; tic
for  i=2:800000
m_s=m-sig;
I_2=(m_s<2);
I_10=(m_s>10);
 m_s(I_2)=(2)*ones(1,sum(I_2)); 
m_s(I_10)=(10)*ones(1,sum(I_10));
X=rand(N,n)*diag(2*sig) + m_s(ones(N,1),:);

S=Paviani(X);

[U,I]=sort(S);  % I gives us the row # X of the best performers
H=X(I(1:N_el),:);   % this is the elite sample from X

m=(max(H)+min(H))/2;  
sig=alph*(m-min(H))+(1-alph)*sig;
R_old=R;
R=U(1);  
   if  R<R_best   E=H(1,:); R_best=R;  end
   if  sig<rel       
   sig=sig+ones(1,n)/10;
     r=r+1;    
   end      
     
[i,R, R_best,r,N]
  
  if abs(R_best+45.7784684040686)<10^-4, break ,end
 
  
end,toc

    

       
        
      
    
        



