similar to: R optim(method="L-BFGS-B"): unexpected behavior when working with parent environments

Displaying 20 results from an estimated 2000 matches similar to: "R optim(method="L-BFGS-B"): unexpected behavior when working with parent environments"

2019 May 03
2
R optim(method="L-BFGS-B"): unexpected behavior when working with parent environments
On 03/05/2019 10:31, Serguei Sokol wrote: > On 02/05/2019 21:35, Florian Gerber wrote: >> Dear all, >> >> when using optim() for a function that uses the parent environment, I >> see the following unexpected behavior: >> >> makeFn <- function(){ >> ???? xx <- ret <- NA >> ???? fn <- function(x){ >> ??????? if(!is.na(xx)
2019 May 03
2
R optim(method="L-BFGS-B"): unexpected behavior when working with parent environments
Yes, I think you are right. I was at first confused by the fact that after the optim() call, > environment(fn)$xx [1] 10 > environment(fn)$ret [1] 100.02 so not 9.999, but this could come from x being assigned the final value without calling fn. -pd > On 3 May 2019, at 11:58 , Duncan Murdoch <murdoch.duncan at gmail.com> wrote: > > Your results below make it look like a
2019 May 06
2
R optim(method="L-BFGS-B"): unexpected behavior when working with parent environments
Optim's Nelder-Mead works correctly for this example. > optim(par=10, fn=fn, method="Nelder-Mead") x=10, ret=100.02 (memory) x=11, ret=121 (calculate) x=9, ret=81 (calculate) x=8, ret=64 (calculate) x=6, ret=36 (calculate) x=4, ret=16 (calculate) x=0, ret=0 (calculate) x=-4, ret=16 (calculate) x=-4, ret=16 (memory) x=2, ret=4 (calculate) x=-2, ret=4 (calculate) x=1, ret=1
2019 May 03
0
R optim(method="L-BFGS-B"): unexpected behavior when working with parent environments
Your results below make it look like a bug in optim(): it is not duplicating a value when it should, so changes to x affect xx as well. Duncan Murdoch On 03/05/2019 4:41 a.m., Serguei Sokol wrote: > On 03/05/2019 10:31, Serguei Sokol wrote: >> On 02/05/2019 21:35, Florian Gerber wrote: >>> Dear all, >>> >>> when using optim() for a function that uses the
2019 May 03
0
R optim(method="L-BFGS-B"): unexpected behavior when working with parent environments
It looks as though this happens when calculating numerical gradients: x is reduced by eps, and fn is called; then x is increased by eps, and fn is called again. No check is made that x has other references after the first call to fn. I'll put together a patch if nobody else gets there first... Duncan Murdoch On 03/05/2019 7:13 a.m., peter dalgaard wrote: > Yes, I think you are
2019 May 06
0
R optim(method="L-BFGS-B"): unexpected behavior when working with parent environments
That's consistent/not surprising if the problem lies in the numerical gradient calculation step ... On 2019-05-06 10:06 a.m., Ravi Varadhan wrote: > Optim's Nelder-Mead works correctly for this example. > > >> optim(par=10, fn=fn, method="Nelder-Mead") > x=10, ret=100.02 (memory) > x=11, ret=121 (calculate) > x=9, ret=81 (calculate) > x=8, ret=64
2019 May 06
1
R optim(method="L-BFGS-B"): unexpected behavior when working with parent environments
It seems that it's an old bug that was found in some other packages, but at that time not optim: https://bugs.r-project.org/bugzilla/show_bug.cgi?id=15958 and that Duncan Murdoch posted a patch already last Friday :) Thomas Am 06.05.2019 um 16:40 schrieb Ben Bolker: > That's consistent/not surprising if the problem lies in the numerical > gradient calculation step ... >
2019 May 03
0
R optim(method="L-BFGS-B"): unexpected behavior when working with parent environments
On 02/05/2019 21:35, Florian Gerber wrote: > Dear all, > > when using optim() for a function that uses the parent environment, I > see the following unexpected behavior: > > makeFn <- function(){ > ??? xx <- ret <- NA > ??? fn <- function(x){ > ?????? if(!is.na(xx) && x==xx){ > ?????????? cat("x=", xx, ", ret=", ret, "
2008 Mar 31
2
L-BFGS-B needs finite values of 'fn'
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)
2009 Apr 15
2
issue with L-BFGS-B in optim (optim just hangs)
Dear R-Help List, I am using optim, with method=L-BFGS-B, to maximize a likelihood inside a large simulation exercise. This runs fine for most simulated data sets, but for some reason, about 1 out of 100 times, optim will just hang. Using a dumb approach to the problem (i.e. printing the parameter values each time the function being maximized is evaluated), I tracked down when this happens,
2010 Aug 06
2
Stopping precision using 'optim'
Hi all~ I am wondering if it is possible to alter the stopping precision for parameters estimated using the 'optim'? If it helps, I am minimizing the log-likelihood of a function using constraints (i.e. L-BFG-S). -Jeremy
2007 Jan 03
1
optim
Hi! I'm trying to figure out how to use optim... I get some really strange results, so I guess I got something wrong. I defined the following function which should be minimized: errorFunction <- function(localShifts,globalShift,fileName,experimentalPI,lambda) { lambda <- 1/sqrt(147) # error <- abs(errHuber(localShifts,globalShift, #
2004 Jan 05
3
optim function : "BFGS" vs "L-BFGS-B"
Dear kind R-experts. Does anybody have an experience to use optim function? If yes, what is the main difference between two method "BFGS" vs "L-BFGS-B"? I used "BFGS" method and got what I wanted. But when I used "L-BFGS-B" the error message said that "L-BFGS-B needs finite values of fn". So that means "BFGS" method can handle even if fn
2011 Feb 25
2
BFGS versus L-BFGS-B
Hi all, I'm trying to figure out the effective differences between BFGS and L-BFGS-B are, besides the obvious that L-BFGS-B should be using a lot less memory, and the user can provide box constraints. 1) Why would you ever want to use BFGS, if L-BFGS-B does the same thing but use less memory? 2) If i'm optimizing with respect to a variable x that must be non-negative, a common approach
2008 Jun 24
2
L-BFGS-B needs finite values of 'fn'
Hi, When I run the following code, r <- c(3,4,4,3,5,4,5,9,8,11,12,13) n <- rep(15,12) x <- c(0, 1.1, 1.3, 2.0, 2.2, 2.8, 3.7, 3.9, 4.4, 4.8, 5.9, 6.8) x <- log10(x) fr <- function(c, alpha, beta) { P <- c + (1-c) * pnorm(alpha + beta * x) P <- pmax(pmin(P,1),0) -(sum(log(choose(n,r))) + sum(r * log(P)) + sum((n -r)* log(1-P))) } fit <- mle((fr), start = list(c
2007 Jul 29
1
behavior of L-BFGS-B with trivial function triggers bug in stats4::mle
With the exception of "L-BFGS-B", all of the other optim() methods return the value of the function when they are given a trivial function (i.e., one with no variable arguments) to optimize. I don't think this is a "bug" in L-BFGS-B (more like a response to an undefined condition), but it leads to a bug in stats4::mle -- a spurious error saying that a better fit has been
2008 Apr 15
1
disturbing seed dependence in optim L-BFGS-B method
The the use of optim with the L-BFGS-B method for the following simple function gives erroneous results. Any help appreciated! Best, Bob Reilly # Code: V=function(p){ p1=p[1];p2=p[2] y=p1*p2-.4*(p1+p2) return(-y)} p=c(.2,.2) # p=c(.8,.8) max=optim(p,V,method = "L-BFGS-B",lower=c(0,0),upper=c(1,1)) max1=optim(max$par,V,method = "L-BFGS-B",lower=c(0,0),upper=c(1,1))
2013 Oct 09
1
Version of L-BFGS-B used in optim etc
Hi. I just noticed the paper by Morales and Nocedal Remark on "Algorithm 778: L-BFGS-B: Fortran Subroutines for Large-Scale Bound Constrained Optimization". TOMS 2011; 38(1): 7 http://www.ece.northwestern.edu/~morales/PSfiles/acm-remark.pdf which describes a couple of improvements (speed and accuracy) to the original Netlib code which AFAICT is that still used by optim() via f2c.
2007 Apr 05
2
Likelihood returning inf values to optim(L-BFGS-B) other options?
Dear R-help list, I am working on an optimization with R by evaluating a likelihood function that contains lots of Gamma calculations (BGNBD: Hardie Fader Lee 2005 Management Science). Since I am forced to implement lower bounds for the four parameters included in the model, I chose the optim() function mith L-BFGS-B as method. But the likelihood often returns inf-values which L-BFGS-B
2007 Apr 09
1
R:Maximum likelihood estimation using BHHH and BFGS
Dear R users, I am new to R. I would like to find *maximum likelihood estimators for psi and alpha* based on the following *log likelihood function*, c is consumption data comprising 148 entries: fn<-function(c,psi,alpha) { s1<-sum(for(i in 1:n){(c[i]-(psi^(-1/alpha)*(lag(c[i],-1))))^2* (lag(c[i],-1)^((-2)*(alpha+1)) )}); s2<- sum(for(m in 1:n){log(lag(c[m],-1)^(((2)*alpha)+2))});