Getting error in my OuputFcn for Genetic Algorithm
古いコメントを表示
Hi
I'm trying to save the state information by using an OutputFcn, but I keep getting errors when I call state.Generation. The errors only say
"Error in run_ga_search>myOutFun (line 63)
state.Generation"
Here's my OutputFcn code:
opts = gaoptimset('Display','off','OutputFcn',@myOutFun);
[x,fval,exitFlag,Output,population] = ga(@grating_cost_function_from_dc,nvars,[],[],[],[],LB,UB,[],opts);
function [state, options, optchanged] = myOutFun(options, state, flag)
%gen = state.Generation;
state.Generation
if strcmp(flag,'iter')
fileID = fopen([folder '/stoppingCriteria.txt'],'w');
fprintf(fileID, 'Stopping Criteria\n');
fprintf(fileID, 'Generation: %6.6f\n', state.Generation/options.MaxGenerations);
fprintf(fileID, 'Time: %6.6f\n', toc(state.StartTime)/options.MaxTime);
fprintf(fileID, 'StallG: %6.6f\n', (gen-state.LastImprovement)/options.MaxStallGenerations);
fprintf(fileID, 'StallT: %6.6f\n', toc(state.LastImprovementTime)/options.MaxStallTime);
fclose(fileID);
save([state_folder '/state_' num2str(state.Generation) '.mat'],'state');
end
end
Thanks
5 件のコメント
Walter Roberson
2016 年 7 月 12 日
For debugging purposes, before your reference to state.Generation, insert
class(state)
disp(state)
and see what shows up.
Yanni Dahmani
2016 年 7 月 12 日
Walter Roberson
2016 年 7 月 12 日
It sounds as if myOutFun has been invoked without any parameters, somehow. I suggest at the command line you invoke
dbstop if caught error
and run again. It should stop at the actual error call. You can then use dbstatus and dbup to find the place the call was made.
What is showing up is the kind of thing I would expect if your line
opts = gaoptimset('Display','off','OutputFcn',@myOutFun);
somehow is instead
opts = gaoptimset('Display','off','OutputFcn',myOutFun);
Yanni Dahmani
2016 年 7 月 12 日
Yanni Dahmani
2016 年 7 月 12 日
編集済み: Yanni Dahmani
2016 年 7 月 13 日
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Operating on Diagonal Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!