fminsearch ''freezing''

3 views (last 30 days)
Samuel Léveillé
Samuel Léveillé on 10 Jun 2019
Edited: Samuel Léveillé on 11 Jun 2019
Hi
I switched to "fminsearch" for a maximum likelihood estimation in my thesis and i started having issues with the optimization just stopping mid iteration. To be more specific, the iteration normaly takes around 2-3 seconds each but it won't start again even if i wait 1h+.
Matlab look like it still running (the above play button) but workload on the CPU is 0% and no error message.
It seem like a random problem, i'm working with simulated data and it happen once in a while but make me obligated to start all over again...
  3 Comments
Catalytic
Catalytic on 10 Jun 2019
Edited: Catalytic on 10 Jun 2019
But first, you can try re-running with
>> dbstop if naninf
to try to trap any unexpected NaNs or infinite values that are developing part way through your calculations. Arithmetic with NaNs could explain the long computation time.
Matt J
Matt J on 11 Jun 2019
Samuel's comment moved here:
Might be a silly question but is fminsearch robust to NaN value? I first used fmincon-interior point with success and needed to switch to a derivative-free one for the next step in my project.
here are my options
options = optimset('Display','iter','MaxFunEvals',10000,'MaxIter',10000);[parametres,fval,exitflag]=fminsearch(@(param)logL(param,S,R,rf,y,I,K,T,ZC,TYPE),START_,options);
The logL function uses a parfor-loop for it's computation and numerical integrations. The logL function does have NaN values at certain points and i could get around the problem with bounds+non-linear contraints with fmincon (who's also robust to NaN).
I also tried on my personnal computer and the server i run the program, same problem. Most of the time it converge to a solution but about 1/25 time it just freeze as i described.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 10 Jun 2019
fminsearch can end up seaching indefinitely if any nan or inf values are encountered.
To prevent this, you need to use an options structure that has an OutputFcn. The OutputFcn should accept 3 inputs, the first of which is the current x values, the second of which is a struct with information about the optimization, and the third is some flag information I think. You can test ~isfinite(optimValues.fval) to see if you have encountered inf or nan, and return true if you want to stop in that case.
Note that fminsearch provides no way to reject a particular value and keep going: it only provides a way to stop. The function value it will return will be that nan or inf. There are tricks you can use to be more useful, but it is not as convenient as one might hope.
  1 Comment
Samuel Léveillé
Samuel Léveillé on 11 Jun 2019
Edited: Samuel Léveillé on 11 Jun 2019
thank you very much! I previouly tried it on the ''simpler'' model that doesn't produce NaN value and didn't had this issue. It start occuring as I changed for the one that can produce NaN during the optimization..!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!