Search code examples
rfminsearch

Get the optimised variables in fminsearch


When using the fminsearch function of the neldermead package

library(neldermead)

foo <- function(x){
  -exp(-x**2)
}
sol <- fminsearch(fun = foo, x0 = -10)

How can I get the optimum values?

I see I can print sol and that this gives the correct value:

> sol

Number of Estimated Variable(s): 1

Estimated Variable(s):
  Initial Final
1     -10     0

But I would need to store that value in a variable. The examples in the documentation do not say how to access to that value, so I guess it is trivial, but I don't find the way to do it.


Solution

  • Not sure the above answer is correct, my understanding is that you need

    neldermead.get(sol, "xopt")
    

    as sol is a neldermead object, see the documentation here