[R-sig-eco] passing temperature or iteration step from optim to function (SANN)

Carsten Dormann carsten.dormann at ufz.de
Fri Feb 27 09:01:59 CET 2009


Dear colleagues,

I am trying to use simulated annealing (SANN in function optim) to solve 
a combinatorial problem. To do so, I have written a function that 
produces a new set of parameters (the gradient function). As temperature 
cools during SANN, I would like to change the step size, as is the 
general idea of SANN. To do so, however, I need to somehow feed the 
current temperature (or the number of iterations performed) into the 
gradient function. The simple question is: HOW?

I much appreciate your help with this! (Or in fact better ideas to find 
combinatorial optima on very rugged optimisation surfaces.)

Cheers,

Carsten


Detailed background:
I want to group the interactions of pollinators and plants into 
so-called modules. I start with an interaction matrix, where columns are 
pollinators and rows are plants (see any of the data sets in the 
bipartite package). Entries in the matrix are 0 for no observed visit or 
an integer for the number of observed visits of pollinators to plants. 
The idea now is to find functional networks. Guimera & Amaral proposed 
(in Nature 1998) a modularity index to do so, and Jens Olesen has 
applied this to pollination networks. I want to replicate this research 
in R.

I thus have to optimise a vector of length (number of pollinators + 
number of plants), which is an index to which module a species belongs 
(e.g. 1,2,1,1,2, ..). The gradient function now generates a new 
sequence, by randomly changing one of the vector's entries. However, 
since I have information on the number of visits, I want to start (at 
high temperature) by preferentially moving the commonly interacting 
species between modules. As time goes by (and temperature cools), I want 
to restrict the random changes to the less commonly observed species.

Pseudo-functions:
M <- function(module.vector, web) # returns the modularity value of a 
given index and web: this is my "fn" for optim
generator <- function(module.vector, web, temperature) # gr: generates a 
new index vector; uses "temperature" to constrain which columns/rows to 
re-assign.
optim(par=init.vec, fn=M, gr=generator, method="SANN")
This works principally fine, except that I cannot pass the current 
temperature from optim to generator! How do I do this?


-- 
Dr. Carsten F. Dormann
Department of Computational Landscape Ecology
Helmholtz Centre for Environmental Research UFZ 
Permoserstr. 15
04318 Leipzig
Germany

Tel: ++49(0)341 2351946
Fax: ++49(0)341 2351939
Email: carsten.dormann at ufz.de
internet: http://www.ufz.de/index.php?de=4205



More information about the R-sig-ecology mailing list