(42S) HP 42S/ DM42: Nelder Mead Optimization
05-01-2020, 05:14 AM (This post was last modified: 05-01-2020 03:13 PM by rawi.)
Post: #3
 rawi Member Posts: 91 Joined: Nov 2019
RE: HP 42S/ DM42: Nelder Mead Optimization
Hi,

Thank you very much for your interest.

First some explanation concerning the code:

Use of registers:
00 --> Minimum termination criterion
19 --> Factor for reflection

______Simplex___*)_new point
x_____05_08_11_14_16
y_____06_09_12_15_17
f(x,y)__07_10_13____18

*) center for reflection: Mean of best and second best value

Values of simplex are sorted so that 07 is the minimum and 13 the maximum

The code:
Steps 2 to 17: Building the simplex
18 - 22: Computing function values
23: Sorting the simplex so that 05, 06, 07 is the minimum 11, 12, 13 the maximum
25 - 36: computing the center for reflection
37: Optimization explanation see later
38 - 60: computing of termination criterion
This is a change to the original Nelder Mead method, where the termination criterion is the differences in function values f(x,y). I thought it is better to take the differences of the x and y values instead.
61 - 63: Comparison of termination criterion with minimum termination criterion. Continue process if not yet reached.
64 - 67: final steps and end of program
68 - 106: Sorting the points of the simplex.
107 - 157: Optimization procedure
108 - 109: Sets reflection factor to standard
110: Subroutine 24 does the reflection. New x an y are stored in 16 and 17 and new function value is in 18
111 - 113: If the new value is worse than the worst of the simplex goto 23 line 133ff (explanation see later)
114 - 121: If new value is better than the worst but not better than the best the new value replaces the worst value and the simplex is sorted and the process continued (line 124-132)
122 - 123: If the new value is better than the old best value reflection factor is doubled and process continues with replacing the worst value by the new one (line 124-132)
133 ff is the routine when the new value is the worst.
134 -139: Reflection factor is halved and a new try with the new reflection factor is done. If the result is better than the worst value of the simplex the new value replaces the old worst value of the simplex (124 - 132)
140 - 157: If the new value is worse than the worst value of the simplex the size of the simplex is halved, the function values of the new simplex points is computed and the simplex is sorted. With the new simplex a new try is started.
158 - 177: The reflection of the worst value at the mean of the two best using the reflection factor in Reg 19 and computing the new function value. Results are stored in 16, 17 and 18.
178 - 187: Computing the function values of the second best and worst point of the simplex.

Concerning printing:
This is difficult because there are changes at many points of the code as shown. If you restrict to complete optimization steps you could add printing commands after step 37.

I hope this helps a bit.

Best regards

Raimund Wildner
 « Next Oldest | Next Newest »