Created
July 20, 2021 16:41
-
-
Save barnjamin/98545fd23b9beb8f564e881faa0d8646 to your computer and use it in GitHub Desktop.
poisson_appx.py
This file contains hidden or 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 numpy as np | |
from scipy import stats | |
import matplotlib.pyplot as plt | |
def compare(n, p): | |
return np.sum([abs(stats.poisson.pmf(x, n*p) - stats.binom.pmf(x, n, p)) for x in range(100)]) | |
max_moneysupply = 1e16 | |
min_balance = 1e6 | |
max_balance = 1e15 | |
max_committee = 60 | |
min_committee = 30 | |
iters = 1e5 | |
money = np.random.randint(int(min_balance), int(max_moneysupply), int(iters)) | |
committee = np.random.randint(int(min_committee), int(max_committee), int(iters)) | |
moneysupply = np.random.randint(int(max_balance), int(max_moneysupply), int(iters)) | |
deltas = np.zeros(int(iters)) | |
for x in range(len(deltas)): | |
if x % 100 == 0: | |
print(x) | |
deltas[x] = compare(money[x], float(committee[x])/float(moneysupply[x])) | |
plt.hist(deltas, bins=25) | |
plt.savefig("poisson_appx.png") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment