필터 지우기
필터 지우기

why in the following code the value of gbest is not updating with each iteration and showing Infinity as a outcome..

조회 수: 1 (최근 30일)
fgbest=Inf;
for j=1:Popsize
% Generate Random Solution
pop(:,j)=randi([500,2000],10,1);
[obj]=objfn(pop,it);
%
% % Evaluation
obj1(j,1) = obj(j,1);%
%
% Update the Personal Best
pbest(:,j) = pop(:,j);% pbest
fpbest(j,1) =obj1(j,1);% objective function
%
% % Update Global Best
if fpbest(j,1) < fgbest
gbest = pbest(:,j);% gbest
end
end
  댓글 수: 1
Geoff Hayes
Geoff Hayes 2016년 7월 23일
sharad - what is your objective function, objfn? Have you stepped through the code to see what is happening and, in particular, what this function is returning? Also, for your condition
if fpbest(j,1) < fgbest
gbest = pbest(:,j);% gbest
end
I think that you want to be using just one of gbest or fgbest. (What is the difference between the two?) Since you are trying to find the global best, you will always want to compare against the last best found solution. So something like
if fpbest(j,1) < fgbest
fgbest = pbest(:,j);
end
may be what you really want.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by