Skip to content

Commit

Permalink
updating
Browse files Browse the repository at this point in the history
  • Loading branch information
choldgraf committed Mar 14, 2018
1 parent fc93eed commit a97b631
Showing 1 changed file with 43 additions and 17 deletions.
60 changes: 43 additions & 17 deletions simulate_pi.ipynb
@@ -1,8 +1,17 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Estimate Pi interactively!\n",
"\n",
"Below you'll see a few widget windows, these run a simulation that estimates the value of \"Pi\" based on the number of random points that fall within vs. outside of a circle. Try playing around with the number of total samples to see how the estimate stabilizes over time!"
]
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -16,7 +25,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -68,7 +77,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -80,9 +89,18 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 21,
"metadata": {},
"outputs": [],
"source": [
"width = '350px'"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {
"scrolled": true
"scrolled": false
},
"outputs": [
{
Expand All @@ -100,7 +118,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "8a5f3428783741cfb42002b8d81fb643",
"model_id": "459c604fa53b4701b5ea60351e9d6629",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -120,7 +138,7 @@
"</p>\n"
],
"text/plain": [
"HBox(children=(Figure(axes=[Axis(scale=LinearScale(max=2.0, min=0.0)), Axis(orientation='vertical', scale=LinearScale())], fig_margin={'top': 60, 'bottom': 60, 'left': 60, 'right': 60}, layout=Layout(height='500px', min_width='125px', width='500px'), marks=[Lines(colors=['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2', '#7f7f7f', '#bcbd22', '#17becf'], interactions={'hover': 'tooltip'}, scales={'x': LinearScale(max=2.0, min=0.0), 'y': LinearScale()}, scales_metadata={'x': {'orientation': 'horizontal', 'dimension': 'x'}, 'y': {'orientation': 'vertical', 'dimension': 'y'}, 'color': {'dimension': 'color'}}, tooltip_style={'opacity': 0.9}, x=array([0. , 0.00500501, 0.01001001, 0.01501502, 0.02002002,\n",
"HBox(children=(Figure(axes=[Axis(scale=LinearScale(max=2.0, min=0.0)), Axis(orientation='vertical', scale=LinearScale())], fig_margin={'top': 60, 'bottom': 60, 'left': 60, 'right': 60}, layout=Layout(height='300px', min_width='125px', width='300px'), marks=[Lines(colors=['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2', '#7f7f7f', '#bcbd22', '#17becf'], interactions={'hover': 'tooltip'}, scales={'x': LinearScale(max=2.0, min=0.0), 'y': LinearScale()}, scales_metadata={'x': {'orientation': 'horizontal', 'dimension': 'x'}, 'y': {'orientation': 'vertical', 'dimension': 'y'}, 'color': {'dimension': 'color'}}, tooltip_style={'opacity': 0.9}, x=array([0. , 0.00500501, 0.01001001, 0.01501502, 0.02002002,\n",
" 0.02502503, 0.03003003, 0.03503504, 0.04004004, 0.04504505,\n",
" 0.05005005, 0.05505506, 0.06006006, 0.06506507, 0.07007007,\n",
" 0.07507508, 0.08008008, 0.08508509, 0.09009009, 0.0950951 ,\n",
Expand Down Expand Up @@ -518,9 +536,10 @@
" nan, nan, nan, nan, nan,\n",
" nan, nan, nan, nan, nan,\n",
" nan, nan, nan, nan, nan,\n",
" nan, nan, nan, nan, nan])), Scatter(colors=['#41f465', '#41f465', '#41f465', '#41f465', '#41f465', '#41f465', '#41f465', '#41f465', '#41f465', '#f44b42'], interactions={'hover': 'tooltip'}, scales={'x': LinearScale(max=2.0, min=0.0), 'y': LinearScale()}, scales_metadata={'x': {'orientation': 'horizontal', 'dimension': 'x'}, 'y': {'orientation': 'vertical', 'dimension': 'y'}, 'color': {'dimension': 'color'}, 'size': {'dimension': 'size'}, 'opacity': {'dimension': 'opacity'}, 'rotation': {'dimension': 'rotation'}, 'skew': {'dimension': 'skew'}}, tooltip_style={'opacity': 0.9}, x=array([1.71315436, 0.19748988, 1.40972373, 0.11370371, 0.90708904,\n",
" 0.93377541, 0.12357248, 0.03169831, 1.02276454, 1.7499571 ]), y=array([0.48384343, 1.3708236 , 0.12113034, 1.35238753, 1.65072799,\n",
" 1.26919014, 0.69238866, 1.73469111, 1.10733379, 1.8480898 ]))], scale_x=LinearScale(allow_padding=False, max=1.0, min=0.0), scale_y=LinearScale(allow_padding=False, max=1.0, min=0.0), title='Ratio of in-to-out dots: 3.6'), Figure(axes=[Axis(scale=LinearScale(max=700.0, min=0.0)), Axis(orientation='vertical', scale=LinearScale(max=4.0, min=2.0))], fig_margin={'top': 60, 'bottom': 60, 'left': 60, 'right': 60}, layout=Layout(height='500px', min_width='125px', width='500px'), marks=[Lines(colors=['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2', '#7f7f7f', '#bcbd22', '#17becf'], interactions={'hover': 'tooltip'}, scales={'x': LinearScale(max=700.0, min=0.0), 'y': LinearScale(max=4.0, min=2.0)}, scales_metadata={'x': {'orientation': 'horizontal', 'dimension': 'x'}, 'y': {'orientation': 'vertical', 'dimension': 'y'}, 'color': {'dimension': 'color'}}, tooltip_style={'opacity': 0.9}, x=array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]), y=array([0., 4., 4., 4., 4., 4., 4., 4., 4., 4.])), Lines(colors=['dodgerblue'], interactions={'hover': 'tooltip'}, preserve_domain={'x': True, 'y': False}, scales={'x': LinearScale(allow_padding=False, max=1.0, min=0.0), 'y': LinearScale(max=4.0, min=2.0)}, scales_metadata={'x': {'orientation': 'horizontal', 'dimension': 'x'}, 'y': {'orientation': 'vertical', 'dimension': 'y'}, 'color': {'dimension': 'color'}}, stroke_width=1.0, tooltip_style={'opacity': 0.9}, x=array([0, 1]), y=array([3.14159265, 3.14159265]))], scale_x=LinearScale(allow_padding=False, max=1.0, min=0.0), scale_y=LinearScale(allow_padding=False, max=1.0, min=0.0), title='Estimation of Pi')))"
" nan, nan, nan, nan, nan])), Scatter(colors=['#f44b42', '#41f465', '#41f465', '#41f465', '#f44b42', '#41f465', '#41f465', '#41f465', '#41f465', '#41f465'], interactions={'hover': 'tooltip'}, scales={'x': LinearScale(max=2.0, min=0.0), 'y': LinearScale()}, scales_metadata={'x': {'orientation': 'horizontal', 'dimension': 'x'}, 'y': {'orientation': 'vertical', 'dimension': 'y'}, 'color': {'dimension': 'color'}, 'size': {'dimension': 'size'}, 'opacity': {'dimension': 'opacity'}, 'rotation': {'dimension': 'rotation'}, 'skew': {'dimension': 'skew'}}, tooltip_style={'opacity': 0.9}, x=array([1.57982682, 0.16947611, 1.72409348, 1.43550414, 1.00592813,\n",
" 0.1069897 , 0.05187035, 0.98937002, 0.77590664, 0.73260458]), y=array([1.57873181, 1.34315478, 0.7966563 , 0.30932293, 1.76904153,\n",
" 0.28396248, 0.82835706, 0.4581817 , 0.78586046, 0.97248903]))], scale_x=LinearScale(allow_padding=False, max=1.0, min=0.0), scale_y=LinearScale(allow_padding=False, max=1.0, min=0.0), title='Ratio of in-to-out dots: 3.2'), Figure(axes=[Axis(scale=LinearScale(max=700.0, min=0.0)), Axis(orientation='vertical', scale=LinearScale(max=4.0, min=2.0))], fig_margin={'top': 60, 'bottom': 60, 'left': 60, 'right': 60}, layout=Layout(height='300px', min_width='125px', width='300px'), marks=[Lines(colors=['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2', '#7f7f7f', '#bcbd22', '#17becf'], interactions={'hover': 'tooltip'}, scales={'x': LinearScale(max=700.0, min=0.0), 'y': LinearScale(max=4.0, min=2.0)}, scales_metadata={'x': {'orientation': 'horizontal', 'dimension': 'x'}, 'y': {'orientation': 'vertical', 'dimension': 'y'}, 'color': {'dimension': 'color'}}, tooltip_style={'opacity': 0.9}, x=array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]), y=array([0. , 0. , 2. , 2.66666667, 3. ,\n",
" 2.4 , 2.66666667, 2.85714286, 3. , 3.11111111])), Lines(colors=['dodgerblue'], interactions={'hover': 'tooltip'}, preserve_domain={'x': True, 'y': False}, scales={'x': LinearScale(allow_padding=False, max=1.0, min=0.0), 'y': LinearScale(max=4.0, min=2.0)}, scales_metadata={'x': {'orientation': 'horizontal', 'dimension': 'x'}, 'y': {'orientation': 'vertical', 'dimension': 'y'}, 'color': {'dimension': 'color'}}, stroke_width=1.0, tooltip_style={'opacity': 0.9}, x=array([0, 1]), y=array([3.14159265, 3.14159265]))], scale_x=LinearScale(allow_padding=False, max=1.0, min=0.0), scale_y=LinearScale(allow_padding=False, max=1.0, min=0.0), title='Estimation of Pi')))"
]
},
"metadata": {},
Expand All @@ -529,7 +548,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "4cd207ae5e6d4b6c8f06d044978383ff",
"model_id": "c0a24fe61cf5460c97ea56bce43c47c4",
"version_major": 2,
"version_minor": 0
},
Expand Down Expand Up @@ -564,15 +583,15 @@
"fig = plt.figure()\n",
"x = np.linspace(0, 5, 1000)\n",
"y = circ(x)\n",
"myplt = plt.plot(x=x, y=y)\n",
"scat = plt.scatter(samples[:10, 0], samples[:10, 1])\n",
"myplt = plt.plot(x=x, y=y, s=[100] * len(y))\n",
"scat = plt.scatter(samples[:10, 0], samples[:10, 1], options={'s': 1})\n",
"plt.xlim(0, 2)\n",
"fig.layout.height = \"500px\"\n",
"fig.layout.width = \"500px\"\n",
"fig.layout.height = width\n",
"fig.layout.width = width\n",
"\n",
"fig_line = plt.figure()\n",
"fig_line.layout.height = \"500px\"\n",
"fig_line.layout.width = \"500px\"\n",
"fig_line.layout.height = width\n",
"fig_line.layout.width = width\n",
"fig_line.title = \"Estimation of Pi\"\n",
"line = plt.plot(range(10), ratios[:10])\n",
"line2 = plt.hline(np.pi, ls='--', c='k')\n",
Expand All @@ -592,6 +611,13 @@
"display(box, box2)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
Expand Down

0 comments on commit a97b631

Please sign in to comment.