Hello Nimble community!
I’m an enthusiastic new nimble user, and I’m sorry in advance for the dictionnary I’ve written here… Just trying to provide some context and go over the steps I’ve already taken. I’m trying to run a very memory-hungry CMR model, and I’m looking for input as to how to reduce calculation time and memory use. I’m using a joint live encounter and dead recovery model. I have ringed birds that can be physically caught in the summer and collared ones that can be observed from a distance all year long. One of the issues I have is that I have a relatively large dataset (45k individuals and 30 years of data), and I’m trying to estimate survival on a seasonal basis (119 occasions total). All observation probabilities are fairly variable through time (probabilities of recapture, collar observations and recovery of dead birds). As such the number of parameters to estimate rises quickly to reach the 300s when everything is time-dependent. In addition to all this, there is heterogeneity in live-encounter probability, which varies between seasons (the individuals that are often seen in winter are not the same ones that are often seen in fall or spring). In order to reduce the number of parameters to estimate I’m using time random effects to estimate variation in the encounters and individual level random effects to model heterogeneity in live-encounter probability.
Looking around in the forum I have come across a few tips that could help with memory use and calculation time, like using the calculate=F and useConjugacy=F options in model and mcmc building. I’ve gotten rid of the initial states matrices in the model code and directly feed the initial observations and initial states from pre-defined constants. I’ve modified the traditionnal code that loops over all occasions to generate observation matrices in order to specify some parameters that only occur during particular seasons. For example I generate observation matrices with capture probabilities only for summer occasions, to avoid having the capture probability appear in all matrix slices but turned on and off with an indicator variable (it was my understanding that these probabilities are still getting sampled by the MCMC even if they are multiplied by a 0 to ‘turn them off’). So doing this should save on the calculation time if I understand things correctly. I have also read Perry’s suggestion (here) about creating my own distribution that would ‘use the ingredients for the MCMC directly’, which would avoid unnefficiently creating gigantic arrays like I’m doing here. However, I’m a bit at a loss here and I’m not sure how or where to look to get started on that. I’ve seen a lot of people on this forum that managed to write their own distributions and I’m eager to learn but I feel like I’m quite a ways away from being able to do that.
I have also looked at marginalizing over latent states using the nimbleEcology distribution as I do not necessarely need to track the latent states. Using the marginalized formulation does speed up the model and MCMC buiding. However, I was surprised to see that when using the dDHMMo distribution, the mcmc takes takes much longer to run than simply using the ‘traditional’ likelihood formulation with dcat() and the latent states. Is this normal? Are there cases where using this formulation should take longer? With my sample dataset and running a very short chain (1000 iterations), running the mcmc with the marginalized parametrization takes 35-37 minutes vs. 10-12 minutes when using the unmarginalized formulation. Did I make a mistake somewhere?
Finally, I’m wondering if there are any other steps I can take to reduce memory usage or calculation time. I will eventually put this on a cluster and run chains in parallel, which should help with calculation time but right now I'm trying to reduce memory use as even with only a fraction of my dataset (11k individuals, 29 occasions), I'm already using up almost all 128GB of ram... I imagine that the higher the thinning, the more we save on memory usage, so some economy can also probably be made there.
I’ve attached my script and a sample of my dataset if this can help (‘only’ 5k individuals and 7 years of data, so 29 occasions). I’ve tried to make the code as clear as possible, but I realize that there is a lot going on so don’t hesitate to let me know if I can clarify some things. There are two nimbleModel codes in the script, one with the marginalization formulation and one without so that anyone can compare time and memory use for both parametrizations.
Thanks in advance for any help with this!
Sincerely,
Frédéric
--
You received this message because you are subscribed to the Google Groups "nimble-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nimble-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nimble-users/d3cb7487-2bca-4f7f-bf09-02cd742ff7a1n%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nimble-users/b63c1c87-a40e-453d-829e-4b7f2356221dn%40googlegroups.com.