On 10/22/14 11:20 AM, Luc Maisonobe wrote: > Le 22/10/2014 18:31, Phil Steitz a écrit : >> On 10/22/14 8:34 AM, l...@apache.org wrote: >>> Repository: commons-math >>> Updated Branches: >>> refs/heads/master 79ae77fda -> 25aa4bd36 >>> >>> >>> Provide access to state derivatives in ContinuousOutputModel. >>> >>> JIRA: MATH-1160 >>> >>> Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo >>> Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/25aa4bd3 >>> Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/25aa4bd3 >>> Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/25aa4bd3 >>> >>> Branch: refs/heads/master >>> Commit: 25aa4bd3665d8b265f03fa2b3e7ab6ee68256367 >>> Parents: 79ae77f >>> Author: Luc Maisonobe <l...@apache.org> >>> Authored: Wed Oct 22 17:34:29 2014 +0200 >>> Committer: Luc Maisonobe <l...@apache.org> >>> Committed: Wed Oct 22 17:34:29 2014 +0200 >>> >>> ---------------------------------------------------------------------- >>> src/changes/changes.xml | 3 +++ >>> .../math3/ode/ContinuousOutputModel.java | 14 +++++++++++++ >>> .../math3/ode/ContinuousOutputModelTest.java | 21 +++++++++++++------- >>> 3 files changed, 31 insertions(+), 7 deletions(-) >>> ---------------------------------------------------------------------- >>> >>> >>> http://git-wip-us.apache.org/repos/asf/commons-math/blob/25aa4bd3/src/changes/changes.xml >>> ---------------------------------------------------------------------- >>> diff --git a/src/changes/changes.xml b/src/changes/changes.xml >>> index bb5c525..9350d6b 100644 >>> --- a/src/changes/changes.xml >>> +++ b/src/changes/changes.xml >>> @@ -73,6 +73,9 @@ Users are encouraged to upgrade to this version as this >>> release not >>> 2. A few methods in the FastMath class are in fact slower that their >>> counterpart in either Math or StrictMath (cf. MATH-740 and MATH-901). >>> "> >>> + <action dev="luc" type="fix" issue="MATH-1160" > >>> + Provide access to state derivatives in ContinuousOutputModel. >>> + </action> >>> <action dev="luc" type="fix" issue="MATH-1138" due-to="Hank >>> Grabowski"> >>> Fixed bicubic spline interpolator, using Akima splines. >>> </action> >>> >>> http://git-wip-us.apache.org/repos/asf/commons-math/blob/25aa4bd3/src/main/java/org/apache/commons/math3/ode/ContinuousOutputModel.java >>> ---------------------------------------------------------------------- >>> diff --git >>> a/src/main/java/org/apache/commons/math3/ode/ContinuousOutputModel.java >>> b/src/main/java/org/apache/commons/math3/ode/ContinuousOutputModel.java >>> index 599eab9..d9f6192 100644 >>> --- a/src/main/java/org/apache/commons/math3/ode/ContinuousOutputModel.java >>> +++ b/src/main/java/org/apache/commons/math3/ode/ContinuousOutputModel.java >>> @@ -332,12 +332,25 @@ public class ContinuousOutputModel >>> * Get the state vector of the interpolated point. >>> * @return state vector at time {@link #getInterpolatedTime} >>> * @exception MaxCountExceededException if the number of functions >>> evaluations is exceeded >>> + * @see #getInterpolatedDerivatives() >>> * @see #getInterpolatedSecondaryState(int) >>> */ >>> public double[] getInterpolatedState() throws MaxCountExceededException { >>> return steps.get(index).getInterpolatedState(); >>> } >>> >>> + /** >>> + * Get the derivatives of the state vector of the interpolated point. >>> + * @return derivatives of the state vector at time {@link >>> #getInterpolatedTime} >>> + * @exception MaxCountExceededException if the number of functions >>> evaluations is exceeded >>> + * @see #getInterpolatedState() >>> + * @see #getInterpolatedSecondaryState(int) >>> + * @since 3.4 >>> + */ >>> + public double[] getInterpolatedDerivatives() throws >>> MaxCountExceededException { >>> + return steps.get(index).getInterpolatedDerivatives(); >> Do you maybe want to make a copy here? > I have followed the same pattern as getInterpolatedState above, which > returns the array without copying it. The reason for this choice was > that the method is essentially used to peek at state during the > integration, and it is called a huge number of time, at each steps. > > I agree this choice was wrong, just as passing arrays so user fill them > in the associated FirstOrderDifferentialEquations interface is not up to > date design. > > Perhaps we should rethink all this for 4.0? As for 3.4, being consistent > with the existing methods seemed better to me. > > Does this seems sensible to you?
Yes, what threw me was @return derivatives of the state vector at time {@link #getInterpolatedTime} which seemed to indicate a copy would be needed. Is the interpolated time invariant over the integration? If not, the javadoc should be fixed. Phil > > best regards, > Luc > >> Phil >>> + } >>> + >>> /** Get the interpolated secondary state corresponding to the secondary >>> equations. >>> * @param secondaryStateIndex index of the secondary set, as returned by >>> {@link >>> * >>> org.apache.commons.math3.ode.ExpandableStatefulODE#addSecondaryEquations( >>> @@ -345,6 +358,7 @@ public class ContinuousOutputModel >>> * ExpandableStatefulODE.addSecondaryEquations(SecondaryEquations)} >>> * @return interpolated secondary state at the current interpolation date >>> * @see #getInterpolatedState() >>> + * @see #getInterpolatedDerivatives() >>> * @since 3.2 >>> * @exception MaxCountExceededException if the number of functions >>> evaluations is exceeded >>> */ >>> >>> http://git-wip-us.apache.org/repos/asf/commons-math/blob/25aa4bd3/src/test/java/org/apache/commons/math3/ode/ContinuousOutputModelTest.java >>> ---------------------------------------------------------------------- >>> diff --git >>> a/src/test/java/org/apache/commons/math3/ode/ContinuousOutputModelTest.java >>> b/src/test/java/org/apache/commons/math3/ode/ContinuousOutputModelTest.java >>> index 2f4053d..3a098ba 100644 >>> --- >>> a/src/test/java/org/apache/commons/math3/ode/ContinuousOutputModelTest.java >>> +++ >>> b/src/test/java/org/apache/commons/math3/ode/ContinuousOutputModelTest.java >>> @@ -63,22 +63,29 @@ public class ContinuousOutputModelTest { >>> pb.getFinalTime(), new double[pb.getDimension()]); >>> >>> Random random = new Random(347588535632l); >>> - double maxError = 0.0; >>> + double maxError = 0.0; >>> + double maxErrorDot = 0.0; >>> for (int i = 0; i < 1000; ++i) { >>> double r = random.nextDouble(); >>> double time = r * pb.getInitialTime() + (1.0 - r) * >>> pb.getFinalTime(); >>> cm.setInterpolatedTime(time); >>> - double[] interpolatedY = cm.getInterpolatedState (); >>> - double[] theoreticalY = pb.computeTheoreticalState(time); >>> + double[] interpolatedY = cm.getInterpolatedState(); >>> + double[] interpolatedYDot = cm.getInterpolatedDerivatives(); >>> + double[] theoreticalY = pb.computeTheoreticalState(time); >>> + double[] theoreticalYDot = new double[pb.getDimension()]; >>> + pb.doComputeDerivatives(time, theoreticalY, theoreticalYDot); >>> double dx = interpolatedY[0] - theoreticalY[0]; >>> double dy = interpolatedY[1] - theoreticalY[1]; >>> double error = dx * dx + dy * dy; >>> - if (error > maxError) { >>> - maxError = error; >>> - } >>> + maxError = FastMath.max(maxError, error); >>> + double dxDot = interpolatedYDot[0] - theoreticalYDot[0]; >>> + double dyDot = interpolatedYDot[1] - theoreticalYDot[1]; >>> + double errorDot = dxDot * dxDot + dyDot * dyDot; >>> + maxErrorDot = FastMath.max(maxErrorDot, errorDot); >>> } >>> >>> - Assert.assertTrue(maxError < 1.0e-9); >>> + Assert.assertEquals(0.0, maxError, 1.0e-9); >>> + Assert.assertEquals(0.0, maxErrorDot, 4.0e-7); >>> >>> } >>> >>> >>> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org >> For additional commands, e-mail: dev-h...@commons.apache.org >> >> >> > > --------------------------------------------------------------------- > To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org > For additional commands, e-mail: dev-h...@commons.apache.org > > --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org For additional commands, e-mail: dev-h...@commons.apache.org