Commit 38575a86 authored by patrick.lambert's avatar patrick.lambert
Browse files

run in JAva and R

parent 9fb8cfd2
library(rJava) # see J4R library(rJava) # see J4R
#library(yaml) #library(yaml)
library(tidyverse) library(tidyverse)
library(jdx)
rm(list = ls()) rm(list = ls())
...@@ -26,18 +27,18 @@ setwd("../..") ...@@ -26,18 +27,18 @@ setwd("../..")
# path to outputs # path to outputs
#outputDir = "simus/" #outputDir = "simus/"
outputFileName = paste0("SA/",seed) #outputFileName = paste0("SA/",seed)
jarfile = "target/GR3D-3.2-SNAPSHOT.jar" jarfile = "target/GR3D-3.2-SNAPSHOT.jar"
simDuration = 48 simDuration = 150
simBegin = 1 simBegin = 1
timeStepDuration = 1 timeStepDuration = 1
seed = 1 seed = 1
arguments = c('-simDuration',simDuration, '-simBegin',simBegin, arguments = c('-q','-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",
...@@ -46,6 +47,7 @@ arguments = c('-simDuration',simDuration, '-simBegin',simBegin, ...@@ -46,6 +47,7 @@ arguments = c('-simDuration',simDuration, '-simBegin',simBegin,
# initializes the Java Virtual Machine ------------------------------------- # initializes the Java Virtual Machine -------------------------------------
.jinit(classpath ="", force.init = TRUE)
.jinit(classpath = jarfile, force.init = TRUE) .jinit(classpath = jarfile, force.init = TRUE)
# modification of xlm parameters ----------------------- # modification of xlm parameters -----------------------
...@@ -53,9 +55,9 @@ parametersNames = c("processes.processesEachStep.10.tempMinRep", ...@@ -53,9 +55,9 @@ parametersNames = c("processes.processesEachStep.10.tempMinRep",
"processes.processesEachStep.10.ratioS95_S50", "processes.processesEachStep.10.ratioS95_S50",
"processes.processesEachStep.6.pHomingAfterEquil") "processes.processesEachStep.6.pHomingAfterEquil")
thetas = c(10, 2, 0.7) thetas = c(10, 2, 0.7)
# run the GR3D with update xlm parameters -------------------------------------------- # run the GR3D with updated parameter values in processes --------------------------------------------
.jclassPath()
.jcall("analysis.EasyRun","V","runSimulation", arguments, outputFileName, .jarray(parametersNames), .jarray(thetas)) .jcall("analysis.EasyRun", "V", "runSimulation", arguments, .jarray(parametersNames), .jarray(thetas))
# call GR3D method to get model outputs ---------------------------------------------- # call GR3D method to get model outputs ----------------------------------------------
...@@ -70,17 +72,17 @@ thetas = c(10, 2, 0.7) ...@@ -70,17 +72,17 @@ thetas = c(10, 2, 0.7)
# range[1] = latitude of the median distribution ( 50 % of effectives are northern) # range[1] = latitude of the median distribution ( 50 % of effectives are northern)
# range[2] = southern limit latitude of the fish distribution # range[2] = southern limit latitude of the fish distribution
#range = .jcall("miscellaneous.EasyRun","[D","getValuesFromAquaNismsGroup","getRangeDistribution") out = .jcall("analysis.EasyRun","[[Ljava/lang/String;","getValuesFromAquanismGroupProcess","processes.processesEachStep.9.exportToR")
.jcall("analysis.EasyRun", "D", "getSingleValueFromAquanismGroupProcess", "processes.processesAtEnd.0.getLogLikelihood"); range <- data.frame(matrix(convertToR(out[[2]]), nrow = 1, dimnames = list(NULL, convertToR(out[[1]])))) %>% type_convert()
# ------------------------------------------------------------ # # ------------------------------------------------------------ #
# 2. log-likelihood ---- # 2. log-likelihood ----
# the proportion of reproductions leading to a recruitment > 50 over the 1920-1950 period was used # 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. # as a proxy of predicted probability of presence in a basin.
# Then a log-likelihood of a binomial distribution is computed # Then a log-likelihood of a binomial distribution is computed
# access through computeLikelihood in DiadromousFishGroup .jcall("analysis.EasyRun", "D", "getSingleValueFromAquanismGroupProcess", "processes.processesAtEnd.0.getLogLikelihood");
# see getProbOfNonNulRecruitmentDuringLastYears in BasinNetwork
# ------------------------------------------------------------ # # ------------------------------------------------------------ #
# 3. proportion of first-time spawners # 3. proportion of first-time spawners
# annual % of first-time spawners according to latitude (or basin_id) # annual % of first-time spawners according to latitude (or basin_id)
...@@ -88,16 +90,21 @@ thetas = c(10, 2, 0.7) ...@@ -88,16 +90,21 @@ thetas = c(10, 2, 0.7)
# then in R: annual slope of the linear regression # then in R: annual slope of the linear regression
# and average over the period # 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 ---- # 4. Mean age of the spawner for male and female ----
# annual mean age in each basin, # annual mean age in each basin,
# then in R: average per year, # then in R: average per year,
# and average over the period (1920 and 1950) # and average over the period (1920 and 1950)
# mean (+sd) and slope after
out = .jcall("analysis.EasyRun","[[Ljava/lang/String;","getValuesFromAquanismGroupProcess","processes.processesEachStep.8.exportToR")
out2 = matrix(unlist(lapply(out, convertToR)), nrow = length(out) , byrow = TRUE)
out3 <- out2[-1,]
colnames(out3) <- unlist(out2[1,])
as.data.frame(out3) %>% type_convert()
# ------------------------------------------------------------ #
# ------------------------------------------------------------ # # ------------------------------------------------------------ #
# 5. number of metapopulation based on the exchange matrix ---- # 5. number of metapopulation based on the exchange matrix ----
...@@ -107,12 +114,16 @@ thetas = c(10, 2, 0.7) ...@@ -107,12 +114,16 @@ thetas = c(10, 2, 0.7)
# moyenne sur les bassins versants des moyennes sur la peride des moyennes des flux # moyenne sur les bassins versants des moyennes sur la peride des moyennes des flux
# access through species.IdentifyPopulation in processesAtEnd # access through species.IdentifyPopulation in processesAtEnd
#TODO A FAIRE !!!
# =================================================================================
toto <- .jcall("analysis.EasyRun","Ljava/util/List;", toto <- .jcall("analysis.EasyRun","Ljava/util/List;",
"getAListFromAquanismGroupProcess","processes.processesAtEnd.1.getRecords") "getAListFromAquanismGroupProcess","processes.processesAtEnd.1.getRecords")
as.list(toto) as.list(toto)
.jcall("miscellaneous.EasyRun","[D","getValuesFromEnvironment","getMeanLastPercOfAut")
# truc = .jcall("analysis.EasyRun","Ljava/util/List;", # truc = .jcall("analysis.EasyRun","Ljava/util/List;",
# "getAListFromAquanismGroupProcess","processes.processesAtEnd.1.getRecords") # "getAListFromAquanismGroupProcess","processes.processesAtEnd.1.getRecords")
......
...@@ -26,8 +26,7 @@ public class EasyRun { ...@@ -26,8 +26,7 @@ public class EasyRun {
static Pilot pilot; static Pilot pilot;
public static void runSimulation(String[] batchArgs, String outputfilename, String[] paramNames, double[] paramValues) public static void runSimulation(String[] batchArgs, String[] paramNames, double[] paramValues) throws Exception {
throws Exception {
try { try {
pilot = new Pilot(); pilot = new Pilot();
...@@ -96,7 +95,7 @@ public class EasyRun { ...@@ -96,7 +95,7 @@ public class EasyRun {
double[] parameterValues = new double[] { 10, 2, 0.7 }; double[] parameterValues = new double[] { 10, 2, 0.7 };
runSimulation(batchArguments, "tsointsoin", parameterNames, parameterValues); runSimulation(batchArguments, parameterNames, parameterValues);
System.out.println("\n== AnalyseSpawnerFeatures =="); System.out.println("\n== AnalyseSpawnerFeatures ==");
String[][] spawnerRunResults = getValuesFromAquanismGroupProcess("processes.processesEachStep.8.exportToR"); String[][] spawnerRunResults = getValuesFromAquanismGroupProcess("processes.processesEachStep.8.exportToR");
......
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