# Understanding Waiting Times Between Events with the Poisson and Exponential Distributions

十月 17, 2017

Probability and Information Theory

No Comments »

A webhook POSTs to our database each time a particular event occurs on our website. We receive about two of these requests per minute. I was mindlessly monitoring the log files one day and noticed it had been roughly 90 seconds since our database had been hit by this request. Before worrying, though, I wondered how rare that observation is. What is the likelihood of waiting longer than 1.5 minutes for the next request?

This is a probability problem that can be solved with an understanding of Poisson processes and the exponential distribution. A Poisson process is any process where independent events occur at constant known rate, e.g. babies are born at a hospital at a rate of three per hour, or calls come into a call center at a rate of 10 per minute. The exponential distribution is the probability distribution that models the waiting times between these events, e.g. the times between calls at the call center are exponentially distributed. To model Poisson processes and exponental distributions, we need to know two things: a time-unit and a rate .

##
Poisson Distribution

Let's start with the Poisson distribution: If we let denote the number of events that occur between now and time , then the probability that events occur within the next time-units, or , is

As mentioned earlier, we receive an average of two requests from this webhook per minute. Thus, the time-unit is one minute and the rate is two. Knowing these, we can answer questions such as:

What is the probability that we receive no requests in the next two minutes?

What is the probability that we receive at least two requests in the next three minutes?

For those who prefer reading code, we can write a classPoissonthat's initialized with its rate :

##
Exponential Distribution

Let's move onto the exponential distribution. As mentioned earlier, the waiting times between events in a Poisson process are exponentially distributed. The exponential distribution can be derived from the Poisson distribution: Let be the waiting time between now and the next event. The probability that is greater than is identical to the probability that 0 events occur between now and time , which we already know:

We also know that the probability of being less than or equal to is the complement of being greater than :

Thus, the distribution function of the waiting times between events in a Poisson process is . With this, and recalling that our time-unit is one minute and our rate is two requests per minute, we can answer questions such as:

- What is the probability that the next request occurs within 15 seconds?

- What is the probability that the next request is between 15 and 30 seconds from now?

##
Conclusion

Now, referring back to the original question: What is the probability of waiting longer than 1.5 minutes for the next request?

The probability of waiting longer than 1.5 minutes for the next request is 4.98%.

原址：http://nbviewer.jupyter.org/github/nicolewhite/notebooks/blob/master/Poisson.ipynb