[math/distributions/poisson] extract Poisson-distributed random variate?

I've searched the Boost documentation and mail archive, but I can't find an example for extracting a random variate from a Poisson distribution. What I want to do is similar to extracting a variate from a uniform distribution, such as the C++ rand() function, which returns a single random variate on the range [0, RAND_MAX]. Is there a way to do something similar using the Poisson distribution with a given mean? For example, something like this: double n, lambda(0.30); //lambda is the mean of the Poisson n = poisson_rand(lambda); Thanks, Mike

Michael Fuller wrote:
I've searched the Boost documentation and mail archive, but I can't find an example for extracting a random variate from a Poisson distribution. What I want to do is similar to extracting a variate from a uniform distribution, such as the C++ rand() function, which returns a single random variate on the range [0, RAND_MAX].
Is there a way to do something similar using the Poisson distribution with a given mean? For example, something like this:
double n, lambda(0.30); //lambda is the mean of the Poisson n = poisson_rand(lambda);
Try boost/random/poisson_distribution.hpp, unfortunately appears not to be documented, but usage is the same as the other distributions in Boost.Random. HTH, John.

John Maddock <john <at> johnmaddock.co.uk> writes:
Try boost/random/poisson_distribution.hpp, unfortunately appears not to be documented, but usage is the same as the other distributions in Boost.Random.
HTH, John.
Excellent, thanks John. Walking home last night I realized that another approach might be to use a uniform random number as the argument to the pdf function. Mike

Michael Fuller wrote:
John Maddock <john <at> johnmaddock.co.uk> writes:
Try boost/random/poisson_distribution.hpp, unfortunately appears not to be documented, but usage is the same as the other distributions in Boost.Random.
HTH, John.
Excellent, thanks John. Walking home last night I realized that another approach might be to use a uniform random number as the argument to the pdf function.
Um, argument to the quantile function surely? John.

John Maddock <john <at> johnmaddock.co.uk> writes:
Um, argument to the quantile function surely?
Oops, yes, the quantile function. I eventually found what I was looking for in some code written by Joaquín M López Muñoz. For the sake of closure, here is an example: //Generate a Poisson-distributed random variate given a //specific mean value): #include <boost/random.hpp> #include <boost/random/poisson_distribution.hpp> #include <boost/random/variate_generator.hpp> #include <boost/random/mersenne_twister.hpp> #include <boost/random/uniform_int.hpp> #include <boost/random/uniform_smallint.hpp> #include <iostream> using namespace std; using namespace boost::random; int main() { double lambda(10); //mean of Poisson distr boost::mt19937 rnd_gen; //Mersenne Twister generator typedef boost::variate_generator< boost::mt19937, boost::poisson_distribution<> > rnd_poisson_t; rnd_poisson_t rnd_poisson( rnd_gen, boost::poisson_distribution<>( lambda )); rnd_poisson = rnd_poisson_t( rnd_gen, boost::poisson_distribution<>( lambda )); cout << "\nFive Poisson-distributed random numbers\n"; for(int i = 0; i < 5; i++) { cout << rnd_poisson() << endl; } return 0; }
participants (2)
-
John Maddock
-
Michael Fuller