1

There is something I didn't understand. I use the sample given from the cpp reference to generate numbers:

const int nrolls = 10; // number of experiments std::default_random_engine generator; std::poisson_distribution<int> distribution(4.1); for (int i=0; i<nrolls; ++i){ int number = distribution(generator); cout<<number<<" "<<endl; } 

(original code: http://www.cplusplus.com/reference/random/poisson_distribution/ )

This outputs: 2 3 1 4 3 4 4 3 2 3 and so on... First of all what those numbers mean? I mean do I have to sum them to create timing? For example: 2, (2+3)=5, (5+1)=6, (6+4)=10,..., and so on..

Secondly, my real question is, I need to produce both random arrivals for network packets and the size of packets. I mean, when the packets come and if packets come, what are the size of packets? How can I do that? I need something like that: http://i.hizliresim.com/dWmaGX.png

3
  • What do you mean by "what do they mean"? They're simply numbers picked from a Poisson distribution. Commented Jan 29, 2015 at 23:46
  • @OliverCharlesworth I mean they don't seem like the numbers to create arrival times? What I am missing? Commented Jan 29, 2015 at 23:49
  • that's not an example from cpp reference, that's an example from cplusplus.com. cppreference example is here Commented Jan 30, 2015 at 4:41

2 Answers 2

6

I'm afraid that the way that you generate an arrival times via a Poisson process is not correct. Poisson process is not the Poisson distribution.

Generating arrival times via Poisson Process does not mean using a Poisson distribution as you do in your code. 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 <iostream> #include <iterator> #include <random> 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<double> 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

Sign up to request clarification or add additional context in comments.

Comments

1

[Explanation about Poisson distribution which may help you for better understanding]

The meaning of "Poisson distribution" and the function of "std::poisson_distribution()" are tightly related but not same.

The Poisson distribution is a discrete probability distribution. You can calculate probabilities like probability of no packet comes in next period (one second for example) is 0.002, that of one packets is 0.075, that of two packets is 0.15, that of three packets is 0.20, and so on when average arrival is 4. (values of possibility I used are samples(not real value)) Total of probabilities that for 0 packets to infinite packets becomes 1.0 always.

std::poisson_distribution() returns numbers of packets for each period which the average of those in long periods equals to average (4.1 in your code) and their distribution is the Poisson distribution.

You can calclate that by following steps.

  1. Make table of number_of_packet and probability.

  2. Make a random number between 0 to 1.

  3. Sum up probabilitys in the table until the sum becomes larger than the random number.

  4. (number of probabilitiys used to sum up)-2 is the value.

Example: If you get 0.3 as random number.

The sum of probabilitys of no packet to two packets are 0.002+0.075+0.15= 0.227 is smaller than 0.3.

The sum of probabilitys of no packet to three packets are 0.002+0.075+0.15+0.20= 0.427 is larger than 0.3.

Then 'two packets' is used for next value.

This is an illustration what happened in std::poisson_distribution().

[Direct answer for your question:How to make packets arrivals in Poisson distribution]

I assume a period is one second for easy understanding.

outputs: 2 3 1 4 3 4 4 3 2 3 you got are number of packets of each seconds, two packets in first second, three packets in 2nd second, one packet in 3rd seconds, and so on.

You can make arrivals by placing packets evenly in that second.

[Example for outputs: 2 3 1]

Time 0s - 1s

Two packets arrives. Divide 1 second by 2 (two 0.5s period), and place packets in middle of them. => 1st packet is placed at 0.25s, and 2nd is at 0.75s.

Time 1s - 2s

Therre packets arrives. Divide 1 second by 3, and place packets in middle of them. => 1st packet is placed at 1.166s, 2nd is at 1.5s, 3rd is at 1.833.

...and so on.

0.25, 0.75, 1.166, 1.5, 1.833 are arrival time of first five packets which comes from the 'outputs: 2 3' you got.

===== Size of packet is another issue.

You should determine what distribution is used for packet size.

I don't think Poisson distribution is suitable for packet size.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.