Get argument values using an output function when Objective returns NaN

1 次查看(过去 30 天)
I'm using fmincon to minimize a function with arguments X. I get the message on a given iteration and the code continues:
"Objective function returned NaN; trying a new point..."
I want the optimizer to STOP and tell me what that argument value is. I have attempted to look at the confusing output function documentation and attempted to make my own output function:
function [stop,wat] = outfun2(x,optimValues,~)
stop=false;
if isnan(optimValues.fval)==1
stop=true;
wat=x;
end
I know this is definitely not correct. The fmincon code just ignores this and continues the optimization.
What is the best way to just get the argument values from an optimizer?
Can I also interrupt the optimization (with control-c) and still get the arguments at the current iteration?
SOLVED: So the answer that Walter gave and the comments helped me figure it out: So the output function stuff is totally unnecessary. Just add a global variable (inside and outside the objective function) and inside the objective let the global variable equal the parameters. Then add 'FunValCheck','on' to your options. This will cause the minimization to stop and pop out your global variable with the last iteration where it failed.

采纳的回答

Walter Roberson
Walter Roberson 2017-9-15
Did you try setting the FunValCheck option?
  3 个评论
Walter Roberson
Walter Roberson 2017-9-15
In your objective function, write a success status and current t and y values to a shared variable (possibly a global variable) that you can check afterwards.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with Optimization Toolbox 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by