Azzera filtri
Azzera filtri

Get argument values using an output function when Objective returns NaN

1 visualizzazione (ultimi 30 giorni)
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.

Risposta accettata

Walter Roberson
Walter Roberson il 15 Set 2017
Did you try setting the FunValCheck option?
  3 Commenti
Walter Roberson
Walter Roberson il 15 Set 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.
CJ
CJ il 19 Set 2017
Alright that helped. I put what I did in the question.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Get Started with Optimization Toolbox in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by