fmincon and the Objective function returned NaN warning

17 次查看(过去 30 天)
I minize the negative of a log-likehood function to estimate the parameters of a mixed logit regression model. I use fmincon to estimate the parameters which are the minizing values of the function. Please see the code below.
options = optimset('MaxFunEvals',10000,'TolFun',1e-9,'TolX',1e-9,'Algorithm','sqp','GradObj','off','DerivativeCheck','on','Display','iter');
[theta_hat,fval,exitflag,output,~,grad,hessian] = fmincon(obj,theta_ig,[],[],[],[],lb,ub,[],options);
During the iterations of fmincon, I see the warning "Objective function returned NaN..." few times. At the end, the minimizing values are found. But I still wonder whether I should take the warning as a sign of something going wrong. Am I supposed to never see this warning during the iterations or would it be fair to say that this can happen and does not necesserily point to a problem. In short, how much should I be concerned about the warning?
Objective function returned NaN; trying a new point...
3 93 1.320737e+04 0.000e+00 8.235e-02 2.297e+01 5.692e+04
4 99 1.176385e+04 0.000e+00 1.000e+00 2.141e+01 1.676e+04
5 105 1.162947e+04 0.000e+00 1.000e+00 2.265e+00 2.635e+03
6 111 1.162639e+04 0.000e+00 1.000e+00 4.153e-01 5.914e+01
7 117 1.162633e+04 0.000e+00 1.000e+00 1.436e-01 8.179e+01
8 123 1.162604e+04 0.000e+00 1.000e+00 8.893e-01 4.767e+02

采纳的回答

Matt J
Matt J 2021-10-13
编辑:Matt J 2021-10-13
The sqp algorithm can recover from NaNs and Infs if your objective and constraint functions are finite on an open domain of x (I don't know about closed domains). The warning is probably just to alert you that the algorithm strayed outside the non-NaN domain of the objective and had to backtrack.
  2 个评论
Snoopy
Snoopy 2021-10-15
Let me consider two cases. In the first case the error is displayed in the first couple of itrations. In this case the given answer to the question is intitutive because probably the initial guess for the minimum is far from where the minimum is. In the second case the error is displayed somewhere mid way of all iterations. This case, which in fact applies to my case, looks more worrisome to me. Because over the iterations the search algorithm should be getting closer to a mnimum but all of a sudden the objective function returns an a NaN. Is my reasoning plausible? If yes, then I should worry that my objective function has a problem.
Matt J
Matt J 2021-10-15
编辑:Matt J 2021-10-15
There are no conclusions that can be drawn knowing only when in the iteration sequence the NaNs occur. We would need to see the objective function.
However, you say that the minimum is reached regardless of when the NaNs occur. That seems to suggest that the solver is doing its job, and demonstrating the capability that it advertises of recovering from NaNs.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with Optimization Toolbox 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by