<html><body bgcolor="#FFFFFF"><div>I've also written MCMC code using arma and have no trouble overwriting (assuming that's what reaffectation is) matrices. </div><div><br></div><div><br>On Jun 15, 2011, at 8:17 PM, "Nicolas Heslot" <<a href="mailto:nh269@cornell.edu">nh269@cornell.edu</a>> wrote:<br><br></div><div></div><blockquote type="cite"><div>Well,<br><br>That's sound good,<br>The distribution I need are multivariate normal, inverse gaussian.<br>Though, the biggest issue is that for one of the parameter there is no closed form so I am using Metropolis Hastings for it.<br>
Any idea about this variable reaffectation thing?<br>It seems to be specific to arma classes like arma::mat<br><br>Nicolas<br><br><div class="gmail_quote">On Wed, Jun 15, 2011 at 8:10 PM, Whit Armstrong <span dir="ltr"><<a href="mailto:armstrong.whit@gmail.com"><a href="mailto:armstrong.whit@gmail.com">armstrong.whit@gmail.com</a></a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">I'm not giving up yet. I'll implement the distribution that is<br>
missing, and send you the example if you lay out your model w/<br>
pseudocode.<br>
<font color="#888888"><br>
-Whit<br>
</font><div><div></div><div class="h5"><br>
<br>
On Wed, Jun 15, 2011 at 7:59 PM, Nicolas Heslot <<a href="mailto:nh269@cornell.edu"><a href="mailto:nh269@cornell.edu">nh269@cornell.edu</a></a>> wrote:<br>
> Hi,<br>
><br>
> Thank you for your quick answer.<br>
> Sorry that I did not explain well enought my issue.<br>
> I did not know about cppbugs but I just checked and it does not seem that I<br>
> can use it for my model because it lacks some of the distribution I need.<br>
> The fraction of code could seems obscure but it is just the updating for a<br>
> block of parameters in the model.<br>
> My problem is rather simple I think.<br>
> Once I affect a matrix to a variable I can't manage to overwrite the content<br>
> of that variable with a different matrix. I really can't figure out how to<br>
> do it.<br>
><br>
> Nicolas<br>
><br>
> On Wed, Jun 15, 2011 at 7:52 PM, Dirk Eddelbuettel <<a href="mailto:edd@debian.org"><a href="mailto:edd@debian.org">edd@debian.org</a></a>> wrote:<br>
>><br>
>> Salut Nicolas,<br>
>><br>
>> On 15 June 2011 at 17:03, Nicolas Heslot wrote:<br>
>> | Hi rcpp-devel!<br>
>> | First of all thank you for this awesome tool!<br>
>><br>
>> Pleasure, and welcome.<br>
>><br>
>> | I started a few days ago coding with Rcpp to try to reduce the computing<br>
>> time<br>
>> | of a MCMC model.<br>
>> | However, I don't have experience with C/C++ and I can't figure out how<br>
>> to<br>
>> | reaffect a new content to a variable.<br>
>> | This seems probably very simple to you but I can't figure it out, and<br>
>> this is<br>
>> | the last step preventing my code to work out I think...<br>
>> | The objects all_ui, all_ui2, all_ui3, all_rd and all_corMat are list<br>
>> objects<br>
>> | containing matrix<br>
>> | But once a matrice extracted from one of those lists is affected, to let<br>
>> say<br>
>> | the object ui I can't affect the next matrix to ui at the next<br>
>> iteration.<br>
>> | I tried to find a way to eliminate the object at each iteration or to<br>
>> empty it<br>
>> | using .reset but without success.<br>
>> |<br>
>> | So any help would be very much appreciated!<br>
>> | (fragment of code posted below)<br>
>> |<br>
>> | arma::mat tmp;<br>
>> | arma::mat tmp2;<br>
>> | arma::mat tmp3;<br>
>> | arma::mat ui;<br>
>> | arma::mat ui2;<br>
>> | arma::mat ui3;<br>
>> | arma::mat sigma;<br>
>> |<br>
>> | for (int j = 0; j < P-1; j++) {<br>
>> | tmp2.fill(0);<br>
>> | tmp3.fill(0);<br>
>> | for (int i = 0; i < N-1; i++) {<br>
>> | ui = all_ui[i];<br>
>> | ui2 = all_ui2[i];<br>
>> | ui3 = all_ui3[i];<br>
>> | rdi = all_rd[i];<br>
>> | all_corMati = all_corMat[i];<br>
>> | sigma = sigma2*all_corMat[i];<br>
>> | // calculate mean and variance<br>
>> | arma::mat tmp = (solve(sig%all_corMat[i])* gen_a(i,j))*all_ui[i];<br>
>> | arma::mat tmp2 += (all_rd[i] -<br>
>> mu*trans(all_ui3[i])-(X(i)*alpha)*trans(all_ui2<br>
>> | [i]) + gen_a(i,j)*a.row(j)*trans(all_ui[i]))*tmp;<br>
>> | arma::mat tmp3 += (gen_a(i,j)*trans(all_ui[i]))*tmp;<br>
>> | }<br>
>> | }<br>
>> |<br>
>> | Thank you for your help<br>
>><br>
>> I'm with Whit here and confess that I do not know your question is. If you<br>
>> show us what you tried, what you expected to happen and what actually<br>
>> happened we may help.<br>
>><br>
>> (By the way, there is no tax on indentation in code and it does make it<br>
>> more<br>
>> readable for those of us who didn't write it ;-)<br>
>><br>
>> Dirk<br>
>><br>
>> | It probably does not help much<br>
>> | but I use R2.13 with the last version of the packages on a windows XP<br>
>> plateform<br>
>> |<br>
>> | Nicolas<br>
>> |<br>
>> |<br>
>> | ----------------------------------------------------------------------<br>
>> | _______________________________________________<br>
>> | Rcpp-devel mailing list<br>
>> | <a href="mailto:Rcpp-devel@lists.r-forge.r-project.org"><a href="mailto:Rcpp-devel@lists.r-forge.r-project.org">Rcpp-devel@lists.r-forge.r-project.org</a></a><br>
>> | <a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" target="_blank"><a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a></a><br>
>><br>
>> --<br>
>> Gauss once played himself in a zero-sum game and won $50.<br>
>> -- #11 at <a href="http://www.gaussfacts.com" target="_blank"><a href="http://www.gaussfacts.com">http://www.gaussfacts.com</a></a><br>
><br>
><br>
> _______________________________________________<br>
> Rcpp-devel mailing list<br>
> <a href="mailto:Rcpp-devel@lists.r-forge.r-project.org"><a href="mailto:Rcpp-devel@lists.r-forge.r-project.org">Rcpp-devel@lists.r-forge.r-project.org</a></a><br>
> <a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" target="_blank"><a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a></a><br>
><br>
><br>
</div></div></blockquote></div><br>
</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>Rcpp-devel mailing list</span><br><span><a href="mailto:Rcpp-devel@lists.r-forge.r-project.org">Rcpp-devel@lists.r-forge.r-project.org</a></span><br><span><a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a></span><br></div></blockquote></body></html>