Created
October 9, 2019 15:45
-
-
Save thunderInfy/1a3a837354d43e9a8e620cbd22be6297 to your computer and use it in GitHub Desktop.
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
class poisson_: | |
def __init__(self, λ): | |
self.λ = λ | |
ε = 0.01 | |
# [α , β] is the range of n's for which the pmf value is above ε | |
self.α = 0 | |
state = 1 | |
self.vals = {} | |
summer = 0 | |
while(1): | |
if state == 1: | |
temp = poisson.pmf(self.α, self.λ) | |
if(temp <= ε): | |
self.α+=1 | |
else: | |
self.vals[self.α] = temp | |
summer += temp | |
self.β = self.α+1 | |
state = 2 | |
elif state == 2: | |
temp = poisson.pmf(self.β, self.λ) | |
if(temp > ε): | |
self.vals[self.β] = temp | |
summer += temp | |
self.β+=1 | |
else: | |
break | |
# normalizing the pmf, values of n outside of [α, β] have pmf = 0 | |
added_val = (1-summer)/(self.β-self.α) | |
for key in self.vals: | |
self.vals[key] += added_val | |
def f(self, n): | |
try: | |
Ret_value = self.vals[n] | |
except(KeyError): | |
Ret_value = 0 | |
finally: | |
return Ret_value |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment