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."
]
},
SnShine
a validé
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"from mdp import *\n",
"from notebook import psource, pseudocode"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## CONTENTS\n",
"\n",
"* Overview\n",
"* MDP\n",
"* Grid MDP\n",
"* Value Iteration Visualization"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## OVERVIEW\n",
SnShine
a validé
"\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",
SnShine
a validé
"execution_count": 2,
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
},
"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",
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
"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",
},
"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[state])\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",
" if action is None:\n",
" return [(0.0, state)]\n",
" else: \n",
" return [(prob, new_state) 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",
"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": [
"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."
SnShine
a validé
"execution_count": 6,
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
"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",
"outputs": [
{
"data": {
"text/plain": [
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sequential_decision_environment"
{
"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",
},
"outputs": [],
"source": [
]
},
{
"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."
{
"cell_type": "code",
"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)"
]
},
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The pseudocode for the algorithm:"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/markdown": [
"### AIMA3e\n",
"__function__ VALUE-ITERATION(_mdp_, _ε_) __returns__ a utility function \n",
" __inputs__: _mdp_, an MDP with states _S_, actions _A_(_s_), transition model _P_(_s′_ | _s_, _a_), \n",
"      rewards _R_(_s_), discount _γ_ \n",
"   _ε_, the maximum error allowed in the utility of any state \n",
" __local variables__: _U_, _U′_, vectors of utilities for states in _S_, initially zero \n",
"        _δ_, the maximum change in the utility of any state in an iteration \n",
"\n",
" __repeat__ \n",
"   _U_ ← _U′_; _δ_ ← 0 \n",
"   __for each__ state _s_ in _S_ __do__ \n",
"     _U′_\\[_s_\\] ← _R_(_s_) + _γ_ max<sub>_a_ ∈ _A_(_s_)</sub> Σ _P_(_s′_ | _s_, _a_) _U_\\[_s′_\\] \n",
"     __if__ | _U′_\\[_s_\\] − _U_\\[_s_\\] | > _δ_ __then__ _δ_ ← | _U′_\\[_s_\\] − _U_\\[_s_\\] | \n",
" __until__ _δ_ < _ε_(1 − _γ_)/_γ_ \n",
" __return__ _U_ \n",
"\n",
"---\n",
"__Figure ??__ The value iteration algorithm for calculating utilities of states. The termination condition is from Equation (__??__)."
],
"text/plain": [
"<IPython.core.display.Markdown object>"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pseudocode(\"Value-Iteration\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## VALUE ITERATION VISUALIZATION\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",
},
"outputs": [],
"source": [
"columns = 4\n",
"rows = 3\n",
"U_over_time = value_iteration_instru(sequential_decision_environment)"
]
},
{
"cell_type": "code",
},
"outputs": [],
"source": [
"%matplotlib inline\n",
"from notebook import make_plot_grid_step_function\n",
"\n",
"plot_grid_step = make_plot_grid_step_function(columns, rows, U_over_time)"
]
},
{
"cell_type": "code",
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAATcAAADuCAYAAABcZEBhAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAADVdJREFUeJzt239o2/edx/HX9+prSRfbbQqLrK9d2iKzcporX2kcnyAH\nV0i8/JjbP7pL/MfcboGQXEaYYab5Y1cYgbZXzuFwmgbcCyX5xwn0D3s4P6rQMAiInKCJ/pjDgWpk\nsL6KU9zN9Vw36WK++8OKUjeO5XWW9M17zwcY/NXnY/h834hnpUh1fN8XAFjzD9U+AACUA3EDYBJx\nA2AScQNgEnEDYBJxA2AScQNgEnEDYBJxA2BSzV+zeXZW/O8MQBmtrXWqfYTg8/0VDYlXbgBMIm4A\nTCJuAEwibgBMIm4ATCJuAEwibgBMIm4ATCJuAEwibgBMIm4ATCJuAEwibgBMIm4ATCJuAEwibgBM\nIm4ATCJuAEwibgBMIm4ATCJuAEwibgBMIm4ATCJuAEwibgBMIm4ATCJuAEwibgBMIm4ATCJuAEwi\nbg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k4gbAJOIGwCTiBsAk4gbAJOIGwCTiBsAk\n4gbApMDGzfd99fYeUCwWUXv7c0qnryy57+rVT7RxY4tisYh6ew/I9/1F6/39faqtdTQ1NVWJY1cM\n8ymNGS3P+nwCG7dE4pzGxjJKpzPq7x9QT8++Jff19OzTkSPvK53OaGwsowsXzhfXcrkJXbyYUFPT\nk5U6dsUwn9KY0fKszyewcTtzZlhdXd1yHEdtbe2anp7W5OT1RXsmJ69rZmZGbW3tchxHXV3dGhkZ\nKq4fPNijQ4fekeM4lT5+2TGf0pjR8qzPJ7Bxy+c9uW5T8dp1G5XPe0vsaSxeh8N394yMDCscdtXS\nEqvMgSuM+ZTGjJZnfT411T5AOczNzamv700NDSWqfZRAYj6lMaPlPQjzCdQrt4GBo4rHWxWPtyoU\napDnTRTXPC+ncNhdtD8cduV5ueJ1Pr+wJ5sd0/h4VvF4TNHoU/K8nDZtel43bkxW7F7KgfmUxoyW\n9/c0n0DFbc+e/Uom00om09qx42UNDp6U7/tKpS6rvr5eoVDDov2hUIPq6uqUSl2W7/saHDyp7dtf\nUjTaomz2M42Ojmt0dFyu26hLl65o/fpQle5sdTCf0pjR8v6e5hPYt6UdHduUSJxVLBbRmjWP6tix\nD4pr8Xirksm0JOnw4fe0d+9runnzK23evFVbtmyt1pErivmUxoyWZ30+zre/s7Kc2VmtfDMAlMHa\ntVrRR7OBelsKAKuFuAEwibgBMIm4ATCJuAEwibgBMIm4ATCJuAEwibgBMIm4ATCJuAEwibgBMIm4\nATCJuAEwibgBMIm4ATCJuAEwibgBMIm4ATCJuAEwibgBMIm4ATCJuAEwibgBMIm4ATCJuAEwibgB\nMIm4ATCJuAEwibgBMIm4ATDJ8X2/2mcAgFXHKzcAJhE3ACYRNwAmETcAJhE3ACYRNwAmETcAJhE3\nACYRNwAmETcAJv0F9s8EDYqi1wAAAAAASUVORK5CYII=\n",
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Widget Javascript not detected. It may not be installed or enabled properly.\n"
]
},
{
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import ipywidgets as widgets\n",
"from IPython.display import display\n",
"iteration_slider = widgets.IntSlider(min=1, max=15, step=1, value=0)\n",
"w=widgets.interactive(plot_grid_step,iteration=iteration_slider)\n",
"\n",
"visualize_callback = make_visualize(iteration_slider)\n",
"\n",
"visualize_button = widgets.ToggleButton(desctiption = \"Visualize\", value = False)\n",
"time_select = widgets.ToggleButtons(description='Extra Delay:',options=['0', '0.1', '0.2', '0.5', '0.7', '1.0'])\n",
"a = widgets.interactive(visualize_callback, Visualize = visualize_button, time_step=time_select)\n",
"display(a)"
]
},
{
"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. The **Visualize Button** will automatically animate the slider for you. The **Extra Delay Box** allows you to set time delay in seconds upto one second for each time step."
}
],
"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",
},
"widgets": {
"state": {
"001e6c8ed3fc4eeeb6ab7901992314dd": {
"views": []
},
"00f29880456846a8854ab515146ec55b": {
"views": []
},
"010f52f7cde545cba25593839002049b": {
"views": []
},
"01473ad99aa94acbaca856a7d980f2b9": {
"views": []
},
"021a4a4f35da484db5c37c5c8d0dbcc2": {
"views": []
},
"02229be5d3bc401fad55a0378977324a": {
"views": []
},
"022a5fdfc8e44fb09b21c4bd5b67a0db": {
"views": [
{
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
}
]
},
"025c3b0250b94d4c8d9b33adfdba4c15": {
"views": []
},
"028f96abfed644b8b042be1e4b16014d": {
"views": []
},
"0303bad44d404a1b9ad2cc167e42fcb7": {
"views": []
},
"031d2d17f32347ec83c43798e05418fe": {
"views": []
},
"03de64f0c2fd43f1b3b5d84aa265aeb7": {
"views": []
},
"03fdd484675b42ad84448f64c459b0e0": {
"views": []
},
"044cf74f03fd44fd840e450e5ee0c161": {
"views": []
},
"054ae5ba0a014a758de446f1980f1ba5": {
"views": []
},
"0675230fb92f4539bc257b768fb4cd10": {
"views": [
{
}
]
},
"06c93b34e1f4424aba9a0b172c428260": {
"views": []
},
"077a5ea324be46c3ad0110671a0c6a12": {
"views": []
},
"0781138d150142a08775861a69beaec9": {
"views": []
},
"0783e74a8c2b40cc9b0f5706271192f4": {
"views": [
{
}
]
},
"07c7678b73634e728085f19d7b5b84f7": {
"views": []
},
"07febf1d15a140d8adb708847dd478ec": {
"views": []
},
"08299b681cd9477f9b19a125e186ce44": {
"views": []
},
"083af89d82e445aab4abddfece61d700": {
"views": []
},
"08a1129a8bd8486bbfe2c9e49226f618": {
"views": []
},
"08a2f800c0d540fdb24015156c7ffc15": {
"views": []
},
"097d8d0feccc4c76b87bbcb3f1ecece7": {
"views": []
},
"098f12158d844cdf89b29a4cd568fda0": {
"views": [
{
}
]
},
"09e96f9d5d32453290af60fbd29ca155": {
"views": []
},
"0a2ec7c49dcd4f768194483c4f2e8813": {
"views": []
},
"0b1d6ed8fe4144b8a24228e1befe2084": {
"views": []
},
"0b299f8157d24fa9830653a394ef806a": {
"views": []
},
"0b2a4ac81a244ff1a7b313290465f8f4": {
"views": []
},
"0b52cfc02d604bc2ae42f4ba8c7bca4f": {
"views": []
},
"0b65fb781274495ab498ad518bc274d4": {
"views": [
{
}
]
},
"0b865813de0841c49b41f6ad5fb85c6a": {
"views": []
},
"0c2070d20fb04864aeb2008a6f2b8b30": {
"views": []
},
"0cf5319bcde84f65a1a91c5f9be3aa28": {
"views": []
},
"0d721b5be85f4f8aafe26b3597242d60": {
"views": []
},
"0d9f29e197ad45d6a04bbb6864d3be6d": {
"views": []
},
"0e03c7e2c0414936b206ed055e19acba": {
"views": []
},
"0e2265aa506a4778bfc480d5e48c388b": {
"views": []
},
"0e4e3d0b6afc413e86970ec4250df678": {
"views": []
},
"0e6a5fe6423542e6a13e30f8929a8b02": {
"views": []
},
"0e7b2f39c94343c3b0d3b6611351886e": {
"views": []
},
"0eb5005fa34440988bcf3be231d31511": {
"views": []
},
"104703ad808e41bc9106829bb0396ece": {
"views": []
},
"109c376b28774a78bf90d3da4587d834": {
"views": []
},
"10b24041718843da976ac616e77ea522": {
"views": []
},
"11516bb6db8b45ef866bd9be8bb59312": {
"views": []
},
"1203903354fa467a8f38dbbad79cbc81": {
"views": []
},
"124ecbe68ada40f68d6a1807ad6bcdf9": {
"views": []
},
"1264becdbb63455183aa75f236a3413e": {
"views": []
},
"13061cc21693480a8380346277c1b877": {
"views": []
},
"130dd4d2c9f04ad28d9a6ac40045a329": {
"views": []
},
"1350a087b5a9422386c3c5f04dd5d1c9": {
"views": []
},
"139bd19be4a4427a9e08f0be6080188e": {
"views": []
},
"13f9f589d36c477f9b597dda459efd16": {
"views": []
},
"140917b5c77348ec82ea45da139a3045": {
"views": []
},
"145419657bb1401ba934e6cea43d5fd1": {
"views": []
},
"15d748f1629d4da1982cd62cfbcb1725": {
"views": []
},
"17ad015dbc744ac6952d2a6da89f0289": {
"views": []
},
"17b6508f32e4425e9f43e5407eb55ed3": {
"views": []
},
"185598d8e5fc4dffae293f270a6e7328": {
"views": []
},
"196473b25f384f3895ee245e8b7874e9": {
"views": []
},
"19c0f87663a0431285a62d4ad6748046": {
"views": []
},
"1a00a7b7446d4ad8b08c9a2a9ea9c852": {
"views": []
},
"1a97f5b88cdc4ae0871578c06bbb9965": {
"views": []
},
"1a9a07777b0c4a45b33e25a70ebdc290": {
"views": []
},
"1af711fe8e4f43f084cef6c89eec40ae": {
"views": [
{
}
]
},
"1aff6a6e15b34bb89d7579d445071230": {
"views": []
},
"1b1ea7e915d846aea9efeae4381b2c48": {
"views": []
},
"1ba02ae1967740b0a69e07dbe95635cb": {
"views": []
},
"1c5c913acbde4e87a163abb2e24e6e38": {
"views": [
{
}
]
},
"1cfca0b7ef754c459e1ad97c1f0ceb3b": {
"views": []
},
"1d8f6a4910e649589863b781aab4c4d4": {
"views": []
},
"1e64b8f5a1554a22992693c194f7b971": {
"views": []
},
"1e8f0a2bf7614443a380e53ed27b48c0": {
"views": []
},
"1f4e6fa4bacc479e8cd997b26a5af733": {
"views": []
},
"1fdf09158eb44415a946f07c6aaba620": {
"views": []
},
"200e3ebead3d4858a47e2f6d345ca395": {
"views": [
{
}
]
},
"2050d4b462474a059f9e6493ba06ac58": {
"views": []
},
"20b5c21a6e6a427ba3b9b55a0214f75e": {
"views": []
},
"20b99631feba4a9c98c9d5f74c620273": {
"views": []
},
"20bcff5082854ab89a7977ae56983e30": {
"views": []
},
"20d708bf9b7845fa946f5f37c7733fee": {
"views": []
},
"210b36ea9edf4ee49ae1ae3fe5005282": {
"views": []
},
"21415393cb2d4f72b5c3f5c058aeaf66": {
"views": []
},
"2186a18b6ed8405a8a720bae59de2ace": {
"views": []
},
"220dc13e9b6942a7b9ed9e37d5ede7ba": {
"views": []
},
"221a735fa6014a288543e6f8c7e4e2ef": {
"views": []
},
"2288929cec4d4c8faad411029f5e21fa": {
"views": []
},
"22b86e207ea6469d85d8333870851a86": {
"views": []
},
"23283ad662a140e3b5e8677499e91d64": {
"views": []
},
"23a7cc820b63454ca6be3dcfd2538ac1": {
"views": []
},
"240ed02d576546028af3edfab9ea8558": {
"views": []
},
"24678e52a0334cb9a9a56f92c29750be": {
"views": []
},
"247820f6d83f4dd9b68f5df77dbda4b7": {
"views": []
},
"24b6a837fbd942c9a68218fb8910dcd5": {
"views": []
},
"24ee3204f26348bca5e6a264973e5b56": {
"views": []
},
"262c7bb5bd7447f791509571fe74ae44": {
"views": []
},
"263595f22d0d45e2a850854bcefe4731": {
"views": []
},
"2640720aa6684c5da6d7870abcbc950b": {
"views": []
},
"265ca1ec7ad742f096bb8104d0cf1550": {
"views": []
},
"26bf66fba453464fac2f5cd362655083": {
"views": []
},
"29769879478f49e8b4afd5c0b4662e87": {
"views": []
},
"29a13bd6bc8d486ca648bf30c9e4c2a6": {
"views": []
},
"29c5df6267584654b76205fc5559c553": {
"views": []
},
"29ce25045e7248e5892e8aafc635c416": {
"views": []
},
"2a17207c43c9424394299a7b52461794": {
"views": []
},
"2a777941580945bc83ddb0c817ed4122": {
"views": []
},
"2ae1844e2afe416183658d7a602e5963": {
"views": []
},
"2afa2938b41944cf8c14e41a431e3969": {
"views": []
},
"2bdc5f9b161548e3aab8ea392b5af1a1": {
"views": []
},
"2c26b2bcfc96473584930a4b622d268e": {
"views": []
},
"2ca2a914a5f940b18df0b5cde2b79e4b": {
"views": []
},
"2ca2c532840548a9968d1c6b2f0acdd8": {
"views": []
},
"2d17c32bfea143babe2b114d8777b15d": {
"views": []
},
"2d3acd8872c342eab3484302cac2cb05": {
"views": [
{
}
]
},
"2dc514cc2f5547aeb97059a5070dc9e3": {
"views": []
},
"2e1351ad05384d058c90e594bc6143c1": {
"views": [
{
}
]
},
"2e9b80fa18984615933e41c1c1db2171": {
"views": []
},
"2ef17ee6b7c74a4bbbbbe9b1a93e4fb6": {
"views": []
},
"2f5438f1b34046a597a467effd43df11": {
"views": [
{
}
]
},
"2f8d22417f3e421f96027fca40e1554f": {
"views": []
},
"2fb0409cfb49469d89a32597dc3edba9": {
"views": []
},
"303ccef837984c97b7e71f2988c737a4": {
"views": []
},
"3058b0808dca48a0bba9a93682260491": {
"views": []
},
"306b65493c28411eb10ad786bbf85dc5": {
"views": []
},
"30f5d30cf2d84530b3199015c5ff00eb": {
"views": []
},
"310b1ac518bd4079bdb7ecaf523a6809": {
"views": []
},
"313eca81d9d24664bcc837db54d59618": {
"views": []
},
"31413caf78c14548baa61e3e3c9edc55": {
"views": []
},
"317fbd3cb6324b2fbdfd6aa46a8d1192": {
"views": []
},
"319425ba805346f5ba366c42e220f9c6": {
"views": [
{
}
]
},
"31fc8165275e473f8f75c6215b5184ff": {
"views": []
},
"329f12edaa0c44d2a619450f188e8777": {
"views": []
},
"32edf057582f4a6ca30ce3cb685bf971": {
"views": []
},
"330e74773ba148e18674cfa3e63cd6cc": {
"views": []
},
"332a89c03bfb49c2bb291051d172b735": {
"views": [
{
}
]
},
"3347dfda0aca450f89dd9b39ca1bec7d": {
"views": []
},
"336e8bcfd7cc4a85956674b0c7bffff2": {
"views": []
},
"3376228b3b614d4ab2a10b2fd0f484fd": {
"views": []
},
"3380a22bc67c4be99c61050800f93395": {
"views": []
},
"34b5c16cbea448809c2ccbce56f8d5a5": {
"views": []
},
"34bb050223504afc8053ce931103f52c": {
"views": []
},
"34c28187175d49198b536a1ab13668c4": {
"views": []
},
"3521f32644514ecf9a96ddfa5d80fb9b": {
"views": []
},