mdp.ipynb 31,2 ko
Newer Older
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Markov decision processes (MDPs)\n",
    "\n",
    "This IPy notebook acts as supporting material for topics covered in **Chapter 17 Making Complex Decisions** of the book* Artificial Intelligence: A Modern Approach*. We makes use of the implementations in mdp.py module. This notebook also includes a brief summary of the main topics as a review. Let us import everything from the mdp module to get started."
   ]
  },
jeff3456's avatar
jeff3456 a validé
  {
   "cell_type": "code",
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from mdp import MDP, GridMDP, sequential_decision_environment, value_iteration"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Review\n",
    "Before we start playing with the actual implementations let us review a couple of things about MDPs.\n",
    "\n",
    "- A stochastic process has the **Markov property** if the conditional probability distribution of future states of the process (conditional on both past and present states) depends only upon the present state, not on the sequence of events that preceded it.\n",
    "\n",
    "    -- Source: [Wikipedia](https://en.wikipedia.org/wiki/Markov_property)\n",
    "\n",
    "Often it is possible to model many different phenomena as a Markov process by being flexible with our definition of state.\n",
    "   \n",
    "\n",
    "- MDPs help us deal with fully-observable and non-deterministic/stochastic environments. For dealing with partially-observable and stochastic cases we make use of generalization of MDPs named POMDPs (partially observable Markov decision process).\n",
    "\n",
    "Our overall goal to solve a MDP is to come up with a policy which guides us to select the best action in each state so as to maximize the expected sum of future rewards."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## MDP\n",
    "\n",
    "To begin with let us look at the implementation of MDP class defined in mdp.py The docstring tells us what all is required to define a MDP namely - set of states,actions, initial state, transition model, and a reward function. Each of these are implemented as methods. Do not close the popup so that you can follow along the description of code below."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "%psource MDP"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The **_ _init_ _** method takes in the following parameters:\n",
    "\n",
    "- init: the initial state.\n",
    "- actlist: List of actions possible in each state.\n",
    "- terminals: List of terminal states where only possible action is exit\n",
    "- gamma: Discounting factor. This makes sure that delayed rewards have less value compared to immediate ones.\n",
    "\n",
    "**R** method returns the reward for each state by using the self.reward dict.\n",
    "\n",
    "**T** method is not implemented and is somewhat different from the text. Here we return (probability, s') pairs where s' belongs to list of possible state by taking action a in state s.\n",
    "\n",
    "**actions** method returns list of actions possible in each state. By default it returns all actions for states other than terminal states.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now let us implement the simple MDP in the image below. States A, B have actions X, Y available in them. Their probabilities are shown just above the arrows. We start with using MDP as base class for our CustomMDP. Obviously we need to make a few changes to suit our case. We make use of a transition matrix as our transitions are not very simple.\n",
    "<img src=\"files/images/mdp-a.png\">"
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Transition Matrix as nested dict. State -> Actions in state -> States by each action -> Probabilty\n",
    "t = {\n",
    "    \"A\": {\n",
    "            \"X\": {\"A\":0.3, \"B\":0.7},\n",
    "            \"Y\": {\"A\":1.0}\n",
    "         },\n",
    "    \"B\": {\n",
    "            \"X\": {\"End\":0.8, \"B\":0.2},\n",
    "            \"Y\": {\"A\":1.0}\n",
    "         },\n",
    "    \"End\": {}\n",
    "}\n",
    "\n",
    "init = \"A\"\n",
    "\n",
    "terminals = [\"End\"]\n",
    "\n",
    "rewards = {\n",
    "    \"A\": 5,\n",
    "    \"B\": -10,\n",
    "    \"End\": 100\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "class CustomMDP(MDP):\n",
    "\n",
    "    def __init__(self, transition_matrix, rewards, terminals, init, gamma=.9):\n",
    "        # All possible actions.\n",
    "        actlist = []\n",
    "        for state in transition_matrix.keys():\n",
    "            actlist.extend(transition_matrix.keys())\n",
    "        actlist = list(set(actlist))\n",
    "\n",
    "        MDP.__init__(self, init, actlist, terminals=terminals, gamma=gamma)\n",
    "        self.t = transition_matrix\n",
    "        self.reward = rewards\n",
    "        for state in self.t:\n",
    "            self.states.add(state)\n",
    "\n",
    "    def T(self, state, action):\n",
    "        return [(new_state, prob) for new_state, prob in self.t[state][action].items()]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Finally we instantize the class with the parameters for our MDP in the picture."
   ]
  },
  {
   "cell_type": "code",
jeff3456's avatar
jeff3456 a validé
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
jeff3456's avatar
jeff3456 a validé
   "source": [
    "our_mdp = CustomMDP(t, rewards, terminals, init, gamma=.9)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "With this we have sucessfully represented our MDP. Later we will look at ways to solve this MDP."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Grid MDP\n",
    "\n",
    "Now we look at a concrete implementation that makes use of the MDP as base class. The GridMDP class in the mdp module is used to represent a grid world MDP like the one shown in  in **Fig 17.1** of the AIMA Book. The code should be easy to understand if you have gone through the CustomMDP example.\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "%psource GridMDP"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The **_ _init_ _** method takes **grid** as an extra parameter compared to the MDP class. The grid is a nested list of rewards in states.\n",
    "\n",
    "**go** method returns the state by going in particular direction by using vector_add.\n",
    "\n",
    "**T** method is not implemented and is somewhat different from the text. Here we return (probability, s') pairs where s' belongs to list of possible state by taking action a in state s.\n",
    "\n",
    "**actions** method returns list of actions possible in each state. By default it returns all actions for states other than terminal states.\n",
    "\n",
    "**to_arrows** are used for representing the policy in a grid like format."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can create a GridMDP like the one in **Fig 17.1** as follows: \n",
    "\n",
    "    GridMDP([[-0.04, -0.04, -0.04, +1],\n",
    "            [-0.04, None,  -0.04, -1],\n",
    "            [-0.04, -0.04, -0.04, -0.04]],\n",
    "            terminals=[(3, 2), (3, 1)])\n",
    "            \n",
    "In fact the **sequential_decision_environment** in mdp module has been instantized using the exact same code."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sequential_decision_environment"
jeff3456's avatar
jeff3456 a validé
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "# Value Iteration\n",
    "\n",
    "Now that we have looked how to represent MDPs. Let's aim at solving them. Our ultimate goal is to obtain an optimal policy. We start with looking at Value Iteration and a visualisation that should help us understanding it better.\n",
    "\n",
    "We start by calculating Value/Utility for each of the states. The Value of each state is the expected sum of discounted future rewards given we start in that state and follow a particular policy pi.The algorithm Value Iteration (**Fig. 17.4** in the book) relies on finding solutions of the Bellman's Equation. The intuition Value Iteration works is because values propagate. This point will we more clear after we encounter the visualisation. For more information you can refer to **Section 17.2** of the book. \n"
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "%psource value_iteration"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "It takes as inputs two parameters an MDP to solve and epsilon the maximum error allowed in the utility of any state. It returns a dictionary containing utilities where the keys are the states and values represent utilities. Let us solve the **sequencial_decision_enviornment** GridMDP.\n"
   ]
  },
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{(0, 0): 0.2962883154554812,\n",
       " (0, 1): 0.3984432178350045,\n",
       " (0, 2): 0.5093943765842497,\n",
       " (1, 0): 0.25386699846479516,\n",
       " (1, 2): 0.649585681261095,\n",
       " (2, 0): 0.3447542300124158,\n",
       " (2, 1): 0.48644001739269643,\n",
       " (2, 2): 0.7953620878466678,\n",
       " (3, 0): 0.12987274656746342,\n",
       " (3, 1): -1.0,\n",
       " (3, 2): 1.0}"
      ]
     },
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "value_iteration(sequential_decision_environment)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Visualization for Value Iteration\n",
    "\n",
    "To illustrate that values propagate out of states let us create a simple visualisation. We will be using a modified version of the value_iteration function which will store U over time. We will also remove the parameter epsilon and instead add the number of iterations we want."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def value_iteration_instru(mdp, iterations=20):\n",
    "    U_over_time = []\n",
    "    U1 = {s: 0 for s in mdp.states}\n",
    "    R, T, gamma = mdp.R, mdp.T, mdp.gamma\n",
    "    for _ in range(iterations):\n",
    "        U = U1.copy()\n",
    "        for s in mdp.states:\n",
    "            U1[s] = R(s) + gamma * max([sum([p * U[s1] for (p, s1) in T(s, a)])\n",
    "                                        for a in mdp.actions(s)])\n",
    "        U_over_time.append(U)\n",
    "    return U_over_time"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Next, we define a function to create the visualisation from the utilities returned by **value_iteration_instru**. The reader need not concern himself with the code that immediately follows as it is the usage of Matplotib with IPython Widgets. If you are interested in reading more about these visit [ipywidgets.readthedocs.io](http://ipywidgets.readthedocs.io)"
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "import matplotlib.pyplot as plt\n",
    "from collections import defaultdict\n",
    "\n",
    "def make_plot_grid_step_function(columns, row, U_over_time):\n",
    "    '''ipywidgets interactive function supports\n",
    "       single parameter as input. This function\n",
    "       creates and return such a function by taking\n",
    "       in input other parameters\n",
    "    '''\n",
    "    def plot_grid_step(iteration):\n",
    "        data = U_over_time[iteration]\n",
    "        data = defaultdict(lambda: 0, data)\n",
    "        grid = []\n",
    "        for row in range(rows):\n",
    "            current_row = []\n",
    "            for column in range(columns):\n",
    "                current_row.append(data[(column, row)])\n",
    "            grid.append(current_row)\n",
    "        grid.reverse() # output like book\n",
    "        fig = plt.matshow(grid, cmap=plt.cm.bwr)\n",
    "\n",
    "        plt.axis('off')\n",
    "        fig.axes.get_xaxis().set_visible(False)\n",
    "        fig.axes.get_yaxis().set_visible(False)\n",
    "\n",
    "        for col in range(len(grid)):\n",
    "            for row in range(len(grid[0])):\n",
    "                magic = grid[col][row]\n",
    "                fig.axes.text(row, col, \"{0:.2f}\".format(magic), va='center', ha='center')\n",
    "\n",
    "        plt.show()\n",
    "    \n",
    "    return plot_grid_step"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "columns = 4\n",
    "rows = 3\n",
    "U_over_time = value_iteration_instru(sequential_decision_environment)\n",
    "           "
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "plot_grid_step = make_plot_grid_step_function(columns, rows, U_over_time)"
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAATgAAADtCAYAAAAr+2lCAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAADM5JREFUeJzt2lFolGe+gPFn0ggH1pKEHPWQ0a2Cya7scpz1ECxyEETY\ngANGUKgNbEqoopbdhFKkXikKB9obRXSDVsqxWch2KdQG9cRVKAgKktYajAtdrWldndhIUxs3vRGZ\nOReJaULSONvqzPjv87txJu/7hTd/Ph8+JyZyuRySFFFZsQ8gSU+KgZMUloGTFJaBkxSWgZMUloGT\nFFb5TIsjI/h/SKQimf1sothHeHrkctMOyyc4SWEZOElhGThJYRk4SWEZOElhGThJYRk4SWEZOElh\nGThJYRk4SWEZOElhGThJYRk4SWEZOElhGThJYRk4SWEZOElhGThJYRk4SWEZOElhGThJYRk4SWEZ\nOElhGThJYRk4SWEZOElhGThJYRk4S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DmVVOBOnuyiqakZgPr6\n5dy7N8ydO4NT9p09+yGNjesBaGp6iePHj42vHTp0gHXrNjBnztzCHLoInFP+nFV+os6ppAI3MJAh\nmVww/r6mJsnAQGbSnqGhISorqygrGz16Mjmf27cHxq8/ceIDNm3aRi6XK9zBC8w55c9Z5SfqnEoq\ncD/Wjh2vsmfPmxO+UjqDLiXOKX/OKj+lOqfyYh/gyJF2jh49QiKRYNmyejKZm+NrmcwtamqSk/ZX\nV1czPPwN2WyWsrKySXsuXfqYlpaN5HI5hoa+4syZbsrLZ5FOry3oz/QkOKf8Oav8/BTmVPQnuM2b\nX+H8+UucO/cJ6XQjnZ0dAPT0XKCiopK5c+dNuWblylUcO/YeAJ2d75BONwLQ19dPX18/V658TmPj\nBvbubS/6gB8X55Q/Z5Wfn8Kcih64iRoa1rBw4SKWLl1MW9sW9u1rH19bvz7N4OCXAOze/QYHD+4l\nlarj7t2vaW5+ecr3SiQSBTt3oTmn/Dmr/ESdU2KmDwRHRkrkH9KSNIPZs5m2qiX1BCdJj5OBkxSW\ngZMUloGTFJaBkxSWgZMUloGTFJaBkxSWgZMUloGTFJaBkxSWgZMUloGTFJaBkxSWgZMUloGTFJaB\nkxSWgZMUloGTFJaBkxSWgZMUloGTFJaBkxSWgZMUloGTFJaBkxSWgZMUloGTFJaBkxSWgZMUloGT\nFJaBkxSWgZMUViKXyxX7DJL0RPgEJyksAycpLAMnKSwDJyksAycpLAMnKaz/B9v3wubCyTXSAAAA\nAElFTkSuQmCC\n",
       "<matplotlib.figure.Figure at 0x7ffadc667358>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import ipywidgets as widgets\n",
    "from IPython.display import display\n",
    "\n",
    "iteration_slider = widgets.IntSlider(min=1, max=15, step=1, value=0)\n",
    "w=widgets.interactive(plot_grid_step,iteration=iteration_slider)\n",
    "display(w)\n",
    "        "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Move the slider above to observe how the utility changes across iterations. It is also possible to move the slider using arrow keys or to jump to the value by directly editing the number with a double click."
  }
 ],
 "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",
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000
   "version": "3.4.3"
  },
  "widgets": {
   "state": {
    "00d75b759a1647a69706c9cf5b0e8a98": {
     "views": []
    },
    "019d2fd6c4b34bbf94ebb66ebb593689": {
     "views": []
    },
    "01caaec7f6054144b22cac9e1f78d164": {
     "views": []
    },
    "032a46b26c964232a6aaacdfe220bdd6": {
     "views": []
    },
    "05384c38e94147459de2a2844c3fb2e2": {
     "views": []
    },
    "060bca32714b4cb89b1211b966903789": {
     "views": []
    },
    "06a7db67ab4849559d36ff59a5ff8bef": {
     "views": []
    },
    "074a3d5a4b014d7ba946ea15cc9545d3": {
     "views": []
    },
    "07b99c25d7d64da1a1f5e6b2c58d7716": {
     "views": []
    },
    "07bf2f9854be4024b4859b495fb4eb4f": {
     "views": []
    },
    "08450b23514b491fb8d194b9777e3f90": {
     "views": []
    },
    "08887af6a57a45f0b777b6965dd15952": {
     "views": []
    },
    "09163f70cb6a4d48b6d944b9b9bc7fd0": {
     "views": []
    },
    "0b3c252bae2e49b980d5d25e333dc794": {
     "views": []
    },
    "0d33b647b68e4b47ae1ac42580e6a946": {
     "views": []
    },
    "0d71f6126bb84067b4b3de013ce92d05": {
     "views": []
    },
    "0ddb73ffcf284298935d9fbe4ee5e0e8": {
     "views": []
    },
    "0e1dd3e76cf54dfbb733f53b5e252c35": {
     "views": []
    },
    "105da0f986494fd2b412656fb714e332": {
     "views": []
    },
    "13e3900de0fc404f914fd032b2df7722": {
     "views": []
    },
    "1489558f04b2499689abc1b78de56a9a": {
     "views": []
    },
    "14f5eb67f7ad4d9ca2c32265be4ee2f1": {
     "views": []
    },
    "160606ae34854e198fdd46db4d941e17": {
     "views": []
    },
    "1837fe25964f4b1691deff74c053d2c8": {
     "views": []
    },
    "1861d014182e47fd8880108cc313e444": {
     "views": []
    },
    "196540ac4c124fef9409668824e89d62": {
     "views": []
    },
    "1a22cae9be4b4ef580a70b508564c843": {
     "views": []
    },
    "1b236c7d3ffa441e99c3d9f399d808f1": {
     "views": []
    },
    "1ceb61e74f444768af001a903613200c": {
     "views": []
    },
    "1e55904ae5e342e3b90e59e72ae1b15c": {
     "views": []
    },
    "1ffbc432d471488da21a42ce6453970a": {
     "views": []
    },
    "2125ca503e6a4c14baaab0ffebac8980": {
     "views": []
    },
    "215195f1d62d44ac92c279e7edd78b56": {
     "views": []
    },
    "22e60012957b4a2f99bba3cd625e35ab": {
     "views": []
    },
    "26255fb5f2b542549d7502cd2648e516": {
     "views": []
    },
    "2864076a54ed434a8f04111d718a9a79": {
     "views": []
    },
    "2b2b4492d048475d816a0063e22a8416": {
     "views": []
    },
    "2b8f0ccdbbfa4eac927c10b81e9532e3": {
     "views": []
    },
    "2d77cddf407f4660ae16840ae7b238b4": {
     "views": []
    },
    "2e8946ba5f8e4818a7aff21b66a14168": {
     "views": []
    },
    "30b10e19d62c470b9aae3cb1f410f1a6": {
     "views": []
    },
    "31b219248e1e40e4a3e29ba31a19a497": {
     "views": []
    },
    "31c26ade2cbe42b1b2df4eea1fafc9fa": {
     "views": []
    },
    "31e12e3f8a5c4e6f869b0330b8d73f18": {
     "views": []
    },
    "32baa76b98434985913fdf1dfa79330e": {
     "views": []
    },
    "335c171f15844d65b1877f7ce4ec3393": {
     "views": []
    },
    "33706132c2a34a2e91f4fdd4f9f371e2": {
     "views": []
    },
    "348462fc9f104c619eca650ed780d30d": {
     "views": []
    },
    "39287951b185448f95f7987aa990df30": {
     "views": []
    },
    "3a97dd20f15349929807859eeba03b4c": {
     "views": []
    },
    "3acc98f38d30452da15945fea2501e3f": {
     "views": []
    },
    "3d99b396df6e4506bcf4bd6b8df2dbbb": {
     "views": []
    },
    "3ddb2db10ddd48569552485b8e14c5f7": {
     "views": []
    },
    "3e04321c15624001aac92778a12fb57f": {
     "views": []
    },
    "413742ea823544f8b00e359b5ed94ed1": {
     "views": []
    },
    "41b245b822534a17959aac68ec06823b": {
     "views": []
    },
    "41b9382352214562ae45dcf493ed5a51": {
     "views": []
    },
    "4418019bd94b49949d1dd7b487aa1a3d": {
     "views": []
    },
    "4573ec2e6ad743b28fa9cd5efdc726b9": {
     "views": []
    },
    "45e13aec606f4edd90e2b1e518e11780": {
     "views": []
    },
    "45e97d751c794e529e64a425a4caab49": {
     "views": []
    },
    "463e9c6c3ca2418e8f42b842da8b8b6b": {
     "views": []
    },
    "468a0fecd6cd4896b3e556a67d074b47": {
     "views": []
    },
    "4793346e168c4805868e8f54f26d3a05": {
     "views": []
    },
    "48cd03aca11e40c1bd7278e47919b856": {
     "views": []
    },
    "4a2842aad51e48468550286b585ed038": {
     "views": []
    },
    "4bfffe57336f463d8365e0c8a30d97bf": {
     "views": []
    },
    "4c8a6dce95fe4b4aaf3c2dabcdc90927": {
     "views": []
    },
    "4e83b08e62624959ba4facaf8d54a42c": {
     "views": []
    },
    "4f64b079e013495090b4196e4e54c43d": {
     "views": []
    },
    "511eb612ae774746a8a3c4b2040017e8": {
     "views": []
    },
    "52f7728bef494080b294ce5653c2fd6b": {
     "views": []
    },
    "55112270a94847f39bc9bdca3093d9d2": {
     "views": []
    },
    "56a3a3103a0b41148f32ef56fac5462e": {
     "views": []
    },
    "56d597e5a8464a72870617285ea3c773": {
     "views": []
    },
    "57b081fdbb124daab57d2991075aa5bc": {
     "views": []
    },
    "586358ee06574fc6b17de440f5f04a0f": {
     "views": []
    },
    "586486a57a904499b78a140ae5014abc": {
     "views": []
    },
    "5c02bdb4715c4cb197dadcb00498cc24": {
     "views": []
    },
    "5d56deba77304a37bbb763445b01a5df": {
     "views": []
    },
    "5d823a76672e49768016632c9d198460": {
     "views": []
    },
    "5f12fc87e22d486cb9007c18e73a7e6b": {
     "views": []
    },
    "5fdb7803b1fb4bdc98c6505759e10579": {
     "views": []
    },
    "604a580daca94d5bb08a09fa630c48ec": {
     "views": []
    },
    "614693adb6f34ff190d1e2f8b23f6001": {
     "views": []
    },
    "629af05cd0b143b899c431a62a33c6e6": {
     "views": []
    },
    "62ffb385e84d4864a54e8012ed70a2e3": {
     "views": []
    },
    "64b1c8b8db854e4498905f00d076fee1": {
     "views": []
    },
    "66a8054046e742dd8712ff649242f17b": {
     "views": []
    },
    "6ab01808068e4efb9601079d0efe6b02": {
     "views": []
    },
    "6c2246aab7124e8999aac4666bb4e279": {
     "views": []
    },
    "6e3bd93027c74451837913a2deb570b5": {
     "views": []
    },
    "79da1b6129f94f5fbf0ae986a850c991": {
     "views": []
    },
    "7ba6997cc8674c09888cc24a9b92f867": {
     "views": []
    },
    "7e2ee372ffb148629dd6d2c600320e24": {
     "views": []
    },
    "7e6581728e8d470484d3da5a5a340360": {
     "views": []
    },
    "7e765d096dae4d8aaeef78e25ebdc261": {
     "views": []
    },
    "7f3ad2353abf47c2abf6d9e5062bf983": {
     "views": []
    },
    "7fdd9e7e2e42408ebc33604d8e16afa7": {
     "views": []
    },
    "80c21e1e6ca74c08beb7c41e67f3242a": {
     "views": []
    },
    "81a062e021ac448991e30dfa46eda9ec": {
     "views": []
    },
    "84081c3c7a9340fbb58eab73f50c9389": {
     "views": []
    },
    "86efc37229d242b690f7f473ca9f8bee": {
     "views": []
    },
    "882f593d053d40ca99c98c5c46e712c8": {
     "views": []
    },
    "886044b13aa14e36b2fdb8a6b21768d2": {
     "views": []
    },
    "893829995fc5410c87d2f525085ef532": {
     "views": []
    },
    "8b21dd8a377d41c3a2b4f05e390132c6": {
     "views": []
    },
    "8bbfffc333a54812af3f1074180542df": {
     "views": []
    },
    "8c4110250f784f8784b7e82a2bad918f": {
     "views": []
    },
    "8fc6e64e4ed84ca891ad95e29ca45072": {
     "views": []
    },
    "9178708718784a3485a8a54ee79a6b35": {
     "views": []
    },
    "91f02880fa774481b6fb4ad6e69f8896": {
     "views": []
    },
    "92bca9527688426f8186f75675aec5c9": {
     "views": []
    },
    "933b7ea2a9e04608a4ac1b0fdafa97d2": {
     "views": []
    },
    "95cf0a72e2c2444eb447b626875e29d2": {
     "views": []
    },
    "96b99f3cad5747d48b148ef043005ba1": {
     "views": []
    },
    "9834c1fa109345628a94aaaa9aaa2336": {
     "views": []
    },
    "9d88502ebd4f4bdcb7cd030e2c63aeae": {
     "views": []
    },
    "a5bc22af6fee4ef5893990f28cf29390": {
     "views": []
    },
    "a91fadf7b2de4d5486f20a4cce7ad93c": {
     "views": []
    },
    "abd4bddd845e4622b97d65aa6de0f881": {
     "views": []
    },
    "acb2435355454391b5f003a812cfb6a9": {
     "views": []
    },
    "b1bfae447b6c4892b872a3e214b97934": {
     "views": []
    },
    "b281e2b8e972430e803fa16c7f90ea50": {
     "views": []
    },
    "b2c1a7539ba9408795fdefec39ab56d8": {
     "views": []
    },
    "b2d86cdeb6cb4b4da1fcda2163595b10": {
     "views": []
    },
    "b5e33499943b4569b93895a46e24c997": {
     "views": []
    },
    "b5f263d0042742e684a0fd39c57b9102": {
     "views": []
    },
    "b7c800e7e6494f488eb5519666948e48": {
     "views": []
    },
    "bb1f943690114500a82b978c12086fa1": {
     "views": []
    },
    "bcc9784236304dac9d91027c9f3d3ed1": {
     "views": []
    },
    "bd0f00d98b5b4f05b36af2965d36697b": {
     "views": []
    },
    "bd1df18071e74b42b2fbc5e23535194a": {
     "views": []
    },
    "bdbbbe6a235d4703a028bad8e55cbd99": {
     "views": []
    },
    "be0f4ebcf81944949c5e6153dd3f7d73": {
     "views": []
    },
    "c13d084b41f2493a92c40e50662eeb09": {
     "views": []
    },
    "c162e2a2e77741a2853b2c0a5908a817": {
     "views": []
    },
    "c1b16e82bc0e4703bdc1b5eb3f16cf9b": {
     "views": []
    },
    "c631b3de79404097982118231704532f": {
     "views": []
    },
    "c70be4921a3e4361b88f0d682f455d91": {
     "views": []
    },
    "c7a9c2baba5d44c28c6ca29b72362d2d": {
     "views": []
    },
    "c7ea4fda3219432994f475462f45e122": {
     "views": []
    },
    "c96ca9c9a8b94112bd9d372d1b6fc612": {
     "views": []
    },
    "ca05552a839b4f8eb79771bd2df4a4ae": {
     "views": []
    },
    "cc888c7614e344f8bbfa05855d5220c4": {
     "views": []
    },
    "ce58302444a543349a30a7cb808bb736": {
     "views": []
    },
    "d0204787ece347319868b910026d71ba": {
     "views": []
    },
    "d2a2e557bc854a65bb27010d043d630b": {
     "views": [
      {
       "cell_index": 27
      }
     ]
    },
    "d63f7515368d439db91dcf8f4486670b": {
     "views": []
    },
    "d675038827d54a35abfcccd0e0a4701f": {
     "views": []
    },
    "d79f6360f79c456a884d7f5f686ac96e": {
     "views": []
    },
    "d865d80c0b994b67a37b911659a766f8": {
     "views": []
    },
    "d90d51edea7a4b7299538ea9f7329778": {
     "views": []
    },
    "ddeeea16dac843e8ba5d9ea589487359": {
     "views": []
    },
    "deb7e283c1d14d00acab0a9a26ef7aa2": {
     "views": []
    },
    "df28f26f282b4ea299ec47a2118c5776": {
     "views": []
    },
    "e0084f1665af4e339c9070da10e44cd4": {
     "views": []
    },
    "e2ff98a9b45b425cb6518b76a44d7cba": {
     "views": []
    },
    "e38b6c3667b74b098486d8ea57892332": {
     "views": []
    },
    "e42e95c00b594dbca00117b9e0a5094c": {
     "views": []
    },
    "e6045e934cf04d179ebaf2e15cf68237": {
     "views": []
    },
    "ea6740dd383e4f3cb1a91e0baa871cee": {
     "views": []
    },
    "ecc7d410ceb4461fb0bb0df8035f6a2b": {
     "views": []
    },
    "ed4ded02280941fc8838a3cfab1c5ef6": {
     "views": []
    },
    "ee7668a984ad4824a7c5a010b5a662fc": {
     "views": []
    },
    "ee8d44e3a8e644af8f13ff961677b911": {
     "views": []
    },
    "f30140cbc3af4b2885a46ff3dae5c2bb": {
     "views": []
    },
    "f50870b946b548819dce0a1a672316b2": {
     "views": []
    },
    "f729673f685045bf8aa46bb958b738c2": {
     "views": []
    },
    "fad542455fab4afc841d754ca9d82617": {
     "views": []
    },
    "fb53f90ef8f94e2da5189d9e618317fa": {
     "views": []
    },
    "fc27107c58654119bd8f490f3985c1d1": {
     "views": []
    },
    "fd67662c175b41d8b9686d74b9e3d5b5": {
     "views": []
    },
    "fe523a66eac544fc8d84198e0e9c7c6c": {
     "views": []
    },
    "ff156f3bd0ba4b879ad69e7567add963": {
     "views": []
    },
    "ffe7080ee38948fea4225524ca760b06": {