Class BracketFinder


  • class BracketFinder
    extends java.lang.Object
    Provide an interval that brackets a local minimum of a function. This code is based on a Python implementation (from SciPy, module optimize.py v0.5).

    This class has been extracted from o.a.c.math4.optim.univariate and modified to: remove support for bracketing a maximum; support bounds on the bracket; correct the sign of the denominator when the magnitude is small; and return true/false if there is a minimum strictly inside the bounds.

    Since:
    1.1
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static double EPS_MIN
      Tolerance to avoid division by zero.
      private int evaluations
      Number of function evaluations performed in the last search.
      private double fHi
      Function value at hi.
      private double fLo
      Function value at lo.
      private double fMid
      Function value at mid.
      private static double GOLD
      Golden section.
      private double growLimit
      Factor for expanding the interval.
      private double hi
      Higher bound of the bracket.
      private double lo
      Lower bound of the bracket.
      private int maxEvaluations
      Number of allowed function evaluations.
      private double mid
      Point inside the bracket.
    • Constructor Summary

      Constructors 
      Constructor Description
      BracketFinder()
      Constructor with default values 100, 100000 (see the other constructor).
      BracketFinder​(double growLimit, int maxEvaluations)
      Create a bracketing interval finder.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) int getEvaluations()  
      (package private) double getFHi()
      Get function value at getHi().
      (package private) double getFLo()
      Get function value at getLo().
      (package private) double getFMid()
      Get function value at getMid().
      (package private) double getHi()  
      (package private) double getLo()  
      (package private) double getMid()  
      (package private) boolean search​(java.util.function.DoubleUnaryOperator func, double a, double b, double min, double max)
      Search downhill from the initial points to obtain new points that bracket a local minimum of the function.
      private double value​(java.util.function.DoubleUnaryOperator func, double x)
      Get the value of the function.
      • Methods inherited from class java.lang.Object

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

      • EPS_MIN

        private static final double EPS_MIN
        Tolerance to avoid division by zero.
        See Also:
        Constant Field Values
      • growLimit

        private final double growLimit
        Factor for expanding the interval.
      • maxEvaluations

        private final int maxEvaluations
        Number of allowed function evaluations.
      • evaluations

        private int evaluations
        Number of function evaluations performed in the last search.
      • lo

        private double lo
        Lower bound of the bracket.
      • hi

        private double hi
        Higher bound of the bracket.
      • mid

        private double mid
        Point inside the bracket.
      • fLo

        private double fLo
        Function value at lo.
      • fHi

        private double fHi
        Function value at hi.
      • fMid

        private double fMid
        Function value at mid.
    • Constructor Detail

      • BracketFinder

        BracketFinder()
        Constructor with default values 100, 100000 (see the other constructor).
      • BracketFinder

        BracketFinder​(double growLimit,
                      int maxEvaluations)
        Create a bracketing interval finder.
        Parameters:
        growLimit - Expanding factor.
        maxEvaluations - Maximum number of evaluations allowed for finding a bracketing interval.
        Throws:
        java.lang.IllegalArgumentException - if the growLimit or maxEvalutations are not strictly positive.
    • Method Detail

      • search

        boolean search​(java.util.function.DoubleUnaryOperator func,
                       double a,
                       double b,
                       double min,
                       double max)
        Search downhill from the initial points to obtain new points that bracket a local minimum of the function. Note that the initial points do not have to bracket a minimum. An exception is raised if a minimum cannot be found within the configured number of function evaluations.

        The bracket is limited to the provided bounds if they create a positive interval min < max. It is possible that the middle of the bracket is at the bounds as the final bracket is f(mid) <= min(f(lo), f(hi)) and lo <= mid <= hi.

        No exception is raised if the initial points are not within the bounds; the points are updated to be within the bounds.

        No exception is raised if the initial points are equal; the bracket will be returned as a single point lo == mid == hi.

        Parameters:
        func - Function whose optimum should be bracketed.
        a - Initial point.
        b - Initial point.
        min - Minimum bound of the bracket (inclusive).
        max - Maximum bound of the bracket (inclusive).
        Returns:
        true if the mid-point is strictly within the final bracket [lo, hi]; false if there is no local minima.
        Throws:
        java.lang.IllegalStateException - if the maximum number of evaluations is exceeded.
      • getEvaluations

        int getEvaluations()
        Returns:
        the number of evaluations.
      • getLo

        double getLo()
        Returns:
        the lower bound of the bracket.
        See Also:
        getFLo()
      • getFLo

        double getFLo()
        Get function value at getLo().
        Returns:
        function value at getLo()
      • getHi

        double getHi()
        Returns:
        the higher bound of the bracket.
        See Also:
        getFHi()
      • getFHi

        double getFHi()
        Get function value at getHi().
        Returns:
        function value at getHi()
      • getMid

        double getMid()
        Returns:
        a point in the middle of the bracket.
        See Also:
        getFMid()
      • getFMid

        double getFMid()
        Get function value at getMid().
        Returns:
        function value at getMid()
      • value

        private double value​(java.util.function.DoubleUnaryOperator func,
                             double x)
        Get the value of the function.
        Parameters:
        func - Function.
        x - Point.
        Returns:
        the value
        Throws:
        java.lang.IllegalStateException - if the maximal number of evaluations is exceeded.