Last active
September 19, 2019 10:47
-
-
Save sachinsdate/d48abefe2f75541c7d98f51599c927b0 to your computer and use it in GitHub Desktop.
Simulate a Poisson process
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import math | |
_lambda = 5 | |
_num_arrivals = 100 | |
_arrival_time = 0 | |
print('RAND,INTER_ARRV_T,ARRV_T') | |
for i in range(_num_arrivals): | |
#Get the next probability value from Uniform(0,1) | |
p = random.random() | |
#Plug it into the inverse of the CDF of Exponential(_lamnbda) | |
_inter_arrival_time = -math.log(1.0 - p)/_lambda | |
#Add the inter-arrival time to the running sum | |
_arrival_time = _arrival_time + _inter_arrival_time | |
#print it all out | |
print(str(p)+','+str(_inter_arrival_time)+','+str(_arrival_time)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment