Use experiment function with multiple sets of parameters in a non-factorial way

31 views
Skip to first unread message

claram...@googlemail.com

unread,
Sep 25, 2018, 6:54:51 AM9/25/18
to SpaDES Users
Hi SpaDES Users,
I would like to use the experiment function with the wolfAlps module - But I don't want a fully factorial experiment but rather use a sequence of complete sets of parameters. 
I want them to be provided using an input file or create them inside / shortly before the experiment call (which is best?) using runif, so that they are evenly distributed. Is this possible? In Example 7 of the eperiment documentation 
# Example 7 - doing replicate runs, of a complex, non factorial experiment.
  # Here we do replication, parameter variation, and module variation all together.
  # This creates 20 combinations.
  # The experiment function tries to make fully factorial, but won't
  # if all the levels don't make sense. Here, changing parameter values
  # in the fireSpread module won't affect the simulation when the fireSpread
  # module is not loaded:

  # library(raster)
  # beginCluster(20) # if you have multiple clusters available, use them here to save time
  sims <- experiment(mySim, replicates = 2, params = experimentParams,
                     modules = experimentModules,
                     dirPrefix = c("expt", "simNum"))
  # endCluster() # end the clusters
  attr(sims, "experiment")


it says in the header that Example 7 is non factorial but then in line four it says that experiment function tries to do it fully factorial, so I am a bit confused..

Ideally, what I want is something like this:

experimentParams <- list(fireSpread = list(spreadprob = list (runif(3, min=0.1, max=0.4),
nfires = list (runif(3, min=10, max=20) ) ...

But this would be fully factorial, right? I there a way around it? Thanks in advance!

Eliot McIntire

unread,
Sep 25, 2018, 10:51:49 AM9/25/18
to SpaDES Users
Don't use experiment. That is for factorial. Run through each list of parameters  with lapply and spades

e.g., (below is not quite right... it is close -- but this should get you in the right direction -- basically, make simLists with correct parameter combinations, the lapply through them)

paramLists = lapply(1:3, function(index) {
    out <- list()
    out[["spreadprob"]] = runif(1, 0.1, 0.4),
    out[["nfires"]] = runif(1, 10, 20))
    out
})

bunchOfSimLists <- lapply(paramLists, function(params) {
    simInit(modules = modules, ...., params = param))

lapply(bunchOfSimLists, spades)

THe last line can be mclapply if you have many cores.

claram...@googlemail.com

unread,
Sep 28, 2018, 8:59:39 AM9/28/18
to SpaDES Users
Thanks, that helped a lot. Another question then would be: Does it make sense to use the experiment wrapper inside an lapply to also get repititions? Or rather use
replicate instead of experiment? Eventually, I will need both, which is why I initially thought experiment would be perfect.
Reply all
Reply to author
Forward
0 new messages