{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Reinforcement Learning\n",
    "\n",
    "This IPy notebook acts as supporting material for **Chapter 21 Reinforcement Learning** of the book* Artificial Intelligence: A Modern Approach*. This notebook makes use of the implementations in rl.py module. We also make use of implementation of MDPs in the mdp.py module to test our agents. It might be helpful if you have already gone through the IPy notebook dealing with Markov decision process. Let us import everything from the rl module. It might be helpful to view the source of some of our implementations. Please refer to the Introductory IPy file for more details."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from rl import *"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "## Review\n",
    "Before we start playing with the actual implementations let us review a couple of things about RL.\n",
    "\n",
    "1. Reinforcement Learning is concerned with how software agents ought to take actions in an environment so as to maximize some notion of cumulative reward. \n",
    "\n",
    "2. Reinforcement learning differs from standard supervised learning in that correct input/output pairs are never presented, nor sub-optimal actions explicitly corrected. Further, there is a focus on on-line performance, which involves finding a balance between exploration (of uncharted territory) and exploitation (of current knowledge).\n",
    "\n",
    "-- Source: [Wikipedia](https://en.wikipedia.org/wiki/Reinforcement_learning)\n",
    "\n",
    "In summary we have a sequence of state action transitions with rewards associated with some states. Our goal is to find the optimal policy (pi) which tells us what action to take in each state."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Passive Reinforcement Learning\n",
    "\n",
    "In passive Reinforcement Learning the agent follows a fixed policy and tries to learn the Reward function and the Transition model (if it is not aware of that).\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Passive Temporal Difference Agent\n",
    "\n",
    "The PassiveTDAgent class in the rl module implements the Agent Program (notice the usage of word Program) described in **Fig 21.4** of the AIMA Book. PassiveTDAgent uses temporal differences to learn utility estimates. In simple terms we learn the difference between the states and backup the values to previous states while following a fixed policy.  Let us look into the source before we see some usage examples."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "%psource PassiveTDAgent"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The Agent Program can be obtained by creating the instance of the class by passing the appropriate parameters. Because of the __ call __ method the object that is created behaves like a callable and returns an appropriate action as most Agent Programs do. To instantiate the object we need a policy(pi) and a mdp whose utility of states will be estimated. Let us import a GridMDP object from the mdp module. **Figure 17.1 (sequential_decision_environment)** is similar to **Figure 21.1** but has some discounting as **gamma = 0.9**."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from mdp import sequential_decision_environment"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Figure 17.1 (sequential_decision_environment)** is a GridMDP object and is similar to the grid shown in **Figure 21.1**. The rewards in the terminal states are **+1** and **-1** and **-0.04** in rest of the states. <img src=\"files/images/mdp.png\"> Now we define a policy similar to **Fig 21.1** in the book."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Action Directions\n",
    "north = (0, 1)\n",
    "south = (0,-1)\n",
    "west = (-1, 0)\n",
    "east = (1, 0)\n",
    "\n",
    "policy = {\n",
    "    (0, 2): east,  (1, 2): east,  (2, 2): east,   (3, 2): None,\n",
    "    (0, 1): north,                (2, 1): north,  (3, 1): None,\n",
    "    (0, 0): north, (1, 0): west,  (2, 0): west,   (3, 0): west, \n",
    "}\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let us create our object now. We also use the **same alpha** as given in the footnote of the book on **page 837**."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "our_agent = PassiveTDAgent(policy, sequential_decision_environment, alpha=lambda n: 60./(59+n))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The rl module also has a simple implementation to simulate iterations. The function is called **run_single_trial**. Now we can try our implementation. We can also compare the utility estimates learned by our agent to those obtained via **value iteration**.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from mdp import value_iteration"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The values calculated by value iteration:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{(0, 1): 0.3984432178350045, (1, 2): 0.649585681261095, (3, 2): 1.0, (0, 0): 0.2962883154554812, (3, 0): 0.12987274656746342, (3, 1): -1.0, (2, 1): 0.48644001739269643, (2, 0): 0.3447542300124158, (2, 2): 0.7953620878466678, (1, 0): 0.25386699846479516, (0, 2): 0.5093943765842497}\n"
     ]
    }
   ],
   "source": [
    "print(value_iteration(sequential_decision_environment))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now the values estimated by our agent after **200 trials**."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{(0, 1): 0.3892840731173828, (1, 2): 0.6211579621949068, (3, 2): 1, (0, 0): 0.3022330060485855, (2, 0): 0.0, (3, 0): 0.0, (1, 0): 0.18020445259687815, (3, 1): -1, (2, 2): 0.822969605478094, (2, 1): -0.8456690895152308, (0, 2): 0.49454878907979766}\n"
     ]
    }
   ],
   "source": [
    "for i in range(200):\n",
    "    run_single_trial(our_agent,sequential_decision_environment)\n",
    "print(our_agent.U)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can also explore how these estimates vary with time by using plots similar to **Fig 21.5a**. To do so we define a function to help us with the same. We will first enable matplotlib using the inline backend."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "def graph_utility_estimates(agent_program, mdp, no_of_iterations, states_to_graph):\n",
    "    graphs = {state:[] for state in states_to_graph}\n",
    "    for iteration in range(1,no_of_iterations+1):\n",
    "        run_single_trial(agent_program, mdp)\n",
    "        for state in states_to_graph:\n",
    "            graphs[state].append((iteration, agent_program.U[state]))\n",
    "    for state, value in graphs.items():\n",
    "        state_x, state_y = zip(*value)\n",
    "        plt.plot(state_x, state_y, label=str(state))\n",
    "    plt.ylim([0,1.2])\n",
    "    plt.legend(loc='lower right')\n",
    "    plt.xlabel('Iterations')\n",
    "    plt.ylabel('U')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Here is a plot of state (2,2)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAEKCAYAAAD9xUlFAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3Xd4HOW1+PHv2VXvsoqbbOResY2RDQbTDTHNlBBKIAkB\nLuQmIYUkXFIggYSEJDck9/4C3BAgdAghFIeOQzHY2Lj3Jne5qdhqVt3d9/fHFI2kVbVWkqXzeR4/\n1s7Ojt5Z7c6Z97xNjDEopZRSAL6eLoBSSqneQ4OCUkoplwYFpZRSLg0KSimlXBoUlFJKuTQoKKWU\nckUsKIjIEyJSKCLrW3j+ehFZKyLrRGSxiEyNVFmUUkq1TyRrCk8Cc1t5fidwljHmROCXwKMRLItS\nSql2iIrUgY0xC0Ukt5XnF3seLgFyIlUWpZRS7ROxoNBBNwNvt/SkiNwK3AqQmJh48vjx47urXEop\n1SesWLGi2BiT1dZ+PR4UROQcrKAwu6V9jDGPYqeX8vLyzPLly7updEop1TeIyO727NejQUFEpgCP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XNGDPCGOPUFI66O1lT\nOc/BWtRlKta8RHHH8HtrPT8HsRaRCWDNkPkycAnwzjEcX6l206Cg+rMKINnz+F3gP+2puRGRsfZs\nlU2lYi39WCUi47GWBXXUO69v4hPgGrvdIgs4E2vitrDs9SJSjTFvAd/HSjspFXHapqD6s7VA0E4D\nPYk1X38usNJu7C0CLg/zuneAb9h5/y1YKSTHo8BaEVlprKmeHa9irYGwBmuW1zuNMQftoBJOMvC6\niMRh1WDu6NwpKtUxOkuqUkopl6aPlFJKuTQoKKWUcmlQUEop5dKgoJRSyqVBQSmllEuDglJKKZcG\nBaWUUq7/D2ktlL9G6rguAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f2937e6ccf8>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "agent = PassiveTDAgent(policy, sequential_decision_environment, alpha=lambda n: 60./(59+n))\n",
    "graph_utility_estimates(agent, sequential_decision_environment, 500, [(2,2)])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "It is also possible to plot multiple states on the same plot."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAEKCAYAAAD9xUlFAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3XecVNX5x/HPA0sv0hEEAQ2gKEVcFSs2CFiwYSIRS2Is\niUaNkUSTXzQxMbEkaozGBCNiQVGJxtUoGNSIYF0ElyaK1AWVpYkodff8/nju3J1dtrOz9ft+vfY1\nM/eeuXPuzp37nHbPtRACIiIiAA2qOwMiIlJzKCiIiEhMQUFERGIKCiIiElNQEBGRmIKCiIjEUhYU\nzGyCma01s/nFrD/fzLLMbJ6ZvWVmA1OVFxERKZtU1hQmAiNKWL8MGBpC6A/8DhifwryIiEgZpKVq\nwyGEGWbWs4T1byW9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AAQPo3r07v/jFL+jatWuZtzdhwgRGjhwZv05PT+fNN9+szCwDqimISD1QWok+\nFdatW0ebNm0KLOvevTtZWVmsWbOGM888k9GjR9O5c+dSt3XrrbeSlpbG+eefHy/r1KlTqc1PFaGa\ngohICjRr1qzY6wW6du3KwQcfXKaS/sSJE3nxxReZNGlSgeGm27Zto1mzZpWW3wQFBRGRFGjbti25\nublxYMjOzmbr1q0AbNy4kZkzZ9K3b18ALrzwQt57773dtjF16lTuuOMOMjIyaN68eYF1H3/8MQcf\nfHCl51tBQUQkRYYPH87MmTMBWLRoEUcccQQDBw5k6NChXH/99fTv3x+ArKysIvsXrrrqKr766iuG\nDRvGoEGDuOKKK+J1r7/+Oqeeemql51l9CiIiKXLllVdy9913c/LJJzNs2DCysrJ2S7N582Z69+5N\nt27ddlu3ZMmSIre7fft2MjMzueeeeyo9z6opiIikyODBgznhhBPIzc0tNk3r1q155plnyrXdlStX\nctttt5GWVvnletUURERS6Ac/+EGlb7N379707t270rcLqimIiEgSBQUREYkpKIiISExBQUREYgoK\nIiIpkjx19ty5cznyyCM56KCDGDBgAE899VSp77/rrrvo168fAwYM4KSTTmLFihUA5OTkMGLEiJTk\nWUFBRCRFkqfObt68OY8++igLFixg6tSpXHvttfH9EYpzyCGHkJmZSVZWFqNHj45nRO3YsSNdunRh\n1qxZlZ5nDUkVkbrv5Rvg83mVu829+8PI20pMkjx1dp8+feLlXbt2pVOnTuTk5Ow2aV6yE044IX4+\nZMgQHn/88fj1mWeeyaRJkzj66KMrugdFUk1BRCQFipo6O+G9995jx44d7L///mXe3kMPPaSps0VE\nKkUpJfpUKGrqbIDPPvuMCy64gEceeYQGDcpWLn/88cfJzMzkjTfeiJelaupsBQURkRQoaurszZs3\nc+qpp3LrrbcyZMiQMm1n+vTp3Hrrrbzxxhs0adIkXq6ps0VEapHCU2fv2LGDs846iwsvvJDRo0cX\nSHvjjTfy3HPP7baNOXPmcPnll5ORkUGnTp0KrNPU2SIitUzy1NlPP/00M2bMY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MKGaNqJ983sXyGEG8zsqhDCoCI+62z8XggDgQ7Re2ZE6w4BDgLWALOA\no81sEXAWcEAIISSmuRBJNdUURPINx+eSmYtPx90ev4EJwHtJAQHgajP7EHgHn5SsNyU7BngyhJAb\nQvgCeAM4LGnb2SGEPHzajp741M/bgIfM7Gzgmz3eO5EyUFAQyWfAT4Lf9WpQCKFXCCFRU/g6TuRT\nOZ+M39RlID4vUdM9+NztSc9z8ZvI7MJnyJwCnAZM3YPti5SZgoLUZ18BrZJeTwN+FE3NjZn1iWar\nLGwv/NaP35jZAfhtQRN2Jt5fyJvAd6N+i47AcfjEbUWK7hexVwjhJeCneLOTSMqpT0HqsywgN2oG\nmojP198T+CDq7M0BzizifVOBK6J2/8V4E1LCeCDLzD4IPtVzwnP4PRA+xGd5/XkI4fMoqBSlFfC8\nmTXFazDXVWwXRcpHs6SKiEhMzUciIhJTUBARkZiCgoiIxBQUREQkpqAgIiIxBQUREYkpKIiISOz/\nAW4Hvin6vj2yAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f29346fe9b0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "graph_utility_estimates(agent, sequential_decision_environment, 500, [(2,2), (3,2)])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "## Active Reinforcement Learning\n",
    "\n",
    "Unlike Passive Reinforcement Learning in Active Reinforcement Learning we are not bound by a policy pi and we need to select our actions. In other words the agent needs to learn an optimal policy. The fundamental tradeoff the agent needs to face is that of exploration vs. exploitation. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### QLearning Agent\n",
    "\n",
    "The QLearningAgent class in the rl module implements the Agent Program described in **Fig 21.8** of the AIMA Book. In Q-Learning the agent learns an action-value function Q which gives the utility of taking a given action in a particular state. Q-Learning does not required a transition model and hence is a model free method. Let us look into the source before we see some usage examples."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "%psource QLearningAgent"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The Agent Program can be obtained by creating the instance of the class by passing the appropriate parameters. Because of the __ call __ method the object that is created behaves like a callable and returns an appropriate action as most Agent Programs do. To instantiate the object we need a mdp similar to the PassiveTDAgent.\n",
    "\n",
    " Let us use the same GridMDP object we used above. **Figure 17.1 (sequential_decision_environment)** is similar to **Figure 21.1** but has some discounting as **gamma = 0.9**. The class also implements an exploration function **f** which returns fixed **Rplus** untill agent has visited state, action **Ne** number of times. This is the same as the one defined on page **842** of the book. The method **actions_in_state** returns actions possible in given state. It is useful when applying max and argmax operations."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let us create our object now. We also use the **same alpha** as given in the footnote of the book on **page 837**. We use **Rplus = 2** and **Ne = 5** as defined on page 843. **Fig 21.7**  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "q_agent = QLearningAgent(sequential_decision_environment, Ne=5, Rplus=2, \n",
    "                         alpha=lambda n: 60./(59+n))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now to try out the q_agent we make use of the **run_single_trial** function in rl.py (which was also used above). Let us use **200** iterations."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "for i in range(200):\n",
    "    run_single_trial(q_agent,sequential_decision_environment)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now let us see the Q Values. The keys are state-action pairs. Where differnt actions correspond according to:\n",
    "\n",
    "north = (0, 1)\n",
    "south = (0,-1)\n",
    "west = (-1, 0)\n",
    "east = (1, 0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "defaultdict(float,\n",
       "            {((0, 0), (-1, 0)): -0.12953971401732597,\n",
       "             ((0, 0), (0, -1)): -0.12753699595470713,\n",
       "             ((0, 0), (0, 1)): -0.01158029172666495,\n",
       "             ((0, 0), (1, 0)): -0.13035841083471436,\n",
       "             ((0, 1), (-1, 0)): -0.04,\n",
       "             ((0, 1), (0, -1)): -0.1057916516323444,\n",
       "             ((0, 1), (0, 1)): 0.13072636267769677,\n",
       "             ((0, 1), (1, 0)): -0.07323076923076924,\n",
       "             ((0, 2), (-1, 0)): 0.12165200587479848,\n",
       "             ((0, 2), (0, -1)): 0.09431411803674361,\n",
       "             ((0, 2), (0, 1)): 0.14047883620608154,\n",
       "             ((0, 2), (1, 0)): 0.19224095989491635,\n",
       "             ((1, 0), (-1, 0)): -0.09696833851887868,\n",
       "             ((1, 0), (0, -1)): -0.15641263417341367,\n",
       "             ((1, 0), (0, 1)): -0.15340385689815017,\n",
       "             ((1, 0), (1, 0)): -0.15224266498911238,\n",
       "             ((1, 2), (-1, 0)): 0.18537063683043895,\n",
       "             ((1, 2), (0, -1)): 0.17757702529142774,\n",
       "             ((1, 2), (0, 1)): 0.17562120416256435,\n",
       "             ((1, 2), (1, 0)): 0.27484289408254886,\n",
       "             ((2, 0), (-1, 0)): -0.16785234970594098,\n",
       "             ((2, 0), (0, -1)): -0.1448679824723624,\n",
       "             ((2, 0), (0, 1)): -0.028114098214323924,\n",
       "             ((2, 0), (1, 0)): -0.16267477943781278,\n",
       "             ((2, 1), (-1, 0)): -0.2301056003129034,\n",
       "             ((2, 1), (0, -1)): -0.4332722098873507,\n",
       "             ((2, 1), (0, 1)): 0.2965645851500498,\n",
       "             ((2, 1), (1, 0)): -0.90815406879654,\n",
       "             ((2, 2), (-1, 0)): 0.1905755278897695,\n",
       "             ((2, 2), (0, -1)): 0.07306332481110034,\n",
       "             ((2, 2), (0, 1)): 0.1793881607466996,\n",
       "             ((2, 2), (1, 0)): 0.34260576652777697,\n",
       "             ((3, 0), (-1, 0)): -0.16576962655130892,\n",
       "             ((3, 0), (0, -1)): -0.16840120349372995,\n",
       "             ((3, 0), (0, 1)): -0.5090288592720464,\n",
       "             ((3, 0), (1, 0)): -0.88375,\n",
       "             ((3, 1), None): -0.6897322258069369,\n",
       "             ((3, 2), None): 0.388990723935834})"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "q_agent.Q"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The Utility **U** of each state is related to **Q** by the following equation.\n",
    "\n",
    "**U (s) = max <sub>a</sub> Q(s, a)**\n",
    "\n",
    "Let us convert the Q Values above into U estimates.\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "U = defaultdict(lambda: -1000.) # Very Large Negative Value for Comparison see below.\n",
    "for state_action, value in q_agent.Q.items():\n",
    "    state, action = state_action\n",
    "    if U[state] < value:\n",
    "                U[state] = value"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "defaultdict(<function __main__.<lambda>>,\n",
       "            {(0, 0): -0.01158029172666495,\n",
       "             (0, 1): 0.13072636267769677,\n",
       "             (0, 2): 0.19224095989491635,\n",
       "             (1, 0): -0.09696833851887868,\n",
       "             (1, 2): 0.27484289408254886,\n",
       "             (2, 0): -0.028114098214323924,\n",
       "             (2, 1): 0.2965645851500498,\n",
       "             (2, 2): 0.34260576652777697,\n",
       "             (3, 0): -0.16576962655130892,\n",
       "             (3, 1): -0.6897322258069369,\n",
       "             (3, 2): 0.388990723935834})"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "U"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let us finally compare these estimates to value_iteration results."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{(0, 1): 0.3984432178350045, (1, 2): 0.649585681261095, (3, 2): 1.0, (0, 0): 0.2962883154554812, (3, 0): 0.12987274656746342, (3, 1): -1.0, (2, 1): 0.48644001739269643, (2, 0): 0.3447542300124158, (2, 2): 0.7953620878466678, (1, 0): 0.25386699846479516, (0, 2): 0.5093943765842497}\n"
     ]
    }
   ],
   "source": [
    "print(value_iteration(sequential_decision_environment))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "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.5.2+"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
