## org.apache.commons.math
Class ConvergingAlgorithmImpl

    java.lang.Object
      org.apache.commons.math.ConvergingAlgorithmImpl

All Implemented Interfaces:
  ConvergingAlgorithm

Direct Known Subclasses:
  AbstractUnivariateRealOptimizer, UnivariateRealIntegratorImpl, UnivariateRealSolverImpl

    public abstract class ConvergingAlgorithmImpl

extends java.lang.Object
implements ConvergingAlgorithm

Provide a default implementation for several functions useful to generic converging algorithms.

Since:
  2.0
Version:
  $Revision: 811685 $ $Date: 2009-09-05 13:36:48 -0400 (Sat, 05 Sep 2009) $

Field Summary
`protected double` `absoluteAccuracy` Maximum absolute error.
`protected double` `defaultAbsoluteAccuracy` Default maximum absolute error.
`protected int` `defaultMaximalIterationCount` Default maximum number of iterations.
`protected double` `defaultRelativeAccuracy` Default maximum relative error.
`protected int` `iterationCount` The last iteration count.
`protected int` `maximalIterationCount` Maximum number of iterations.
`protected double` `relativeAccuracy` Maximum relative error.

Constructor Summary
`protected` `ConvergingAlgorithmImpl(int defaultMaximalIterationCount, double defaultAbsoluteAccuracy)` Construct an algorithm with given iteration count and accuracy.

Method Summary
`double` `getAbsoluteAccuracy()` Get the actual absolute accuracy.
`int` `getIterationCount()` Get the number of iterations in the last run of the algorithm.
`int` `getMaximalIterationCount()` Get the upper limit for the number of iterations.
`double` `getRelativeAccuracy()` Get the actual relative accuracy.
`void` `resetAbsoluteAccuracy()` Reset the absolute accuracy to the default.
`void` `resetMaximalIterationCount()` Reset the upper limit for the number of iterations to the default.
`void` `resetRelativeAccuracy()` Reset the relative accuracy to the default.
`void` `setAbsoluteAccuracy(double accuracy)` Set the absolute accuracy.
`void` `setMaximalIterationCount(int count)` Set the upper limit for the number of iterations.
`void` `setRelativeAccuracy(double accuracy)` Set the relative accuracy.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### absoluteAccuracy

    protected double absoluteAccuracy

  Maximum absolute error.

### relativeAccuracy

    protected double relativeAccuracy

  Maximum relative error.

### maximalIterationCount

    protected int maximalIterationCount

  Maximum number of iterations.

### defaultAbsoluteAccuracy

    protected double defaultAbsoluteAccuracy

  Default maximum absolute error.

### defaultRelativeAccuracy

    protected double defaultRelativeAccuracy

  Default maximum relative error.

### defaultMaximalIterationCount

    protected int defaultMaximalIterationCount

  Default maximum number of iterations.

### iterationCount

    protected int iterationCount

  The last iteration count.

Constructor Detail

### ConvergingAlgorithmImpl

    protected ConvergingAlgorithmImpl(int defaultMaximalIterationCount,
                                      double defaultAbsoluteAccuracy)

  Construct an algorithm with given iteration count and accuracy.

  Parameters:
    `defaultAbsoluteAccuracy` - maximum absolute error
    `defaultMaximalIterationCount` - maximum number of iterations
  Throws:
    `java.lang.IllegalArgumentException` - if f is null or the defaultAbsoluteAccuracy is not valid

Method Detail

### getIterationCount

    public int getIterationCount()

  Get the number of iterations in the last run of the algorithm.

  This is mainly meant for testing purposes. It may occasionally help track down performance problems: if the iteration count is notoriously high, check whether the problem is evaluated properly, and whether another algorithm is more amenable to the problem.

  Specified by:
    `getIterationCount` in interface `ConvergingAlgorithm`
  Returns:
    the last iteration count.

### setAbsoluteAccuracy

    public void setAbsoluteAccuracy(double accuracy)

  Set the absolute accuracy.

  The default is usually chosen so that results in the interval -10..-0.1 and +0.1..+10 can be found with a reasonable accuracy. If the expected absolute value of your results is of much smaller magnitude, set this to a smaller value.

  Algorithms are advised to do a plausibility check with the relative accuracy, but clients should not rely on this.

  Specified by:
    `setAbsoluteAccuracy` in interface `ConvergingAlgorithm`
  Parameters:
    `accuracy` - the accuracy.

### getAbsoluteAccuracy

    public double getAbsoluteAccuracy()

  Get the actual absolute accuracy.

  Specified by:
    `getAbsoluteAccuracy` in interface `ConvergingAlgorithm`
  Returns:
    the accuracy

### resetAbsoluteAccuracy

    public void resetAbsoluteAccuracy()

  Reset the absolute accuracy to the default.

  The default value is provided by the algorithm implementation.

  Specified by:
    `resetAbsoluteAccuracy` in interface `ConvergingAlgorithm`

### setMaximalIterationCount

    public void setMaximalIterationCount(int count)

  Set the upper limit for the number of iterations.

  Usually a high iteration count indicates convergence problems. However, the "reasonable value" varies widely for different algorithms. Users are advised to use the default value supplied by the algorithm.

  A `ConvergenceException` will be thrown if this number is exceeded.

  Specified by:
    `setMaximalIterationCount` in interface `ConvergingAlgorithm`
  Parameters:
    `count` - maximum number of iterations

### getMaximalIterationCount

    public int getMaximalIterationCount()

  Get the upper limit for the number of iterations.

  Specified by:
    `getMaximalIterationCount` in interface `ConvergingAlgorithm`
  Returns:
    the actual upper limit

### resetMaximalIterationCount

    public void resetMaximalIterationCount()

  Reset the upper limit for the number of iterations to the default.

  The default value is supplied by the algorithm implementation.

  Specified by:
    `resetMaximalIterationCount` in interface `ConvergingAlgorithm`
  See Also:
    `ConvergingAlgorithm.setMaximalIterationCount(int)`

### setRelativeAccuracy

    public void setRelativeAccuracy(double accuracy)

  Set the relative accuracy.

  This is used to stop iterations if the absolute accuracy can't be achieved due to large values or short mantissa length.

  If this should be the primary criterion for convergence rather then a safety measure, set the absolute accuracy to a ridiculously small value, like `MathUtils.SAFE_MIN`.

  Specified by:
    `setRelativeAccuracy` in interface `ConvergingAlgorithm`
  Parameters:
    `accuracy` - the relative accuracy.

### getRelativeAccuracy

    public double getRelativeAccuracy()

  Get the actual relative accuracy.

  Specified by:
    `getRelativeAccuracy` in interface `ConvergingAlgorithm`
  Returns:
    the accuracy

### resetRelativeAccuracy

    public void resetRelativeAccuracy()

  Reset the relative accuracy to the default. The default value is provided by the algorithm implementation.

  Specified by:
    `resetRelativeAccuracy` in interface `ConvergingAlgorithm`

Copyright (c) 2003-2011 Apache Software Foundation