how to use 'OutputFcn' in GA
10 次查看(过去 30 天)
显示 更早的评论
Dear All,
I'm trying to use the next function to find some information about previous generation and I found difficulty with writing the state and the options
options = gaoptimset('OutputFcn', @outputfun);
[state,options,optchanged] = outputfun(options,state,flag)
I have this code which is work,
function [x,fval,exitflag,output,population,score] = optimGA(nvars,lb,PopulationSize_Data,Generations_Data,TolFun_Data,InitialPopulation_Data)
%%This is an auto generated MATLAB file from Optimization Tool.
could you please explain to me how to write it. or you may have better idea
Thank you in advance
0 个评论
回答(1 个)
Alan Weiss
2014-8-27
GA will pass in options, state, and flag. You should pass those exact same options and state to the output function output arguments, and set optchanged to false, unless for some reason you want to change the options during your output function call. See the documentation.
Alan Weiss
MATLAB mathematical toolbox documentation
2 个评论
Alan Weiss
2014-8-27
function[state,options,optchanged] = outputfun(options, state, flag)
optchanged = false;
% DO NOT set options, state, or flag!
% Just write code to calculate whatever it is you want here.
% If you need to read an option, then read it, don't set it.
% Make sure that your options include @outputfun as your output function.
Alan Weiss
MATLAB mathematical toolbox documentation
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!