Using distribution functions in custom samplers

36 views
Skip to first unread message

dirkdouw...@gmail.com

unread,
Aug 10, 2022, 12:05:04 AM8/10/22
to nimble-users
Hello,

I am writing a custom sampler and I get the following error message when trying to compile the MCMC,

> printErrors()
P_6_MCMC.cpp: In member function 'virtual void nfRefClass_R_GlobalEnv60::run()':
P_6_MCMC.cpp:1108:59: error: cannot convert 'NimArr<1, double>' to 'double' for argument '2' to 'double Rf_dnbinom(double, double, double, int)'
  llen = dnbinom(Interm_763, (**model_r0), Interm_764, true);
                                                           ^
P_6_MCMC.cpp:1116:59: error: cannot convert 'NimArr<1, double>' to 'double' for argument '2' to 'double Rf_dnbinom(double, double, double, int)'
  llep = dnbinom(Interm_765, (**model_r1), Interm_766, true);
                                                           ^
At global scope:
cc1plus.exe: warning: unrecognized command line option "-Wno-ignored-attributes"
cc1plus.exe: warning: unrecognized command line option "-Wno-misleading-indentation"
make: *** [C:/PROGRA~1/R/R-36~1.3/etc/x64/Makeconf:215: P_6_MCMC.o] Error 1


This seems to imply the issue is with the following two lines of the sampler,

 llen <- dnbinom(x=model$y[loc,ct],size = model$r0 ,
                      prob = model$r0/(model$r0+model$lambda_en[loc,ct]),log =TRUE)

 llep <- dnbinom(x=model$y[loc,ct],size = model$r1 ,
                      prob = model$r1/(model$r1+model$lambda_ep[loc,ct]),log =TRUE)

I need to do some density calculations for the sampler. It works fine uncompiled. I could just try to calculate the densities manually but I am worried about numerical errors as I am not sure how to calculate these densities safely. Any idea how to get the distribution functions to work?

Thanks!

Perry de Valpine

unread,
Aug 10, 2022, 12:20:01 AM8/10/22
to dirkdouw...@gmail.com, nimble-users
Hi Dirk,

The error in saying something that should be a scalar argument is being passed as a vector.  As a quick idea, please try using model$r0[1] and model$r1[1] and let me know if that works.

-Perry 

--
You received this message because you are subscribed to the Google Groups "nimble-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nimble-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nimble-users/fa87b1e1-6fb7-45a9-96bf-a1cf81556d4bn%40googlegroups.com.

dirkdouw...@gmail.com

unread,
Aug 10, 2022, 6:44:42 PM8/10/22
to nimble-users
Thanks Perry, it works. I guess the lesson is that all model parameters are vectors even if only 1d. 

Perry de Valpine

unread,
Aug 10, 2022, 7:50:53 PM8/10/22
to dirkdouw...@gmail.com, nimble-users
Reply all
Reply to author
Forward
0 new messages