Last active
August 16, 2020 08:04
-
-
Save riceissa/041f418cccec32287008020d850d6daa to your computer and use it in GitHub Desktop.
yule.py
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
#!/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() |
Author
riceissa
commented
Feb 5, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment