Class QuasiNewtonMultiOptimizer


public class QuasiNewtonMultiOptimizer 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 The implementation of this class is based on Numerical Recipes 3rd ed. Section 10.9 page 521.
  • Field Details

    • ITMAX

      public static final int ITMAX
      Maximum number of iterations.
      See Also:
    • EPS

      public static final double EPS
      Machine precision.
      See Also:
    • TOLX

      public static final double TOLX
      Convergence criterion on x values.
      See Also:
    • STPMX

      public static final double STPMX
      Scaled maximum step length allowed in line searches.
      See Also:
    • ALF

      public static final double ALF
      See Also:
    • TOLX2

      public static final double TOLX2
      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:
    • p

      private double[] p
      n-dimensional start point.
    • tolerance

      private double tolerance
      The fractional tolerance in the function value such that failure to decrease by more than this amount on one iteration signals done-ness.
    • iter

      private int iter
      Member contains number of iterations that were needed to estimate a minimum.
    • gradientListener

      Listener to obtain gradient values for the multi dimension function being evaluated. If the gradient is unknown (e.g. doesn't have a closed expression), the provided listener could use a GradientEstimator to obtain one.
    • fret

      double fret
      value of the function at the minimum.
  • Constructor Details

    • QuasiNewtonMultiOptimizer

      public QuasiNewtonMultiOptimizer()
      Empty constructor.
    • QuasiNewtonMultiOptimizer

      public QuasiNewtonMultiOptimizer(MultiDimensionFunctionEvaluatorListener listener, GradientFunctionEvaluatorListener gradientListener, double tolerance)
      Constructor.
      Parameters:
      listener - Listener to evaluate a multidimensional function.
      gradientListener - Listener to obtain gradient value for the multidimensional function being evaluated.
      tolerance - Tolerance or accuracy to be expected on estimated local minimum.
      Throws:
      IllegalArgumentException - Raised if tolerance is negative.
    • QuasiNewtonMultiOptimizer

      public QuasiNewtonMultiOptimizer(MultiDimensionFunctionEvaluatorListener listener, GradientFunctionEvaluatorListener gradientListener, double[] startPoint, double tolerance)
      Constructor.
      Parameters:
      listener - Listener to evaluate a multidimensional function.
      gradientListener - Listener to obtain gradient value for the multidimensional function being evaluated.
      startPoint - Start point where algorithm will be started. Start point should be close to the local minimum to be found. Provided array must have a length equal to the number of dimensions of the function being evaluated, otherwise and exception will be raised when searching for the minimum.
      tolerance - Tolerance or accuracy to be expected on estimated local minimum.
      Throws:
      IllegalArgumentException - Raised if tolerance is negative.
  • Method Details

    • minimize

      public void minimize() throws LockedException, NotReadyException, OptimizationException
      This function estimates a function minimum. Implementations of this class will usually search a local minimum close to a start point. Given a starting point p[0..n-1], the Broyden-Fletcher-Goldfarb-Sharno variant of Davidon Fletcher-Powell minimization is performed on a function whose value and gradient are provided by respective listeners. The convergence requirement on zeroing the gradient is provided by tolerance. This method estimates the location of the minimum, sets the number of iterations that were required and the minimum value of the function at the minimum. The internal method lnsrch is called within this method to perform approximate line minimizations.
      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, a gradient listener and a start point are provided.
      Overrides:
      isReady in class MultiOptimizer
      Returns:
      True if this instance is ready, 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.
    • 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.
    • 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.
    • isStartPointAvailable

      public boolean isStartPointAvailable()
      Returns boolean indicating whether start point has already been provided and is ready for retrieval.
      Returns:
      True if available, false otherwise.
    • setStartPoint

      public void setStartPoint(double[] startPoint) throws LockedException
      Sets start point where algorithm will be started. Start point should be close to the local minimum to be found.
      Parameters:
      startPoint - Start point where algorithm will be started.
      Throws:
      LockedException - Raised if this instance is locked.
    • getStartPoint

      public double[] getStartPoint() throws NotAvailableException
      Returns start point where algorithm will be started. Start point should be close to the local minimum to be found.
      Returns:
      Start point where algorithm will be started.
      Throws:
      NotAvailableException - Raised if start point has not yet been provided and is not available.
    • getGradientListener

      public GradientFunctionEvaluatorListener getGradientListener() throws NotAvailableException
      Returns gradient listener in charge of obtaining gradient values for the function to be evaluated.
      Returns:
      Gradient listener.
      Throws:
      NotAvailableException - Raised if gradient listener has not yet been provided.
    • setGradientListener

      public void setGradientListener(GradientFunctionEvaluatorListener gradientListener) throws LockedException
      Sets gradient listener in charge of obtaining gradient values for the function to be evaluated.
      Parameters:
      gradientListener - Gradient listener.
      Throws:
      LockedException - Raised if this instance is locked.
    • isGradientListenerAvailable

      public boolean isGradientListenerAvailable()
      Returns boolean indicating whether a gradient listener has already been provided and is available for retrieval.
      Returns:
      True if available, false otherwise.
    • getIterations

      public int getIterations()
      Return number of iterations that were needed to estimate a minimum.
      Returns:
      number of iterations that were needed.
    • sqr

      private double sqr(double x)
      Computes the squared value of provided double.
      Parameters:
      x - Value to be squared.
      Returns:
      Squared value.
    • lnsrch

      private void lnsrch(double[] xold, double fold, double[] g, double[] p, double[] x, double[] f, double stpmax, boolean[] check) throws OptimizationException
      Internal method to search for a minimum along a line. NOTE: comments of params might be incorrect.
      Parameters:
      xold - previous point.
      fold - previous function evaluation.
      g - gradient.
      p - point.
      x - point.
      f - function.
      stpmax - stores point maximum.
      check - checks line search.
      Throws:
      OptimizationException - Raised if convergence was not achieved.