We’re getting really close to releasing a version of Stan with multi-core support for parallel likelihood evaluations. There’s a code-complete, tested branch that works. I’m finishing up the doc now and should have a pull request very soon. I just wanted to share the first working example, which translates a simple fixed-size logistic regression
data {
int y[12];
real x[12];
}
parameters {
vector[2] beta;
}
model {
beta ~ normal(0, 1);
y ~ bernoulli_logit(beta[1] + beta[2] * to_vector(x));
}
to the following fixed-size/fixed-shard-size mapped version:
functions {
// logistic regression lpmf
vector lr(vector beta, vector theta, real[] x, int[] y) {
real lp = bernoulli_logit_lpmf(y | beta[1] + to_vector(x) * beta[2]);
return [lp]';
}
}
data {
// N = 12 data points
int y[12];
real x[12];
}
transformed data {
// K = 3 shards
int ys[3, 4] = { y[1:4], y[5:8], y[9:12] };
real xs[3, 4] = { x[1:4], x[5:8], x[9:12] };
vector[0] theta[3];
}
parameters {
vector[2] beta;
}
model {
beta ~ normal(0, 1);
target += sum(map_rect(lr, beta, theta, xs, ys));
}
Like the ODE integrator and algebraic solver, dealing with the types and dummies to pack/unpack is clunky.
I’m already seeing that it’d be nice to have a version of map_rect
that maps a function returning a single real value to avoid that final bit of syntactic cruft in the return, [lp]'
. That should be very easy to build using a simple adaptor.