Class GoldenSingleOptimizer
java.lang.Object
com.irurueta.numerical.optimization.Optimizer
com.irurueta.numerical.optimization.SingleOptimizer
com.irurueta.numerical.optimization.BracketedSingleOptimizer
com.irurueta.numerical.optimization.GoldenSingleOptimizer
This class for a single dimensional function's local minimum.
This class is based in the Golden search algorithm found in
Numerical Recipes 3rd ed. Section 10.2 page 492.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final double
Golden ratio.static final double
Constant defining the default accuracy of the estimated minimum.static final double
Minimum allowed tolerance.static final double
Golden ratio.private double
Tolerance value.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
ConstructorsConstructorDescriptionEmpty constructor.GoldenSingleOptimizer
(SingleDimensionFunctionEvaluatorListener listener, double minEvalPoint, double middleEvalPoint, double maxEvalPoint, double tolerance) Constructor. -
Method Summary
Modifier and TypeMethodDescriptiondouble
Returns tolerance value, which is the accuracy to be obtained when a minimum is estimated.private void
internalSetTolerance
(double tolerance) Internal method to set algorithm tolerance.boolean
isReady()
Returns boolean indicating whether this instance is ready to start the estimation of a minimum or not.void
minimize()
This function estimates a function minimum within provided or computed bracket of values.void
setTolerance
(double tolerance) Sets algorithm's tolerance.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
-
R
public static final double RGolden ratio.- See Also:
-
C
public static final double CGolden ratio.- See Also:
-
DEFAULT_TOLERANCE
public static final double DEFAULT_TOLERANCEConstant defining the default accuracy of the estimated minimum.- See Also:
-
MIN_TOLERANCE
public static final double MIN_TOLERANCEMinimum allowed tolerance.- See Also:
-
tolerance
private double toleranceTolerance value. The algorithm will iterate until the result converges below this value of accuracy or until the maximum number of iterations is achieved (and in such case, convergence will be assumed to have failed).
-
-
Constructor Details
-
GoldenSingleOptimizer
public GoldenSingleOptimizer()Empty constructor. -
GoldenSingleOptimizer
public GoldenSingleOptimizer(SingleDimensionFunctionEvaluatorListener listener, 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.minEvalPoint
- Minimum bracket evaluation point.middleEvalPoint
- Middle bracket evaluation point.maxEvalPoint
- Maximum bracket evaluation point.tolerance
- Tolerance or accuracy to be obtained in estimated minimum.- Throws:
InvalidBracketRangeException
- Raised if the following condition is not met: minEvalPoint <= middleEvalPoint <= maxEvalPoint.IllegalArgumentException
- Raised if tolerance is negative.
-
-
Method Details
-
getTolerance
public double getTolerance()Returns tolerance value, which is the accuracy to be obtained when a minimum is estimated. The algorithm will iterate until the result converges below this value of accuracy or until the maximum number of iterations is achieved (and in such case, convergence will be assumed to have failed).- Returns:
- Tolerance value.
-
setTolerance
Sets algorithm's tolerance. The algorithm will iterate until the result converges below this value of accuracy or until the maximum number of iterations is achieved (an in such case, convergence will be assumed to have failed).- Parameters:
tolerance
- Tolerance or accuracy to be obtained in estimated minimum.- Throws:
LockedException
- Raised if this instance is locked. This instance will be locked while doing some operations. Attempting to change any parameter while being locked will raise this exception.IllegalArgumentException
- Raised if tolerance is negative.
-
minimize
This function estimates a function minimum within provided or computed bracket of values. Given a function f, 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 prevision of about tolerance using Brent's method. The abscissa of the minimum is returned as "xmin", and the function value of the minimum is returned as "fmin", the returned function value.- 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 minimum or not. The instance is ready when both the listener and the bracket are available.- Overrides:
isReady
in classSingleOptimizer
- Returns:
- True if this instance is ready, false otherwise.
-
internalSetTolerance
private void internalSetTolerance(double tolerance) Internal method to set algorithm tolerance. This method does not check whether this instance is locked or not. The algorithm will iterate until the result converges below this value of accuracy or until the maximum number of iterations is achieved (and in such case, convergence will be assumed to have failed).- Parameters:
tolerance
- Tolerance or accuracy to be obtained in estimated minimum.- Throws:
IllegalArgumentException
- Raised if tolerance is negative.
-