Class SimpleUnivariateValueChecker
java.lang.Object
org.apache.commons.math3.optim.AbstractConvergenceChecker<UnivariatePointValuePair>
org.apache.commons.math3.optim.univariate.SimpleUnivariateValueChecker
- All Implemented Interfaces:
ConvergenceChecker<UnivariatePointValuePair>
public class SimpleUnivariateValueChecker
extends AbstractConvergenceChecker<UnivariatePointValuePair>
Simple implementation of the
The
ConvergenceChecker
interface
that uses only objective function values.
Convergence is considered to have been reached if either the relative
difference between the objective function values is smaller than a
threshold or if either the absolute difference between the objective
function values is smaller than another threshold.
The
converged
method will also return true
if the number of iterations
has been set (see this constructor
).- Since:
- 3.1
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final int
IfmaxIterationCount
is set to this value, the number of iterations will never causeconverged(int,UnivariatePointValuePair,UnivariatePointValuePair)
to returntrue
.private final int
Number of iterations after which theconverged(int,UnivariatePointValuePair,UnivariatePointValuePair)
method will return true (unless the check is disabled). -
Constructor Summary
ConstructorsConstructorDescriptionSimpleUnivariateValueChecker
(double relativeThreshold, double absoluteThreshold) Build an instance with specified thresholds.SimpleUnivariateValueChecker
(double relativeThreshold, double absoluteThreshold, int maxIter) Builds an instance with specified thresholds. -
Method Summary
Modifier and TypeMethodDescriptionboolean
converged
(int iteration, UnivariatePointValuePair previous, UnivariatePointValuePair current) Check if the optimization algorithm has converged considering the last two points.Methods inherited from class org.apache.commons.math3.optim.AbstractConvergenceChecker
getAbsoluteThreshold, getRelativeThreshold
-
Field Details
-
ITERATION_CHECK_DISABLED
private static final int ITERATION_CHECK_DISABLEDIfmaxIterationCount
is set to this value, the number of iterations will never causeconverged(int,UnivariatePointValuePair,UnivariatePointValuePair)
to returntrue
.- See Also:
-
maxIterationCount
private final int maxIterationCountNumber of iterations after which theconverged(int,UnivariatePointValuePair,UnivariatePointValuePair)
method will return true (unless the check is disabled).
-
-
Constructor Details
-
SimpleUnivariateValueChecker
public SimpleUnivariateValueChecker(double relativeThreshold, double absoluteThreshold) Build an instance with specified thresholds. In order to perform only relative checks, the absolute tolerance must be set to a negative value. In order to perform only absolute checks, the relative tolerance must be set to a negative value.- Parameters:
relativeThreshold
- relative tolerance thresholdabsoluteThreshold
- absolute tolerance threshold
-
SimpleUnivariateValueChecker
public SimpleUnivariateValueChecker(double relativeThreshold, double absoluteThreshold, int maxIter) Builds an instance with specified thresholds. In order to perform only relative checks, the absolute tolerance must be set to a negative value. In order to perform only absolute checks, the relative tolerance must be set to a negative value.- Parameters:
relativeThreshold
- relative tolerance thresholdabsoluteThreshold
- absolute tolerance thresholdmaxIter
- Maximum iteration count.- Throws:
NotStrictlyPositiveException
- ifmaxIter <= 0
.- Since:
- 3.1
-
-
Method Details
-
converged
public boolean converged(int iteration, UnivariatePointValuePair previous, UnivariatePointValuePair current) Check if the optimization algorithm has converged considering the last two points. This method may be called several time from the same algorithm iteration with different points. This can be detected by checking the iteration number at each call if needed. Each time this method is called, the previous and current point correspond to points with the same role at each iteration, so they can be compared. As an example, simplex-based algorithms call this method for all points of the simplex, not only for the best or worst ones.- Specified by:
converged
in interfaceConvergenceChecker<UnivariatePointValuePair>
- Specified by:
converged
in classAbstractConvergenceChecker<UnivariatePointValuePair>
- Parameters:
iteration
- Index of current iterationprevious
- Best point in the previous iteration.current
- Best point in the current iteration.- Returns:
true
if the algorithm has converged.
-