Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Boost's pdf function

Tags:

c++

boost

Silly question but I'm spending too much time looking for answers on the web with no success. I have a boost::random::gamma_distribution object and a float value for which I would like to compute the pdf.

Which Boost modules exactly should I inlude and how to I call the function that computes a pdf for gamma?

Thanks

like image 819
user1701545 Avatar asked Sep 15 '26 22:09

user1701545


1 Answers

I have peeked at random/gamma_distribution.hpp and there isn't a method to return a pdf, so an instance of gamma_distribution won't help you. However, boost::math::gamma_distribution provides implementation notes and a formula (the table at the bottom) to define a pdf using a library function gamma_p_derivative.

Now you can put together a pdf function yourself:

#include <boost/math/special_functions/gamma.hpp>

// Makes sense for k, theta, x greater than 0.
double gamma_pdf(double k, double theta, double x) {
    return boost::math::gamma_p_derivative(k, x / theta) / theta;
}

And that's basically it. Since gamma.hpp contains the required definitions you don't have to link any additional libraries during compilation.

like image 51
Richard Pump Avatar answered Sep 18 '26 13:09

Richard Pump



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!