How do I generate a Poisson Process?

后端 未结 8 2010
被撕碎了的回忆
被撕碎了的回忆 2021-02-20 06:07

Original Question:

I want to generate a Poisson process. If the number of arrivals by time t is N(t) and I have a Poisson distribution with parameter

8条回答
  •  感动是毒
    2021-02-20 06:49

    Generating arrival times via Poisson Process does not mean using a Poisson distribution. It is done by creating an exponential distribution based on the Poisson arrival rate lamda.

    In short, you need to generate an exponential distribution with an average = 1/lamda, see the following example:

    #include 
    #include 
    #include 
    
    int
    main ()
    {
     // seed the RNG
     std::random_device rd; // uniformly-distributed integer random number generator
     std::mt19937 rng (rd ()); // mt19937: Pseudo-random number generation
    
     double averageArrival = 15;
     double lamda = 1 / averageArrival;
     std::exponential_distribution exp (lamda);
    
    double sumArrivalTimes=0;
    double newArrivalTime;
    
    
     for (int i = 0; i < 10; ++i)
      {
       newArrivalTime=  exp.operator() (rng); // generates the next random number in the distribution 
       sumArrivalTimes  = sumArrivalTimes + newArrivalTime;  
       std::cout << "newArrivalTime:  " << newArrivalTime  << "    ,sumArrivalTimes:  " << sumArrivalTimes << std::endl;  
      }
    
    }
    

    The result of running this code:

    newArrivalTime:  21.6419    ,sumArrivalTimes:  21.6419
    newArrivalTime:  1.64205    ,sumArrivalTimes:  23.2839
    newArrivalTime:  8.35292    ,sumArrivalTimes:  31.6368
    newArrivalTime:  1.82962    ,sumArrivalTimes:  33.4665
    newArrivalTime:  34.7628    ,sumArrivalTimes:  68.2292
    newArrivalTime:  26.0752    ,sumArrivalTimes:  94.3045
    newArrivalTime:  63.4728    ,sumArrivalTimes:  157.777
    newArrivalTime:  3.22149    ,sumArrivalTimes:  160.999
    newArrivalTime:  1.64637    ,sumArrivalTimes:  162.645
    newArrivalTime:  13.8235    ,sumArrivalTimes:  176.469
    

    so, based on your experiment you can either use: newArrivalTime or sumArrivalTimes.

    ref: http://www.math.wsu.edu/faculty/genz/416/lect/l05-45.pdf

提交回复
热议问题