Show code
import pandas as pd
import numpy as np
from tqdm import tqdm
import os
import sys
sys.path.append("../python")
import general
import visualizationsfrom IPython.display import HTML
HTML('''<script>
code_show=true;
function code_toggle() {
if (code_show){
$('div.input').hide();
} else {
$('div.input').show();
}
code_show = !code_show
}
$( document ).ready(code_toggle);
</script>
<form action="javascript:code_toggle()"><input type="submit" value="Click here to toggle on/off the raw code."></form>''')params = {'OUTPUT' : {'path' : os.path.join('output_html', 'power_law'),
'name' : 'power_law_20200917'},
# Simulating heights of American Women
'GAUSSIAN': {'mean' : 65,
'stdev' : 3.5,
'n' : 10000},
# Simulating batting averages (baseball)
'BINOMIAL' : {'at_bats_per_game' : 4,
'batting_average' : 0.3,
'number_of_games' : 100000},
# Value of founded company
'POWERLAW' : {'shape' : 0.8,
'n' : 50000000,
'iteration_size' : 100000} # Recalculate mean every, say 100,000th sample
}100%|██████████| 10000/10000 [00:00<00:00, 35367.48it/s]
power_law_means, power_law_medians, n_samples = [],[],[]
for i in tqdm(range(1,int(params['POWERLAW']['n']/params['POWERLAW']['iteration_size'])+1)):
power_law_means.append(np.mean(random_sample[:(i*params['POWERLAW']['iteration_size'])]))
power_law_medians.append(np.percentile(random_sample[:(i*params['POWERLAW']['iteration_size'])],50))
n_samples.append(i*params['POWERLAW']['iteration_size'])100%|██████████| 500/500 [03:44<00:00, 2.23it/s]