# Fminunc gives Hessian with NaN

4 views (last 30 days)
CT on 23 Apr 2020
Edited: Matt J on 12 Apr 2021
I am running a minimisation problem using fminunc but I get an Hessian matrix with NaN values. Could you help me to understand:
1) Why?
2) Which sort of underlying problem in my routine does it highlight?
3) How can I fix it (if fixable)
Note the the starting values have been accurately chosen among many as inducing the lowest function value when running fminunc
Here my code
clear
rng default
global L suppsize_X R absdiff epsilon V n YX_product
options = optimoptions(@fminunc, 'OptimalityTolerance', 1e-10, 'StepTolerance', 1e-10 ,'Display','off');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function lik=obj_function_smoothed(coeff)
global L suppsize_X R absdiff epsilon V n YX_product
beta1=coeff(1);
beta2=coeff(2);
beta3=coeff(3);
beta4=coeff(4);
log_sigma_sq=coeff(5);
integral_component=zeros(((L+1)*suppsize_X),R);
lambda=0.05;
for r=1:R
payoff_temp_exp=exp((beta1*absdiff(:,1)+beta2*absdiff(:,2)+beta3*absdiff(:,3)+beta4*absdiff(:,4)+epsilon(:,r)+sqrt(exp(log_sigma_sq))*V(:,r))/lambda); %((L+1)*suppsize_X)x1
denom_temp=sum(reshape(payoff_temp_exp,L+1, suppsize_X)); %1 x suppsize_X
denom_temp2=repmat(denom_temp, L+1,1); %(L+1) x suppsize_X
denom=reshape(denom_temp2, (L+1)*suppsize_X,1); %((L+1)*suppsize_X)x1
integral_component(:,r)=payoff_temp_exp./denom; %((L+1)*suppsize_X)x1
end
integral=sum(integral_component,2)/R;
integral_sample=repmat(integral,n,1);
lik=-sum(log(integral_sample).*YX_product)/n;
end
Laureen de Barsy on 12 Apr 2021
Dear CT, I have a similar problem. Did you or someone else find an answer to the above question? Thank you!

Matt J on 12 Apr 2021
Edited: Matt J on 12 Apr 2021
It is likely due to the objective function having an infinite value at the point being evaluated.
I notice the posted objective has exp(z) operations, which can easily overflow to Inf if the input z is too large. Similarly, it can underflow to zero if z-->-Inf which, if if it then becomes the input to the log() operations further downstream in the code, can also generate Infs.