Class GoldenSingleOptimizer


public class GoldenSingleOptimizer extends BracketedSingleOptimizer
This class for a single dimensional function's local minimum. This class is based in the Golden search algorithm found in Numerical Recipes 3rd ed. Section 10.2 page 492.
  • Field Details

    • R

      public static final double R
      Golden ratio.
      See Also:
    • C

      public static final double C
      Golden ratio.
      See Also:
    • DEFAULT_TOLERANCE

      public static final double DEFAULT_TOLERANCE
      Constant defining the default accuracy of the estimated minimum.
      See Also:
    • MIN_TOLERANCE

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

      private double tolerance
      Tolerance value. The algorithm will iterate until the result converges below this value of accuracy or until the maximum number of iterations is achieved (and in such case, convergence will be assumed to have failed).
  • Constructor Details

    • GoldenSingleOptimizer

      public GoldenSingleOptimizer()
      Empty constructor.
    • GoldenSingleOptimizer

      public GoldenSingleOptimizer(SingleDimensionFunctionEvaluatorListener listener, double minEvalPoint, double middleEvalPoint, double maxEvalPoint, double tolerance) throws InvalidBracketRangeException
      Constructor. Creates an instance with provided bracket of values and a listener to get single dimension function evaluations.
      Parameters:
      listener - Listener to evaluate a function.
      minEvalPoint - Minimum bracket evaluation point.
      middleEvalPoint - Middle bracket evaluation point.
      maxEvalPoint - Maximum bracket evaluation point.
      tolerance - Tolerance or accuracy to be obtained in estimated minimum.
      Throws:
      InvalidBracketRangeException - Raised if the following condition is not met: minEvalPoint <= middleEvalPoint <= maxEvalPoint.
      IllegalArgumentException - Raised if tolerance is negative.
  • Method Details

    • getTolerance

      public double getTolerance()
      Returns tolerance value, which is the accuracy to be obtained when a minimum is estimated. The algorithm will iterate until the result converges below this value of accuracy or until the maximum number of iterations is achieved (and in such case, convergence will be assumed to have failed).
      Returns:
      Tolerance value.
    • setTolerance

      public void setTolerance(double tolerance) throws LockedException
      Sets algorithm's tolerance. The algorithm will iterate until the result converges below this value of accuracy or until the maximum number of iterations is achieved (an in such case, convergence will be assumed to have failed).
      Parameters:
      tolerance - Tolerance or accuracy to be obtained in estimated minimum.
      Throws:
      LockedException - Raised if this instance is locked. This instance will be locked while doing some operations. Attempting to change any parameter while being locked will raise this exception.
      IllegalArgumentException - Raised if tolerance is negative.
    • minimize

      public void minimize() throws LockedException, NotReadyException, OptimizationException
      This function estimates a function minimum within provided or computed bracket of values. Given a function f, and given a bracketing triplet of abscissas "ax", "bx", "cx" (such that bx is between ax and cx, and f(bx) is less than both f(ax) and f(cx), this routine isolates the minimum to a fractional prevision of about tolerance using Brent's method. The abscissa of the minimum is returned as "xmin", and the function value of the minimum is returned as "fmin", the returned function value.
      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 either a listener or a bracket has not yet been provided or computed.
      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 minimum or not. The instance is ready when both the listener and the bracket are available.
      Overrides:
      isReady in class SingleOptimizer
      Returns:
      True if this instance is ready, false otherwise.
    • internalSetTolerance

      private void internalSetTolerance(double tolerance)
      Internal method to set algorithm tolerance. This method does not check whether this instance is locked or not. The algorithm will iterate until the result converges below this value of accuracy or until the maximum number of iterations is achieved (and in such case, convergence will be assumed to have failed).
      Parameters:
      tolerance - Tolerance or accuracy to be obtained in estimated minimum.
      Throws:
      IllegalArgumentException - Raised if tolerance is negative.