Skip to content

Instantly share code, notes, and snippets.

@thunderInfy
Created October 9, 2019 15:45
Show Gist options
  • Save thunderInfy/1a3a837354d43e9a8e620cbd22be6297 to your computer and use it in GitHub Desktop.
Save thunderInfy/1a3a837354d43e9a8e620cbd22be6297 to your computer and use it in GitHub Desktop.
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