You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by lu...@apache.org on 2009/06/21 19:01:04 UTC
svn commit: r787050 - in /commons/proper/math/trunk/src:
java/org/apache/commons/math/ java/org/apache/commons/math/ode/
java/org/apache/commons/math/ode/nonstiff/
test/org/apache/commons/math/ode/nonstiff/
Author: luc
Date: Sun Jun 21 17:01:03 2009
New Revision: 787050
URL: http://svn.apache.org/viewvc?rev=787050&view=rev
Log:
removed the current point from count in multistep integrators
updated documentation since now Adams-Bashforth and Adams-Moulton
are adaptive stepsize integrators
Modified:
commons/proper/math/trunk/src/java/org/apache/commons/math/MessagesResources_fr.java
commons/proper/math/trunk/src/java/org/apache/commons/math/ode/MultistepIntegrator.java
commons/proper/math/trunk/src/java/org/apache/commons/math/ode/nonstiff/AdamsBashforthIntegrator.java
commons/proper/math/trunk/src/java/org/apache/commons/math/ode/nonstiff/AdamsMoultonIntegrator.java
commons/proper/math/trunk/src/test/org/apache/commons/math/ode/nonstiff/AdamsBashforthIntegratorTest.java
commons/proper/math/trunk/src/test/org/apache/commons/math/ode/nonstiff/AdamsMoultonIntegratorTest.java
Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/MessagesResources_fr.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/MessagesResources_fr.java?rev=787050&r1=787049&r2=787050&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/MessagesResources_fr.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/MessagesResources_fr.java Sun Jun 21 17:01:03 2009
@@ -308,8 +308,8 @@
"intervalle d''int\u00e9gration trop petit : {0}" },
// org.apache.commons.math.ode.MultistepIntegrator
- { "{0} is supported only for 2 points or more",
- "la m\u00e9thode {0} n''est disponible que pour 2 points ou plus" },
+ { "{0} method needs at least one previous point",
+ "la m\u00e9thode {0} n\u00e9cessite au moins un point pr\u00e9c\u00e9dent" },
// org.apache.commons.math.ode.stiff.BDFIntegrator
{ "unsupported order {0} for BDF methods, must be between {1} and {2}",
Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/ode/MultistepIntegrator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/MultistepIntegrator.java?rev=787050&r1=787049&r2=787050&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/ode/MultistepIntegrator.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/ode/MultistepIntegrator.java Sun Jun 21 17:01:03 2009
@@ -47,7 +47,7 @@
/** Starter integrator. */
private FirstOrderIntegrator starter;
- /** Number of steps of the multistep method (including the one being computed). */
+ /** Number of steps of the multistep method (excluding the one being computed). */
private final int nSteps;
/** First scaled derivative (h y'). */
@@ -77,7 +77,7 @@
* some defaults settings.</p>
* @param name name of the method
* @param nSteps number of steps of the multistep method
- * (including the one being computed)
+ * (excluding the one being computed)
* @param order order of the method
* @param minStep minimal step (must be positive even for backward
* integration), the last step can be smaller than this
@@ -94,9 +94,9 @@
super(name, minStep, maxStep, scalAbsoluteTolerance, scalRelativeTolerance);
- if (nSteps <= 1) {
+ if (nSteps <= 0) {
throw MathRuntimeException.createIllegalArgumentException(
- "{0} is supported only for 2 points or more",
+ "{0} method needs at least one previous point",
name);
}
@@ -104,7 +104,7 @@
scalAbsoluteTolerance,
scalRelativeTolerance);
this.nSteps = nSteps;
- transformer = NordsieckTransformer.getInstance(nSteps);
+ transformer = NordsieckTransformer.getInstance(nSteps + 1);
exp = -1.0 / order;
@@ -122,7 +122,7 @@
* some defaults settings.</p>
* @param name name of the method
* @param nSteps number of steps of the multistep method
- * (including the one being computed)
+ * (excluding the one being computed)
* @param order order of the method
* @param minStep minimal step (must be positive even for backward
* integration), the last step can be smaller than this
@@ -141,7 +141,7 @@
vecAbsoluteTolerance,
vecRelativeTolerance);
this.nSteps = nSteps;
- transformer = NordsieckTransformer.getInstance(nSteps);
+ transformer = NordsieckTransformer.getInstance(nSteps + 1);
exp = -1.0 / order;
@@ -291,7 +291,7 @@
final Class<MultistepIntegrator> cl = MultistepIntegrator.class;
final Field f = cl.getDeclaredField("transformer");
f.setAccessible(true);
- f.set(this, NordsieckTransformer.getInstance(nSteps));
+ f.set(this, NordsieckTransformer.getInstance(nSteps + 1));
} catch (NoSuchFieldException nsfe) {
IOException ioe = new IOException();
@@ -325,7 +325,7 @@
final double prev = interpolator.getPreviousTime();
final double curr = interpolator.getCurrentTime();
stepStart = prev;
- stepSize = (curr - prev) / nSteps;
+ stepSize = (curr - prev) / (nSteps + 1);
// compute the first scaled derivative
interpolator.setInterpolatedTime(prev);
@@ -335,8 +335,8 @@
}
// compute the high order scaled derivatives
- final double[][] multistep = new double[nSteps - 1][];
- for (int i = 1; i < nSteps; ++i) {
+ final double[][] multistep = new double[nSteps][];
+ for (int i = 1; i <= nSteps; ++i) {
interpolator.setInterpolatedTime(prev + stepSize * i);
final double[] msI = interpolator.getInterpolatedDerivatives().clone();
for (int j = 0; j < n; ++j) {
Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/ode/nonstiff/AdamsBashforthIntegrator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/nonstiff/AdamsBashforthIntegrator.java?rev=787050&r1=787049&r2=787050&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/ode/nonstiff/AdamsBashforthIntegrator.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/ode/nonstiff/AdamsBashforthIntegrator.java Sun Jun 21 17:01:03 2009
@@ -32,7 +32,9 @@
* Differential Equations.
*
* <p>Adams-Bashforth methods (in fact due to Adams alone) are explicit
- * multistep ODE solvers with fixed stepsize. The value of state vector
+ * multistep ODE solvers. This implementation is a variation of the classical
+ * one: it uses adaptive stepsize to implement error control, whereas
+ * classical implementations are fixed step size. The value of state vector
* at step n+1 is a simple combination of the value at step n and of the
* derivatives at steps n, n-1, n-2 ... Depending on the number k of previous
* steps one wants to use for computing the next value, different formulas
@@ -45,8 +47,7 @@
* <li>...</li>
* </ul>
*
- * <p>A k-steps Adams-Bashforth method is of order k. There is no theoretical limit to the
- * value of k, but due to an implementation limitation k must be greater than 1.</p>
+ * <p>A k-steps Adams-Bashforth method is of order k.</p>
*
* <h3>Implementation details</h3>
*
@@ -112,7 +113,7 @@
* Taylor series formulas,</li>
* <li>it simplifies step changes that occur when discrete events that truncate
* the step are triggered,</li>
- * <li>it allows to extend the methods in order to support adaptive stepsize (not implemented yet).</li>
+ * <li>it allows to extend the methods in order to support adaptive stepsize.</li>
* </ul></p>
*
* <p>The Nordsieck vector at step n+1 is computed from the Nordsieck vector at step n as follows:
@@ -142,8 +143,7 @@
/**
* Build an Adams-Bashforth with the given order and step size.
- * @param order order of the method (must be greater than 1: due to
- * an implementation limitation the order 1 method is not supported)
+ * @param nSteps number of steps of the method excluding the one being computed
* @param minStep minimal step (must be positive even for backward
* integration), the last step can be smaller than this
* @param maxStep maximal step (must be positive even for backward
@@ -152,19 +152,18 @@
* @param scalRelativeTolerance allowed relative error
* @exception IllegalArgumentException if order is 1 or less
*/
- public AdamsBashforthIntegrator(final int order,
+ public AdamsBashforthIntegrator(final int nSteps,
final double minStep, final double maxStep,
final double scalAbsoluteTolerance,
final double scalRelativeTolerance)
throws IllegalArgumentException {
- super("Adams-Bashforth", order, order, minStep, maxStep,
+ super("Adams-Bashforth", nSteps, nSteps + 1, minStep, maxStep,
scalAbsoluteTolerance, scalRelativeTolerance);
}
/**
* Build an Adams-Bashforth with the given order and step size.
- * @param order order of the method (must be greater than 1: due to
- * an implementation limitation the order 1 method is not supported)
+ * @param nSteps number of steps of the method excluding the one being computed
* @param minStep minimal step (must be positive even for backward
* integration), the last step can be smaller than this
* @param maxStep maximal step (must be positive even for backward
@@ -173,12 +172,12 @@
* @param vecRelativeTolerance allowed relative error
* @exception IllegalArgumentException if order is 1 or less
*/
- public AdamsBashforthIntegrator(final int order,
+ public AdamsBashforthIntegrator(final int nSteps,
final double minStep, final double maxStep,
final double[] vecAbsoluteTolerance,
final double[] vecRelativeTolerance)
throws IllegalArgumentException {
- super("Adams-Bashforth", order, order, minStep, maxStep,
+ super("Adams-Bashforth", nSteps, nSteps + 1, minStep, maxStep,
vecAbsoluteTolerance, vecRelativeTolerance);
}
Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/ode/nonstiff/AdamsMoultonIntegrator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/nonstiff/AdamsMoultonIntegrator.java?rev=787050&r1=787049&r2=787050&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/ode/nonstiff/AdamsMoultonIntegrator.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/ode/nonstiff/AdamsMoultonIntegrator.java Sun Jun 21 17:01:03 2009
@@ -36,10 +36,12 @@
* Differential Equations.
*
* <p>Adams-Moulton methods (in fact due to Adams alone) are implicit
- * multistep ODE solvers with fixed stepsize. The value of state vector
+ * multistep ODE solvers. This implementation is a variation of the classical
+ * one: it uses adaptive stepsize to implement error control, whereas
+ * classical implementations are fixed step size. The value of state vector
* at step n+1 is a simple combination of the value at step n and of the
* derivatives at steps n+1, n, n-1 ... Since y'<sub>n+1</sub> is needed to
- * compute y<sub>n+1</sub>, another method must be used to compute a first
+ * compute y<sub>n+1</sub>,another method must be used to compute a first
* estimate of y<sub>n+1</sub>, then compute y'<sub>n+1</sub>, then compute
* a final estimate of y<sub>n+1</sub> using the following formulas. Depending
* on the number k of previous steps one wants to use for computing the next
@@ -52,8 +54,7 @@
* <li>...</li>
* </ul>
*
- * <p>A k-steps Adams-Moulton method is of order k+1. There is no theoretical limit to the
- * value of k, but due to an implementation limitation k must be greater than 1.</p>
+ * <p>A k-steps Adams-Moulton method is of order k+1.</p>
*
* <h3>Implementation details</h3>
*
@@ -119,7 +120,7 @@
* Taylor series formulas,</li>
* <li>it simplifies step changes that occur when discrete events that truncate
* the step are triggered,</li>
- * <li>it allows to extend the methods in order to support adaptive stepsize (not implemented yet).</li>
+ * <li>it allows to extend the methods in order to support adaptive stepsize.</li>
* </ul></p>
*
* <p>The predicted Nordsieck vector at step n+1 is computed from the Nordsieck vector at step
@@ -158,9 +159,8 @@
public class AdamsMoultonIntegrator extends MultistepIntegrator {
/**
- * Build an Adams-Moulton integrator with the given order and step size.
- * @param order order of the method (must be greater than 1: due to
- * an implementation limitation the order 1 method is not supported)
+ * Build an Adams-Moulton integrator with the given order and error control parameters.
+ * @param nSteps number of steps of the method excluding the one being computed
* @param minStep minimal step (must be positive even for backward
* integration), the last step can be smaller than this
* @param maxStep maximal step (must be positive even for backward
@@ -169,19 +169,18 @@
* @param scalRelativeTolerance allowed relative error
* @exception IllegalArgumentException if order is 1 or less
*/
- public AdamsMoultonIntegrator(final int order,
+ public AdamsMoultonIntegrator(final int nSteps,
final double minStep, final double maxStep,
final double scalAbsoluteTolerance,
final double scalRelativeTolerance)
throws IllegalArgumentException {
- super("Adams-Moulton", order, order, minStep, maxStep,
+ super("Adams-Moulton", nSteps, nSteps + 1, minStep, maxStep,
scalAbsoluteTolerance, scalRelativeTolerance);
}
/**
* Build an Adams-Moulton integrator with the given order and step size.
- * @param order order of the method (must be greater than 1: due to
- * an implementation limitation the order 1 method is not supported)
+ * @param nSteps number of steps of the method excluding the one being computed
* @param minStep minimal step (must be positive even for backward
* integration), the last step can be smaller than this
* @param maxStep maximal step (must be positive even for backward
@@ -190,12 +189,12 @@
* @param vecRelativeTolerance allowed relative error
* @exception IllegalArgumentException if order is 1 or less
*/
- public AdamsMoultonIntegrator(final int order,
+ public AdamsMoultonIntegrator(final int nSteps,
final double minStep, final double maxStep,
final double[] vecAbsoluteTolerance,
final double[] vecRelativeTolerance)
throws IllegalArgumentException {
- super("Adams-Moulton", order, order, minStep, maxStep,
+ super("Adams-Moulton", nSteps, nSteps + 1, minStep, maxStep,
vecAbsoluteTolerance, vecRelativeTolerance);
}
Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/ode/nonstiff/AdamsBashforthIntegratorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/ode/nonstiff/AdamsBashforthIntegratorTest.java?rev=787050&r1=787049&r2=787050&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/ode/nonstiff/AdamsBashforthIntegratorTest.java (original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/ode/nonstiff/AdamsBashforthIntegratorTest.java Sun Jun 21 17:01:03 2009
@@ -31,7 +31,7 @@
public void dimensionCheck() throws DerivativeException, IntegratorException {
TestProblem1 pb = new TestProblem1();
FirstOrderIntegrator integ =
- new AdamsBashforthIntegrator(3, 0.0, 1.0, 1.0e-10, 1.0e-10);
+ new AdamsBashforthIntegrator(2, 0.0, 1.0, 1.0e-10, 1.0e-10);
integ.integrate(pb,
0.0, new double[pb.getDimension()+10],
1.0, new double[pb.getDimension()+10]);
@@ -46,7 +46,7 @@
double[] vecAbsoluteTolerance = { 1.0e-15, 1.0e-16 };
double[] vecRelativeTolerance = { 1.0e-15, 1.0e-16 };
- FirstOrderIntegrator integ = new AdamsBashforthIntegrator(5, minStep, maxStep,
+ FirstOrderIntegrator integ = new AdamsBashforthIntegrator(4, minStep, maxStep,
vecAbsoluteTolerance,
vecRelativeTolerance);
TestProblemHandler handler = new TestProblemHandler(pb, integ);
@@ -69,7 +69,7 @@
double scalAbsoluteTolerance = Math.pow(10.0, i);
double scalRelativeTolerance = 0.01 * scalAbsoluteTolerance;
- FirstOrderIntegrator integ = new AdamsBashforthIntegrator(5, minStep, maxStep,
+ FirstOrderIntegrator integ = new AdamsBashforthIntegrator(4, minStep, maxStep,
scalAbsoluteTolerance,
scalRelativeTolerance);
TestProblemHandler handler = new TestProblemHandler(pb, integ);
@@ -100,7 +100,7 @@
TestProblem1 pb = new TestProblem1();
double range = pb.getFinalTime() - pb.getInitialTime();
- AdamsBashforthIntegrator integ = new AdamsBashforthIntegrator(3, 0, range, 1.0e-12, 1.0e-12);
+ AdamsBashforthIntegrator integ = new AdamsBashforthIntegrator(2, 0, range, 1.0e-12, 1.0e-12);
TestProblemHandler handler = new TestProblemHandler(pb, integ);
integ.addStepHandler(handler);
integ.setMaxEvaluations(650);
@@ -116,7 +116,7 @@
TestProblem5 pb = new TestProblem5();
double range = Math.abs(pb.getFinalTime() - pb.getInitialTime());
- FirstOrderIntegrator integ = new AdamsBashforthIntegrator(5, 0, range, 1.0e-12, 1.0e-12);
+ FirstOrderIntegrator integ = new AdamsBashforthIntegrator(4, 0, range, 1.0e-12, 1.0e-12);
TestProblemHandler handler = new TestProblemHandler(pb, integ);
integ.addStepHandler(handler);
integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
@@ -133,14 +133,14 @@
TestProblem6 pb = new TestProblem6();
double range = Math.abs(pb.getFinalTime() - pb.getInitialTime());
- for (int order = 2; order < 9; ++order) {
+ for (int nSteps = 1; nSteps < 8; ++nSteps) {
AdamsBashforthIntegrator integ =
- new AdamsBashforthIntegrator(order, 1.0e-6 * range, 0.1 * range, 1.0e-10, 1.0e-10);
+ new AdamsBashforthIntegrator(nSteps, 1.0e-6 * range, 0.1 * range, 1.0e-10, 1.0e-10);
TestProblemHandler handler = new TestProblemHandler(pb, integ);
integ.addStepHandler(handler);
integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
pb.getFinalTime(), new double[pb.getDimension()]);
- if (order < 5) {
+ if (nSteps < 4) {
assertTrue(integ.getEvaluations() > 160);
} else {
assertTrue(integ.getEvaluations() < 70);
Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/ode/nonstiff/AdamsMoultonIntegratorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/ode/nonstiff/AdamsMoultonIntegratorTest.java?rev=787050&r1=787049&r2=787050&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/ode/nonstiff/AdamsMoultonIntegratorTest.java (original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/ode/nonstiff/AdamsMoultonIntegratorTest.java Sun Jun 21 17:01:03 2009
@@ -31,7 +31,7 @@
public void dimensionCheck() throws DerivativeException, IntegratorException {
TestProblem1 pb = new TestProblem1();
FirstOrderIntegrator integ =
- new AdamsMoultonIntegrator(3, 0.0, 1.0, 1.0e-10, 1.0e-10);
+ new AdamsMoultonIntegrator(2, 0.0, 1.0, 1.0e-10, 1.0e-10);
integ.integrate(pb,
0.0, new double[pb.getDimension()+10],
1.0, new double[pb.getDimension()+10]);
@@ -46,9 +46,9 @@
double[] vecAbsoluteTolerance = { 1.0e-15, 1.0e-16 };
double[] vecRelativeTolerance = { 1.0e-15, 1.0e-16 };
- FirstOrderIntegrator integ = new AdamsMoultonIntegrator(5, minStep, maxStep,
- vecAbsoluteTolerance,
- vecRelativeTolerance);
+ FirstOrderIntegrator integ = new AdamsMoultonIntegrator(4, minStep, maxStep,
+ vecAbsoluteTolerance,
+ vecRelativeTolerance);
TestProblemHandler handler = new TestProblemHandler(pb, integ);
integ.addStepHandler(handler);
integ.integrate(pb,
@@ -69,9 +69,9 @@
double scalAbsoluteTolerance = Math.pow(10.0, i);
double scalRelativeTolerance = 0.01 * scalAbsoluteTolerance;
- FirstOrderIntegrator integ = new AdamsMoultonIntegrator(5, minStep, maxStep,
- scalAbsoluteTolerance,
- scalRelativeTolerance);
+ FirstOrderIntegrator integ = new AdamsMoultonIntegrator(4, minStep, maxStep,
+ scalAbsoluteTolerance,
+ scalRelativeTolerance);
TestProblemHandler handler = new TestProblemHandler(pb, integ);
integ.addStepHandler(handler);
integ.integrate(pb,
@@ -100,7 +100,7 @@
TestProblem1 pb = new TestProblem1();
double range = pb.getFinalTime() - pb.getInitialTime();
- AdamsMoultonIntegrator integ = new AdamsMoultonIntegrator(3, 0, range, 1.0e-12, 1.0e-12);
+ AdamsMoultonIntegrator integ = new AdamsMoultonIntegrator(2, 0, range, 1.0e-12, 1.0e-12);
TestProblemHandler handler = new TestProblemHandler(pb, integ);
integ.addStepHandler(handler);
integ.setMaxEvaluations(650);
@@ -116,7 +116,7 @@
TestProblem5 pb = new TestProblem5();
double range = Math.abs(pb.getFinalTime() - pb.getInitialTime());
- FirstOrderIntegrator integ = new AdamsMoultonIntegrator(5, 0, range, 1.0e-12, 1.0e-12);
+ FirstOrderIntegrator integ = new AdamsMoultonIntegrator(4, 0, range, 1.0e-12, 1.0e-12);
TestProblemHandler handler = new TestProblemHandler(pb, integ);
integ.addStepHandler(handler);
integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
@@ -133,14 +133,14 @@
TestProblem6 pb = new TestProblem6();
double range = Math.abs(pb.getFinalTime() - pb.getInitialTime());
- for (int order = 2; order < 8; ++order) {
+ for (int nSteps = 1; nSteps < 7; ++nSteps) {
AdamsMoultonIntegrator integ =
- new AdamsMoultonIntegrator(order, 1.0e-6 * range, 0.1 * range, 1.0e-9, 1.0e-9);
+ new AdamsMoultonIntegrator(nSteps, 1.0e-6 * range, 0.1 * range, 1.0e-9, 1.0e-9);
TestProblemHandler handler = new TestProblemHandler(pb, integ);
integ.addStepHandler(handler);
integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
pb.getFinalTime(), new double[pb.getDimension()]);
- if (order < 5) {
+ if (nSteps < 4) {
assertTrue(integ.getEvaluations() > 150);
} else {
assertTrue(integ.getEvaluations() < 90);