[Rcpp-devel] variable affectation in Rcpp Rcpp Armadillo

Whit Armstrong armstrong.whit at gmail.com
Thu Jun 16 01:33:22 CEST 2011


You're not the only person working on MCMC w/ Rcpp.

I'm not sure about your exact question, but if you provide a .bug file
or write your model in pseudo code (i.e.  alpha ~ dnorm(0, tau)), then
I'll write up a cppbugs example for you.

-Whit


On Wed, Jun 15, 2011 at 5:03 PM, Nicolas Heslot <nh269 at cornell.edu> wrote:
> Hi rcpp-devel!
> First of all thank you for this awesome tool!
>
> I started a few days ago coding with Rcpp to try to reduce the computing
> time of a MCMC model.
> However, I don't have experience with C/C++ and I can't figure out how to
> reaffect a new content to a variable.
> This seems probably very simple to you but I can't figure it out, and this
> is the last step preventing my code to work out I think...
> The objects all_ui, all_ui2, all_ui3, all_rd and all_corMat are list objects
> containing matrix
> But once a matrice extracted from one of those lists is affected, to let say
> the object ui I can't affect the next matrix to ui at the next iteration.
> I tried to find a way to eliminate the object at each iteration or to empty
> it using .reset but without success.
>
> So any help would be very much appreciated!
> (fragment of code posted below)
>
> arma::mat tmp;
> arma::mat tmp2;
> arma::mat tmp3;
> arma::mat ui;
> arma::mat ui2;
> arma::mat ui3;
> arma::mat sigma;
>
> for (int j = 0; j < P-1; j++) {
> tmp2.fill(0);
> tmp3.fill(0);
>  for (int i = 0; i < N-1; i++) {
>  ui = all_ui[i];
> ui2 = all_ui2[i];
>  ui3 = all_ui3[i];
> rdi = all_rd[i];
> all_corMati = all_corMat[i];
>  sigma = sigma2*all_corMat[i];
> // calculate mean and variance
> arma::mat tmp = (solve(sig%all_corMat[i])* gen_a(i,j))*all_ui[i];
> arma::mat tmp2 += (all_rd[i] -
> mu*trans(all_ui3[i])-(X(i)*alpha)*trans(all_ui2[i]) +
> gen_a(i,j)*a.row(j)*trans(all_ui[i]))*tmp;
> arma::mat tmp3 += (gen_a(i,j)*trans(all_ui[i]))*tmp;
> }
> }
>
> Thank you for your help
>
> It probably does not help much
> but I use R2.13 with the last version of the packages on a windows XP
> plateform
>
> Nicolas
>
>
> _______________________________________________
> Rcpp-devel mailing list
> Rcpp-devel at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
>
>


More information about the Rcpp-devel mailing list