The exponential distribution is the probability distribution of the time between events in a Poisson process.
#Exponential Distribution
The exponential distribution random variable is continuous and usually measures the passage of time, although it can be used in other applications.
Typical questions may be: “what is the probability that some event will occur in the next x hours or days, or what is the probability that some event will occur between $x_1$ hours and $x_2$ hours, or what is the probability that the event will take more than $x_1$ hours to take place”.
In summary, the random variable X is equal to (a) the time between events or(b) the passage of time to complete an action, for example, waiting for a customer.
Probability Density Function of Exponential Distribution
$$ f(x) = \begin{cases} \lambda e^{-\lambda x}, & x \geq 0 \\ 0, & \text{otherwise} \end{cases} $$- Where λ = 1/E(X)
- e, constant, euler number, base for natural logarithms = 2.71828
In the previous example of the donut shop where the waiting time can be modelled by
$$ f(x) = \begin{cases} \frac{1}{4} e^{-\frac{x}{4}}, & x \geq 0 \\ 0, & \text{otherwise} \end{cases} $$ The probability that the waiting time is between any two values (a,b) can be computed as $$ \int_{a}^{b} \frac{1}{4} e^{-\frac{x}{4}} \, dx. $$ e.g. between 2 and 5 minutes: $$ P(2 < X < 5) = \int_{2}^{5} f(x) \, dx = \int_{2}^{5} \frac{1}{4} e^{-\frac{x}{4}} \, dx = 0.32 $$
#Implementing Exponential Distribution in Python
Python provides an implementation of the exponential random variable with the
functions stats.expon.pdf and stats.expon.cdf whose details are as follows:
- the first argument x in pdf and q in cdf is the value at which to compute the function;
- the second argument, scale, is the expected value, 1/λ, by default equal to one;
stats.expon.pdf(x = 2, scale = 1/3) #0.007436257
#Computes the pdf at the point 2 of an exponential random variable with parameter λ = 3
stats.expon.cdf(x = 4) #0.9816844
#computes the cdf at the point 4 of an exponential random variable with parameter λ = 1
#Generating Random Numbers from an Exponential Distribution
For this np.random.exponential in Python function example, let’s assume we have
six computers, each of which is expected to last an average of seven years. Can
we simulate the expected failure dates for this set of machines?
np.random.exponential(7, 6)
#Returns
array([0.18827471, 8.59723434, 6.92963474, 1.75944546, 1.00673017,
5.58482594])