{
 "metadata": {
  "name": "",
  "signature": "sha256:47d64bacc2f597ef2e39688a14b58dc93224617c01ee343a7bb71c0cc97e6efa"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 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,'../code') # allow us to format the book\n",
      "import book_format\n",
      "book_format.load_style()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "html": [
        "<style>\n",
        "@import url('http://fonts.googleapis.com/css?family=Source+Code+Pro');\n",
        "\n",
        "    div.cell{\n",
        "        width: 850px;\n",
        "        margin-left: 0% !important;\n",
        "        margin-right: auto;\n",
        "    }\n",
        "    div.text_cell code {\n",
        "        background: transparent;\n",
        "        color: #000000;\n",
        "        font-weight: 600;\n",
        "        font-size: 11pt;\n",
        "        font-style: bold;\n",
        "        font-family:  'Source Code Pro', Consolas, monocco, monospace;\n",
        "   }\n",
        "    h1 {\n",
        "        font-family: 'Open sans',verdana,arial,sans-serif;\n",
        "\t}\n",
        "\t\n",
        "    div.input_area {\n",
        "        background: #F6F6F9;\n",
        "        border: 1px solid #586e75;\n",
        "    }\n",
        "\n",
        "    .text_cell_render h1 {\n",
        "        font-weight: 200;\n",
        "        font-size: 30pt;\n",
        "        line-height: 100%;\n",
        "        color:#c76c0c;\n",
        "        margin-bottom: 0.5em;\n",
        "        margin-top: 1em;\n",
        "        display: block;\n",
        "        white-space: wrap;\n",
        "    } \n",
        "    h2 {\n",
        "        font-family: 'Open sans',verdana,arial,sans-serif;\n",
        "    }\n",
        "    .text_cell_render h2 {\n",
        "        font-weight: 200;\n",
        "        font-size: 20pt;\n",
        "        font-style: italic;\n",
        "        line-height: 100%;\n",
        "        color:#c76c0c;\n",
        "        margin-bottom: 0.5em;\n",
        "        margin-top: 1.5em;\n",
        "        display: block;\n",
        "        white-space: nowrap;\n",
        "    } \n",
        "    h3 {\n",
        "        font-family: 'Open sans',verdana,arial,sans-serif;\n",
        "    }\n",
        "    .text_cell_render h3 {\n",
        "        font-weight: 300;\n",
        "        font-size: 18pt;\n",
        "        line-height: 100%;\n",
        "        color:#d77c0c;\n",
        "        margin-bottom: 0.5em;\n",
        "        margin-top: 2em;\n",
        "        display: block;\n",
        "        white-space: nowrap;\n",
        "    }\n",
        "    h4 {\n",
        "        font-family: 'Open sans',verdana,arial,sans-serif;\n",
        "    }\n",
        "    .text_cell_render h4 {\n",
        "        font-weight: 300;\n",
        "        font-size: 16pt;\n",
        "        color:#d77c0c;\n",
        "        margin-bottom: 0.5em;\n",
        "        margin-top: 0.5em;\n",
        "        display: block;\n",
        "        white-space: nowrap;\n",
        "    }\n",
        "    h5 {\n",
        "        font-family: 'Open sans',verdana,arial,sans-serif;\n",
        "    }\n",
        "    .text_cell_render h5 {\n",
        "        font-weight: 300;\n",
        "        font-style: normal;\n",
        "        color: #1d3b84;\n",
        "        font-size: 16pt;\n",
        "        margin-bottom: 0em;\n",
        "        margin-top: 1.5em;\n",
        "        display: block;\n",
        "        white-space: nowrap;\n",
        "    }\n",
        "    div.text_cell_render{\n",
        "        font-family: 'Open sans',verdana,arial,sans-serif;\n",
        "        line-height: 135%;\n",
        "        font-size: 110%;\n",
        "        width:750px;\n",
        "        margin-left:auto;\n",
        "        margin-right:auto;\n",
        "        text-align:justify;\n",
        "        text-justify:inter-word;\n",
        "    }\n",
        "    div.output_subarea.output_text.output_pyout {\n",
        "        overflow-x: auto;\n",
        "        overflow-y: scroll;\n",
        "        max-height: 300px;\n",
        "    }\n",
        "    div.output_subarea.output_stream.output_stdout.output_text {\n",
        "        overflow-x: auto;\n",
        "        overflow-y: scroll;\n",
        "        max-height: 300px;\n",
        "    }\n",
        "    code{\n",
        "      font-size: 70%;\n",
        "    }\n",
        "    .rendered_html code{\n",
        "    background-color: transparent;\n",
        "    }\n",
        "    ul{\n",
        "        margin: 2em;\n",
        "    }\n",
        "    ul li{\n",
        "        padding-left: 0.5em; \n",
        "        margin-bottom: 0.5em; \n",
        "        margin-top: 0.5em; \n",
        "    }\n",
        "    ul li li{\n",
        "        padding-left: 0.2em; \n",
        "        margin-bottom: 0.2em; \n",
        "        margin-top: 0.2em; \n",
        "    }\n",
        "    ol{\n",
        "        margin: 2em;\n",
        "    }\n",
        "    ol li{\n",
        "        padding-left: 0.5em; \n",
        "        margin-bottom: 0.5em; \n",
        "        margin-top: 0.5em; \n",
        "    }\n",
        "    ul li{\n",
        "        padding-left: 0.5em; \n",
        "        margin-bottom: 0.5em; \n",
        "        margin-top: 0.2em; \n",
        "    }\n",
        "    a:link{\n",
        "       font-weight: bold;\n",
        "       color:#447adb;\n",
        "    }\n",
        "    a:visited{\n",
        "       font-weight: bold;\n",
        "       color: #1d3b84;\n",
        "    }\n",
        "    a:hover{\n",
        "       font-weight: bold;\n",
        "       color: #1d3b84;\n",
        "    }\n",
        "    a:focus{\n",
        "       font-weight: bold;\n",
        "       color:#447adb;\n",
        "    }\n",
        "    a:active{\n",
        "       font-weight: bold;\n",
        "       color:#447adb;\n",
        "    }\n",
        "    .rendered_html :link {\n",
        "       text-decoration: underline; \n",
        "    }\n",
        "    .rendered_html :hover {\n",
        "       text-decoration: none; \n",
        "    }\n",
        "    .rendered_html :visited {\n",
        "      text-decoration: none;\n",
        "    }\n",
        "    .rendered_html :focus {\n",
        "      text-decoration: none;\n",
        "    }\n",
        "    .rendered_html :active {\n",
        "      text-decoration: none;\n",
        "    }\n",
        "    .warning{\n",
        "        color: rgb( 240, 20, 20 )\n",
        "    } \n",
        "    hr {\n",
        "      color: #f3f3f3;\n",
        "      background-color: #f3f3f3;\n",
        "      height: 1px;\n",
        "    }\n",
        "    blockquote{\n",
        "      display:block;\n",
        "      background: #fcfcfc;\n",
        "      border-left: 5px solid #c76c0c;\n",
        "      font-family: 'Open sans',verdana,arial,sans-serif;\n",
        "      width:680px;\n",
        "      padding: 10px 10px 10px 10px;\n",
        "      text-align:justify;\n",
        "      text-justify:inter-word;\n",
        "      }\n",
        "      blockquote p {\n",
        "        margin-bottom: 0;\n",
        "        line-height: 125%;\n",
        "        font-size: 100%;\n",
        "      }\n",
        "</style>\n",
        "<script>\n",
        "    MathJax.Hub.Config({\n",
        "                        TeX: {\n",
        "                           extensions: [\"AMSmath.js\"]\n",
        "                           },\n",
        "                tex2jax: {\n",
        "                    inlineMath: [ ['$','$'], [\"\\\\(\",\"\\\\)\"] ],\n",
        "                    displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"] ]\n",
        "                },\n",
        "                displayAlign: 'center', // Change this to 'center' to center equations.\n",
        "                \"HTML-CSS\": {\n",
        "                    styles: {'.MathJax_Display': {\"margin\": 4}}\n",
        "                }\n",
        "        });\n",
        "</script>\n"
       ],
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 1,
       "text": [
        "<IPython.core.display.HTML at 0x7f77b8e02fd0>"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "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",
      "%matplotlib inline\n",
      "\n",
      "def barplot(pos, ylim=(0,1)):\n",
      "    \"\"\" implement plotting of bar plots in a way that plays nicely with the\n",
      "    animations.\"\"\"\n",
      "    \n",
      "    plt.cla()\n",
      "    ax = plt.gca()\n",
      "    x = np.arange(len(pos))\n",
      "    ax.bar(x, pos)\n",
      "    if ylim:\n",
      "        plt.ylim(ylim)\n",
      "    plt.xticks(x+0.4, x)\n",
      "    plt.grid()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 2
    },
    {
     "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": 3
    },
    {
     "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",
      "    barplot(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('no_info.gif', writer='imagemagick')"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "display_data",
       "png": "iVBORw0KGgoAAAANSUhEUgAAAY0AAACuCAYAAADK6FH9AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAADl9JREFUeJzt3WuMXGd9x/HvHxL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/HRX\nWUopbwCO9WeqkzTLuKLW+kp672n6RCnlGR1m2UzvEPDvA68BdvcPyXSqP0P8qdWZdIc5XgC8HXg+\nvR2hP+r/vnWm1voVeoeiF4C/oXdn8Qs+q98IpfGj3MrkJ1YpZTO9KfxcrfVrXedZVWt9CHiE3l5Q\nV14N3FRKWQLeCfxxKeXNHeYBeocV+/89CHwTeEGHcY4DD9Zav1FrfYLeYbyrO8yz6i3AP3Qdgt5h\n8gO11if6h4LuA17ecSZqrX/RP/ezi97fxkcu9DY3wuGpA8D2Usrp25N0eUJsEpVSAvgI8Ila6xcm\nIM/PAT/oT+mngKuAzoqs1no7cHs/2x3AE7XWT3aVp5/jOcD/1Fq/39+LvQL4eoeRDgJX9nN9l94J\n34c7zLPqzUzGRScPA+/uX5jzdHoz6Pd2mojelYr937PXAM+utX75Qm9z4mcatdZTwOrtSfYyAbcn\nKaV8iN6U8KpSynIppet/pfA64CbgbaWU+/qPLqfOVwL7SimHgX+lN/uZpBOrk+Bq4L5Syv3APwG/\nV2v9fldhaq0n6f1ufRH4Mr0dkGNd5YHTlwA/UWv9ry5zwOnZ4GfpzTAO0jvnc7TbVAD8XSnlCL2r\nSt96MTbobUQkSc0mfqYhSZocloYkqZmlIUlqZmlIkppZGpKkZpaGJKmZpSFJavb/A9CC7H8FLJ4A\nAAAASUVORK5CYII=\n",
       "text": [
        "<matplotlib.figure.Figure at 0x7f77b8e02b38>"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      " <img src=\"no_info.gif\">"
     ]
    },
    {
     "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",
      "    barplot(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=200)\n",
      "anim.save('simulate.gif', writer='imagemagick')"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "display_data",
       "png": "iVBORw0KGgoAAAANSUhEUgAAAY0AAACuCAYAAADK6FH9AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAADtRJREFUeJzt3W+MXFd9xvHvDxLHaUMFocabxg1/GpoEE5lAYeXNC6SG\nAnENVZNyKlBRlVYlUF7U0qolBKUBVOogZdWillYRElCkQjnQokqpEmiNVRXvvrBNGgdnY0NAYSm2\nYjnCJEBjF359MbPW2lnPnNizvuPk+5FWmblzdu/j2LvPPefeuRuZiSRJLZ7TdQBJ0rnD0pAkNbM0\nJEnNLA1JUjNLQ5LUzNKQJDUbWhoRcWdEHIyIBxrGlojYHxH7ImLzaCJKksZFDHufRkRsBI4Cn87M\nqweMWwU8BEwCq4HtmXn5CLNKkjo2dKaRmXPA4YavNQnszcxDmbkALETEhjMNKEkaH+eN8GutBQ5E\nxM3AY8BB4BLg/hHuQ5LUoVGWBgCZeRdARNwAPGXta9u2bd63RJLOAdddd12cvG2UpXGA3sxi0UR/\n21NcddVVp7WDe+65h+uvv/60PnclmGewccsD45fJPIONWx4Yv0wrlWd+fn7Z7addGhGxFcjMvLW/\naSewPiLW0DsRvi4z95zu15ckjZ+WS24/DswCV0TEwpJLaSf6HwBk5lHgFmAHsA3YMvq4kqQuDZ1p\nZOZ7gfcus/2mZbZVoI4m2lNdfvl4XcFrnsHGLQ+MXybzDDZueWD8Mp3tPEPfpzFq27Zty9M9pyFJ\nOjvm5+eXPRHubUQkSc0sDUlSM0tDktTM0pA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8up82XA9lLKHuDf6c1+xunE6ji4ErivlHI/\n8C/AH9Zaf9JVmFrrEXrfW18Fvk7vAGR/V3ng+CXAj9daO/91gv3Z4JfozTB20Tvns6/bVAB8spSy\nl95Vpe88Gzv0NiKSpGZjP9OQJI0PS0OS1MzSkCQ1szQkSc0sDUlSM0tDktTM0pAkNft/m9qAs9EE\nOqgAAAAASUVORK5CYII=\n",
       "text": [
        "<matplotlib.figure.Figure at 0x7f779abe8c18>"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      " <img src=\"simulate.gif\">"
     ]
    }
   ],
   "metadata": {}
  }
 ]
}