Problem statement
Consider a function which is the sum of two Gaussian bumps. For given values of the mean and standard deviation for each bump, that sum is a function of two variables.
Let's take a look at the contours of that function. We'll choose the mean and standard deviation of the Gaussian bumps. I pulled these values out of a hat.
The problem is this: staying on one of the contours of F, try to get as close as possible to a given point (x1, y1). This problem is stated in this post on Stack Overflow: Calculate inverse of normal function that minimizes another function
Motivation of solution
At the point on the contour closest to (x1, y1), a circle centered on (x1, y1) is tangent to the contour, and therefore just touches the contour. As one travels around that circle, the value of F rises and falls, and has a local extremum at the tangent point. When the circle is too small, it doesn't touch the chosen contour. When the circle is too big, it crosses the contour (not tangent). So to find the right circle, and therefore the tangent location, we'll vary the size until there is a local extremum equal to the chosen contour. This is expressed by maximizing or minimizing the value of F on the circle (function fmax_circular) within solving the equation max/min of F = contour (function find_root). fmax_circular makes use of fargmax1, which is an implementation of golden section search (purpose-built, not built-in). find_root is built-in.
Solution
Choose the point to which we want to get close.
Choose the contour level on which we want to stay while we try to get close to (x1, y1).
Load a script to define the functions needed to solve the problem. (You can find the script here.)
Find the distance, r0, from (x1, y1) to the nearest point on the contour F(x, y) = z0.
⇒ |
Find the tangent point on the circle of radius r0 centered on (x1, y1). fargmax_circular returns a list; assume it's just one element. That's not guaranteed to work, since [t0] : ... fails when right-hand side has 2 or more elements. I expect that happens rarely, if ever.
⇒ |
(x0, y0) is the point on z0 contour of F, nearest to (x1, y1). r0 is distance from (x1, y1) to (x0, y0).
⇒ |
F(x0, y0) should be equal to z0.
⇒ |
⇒ |
If we draw the contour F(x, y) = z0, we should find it just touches the circle of radius r0 centered on (x1, y1).
No comments:
Post a Comment