A while without posting…
Well, this is part of a set of exercises that I’ll be solving for, you know, personal stuff. I’ll do Copy-Paste of some stuff just to set the context and the idea, which was taken from the book Numerical Methods Using Matlab by John H. Mathews and Kurtis K. Fink. The implementation shown at the end was done all by me using Python.
Nelder-Mead Method
A simplex method for finding a local minimum of a function of several variables has been devised by Nelder and Mead. For two variables, a simplex is a triangle, and the method is a pattern search that compares function values at the three vertices of a triangle. The worst vertex, where is largest, is rejected and replaced with a new vertex. A new triangle is formed and the search is continued. The process generates a sequence of triangles (which might have different shapes), for which the function values at the vertices get smaller and smaller. The size of the triangles is reduced and the coordinates of the minimum point are found.
The algorithm is stated using the term simplex (a generalized triangle in dimensions) and will find the minimum of a function of variables. It is effective and computationally compact.
Initial Triangle BGW
Let be the function that is to be minimized. To start, we are given three vertices of a triangle: , . The function is then evaluated at each of the three points: for . The subscripts are then reordered so that . We use the notation
, , and
to help remember that is the best vertex, is good (next to best), and is the worst vertex.
Midpoint of the Good Side
The construction process uses the midpoint of the line segment joining and . It is found by averaging the coordinates:
.
Reflection Using the Point
The function decreases as we move along the side of the triangle from to , and it decreases as we move along the side from to . Hence it is feasible that takes on smaller values at points that lie away from W on the opposite side of the line between and . We choose a test point that is obtained by “reflecting” the triangle through the side . To determine , we first find the midpoint of the side . Then draw the line segment from to and call its length . This last segment is extended a distance through to locate the point (see Figure 8.6). The vector formula for is
.
Expansion Using the Point
If the function value at is smaller than the function value at , then we have moved in the correct direction toward the minimum. Perhaps the minimum is just a bit farther than the point . So we extend the line segment through and to the point . This forms an expanded triangle . The point is found by moving an additional distance along the line joining and (see Figure 8.7). If the function value at is less than the function value at , then we have found a better vertex than . The vector formula for is
.
Contraction Using the Point
If the function values at and are the same, another point must be tested. Perhaps the function is smaller at , but we cannot replace with because we must have a triangle. Consider the two midpoints and of the line segments and , respectively (see Figure 8.8). The point with the smaller function value is called , and the new triangle is . Note. The choice between and might seem inappropriate for the two-dimensional case, but it is important in higher dimensions.
Shrink toward
If the function value at is not less than the value at , the points and must be shrunk toward (see Figure 8.9). The point is replaced with , and is replaced with , which is the midpoint of the line segment joining with .
Logical Decisions for Each Step
A computationally efficient algorithm should perform function evaluations only if needed. In each step, a new vertex is found, which replaces . As soon as it is found, further investigation is not needed, and the iteration step is completed. The logical details for two-dimensional cases are explained in Table 8.5.
Testing the implementation on a provided example
Use the Nelder-Mead algorithm to find the minimum of . Start with the three vertices
.
The process done in the example generates a sequence of triangles that converges down on the solution point (see Figure 8.10). Table 8.6 gives the function values at vertices of the triangle for several steps in the iteration. (Again, this results are given by the author, my implementation results are presented at the end.)
Now, my results are shown. The 3D plot of the graph in looks as follows:
So, it’s easy to see that this function has a local minimum. Now, running the code for 10 iterations, we obtain the following data:
The iterative plotting in two dimensions (because a picture is worth a thousand words) of the approximation to the local minimum is shown below. The cyan triangle is the current triangle in the iteration, and the red dot is the current minimum.
I hope you find this post useful, even without explaining the code (check my Github for it).
References:
- Numerical Methods Using Matlab, 4th Edition, 2004. John H. Mathews and Kurtis K. Fink.
- NumPy Reference. (https://docs.scipy.org/doc/numpy/reference/)
- Matplotlib. (http://matplotlib.org/)
One thought on “Nelder-Mead Method”