Class DerivativeBrentSingleOptimizer


public class DerivativeBrentSingleOptimizer extends BracketedSingleOptimizer
Class to compute local minimum on single dimension functions using a modification of Brent's algorithm that takes into account the function's derivative. This class will search for a local minimum within a bracket of values. A bracket is a set of points: "a" a minimum evaluation point, "b" a middle evaluation point and "c" a maximum evaluation where a <= b <= c, and where f(b) <= f(a) and f(b) <= f(c). This class is based on the implementation of Numerical Recipes 3rd ed. Section 10.4. Page 500.
  • Field Details

    • ITMAX

      public static final int ITMAX
      Maximum number of iterations to perform. If convergence is not found within this number of iterations, the minimum search will be considered as failed.
      See Also:
    • ZEPS

      public static final double ZEPS
      Constant defining machine precision.
      See Also:
    • DEFAULT_TOLERANCE

      public static final double DEFAULT_TOLERANCE
      Default tolerance. Estimated result will be found with an accuracy below or equal to provided tolerance value.
      See Also:
    • MIN_TOLERANCE

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

      private SingleDimensionFunctionEvaluatorListener derivativeListener
      Listener to evaluate the functions derivative. If the function's derivative is not know (e.g. does not have a closed expression), then a DerivativeEstimator might be used inside the listener implementation.
    • tolerance

      private double tolerance
      Tolerance. Estimated result will be found with an accuracy below or equal to provided tolerance value.
  • Constructor Details

    • DerivativeBrentSingleOptimizer

      protected DerivativeBrentSingleOptimizer()
      Empty constructor.
    • DerivativeBrentSingleOptimizer

      protected DerivativeBrentSingleOptimizer(SingleDimensionFunctionEvaluatorListener listener, SingleDimensionFunctionEvaluatorListener derivativeListener, 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.
      derivativeListener - Listener to get function derivative.
      minEvalPoint - Minimum bracket evaluation point.
      middleEvalPoint - Middle bracket evaluation point.
      maxEvalPoint - Maximum bracket evaluation point.
      tolerance - tolerance to find result with. Estimated result will be found with an accuracy below or equal to provided tolerance value.
      Throws:
      InvalidBracketRangeException - Raised if the following condition is not met: minEvalPoint <= middleEvalPoint <= maxEvalPoint.
      IllegalArgumentException - Raised if tolerance is negative.
  • Method Details

    • getDerivativeListener

      public SingleDimensionFunctionEvaluatorListener getDerivativeListener() throws NotAvailableException
      Returns derivative listener to get function derivative.
      Returns:
      Derivative listener.
      Throws:
      NotAvailableException - Raised if derivative listener is not available for retrieval.
    • setDerivativeListener

      public void setDerivativeListener(SingleDimensionFunctionEvaluatorListener derivativeListener) throws LockedException
      Sets derivative listener that gets function derivative.
      Parameters:
      derivativeListener - Sets derivative listener.
      Throws:
      LockedException - Raised if this instance is locked.
    • isDerivativeListenerAvailable

      public boolean isDerivativeListenerAvailable()
      Returns boolean indicating whether derivative listener has been provided and is available for retrieval.
      Returns:
      Boolean indicating whether derivative listener is available.
    • getTolerance

      public double getTolerance()
      Returns tolerance value. Estimated result will be found with an accuracy below or equal to provided tolerance value.
      Returns:
      Tolerance value.
    • setTolerance

      public void setTolerance(double tolerance) throws LockedException
      Sets tolerance value. Estimated result will be found with an accuracy below or equal to provided tolerance value.
      Parameters:
      tolerance - Tolerance value.
      Throws:
      LockedException - Raised if this instance is locked.
      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 that computes a function and also its derivative function df, 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 precision of about tolerance using a modification of Brent's method that uses derivatives. The abscissa of the minimum is returned as "xmin" and the minimum function value is returned as "fmin".
      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 local minimum. This instance will be ready once a listener, derivative listener and bracket are available.
      Overrides:
      isReady in class SingleOptimizer
      Returns:
      True if ready, false otherwise.
    • internalSetTolerance

      private void internalSetTolerance(double tolerance)
      Internal method to set tolerance. Estimated result will be found with an accuracy below or equal to provided tolerance value.
      Parameters:
      tolerance - Tolerance value.
      Throws:
      IllegalArgumentException - Raised if tolerance is negative.