Commit 4c560443 authored by patrick.lambert's avatar patrick.lambert
Browse files

to run the sensitivity analysis

parent 4bac0727
library(tidyverse)
library(XML)
require(XML)
#source("../GR3D_Rdescription/GR3D_NEA_XML_parameters.R")
setwd("~/Documents/workspace/GR3D/exploration/NEA_sensitivity_analysis")
......@@ -19,4 +19,11 @@ no_processesAtEnd = tibble( process = names(fishXML[["species.DiadromousFishGrou
filter(process != "comment") %>%
mutate(no_java = row_number()-1) %>%
select(no_R, no_java, process)
\ No newline at end of file
fishXML[["species.DiadromousFishGroup"]][["processes"]][["processesEachStep"]][["species.DisperseAndMigrateToRiverWithMultiNomDistriAndDeathBasin"]]
fishXML[["species.DiadromousFishGroup"]][["processes"]][["processesEachStep"]][["species.SurviveAfterReproduction"]]
species.SurviveAfterReproduction
\ No newline at end of file
require(tidyverse)
# list of As factors with levels
listFactorWithModalities = list()
listFactorWithModalities[["Allee"]] =
list("sizeProportional" = list('processANG' = data.frame(process = 'species.ReproduceWithDiagnose',
par = 'Soffset',
value = -1)),
"constant" = list('processANG' = data.frame(process = 'species.ReproduceWithDiagnose',
par = 'Soffset',
value = 1000) ),
"noEffect" = list('processANG' = data.frame(process = 'species.ReproduceWithDiagnose',
par = 'Soffset',
value = 0) ))
listFactorWithModalities[["homing"]] =
list("high" = list('processANG' = data.frame(process = 'species.DisperseAndMigrateToRiverWithMultiNomDistriAndDeathBasin',
par = 'pHomingAfterEquil',
value = .95)),
"low" = list('processANG' = data.frame(process = 'species.DisperseAndMigrateToRiverWithMultiNomDistriAndDeathBasin',
par = 'pHomingAfterEquil',
value = 0.75)))
listFactorWithModalities[["strayingDistance"]] =
list("high" = list('processANG' = data.frame(process = rep('species.DisperseAndMigrateToRiverWithMultiNomDistriAndDeathBasin',2),
par = c('alpha1Rep', 'meanInterDistance'),
value = c(35.8, 1460.38))),
"medium" = list('processANG' = data.frame(process = rep('species.DisperseAndMigrateToRiverWithMultiNomDistriAndDeathBasin',2),
par = c('alpha1Rep', 'meanInterDistance'),
value = c(12, 750))),
"low" = list('processANG' = data.frame(process = rep('species.DisperseAndMigrateToRiverWithMultiNomDistriAndDeathBasin',2),
par = c('alpha1Rep', 'meanInterDistance'),
value = c(6, 380))))
listFactorWithModalities[["survivalAfterReproduction"]] =
list("constant" = list('processANG' = data.frame(process = rep('species.SurviveAfterReproduction',2),
par = c('maximalSurvivalRate', 'temperatureEffectSurvivalAfterReproduction.alpha'),
value = c(0.1*2, 0))),
"temperatureDependant" = list('processANG' = data.frame(process = rep('species.SurviveAfterReproduction',2),
par = c('maximalSurvivalRate', 'temperatureEffectSurvivalAfterReproduction.alpha'),
value = c(0.18, -0.58))))
# ---------------------------------------- sampling design ----
#selectedListFactorWithModalities = listFactorWithModalities[c('Allee', 'homing')]
selectedListFactorWithModalities = listFactorWithModalities
factorModalities = tibble(names(selectedListFactorWithModalities[[1]]))
names(factorModalities) <- names(selectedListFactorWithModalities[1])
for (i in 2:length(selectedListFactorWithModalities)) {
factor = tibble(names(selectedListFactorWithModalities[[i]]))
names(factor) <- names(selectedListFactorWithModalities[i])
factorModalities <- factorModalities %>% expand_grid(factor)
}
factorModalities <- factorModalities %>% expand_grid(replicate = 1)
# ------------------------------------- simulation list ----
simulationList = list()
for (simul in 1:nrow(factorModalities)) {
# simulation names
nameSimul = tibble(name = paste(names(factorModalities), factorModalities[i,], sep = ':')) %>%
summarise(name = paste(name, collapse = '_')) %>% unlist(use.names = FALSE)
#cat(nameSimul, '\n')
# parameters to be modified in class Environment
parametersValueENV= c(par = 'simulationName', value = paste0('simul_', simul))
# parameters to be modified in class AquaNismGroup
parametersValueANG = c()
for (factor in names(factorModalities %>% select(-replicate))) {
modality = factorModalities[i, factor] %>% unlist(use.names = FALSE)
#cat('\t',factor , ':', modality, '\n')
parametersValueANG = parametersValueANG %>%
bind_rows(listFactorWithModalities[[factor]][[modality]]$processANG %>%
inner_join(no_processesEachStep %>% select(process, no_java), by =c('process')) %>%
mutate(target = paste("processes.processesEachStep", no_java, par, sep ='.')) %>%
select(target, value, process))
}
simulationList[[simul]] = list(name = paste0('simul_', simul),
longName = nameSimul,
replicate = factorModalities[simul,'replicate'],
parametersValueANG = parametersValueANG,
parametersValueENV = parametersValueENV)
}
simulationList
......@@ -4,15 +4,35 @@ library(rJava) # see J4R
library(tidyverse)
library(jdx)
library(tictoc)
library(XML)
rm(list = ls())
## to have the same working directory as GR3D
#setwd("~/Documents/workspace/GR3D/exploration/NEA_sensitivity_analysis")
setwd("~/Documents/workspace/GR3D/exploration/NEA_sensitivity_analysis")
setwd("../..")
# ========================================================
# load the function to calculate the metapopulations
source("exploration/GR3D_Rdescription/GR3Dmetapopulation.R")
# load the xml
fishXML <- xmlToList(xmlParse("data/input/northeastamerica/fishRIOBasin_Sapidissima_Rjava.xml"))
no_processesEachStep = tibble( process = names(fishXML[["species.DiadromousFishGroup"]][["processes"]][["processesEachStep"]][])) %>%
mutate(no_R = row_number()) %>%
filter(process != "comment") %>%
mutate(no_java = row_number()-1) %>%
select(no_R, no_java, process)
no_processesAtEnd = tibble( process = names(fishXML[["species.DiadromousFishGroup"]][["processes"]][["processesAtEnd"]][])) %>%
mutate(no_R = row_number()) %>%
filter(process != "comment") %>%
mutate(no_java = row_number()-1) %>%
select(no_R, no_java, process)
# ====================================== LOCAL FUNCTIONS =====================================
convertFromSALtoR = function(java_out){
require(jdx)
......@@ -137,7 +157,7 @@ jarfile = "target/GR3D-3.2-SNAPSHOT.jar"
# call GR3D method to get model outputs ----------------------------------------------
#==================== run simulation 1 =====
runSimulation = function(simulationParameter) {
arguments = c('-simDuration', 600, '-simBegin',2,
'-timeStepDuration', 1,
......@@ -158,8 +178,6 @@ runSimulation = function(simulationParameter) {
return(result)
}
#============================
listeSimulation <- list(list(replicat = 1,
parametersNamesANG = c("processes.processesEachStep.11.Soffset",
"processes.processesEachStep.6.pHomingAfterEquil"),
......@@ -188,8 +206,38 @@ listeSimulation <- list(list(replicat = 1,
parametersNamesENV = c("simulationName"),
thetasENV = c("noAllee_lowHoming"))
)
tic()
resSimulation = lapply(listeSimulation, runSimulation)
toc()
#==================== run simulation 2 =====
runSimulation2 = function(simulationParameter) {
cat(simulationParameter$name, ' = ', simulationParameter$longName,'\n')
arguments = c('-simDuration', 600, '-simBegin',2,
'-timeStepDuration', 1,
'-RNGStatusIndex', format(simulationParameter$replicat %>% unlist(use.names = FALSE), scientific = FALSE),
'-groups',"data/input/northeastamerica/fishRIOBasin_Sapidissima_Rjava.xml",
'-env',"data/input/northeastamerica/RIOBNneaBasins_Rjava.xml",
'-observers',"data/input/northeastamerica/RIO_obs_empty.xml")
runEasyRun(arguments,
parametersNamesANG = simulationParameter$parametersValueANG[,'target'],
thetasANG = simulationParameter$parametersValueANG[,'value'],
parametersNamesENV = simulationParameter$parametersValueENV['par'],
thetasENV = simulationParameter$parametersValueENV['value'])
tic()
result = exploreEasyRun()
toc()
return(result)
}
getwd()
source(file = 'exploration/NEA_sensitivity_analysis/prepareSensitivityAnalysis.R')
runSimulation2(simulationList[[1]])
resSimulation = lapply(simulationList, runSimulation2)
save(listeSimulation, resSimulation, file = 'simulation.Rdata')
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment