Class ConjugateGradientMultiOptimizer
java.lang.Object
com.irurueta.numerical.optimization.Optimizer
com.irurueta.numerical.optimization.MultiOptimizer
com.irurueta.numerical.optimization.LineMultiOptimizer
com.irurueta.numerical.optimization.ConjugateGradientMultiOptimizer
This class searches for a multi dimension function local minimum.
The local minimum is searched by starting the algorithm at a start point
and a given direction which should be close and point to the local minimum to
be found to achieve the best accuracy with the lowest number of iterations.
NOTE: this algorithm might not have proper convergence in some situations,
but it is ensured to provide faster convergence than other algorithms such
as Brent because gradient information is also provided.
The implementation of this class is based on Numerical Recipes 3rd ed.
Section 10.8 page 515.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final double
Constant defining default tolerance or accuracy to be achieved on the minimum being estimated by this class.static final boolean
Defines whether Polak-Ribiere is used if true, otherwise Fletcher-Reeves will be used.static final double
Constant defining a value to be considered as machine precision.private double
Value of the function at the minimum.Listener to obtain gradient values for the multi dimension function being evaluated.static final double
Convergence criterion for the zero gradient test.private int
Member contains number of iterations that were needed to estimate a minimum.static final int
Maximum allowed iterations.static final double
Minimum allowed tolerance value.private double
The fractional tolerance in the function value such that failure to decrease by more than this amount on one iteration signals done-ness.private boolean
Boolean indicating whether Polak-Ribiere method is used if true, otherwise Fletcher-Reeves will be used.Fields inherited from class com.irurueta.numerical.optimization.LineMultiOptimizer
p, xi
Fields inherited from class com.irurueta.numerical.optimization.MultiOptimizer
fmin, listener, resultAvailable, xmin
Fields inherited from class com.irurueta.numerical.optimization.Optimizer
iterationCompletedListener, locked
-
Constructor Summary
ConstructorsConstructorDescriptionEmpty constructor.ConjugateGradientMultiOptimizer
(MultiDimensionFunctionEvaluatorListener listener, GradientFunctionEvaluatorListener gradientListener, double[] point, double[] direction, double tolerance, boolean usePolakRibiere) Constructor.ConjugateGradientMultiOptimizer
(MultiDimensionFunctionEvaluatorListener listener, GradientFunctionEvaluatorListener gradientListener, double[] point, double tolerance, boolean usePolakRibiere) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionReturns gradient listener in charge of obtaining gradient values for the function to be evaluated.int
Return number of iterations that were needed to estimate a minimum.double
Returns tolerance or accuracy to be expected on estimated local minimum.private void
internalSetStartPoint
(double[] point) Internal method to set start point where local minimum is searched nearby.private void
internalSetTolerance
(double tolerance) Internal method to set tolerance or accuracy to be expected on estimated local minimum.boolean
Returns boolean indicating whether a gradient listener has already been provided and is available for retrieval.boolean
Returns boolean indicating whether Polak-Ribiere method is used or Fletcher-Reeves is used instead.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.void
setGradientListener
(GradientFunctionEvaluatorListener gradientListener) Sets gradient listener in charge of obtaining gradient values for the function to be evaluated.void
setStartPoint
(double[] point) Sets start point where local minimum is searched nearby.void
setTolerance
(double tolerance) Sets tolerance or accuracy to be expected on estimated local minimum.void
setUsePolakRibiere
(boolean useIt) Sets boolean indicating whether Polak-Ribiere method or Fletcher-Reeves method is used.Methods inherited from class com.irurueta.numerical.optimization.LineMultiOptimizer
getDirection, getStartPoint, isDirectionAvailable, isStartPointAvailable, linmin, setStartPointAndDirection
Methods inherited from class com.irurueta.numerical.optimization.MultiOptimizer
getEvaluationAtResult, getListener, getResult, isListenerAvailable, isResultAvailable, setListener
Methods inherited from class com.irurueta.numerical.optimization.Optimizer
getOnIterationCompletedListener, isLocked, setOnIterationCompletedListener
-
Field Details
-
DEFAULT_TOLERANCE
public static final double DEFAULT_TOLERANCEConstant defining default tolerance or accuracy to be achieved on the minimum being estimated by this class.- See Also:
-
MIN_TOLERANCE
public static final double MIN_TOLERANCEMinimum allowed tolerance value.- See Also:
-
ITMAX
public static final int ITMAXMaximum allowed iterations.- See Also:
-
EPS
public static final double EPSConstant defining a value to be considered as machine precision.- See Also:
-
GTOL
public static final double GTOLConvergence criterion for the zero gradient test.- See Also:
-
DEFAULT_USE_POLAK_RIBIERE
public static final boolean DEFAULT_USE_POLAK_RIBIEREDefines whether Polak-Ribiere is used if true, otherwise Fletcher-Reeves will be used.- See Also:
-
tolerance
private double toleranceThe fractional tolerance in the function value such that failure to decrease by more than this amount on one iteration signals done-ness. -
iter
private int iterMember contains number of iterations that were needed to estimate a minimum. -
fret
private double fretValue of the function at the minimum. -
gradientListener
Listener to obtain gradient values for the multi dimension function being evaluated. If the gradient is unknown (e.g. doesn't have a closed expression), the provided listener could use a GradientEstimator to obtain one. -
usePolakRibiere
private boolean usePolakRibiereBoolean indicating whether Polak-Ribiere method is used if true, otherwise Fletcher-Reeves will be used.
-
-
Constructor Details
-
ConjugateGradientMultiOptimizer
public ConjugateGradientMultiOptimizer()Empty constructor. -
ConjugateGradientMultiOptimizer
public ConjugateGradientMultiOptimizer(MultiDimensionFunctionEvaluatorListener listener, GradientFunctionEvaluatorListener gradientListener, double[] point, double[] direction, double tolerance, boolean usePolakRibiere) Constructor.- Parameters:
listener
- Listener to evaluate a multi-dimension function.gradientListener
- Listener to obtain gradient value for the multi-dimension function being evaluated.point
- Start point where algorithm will be started. Start point should be close to the local minimum to be found. Provided array must have a length equal to the number of dimensions of the function being evaluated, otherwise and exception will be raised when searching for the minimum.direction
- Direction to start looking for a minimum. Provided array must have the same length as the number of dimensions of the function being evaluated. Provided direction is considered as a vector pointing to the minimum to be found.tolerance
- Tolerance or accuracy to be expected on estimated local minimum.usePolakRibiere
- True if Polak-Ribiere method is used, otherwise Fletcher-Reeves will be used.- Throws:
IllegalArgumentException
- Raised if provided point and direction don't have the same length or if provided tolerance is negative.
-
ConjugateGradientMultiOptimizer
public ConjugateGradientMultiOptimizer(MultiDimensionFunctionEvaluatorListener listener, GradientFunctionEvaluatorListener gradientListener, double[] point, double tolerance, boolean usePolakRibiere) Constructor.- Parameters:
listener
- Listener to evaluate a multidimensional function.gradientListener
- Listener to obtain gradient value for the multidimensional function being evaluated.point
- Start point where algorithm will be started. Start point should be close to the local minimum to be found. Provided array must have a length equal to the number of dimensions of the function being evaluated, otherwise and exception will be raised when searching for the minimum.tolerance
- Tolerance or accuracy to be expected on estimated local minimum.usePolakRibiere
- True if Polak-Ribiere method is used, otherwise Fletcher-Reeves will be used.- Throws:
IllegalArgumentException
- Raised if tolerance is negative.
-
-
Method Details
-
minimize
This function estimates a function minimum. Implementations of this class will usually search a local minimum close to a start point and will start looking into provided start direction. Minimization of a function f. Input consists of an initial starting point p. The initial matrix xi, whose columns contain the initial set of directions, is set to the identity. Returned is the best point found, at which point fret is the minimum function value and iter is the number of iterations taken.- 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 a listener, a gradient listener and a start point haven't been provided.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. An instance is ready once a listener, a gradient listener and a start point are provided.- Overrides:
isReady
in classLineMultiOptimizer
- Returns:
- True if this instance is ready, false otherwise.
-
getTolerance
public double getTolerance()Returns tolerance or accuracy to be expected on estimated local minimum.- Returns:
- Tolerance or accuracy to be expected on estimated local minimum.
-
setTolerance
Sets tolerance or accuracy to be expected on estimated local minimum.- Parameters:
tolerance
- Tolerance or accuracy to be expected on estimated local minimum.- Throws:
LockedException
- Raised if this instance is locked.IllegalArgumentException
- Raised if provided tolerance is negative.
-
getGradientListener
Returns gradient listener in charge of obtaining gradient values for the function to be evaluated.- Returns:
- Gradient listener.
- Throws:
NotAvailableException
- Raised if gradient listener has not yet been provided.
-
setGradientListener
public void setGradientListener(GradientFunctionEvaluatorListener gradientListener) throws LockedException Sets gradient listener in charge of obtaining gradient values for the function to be evaluated.- Parameters:
gradientListener
- Gradient listener.- Throws:
LockedException
- Raised if this instance is locked.
-
isGradientListenerAvailable
public boolean isGradientListenerAvailable()Returns boolean indicating whether a gradient listener has already been provided and is available for retrieval.- Returns:
- True if available, false otherwise.
-
isPolakRibiereEnabled
public boolean isPolakRibiereEnabled()Returns boolean indicating whether Polak-Ribiere method is used or Fletcher-Reeves is used instead.- Returns:
- If true, Polak-Ribiere method is used, otherwise Fletcher-Reeves is used.
-
setUsePolakRibiere
Sets boolean indicating whether Polak-Ribiere method or Fletcher-Reeves method is used. If provided value is true, Polak-Ribiere method will be used, otherwise Flecther-Reeves method will be used.- Parameters:
useIt
- Boolean to determine method.- Throws:
LockedException
- Raised if this instance is locked.
-
setStartPoint
Sets start point where local minimum is searched nearby.- Parameters:
point
- Start point to search for a local minimum.- Throws:
LockedException
- Raised if this instance is locked.
-
getIterations
public int getIterations()Return number of iterations that were needed to estimate a minimum.- Returns:
- number of iterations that were needed.
-
internalSetTolerance
private void internalSetTolerance(double tolerance) Internal method to set tolerance or accuracy to be expected on estimated local minimum. This method does not check whether this instance is locked.- Parameters:
tolerance
- Tolerance or accuracy to be expected on estimated local minimum.- Throws:
IllegalArgumentException
- Raised if provided tolerance is negative.
-
internalSetStartPoint
private void internalSetStartPoint(double[] point) Internal method to set start point where local minimum is searched nearby. This method does not check whether this instance is locked.- Parameters:
point
- Start point to search for a local minimum.
-