MATLAB Answers

0

Print more iteration detail in GA code

Asked by Maryam on 31 Oct 2018
Latest activity Commented on by Alan Weiss
on 1 Nov 2018
I have written a GA code, and I want to print out the variable's value at each iteration. Would you please let me know what command should I use for this matter? Thank you.

  0 Comments

Sign in to comment.

1 Answer

Answer by Alan Weiss
on 1 Nov 2018
 Accepted Answer

Take a look at Custom Output Function for Genetic Algorithm. This enables you to get all population members at each iteration (if you modify the example just a bit).
Unless all you want is the best fitness function value at each iteration, in which case all you need to do is set the 'Display' option to 'iter'.
Alan Weiss
MATLAB mathematical toolbox documentation

  2 Comments

Thanks for your answer Alan! I don't want to get the population for each iteration! I used 'Display' option with 'iter', but that just shows the variables value in a graph! I actually want MATLAB to print the values out so I can have the exact numbers for each variable at each iteration!
Again, I'm not sure that I understand exactly what you want. At each iteration there is a population. Perhaps what you want is the best individual at each iteration, the one that gives the lowest fitness function. In that case, look at the Custom Output Function example and just take bestx (which is a row vector containing the variables that I believe you want); you don't need the rest of the stuff for plotting and for saving the whole population.
Alan Weiss
MATLAB mathematical toolbox documentation

Sign in to comment.