Skip to content

do_optimhess: ndeps parscale

1 message · Kasper Kristensen

#
Dear list

I think there might be an inconsistency in the function "do_optimhess"
in src/main/optim.c. 
Consider changing the line
"eps = OS->ndeps[i]/(OS->parscale[i]);" 
to
"eps = OS->ndeps[i];"
Then "ndeps" is the finite-difference step on "par/parscale" as it
should be according to the documentation.

Motivation:
[1] 1.000000e+03 7.726989e-09
optim(xstart,f,hessian=FALSE,method="CG",control=list(parscale=parscale))$par
[1] -2.321611e-09 -2.277797e-15
[,1]    [,2]
[1,] 1.000089e-06       0
[2,] 0.000000e+00 3194528
optim(xhat,f,hessian=TRUE,method="CG",control=list(parscale=parscale))$hessian
             [,1]    [,2]
[1,] 1.000000e-06       0
[2,] 0.000000e+00 1648722

##### RECOMPILING WITH THE SUGGESTED CHANGE GIVES CORRECT HESSIAN:
optim(xhat,f,hessian=TRUE,method="CG",control=list(parscale=parscale))$hessian
             [,1]    [,2]
[1,] 1.000001e-06       0
[2,] 0.000000e+00 1000001


Best regards
Kasper Kristensen