Get argument values using an output function when Objective returns NaN
1 view (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
Walter Roberson
on 15 Sep 2017
Did you try setting the FunValCheck option?
3 Comments
Walter Roberson
on 15 Sep 2017
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.
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!