Refactored integration API for consistency with solvers API.
Now the main convergence parameters are set in the constructor and remain fixed. JIRA: MATH-501 git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1161181 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
9161afbbbc
commit
f9ea0c63a0
|
@ -214,8 +214,7 @@ public class LegendreGaussIntegrator extends UnivariateRealIntegratorImpl {
|
|||
|
||||
// check convergence
|
||||
if ((iterations.getCount() + 1 >= minimalIterationCount) && (delta <= limit)) {
|
||||
setResult(t);
|
||||
return result;
|
||||
return t;
|
||||
}
|
||||
|
||||
// prepare next iteration
|
||||
|
|
|
@ -131,8 +131,7 @@ public class RombergIntegrator extends UnivariateRealIntegratorImpl {
|
|||
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;
|
||||
|
|
|
@ -102,10 +102,9 @@ public class SimpsonIntegrator extends UnivariateRealIntegratorImpl {
|
|||
|
||||
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 UnivariateRealIntegratorImpl {
|
|||
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;
|
||||
|
|
|
@ -151,8 +151,7 @@ public class TrapezoidIntegrator extends UnivariateRealIntegratorImpl {
|
|||
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;
|
||||
|
|
|
@ -77,29 +77,16 @@ public interface UnivariateRealIntegrator {
|
|||
throws TooManyEvaluationsException, ConvergenceException,
|
||||
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();
|
||||
|
||||
}
|
||||
|
|
|
@ -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.NotStrictlyPositiveException;
|
|||
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 UnivariateRealIntegratorImpl implements 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 UnivariateRealIntegratorImpl implements UnivariateRealInte
|
|||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public double getResult() throws IllegalStateException {
|
||||
if (resultComputed) {
|
||||
return result;
|
||||
} else {
|
||||
throw MathRuntimeException.createIllegalStateException(LocalizedFormats.NO_RESULT_AVAILABLE);
|
||||
}
|
||||
public int getEvaluations() {
|
||||
return evaluations.getCount();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public int getEvaluations() throws IllegalStateException {
|
||||
if (resultComputed) {
|
||||
return evaluations.getCount();
|
||||
} else {
|
||||
throw MathRuntimeException.createIllegalStateException(LocalizedFormats.NO_RESULT_AVAILABLE);
|
||||
}
|
||||
}
|
||||
|
||||
/** {@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 UnivariateRealIntegratorImpl implements UnivariateRealInte
|
|||
evaluations.setMaximalCount(maxEval);
|
||||
evaluations.resetCount();
|
||||
iterations.resetCount();
|
||||
resultComputed = false;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -52,10 +52,13 @@ The <action> type attribute can be add,update,fix,remove.
|
|||
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.
|
||||
|
|
Loading…
Reference in New Issue