lundi 25 mars 2019

How to compute (negative binomial) distribution PDF and CDF in C++?

STD has many distributions, that apparently are used to generate pseudo random variables, see e.g. below code that generates and outputs some negative binomial distributed numbers.

Now this might mean that internally, there is code that computes the CDF and or PDF of the negative binomial distribution, i.e. the probability that the random variable takes on a certain value, e.g. 6. Is there a way to output that probability? If yes, how? I know I could run my own code for that, but I'd rather not do that if it there is some way to get the probabilities from std.

If possible, same question for other distributions, e.g. CDF of gamma distribution.

int main()
{
   std::negative_binomial_distribution<int> negBin{ 5,0.5 };//Negative binomial distribution
   std::mt19937 RNG(260783);//Random generator
   for (size_t i = 0; i < 4; i++)
   {
        std::cout << negBin(RNG) << std::endl;
   }
   return 0;
}




Aucun commentaire:

Enregistrer un commentaire