User Tools

Site Tools


tutorials:sensitivity-analysis-using-grolink-and-gror

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
tutorials:sensitivity-analysis-using-grolink-and-gror [2024/06/25 17:38] thomastutorials:sensitivity-analysis-using-grolink-and-gror [2025/06/06 17:11] (current) – [Example: Morris Screening using the sensitivity package] 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/wordpress/courses-and-tutorials/simplefspm/ | "Example08" FSPM model]] from the gallery as an example.+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 | "Example08" FSPM model]] from the gallery as an example.
 ===== Prerequisites ===== ===== Prerequisites =====
 Make sure to [[:tutorials:getting-started-with-grolink-and-gror|set up GroR]]. Play a bit around with it and get a feel for how it works and what the [[https://gitlab.com/grogra/groimp-utils/rapilibrary#grolink|different functions]] do and what they return. The approach presented in the wiki here is just one way you could approach a sensitivity analysis. You will likely find your own approach for your specific model, but GroR will be the space you work in. Make sure to [[:tutorials:getting-started-with-grolink-and-gror|set up GroR]]. Play a bit around with it and get a feel for how it works and what the [[https://gitlab.com/grogra/groimp-utils/rapilibrary#grolink|different functions]] do and what they return. The approach presented in the wiki here is just one way you could approach a sensitivity analysis. You will likely find your own approach for your specific model, but GroR will be the space you work in.
  
 ==== Downloads ==== ==== Downloads ====
-  * {{ :tutorials:example08_prepared.zip | Prepared ''Example08'' model}} +  * {{ :tutorials:example08_prepared.zip | Prepared Example08 model}} 
-  * {{ :tutorials:example08_analysis.zip | R Script of this wiki and model outputs as ''.rds''}}+  * {{ :tutorials:example08_analysis.zip | R Script of this wiki and model outputs as .rds}}
  
 ===== Prepare your model===== ===== Prepare your model=====
Line 51: Line 51:
 {{:tutorials:params.png?300|parameters.rgg file}} {{:tutorials:params.png?300|parameters.rgg file}}
  
-The folder and file can be created via <key>Object</key> -> <key>New</key> in the File explorer.+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 98: Line 98:
 library(sensitivity) library(sensitivity)
  
-wb1 <- GroLink.open("http://localhost:58081/api", path="Example08.gsz") # copy gsz to groimp path+# copy groimp model gsz to groimp path to open it like this: 
 +wb1 <- GroLink.open("http://localhost:58081/api", path="Example08_prepared.gsz") 
 +push model gsz to groimp from any file location like this: 
 +wb1 <- GroLink.open("http://localhost:58081/api",content = readBin("D:/Example08_prepared.gsz", "raw", 10e6))
  
 </code> </code>
Line 123: Line 126:
 </code> </code>
  
 +When you run the while loop, in the end, the ''model_output'' variable will contain the total amount of absorbed light by all leaves at the growth step when flowers emerged (this will be some float) or 0 in case no flowers emerged.
  
  
Line 130: 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 ''sensitivity'' R-package. This is not a tutorial on ''sensitivity'', but it is very well documented (e.g. in the R help function).+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 ''sensitivity'' R-package. This is not a tutorial on ''sensitivity'', but it is very well documented (e.g. in the R help function). It is worth noting that this example uses the so-called decoupled approach of ''sensitivity'', see ''?tell''. This basically means that the generation of the parameter set, model execution and output analysis will be done as separate steps.
  
 First, I generate a set of input parameters for the model: First, I generate a set of input parameters for the model:
Line 153: Line 156:
  
 <code R> <code R>
-executeModel <- function(params, timeout = 200){ +executeModel <- function(params,       # Vector containing values for all model parameters 
-  wb1 <- GroLink.open("http://localhost:58081/api", path="Example08.gsz")+                         timeout = 200 # max. number of grow function executions 
 +                         ){ 
 +  # Open workbench with model 
 +  wb1 <- GroLink.open("http://localhost:58081/api", content readBin("D:/Example08_prepared.gsz", "raw", 10e6)
 +  # Override parameters.rgg with new values from params vector
   WBRef.updateFile(wb1, "param/parameters.rgg",   WBRef.updateFile(wb1, "param/parameters.rgg",
                    paste("static float NormalInternodeLength = ", as.character(params[1]),                    paste("static float NormalInternodeLength = ", as.character(params[1]),
Line 163: Line 170:
                          ";",                          ";",
                          sep = ""))                          sep = ""))
 +  # Compile the workbench
   WBRef.compile(wb1)   WBRef.compile(wb1)
  
   model_output <- ""   model_output <- ""
   n_grows <- 0   n_grows <- 0
 +  # Execute the grow function for as long as there are no flowers
   while (!(is.numeric(model_output)) && (n_grows < timeout)) {   while (!(is.numeric(model_output)) && (n_grows < timeout)) {
     result <- WBRef.runRGGFunction(wb1,"grow")     result <- WBRef.runRGGFunction(wb1,"grow")
Line 176: Line 184:
     n_grows <- n_grows + 1     n_grows <- n_grows + 1
   }   }
 +  # Retrun NA in case of timeout
   if (n_grows == timeout) {   if (n_grows == timeout) {
     model_output <- NA     model_output <- NA
   }   }
 +  # Close workbench in the end
   WBRef.close(wb1)   WBRef.close(wb1)
   return(model_output)   return(model_output)
Line 194: Line 204:
 </code> </code>
  
-Through the use of ''future_apply'' and the way the ''multisession'' is setup, you will run one instance of GroIMP on every core of your computer. With this ''Example08'' model, this can take some time, on my 20-core machine it took around 2 minutes (and used ~5Gb RAM).+Through the use of ''future_apply'' and the way the ''multisession'' is setup, you will run one instance of GroIMP on every core of your computer. With this ''Example08'' model, this can take some time, on my 20-core machine it took around 2 minutes (and used ~5Gb RAM). This simple parallelization could likely be optimized a lot and will not scale amazingly to e.g. a remote cluster.
  
 The only thing remaining is to analyze the output and plot the results: The only thing remaining is to analyze the output and plot the results:
tutorials/sensitivity-analysis-using-grolink-and-gror.1719329929.txt.gz · Last modified: 2024/06/25 17:38 by thomas