Last active
August 30, 2021 18:50
-
-
Save sausheong/d7ffb3d8885e679a578ba151c9764403 to your computer and use it in GitHub Desktop.
Estimations
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
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"%%time\n", | |
"import numpy as np\n", | |
"import pandas as pd\n", | |
"import math \n", | |
"import matplotlib.pyplot as plt\n", | |
"from scipy.interpolate import interp1d\n", | |
"from scipy import stats\n", | |
"\n", | |
"no_of_experiments = 10000000\n", | |
"num_bins = 100\n", | |
"\n", | |
"tasks = {\n", | |
" \"Task 1\": [4,7, 12],\n", | |
"}\n", | |
"\n", | |
"data = pd.DataFrame(tasks, index=[\"optimistic\", \"likely\", \n", | |
" \"pessimistic\"])\n", | |
"points = [0] * no_of_experiments\n", | |
"\n", | |
"for column in data:\n", | |
" a, b, c = data[column][0], data[column][1], data[column][2]\n", | |
" alpha = ((4*b) + c - (5*a))/(c - a)\n", | |
" beta = ((5*c) - a - (4*b))/(c - a)\n", | |
" r = np.random.beta(alpha, beta, no_of_experiments)\n", | |
" p = (r*(c-a)) + a\n", | |
" points += p\n", | |
"\n", | |
"plt.figure(figsize=(12,8))\n", | |
"n, bins, patches = plt.hist(points, num_bins, \n", | |
" range = (0, np.max(points)),\n", | |
" color = \"skyblue\", lw=1, \n", | |
" edgecolor=\"steelblue\", \n", | |
" weights=[1/no_of_experiments]*\n", | |
" no_of_experiments)\n", | |
"plt.show() " | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.6.8" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment