\n",
""
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# vacuum.rooms = [\"Living Room\", \"Kitchen\", \"Office\", \"Hallway\", \"Dining Room\"]\n",
"X = VARIABLES.discrete_series(\"X\", [1], vacuum.rooms)\n",
"prior = gtsam.DiscreteDistribution(X[1], \"0/0/1/0/0\")\n",
"pretty(prior)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We use this discrete distribution to convey our knowledge that the robot *always* starts out in the office. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## The State Space for our Vacuum Cleaning Robot\n",
"\n",
"> Connected rooms, un-directionally.\n",
"\n",
"For the trash sorting robot, the state was defined as the category of the current item in the work space.\n",
"This category had no dependence on the category of the previous piece of trash, nor did it have any effect on the category\n",
"of the subsequent piece of trash. There were no constraints on the transition from the state at time $t_k$\n",
"to the state at time $t_{k+1}$.\n",
"Therefore, it was sufficient to merely enumerate the set of possible states; there\n",
"were no important relationships between states that required representation.\n",
"\n",
"\n",
"\n",
"This is not the case for our vacuum cleaning robot.\n",
"For example, as can be seen from\n",
"Figure 3.1,\n",
"if the robot is currently in the office, it cannot transition directly to the living room;\n",
"it must first transition to the hallway before it can transition to the living room.\n",
"For the vacuum cleaning robot, room adjacency is an important relationship, and therefore\n",
"it should be encoded into our representation.\n",
"This can be accomplished using a connectivity graph.\n",
"Each vertex of this graph represents a state (i.e., a specific room in the house), and two\n",
"vertices, $x_i, x_j$ are connected by an edge if and only if it the transition between\n",
"these two states is possible. Since our robot can move in any direction, if it\n",
"can transition from $x_i$ to $x_j$, then it can also transition from $x_j$ to $x_i$\n",
"(as is the case, e.g., for $x_i = \\text{Hallway}$ and $x_j = \\text{Dining Room}$).\n",
"Therefore, we represent the state space by an *undirected* graph.\n",
"Taken together, the collection of states along with connectivity information is referred to as the **state space**,\n",
"which in this can be represented by the connectivity graph shown in \n",
"Figure 3.2."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Bayesian vs. Frequentist Interpretations or Probability\n",
"\n",
"> Believing with probabilities.\n",
"\n",
"\n",
"\n",
"In this book, we take a **Bayesian view** of probability, rather than a frequentist one.\n",
"This means that we view probabilities as describing our *knowledge* about\n",
"events, rather than tallying up the frequencies by which they occur.\n",
"For example, think of the weather forecaster talking about the probability of rain tomorrow: this represents a belief about a future state, rather than statistics about previous rainy days.\n",
"Probabilities viewed this way can be used to describe knowledge about\n",
"the state of the world, and how actions affect the state of an agent and\n",
"the world.\n",
"\n",
"\n",
"\n",
"This is to be contrasted with a **frequentist view**, where probabilities\n",
"are used to describe the frequencies of events in a series of repeated\n",
"trials. A Bayesian, instead, might qualify knowledge about an\n",
"event that has not even happened yet, let alone multiple times. Of\n",
"course, in most cases this belief is based on experience, i.e., lots of\n",
"repeated events in the past, and so it can be seen that perhaps these\n",
"views are not so different after all.\n",
"\n",
"In this chapter we will get comfortable with the Bayesian view, and learn how to calculate with them. This will allow use to fuse knowledge from different sources, e.g., how uncertain actions and noisy measurements can nevertheless yield enough information about our current state to make reasonable decisions.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## GTSAM 101\n",
"\n",
"The code above should feel familiar, but we used a new `Variables` method called `discrete_series` to define a *time series* of state variables. The signature of this method is\n",
"```python\n",
"def discrete_series(self, character: str, indices: Iterable[int],\n",
" domain: List[str]) -> Dict[int, DiscreteKey]:\n",
" \"\"\"Create several discrete variables with Symbol names.\n",
"\n",
" Args:\n",
" character (str): a single character.\n",
" indices: (Iterable[int]): a set of integer indices.\n",
" domain (List[str]): names for the different values.\n",
"\n",
" Returns:\n",
" Dict[int, DiscreteKey], i.e., [(gtsam.Key, cardinality)]\n",
" \"\"\"\n",
"```\n",
"\n",
"For example, the following creates a series of 5 state variables:"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"states = VARIABLES.discrete_series('X', [1, 2, 3], vacuum.rooms)\n"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{1: (6341068275337658369, 5), 2: (6341068275337658370, 5), 3: (6341068275337658371, 5)}\n"
]
}
],
"source": [
"print(states)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"When we print the results, we see that we now get a dictionary of DiscreteKeys, i.e., integer tuples of the form *(Key, cardinality)*. However, the \"Keys\" now seem to be very large integers. This is because for series of variables we use the `gtsam.Symbol` type, composed of a single character and an integer index:"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"X1\n"
]
}
],
"source": [
"symbol = gtsam.Symbol('X', 1)\n",
"print(symbol.string())\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"GTSAM internally stores symbols as a 64-bit integer key, with the 8-bit character in the most significant bits, which explains the large integer value:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"6341068275337658369\n"
]
}
],
"source": [
"print(symbol.key())\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can see that this corresponds to the first state above. However, as before, pretty printing translates these into a nicer looking strings wherever it matters."
]
}
],
"metadata": {
"colab": {
"collapsed_sections": [],
"include_colab_link": true,
"name": "S31_vacuum_state.ipynb",
"provenance": []
},
"kernelspec": {
"display_name": "Python 3.8.12 ('gtbook')",
"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.10.13"
},
"latex_metadata": {
"affiliation": "Georgia Institute of Technology",
"author": "Frank Dellaert and Seth Hutchinson",
"title": "Introduction to Robotics"
},
"vscode": {
"interpreter": {
"hash": "9f7376ced4243bb13dfcffa8a3ba834e0602aa8334cd3a1d8ba8d285f4628083"
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}

*P(X1):*

\n",
"\n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
"

\n",
"

"
],
"text/plain": [
"X1 | value |
---|---|

Living Room | 0 |

Kitchen | 0 |

Office | 1 |

Hallway | 0 |

Dining Room | 0 |