fr <- function(x) { ## Rosenbrock Banana function
x1 <- x[1]
x2 <- x[2]
100 * (x2 - x1 * x1)^2 + (1 - x1)^2
}
optim(c(-1.2,1), fr, control=list(trace=T))
takes somewhere between 195 function evaluations to converge. Addind trace=T gives the results of the function (for my function the SSE), but I'm interested in the values used to get to the SSE.
The function I'm trying to optimize runs into local minimums and I'm interested in knowing where those are. Has anyone ever tried that? Could that be achieved by "dumping" the values in a file? Not sure how to do it within optim() or within the function to be optimized. Stackoverflow hasn't been of much help...
Thanks!
Guillaume
--
Check out our R resources at http://www.noamross.net/davis-r-users-group.html
---
You received this message because you are subscribed to the Google Groups "Davis R Users' Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to davis-rug+...@googlegroups.com.
Visit this group at http://groups.google.com/group/davis-rug.
For more options, visit https://groups.google.com/d/optout.
Another way to do this is to set the trace
control option to a non-zero value like so:
optim(..., control=list(trace=1))
This will print the output to the console. If you’re just debugging and want to inspect the values, this may be enough. Depending on the algorithm you choose, the way it is displayed is different, and values greater than 1 can provide more data. If you want to capture the trace information as text, you can use capture.output()
:
trace_data = capture.output(optim(..., control=list(trace=1)))
This will get the trace information as text, but you’ll need to parse it to get numbers.
If you use the nloptr package , which is an excellent alternative to optim
, I’ve written a small package, tracer, specifically for this purpose: https://github.com/noamross/tracer. tracer::nloptr_tr()
is a drop-in replacement for nloptr()
which captures the trace information.
(And I’d be happy for contributions to tracer to parse optim()
outputs).