Fixed language about 'next chapter'.
I split the multivariate KF chapter into two, so references to the 'next' chapter were inaccurate.
This commit is contained in:
parent
1b71b73c55
commit
f07250b8f0
@ -286,7 +286,7 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Now that we understand the discrete Bayes filter and Gaussians we are prepared to implement a Kalman filter. We will do this exactly as we did the discrete Bayes filter - rather than starting with equations we will develop the code step by step based on reasoning about the problem. \"One dimensional\" just means that the filter only tracks one variable, such as position on the x-axis. In the next chapter we will learn a more general form that can track many variables simultaneously, such as position, velocity, and accelerations in x, y, z. "
|
||||
"Now that we understand the discrete Bayes filter and Gaussians we are prepared to implement a Kalman filter. We will do this exactly as we did the discrete Bayes filter - rather than starting with equations we will develop the code step by step based on reasoning about the problem. \"One dimensional\" just means that the filter only tracks one variable, such as position on the x-axis. In the subsequent chapters we will learn a more general form that can track many variables simultaneously, such as position, velocity, and accelerations in x, y, z. "
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -931,7 +931,7 @@
|
||||
"source": [
|
||||
"This result bothered me quite a bit when I first learned it. If my first measurement was 10, and the next one was 50, why would I choose 30 as a result? And why would I be *more* confident? Doesn't it make sense that either one of the measurements is wrong, or that I am measuring a moving object? Shouldn't the result be nearer 50? And, shouldn't the variance be larger, not smaller?\n",
|
||||
"\n",
|
||||
"Well, no. Recall the g-h filter chapter. In that chapter we agreed that if I weighed myself on two scales, and the first read 160 lbs while the second read 170 lbs, and both were equally accurate, the best estimate was 165 lbs. Furthermore I should be a bit more confident about 165 lbs vs 160 lbs or 170 lbs because I know have two readings, both near this estimate, increasing my confidence that neither is wildly wrong. \n",
|
||||
"Well, no. Recall the g-h filter chapter. We agreed that if I weighed myself on two scales, and the first read 160 lbs while the second read 170 lbs, and both were equally accurate, the best estimate was 165 lbs. Furthermore I should be a bit more confident about 165 lbs vs 160 lbs or 170 lbs because I know have two readings, both near this estimate, increasing my confidence that neither is wildly wrong. \n",
|
||||
"\n",
|
||||
"Of course, this example is quite exaggerated. The width of the Gaussians is fairly narrow, so this combination of measurements is extraordinarily unlikely. It is hard to eyeball this, but the measurements are well over $3\\sigma$ apart, so the probability of this happening is much less than 1%. Still, it can happen, and the math is correct. \n",
|
||||
"\n",
|
||||
@ -1345,7 +1345,7 @@
|
||||
"velocity = 1.\n",
|
||||
"```\n",
|
||||
" \n",
|
||||
"So how do I know the velocity? Magic? Consider it a prediction, or perhaps we have a secondary velocity sensor. If this is a robot then this would be a control input to the robot. In the next chapter we will learn how to handle situations where you don't have a velocity sensor or input, so please accept this simplification for now.\n",
|
||||
"So how do I know the velocity? Magic? Consider it a prediction, or perhaps we have a secondary velocity sensor. If this is a robot then this would be a control input to the robot. In subsequent chapters we will learn how to handle situations where you don't have a velocity sensor or input, so please accept this simplification for now.\n",
|
||||
"\n",
|
||||
"```python\n",
|
||||
"process_var = 1.\n",
|
||||
@ -1562,7 +1562,7 @@
|
||||
"\n",
|
||||
"$$\\mu= \\frac{1}{10} \\mu_\\mathtt{prior} + \\frac{9}{10} \\mu_\\mathtt{z}$$\n",
|
||||
"\n",
|
||||
"We can see that we are scaling the prior and the measurement by some factor. Think back to the *The g-h Filter* chapter and this plot:"
|
||||
"We can see that we are scaling the prior and the measurement by some factor. Think back to the **g-h Filter** chapter and this plot:"
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -1715,7 +1715,7 @@
|
||||
" 5. update belief in the state based on how certain we are \n",
|
||||
" in the measurement\n",
|
||||
"\n",
|
||||
"You will be hard pressed to find a Bayesian filter algorithm that does not fit into this form. Some filters will not include some aspect, such as error in the prediction, and others will have very complicated methods of computation, but this is what they all do. If you go back to the g-h filter chapter and reread it you'll recognize that the very simple thought experiments we did there result in this algorithm."
|
||||
"You will be hard pressed to find a Bayesian filter algorithm that does not fit into this form. Some filters will not include some aspect, such as error in the prediction, and others will have very complicated methods of computation, but this is what they all do. If you go back to the **g-h Filter** chapter and reread it you'll recognize that the very simple thought experiments we did there result in this algorithm."
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -1905,7 +1905,7 @@
|
||||
" self.P += self.Q\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"That give us the following code. Production code would require significant comments and error checking. However, in the next chapter we will develop Kalman filter code that works for any dimension. This class will never be more than a stepping stone for us, so I'll keep things simple."
|
||||
"That give us the following code. Production code would require significant comments and error checking. However, in subsequent chapters we will develop Kalman filter code that works for any dimension. This class will never be more than a stepping stone for us, so I'll keep things simple."
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -1943,7 +1943,7 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"So far we have developed filters for a position sensor. We are used to this problem by now, and may feel ill-equipped to implement a Kalman filter for a different problem. To be honest, there is still quite a bit of information missing from this presentation. The next chapter will fill in the gaps. Still, lets get a feel for it by designing and implementing a Kalman filter for a thermometer. The sensor for the thermometer outputs a voltage that corresponds to the temperature that is being measured. We have read the manufacturer's specifications for the sensor, and it tells us that the sensor exhibits white noise with a standard deviation of 0.13 volts.\n",
|
||||
"So far we have developed filters for a position sensor. We are used to this problem by now, and may feel ill-equipped to implement a Kalman filter for a different problem. To be honest, there is still quite a bit of information missing from this presentation. Following chapters will fill in the gaps. Still, lets get a feel for it by designing and implementing a Kalman filter for a thermometer. The sensor for the thermometer outputs a voltage that corresponds to the temperature that is being measured. We have read the manufacturer's specifications for the sensor, and it tells us that the sensor exhibits white noise with a standard deviation of 0.13 volts.\n",
|
||||
"\n",
|
||||
"We can simulate the temperature sensor measurement with this function:"
|
||||
]
|
||||
@ -1966,7 +1966,7 @@
|
||||
"source": [
|
||||
"Now we need to write the Kalman filter processing loop. As with our previous problem, we need to perform a cycle of predicting and updating. The sensing step probably seems clear - call `volt()` to get the measurement, pass the result into `update()` method, but what about the predict 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 known movement, so we will set that to zero. However, that means that we are predicting that the temperature will never change. If that is true, then over time we should become extremely confident in our results. Once the filter has enough measurements it will become very confident that it can predict the subsequent temperatures, and this will lead it to ignoring measurements that result due to an actual temperature change. This is called a *smug* filter, and is something you want to avoid. So we will add a bit of error to our prediction step to tell the filter not to discount changes in voltage over time. In the code below I set `process_var = .05**2`. This is the expected variance in the change of voltage over each time step. I chose this value merely to be able to show how the variance changes through the update and predict steps. For an real sensor you would set this value for the actual amount of change you expect. For example, this would be an extremely small number if it is a thermometer for ambient air temperature in a house, and a high number if this is a thermocouple in a chemical reaction chamber. We will say more about selecting the actual value in the next chapter. \n",
|
||||
"As always, we will trust in the math. We have no known movement, so we will set that to zero. However, that means that we are predicting that the temperature will never change. If that is true, then over time we should become extremely confident in our results. Once the filter has enough measurements it will become very confident that it can predict the subsequent temperatures, and this will lead it to ignoring measurements that result due to an actual temperature change. This is called a *smug* filter, and is something you want to avoid. So we will add a bit of error to our prediction step to tell the filter not to discount changes in voltage over time. In the code below I set `process_var = .05**2`. This is the expected variance in the change of voltage over each time step. I chose this value merely to be able to show how the variance changes through the update and predict steps. For an real sensor you would set this value for the actual amount of change you expect. For example, this would be an extremely small number if it is a thermometer for ambient air temperature in a house, and a high number if this is a thermocouple in a chemical reaction chamber. We will say more about selecting the actual value in the later chapters.\n",
|
||||
"\n",
|
||||
"Let's see what happens. "
|
||||
]
|
||||
@ -2240,7 +2240,7 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"It is easy to see that the filter is not correctly responding to the measurements. The measurements clearly indicate that the dog is changing speed but the filter has been told that it's predictions are nearly perfect so it almost entirely ignores the measurements. I encourage you to adjust the amount of movement in the dog vs process variance. We will also be studying this topic much more in the following chapter. The key point is the filter will do what you tell it to. There is nothing in the math that allows the filter to recognize that you have lied to it about the variance in the measurements and process model."
|
||||
"It is easy to see that the filter is not correctly responding to the measurements. The measurements clearly indicate that the dog is changing speed but the filter has been told that it's predictions are nearly perfect so it almost entirely ignores the measurements. I encourage you to adjust the amount of movement in the dog vs process variance. We will also be studying this topic much more in the later chapters. The key point is the filter will do what you tell it to. There is nothing in the math that allows the filter to recognize that you have lied to it about the variance in the measurements and process model."
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -2387,7 +2387,7 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Implement the Kalman filter using Jupyter 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 written the boilerplate for this; you fill in the required code."
|
||||
"Implement the Kalman filter using Jupyter 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 **Gaussians** 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 written the boilerplate for this; you fill in the required code."
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -2554,7 +2554,7 @@
|
||||
"source": [
|
||||
"Here we use a bad initial guess of 100. We can see that the filter never 'acquires' the signal. Note now the peak of the filter output always lags the peak of the signal by a small amount, and how the filtered signal does not come very close to capturing the high and low peaks of the input signal.\n",
|
||||
"\n",
|
||||
"If we recall the g-h filter chapter we can understand what is happening here. The structure of the g-h filter requires that the filter output chooses a value part way between the prediction and measurement. A varying signal like this one is always accelerating, whereas our process model assumes constant velocity, so the filter is mathematically guaranteed to always lag the input signal. \n",
|
||||
"If we recall the **g-h Filter** chapter we can understand what is happening here. The structure of the g-h filter requires that the filter output chooses a value part way between the prediction and measurement. A varying signal like this one is always accelerating, whereas our process model assumes constant velocity, so the filter is mathematically guaranteed to always lag the input signal. \n",
|
||||
"\n",
|
||||
"Maybe we didn't adjust things 'quite right'. After all, the output looks like an offset sin wave. Let's test this assumption."
|
||||
]
|
||||
@ -2766,7 +2766,7 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"The one dimensional Kalman filter that we describe in this chapter is a special, restricted case of the more general filter. Most texts do not discuss the one dimensional form. However, I think it is a vital stepping stone. We started the book with the g-h filter, then implemented the discrete Bayes filter, and now implemented the one dimensional Kalman filter. I have tried to show you that each of these filters use the same algorithm and reasoning. The mathematics of the Kalman filter that we will learn shortly is fairly sophisticated, and it can be difficult to understand the underlying simplicity of the filter. That sophistication comes with significant benefits: the filters we design in the next chapter will markedly outperform the filters in this chapter.\n",
|
||||
"The one dimensional Kalman filter that we describe in this chapter is a special, restricted case of the more general filter. Most texts do not discuss the one dimensional form. However, I think it is a vital stepping stone. We started the book with the g-h filter, then implemented the discrete Bayes filter, and now implemented the one dimensional Kalman filter. I have tried to show you that each of these filters use the same algorithm and reasoning. The mathematics of the Kalman filter that we will learn shortly is fairly sophisticated, and it can be difficult to understand the underlying simplicity of the filter. That sophistication comes with significant benefits: the generalized filter will markedly outperform the filters in this chapter.\n",
|
||||
"\n",
|
||||
"This chapter takes time to assimilate. To truly understand it you will probably have to work through this chapter several times. I encourage you to change the various constants in the code and observe the results. Convince yourself that Gaussians are a good representation of a unimodal belief of the position of a dog in a hallway, the position of an aircraft in the sky, or the temperature of a chemical reaction chamber. Then convince yourself that multiplying Gaussians truly does compute a new belief from your prior belief and the new measurement. Finally, convince yourself that if you are measuring movement, that adding the Gaussians together updates your belief. \n",
|
||||
"\n",
|
||||
|
Loading…
Reference in New Issue
Block a user