{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": false
   },
   "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": false
   },
   "outputs": [],
   "source": [
    "from mdp import sequential_decision_environment"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<mdp.GridMDP at 0x7f688c0702e8>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "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": 5,
   "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": 6,
   "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": 7,
   "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": 8,
   "metadata": {
    "collapsed": false
   },
   "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": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{(0, 1): 0.4496668011879283, (1, 2): 0.619085803445832, (3, 2): 1, (0, 0): 0.32062531035042224, (2, 0): 0.0, (3, 0): 0.0, (1, 0): 0.235638474671875, (3, 1): -1, (2, 2): 0.7597530664991547, (2, 1): 0.4275522091676434, (0, 2): 0.5333144285450669}\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": 10,
   "metadata": {
    "collapsed": false
   },
   "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": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYcAAAEPCAYAAACp/QjLAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJztnXmYVMXZt+/ZIMIgAygiu8ENxQWDShR13FAxLjEuwS0a\nEzX5fF3eJKLRKEaNJppoVGI04hKjYtRoJC4R8zrghojIIouyB1AEBWSHGaa+P54u+/Q63T3dMz1n\nfvd19dV9tjp1qs+pXz3PU1UHhBBCCCGEEEIIIYQQQgghhBBCCCGEEEIIIYQIJQ8DnwMzUmw/B5gG\nTAfeBvZt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nOcj2wGqsZb8nsa9WrCV50PpN4CzsGdsROByzGFJNkdwemz3zFez9yPs1eDVCFJBifhOcEPnCt9in\nYS30qcAjwD1YjGEKVmmvwFw68W/PehW4FJiFTSH/bmDbg1jA+QPgvMBxz2PvQZ8WWfeLSPr9SXz7\nlsNE65+YRVICXJXz1QohhBBCCCGEEEIIIYQQQgghhBBCCCGEEEIIIYQQQgghhBBChJn/D14FxN7T\nQhWsAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f688c024198>"
      ]
     },
     "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": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYcAAAEPCAYAAACp/QjLAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3XlcFuX+//EXIqaIO2LuWJZaxzp+TbOyE9lmlprntJkt\nxzYr7VtZHVt+X8XK3CrNLJfMTHNp0bTSY2aGuea+5EKY+66IgiDr/fn9MYDAAN4gt6C8n48HD++Z\nue65r7mEed8z18w1ICIiIiIiIiIiIiIiIiIiIiIiIiIickEaDxwCNuaxvBuwHtgALAGuOkf1EhGR\nYnQj0IK8w+E6oEr66/bA8nNRKRERKX6h5B0OWVUD9vq2KiIi4o0yxV2BLJ4A5hR3JURE5NwI5cxH\nDjcDm3GOHkREpJiVLe4K4HRCf4rT5xCTW4Grr77a1q9ff04rJSJyAVgP/L0wbyzu00oNgBnAw8C2\nvAqtX78eM9OPGf369Sv2OpSUH7WF2kJtkf8PcHVhd86+Pn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IQUSkgM7myEF3SIuIiIvC\nQUREXBQOIiLionAQEREXhYOIiLgoHERExEXhICIiLgoHERFxUTiIiIiLwkFERFwUDiIi4qJwEBER\nF4WDiIi4KBxERMRF4SAiIi4KBxERcVE4iIiIi8JBRERcFA4iIuKicBAREReFg4iIuCgcRETEpWxx\nV0BEJDfVq1cnJiamuKtxXqhWrRrHjh0r0nX6FenafMfMrLjrICLnkJ+fH/q7905ebeXn5weF3M/r\ntJKIiLgoHERExEXhICIiLgoHERFxORfh0B7YCkQBfXJZ3g1YD2wAlgBXnYM6iYictddff50PP/zQ\n55/zww8/8OCDD/r8c7LydTj4AyNxAuIKoCvQLEeZ7cA/cELhbWCsj+skInLWjhw5wqRJk3jmmWcA\n2Lx5M9dccw3Vq1enatWq3HDDDSxevNjrdXXt2pW6detStWpV2rZty4oVKzKXd+zYkU2bNrFx40af\nbEtufB0OrYFtwE4gBZgGdM5RZhlwIv3170A9H9dJROSsTZgwgbvuuouLLroIgLp16/LNN98QHR1N\nTEwMDz74IPfee69X6zp58iTXXnsta9asISYmhscee4y77rqL+Pj4zDJdu3Zl7Nhz993Z1+FQF9iT\nZXpv+ry8PAHM8WmNRESKwNy5c7npppsyp6tUqUKjRo3w8/MjLS2NMmXKULt2ba/W1ahRI1588UVq\n1aqFn58fTz31FMnJyfz555+ZZcLCwpg9e3aRb0defH2HdEHuYLkZeBy4wUd1EREpMhs3bqRJkyau\n+VWrViU+Pp46deqwYMGCQq173bp1JCcn07hx48x5TZs2ZefOnZw8eZKgoKBC19tbvg6HfUD9LNP1\ncY4ecroK+BSnbyLX++XDw8MzX4eFhREWFlZUdRSR85RfEY3xUJgbsY8fP06lSpVynZ+QkED//v25\n7777WL16dcadyl6JjY3lkUceITw8PNv6M14fP348z3CIiIggIiKiYBuSB18Pn1EWiARuAfYDK3A6\npbdkKdMAWAA8DCzPYz0aPkOklCnpw2fUqlWLOXPm0LJly1yXmxmVKlVi6dKlXHWVdxdhnjp1ivbt\n29O0aVPGjBmTb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S0CgUrprysCS3CuQCoVbZHbTXQXsqnAfiAZp7+lO86VCPPJ/bK0\nN3DaZitwxzmtqe+1xTmVsg7nFMJanEubS2N7NAfW4LTFBpzz7VA62yKrmzh9tVJpbItGOL8T63Au\n987YR5bGthARERERERERERERERERERERERERERE5n5xM/7ch0LWI1/1GjuklRbx+ERHxkYwxmcI4\nfUett840/ljO8Z5EROQ8kbEDXw4cx7nb+gWcscWG4jwkZT3wdHq5MGARMIvTA5nNxBn58g9Oj345\nCEhNX9+k9HkZRyl+6eveiHNX8/1Z1h0BfANsAb7MUs9BOKOtrk9/r4iI+FBGOGQdiwecMHgz/fVF\nOM9JCMXZgZ/EOQ2VoVr6vxVwdvgZ0zmPHDKm/4UzdIEfEALswhkMLQwnoOqkL1uKM7JmDbKPqFnZ\n240T8YWSPCqrSFHLOcjY7cCjON/8l+OMSdM4fdkKnB16hhdwxrBZhjOy5WVn+Ky2wBScIZEPAwuB\nVunTK3DG0LL0dTbECYxE4DOgC3CqoBsnUpQUDlLa9cJ5kFAL4FKcAcsA4rOUCcMZBbUNzjMV1uI8\n1zk/hjuMMsbOT8oyLw1naPI0nOGWv8V5ZsFcRIqRwkFKkzhOD3EMzkNznuN0p/PlnH5Wc1aVgRic\nb/ZNyf5oxRRy77ReBDyA8zdWE/gHzhFDXkMkV8QZPfO/OM9HvvqMWyPiQyX5SXAiRSXjG/t6nG/o\n64DPgRE4fQxrcHbah3FO6eR8etZc4BlgM84Q8suyLBuL0+G8Gngky/u+w3kO+vr0ea+mr78Z7qdv\nGU5ozcI5IvEDXir01oqIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIhcyP4/S815E0SFY3EAAAAA\nSUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f688c070be0>"
      ]
     },
     "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": 13,
   "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": 14,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "q_agent = QLearningAgent(sequential_decision_environment, Ne=5, Rplus=2, \n",
    "                         alpha=lambda n: 60./(59+n))\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": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "for i in range(200):\n",
    "    run_single_trial(q_agent,sequential_decision_environment)\n"
   ]
  },
  {
   "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": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "defaultdict(float,\n",
       "            {((0, 0), (-1, 0)): -0.07323076923076924,\n",
       "             ((0, 0), (0, -1)): -0.0759999433406361,\n",
       "             ((0, 0), (0, 1)): 0.2244371077466747,\n",
       "             ((0, 0), (1, 0)): -0.07085714285714287,\n",
       "             ((0, 1), (-1, 0)): -0.04883916667786259,\n",
       "             ((0, 1), (0, -1)): -0.05252175603090532,\n",
       "             ((0, 1), (0, 1)): 0.3396752416362625,\n",
       "             ((0, 1), (1, 0)): -0.07323076923076924,\n",
       "             ((0, 2), (-1, 0)): -0.05158410382845185,\n",
       "             ((0, 2), (0, -1)): -0.04733337973118637,\n",
       "             ((0, 2), (0, 1)): -0.048398095611170026,\n",
       "             ((0, 2), (1, 0)): 0.4729172313717893,\n",
       "             ((1, 0), (-1, 0)): 0.14857758363326573,\n",
       "             ((1, 0), (0, -1)): -0.0759999433406361,\n",
       "             ((1, 0), (0, 1)): -0.07695450531425811,\n",
       "             ((1, 0), (1, 0)): -0.09719395035017139,\n",
       "             ((1, 2), (-1, 0)): 0.21593724199115555,\n",
       "             ((1, 2), (0, -1)): 0.26570820298073916,\n",
       "             ((1, 2), (0, 1)): 0.19612684250448048,\n",
       "             ((1, 2), (1, 0)): 0.6105607273543103,\n",
       "             ((2, 0), (-1, 0)): 0.06795076480003,\n",
       "             ((2, 0), (0, -1)): -0.11306695825372484,\n",
       "             ((2, 0), (0, 1)): -0.105596446586541,\n",
       "             ((2, 0), (1, 0)): -0.10409381636745853,\n",
       "             ((2, 1), (-1, 0)): -0.0383184014263534,\n",
       "             ((2, 1), (0, -1)): -0.7913059177862865,\n",
       "             ((2, 1), (0, 1)): -0.7672970392961057,\n",
       "             ((2, 1), (1, 0)): -0.8402721538112866,\n",
       "             ((2, 2), (-1, 0)): 0.2351847866756862,\n",
       "             ((2, 2), (0, -1)): 0.24909509983624728,\n",
       "             ((2, 2), (0, 1)): 0.25112211666264095,\n",
       "             ((2, 2), (1, 0)): 0.7743960998734626,\n",
       "             ((3, 0), (-1, 0)): -0.1037923159515085,\n",
       "             ((3, 0), (0, -1)): -0.07807333741195537,\n",
       "             ((3, 0), (0, 1)): -0.9374064176172849,\n",
       "             ((3, 0), (1, 0)): -0.07323076923076924,\n",
       "             ((3, 1), None): -1,\n",
       "             ((3, 2), None): 1})"
      ]
     },
     "execution_count": 16,
     "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": 17,
   "metadata": {
    "collapsed": false
   },
   "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": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "defaultdict(<function __main__.<lambda>>,\n",
       "            {(0, 0): 0.2244371077466747,\n",
       "             (0, 1): 0.3396752416362625,\n",
       "             (0, 2): 0.4729172313717893,\n",
       "             (1, 0): 0.14857758363326573,\n",
       "             (1, 2): 0.6105607273543103,\n",
       "             (2, 0): 0.06795076480003,\n",
       "             (2, 1): -0.0383184014263534,\n",
       "             (2, 2): 0.7743960998734626,\n",
       "             (3, 0): -0.07323076923076924,\n",
       "             (3, 1): -1,\n",
       "             (3, 2): 1})"
      ]
     },
     "execution_count": 18,
     "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": 19,
   "metadata": {
    "collapsed": false
   },
   "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.4.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
