Open Andrea-Havron-NOAA opened 2 years ago
Related to Issue #334
Vectorizing won't make the calculations more efficient, the function to do the vectorization will still have to loop through all the elements. It may be easier for developers to rely on vectorized methods to simply coding though.
I forgot to respond earlier but from the Stan manual (page 14 of this pdf):
"Unlike in Python and R, which are interpreted, Stan is translated to C++ and compiled, so loops and assignment statements are fast. Vectorized code is faster in Stan because (a) the expression tree used to compute derivatives can be simplified, leading to fewer virtual function calls, and (b) computations that would be repeated in the looping version, such as log(sigma) in the above model, will be computed once and reused."
I'm not sure about (a) but I was referring to (b) when I made the issue. Overall this will be a very small effect and is thus very low priority in my opinion.
I think @msupernaw has a prototype for this in the linked branch
It is more efficience to calculate vectorized negative log-likelihoods than to loop through individual observations.
We may want to vectorize this in the future. It's redundant/inefficient to calculate the constants
logy.size()
times. Stan is very strict about this in their code base._Originally posted by @Cole-Monnahan-NOAA in https://github.com/NOAA-FIMS/FIMS/pull/181#discussion_r908960117_