--
Ben
A lot of work for the CPU, not for the human. The file sourced fixes the seed but otherwise pretty much uses the defaults.
Ben
--
I would try to get some results from Windows. Actually, I can get results for both Windows and Linux from the same computer.For comparing O3 and O2, is package RStan also installed differently?
> On Dec 19, 2012, at 4:33 PM, Ben Goodrich wrote:
I'm sort of amazed at the variation in compilers
across models. But then maybe that's random init
differences? Are they all running with the same seed?
bench <- function(i) {
mark <- "elapsed"
compile <- system.time(fit <- stan_demo(i, chains = 0, iter = 0))[mark]
execute <- system.time(fit <- stan_demo(i, fit = fit, seed = 12345, refresh = -1))[mark]
if (length(dim(fit)) == 0) execute <- NA_real_ # failure
return(c(compile, execute))
}
And it's time to generalize the Matt trick to multivariate
models for alpha in vol2/schools/schools.stan
For evaluation, it's clear we should do efficient
implementations.
On the pedagogy side, we have the conflicting goals
of clarity and speed.
> In a couple of cases, we have both an unvectorized and a vectorized
> version of the model, but that is not so helpful when the unvectorized version is unreasonably slow.
I see room for two versions -- one clear and one fast.
Pedagogically, that would be the best of both worlds.
model {
for(p in 1:N) {
Y[p] ~ normal(alpha[school[p], 1] + alpha[school[p], 2] * LRT[p] +
alpha[school[p], 3] * VR[p, 1] + beta[1] * LRT[p] * LRT[p] +
beta[2] * VR[p, 2] + beta[3] * Gender[p] +
beta[4] * School_gender[p, 1] + beta[5] * School_gender[p, 2] +
beta[6] * School_denom[p, 1] + beta[7] * School_denom[p, 2] +
beta[8] * School_denom[p, 3], exp(-.5 * (theta + phi * LRT[p])));
}
// min.var <- exp(-(theta + phi * (-34.6193))) # lowest LRT score = -34.6193
// max.var <- exp(-(theta + phi * (37.3807))) # highest LRT score = 37.3807
# Priors for fixed effects:
beta ~ normal(0, 100);
// for (k in 1:8) beta[k] ~ normal(0.0, 100);
theta ~ normal(0.0, 100);
phi ~ normal(0.0, 100);
# Priors for random coefficients:
for (m in 1:M) alpha[m] ~ multi_normal(gamma, Sigma);
# Hyper-priors:
gamma ~ multi_normal(gamma_mu, gamma_Sigma);
Sigma ~ inv_wishart(3, invR);
}
model {
vector[N] mu;
vector[N] sigma;
for(p in 1:N) {
mu[p] <- alpha[school[p], 1] + alpha[school[p], 2] * LRT[p] +
alpha[school[p], 3] * VR[p, 1] + beta[1] * LRT[p] * LRT[p] +
beta[2] * VR[p, 2] + beta[3] * Gender[p] +
beta[4] * School_gender[p, 1] + beta[5] * School_gender[p, 2] +
beta[6] * School_denom[p, 1] + beta[7] * School_denom[p, 2] +
beta[8] * School_denom[p, 3];
sigma[p] <- exp(-.5 * (theta + phi * LRT[p]));
}
Y ~ normal(mu, sigma);
# Priors for fixed effects:
beta ~ normal(0, 100);
// for (k in 1:8) beta[k] ~ normal(0.0, 100);
I share your notion of clarity.
The Matt trick's clarity is probably an issue with
habit. In some ways, it's clearer to think of
a bunch of normal variates getting rescaled than to
think about drawing from all sorts of differently scaled
and located distributions.
I think having to create a vector and write into it
for vectorization is less clear for everyone.
The main reason plain old vectorization may be less
clear is that it's not immediately evident to either
the BUGS or R user how we've vectorized. That is,
we allow any of the arguments to be a scalar that's
just repeated. Most R functions won't let you do that,
will they?
> P.S. Also, I think we should consider putting all our examples in a big pdf file. Yes, I know they are all there on the webpage, but I think there's something about a recipe book which is helpful to people.
Formatting is problematic for this kind of thing.
The attached uses 11pt font on regular notebook
paper (8.5" x 11"), with text width 6.5" and height
9.5". That'll make it challenging to read on an iPad,
but it should print OK.
I also include a small sized model (room for 88 chars)
and a footnote sized model (98 chars, but obviously
too small).
Any suggestions on formatting?
--
<do_examples.sh>
I like the pdf -- I find it easier to browse
than having to navigate among a bunch of web
pages.