Thread: Programming Poisson Distribution :: C++

  1. #1
    Registered User
    Join Date
    Nov 2001

    Programming Poisson Distribution :: C++


    I would like to design a function that will return a random number based on Poisson Distribution. Here is an example of a problem I want to solve using this function.

    Given: One car passes through an intersection every 5 minutes.

    Question: Determine the time of arrival of each car based on the time of the last car in 30 days. For example:

    Start: t = 0
    car1: t += 4 -> (t would then equal 4 : t = 4)
    car2: t += 4.8 -> (t = 8.8)
    car3: t += 3.2
    car4: t += 4.6
    car5: t += 5.3
    car6: t += 4.9

    Given a start time of 0, I want this function to calculate the arrival time of every car from there on relative to the previous car. This is based on Poisson Distribution.

    Please post if you have any idea on this problem.


  2. #2
    Registered User
    Join Date
    Jun 2002


    A lot of people might be familiar with Poisson's Distribution - much like me. Those with some statistics knowledge might want a short explanantion : go to .

    If my understanding of the problem is accurate (maybe it is not ; sorry then), here's how I'd do it :

    1. Start at t=0.
    2. Calculate probability for a set number of points, say numerous points starting your initial time, at a 0,1 interval (since times had a precision of 0.1 in your example problem).
    Ex.: the formula is P(x) = u^x e^-u / x!. In this case, u = 5. So you calculate for x = 0, x = 1, etc. , until the total probability would get near 1 (getting to 0,999999 should be enough).
    3. Get yourself a good pseudorandom number generator. Get a random number between 0 and 1. Interpolate the result with answers found in 2. The nearest value to that number would then be your time.
    4. Get back to 2., using the t you found as your new initial time, determining new intervals. (Yep, recursive function).

    Hope I could be of any help. If I was mistaken on that, please disregard my post ; I know nothing on Poisson's distributions, only what I read from your post and that site

    Good luck.

  3. #3
    Registered User
    Join Date
    Nov 2001
    Okay. Thanks.

    I understand your algorithm up to step 3. What do you mean "interpolate" using a random number? Why is that necessary?


  4. #4
    Registered User
    Join Date
    Jun 2002
    What I meant is that the pseudorandom number you will find will most likely not be exactly one of your t's. You will need to find the value that is closer to the value you get. I admit that that particular point was not what I would call 'clear'.

    Ex.: t = 0 has P(t) = 0.006738.
    t=0.1 has P(t) = 0.007915, for a total probability of 0.01465. So, if that random number was, say, 0.006849, its corresponding (i.e. interpolated) probability would be in the range of t=0.1 . If it was higher than the total probability, then t > 0.1.

    It is necessary to use random numbers because data is not homogenous (i.e. cars don'r arrive at regular intervals).

    Hope it cleared things.
    Using Dev-C++ beta under Win XP Pro. That or g++ on Mandrake Linux 9.0 .

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. RTTI for distribution
    By coletek in forum C++ Programming
    Replies: 6
    Last Post: 09-13-2010, 10:05 AM
  2. newbie - poisson numbers
    By fireflym in forum C++ Programming
    Replies: 2
    Last Post: 10-28-2008, 05:35 AM
  3. Which distribution of Linux should I get?
    By joshdick in forum A Brief History of
    Replies: 50
    Last Post: 01-19-2003, 08:26 AM
  4. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 11:39 AM
  5. Replies: 5
    Last Post: 10-12-2001, 03:51 AM