vonjd
vonjd

Reputation: 4380

Run nlrx simulation with deterministic parameter variation

I want to run the simple netlogo fire model with the nlrx package with different values for density... but I don't want to do it stochastically but deterministically (systematically), i.e. vary density from 0 to 100 with stepsize 1, each 10 times:

10 times with density 0
10 times with density 1
10 times with density 2
...
10 times with density 99
10 times with density 100

How would I do that?

Thank you!

Upvotes: 1

Views: 139

Answers (1)

nldoc
nldoc

Reputation: 1199

For these kind of simulations you can either use the simdesign_distinct() or the simdesign_ff(). with simdesign_distinct() you can specify distinct values which are simulated (see example below). If you have more than one variable, each vector of values need to have the same length. The 1st simulation will then use all 1st values of these vectors, the 2nd all 2nd values and so on. The simdesign_ff() creates a full factorial design, which is only really relevant when you have more than one variable. For one variable the functionality is very similar to simdesign_distinct() but with the difference that you can define min, max, and step to create a vector of values automatically for each variable. Below are two examples (I had to use ifelse-value(...) within the metrics slot to prevent a division by zero error that was produced by NetLogo with a density value of 0):

library(nlrx)
# Windows default NetLogo installation path (adjust to your needs!):
netlogopath <- file.path("C:/Program Files/NetLogo 6.1.0")
modelpath <- file.path(netlogopath, "app/models/Sample Models/Earth Science/Fire.nlogo")
outpath <- file.path("C:/out")
nl <- nl(nlversion = "6.1.0",
         nlpath = netlogopath,
         modelpath = modelpath,
         jvmmem = 1024)

## Example 1: simdesign_distinct
nl@experiment <- experiment(expname="fire",
                            outpath=outpath,
                            repetition=1,
                            tickmetrics="true",
                            idsetup="setup",
                            idgo="go",
                            runtime=0, 
                            metrics=c("ifelse-value (initial-trees > 0) [(burned-trees / initial-trees) * 100][0]"),
                            variables = list('density' = list(values=seq(0,100,1))),
                            constants = list())

#### use nseeds = 10 to simulate over 10 different random seeds (replicates)
nl@simdesign <- simdesign_distinct(nl, nseeds = 10)

#### Run simulations
results <- run_nl_all(nl)


## Example 2: Simdesign_ff
nl@experiment <- experiment(expname="fire",
                            outpath=outpath,
                            repetition=1,
                            tickmetrics="true",
                            idsetup="setup",
                            idgo="go",
                            runtime=0, 
                            metrics=c("ifelse-value (initial-trees > 0) [(burned-trees / initial-trees) * 100][0]"),
                            variables = list('density' = list(min=0, max=100, step=1)),
                            constants = list())

#### use nseeds = 10 to simulate over 10 different random seeds (replicates)
nl@simdesign <- simdesign_ff(nl, nseeds = 10)

#### Run simulations
results <- run_nl_all(nl)

Upvotes: 2

Related Questions