fmincon does not call output function
古いコメントを表示
MATLAB R2016b
I am using fmincon, and would like to run an output function to save data of each iteration.
I set the options and call fmincon as follows:
options = optimoptions('fmincon','Display','iter','Algorithm','sqp','DiffMinChange',0.01,'DiffMaxChange',0.5,'OutputFcn',@outf,'PlotFcn',@optimplotfval);
[x,fval,exitflag,output] = fmincon(@(X) Start(X,initval,C),X0,[],[],[],[],lb,ub,@(X) Constraints(C),options);
My output function is
function stop = outf(x,optimValues,state)
tenditer=toc;
stop=false;
fid = fopen('history_fuel.txt', 'at');
fprintf(fid,'%f \n',optimValues.fval);
fclose(fid);
%...
%snip
%...
tic;
end
Fmincon iterates without problems, but never calls the output function, no file written and I double-checked by adding a debug-pause in my output function which is never triggered. I just followed the documentation and now I don't see what went wrong.
My question is: Why does it not call the output function and how can I do it?
Question 2: Also the PlotFcn is supposed to do something every iteration or not? In case it is supposed to, that one does not do anything either.
7 件のコメント
Torsten
2017 年 12 月 19 日
...,@(X) Constraints(C),...
looks strange in your call to fmincon.
Best wishes
Torsten.
GForce
2017 年 12 月 19 日
Torsten
2017 年 12 月 19 日
So C is some function of X which already includes the constraints ?
GForce
2017 年 12 月 19 日
Ok.
What about changing
options = optimoptions('fmincon',...
to
options = optimoptions(@fmincon,...
You know this page
https://de.mathworks.com/help/optim/ug/output-functions.html#brjhnpu
?
Best wishes
Torsten.
GForce
2017 年 12 月 19 日
Matt J
2017 年 12 月 19 日
No sorry forgot to mention, C is just a vector of constants. These constants together with the global variables from the objective function are used to calculate the constraints.
You are making a big assumption that the objective function will always be evaluated before the constraints. It would be better if you followed the guidelines here.
回答 (1 件)
What happens when you insert the debug pause again and call the OutputFcn directly from the options object
options = optimoptions('fmincon','Display','iter','Algorithm','sqp',...
'DiffMinChange',0.01,'DiffMaxChange',0.5,...
'OutputFcn',@outf,'PlotFcn',@optimplotfval);
options.OutputFcn()
カテゴリ
ヘルプ センター および File Exchange で Surrogate Optimization についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!