Hi all,
I'm running a fairly complex model that takes up a lot of memory, and I've been trying to write functions that will do some of the calculations and lighten the memory usage.
I'm running the model by creating the model, changing the mcmc samplers, compiling the model and then using run(). Everything goes fine until I get to run, at which point R crashes. As you can imagine, this makes finding the problem a little difficult. My suspicion that either my custom sampler or one of my Nimble functions is written incorrectly, but I'm struggling to pinpoint the exact issue.
I've attached my nimble code and two scripts that hold the functions and a simulation data set for reproducibility. Here's the run code part, which fails on the last line:
prepbirds <- nimbleModel(code = nimIBM, constants = nc,
data = nd, inits = ni, calculate = T, check = T)
prepbirds$phi.p[,1] <- 1
prepbirds$initializeInfo()
prepbirds$calculate()
mcmcbirds <- configureMCMC(prepbirds, monitors = pars, print = T, control = list(adaptInterval = adaptInterval, scale=.1))
mcmcbirds$removeSampler(paste0("s[",1:M,", 1:2, 1]"))
for(i in 1:M){
mcmcbirds$addSampler(target = paste0("s[",i,", 1:2, 1]"),
type = 'RW_block', silent=TRUE,
control = list(adaptInterval = adaptInterval, propCov=diag(2), scale=SamplerScale, adaptScaleOnly=TRUE))
for(tt in 2:occ){
mcmcbirds$addSampler(target = paste0("s[",i,", 1:2, ", tt, "]"),
type = 'myRWtrajectoryPotentialSampler',
control = list(ind=i, scale=SamplerScale, npix=npix, pxw = pxw,xmin = xmin, ymin = ymin, xmax = xmax, ymax = ymax, gcoords= gcoords, pixMat = pixels))
}
}
birdsMCMC <- buildMCMC(mcmcbirds)
Cmodel <- compileNimble(prepbirds) #takes a long time (sometimes)
Compbirds <- compileNimble(birdsMCMC, project = prepbirds)
Compbirds$run(niter = 2, nburnin = 0, thin = 1, reset = F)
Any tips or thoughts are appreciated!