%% RBFN initialization

%% control parameters for RBFN:
% number of RBFN improvements
nsteps = 300;
% regularization factor (measure of how far we are from interpolation and
% closer to approximation)
lambda = 0.0000001;
%% other options
% choose if you want to display results during optimization
rbfndisplayconf = 0; %set 1 for on and 0 for off
% rbfndisplayconf = 1; %set 1 for on and 0 for off
% choose if you want to plot the approximation updates (it is possible only
% for one- or two-dimensinal problems)
showrbfn = 0;  %set 1 for on and 0 for off
% showrbfn = 1;  %set 1 for on and 0 for off
% choose if you wand to save those plots
showrbfnsave = 0; %set 1 for on and 0 for off
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

if rbfndisplayconf
    display( ' ' );
    display(sprintf( 'RBFN cofiguration:' ));
    display(sprintf( '   nsteps = %g', nsteps ));
    display(sprintf( '   lambda = %g', lambda ));
    display( ' ' );

    display( sprintf( 'Fitness call     BSF value     GApoint      GRpoint      RNDpoint       rbfrad') );
end

global rbfrad
istep = 0;
addps = 3;
npoints = 2^Dim + 1;
global points
points = zeros(npoints+addps*nsteps,Dim);
ptsvals = zeros(npoints+addps*nsteps,1);
xreal = zeros(Dim,1);

for i=1:npoints-1
    a = i-1;
    for j=1:Dim
        points(i,j)=mod(a,2);
        a = floor(a/2);
    end
end    
points(npoints,:) = 0.5;

realbsf_value = 999999999999 ; 
realbsf = zeros( Dim, 1 );
for i=1:npoints
    xreal(:) = points(i,:)'.*(Domain(:,2)-Domain(:,1))+Domain(:,1);
    ptsvals(i) = F(xreal(:));
    if ptsvals(i) < realbsf_value 
        realbsf_value = ptsvals(i);
        realbsf(:) = points(i,:);
%         Feval(npoints, realbsf_value, realbsf);
    end
end

if rbfndisplayconf
    display( sprintf( '%12d   %10g', npoints, realbsf_value) );
end
    
dmax = sqrt(Dim);
ga2 = npoints;

%% author: Anicka Kucerova, Czech Technical University in Prague
%% version 0.1.2
%% 30 Mar 2009