-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
321 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
|
||
# ——————————————————————————————— | ||
# State-space length-based age-structured model by Kyuhan Kim | ||
# Copyright © 2023 Kyuhan Kim. All rights reserved. | ||
# Contact: kh2064@gmail.com for questions | ||
# MIT License: https://opensource.org/licenses/MIT | ||
# ——————————————————————————————— | ||
|
||
################ | ||
## Cross Test ## | ||
################ | ||
|
||
## cross test combinations | ||
CrossComb=expand.grid(ModelsForCross, | ||
ModelsForCross) | ||
|
||
CrossComb=CrossComb[,c(2,1)] ## switch the order of the columns | ||
|
||
OMs=lapply(CrossComb[,1], function(x) ModelsEstimResults[,x]$f ) ## OMs: operating models | ||
EMs=lapply(CrossComb[,2], function(x) ModelsEstimResults[,x]$f ) ## EMs: estimation models | ||
|
||
## run the cross test | ||
CrossFitResults=parallel::mcmapply(MackCross, | ||
OMobj = OMs, | ||
EMobj= EMs, | ||
MoreArgs = list(qPenalty=qPenalty, | ||
SimProcess = SimProcess, | ||
nsims=nsimCross, | ||
silent = T, | ||
seed=1234), | ||
mc.cores = nCores-1, | ||
SIMPLIFY = T) | ||
|
||
|
||
## AICs | ||
AICs=do.call(rbind, CrossFitResults["AIC",]) | ||
rownames(AICs)<-apply(CrossComb, 1, function(x) paste0("M",x, collapse="")) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
all: CrossFit.RData | ||
|
||
CrossFit.RData: setup.R | ||
Rscript setup.R |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
|
||
# ——————————————————————————————— | ||
# State-space length-based age-structured model by Kyuhan Kim | ||
# Copyright © 2023 Kyuhan Kim. All rights reserved. | ||
# Contact: kh2064@gmail.com for questions | ||
# MIT License: https://opensource.org/licenses/MIT | ||
# ——————————————————————————————— | ||
|
||
cat('\n\n Setup begins \n\n') | ||
|
||
LocalRun=T | ||
|
||
############# | ||
## library ## | ||
############# | ||
|
||
require(dplyr) | ||
require(TMB) | ||
require(sn) | ||
require(rootSolve) | ||
require(extraDistr) | ||
require(parallel) | ||
|
||
###################################### | ||
## load fitted models and functions ## | ||
###################################### | ||
|
||
if(LocalRun==T) { | ||
load("../../Results/ModelFitted.RData") | ||
} else { | ||
load("/input/Mack-LBASM-ModelFitting/ModelFitted.RData") | ||
} | ||
|
||
source("../../Data_and_functions/MackData.R") | ||
source("../../Data_and_functions/MackFunctions.R") | ||
source("../../Data_and_functions/TMBInputObjs.R") | ||
|
||
## compile the TMB model ## | ||
compile("../../src/Main/main.cpp"); dyn.load(dynlib("../../src/Main/main")) | ||
|
||
################################## | ||
## read environmental variables ## | ||
################################## | ||
|
||
##env variables ## | ||
nsimCross <- as.integer(Sys.getenv("nsimCross", 2)) | ||
SimProcess <- as.integer(Sys.getenv("SimProcess", 1)) | ||
qPenalty <- as.integer(Sys.getenv("qPenalty", 0)) | ||
|
||
## number of cores | ||
nCores=detectCores() | ||
|
||
print(paste0("Cores: ", nCores)) | ||
print(paste0("nSims: ", nsimCross)) | ||
print(paste0("Simulate process error: ", SimProcess)) | ||
print(paste0("Penalty on sigq: ", qPenalty)) | ||
|
||
################ | ||
## input objs ## | ||
################ | ||
|
||
ModelsForCross=c(10,11,12) ## models to be cross tested | ||
|
||
cat('\n\n Setup finished \n\n') | ||
|
||
################################################ | ||
##### run the analysis script (first step) ##### | ||
################################################ | ||
|
||
cat('\n\n Run CrossFit.R \n\n') | ||
source("CrossFit.R") | ||
cat('\n\n CrossFit.R finished \n\n') | ||
|
||
################################### | ||
## save the results (first step) ## | ||
################################### | ||
|
||
if(LocalRun==T) { | ||
save.image("../../Results/CrossFit.RData") | ||
} else { | ||
save.image("CrossFit.RData") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters