Keep getting error: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: NaN
조회 수: 15 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (2개)
CS Researcher
2016년 5월 3일
편집: CS Researcher
2016년 5월 3일
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.
댓글 수: 0
Walter Roberson
2016년 5월 3일
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:
- 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.
- 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.
- 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.
- 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
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!