org.apache.commons.math3.optim.univariate

## Class BrentOptimizer

- java.lang.Object
- - org.apache.commons.math3.optim.BaseOptimizer<UnivariatePointValuePair>
  - - org.apache.commons.math3.optim.univariate.UnivariateOptimizer
    - - org.apache.commons.math3.optim.univariate.BrentOptimizer

- Direct Known Subclasses:
    PowellOptimizer.LineSearch

      public class BrentOptimizer
      extends UnivariateOptimizer

  For a function defined on some interval `(lo, hi)`, this class finds an approximation `x` to the point at which the function attains its minimum. It implements Richard Brent's algorithm (from his book "Algorithms for Minimization without Derivatives", p. 79) for finding minima of real univariate functions.
  This code is an adaptation, partly based on the Python code from SciPy (module "optimize.py" v0.5); the original algorithm is also modified
  - to use an initial guess provided by the user,
  - to ensure that the best point encountered is the one returned.
  Since:
    2.0
  Version:
    $Id: BrentOptimizer.java 1416643 2012-12-03 19:37:14Z tn $

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `private double` | `absoluteThreshold` Absolute threshold.
    `private static double` | `GOLDEN_SECTION` Golden section.
    `private static double` | `MIN_RELATIVE_TOLERANCE` Minimum relative tolerance.
    `private double` | `relativeThreshold` Relative threshold.

    - ### Fields inherited from class org.apache.commons.math3.optim.BaseOptimizer

      `evaluations, iterations`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `BrentOptimizer(double rel, double abs)` The arguments are used for implementing the original stopping criterion of Brent's algorithm.
    `BrentOptimizer(double rel, double abs, ConvergenceChecker<UnivariatePointValuePair> checker)` The arguments are used implement the original stopping criterion of Brent's algorithm.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `private UnivariatePointValuePair` | `best(UnivariatePointValuePair a, UnivariatePointValuePair b, boolean isMinim)` Selects the best of two points.
    `protected UnivariatePointValuePair` | `doOptimize()` Performs the bulk of the optimization algorithm.

    - ### Methods inherited from class org.apache.commons.math3.optim.univariate.UnivariateOptimizer

      `computeObjectiveValue, getGoalType, getMax, getMin, getStartValue, optimize`

    - ### Methods inherited from class org.apache.commons.math3.optim.BaseOptimizer

      `getConvergenceChecker, getEvaluations, getIterations, getMaxEvaluations, getMaxIterations, incrementEvaluationCount, incrementIterationCount`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### GOLDEN_SECTION

          private static final double GOLDEN_SECTION

      Golden section.

    - #### MIN_RELATIVE_TOLERANCE

          private static final double MIN_RELATIVE_TOLERANCE

      Minimum relative tolerance.

    - #### relativeThreshold

          private final double relativeThreshold

      Relative threshold.

    - #### absoluteThreshold

          private final double absoluteThreshold

      Absolute threshold.

  - ### Constructor Detail

    - #### BrentOptimizer

          public BrentOptimizer(double rel,
                        double abs,
                        ConvergenceChecker<UnivariatePointValuePair> checker)

      The arguments are used implement the original stopping criterion of Brent's algorithm. `abs` and `rel` define a tolerance `tol = rel |x| + abs`. `rel` should be no smaller than 2 macheps and preferably not much less than sqrt(macheps), where macheps is the relative machine precision. `abs` must be positive.
      Parameters:
        `rel` - Relative threshold.
        `abs` - Absolute threshold.
        `checker` - Additional, user-defined, convergence checking procedure.
      Throws:
        `NotStrictlyPositiveException` - if `abs <= 0`.
        `NumberIsTooSmallException` - if `rel < 2 * Math.ulp(1d)`.

    - #### BrentOptimizer

          public BrentOptimizer(double rel,
                        double abs)

      The arguments are used for implementing the original stopping criterion of Brent's algorithm. `abs` and `rel` define a tolerance `tol = rel |x| + abs`. `rel` should be no smaller than 2 macheps and preferably not much less than sqrt(macheps), where macheps is the relative machine precision. `abs` must be positive.
      Parameters:
        `rel` - Relative threshold.
        `abs` - Absolute threshold.
      Throws:
        `NotStrictlyPositiveException` - if `abs <= 0`.
        `NumberIsTooSmallException` - if `rel < 2 * Math.ulp(1d)`.

  - ### Method Detail

    - #### doOptimize

          protected UnivariatePointValuePair doOptimize()

      Performs the bulk of the optimization algorithm.
      Specified by:
        `doOptimize` in class `BaseOptimizer<UnivariatePointValuePair>`
      Returns:
        the point/value pair giving the optimal value of the objective function.

    - #### best

          private UnivariatePointValuePair best(UnivariatePointValuePair a,
                                      UnivariatePointValuePair b,
                                      boolean isMinim)

      Selects the best of two points.
      Parameters:
        `a` - Point and value.
        `b` - Point and value.
        `isMinim` - `true` if the selected point must be the one with the lowest value.
      Returns:
        the best point, or `null` if `a` and `b` are both `null`. When `a` and `b` have the same function value, `a` is returned.

Copyright (c) 2003-2013 Apache Software Foundation