Keep getting error: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: NaN

29 visualizzazioni (ultimi 30 giorni)
Good afternoon,
So I am trying find a specific set of parameters called [mu sigma tau] with the use of 100x1 vector with at least 5 values of NaN. When I run the function simple_egfit, I get this error:
Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: NaN
ans =
NaN NaN NaN
This is a specific type of function not found in Matlab so I really don't have much help here. Any advice to work around this would be greatly appreciated. Thanks

Risposte (2)

CS Researcher
CS Researcher il 3 Mag 2016
Modificato: CS Researcher il 3 Mag 2016
Not completely sure what the problem is but you can remove the NaN entries from the array. Lets say your array of size 100x1 is x, you can do the following:
x(isnan(x)) = [];
It will reduce the size of your array though. Do you need to be of 100x1 size? If yes, you can replace [] by some number.

Walter Roberson
Walter Roberson il 3 Mag 2016
Your code uses one of fminbnd, fminsearch, or fzero. None of those can deal with NaN values, and if they encounter it they will continue to iterate until they reach the iterations limit. You have some choices:
  1. If the objective function calculation "always" has NaN because of the input data, you need to rewrite the objective function to act reasonably on the NaN. If you "always" have NaN and cannot reasonably rewrite the objective function then you probably need to completely change your strategy for what you are trying to do.
  2. To stop the optimization as soon as a NaN or inf is detected, turn on the FunValCheck option. Note that if you do this for fminsearch then if the NaN is generated because of an unfortunate random choice, the point will not simply be rejected with the search continuing: the entire search will end. On the other hand, fminsearch would otherwise get stuck because of the NaN and is never able to recover anyhow, so you might as well set FunValCheck for it.
  3. If you are using fminbnd and the objective function gives NaN when one of the entries reaches a particular value, then set the lower bounds and upper bounds so that value will not be considered. fminsearch and fzero do not use bounds constraints so this is not available for those.
  4. If you are using fzero then, as mentioned, you cannot set lower bound or upper bounds. However, if you have the Optimization toolbox, then you can transform fzero applied to function F to become fmincon applied to F^2, and then put your constraints on that.
My crystal ball is suggesting that you probably need to completely change your strategy for what you are trying to do. In particularly it is suggesting to me that you need to have a look at John D'Errico's File Exchange contribution inpaint_nan

Categorie

Scopri di più su Optimization 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