Bugzilla – Bug 15052
nlminb() hangs if all functions return NA
Last modified: 2014-02-16 11:41:42 UTC
The nlminb() optimizer hangs (with continuous 100% CPU usage) if all functions (objective, gradient, hessian) return NA values. This should of course not be the standard use case...
f <- function (x) NA_real_
gr <- function (x) rep.int(NA_real_, length(x))
hess <- function (x) matrix(NA_real_, length(x), length(x))
nlminb(1:5, f, gr, hess)
The session can't be interrupted by the BREAK signal (C-c), thus I suppose the problem is in the C code.
Similarly, nlminb() is heavily occupied if the objective function and the hessian return NA values, but the gradient returns a numeric vector as intended (even the 0-vector)
nlminb(1:5, f, function(x) rep.int(0, length(x)), hess)
However, there is no such problem with
nlminb(1:5, f, hessian=hess)
nlminb(1:5, f, gradient=gr)
--- session info:
R Under development (unstable) (2012-09-19 r60760)
Platform: x86_64-unknown-linux-gnu (64-bit)
It fails in the Fortran code.
Although the help page claims NA/infinite values are supported, I see nothing in the Fortran code to support the claim. So I've removed the claim.
Workaround to replace NA/NaN in function evaluations by +Inf seems to work.
(spam comment removed)