Closed EgilFischer closed 7 years ago
Trying some pragmatic solutions I found out that if I
1) use << param_range <- nl_get_param_range(experiment, diff_only = FALSE) >> that it will run, but now it is changing all parameters also the once that need to be constants. This works with Nelder-Mead but not with L-BFGS-B because it will cause an error because of a non-finite number.
2) if I remove the constants from the declaration of <
Still these are not satisfactory solutions.
Thank you for reporting the problem. It is possible that nlexperiment mixed up some variable mapping. But, I don't think I can easily reproduce the error without the NetLogo model. Can you share it somewhere or just use my email darko.bergant@gmail.com.
Hi, I would like to use nlexperiment to fit a Netlogo model to data. I am able to run the model, do a sensitivity analysis etc. but as soon as I tried to use optim or nmkb I run into troubles with my own model. The example at the website does work. When I am trying to fit my own code (I was testing so it is a fairly simple Netlogo-model for an infection going through a population) to some fake data, I run into troubles as I get the following error message for which I do not know what to do:
[1] "Java-Object{Nothing named EXPERIMENT$PARAM_SETS has been defined. at position 37 in }" Error in RNetLogo::NLCommand(sprintf("set %s %s", nl_param, param_value)) :
Thanks,
Egil Fischer
My R-code looks as follows: `fit.data '# time inf cur '# 1 0 0.010000000 0.00000000 '# 2 2 0.038478868 0.01276641 '# 3 5 0.199355083 0.10651282 '# 4 7 0.327192178 0.26911589 '# 5 10 0.285740281 0.56237504 '# 6 12 0.198824897 0.70756273 '# 7 15 0.100935272 0.83857641 '# 8 17 0.061902226 0.88654818 '# 9 20 0.029060006 0.92569697 '# 10 30 0.002204088 0.95704138
nl_netlogo_path("C:/Program Files/NetLogo 6.0/app") NLStart(nl.path = "C:/Program Files/NetLogo 6.0/app", nl.jarname = "netlogo-6.0.0.jar", gui = F)
experiment <- nl_experiment( model_file = "D:/SURFdrive/Rekenclusters/TestModel/epiDEM.nlogo",
setup_commands = c("setup", "repeat 1 [go]" ),
iterations = 30,
param_values = list( initial_people = 100, infection_chance = seq(from = 0, to = 30, by = 10), average_recovery_time = seq(from = 100, to = 400, by = 100) ),
step_measures = measures( infected = "count turtles with [infected?]", cured = "count turtles with [cured?]" ),
eval_criteria = criteria( c_infected = sum((step$infected[step$step_id == round(times/10)] - (fit.data$inf100))^2), c_cured = sum((step$cured[step$step_id == round(times/10)] - (fit.data$cur100))^2) ),
eval_aggregate_fun = sum, # aggregate over repetitions
eval_mutate = criteria( # evaluation criterium eval_value = sqrt(c_infected + c_cured) ) )
result <- nl_run(experiment, print_progress = T, parallel = F,gui = F) '#works fine
cl <- nl_eval_init(experiment, parallel = FALSE) trace <- nl_eval_tracer(verbose = FALSE) param_range <- nl_get_param_range(experiment)
set.seed(1)
'# the following command produces the error. o_result <- optim( par = (param_range$upper + param_range$lower)/2, nl_eval_run, experiment = experiment, criteria = "eval_value", call_back = trace$add, parallel = FALSE, cluster = cl, method = "L-BFGS-B", lower = param_range$lower, upper = param_range$upper, control = list(maxit = 200, trace = 1))
tr <- trace$get() nl_eval_close(cl) ` Some additional info: Netlogo = version 6.0.0 OS = Windows 7
R.version _
platform x86_64-w64-mingw32
arch x86_64
os mingw32
system x86_64, mingw32
status
major 3
minor 4.0
year 2017
month 04
day 21
svn rev 72570
language R
version.string R version 3.4.0 (2017-04-21) nickname You Stupid Darkness