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!