Fminunc gives Hessian with NaN

조회 수: 7 (최근 30일)
CT
CT 2020년 4월 23일
편집: Matt J 2021년 4월 12일
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
load matrices
global L suppsize_X R absdiff epsilon V n YX_product
options = optimoptions(@fminunc, 'OptimalityTolerance', 1e-10, 'StepTolerance', 1e-10 ,'Display','off');
[paramhat,fval,exitflag, ~, grad, hessian]=fminunc(@obj_function_smoothed,coeff, options);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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
  댓글 수: 1
Laureen de Barsy
Laureen de Barsy 2021년 4월 12일
Dear CT, I have a similar problem. Did you or someone else find an answer to the above question? Thank you!

댓글을 달려면 로그인하십시오.

답변 (1개)

Matt J
Matt J 2021년 4월 12일
편집: Matt J 2021년 4월 12일
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.

카테고리

Help CenterFile Exchange에서 Linear Algebra에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by