How to get the best idividuals values in each iteration point using GA tool in matlab??? Need your help

7 views (last 30 days)
Hi i am using optimtool in GA tool box in MATLAB. I am getting the plot for best fitness value for each iteration point but now i want to get the best individuals values in each iteration point. Is it possible to get individual values in each generation? If possible then please help me.

Answers (2)

Alan Weiss
Alan Weiss on 12 Feb 2015
You can use an output function to get the individuals and their fitness values. As you see in State Structure, you can get both the population and the scores.
GA has a slightly different syntax for its output functions, but you can look at output functions for different solvers to see how they can be used: Particle Swarm, fmincon, or even the MATLAB fminsearch optimizater.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation
  1 Comment
palash de
palash de on 13 Feb 2015
First of all thank you Alan Weiss
lb = [-1 -1];
ub = [1 1];
nvars=2;
options=gaoptimset('PopulationSize',20,'Generations',200,'StallGenLimit',200,'SelectionFcn', @selectionroulette,'CrossoverFcn',@crossovertwopoint,'Display', 'off','PlotFcns', {@gaplotbestf @gaplotbestindiv});
[x,fval,exitflag,output,population,score] = ga(@objective_function_singlecrk_ga,nvars,[],[],[],[],lb,ub,[],[],options);
Now i am getting the best fitness vs generation but i also want the variables vs generation plot although i am getting the bar plot.

Sign in to comment.


Saeid Ghouli
Saeid Ghouli on 21 Oct 2022
You can define a custom plot function. Inside your plot function, use these two lines to obtain the best individuals:
[~,I] = min(state.Score);
best_individuals = state.Population(I,:);

Community Treasure Hunt

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

Start Hunting!