Wald/Inverse Gaussian Distribution

326 views
Skip to first unread message

Joe Houpt

unread,
Jul 17, 2013, 10:57:43 AM7/17/13
to stan-...@googlegroups.com

I have been using the Wald/inverse Gaussian distribution in some model using the lp__ incrementing method.  In hopes of speeding things up, I adapted the code from another distribution (Weibull, I think) for the inverse Gaussian distribution.  Please let me know what I can do to make the distribution available in stan.
Thank you,
Joe
inv_gaussian.hpp

Ben Goodrich

unread,
Jul 17, 2013, 12:03:16 PM7/17/13
to stan-...@googlegroups.com
Thanks Joe. Hopefully, this indicates that adding a distribution to Stan is relatively easy if you can start with a similar distribution that is already in Stan.

There are a few more steps that need to be taken in order to incorporate this into Stan, such as writing unit tests, exposing the function to the Stan language, coding an algorithm to draw random numbers, etc. If you are interested in learning how to do this and have some familiarity with git, we can walk you through the process. If not, someone else will probably pick up your attachment and take it the rest of the way eventually.

One thing that I had mentioned on the developer list a month or so ago is that we would like to push in the direction of implementing more general distributions that have 3, 4, 5, ... parameters and include the more commonly-used distributions as special cases. Doing so provides a lot more flexibility (to the user) without much additional cost (to the developer). So, would you be willing to implement the generalized inverse Gaussian?

http://en.wikipedia.org/wiki/Generalized_inverse_Gaussian_distribution

And if you want the plain inverse Gaussian as well, just make what you have now into a one-line C++ function that calls the generalized_inverse_gaussian_log() with the appropriate restrictions on the parameters.

Thanks,
Ben

Joe Houpt

unread,
Jul 17, 2013, 2:21:03 PM7/17/13
to stan-...@googlegroups.com
Hi Ben,
I don't have any experience with git, but I am interested in the process of adding the function to Stan.  I don't mind implementing the generalized Inverse Gaussian, as long as there is already a function available to calculate the modified Bessel function. 
Thanks,
Joe

Bob Carpenter

unread,
Jul 17, 2013, 2:41:37 PM7/17/13
to stan-...@googlegroups.com
Yes, we have the modified Bessel function. It's not in
the current release of Stan, but is on the develop branch
in Git and will be in Stan 2.0.

You can check out our wiki for some more tips for developers.

https://github.com/stan-dev/stan/wiki

In particular, there's a discussion of the Git development process (which
is pretty daunting if you haven't used git at this point, but we
have step-by-step instructions), and a discussion of some tools that
might be helpful, and a discussion of what we need in addition to the
function itself in the way of doc, tests, and symbol table manipulation.

There are two ways to implement a new distribution. The efficient,
vectorized way is illustrated with most of our distributions. You can
also just template out the arguments and write the function itself without
calculating derivatives by hand. It'll be quite a bit (maybe a factor of 2 to 10),
slower, but it might be a good place to start to get something working right
away -- it's always easy to go from working to optimized than the other way
around.

- Bob
> --
> You received this message because you are subscribed to the Google Groups "stan users mailing list" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Ben Goodrich

unread,
Jul 17, 2013, 2:53:14 PM7/17/13
to stan-...@googlegroups.com
That is great! If you want to learn a bit of git, that would be great (and probably a good investment of time if you are now or ever in the future involved with other software projects). Bob's post has a link and some explanations. But honestly, if you get too frustrated with git or the whole process, just attach the .hpp implementation files and the .cpp testing files to a post and someone will commit them for you.

Thanks,
Ben
Reply all
Reply to author
Forward
0 new messages