function [Convergence_curve,Top_predator_fit,Error,Top_predator_pos]=BMPA_TVSinV(SearchAgents_no,Max_iter,dim,fobj)
rand('state',sum(100*clock)) %#ok
Top_predator_pos=zeros(1,dim);
Top_predator_fit=inf;
Convergence_curve=zeros(1,Max_iter);
stepsize=zeros(SearchAgents_no,dim);
fitness=inf(SearchAgents_no,1);
Prey=initialization(SearchAgents_no,dim,1,0)>0.5;
%% Initilization
SIGMAi=8; SIGMAf=0.05;
GAMMAi=0.3; GAMMAf=0;
PHIi=0.3; PHIf=4;
Iter=1;
FADs=0.2;
P=0.5;
%%
while Iter<=Max_iter
% Updating PHI, SIGMA and GAMMA
PHI=PHIi+Iter*(PHIf-PHIi)/Max_iter; % Eq. 14
SIGMA=SIGMAi+Iter*(SIGMAf-SIGMAi)/Max_iter; % Eq. 17
GAMMA=GAMMAi+Iter*(GAMMAf-GAMMAi)/Max_iter; % Eq. 18
%------------------- Detecting top predator -----------------
for i=1:size(Prey,1)
[fitness(i),Acc]=feval(fobj,Prey(i,:));
if fitness(i)<Top_predator_fit
Top_predator_fit=fitness(i);
Top_predator_pos=Prey(i,:);
Error=1-Acc;
end
end
%------------------- Marine Memory saving -------------------
if Iter==1
fit_old=fitness; Prey_old=Prey;
end
Inx=(fit_old<fitness);
Indx=repmat(Inx,1,dim);
Prey=Indx.*Prey_old+~Indx.*Prey;
fitness=Inx.*fit_old+~Inx.*fitness;
fit_old=fitness; Prey_old=Prey;
%------------------------------------------------------------
Elite=repmat(Top_predator_pos,SearchAgents_no,1); %(Eq. 10)
CF=(1-Iter/Max_iter)^(2*Iter/Max_iter);
RL=0.05*levy(SearchAgents_no,dim,1.5); %Levy random number vector
RB=randn(SearchAgents_no,dim); %Brownian random number vector
for i=1:size(Prey,1)
for j=1:size(Prey,2)
R=rand();
%------------------ Phase 1 -------------------
if Iter<Max_iter/3
stepsize(i,j)=RB(i,j)*(Elite(i,j)-RB(i,j)*Prey(i,j));
Prey(i,j)=Prey(i,j)+P*R*stepsize(i,j);
%--------------- Phase 2 ----------------
elseif Iter>Max_iter/3 && Iter<2*Max_iter/3
if i>size(Prey,1)/2
stepsize(i,j)=RB(i,j)*(RB(i,j)*Elite(i,j)-Prey(i,j));
Prey(i,j)=Elite(i,j)+P*CF*stepsize(i,j);
else
stepsize(i,j)=RL(i,j)*(Elite(i,j)-RL(i,j)*Prey(i,j));
Prey(i,j)=Prey(i,j)+P*R*stepsize(i,j);
end
%----------------- Phase 3 -------------------
else
stepsize(i,j)=RL(i,j)*(RL(i,j)*Elite(i,j)-Prey(i,j));
Prey(i,j)=Elite(i,j)+P*CF*stepsize(i,j);
end
end
end
%% Time-varying Sinus transfer function
Prey=max(min (Prey,6),-6); % Eq. 11
S=abs(sin(Prey/PHI)); % Eq. 12
Prey=rand(SearchAgents_no,dim)<S; % Eq. 13
%%
%------------------ Detecting top predator ------------------
for i=1:size(Prey,1)
[fitness(i),Acc]=feval(fobj,Prey(i,:));
if fitness(i)<Top_predator_fit
Top_predator_fit=fitness(i);
Top_predator_pos=Prey(i,:);
Error=1-Acc;
end
end
%---------------------- Marine Memory saving ----------------
if Iter==1
fit_old=fitness; Prey_old=Prey;
end
Inx=(fit_old<fitness);
Indx=repmat(Inx,1,dim);
Prey=Indx.*Prey_old+~Indx.*Prey;
fitness=Inx.*fit_old+~Inx.*fitness;
fit_old=fitness; Prey_old=Prey;
tmpPrey=Prey;
%---------- Eddy formation and FADs� effect (Eq 16) -----------
if rand()<FADs
U=rand(SearchAgents_no,dim)<FADs;
Prey=Prey+CF*((0+rand(SearchAgents_no,dim).*(1)).*U);
else
r=rand(); Rs=size(Prey,1);
stepsize=(FADs*(1-r)+r)*(Prey(randperm(Rs),:)-Prey(randperm(Rs),:));
Prey=Prey+stepsize;
end
%% Time-varying V-Shaped transfer function
Prey=max(min (Prey,6),-6); % Eq. 11
S=abs(2/pi*atan(Prey/SIGMA*pi/2))+GAMMA; % Eq. 15
temp=rand(SearchAgents_no,dim)<S; % Eq. 16
moving=find(temp==1);
tmpPrey(moving)=~tmpPrey(moving);
Prey=tmpPrey;
%%
Convergence_curve(Iter)=Top_predator_fit;
fprintf('Iteration:%3d\tAccuracy:%7.4f\tFitness:%7.4f\t#Selected Features:%d\n',Iter,((1-Error)*100),Top_predator_fit,(sum(Top_predator_pos,2)));
Iter=Iter+1;
end