You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm wondering if there is enough interest in an equivalent R package.
The motivation would be that the existing R packages implementing the distribution do not also include functions for the CDF and density (as far as im aware). So maybe qpolyagamma and dpolyagamma would be useful for R users? Speed could also be a motivator?
The C library can be used to write a polyagamma sampler wrapper for any modern language that has support for C-extensions. The only thing it would need to implement separately is a bitgenerator to be used for random number generation and C implementations of random_gamma, random_standard_exponential and random_standard_normal. Both of the 2 requirements can be met fairly easily for an R extension by vendoring numpy's implementations found here and using the Xoroshiro128plus bitgenerator implementantion found in the C example. Nothing would need to modified in the C source of the library since the aforementioned functions are used via forward declaration and not included explicitly via header files.
If this R wrapper would be written, I think the following steps would be likely taken:
create a seperate repo to house the R package.
use this repo's C library (include and src folders) as a sub-module.
add a distiributions.c file that vendors the random_gamma, random_standard_exponential and random_standard_normal implementations from numpy. Alternatively , other implementations could be used, but they would likely be slower.
make sure the bitgen struct definition is available somewhere in the source:
Have a copy of bitgenerator implementation in the source, similar to what is in the C example.
Write the r_wrapper.c code to make the C code available in R. See here for an example.
Write the actual R implementations of ppolyagamma, dpolyagamma and qpolyagamma that call the C library functions. Due to R's design of random generation, we would need a polyagamma_set_seed utility function for setting the global seed.
Optionally, this python interface which accepts a random_state parameter could be replicated fairly easily, but I dont think R users would like this kind of API.
NOTE: Something similar would be done if someone were to attempt to write a wrapper for another language like Julia.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm wondering if there is enough interest in an equivalent R package.
The motivation would be that the existing R packages implementing the distribution do not also include functions for the CDF and density (as far as im aware). So maybe
qpolyagammaanddpolyagammawould be useful for R users? Speed could also be a motivator?The C library can be used to write a polyagamma sampler wrapper for any modern language that has support for C-extensions. The only thing it would need to implement separately is a bitgenerator to be used for random number generation and C implementations of
random_gamma,random_standard_exponentialandrandom_standard_normal. Both of the 2 requirements can be met fairly easily for an R extension by vendoring numpy's implementations found here and using the Xoroshiro128plus bitgenerator implementantion found in the C example. Nothing would need to modified in the C source of the library since the aforementioned functions are used via forward declaration and not included explicitly via header files.If this R wrapper would be written, I think the following steps would be likely taken:
includeandsrcfolders) as a sub-module.distiributions.cfile that vendors therandom_gamma,random_standard_exponentialandrandom_standard_normalimplementations from numpy. Alternatively , other implementations could be used, but they would likely be slower.r_wrapper.ccode to make the C code available in R. See here for an example.ppolyagamma,dpolyagammaandqpolyagammathat call the C library functions. Due to R's design of random generation, we would need apolyagamma_set_seedutility function for setting the global seed.random_stateparameter could be replicated fairly easily, but I dont think R users would like this kind of API.NOTE: Something similar would be done if someone were to attempt to write a wrapper for another language like Julia.
Beta Was this translation helpful? Give feedback.
All reactions