extracting more information from optim in R?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

extracting more information from optim in R?

Steve Su-2
Dear All,

I am in the process of translating some of my functions into C and one such function sometimes get stuck when I applied optim. The pure R codes work fine but the translated C codes occasionally get stuck and I like to find out why.

Is it possible to extract the parameters of function calculated in each step of the Nelder-Simplex algorithm, the trace option only produce the value of the objective function in each iteration? Is there a simple way to extract this information?

Any help greatly appreciated.

###########################################

Assistant Professor Steve Su
School of Mathematics and Statistics
Faculty of Engineering, Computing and Mathematics

M019, 35 Stirling Highway
Crawley, 6009, WA, Australia

Phone:+6164883369

http://www.uwa.edu.au/people/steve.su
CRICOS Provider Code: 00126G
        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: extracting more information from optim in R?

Bart Joosen
I have no experience with writing C code, but if I have such problems in R code, I add a line to my function which prints the values to the console:
eg:
fr <- function(x) {   ## Rosenbrock Banana function
    x1 <- x[1]
    x2 <- x[2]
        cat (paste(x1, x2, "\n"))
    100 * (x2 - x1 * x1)^2 + (1 - x1)^2
}
optim(c(-1.2,1), fr)

If the same goes for C, I don't know.

Bart