[R] L-BFGS-B needs finite values of 'fn'
Paul Smith
phhs80 at gmail.com
Mon Mar 31 13:24:09 CEST 2008
Dear All,
I am trying to solve the optimization problem below, but I am always
getting the following error:
Error in optim(rep(20, nvar), f, gr, method = "L-BFGS-B", lower = rep(0, :
L-BFGS-B needs finite values of 'fn'
Any ideas?
Thanks in advance,
Paul
-----------------------------------------------
k <- 10000
b <- 0.3
f <- function(x) {
n <- length(x)
r <- sum((b^(0:(n-1)))*log(x)) - 2000000*(sum(x)-k)^2
return(r)
}
gr <- function(x) {
n <- length(x)
r <- (b^(0:(n-1)))*(1/x) - 4000000*(sum(x)-k)
return(r)
}
nvar <- 10
(sols <- optim(rep(20,nvar),f,gr,method="L-BFGS-B",lower=rep(0,nvar),upper=rep(k,nvar),control=list(fnscale=-1,parscale=rep(2000,nvar),factr=1e-300,pgtol=1e-300)))
More information about the R-help
mailing list