This repository has been archived by the owner on Sep 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
runCVbatch.R
executable file
·77 lines (56 loc) · 1.9 KB
/
runCVbatch.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env Rscript
# Aidan Draper
# June 12, 2018
# Batch system file for cross-validation of charcoal Bayesian model
# install.packages('spBayes', lib = "/afs/crc.nd.edu/user/a/adraper2/condor/Rlibs")
library(spBayes, lib = "/afs/crc.nd.edu/user/a/adraper2/condor/Rlibs")
library(mgcv)
args = commandArgs(trailingOnly=TRUE)
if (length(args)<2) {
stop("Two arguments must be supplied (lake name, process number). Run again.", call.=FALSE)
} else if (length(args)==2) {
# default output file
lake.name = args[1]
process = as.integer(args[2])
if(process == 0){
start = process + 1
stop = process + 3
} else {
start = (process * 3) + 1
stop = start + 2
}
} else {
stop("Too many arguments supplied. Run again.", call.=FALSE)
}
lake.inputs = paste("InputsCV", lake.name, ".rda",sep="")
load(lake.inputs)
###############################################################################
## Function created by Malcolm Itter
## May 25, 2018
###############################################################################
## RunAdaptMCMC_CV - Function to run MCMC simulation for univariate model
## using cross validation inputs
###############################################################################
run.cv = function(x){
attach(x)
out = try(adaptMetropGibbs(ltd=ltd,starting=starting,tuning=tune,batch=2400,report=400,
inputs=inputs,priors=priors))
n.sim = 2400*25
n.burn = 50000
n.step = 5
save.idx = seq(n.burn+1,n.sim,n.step)
if (class(out)=="try-error"){
samps = array(NA,dim=c(length(save.idx),length(starting)))
} else {
samps = out$p.theta.samples[save.idx,]
}
return(samps)
detach(x)
}
####### END OF Malcolm's CODE ######
results = vector("list", ((stop - start) + 1))
for (i in start : stop){
results[[i]] = run.cv(mod.inputs[[i]])
}
out.file = paste("OutCV",lake.name,process,".rda",sep="")
save(results,file=out.file)