Class DerivativeBrentSingleOptimizer
java.lang.Object
com.irurueta.numerical.optimization.Optimizer
com.irurueta.numerical.optimization.SingleOptimizer
com.irurueta.numerical.optimization.BracketedSingleOptimizer
com.irurueta.numerical.optimization.DerivativeBrentSingleOptimizer
Class to compute local minimum on single dimension functions using a
modification of Brent's algorithm that takes into account the function's
derivative.
This class will search for a local minimum within a bracket of values.
A bracket is a set of points: "a" a minimum evaluation point,
"b" a middle evaluation point and "c" a maximum evaluation where a <= b
<= c, and where f(b) <= f(a) and f(b) <= f(c).
This class is based on the implementation of Numerical Recipes 3rd ed.
Section 10.4. Page 500.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final double
Default tolerance.Listener to evaluate the functions derivative.static final int
Maximum number of iterations to perform.static final double
Minimum allowed tolerance value.private double
Tolerance.static final double
Constant defining machine precision.Fields inherited from class com.irurueta.numerical.optimization.BracketedSingleOptimizer
ax, bx, cx, DEFAULT_MAX_EVAL_POINT, DEFAULT_MIDDLE_EVAL_POINT, DEFAULT_MIN_EVAL_POINT, GLIMIT, GOLD, TINY
Fields inherited from class com.irurueta.numerical.optimization.SingleOptimizer
fmin, listener, resultAvailable, xmin
Fields inherited from class com.irurueta.numerical.optimization.Optimizer
iterationCompletedListener, locked
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Empty constructor.protected
DerivativeBrentSingleOptimizer
(SingleDimensionFunctionEvaluatorListener listener, SingleDimensionFunctionEvaluatorListener derivativeListener, double minEvalPoint, double middleEvalPoint, double maxEvalPoint, double tolerance) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionReturns derivative listener to get function derivative.double
Returns tolerance value.private void
internalSetTolerance
(double tolerance) Internal method to set tolerance.boolean
Returns boolean indicating whether derivative listener has been provided and is available for retrieval.boolean
isReady()
Returns boolean indicating whether this instance is ready to start the estimation of a local minimum.void
minimize()
This function estimates a function minimum within provided or computed bracket of values.void
setDerivativeListener
(SingleDimensionFunctionEvaluatorListener derivativeListener) Sets derivative listener that gets function derivative.void
setTolerance
(double tolerance) Sets tolerance value.Methods inherited from class com.irurueta.numerical.optimization.BracketedSingleOptimizer
areBracketEvaluationsAvailable, computeBracket, computeBracket, computeBracket, evaluateBracket, getEvaluationAtMax, getEvaluationAtMiddle, getEvaluationAtMin, getMaxEvaluationPoint, getMiddleEvaluationPoint, getMinEvaluationPoint, isBracketAvailable, mov3, setBracket, shift2, shift3, sign
Methods inherited from class com.irurueta.numerical.optimization.SingleOptimizer
getEvaluationAtResult, getListener, getResult, isListenerAvailable, isResultAvailable, setListener
Methods inherited from class com.irurueta.numerical.optimization.Optimizer
getOnIterationCompletedListener, isLocked, setOnIterationCompletedListener
-
Field Details
-
ITMAX
public static final int ITMAXMaximum number of iterations to perform. If convergence is not found within this number of iterations, the minimum search will be considered as failed.- See Also:
-
ZEPS
public static final double ZEPSConstant defining machine precision.- See Also:
-
DEFAULT_TOLERANCE
public static final double DEFAULT_TOLERANCEDefault tolerance. Estimated result will be found with an accuracy below or equal to provided tolerance value.- See Also:
-
MIN_TOLERANCE
public static final double MIN_TOLERANCEMinimum allowed tolerance value.- See Also:
-
derivativeListener
Listener to evaluate the functions derivative. If the function's derivative is not know (e.g. does not have a closed expression), then a DerivativeEstimator might be used inside the listener implementation. -
tolerance
private double toleranceTolerance. Estimated result will be found with an accuracy below or equal to provided tolerance value.
-
-
Constructor Details
-
DerivativeBrentSingleOptimizer
protected DerivativeBrentSingleOptimizer()Empty constructor. -
DerivativeBrentSingleOptimizer
protected DerivativeBrentSingleOptimizer(SingleDimensionFunctionEvaluatorListener listener, SingleDimensionFunctionEvaluatorListener derivativeListener, double minEvalPoint, double middleEvalPoint, double maxEvalPoint, double tolerance) throws InvalidBracketRangeException Constructor. Creates an instance with provided bracket of values and a listener to get single dimension function evaluations.- Parameters:
listener
- Listener to evaluate a function.derivativeListener
- Listener to get function derivative.minEvalPoint
- Minimum bracket evaluation point.middleEvalPoint
- Middle bracket evaluation point.maxEvalPoint
- Maximum bracket evaluation point.tolerance
- tolerance to find result with. Estimated result will be found with an accuracy below or equal to provided tolerance value.- Throws:
InvalidBracketRangeException
- Raised if the following condition is not met: minEvalPoint <= middleEvalPoint <= maxEvalPoint.IllegalArgumentException
- Raised if tolerance is negative.
-
-
Method Details
-
getDerivativeListener
public SingleDimensionFunctionEvaluatorListener getDerivativeListener() throws NotAvailableExceptionReturns derivative listener to get function derivative.- Returns:
- Derivative listener.
- Throws:
NotAvailableException
- Raised if derivative listener is not available for retrieval.
-
setDerivativeListener
public void setDerivativeListener(SingleDimensionFunctionEvaluatorListener derivativeListener) throws LockedException Sets derivative listener that gets function derivative.- Parameters:
derivativeListener
- Sets derivative listener.- Throws:
LockedException
- Raised if this instance is locked.
-
isDerivativeListenerAvailable
public boolean isDerivativeListenerAvailable()Returns boolean indicating whether derivative listener has been provided and is available for retrieval.- Returns:
- Boolean indicating whether derivative listener is available.
-
getTolerance
public double getTolerance()Returns tolerance value. Estimated result will be found with an accuracy below or equal to provided tolerance value.- Returns:
- Tolerance value.
-
setTolerance
Sets tolerance value. Estimated result will be found with an accuracy below or equal to provided tolerance value.- Parameters:
tolerance
- Tolerance value.- Throws:
LockedException
- Raised if this instance is locked.IllegalArgumentException
- Raised if tolerance is negative.
-
minimize
This function estimates a function minimum within provided or computed bracket of values. Given a function f that computes a function and also its derivative function df, and given a bracketing triplet of abscissas "ax", "bx", "cx" (such that bx is between ax and cx, and f(bx) is less than both f(ax) and f(cx), this routine isolates the minimum to a fractional precision of about tolerance using a modification of Brent's method that uses derivatives. The abscissa of the minimum is returned as "xmin" and the minimum function value is returned as "fmin".- Overrides:
minimize
in classOptimizer
- Throws:
LockedException
- Raised if this instance is locked, because estimation is being computed.NotReadyException
- Raised if this instance is not ready because either a listener or a bracket has not yet been provided or computed.OptimizationException
- Raised if the algorithm failed because of lack of convergence or because function couldn't be evaluated.
-
isReady
public boolean isReady()Returns boolean indicating whether this instance is ready to start the estimation of a local minimum. This instance will be ready once a listener, derivative listener and bracket are available.- Overrides:
isReady
in classSingleOptimizer
- Returns:
- True if ready, false otherwise.
-
internalSetTolerance
private void internalSetTolerance(double tolerance) Internal method to set tolerance. Estimated result will be found with an accuracy below or equal to provided tolerance value.- Parameters:
tolerance
- Tolerance value.- Throws:
IllegalArgumentException
- Raised if tolerance is negative.
-