Skip to content
Prev 202216 / 398503 Next

optim or nlminb for minimization, which to believe?

Hi Harold,

Hans is right.  You can see this if you use BB::spg

require(BB)

opt2 <- spg(startVal, fn)  # this is fine

opt3 <- spg(startVal, fn,gradient)  # this is not fine!
Gradient check details:  max. relative difference in gradients=  0.001697913 

  analytic gradient: 0.1724284 -0.3382045 0.1724284 -0.3382045 -0.4902559 

  numerical gradient: 0.2826690 -0.2569404 0.2826690 -0.2569404 -0.4223231
Error in spg(startVal, fn, gradient) : 
  Analytic gradient does not seem correct! See comparison above. Fix it, remove it, or increase checkGrad.tol.
Ravi.

____________________________________________________________________

Ravi Varadhan, Ph.D.
Assistant Professor,
Division of Geriatric Medicine and Gerontology
School of Medicine
Johns Hopkins University

Ph. (410) 502-2619
email: rvaradhan at jhmi.edu


----- Original Message -----
From: Hans W Borchers <hwborchers at googlemail.com>
Date: Sunday, November 29, 2009 6:18 pm
Subject: Re: [R] optim or nlminb for minimization, which to believe?
To: r-help at r-project.org