This guy has it GitHub - tk2lab/logbesselk: Provide function to calculate the modified Bessel function of the second kind and its derivatives.. I tried porting to R but I wasn’t able to get the same answers.
@Bob_Carpenter @spinkney @andrjohns
Thank you for the reply.
I gather Bessel functions with real order are hard to implement. I think I will have to wait for 1F1 or 0F1 to get implemented.
Thanks for the reminder! The PR for the pFq gradient calculations should be merged soon, once that’s in I’ll be adding the remaining hypergeometric functions from Boost
Hi @andrjohns ,
Thank you so much for working on this. I really appreciate it.
I am working on two projects where pFq turns up. One on N-mixture models that uses pFq and one on local adaptation which uses 1F1. It would be extremely helpful to have both pFq and 1F1 functions. I wrote my own implementation here, but they are very slow.
If you are looking for a case study that uses pFq, I can provide my code on the N-mixture model. These models are widely used in ecology. Having native implementation of pFq and grad_pFq in Stan would speed up these models by orders of magnitude.
Hi @andrjohns
I saw that the grad_pFq just got merged. Can I request that 1F1 or 0F1 functions be available for users in the next release? I completely understand if you do not have time to get these functions in time.
In my postdoc project, I call these functions 5 million times. My current implementation of the function as a truncated power series gets the job done but only works on 1/25th of the dataset, even after running the model on a cluster using map_rect.
Thank you so much for your time.
Note that once the function is in Stan math, it is relatively easy to use it in Stan even if it was not yet “officially” exposed to users. You need to:
- obtain a version of cmdstan (or other interface you are using) with the new version of Stan math (e.g. from the development branch). If this doesn’t yet exist, you can fork the repo and update the math reference yourself
- create a C++ function that just calls the Stan math implementation (see Using external C++ code)
I tried following the links, but I do not understand Stan, constant, and C++ enough that I can recreate a working code.
This may be too much to ask. Can you provide a working example of how to include hypergeometric functions (including their gradients) in a stan script?
Thanks in advance
Unfortunately, I don’t think I’ll be able to do that in a reasonable time frame.
No worries, thank you for the quick response