Nelder Mead; Simplex; MSA

2 views (last 30 days)
dhiman banerjee
dhiman banerjee on 11 Nov 2019
Edited: Matt J on 11 Nov 2019
I have coded Nelder -mead simplex method but getting some error: looks it is stuck in infinite loop. Please help.
************************************************************************************************************************************************************************************
function [Best_pos1,Best_score1]=simplex(Moth_pos1,Moth_fitness1,fobj,SearchAgents_no,ub,lb,OPTIONS)
%[Best_pos,Best_score,Convergence_curve]=MSA(SearchAgents_no,Nc,G,ub,lb,d,fobj,OPTIONS);
%StdVal=10; %any value for convergence
% n=3; %value of N+1
P=1; %reflection coefficient
Chi=2; %expansion coefficient
Gamma=0.5; %contraction coefficient
Sig=0.5; %shrink coefficient
StdVal=1;
while(StdVal > 0.00001)
[Best_score1, location] = min(Moth_fitness1(1:SearchAgents_no+1));
Best_pos1=Moth_pos1(location,:);
[Moth_fitness1,L]=sort(Moth_fitness1);
L1=L.';
Moth_pos11 = Moth_pos1(L1,:);
centroid=(sum(Moth_pos11 ))./SearchAgents_no;
xr=centroid+P*(centroid-Moth_pos11(SearchAgents_no,:));%Reflect
xr=feasiblity(xr,ub,lb,OPTIONS);
if (fobj(Moth_pos11(1,:))<= fobj(xr)&& fobj(xr)<fobj(Moth_pos11(SearchAgents_no,:)))
Moth_pos11(SearchAgents_no+1,:)=xr;
continue;
end
if(fobj(xr) < fobj(Moth_pos11(1,:))) %Expand
xe = (1-Chi).*centroid+Chi.*xr;
xe=feasiblity(xe,ub,lb,OPTIONS);
if(fobj(xe) < fobj(xr))
Moth_pos11(SearchAgents_no+1,:)=xe;
continue;
else
Moth_pos11(SearchAgents_no+1,:)=xr;
continue;
end
end
if(fobj(Moth_pos11(SearchAgents_no,:)) <= fobj(xr)) %Contract
xcout = (1-Gamma).*centroid + Gamma.*xr; %Contract Outside
xcout=feasiblity(xcout,ub,lb,OPTIONS);
xcin = (1-Gamma).*centroid + Gamma.*Moth_pos11(SearchAgents_no+1,:); %Contract Inside
xcin=feasiblity(xcin,ub,lb,OPTIONS);
if fobj(Moth_pos11(SearchAgents_no,:)) <= fobj(xr) && fobj(xr) < fobj(Moth_pos11(SearchAgents_no+1,:)) && fobj(xcout) <= fobj(xr)
Moth_pos11(SearchAgents_no+1,:)=xcout;
continue;
elseif fobj(Moth_pos11(SearchAgents_no+1,:))<= fobj(xr) && fobj(xcin) < fobj(Moth_pos11(SearchAgents_no+1,:)) %Contract Inside
Moth_pos11(SearchAgents_no+1,:) = xcin;
continue;
else
for i=2:SearchAgents_no+1
Moth_pos11(i,:)= (1-Sig).*Moth_pos11(1,:) + Sig.*Moth_pos11(i,:);
end
end
end
for i2 = 1:SearchAgents_no+1
Moth_fitness11(i2,:) = fobj(Moth_pos11(i2,:));
end
Moth_fitness11=sort(Moth_fitness11);
if Moth_fitness11(SearchAgents_no+1,:)-Moth_fitness11(1,:)<StdVal
[Best_score1, location] = min(Moth_fitness11);
Best_pos1 = Moth_pos11(location,:);
break;
else
continue;
end
end

Answers (0)

Categories

Find more on Statistics and Machine Learning Toolbox in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!