tutorials:sensitivity-analysis-using-grolink-and-gror
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| tutorials:sensitivity-analysis-using-grolink-and-gror [2024/06/25 15:32] – [Model execution and output gathering in R] thomas | tutorials:sensitivity-analysis-using-grolink-and-gror [2025/09/24 16:31] (current) – t | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Sensitivity analysis on GroIMP models using GroR ====== | ====== Sensitivity analysis on GroIMP models using GroR ====== | ||
| - | This wiki explains how to do a sensitivity analysis on GroIMP models using the GroR interface using a Morris screening over input parameters of the [[http://134.76.18.36/ | + | This wiki explains how to do a sensitivity analysis on GroIMP models using the GroR interface using a Morris screening over input parameters of the [[https://gallery.grogra.de/project_gallery/67053a3f256715cda41c867f |
| ===== Prerequisites ===== | ===== Prerequisites ===== | ||
| Make sure to [[: | Make sure to [[: | ||
| + | |||
| + | ==== Downloads ==== | ||
| + | * {{ : | ||
| + | * {{ : | ||
| ===== Prepare your model===== | ===== Prepare your model===== | ||
| Line 47: | Line 51: | ||
| {{: | {{: | ||
| - | The folder and file can be created via <key>Object</ | + | The folder and file can be created via **Object** -> **New** in the File explorer. |
| The file only contains the parameter definitions (the values are what they were in the original gallery model): | The file only contains the parameter definitions (the values are what they were in the original gallery model): | ||
| Line 94: | Line 98: | ||
| library(sensitivity) | library(sensitivity) | ||
| - | wb1 <- GroLink.open(" | + | # copy groimp model gsz to groimp path to open it like this: |
| + | wb1 <- GroLink.open(" | ||
| + | # push model gsz to groimp | ||
| + | wb1 <- GroLink.open(" | ||
| </ | </ | ||
| Line 119: | Line 126: | ||
| </ | </ | ||
| + | When you run the while loop, in the end, the '' | ||
| Line 126: | Line 133: | ||
| ===== Example: Morris Screening using the sensitivity package ===== | ===== Example: Morris Screening using the sensitivity package ===== | ||
| + | The Morris Screening will be used to analyze the 5 structural plant growth parameters with regard to their importance (their main and interaction effect) on the total amount of absorbed light by leaves. This is just a random example out of the plethora of available sensitivity analysis methods. Most of the common ones are implemented in the '' | ||
| + | |||
| + | First, I generate a set of input parameters for the model: | ||
| + | |||
| + | <code R> | ||
| + | m <- morris(model = NULL, factors = c(" | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | r = 20, # 20 repetitions | ||
| + | binf = c(0.05, 0.01, 0.05, 0.1, 0.1), # min value of inputs | ||
| + | bsup = c(0.8, 0.1, 1, 1, 1), # max value of inputs | ||
| + | | ||
| + | # grid.jump is recommended to be levels/2, see ?morris | ||
| + | |||
| + | |||
| + | params <- m$X | ||
| + | </ | ||
| + | |||
| + | '' | ||
| + | |||
| + | <code R> | ||
| + | executeModel <- function(params, | ||
| + | | ||
| + | ){ | ||
| + | # Open workbench with model | ||
| + | wb1 <- GroLink.open(" | ||
| + | # Override parameters.rgg with new values from params vector | ||
| + | WBRef.updateFile(wb1, | ||
| + | | ||
| + | "; | ||
| + | "; | ||
| + | "; | ||
| + | "; | ||
| + | ";", | ||
| + | sep = "" | ||
| + | # Compile the workbench | ||
| + | WBRef.compile(wb1) | ||
| + | |||
| + | model_output <- "" | ||
| + | n_grows <- 0 | ||
| + | # Execute the grow function for as long as there are no flowers | ||
| + | while (!(is.numeric(model_output)) && (n_grows < timeout)) { | ||
| + | result <- WBRef.runRGGFunction(wb1," | ||
| + | model_output <- unlist(result$console) | ||
| + | if (model_output != "no flower" | ||
| + | model_output <- as.numeric(model_output) | ||
| + | } | ||
| + | n_grows <- n_grows + 1 | ||
| + | } | ||
| + | # Retrun NA in case of timeout | ||
| + | if (n_grows == timeout) { | ||
| + | model_output <- NA | ||
| + | } | ||
| + | # Close workbench in the end | ||
| + | WBRef.close(wb1) | ||
| + | return(model_output) | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | This function contains the while-loop from above but also modifies (overrides) the '' | ||
| + | |||
| + | <code R> | ||
| + | plan(multisession, | ||
| + | |||
| + | system.time(model_outputs <- future_apply(params, | ||
| + | |||
| + | saveRDS(model_outputs, | ||
| + | </ | ||
| + | |||
| + | Through the use of '' | ||
| + | |||
| + | The only thing remaining is to analyze the output and plot the results: | ||
| + | |||
| + | <code R> | ||
| + | sensitivity:: | ||
| + | |||
| + | plot(m) | ||
| + | </ | ||
| + | |||
| + | This should now look something like this: | ||
| + | |||
| + | {{: | ||
| + | |||
| + | |||
| + | ===== Dump of R code to grab datasets via API ===== | ||
| + | <code R> | ||
| + | wb <- GroLink.open(" | ||
| + | | ||
| + | |||
| + | GroR:: | ||
| + | |||
| + | WBRef.runRGGFunction(wb, | ||
| + | WBRef.runRGGFunction(wb, | ||
| + | WBRef.runRGGFunction(wb, | ||
| + | |||
| + | string <- WBRef.getDataset(wb," | ||
| + | |||
| + | out <- read.csv(textConnection(WBRef.getDataset(wb," | ||
| + | |||
| + | WBRef.close(wb) | ||
| + | |||
| + | plot(m) | ||
| + | </ | ||
| + | |||
| + | |||
tutorials/sensitivity-analysis-using-grolink-and-gror.1719322379.txt.gz · Last modified: 2024/06/25 15:32 by thomas
