[Rd] Error in simulation. NAN
Hi all, im triyng to implement a bayesian model with R and c++. I have a strange problem. I can't reproduce the error with a small script and then i post the original one. The problem is after the line for(MCMC_iter2=0;MCMC_iter2For the first 34 iterations all work fine, after, all the simulations of mu_acc_P return an "nan". If i delete the line alpha_acc_P[0] = rnorm(app1_3,sqrt(app1_4) ); the simulations of mu_acc_P work fine. For me it is really strange, Thanks!. #include #include using namespace std; #include #include #include #include #include #include "funzioni.h" #define _USE_MATH_DEFINES extern "C" { SEXP Model1_imp11Cpp( SEXP ad_start_r, SEXP ad_end_r, SEXP ad_esp_r, SEXP burnin_r, SEXP thin_r,SEXP iter_1_r,SEXP iter_2_r, SEXP n_j_r,SEXP J_r, SEXP prior_alpha_r,SEXP prior_rho_r,SEXP prior_sigma2_r,SEXP prior_phi_r,SEXP prior_zeta2_r, SEXP sdprop_rho_r,SEXP sdprop_sigma2_r, SEXP start_alpha_r,SEXP start_mu_r,SEXP start_rho_r,SEXP start_sigma2_r,SEXP start_k_r,SEXP start_phi_r, SEXP start_zeta2_r, SEXP x_r,SEXP H_r, SEXP acceptratio_r // SEXP Sigma_adapt_sp_r, SEXP mean_adapt_sp_r, SEXP sim_acc_sp_r, SEXP ep_sp_r, SEXP acc_index_sp_r, // SEXP Sigma_adapt_k_r, SEXP mean_adapt_k_r, SEXP sim_acc_k_r, SEXP ep_k_r, SEXP acc_index_k_r // ){ /* Varie ed eventuali */ // indici int i,j,k,l,h,t,f,info,MCMC_iter,MCMC_iter2; int nProtect= 0; int indice_adapt=0; double duepi = (2*M_PI); // costanti char const *lower = "L"; char const *upper = "U"; char const *ntran = "N"; char const *ytran = "T"; char const *rside = "R"; char const *lside = "L"; const double one = 1.0; const double negOne = -1.0; const double zero = 0.0; const int incOne = 1; /* Set-up */ double *x_P = REAL(x_r); int n_j = INTEGER(n_j_r)[0]; int J= INTEGER(J_r)[0]; int N = n_j*J; int iter_1 = INTEGER(iter_1_r)[0]; int iter_2 = INTEGER(iter_2_r)[0]; int burnin = INTEGER(burnin_r)[0]; int thin = INTEGER(thin_r)[0]; int ad_start = INTEGER(ad_start_r)[0]; int ad_end = INTEGER(ad_end_r)[0]; double *ad_esp_P = REAL(ad_esp_r); double *acceptratio_P = REAL(acceptratio_r); double *H_P = REAL(H_r); // int nSamples_save = INTEGER(nSamples_save_r)[0]; // PRIOR double *prior_alpha = REAL(prior_alpha_r); double M_alpha = prior_alpha[0]; double sigma2_alpha = prior_alpha[1]; double *prior_rho = REAL(prior_rho_r); double a_rho = prior_rho[0];double b_rho = prior_rho[1]; double *prior_sigma2 = REAL(prior_sigma2_r); double a_sigma2 = prior_sigma2[0]; double b_sigma2 = prior_sigma2[1]; double *prior_zeta2 = REAL(prior_zeta2_r); double a_zeta2 = prior_zeta2[0]; double b_zeta2 = prior_zeta2[1]; double *prior_phi = REAL(prior_phi_r); double M_phi= prior_phi[0]; double sigma2_phi = prior_phi[1]; double lim_down= prior_phi[2]; double lim_up = prior_phi[3]; // PROPOSAL double *sdprop_rho = REAL(sdprop_rho_r); double sd_rho = sdprop_rho[0]; double *sdprop_sigma2 = REAL(sdprop_sigma2_r); double sd_sigma2 = sdprop_sigma2[0]; // STARTING double *start_alpha_P = REAL(start_alpha_r); double start_alpha = start_alpha_P[0]; double *start_mu_P = REAL(start_mu_r); // for(j=0;jF77_NAME(dcopy)(&incOne, start_sigma2_P, &incOne, sigma2_acc_P, &incOne); // rho double *rho_acc_P = (double *) R_alloc(1, sizeof(double)); F77_NAME(dcopy)(&incOne, start_rho_P, &incOne, rho_acc_P, &incOne); // k double *k_acc_P = (double *) R_alloc(n_j*J, sizeof(double)); F77_NAME(dcopy)(&incN, start_k_P, &incOne, k_acc_P, &incOne); // variabili di appoggio per i parametri double *mu_app_P = (double *) R_alloc(J, sizeof(double)); F77_NAME(dcopy)(&incJ, start_mu_P, &incOne, mu_app_P, &incOne); /* // OUTPUT di R */ SEXP mu_out_r,alpha_out_r; PROTECT(mu_out_r = allocMatrix(REALSXP, J, nSamples_save)); nProtect++; double *mu_out_P = REAL(mu_out_r); PROTECT(alpha_out_r = allocMatrix(REALSXP, 1, nSamples_save)); nProtect++; double *alpha_out_P = REAL(alpha_out_r); // // PROTECT(accept_r = allocMatrix(REALSXP, 1, 1)); nProtect++; /* Varie ed eventuali III */ // MATRICI COVARIANZA E AFFINI double *C_P = (double *) R_alloc(nn_j, sizeof(double)); double *C_cand_P = (double *) R_alloc(nn_j, sizeof(double)); double Sum_Sig
Re: [Rd] libR.so: cannot open shared object file
Can you add some details? Suppose i have the package Model.tar.gz and my writable are is in user/area, what i have to do next to install the package? Il 04/09/13 00:04, Geoff Jentry ha scritto: One problem is that i have not the privileges to install a package. If you have a writable area you can install to there with the --library=LIB argument and then load the package using the lib.loc command. __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] libR.so: cannot open shared object file
Hi all I have a R code that incorporates a C++ programm. I compiled the C++ code with the following: R CMD SHLIB Model.cpp -Wall funzioni.cpp it seems to work fine but when i run the R code i get this error message Error in dyn.load(paste(dir_func, "Model.so", sep = "")) : unable to load shared object '/lustre/work/uuu/RCpp/Model.so': libR.so: cannot open shared object file: No such file or directory I don't know how to fix it. The code is running on a cluster. Thanks. __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] libR.so: cannot open shared object file
One problem is that i have not the privileges to install a package. Il 03/09/13 23:14, Dirk Eddelbuettel ha scritto: On 3 September 2013 at 22:48, gianluca.mastranto...@yahoo.it wrote: | Hi all | | I have a R code that incorporates a C++ programm. I compiled the C++ | code with the following: | | R CMD SHLIB Model.cpp -Wall funzioni.cpp | | it seems to work fine but when i run the R code i get this error message | | Error in dyn.load(paste(dir_func, "Model.so", sep = "")) : |unable to load shared object '/lustre/work/uuu/RCpp/Model.so': |libR.so: cannot open shared object file: No such file or directory | | I don't know how to fix it. | The code is running on a cluster. Qualified guess: you ran R CMD SHLIB on the _central / master_ node, but not the _compute_ nodes. They never got the object file. One more rigorous approach would be to wrap your function up in a package, and have each compute node load the package. Hope this helps, Dirk __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] libR.so: cannot open shared object file
First of all, thanks for your help. I did all the things you told me. I was able to load the library, but then Error in dyn.load(file, DLLpath = DLLpath, ...) : unable to load shared object '/lustre/work/gjona2/Wrap/BayesWrap/libs/BayesWrap.so': libR.so: cannot open shared object file: No such file or directory In addition: Warning message: package 'BayesWrap' was built under R version 2.15.2 Error: package/namespace load failed for 'BayesWrap' Execution halted what does it means? G.M. Il 04/09/13 22:42, Prof Brian Ripley ha scritto: On 04/09/2013 19:58, Geoff Jentry wrote: Can you add some details? Suppose i have the package Model.tar.gz and my writable are is in user/area, what i have to do next to install the package? What I was picturing was something like this (forgive me if syntax isn't 100%): mkdir user/area/myRLib R CMD INSTALL --library=user/area/myRLib Model.tar.gz and then in R: library(Model, lib.loc="user/area/myRLib") Note though Brian Ripley's response to me where he indicates that this is handled automatically. Yes, install.packages("Model.tar.gz") should suffice. -J __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] libR.so: cannot open shared object file
just for completion i need to use library(Model, lib.loc="user/area/myRLib") because if i use library(Model) i get this message Error in library("BayesWrap") : there is no package called 'BayesWrap' Il 05/09/13 11:59, gianluca.mastranto...@yahoo.it ha scritto: First of all, thanks for your help. I did all the things you told me. I was able to load the library, but then Error in dyn.load(file, DLLpath = DLLpath, ...) : unable to load shared object '/lustre/work/gjona2/Wrap/BayesWrap/libs/BayesWrap.so': libR.so: cannot open shared object file: No such file or directory In addition: Warning message: package 'BayesWrap' was built under R version 2.15.2 Error: package/namespace load failed for 'BayesWrap' Execution halted what does it means? G.M. Il 04/09/13 22:42, Prof Brian Ripley ha scritto: On 04/09/2013 19:58, Geoff Jentry wrote: Can you add some details? Suppose i have the package Model.tar.gz and my writable are is in user/area, what i have to do next to install the package? What I was picturing was something like this (forgive me if syntax isn't 100%): mkdir user/area/myRLib R CMD INSTALL --library=user/area/myRLib Model.tar.gz and then in R: library(Model, lib.loc="user/area/myRLib") Note though Brian Ripley's response to me where he indicates that this is handled automatically. Yes, install.packages("Model.tar.gz") should suffice. -J __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] libR.so: cannot open shared object file
Thank you, now all works well. G.M. Il 06/09/13 15:28, brian avants ha scritto: > Hello Everyone > > I have been following this thread because I have similar issues with > an outside-of-R package. The problem is related to dylib loading > i.e. of the form > > Error in dyn.load(file, DLLpath = DLLpath, ...) : > unable to load shared object > '/Users/stnava/code/gitANTs/ANTsR/src/ANTS/ANTS-build/lib/ANTsR/libs/libRantsRegistration.so': > dlopen(/Users/stnava/code/gitANTs/ANTsR/src/ANTS/ANTS-build/lib/ANTsR/libs/libRantsRegistration.so, > > 6): Library not loaded: libitkdouble-conversion-4.5.1.dylib > Referenced from: > /Users/stnava/code/gitANTs/ANTsR/src/ANTS/ANTS-build/lib/libl_antsRegistration.dylib > Reason: image not found > > A solution that seems to work on both osx and linux is: > > export > R_LD_LIBRARY_PATH=/Users/stnava/code/gitANTs/ANTsR/src/ANTS/ANTS-build/lib/ > > but I would really like to avoid this, if possible.I tried using > .libPaths ( suspecting it would not work ) and I got the same error as > above ... > > as an aside, there seems very little documentation for > R_LD_LIBRARY_PATH & I don't recall how I came across it ... i have > some other notes here: > > https://github.com/stnava/ANTsR/blob/master/configure > > any thoughts appreciated , at your leisure ... > > & thanks, as usual, > > > > brian > > > > > On Thu, Sep 5, 2013 at 4:38 PM, Prof Brian Ripley > mailto:rip...@stats.ox.ac.uk>> wrote: > > On 05/09/2013 21:28, gianluca.mastranto...@yahoo.it > <mailto:gianluca.mastranto...@yahoo.it> wrote: > > just for completion > > i need to use > library(Model, lib.loc="user/area/myRLib") > because if i use > library(Model) > i get this message > Error in library("BayesWrap") : there is no package called > 'BayesWrap' > > > For the record: not if you follow my suggestion. > > See ?.libPaths for why. > > > > > > Il 05/09/13 11:59, gianluca.mastranto...@yahoo.it > <mailto:gianluca.mastranto...@yahoo.it> ha scritto: > > First of all, thanks for your help. > > I did all the things you told me. I was able to load the > library, but > then > > Error in dyn.load(file, DLLpath = DLLpath, ...) : > unable to load shared object > '/lustre/work/gjona2/Wrap/BayesWrap/libs/BayesWrap.so': > libR.so: cannot open shared object file: No such file or > directory > In addition: Warning message: > package 'BayesWrap' was built under R version 2.15.2 > Error: package/namespace load failed for 'BayesWrap' > Execution halted > > what does it means? > > G.M. > > Il 04/09/13 22:42, Prof Brian Ripley ha scritto: > > On 04/09/2013 19:58, Geoff Jentry wrote: > > Can you add some details? > Suppose i have the package Model.tar.gz and my > writable are is in > user/area, what i have to do next to install > the package? > > > What I was picturing was something like this > (forgive me if syntax > isn't > 100%): > > mkdir user/area/myRLib > R CMD INSTALL --library=user/area/myRLib Model.tar.gz > > and then in R: > library(Model, lib.loc="user/area/myRLib") > > Note though Brian Ripley's response to me where he > indicates that this > is handled automatically. > > > Yes, install.packages("Model.tar.gz") should suffice. > > > -J > > __ > R-devel@r-project.org > <mailto:R-devel@r-project.org> mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel > > > > > > > > -- > Brian D. Ripley, rip...@stats.ox.ac.uk <mailto:rip...@stats.ox.ac.uk> > Professor of Applied Statistics, > http://www.stats.ox.ac.uk/~ripley/ > <http://www.stats.ox.ac.uk/%7Eripley/> > University of Oxford, Tel: +44 1865 272861 > (self) > 1 South Parks Road, +44 1865 272866 (PA) > Oxford OX1 3TG, UKFax: +44 1865 272595 > > > __ > R-devel@r-project.org <mailto:R-devel@r-project.org> mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel > > [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel