Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

random

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;
}
like image 397
willem Avatar asked Mar 25 '19 08:03

willem


People also ask

How do you find the CDF of a binomial distribution?

y = binocdf( x , n , p ) computes a binomial cumulative distribution function at each of the values in x using the corresponding number of trials in n and the probability of success for each trial in p .

What is PDF of negative binomial distribution?

Given a sequence of r Bernoulli trials with probability of success p, X follows a negative binomial distribution if X = k is the number of trials needed to get to the rth success. Pdf of X. P(X = k) = (k - 1. r - 1.

What is binomial PDF and CDF?

BinomPDF and BinomCDF are both functions to evaluate binomial distributions on a TI graphing calculator. Both will give you probabilities for binomial distributions. The main difference is that BinomCDF gives you cumulative probabilities.

How do you find the negative binomial coefficient?

(the negative binomial coefficient is the left one). By definition, (−rk)∗(−1)k=(−1)k(−r)(−r−1)⋯(−r−k+1)k! =(−1)k+1r(r+1)⋯(r+k−1)k!


1 Answers

The standard doesn't specify how an implementation should implement the distribution, other than that sampling from it should take an amortised constant number of samples from the Generator.

None of the members provide either the CDF or PDF

like image 159
Caleth Avatar answered Nov 12 '22 15:11

Caleth