Lines for Errors in Assignment

132 views
Skip to first unread message

John Hall

unread,
Feb 18, 2014, 5:46:49 PM2/18/14
to stan-...@googlegroups.com
I was playing around with creating some lags and difference variables in the Transformed Data block. I had accidentally set the dimension on one of the transformed variables to a variable also defined in the transformed data block instead of making the calculation directly. It was quite difficult to figure out what was causing the problem as the output wasn't telling me what line to look at. For instance it would say
Error : error in call to assign; require matching dimensions, but found arg1(rows=0,cols=1); arg2(rows=527,cols=1)
failed to create the sampler; sampling not done

It might be helpful to make it more clear what line is generating these errors.

The correct code is below (just the data and transformed data blocks at least). To make the above show up, you would change the vector[T - P] to vector[T_P].

data {
    int<lower=0> T;
    int<lower=0> N;
    vector[T] Y[N];
    int<lower=1, upper=T> P;
}
transformed data {
    int<lower=0> T_P;
    vector[T - 1] Y_[N];
    vector[T - P] Y_lag[N];
    vector[T - P] Y_diff[N];
   
    T_P <- T - P;
    for (n in 1:N) {
        Y_[n] <- tail(Y[n], T_P);
        Y_lag[n] <- tail(head(Y[n], T - 1), T_P);
        Y_diff[n] <- Y_[n] - Y_lag[n];
    }
}

Bob Carpenter

unread,
Feb 19, 2014, 10:38:59 AM2/19/14
to stan-...@googlegroups.com
We plan to add line numbers to error messages. But it’s not so easy.

There’s been some recent proposals on the stan-dev list, but it’s
going to be fairly involved on the code side because of the way we’re
generating C++ code and using library functions and because we don’t
want to do something naive that’ll impact performance measurably.

- 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.
> For more options, visit https://groups.google.com/groups/opt_out.

John Hall

unread,
Feb 19, 2014, 2:02:06 PM2/19/14
to stan-...@googlegroups.com
Are you also considering a function to convert a vector to a matrix (like an analog to to_vector)? It's not always easy in Stan to go from one data type to another and it can be helpful for some types of problems.

Bob Carpenter

unread,
Feb 19, 2014, 2:17:45 PM2/19/14
to stan-...@googlegroups.com


On Feb 19, 2014, at 8:02 PM, John Hall <john.mic...@gmail.com> wrote:

> Are you also considering a function to convert a vector to a matrix (like an analog to to_vector)? It's not always easy in Stan to go from one data type to another and it can be helpful for some types of problems.

It wasn’t on our radar, but it is now:

https://github.com/stan-dev/stan/issues/575

I added a whole bunch of variants, all of which should be very easy to
write. The only even remotely challenging one is flatten(), because it
requires template programming.

If someone wanted to write their first Stan function and help us out,
this’d be a great project to get your feet wet!

- Bob

John Hall

unread,
Feb 19, 2014, 2:45:23 PM2/19/14
to stan-...@googlegroups.com
It does seem like a simple project for someone. I've got more experience with Matlab/R/Python than C++ so I'm afraid I would probably screw something up if I tried to do it myself. I noticed that the function would be helpful as I was making an ECM model (why I was doing the differences and lags) and I had to sample a bunch of parameters from the multivariate normal and then put them into the correct places in other matrices.

Bob Carpenter

unread,
Feb 19, 2014, 2:48:35 PM2/19/14
to stan-...@googlegroups.com
No problem — I wasn’t trying to suggest you should do it.

We won’t let anyone screw it up — there will have to be tests
in place to make sure it does what it’s supposed to do and we
code review all changes, even those from within the dev team, so
there are at least two sets of eyes on everything (not that that
prevents all errors getting through, but it certainly cuts down
on the quantity and improves code consistency).

- Bob
Message has been deleted
Message has been deleted

David Manheim

unread,
Sep 16, 2015, 4:23:51 PM9/16/15
to Stan users mailing list
The other extension, which would be helpful, is the unflatten equivalent.

Specifically, I'd love to be able to move from a vector to a matrix by specifying that the N element vector should be an a*b matrix, where a*b=N.

This doesn't seem to be covered by any existing function (but if it is, a pointer would be great!)

David Manheim

Bob Carpenter

unread,
Sep 16, 2015, 4:42:51 PM9/16/15
to stan-...@googlegroups.com
I agree that would be useful and I updated the feature request to
reflect that.

These are relatively easy things to add to Stan if someone wants
to get started helping out this way!

- 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.

Reply all
Reply to author
Forward
0 new messages