function  [R_best,m,time]=CEoptima(f,options)

n=getfield(options,'Dimension');  % dimesions of problem
N=getfield(options,'Sample_size'); % sample size
alf_m=getfield(options,'Smooth_mu');
alf_s=getfield(options,'Smooth_var');
alf_c=getfield(options,'Smooth_correl');

N_el=round(N*getfield(options,'Elite_part'));  % elite sample
rel=getfield(options,'diff_var'); 
 K=getfield(options,'Injection_size'); 
freq=getfield(options,'Correl_freq');
T=K;
%######################################################################################################
sig= 10*ones(1,n);   
m=4*rand(1,n)-2; 
R_best=inf;  r=0; count=0; Corr=eye(n,n); Cholesky=Corr; tic
for  i=1:80000000

X=randn(N,n)*Cholesky*diag(sqrt(sig))+ m(ones(N,1),:);
S=feval(f,X);

[U,I]=sort(S); 
H=X(I(1:N_el),:);   

m=alf_m*mean(H,1)+(1-alf_m)*m;  
sig=alf_s*var(H,1)+(1-alf_s)*sig;



if (mod(i,freq)==0)&(alf_c~=0)
Corr=alf_c*corrcoef(H,1)+(1-alf_c)*Corr;
Cholesky=chol(Corr);
end


R=U(1);  
if  R<R_best E=H(1,:); R_best=R;  end
if  sig<rel       
     sig=sig+ones(1,n)*T; m=E;
     if T>K/100 , T=T/10; else T=K;  count=count+1; end
     r=r+1;    
 end      
     

   
 if count>=1 ,break, end  
   
   [R, R_best,r,m(1:2)]
  
 
   
end,time=toc;

    

       
        
      
    
        



