Adjusted format to work correctly with nbconvert.

Mostly replaced align with aligned.
This commit is contained in:
Roger Labbe 2014-05-26 13:29:10 -07:00
parent bd10117312
commit 2b6c7005ae
3 changed files with 28 additions and 19 deletions

9
.gitignore vendored Normal file
View File

@ -0,0 +1,9 @@
*.aux
*.html
*.out
*.pdf
*.gz
*.tex
*.toc
*_files/
.ipynb_checkpoints/

View File

@ -371,19 +371,19 @@
"source": [
"##### **Step 2:** Design State Transition Function\n",
"\n",
"Our next step is to design the state transistion function. Recall that the state transistion function is implemented as a matrix $\\small{\\mathbf{F}}$ that we multipy with the previous state of our system to get the next state, like so. \n",
"Our next step is to design the state transistion function. Recall that the state transistion function is implemented as a matrix $\\mathbf{F}$ that we multipy with the previous state of our system to get the next state, like so. \n",
"\n",
"$$\\mathbf{x}' = \\mathbf{Fx}$$\n",
"\n",
"I will not belabor this as it is very similar to the 1-D case we did in the previous chapter. Our state equations for position and velocity would be:\n",
"\n",
"$$\n",
"\\begin{align}\n",
"x' &= (1*x) + (\\Delta t * v_x) &+ (0*y) &+ (0 * v_y) \\\\\n",
"v_x &= (0*x) + (1*v_x) &+ (0*y) &+ (0 * v_y) \\\\\n",
"y' &= (0*x) + (0* v_x) &+ (1*y) &+ (\\Delta t * v_y) \\\\\n",
"v_y &= (0*x) + (0*v_x) &+ (0*y) &+ (1 * v_y)\n",
"\\end{align}\n",
"\\begin{aligned}\n",
"x' &= (1*x) + (\\Delta t * v_x) + (0*y) + (0 * v_y) \\\\\n",
"v_x &= (0*x) + (1*v_x) + (0*y) + (0 * v_y) \\\\\n",
"y' &= (0*x) + (0* v_x) + (1*y) + (\\Delta t * v_y) \\\\\n",
"v_y &= (0*x) + (0*v_x) + (0*y) + (1 * v_y)\n",
"\\end{aligned}\n",
"$$\n"
]
},
@ -391,7 +391,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Laying it out that way shows us both the values and row-column organization required for $\\small{\\mathbf{F}}$. In linear algebra, we would write this as:\n",
"Laying it out that way shows us both the values and row-column organization required for $\\small\\mathbf{F}$. In linear algebra, we would write this as:\n",
"\n",
"$$\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",
@ -424,7 +424,7 @@
"metadata": {},
"source": [
"##### **Step 3**: Design the Motion Function\n",
"We have no control inputs to our robot (yet!), so this step is trivial - set the motion transition function $\\small{\\mathbf{B}}$ to zero. This is done for us by the class when it is created so we can skip this step, but for completeness we will be explicit."
"We have no control inputs to our robot (yet!), so this step is trivial - set the motion transition function $\\small\\mathbf{B}$ to zero. This is done for us by the class when it is created so we can skip this step, but for completeness we will be explicit."
]
},
{
@ -455,13 +455,13 @@
"we write the following:\n",
"\n",
"$$\n",
"\\begin{align*}\n",
"z_x' &= (\\frac{x}{0.3048}) + (0* v_x) &+ (0*y) &+ (0 * v_y) \\\\\n",
"z_y' &= (0*x) + (0* v_x) &+ (\\frac{y}{0.3048}) &+ (0 * v_y) \\\\\n",
"\\end{align*}\n",
"\\begin{aligned}\n",
"z_x' &= (\\frac{x}{0.3048}) + (0* v_x) &+ (0*y) + (0 * v_y) \\\\\n",
"z_y' &= (0*x) + (0* v_x) + (\\frac{y}{0.3048}) + (0 * v_y) \\\\\n",
"\\end{aligned}\n",
"$$\n",
"\n",
"Perhaps the $\\frac{1}{0.3048}$ caught you off guard. At first I always found $\\small{\\mathbf{H}}$ a bit counter-intuitive to design because it takes you from the state variables to the measurements, but the Kalman filter is trying to take measurements and produce state variables to them. If you read the math chapter you will understand why $\\small{\\mathbf{H}}$ is designed to go in this direction. If not, well, you'll have to remember how this works and trust that it is correct.\n",
"Perhaps the $\\frac{1}{0.3048}$ caught you off guard. At first I always found $\\small\\mathbf{H}$ a bit counter-intuitive to design because it takes you from the state variables to the measurements, but the Kalman filter is trying to take measurements and produce state variables to them. If you read the math chapter you will understand why $\\small\\mathbf{H}$ is designed to go in this direction. If not, well, you'll have to remember how this works and trust that it is correct.\n",
"\n",
"So, here is the Python that implements this:"
]
@ -564,7 +564,7 @@
"source": [
"#### **Step 7**: Design Initial Conditions\n",
"\n",
"For our simple problem we will set the initial position at (0,0) with a velocity of (0,0). Since that is a pure guess, we will set the covariance matrix $\\small{\\mathbf{P}}$ to a large value.\n",
"For our simple problem we will set the initial position at (0,0) with a velocity of (0,0). Since that is a pure guess, we will set the covariance matrix $\\small\\mathbf{P}$ to a large value.\n",
"$$ \\mathbf{x} = \\begin{bmatrix}0\\\\0\\\\0\\\\0\\end{bmatrix}\\\\\n",
"\\mathbf{P} = \\begin{bmatrix}500&0&0&0\\\\0&500&0&0\\\\0&0&500&0\\\\0&0&0&500\\end{bmatrix}$$\n",
"\n",
@ -673,7 +673,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"I encourage you to play with this, setting $\\small{\\mathbf{Q}}$ and $\\small{\\mathbf{R}}$ to various values. However, we did a fair amount of that sort of thing in the last chapters, and we have a lot of material to cover, so I will move on to more complicated cases where we will also have a chance to experience changing these values.\n",
"I encourage you to play with this, setting $\\small\\mathbf{Q}$ and $\\small\\mathbf{R}$ to various values. However, we did a fair amount of that sort of thing in the last chapters, and we have a lot of material to cover, so I will move on to more complicated cases where we will also have a chance to experience changing these values.\n",
"\n",
"Now I will run the same Kalman filter with the same settings, but also plot the covariance ellipse for $x$ and $y$. First, the code without explanation, so we can see the output. I print the last covariance to see what it looks like. But before you scroll down to look at the results, what do you think it will look like? You have enough information to figure this out but this is still new to you, so don't be discouraged if you get it wrong."
]
@ -763,7 +763,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Did you correctly predict what the covariance matrix and plots would look like? Perhaps you were expecting a tilted ellipse, as in the last chapters. If so, recall that in those chapters we were not plotting $x$ against $y$, but $x$ against $\\dot{x}$. $x$ *is correlated* to $\\dot{x}$, but $x$ is not correlated or dependent on $y$. Therefore our ellipses are not tilted. Furthermore, the noise for both $x$ and $y$ are modelled to have the same value, 5, in $\\small{\\mathbf{R}}$. If we were to set R to, for example,\n",
"Did you correctly predict what the covariance matrix and plots would look like? Perhaps you were expecting a tilted ellipse, as in the last chapters. If so, recall that in those chapters we were not plotting $x$ against $y$, but $x$ against $\\dot{x}$. $x$ *is correlated* to $\\dot{x}$, but $x$ is not correlated or dependent on $y$. Therefore our ellipses are not tilted. Furthermore, the noise for both $x$ and $y$ are modelled to have the same value, 5, in $\\small\\mathbf{R}$. If we were to set R to, for example,\n",
"\n",
"$$\\mathbf{R} = \\begin{bmatrix}10&0\\\\0&5\\end{bmatrix}$$\n",
"\n",

View File

@ -780,12 +780,12 @@
"source": [
"Note that I rewrote the equations somewhat:\n",
"\n",
"$$\\begin{align*}\n",
"$$\\begin{aligned}\n",
"\\hat{x}_t &= gz + \\hat{x}_{t-1} (1-g) \\\\\n",
"&= gz + \\hat{x}_{t-1} - g\\hat{x}_{t-1} \\\\\n",
"&= \\hat{x}_{t-1} + g*(z-\\hat{x}_{t-1}) \\\\\n",
"&= \\hat{x}_{t-1} + g*residual\n",
"\\end{align*}\n",
"\\end{aligned}\n",
"$$\n",
"\n",
"I'll let you decide which form of the equation is more expressive. One form explicitly uses $g$ and $(1-g)$ to compute the point between the two values, the other finds the difference between the points, and adds a fraction of that to the first value. Both are computing the same thing. You'll see both forms in the literature, so I have used both to expose you to them. "