{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "view-in-github",
"tags": [
"no-tex"
]
},
"source": [
""
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "w-CIikP0ZZnm",
"outputId": "1eb10a06-4b94-420b-edd9-1620b93cefdd",
"tags": [
"remove-cell"
]
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Note: you may need to restart the kernel to use updated packages.\n"
]
}
],
"source": [
"%pip install -q -U gtbook"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"id": "uef6Kglzcrha",
"tags": [
"remove-cell"
]
},
"outputs": [],
"source": [
"from gtbook.discrete import Variables\n",
"import numpy as np\n",
"import pandas as pd\n",
"import gtsam\n",
"import plotly.express as px\n",
"try:\n",
" import google.colab\n",
"except:\n",
" import plotly.io as pio\n",
" pio.renderers.default = \"png\"\n"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"# Decision Theory\n",
"\n",
"> Decision theory is about turning information into action.\n",
"\n",
"\n",
"
"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "ul23OZt2WV5m"
},
"source": [
"Planning is simple for the trash sorter robot. At each time instant, the robot makes a decision about what\n",
"action to take and then executes that action.\n",
"There is no coupling between actions, \n",
"and there is no dependence on the current action to establish conditions that will ensure success at future stages.\n",
"Thus, planning reduces to simple decision making: at this moment, based on the best information\n",
"available, what single action should the robot execute. \n",
"This process is repeated each time a new item of trash arrives.\n",
"\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Naive Decision Making Using Priors\n",
"\n",
"> A robot without sensors can make naive decisions using prior information. \n",
"\n",
"Consider the case of a trash sorting robot that is not equipped with any sensing capabilities.\n",
"How can this robot make a decision about how to act in the world? \n",
"Without sensing, the best information that is available is the prior knowledge the robot has about the world.\n",
"In our case, this knowledge is encoded as the prior probability $P(C)$ over the categories of trash. \n",
"Looking back at the table of priors in the previous sections, we see that paper occurs about 30% of the time\n",
"and that cardboard occurs about 20% of the time, meaning that the paper bin is the appropriate destination\n",
"about 50% of the time.\n",
"We could adopt a simple decision rule for selecting actions:\n",
"*Choose the action that maximizes the prior probability of making the right choice.*\n",
"This would result in the robot always putting trash in the paper bin.\n",
"If we do this, we expect that the robot will do the right thing around 50% of the time. This isn't great, but it's better than any other action, given the typical distribution of categories of trash.\n",
"This approach, however, takes no account of the cost of wrong actions, which can result in significant problems."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Optimizing for the Worst Case\n",
"\n",
"> A conservative approach to accounting for costs is to minimize the damage that can occur in the worst case scenario.\n",
"\n",
"One way to account for the costs of actions would be to apply an action that minimizes the worst-case cost.\n",
"This provides a quantitative upper bound on how badly things could go.\n",
"Denote by $\\mathrm{cost}(a_i,c)$ the cost of applying action $a_i$ when the piece of trash\n",
"in the work cell is from category $c$.\n",
"We then write our decision rule as a minimization problem\n",
"\n",
"\n",
"$$a^* = \\arg \\min_{a_i} \\max_{c \\in \\Omega} \\mathrm{cost}(a_i,c).$$\n",
"\n",
"From the table of costs given in previous sections, we see that this approach leads\n",
"to always executing the *nop* action, since the worst-case cost for this action is 1,\n",
"while the worst-case costs for the other three actions are 6, 2, and 10.\n",
"This approach, however, merely reduces our trash sorting\n",
"system to a conveyor belt that allows all items of trash to pass through, unsorted.\n",
"In this case, the conservative action is to take no action, and\n",
"the robot becomes a motionless spectator."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Minimizing Expected Cost\n",
"\n",
"> If the system will operate over a long period of time, we can optimize the long-term average cost.\n",
"\n",
"When there is uncertainty about the world state, what is the right way to choose\n",
"actions to minimize costs? \n",
"The ideal decision would always minimize the cost of executing each action, but because our knowledge of the world is uncertain (captured in the prior probability distribution),\n",
"it is impossible to know which action this would be. \n",
"In such cases, the concept of $expectation$ from probability theory (introduced above) provides a principled way to reason about decisions.\n",
"\n",
"The idea of expected cost is this: what do we expect to be the average cost of performing an action many times.\n",
"The expected value for the cost of applying action $a$\n",
"is merely the weighted average of the costs $cost(a,c)$, where the weights are exactly the prior probabilities assigned to the categories, $c$:\n",
"\n",
"$$E[ cost(a, C) ] = \\sum_{c \\in \\Omega} cost(a,c) P(c) $$\n",
"\n",
"\n",
"In the equation above for expectation, the notation $E [ cost(a, C) ]$ denotes the expected cost for executing the action $a$ with the expectation being taken with respect to the randomly occurring trash category $C$.\n",
"We use upper case $C$ to indicate that the category is a random quantity, and that the expectation\n",
"should be computed with respect to the probability distribution on categories\n",
"(i.e., the priors given in the previous section).\n",
"\n",
"We can now formulate our decision process as the following minimization problem\n",
"\n",
"$$a^* = \\arg \\min_{a_i} E[ cost(a_i, C) ]$$\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Implementation in Python"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 175
},
"id": "wIkfiBY_WiBZ",
"outputId": "5e94e251-8d60-4d64-82f4-737716526b50"
},
"outputs": [
{
"data": {
"text/html": [
"
\n", " | cardboard | \n", "paper | \n", "can | \n", "scrap metal | \n", "bottle | \n", "
---|---|---|---|---|---|
glass bin | \n", "2 | \n", "2 | \n", "4 | \n", "6 | \n", "0 | \n", "
metal bin | \n", "1 | \n", "1 | \n", "0 | \n", "0 | \n", "2 | \n", "
paper bin | \n", "0 | \n", "0 | \n", "5 | \n", "10 | \n", "3 | \n", "
nop | \n", "1 | \n", "1 | \n", "1 | \n", "1 | \n", "1 | \n", "
P(0):
\n", "0 | value |
---|---|
0 | 0.2 |
1 | 0.3 |
2 | 0.25 |
3 | 0.2 |
4 | 0.05 |