MATLAB: How to view the automatically generated initial population from GA in Global Optimization Toolbox

genetic algorithmGlobal Optimization Toolbox

I am using the GA function in the Optimization Toolbox, and I'm trying to figure out how I can see the initial population that MATLAB created for me. Any tips on that?

Best Answer

To see the intial population, one can specify/set the 'OutputFcns' property from the option used by GA. The function set by 'OutputFcns' gets called every itteration. First write a function MATLAB file called my_view containing
function [state, options,optchanged] = my_view(options,state,flag,interval)
optchanged = false;
disp(state.Population)
end
Now set the 'OutputFcns' property to this function via
options = gaoptimset('OutputFcns',@my_view);
Finally call the GA function with this specified option
x = ga(fitnessfcn,nvars,options)