Fitness function run twice / stopping a GA
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Geoff Hayes
il 23 Mag 2018
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.
Risposte (0)
Vedere anche
Categorie
Scopri di più su Linear Least Squares in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!