Skip to content

Instantly share code, notes, and snippets.

@riceissa
Last active August 16, 2020 08:04
Show Gist options
  • Save riceissa/041f418cccec32287008020d850d6daa to your computer and use it in GitHub Desktop.
Save riceissa/041f418cccec32287008020d850d6daa to your computer and use it in GitHub Desktop.
yule.py
#!/usr/bin/env python3
import matplotlib.pyplot as plt
import numpy as np
NUM_CITIES = 1000
city_pops = [1] * NUM_CITIES # initialize NUM_CITIES cities each with population 1
for person in range(100000):
prob_vector = np.divide(city_pops, sum(city_pops))
chosen_city = np.random.choice(list(range(NUM_CITIES)), size=1, p=prob_vector)[0]
city_pops[chosen_city] += 1
print(city_pops)
plt.hist(city_pops, bins=100)
plt.show()
@riceissa
Copy link
Author

riceissa commented Feb 5, 2020

Figure_1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment