Exponential Distribution and Waiting Times

Home » Exponential Distribution and Waiting Times
Exponential.sv

Exponential Function

$F(x)=1−e^{λx}$

In [2]:
import numpy as np
import matplotlib.pyplot as pl
%matplotlib inline

x = np.arange(0,10,0.01)
y = 1 - np.exp(-x)

pl.plot(x,y)
pl.grid()
pl.show()

$y=e^{-λx}$
$e^{-λx}=1-y$
$-λx=ln(1-y)$
$x = \frac{ln(1-y)}{-λ}$

To simulate waiting times we choose y random (uniform distributed) in the range [0,1] which is equivalent with choosing a random variable U in the same range:
$x = \frac{ln(U)}{-λ}$

In [29]:
from scipy.stats import poisson

NUM_SAMPLES=1000000
BUCKET_SIZE=10
LAMBDA=1
NUM_BUCKETS=30

u = np.random.rand(NUM_SAMPLES)
waitingTimes = np.log2(u)/(-1*LAMBDA)
waitingTimeFrequency = np.zeros(NUM_BUCKETS)

eventsInCurrentBucket=0
waitingInCurrentBucket=0
for i,val in enumerate(waitingTimes):
    eventsInCurrentBucket+=1
    waitingInCurrentBucket+=val
    while(waitingInCurrentBucket>BUCKET_SIZE):
        waitingTimeFrequency[eventsInCurrentBucket]+=1
        eventsInCurrentBucket=0
        waitingInCurrentBucket-=BUCKET_SIZE

x = np.arange(0,NUM_BUCKETS)
y = poisson.pmf(x,7)*150000

pl.plot(x,waitingTimeFrequency,label='experiment')
pl.plot(x,y,label='poisson')
pl.grid()
pl.legend()
pl.show()
In [ ]: