Fixed minor typos
This commit is contained in:
parent
7f3a50aee4
commit
a9ef2c4207
@ -331,7 +331,7 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"The constructor `_init()__` initializes the DogSensor class with an initial position `x0`, velocity `vel`, and the variance in the measurement and noise. The `sense_position()` 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_position()` you will see a call to `numpy.random.randn()`. This returns a number sampled from a normal distribution with a mean of 0.0. and a standard deviation of 1.0. *Variance* is defined as the standard deviation squared, so in `__init()__` we take the square root of the variances to get the standard deviation. Therefore the expression `self.x + random.randn() * self.noise` computes a simulated measurement with the variance that we desire. \n",
|
||||
"The constructor `__init()__` initializes the DogSensor class with an initial position `x0`, velocity `vel`, and the variance in the measurement and noise. The `sense_position()` 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_position()` you will see a call to `numpy.random.randn()`. This returns a number sampled from a normal distribution with a mean of 0.0. and a standard deviation of 1.0. *Variance* is defined as the standard deviation squared, so in `__init()__` we take the square root of the variances to get the standard deviation. Therefore the expression `self.x + random.randn() * self.noise` computes a simulated measurement with the variance that we desire. \n",
|
||||
"\n",
|
||||
"Let's look at some example output for that."
|
||||
]
|
||||
@ -626,7 +626,7 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Notice how this relates to the bar charts from the Discrete Bayes chapter. In that chapter we drews bars of various heights to depict the probability that the dog was at any given position. In many cases those bars took on a shape very similar to this chart. The differences are that the bars depict the probability of a discrete position, whereas this chart depicts the probability distribution of a continuous range of positions. \n",
|
||||
"Notice how this relates to the bar charts from the Discrete Bayes chapter. In that chapter we drew bars of various heights to depict the probability that the dog was at any given position. In many cases those bars took on a shape very similar to this chart. The differences are that the bars depict the probability of a discrete position, whereas this chart depicts the probability distribution of a continuous range of positions. \n",
|
||||
"\n",
|
||||
"This graph corresponds to a fairly inexact belief. While we believe that the dog is at 23, note that roughly speaking positions 21 to 25 are quite likely as well. Let's assume for the moment our dog is standing still, and we query the sensor again. This time it returns 23.2 as the position. Can we use this additional information to improve our estimate of the dog's position?\n",
|
||||
"\n",
|
||||
@ -1033,7 +1033,7 @@
|
||||
"source": [
|
||||
"That is a beautiful result, but it is not yet a filter. We assumed that the dog was sitting still, an extremely dubious assumption. Certainly it is a useless one - who would need to write a filter to track non-moving objects? The histogram used a loop of predict and update functions, and we must do the same to accommodate movement.\n",
|
||||
"\n",
|
||||
"How how do we perform the predict function with Gaussians? Recall the histogram method:\n",
|
||||
"How do we perform the predict function with Gaussians? Recall the histogram method:\n",
|
||||
"\n",
|
||||
" def predict(pos, move, p_correct, p_under, p_over):\n",
|
||||
" n = len(pos)\n",
|
||||
@ -1383,8 +1383,9 @@
|
||||
"So, we use `x` for the state (estimated value of the filter) and `P` for the variance of the state. `R` is the measurement error, and `Q` is the movement error. This gives us:\n",
|
||||
"\n",
|
||||
" class KalmanFilter1D:\n",
|
||||
" def __init__(self, x0, R, Q):\n",
|
||||
" def __init__(self, x0, P, R, Q):\n",
|
||||
" self.x = x0\n",
|
||||
" self.P = P\n",
|
||||
" self.R = R\n",
|
||||
" self.Q = Q\n",
|
||||
" \n",
|
||||
@ -1614,6 +1615,7 @@
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"movement = 0\n",
|
||||
"variance = 2.13**2\n",
|
||||
"movement_variance = .2\n",
|
||||
"actual_voltage = 16.3\n",
|
||||
@ -1686,7 +1688,7 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Think of this animation in terms of the g-h filter. At each step the g-h filter makes a prediction, takes a measurement, computes the residual (the difference between the prediction and the measurement, and then selects a point on the residual line based on the scaling factor *g*. The Kalman filter is doing exactly the same thing, except that the scaling factor *g* varies with time. As the filter becomes more confident in its state the scaling factor favors the filter's prediction over the measurement. \n",
|
||||
"Think of this animation in terms of the g-h filter. At each step the g-h filter makes a prediction, takes a measurement, computes the residual (the difference between the prediction and the measurement), and then selects a point on the residual line based on the scaling factor *g*. The Kalman filter is doing exactly the same thing, except that the scaling factor *g* varies with time. As the filter becomes more confident in its state the scaling factor favors the filter's prediction over the measurement. \n",
|
||||
"\n",
|
||||
"> If this is not clear, I urge you to go back and review the g-h chapter. This is the crux of the algorithms in this book. "
|
||||
]
|
||||
|
@ -341,7 +341,7 @@
|
||||
" \\end{bmatrix}\n",
|
||||
"$$\n",
|
||||
"\n",
|
||||
"If you haven't seen this before it is probably a bit confusing at the moment. Rather than explain the math right now, we will take our usual tactic of building our intuition first with various physical models. At this point, note that the diagonal contains the variance for each state variable, and that all off-diagonal elements (covariances) are represent how much the $i$th (row) and $j$th (column) state variable are linearly correlated to each other. In other words, it is a measure for how much they change together. No correlation will have a covariance of 0. So, for example, if the variance for x is 10, the variance for y is 4, and there is no linear correlation between x and y, then we would say\n",
|
||||
"If you haven't seen this before it is probably a bit confusing at the moment. Rather than explain the math right now, we will take our usual tactic of building our intuition first with various physical models. At this point, note that the diagonal contains the variance for each state variable, and that all off-diagonal elements (covariances) are represent how much the $i$th (row) and $j$th (column) state variable are linearly correlated to each other. In other words, it is a measure for how much they change together. A covariance of 0 indicates no correlation. So, for example, if the variance for x is 10, the variance for y is 4, and there is no linear correlation between x and y, then we would say\n",
|
||||
"\n",
|
||||
"$$\\Sigma = \\begin{bmatrix}10&0\\\\0&4\\end{bmatrix}$$\n",
|
||||
"\n",
|
||||
@ -890,7 +890,7 @@
|
||||
"source": [
|
||||
"### Expected Value\n",
|
||||
"\n",
|
||||
"I could just give you the formula for the covariance but it will make more sense if you see how it is derived. To do that we first need to talked about *expected value* of a random variable. The expected value is just the value we expect, on average, for the variable. \n",
|
||||
"I could just give you the formula for the covariance but it will make more sense if you see how it is derived. To do that we first need to talk about *expected value* of a random variable. The expected value is just the value we expect, on average, for the variable. \n",
|
||||
"\n",
|
||||
"The *expected value* of a random variable is just the average value it would have if we took an infinite number of samples of it and then averaged those samples together. Let's say we have $x=[1,3,5]$ and each value is equally probable. What would we *expect* $x$ to have, on average?\n",
|
||||
"\n",
|
||||
@ -1021,7 +1021,7 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"We said above that \"the *covariance* measures how much two random variables move in the same direction\", so let's see what that means in practice. We will do this with two variables so that we can plot the covariance matrix. If we start with the value $x_0 = (1, 2)$ we can create subsequent sames that vary in the same direction with $x_1 = (2, 4)$, $x_2=(3,6)$, and $x_3=(4,8). I don't feel like computing this by hand, so we will use NumPy to compute the covariance."
|
||||
"We said above that \"the *covariance* measures how much two random variables move in the same direction\", so let's see what that means in practice. We will do this with two variables so that we can plot the covariance matrix. If we start with the value $x_0 = (1, 2)$ we can create subsequent values that vary in the same direction with $x_1 = (2, 4)$, $x_2=(3,6)$, and $x_3=(4,8)$. I don't feel like computing this by hand, so we will use NumPy to compute the covariance."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -453,7 +453,7 @@
|
||||
"\n",
|
||||
"However, I can present enough of the theory to allow us to create the system equations for many different Kalman filters, and give you enough background to at least follow the mathematics in the literature. My goal is to get you to the stage where you can read a Kalman filtering book or paper and understand it well enough to implement the algorithms. The background math is deep, but we end up using a few simple techniques over and over again in practice. \n",
|
||||
"\n",
|
||||
"Let's lay out the problem and discuss what the solution will be. We model *dynamic systems* with a set of first order *differential equations*. This should not be a surprise as calculus is the math of of thing that vary. For example, we say that velocity is the derivative of distance with respect to time\n",
|
||||
"Let's lay out the problem and discuss what the solution will be. We model *dynamic systems* with a set of first order *differential equations*. This should not be a surprise as calculus is the math of things that vary. For example, we say that velocity is the derivative of distance with respect to time\n",
|
||||
"\n",
|
||||
"$$\\mathbf{v}= \\frac{d \\mathbf{x}}{d t} = \\dot{\\mathbf{x}}$$\n",
|
||||
"\n",
|
||||
|
Loading…
Reference in New Issue
Block a user