# Thread: "Inverse" of exponential distribution?

1. ## "Inverse" of exponential distribution?

I'm embarrassed that I apparently remember nothing about statistics, but I'm hoping this is a pretty simple problem:

I'm trying to simulate the arrival of people in a queue using an exponential distribution function. To sample from the PDF, I do:

x = -ln(u) * v

Where u is a uniform random variable in [0, 1) and v is a scaling factor so that E[X] = v. This gives me the expected period between people. Unfortunately, what I want is to sample expected *frequency*.

Any tips would be really useful. Or maybe I'll just go dig up my old stats books...

Thanks!

2. Originally Posted by Talisman00
I'm embarrassed that I apparently remember nothing about statistics, but I'm hoping this is a pretty simple problem:

I'm trying to simulate the arrival of people in a queue using an exponential distribution function. To sample from the PDF, I do:

x = -ln(u) * v

Where u is a uniform random variable in [0, 1) and v is a scaling factor so that E[X] = v. This gives me the expected period between people. Unfortunately, what I want is to sample expected *frequency*.

Any tips would be really useful. Or maybe I'll just go dig up my old stats books...

Thanks!
The expected frequency is 1/v

RonL

3. Originally Posted by CaptainBlack
The expected frequency is 1/v

RonL
Sorry, I probably should have worded my question more carefully: what I want is to sample from the frequency distribution (and, more generally, to know what the formula for the frequency PDF is).

Maybe that's trivial too -- I'll have to sleep on it though!

4. Originally Posted by Talisman00
Sorry, I probably should have worded my question more carefully: what I want is to sample from the frequency distribution (and, more generally, to know what the formula for the frequency PDF is).

Maybe that's trivial too -- I'll have to sleep on it though!
What do you mean sample from the frequency distribution?

The number of arrivals in a time interval of length T has a Poisson distribution
with mean T/v.

RonL

5. Originally Posted by CaptainBlack
What do you mean sample from the frequency distribution?

The number of arrivals in a time interval of length T has a Poisson distribution
with mean T/v.

RonL
A ha! That's enlightening. Given this relationship between the exponential distribution and the Poisson distribution, I'm surprised I didn't come across it in my online searching -- but now that you've shown me the light, I find lots of explanations.

Trying to use the parlance: I want to generate Poisson variates(?), much in the same way I used -ln(u)*v to generate exponential variates for wait time. It looks like there's some literature on this out there, so I think I'll head off in that direction.

Thanks again!

6. Originally Posted by Talisman00
A ha! That's enlightening. Given this relationship between the exponential distribution and the Poisson distribution, I'm surprised I didn't come across it in my online searching -- but now that you've shown me the light, I find lots of explanations.

Trying to use the parlance: I want to generate Poisson variates(?), much in the same way I used -ln(u)*v to generate exponential variates for wait time. It looks like there's some literature on this out there, so I think I'll head off in that direction.

Thanks again!
If you have access to Don Knuth's TAOCP see volume 2 semi-numerical
algorithms for the method (it is equivalent to generating exponentials untill
the sum of them exceeds T).

RonL

7. Originally Posted by CaptainBlack
(it is equivalent to generating exponentials untill
the sum of them exceeds T).
This is actually what I'm doing now, although I felt too sheepish to get this code reviewed . Looking at other code online, I guess I can save a few log calculations (one per go-round) but still have to iterate. Ick.

If TAOCP doesn't have a much better solution, I guess I'll stick with what I have.

Thanks!

 I should mention that this is not a performance-critical application. I just want to avoid outrageously inefficient code.

8. Originally Posted by Talisman00
This is actually what I'm doing now, although I felt too sheepish to get this code reviewed . Looking at other code online, I guess I can save a few log calculations (one per go-round) but still have to iterate. Ick.

If TAOCP doesn't have a much better solution, I guess I'll stick with what I have.

Thanks!

 I should mention that this is not a performance-critical application. I just want to avoid outrageously inefficient code.
TAOCP does essentially what I described above, but Knuth has some nice
touches which make it look as though its doing something else and can
save a lot of transcendental function evaluations.

RonL

9. Originally Posted by CaptainBlack
TAOCP does essentially what I described above, but Knuth has some nice
touches which make it look as though its doing something else and can
save a lot of transcendental function evaluations.

RonL
Instead of waiting 'til the sum of ln(-u) exceeds T, I guess I can wait 'til the product of u exceeds exp(-T), which saves me enough computation for my needs.

A related question: I'm making a wild guess that my actual distribution is Poisson. Supposing I can get some nitty-gritty data, can you suggest either (1) a good way to measure "how Poisson" it is, or (2) a way to determine what "well-known" distribution fits it best (parameters and all)?

I realize the second one is rather involved, but I'm willing to settle for a very rough approximation (that doesn't involve keeping around a large table of past stats).

10. Originally Posted by Talisman00
Instead of waiting 'til the sum of ln(-u) exceeds T, I guess I can wait 'til the product of u exceeds exp(-T), which saves me enough computation for my needs.

A related question: I'm making a wild guess that my actual distribution is Poisson. Supposing I can get some nitty-gritty data, can you suggest either (1) a good way to measure "how Poisson" it is, or (2) a way to determine what "well-known" distribution fits it best (parameters and all)?

I realize the second one is rather involved, but I'm willing to settle for a very rough approximation (that doesn't involve keeping around a large table of past stats).
The first step is always to look at the data, but if I can see some data
I think I could suggest something.

As a default I would expect to perform a chi-squared test.

RonL