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

run in JAva and R

parent 9fb8cfd2
library(rJava) # see J4R
#library(yaml)
library(tidyverse)
library(jdx)
rm(list = ls())
......@@ -26,18 +27,18 @@ setwd("../..")
# path to outputs
#outputDir = "simus/"
outputFileName = paste0("SA/",seed)
#outputFileName = paste0("SA/",seed)
jarfile = "target/GR3D-3.2-SNAPSHOT.jar"
simDuration = 48
simDuration = 150
simBegin = 1
timeStepDuration = 1
seed = 1
arguments = c('-simDuration',simDuration, '-simBegin',simBegin,
'-timeStepDuration',timeStepDuration,
arguments = c('-q','-simDuration', simDuration, '-simBegin',simBegin,
'-timeStepDuration', timeStepDuration,
'-RNGStatusIndex', format(seed,scientific = FALSE),
'-groups',"data/input/northeastamerica/fishRIOBasin_Sapidissima_Rjava.xml",
'-env',"data/input/northeastamerica/RIOBNneaBasins_Rjava.xml",
......@@ -46,6 +47,7 @@ arguments = c('-simDuration',simDuration, '-simBegin',simBegin,
# initializes the Java Virtual Machine -------------------------------------
.jinit(classpath ="", force.init = TRUE)
.jinit(classpath = jarfile, force.init = TRUE)
# modification of xlm parameters -----------------------
......@@ -53,9 +55,9 @@ parametersNames = c("processes.processesEachStep.10.tempMinRep",
"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))
# run the GR3D with updated parameter values in processes --------------------------------------------
.jclassPath()
.jcall("analysis.EasyRun", "V", "runSimulation", arguments, .jarray(parametersNames), .jarray(thetas))
# call GR3D method to get model outputs ----------------------------------------------
......@@ -70,17 +72,17 @@ thetas = c(10, 2, 0.7)
# 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");
out = .jcall("analysis.EasyRun","[[Ljava/lang/String;","getValuesFromAquanismGroupProcess","processes.processesEachStep.9.exportToR")
range <- data.frame(matrix(convertToR(out[[2]]), nrow = 1, dimnames = list(NULL, convertToR(out[[1]])))) %>% type_convert()
# ------------------------------------------------------------ #
# 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.
# as a proxy of predicted probability of presence in a basin.
# Then a log-likelihood of a binomial distribution is computed
# access through computeLikelihood in DiadromousFishGroup
# see getProbOfNonNulRecruitmentDuringLastYears in BasinNetwork
.jcall("analysis.EasyRun", "D", "getSingleValueFromAquanismGroupProcess", "processes.processesAtEnd.0.getLogLikelihood");
# ------------------------------------------------------------ #
# 3. proportion of first-time spawners
# annual % of first-time spawners according to latitude (or basin_id)
......@@ -88,16 +90,21 @@ thetas = c(10, 2, 0.7)
# 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)
# 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 ----
......@@ -107,12 +114,16 @@ thetas = c(10, 2, 0.7)
# moyenne sur les bassins versants des moyennes sur la peride des moyennes des flux
# access through species.IdentifyPopulation in processesAtEnd
#TODO A FAIRE !!!
# =================================================================================
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")
......
......@@ -26,8 +26,7 @@ public class EasyRun {
static Pilot pilot;
public static void runSimulation(String[] batchArgs, String outputfilename, String[] paramNames, double[] paramValues)
throws Exception {
public static void runSimulation(String[] batchArgs, String[] paramNames, double[] paramValues) throws Exception {
try {
pilot = new Pilot();
......@@ -96,7 +95,7 @@ public class EasyRun {
double[] parameterValues = new double[] { 10, 2, 0.7 };
runSimulation(batchArguments, "tsointsoin", parameterNames, parameterValues);
runSimulation(batchArguments, parameterNames, parameterValues);
System.out.println("\n== AnalyseSpawnerFeatures ==");
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