I am running the nloptr
package in R
which is a package for nonlinear optimization. Within the nloptr
package I am using the cobyla()
command to perform my optimization. Now, I can specify the maximim number of iterations of the algorithm using the maxeval
parameter, but when cobyla()
command executes it only allows me to see the output for the final evaluation. However, I would like to be able to see all of the outputs at every iteration of the method.
Someone recommended to me that I use the trace()
command to be able to see all of the intermediary output but I cannot figure out how to get R
to store this information. Can anyone suggest to me how to accomplish this using trace()
(or any other way).
Here is the code I am working with:
library(nloptr)
#########################################################################################
###
#########################################################################################
f = function(x){
ans = cos(pi*x/5)+.2*sin(4*pi*x/5)
return(ans)
}
const = function(x){
ans = numeric(1)
ans[1] = -(sin(pi*x/5)+.2*cos(4*pi*x/5))
return(ans)
}
#########################################################################################
###
#########################################################################################
x0 = runif(1,0,10)
COB = cobyla(x0,f,hin=const,lower=0,upper=10,nl.info = TRUE,
control = list(xtol_rel = 1e-16, maxeval = 2000))
So I would like to be able to store the output for running cobyla()
for iterations 1,2,...,maxeval
And so what I would think I would need to do is use
trace(f)
or
trace(cobyla)
before executing the code but I am not sure how to store the values of running the trace()
command