简体   繁体   English

运行具有确定性参数变化的 nlrx 仿真

[英]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), ie vary density from 0 to 100 with stepsize 1, each 10 times:我想使用具有不同密度值的 nlrx 包运行简单的 netlogo 火灾模型......但我不想随机地而是确定性地(系统地)进行它,即以步长 1 将密度从 0 变化到 100,每个 10次:

10 times with density 0密度为 0 时 10 次
10 times with density 1 10 次,密度 1
10 times with density 2 10 倍,密度 2
... ...
10 times with density 99 10倍密度99
10 times with density 100 10 倍,密度 100

How would I do that?我该怎么做?

Thank you!谢谢!

For these kind of simulations you can either use the simdesign_distinct() or the simdesign_ff() .对于此类模拟,您可以使用simdesign_distinct()simdesign_ff() with simdesign_distinct() you can specify distinct values which are simulated (see example below).使用simdesign_distinct()您可以指定模拟的不同值(参见下面的示例)。 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. simdesign_ff()创建了一个完整的因子设计,只有当您有多个变量时才真正相关。 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.对于一个变量,其功能与simdesign_distinct()非常相似,但不同之处在于您可以定义 min、max 和 step 以自动为每个变量创建值向量。 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):下面是两个例子(我必须在度量槽中使用 ifelse-value(...) 来防止被零除的错误,这是由密度值为 0 的 NetLogo 产生的):

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM