jwindle / BayesLogit

The R Package BayesLogit
GNU General Public License v3.0
14 stars 6 forks source link

Use of Pólya-Gamma generator #8

Open GuidoAMoreira opened 3 years ago

GuidoAMoreira commented 3 years ago

Dear BayesLogit maintainers. Hello, I am currently developing an R package for the model from my PhD thesis (in Statistics) and there is one step where one of the full conditionals is actually a logistic regression. So I want to use the PG data augmentation to draw from the full conditional without resorting to a Metropolis-Hastings step. However the algorithm is particularly heavy and I am doing all the calculations at the C++ level, so I can't really use the wrapper function in your package.

I would prefer to include the class you use in the BayesLogit package than copy-pasting the code into my own. I wonder if you would expose the class so that I could include the header properly.

Thank you for your time.

zoj613 commented 3 years ago

Hi @GuidoAMoreira , I am not a maintainer of this package, but maybe I can be of help. I recently wrote a C implementation of the authors' paper that is also python friendly. If you don't mind using C code in your C++ source then maybe https://github.com/zoj613/polya-gamma might be of use, until the authors respond. There is an example in one the directories showing how it can be used in C code.

jwindle commented 3 years ago

The old version of the repository had this sort of capability, but getting that to work now would probably be somewhat annoying.

The src directory should have almost all the code you need ( https://github.com/jwindle/BayesLogit/tree/master/src).

I think all you would need to do for a C++ implementation is replace the macros in the simple_RNG_wrapper.h file: ( https://github.com/jwindle/BayesLogit/blob/master/src/simple_RNG_wrapper.h) with an appropriate C implementation, like using GNU GSL. Though, that would probably require using a global random number generator.

(You can see how that might work here: https://github.com/jwindle/RNG/blob/master/GRNG.cpp)

On Fri, Jan 8, 2021 at 2:47 PM zoj613 notifications@github.com wrote:

Hi @GuidoAMoreira https://github.com/GuidoAMoreira , I am not a maintainer of this package, but maybe I can be of help. I recently wrote a C implementation of the authors' paper that is also python friendly. If you don't mind using C code in your C++ source then maybe https://github.com/zoj613/polya-gamma might be of use, until the authors respond.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/jwindle/BayesLogit/issues/8#issuecomment-756990750, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACJWSASSYHQOSNTO6W6Q4DSY5VN5ANCNFSM4V25MGQQ .

GuidoAMoreira commented 3 years ago

Thank you both for your comments. I will study the codes you mentioned and adapt it to my case. I'll comment in case I have trouble (I'm a beginner in C++ still). You're very kind.