Re: Writing pars and par names in generated c++ (indexing question)

10 views
Skip to first unread message

Bob Carpenter

unread,
May 26, 2015, 4:01:18 PM5/26/15
to stan-...@googlegroups.com, stan...@googlegroups.com
[moving this thread over to stan-users]

I see --- there appears to be an error in the order for write_csv() ---
it doesn't match the headers.

We don't use write_csv() any more (even in optimization), so I'm
bumping the priority on this fix:

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

- Bob

> On May 26, 2015, at 2:55 PM, Andria Dawson <andria...@gmail.com> wrote:
>
> Hi Bob,
>
> Thanks for the quick reply. That makes sense about the internal vs external looping, but it look like in external i/o the parameter names are not consistent with the parameter values - the last two chunks of code above, which appear in write_csv_header and write_csv respectively.
>
> And we can definitely post this to the list - I didn't know how to cross-post the answer, but could add our email thread?
>
> Cheers,
> Andria
>
>
> On 26 May 2015 at 12:36, Bob Carpenter <ca...@alias-i.com> wrote:
> [would you mind having this discussion on our stan-users group or
> at least allowing us to cross-post answers?]
>
> There are a couple things going on.
>
> External I/O: this is reading from data files (via var_context)
> as done in the constructor and writing output as done in CSV output.
> This is uniformly first-index fastest.
>
> Internal I/O: this is converting to and from the constrained and
> unconstrained parameter vectors and back. This is the natural data type
> ordering with std::vector (last index fastest) and Eigen::Matrix (first index
> fastest).
>
> - Bob
>
> > On May 26, 2015, at 1:48 PM, Andria Dawson <andria...@gmail.com> wrote:
> >
> > Hey Daniel and Bob,
> >
> > Hope you are both doing well!
> >
> > I am still working on the space-time model, using Stan but avoiding autodiff by hard coding my gradient, and then using open MP. I've upgraded to version 2.6.2. Seems to be going well. I have a question about indexing in the generated c++ code in the case where we have vector<vector_d>. It looks like the ordering of the loop variables is different when param_names__ are written as compared to when the parameter itself it written, so I'm just trying to understand what is going on.
> >
> > For example, in my code, I define alpha_s in Stan as:
> > vector[N_knots] alpha_s[W];
> >
> > Then I see the following pieces of code, and I am struggling to understand the looping. First we define alpha_s in the following block of code:
> >
> > vector<vector_d> alpha_s;
> > size_t dim_alpha_s_0__ = W;
> > for (size_t k_0__ = 0; k_0__ < dim_alpha_s_0__; ++k_0__) {
> > alpha_s.push_back(in__.vector_constrain(N_knots));
> > }
> >
> > Then, I think the following block of code writes the parameter names, where the "fast" index appears to be k_0__ (species in my model), and the "slow" index is k_1__ (the knots in my model):
> >
> > for (int k_1__ = 1; k_1__ <= N_knots; ++k_1__) {
> > for (int k_0__ = 1; k_0__ <= W; ++k_0__) {
> > param_name_stream__.str(std::string());
> > param_name_stream__ << "alpha_s" << '.' << k_0__ << '.' << k_1__;
> > param_names__.push_back(param_name_stream__.str());
> > }
> > }
> >
> > But it looks like the data is written out with the following, where it appears "fast" index is over the knots, for a given "slow" k_0__ (species)
> >
> > vector<vector_d> alpha_s;
> > size_t dim_alpha_s_0__ = W;
> > for (size_t k_0__ = 0; k_0__ < dim_alpha_s_0__; ++k_0__) {
> > alpha_s.push_back(in__.vector_constrain(N_knots));
> > writer__.write(alpha_s[k_0__]);
> > }
> >
> >
> > Do you know why the ordering appears to be different for the pars and the par names? Am I missing something?
> >
> > Thanks again for your help!
> > Andria
>
>

Reply all
Reply to author
Forward
0 new messages