On 3/17/13 7:58 PM, Dawen Liang wrote:
> Thanks for the advice. The sampling finished last night, but as I expected the effective sample size/r_hat is far from
> satisfactory,
This might be for other reasons.
If you tell us more about your model, we might be
able to suggest something.
> and it created a stan object occupying 8GB of my RAM (I ran 4 chains with 1000 iterations each). Don't
> know what to do yet...
How many parameters did you have such that 4 chains of 1K
iterations took 8GB of RAM? Is that in RStan or using the
new command from the command-line to calculate R-hat and ESS
and whatnot?
For memory, you can stream the data out to file rather than saving
it. The command-line version streams, and I believe
RStan is set up to turn off internal saving and turn on
streaming (someone else will know how to do it if possible).
You might want to try a smaller version of the model or
less data until you're confident it's all working, then turn
it loose on more data.
> As for the MATLAB counterpart, I think y ./ x will do the thing, where y is a number and x is a vector. MATLAB also has
> an explicit broadcast function bsxfun. But in this case, I think y / x, which is interpreted as broadcast, would be
> better, because "." means "element-wise" to many people, which implies both arguments are vectors. Anyway, it's just my
> thought.
The problem in my mind is that we already use / for
matrix division. And this isn't a matrix division
operation, which would be y / x = y * inv(x).
I guess it's going to be confusing either way.
> I also noticed that in FAQ about speeding up the code, there mentions that instead of doing (where y is a N*K matrix):
>
> for (k in 1:K) {
> for (i in 1:N) {
> y[i,k] ~ normal(0, 1);
> }
> }
>
> A much faster way would be:
>
> y ~ normal(0,1);
Sorry about that.
The FAQ got ahead of what we've implemented.
We've only vectorized probability functions for vectors,
row vectors and 1D arrays. We will be doing matrices
and general arrays in the very near future (we just
laid the metaprogramming groundwork in the code last week).
For now, the best you can do is:
> for (i in 1:N) {
> y[i] ~ normal(0, 1);
It's probably not worth flattening the matrix into a
single size (F * K) array at this point, but it's possible
with some index fiddling.
> However, in my model, we have a matrix<lower=0>[F, K] D and I wrote:
>
> log(D) ~ normal(0, 1);
> or
> D ~ lognormal(0, 1);
These two things are not at all the same. We work through
this very example in section 16.2 of the manual.
> It gave me a syntax error on both.
Right. Until we add matrices to our vectorization,
it needs to be:
for (f in 1:F)
D[f] ~ lognormal(0,1);
It's a bit more efficient here (for now, until we vectorize)
to just declare it as an array,
real<lower=0> D[F,K];
or an array of vectors,
vector<lower=0>[K] D[F];
The reason is that we can then save an allocate/copy
step for D[f].
> And just now, I found that it seems that transpose operator (') doesn't work in
> RStudio, as it kept asking me to enter another ' to balance.
Is that in an editor? Or was it in feeding the
model in as a string argument somewhere? (I don't
like the latter practice -- I think it makes more sense
to keep the models in their own files, but I seem
to be in the minority with this opinion.)
> If there is any misunderstanding of the usage, please let
> me know.
No, it's an apostrophe for transpose.
I have no idea what's up with RStudio. You could always put the
model in another file and just call it by name from the stan()
command.
- Bob