diff --git a/12-Particle-Filters.ipynb b/12-Particle-Filters.ipynb index 3425050..4f6d48f 100644 --- a/12-Particle-Filters.ipynb +++ b/12-Particle-Filters.ipynb @@ -425,9 +425,11 @@ "metadata": {}, "source": [ "## Probability distributions via MC\n", - "Suppose we want to know the area under the curve $y= \\mathrm{e}^{\\sin(x)}$ in the interval [0, $\\pi$]. We can compute the area with the definite integral $\\int_0^\\pi \\mathrm{e}^{\\sin(x)}\\, \\mathrm{d}x$. As an exercise, go ahead and compute the answer; I'll wait. If you are wise you did not take that challenge; $y= \\mathrm{e}^{\\sin(x)}$ cannot be integrated and so you can not find the answer this way.\n", + "Suppose we want to know the area under the curve $y= \\mathrm{e}^{\\sin(x)}$ in the interval [0, $\\pi$]. We can compute the area with the definite integral $\\int_0^\\pi \\mathrm{e}^{\\sin(x)}\\, \\mathrm{d}x$. As an exercise, go ahead and compute the answer; I'll wait. If you are wise you did not take that challenge; $y= \\mathrm{e}^{\\sin(x)}$ cannot be integrated and so you can not find the answer this way. \n", "\n", - "However, this is trivial to compute using a Monte Carlo technique. Create a bounding box that contains the curve in the desired interval, generate random pairs $(x,y)$, and count how many fall under the curve. Multiply the area of the bounding box by the ratio of points that were under the curve vs the total number of points and you will have computed the are under the curve. As you tend towards infinite points you can achieve any arbitrary precision. In practice, a few thousand points will give you a fairly accurate result.\n", + "The world is filled with equations which we cannot integrate. We cannot integrate something as simple as $\\int_a^b x^x\\, \\mathrm{d}x$. For a realistic example from physics, think of how we calculate luminosity of an object. An object reflects light. Some of that light bounces off of other objects and *restrikes* the original object, increasing the luminosity. This creates a **recursive integral**. Good luck with that one.\n", + "\n", + "However, these are trivial to compute using a Monte Carlo technique. Create a bounding box that contains the curve in the desired interval, generate random pairs $(x,y)$, and count how many fall under the curve. Multiply the area of the bounding box by the ratio of points that were under the curve vs the total number of points and you will have computed the are under the curve. As you tend towards infinite points you can achieve any arbitrary precision. In practice, a few thousand points will give you a fairly accurate result.\n", "\n", "Think of how powerful this technique is. You can use it to numerically integrate any function. The function can be of any arbitrary difficulty, including being non integrable and noncontinuous, and yet we can trivially find the answer. \n", "\n", @@ -436,7 +438,7 @@ "We start by creating the points.\n", "\n", "```python\n", - " N = 20ch000\n", + "N = 20000\n", "ps = uniform(-1, 1, (N, 2))\n", "```\n", "\n", @@ -511,7 +513,7 @@ "\n", "$$A = \\int_0^{2\\pi r} 2\\pi t\\, dt = \\pi r^2 $$\n", "\n", - "The Monte Carlo technique does something very similar by summing the infinite number of points inside the circle. Computers can't sum infinities, so we settle for a representative sampling of points and less than infinite precision in the results. Using Monte Carlo for this problem is remarkably unnecessary, but imagine instead trying to find the area inside a fractal Mandelbrot set. As far as I know there is no analytic solution to that problem, yet we could use the code above to find the answer. MC is a powerful tool to reach for when analysis fails. \n", + "The Monte Carlo technique does something very similar by summing the infinite number of points inside the circle. Computers can't sum infinities, so we settle for a representative sampling of points and less than infinite precision in the results. Using Monte Carlo for this problem is remarkably unnecessary, but imagine instead trying to compute the recursive integral for luminosity that I mentioned. As far as I know there is no analytic solution to that problem, yet we could use the code above to find the answer. MC is a powerful tool to reach for when analysis fails. \n", "\n", "This insight leads us to the realization that we can use Monte Carlo to compute the probability density of any probability distribution. For example, suppose we have a Gaussian. The Gaussian has a probability distribution as shown below." ]