jpl.mipl.util
Class Amoeba

java.lang.Object
  extended by jpl.mipl.util.Amoeba

public class Amoeba
extends Object

Amoeba algorithm for finding a minimum of the given multidimensional function. Implements the "downhill simplex method" of Nelder and Mead.

P is an array of numDim+1 rows, where each row is a potential solution. The algorithm operates by moving the solutions around in multidimensional space using one of 4 defined transforms, "flowing" the highest values "downhill", in an amoeba-like manner. See the book for more details. P must be initialized as follows: the first row is an initial guess at the solution. Each successive row is equal to that first row, with one of the variables perturbed by an amount "which is your guess of the problem's characteristic length scale", so each variable is perturbed in one and only one row. Upon completion, any row will hold a valid solution, although P[0] is normally used. See alternative compute() versions for wrapper functions which do this initialization for you. Physically, P must be an array[][WIDTH], where WIDTH is the physical size of the second dimension. Only numDim elements are used from the second dimension. The first dimension must be big enough to hold numDim+1 rows. The code internally is complicated somewhat in order to support a variable WIDTH dimension.

See Also:
ObjectiveFunction

Constructor Summary
Amoeba(int numDim, double funTol, int maxIterations)
          Constructs a new Amoeba.
 
Method Summary
 int compute(double[][] Parg, double[] Y, ObjectiveFunction objFunc)
          This is the actual Amoeba algorithm implementation.
 double compute(double[] pZero, double[] lambda, ObjectiveFunction objFunc)
          This is a wrapper around the amoeba algorithm which does the initialization for you.
 double compute(double[] pZero, double lambda, ObjectiveFunction objFunc)
          This is a wrapper around the amoeba algorithm which does the initialization for you.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Amoeba

public Amoeba(int numDim,
              double funTol,
              int maxIterations)
Constructs a new Amoeba.

Parameters:
numDim - the number of dimensions( independent variables )
funTol - the fractional convergence tolerance to be achieved in the function. 0.00000001 (1e-8) is a good value.
maxIterations - the maximum number of iterations allowed. (suggestion: 5000)
Method Detail

compute

public int compute(double[][] Parg,
                   double[] Y,
                   ObjectiveFunction objFunc)
This is the actual Amoeba algorithm implementation.

Parameters:
Parg - must be initialized as follows: the first row is an initial guess at the solution. Each successive row is equal to that first row, with one of the variables perturbed by an amount "which is your guess of the problem's characteristic length scale", so each variable is perturbed in one and only one row. Upon completion, any row will hold a valid solution, although Parg[0] is normally used. See alternative compute methods for wrapper functions which do this initialization for you.
Y - an array of numDim+1 values, which hold the results of the function evaluation for each trial in Parg. It must be preinitialized based on the initial Parg.
objFunc - the actual function to be minimized.
Returns:
Number of iterations that was necessary to converge to the solution within tolerance limits.

compute

public final double compute(double[] pZero,
                            double lambda,
                            ObjectiveFunction objFunc)
This is a wrapper around the amoeba algorithm which does the initialization for you. You provide only the initial solution, pZero, as a simple vector of size numDim, plus the "length scale" constant, lambda. This wrapper will allocate Parg and Y, fill them up appropriately, call amoeba, and return the P[0] solution in pZero and the Y[0] value as the function return. This should handle all uses of amoeba except when you want lambda to be a vector, e.g. a different "length scale" for each variable. See alternative compute() for this case.

Parameters:
pZero - The initial solution.
lambda - The "length scale" constant.
objFunc - the actual function to be minimized.
Returns:
Y[0] which holds the result of the objFunc evaluation.

compute

public final double compute(double[] pZero,
                            double[] lambda,
                            ObjectiveFunction objFunc)
This is a wrapper around the amoeba algorithm which does the initialization for you. The "length scale" constant, lambda, is an array of doubles (of size numDim). This allows you to have a different length scale for each variable.

Parameters:
pZero[] - The initial solution.
lambda[] - The "length scale" constant array.
objFunc - the actual function to be minimized.
Returns:
Y[0] which holds the result of the objFunc evaluation.