Last active
November 1, 2018 14:01
-
-
Save AllenDowney/1506edbddaf7f1280e80458e977e41e4 to your computer and use it in GitHub Desktop.
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": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Think Bayes\n", | |
"\n", | |
"This notebook presents code and exercises from Think Bayes, second edition.\n", | |
"\n", | |
"Copyright 2018 Allen B. Downey\n", | |
"\n", | |
"MIT License: https://opensource.org/licenses/MIT" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# Configure Jupyter so figures appear in the notebook\n", | |
"%matplotlib inline\n", | |
"\n", | |
"# Configure Jupyter to display the assigned value after an assignment\n", | |
"%config InteractiveShell.ast_node_interactivity='last_expr_or_assign'\n", | |
"\n", | |
"import math\n", | |
"import numpy as np\n", | |
"\n", | |
"from thinkbayes2 import Pmf, Cdf, Suite\n", | |
"import thinkplot" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"### The Game of Ur problem\n", | |
"\n", | |
"In the Royal Game of Ur, players advance tokens along a track with 14 spaces. To determine how many spaces to advance, a player rolls 4 dice with 4 sides. Two corners on each die are marked; the other two are not. The total number of marked corners -- which is 0, 1, 2, 3, or 4 -- is the number of spaces to advance.\n", | |
"\n", | |
"For example, if the total on your first roll is 2, you could advance a token to space 2. If you roll a 3 on the next roll, you could advance the same token to space 5.\n", | |
"\n", | |
"Suppose you have a token on space 13. How many rolls did it take to get there?\n", | |
"\n", | |
"Hint: you might want to start by computing the distribution of k given n, where k is the number of the space and n is the number of rolls.\n", | |
"\n", | |
"Then think about the prior distribution of n." | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Here's a Pmf that represents one of the 4-sided dice." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"Pmf({0: 0.5, 1: 0.5})" | |
] | |
}, | |
"execution_count": 2, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"die = Pmf([0, 1])" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"And here's the outcome of a single roll." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"Pmf({0: 0.0625, 1: 0.25, 2: 0.375, 3: 0.25, 4: 0.0625})" | |
] | |
}, | |
"execution_count": 3, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"roll = sum([die]*4)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"I'll start with a simulation, which helps in two ways: it makes modeling assumptions explicit and it provides an estimate of the answer.\n", | |
"\n", | |
"The following function simulates playing the game over and over; after every roll, it yields the number of rolls and the total so far. When it gets past the 14th space, it starts over." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"def roll_until(iters):\n", | |
" \"\"\"Generates observations of the game.\n", | |
" \n", | |
" iters: number of observations\n", | |
" \n", | |
" yields: number of rolls, total\n", | |
" \"\"\"\n", | |
" for i in range(iters):\n", | |
" total = 0\n", | |
" for n in range(1, 1000):\n", | |
" total += roll.Random()\n", | |
" if total > 14:\n", | |
" break\n", | |
" yield(n, total)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Now I'll the simulation many times and, every time the token is observed on space 13, record the number of rolls it took to get there." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"pmf_sim = Pmf()\n", | |
"for n, k in roll_until(1000000):\n", | |
" if k == 13:\n", | |
" pmf_sim[n] += 1" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Here's the distribution of the number of rolls:" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"501019" | |
] | |
}, | |
"execution_count": 6, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"pmf_sim.Normalize()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"4 0.01727080210530938\n", | |
"5 0.14913606070827654\n", | |
"6 0.29612849013710063\n", | |
"7 0.27942253686985924\n", | |
"8 0.16166652362485256\n", | |
"9 0.06677391476171562\n", | |
"10 0.021727718908863738\n", | |
"11 0.006071626026158689\n", | |
"12 0.001429087519634984\n", | |
"13 0.00031136543723890716\n", | |
"14 5.788203640979684e-05\n", | |
"15 3.991864579985989e-06\n" | |
] | |
} | |
], | |
"source": [ | |
"pmf_sim.Print()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 8, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAagAAAEYCAYAAAAJeGK1AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAHQVJREFUeJzt3XuUVeWd5vHvQ3FT0QSFTlpLLFS8oCBqiSYmWknUkI4LdAZHGJOhZ+zF5IImccXRGBdJTHQR7WSMrRMlhsZJi2iMOtUZjEEj2okoN8sLKC0SRyowE4TEtMY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mi4j7a1xTE9nFFufWsg7r+3wEZda3fTM/Kms7UnmgxvWYVY2PoMzMLEk+gjIzsyQ5oMzMLEkOKDMzS5IDyszMkuSAMjOzJP1/IORnQlZsL9AAAAAASUVORK5CYII=\n", | |
"text/plain": [ | |
"<Figure size 432x288 with 1 Axes>" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"thinkplot.Hist(pmf_sim, label='Simulation')\n", | |
"thinkplot.decorate(xlabel='Number of rolls to get to space 13',\n", | |
" ylabel='PMF')" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"### Bayes\n", | |
"\n", | |
"Now let's think about a Bayesian solution. It is straight forward to compute the likelihood function, which is the probability of being on space 13 after a hypothetical `n` rolls.\n", | |
"\n", | |
"`pmf_n` is the distribution of spaces after `n` rolls.\n", | |
"\n", | |
"`pmf_13` is the probability of being on space 13 after `n` rolls." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 9, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"4 0.008544921875\n", | |
"5 0.0739288330078125\n", | |
"6 0.14878177642822266\n", | |
"7 0.13948291540145874\n", | |
"8 0.08087921887636185\n", | |
"9 0.033626414369791746\n", | |
"10 0.010944152454612777\n", | |
"11 0.002951056014353526\n", | |
"12 0.0006854188303009323\n", | |
"13 0.00014100133496341982\n", | |
"14 2.6227807875534026e-05\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/plain": [ | |
"0.4999919364007537" | |
] | |
}, | |
"execution_count": 9, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"pmf_13 = Pmf()\n", | |
"for n in range(4, 15):\n", | |
" pmf_n = sum([roll]*n)\n", | |
" pmf_13[n] = pmf_n[13]\n", | |
" \n", | |
"pmf_13.Print()\n", | |
"pmf_13.Total()" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"The total probability of the data is very close to 1/2, but it's not obvious (to me) why.\n", | |
"\n", | |
"Nevertheless, `pmf_13` is the probability of the data for each hypothetical values of `n`, so it is the likelihood function.\n", | |
"\n", | |
"### The prior\n", | |
"\n", | |
"Now we need to think about a prior distribution on the number of rolls. This is not easy to reason about, so let's start by assuming that it is uniform, and see where that gets us.\n", | |
"\n", | |
"If the prior is uniform, the posterior equals the likelihood function, normalized." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 10, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"4 0.017090119365747274\n", | |
"5 0.1478600505840099\n", | |
"6 0.2975683518003199\n", | |
"7 0.2789703298127999\n", | |
"8 0.16176104650522904\n", | |
"9 0.0672539133567936\n", | |
"10 0.021888657911956433\n", | |
"11 0.005902207214774348\n", | |
"12 0.0013708597687294604\n", | |
"13 0.00028200721791321923\n", | |
"14 5.245646172683854e-05\n" | |
] | |
} | |
], | |
"source": [ | |
"posterior = pmf_13.Copy()\n", | |
"posterior.Normalize()\n", | |
"posterior.Print()" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"That sure looks similar to what we got by simulation. Let's compare them." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 11, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAagAAAEYCAYAAAAJeGK1AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAIABJREFUeJzt3Xt4FeW59/HvTUAQ8YCG3SoJBneDFgwgRrRKgW3R4hZB+qqAtaJY87aAh03BarVI2dXLIm0tYiuoiG1FVESKCrWgor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1zB0UcfzRtvvEGfPn04/PDD+eCDD9i2bRvvvfcev/rVr3j11VdZunQpnTt35qmnnqJNmzZMnTqVp556it27d3PmmWcya9asAz43GThwINOnT2fr1q1MnjwZgN27d/Pll1/ywQcfUFBQwIQJE9i1axfp6enMnTuXY489loKCAsaMGUP79u3p169fjT+SFStWMH36dJ5++un9lt93330sXLiQhQsXsnXrVsaNG0dxcTHt27fnvvvu46STTtqvffLVH8Ddd9/NU089xd69e3n88cc56aST2LFjB2PGjGHTpk20b9+e2bNn07NnzyqXb9++nVGjRlFcXEzfvn1xT9yo+uyzz7jkkksoKiqitLSUn/70p4wYMaLGc62r2ALK3UvMbDzwLInHzOe4+9tmNhXId/fFwHgzGwTsBT4hcXuPqN1jwDqgBBjn7qVx1XowmfX3SbHuf+bVo+L9D05atHHjxtGzZ09uuOGG/ZaPHz+eyy+/nNGjRzNnzhyuvfZaFi1aBMB7773H8uXLSUtLY8qUKbz//vu88MILrFu3jm984xs88cQTTJs2jeHDh/PMM89w4YUXMn78+PLQ+d73vsfTTz/NBRdU/vd26NChDB06FIBLLrmEAQMGsHfvXq655hr+9Kc/0alTJx599FFuvvlm5syZw5VXXsndd9/NgAEDmDSpfv/eZs6cyV/+8hcWLVpE27ZtycvL49577yU7O5vXXnuNsWPH8vzzz1e7j/T0dFavXs1vf/tbpk+fzv3338+tt97KKaecwqJFi3j++ee5/PLLKSwsrHL5z372M/r168fkyZN55plnmD17NgB//vOfOe6443jmmWcA2LlzZ73Osyaxvgfl7kuAJRWWTU6avq6abW8DbqtqvYi0PEcccQSXX345M2bM4NBDDy1fvnLlShYuXAgkAiU5wC6++GLS0v7/WyjnnXcebdq0IScnh9LSUgYPHgxATk4OmzdvBuCFF15g2rRpfP755+zYsYMePXpUGVBlpk2bxqGHHsq4ceNYu3Yta9eu5ZxzzgGgtLSUY489lp07d/Lpp58yYMCA8lqXLl1ap5/BH/7wBzIyMli0aBFt2rRh165dvPLKK1x88cXlbb744osa9/Od73wHgFNPPbX8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R9NlVs9cUvRCktSN/11mNf1wRkXqqKXAeAvYCfwX+E+hBLXs1d/cSMxsPPAukAXPc/W0zmwrku/tiMzsNeBLoCFxgZj9z9x7A14FZ0cMTrUh8BtVyAirJrL9PqrlRA828ehQAbzVCbwsiIqlSU0B1d/ccADN7AHi9Ljt39yXAkgrLJidNryJx66/idq8AOXU5loiItCw1fca0t2zC3UtirkVERKRcTVdQvczsX9G0AYdG87V5ik9ERKTeanqKL62xChEREUnWkMfIRUREYqOAEhGRICmgREQkSAooEREJkgJKRESCpIASEZEgKaBERCRICigREQmSAkpERIKkgBIRkSApoEREJEgKKBERCZICSkREgqSAEhGRICmgREQkSAooEREJkgJKRESCpIASEZEgKaBERCRICigREQmSAkpERIKkgBIRkSApoEREJEgKKBERCZICSkREghRrQJnZYDNbb2YbzezGStb3N7PVZlZiZhdVWDfazDZEX6PjrFNERMITW0CZWRpwD3Ae0B0YZWbdKzT7CLgCmFdh26OBW4HTgb7ArWbWMa5aRUQkPHFeQfUFNrr7Jnf/EpgPDEtu4O6b3f0tYF+Fbb8NLHP3He7+CbAMGBxjrSIiEpg4A6ozsCVpvihaFve2IiLSAsQZUFbJMk/ltmaWZ2b5ZpZfXFxcp+JERCRscQZUEZCZNJ8BbE3ltu4+291z3T23U6dO9S5URETCE2dArQKyzayrmR0CjAQW13LbZ4Fzzaxj9HDEudEyERE5SMQWUO5eAownESzvAI+5+9tmNtXMhgKY2WlmVgRcDMwys7ejbXcA/00i5FYBU6NlIiJykGgd587dfQmwpMKyyUnTq0jcvqts2znAnDjrExGRcKknCRERCZICSkREgqSAEhGRICmgREQkSAooEREJkgJKRESCpIASEZEgKaBERCRICigREQmSAkpERIKkgBIRkSApoEREJEgKKBERCZICSkREgqSAEhGRICmgREQkSAooEREJkgJKRESCFOuQ7yIt2ooL4j9GWjvIuhQyh8d/LJHAKKBE6iKtHZTuYc2Gj2M/VE52ZyjdA5vnKaDkoKRbfCJ1kXVpIqQaU+mexj2eSCB0BSVSF5nDIXM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Wb4/MzsVuBI4nUSnnFeb2SnVnOMPgN+4e28gl0T3OhWdBSR3ipwN3BON6fMp8H+S1q2O2os0mAJKDgrR7anfkxissLZWufu2aPya94GyYTnWkAilMo+5+z533wBsAk4CzgUuN7NC4DXgGBL/sQO87u4fVHK804AVUUe2Zb10969Fncn76wc86e6fufsuEp3hfrOabVcCPzGzHwPHu/vuStoc7e7/L2n+A3cvjKYL2P9n8Q8SvcSLNJgCSg4md5G4skke26qE6N9B1HnsIUnrvkia3pc0v4/E0AFlKvYX5oAB17h77+ira9K4U59VUV+1Qw9UI3l/ddqHu88DhgK7gWereMihxMyS/69I/rmUsv/Pol20L5EGU0DJQcPddwCPkQipMpuBU6PpYUCbeuz6YjNrFX0udQKwHngW+KGZtYFE781W86CPrwEDzCw9euBhFPBiHWt5Cbgw6q39MGA48NeqGpvZCcAmd59Bogf0npU0Wx+dV210A2r9hKBIdVrX3ESkRfklMD5p/j7gT2b2OvAcVV/dVGc9iSD5CvADd99jZveTuPW1OroyK6aGYdfdfZuZ3QS8QOJKaIm712mYDHdfbWZzgdejRfe7+xvVbDICuMzM9gL/A0ytpM0zwEBgY3XHjsL4ayQ+LxNpMPVmLiLVssSAh79393NqaDecxPhFP22cyqSl0y0+EamWu28D7qvpRV0Sd2R+WUMbkVrTFZSIiARJV1AiIhIkBZSIiARJASUiIkFSQImISJAUUCIiEqT/Ba3tD7M1DMW6AAAAAElFTkSuQmCC\n", | |
"text/plain": [ | |
"<Figure size 432x288 with 1 Axes>" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"thinkplot.Hist(pmf_sim, label='Simulation')\n", | |
"thinkplot.Pmf(posterior, color='orange', label='Normalized likelihoods')\n", | |
"thinkplot.decorate(xlabel='Number of rolls (n)',\n", | |
" ylabel='PMF')" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Since the posterior distribution based on a uniform prior matches the simulation, it seems like the uniform prior must be correct. But it is not obvious (to me) why." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"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.5" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment