I am trying to fit a large hierarchical model. What I have implemented so far in Stan works well and takes a few days.
I am looking into simple options to speed inference up. I thought one possibility would be to pass a more aggressive optimization flag to stanc, as described in 34.5 Optimization | Stan User’s Guide.
However, all three --O0, --O1, and --Oexperimental flags output identical code and binaries. Anything I am missing?
Depending on your model, it’s possible that the compiler optimizations are unable to do anything, but that seems unlikely. If you’re able to share your Stan code that may help us debug
Thanks @WardBrian, makes sense. Upon a close inspection of my model, I note there is nothing that can be improved by --Oexperimental optimizations. But if I introduce a static loop, it seems to be unrolled if I use the experimental option, so all good from that perspective.
One last thing, how can I prevent cmdstan from saving the random effects matrix \epsilon in the model I outline below? It is a huge matrix that takes quite a lot of disk space but whose posterior is not interesting to look at.
parameters {
// Other parameters
// ...
// Matrix of random effects
matrix[K,N] epsilon;
}
model {
// Other model code
// ...
k[i,j] ~ binomial(n[j], inv_logit(... + epsilon[i,j]));
}
Subsets of parameters have been requested (e.g. here) but is not currently possible.
Also, be careful with --Oexperimental - it’s very experimental, and may contain transformations which make your program even slower or no longer correct