Another attempt to remove output - script did not point to ipython

This commit is contained in:
Roger Labbe committed 2014-05-06 09:56:40 -05:00
1 parent 9ae5aea761
commit 71b1b12212
1 file changed
+170 -200
+170 -200
View File
@@ -1,201 +1,171 @@
{
"metadata": {
"name": ""
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#Gaussian Probabilities\n",
"\n",
"#### Introduction\n",
"\n",
"The histogram filter uses a vector or multidimensional array of probabilities to represent our belief of the system state. This is very powerful, but it has limitations. Let us list a few. First, it is multimodal, and we may not want a multimodal result. In other words, we would not want our GPS telling us that we are 50% likely to be here, 40% likely to be there, and so on. There are plenty of techniques to go from a multimodal histogram to a unimodal result, but they all involve significant processing time. This becomes worse as we extend the problem into multiple dimensions. In general for $d$ dimensions the computational run time will be $O(n^d)$. So these filters become intractable in higher dimensions. \n",
"\n",
"Second, the results are hard to analyze. Recall the GPS in your car. It probably has a display that tells you how much error is in the filter - it tells you are at a specific location on the earth, with for example 9 meters of error. How would you derive that information from a histogram filter? There is no clear cut way. Most, if not all of the bins in the histogram will be non-zero, and there will usually be several clusters of higher probabilities. Being multimodal, there is no clear way to derive a single error estimate. Certainly one could come up with a heuristic, but often we want mathematically precise answers, not heuristics.\n",
"\n",
"Third, the histogram is discrete, but we live in a continuous world. The histogram requires that you model the output of your filter as a set of discrete points. In our dog in the hallway example, we used 10 positions, which is obviously far too few positions for anything but a toy problem. For example, for a 100 meter hallway you would need 10,000 positions to model the hallway to 1cm accuracy. So each sense and update operation would entail performing calculations for 10,000 different probabilities. It gets exponentially worse as we add dimensions. If our dog was roaming in a $100x100 m^2$ courtyard, we would need 100,000,000 bins ($10,000^2$) to get 1cm accuracy.\n",
"\n",
"Finally, the histogram does not represent what happens in the pysical world very well. For example, in the last chapter we had this as a probability distribution: [ 0.2245871 0.06288015 0.06109133 0.0581008 0.09334062 0.2245871\n",
" 0.06288015 0.06109133 0.0581008 0.09334062]. The largest probabilities are in position 0 and position 5. This does not fit our physical intuition at all. A dog cannot be in two places at once.\n",
" \n",
" \n",
"Consider how a bimetallic thermometer works. These thermometers use a strip of bimetallic material bent into a loose coil shape, with a pointer attached to the spring. The two metals expand at different rates, so the strip will either coil tighter or uncoil as the temperature changes, and the pointer indicates the current temperature. It is in some ways a crude system, yet it works well. What kinds of errors might we expect from this system? It will not respond to rapid temperature changes, so it will always lag the current temperature a small amount. There may be frictions in the system causing the pointer to not register the correct value. And so on. Finally, when you read the dial you will rarely be exactly perpindicular to the face of the dial. Viewing the pointer against the dial from an angle will result in a small reading error - 34 might look like 35 from the left of the dial, for example. However, in total all of these effects will generally be low, and we would expect the total errors to always be small. We would probably agree that an error of 2 degrees is reasonable, but an error of 100 degrees would occur extremely rarely, if ever. Furthermore, we would expect the errors to cluster around the correct value. So in most systems we would expect the errors to equally likely to be larger or smaller than the correct value. If the correct temperature was 35 degrees, and we were told the thermometer was accurate within 2 degrees, we wouldn't be suprised to read either 33 degrees or 37 degrees. \n",
"\n",
"So we desire a unimodal, continuous way to represent probabilities that models how the real world works, and that is very computationally efficient to calculate. As you might guess from the chapter name, gaussian distributions provide all of these features.\n",
"\n",
"\n",
"#### Probability Distributions\n",
"\n",
"Before we go into the math, lets look at a graph of the gaussian distribution. Don't bother reading the code yet; it is not important at this stage."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import math\n",
"\n",
"def gaussian (x, mu, sigma):\n",
" ''' compute the gaussian with the specified mean(mu) and sigma'''\n",
" return math.exp (-0.5 * (x-mu)**2 / sigma) / math.sqrt(2.*math.pi*sigma)\n"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 1
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%matplotlib inline\n",
"\n",
"xs = arange(0,10,0.1)\n",
"ys = [gaussian (x, 5, 3) for x in xs]\n",
"plot (xs, ys)\n",
"show()"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "display_data",
"png": "iVBORw0KG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bYK6dW2nkZqizl6s+fxzeOstDd/4mgsvNLtivvSS7SRi0wmLfU5ODvHx8cTFxZF5\njP1TN2/eTLdu3Tj11FN58MEHj/hYdHQ0HTt2pHPnznTV3rYB74EHzCEaDRvaTiK/5nLB5MnmYHK9\niA5eHodx3G437dq1Y/ny5URGRtKlSxeys7NJSEioeMzOnTv5+uuvefnll2ncuDETJ06s+Fjr1q35\n8MMPadKkyfEDaBgnIPyyRH/LFjjzTNtp5LfKy6FDB7OqViuaA0ONDuPk5eURGxtLdHQ0oaGhpKen\ns3jx4iMeExYWRnJyMqGhocf8HCrkweGhh8xNWRV631SnDkyaBNOn204itngs9sXFxbRs2bLi7aio\nKIqLiyv9yV0uF3369CE5OZnZmuwbsHbtgrlzdVPW1111FXzxBeTl2U4iNoR4+qDL5TqpT75y5Upa\ntGjBzp07SUtLIz4+np49e57U5xTfM3MmDBwIrVrZTiKehIbCLbeYsXvdrA0+Hot9ZGQkRULine truncated
"text": [
"<matplotlib.figure.Figure at 0x5da42e8>"
]
}
],
"prompt_number": 2
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Probably this is immediately recognizable to you as a 'bell curve'. This curve is ubiquitious because under real world conditions most observations are distributed in such a manner. We will not prove the math here, but the **central limit theorem** proves that under certain conditions the arithmetic mean of independent observations will be distributed in this manner, even if the observations themselves do not have this distribution. In nonmathematical terms, this means that if you take a bunch of measurements from a sensor and use them in a filter, they are very likely to create this distribution.\n",
"\n",
"Before we go further, a moment for terminology. This is variously called a normal distribution, a Gaussian distribution, or a bell curve. However, other distributions also have a bell shaped curve, so that name is somewhat ambiguous, and we will not use it again."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Gaussian Distributions\n",
"\n",
"So let us explore how gaussians work. A gaussian is a continuous probability distribution that is completely described with two parameters, the mean ($\\mu$) and the variance ($\\sigma^2$). It is defined as:\n",
"$$ \n",
"f(x, \\mu, \\sigma) = \\frac{1}{\\sigma\\sqrt{2\\pi}} e^{-0.5*{(x-\\mu)^2}/\\sigma^2 }\n",
"$$"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You will not need to understand how this equation comes about, or remember it for this book, but it is useful to look at it to see how it works. Specifically, notice the term for $e$. When $x==\\mu$, the term reduces to $e^0=1$. Any other value of x will result in a smaller value for the exponent term due to the negative sign, so the curve will always be highest at $x==\\mu$.\n",
"\n",
"Now we will plot a gaussian centered around 23 ($\\mu=23$), with a variance of 1 ($\\sigma^2=1$). "
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"xs = arange(16,30,0.1)\n",
"ys = [gaussian (x,23,1) for x in xs]\n",
"plt.plot (xs,ys, 'r')\n",
"plt.axvline(23); plt.axvline(24) \n",
"plt.show()"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "display_data",
"png": "iVBORw0KGgoAAAANSUhEUgAAAXsAAAEACAYAAABS29YJAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3X10U2WeB/BvoFEE5NUqJamGNqUNtk0LfeFlqmFoqTBO\nhcqc6VnfZuxoh12GYZzxuLNnZwTXszPVcTloXa3MyOroVmbFobpARIZGWRSC0OHFwqFAKyEI8k4p\nL23TZ/+4ptK3NGmTPPcm3885HJvkPvf+WnO/ffrkPs/VCSEEiIgoog2SXQAREYUew56IKAow7ImI\nogDDnogoCjDsiYiiAMOeiCgK9Bn2drsdKSkpSEpKQnl5ea/b7dixAzExMVizZk3AbYmIKLR0vq6z\n93g8SE5OxqZNm2AwGJCdnY2qqipYLJZu2xUUFGDo0KH48Y9/jPvvv9/vtkREFHo+e/ZOpxNmsxkm\nkwl6vR4lJSWorq7utt1LL72EBQsWIDY2NuC2REQUej7D3u12Iz4+vuOx0WiE2+3utk11dTUWLlwI\nANDpdH63JSKi8PAZ9t7g9mXJkiX4/e9/D51OByEEvKNC/rQlIqLwiPH1osFggMvl6njscrlgNBo7\nbbNz506UlJQAAE6fPo0NGzZAr9f71RY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FxAIDY2FjMnzLine truncated
"text": [
"<matplotlib.figure.Figure at 0x84d8400>"
]
}
],
"prompt_number": 3
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"As we expected the curve is centered around 23. The width of the curve is defined by the variance. If the variance is large than the curve will be wide, and if the variance is small the curve will be narrow.\n",
"\n",
"So what does this curve *mean*? Assume for a moment that we have a themometer that reads 23$\\,^{\\circ}$. We have asserted (without proof) that the distribution will be *normal*. If that is true, then this chart can be interpreted as a continuous curve depicting our belief that the temperature is any given temperature. In this curve, we assign a probability of the temperature being exactly 23$\\,^{\\circ}$ is 40%. Looking to the right, we assign the probability that the temperature is 24$\\,^{\\circ}$ is about 25%. We find 20$\\,^{\\circ}$ and 26$\\,^{\\circ}$ quite unlikely, and temperatures beyond that range extremely rare. \n",
"\n",
"Since this is a probability distribution it is required that the area under the curve always equals one. This should be intuitively clear - the area under the curve represents all possible occurances, which must sum to one.\n",
"\n",
"This leads to an important insight. If the variance is small the curve will be narrow. To keep the area == 1, the curve must also be tall. On the other hand if the variance is large the curve will be wide, and thus it will also have to be short to make the area == 1.\n",
"\n",
"Let us look at that:"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"plt.plot (xs,[gaussian(x, 23, .2) for x in xs],'b')\n",
"plt.plot (xs,[gaussian(x, 23, 1) for x in xs],'g')\n",
"plt.plot (xs,[gaussian(x, 23, 5) for x in xs],'r')\n",
"plt.show()"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "display_data",
"png": "iVBORw0KGgoAAAANSUhEUgAAAXUAAAEACAYAAABMEua6AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3XlclNX+B/DPwIwiLqDgOoOiDJuhgIKoaU65oF5D2wxb\nXEIjzcy6P7PtFmZ5pfK2SCndq6ZliKWJFmJuo6blaJqUuOCCDiMqi4iCMDBzfn8cQdaBgWf27/v1\nmpezPHOeb8R85nCe5zlHxBhjIIQQYh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ublAd27C98+IUIw2FNXqVSQy+Xw9vaGRCJBdHQ0UlJS6mxHKxoRa2KqnjpAC1AT62cw1DUa\nDby8vKoey2QyaDSaGtuIRCIcOnQIwcHBGD9+PDIyMkxTKSFNZKqeOkDj6sT6GRx+ETVhLbABAwZA\nrVbD1dUV27dvx6RJk3D27FnBCiTEWHl5wMCBpmmbeurE2hkMdalUCrVaXfVYrVZDJpPV2KZ9+/ZV\n98eNG4c5c+agoKAAneq58iMuLq7qvkKhgEKhaGbZhDSMeurElimVSiiVyma/X8QMDIhXVFTA398f\nu3fvRo8ePTBo0CAkJSXVOFB67do1dOnSBSKRCCqVCpMnT0ZWVlbdHRm5IjYhzTVwIJCYCILine truncated
"text": [
"<matplotlib.figure.Figure at 0x86255c0>"
]
}
],
"prompt_number": 4
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"So what is this telling us? The blue gaussian is very narrow. It is saying that we believe x=23, and that we are very sure about that. In contrast, the red gaussian also believes that x=23, but we are much less sure about that. Our believe that x=23 is lower, and so our belief about the likely possible values for x is spread out - we think it is quite likely that x=2 or x=8, for example. The blue gaussian has almost completely eliminated 22 or 24 as possible value - their probably is almost 0.0, whereas the red curve considers them nearly as likely as 23.\n",
"\n",
"If we think back to the thermometer, we can consider these three curves as representing 3 thermometers. The blue curve represents a very accurate thermometer, and the red one represents a fairly inaccurate one. Green of course represents one in between the two others. Note the very powerful property the Gaussian distribution affords us - we can entirely represent both the reading and the error of a thermometer with only two numbers - the mean and the variance.\n",
"\n",
"The standard notation for a normal distribution is just $N(\\mu,\\sigma^2)$. I will not go into detail as to why $\\sigma^2$ is used, other than to note that $\\sigma$ is commonly called the *standard deviation*, which has enormous utility in statistics. The standard deviation is not really used in this book, so I will not address it further. The important thing to understand is that the variance ($\\sigma^2$) is a measure of the width of the curve. The curve above is notated as $N(23, 1)$, since $\\mu=23$ and $\\sigma=1$. We will use this notiation throughout the rest of the book, so learn it now.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Computational Properties of the Gaussian\n",
"\n",
"Recall how our histogram filter worked. We had a vector (Python array) representing our belief at a certain moment in time. When we performed another measurement using the *sense()* function we had to multiply probabilities together, and when we performed the motion step using the *update()* function we had to shift and add probabilities. I've promised you that the Kalman filter uses essentially the same process, and that it uses Gaussians instead of histograms, so you might reasonable expect that we will be multipling, adding, and shifting Gaussians in the Kalman filter.\n",
"\n",
"A typical math book would directly launch into a multipage proof of the behavior of Gaussians under these operations, but I don't see the value in that unless you plan to do statistics. I think the math will be much more intuitive and clear if we just start developing a Kalman filter using Gaussians, and I will provide the equations for multiplying and shifting Gaussians at the appropriate time. You will then be able to develop a physical intuition for what these operations do, rather than be forced to digest a lot of fairly abstract math.\n",
"\n",
"The key point, which I will only assert for now, is that all the operations are very simple, and that they preserve the properties of the Gaussian. This is somewhat remarkable, in that the Gaussian is a nonlinear function, and typically if you multiply a nonlinear equation with itself you end up with a different equation. For example, the shape of $sin(x)sin(x)$ is very different from $sin(x)$. But the result of multiplying two Gaussians is yet another Gaussian. This is a fundamental discovery, and the key reason why Kalman filters are possible\n",
"\n",
"\n",
"#### Summary and Key Points"
]
}
],
"metadata": {}
}
]
{
"metadata": {
"name": "",
"signature": "sha256:7987517a7cb3fbbd21339999a44f481804ef1719e02dea0e02c2456b42d2d036"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#Gaussian Probabilities\n",
"\n",
"#### Introduction\n",
"\n",
"The histogram filter uses a vector or multidimensional array of probabilities to represent our belief of the system state. This is very powerful, but it has limitations. Let us list a few. First, it is multimodal, and we may not want a multimodal result. In other words, we would not want our GPS telling us that we are 50% likely to be here, 40% likely to be there, and so on. There are plenty of techniques to go from a multimodal histogram to a unimodal result, but they all involve significant processing time. This becomes worse as we extend the problem into multiple dimensions. In general for $d$ dimensions the computational run time will be $O(n^d)$. So these filters become intractable in higher dimensions. \n",
"\n",
"Second, the results are hard to analyze. Recall the GPS in your car. It probably has a display that tells you how much error is in the filter - it tells you are at a specific location on the earth, with for example 9 meters of error. How would you derive that information from a histogram filter? There is no clear cut way. Most, if not all of the bins in the histogram will be non-zero, and there will usually be several clusters of higher probabilities. Being multimodal, there is no clear way to derive a single error estimate. Certainly one could come up with a heuristic, but often we want mathematically precise answers, not heuristics.\n",
"\n",
"Third, the histogram is discrete, but we live in a continuous world. The histogram requires that you model the output of your filter as a set of discrete points. In our dog in the hallway example, we used 10 positions, which is obviously far too few positions for anything but a toy problem. For example, for a 100 meter hallway you would need 10,000 positions to model the hallway to 1cm accuracy. So each sense and update operation would entail performing calculations for 10,000 different probabilities. It gets exponentially worse as we add dimensions. If our dog was roaming in a $100x100 m^2$ courtyard, we would need 100,000,000 bins ($10,000^2$) to get 1cm accuracy.\n",
"\n",
"Finally, the histogram does not represent what happens in the pysical world very well. For example, in the last chapter we had this as a probability distribution: [ 0.2245871 0.06288015 0.06109133 0.0581008 0.09334062 0.2245871\n",
" 0.06288015 0.06109133 0.0581008 0.09334062]. The largest probabilities are in position 0 and position 5. This does not fit our physical intuition at all. A dog cannot be in two places at once.\n",
" \n",
" \n",
"Consider how a bimetallic thermometer works. These thermometers use a strip of bimetallic material bent into a loose coil shape, with a pointer attached to the spring. The two metals expand at different rates, so the strip will either coil tighter or uncoil as the temperature changes, and the pointer indicates the current temperature. It is in some ways a crude system, yet it works well. What kinds of errors might we expect from this system? It will not respond to rapid temperature changes, so it will always lag the current temperature a small amount. There may be frictions in the system causing the pointer to not register the correct value. And so on. Finally, when you read the dial you will rarely be exactly perpindicular to the face of the dial. Viewing the pointer against the dial from an angle will result in a small reading error - 34 might look like 35 from the left of the dial, for example. However, in total all of these effects will generally be low, and we would expect the total errors to always be small. We would probably agree that an error of 2 degrees is reasonable, but an error of 100 degrees would occur extremely rarely, if ever. Furthermore, we would expect the errors to cluster around the correct value. So in most systems we would expect the errors to equally likely to be larger or smaller than the correct value. If the correct temperature was 35 degrees, and we were told the thermometer was accurate within 2 degrees, we wouldn't be suprised to read either 33 degrees or 37 degrees. \n",
"\n",
"So we desire a unimodal, continuous way to represent probabilities that models how the real world works, and that is very computationally efficient to calculate. As you might guess from the chapter name, gaussian distributions provide all of these features.\n",
"\n",
"\n",
"#### Probability Distributions\n",
"\n",
"Before we go into the math, lets look at a graph of the gaussian distribution. Don't bother reading the code yet; it is not important at this stage."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import math\n",
"\n",
"def gaussian (x, mu, sigma):\n",
" ''' compute the gaussian with the specified mean(mu) and sigma'''\n",
" return math.exp (-0.5 * (x-mu)**2 / sigma) / math.sqrt(2.*math.pi*sigma)\n"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%matplotlib inline\n",
"\n",
"xs = arange(0,10,0.1)\n",
"ys = [gaussian (x, 5, 3) for x in xs]\n",
"plot (xs, ys)\n",
"show()"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Probably this is immediately recognizable to you as a 'bell curve'. This curve is ubiquitious because under real world conditions most observations are distributed in such a manner. We will not prove the math here, but the **central limit theorem** proves that under certain conditions the arithmetic mean of independent observations will be distributed in this manner, even if the observations themselves do not have this distribution. In nonmathematical terms, this means that if you take a bunch of measurements from a sensor and use them in a filter, they are very likely to create this distribution.\n",
"\n",
"Before we go further, a moment for terminology. This is variously called a normal distribution, a Gaussian distribution, or a bell curve. However, other distributions also have a bell shaped curve, so that name is somewhat ambiguous, and we will not use it again."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Gaussian Distributions\n",
"\n",
"So let us explore how gaussians work. A gaussian is a continuous probability distribution that is completely described with two parameters, the mean ($\\mu$) and the variance ($\\sigma^2$). It is defined as:\n",
"$$ \n",
"f(x, \\mu, \\sigma) = \\frac{1}{\\sigma\\sqrt{2\\pi}} e^{-0.5*{(x-\\mu)^2}/\\sigma^2 }\n",
"$$"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You will not need to understand how this equation comes about, or remember it for this book, but it is useful to look at it to see how it works. Specifically, notice the term for $e$. When $x==\\mu$, the term reduces to $e^0=1$. Any other value of x will result in a smaller value for the exponent term due to the negative sign, so the curve will always be highest at $x==\\mu$.\n",
"\n",
"Now we will plot a gaussian centered around 23 ($\\mu=23$), with a variance of 1 ($\\sigma^2=1$). "
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"xs = arange(16,30,0.1)\n",
"ys = [gaussian (x,23,1) for x in xs]\n",
"plt.plot (xs,ys, 'r')\n",
"plt.axvline(23); plt.axvline(24) \n",
"plt.show()"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"As we expected the curve is centered around 23. The width of the curve is defined by the variance. If the variance is large than the curve will be wide, and if the variance is small the curve will be narrow.\n",
"\n",
"So what does this curve *mean*? Assume for a moment that we have a themometer that reads 23$\\,^{\\circ}$. We have asserted (without proof) that the distribution will be *normal*. If that is true, then this chart can be interpreted as a continuous curve depicting our belief that the temperature is any given temperature. In this curve, we assign a probability of the temperature being exactly 23$\\,^{\\circ}$ is 40%. Looking to the right, we assign the probability that the temperature is 24$\\,^{\\circ}$ is about 25%. We find 20$\\,^{\\circ}$ and 26$\\,^{\\circ}$ quite unlikely, and temperatures beyond that range extremely rare. \n",
"\n",
"Since this is a probability distribution it is required that the area under the curve always equals one. This should be intuitively clear - the area under the curve represents all possible occurances, which must sum to one.\n",
"\n",
"This leads to an important insight. If the variance is small the curve will be narrow. To keep the area == 1, the curve must also be tall. On the other hand if the variance is large the curve will be wide, and thus it will also have to be short to make the area == 1.\n",
"\n",
"Let us look at that:"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"plt.plot (xs,[gaussian(x, 23, .2) for x in xs],'b')\n",
"plt.plot (xs,[gaussian(x, 23, 1) for x in xs],'g')\n",
"plt.plot (xs,[gaussian(x, 23, 5) for x in xs],'r')\n",
"plt.show()"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"So what is this telling us? The blue gaussian is very narrow. It is saying that we believe x=23, and that we are very sure about that. In contrast, the red gaussian also believes that x=23, but we are much less sure about that. Our believe that x=23 is lower, and so our belief about the likely possible values for x is spread out - we think it is quite likely that x=2 or x=8, for example. The blue gaussian has almost completely eliminated 22 or 24 as possible value - their probably is almost 0.0, whereas the red curve considers them nearly as likely as 23.\n",
"\n",
"If we think back to the thermometer, we can consider these three curves as representing 3 thermometers. The blue curve represents a very accurate thermometer, and the red one represents a fairly inaccurate one. Green of course represents one in between the two others. Note the very powerful property the Gaussian distribution affords us - we can entirely represent both the reading and the error of a thermometer with only two numbers - the mean and the variance.\n",
"\n",
"The standard notation for a normal distribution is just $N(\\mu,\\sigma^2)$. I will not go into detail as to why $\\sigma^2$ is used, other than to note that $\\sigma$ is commonly called the *standard deviation*, which has enormous utility in statistics. The standard deviation is not really used in this book, so I will not address it further. The important thing to understand is that the variance ($\\sigma^2$) is a measure of the width of the curve. The curve above is notated as $N(23, 1)$, since $\\mu=23$ and $\\sigma=1$. We will use this notiation throughout the rest of the book, so learn it now.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Computational Properties of the Gaussian\n",
"\n",
"Recall how our histogram filter worked. We had a vector (Python array) representing our belief at a certain moment in time. When we performed another measurement using the *sense()* function we had to multiply probabilities together, and when we performed the motion step using the *update()* function we had to shift and add probabilities. I've promised you that the Kalman filter uses essentially the same process, and that it uses Gaussians instead of histograms, so you might reasonable expect that we will be multipling, adding, and shifting Gaussians in the Kalman filter.\n",
"\n",
"A typical math book would directly launch into a multipage proof of the behavior of Gaussians under these operations, but I don't see the value in that unless you plan to do statistics. I think the math will be much more intuitive and clear if we just start developing a Kalman filter using Gaussians, and I will provide the equations for multiplying and shifting Gaussians at the appropriate time. You will then be able to develop a physical intuition for what these operations do, rather than be forced to digest a lot of fairly abstract math.\n",
"\n",
"The key point, which I will only assert for now, is that all the operations are very simple, and that they preserve the properties of the Gaussian. This is somewhat remarkable, in that the Gaussian is a nonlinear function, and typically if you multiply a nonlinear equation with itself you end up with a different equation. For example, the shape of $sin(x)sin(x)$ is very different from $sin(x)$. But the result of multiplying two Gaussians is yet another Gaussian. This is a fundamental discovery, and the key reason why Kalman filters are possible\n",
"\n",
"\n",
"#### Summary and Key Points"
]
}
],
"metadata": {}
}
]
}