how to use fminunc to get Hessian matrix

9 Ansichten (letzte 30 Tage)
Sophia
Sophia am 2 Sep. 2014
Kommentiert: Yulong Deng am 28 Okt. 2014
Hi,
I tried to use "fminunc" to get Hessian matrix, but received error information such as - ____________________________________________________________________________
Error using Agarch. Too many output arguments ... Error in rho1_H01_noplots (line 139) [theta,fval,exitflag,output,grad,hessian] = fminunc(@(theta)Agarch(theta,z,zx),theta0,opts);
Caused by: Failure in initial user-supplied objective function evaluation. FMINUNC cannot continue. ____________________________________________________________________________
And I defined "opts" as - ____________________________________________________________________________
opts = optimset('GradObj','on','Hessian','on','Algorithm','sqp','Display', 'off'); ____________________________________________________________________________
I have been reading the online documents relevant to "fminunc" and "hessian" and adjusted my code correspondingly, but still can't make it work. So I am wondering if anyone could help me fix this issue.
Thanks very much!
Xiao

Antworten (1)

Alan Weiss
Alan Weiss am 2 Sep. 2014
Your options don't make sense, and may indicate a deeper problem. As explained in the options section of the fminunc documentation, the sqp algorithm does not take an input Hessian; the only algorithm that accepts an input Hessian is the trust-region algorithm. So it is possible that your objective function is trying to return the objective, gradient, and Hessian, but fminunc does not use the Hessian. So if you did not conditionalize your code to only give the number of outputs requested, then you can get this error.
That said, all algorithms can produce an output Hessian estimate.
There might be something else going on. Without more details, I don't know.
Alan Weiss
MATLAB mathematical toolbox documentation
  12 Kommentare
Sophia
Sophia am 17 Sep. 2014
Bearbeitet: Sophia am 17 Sep. 2014
Thanks for your response. I appreciate it.
My code is pretty long, and I am not sure if it's appropriate for me to put all of them here, but when I ran more simulations with the same code today, I did receive some error information saying that - _____________________________________________________________________
.
.
.
Optimization completed because the size of the gradient is less than the default value of the function tolerance.
Computing finite-difference Hessian using user-supplied objective function.
Undefined function or variable "relStepSize".
Error in C:\PROGRA~1\Matlab\R2013a\toolbox\optim\optim\private\lineSearch.p>bracketingPhase (line 191)
Error in C:\PROGRA~1\Matlab\R2013a\toolbox\optim\optim\private\lineSearch.p>lineSearch (line 65)
Error in fminusub (line 201) [alpha,f,grad,exitflagLnSrch,funcCountLnSrch,faultTolStruct] = ...
Error in fminunc (line 419) [x,FVAL,GRAD,HESSIAN,EXITFLAG,OUTPUT] = fminusub(funfcn,x, ...
Error in R715garch11ar_1000_noplots (line 247) [theta_star,fval_star,exitflag_star,output_star,grad_star,hessian_star] = fminunc(fun_star,theta0_star,opts);
_______________________________________________________________________
And in my code, I wrote:
_______________________________________________________
.
.
.
opts = optimoptions(@fminunc,'Algorithm', 'quasi-newton');
.
.
.
fun_star = @(theta_star)Agarch(theta_star,z_star,z1_star,z2_star);
%Agarch is a self-defined function used to cal the negative log-likelihood
%such as "function f = Agarch(theta,z,z1,z2) ...."
[theta_star,fval_star,exitflag_star,output_star,grad_star,hessian_star] = fminunc(fun_star,theta0_star,opts);
.
.
.
____________________________________________________
Based on the error information above, it seems to me that I need to define a variable "relStepSize" somewhere, but I don't understand what the other "Error"s mean ...
Should I define or specify more options in "opts", such as "TolX", "TolFun"?
Thanks!
Yulong Deng
Yulong Deng am 28 Okt. 2014
I have the same question with you about the same error, while I tried to divide the function by some integers which can let the result show, but I also don't know how to let the original function run without any problem.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by