Class BracketFinder

java.lang.Object
org.apache.commons.statistics.inference.BracketFinder

class BracketFinder extends 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 final double
    Tolerance to avoid division by zero.
    private int
    Number of function evaluations performed in the last search.
    private double
    Function value at hi.
    private double
    Function value at lo.
    private double
    Function value at mid.
    private static final double
    Golden section.
    private final double
    Factor for expanding the interval.
    private double
    Higher bound of the bracket.
    private double
    Lower bound of the bracket.
    private final int
    Number of allowed function evaluations.
    private double
    Point inside the bracket.
  • Constructor Summary

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

    Modifier and Type
    Method
    Description
    (package private) int
     
    (package private) double
    Get function value at getHi().
    (package private) double
    Get function value at getLo().
    (package private) double
    Get function value at getMid().
    (package private) double
     
    (package private) double
     
    (package private) double
     
    (package private) boolean
    search(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(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 Details

    • EPS_MIN

      private static final double EPS_MIN
      Tolerance to avoid division by zero.
      See Also:
    • GOLD

      private static final double GOLD
      Golden section.
      See Also:
    • 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 Details

    • 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:
      IllegalArgumentException - if the growLimit or maxEvalutations are not strictly positive.
  • Method Details

    • search

      boolean search(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:
      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

      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

      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

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

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