From: Camarda, Carlo Giovanni <Camarda_at_demogr.mpg.de>

Date: Sun 15 May 2005 - 23:12:17 EST

5) I would like to see separately the values of my parameters during each iteration (what, on the screen, are the values of X) 6) Hence I would need to know the way of asking R to save somewhere the values of X during the optimization procedure 7) I have already tried to use "write.table" into the function I want to minimize (in the example with comments), but it gave me more values that I would need

res <- -10 * sin(r)/r

#write.table(x=b, file="B.txt", append=TRUE, sep=",", col.names=FALSE,

R-help@stat.math.ethz.ch mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sun May 15 23:15:49 2005

Date: Sun 15 May 2005 - 23:12:17 EST

Dear R-users,

I am going to try to be as clearer as possible, showing also an example.

1) I have a function (in my real case it's much more complex) 2) I use "optim" to minimize 3) I want to use as method L-BFGS-B for several reasons 4) I know I could use "trace=6" (in "control") in order to see "live"the procedure

5) I would like to see separately the values of my parameters during each iteration (what, on the screen, are the values of X) 6) Hence I would need to know the way of asking R to save somewhere the values of X during the optimization procedure 7) I have already tried to use "write.table" into the function I want to minimize (in the example with comments), but it gave me more values that I would need

Might you know a solution?

**EXAMPLE:
**

###### function

fun <- function(param){

a <- param[1] b <- param[2] r <- sqrt(a^2+b^2)

res <- -10 * sin(r)/r

#write.table(x=b, file="B.txt", append=TRUE, sep=",", col.names=FALSE,

# row.names=FALSE)

return(res)

}

######## optimization procedure

ott <- optim(par=c(-1,1),

fn =fun, method = c("L-BFGS-B"), control=c(trace=6) )

Thanks in advance,

Carlo Giovanni Camarda

Tel: +49 (0)381 2081 172

Fax: +49 (0)381 2081 472

Camarda@demogr.mpg.de

+++++

This mail has been sent through the MPI for Demographic Rese...{{dropped}}

R-help@stat.math.ethz.ch mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sun May 15 23:15:49 2005

*
This archive was generated by hypermail 2.1.8
: Fri 03 Mar 2006 - 03:31:46 EST
*