Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
SimAquaLife
GR3D
Commits
3fb82fe0
Commit
3fb82fe0
authored
Feb 17, 2021
by
patrick.lambert
Browse files
possibility to export several outputs
parent
8285291e
Changes
2
Hide whitespace changes
Inline
Side-by-side
exploration/R_AS_GR3D/tryFromRougier.R
View file @
3fb82fe0
library
(
rJava
)
library
(
yaml
)
#
library(yaml)
library
(
dplyr
)
rm
(
list
=
ls
())
set.seed
(
1
)
# # parameters and prios=rs of parameters to be fitted
# inputData = yaml.load_file("ABC_seq_2param_3stats_NewAfterSA.yaml")
# # load prior
...
...
@@ -21,23 +19,25 @@ set.seed(1)
# }
# parametersNames = unlist(parametersNames)
parametersNames
=
c
(
"processes.processesEachStep.8.tempMinRep"
,
"processes.processesEachStep.8.ratioS95_S50"
,
"processes.processesEachStep.6.pHomingAfterEquil"
)
thetas
=
c
(
10
,
2
,
0.7
)
## to have the same working diretory as GR3D
setwd
(
"../.."
)
# path to outputs
outputDir
=
"simus/"
jarfile
=
"
../../
target/GR3D-3.2-SNAPSHOT.jar"
jarfile
=
"target/GR3D-3.2-SNAPSHOT.jar"
simDuration
=
48
simBegin
=
1
timeStepDuration
=
1
seed
=
1
## to have the same working diretory as GR3D
setwd
(
"../.."
)
parametersNames
=
c
(
"processes.processesEachStep.8.tempMinRep"
,
"processes.processesEachStep.8.ratioS95_S50"
,
"processes.processesEachStep.6.pHomingAfterEquil"
)
thetas
=
c
(
10
,
2
,
0.7
)
arguments
=
c
(
''
,
'-simDuration'
,
simDuration
,
'-simBegin'
,
simBegin
,
'-timeStepDuration'
,
timeStepDuration
,
...
...
@@ -46,54 +46,12 @@ arguments = c('','-simDuration',simDuration, '-simBegin',simBegin,
'-env'
,
"data/input/northeastamerica/RIOBNneaBasins_Rjava.xml"
,
'-observers'
,
"data/input/northeastamerica/RIO_obs_empty.xml"
)
outputFile
=
paste0
(
outputDir
,
"output
"
,
seed
)
outputFile
=
paste0
(
"Avirer
"
,
seed
)
.jinit
(
classpath
=
""
,
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"
)
.jcall
(
"miscellaneous.EasyRun"
,
"[D"
,
"getValuesFromAquanismGroup"
,
"getRangeDistribution"
)
# return a function to run the model with parameters as arguments
salrun
<-
function
(
jarfile
,
simDuration
,
simBegin
,
timeStepDuration
=
1
)
{
assign
(
"inputData"
,
inputData
)
assign
(
"outputDir"
,
outputDir
)
function
(
parameters
)
{
# loading the user's data
parametersNames
=
list
()
for
(
i
in
1
:
length
(
inputData
$
parameters
))
{
parametersNames
=
c
(
parametersNames
,
inputData
$
parameters
[[
i
]]
$
javapath
)
}
# extracting the seed and the model parameters
seed
=
parameters
[
1
]
thetas
=
parameters
[
2
:
length
(
parameters
)]
outputFile
=
paste
(
outputDir
,
"output"
,
seed
,
sep
=
""
)
if
(
!
file.exists
(
paste
(
outputFile
,
".csv"
,
sep
=
""
)))
{
# run
arguments
=
c
(
'-q'
,
'-simDuration'
,
simDuration
,
'-simBegin'
,
simBegin
,
'-timeStepDuration'
,
timeStepDuration
,
'-groups'
,
"data/input/fishTryRealBV_CC.xml"
,
'-env'
,
"data/input/BNtryRealBasins.xml"
,
'-observers'
,
"data/input/obsTryRealABC.xml"
,
'-RNGStatusIndex'
,
format
(
seed
,
scientific
=
FALSE
))
.jinit
(
classpath
=
jarfile
)
#, force.init=TRUE)
.jcall
(
"miscellaneous.EasyABC"
,
"V"
,
"runSimulation"
,
arguments
,
outputFile
,
.jarray
(
unlist
(
parametersNames
)),
.jarray
(
thetas
))
}
# output
likelihood
=
as.double
(
as.matrix
(
read.csv
(
paste
(
outputFile
,
".csv"
,
sep
=
""
),
skip
=
10
,
h
=
F
,
sep
=
";"
))[
1
,
2
])
agestat
=
as.double
(
as.matrix
(
read.csv
(
paste
(
outputFile
,
".csv"
,
sep
=
""
),
skip
=
11
,
h
=
F
,
sep
=
";"
))[
1
,
2
])
maxlat
=
as.double
(
as.matrix
(
read.csv
(
paste
(
outputFile
,
".csv"
,
sep
=
""
),
skip
=
12
,
h
=
F
,
sep
=
";"
))[
1
,
2
])
if
(
maxlat
>
0
)
c
(
likelihood
,
agestat
,
maxlat
)
else
c
(
NA
,
NA
,
NA
)
}
}
model
=
salrun
(
jarfile
=
"GR3D-1.0-SNAPSHOT.jar"
,
simDuration
=
400
,
simBegin
=
2
)
src/main/java/miscellaneous/EasyRun.java
View file @
3fb82fe0
...
...
@@ -16,26 +16,36 @@
*/
package
miscellaneous
;
import
java.util.Arrays
;
import
fr.cemagref.simaqualife.extensions.pilot.BatchRunner
;
import
fr.cemagref.simaqualife.pilot.Pilot
;
public
class
EasyRun
{
static
Pilot
pilot
;
public
static
void
runSimulation
(
String
[]
batchArgs
,
String
outputfilename
,
String
[]
paramNames
,
double
[]
paramValues
)
throws
Exception
{
try
{
Pilot
pilot
=
new
Pilot
();
pilot
=
new
Pilot
();
BatchRunner
runner
=
new
BatchRunner
(
pilot
);
pilot
.
init
();
runner
.
parseArgs
(
batchArgs
,
false
,
true
,
false
);
pilot
.
load
();
// update the simulation parameters
ReflectUtils
.
setFieldValueFromPath
(
pilot
.
getAquaticWorld
().
getAquaNismsGroupsList
().
get
(
0
),
"processes.processesAtEnd.0.fileNameOutput"
,
outputfilename
);
for
(
int
i
=
0
;
i
<
paramNames
.
length
;
i
++)
{
ReflectUtils
.
setFieldValueFromPath
(
pilot
.
getAquaticWorld
().
getAquaNismsGroupsList
().
get
(
0
),
paramNames
[
i
],
paramValues
[
i
]);
}
// run the simulation
pilot
.
run
();
// For forcing resources releasing (like shp files)
System
.
gc
();
}
catch
(
Throwable
e
)
{
...
...
@@ -45,6 +55,16 @@ public class EasyRun {
}
public
static
double
[]
getValuesFromEnvironement
(
String
outputName
)
throws
Exception
{
return
(
double
[])
ReflectUtils
.
getValueFromPath
(
pilot
.
getAquaticWorld
().
getEnvironment
(),
outputName
);
}
public
static
double
[]
getValuesFromAquanismGroup
(
String
outputName
)
throws
Exception
{
return
(
double
[])
ReflectUtils
.
getValueFromPath
(
pilot
.
getAquaticWorld
().
getAquaNismsGroupsList
().
get
(
0
),
outputName
);
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
String
[]
batchArguments
=
(
"-simDuration 48 -simBegin 1 -timeStepDuration 1 -RNGStatusIndex 1 "
+
"-groups data/input/northeastamerica/fishRIOBasin_Sapidissima_Rjava.xml "
...
...
@@ -55,12 +75,15 @@ public class EasyRun {
"processes.processesEachStep.8.ratioS95_S50"
,
"processes.processesEachStep.6.pHomingAfterEquil"
};
double
[]
parameterValues
=
new
double
[]
{
10
,
2
,
0.7
};
runSimulation
(
batchArguments
,
"tsointsoin"
,
parameterNames
,
parameterValues
);
// runSimulation(
// batchArguments, "data/output/tsointsoin", new String[] { " = c("processes.processesEachStep.8.tempMinRep"",
// "processes.processesEachStep.8.ratioS95_S50", "processes.processesEachStep.6.pHomingAfterEquil" },
// new double[] { 10, 2, 0.7 });
System
.
out
.
println
(
Arrays
.
toString
(
getValuesFromEnvironement
(
"getMeanLastPercOfAut"
)));
System
.
out
.
println
(
Arrays
.
toString
(
getValuesFromAquanismGroup
(
"getRangeDistribution"
)));
// double[] basinRecruitments = runSimulation(batchArguments, "tsointsoin", parameterNames, parameterValues);
// System.out.println(Arrays.toString(basinRecruitments));
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment