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!