Optimise convolution
Closed this issue · 2 comments
To reduce compute time of the convolution model one option is to only calculate the probability mass function for unique combinations of log means and log standard deviations.
In the current framework this would need to be done by detecting unique entries in a vector in stan, computing the pmf for these and then sharing it across all original vectors in such a way that the control code has a lower cost than calculating the pmf.
Another option is to reduce the complexity of the pmf perhaps by using a different delay distribution or to provide a second version of the model where the pmf is estimated once or by some supplied indicator rather than for every time point as currently.
Pseudo code for this optimisation would be:
- Create an object with mean, standard deviation, a row index, and an label for the unique combination id.
- Filter for just unique combinations
- Loop though each combination and calculate the pmf
- Link the pmg look up table with the row index from 1.
In stan like code this can be thought about in terms of for loops and break statements. Something like the following.
int n = num_elements(cmean);
vector pmf[n];
int j;
for (s in 1:n) {
j = 1;
while (j <= s) {
if (j == s) {
pmf[s] = calc_pmf(cmean[s], sd[s], max);
}else{
if(cmean[j] == cmean[s] && sd[j] == sd[s]) {
pmf[s] = pmf[j];
break;
}
j += 1;
}
}