Class SimplexMultiOptimizer


public class SimplexMultiOptimizer extends MultiOptimizer
This class searches for a multi dimension function local minimum. The local minimum is searched by starting the algorithm at a start point and a given set of deltas to obtain surrounding points to the start point where the algorithm will be started. The Simplex algorithm will increase or decrease such deltas and move the start point around until the minimum is found. The implementation of this class is based on Numerical Recipes 3rd ed. Section 10.5 page 502.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final double
    Constant defining default tolerance or accuracy to be achieved on the minimum being estimated by this class.
    private double
    The fractional tolerance in the function value such that failure to decrease by more than this amount on one iteration signals doneness.
    static final double
    Minimum allowed tolerance value.
    private int
    Number of points in the simplex.
    private int
    Number of dimensions of current function being optimized.
    private int
    Number of function evaluations.
    static final int
    Maximum number of iterations.
    private com.irurueta.algebra.Matrix
    Current simplex.
    static final double
    Small value considered to be machine precision.
    private double[]
    Function values at the vertices of the simples.

    Fields inherited from class com.irurueta.numerical.optimization.MultiOptimizer

    fmin, listener, resultAvailable, xmin

    Fields inherited from class com.irurueta.numerical.optimization.Optimizer

    iterationCompletedListener, locked
  • Constructor Summary

    Constructors
    Constructor
    Description
    Empty constructor.
    SimplexMultiOptimizer(MultiDimensionFunctionEvaluatorListener listener, double[] startPoint, double[] deltas, double tolerance)
    Constructor.
    SimplexMultiOptimizer(MultiDimensionFunctionEvaluatorListener listener, double[] startPoint, double delta, double tolerance)
    Constructor.
    SimplexMultiOptimizer(MultiDimensionFunctionEvaluatorListener listener, com.irurueta.algebra.Matrix simplex, double tolerance)
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    private double
    amotry(com.irurueta.algebra.Matrix p, double[] y, double[] psum, int ihi, double fac, MultiDimensionFunctionEvaluatorListener listener)
    Internal method to move simplex around.
    boolean
    Returns boolean indicating whether function evaluations at simplex vertices are available for retrieval.
    double[]
    Returns function evaluations at simplex points or vertices.
    private void
    getPsum(com.irurueta.algebra.Matrix p, double[] psum)
    Computes the sum of the elements of each matrix column.
    com.irurueta.algebra.Matrix
    Returns current simplex.
    double
    Returns tolerance or accuracy to be expected on estimated local minimum.
    private void
    internalSetSimplex(double[] startPoint, double delta)
    Internal method to set a simplex as a central point and a set of surrounding points at distance delta.
    private void
    internalSetSimplex(double[] startPoint, double[] deltas)
    Internal method to set a simplex defined as a central point and a set of surrounding points at their corresponding distance deltas[i], where "i" corresponds to one position of provided array of distances.
    private void
    internalSetSimplex(com.irurueta.algebra.Matrix simplex)
    Internal method to Set simplex as a matrix containing on each row a point of the simplex.
    private void
    internalSetTolerance(double tolerance)
    Internal method to set tolerance or accuracy to be expected on estimated local minimum.
    boolean
    Returns boolean indicating whether this instance is ready to start the estimation of a local minimum.
    boolean
    Returns boolean indicating whether a simplex has been provided and is available for retrieval.
    void
    This function estimates a function minimum.
    void
    setSimplex(double[] startPoint, double delta)
    Sets a simplex defined as a central point and a set of surrounding points at distance delta.
    void
    setSimplex(double[] startPoint, double[] deltas)
    Sets a simplex defined as a central point and a set of surrounding points at their corresponding distance deltas[i], where "i" corresponds to one position of provided array of distances.
    void
    setSimplex(com.irurueta.algebra.Matrix simplex)
    Sets simplex as a matrix containing on each row a point of the simplex.
    void
    setTolerance(double tolerance)
    Sets tolerance or accuracy to be expected on estimated local minimum.
    private static void
    swap(double[] a, double[] b)
    Swaps a and b values.

    Methods inherited from class com.irurueta.numerical.optimization.MultiOptimizer

    getEvaluationAtResult, getListener, getResult, isListenerAvailable, isResultAvailable, setListener

    Methods inherited from class com.irurueta.numerical.optimization.Optimizer

    getOnIterationCompletedListener, isLocked, setOnIterationCompletedListener

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • NMAX

      public static final int NMAX
      Maximum number of iterations.
      See Also:
    • TINY

      public static final double TINY
      Small value considered to be machine precision.
      See Also:
    • DEFAULT_TOLERANCE

      public static final double DEFAULT_TOLERANCE
      Constant defining default tolerance or accuracy to be achieved on the minimum being estimated by this class.
      See Also:
    • MIN_TOLERANCE

      public static final double MIN_TOLERANCE
      Minimum allowed tolerance value.
      See Also:
    • ftol

      private double ftol
      The fractional tolerance in the function value such that failure to decrease by more than this amount on one iteration signals doneness.
    • nfunc

      private int nfunc
      Number of function evaluations.
    • mpts

      private int mpts
      Number of points in the simplex.
    • ndim

      private int ndim
      Number of dimensions of current function being optimized.
    • y

      private double[] y
      Function values at the vertices of the simples.
    • p

      private com.irurueta.algebra.Matrix p
      Current simplex.
  • Constructor Details

    • SimplexMultiOptimizer

      public SimplexMultiOptimizer()
      Empty constructor.
    • SimplexMultiOptimizer

      public SimplexMultiOptimizer(MultiDimensionFunctionEvaluatorListener listener, double[] startPoint, double delta, double tolerance)
      Constructor.
      Parameters:
      listener - Listener to evaluate a multidimensional function.
      startPoint - Point where the algorithm is started.
      delta - Delta to find other points close to the start point so that an initial simplex is defined.
      tolerance - Tolerance or accuracy to be expected on estimated local minimum.
      Throws:
      IllegalArgumentException - Raised if tolerance is negative.
    • SimplexMultiOptimizer

      public SimplexMultiOptimizer(MultiDimensionFunctionEvaluatorListener listener, double[] startPoint, double[] deltas, double tolerance)
      Constructor.
      Parameters:
      listener - Listener to evaluate a multidimensional function.
      startPoint - Point where the algorithm is started.
      deltas - Set of deltas to find other points close to the start point so that an initial simplex is defined.
      tolerance - Tolerance or accuracy to be expected on estimated local minimum.
      Throws:
      IllegalArgumentException - Raised if tolerance is negative or if deltas don't have the same length as provided start point.
    • SimplexMultiOptimizer

      public SimplexMultiOptimizer(MultiDimensionFunctionEvaluatorListener listener, com.irurueta.algebra.Matrix simplex, double tolerance)
      Constructor.
      Parameters:
      listener - Listener to evaluate a multidimensional function.
      simplex - Initial simplex to start the algorithm. The simplex is a set of points around the minimum to be found.
      tolerance - Tolerance or accuracy to be expected on estimated local minimum.
      Throws:
      IllegalArgumentException - Raised if tolerance is negative.
  • Method Details

    • getSimplex

      public com.irurueta.algebra.Matrix getSimplex() throws NotAvailableException
      Returns current simplex. A simplex is a set of points delimiting an n-dimensional region. The simplex can be seen as the n-dimensional version of a bracket of values. This class must be started at an initial simplex where a minimum will be searched. As the algorithm iterates, the simplex will be moved around and its size will be reduced until a minimum is found.
      Returns:
      Current simplex.
      Throws:
      NotAvailableException - Raised if not provided or computed.
    • setSimplex

      public void setSimplex(double[] startPoint, double delta) throws LockedException
      Sets a simplex defined as a central point and a set of surrounding points at distance delta. The simplex will be made of the computed surrounding points.
      Parameters:
      startPoint - Central point.
      delta - Distance of surrounding points.
      Throws:
      LockedException - Raised if this instance is locked.
    • internalSetSimplex

      private void internalSetSimplex(double[] startPoint, double delta)
      Internal method to set a simplex as a central point and a set of surrounding points at distance delta. The simplex will be made of the computed surrounding points. This method does not check whether this instance is locked.
      Parameters:
      startPoint - Central point.
      delta - Distance of surrounding points.
    • setSimplex

      public void setSimplex(double[] startPoint, double[] deltas) throws LockedException
      Sets a simplex defined as a central point and a set of surrounding points at their corresponding distance deltas[i], where "i" corresponds to one position of provided array of distances. The simplex will be made of the computed surrounding points.
      Parameters:
      startPoint - Central point.
      deltas - Distances of surrounding points. Each surrounding point can have a different distance than the others. The number of provided distances must be equal to the dimension or length of the start point array.
      Throws:
      LockedException - Raised if this instance is locked.
      IllegalArgumentException - Raised if startPoint and deltas don't have the same length.
    • internalSetSimplex

      private void internalSetSimplex(double[] startPoint, double[] deltas)
      Internal method to set a simplex defined as a central point and a set of surrounding points at their corresponding distance deltas[i], where "i" corresponds to one position of provided array of distances. The simplex will be made of the computed surrounding points.
      Parameters:
      startPoint - Central point.
      deltas - Distances of surrounding points. Each surrounding point can have a different distance than the others. The number of provided distances must be equal to the dimension or length of the start point array.
      Throws:
      IllegalArgumentException - Raised if startPoint and deltas don't have the same length.
    • setSimplex

      public void setSimplex(com.irurueta.algebra.Matrix simplex) throws LockedException
      Sets simplex as a matrix containing on each row a point of the simplex. The number of columns defines the dimension of the points in the function, if not properly set, then minimize() method will fail when being called.
      Parameters:
      simplex - Simplex of points.
      Throws:
      LockedException - Raised if this instance is locked.
    • internalSetSimplex

      private void internalSetSimplex(com.irurueta.algebra.Matrix simplex)
      Internal method to Set simplex as a matrix containing on each row a point of the simplex. The number of columns defines the dimension of the points in the function, if not properly set, then minimize() method will fail when being called. This method does not check whether this instance is locked.
      Parameters:
      simplex - Simplex of points.
    • isSimplexAvailable

      public boolean isSimplexAvailable()
      Returns boolean indicating whether a simplex has been provided and is available for retrieval.
      Returns:
      True if available, false otherwise.
    • getEvaluationsAtSimplex

      public double[] getEvaluationsAtSimplex() throws NotAvailableException
      Returns function evaluations at simplex points or vertices.
      Returns:
      Function evaluations at simplex vertices.
      Throws:
      NotAvailableException - Raised if not available for retrieval. This parameter will be available one minimization has been computed.
    • areFunctionEvaluationsAvailable

      public boolean areFunctionEvaluationsAvailable()
      Returns boolean indicating whether function evaluations at simplex vertices are available for retrieval. Function evaluations at simplex vertices will be available one minimization has been computed.
      Returns:
      True if available, false otherwise.
    • getTolerance

      public double getTolerance()
      Returns tolerance or accuracy to be expected on estimated local minimum.
      Returns:
      Tolerance or accuracy to be expected on estimated local minimum.
    • setTolerance

      public void setTolerance(double tolerance) throws LockedException
      Sets tolerance or accuracy to be expected on estimated local minimum.
      Parameters:
      tolerance - Tolerance or accuracy to be expected on estimated local minimum.
      Throws:
      LockedException - Raised if this instance is locked.
      IllegalArgumentException - Raised if provided tolerance is negative.
    • internalSetTolerance

      private void internalSetTolerance(double tolerance)
      Internal method to set tolerance or accuracy to be expected on estimated local minimum. This method does not check whether this instance is locked.
      Parameters:
      tolerance - Tolerance or accuracy to be expected on estimated local minimum.
      Throws:
      IllegalArgumentException - Raised if provided tolerance is negative.
    • minimize

      public void minimize() throws LockedException, NotReadyException, OptimizationException
      This function estimates a function minimum. Implementations of this class will usually search a local minimum inside a given simplex of points. The algorithm will iterate moving the simplex around and reducing its size until a minimum is found.
      Overrides:
      minimize in class Optimizer
      Throws:
      LockedException - Raised if this instance is locked, because estimation is being computed.
      NotReadyException - Raised if this instance is not ready, because a listener, a gradient listener and a start point haven't been provided.
      OptimizationException - Raised if the algorithm failed because of lack of convergence or because function couldn't be evaluated.
    • isReady

      public boolean isReady()
      Returns boolean indicating whether this instance is ready to start the estimation of a local minimum. An instance is ready once a listener and a simplex are provided.
      Overrides:
      isReady in class MultiOptimizer
      Returns:
      True if this instance is ready, false otherwise.
    • getPsum

      private void getPsum(com.irurueta.algebra.Matrix p, double[] psum)
      Computes the sum of the elements of each matrix column.
      Parameters:
      p - Matrix where columns will be summed.
      psum - Array to contain computed sums. Provided array must have a length equal to the number of matrix columns. This is an output parameter.
    • amotry

      private double amotry(com.irurueta.algebra.Matrix p, double[] y, double[] psum, int ihi, double fac, MultiDimensionFunctionEvaluatorListener listener) throws EvaluationException
      Internal method to move simplex around.
      Parameters:
      p - a matrix.
      y - an array.
      psum - another array.
      ihi - a value.
      fac - another value.
      listener - a listener to evaluate function to optimize.
      Returns:
      a value returned by the evaluated function.
      Throws:
      EvaluationException - Raised if function evaluation fails.
    • swap

      private static void swap(double[] a, double[] b)
      Swaps a and b values.
      Parameters:
      a - value.
      b - value.