Author: luc Date: Wed Mar 23 19:36:04 2011 New Revision: 1084690 URL: http://svn.apache.org/viewvc?rev=1084690&view=rev Log: Removed the ConvergingAlgorithm interface and ConvergingAlgorithmImpl class
JIRA: MATH-500 Removed: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/integration/ConvergingAlgorithm.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/integration/ConvergingAlgorithmImpl.java Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/integration/LegendreGaussIntegrator.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/integration/RombergIntegrator.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/integration/SimpsonIntegrator.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/integration/TrapezoidIntegrator.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/integration/UnivariateRealIntegrator.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/integration/UnivariateRealIntegratorImpl.java commons/proper/math/trunk/src/site/xdoc/changes.xml commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/integration/LegendreGaussIntegratorTest.java Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/integration/LegendreGaussIntegrator.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/integration/LegendreGaussIntegrator.java?rev=1084690&r1=1084689&r2=1084690&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/integration/LegendreGaussIntegrator.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/integration/LegendreGaussIntegrator.java Wed Mar 23 19:36:04 2011 @@ -153,12 +153,6 @@ public class LegendreGaussIntegrator ext } - @Deprecated - public double integrate(final double min, final double max) - throws ConvergenceException, MathUserException, IllegalArgumentException { - return integrate(f, min, max); - } - /** {@inheritDoc} */ public double integrate(final UnivariateRealFunction f, final double min, final double max) throws ConvergenceException, MathUserException, IllegalArgumentException { Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/integration/RombergIntegrator.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/integration/RombergIntegrator.java?rev=1084690&r1=1084689&r2=1084690&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/integration/RombergIntegrator.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/integration/RombergIntegrator.java Wed Mar 23 19:36:04 2011 @@ -39,30 +39,12 @@ import org.apache.commons.math.util.Fast public class RombergIntegrator extends UnivariateRealIntegratorImpl { /** - * Construct an integrator for the given function. - * - * @param f function to integrate - * @deprecated as of 2.0 the integrand function is passed as an argument - * to the {@link #integrate(UnivariateRealFunction, double, double)}method. - */ - @Deprecated - public RombergIntegrator(UnivariateRealFunction f) { - super(f, 32); - } - - /** * Construct an integrator. */ public RombergIntegrator() { super(32); } - @Deprecated - public double integrate(final double min, final double max) - throws MaxCountExceededException, MathUserException, IllegalArgumentException { - return integrate(f, min, max); - } - /** {@inheritDoc} */ public double integrate(final UnivariateRealFunction f, final double min, final double max) throws MaxCountExceededException, MathUserException, IllegalArgumentException { Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/integration/SimpsonIntegrator.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/integration/SimpsonIntegrator.java?rev=1084690&r1=1084689&r2=1084690&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/integration/SimpsonIntegrator.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/integration/SimpsonIntegrator.java Wed Mar 23 19:36:04 2011 @@ -38,30 +38,12 @@ import org.apache.commons.math.util.Fast public class SimpsonIntegrator extends UnivariateRealIntegratorImpl { /** - * Construct an integrator for the given function. - * - * @param f function to integrate - * @deprecated as of 2.0 the integrand function is passed as an argument - * to the {@link #integrate(UnivariateRealFunction, double, double)}method. - */ - @Deprecated - public SimpsonIntegrator(UnivariateRealFunction f) { - super(f, 64); - } - - /** * Construct an integrator. */ public SimpsonIntegrator() { super(64); } - @Deprecated - public double integrate(final double min, final double max) - throws MaxCountExceededException, MathUserException, IllegalArgumentException { - return integrate(f, min, max); - } - /** {@inheritDoc} */ public double integrate(final UnivariateRealFunction f, final double min, final double max) throws MaxCountExceededException, MathUserException, IllegalArgumentException { Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/integration/TrapezoidIntegrator.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/integration/TrapezoidIntegrator.java?rev=1084690&r1=1084689&r2=1084690&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/integration/TrapezoidIntegrator.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/integration/TrapezoidIntegrator.java Wed Mar 23 19:36:04 2011 @@ -40,18 +40,6 @@ public class TrapezoidIntegrator extends private double s; /** - * Construct an integrator for the given function. - * - * @param f function to integrate - * @deprecated as of 2.0 the integrand function is passed as an argument - * to the {@link #integrate(UnivariateRealFunction, double, double)}method. - */ - @Deprecated - public TrapezoidIntegrator(UnivariateRealFunction f) { - super(f, 64); - } - - /** * Construct an integrator. */ public TrapezoidIntegrator() { @@ -96,12 +84,6 @@ public class TrapezoidIntegrator extends } } - @Deprecated - public double integrate(final double min, final double max) - throws MaxCountExceededException, MathUserException, IllegalArgumentException { - return integrate(f, min, max); - } - /** {@inheritDoc} */ public double integrate(final UnivariateRealFunction f, final double min, final double max) throws MaxCountExceededException, MathUserException, IllegalArgumentException { Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/integration/UnivariateRealIntegrator.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/integration/UnivariateRealIntegrator.java?rev=1084690&r1=1084689&r2=1084690&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/integration/UnivariateRealIntegrator.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/integration/UnivariateRealIntegrator.java Wed Mar 23 19:36:04 2011 @@ -26,9 +26,74 @@ import org.apache.commons.math.analysis. * @version $Revision$ $Date$ * @since 1.2 */ -public interface UnivariateRealIntegrator extends ConvergingAlgorithm { +public interface UnivariateRealIntegrator { - /** + /** + * Set the upper limit for the number of iterations. + * <p> + * 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.</p> + * <p> + * A {@link ConvergenceException} will be thrown if this number + * is exceeded.</p> + * + * @param count maximum number of iterations + */ + public void setMaximalIterationCount(int count); + + /** + * Get the upper limit for the number of iterations. + * + * @return the actual upper limit + */ + public int getMaximalIterationCount(); + + /** + * Set the absolute accuracy. + * <p> + * 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.</p> + * <p> + * Algorithms are advised to do a plausibility check with the relative + * accuracy, but clients should not rely on this.</p> + * + * @param accuracy the accuracy. + * @throws IllegalArgumentException if the accuracy can't be achieved by + * the solver or is otherwise deemed unreasonable. + */ + public void setAbsoluteAccuracy(double accuracy); + + /** + * Get the actual absolute accuracy. + * + * @return the accuracy + */ + public double getAbsoluteAccuracy(); + + /** + * Set the relative accuracy. + * <p> + * This is used to stop iterations if the absolute accuracy can't be + * achieved due to large values or short mantissa length.</p> + * <p> + * If this should be the primary criterion for convergence rather then a + * safety measure, set the absolute accuracy to a ridiculously small value, + * like {@link org.apache.commons.math.util.MathUtils#SAFE_MIN MathUtils.SAFE_MIN}.</p> + * + * @param accuracy the relative accuracy. + */ + public void setRelativeAccuracy(double accuracy); + + /** + * Get the actual relative accuracy. + * @return the accuracy + */ + public double getRelativeAccuracy(); + + /** * Set the lower limit for the number of iterations. * <p> * Minimal iteration is needed to avoid false early convergence, e.g. Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/integration/UnivariateRealIntegratorImpl.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/integration/UnivariateRealIntegratorImpl.java?rev=1084690&r1=1084689&r2=1084690&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/integration/UnivariateRealIntegratorImpl.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/integration/UnivariateRealIntegratorImpl.java Wed Mar 23 19:36:04 2011 @@ -17,9 +17,8 @@ package org.apache.commons.math.analysis.integration; import org.apache.commons.math.MathRuntimeException; -import org.apache.commons.math.analysis.UnivariateRealFunction; import org.apache.commons.math.exception.util.LocalizedFormats; -import org.apache.commons.math.exception.NullArgumentException; +import org.apache.commons.math.exception.MaxCountExceededException; /** * Provide a default implementation for several generic functions. @@ -27,82 +26,81 @@ import org.apache.commons.math.exception * @version $Revision$ $Date$ * @since 1.2 */ -public abstract class UnivariateRealIntegratorImpl - extends ConvergingAlgorithmImpl implements UnivariateRealIntegrator { +public abstract class UnivariateRealIntegratorImpl implements UnivariateRealIntegrator { + /** Serializable version identifier. */ private static final long serialVersionUID = 6248808456637441533L; + + /** Maximum absolute error. */ + protected double absoluteAccuracy; + + /** Maximum relative error. */ + protected double relativeAccuracy; + + /** Maximum number of iterations. */ + protected int maximalIterationCount; + /** minimum number of iterations */ protected int minimalIterationCount; + /** default minimum number of iterations */ protected int defaultMinimalIterationCount; + + /** The last iteration count. */ + protected int iterationCount; + /** indicates whether an integral has been computed */ protected boolean resultComputed = false; + /** the last computed integral */ protected double result; - /** The integrand functione. - * @deprecated as of 2.0 the integrand function is passed as an argument - * to the {@link #integrate(UnivariateRealFunction, double, double)}method. */ - @Deprecated - protected UnivariateRealFunction f; - - /** - * Construct an integrator with given iteration count and accuracy. - * - * @param f the integrand function - * @param defaultMaximalIterationCount maximum number of iterations - * @throws IllegalArgumentException if f is null or the iteration - * limits are not valid - * @deprecated as of 2.0 the integrand function is passed as an argument - * to the {@link #integrate(UnivariateRealFunction, double, double)}method. - */ - @Deprecated - protected UnivariateRealIntegratorImpl(final UnivariateRealFunction f, - final int defaultMaximalIterationCount) - throws IllegalArgumentException { - - setMaximalIterationCount(defaultMaximalIterationCount); - setAbsoluteAccuracy(1.0e-15); - - if (f == null) { - throw new NullArgumentException(LocalizedFormats.FUNCTION); - } - - this.f = f; - - // parameters that are problem specific - setRelativeAccuracy(1.0e-6); - this.defaultMinimalIterationCount = 3; - this.minimalIterationCount = defaultMinimalIterationCount; - - verifyIterationCount(); - } /** * Construct an integrator with given iteration count and accuracy. * - * @param defaultMaximalIterationCount maximum number of iterations - * @throws IllegalArgumentException if f is null or the iteration - * limits are not valid + * @param maximalIterationCount maximum number of iterations */ - protected UnivariateRealIntegratorImpl(final int defaultMaximalIterationCount) - throws IllegalArgumentException { + protected UnivariateRealIntegratorImpl(final int maximalIterationCount) { - setMaximalIterationCount(defaultMaximalIterationCount); + setMaximalIterationCount(maximalIterationCount); setAbsoluteAccuracy(1.0e-15); - // parameters that are problem specific setRelativeAccuracy(1.0e-6); - this.defaultMinimalIterationCount = 3; - this.minimalIterationCount = defaultMinimalIterationCount; + setMinimalIterationCount(3); verifyIterationCount(); } - /** - * Access the last computed integral. - * - * @return the last computed integral - * @throws IllegalStateException if no integral has been computed - */ + /** {@inheritDoc} */ + public void setMaximalIterationCount(final int count) { + maximalIterationCount = count; + } + + /** {@inheritDoc} */ + public int getMaximalIterationCount() { + return maximalIterationCount; + } + + /** {@inheritDoc} */ + public void setAbsoluteAccuracy(double accuracy) { + absoluteAccuracy = accuracy; + } + + /** {@inheritDoc} */ + public double getAbsoluteAccuracy() { + return absoluteAccuracy; + } + + /** {@inheritDoc} */ + public void setRelativeAccuracy(final double accuracy) { + relativeAccuracy = accuracy; + } + + /** {@inheritDoc} */ + public double getRelativeAccuracy() { + return relativeAccuracy; + } + + /** {@inheritDoc} */ public double getResult() throws IllegalStateException { if (resultComputed) { return result; @@ -117,7 +115,7 @@ public abstract class UnivariateRealInte * @param newResult the result to set * @param iterationCount the iteration count to set */ - protected final void setResult(double newResult, int iterationCount) { + protected final void setResult(final double newResult, final int iterationCount) { this.result = newResult; this.iterationCount = iterationCount; this.resultComputed = true; @@ -132,7 +130,7 @@ public abstract class UnivariateRealInte } /** {@inheritDoc} */ - public void setMinimalIterationCount(int count) { + public void setMinimalIterationCount(final int count) { minimalIterationCount = count; } @@ -153,8 +151,8 @@ public abstract class UnivariateRealInte * @param upper upper endpoint * @throws IllegalArgumentException if not interval */ - protected void verifyInterval(double lower, double upper) throws - IllegalArgumentException { + protected void verifyInterval(final double lower, final double upper) + throws IllegalArgumentException { if (lower >= upper) { throw MathRuntimeException.createIllegalArgumentException( LocalizedFormats.ENDPOINTS_NOT_AN_INTERVAL, @@ -174,4 +172,27 @@ public abstract class UnivariateRealInte minimalIterationCount, maximalIterationCount); } } + + /** + * Reset the iterations counter to 0. + * + * @since 2.2 + */ + protected void resetIterationsCounter() { + iterationCount = 0; + } + + /** + * Increment the iterations counter by 1. + * + * @throws MaxCountExceededException if the maximal number + * of iterations is exceeded. + * @since 2.2 + */ + protected void incrementIterationsCounter() { + if (++iterationCount > maximalIterationCount) { + throw new MaxCountExceededException(maximalIterationCount); + } + } + } Modified: commons/proper/math/trunk/src/site/xdoc/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/site/xdoc/changes.xml?rev=1084690&r1=1084689&r2=1084690&view=diff ============================================================================== --- commons/proper/math/trunk/src/site/xdoc/changes.xml (original) +++ commons/proper/math/trunk/src/site/xdoc/changes.xml Wed Mar 23 19:36:04 2011 @@ -52,6 +52,9 @@ The <action> type attribute can be add,u If the output is not quite correct, check for invisible trailing spaces! --> <release version="3.0" date="TBD" description="TBD"> + <action dev="luc" type="fix" issue="MATH-500" due-to="Gilles Sadowski" > + Removed the ConvergingAlgorithm interface and ConvergingAlgorithmImpl class + </action> <action dev="luc" type="add" issue="MATH-436" due-to="Thomas Neidhart"> Added a consistency check for number of points with respect to the number of clusters in Kmeans++ clustering Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/integration/LegendreGaussIntegratorTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/integration/LegendreGaussIntegratorTest.java?rev=1084690&r1=1084689&r2=1084690&view=diff ============================================================================== --- commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/integration/LegendreGaussIntegratorTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/integration/LegendreGaussIntegratorTest.java Wed Mar 23 19:36:04 2011 @@ -35,7 +35,7 @@ public class LegendreGaussIntegratorTest @Test public void testSinFunction() throws MathException { UnivariateRealFunction f = new SinFunction(); - UnivariateRealIntegrator integrator = new LegendreGaussIntegrator(5, 64); + UnivariateRealIntegratorImpl integrator = new LegendreGaussIntegrator(5, 64); integrator.setAbsoluteAccuracy(1.0e-10); integrator.setRelativeAccuracy(1.0e-14); integrator.setMinimalIterationCount(2);