Changed fonts for source code. Switched to using ` to denote source code.
This commit is contained in:
parent
ebcc3b9d73
commit
af8e3a5284
@ -1,7 +1,7 @@
|
||||
{
|
||||
"metadata": {
|
||||
"name": "",
|
||||
"signature": "sha256:0cee74bbc347583f138d62e7fd98e2e82f11b90e2398c10fbe7f66c865143a76"
|
||||
"signature": "sha256:9d11bcd4ef99a8c59d3debbacc1dd13ef2280c966fe5c9e19cd4963b8e29bdea"
|
||||
},
|
||||
"nbformat": 3,
|
||||
"nbformat_minor": 0,
|
||||
@ -33,14 +33,20 @@
|
||||
{
|
||||
"html": [
|
||||
"<style>\n",
|
||||
"@import url('http://fonts.googleapis.com/css?family=Source+Code+Pro');\n",
|
||||
"\n",
|
||||
" div.cell{\n",
|
||||
" width: 850px;\n",
|
||||
" margin-left: 0% !important;\n",
|
||||
" margin-right: auto;\n",
|
||||
" }\n",
|
||||
" div.text_cell code {\n",
|
||||
" background: #F6F6F9;\n",
|
||||
" color: #0000FF;\n",
|
||||
" background: #FFFFFF;\n",
|
||||
" color: #000000;\n",
|
||||
" font-weight: 600;\n",
|
||||
" font-size: 13pt;\n",
|
||||
" font-style: bold;\n",
|
||||
" font-family: 'Source Code Pro', Consolas, monocco, monospace;\n",
|
||||
" }\n",
|
||||
" h1 {\n",
|
||||
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
|
||||
@ -242,13 +248,13 @@
|
||||
],
|
||||
"metadata": {},
|
||||
"output_type": "pyout",
|
||||
"prompt_number": 1,
|
||||
"prompt_number": 16,
|
||||
"text": [
|
||||
"<IPython.core.display.HTML at 0x2ae6710>"
|
||||
"<IPython.core.display.HTML at 0x2c27ad0>"
|
||||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 1
|
||||
"prompt_number": 16
|
||||
},
|
||||
{
|
||||
"cell_type": "heading",
|
||||
@ -262,7 +268,8 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"In this chapter we will work through the design of several Kalman filters to gain experience and confidence with the various equations and techniques. \n",
|
||||
"In this chapter we will work through the design of several Kalman filters to gain experience and confidence with the various equations and techniques.\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"For our first multidimensional problem we will track a robot in a 2D space, such as a field. We will start with a simple noisy sensor that outputs noisy $(x,y)$ coordinates which we will need to filter to generate a 2D track. Once we have mastered this concept, we will extend the problem significantly with more sensors and then adding control inputs. \n",
|
||||
"blah blah"
|
||||
@ -282,7 +289,7 @@
|
||||
"source": [
|
||||
"This first attempt at tracking a robot will closely resemble the 1-D dog tracking problem of previous chapters. This will allow us to 'get our feet wet' with Kalman filtering. So, instead of a sensor that outputs position in a hallway, we now have a sensor that supplies a noisy measurement of position in a 2-D space, such as an open field. That is, at each time $T$ it will provide an $(x,y)$ coordinate pair specifying the measurement of the sensor's position in the field.\n",
|
||||
"\n",
|
||||
"Implemention of code to interact with real sensors is beyond the scope of this book, so as before we will program simple simuations in Python to represent the sensors. We will develop several of these sensors as we go, each with more complications, so as I program them I will just append a number to the function name. $\\verb,pos_sensor1 (),$ is the first sensor we write, and so on. \n",
|
||||
"Implemention of code to interact with real sensors is beyond the scope of this book, so as before we will program simple simuations in Python to represent the sensors. We will develop several of these sensors as we go, each with more complications, so as I program them I will just append a number to the function name. `pos_sensor1()` is the first sensor we write, and so on.\n",
|
||||
"\n",
|
||||
"So let's start with a very simple sensor, one that travels in a straight line. It takes as input the last position, velocity, and how much noise we want, and returns the new position. "
|
||||
]
|
||||
@ -400,7 +407,7 @@
|
||||
"$$\n",
|
||||
"\\begin{bmatrix}x\\\\v_x\\\\y\\\\v_y\\end{bmatrix}' = \\begin{bmatrix}1& \\Delta t& 0& 0\\\\0& 1& 0& 0\\\\0& 0& 1& \\Delta t\\\\ 0& 0& 0& 1\\end{bmatrix}\\begin{bmatrix}x\\\\v_x\\\\y\\\\v_y\\end{bmatrix}$$\n",
|
||||
"\n",
|
||||
"So, let's do this in Python. It is very simple; the only thing new here is setting $\\vert,dim_z,$ to 2. We will see why it is set to 2 in step 4."
|
||||
"So, let's do this in Python. It is very simple; the only thing new here is setting `dim_z` to 2. We will see why it is set to 2 in step 4."
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -450,7 +457,7 @@
|
||||
"##### **Step 4**: Design the Measurement Function\n",
|
||||
"The measurement function defines how we go from the state variables to the measurements using the equation $\\mathbf{z} = \\mathbf{Hx}$. At first this is a bit counterintuitive, after all, we use the Kalman filter to go from measurements to state. But the update step needs to compute the residual between the current measurement and the measurement represented by the prediction step. Therefore $\\textbf{H}$ is multiplied by the state $\\textbf{x}$ to produce a measurement $\\textbf{z}$. \n",
|
||||
"\n",
|
||||
"In this case we have measurements for (x,y), so z must be of dimension $2\\times 1$. Our state variable is size $4\\times 1$. We can deduce the required size for $\\textbf{H}$ by recalling that multiplying a matrix of size $m\\times n$ by $n\\times p$ yields a matrix of size $m\\times p$. Thus,\n",
|
||||
"In this case we have measurements for (x,y), so $\\textbf{z}$ must be of dimension $2\\times 1$. Our state variable is size $4\\times 1$. We can deduce the required size for $\\textbf{H}$ by recalling that multiplying a matrix of size $m\\times n$ by $n\\times p$ yields a matrix of size $m\\times p$. Thus,\n",
|
||||
"\n",
|
||||
"$$ \n",
|
||||
"\\begin{aligned}\n",
|
||||
@ -948,7 +955,7 @@
|
||||
"\n",
|
||||
" traj = BallTrajectory2D (x0=0, y0=15, velocity=100, theta_deg=60)\n",
|
||||
" \n",
|
||||
"and then call $\\verb,traj.position(t),$ for each time step. Let's test this "
|
||||
"and then call `traj.position(t)` for each time step. Let's test this "
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -999,7 +1006,7 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"test_ball_vacuum([3,0]) # plot with noise in x onlyThis looks reasonable, so let's continue (excercise for the reader: validate this simulation more robustly)."
|
||||
"This looks reasonable, so let's continue (excercise for the reader: validate this simulation more robustly)."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"metadata": {
|
||||
"name": "",
|
||||
"signature": "sha256:aff9b578dbba090922a2bed55d3d82911a7c3fc265cd40e9f17e68bbab2ce8e5"
|
||||
"signature": "sha256:c1819e9ca7da173dd60891f9141240e1487e969120eed3fa9b30207968d8eb4d"
|
||||
},
|
||||
"nbformat": 3,
|
||||
"nbformat_minor": 0,
|
||||
@ -33,14 +33,20 @@
|
||||
{
|
||||
"html": [
|
||||
"<style>\n",
|
||||
"@import url('http://fonts.googleapis.com/css?family=Source+Code+Pro');\n",
|
||||
"\n",
|
||||
" div.cell{\n",
|
||||
" width: 850px;\n",
|
||||
" margin-left: 0% !important;\n",
|
||||
" margin-right: auto;\n",
|
||||
" }\n",
|
||||
" div.text_cell code {\n",
|
||||
" background: #F6F6F9;\n",
|
||||
" color: #0000FF;\n",
|
||||
" background: #FFFFFF;\n",
|
||||
" color: #000000;\n",
|
||||
" font-weight: 600;\n",
|
||||
" font-size: 13pt;\n",
|
||||
" font-style: bold;\n",
|
||||
" font-family: 'Source Code Pro', Consolas, monocco, monospace;\n",
|
||||
" }\n",
|
||||
" h1 {\n",
|
||||
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
|
||||
@ -242,13 +248,13 @@
|
||||
],
|
||||
"metadata": {},
|
||||
"output_type": "pyout",
|
||||
"prompt_number": 2,
|
||||
"prompt_number": 1,
|
||||
"text": [
|
||||
"<IPython.core.display.HTML at 0x1e888d0>"
|
||||
"<IPython.core.display.HTML at 0x2d74c90>"
|
||||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 2
|
||||
"prompt_number": 1
|
||||
},
|
||||
{
|
||||
"cell_type": "heading",
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"metadata": {
|
||||
"name": "",
|
||||
"signature": "sha256:851817f6127dcb57f996a34cf3bafc84f994f38c764af97eb71a8442b62cae41"
|
||||
"signature": "sha256:4ca13721197346f81b4551f2897e3b34983888159a0e887ab7d3fe729999e595"
|
||||
},
|
||||
"nbformat": 3,
|
||||
"nbformat_minor": 0,
|
||||
@ -31,92 +31,227 @@
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"output_type": "stream",
|
||||
"stream": "stdout",
|
||||
"text": [
|
||||
"Installed secnum.py. To use it, type:\n",
|
||||
" %load_ext secnum\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"javascript": [
|
||||
"console.log(\"Section numbering...\");\n",
|
||||
"html": [
|
||||
"<style>\n",
|
||||
"@import url('http://fonts.googleapis.com/css?family=Source+Code+Pro');\n",
|
||||
"\n",
|
||||
"function number_sections(threshold) {\n",
|
||||
"\n",
|
||||
" var h1_number = 0;\n",
|
||||
" var h2_number = 0;\n",
|
||||
"\n",
|
||||
" if (threshold === undefined) {\n",
|
||||
" threshold = 2; // does nothing so far\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" var cells = IPython.notebook.get_cells();\n",
|
||||
" \n",
|
||||
" for (var i=0; i < cells.length; i++) {\n",
|
||||
"\n",
|
||||
" var cell = cells[i];\n",
|
||||
" if (cell.cell_type !== 'heading') continue;\n",
|
||||
" \n",
|
||||
" var level = cell.level;\n",
|
||||
" if (level > threshold) continue;\n",
|
||||
" \n",
|
||||
" if (level === 1) {\n",
|
||||
" \n",
|
||||
" h1_number ++;\n",
|
||||
" var h1_element = cell.element.find('h1');\n",
|
||||
" var h1_html = h1_element.html();\n",
|
||||
" \n",
|
||||
" console.log(\"h1_html: \" + h1_html);\n",
|
||||
"\n",
|
||||
" var patt = /^[0-9]+\\.\\s(.*)/; // section number at start of string\n",
|
||||
" var title = h1_html.match(patt); // just the title\n",
|
||||
"\n",
|
||||
" if (title != null) { \n",
|
||||
" h1_element.html(h1_number + \". \" + title[1]);\n",
|
||||
" }\n",
|
||||
" else {\n",
|
||||
" h1_element.html(h1_number + \". \" + h1_html);\n",
|
||||
" }\n",
|
||||
" \n",
|
||||
" h2_number = 0;\n",
|
||||
" \n",
|
||||
" div.cell{\n",
|
||||
" width: 850px;\n",
|
||||
" margin-left: 0% !important;\n",
|
||||
" margin-right: auto;\n",
|
||||
" }\n",
|
||||
" \n",
|
||||
" if (level === 2) {\n",
|
||||
" \n",
|
||||
" h2_number ++;\n",
|
||||
" \n",
|
||||
" var h2_element = cell.element.find('h2');\n",
|
||||
" var h2_html = h2_element.html();\n",
|
||||
"\n",
|
||||
" console.log(\"h2_html: \" + h2_html);\n",
|
||||
"\n",
|
||||
" \n",
|
||||
" var patt = /^[0-9]+\\.[0-9]+\\.\\s/;\n",
|
||||
" var result = h2_html.match(patt);\n",
|
||||
"\n",
|
||||
" if (result != null) {\n",
|
||||
" h2_html = h2_html.replace(result, \"\");\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" h2_element.html(h1_number + \".\" + h2_number + \". \" + h2_html);\n",
|
||||
" \n",
|
||||
" div.text_cell code {\n",
|
||||
" background: #FFFFFF;\n",
|
||||
" color: #000000;\n",
|
||||
" font-weight: 600;\n",
|
||||
" font-size: 13pt;\n",
|
||||
" font-style: bold;\n",
|
||||
" font-family: 'Source Code Pro', Consolas, monocco, monospace;\n",
|
||||
" }\n",
|
||||
" h1 {\n",
|
||||
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
|
||||
"\t}\n",
|
||||
"\t\n",
|
||||
" div.input_area {\n",
|
||||
" background: #F6F6F9;\n",
|
||||
" border: 1px solid #586e75;\n",
|
||||
" }\n",
|
||||
" \n",
|
||||
" }\n",
|
||||
" \n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"number_sections();\n",
|
||||
"\n",
|
||||
"// $([IPython.evnts]).on('create.Cell', number_sections);\n",
|
||||
"\n",
|
||||
"$([IPython.events]).on('selected_cell_type_changed.Notebook', number_sections);\n",
|
||||
"\n"
|
||||
" .text_cell_render h1 {\n",
|
||||
" font-weight: 200;\n",
|
||||
" font-size: 30pt;\n",
|
||||
" line-height: 100%;\n",
|
||||
" color:#c76c0c;\n",
|
||||
" margin-bottom: 0.5em;\n",
|
||||
" margin-top: 1em;\n",
|
||||
" display: block;\n",
|
||||
" white-space: wrap;\n",
|
||||
" } \n",
|
||||
" h2 {\n",
|
||||
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
|
||||
" }\n",
|
||||
" .text_cell_render h2 {\n",
|
||||
" font-weight: 200;\n",
|
||||
" font-size: 20pt;\n",
|
||||
" font-style: italic;\n",
|
||||
" line-height: 100%;\n",
|
||||
" color:#c76c0c;\n",
|
||||
" margin-bottom: 0.5em;\n",
|
||||
" margin-top: 1.5em;\n",
|
||||
" display: block;\n",
|
||||
" white-space: nowrap;\n",
|
||||
" } \n",
|
||||
" h3 {\n",
|
||||
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
|
||||
" }\n",
|
||||
" .text_cell_render h3 {\n",
|
||||
" font-weight: 300;\n",
|
||||
" font-size: 18pt;\n",
|
||||
" line-height: 100%;\n",
|
||||
" color:#d77c0c;\n",
|
||||
" margin-bottom: 0.5em;\n",
|
||||
" margin-top: 2em;\n",
|
||||
" display: block;\n",
|
||||
" white-space: nowrap;\n",
|
||||
" }\n",
|
||||
" h4 {\n",
|
||||
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
|
||||
" }\n",
|
||||
" .text_cell_render h4 {\n",
|
||||
" font-weight: 300;\n",
|
||||
" font-size: 16pt;\n",
|
||||
" color:#d77c0c;\n",
|
||||
" margin-bottom: 0.5em;\n",
|
||||
" margin-top: 0.5em;\n",
|
||||
" display: block;\n",
|
||||
" white-space: nowrap;\n",
|
||||
" }\n",
|
||||
" h5 {\n",
|
||||
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
|
||||
" }\n",
|
||||
" .text_cell_render h5 {\n",
|
||||
" font-weight: 300;\n",
|
||||
" font-style: normal;\n",
|
||||
" color: #1d3b84;\n",
|
||||
" font-size: 16pt;\n",
|
||||
" margin-bottom: 0em;\n",
|
||||
" margin-top: 1.5em;\n",
|
||||
" display: block;\n",
|
||||
" white-space: nowrap;\n",
|
||||
" }\n",
|
||||
" div.text_cell_render{\n",
|
||||
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
|
||||
" line-height: 135%;\n",
|
||||
" font-size: 110%;\n",
|
||||
" width:750px;\n",
|
||||
" margin-left:auto;\n",
|
||||
" margin-right:auto;\n",
|
||||
" text-align:justify;\n",
|
||||
" text-justify:inter-word;\n",
|
||||
" }\n",
|
||||
" div.output_subarea.output_text.output_pyout {\n",
|
||||
" overflow-x: auto;\n",
|
||||
" overflow-y: scroll;\n",
|
||||
" max-height: 300px;\n",
|
||||
" }\n",
|
||||
" div.output_subarea.output_stream.output_stdout.output_text {\n",
|
||||
" overflow-x: auto;\n",
|
||||
" overflow-y: scroll;\n",
|
||||
" max-height: 300px;\n",
|
||||
" }\n",
|
||||
" code{\n",
|
||||
" font-size: 70%;\n",
|
||||
" }\n",
|
||||
" .rendered_html code{\n",
|
||||
" background-color: transparent;\n",
|
||||
" }\n",
|
||||
" ul{\n",
|
||||
" margin: 2em;\n",
|
||||
" }\n",
|
||||
" ul li{\n",
|
||||
" padding-left: 0.5em; \n",
|
||||
" margin-bottom: 0.5em; \n",
|
||||
" margin-top: 0.5em; \n",
|
||||
" }\n",
|
||||
" ul li li{\n",
|
||||
" padding-left: 0.2em; \n",
|
||||
" margin-bottom: 0.2em; \n",
|
||||
" margin-top: 0.2em; \n",
|
||||
" }\n",
|
||||
" ol{\n",
|
||||
" margin: 2em;\n",
|
||||
" }\n",
|
||||
" ol li{\n",
|
||||
" padding-left: 0.5em; \n",
|
||||
" margin-bottom: 0.5em; \n",
|
||||
" margin-top: 0.5em; \n",
|
||||
" }\n",
|
||||
" ul li{\n",
|
||||
" padding-left: 0.5em; \n",
|
||||
" margin-bottom: 0.5em; \n",
|
||||
" margin-top: 0.2em; \n",
|
||||
" }\n",
|
||||
" a:link{\n",
|
||||
" font-weight: bold;\n",
|
||||
" color:#447adb;\n",
|
||||
" }\n",
|
||||
" a:visited{\n",
|
||||
" font-weight: bold;\n",
|
||||
" color: #1d3b84;\n",
|
||||
" }\n",
|
||||
" a:hover{\n",
|
||||
" font-weight: bold;\n",
|
||||
" color: #1d3b84;\n",
|
||||
" }\n",
|
||||
" a:focus{\n",
|
||||
" font-weight: bold;\n",
|
||||
" color:#447adb;\n",
|
||||
" }\n",
|
||||
" a:active{\n",
|
||||
" font-weight: bold;\n",
|
||||
" color:#447adb;\n",
|
||||
" }\n",
|
||||
" .rendered_html :link {\n",
|
||||
" text-decoration: underline; \n",
|
||||
" }\n",
|
||||
" .rendered_html :hover {\n",
|
||||
" text-decoration: none; \n",
|
||||
" }\n",
|
||||
" .rendered_html :visited {\n",
|
||||
" text-decoration: none;\n",
|
||||
" }\n",
|
||||
" .rendered_html :focus {\n",
|
||||
" text-decoration: none;\n",
|
||||
" }\n",
|
||||
" .rendered_html :active {\n",
|
||||
" text-decoration: none;\n",
|
||||
" }\n",
|
||||
" .warning{\n",
|
||||
" color: rgb( 240, 20, 20 )\n",
|
||||
" } \n",
|
||||
" hr {\n",
|
||||
" color: #f3f3f3;\n",
|
||||
" background-color: #f3f3f3;\n",
|
||||
" height: 1px;\n",
|
||||
" }\n",
|
||||
" blockquote{\n",
|
||||
" display:block;\n",
|
||||
" background: #fcfcfc;\n",
|
||||
" border-left: 5px solid #c76c0c;\n",
|
||||
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
|
||||
" width:680px;\n",
|
||||
" padding: 10px 10px 10px 10px;\n",
|
||||
" text-align:justify;\n",
|
||||
" text-justify:inter-word;\n",
|
||||
" }\n",
|
||||
" blockquote p {\n",
|
||||
" margin-bottom: 0;\n",
|
||||
" line-height: 125%;\n",
|
||||
" font-size: 100%;\n",
|
||||
" }\n",
|
||||
"</style>\n",
|
||||
"<script>\n",
|
||||
" MathJax.Hub.Config({\n",
|
||||
" TeX: {\n",
|
||||
" extensions: [\"AMSmath.js\"]\n",
|
||||
" },\n",
|
||||
" tex2jax: {\n",
|
||||
" inlineMath: [ ['$','$'], [\"\\\\(\",\"\\\\)\"] ],\n",
|
||||
" displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"] ]\n",
|
||||
" },\n",
|
||||
" displayAlign: 'center', // Change this to 'center' to center equations.\n",
|
||||
" \"HTML-CSS\": {\n",
|
||||
" styles: {'.MathJax_Display': {\"margin\": 4}}\n",
|
||||
" }\n",
|
||||
" });\n",
|
||||
"</script>\n"
|
||||
],
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
"output_type": "pyout",
|
||||
"prompt_number": 1,
|
||||
"text": [
|
||||
"<IPython.core.display.HTML at 0x2a13b90>"
|
||||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 1
|
||||
|
378
Gaussians.ipynb
378
Gaussians.ipynb
File diff suppressed because one or more lines are too long
@ -1,7 +1,7 @@
|
||||
{
|
||||
"metadata": {
|
||||
"name": "",
|
||||
"signature": "sha256:b896371b827d48a658ba791bdaf8bed2d0c3878ddeea9731b9cd40ec8f9df021"
|
||||
"signature": "sha256:dd34f4987a60a8a3c453361b731ac3f9a06c88bce6e4f0c67907f60ea9ab99fc"
|
||||
},
|
||||
"nbformat": 3,
|
||||
"nbformat_minor": 0,
|
||||
@ -31,92 +31,227 @@
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"output_type": "stream",
|
||||
"stream": "stdout",
|
||||
"text": [
|
||||
"Installed secnum.py. To use it, type:\n",
|
||||
" %load_ext secnum\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"javascript": [
|
||||
"console.log(\"Section numbering...\");\n",
|
||||
"html": [
|
||||
"<style>\n",
|
||||
"@import url('http://fonts.googleapis.com/css?family=Source+Code+Pro');\n",
|
||||
"\n",
|
||||
"function number_sections(threshold) {\n",
|
||||
"\n",
|
||||
" var h1_number = 0;\n",
|
||||
" var h2_number = 0;\n",
|
||||
"\n",
|
||||
" if (threshold === undefined) {\n",
|
||||
" threshold = 2; // does nothing so far\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" var cells = IPython.notebook.get_cells();\n",
|
||||
" \n",
|
||||
" for (var i=0; i < cells.length; i++) {\n",
|
||||
"\n",
|
||||
" var cell = cells[i];\n",
|
||||
" if (cell.cell_type !== 'heading') continue;\n",
|
||||
" \n",
|
||||
" var level = cell.level;\n",
|
||||
" if (level > threshold) continue;\n",
|
||||
" \n",
|
||||
" if (level === 1) {\n",
|
||||
" \n",
|
||||
" h1_number ++;\n",
|
||||
" var h1_element = cell.element.find('h1');\n",
|
||||
" var h1_html = h1_element.html();\n",
|
||||
" \n",
|
||||
" console.log(\"h1_html: \" + h1_html);\n",
|
||||
"\n",
|
||||
" var patt = /^[0-9]+\\.\\s(.*)/; // section number at start of string\n",
|
||||
" var title = h1_html.match(patt); // just the title\n",
|
||||
"\n",
|
||||
" if (title != null) { \n",
|
||||
" h1_element.html(h1_number + \". \" + title[1]);\n",
|
||||
" }\n",
|
||||
" else {\n",
|
||||
" h1_element.html(h1_number + \". \" + h1_html);\n",
|
||||
" }\n",
|
||||
" \n",
|
||||
" h2_number = 0;\n",
|
||||
" \n",
|
||||
" div.cell{\n",
|
||||
" width: 850px;\n",
|
||||
" margin-left: 0% !important;\n",
|
||||
" margin-right: auto;\n",
|
||||
" }\n",
|
||||
" \n",
|
||||
" if (level === 2) {\n",
|
||||
" \n",
|
||||
" h2_number ++;\n",
|
||||
" \n",
|
||||
" var h2_element = cell.element.find('h2');\n",
|
||||
" var h2_html = h2_element.html();\n",
|
||||
"\n",
|
||||
" console.log(\"h2_html: \" + h2_html);\n",
|
||||
"\n",
|
||||
" \n",
|
||||
" var patt = /^[0-9]+\\.[0-9]+\\.\\s/;\n",
|
||||
" var result = h2_html.match(patt);\n",
|
||||
"\n",
|
||||
" if (result != null) {\n",
|
||||
" h2_html = h2_html.replace(result, \"\");\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" h2_element.html(h1_number + \".\" + h2_number + \". \" + h2_html);\n",
|
||||
" \n",
|
||||
" div.text_cell code {\n",
|
||||
" background: #FFFFFF;\n",
|
||||
" color: #000000;\n",
|
||||
" font-weight: 600;\n",
|
||||
" font-size: 13pt;\n",
|
||||
" font-style: bold;\n",
|
||||
" font-family: 'Source Code Pro', Consolas, monocco, monospace;\n",
|
||||
" }\n",
|
||||
" h1 {\n",
|
||||
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
|
||||
"\t}\n",
|
||||
"\t\n",
|
||||
" div.input_area {\n",
|
||||
" background: #F6F6F9;\n",
|
||||
" border: 1px solid #586e75;\n",
|
||||
" }\n",
|
||||
" \n",
|
||||
" }\n",
|
||||
" \n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"number_sections();\n",
|
||||
"\n",
|
||||
"// $([IPython.evnts]).on('create.Cell', number_sections);\n",
|
||||
"\n",
|
||||
"$([IPython.events]).on('selected_cell_type_changed.Notebook', number_sections);\n",
|
||||
"\n"
|
||||
" .text_cell_render h1 {\n",
|
||||
" font-weight: 200;\n",
|
||||
" font-size: 30pt;\n",
|
||||
" line-height: 100%;\n",
|
||||
" color:#c76c0c;\n",
|
||||
" margin-bottom: 0.5em;\n",
|
||||
" margin-top: 1em;\n",
|
||||
" display: block;\n",
|
||||
" white-space: wrap;\n",
|
||||
" } \n",
|
||||
" h2 {\n",
|
||||
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
|
||||
" }\n",
|
||||
" .text_cell_render h2 {\n",
|
||||
" font-weight: 200;\n",
|
||||
" font-size: 20pt;\n",
|
||||
" font-style: italic;\n",
|
||||
" line-height: 100%;\n",
|
||||
" color:#c76c0c;\n",
|
||||
" margin-bottom: 0.5em;\n",
|
||||
" margin-top: 1.5em;\n",
|
||||
" display: block;\n",
|
||||
" white-space: nowrap;\n",
|
||||
" } \n",
|
||||
" h3 {\n",
|
||||
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
|
||||
" }\n",
|
||||
" .text_cell_render h3 {\n",
|
||||
" font-weight: 300;\n",
|
||||
" font-size: 18pt;\n",
|
||||
" line-height: 100%;\n",
|
||||
" color:#d77c0c;\n",
|
||||
" margin-bottom: 0.5em;\n",
|
||||
" margin-top: 2em;\n",
|
||||
" display: block;\n",
|
||||
" white-space: nowrap;\n",
|
||||
" }\n",
|
||||
" h4 {\n",
|
||||
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
|
||||
" }\n",
|
||||
" .text_cell_render h4 {\n",
|
||||
" font-weight: 300;\n",
|
||||
" font-size: 16pt;\n",
|
||||
" color:#d77c0c;\n",
|
||||
" margin-bottom: 0.5em;\n",
|
||||
" margin-top: 0.5em;\n",
|
||||
" display: block;\n",
|
||||
" white-space: nowrap;\n",
|
||||
" }\n",
|
||||
" h5 {\n",
|
||||
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
|
||||
" }\n",
|
||||
" .text_cell_render h5 {\n",
|
||||
" font-weight: 300;\n",
|
||||
" font-style: normal;\n",
|
||||
" color: #1d3b84;\n",
|
||||
" font-size: 16pt;\n",
|
||||
" margin-bottom: 0em;\n",
|
||||
" margin-top: 1.5em;\n",
|
||||
" display: block;\n",
|
||||
" white-space: nowrap;\n",
|
||||
" }\n",
|
||||
" div.text_cell_render{\n",
|
||||
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
|
||||
" line-height: 135%;\n",
|
||||
" font-size: 110%;\n",
|
||||
" width:750px;\n",
|
||||
" margin-left:auto;\n",
|
||||
" margin-right:auto;\n",
|
||||
" text-align:justify;\n",
|
||||
" text-justify:inter-word;\n",
|
||||
" }\n",
|
||||
" div.output_subarea.output_text.output_pyout {\n",
|
||||
" overflow-x: auto;\n",
|
||||
" overflow-y: scroll;\n",
|
||||
" max-height: 300px;\n",
|
||||
" }\n",
|
||||
" div.output_subarea.output_stream.output_stdout.output_text {\n",
|
||||
" overflow-x: auto;\n",
|
||||
" overflow-y: scroll;\n",
|
||||
" max-height: 300px;\n",
|
||||
" }\n",
|
||||
" code{\n",
|
||||
" font-size: 70%;\n",
|
||||
" }\n",
|
||||
" .rendered_html code{\n",
|
||||
" background-color: transparent;\n",
|
||||
" }\n",
|
||||
" ul{\n",
|
||||
" margin: 2em;\n",
|
||||
" }\n",
|
||||
" ul li{\n",
|
||||
" padding-left: 0.5em; \n",
|
||||
" margin-bottom: 0.5em; \n",
|
||||
" margin-top: 0.5em; \n",
|
||||
" }\n",
|
||||
" ul li li{\n",
|
||||
" padding-left: 0.2em; \n",
|
||||
" margin-bottom: 0.2em; \n",
|
||||
" margin-top: 0.2em; \n",
|
||||
" }\n",
|
||||
" ol{\n",
|
||||
" margin: 2em;\n",
|
||||
" }\n",
|
||||
" ol li{\n",
|
||||
" padding-left: 0.5em; \n",
|
||||
" margin-bottom: 0.5em; \n",
|
||||
" margin-top: 0.5em; \n",
|
||||
" }\n",
|
||||
" ul li{\n",
|
||||
" padding-left: 0.5em; \n",
|
||||
" margin-bottom: 0.5em; \n",
|
||||
" margin-top: 0.2em; \n",
|
||||
" }\n",
|
||||
" a:link{\n",
|
||||
" font-weight: bold;\n",
|
||||
" color:#447adb;\n",
|
||||
" }\n",
|
||||
" a:visited{\n",
|
||||
" font-weight: bold;\n",
|
||||
" color: #1d3b84;\n",
|
||||
" }\n",
|
||||
" a:hover{\n",
|
||||
" font-weight: bold;\n",
|
||||
" color: #1d3b84;\n",
|
||||
" }\n",
|
||||
" a:focus{\n",
|
||||
" font-weight: bold;\n",
|
||||
" color:#447adb;\n",
|
||||
" }\n",
|
||||
" a:active{\n",
|
||||
" font-weight: bold;\n",
|
||||
" color:#447adb;\n",
|
||||
" }\n",
|
||||
" .rendered_html :link {\n",
|
||||
" text-decoration: underline; \n",
|
||||
" }\n",
|
||||
" .rendered_html :hover {\n",
|
||||
" text-decoration: none; \n",
|
||||
" }\n",
|
||||
" .rendered_html :visited {\n",
|
||||
" text-decoration: none;\n",
|
||||
" }\n",
|
||||
" .rendered_html :focus {\n",
|
||||
" text-decoration: none;\n",
|
||||
" }\n",
|
||||
" .rendered_html :active {\n",
|
||||
" text-decoration: none;\n",
|
||||
" }\n",
|
||||
" .warning{\n",
|
||||
" color: rgb( 240, 20, 20 )\n",
|
||||
" } \n",
|
||||
" hr {\n",
|
||||
" color: #f3f3f3;\n",
|
||||
" background-color: #f3f3f3;\n",
|
||||
" height: 1px;\n",
|
||||
" }\n",
|
||||
" blockquote{\n",
|
||||
" display:block;\n",
|
||||
" background: #fcfcfc;\n",
|
||||
" border-left: 5px solid #c76c0c;\n",
|
||||
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
|
||||
" width:680px;\n",
|
||||
" padding: 10px 10px 10px 10px;\n",
|
||||
" text-align:justify;\n",
|
||||
" text-justify:inter-word;\n",
|
||||
" }\n",
|
||||
" blockquote p {\n",
|
||||
" margin-bottom: 0;\n",
|
||||
" line-height: 125%;\n",
|
||||
" font-size: 100%;\n",
|
||||
" }\n",
|
||||
"</style>\n",
|
||||
"<script>\n",
|
||||
" MathJax.Hub.Config({\n",
|
||||
" TeX: {\n",
|
||||
" extensions: [\"AMSmath.js\"]\n",
|
||||
" },\n",
|
||||
" tex2jax: {\n",
|
||||
" inlineMath: [ ['$','$'], [\"\\\\(\",\"\\\\)\"] ],\n",
|
||||
" displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"] ]\n",
|
||||
" },\n",
|
||||
" displayAlign: 'center', // Change this to 'center' to center equations.\n",
|
||||
" \"HTML-CSS\": {\n",
|
||||
" styles: {'.MathJax_Display': {\"margin\": 4}}\n",
|
||||
" }\n",
|
||||
" });\n",
|
||||
"</script>\n"
|
||||
],
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
"output_type": "pyout",
|
||||
"prompt_number": 1,
|
||||
"text": [
|
||||
"<IPython.core.display.HTML at 0x2d55b90>"
|
||||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 1
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"metadata": {
|
||||
"name": "",
|
||||
"signature": "sha256:c02db5403bca8fcc62114de79446c5628d7d653edbf08487cc19e4881b8172d4"
|
||||
"signature": "sha256:df62e55f1f0a4f8dcc70cac1a108cfa5b4a6221d30c37287df8c61e83810b1bf"
|
||||
},
|
||||
"nbformat": 3,
|
||||
"nbformat_minor": 0,
|
||||
@ -31,95 +31,230 @@
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"output_type": "stream",
|
||||
"stream": "stdout",
|
||||
"text": [
|
||||
"Installed secnum.py. To use it, type:\n",
|
||||
" %load_ext secnum\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"javascript": [
|
||||
"console.log(\"Section numbering...\");\n",
|
||||
"html": [
|
||||
"<style>\n",
|
||||
"@import url('http://fonts.googleapis.com/css?family=Source+Code+Pro');\n",
|
||||
"\n",
|
||||
"function number_sections(threshold) {\n",
|
||||
"\n",
|
||||
" var h1_number = 0;\n",
|
||||
" var h2_number = 0;\n",
|
||||
"\n",
|
||||
" if (threshold === undefined) {\n",
|
||||
" threshold = 2; // does nothing so far\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" var cells = IPython.notebook.get_cells();\n",
|
||||
" \n",
|
||||
" for (var i=0; i < cells.length; i++) {\n",
|
||||
"\n",
|
||||
" var cell = cells[i];\n",
|
||||
" if (cell.cell_type !== 'heading') continue;\n",
|
||||
" \n",
|
||||
" var level = cell.level;\n",
|
||||
" if (level > threshold) continue;\n",
|
||||
" \n",
|
||||
" if (level === 1) {\n",
|
||||
" \n",
|
||||
" h1_number ++;\n",
|
||||
" var h1_element = cell.element.find('h1');\n",
|
||||
" var h1_html = h1_element.html();\n",
|
||||
" \n",
|
||||
" console.log(\"h1_html: \" + h1_html);\n",
|
||||
"\n",
|
||||
" var patt = /^[0-9]+\\.\\s(.*)/; // section number at start of string\n",
|
||||
" var title = h1_html.match(patt); // just the title\n",
|
||||
"\n",
|
||||
" if (title != null) { \n",
|
||||
" h1_element.html(h1_number + \". \" + title[1]);\n",
|
||||
" }\n",
|
||||
" else {\n",
|
||||
" h1_element.html(h1_number + \". \" + h1_html);\n",
|
||||
" }\n",
|
||||
" \n",
|
||||
" h2_number = 0;\n",
|
||||
" \n",
|
||||
" div.cell{\n",
|
||||
" width: 850px;\n",
|
||||
" margin-left: 0% !important;\n",
|
||||
" margin-right: auto;\n",
|
||||
" }\n",
|
||||
" \n",
|
||||
" if (level === 2) {\n",
|
||||
" \n",
|
||||
" h2_number ++;\n",
|
||||
" \n",
|
||||
" var h2_element = cell.element.find('h2');\n",
|
||||
" var h2_html = h2_element.html();\n",
|
||||
"\n",
|
||||
" console.log(\"h2_html: \" + h2_html);\n",
|
||||
"\n",
|
||||
" \n",
|
||||
" var patt = /^[0-9]+\\.[0-9]+\\.\\s/;\n",
|
||||
" var result = h2_html.match(patt);\n",
|
||||
"\n",
|
||||
" if (result != null) {\n",
|
||||
" h2_html = h2_html.replace(result, \"\");\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" h2_element.html(h1_number + \".\" + h2_number + \". \" + h2_html);\n",
|
||||
" \n",
|
||||
" div.text_cell code {\n",
|
||||
" background: transparent;\n",
|
||||
" color: #000000;\n",
|
||||
" font-weight: 600;\n",
|
||||
" font-size: 13pt;\n",
|
||||
" font-style: bold;\n",
|
||||
" font-family: 'Source Code Pro', Consolas, monocco, monospace;\n",
|
||||
" }\n",
|
||||
" h1 {\n",
|
||||
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
|
||||
"\t}\n",
|
||||
"\t\n",
|
||||
" div.input_area {\n",
|
||||
" background: #F6F6F9;\n",
|
||||
" border: 1px solid #586e75;\n",
|
||||
" }\n",
|
||||
" \n",
|
||||
" }\n",
|
||||
" \n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"number_sections();\n",
|
||||
"\n",
|
||||
"// $([IPython.evnts]).on('create.Cell', number_sections);\n",
|
||||
"\n",
|
||||
"$([IPython.events]).on('selected_cell_type_changed.Notebook', number_sections);\n",
|
||||
"\n"
|
||||
" .text_cell_render h1 {\n",
|
||||
" font-weight: 200;\n",
|
||||
" font-size: 30pt;\n",
|
||||
" line-height: 100%;\n",
|
||||
" color:#c76c0c;\n",
|
||||
" margin-bottom: 0.5em;\n",
|
||||
" margin-top: 1em;\n",
|
||||
" display: block;\n",
|
||||
" white-space: wrap;\n",
|
||||
" } \n",
|
||||
" h2 {\n",
|
||||
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
|
||||
" }\n",
|
||||
" .text_cell_render h2 {\n",
|
||||
" font-weight: 200;\n",
|
||||
" font-size: 20pt;\n",
|
||||
" font-style: italic;\n",
|
||||
" line-height: 100%;\n",
|
||||
" color:#c76c0c;\n",
|
||||
" margin-bottom: 0.5em;\n",
|
||||
" margin-top: 1.5em;\n",
|
||||
" display: block;\n",
|
||||
" white-space: nowrap;\n",
|
||||
" } \n",
|
||||
" h3 {\n",
|
||||
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
|
||||
" }\n",
|
||||
" .text_cell_render h3 {\n",
|
||||
" font-weight: 300;\n",
|
||||
" font-size: 18pt;\n",
|
||||
" line-height: 100%;\n",
|
||||
" color:#d77c0c;\n",
|
||||
" margin-bottom: 0.5em;\n",
|
||||
" margin-top: 2em;\n",
|
||||
" display: block;\n",
|
||||
" white-space: nowrap;\n",
|
||||
" }\n",
|
||||
" h4 {\n",
|
||||
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
|
||||
" }\n",
|
||||
" .text_cell_render h4 {\n",
|
||||
" font-weight: 300;\n",
|
||||
" font-size: 16pt;\n",
|
||||
" color:#d77c0c;\n",
|
||||
" margin-bottom: 0.5em;\n",
|
||||
" margin-top: 0.5em;\n",
|
||||
" display: block;\n",
|
||||
" white-space: nowrap;\n",
|
||||
" }\n",
|
||||
" h5 {\n",
|
||||
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
|
||||
" }\n",
|
||||
" .text_cell_render h5 {\n",
|
||||
" font-weight: 300;\n",
|
||||
" font-style: normal;\n",
|
||||
" color: #1d3b84;\n",
|
||||
" font-size: 16pt;\n",
|
||||
" margin-bottom: 0em;\n",
|
||||
" margin-top: 1.5em;\n",
|
||||
" display: block;\n",
|
||||
" white-space: nowrap;\n",
|
||||
" }\n",
|
||||
" div.text_cell_render{\n",
|
||||
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
|
||||
" line-height: 135%;\n",
|
||||
" font-size: 110%;\n",
|
||||
" width:750px;\n",
|
||||
" margin-left:auto;\n",
|
||||
" margin-right:auto;\n",
|
||||
" text-align:justify;\n",
|
||||
" text-justify:inter-word;\n",
|
||||
" }\n",
|
||||
" div.output_subarea.output_text.output_pyout {\n",
|
||||
" overflow-x: auto;\n",
|
||||
" overflow-y: scroll;\n",
|
||||
" max-height: 300px;\n",
|
||||
" }\n",
|
||||
" div.output_subarea.output_stream.output_stdout.output_text {\n",
|
||||
" overflow-x: auto;\n",
|
||||
" overflow-y: scroll;\n",
|
||||
" max-height: 300px;\n",
|
||||
" }\n",
|
||||
" code{\n",
|
||||
" font-size: 70%;\n",
|
||||
" }\n",
|
||||
" .rendered_html code{\n",
|
||||
" background-color: transparent;\n",
|
||||
" }\n",
|
||||
" ul{\n",
|
||||
" margin: 2em;\n",
|
||||
" }\n",
|
||||
" ul li{\n",
|
||||
" padding-left: 0.5em; \n",
|
||||
" margin-bottom: 0.5em; \n",
|
||||
" margin-top: 0.5em; \n",
|
||||
" }\n",
|
||||
" ul li li{\n",
|
||||
" padding-left: 0.2em; \n",
|
||||
" margin-bottom: 0.2em; \n",
|
||||
" margin-top: 0.2em; \n",
|
||||
" }\n",
|
||||
" ol{\n",
|
||||
" margin: 2em;\n",
|
||||
" }\n",
|
||||
" ol li{\n",
|
||||
" padding-left: 0.5em; \n",
|
||||
" margin-bottom: 0.5em; \n",
|
||||
" margin-top: 0.5em; \n",
|
||||
" }\n",
|
||||
" ul li{\n",
|
||||
" padding-left: 0.5em; \n",
|
||||
" margin-bottom: 0.5em; \n",
|
||||
" margin-top: 0.2em; \n",
|
||||
" }\n",
|
||||
" a:link{\n",
|
||||
" font-weight: bold;\n",
|
||||
" color:#447adb;\n",
|
||||
" }\n",
|
||||
" a:visited{\n",
|
||||
" font-weight: bold;\n",
|
||||
" color: #1d3b84;\n",
|
||||
" }\n",
|
||||
" a:hover{\n",
|
||||
" font-weight: bold;\n",
|
||||
" color: #1d3b84;\n",
|
||||
" }\n",
|
||||
" a:focus{\n",
|
||||
" font-weight: bold;\n",
|
||||
" color:#447adb;\n",
|
||||
" }\n",
|
||||
" a:active{\n",
|
||||
" font-weight: bold;\n",
|
||||
" color:#447adb;\n",
|
||||
" }\n",
|
||||
" .rendered_html :link {\n",
|
||||
" text-decoration: underline; \n",
|
||||
" }\n",
|
||||
" .rendered_html :hover {\n",
|
||||
" text-decoration: none; \n",
|
||||
" }\n",
|
||||
" .rendered_html :visited {\n",
|
||||
" text-decoration: none;\n",
|
||||
" }\n",
|
||||
" .rendered_html :focus {\n",
|
||||
" text-decoration: none;\n",
|
||||
" }\n",
|
||||
" .rendered_html :active {\n",
|
||||
" text-decoration: none;\n",
|
||||
" }\n",
|
||||
" .warning{\n",
|
||||
" color: rgb( 240, 20, 20 )\n",
|
||||
" } \n",
|
||||
" hr {\n",
|
||||
" color: #f3f3f3;\n",
|
||||
" background-color: #f3f3f3;\n",
|
||||
" height: 1px;\n",
|
||||
" }\n",
|
||||
" blockquote{\n",
|
||||
" display:block;\n",
|
||||
" background: #fcfcfc;\n",
|
||||
" border-left: 5px solid #c76c0c;\n",
|
||||
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
|
||||
" width:680px;\n",
|
||||
" padding: 10px 10px 10px 10px;\n",
|
||||
" text-align:justify;\n",
|
||||
" text-justify:inter-word;\n",
|
||||
" }\n",
|
||||
" blockquote p {\n",
|
||||
" margin-bottom: 0;\n",
|
||||
" line-height: 125%;\n",
|
||||
" font-size: 100%;\n",
|
||||
" }\n",
|
||||
"</style>\n",
|
||||
"<script>\n",
|
||||
" MathJax.Hub.Config({\n",
|
||||
" TeX: {\n",
|
||||
" extensions: [\"AMSmath.js\"]\n",
|
||||
" },\n",
|
||||
" tex2jax: {\n",
|
||||
" inlineMath: [ ['$','$'], [\"\\\\(\",\"\\\\)\"] ],\n",
|
||||
" displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"] ]\n",
|
||||
" },\n",
|
||||
" displayAlign: 'center', // Change this to 'center' to center equations.\n",
|
||||
" \"HTML-CSS\": {\n",
|
||||
" styles: {'.MathJax_Display': {\"margin\": 4}}\n",
|
||||
" }\n",
|
||||
" });\n",
|
||||
"</script>\n"
|
||||
],
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
"output_type": "pyout",
|
||||
"prompt_number": 2,
|
||||
"text": [
|
||||
"<IPython.core.display.HTML at 0x216f7d0>"
|
||||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 1
|
||||
"prompt_number": 2
|
||||
},
|
||||
{
|
||||
"cell_type": "heading",
|
||||
@ -188,8 +323,7 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"The constructor $\\verb,__init()__,$ initializes the DogSensor class with an initial position (x0), velocity (vel), and an noise scaling factor. The $\\verb,sense(),$ function has the dog move by the set velocity and returns its new position, with noise added. If you look at the code for $\\verb,sense(),$ you will see a call to $\\verb,numpy.random.randn(),$. This returns a number sampled from a normal distribution with a mean of 0.0. Let's look at some example output for that.\n",
|
||||
"\n"
|
||||
"The constructor `_init()__` initializes the DogSensor class with an initial position `x0`, velocity `vel`, and an noise scaling factor. The `sense()` function has the dog move by the set velocity and returns its new position, with noise added. If you look at the code for `sense()` you will see a call to `numpy.random.randn()`. This returns a number sampled from a normal distribution with a mean of 0.0. Let's look at some example output for that."
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -218,7 +352,7 @@
|
||||
"source": [
|
||||
"You should see a sequence of numbers near 0, some negative and some positive. Most are probably between -1 and 1, but a few might lie somewhat outside that range. This is what we expect from a normal distribution - values are clustered around the mean, and there are fewer values the further you get from the mean.\n",
|
||||
"\n",
|
||||
"Okay, so lets look at the output of the $\\verb,DogSensor,$ class. We will start by setting the noise to 0 to check that the class does what we think it does"
|
||||
"Okay, so lets look at the output of the `DogSensor` class. We will start by setting the noise to 0 to check that the class does what we think it does"
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -262,7 +396,7 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"The constructor initialized the dog at position 0 with a velocity of 1 (move 1.0 to the right). So we would expect to see an output of 1..10, and indeed that is what we see. If you thought the correct answer should have been 0..9 recall that *sense()* returns the dog's position *after* updating his position, so the first postion is 0.0 + 1, or 1.0.\n",
|
||||
"The constructor initialized the dog at position 0 with a velocity of 1 (move 1.0 to the right). So we would expect to see an output of 1..10, and indeed that is what we see. If you thought the correct answer should have been 0..9 recall that `sense()` returns the dog's position *after* updating his position, so the first postion is 0.0 + 1, or 1.0.\n",
|
||||
"\n",
|
||||
"Now let's inject some noise in the signal."
|
||||
]
|
||||
@ -308,7 +442,7 @@
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"\n",
|
||||
"> **Note**: numpy uses a random number generator to generate the normal distribution samples. The numbers I see as I write this are unlikely to be the ones that you see. If you run the cell above multiple times, you should get a slightly different result each time. I could use $\\verb,numpy.random.seed(some_value),$ to force the results to be the same each time. This would simplify my explanations in some cases, but would ruin the interactive nature of this chapter. To get a real feel for how normal distributions and Kalman filters work you will probably want to run cells several times, observing what changes, and what stays roughly the same.\n",
|
||||
"> **Note**: numpy uses a random number generator to generate the normal distribution samples. The numbers I see as I write this are unlikely to be the ones that you see. If you run the cell above multiple times, you should get a slightly different result each time. I could use `numpy.random.seed(some_value)` to force the results to be the same each time. This would simplify my explanations in some cases, but would ruin the interactive nature of this chapter. To get a real feel for how normal distributions and Kalman filters work you will probably want to run cells several times, observing what changes, and what stays roughly the same.\n",
|
||||
"\n",
|
||||
"So the output of the sensor should be a wavering blue line drawn over a dotted red line. The dotted red line shows the actual position of the dog, and the blue line is the noise signal produced by the simulated RFID sensor. Please note that the red dotted line was manually plotted - we do not yet have a filter that recovers that information! \n",
|
||||
"\n",
|
||||
@ -361,7 +495,7 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"You may not have a full understanding of the exact *meaning* of a noise value of 100.0, but as it turns out if you multiply $\\verb,randn(),$ with a number $n$, the result is just a normal distribution with $\\sigma = \\sqrt{n}$. So the example with noise = 100 is using the normal distribution $\\mathcal{N}(0,100)$. Recall the notation for a normal distribution is $\\mathcal{N}(\\mu,\\sigma^2)$. If the square root is confusing, recall that normal distributions use $\\sigma^2$ for the variance, and $\\sigma$ is the standard deviation, which we do not use in this book. DogSensor.$\\verb,__init__(),$ takes the square root of the noise setting so that the $\\verb,noise * randn(),$ call properly computes the normal distribution."
|
||||
"You may not have a full understanding of the exact *meaning* of a noise value of 100.0, but as it turns out if you multiply `randn()` with a number $n$, the result is just a normal distribution with $\\sigma = \\sqrt{n}$. So the example with noise = 100 is using the normal distribution $\\mathcal{N}(0,100)$. Recall the notation for a normal distribution is $\\mathcal{N}(\\mu,\\sigma^2)$. If the square root is confusing, recall that normal distributions use $\\sigma^2$ for the variance, and $\\sigma$ is the standard deviation, which we do not use in this book. `DogSensor.__init__()` takes the square root of the noise setting so that the `noise * randn()` call properly computes the normal distribution."
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -727,9 +861,9 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"That is less abstract, which perhaps helps with comprehension, but it is poor coding practice. We are writing a Kalman filter that works for any problem, not just tracking dogs in a hallway, so we don't use variable names with 'dog' in them. Still, the $\\verb,sense_dog(),$ function should make what we are doing very clear. \n",
|
||||
"That is less abstract, which perhaps helps with comprehension, but it is poor coding practice. We are writing a Kalman filter that works for any problem, not just tracking dogs in a hallway, so we don't use variable names with 'dog' in them. Still, the `sense_dog()` function should make what we are doing very clear. \n",
|
||||
"\n",
|
||||
"Let's look at an example. We will suppose that our current belief for the dog's position is $N(2,5)$. Don't worry about where that number came from. It may appear that we have a chicken and egg problem, in that how do we know the position before we sense it, but we will resolve that shortly. We will create a $\\verb,DogSensor,$ object initialized to be at position 0.0, and with no velocity, and modest noise. This corresponds to the dog standing still at the far left side of the hallway. Note that we mistakenly believe the dog is at postion 2.0, not 0.0."
|
||||
"Let's look at an example. We will suppose that our current belief for the dog's position is $N(2,5)$. Don't worry about where that number came from. It may appear that we have a chicken and egg problem, in that how do we know the position before we sense it, but we will resolve that shortly. We will create a `DogSensor` object initialized to be at position 0.0, and with no velocity, and modest noise. This corresponds to the dog standing still at the far left side of the hallway. Note that we mistakenly believe the dog is at postion 2.0, not 0.0."
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -781,7 +915,7 @@
|
||||
"source": [
|
||||
"Because of the random numbers I do not know the exact values that you see, but the position should have converged very quickly to almost 0 despite the initial error of believing that the position was 2.0. Furthermore, the variance should have quickly converged from the intial value of 5.0 to 0.238.\n",
|
||||
"\n",
|
||||
"By now the fact that we converged to a position of 0.0 should not be terribly suprising. All we are doing is computing $\\verb,new_pos = old_pos * measurement,$ and the measurement is a normal distribution around 0, so we should get very close to 0 after 20 iterations. But the truly amazing part of this code is how the variance became 0.238 despite every measurement having a variance of 5.0. \n",
|
||||
"By now the fact that we converged to a position of 0.0 should not be terribly suprising. All we are doing is computing `new_pos = old_pos * measurement` and the measurement is a normal distribution around 0, so we should get very close to 0 after 20 iterations. But the truly amazing part of this code is how the variance became 0.238 despite every measurement having a variance of 5.0. \n",
|
||||
"\n",
|
||||
"If we think about the physical interpretation of this is should be clear that this is what should happen. If you sent 20 people into the hall with a tape measure to physically measure the position of the dog you would be very confident in the result after 20 measurements - more confident than after 1 or 2 measurements. So it makes sense that as we make more measurements the variance gets smaller.\n",
|
||||
"\n",
|
||||
@ -817,13 +951,13 @@
|
||||
" \n",
|
||||
"In a nutshell, we shift the probability vector by the amount we believe the animal moved, and adjust the probability. How do we do that with gaussians?\n",
|
||||
"\n",
|
||||
"It turns out that we just add gaussians. Think of the case without gaussians. I think my dog is at 7.3m, and he moves 2.6m to right, where is he now? Obviously, $7.3+2.6=9.9$. He is at 9.9m. Abstractly, the algorithm is $\\verb,new_pos = old_pos + dist_moved,$. It does not matter if we use floating point numbers or gaussians for these values, the algorithm must be the same. \n",
|
||||
"It turns out that we just add gaussians. Think of the case without gaussians. I think my dog is at 7.3m, and he moves 2.6m to right, where is he now? Obviously, $7.3+2.6=9.9$. He is at 9.9m. Abstractly, the algorithm is `new_pos = old_pos + dist_moved`. It does not matter if we use floating point numbers or gaussians for these values, the algorithm must be the same. \n",
|
||||
"\n",
|
||||
"How is addition for gaussians performed? It turns out to be very simple:\n",
|
||||
"$$ N({\\mu}_1, {{\\sigma}_1}^2)+N({\\mu}_2, {{\\sigma}_2}^2) = N({\\mu}_1 + {\\mu}_2, {{\\sigma}_1}^2 + {{\\sigma}_2}^2)$$\n",
|
||||
"\n",
|
||||
"All we do is add the means and the variance separately! Does that make sense? Think of the physical representation of this abstract equation.\n",
|
||||
"${\\mu}_1$ is the old position, and ${\\mu}_2$ is the distance moved. Surely it makes sense that our new position is ${\\mu}_1 + {\\mu}_2$. What about the variance? It is perhaps harder to form an intuition about this. However, recall that with the $\\verb,update(),$ function for the histogram filter we always lost information - our confidence after the update was lower than our confidence before the update. Perhaps this makes sense - we don't really know where the dog is moving, so perhaps the confidence should get smaller (variance gets larger). I assure you that the equation for gaussian addition is correct, and derived by basic algebra. Therefore it is reasonable to expect that if we are using gaussians to model physical events, the results must correctly describe those events.\n",
|
||||
"${\\mu}_1$ is the old position, and ${\\mu}_2$ is the distance moved. Surely it makes sense that our new position is ${\\mu}_1 + {\\mu}_2$. What about the variance? It is perhaps harder to form an intuition about this. However, recall that with the `update()` function for the histogram filter we always lost information - our confidence after the update was lower than our confidence before the update. Perhaps this makes sense - we don't really know where the dog is moving, so perhaps the confidence should get smaller (variance gets larger). I assure you that the equation for gaussian addition is correct, and derived by basic algebra. Therefore it is reasonable to expect that if we are using gaussians to model physical events, the results must correctly describe those events.\n",
|
||||
"\n",
|
||||
"I recognize the amount of hand waving in that argument. Now is a good time to either work through the algebra to convince yourself of the mathematical correctness of the algorithm, or to work through some examples and see that it behaves reasonably. This book will do the latter.\n",
|
||||
"\n",
|
||||
@ -846,7 +980,7 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"What is left? Just calling these functions. The histogram did nothing more than loop over the $\\verb,sense(),$ and $\\verb,update(),$ functions, so let's do the same. "
|
||||
"What is left? Just calling these functions. The histogram did nothing more than loop over the `sense()` and `update()` functions, so let's do the same. "
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -941,7 +1075,7 @@
|
||||
" movement = 1 \n",
|
||||
" movement_error = 2\n",
|
||||
" \n",
|
||||
"For the moment we are assuming that we have some other sensor that detects how the dog is moving. For example, there could be an inertial sensor clipped onto the dog's collar, and it reports how far the dog moved each time it is triggered. The details don't matter. The upshot is that we have a sensor, it has noise, and so we represent it with a Gaussian. Later we will learn what to do if we do not have a sensor for the $\\verb,update(),$ step.\n",
|
||||
"For the moment we are assuming that we have some other sensor that detects how the dog is moving. For example, there could be an inertial sensor clipped onto the dog's collar, and it reports how far the dog moved each time it is triggered. The details don't matter. The upshot is that we have a sensor, it has noise, and so we represent it with a Gaussian. Later we will learn what to do if we do not have a sensor for the `update()` step.\n",
|
||||
"\n",
|
||||
"For now let's walk through the code and output bit by bit.\n",
|
||||
"\n",
|
||||
@ -976,13 +1110,13 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Now we just enter our $\\verb,sense() - >update(),$ loop.\n",
|
||||
"Now we just enter our `sense() ... update()` loop.\n",
|
||||
"\n",
|
||||
" for i in range(10):\n",
|
||||
" pos = update(pos[0], pos[1], movement, sensor_error)\n",
|
||||
" print 'UPDATE:', \"%.4f\" %pos[0], \", %.4f\" %pos[1]\n",
|
||||
"\n",
|
||||
"Wait, why $\\verb,update(),$ before sense? It turns out the order does not matter once, but the first call to $\\verb,DogSensor.sense(),$ assumes that the dog has already moved, so we start with the update step. In practice you will order these calls based on the details of your sensor, and you will very typically do the $\\verb,sense(),$ first.\n",
|
||||
"Wait, why `update()` before sense? It turns out the order does not matter once, but the first call to `,DogSensor.sense()` assumes that the dog has already moved, so we start with the update step. In practice you will order these calls based on the details of your sensor, and you will very typically do the `sense()` first.\n",
|
||||
"\n",
|
||||
"So we call the update function with the gaussian representing our current belief about our position, the another gaussian representing our belief as to where the dog is moving, and then print the output. Your output will differ, but when writing this I get this as output:\n",
|
||||
"\n",
|
||||
@ -1007,7 +1141,7 @@
|
||||
" \n",
|
||||
"as the result. What is happening? Well, at this point the dog is really at 1.0, however the predicted position is 1.6279. What is happening is the RFID sensor has a fair amount of noise, and so we compute the position as 1.6279. That is pretty far off from 1, but this is just are first time through the loop. Intuition tells us that the results will get better as we make more measurements, so let's hope that this is true for our filter as well. Now look at the variance: 9.8047. It has dropped tremendously from 502.0. Why? Well, the RFID has a reasonably small variance of 2.0, so we trust it far more than our previous belief. At this point there is no way to know for sure that the RFID is outputting reliable data, so the variance is not 2.0, but is has gotten much better.\n",
|
||||
"\n",
|
||||
"Now the software just loops, calling $\\verb,update(),$ and $\\verb,sense(),$ in turn. Because of the random sampling I do not know exactly what numbers you are seeing, but the final position is probably between 9 and 11, and the final variance is probably around 3.5. After several runs I did see the final position nearer 7, which would have been the result of several measurements with relatively large errors.\n",
|
||||
"Now the software just loops, calling `update()` and `sense()` in turn. Because of the random sampling I do not know exactly what numbers you are seeing, but the final position is probably between 9 and 11, and the final variance is probably around 3.5. After several runs I did see the final position nearer 7, which would have been the result of several measurements with relatively large errors.\n",
|
||||
"\n",
|
||||
"Now look at the plot. The noisy measurements are plotted in with a dotted red line, and the filter results are in the solid blue line. Both are quite noisy, but notice how much noisier the measurements (red line) are. This is your first Kalman filter shown to work!"
|
||||
]
|
||||
@ -1180,7 +1314,7 @@
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"#####Excercise:\n",
|
||||
"Modify the values of mov$\\verb,ement_error,$ and $\\verb,sensor_error,$ and note the effect on the filter and on the variance. Which has a larger effect on the value that variance converges to. For example, which results in a smaller variance:\n",
|
||||
"Modify the values of `movement_error` and `sensor_error` and note the effect on the filter and on the variance. Which has a larger effect on the value that variance converges to. For example, which results in a smaller variance:\n",
|
||||
"\n",
|
||||
" movement_error = 40\n",
|
||||
" sensor_error = 2\n",
|
||||
@ -1225,7 +1359,8 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"We generate white noise with a given variance using the equation $\\verb,random.randn() * variance,$. The specification gives us the standard deviation of the noise, not the variance, but recall that variance is just the square of the standard deviation. Hence we raise 2.13 to the second power.\n",
|
||||
"We generate white noise with a given variance using the equation `random.randn() * variance`. The specification gives us the standard deviation of the noise, not the variance, but recall that variance is just the square of the standard deviation. Hence we raise 2.13 to the second power.\n",
|
||||
"\n",
|
||||
"> **Sidebar**: spec sheets are just what they sound like - specifications. Any individual sensor will exhibit different performance based on normal manufacturing variations. Numbers given are often maximums - the spec is a guarantee that the performace will be at least that good. So, our sensor might have standard deviation of 1.8. If you buy an expensive piece of equipment it often comes with a sheet of paper displaying the test results of your specific item; this is usually very trustworthy. On the other hand, if this is a cheap sensor it is likely it received little to no testing prior to being sold. Manufacturers typically test a small subset of their output to verify that everything falls within the desired performance range. If you have a critical application you will need to read the specification sheet carefully to figure out exactly what they mean by their ranges. Do they guarantee their number is a maximum, or is it, say, the $3\\sigma$ error rate? Is every item tested? Is the variance normal, or some other distribution. Finally, manufacturing is not perfect. Your part might be defective and not match the performance on the sheet.\n",
|
||||
"\n",
|
||||
"> For example, I just randomly looked up a data sheet for an airflow sensor. There is a field *Repeatability*, with the value $\\pm 0.50\\%$. Is this a Gaussian? Is there a bias? For example, perhaps the repeatibility is nearly 0.0% at low temperatures, and always nearly +0.50 at high temperatures. Data sheets for electrical components often contain a section of \"Typical Performance Characteristics\". These are used to capture information that cannot be easily conveyed in a table. For example, I am looking at a chart showing output voltage vs current for a LM555 timer. There are three curves showing the performance at different temperatures. The response is ideally linear, but all three lines are curved. This clarifies that errors in voltage outputs are probably not Gaussian - in this chip's case higher temperatures leads to lower voltage output, and the voltage output is quite nonlinear if the input current is very high. \n",
|
||||
@ -1237,7 +1372,7 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Now we need to write the Kalman filter processing loop. As with our previous problem, we need to perform a cycle of sensing and updating. The sensing step probably seems clear - call $\\verb,volt(),$ to get the measurement, pass the result into $\\verb,sense(),$ function, but what about the update step? We do not have a sensor to detect 'movement' in the voltage, and for any small duration we expect the voltage to remain constant. How shall we handle this?\n",
|
||||
"Now we need to write the Kalman filter processing loop. As with our previous problem, we need to perform a cycle of sensing and updating. The sensing step probably seems clear - call `volt()` to get the measurement, pass the result into `sense()` function, but what about the update step? We do not have a sensor to detect 'movement' in the voltage, and for any small duration we expect the voltage to remain constant. How shall we handle this?\n",
|
||||
"\n",
|
||||
"As always, we will trust in the math. We have no movement, and no error associated with them, so we will just set both to zero. Let's see what happens. "
|
||||
]
|
||||
@ -1311,7 +1446,7 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"The first plot shows the individual sensor measurements marked with '+'s vs the filter output. Despite a lot of noise in the sensor we quickly discover the approximate voltage of the sensor. In the run I just completed at the time of authorship, the last voltage output from the filter is $16.213$, which is quite close to the $16.4$ used by the $\\verb,volt(),$ function. On other runs I have gotten up to around $16.9$ as an output and also as low as 15.5 or so.\n",
|
||||
"The first plot shows the individual sensor measurements marked with '+'s vs the filter output. Despite a lot of noise in the sensor we quickly discover the approximate voltage of the sensor. In the run I just completed at the time of authorship, the last voltage output from the filter is $16.213$, which is quite close to the $16.4$ used by the `volt()` function. On other runs I have gotten up to around $16.9$ as an output and also as low as 15.5 or so.\n",
|
||||
"\n",
|
||||
"The second plot shows how the variance converges over time. Compare this plot to the variance plot for the dog sensor. While this does converge to a very small value, it is much slower than the dog problem. The next section **Explaining the Results - Multi-Sensor Fusion** explains why this happens.\n",
|
||||
"\n",
|
||||
@ -1729,7 +1864,7 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Implement the Kalman filter using IPython Notebook's animation features to allow you to modify the various constants in real time using sliders. Refer to the section **Interactive Gaussians** in the Gaussian chapter to see how to do this. You will use the $\\verb,interact(),$ function to call a calculation and plotting function. Each parameter passed into $\\verb,interact(),$ automatically gets a slider created for it. I have built the boilerplate for this; just fill in the required code."
|
||||
"Implement the Kalman filter using IPython Notebook's animation features to allow you to modify the various constants in real time using sliders. Refer to the section **Interactive Gaussians** in the Gaussian chapter to see how to do this. You will use the `interact()` function to call a calculation and plotting function. Each parameter passed into `interact()` automatically gets a slider created for it. I have built the boilerplate for this; just fill in the required code."
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -1839,8 +1974,8 @@
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Our equations are linear: \n",
|
||||
"$$\\begin{aligned}new\\_pos&=old\\_pos+dist\\_moved\\\\\n",
|
||||
"new\\_position&=old\\_position*measurement\\end{aligned}$$\n",
|
||||
"$$\\begin{aligned}new\\_pos &= old\\_pos+dist\\_moved\\\\\n",
|
||||
"new\\_position &= old\\_position*measurement\\end{aligned}$$\n",
|
||||
"\n",
|
||||
"Do you suppose that this filter works well or poorly with nonlinear systems?\n",
|
||||
"\n",
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"metadata": {
|
||||
"name": "",
|
||||
"signature": "sha256:fdd9588156d15653acb028f0f53de8dea2e5576bfa2c820eb3ee2128eda73c13"
|
||||
"signature": "sha256:cacd3ef5d9830b08d539ac3933475779ace5170a2903b1fce9e7afb6e87e4362"
|
||||
},
|
||||
"nbformat": 3,
|
||||
"nbformat_minor": 0,
|
||||
@ -31,95 +31,230 @@
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"output_type": "stream",
|
||||
"stream": "stdout",
|
||||
"text": [
|
||||
"Installed secnum.py. To use it, type:\n",
|
||||
" %load_ext secnum\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"javascript": [
|
||||
"console.log(\"Section numbering...\");\n",
|
||||
"html": [
|
||||
"<style>\n",
|
||||
"@import url('http://fonts.googleapis.com/css?family=Source+Code+Pro');\n",
|
||||
"\n",
|
||||
"function number_sections(threshold) {\n",
|
||||
"\n",
|
||||
" var h1_number = 0;\n",
|
||||
" var h2_number = 0;\n",
|
||||
"\n",
|
||||
" if (threshold === undefined) {\n",
|
||||
" threshold = 2; // does nothing so far\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" var cells = IPython.notebook.get_cells();\n",
|
||||
" \n",
|
||||
" for (var i=0; i < cells.length; i++) {\n",
|
||||
"\n",
|
||||
" var cell = cells[i];\n",
|
||||
" if (cell.cell_type !== 'heading') continue;\n",
|
||||
" \n",
|
||||
" var level = cell.level;\n",
|
||||
" if (level > threshold) continue;\n",
|
||||
" \n",
|
||||
" if (level === 1) {\n",
|
||||
" \n",
|
||||
" h1_number ++;\n",
|
||||
" var h1_element = cell.element.find('h1');\n",
|
||||
" var h1_html = h1_element.html();\n",
|
||||
" \n",
|
||||
" console.log(\"h1_html: \" + h1_html);\n",
|
||||
"\n",
|
||||
" var patt = /^[0-9]+\\.\\s(.*)/; // section number at start of string\n",
|
||||
" var title = h1_html.match(patt); // just the title\n",
|
||||
"\n",
|
||||
" if (title != null) { \n",
|
||||
" h1_element.html(h1_number + \". \" + title[1]);\n",
|
||||
" }\n",
|
||||
" else {\n",
|
||||
" h1_element.html(h1_number + \". \" + h1_html);\n",
|
||||
" }\n",
|
||||
" \n",
|
||||
" h2_number = 0;\n",
|
||||
" \n",
|
||||
" div.cell{\n",
|
||||
" width: 850px;\n",
|
||||
" margin-left: 0% !important;\n",
|
||||
" margin-right: auto;\n",
|
||||
" }\n",
|
||||
" \n",
|
||||
" if (level === 2) {\n",
|
||||
" \n",
|
||||
" h2_number ++;\n",
|
||||
" \n",
|
||||
" var h2_element = cell.element.find('h2');\n",
|
||||
" var h2_html = h2_element.html();\n",
|
||||
"\n",
|
||||
" console.log(\"h2_html: \" + h2_html);\n",
|
||||
"\n",
|
||||
" \n",
|
||||
" var patt = /^[0-9]+\\.[0-9]+\\.\\s/;\n",
|
||||
" var result = h2_html.match(patt);\n",
|
||||
"\n",
|
||||
" if (result != null) {\n",
|
||||
" h2_html = h2_html.replace(result, \"\");\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" h2_element.html(h1_number + \".\" + h2_number + \". \" + h2_html);\n",
|
||||
" \n",
|
||||
" div.text_cell code {\n",
|
||||
" background: transparent;\n",
|
||||
" color: #000000;\n",
|
||||
" font-weight: 600;\n",
|
||||
" font-size: 13pt;\n",
|
||||
" font-style: bold;\n",
|
||||
" font-family: 'Source Code Pro', Consolas, monocco, monospace;\n",
|
||||
" }\n",
|
||||
" h1 {\n",
|
||||
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
|
||||
"\t}\n",
|
||||
"\t\n",
|
||||
" div.input_area {\n",
|
||||
" background: #F6F6F9;\n",
|
||||
" border: 1px solid #586e75;\n",
|
||||
" }\n",
|
||||
" \n",
|
||||
" }\n",
|
||||
" \n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"number_sections();\n",
|
||||
"\n",
|
||||
"// $([IPython.evnts]).on('create.Cell', number_sections);\n",
|
||||
"\n",
|
||||
"$([IPython.events]).on('selected_cell_type_changed.Notebook', number_sections);\n",
|
||||
"\n"
|
||||
" .text_cell_render h1 {\n",
|
||||
" font-weight: 200;\n",
|
||||
" font-size: 30pt;\n",
|
||||
" line-height: 100%;\n",
|
||||
" color:#c76c0c;\n",
|
||||
" margin-bottom: 0.5em;\n",
|
||||
" margin-top: 1em;\n",
|
||||
" display: block;\n",
|
||||
" white-space: wrap;\n",
|
||||
" } \n",
|
||||
" h2 {\n",
|
||||
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
|
||||
" }\n",
|
||||
" .text_cell_render h2 {\n",
|
||||
" font-weight: 200;\n",
|
||||
" font-size: 20pt;\n",
|
||||
" font-style: italic;\n",
|
||||
" line-height: 100%;\n",
|
||||
" color:#c76c0c;\n",
|
||||
" margin-bottom: 0.5em;\n",
|
||||
" margin-top: 1.5em;\n",
|
||||
" display: block;\n",
|
||||
" white-space: nowrap;\n",
|
||||
" } \n",
|
||||
" h3 {\n",
|
||||
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
|
||||
" }\n",
|
||||
" .text_cell_render h3 {\n",
|
||||
" font-weight: 300;\n",
|
||||
" font-size: 18pt;\n",
|
||||
" line-height: 100%;\n",
|
||||
" color:#d77c0c;\n",
|
||||
" margin-bottom: 0.5em;\n",
|
||||
" margin-top: 2em;\n",
|
||||
" display: block;\n",
|
||||
" white-space: nowrap;\n",
|
||||
" }\n",
|
||||
" h4 {\n",
|
||||
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
|
||||
" }\n",
|
||||
" .text_cell_render h4 {\n",
|
||||
" font-weight: 300;\n",
|
||||
" font-size: 16pt;\n",
|
||||
" color:#d77c0c;\n",
|
||||
" margin-bottom: 0.5em;\n",
|
||||
" margin-top: 0.5em;\n",
|
||||
" display: block;\n",
|
||||
" white-space: nowrap;\n",
|
||||
" }\n",
|
||||
" h5 {\n",
|
||||
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
|
||||
" }\n",
|
||||
" .text_cell_render h5 {\n",
|
||||
" font-weight: 300;\n",
|
||||
" font-style: normal;\n",
|
||||
" color: #1d3b84;\n",
|
||||
" font-size: 16pt;\n",
|
||||
" margin-bottom: 0em;\n",
|
||||
" margin-top: 1.5em;\n",
|
||||
" display: block;\n",
|
||||
" white-space: nowrap;\n",
|
||||
" }\n",
|
||||
" div.text_cell_render{\n",
|
||||
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
|
||||
" line-height: 135%;\n",
|
||||
" font-size: 110%;\n",
|
||||
" width:750px;\n",
|
||||
" margin-left:auto;\n",
|
||||
" margin-right:auto;\n",
|
||||
" text-align:justify;\n",
|
||||
" text-justify:inter-word;\n",
|
||||
" }\n",
|
||||
" div.output_subarea.output_text.output_pyout {\n",
|
||||
" overflow-x: auto;\n",
|
||||
" overflow-y: scroll;\n",
|
||||
" max-height: 300px;\n",
|
||||
" }\n",
|
||||
" div.output_subarea.output_stream.output_stdout.output_text {\n",
|
||||
" overflow-x: auto;\n",
|
||||
" overflow-y: scroll;\n",
|
||||
" max-height: 300px;\n",
|
||||
" }\n",
|
||||
" code{\n",
|
||||
" font-size: 70%;\n",
|
||||
" }\n",
|
||||
" .rendered_html code{\n",
|
||||
" background-color: transparent;\n",
|
||||
" }\n",
|
||||
" ul{\n",
|
||||
" margin: 2em;\n",
|
||||
" }\n",
|
||||
" ul li{\n",
|
||||
" padding-left: 0.5em; \n",
|
||||
" margin-bottom: 0.5em; \n",
|
||||
" margin-top: 0.5em; \n",
|
||||
" }\n",
|
||||
" ul li li{\n",
|
||||
" padding-left: 0.2em; \n",
|
||||
" margin-bottom: 0.2em; \n",
|
||||
" margin-top: 0.2em; \n",
|
||||
" }\n",
|
||||
" ol{\n",
|
||||
" margin: 2em;\n",
|
||||
" }\n",
|
||||
" ol li{\n",
|
||||
" padding-left: 0.5em; \n",
|
||||
" margin-bottom: 0.5em; \n",
|
||||
" margin-top: 0.5em; \n",
|
||||
" }\n",
|
||||
" ul li{\n",
|
||||
" padding-left: 0.5em; \n",
|
||||
" margin-bottom: 0.5em; \n",
|
||||
" margin-top: 0.2em; \n",
|
||||
" }\n",
|
||||
" a:link{\n",
|
||||
" font-weight: bold;\n",
|
||||
" color:#447adb;\n",
|
||||
" }\n",
|
||||
" a:visited{\n",
|
||||
" font-weight: bold;\n",
|
||||
" color: #1d3b84;\n",
|
||||
" }\n",
|
||||
" a:hover{\n",
|
||||
" font-weight: bold;\n",
|
||||
" color: #1d3b84;\n",
|
||||
" }\n",
|
||||
" a:focus{\n",
|
||||
" font-weight: bold;\n",
|
||||
" color:#447adb;\n",
|
||||
" }\n",
|
||||
" a:active{\n",
|
||||
" font-weight: bold;\n",
|
||||
" color:#447adb;\n",
|
||||
" }\n",
|
||||
" .rendered_html :link {\n",
|
||||
" text-decoration: underline; \n",
|
||||
" }\n",
|
||||
" .rendered_html :hover {\n",
|
||||
" text-decoration: none; \n",
|
||||
" }\n",
|
||||
" .rendered_html :visited {\n",
|
||||
" text-decoration: none;\n",
|
||||
" }\n",
|
||||
" .rendered_html :focus {\n",
|
||||
" text-decoration: none;\n",
|
||||
" }\n",
|
||||
" .rendered_html :active {\n",
|
||||
" text-decoration: none;\n",
|
||||
" }\n",
|
||||
" .warning{\n",
|
||||
" color: rgb( 240, 20, 20 )\n",
|
||||
" } \n",
|
||||
" hr {\n",
|
||||
" color: #f3f3f3;\n",
|
||||
" background-color: #f3f3f3;\n",
|
||||
" height: 1px;\n",
|
||||
" }\n",
|
||||
" blockquote{\n",
|
||||
" display:block;\n",
|
||||
" background: #fcfcfc;\n",
|
||||
" border-left: 5px solid #c76c0c;\n",
|
||||
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
|
||||
" width:680px;\n",
|
||||
" padding: 10px 10px 10px 10px;\n",
|
||||
" text-align:justify;\n",
|
||||
" text-justify:inter-word;\n",
|
||||
" }\n",
|
||||
" blockquote p {\n",
|
||||
" margin-bottom: 0;\n",
|
||||
" line-height: 125%;\n",
|
||||
" font-size: 100%;\n",
|
||||
" }\n",
|
||||
"</style>\n",
|
||||
"<script>\n",
|
||||
" MathJax.Hub.Config({\n",
|
||||
" TeX: {\n",
|
||||
" extensions: [\"AMSmath.js\"]\n",
|
||||
" },\n",
|
||||
" tex2jax: {\n",
|
||||
" inlineMath: [ ['$','$'], [\"\\\\(\",\"\\\\)\"] ],\n",
|
||||
" displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"] ]\n",
|
||||
" },\n",
|
||||
" displayAlign: 'center', // Change this to 'center' to center equations.\n",
|
||||
" \"HTML-CSS\": {\n",
|
||||
" styles: {'.MathJax_Display': {\"margin\": 4}}\n",
|
||||
" }\n",
|
||||
" });\n",
|
||||
"</script>\n"
|
||||
],
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
"output_type": "pyout",
|
||||
"prompt_number": 5,
|
||||
"text": [
|
||||
"<IPython.core.display.HTML at 0x20207d0>"
|
||||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 1
|
||||
"prompt_number": 5
|
||||
},
|
||||
{
|
||||
"cell_type": "heading",
|
||||
@ -201,16 +336,16 @@
|
||||
"\n",
|
||||
"If you are reasonably well-versed in linear algebra this equation should look quite managable; if not, don't worry! If you want to learn the math we will cover it in detail in the next optional chapter. If you choose to skip that chapter the rest of this book should still be managable for you\n",
|
||||
"\n",
|
||||
"I have programmed it and saved it in the file *stats.py* with the function name *multivariate_gaussian*. I am not showing the code here because I have taken advantage of the linear algebra solving apparatus of numpy to efficiently compute a solution - the code does not correspond to the equation in a one to one manner. If you wish to view the code, I urge you to either load it in an editor, or load it into this worksheet by putting $\\verb,%load -s multivariate_gaussian stats.py,$ in the next cell and executing it with ctrl-enter. "
|
||||
"I have programmed it and saved it in the file `stats.py` with the function name `multivariate_gaussian`. I am not showing the code here because I have taken advantage of the linear algebra solving apparatus of numpy to efficiently compute a solution - the code does not correspond to the equation in a one to one manner. If you wish to view the code, I urge you to either load it in an editor, or load it into this worksheet by putting `%load -s multivariate_gaussian stats.py` in the next cell and executing it with ctrl-enter. "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
">As of version 0.14 scipy.stats has implemented the multivariate normal equation with the function $\\verb,multivariate_normal(),$. It is superior to my function in several ways. First, it is implemented in Fortran, and is therefore faster than mine. Second, it implements a 'frozen' form where you set the mean and covariance once, and then calculate the probability for any number of values for x over any arbitrary number of calls. This is much more efficient then recomputing everything in each call. So, if you have version 0.14 or later you may want to substitute my function for the built in version. Use $\\verb,scipy.version.version,$ to get the version number. I deliberately named my function $\\verb,multivariate_gaussian(),$ to ensure it is never confused with the built in version.\n",
|
||||
">As of version 0.14 scipy.stats has implemented the multivariate normal equation with the function `multivariate_normal()`. It is superior to my function in several ways. First, it is implemented in Fortran, and is therefore faster than mine. Second, it implements a 'frozen' form where you set the mean and covariance once, and then calculate the probability for any number of values for x over any arbitrary number of calls. This is much more efficient then recomputing everything in each call. So, if you have version 0.14 or later you may want to substitute my function for the built in version. Use `scipy.version.version` to get the version number. I deliberately named my function `multivariate_gaussian()` to ensure it is never confused with the built in version.\n",
|
||||
"\n",
|
||||
"> If you intend to use Python for Kalman filters, you will want to read the <a href=\"http://docs.scipy.org/doc/scipy/reference/tutorial/stats.html\">tutorial</a> for the $\\verb,scipy.stats,$ module, which explains 'freezing' distributions and other very useful features. As of this date, it includes an example of using the multivariate_normal function, which does work a bit differently from my function."
|
||||
"> If you intend to use Python for Kalman filters, you will want to read the <a href=\"http://docs.scipy.org/doc/scipy/reference/tutorial/stats.html\">tutorial</a>[1] for the `scipy.stats` module, which explains 'freezing' distributions and other very useful features. As of this date, it includes an example of using the multivariate_normal function, which does work a bit differently from my function."
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -405,7 +540,7 @@
|
||||
"source": [
|
||||
"The result is clearly a 3D bell shaped curve. We can see that the gaussian is centered around (2,7), and that the probability quickly drops away in all directions. On the sides of the plot I have drawn the Gaussians for $x$ in greens and for $y$ in orange.\n",
|
||||
"\n",
|
||||
"As beautiful as this is, it is perhaps a bit hard to get useful information. For example, it is not easy to tell if $x$ and $y$ both have the same variance or not. So for most of the rest of this book we will display multidimensional Gaussian using contour plots. I will use some helper functions in $\\verb,gaussian.py,$ to plot them. If you are interested in linear algebra go ahead and look at the code used to produce these contours, otherwise feel free to ignore it."
|
||||
"As beautiful as this is, it is perhaps a bit hard to get useful information. For example, it is not easy to tell if $x$ and $y$ both have the same variance or not. So for most of the rest of this book we will display multidimensional Gaussian using contour plots. I will use some helper functions in `gaussian.py` to plot them. If you are interested in linear algebra go ahead and look at the code used to produce these contours, otherwise feel free to ignore it."
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -841,7 +976,7 @@
|
||||
"\\end{aligned}\n",
|
||||
"$$\n",
|
||||
"\n",
|
||||
"Now we have to account for the second row. I've let it somewhat unstated up to now, but we are assuming constant velocity for this problem. Naturally this assumption is not true; if our dog moves it must accelerate and deaccelerate. If you cast your mind back to the $g-h Filter$ chapter we explored the effect of assuming constant velocity. So long as the acceleration is small compared to $\\Delta t$ the filter will still perform well. \n",
|
||||
"Now we have to account for the second row. I've let it somewhat unstated up to now, but we are assuming constant velocity for this problem. Naturally this assumption is not true; if our dog moves it must accelerate and deaccelerate. If you cast your mind back to the *g-h Filter* chapter we explored the effect of assuming constant velocity. So long as the acceleration is small compared to $\\Delta t$ the filter will still perform well. \n",
|
||||
"\n",
|
||||
"Therefore we will assume that\n",
|
||||
"\n",
|
||||
@ -966,7 +1101,7 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"As promised, the Kalman filter equations are already programmed for you. In many circumstances you will never have to write your own Kalman filter equations. We will look at the code later, but for now we will just import the code and use it. I have placed it in *KalmanFilter.py*, so let's start by importing it and creating a filter."
|
||||
"As promised, the Kalman filter equations are already programmed for you. In many circumstances you will never have to write your own Kalman filter equations. We will look at the code later, but for now we will just import the code and use it. I have placed it in `KalmanFilter.py`, so let's start by importing it and creating a filter."
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -1038,7 +1173,7 @@
|
||||
"> Summary: For our dog tracking problem, in the 1-D case $\\mu$ was the position, and $\\sigma^2$ was the variance. In the 2-D case $\\mathbf{x}$ is our position and velocity, and $\\mathbf{P}$ is the *covariance* of the position and velocity. It is the same thing, just in higher dimensions!\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"All that is left is to run the code! The $\\tt DogSensor$ class from the previous chapter has been placed in $\\verb,DogSensor.py,$."
|
||||
"All that is left is to run the code! The `DogSensor` class from the previous chapter has been placed in `DogSensor.py`."
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -1103,9 +1238,9 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"This is the complete code for the filter, and most of it is just boilerplate. The first function $\\verb,dog_tracking_filter(),$ is a helper function that creates a $\\verb,KalmanFilter,$ object with specified $\\mathbf{R}$, $\\mathbf{Q}$ and $\\mathbf{P}$ matrices. We've shown this code already, so I will not discuss it more here. \n",
|
||||
"This is the complete code for the filter, and most of it is just boilerplate. The first function `dog_tracking_filter()` is a helper function that creates a `KalmanFilter` object with specified $\\mathbf{R}$, $\\mathbf{Q}$ and $\\mathbf{P}$ matrices. We've shown this code already, so I will not discuss it more here. \n",
|
||||
"\n",
|
||||
"The function $\\verb,filter_dog(),$ implements the filter itself. Lets work through it line by line. The first line creates the simulation of the DogSensor, as we have seen in the previous chapter.\n",
|
||||
"The function `filter_dog()` implements the filter itself. Lets work through it line by line. The first line creates the simulation of the DogSensor, as we have seen in the previous chapter.\n",
|
||||
"\n",
|
||||
" dog = DogSensor(velocity=1, noise=noise)\n",
|
||||
"\n",
|
||||
@ -1119,7 +1254,7 @@
|
||||
" zs = [None] * count\n",
|
||||
" cov = [None] * count\n",
|
||||
" \n",
|
||||
"Finally we get to the filter. All we need to do is perform the update and predict steps of the Kalman filter for each measurement. The $\\verb,KalmanFilter,$ class provides the two functions $\\verb,update(),$ and $\\verb,predict(),$ for this purpose. $\\verb,update(),$ performs the measurement update step of the Kalman filter, and so it takes a variable containing the sensor measurement. \n",
|
||||
"Finally we get to the filter. All we need to do is perform the update and predict steps of the Kalman filter for each measurement. The `KalmanFilter` class provides the two functions `update()` and `predict()` for this purpose. `update()` performs the measurement update step of the Kalman filter, and so it takes a variable containing the sensor measurement. \n",
|
||||
"\n",
|
||||
"Absent the bookkeeping work of storing the filter's data, the for loop reads:\n",
|
||||
"\n",
|
||||
@ -1128,9 +1263,9 @@
|
||||
" dog_filter.update (z)\n",
|
||||
" dog_filter.predict()\n",
|
||||
" \n",
|
||||
"It really cannot get much simpler than that. As we tackle more complicated problems this code will remain largely the same; all of the work goes into setting up the $\\verb,KalmanFilter,$ variables; executing the filter is trivial.\n",
|
||||
"It really cannot get much simpler than that. As we tackle more complicated problems this code will remain largely the same; all of the work goes into setting up the `KalmanFilter` variables; executing the filter is trivial.\n",
|
||||
"\n",
|
||||
"Now let's look at the result. Here is some code that calls $\\verb,filter_track(),$ and then plots the result. It is fairly uninteresting code, so I will not walk through it."
|
||||
"Now let's look at the result. Here is some code that calls `filter_track()` and then plots the result. It is fairly uninteresting code, so I will not walk through it."
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -1718,6 +1853,21 @@
|
||||
"\n",
|
||||
"> **sidebar**: when plotting covariance ellipses, make sure to always use *plt.axis('equal')* in your code. If the axis use different scales the ellipses will be drawn distorted. For example, the ellipse may be drawn as being taller than it is wide, but it may actually be wider than tall."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "heading",
|
||||
"level": 2,
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"References"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"[1] http://docs.scipy.org/doc/scipy/reference/tutorial/stats.htmly"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {}
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"metadata": {
|
||||
"name": "",
|
||||
"signature": "sha256:5a550f9fc280bc70f84269889df27a4796e358296fd0bd82d4b2b6e09eea2c89"
|
||||
"signature": "sha256:508bfe56a37ac55e285aada1ed5172acfa5e46822f874f77b092acceb435750c"
|
||||
},
|
||||
"nbformat": 3,
|
||||
"nbformat_minor": 0,
|
||||
@ -31,92 +31,227 @@
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"output_type": "stream",
|
||||
"stream": "stdout",
|
||||
"text": [
|
||||
"Installed secnum.py. To use it, type:\n",
|
||||
" %load_ext secnum\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"javascript": [
|
||||
"console.log(\"Section numbering...\");\n",
|
||||
"html": [
|
||||
"<style>\n",
|
||||
"@import url('http://fonts.googleapis.com/css?family=Source+Code+Pro');\n",
|
||||
"\n",
|
||||
"function number_sections(threshold) {\n",
|
||||
"\n",
|
||||
" var h1_number = 0;\n",
|
||||
" var h2_number = 0;\n",
|
||||
"\n",
|
||||
" if (threshold === undefined) {\n",
|
||||
" threshold = 2; // does nothing so far\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" var cells = IPython.notebook.get_cells();\n",
|
||||
" \n",
|
||||
" for (var i=0; i < cells.length; i++) {\n",
|
||||
"\n",
|
||||
" var cell = cells[i];\n",
|
||||
" if (cell.cell_type !== 'heading') continue;\n",
|
||||
" \n",
|
||||
" var level = cell.level;\n",
|
||||
" if (level > threshold) continue;\n",
|
||||
" \n",
|
||||
" if (level === 1) {\n",
|
||||
" \n",
|
||||
" h1_number ++;\n",
|
||||
" var h1_element = cell.element.find('h1');\n",
|
||||
" var h1_html = h1_element.html();\n",
|
||||
" \n",
|
||||
" console.log(\"h1_html: \" + h1_html);\n",
|
||||
"\n",
|
||||
" var patt = /^[0-9]+\\.\\s(.*)/; // section number at start of string\n",
|
||||
" var title = h1_html.match(patt); // just the title\n",
|
||||
"\n",
|
||||
" if (title != null) { \n",
|
||||
" h1_element.html(h1_number + \". \" + title[1]);\n",
|
||||
" }\n",
|
||||
" else {\n",
|
||||
" h1_element.html(h1_number + \". \" + h1_html);\n",
|
||||
" }\n",
|
||||
" \n",
|
||||
" h2_number = 0;\n",
|
||||
" \n",
|
||||
" div.cell{\n",
|
||||
" width: 850px;\n",
|
||||
" margin-left: 0% !important;\n",
|
||||
" margin-right: auto;\n",
|
||||
" }\n",
|
||||
" \n",
|
||||
" if (level === 2) {\n",
|
||||
" \n",
|
||||
" h2_number ++;\n",
|
||||
" \n",
|
||||
" var h2_element = cell.element.find('h2');\n",
|
||||
" var h2_html = h2_element.html();\n",
|
||||
"\n",
|
||||
" console.log(\"h2_html: \" + h2_html);\n",
|
||||
"\n",
|
||||
" \n",
|
||||
" var patt = /^[0-9]+\\.[0-9]+\\.\\s/;\n",
|
||||
" var result = h2_html.match(patt);\n",
|
||||
"\n",
|
||||
" if (result != null) {\n",
|
||||
" h2_html = h2_html.replace(result, \"\");\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" h2_element.html(h1_number + \".\" + h2_number + \". \" + h2_html);\n",
|
||||
" \n",
|
||||
" div.text_cell code {\n",
|
||||
" background: transparent;\n",
|
||||
" color: #000000;\n",
|
||||
" font-weight: 600;\n",
|
||||
" font-size: 13pt;\n",
|
||||
" font-style: bold;\n",
|
||||
" font-family: 'Source Code Pro', Consolas, monocco, monospace;\n",
|
||||
" }\n",
|
||||
" h1 {\n",
|
||||
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
|
||||
"\t}\n",
|
||||
"\t\n",
|
||||
" div.input_area {\n",
|
||||
" background: #F6F6F9;\n",
|
||||
" border: 1px solid #586e75;\n",
|
||||
" }\n",
|
||||
" \n",
|
||||
" }\n",
|
||||
" \n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"number_sections();\n",
|
||||
"\n",
|
||||
"// $([IPython.evnts]).on('create.Cell', number_sections);\n",
|
||||
"\n",
|
||||
"$([IPython.events]).on('selected_cell_type_changed.Notebook', number_sections);\n",
|
||||
"\n"
|
||||
" .text_cell_render h1 {\n",
|
||||
" font-weight: 200;\n",
|
||||
" font-size: 30pt;\n",
|
||||
" line-height: 100%;\n",
|
||||
" color:#c76c0c;\n",
|
||||
" margin-bottom: 0.5em;\n",
|
||||
" margin-top: 1em;\n",
|
||||
" display: block;\n",
|
||||
" white-space: wrap;\n",
|
||||
" } \n",
|
||||
" h2 {\n",
|
||||
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
|
||||
" }\n",
|
||||
" .text_cell_render h2 {\n",
|
||||
" font-weight: 200;\n",
|
||||
" font-size: 20pt;\n",
|
||||
" font-style: italic;\n",
|
||||
" line-height: 100%;\n",
|
||||
" color:#c76c0c;\n",
|
||||
" margin-bottom: 0.5em;\n",
|
||||
" margin-top: 1.5em;\n",
|
||||
" display: block;\n",
|
||||
" white-space: nowrap;\n",
|
||||
" } \n",
|
||||
" h3 {\n",
|
||||
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
|
||||
" }\n",
|
||||
" .text_cell_render h3 {\n",
|
||||
" font-weight: 300;\n",
|
||||
" font-size: 18pt;\n",
|
||||
" line-height: 100%;\n",
|
||||
" color:#d77c0c;\n",
|
||||
" margin-bottom: 0.5em;\n",
|
||||
" margin-top: 2em;\n",
|
||||
" display: block;\n",
|
||||
" white-space: nowrap;\n",
|
||||
" }\n",
|
||||
" h4 {\n",
|
||||
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
|
||||
" }\n",
|
||||
" .text_cell_render h4 {\n",
|
||||
" font-weight: 300;\n",
|
||||
" font-size: 16pt;\n",
|
||||
" color:#d77c0c;\n",
|
||||
" margin-bottom: 0.5em;\n",
|
||||
" margin-top: 0.5em;\n",
|
||||
" display: block;\n",
|
||||
" white-space: nowrap;\n",
|
||||
" }\n",
|
||||
" h5 {\n",
|
||||
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
|
||||
" }\n",
|
||||
" .text_cell_render h5 {\n",
|
||||
" font-weight: 300;\n",
|
||||
" font-style: normal;\n",
|
||||
" color: #1d3b84;\n",
|
||||
" font-size: 16pt;\n",
|
||||
" margin-bottom: 0em;\n",
|
||||
" margin-top: 1.5em;\n",
|
||||
" display: block;\n",
|
||||
" white-space: nowrap;\n",
|
||||
" }\n",
|
||||
" div.text_cell_render{\n",
|
||||
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
|
||||
" line-height: 135%;\n",
|
||||
" font-size: 110%;\n",
|
||||
" width:750px;\n",
|
||||
" margin-left:auto;\n",
|
||||
" margin-right:auto;\n",
|
||||
" text-align:justify;\n",
|
||||
" text-justify:inter-word;\n",
|
||||
" }\n",
|
||||
" div.output_subarea.output_text.output_pyout {\n",
|
||||
" overflow-x: auto;\n",
|
||||
" overflow-y: scroll;\n",
|
||||
" max-height: 300px;\n",
|
||||
" }\n",
|
||||
" div.output_subarea.output_stream.output_stdout.output_text {\n",
|
||||
" overflow-x: auto;\n",
|
||||
" overflow-y: scroll;\n",
|
||||
" max-height: 300px;\n",
|
||||
" }\n",
|
||||
" code{\n",
|
||||
" font-size: 70%;\n",
|
||||
" }\n",
|
||||
" .rendered_html code{\n",
|
||||
" background-color: transparent;\n",
|
||||
" }\n",
|
||||
" ul{\n",
|
||||
" margin: 2em;\n",
|
||||
" }\n",
|
||||
" ul li{\n",
|
||||
" padding-left: 0.5em; \n",
|
||||
" margin-bottom: 0.5em; \n",
|
||||
" margin-top: 0.5em; \n",
|
||||
" }\n",
|
||||
" ul li li{\n",
|
||||
" padding-left: 0.2em; \n",
|
||||
" margin-bottom: 0.2em; \n",
|
||||
" margin-top: 0.2em; \n",
|
||||
" }\n",
|
||||
" ol{\n",
|
||||
" margin: 2em;\n",
|
||||
" }\n",
|
||||
" ol li{\n",
|
||||
" padding-left: 0.5em; \n",
|
||||
" margin-bottom: 0.5em; \n",
|
||||
" margin-top: 0.5em; \n",
|
||||
" }\n",
|
||||
" ul li{\n",
|
||||
" padding-left: 0.5em; \n",
|
||||
" margin-bottom: 0.5em; \n",
|
||||
" margin-top: 0.2em; \n",
|
||||
" }\n",
|
||||
" a:link{\n",
|
||||
" font-weight: bold;\n",
|
||||
" color:#447adb;\n",
|
||||
" }\n",
|
||||
" a:visited{\n",
|
||||
" font-weight: bold;\n",
|
||||
" color: #1d3b84;\n",
|
||||
" }\n",
|
||||
" a:hover{\n",
|
||||
" font-weight: bold;\n",
|
||||
" color: #1d3b84;\n",
|
||||
" }\n",
|
||||
" a:focus{\n",
|
||||
" font-weight: bold;\n",
|
||||
" color:#447adb;\n",
|
||||
" }\n",
|
||||
" a:active{\n",
|
||||
" font-weight: bold;\n",
|
||||
" color:#447adb;\n",
|
||||
" }\n",
|
||||
" .rendered_html :link {\n",
|
||||
" text-decoration: underline; \n",
|
||||
" }\n",
|
||||
" .rendered_html :hover {\n",
|
||||
" text-decoration: none; \n",
|
||||
" }\n",
|
||||
" .rendered_html :visited {\n",
|
||||
" text-decoration: none;\n",
|
||||
" }\n",
|
||||
" .rendered_html :focus {\n",
|
||||
" text-decoration: none;\n",
|
||||
" }\n",
|
||||
" .rendered_html :active {\n",
|
||||
" text-decoration: none;\n",
|
||||
" }\n",
|
||||
" .warning{\n",
|
||||
" color: rgb( 240, 20, 20 )\n",
|
||||
" } \n",
|
||||
" hr {\n",
|
||||
" color: #f3f3f3;\n",
|
||||
" background-color: #f3f3f3;\n",
|
||||
" height: 1px;\n",
|
||||
" }\n",
|
||||
" blockquote{\n",
|
||||
" display:block;\n",
|
||||
" background: #fcfcfc;\n",
|
||||
" border-left: 5px solid #c76c0c;\n",
|
||||
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
|
||||
" width:680px;\n",
|
||||
" padding: 10px 10px 10px 10px;\n",
|
||||
" text-align:justify;\n",
|
||||
" text-justify:inter-word;\n",
|
||||
" }\n",
|
||||
" blockquote p {\n",
|
||||
" margin-bottom: 0;\n",
|
||||
" line-height: 125%;\n",
|
||||
" font-size: 100%;\n",
|
||||
" }\n",
|
||||
"</style>\n",
|
||||
"<script>\n",
|
||||
" MathJax.Hub.Config({\n",
|
||||
" TeX: {\n",
|
||||
" extensions: [\"AMSmath.js\"]\n",
|
||||
" },\n",
|
||||
" tex2jax: {\n",
|
||||
" inlineMath: [ ['$','$'], [\"\\\\(\",\"\\\\)\"] ],\n",
|
||||
" displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"] ]\n",
|
||||
" },\n",
|
||||
" displayAlign: 'center', // Change this to 'center' to center equations.\n",
|
||||
" \"HTML-CSS\": {\n",
|
||||
" styles: {'.MathJax_Display': {\"margin\": 4}}\n",
|
||||
" }\n",
|
||||
" });\n",
|
||||
"</script>\n"
|
||||
],
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
"output_type": "pyout",
|
||||
"prompt_number": 1,
|
||||
"text": [
|
||||
"<IPython.core.display.HTML at 0x239bb50>"
|
||||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 1
|
||||
@ -406,7 +541,7 @@
|
||||
"\n",
|
||||
"If this makes you uncomfortable, I advise not worrying about it. We are just defining an algorithm for choosing our sigma points; if the 'square' root in method of computation ($SS$) is slightly different than the other case ($SS^T), it shouldn't really matter. Plus, this still works for the one dimensional case, as the transpose of a scalar is just the scalar. \n",
|
||||
"\n",
|
||||
"I will derive the math for computing this in a later section in this chapter. For now I will say that this is a well worn area of linear algebra, and performing this 'square root' uses something called the Cholesky decomposition. This is a library procedure that is available in any linear algebra library. For example, numpy provides it in $\\verb,numpy.linalg.cholesky(),$, and we will be using that function in our code. If your language of choice is Fortran, C, C++, or the like the standard libraries like LAPACK also provide this routine. And, of course, matlab provides $\\verb,chol(),$, which does the same thing."
|
||||
"I will derive the math for computing this in a later section in this chapter. For now I will say that this is a well worn area of linear algebra, and performing this 'square root' uses something called the Cholesky decomposition. This is a library procedure that is available in any linear algebra library. For example, numpy provides it in `numpy.linalg.cholesky()`, and we will be using that function in our code. If your language of choice is Fortran, C, C++, or the like the standard libraries like LAPACK also provide this routine. And, of course, matlab provides `chol()`, which does the same thing."
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -421,7 +556,7 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"So let's just implement this algorithm. First, let's write the code to compute the mean and covariance given the sigma points. Unfortunately, this requires a short diversion into the intricacies of numpy's data types. Through historical accidents, numpy provides several data structures to represent matrices, and they do not 'play well' with each other. Most sources recommend using the type $\\verb,numpy.array,$, however, it is quite cumbersome to use for intensive linear algebra. Since everything I do in this book is linear algebra, I choose to use $\\verb,numpy.matrix,$ instead. Fortunately, numpy provides $\\verb,numpy.asmatrix(),$. It will convert a variable to $\\verb,numpy.matrix,$ if it is not already one; better yet, it will turn a scalar into a $1{\\times}1$ matrix. The result is that we can pass scalars, $\\verb,numpy.array,$'s, or $\\verb,numpy.matrix,$s into my code and it will work.\n",
|
||||
"So let's just implement this algorithm. First, let's write the code to compute the mean and covariance given the sigma points. Unfortunately, this requires a short diversion into the intricacies of numpy's data types. Through historical accidents, numpy provides several data structures to represent matrices, and they do not 'play well' with each other. Most sources recommend using the type `numpy.array`, however, it is quite cumbersome to use for intensive linear algebra. Since everything I do in this book is linear algebra, I choose to use `numpy.matrix` instead. Fortunately, numpy provides `numpy.asmatrix()`. It will convert a variable to `numpy.matrix` if it is not already one; better yet, it will turn a scalar into a $1{\\times}1$ matrix. The result is that we can pass scalars, `numpy.array`'s, or `numpy.matrix`s into my code and it will work.\n",
|
||||
"\n",
|
||||
"So we will store the sigma points and weights in matrices, like so:\n",
|
||||
"\n",
|
||||
|
@ -1,10 +1,7 @@
|
||||
rem
|
||||
python merge_book.py Kalman_Filters.ipynb >Kalman_and_Bayesian_Filters_in_Python.ipynb
|
||||
|
||||
python merge_book.py >Kalman_and_Bayesian_Filters_in_Python.ipynb
|
||||
|
||||
|
||||
python merge_book.py Preface.ipynb Signals_and_Noise.ipynb g-h_filter.ipynb discrete_bayes.ipynb Gaussians.ipynb Kalman_Filters.ipynb Multidimensional_Kalman_Filters.ipynb Kalman_Filter_Math.ipynb Designing_Kalman_Filters.ipynb Extended_Kalman_Filters.ipynb Unscented_Kalman_Filter.ipynb Designing_Nonlinear_Kalman_Filters.ipynb >Kalman_and_Bayesian_Filters_in_Python.ipynb
|
||||
|
||||
|
||||
ipython nbconvert --to latex --template book --post PDF Kalman_and_Bayesian_Filters_in_Python.ipynb
|
||||
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"metadata": {
|
||||
"name": "",
|
||||
"signature": "sha256:ddbf9941478e20c05711bbd952679c9b9ff0760b93bc9211123c4a8f8671c9fa"
|
||||
"signature": "sha256:a7f391a6729b3d01b0ccfdf3825a3ab878f59e1d4937e5135a8b6c0f64c253a2"
|
||||
},
|
||||
"nbformat": 3,
|
||||
"nbformat_minor": 0,
|
||||
@ -31,92 +31,227 @@
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"output_type": "stream",
|
||||
"stream": "stdout",
|
||||
"text": [
|
||||
"Installed secnum.py. To use it, type:\n",
|
||||
" %load_ext secnum\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"javascript": [
|
||||
"console.log(\"Section numbering...\");\n",
|
||||
"html": [
|
||||
"<style>\n",
|
||||
"@import url('http://fonts.googleapis.com/css?family=Source+Code+Pro');\n",
|
||||
"\n",
|
||||
"function number_sections(threshold) {\n",
|
||||
"\n",
|
||||
" var h1_number = 0;\n",
|
||||
" var h2_number = 0;\n",
|
||||
"\n",
|
||||
" if (threshold === undefined) {\n",
|
||||
" threshold = 2; // does nothing so far\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" var cells = IPython.notebook.get_cells();\n",
|
||||
" \n",
|
||||
" for (var i=0; i < cells.length; i++) {\n",
|
||||
"\n",
|
||||
" var cell = cells[i];\n",
|
||||
" if (cell.cell_type !== 'heading') continue;\n",
|
||||
" \n",
|
||||
" var level = cell.level;\n",
|
||||
" if (level > threshold) continue;\n",
|
||||
" \n",
|
||||
" if (level === 1) {\n",
|
||||
" \n",
|
||||
" h1_number ++;\n",
|
||||
" var h1_element = cell.element.find('h1');\n",
|
||||
" var h1_html = h1_element.html();\n",
|
||||
" \n",
|
||||
" console.log(\"h1_html: \" + h1_html);\n",
|
||||
"\n",
|
||||
" var patt = /^[0-9]+\\.\\s(.*)/; // section number at start of string\n",
|
||||
" var title = h1_html.match(patt); // just the title\n",
|
||||
"\n",
|
||||
" if (title != null) { \n",
|
||||
" h1_element.html(h1_number + \". \" + title[1]);\n",
|
||||
" }\n",
|
||||
" else {\n",
|
||||
" h1_element.html(h1_number + \". \" + h1_html);\n",
|
||||
" }\n",
|
||||
" \n",
|
||||
" h2_number = 0;\n",
|
||||
" \n",
|
||||
" div.cell{\n",
|
||||
" width: 850px;\n",
|
||||
" margin-left: 0% !important;\n",
|
||||
" margin-right: auto;\n",
|
||||
" }\n",
|
||||
" \n",
|
||||
" if (level === 2) {\n",
|
||||
" \n",
|
||||
" h2_number ++;\n",
|
||||
" \n",
|
||||
" var h2_element = cell.element.find('h2');\n",
|
||||
" var h2_html = h2_element.html();\n",
|
||||
"\n",
|
||||
" console.log(\"h2_html: \" + h2_html);\n",
|
||||
"\n",
|
||||
" \n",
|
||||
" var patt = /^[0-9]+\\.[0-9]+\\.\\s/;\n",
|
||||
" var result = h2_html.match(patt);\n",
|
||||
"\n",
|
||||
" if (result != null) {\n",
|
||||
" h2_html = h2_html.replace(result, \"\");\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" h2_element.html(h1_number + \".\" + h2_number + \". \" + h2_html);\n",
|
||||
" \n",
|
||||
" div.text_cell code {\n",
|
||||
" background: #FFFFFF;\n",
|
||||
" color: #000000;\n",
|
||||
" font-weight: 600;\n",
|
||||
" font-size: 13pt;\n",
|
||||
" font-style: bold;\n",
|
||||
" font-family: 'Source Code Pro', Consolas, monocco, monospace;\n",
|
||||
" }\n",
|
||||
" h1 {\n",
|
||||
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
|
||||
"\t}\n",
|
||||
"\t\n",
|
||||
" div.input_area {\n",
|
||||
" background: #F6F6F9;\n",
|
||||
" border: 1px solid #586e75;\n",
|
||||
" }\n",
|
||||
" \n",
|
||||
" }\n",
|
||||
" \n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"number_sections();\n",
|
||||
"\n",
|
||||
"// $([IPython.evnts]).on('create.Cell', number_sections);\n",
|
||||
"\n",
|
||||
"$([IPython.events]).on('selected_cell_type_changed.Notebook', number_sections);\n",
|
||||
"\n"
|
||||
" .text_cell_render h1 {\n",
|
||||
" font-weight: 200;\n",
|
||||
" font-size: 30pt;\n",
|
||||
" line-height: 100%;\n",
|
||||
" color:#c76c0c;\n",
|
||||
" margin-bottom: 0.5em;\n",
|
||||
" margin-top: 1em;\n",
|
||||
" display: block;\n",
|
||||
" white-space: wrap;\n",
|
||||
" } \n",
|
||||
" h2 {\n",
|
||||
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
|
||||
" }\n",
|
||||
" .text_cell_render h2 {\n",
|
||||
" font-weight: 200;\n",
|
||||
" font-size: 20pt;\n",
|
||||
" font-style: italic;\n",
|
||||
" line-height: 100%;\n",
|
||||
" color:#c76c0c;\n",
|
||||
" margin-bottom: 0.5em;\n",
|
||||
" margin-top: 1.5em;\n",
|
||||
" display: block;\n",
|
||||
" white-space: nowrap;\n",
|
||||
" } \n",
|
||||
" h3 {\n",
|
||||
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
|
||||
" }\n",
|
||||
" .text_cell_render h3 {\n",
|
||||
" font-weight: 300;\n",
|
||||
" font-size: 18pt;\n",
|
||||
" line-height: 100%;\n",
|
||||
" color:#d77c0c;\n",
|
||||
" margin-bottom: 0.5em;\n",
|
||||
" margin-top: 2em;\n",
|
||||
" display: block;\n",
|
||||
" white-space: nowrap;\n",
|
||||
" }\n",
|
||||
" h4 {\n",
|
||||
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
|
||||
" }\n",
|
||||
" .text_cell_render h4 {\n",
|
||||
" font-weight: 300;\n",
|
||||
" font-size: 16pt;\n",
|
||||
" color:#d77c0c;\n",
|
||||
" margin-bottom: 0.5em;\n",
|
||||
" margin-top: 0.5em;\n",
|
||||
" display: block;\n",
|
||||
" white-space: nowrap;\n",
|
||||
" }\n",
|
||||
" h5 {\n",
|
||||
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
|
||||
" }\n",
|
||||
" .text_cell_render h5 {\n",
|
||||
" font-weight: 300;\n",
|
||||
" font-style: normal;\n",
|
||||
" color: #1d3b84;\n",
|
||||
" font-size: 16pt;\n",
|
||||
" margin-bottom: 0em;\n",
|
||||
" margin-top: 1.5em;\n",
|
||||
" display: block;\n",
|
||||
" white-space: nowrap;\n",
|
||||
" }\n",
|
||||
" div.text_cell_render{\n",
|
||||
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
|
||||
" line-height: 135%;\n",
|
||||
" font-size: 110%;\n",
|
||||
" width:750px;\n",
|
||||
" margin-left:auto;\n",
|
||||
" margin-right:auto;\n",
|
||||
" text-align:justify;\n",
|
||||
" text-justify:inter-word;\n",
|
||||
" }\n",
|
||||
" div.output_subarea.output_text.output_pyout {\n",
|
||||
" overflow-x: auto;\n",
|
||||
" overflow-y: scroll;\n",
|
||||
" max-height: 300px;\n",
|
||||
" }\n",
|
||||
" div.output_subarea.output_stream.output_stdout.output_text {\n",
|
||||
" overflow-x: auto;\n",
|
||||
" overflow-y: scroll;\n",
|
||||
" max-height: 300px;\n",
|
||||
" }\n",
|
||||
" code{\n",
|
||||
" font-size: 70%;\n",
|
||||
" }\n",
|
||||
" .rendered_html code{\n",
|
||||
" background-color: transparent;\n",
|
||||
" }\n",
|
||||
" ul{\n",
|
||||
" margin: 2em;\n",
|
||||
" }\n",
|
||||
" ul li{\n",
|
||||
" padding-left: 0.5em; \n",
|
||||
" margin-bottom: 0.5em; \n",
|
||||
" margin-top: 0.5em; \n",
|
||||
" }\n",
|
||||
" ul li li{\n",
|
||||
" padding-left: 0.2em; \n",
|
||||
" margin-bottom: 0.2em; \n",
|
||||
" margin-top: 0.2em; \n",
|
||||
" }\n",
|
||||
" ol{\n",
|
||||
" margin: 2em;\n",
|
||||
" }\n",
|
||||
" ol li{\n",
|
||||
" padding-left: 0.5em; \n",
|
||||
" margin-bottom: 0.5em; \n",
|
||||
" margin-top: 0.5em; \n",
|
||||
" }\n",
|
||||
" ul li{\n",
|
||||
" padding-left: 0.5em; \n",
|
||||
" margin-bottom: 0.5em; \n",
|
||||
" margin-top: 0.2em; \n",
|
||||
" }\n",
|
||||
" a:link{\n",
|
||||
" font-weight: bold;\n",
|
||||
" color:#447adb;\n",
|
||||
" }\n",
|
||||
" a:visited{\n",
|
||||
" font-weight: bold;\n",
|
||||
" color: #1d3b84;\n",
|
||||
" }\n",
|
||||
" a:hover{\n",
|
||||
" font-weight: bold;\n",
|
||||
" color: #1d3b84;\n",
|
||||
" }\n",
|
||||
" a:focus{\n",
|
||||
" font-weight: bold;\n",
|
||||
" color:#447adb;\n",
|
||||
" }\n",
|
||||
" a:active{\n",
|
||||
" font-weight: bold;\n",
|
||||
" color:#447adb;\n",
|
||||
" }\n",
|
||||
" .rendered_html :link {\n",
|
||||
" text-decoration: underline; \n",
|
||||
" }\n",
|
||||
" .rendered_html :hover {\n",
|
||||
" text-decoration: none; \n",
|
||||
" }\n",
|
||||
" .rendered_html :visited {\n",
|
||||
" text-decoration: none;\n",
|
||||
" }\n",
|
||||
" .rendered_html :focus {\n",
|
||||
" text-decoration: none;\n",
|
||||
" }\n",
|
||||
" .rendered_html :active {\n",
|
||||
" text-decoration: none;\n",
|
||||
" }\n",
|
||||
" .warning{\n",
|
||||
" color: rgb( 240, 20, 20 )\n",
|
||||
" } \n",
|
||||
" hr {\n",
|
||||
" color: #f3f3f3;\n",
|
||||
" background-color: #f3f3f3;\n",
|
||||
" height: 1px;\n",
|
||||
" }\n",
|
||||
" blockquote{\n",
|
||||
" display:block;\n",
|
||||
" background: #fcfcfc;\n",
|
||||
" border-left: 5px solid #c76c0c;\n",
|
||||
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
|
||||
" width:680px;\n",
|
||||
" padding: 10px 10px 10px 10px;\n",
|
||||
" text-align:justify;\n",
|
||||
" text-justify:inter-word;\n",
|
||||
" }\n",
|
||||
" blockquote p {\n",
|
||||
" margin-bottom: 0;\n",
|
||||
" line-height: 125%;\n",
|
||||
" font-size: 100%;\n",
|
||||
" }\n",
|
||||
"</style>\n",
|
||||
"<script>\n",
|
||||
" MathJax.Hub.Config({\n",
|
||||
" TeX: {\n",
|
||||
" extensions: [\"AMSmath.js\"]\n",
|
||||
" },\n",
|
||||
" tex2jax: {\n",
|
||||
" inlineMath: [ ['$','$'], [\"\\\\(\",\"\\\\)\"] ],\n",
|
||||
" displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"] ]\n",
|
||||
" },\n",
|
||||
" displayAlign: 'center', // Change this to 'center' to center equations.\n",
|
||||
" \"HTML-CSS\": {\n",
|
||||
" styles: {'.MathJax_Display': {\"margin\": 4}}\n",
|
||||
" }\n",
|
||||
" });\n",
|
||||
"</script>\n"
|
||||
],
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
"output_type": "pyout",
|
||||
"prompt_number": 1,
|
||||
"text": [
|
||||
"<IPython.core.display.HTML at 0x25adb90>"
|
||||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 1
|
||||
@ -148,7 +283,7 @@
|
||||
"\n",
|
||||
"To keep the problem small, we will assume that there are only 10 positions in a single hallway to consider, which we will number 0 to 9, where 1 is to the right of 0, 2 is to the right of 1, and so on. For reasons that will be clear later, we will also assume that the hallway is circular or rectangular. If you move right from position 9, you will be at position 0. \n",
|
||||
"\n",
|
||||
"When I begin listening to the sensor I have no reason to believe that Simon is at any particular position in the hallway. He is equally likely to be in any position. The probability that he is in each position is therefore $1/10$ \n",
|
||||
"When I begin listening to the sensor I have no reason to believe that Simon is at any particular position in the hallway. He is equally likely to be in any position. The probability that he is in each position is therefore 1/10. \n",
|
||||
"\n",
|
||||
"Let us represent our belief of his position at any time in a numpy array."
|
||||
]
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"metadata": {
|
||||
"name": "",
|
||||
"signature": "sha256:4ac13c77a9a10a85c53f1d673717982e8b84a217f710a775767b2f08a92d841a"
|
||||
"signature": "sha256:54842314075cdbcdc03bb78f35c3e8a836a4ff44b02d617f5738d57e43019ee4"
|
||||
},
|
||||
"nbformat": 3,
|
||||
"nbformat_minor": 0,
|
||||
@ -33,14 +33,20 @@
|
||||
{
|
||||
"html": [
|
||||
"<style>\n",
|
||||
"@import url('http://fonts.googleapis.com/css?family=Source+Code+Pro');\n",
|
||||
"\n",
|
||||
" div.cell{\n",
|
||||
" width: 850px;\n",
|
||||
" margin-left: 0% !important;\n",
|
||||
" margin-right: auto;\n",
|
||||
" }\n",
|
||||
" div.text_cell code {\n",
|
||||
" background: #F6F6F9;\n",
|
||||
" color: #0000FF;\n",
|
||||
" background: #FFFFFF;\n",
|
||||
" color: #000000;\n",
|
||||
" font-weight: 600;\n",
|
||||
" font-size: 13pt;\n",
|
||||
" font-style: bold;\n",
|
||||
" font-family: 'Source Code Pro', Consolas, monocco, monospace;\n",
|
||||
" }\n",
|
||||
" h1 {\n",
|
||||
" font-family: 'Open sans',verdana,arial,sans-serif;\n",
|
||||
@ -244,7 +250,7 @@
|
||||
"output_type": "pyout",
|
||||
"prompt_number": 1,
|
||||
"text": [
|
||||
"<IPython.core.display.HTML at 0x2aabc50>"
|
||||
"<IPython.core.display.HTML at 0x1455c90>"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
@ -1,12 +1,18 @@
|
||||
<style>
|
||||
@import url('http://fonts.googleapis.com/css?family=Source+Code+Pro');
|
||||
|
||||
div.cell{
|
||||
width: 850px;
|
||||
margin-left: 0% !important;
|
||||
margin-right: auto;
|
||||
}
|
||||
div.text_cell code {
|
||||
background: #F6F6F9;
|
||||
color: #0000FF;
|
||||
background: transparent;
|
||||
color: #000000;
|
||||
font-weight: 600;
|
||||
font-size: 13pt;
|
||||
font-style: bold;
|
||||
font-family: 'Source Code Pro', Consolas, monocco, monospace;
|
||||
}
|
||||
h1 {
|
||||
font-family: 'Open sans',verdana,arial,sans-serif;
|
||||
|
Loading…
Reference in New Issue
Block a user