The AMOEBA function performs multidimensional minimization of a function Func ( x ), where x is an n -dimensional vector, using the downhill simplex method of Nelder and Mead, 1965, Computer Journal , Vol 7, pp 308-313.
The downhill simplex method is not as efficient as Powell's method, and usually requires more function evaluations. However, the simplex method requires only function evaluations--not derivatives--and may be more reliable than Powell's method.
If the minimum is found, AMOEBA returns an n -element vector corresponding to the function's minimum value. If a minimum within the given tolerance is not found within the specified number of iterations, AMOEBA returns a scalar value of -1. Results are returned with the same precision (single- or double-precision floating-point) as is returned by the user-supplied function to be minimized.
This routine is written in the IDL language. Its source code can be found in the file
amoeba.pro
in the
lib
subdirectory of the IDL distribution. AMOEBA is based on the routine
amoeba
described in section 10.4 of
Numerical Recipes in C: The Art of Scientific Computing
(Second Edition), published by Cambridge University Press, and is used by permission.
The fractional tolerance to be achieved in the function value--that is, the fractional decrease in the function value in the terminating step. If the function you supply returns a single-precision result, Ftol should never be less than your machine's floating-point precision--the value contained in the EPS field of the structure returned by the MACHAR function. If the function you supply returns a double-precision floating-point value, Ftol should not be less than your machine' double-precision floating-point precision. See MACHAR for details.
Set this keyword equal to a string containing the name of the function to be minimized. If this keyword is omitted, AMOEBA assumes that an IDL function named "FUNC" is to be used.
The function to be minimized must be written as an IDL function and compiled prior to calling AMOEBA. This function must accept an n -element vector as its only parameter and return a scalar single- or double precision floating-point value as its result.
Set this keyword equal to a named variable that will contain an ( n +1)-element vector of the function values at the simplex points. The first element contains the function minimum.
Set this keyword equal to a named variable that will contain a count of the number of times the function was evaluated.
Set this keyword equal to a scalar value specifying the maximum number of function evaluations allowed before terminating. The default is 5000.
Set this keyword equal to an n -element single- or double-precision floating-point vector specifying the initial starting point. Note that if you specify P0, you must also specify SCALE.
For example, in a 3-dimensional problem, if the initial guess is the point [0,0,0], and you know that the function's minimum value occurs in the interval:
-10 < X[0] < 10, -100 < X[1] < 100, -200 < X[(2] < 200,
Set this keyword equal to a scalar or n -element vector containing the problem's characteristic length scale for each dimension. SCALE is used with P0 to form an initial ( n +1) point simplex. If all dimensions have the same scale, set SCALE equal to a scalar.
Set this keyword equal to an n by n +1 single- or double-precision floating-point array containing the starting simplex. After AMOEBA has returned, the SIMPLEX array contains the simplex enclosing the function minimum. The first point in the array, SIMPLEX[*,0], corresponds to the function's minimum. This keyword is ignored if the P0 and SCALE keywords are set.
Use AMOEBA to find the slope and intercept of a straight line that fits a given set of points, minimizing the maximum error. The function to be minimized (FUNC, in this case) returns the maximum error, given p[0] = intercept, and p[1] = slope. First define the function FUNC:
RETURN, MAX(ABS(Y - (P[0] + P[1] * X)))
Put the data points into a common block so they are accessible to the function:
Y = [ 12.0, 24.3, 39.6, 51.0, 66.5, 78.4, 92.7, 107.8, 120.0, $
135.5, 147.5, 161.0, 175.4, 187.4, 202.5, 215.4, 229.9]
Call the function. Set the fractional tolerance to 1 part in 10 5 , the initial guess to [0,0], and specify that the minimum should be found within a distance of 100 of that point:
R = AMOEBA(1.0e-5, SCALE=1.0e2, P0 = [0, 0], FUNCTION_VALUE=fval)
IF N_ELEMENTS(R) EQ 1 THEN MESSAGE, 'AMOEBA failed to converge'
PRINT, 'Intercept, Slope:', r, $
'Function value (max error): ', fval[0]