How do I sample random variates from a Normal Inverse Gaussian (NIG) distribution?
I need to generate 100 numbers from the NIG distribution.
I use boost::math::inverse_gaussian but it does not have an operator() member function like std::normal_distribution
Edit: Hörmann, W., Leydold have been doing some research into this topic:
I don't find the inverse Gaussian distribution in Boost.Random.
You can use the so-called inverse transform sampling technique. That is, you take the inverse cdf (i.e. the quantile function) of the inverse Gaussian distribution, and you apply it to a sample of uniformly random numbers in (0,1).
Something like that:
boost::math::inverse_gaussian my_ig(2, 3);
double inverseCDFig(double p){
return boost::math::quantile(my_ig, p);
}
Then you use std::uniform_real_distribution to generate uniformly random numbers between 0 and 1, say u[i]
for i = 0; i < N
, and you compute inverseCDFig(u[i])
for every i
. In this way you get a random sample from the inverse Gaussian distribution.