Small Optimizations and Numerical integration
I’ve been thinking and reading about little ways in which I can numerically optimize my code. While on the one hand preallocated memory, etc, can go a long way, I am also thinking about algorithms.
One area in particular is the numerical integrations which need to happen over and over and over again in the course of the software. At the moment it turns out that my method, while naive, is probably a pretty good one as some numerical experiments show good convergence properties with relatively small sample sizes (between 1000 and 2000 points) based on the variance of the last half of the estimates and the ACF of the same.
I went looking around for places to replace loops with vectorized operations with little luck. It is the nature of MCMC that loops become necessary. On the other hand, there are a couple places where if I am willing to sacrifice the memory to the task, I could precompute inputs to each loop iteration using the “apply” function and then use the loop to do the final transitions. Alternatively, I am thinking that because many, many inputs don’t ever change, that it may be possible to use the “call” and “do.call” functionality to prepackage all the unchanging bits into something that can then be executed much faster because, again, there is no need to do a bunch of memory accesses. At this time I am using do.call with a seperate list of arguments, so the list has to be created then fed to the do.call mechanism. This, I suspect, is far from efficient.