Conditional Optimization problem: inf and NaN

7 ビュー (過去 30 日間)
Martin
Martin 2013 年 5 月 14 日
Hi guys, I am doing a conditional optimization procedure. My problem is that it says:
'fmincon cannot continue: user function is returning Inf or NaN values.'
Apparently my user function returns a Inf, or NaN! Is there a way to avoid this issue? I am running the optimization 1000 times at once, but it is pretty frustrating when it fails on the half-way!
I tried FunValCheck 'on' without luck.
The fmincon looks: fmincon(@(varrho) nlobj(varrho,...,...),...,...)
The objective function is nlobj. I need to minimize it to catch the 5x1 parameter vector "varrho". nlobj returns a scalar and the gradient of it returns a 5x1 vector. I believe these are NaN or Inf. Is there a way to convert these to, say nlobj=5 and gradient=[5 5 5 5 5]' ?
Or probably this not the best way of doing it ?
hope to hear from someone. Thank in advance and have a good day,
-Martin Bergholt

回答 (4 件)

Yao Li
Yao Li 2013 年 5 月 14 日
Try other initial values and adjust the tolerance by implementing optimoptions()
  1 件のコメント
Martin
Martin 2013 年 5 月 14 日
編集済み: Martin 2013 年 5 月 14 日
Hi Yao, my problem is that I need to try out enormous many initial values ! Tol does not work either. But thx

サインインしてコメントする。


Shashank Prasanna
Shashank Prasanna 2013 年 5 月 14 日
Don't let your objective function return nans and infs. Put a condition in the objective function to check for nans and infs isnan isinf
Or use a solver that takes care of this automatically:
interior-point or sqp
  3 件のコメント
Shashank Prasanna
Shashank Prasanna 2013 年 5 月 14 日
How you wish you take care of inf and nan is up to you. It is your objective function and it depends on your problem and what you are trying to optimize.
If you don't know how, I'd recommend trying my second suggestion, changing the solver. Some solvers are capable of handling infs and nans.
Shashank Prasanna
Shashank Prasanna 2013 年 5 月 15 日
Martin, you may have to provide us with your nlobj to understand how we can modify it to not return inf or nan.

サインインしてコメントする。


Martin
Martin 2013 年 5 月 14 日
編集済み: Martin 2013 年 5 月 14 日
Hi Shashank, Thanks for answer.
I agree that isinf() and isnan() binary identifies the inf and NaN, respectively. But how should such kind of condition be implemented in an objective function? I have pretty hard times in seeing it:) If you can elaborate it would be great
My system looks like
for for ....
[varrho, y] = fmincon(@(varrho) nlobj(varrho,...,...),...,...)
end end ....
where
ret = nlobj(varrho,...,...)
stuff
ret = xyz
It runs thousands of times until the damn message arrives: 'fmincon cannot continue: user function is returning Inf or NaN values.'
- best Martin Bergholt
  1 件のコメント
Shashank Prasanna
Shashank Prasanna 2013 年 5 月 14 日
message to you above

サインインしてコメントする。


Martin
Martin 2013 年 5 月 15 日
I tried all algorithms. It seems to, that I have to use to trust-region-reflective, because of my gradient function. And I do not apply an constraint function.
I tried all tolerances. I tried to return some numbers which I know is satisfied of the objective function, in case objective function is NaN or inf.
I am lost.
  2 件のコメント
Shashank Prasanna
Shashank Prasanna 2013 年 5 月 15 日
Martin, please reply as a comment to an existing answer instead of creating a new answer which is really a comment. This makes it easier to track the right answer.
Martin
Martin 2013 年 5 月 15 日
編集済み: Martin 2013 年 5 月 15 日
Hi Shashank, I am noob here:), - sorry, wont happen again.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLinear Programming and Mixed-Integer Linear Programming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by