Skip to content

Instantly share code, notes, and snippets.

@epogrebnyak
Created January 13, 2021 12:12
Show Gist options
  • Save epogrebnyak/a2a42822562878aaa7b90eb94648ef50 to your computer and use it in GitHub Desktop.
Save epogrebnyak/a2a42822562878aaa7b90eb94648ef50 to your computer and use it in GitHub Desktop.
Poisson replicated
from scipy.stats import poisson
from dataclasses import dataclass
from math import factorial, exp
@dataclass
class Poisson:
mu : float
def __postinit__(self):
assert self.mu > 0
def probability(self, k):
return (self.mu ** k) / factorial (k) * exp(-1 * self.mu)
assert abs(Poisson(5).probability(4) - poisson(5).pmf(4)) < 0.0001
"""
https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.poisson.html#scipy.stats.poisson
http://www.stats.ox.ac.uk/~filippi/Teaching/psychology_humanscience_2015/lecture5.pdf
https://stats.stackexchange.com/questions/504701/why-is-poisson-distribution-centered-left-of-mean
https://u.math.biu.ac.il/~amirgi/CTMCnotes.pdf
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment