How do i insert my own initial population in genetic algorithm toolbox?
Afficher commentaires plus anciens
ive created a matrix (MAT) where the number of rows (N) is the number of posible solutions and the columns are the variables, which in this case is 16.
ive already developed a fitness function where evaluates each row, and the results (N) are displayed in a new matrix Nx1. Therefore, I want the program to take a random number of rows of MAT, put them in my fitnes function, and do its own genetic operations (selection,crossover, etc) to give me the best solution (minimized).
So, how do i program ga optimizacion toolbox or the ga function ( ga(@fitnessfun, nvars, options) ) in order to do this?
Thank you in advance.
Réponses (1)
Walter Roberson
le 10 Fév 2018
0 votes
7 commentaires
Hamidreza Mazloumi
le 24 Juil 2020
Hello Walter.
I extract the initial population successfully. I use an external function wich calculates the fitness value of every point and stores it in a lookup table (Objectives).
Objectives(:,nGen) = NaN(number_of_members,1) ;
for i = 1 : length(feasible_members)
Objectives(feasible_members(i),nGen) = heatflux(i) ;
end
I also have created a function which only reads the fitness value of every point. I use this reading function as the objective function for "ga".
function obj=external_obj_func(in)
global NFE nGen %Number of Function Evaluations
global Objectives %1-D array for single objective optimization and 2-D array for double-objective opt
in
NFE = NFE + 1 ;
% obj=Objectives(NFE,nGen);
obj = 1 ;
And this is how I call "ga" :
[x,fval,~,~,population,~]=ga(fun,5,[],[],[],[],lb,ub,@cavity_ARNLC,opt);
The problem is that I expected the "ga" to evaluate the fitness at every point of the initial population (reading from lookup table (Objectives)) and then generate the new generation population and stop the current iteration. In contrast "ga" evaluates fitness at every point of current generation then it tends to generate a new subpopulation by means of passing elite members, mutation and crossover and then calculate fitness values for this new subpopulation in the same itteration
Is there any way to prevent matlab from creating this new subpopulation and calculating fitness values at new points at this current iteration?
Walter Roberson
le 24 Juil 2020
(reminder to myself)
Gustavo Lunardon
le 13 Sep 2022
Was a solution found out for this?
Walter Roberson
le 13 Sep 2022
The solution for the original question is what I posted earlier, the InitialPopulationMatrix option.
Walter Roberson
le 13 Sep 2022
toolbox/globaloptim/globaloptim/private/makeState.m runs the creation function if the size of the InitialPopulation is smaller than the PopulationSize option.
Objectives(feasible_members(i),nGen)
looks like something that should instead be handled through the InitialScores option.
makeState does not create any elite members.
Gustavo Lunardon
le 13 Sep 2022
Modifié(e) : Gustavo Lunardon
le 13 Sep 2022
I was having a similar problem earlier today actually. I pass an initial population to GA by the options via optimoptions (gaoptimset was phased out meanwhile, old question) and some of of the population members are the outcome of fmincon, globalsearch, etc. This means I have some good (and feasible) members in the population already, but I wanted to use GA for refinement and perhaps find an optimum somewhere else. Like the original post, however, GA gives me a worse objective function value than what I can get from the initial population, maybe by the creation of the subpopulation mentioned by Hamidreza. I tried to pass [] to 'creationfunction' but also did not solve the problem.
ga can return a worse value than the original if the original population elements turn out to be outside the constraints.
Also, sometimes when people construct arrays of numbers that have been computed, they copy some display form of the number instead of transfering the number in binary form from its computed source. If you build your arrays by text then unless you are careful to have asked MATLAB to display more digits than it normally would, you might not end up reproducing the exact locations, and if the function is steep then that can make a considerable difference as to what the scores are.
For example, if we
format long g
pi
pi - 3.14159265358979
pi - 3.141592653589793
we copied the exact text that MATLAB displays for pi, but that turns out to be a value slightly smaller than the actual value of pi. We had to go one more digit than is displayed by MATLAB in order to match the actual value.
Catégories
En savoir plus sur Genetic Algorithm dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!