필터 지우기
필터 지우기

Get argument values using an output function when Objective returns NaN

조회 수: 1 (최근 30일)
CJ
CJ 2017년 9월 15일
댓글: CJ 2017년 9월 19일
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.
CJ
CJ 2017년 9월 19일
Alright that helped. I put what I did in the question.

댓글을 달려면 로그인하십시오.

추가 답변 (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