Class BracketedSingleRootEstimator

Direct Known Subclasses:
BisectionSingleRootEstimator, BrentSingleRootEstimator, DerivativeSingleRootEstimator, FalsePositionSingleRootEstimator, RidderSingleRootEstimator, SecantSingleRootEstimator

public abstract class BracketedSingleRootEstimator extends SingleRootEstimator
Computes a root for a single dimension function inside a given bracket of values, in other words, root will only be searched within provided minimum and maximum evaluation points.
  • Field Details

    • NTRY

      public static final int NTRY
      Number tries to automatically compute a bracket of values for a given function.
      See Also:
    • FACTOR

      public static final double FACTOR
      Factor to use to modify initial values when searching for a bracket.
      See Also:
    • DEFAULT_MIN_EVAL_POINT

      public static final double DEFAULT_MIN_EVAL_POINT
      Default minimum evaluation point.
      See Also:
    • DEFAULT_MAX_EVAL_POINT

      public static final double DEFAULT_MAX_EVAL_POINT
      Default maximum evaluation point.
      See Also:
    • BRACKET_EPS

      public static final double BRACKET_EPS
      Constant defining the value by which the largest bracket evaluation value is increased respect the minimum.
      See Also:
    • minEvalPoint

      protected double minEvalPoint
      Minimum evaluation point.
    • maxEvalPoint

      protected double maxEvalPoint
      Maximum evaluation point.
    • bracketAvailable

      protected boolean bracketAvailable
      Boolean indicating whether a bracket has been computed and is available.
  • Constructor Details

    • BracketedSingleRootEstimator

      protected BracketedSingleRootEstimator()
      Empty constructor.
    • BracketedSingleRootEstimator

      protected BracketedSingleRootEstimator(SingleDimensionFunctionEvaluatorListener listener, double minEvalPoint, double maxEvalPoint) throws InvalidBracketRangeException
      Constructor.
      Parameters:
      listener - Listener to evaluate a single dimension function f(x) to find its roots.
      minEvalPoint - Smallest value inside the bracket of values where the root will be searched.
      maxEvalPoint - Largest value inside the bracket of values where the root will be searched.
      Throws:
      InvalidBracketRangeException - Raised if minEvalPoint < maxEvalPoint.
  • Method Details

    • setBracket

      public void setBracket(double minEvalPoint, double maxEvalPoint) throws LockedException, InvalidBracketRangeException
      Sets the bracket of values (i.e. range of values) where the root will be searched.
      Parameters:
      minEvalPoint - Smallest value inside the bracket of values where the root will be searched.
      maxEvalPoint - Largest value inside the bracket of values where the root will be searched.
      Throws:
      LockedException - Raised if this instance is locked while doing some computations.
      InvalidBracketRangeException - Raised if minEvalPoint < maxEvalPoint.
    • internalSetBracket

      private void internalSetBracket(double minEvalPoint, double maxEvalPoint) throws InvalidBracketRangeException
      Internal method to set the bracket of values (i.e. range of values) where the root will be searched.
      Parameters:
      minEvalPoint - Smallest value inside the bracket of values where the root will be searched.
      maxEvalPoint - Largest value inside the bracket of values where the root will be searched.
      Throws:
      InvalidBracketRangeException - Raised if minEvalPoint < maxEvalPoint.
    • isBracketAvailable

      public boolean isBracketAvailable()
      Returns boolean indicating whether bracket has been set or not.
      Returns:
      True if bracket has been set, false otherwise.
    • getMinEvaluationPoint

      public double getMinEvaluationPoint() throws NotAvailableException
      Returns smallest value inside the bracket of values where the root will be searched.
      Returns:
      Smallest value inside the bracket.
      Throws:
      NotAvailableException - Raised if bracket has not been set.
    • getMaxEvaluationPoint

      public double getMaxEvaluationPoint() throws NotAvailableException
      Returns largest value inside the bracket of values where the root will be searched.
      Returns:
      Largest values inside the bracket.
      Throws:
      NotAvailableException - Raised if bracket has not been set.
    • computeBracket

      public void computeBracket(double minEvalPoint, double maxEvalPoint) throws LockedException, NotReadyException, InvalidBracketRangeException, RootEstimationException
      Starting from provided minimum and maximum values, this method expands the range (i.e. bracket of values) until a zero crossing is found where a root is present or until the bracket becomes unacceptably large, where an exception will be raised. Notice that this method searches for zero crossings, hence, functions such as Math.pow(x - root, 2.0), will raise a RootEstimationException because the only root present in them does not produce a zero crossing.
      Parameters:
      minEvalPoint - Smallest initial value to estimate a new larger bracket.
      maxEvalPoint - Largest initial value to estimate a new larger bracket.
      Throws:
      LockedException - Raised if this instance is locked while doing some computations.
      NotReadyException - Raised if this instance is not ready (e.g. a listener has not yet been provided, etc.)
      InvalidBracketRangeException - Raised if minEvalPoint < maxEvalPoint
      RootEstimationException - Raised if a bracket couldn't be found inside the provided limits because no zero crossing was present or convergence was not achieved.
    • computeBracket

      public void computeBracket(double point) throws LockedException, NotReadyException, InvalidBracketRangeException, RootEstimationException
      Starting from provided point, this method expands the range (i.e. bracket of values) until a zero crossing is found where a root is present or until the bracket becomes unacceptably large, where an exception will be raised. Notice that this method searches for zero crossings, hence, functions such as Math.pow(x - root, 2.0), will raise a RootEstimationException because the only root present in them does not produce a zero crossing.
      Parameters:
      point - Initial value to start the bracket computation. Bracket range is expanded starting at the point that was provided.
      Throws:
      LockedException - Raised if this instance is locked while doing some computations.
      NotReadyException - Raised if this instance is not ready (e.g. a listener has not yet been provided, etc.).
      InvalidBracketRangeException - Raised if point is close to Double.MAX_VALUE.
      RootEstimationException - Raised if a bracket couldn't be found inside the provided limits because no zero crossing was present or convergence was not achieved.
    • computeBracket

      public void computeBracket() throws LockedException, NotReadyException, RootEstimationException
      Starting at zero, this method expands the range (i.e. bracket of values) until a zero crossing is found where a root is present or until the bracket becomes unacceptably large, where an exception will be raised. Notice that this method searches for zero crossings, hence, functions such as Math.pow(x - root, 2.0), will raise a RootEstimationException because the only root present in them does not produce a zero crossing.
      Throws:
      LockedException - Raised if this instance is locked while doing some computations.
      NotReadyException - Raised if this instance is not ready (e.g. a listener has not yet been provided, etc.).
      RootEstimationException - Raised if a bracket couldn't be found inside the provided limits because no zero crossing was present or convergence was not achieved.
    • swap

      protected void swap(double[] a, double[] b)
      Internal method to swap two values. Value inside a[0] will be swapped with value provided in b[0].
      Parameters:
      a - Value to be swapped.
      b - Value to be swapped.
    • sign

      protected double sign(double a, double b)
      Internal method to determine whether a and b have the same sign.
      Parameters:
      a - Value to be compared.
      b - Value to be compared.
      Returns:
      Returns "a" if "a" and "b" have the same sign or "-a" otherwise.