Hi,
I'm experiencing something similar to
here - I didn't find a similar post focussing on RTMB.
I am trying to run a hidden Markov model with 2 random effects per time point and 10K observations, i.e. 20K random effects.
The likelihood function basically looks like
for (track in 1:ntracks) {
nll <- nll - track_llk(..., ~ 120 random effects for this track)
}
The inner part necessarily introduces dependence (due to the forward algorithm), leading to a banded Hessian with bandwidth ~ 120.
Doing the rough calculation, that means I should have ~ 120 * 20K = 2.4M non-zero entries in the Hessian.
After the tape has been optimized and (I guess) the sparsity pattern of the Hessian has been matched, it takes up ~ 4 Gb of memory, but when calling MakeADFun() or in the next step, calling obj$fn() / obj$env$spHess() (I'm not totally sure about that), memory spikes to ~ 17 Gb which is a problem, particularly because I want to scale up the problem and the peak memory usage seems to grow quadratically in the number of random effects.
Can I do anything in my code to optimize for memory usage? For example would replacing the outer loop by sapply() help? Or is the size just inherent to the problem?
Thanks in advance :)