The Nelder-Mead Method in Two Dimensions
by Greg Spradlin, Embry-Riddle Aeronautical University, USA,
spradlig@erau.edu,
2003 Greg Spradlin.
NOTE: This worksheet demonstrates the use of Maple for finding a local minimum of a function of two variables, using the Nelder-Mead method.
Introduction: The Nelder-Mead Method
This worksheet illustrates the Nelder-Mead Method of unconstrained nonlinear optimization. The Nelder-Mead method does not require the objective function f to be differentiable. Therefore it is well-suited to problems involving a non-differentiable objective function of a small number of decision variables. This worksheet applies the method to any function of two variables. The user enters the function, the initial simplex (triangle), and the desired accuracy. The minimum value and its location are returned, along with a list of all simplices produced during the method and the actions taken, plus a plot of all the simplices.
The Nelder-Mead Method: a summary
The method used here is described in Rardin (see References) for an arbitrary number of decision variables and repeated here for the special case of two decision variables. Begin with an initial simplex, or triangle, of three non-conlinear points y (1), y (2), and y (3). Arrange them in "nonimproving" order, so if searching for a minimum, f ( y (1)) <= f ( y (2)) <= f ( y (3)) . The idea is to move the "worst" point y (3) towards the "better" points y (1) and y (2) in the hopes of improving the objective function.
Step 1: Centroid
Let x = ( y (1) + y (2))/2, the mean of the best two points.
Step 2: Direction
Let the away-from-worst-move direction x = x - y (3), the vector from the worst point y (3) to x .
Step 3: Attempt Reflection
Compute f ( x + x ) . If f ( x + x ) <= f ( y (1)), that is, if x + x is at least as good as y (1), then proceed to Step 4 : Attempt Expansion. If f ( y (1)) < f ( x + x ) <= f ( y (2)), then replace y (3) with x + x . This is called " reflection ," since the new triangle is the previous triangle reflected over the side y (1)- y (2). If f ( x + x ) > f ( y (2)), proceed to Step 5: Attempt Contraction.
Step 4: Attempt Expansion
Compute f ( x + 2 x ). If f ( x + 2 x ) <= f ( x + x ), that is, if x + 2 x is at least as good as x + x , then replace y (3) with x+ 2 x . This is called " expansion ", for the new simplex (triangle) is larger than the previous one. If, however, f ( x + 2 x ) > f ( x + x ), that is, x + 2 x is no better than x + x , replace y (3) with x + x . This is called " reflection ," since the new triangle is the previous triangle reflected over the side y (1)- y (2).
Step 5: Attempt Contraction
If f ( x + x /2) < f ( y (3)), that is, x + x /2 is better than the current worst y (3), replace y (3) with x + x/ 2. Following Lagarias et al (see References) we call this step outside contraction , because the new simplex is half the size of the previous one and outside of it. If f ( x + x /2) >= f ( y (3)), then evaluate f ( x - x /2). If f ( x - x /2) < f ( y (3)), then replace y (3) with x - x/ 2. We call this inside contraction , because the new simplex is half the size of the previous one and inside it. If both x + x /2 and x - x /2 are worse than current worst y (3), that is, f ( x + x /2) > f ( y (3)) and
f ( x - x /2) > f ( y (3)) , then shrink the simplex toward y (1) as described below.
Step 5: Shrinking
Shrink the simplex toward the best point y (1) by replacing y (2) with ( y (1) + y (2))/2 and
y (3) with ( y (1) + y (3))/2. All three sides of the triangle have been halved in length.
Termination:
After Reflection, Expansion, Contraction, or Shrinking has been performed, reorder the y 's if necessary so f ( y (1)) <= f ( y (2)) <= f ( y (3)) . Repeat the process until f ( y (1)), f ( y (2)), and f ( y (3)) are all within a predetermined tolerance from f ( x + x ) (described in Step 3). Report the smallest of f ( y (1)), f ( y (2)), f ( y (3)) and f ( x ) as the minimum and report its location. Note that there are five ways to get from one simplex to the next: reflection, expansion, outside contraction, inside contraction, and shrinking.
The Algorithm
Enter, plot objective function, viewing window
Warning, the name changecoords has been redefined
Enter initial simplex, stopping tolerance
Create function acting on points
Procedure for ordering points by objective function values
Create first simplex
Procedure for deciding which action to perform on simplex
Execution of algorithm
Print list of simplices, actions
Simplex Number 0: (1.500000,0.000000),(2.000000,.500000),(2.000000,0.000000) Inside Contraction
Simplex Number 1: (1.250000,.750000),(1.500000,0.000000),(2.000000,.500000) Inside Contraction
Simplex Number 2: (.125000,.125000),(1.250000,.750000),(1.500000,0.000000) Reflect
Simplex Number 3: (-.125000,.875000),(.125000,.125000),(1.250000,.750000) Outside Contraction
Simplex Number 4: (-.125000,.875000),(-.625000,.375000),(.125000,.125000) Inside Contraction
Simplex Number 5: (-.125000,.875000),(-.625000,.375000),(-.125000,.375000) Reflect
Simplex Number 6: (-.125000,.875000),(-.625000,.875000),(-.625000,.375000) Inside Contraction
Simplex Number 7: (-.125000,.875000),(-.500000,.625000),(-.625000,.875000) Inside Contraction
Simplex Number 8: (-.468750,.812500),(-.125000,.875000),(-.500000,.625000) Outside Contraction
Simplex Number 9: (-.195313,.953125),(-.468750,.812500),(-.125000,.875000) Inside Contraction
Simplex Number 10: (-.195313,.953125),(-.228516,.878906),(-.468750,.812500) Reflect
Simplex Number 11: (.044922,1.019531),(-.195313,.953125),(-.228516,.878906) Inside Contraction
Simplex Number 12: (.044922,1.019531),(-.151855,.932617),(-.195313,.953125) Inside Contraction
Simplex Number 13: (-.124390,.964600),(.044922,1.019531),(-.151855,.932617) Inside Contraction
Simplex Number 14: (-.095795,.962341),(-.124390,.964600),(.044922,1.019531) Inside Contraction
Simplex Number 15: (-.032585,.991501),(-.095795,.962341),(-.124390,.964600) Inside Contraction
Simplex Number 16: (-.032585,.991501),(-.094290,.970760),(-.095795,.962341) Inside Contraction
Simplex Number 17: (-.079616,.971736),(-.032585,.991501),(-.094290,.970760) Reflect
Simplex Number 18: (-.079616,.971736),(-.017911,.992476),(-.032585,.991501) Inside Contraction
Simplex Number 19: (-.040674,.986804),(-.079616,.971736),(-.017911,.992476) Outside Contraction
Simplex Number 20: (-.081262,.972666),(-.040674,.986804),(-.079616,.971736) Inside Contraction
Simplex Number 21: (-.070292,.975735),(-.081262,.972666),(-.040674,.986804) Outside Contraction
Simplex Number 22: (-.070292,.975735),(-.093329,.967900),(-.081262,.972666) Inside Contraction
Simplex Number 23: (-.070292,.975735),(-.081536,.972242),(-.093329,.967900) Reflect
Simplex Number 24: (-.058500,.980078),(-.070292,.975735),(-.081536,.972242) Inside Contraction
Simplex Number 25: (-.072966,.975074),(-.058500,.980078),(-.070292,.975735) Inside Contraction
Simplex Number 26: (-.072966,.975074),(-.058500,.980078),(-.068013,.976656) Outside Contraction
Simplex Number 27: (-.072966,.975074),(-.064593,.978036),(-.058500,.980078) Inside Contraction
Simplex Number 28: (-.063640,.978317),(-.072966,.975074),(-.064593,.978036) Inside Contraction
Simplex Number 29: (-.066448,.977366),(-.063640,.978317),(-.072966,.975074) Inside Contraction
Simplex Number 30: (-.066448,.977366),(-.069005,.976458),(-.063640,.978317) Inside Contraction
Simplex Number 31: (-.065683,.977614),(-.066448,.977366),(-.069005,.976458) Outside Contraction
Simplex Number 32: (-.064596,.978006),(-.065683,.977614),(-.066448,.977366) Inside Contraction
Simplex Number 33: (-.065794,.977588),(-.064596,.978006),(-.065683,.977614) Inside Contraction
Draw simplices
Warning, the name arrow has been redefined
Final Answer
The minimum value,
occurs at
References
Lagarias, J.C., Reeds, J.A., Wright, M.H., and Wright, P.E. (1998). Convergence Properties of the Nelder-Mead
Simplex Method in Low Dimensions. SIAM J. Optim ., 9 , 112-147
Nelder, J.A. and Mead, R. (1965). A simplex method for function optimization, Computer J ., 7 , 308-313.
Rardin, R.L. (1997). Optimization in Operations Research , Prentice-Hall.
Walters, F.H., Parker, L.R., Morgan, S.L., and Deming, S.N. (1991). Sequential Simplex Optimization , CRC Press.
Conclusion
This worksheet shows the Nelder-Mead in action and gives a list of simplices constructed, actions taken, and a plot of all simplices, automatically scaled to display the simplices. Maple is ideal for running the algorithm due to its convenient graphics capabilities. Running the program reveals typical behavior of the algorithm. For example, if the initial simplex is far from a minimum, there may be several expansion steps during which the simplex moves toward the minimum point. The shrinking step rarely occurs; rather, the simplex converges to a point via contraction.
A natural extension of this work would be to generalize the algorithm to alter the change in size of a simplex during the reflection, expansion, and contraction steps (see Lagarias et al ). Another would be to run the algorithm with more than two decision variables. In the case of three decision variables, Maple's interactive three-dimensional graphics can display the tetrahedral simplices.
Disclaimer: While every effort has been made to validate the solutions in this worksheet, Waterloo Maple Inc. and the contributors are not responsible for any errors contained and are not liable for any damages resulting from the use of this material.