Re: [R] L-BFGS-B needs finite values of 'fn'

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Mon, 31 Mar 2008 12:43:17 +0100 (BST)

Your function gives -Inf at the lower bound on the parameters, so you are minimizing a function without a lower bound.

Using the trace facilities of optim() would have got you thereeasily enough.

On Mon, 31 Mar 2008, Paul Smith wrote:

> 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)))
>
> ______________________________________________

> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

-- 
Brian D. Ripley,                  ripley_at_stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Mon 31 Mar 2008 - 11:48:23 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 31 Mar 2008 - 13:30:26 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive