forked from stephenhky/econ_inequality
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpareto_gini_sim.py
32 lines (25 loc) · 919 Bytes
/
pareto_gini_sim.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
__author__ = 'hok1'
from ginicoef import gini_coef
import wealthdist as wsample
from multiprocessing import Pool
import numpy as np
import csv
from itertools import product
sum_wealth = 1e+12
populations = [10, 50, 100, 500, 1000, 5000, 10000, 50000, 100000, 500000, 1000000, 5000000]
alphas = np.linspace(0.1, 3, num=61)
def cal_gini((population, alpha)):
return gini_coef(wsample.sample_pareto_wealth(sum_wealth=sum_wealth, size=population, alpha=alpha))
if __name__ == '__main__':
outf = open('ginicoef.csv', 'wb')
writer = csv.writer(outf)
headers = ['population', 'alpha', 'gini_coef']
writer.writerow(headers)
pairs = product(populations, alphas)
for pair in pairs:
p = Pool(processes=10)
rep_pairs = [pair]*100
results = p.map(cal_gini, rep_pairs)
for ginival in results:
writer.writerow([pair[0], pair[1], ginival])
outf.close()