MATLAB Answers

How can I stop fminsearch in one iteration after a specific time?

3 ビュー (過去 30 日間)
fatemeh jafariani
fatemeh jafariani 2020 年 6 月 21 日
編集済み: Walter Roberson 2020 年 6 月 22 日
I used fminsearch for fitting experiment data to a model. It has 5 parameres. For beter optimizing, I changed two parameters in every run of fminsearch but unfortunatly sometimes for some of parameters value, it stops in one iteration and doesn't go to another one or finish. I need to set a certain time for stopping these iterations and sending program to another one. How can I do this?
Thanks,

  0 件のコメント

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

採用された回答

Walter Roberson
Walter Roberson 2020 年 6 月 21 日
fminsearch will stop immediately if funvalcheck is set and the first iteration is nan or complex. Or if there is an error evaluating the function.

  4 件のコメント

表示 1 件の古いコメント
Walter Roberson
Walter Roberson 2020 年 6 月 21 日
Did you check that your function returns non-nan on the initial conditions?
If your initial conditions return a finite value but at some point in searching you encounter nan, then the implication is either that you need constraints or else that you have reached a point where double precision is not sufficient to compute your values (for example, factorial(171)/factorial(170) should obviously be 171 but factorial(171) overflows double precision so you get infinity instead.)
fminsearch is not designed to have bounds of any kind. However, if you look in the File Exchange, John D'Errico has provided fminsearchbnd which supports upper and lower bounds.
fatemeh jafariani
fatemeh jafariani 2020 年 6 月 22 日
Did you check that your function returns non-nan on the initial conditions? yes, I checked. you' re right, it returns a finite value but at some point in searching I encounter nan.
Thank you for your help, I will have a look in the File Exchange that you said.
Walter Roberson
Walter Roberson 2020 年 6 月 22 日
dbstop if naninf
can be very useful.
However in practice it can turn out to be more useful to put a conditional breakpoint at the end of your function that tests whether the value you are about to return contains non-finite numbers. The conditional breakpoint approach avoids accidental triggers on the internals of the optimization functions.

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

その他の回答 (1 件)

Thiago Henrique Gomes Lobato
Thiago Henrique Gomes Lobato 2020 年 6 月 21 日
If when you say stop you mean it simply freezes and you don't get an error nor the iteration goes on than you probably have some while loop in your function that, for those parameters, simpy never ends or maybe a specific process that takes unreasonable many time for centain parameter combinations. Different from fminunc, for example, fminseach doesn't performs any line search, so as long as your function has constant time each iteration should take roughly the same amount of time. If it simply "freezes" then it is something in your function.

  1 件のコメント

fatemeh jafariani
fatemeh jafariani 2020 年 6 月 21 日
thank you for your help.

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by