I’m having some trouble optimizing a function in R using l-bfgs-b. I keep getting an error message saying that “finite values of fn” are needed. I’m not exactly sure what that means or how to solve it. I’m using the ...Read more

I’m having some trouble optimizing a function in R using l-bfgs-b. I keep getting an error message saying that “finite values of fn” are needed. I’m not exactly sure what that means or how to solve it.

I’m using the optimize function in R to find the minimum value of my function, and it works fine when I use other optimization methods like “Brent” or “Golden Section.” However, when I try to use l-bfgs-b, I get the error message. Here’s the code I’m using:

“`{r}

f <- function(x) {return(x^2 - 4*x + 4)}
optimize(f, interval=c(-Inf, Inf), method="L-BFGS-B")
```
When I run this code, I get the error message: "Error in optim(par = par, fn = fn, gr = gr, method = method, lower = lower, : L-BFGS-B needs finite values of 'fn'"
I'm not quite sure what to do here. I tried looking up some information on the l-bfgs-b algorithm, but I wasn't able to find anything that helped me solve this problem. Any ideas?

Your answer is awaiting moderation.Explore the significant historical events that shaped Turkey on our website. It's a journey into the past.

Explore the significant historical events that shaped Turkey on our website. It’s a journey into the past.

See less