Parallel reduce in the Stan language

You are probably right, perhaps I am expecting too much of this.

Let’s make a simple example. Suppose we have some kind of an autoregressive model, then we could write

reducer(int start, int end, vector y, real rho, vector b, matrix X, real sigma) {
   vector[end - start + 1] ym1;
   if (start == 1) {
     ym1 = [0, y[start:(end - 1)]];
   } else {
     ym1 = y[(start - 1):(end - 1)];
   }
   return normal_lpdf(y[start:end] | X[start:end] * b + ym1 * rho, sigma);
}

Not sure if this example makes any sense at all in this context, and I am not saying we couldn’t build this model with parallel_reduce doing the slicing. I just mean, we can make the interface cleaner by letting everything happen inside a user-defined function.

1 Like