Skip to content

optim() non-finite finite-difference value

2 messages · Werner Bier, Spencer Graves

#
I just encountered that myself using optim in S-Plus 6.1.  For a 
certain set of parameter values, the function I wanted to minimize 
returned NaN (not a number).  To fix this problem, I set a trace with 
something like options(trace=99) using, I think, method = "CG".  This 
printed out all the parameter values tested including the one that 
generated the offense.  I then took that set of parameter values to the 
function to be optimized and figured out a way to limit the range of the 
computations.  I used a construct like the following:

	  good.num.limit = c(.Machine$double.xmin, .Machine$double.xmax)^(1/3)

Then I constrained certain positive numbers to lie within these bounds, 
thereby avoiding 0 and Inf.

	  Then I tested the result using method = "Nelder-Mead", "BFGS", and 
"CG".  For my particular installation, for some unknown reason, 
Nelder-Mead bombed S-Plus, BFGS returned a nonsense answer, but CG was 
sensible.  Just a few minutes ago, I restarted my (several hour) job.  I 
think it should be more likely to finish now.

	  hope this helps.
	  spencer graves
Werner Bier wrote: