fmincon and the Objective function returned NaN warning
26 views (last 30 days)
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 on 13 Oct 2021
Edited: Matt J on 13 Oct 2021
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.