diff --git a/animations/discrete_bayes_animations.ipynb b/animations/discrete_bayes_animations.ipynb
index ccb09ae..3002c9c 100644
--- a/animations/discrete_bayes_animations.ipynb
+++ b/animations/discrete_bayes_animations.ipynb
@@ -1,409 +1,481 @@
{
- "metadata": {
- "name": "",
- "signature": "sha256:8f58b707cf76c184d840e41abdb14f1e584995252c4df05a742336b9f07b9b0b"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
+ "cells": [
{
- "cells": [
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Discrete Bayes Animations"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
{
- "cell_type": "heading",
- "level": 1,
+ "data": {
+ "text/html": [
+ "\n",
+ "\n"
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "execution_count": 1,
"metadata": {},
- "source": [
- "Discrete Bayes Animations"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "from __future__ import division, print_function\n",
- "import matplotlib.pyplot as plt\n",
- "import sys\n",
- "sys.path.insert(0,'..') # allow us to format the book\n",
- "sys.path.insert(0,'../code') \n",
- "import book_format\n",
- "book_format.load_style(directory='..')"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "html": [
- "\n",
- "\n"
- ],
- "metadata": {},
- "output_type": "pyout",
- "prompt_number": 8,
- "text": [
- ""
- ]
- }
- ],
- "prompt_number": 8
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "This notebook creates the animations for the Discrete Bayesian filters chapter. It is not really intended to be a readable part of the book, but of course you are free to look at the source code, and even modify it. However, if you are interested in running your own animations, I'll point you to the examples subdirectory of the book, which contains a number of python scripts that you can run and modify from an IDE or the command line. This module saves the animations to GIF files, which is quite slow and not very interactive. "
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "from matplotlib import animation\n",
- "import matplotlib.pyplot as plt\n",
- "import numpy as np\n",
- "from book_plots import bar_plot\n",
- "%matplotlib inline"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [],
- "prompt_number": 9
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# the predict algorithm of the discrete bayesian filter\n",
- "def predict(pos, move, p_correct, p_under, p_over):\n",
- " n = len(pos)\n",
- " result = np.array(pos, dtype=float)\n",
- " for i in range(n):\n",
- " result[i] = \\\n",
- " pos[(i-move) % n] * p_correct + \\\n",
- " pos[(i-move-1) % n] * p_over + \\\n",
- " pos[(i-move+1) % n] * p_under \n",
- " return result\n",
- "\n",
- "\n",
- "def normalize(p):\n",
- " s = sum(p)\n",
- " for i in range (len(p)):\n",
- " p[i] = p[i] / s\n",
- " \n",
- "# the update algorithm of the discrete bayesian filter\n",
- "def update(pos, measure, p_hit, p_miss):\n",
- " q = np.array(pos, dtype=float)\n",
- " for i in range(len(hallway)):\n",
- " if hallway[i] == measure:\n",
- " q[i] = pos[i] * p_hit\n",
- " else:\n",
- " q[i] = pos[i] * p_miss\n",
- " normalize(q)\n",
- " return q"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [],
- "prompt_number": 10
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "pos = [1.0,0,0,0,0,0,0,0,0,0]\n",
- "def bar_animate(nframe):\n",
- " global pos\n",
- " bar_plot(pos)\n",
- " pos = predict(pos, 1, .8, .1, .1)\n",
- "\n",
- "\n",
- "fig = plt.figure(figsize=(6.5, 2.5))\n",
- "anim = animation.FuncAnimation(fig, bar_animate,\n",
- " frames=100, interval=75)\n",
- "anim.save('02_no_info.gif', writer='imagemagick')"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "metadata": {},
- "output_type": "display_data",
- "png": "iVBORw0KGgoAAAANSUhEUgAAAbgAAACsCAYAAAAJ+rmKAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAADrJJREFUeJzt3X+Q3Hddx/Hnq0krBMIVy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klyZ5ItJ3p1k\n3bhDDfC7wAfGHaJXs3X+FuB/6B7dfl9VfXy8qR7iVuCFSX66+fn+Bt2PkK2qY6HgJnsf6jGk2T15\nDfDqZktuolTVj6rqWXR/Ec5KcvaYIx2R5DeBb1bVjUzwFhLw/Ko6HXgJ8CfN7vNJshZ4NvD3VfVs\nukdev3a8keaX5ATgpcA/jTtLryQ/B/wZcArdPTGPTvLysYbqU1X7gDcBHwP2ADcyhheGx0LBLebD\n5hoiyfHAB4H3VdU/jzvPIM0uq38FZsadpcfzgPOa97iuBl6c5D1jzvQQVfX15v9vAR+mu4t/khwA\nDlTV55v1a+gW3iR6CfCF5ns5SWaAz1bVt6vqMPAhuo/PiVJVV1TVTFW9CLiP7rEUq+pYKLgjHzZv\nXlFdSPfD5VqkJAEuB26rqreNO898kmxIcmKz/Ejg1+i+6psIVfX6qtpYVU+hu9vqE1X1++PO1SvJ\nuiTrm+VHAb8OTNSRvVX1DeDOJE9vLtoMfHmMkQbZSvfFzKTZB5yZ5JHN7/ZmYNJ255Pk8c3/TwZ+\nmzHs6h12JpOxW+jD5mOO9ROSXA28CHhckjuBN1TVlWOO1ev5wDbgliQPlsbrquraMWbq9zPAVc1R\na8cB762qfxtzpkEmcdf5ScCHu895rAXeX1UfG2+kee0A3t+8YL2dCTw5RPMCYTMwce9jVtXNzd6D\nWbq7/b4IvGu8qeZ1TZLH0T0g5o+r6rurHWDiPyYgSdJyHAu7KCVJWjILTpLUShacJKmVLDhJUitZ\ncJKkVrLgJEmtZMFJklrp/wGkNvPGWyX77wAAAABJRU5ErkJggg==\n",
- "text": [
- ""
- ]
- }
- ],
- "prompt_number": 11
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- ""
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "pos = np.array([.1]*10)\n",
- "hallway = np.array([1, 1, 0, 0, 0, 0, 0, 0, 1, 0])\n",
- "\n",
- "def bar_animate(nframe):\n",
- " global pos\n",
- " if nframe == 0:\n",
- " return\n",
- "\n",
- " bar_plot(pos, ylim=(0,1.0))\n",
- " if nframe % 2 == 0:\n",
- " pos = predict(pos, 1, .8, .1, .1)\n",
- " else:\n",
- " x = (nframe/2) % len(hallway)\n",
- " z = hallway[x]\n",
- " pos = update(pos, z, .6, .2)\n",
- " \n",
- "\n",
- "fig = plt.figure(figsize=(6.5, 2.5))\n",
- "anim = animation.FuncAnimation(fig, bar_animate,\n",
- " frames=60, interval=75)\n",
- "anim.save('02_simulate.gif', writer='imagemagick')"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "metadata": {},
- "output_type": "display_data",
- "png": "iVBORw0KGgoAAAANSUhEUgAAAbgAAACsCAYAAAAJ+rmKAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAADXJJREFUeJzt3X2QXXddx/H3pwm1BMpW6FgkXSYokZRRbHlIOyAPSpSk\naquMY41UxypYR4M4jlrgD/zDGRn+YGSYYifUtlMUGocCGsYmZRBEEKwN9IHSrJMUdkwCVJ66DA91\nEvn6xz2Nl+1m7+7mbs7Nr+/XTCb3nPPL3s/sZvdzf79zzt1UFZIkteaMvgNIkrQaLDhJUpMsOElS\nkyw4SVKTLDhJUpMsOElSk0YWXJIbkzyY5LOLjHl7kgNJ7kly0XgjSpK0fEuZwd0EbD3RwSSXAs+s\nqo3A7wLXjSmbJEkrNrLgqurjwDcWGXIZcHM39g7gnCTnjSeeJEkrs3YMH2M9cGho+zBwPvDgIzvm\n5uZ8uxRJ0qqZmprK/H3jushk/ge20CRJvRpHwR0Bpoe2z+/2SZLUm3EsUe4GdgC7klwCPFRVD55o\n8NTU1BieUpL0WDc3N7fo8ZEFl+QW4KXAuUkOAX8OPA6gqnZW1W1JLk1yEPg2cNVJp5Yk6STlVPy6\nnOGLTJzBSZLGYXgGt5oXmUiSNFEsOElSkyw4SVKTLDhJUpMsOElSkyw4SVKTLDhJUpMsOElSkyw4\nSVKTLDhJUpMsOElSkyw4SVK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uAO/pN8mhJzkhyN/Ag8NGqur/vTPP8FfCnwPf6\nDrKIAj6cZF+S1/QdZgHPAL6S5KYkn0lyfZJ1fYdaxK8B7+k7xLBudv5W4L8YXN3+UFV9uN9Uj3If\n8OIkT+6+vj/P4BayU+p0KLjJXkM9jXTLk7cCr+tmchOlqr5XVRcy+EZ4SZKX9RzpuCS/APx3Vd3F\nBM+QgBdV1UXANuAPuuXzSbIWeC7w11X1XAZXXr++30gLS3Im8IvAe/vOMizJjwJ/BGxgsBLzxCSv\n6jXUPFU1A7wF+BCwB7iLHl4Yng4Ft5SbzTVCkscB7wP+rqr+oe88i+mWrP4JeH7fWYa8ELisO8d1\nC/AzSd7Vc6ZHqaovdX9/BfgAgyX+SXIYOFxVd3bbtzIovEm0Dfh097mcJM8HPllVX6uqY8D7Gfz/\nnChVdWNVPb+qXgo8xOBailPqdCi44zebd6+ormBwc7mWKEmAG4D7q+ptfedZSJJzk5zTPX488LMM\nXvVNhKp6Y1VNV9UzGCxbfaSqfrPvXMOSrEtydvf4CcDPARN1ZW9VfRk4lOTHul1bgM/1GGkx2xm8\nmJk0M8AlSR7ffW9vASZtOZ8kP9T9/XTgl+lhqXfif6P3iW427znW90lyC/BS4ClJDgFvqqqbeo41\n7EXAlcC9SR4pjTdU1d4eM833w8DN3VVrZwB/W1X/3HOmxUzi0vl5wAcGP/NYC7y7qj7Ub6QFvRZ4\nd/eC9QEm8M0huhcIW4CJO49ZVfd0qwf7GCz7fQZ4Z7+pFnRrkqcwuCDm96vqm6c6wMTfJiBJ0kqc\nDkuUkiQtmwUnSWqSBSdJapIFJ0lqkgUnSWqSBSdJapIFJ0lq0v8ByVyjNXG2/lYAAAAASUVORK5C\nYII=\n",
- "text": [
- ""
- ]
- }
- ],
- "prompt_number": 14
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- " "
- ]
+ "output_type": "execute_result"
}
],
- "metadata": {}
+ "source": [
+ "from __future__ import division, print_function\n",
+ "import matplotlib.pyplot as plt\n",
+ "import sys\n",
+ "sys.path.insert(0,'..') # allow us to format the book\n",
+ "sys.path.insert(0,'../code') \n",
+ "import book_format\n",
+ "book_format.load_style(directory='..')"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "This notebook creates the animations for the Discrete Bayesian filters chapter. It is not really intended to be a readable part of the book, but of course you are free to look at the source code, and even modify it. However, if you are interested in running your own animations, I'll point you to the examples subdirectory of the book, which contains a number of python scripts that you can run and modify from an IDE or the command line. This module saves the animations to GIF files, which is quite slow and not very interactive. "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [],
+ "source": [
+ "from matplotlib import animation\n",
+ "import matplotlib.pyplot as plt\n",
+ "import numpy as np\n",
+ "from book_plots import bar_plot\n",
+ "%matplotlib inline\n",
+ "\n",
+ "# the predict algorithm of the discrete bayesian filter\n",
+ "def predict(pos, move, p_correct, p_under, p_over):\n",
+ " n = len(pos)\n",
+ " result = np.array(pos, dtype=float)\n",
+ " for i in range(n):\n",
+ " result[i] = \\\n",
+ " pos[(i-move) % n] * p_correct + \\\n",
+ " pos[(i-move-1) % n] * p_over + \\\n",
+ " pos[(i-move+1) % n] * p_under \n",
+ " return result\n",
+ "\n",
+ "\n",
+ "def normalize(p):\n",
+ " s = sum(p)\n",
+ " for i in range (len(p)):\n",
+ " p[i] = p[i] / s\n",
+ " \n",
+ "# the update algorithm of the discrete bayesian filter\n",
+ "def update(pos, measure, p_hit, p_miss):\n",
+ " q = np.array(pos, dtype=float)\n",
+ " for i in range(len(hallway)):\n",
+ " if hallway[i] == measure:\n",
+ " q[i] = pos[i] * p_hit\n",
+ " else:\n",
+ " q[i] = pos[i] * p_miss\n",
+ " normalize(q)\n",
+ " return q"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "'imagemagick'"
+ ]
+ },
+ "execution_count": 3,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "import matplotlib\n",
+ "matplotlib.matplotlib_fname()\n",
+ "matplotlib.rcParams['animation.writer']"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "\"anim = animation.FuncAnimation(fig, bar_animate,\\n frames=100, interval=75)\\nanim.save('02_no_info.gif', writer='imagemagick')\""
+ ]
+ },
+ "execution_count": 5,
+ "metadata": {},
+ "output_type": "execute_result"
+ },
+ {
+ "data": {
+ "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZgAAAELCAYAAADkyZC4AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAE49JREFUeJzt3X+QXXd93vH3YwkDBrE2UbFBFmMoW2onBALCBhx+JChB\nNq3dhkxcFYcBiuO2WGGameI2ndLMME1LAilDDIyCbTAFbBIDid2xbOqBGAiuYbFdYywR2cJEsgy2\nwSxCJkSKP/3jHonrrfan9qt7Vvt+zezsPed8z7mPVrv32fPrbqoKSZIW2zGjDiBJOjpZMJKkJiwY\nSVITFowkqQkLRpLUhAUjSWrCgpEkNWHBaFlJ8sQk70zy10keSfK9JF9JsmlozKVJPn8EM52U5ONJ\n7kyyL8n/nmbc05P8aZLJ7uPKJP/gSOWU5mvlqANIR9gHgVcBvw38X+ApwAuBtSPM9Hjge8B7gN8A\nVkwdkOQY4H8B+4H1DH45/ADw58CZRyypNA/xTn4tJ0keBv5TVX1gmuW/B7xjyuw3VtVHkzwZ+K/A\n64ATgG8C76yqz3TrngLsAH4TeDPwUuB+4Her6pNzzPcRYE1V/cqU+b8KXA88t6q2d/NOA+4Efqmq\nbprL9qUjyUNkWm7uB85KcsI0y/8Q+ATwZeCk7uNPkwS4Fngeg72Mn2WwN3RVkl+eso0/AC4Fnt9t\n6+NJXnCYuc8E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bLkJXAcV0RH0c/rqj9x8AtVfW3VfX3wE3Arx2J\nJ+5zwczlJk8dQpJTgF8ARr6nkOSYJLcD3wU+W1VfHXWmzv8A/j09KbwhBdyYZCLJBaMOAzwLeDDJ\nh5PcmuRDSY4bdagp/gXwiVGHqKr7gPcAfwPsZnBF7Y2jTQXAncDLkzy1+797LUfoZvg+F0w/j931\nXHd47GoGh6J+NOo8VfVoVb2AwTf0GUl+dtSZkvwT4IHuTVl7s7fQObOqfoHBm8e+tTskO0orgRcC\nH6iqFzK4UvQ/jDbST3W3T/xT4M96kOUEBm+ddQqDowdPTvL6kYYCqmob8C7gs8AW4DaO0C9WfS6Y\nudzkqSFJHgd8CvhYVf35qPMM6w6rfJ7BG6eO2suAc7rzHVcCv5zkoyPOBEBV3d99fhD4DINDxaO0\nC9g1tOd5NYPC6YuzgK91X69RWw98q6q+V1X7gU8z+F4buaq6vKrWVdUrgR8wOL/dXJ8LZi43eaqT\nJMBlwF1V9d5R5wFIsjrJ8d3jJwK/wuDc0EhV1e9W1dqqehaDwyufq6o3jDpXkuOSrOoePwn4VWCk\nVytW1XeAnUn+UTdrPfCNEUaaaiODXxL64NvAS5I8sft5XA/cNeJMACR5Wvf5mcA/5wgdUuztHxyb\n7ibPEcciyZXAK4GfSbITeEdVfXjEsQDOBM4H7khy4O/x/Mequn6EmZ4OXNFdEXgM8Mmqum6EeabT\nl8OxJwKfGbw2sRL4eFV9drSRANgEfLz7Re8eDnEz9Sh0Jbwe6MO5KqrqK0muBm4F9nef/2S0qQ66\nOsnPMLiK7N9W1Q+PxJP29jJlSdLS1udDZJKkJcyCkSQ1YcFIkpqwYCRJTVgwkqQmLBhJUhMWjCSp\nCQtGktTE/wPYAenFmNOy1QAAAABJRU5ErkJggg==\n",
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ },
+ {
+ "data": {
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ },
+ {
+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47oE\n+OUkb57xTHdSVV8d/v0m8KeM7uKfJ3uAPWNH55cxCt48egbwqeF7OU/OBL5SVd+qqn3AOxn99zlX\nqur1VbWlqp4CfIfRcymOqKMhcAfzYnOtIEmAi4EvVNX/mPU8S0lyfJLjhtP3Av4Bo8cK50JV/ceq\n2lRVD2F0t9UHqur5s55rXJJjk9x3OH1v4OnAXD2zt6q+BuxO8vBh05nA52c40kq2MboxM2/+Ejgj\nyb2G3+0zgS/MeKY7SfLA4d+fAX6VGdzVu+ILvefBci82n/FYPyHJJcBTgJ9Kshv4nap6w4zHGvdE\n4Bzgs0muHbb9h6p6zwxnmvRg4E3Ds2aPAd5eVVfMeKaVzONd5ycAfzr6m8dG4K1V9b7ZjrSk7cBb\nhxusX2aJN4eYteEGwpnA3D2OWVXXJLkM+DSwb/j3D2c71ZIuS/JTjJ5F+VtV9d0jPcDcv0xAkqT1\nOBruopQkac0MnCSpJQMnSWrJwEmSWjJwkqSWDJwkqSUDJ0lqycBJklr6f3Fv5H3JWvWBAAAAAElF\nTkSuQmCC\n",
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "from gif_animate import animate\n",
+ "\n",
+ "pos = [1.0,0,0,0,0,0,0,0,0,0]\n",
+ "def bar_animate(nframe):\n",
+ " global pos\n",
+ " bar_plot(pos)\n",
+ " plt.title('Step {}'.format(nframe + 1))\n",
+ " pos = predict(pos, 1, .8, .1, .1)\n",
+ "\n",
+ "for i in range(10):\n",
+ " bar_animate(i)\n",
+ "\n",
+ "fig = plt.figure(figsize=(6.5, 2.5))\n",
+ "animate('foo.gif', bar_animate, frames=100, interval=75);\n",
+ "'''anim = animation.FuncAnimation(fig, bar_animate,\n",
+ " frames=100, interval=75)\n",
+ "anim.save('02_no_info.gif', writer='imagemagick')'''"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ ""
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [],
+ "source": [
+ "pos = np.array([.1]*10)\n",
+ "hallway = np.array([1, 1, 0, 0, 0, 0, 0, 0, 1, 0])\n",
+ "\n",
+ "def bar_animate(nframe):\n",
+ " global pos\n",
+ " if nframe == 0:\n",
+ " return\n",
+ "\n",
+ " bar_plot(pos, ylim=(0,1.0))\n",
+ " if nframe % 2 == 0:\n",
+ " pos = predict(pos, 1, .8, .1, .1)\n",
+ " else:\n",
+ " x = (nframe/2) % len(hallway)\n",
+ " z = hallway[x]\n",
+ " pos = update(pos, z, .6, .2)\n",
+ " \n",
+ "\n",
+ "fig = plt.figure(figsize=(6.5, 2.5))\n",
+ "anim = animation.FuncAnimation(fig, bar_animate,\n",
+ " frames=60, interval=75)\n",
+ "anim.save('02_simulate.gif', writer='imagemagick')"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ " "
+ ]
}
- ]
-}
\ No newline at end of file
+ ],
+ "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.5.1"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}