Can I include boolean parameters in the variables for a simdesign? An if so, how would that look like? Right now I only have metric variables like that:
variables = list(
'navigation-system-rate' = list(min = 0, max = 1, qfun="qunif"),
"expected-weight" = list(min = 0, max = 1, qfun="qunif")
)
but I want them to take the value "true" or "false" randomly for a certain parameter. Is that possible somehow?
CodePudding user response:
Yes you can define boolean and categorical variable values, but only for certain simdesigns (simple, distinct, full factorial) as explained here: https://docs.ropensci.org/nlrx/articles/furthernotes.html#variables-and-constants-definitions
For example you can use,
variables = list(
"bool1" = list(values = c("true", "false")),
"bool2" = list(values = c("true", "false"))
)
and then for example apply a simdesign_ff()
to run all combinations of your boolean variables.
All other simdesigns expect a numeric range/distribution and will not work with any categorical/boolean values. As a simple workaround you could just apply some transformation to your parameter matrix after it has been generated.
E.g., if you are doing a latin hypercube, you can just define your boolean variable as uniformly distributed variable within the range 0 to 1. Then after applying the simdesign_lhs
, just overwrite the nl@simdesign@siminput
tibble and update the values of your variable by setting all cells with a value < 0.5 to false, and all other values to true.
# Define variable as numeric in range 0 .. 1
nl@experiment <- experiment(
# ...
variables = list("bool1" = list(min = 0, max = 1, qfun="qunif"))
# ...
)
# apply simdesign_lhs to generate parameter matrix
nl@simdesign <- simdesign_lhs(nl=nl,
samples=100,
nseeds=3,
precision=3)
# apply transformation to boolean (netlogo needs booleans as strings)
nl@simdesign@siminput <- nl@simdesign@siminput %>%
dplyr::mutate(bool1 = dplyr::if_else(bool1 < 0.5, "false", "true"))