Skip to content
Prev 202071 / 398503 Next

optim or nlminb for minimization, which to believe?

Your function named 'gradient' is not the correct gradient. Take as an
example the following point x0, very near to the true minimum,

    x0 <- c(-0.2517964, 0.4898680, -0.2517962, 0.4898681, 0.7500995)
 
then you get

    > gradient(x0)
    [1] -0.0372110470  0.0001816991 -0.0372102284  0.0001820976 
0.0144292657

but the numerical gradient is different:

    > library(numDeriv)
    > grad(fn, x0)
    [1] -6.151645e-07 -5.507219e-07  1.969143e-07 -1.563892e-07
-4.955502e-08

that is the derivative is close to 0 in any direction -- as it should be for
an optimum.

No wonder, optim et al. get confused when applying this 'gradient'.

Regards
Hans Werner
Doran, Harold wrote: