Rstan running time

87 views
Skip to first unread message

庄梦舟

unread,
Oct 4, 2016, 7:27:33 PM10/4/16
to Stan users mailing list

Hi everyone,

I am currently working on the estimation of a hierarchical bayesian model. I noticed that usually it takes about 25 mins to run 100 iterations but however it takes FOREVER to run 500 iterations. Is the estimation time linear in terms of the number of iterations? In other words, should the running time for 500 iterations 5 times of the time for 100 iterations? The dataset contains only 1000 observations, and I believe the model per se is not complicated.

I noticed that sometimes for the 500 iterations, the viewer window would stop updating the progress (e.g., stop at 90% sampling). Is this caused by the memory limits or just my coding problem? 

Please let me know if you have any thoughts. The R script and data file are attached. 

Thanks in advance!

Best,
Austin
stan.R
keyword.stan
identity.Rdata

Bob Carpenter

unread,
Oct 4, 2016, 8:04:29 PM10/4/16
to stan-...@googlegroups.com
Run time is not linear in number of iterations because
the number of calls to log density and gradient calculations
(the real time sinks) changes. As adaptation runs
during warmup, it changes the parameters of the underlying Hamiltonian simulation.
If the step size and mass matrix produce small steps, it may seem like it'll never
finish. This is usually done in response to complex posterior geometry,
often arising in hierarchical models.

I have no idea about viewer windows in RStan, though.

- Bob
> --
> You received this message because you are subscribed to the Google Groups "Stan users mailing list" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+...@googlegroups.com.
> To post to this group, send email to stan-...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
> <stan.R><keyword.stan><identity.Rdata>

Bob Carpenter

unread,
Oct 4, 2016, 8:09:41 PM10/4/16
to stan-...@googlegroups.com
For that model, we do not recommend the inv_gamma(0.001, 0.001)
priors, the normal(0, 100) priors or the inverse Wisharts.

You can also vectorize many of your other calls for more efficiency.

And you don't want to do things like create constant
diagonal matrices as local variables---they should be in
transformed data if you need them. But you really want to
use the cholesky factor parameterizations of covariance for
efficiency. See the manual chapter on regression for prior
recommendations and how to code them.

- Bob

> On Oct 4, 2016, at 7:27 PM, 庄梦舟 <mengzho...@gmail.com> wrote:
>
>

庄梦舟

unread,
Oct 4, 2016, 11:44:00 PM10/4/16
to Stan users mailing list
Thanks for the advice Bob!

Another quick question is that: do you have any idea of the approximate running time of such model. I tried to do it on my I7 6700 2.6 GHz+16 Gb RAM laptop, but it seems like that the results never come out. Should I switch to a more powerful server instead of my laptop?

Thanks,
Austin

在 2016年10月4日星期二 UTC-5下午7:09:41,Bob Carpenter写道:

Bob Carpenter

unread,
Oct 5, 2016, 1:44:29 PM10/5/16
to stan-...@googlegroups.com
Unless you're somehow running out of memory (you can
check your system monitors depending on OS), a more
powerful computer's only going to be an incremental
improvement. You really need to code the model more
efficiently computationally or find a more efficient parameterization
statistically or work with less data.

Run time is very sensitive to data. If the model is
misspecified for the data, run time can be very long even
in cases where data generated from the model will fit easily.

We always recommend fake-data testing to start. Take a small
instance of your problem, generate fake data from the priors,
then see if you can fit it. If you find yourself saying "the priors
are too wide for simulation", then you probably want stronger
priors in your model.

- Bob

庄梦舟

unread,
Oct 5, 2016, 2:03:10 PM10/5/16
to Stan users mailing list
Thanks Bob. I am estimate the model using simulated fake-data, which is about 1k observations. 

your answer really helps! Thanks a lot!

Austin

在 2016年10月5日星期三 UTC-5下午12:44:29,Bob Carpenter写道:
Reply all
Reply to author
Forward
0 new messages