MATLAB相关技术,跟踪每次迭代的数值,包括目标函数值,种群等等所有优化算法的状态,平台是MATLAB2015R,其他版本类似。本处以多目标遗传算法为例,对每次迭代的种群某一个目标函数最小值与相应代数画图。
工具/原料
MATLAB2015R
方法/步骤
1
创建output function%%% 代码% state.Generation 当前代数% state.Score 种群的目标函数值function [state, options,optchanged] = outfun(options,state,flag)optchanged = false;switch flag case 'init' disp('Starting the algorithm'); case {'iter','interrupt'} plot(state.Generation,min(state.Score(:,1)),'.'); hold on; disp('Iterating ...'); disp(state.Generation); case 'done' disp('Performing final task');end%%%
2
创建options在optimset中加入'OutputFcn', @outfun%%% options = optimset('OutputFcn', @outfun);%%%
3
运行程序[x,fval,flag,output,population] = gamultiobj(@objfun,nvars,... [],[],[],[],lb,ub,options);
注意事项
此文是原创,引用请注明转载