Author: luc Date: Wed Aug 24 16:03:16 2011 New Revision: 1161181 URL: http://svn.apache.org/viewvc?rev=1161181&view=rev Log: Refactored integration API for consistency with solvers API. Now the main convergence parameters are set in the constructor and remain fixed.
JIRA: MATH-501 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 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=1161181&r1=1161180&r2=1161181&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 Aug 24 16:03:16 2011 @@ -214,8 +214,7 @@ public class LegendreGaussIntegrator ext // check convergence if ((iterations.getCount() + 1 >= minimalIterationCount) && (delta <= limit)) { - setResult(t); - return result; + return t; } // prepare next iteration 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=1161181&r1=1161180&r2=1161181&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 Aug 24 16:03:16 2011 @@ -131,8 +131,7 @@ public class RombergIntegrator extends U final double delta = FastMath.abs(s - olds); final double rLimit = relativeAccuracy * (FastMath.abs(olds) + FastMath.abs(s)) * 0.5; if ((delta <= rLimit) || (delta <= absoluteAccuracy)) { - setResult(s); - return result; + return s; } } olds = s; 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=1161181&r1=1161180&r2=1161181&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 Aug 24 16:03:16 2011 @@ -102,10 +102,9 @@ public class SimpsonIntegrator extends U TrapezoidIntegrator qtrap = new TrapezoidIntegrator(); if (minimalIterationCount == 1) { - final double s = (4 * qtrap.stage(this, 1) - qtrap.stage(this, 0)) / 3.0; - setResult(s); - return result; + return (4 * qtrap.stage(this, 1) - qtrap.stage(this, 0)) / 3.0; } + // Simpson's rule requires at least two trapezoid stages. double olds = 0; double oldt = qtrap.stage(this, 0); @@ -118,8 +117,7 @@ public class SimpsonIntegrator extends U final double rLimit = relativeAccuracy * (FastMath.abs(olds) + FastMath.abs(s)) * 0.5; if ((delta <= rLimit) || (delta <= absoluteAccuracy)) { - setResult(s); - return result; + return s; } } olds = s; 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=1161181&r1=1161180&r2=1161181&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 Aug 24 16:03:16 2011 @@ -151,8 +151,7 @@ public class TrapezoidIntegrator extends final double rLimit = relativeAccuracy * (FastMath.abs(oldt) + FastMath.abs(t)) * 0.5; if ((delta <= rLimit) || (delta <= absoluteAccuracy)) { - setResult(t); - return result; + return t; } } oldt = t; 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=1161181&r1=1161180&r2=1161181&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 Aug 24 16:03:16 2011 @@ -78,28 +78,15 @@ public interface UnivariateRealIntegrato MathIllegalArgumentException, NullArgumentException; /** - * Get the result of the last run of the integrator. - * - * @return the last result - * @throws IllegalStateException if there is no result available, either - * because no result was yet computed or the last attempt failed - */ - double getResult() throws IllegalStateException; - - /** * Get the number of function evaluations of the last run of the integrator. * @return number of function evaluations - * @throws IllegalStateException if there is no result available, either - * because no result was yet computed or the last attempt failed */ - int getEvaluations() throws IllegalStateException; + int getEvaluations(); /** * Get the number of iterations of the last run of the integrator. * @return number of iterations - * @throws IllegalStateException if there is no result available, either - * because no result was yet computed or the last attempt failed */ - int getIterations() throws IllegalStateException; + int getIterations(); } 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=1161181&r1=1161180&r2=1161181&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 Aug 24 16:03:16 2011 @@ -17,7 +17,6 @@ package org.apache.commons.math.analysis.integration; import org.apache.commons.math.ConvergenceException; -import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.analysis.UnivariateRealFunction; import org.apache.commons.math.analysis.solvers.UnivariateRealSolverUtils; import org.apache.commons.math.exception.MathIllegalArgumentException; @@ -26,7 +25,6 @@ import org.apache.commons.math.exception import org.apache.commons.math.exception.NullArgumentException; import org.apache.commons.math.exception.NumberIsTooSmallException; import org.apache.commons.math.exception.TooManyEvaluationsException; -import org.apache.commons.math.exception.util.LocalizedFormats; import org.apache.commons.math.util.Incrementor; import org.apache.commons.math.util.MathUtils; @@ -74,12 +72,6 @@ public abstract class UnivariateRealInte /** Upper bound for the interval. */ protected double max; - /** indicates whether an integral has been computed */ - protected boolean resultComputed = false; - - /** the last computed integral */ - protected double result; - /** * Construct an integrator with given accuracies and iteration counts. * <p> @@ -189,41 +181,13 @@ public abstract class UnivariateRealInte } /** {@inheritDoc} */ - public double getResult() throws IllegalStateException { - if (resultComputed) { - return result; - } else { - throw MathRuntimeException.createIllegalStateException(LocalizedFormats.NO_RESULT_AVAILABLE); - } - } - - /** {@inheritDoc} */ - public int getEvaluations() throws IllegalStateException { - if (resultComputed) { - return evaluations.getCount(); - } else { - throw MathRuntimeException.createIllegalStateException(LocalizedFormats.NO_RESULT_AVAILABLE); - } + public int getEvaluations() { + return evaluations.getCount(); } /** {@inheritDoc} */ - public int getIterations() throws IllegalStateException { - if (resultComputed) { - return iterations.getCount(); - } else { - throw MathRuntimeException.createIllegalStateException(LocalizedFormats.NO_RESULT_AVAILABLE); - } - } - - /** - * Convenience function for implementations. - * - * @param newResult the result to set - * @param newCount the iteration count to set - */ - protected final void setResult(final double newResult) { - result = newResult; - resultComputed = true; + public int getIterations() { + return iterations.getCount(); } /** @@ -272,7 +236,6 @@ public abstract class UnivariateRealInte evaluations.setMaximalCount(maxEval); evaluations.resetCount(); iterations.resetCount(); - resultComputed = false; } 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=1161181&r1=1161180&r2=1161181&view=diff ============================================================================== --- commons/proper/math/trunk/src/site/xdoc/changes.xml (original) +++ commons/proper/math/trunk/src/site/xdoc/changes.xml Wed Aug 24 16:03:16 2011 @@ -52,10 +52,13 @@ 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-501" > + Refactored integration API for consistency with solvers API. Now the main convergence + parameters are set in the constructor and remain fixed. + </action> <action dev="luc" type="fix" issue="MATH-464" > - Changed integration API for consistency with solvers API. Now the main convergence - parameters are set in the constructor and remain fixed, but a maximal number of function - evaluation must be provided at each call to the integration method. + Added a maximal number of function evaluations to the integration method, similar + to what is done in the solvers API. </action> <action dev="psteitz" type="update" issue="MATH-449" due-to="Patrick Meyer"> Added storeless covariance implementation.