Fitness function run twice / stopping a GA
조회 수: 2 (최근 30일)
이전 댓글 표시
Hello.
I have currently two problem with my GA code. My elements are defined by 4 value, and each time my fitness function is called, I display the values. What I get is :
-0.1827 0.2077 -0.0817 0.0275
-0.1827 0.2077 -0.0817 0.0275
0.8208 -0.6566 0.1232 0.0194
-0.8640 0.7799 -0.1599 0.0242
As you can see, the first element is plotted twice,meaning the fitness function is called twice with that element. But if I look at the population, it is not in it.
Here is my "run" code :
clear all
ObjectiveFunction = @fitnescalc;
nvars = 4; % Number of variables
ConstraintFunction = @constraint;
CreationFcn=@populationInit;
IP=[populationInit()]
for i=1:2
IP = [IP;populationInit()]; % Population MAtrix goes here
end
options = optimoptions('ga','InitialPopulationMatrix',IP,'OutputFcn',@gaoutfun,'PopulationSize',length(IP(:,1)));
[x,fval] = ga(ObjectiveFunction,nvars,[],[],[],[],[],[], ...
ConstraintFunction,options);
Do you see where it could come from ? Thank you
댓글 수: 2
Geoff Hayes
2018년 5월 23일
Boris - what does populationInit() do? i.e. what is the code for this function? Does it return a single element or multiple ones? It looks like you initialize IP as
IP=[populationInit()]
and then update it twice with two calls to this same function so how large is your initial population?
Please copy and paste the code for populationInit to your question.
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Linear Least Squares에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!