Class FieldBracketingNthOrderBrentSolver<T extends RealFieldElement<T>>

java.lang.Object
org.apache.commons.math3.analysis.solvers.FieldBracketingNthOrderBrentSolver<T>
Type Parameters:
T - the type of the field elements
All Implemented Interfaces:
BracketedRealFieldUnivariateSolver<T>
Direct Known Subclasses:
BracketingNthOrderBrentSolverDFP

public class FieldBracketingNthOrderBrentSolver<T extends RealFieldElement<T>> extends Object implements BracketedRealFieldUnivariateSolver<T>
This class implements a modification of the Brent algorithm.

The changes with respect to the original Brent algorithm are:

  • the returned value is chosen in the current interval according to user specified AllowedSolution
  • the maximal order for the invert polynomial root search is user-specified instead of being invert quadratic only

The given interval must bracket the root.

Since:
3.6
  • Field Details

    • MAXIMAL_AGING

      private static final int MAXIMAL_AGING
      Maximal aging triggering an attempt to balance the bracketing interval.
      See Also:
    • field

      private final Field<T extends RealFieldElement<T>> field
      Field to which the elements belong.
    • maximalOrder

      private final int maximalOrder
      Maximal order.
    • functionValueAccuracy

      private final T extends RealFieldElement<T> functionValueAccuracy
      Function value accuracy.
    • absoluteAccuracy

      private final T extends RealFieldElement<T> absoluteAccuracy
      Absolute accuracy.
    • relativeAccuracy

      private final T extends RealFieldElement<T> relativeAccuracy
      Relative accuracy.
    • evaluations

      private IntegerSequence.Incrementor evaluations
      Evaluations counter.
  • Constructor Details

    • FieldBracketingNthOrderBrentSolver

      public FieldBracketingNthOrderBrentSolver(T relativeAccuracy, T absoluteAccuracy, T functionValueAccuracy, int maximalOrder) throws NumberIsTooSmallException
      Construct a solver.
      Parameters:
      relativeAccuracy - Relative accuracy.
      absoluteAccuracy - Absolute accuracy.
      functionValueAccuracy - Function value accuracy.
      maximalOrder - maximal order.
      Throws:
      NumberIsTooSmallException - if maximal order is lower than 2
  • Method Details

    • getMaximalOrder

      public int getMaximalOrder()
      Get the maximal order.
      Returns:
      maximal order
    • getMaxEvaluations

      public int getMaxEvaluations()
      Get the maximal number of function evaluations.
      Specified by:
      getMaxEvaluations in interface BracketedRealFieldUnivariateSolver<T extends RealFieldElement<T>>
      Returns:
      the maximal number of function evaluations.
    • getEvaluations

      public int getEvaluations()
      Get the number of evaluations of the objective function. The number of evaluations corresponds to the last call to the optimize method. It is 0 if the method has not been called yet.
      Specified by:
      getEvaluations in interface BracketedRealFieldUnivariateSolver<T extends RealFieldElement<T>>
      Returns:
      the number of evaluations of the objective function.
    • getAbsoluteAccuracy

      public T getAbsoluteAccuracy()
      Get the absolute accuracy.
      Specified by:
      getAbsoluteAccuracy in interface BracketedRealFieldUnivariateSolver<T extends RealFieldElement<T>>
      Returns:
      absolute accuracy
    • getRelativeAccuracy

      public T getRelativeAccuracy()
      Get the relative accuracy.
      Specified by:
      getRelativeAccuracy in interface BracketedRealFieldUnivariateSolver<T extends RealFieldElement<T>>
      Returns:
      relative accuracy
    • getFunctionValueAccuracy

      public T getFunctionValueAccuracy()
      Get the function accuracy.
      Specified by:
      getFunctionValueAccuracy in interface BracketedRealFieldUnivariateSolver<T extends RealFieldElement<T>>
      Returns:
      function accuracy
    • solve

      public T solve(int maxEval, RealFieldUnivariateFunction<T> f, T min, T max, AllowedSolution allowedSolution) throws NullArgumentException, NoBracketingException
      Solve for a zero in the given interval. A solver may require that the interval brackets a single zero root. Solvers that do require bracketing should be able to handle the case where one of the endpoints is itself a root.
      Specified by:
      solve in interface BracketedRealFieldUnivariateSolver<T extends RealFieldElement<T>>
      Parameters:
      maxEval - Maximum number of evaluations.
      f - Function to solve.
      min - Lower bound for the interval.
      max - Upper bound for the interval.
      allowedSolution - The kind of solutions that the root-finding algorithm may accept as solutions.
      Returns:
      a value where the function is zero.
      Throws:
      NullArgumentException - if f is null.
      NoBracketingException - if root cannot be bracketed
    • solve

      public T solve(int maxEval, RealFieldUnivariateFunction<T> f, T min, T max, T startValue, AllowedSolution allowedSolution) throws NullArgumentException, NoBracketingException
      Solve for a zero in the given interval, start at startValue. A solver may require that the interval brackets a single zero root. Solvers that do require bracketing should be able to handle the case where one of the endpoints is itself a root.
      Specified by:
      solve in interface BracketedRealFieldUnivariateSolver<T extends RealFieldElement<T>>
      Parameters:
      maxEval - Maximum number of evaluations.
      f - Function to solve.
      min - Lower bound for the interval.
      max - Upper bound for the interval.
      startValue - Start value to use.
      allowedSolution - The kind of solutions that the root-finding algorithm may accept as solutions.
      Returns:
      a value where the function is zero.
      Throws:
      NullArgumentException - if f is null.
      NoBracketingException - if root cannot be bracketed
    • guessX

      private T guessX(T targetY, T[] x, T[] y, int start, int end)
      Guess an x value by nth order inverse polynomial interpolation.

      The x value is guessed by evaluating polynomial Q(y) at y = targetY, where Q is built such that for all considered points (xi, yi), Q(yi) = xi.

      Parameters:
      targetY - target value for y
      x - reference points abscissas for interpolation, note that this array is modified during computation
      y - reference points ordinates for interpolation
      start - start index of the points to consider (inclusive)
      end - end index of the points to consider (exclusive)
      Returns:
      guessed root (will be a NaN if two points share the same y)