Commit 26c10a34 authored by patrick.lambert's avatar patrick.lambert
Browse files

new version to run Java from R

parent 7fd22080
library(rJava) library(rJava) # see J4R
#library(yaml) #library(yaml)
library(dplyr) library(tidyverse)
rm(list=ls()) rm(list = ls())
# # parameters and prios=rs of parameters to be fitted # # parameters and prios=rs of parameters to be fitted
# inputData = yaml.load_file("ABC_seq_2param_3stats_NewAfterSA.yaml") # inputData = yaml.load_file("ABC_seq_2param_3stats_NewAfterSA.yaml")
...@@ -20,36 +20,101 @@ rm(list=ls()) ...@@ -20,36 +20,101 @@ rm(list=ls())
# parametersNames = unlist(parametersNames) # parametersNames = unlist(parametersNames)
## to have the same working diretory as GR3D # GR3D arguments -----------------------------------------
## to have the same working directory as GR3D
setwd("../..") setwd("../..")
# path to outputs # path to outputs
outputDir = "simus/" #outputDir = "simus/"
outputFileName = paste0("SA/",seed)
jarfile = "target/GR3D-3.2-SNAPSHOT.jar" jarfile = "target/GR3D-3.2-SNAPSHOT.jar"
simDuration = 48 simDuration = 48
simBegin = 1 simBegin = 1
timeStepDuration =1 timeStepDuration = 1
seed = 1 seed = 1
parametersNames = c("processes.processesEachStep.8.tempMinRep", arguments = c('-simDuration',simDuration, '-simBegin',simBegin,
"processes.processesEachStep.8.ratioS95_S50",
"processes.processesEachStep.6.pHomingAfterEquil")
thetas = c(10, 2, 0.7)
arguments = c('','-simDuration',simDuration, '-simBegin',simBegin,
'-timeStepDuration',timeStepDuration, '-timeStepDuration',timeStepDuration,
'-RNGStatusIndex', format(seed,scientific = FALSE), '-RNGStatusIndex', format(seed,scientific = FALSE),
'-groups',"data/input/northeastamerica/fishRIOBasin_Sapidissima_Rjava.xml", '-groups',"data/input/northeastamerica/fishRIOBasin_Sapidissima_Rjava.xml",
'-env',"data/input/northeastamerica/RIOBNneaBasins_Rjava.xml", '-env',"data/input/northeastamerica/RIOBNneaBasins_Rjava.xml",
'-observers',"data/input/northeastamerica/RIO_obs_empty.xml") '-observers',"data/input/northeastamerica/RIO_obs_empty.xml")
outputFile = paste0("SA/",seed)
# initializes the Java Virtual Machine -------------------------------------
.jinit(classpath = jarfile, force.init = TRUE) .jinit(classpath = jarfile, force.init = TRUE)
.jcall("miscellaneous.EasyRun","V","runSimulation",arguments, outputFile,.jarray(parametersNames),.jarray(thetas))
.jcall("miscellaneous.EasyRun","[D","getValuesFromEnvironement","getMeanLastPercOfAut") # modification of xlm parameters -----------------------
.jcall("miscellaneous.EasyRun","[D","getValuesFromAquanismGroup","getRangeDistribution") parametersNames = c("processes.processesEachStep.10.tempMinRep",
# truc = .jcall("miscellaneous.EasyRun","Ljava/util/List;", "processes.processesEachStep.10.ratioS95_S50",
"processes.processesEachStep.6.pHomingAfterEquil")
thetas = c(10, 2, 0.7)
# run the GR3D with update xlm parameters --------------------------------------------
.jcall("analysis.EasyRun","V","runSimulation", arguments, outputFileName, .jarray(parametersNames), .jarray(thetas))
# call GR3D method to get model outputs ----------------------------------------------
#TODO export [char] and then data.frame(toto) %>% type_convert()
# ----------------------------------------------------------------------------------#
# 1. northern limit and distribution centroid ----
# only basins with more than 50 recruits in average in the last 10 years (colonised basins)
# compute only in SPRING
# access through getRangeDistribution in DiadromousFishGroup ==== NOT CORRECT
# range[1] = latitude of the median distribution ( 50 % of effectives are northern)
# range[2] = southern limit latitude of the fish distribution
#range = .jcall("miscellaneous.EasyRun","[D","getValuesFromAquaNismsGroup","getRangeDistribution")
.jcall("analysis.EasyRun", "D", "getSingleValueFromAquanismGroupProcess", "processes.processesAtEnd.0.getLogLikelihood");
# ------------------------------------------------------------ #
# 2. log-likelihood ----
# the proportion of reproductions leading to a recruitment > 50 over the 1920-1950 period was used
# as a proxy of predicted probability of presecen in a basin.
# Then a log-likelihood of a binomial distribution is computed
# access through computeLikelihood in DiadromousFishGroup
# see getProbOfNonNulRecruitmentDuringLastYears in BasinNetwork
# ------------------------------------------------------------ #
# 3. proportion of first-time spawners
# annual % of first-time spawners according to latitude (or basin_id)
# between 1920-1950
# then in R: annual slope of the linear regression
# and average over the period
# mean (+sd) and slpe after
# access through AnalyseSpawnerRun in [processesAtEnd]
# ------------------------------------------------------------ #
# 4. Mean age of the spawner for male and female ----
# annual mean age in each basin,
# then in R: average per year,
# and average over the period (1920 and 1950)
# ------------------------------------------------------------ #
# 5. number of metapopulation based on the exchange matrix ----
# annual exchange matrix between 1920 and 1950
# then in R: compute average matrix over the period,
# run metapopulationIdentification
# moyenne sur les bassins versants des moyennes sur la peride des moyennes des flux
# access through species.IdentifyPopulation in processesAtEnd
toto <- .jcall("analysis.EasyRun","Ljava/util/List;",
"getAListFromAquanismGroupProcess","processes.processesAtEnd.1.getRecords")
as.list(toto)
.jcall("miscellaneous.EasyRun","[D","getValuesFromEnvironment","getMeanLastPercOfAut")
# truc = .jcall("analysis.EasyRun","Ljava/util/List;",
# "getAListFromAquanismGroupProcess","processes.processesAtEnd.1.getRecords") # "getAListFromAquanismGroupProcess","processes.processesAtEnd.1.getRecords")
# #
# trucMieux = .jcast(truc, "ljava/util/ArrayList", convert.array = FALSE) # trucMieux = .jcast(truc, "ljava/util/ArrayList", convert.array = FALSE)
......
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