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 2010/03/07 11:59:34 UTC
svn commit: r919963 - in /commons/proper/math/trunk/src:
main/java/org/apache/commons/math/ode/jacobians/
test/java/org/apache/commons/math/ode/jacobians/
Author: luc
Date: Sun Mar 7 10:59:33 2010
New Revision: 919963
URL: http://svn.apache.org/viewvc?rev=919963&view=rev
Log:
separated ODEWithJacobians from ParameterizedODE:
when jacobians are already available, there is no need to have a setParameter method
Added:
commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/jacobians/ODEWithJacobians.java
- copied, changed from r919808, commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/jacobians/ParameterizedODEWithJacobians.java
Removed:
commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/jacobians/ParameterizedODEWithJacobians.java
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/jacobians/EventHandlerWithJacobians.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/jacobians/FirstOrderIntegratorWithJacobians.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/jacobians/FirstOrderIntegratorWithJacobiansTest.java
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/jacobians/EventHandlerWithJacobians.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/jacobians/EventHandlerWithJacobians.java?rev=919963&r1=919962&r2=919963&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/jacobians/EventHandlerWithJacobians.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/jacobians/EventHandlerWithJacobians.java Sun Mar 7 10:59:33 2010
@@ -112,7 +112,7 @@
* the step handler itself is called (see below for scheduling). It
* allows the user to update his internal data to acknowledge the fact
* the event has been handled (for example setting a flag in the {@link
- * org.apache.commons.math.ode.jacobians.ParameterizedODEWithJacobians
+ * org.apache.commons.math.ode.jacobians.ODEWithJacobians
* differential equations} to switch the derivatives computation in
* case of discontinuity), or to direct the integrator to either stop
* or continue integration, possibly with a reset state or derivatives.</p>
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/jacobians/FirstOrderIntegratorWithJacobians.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/jacobians/FirstOrderIntegratorWithJacobians.java?rev=919963&r1=919962&r2=919963&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/jacobians/FirstOrderIntegratorWithJacobians.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/jacobians/FirstOrderIntegratorWithJacobians.java Sun Mar 7 10:59:33 2010
@@ -44,7 +44,7 @@
* problem has dimension n and there are p parameters, the compound problem will
* have dimension n × (1 + n + k).</p>
* @see ParameterizedODE
- * @see ParameterizedODEWithJacobians
+ * @see ODEWithJacobians
* @version $Revision$ $Date$
* @since 2.1
*/
@@ -54,7 +54,7 @@
private final FirstOrderIntegrator integrator;
/** Raw equations to integrate. */
- private final ParameterizedODEWithJacobians ode;
+ private final ODEWithJacobians ode;
/** Maximal number of evaluations allowed. */
private int maxEvaluations;
@@ -73,7 +73,7 @@
* @param hP step sizes to use for computing the jacobian df/dp, must have the
* same dimension as the original problem parameters dimension
* @see #FirstOrderIntegratorWithJacobians(FirstOrderIntegrator,
- * ParameterizedODEWithJacobians)
+ * ODEWithJacobians)
*/
public FirstOrderIntegratorWithJacobians(final FirstOrderIntegrator integrator,
final ParameterizedODE ode,
@@ -93,7 +93,7 @@
* ParameterizedODE, double[], double[], double[])
*/
public FirstOrderIntegratorWithJacobians(final FirstOrderIntegrator integrator,
- final ParameterizedODEWithJacobians ode) {
+ final ODEWithJacobians ode) {
this.integrator = integrator;
this.ode = ode;
setMaxEvaluations(-1);
@@ -107,7 +107,9 @@
* @see #clearStepHandlers()
*/
public void addStepHandler(StepHandlerWithJacobians handler) {
- integrator.addStepHandler(new StepHandlerWrapper(handler));
+ final int n = ode.getDimension();
+ final int k = ode.getParametersDimension();
+ integrator.addStepHandler(new StepHandlerWrapper(handler, n, k));
}
/** Get all the step handlers that have been added to the integrator.
@@ -149,7 +151,9 @@
double maxCheckInterval,
double convergence,
int maxIterationCount) {
- integrator.addEventHandler(new EventHandlerWrapper(handler),
+ final int n = ode.getDimension();
+ final int k = ode.getParametersDimension();
+ integrator.addEventHandler(new EventHandlerWrapper(handler, n, k),
maxCheckInterval, convergence, maxIterationCount);
}
@@ -438,7 +442,7 @@
/** Wrapper class to compute jacobians by finite differences for ODE which do not compute them themselves. */
private class FiniteDifferencesWrapper
- implements ParameterizedODEWithJacobians {
+ implements ODEWithJacobians {
/** Raw ODE without jacobians computation. */
private final ParameterizedODE ode;
@@ -488,17 +492,12 @@
}
/** {@inheritDoc} */
- public void setParameter(int i, double value) {
- ode.setParameter(i, value);
- }
-
- /** {@inheritDoc} */
public void computeJacobians(double t, double[] y, double[] yDot,
double[][] dFdY, double[][] dFdP)
throws DerivativeException {
- final int n = ode.getDimension();
- final int k = ode.getParametersDimension();
+ final int n = hY.length;
+ final int k = hP.length;
evaluations += n + k;
if (evaluations > maxEvaluations) {
@@ -531,16 +530,27 @@
}
/** Wrapper for step handlers. */
- private class StepHandlerWrapper implements StepHandler {
+ private static class StepHandlerWrapper implements StepHandler {
/** Underlying step handler with jacobians. */
private final StepHandlerWithJacobians handler;
+ /** Dimension of the original ODE. */
+ private final int n;
+
+ /** Number of parameters. */
+ private final int k;
+
/** Simple constructor.
* @param handler underlying step handler with jacobians
+ * @param n dimension of the original ODE
+ * @param k number of parameters
*/
- public StepHandlerWrapper(final StepHandlerWithJacobians handler) {
+ public StepHandlerWrapper(final StepHandlerWithJacobians handler,
+ final int n, final int k) {
this.handler = handler;
+ this.n = n;
+ this.k = k;
}
/** Get the underlying step handler with jacobians.
@@ -553,10 +563,7 @@
/** {@inheritDoc} */
public void handleStep(StepInterpolator interpolator, boolean isLast)
throws DerivativeException {
- handler.handleStep(new StepInterpolatorWrapper(interpolator,
- ode.getDimension(),
- ode.getParametersDimension()),
- isLast);
+ handler.handleStep(new StepInterpolatorWrapper(interpolator, n, k), isLast);
}
/** {@inheritDoc} */
@@ -824,7 +831,7 @@
}
/** Wrapper for event handlers. */
- private class EventHandlerWrapper implements EventHandler {
+ private static class EventHandlerWrapper implements EventHandler {
/** Underlying event handler with jacobians. */
private final EventHandlerWithJacobians handler;
@@ -840,11 +847,12 @@
/** Simple constructor.
* @param handler underlying event handler with jacobians
+ * @param n dimension of the original ODE
+ * @param k number of parameters
*/
- public EventHandlerWrapper(final EventHandlerWithJacobians handler) {
+ public EventHandlerWrapper(final EventHandlerWithJacobians handler,
+ final int n, final int k) {
this.handler = handler;
- final int n = ode.getDimension();
- final int k = ode.getParametersDimension();
y = new double[n];
dydy0 = new double[n][n];
dydp = new double[n][k];
Copied: commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/jacobians/ODEWithJacobians.java (from r919808, commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/jacobians/ParameterizedODEWithJacobians.java)
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/jacobians/ODEWithJacobians.java?p2=commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/jacobians/ODEWithJacobians.java&p1=commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/jacobians/ParameterizedODEWithJacobians.java&r1=919808&r2=919963&rev=919963&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/jacobians/ParameterizedODEWithJacobians.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/ode/jacobians/ODEWithJacobians.java Sun Mar 7 10:59:33 2010
@@ -18,6 +18,7 @@
package org.apache.commons.math.ode.jacobians;
import org.apache.commons.math.ode.DerivativeException;
+import org.apache.commons.math.ode.FirstOrderDifferentialEquations;
/** This interface represents {@link ParameterizedODE
@@ -29,8 +30,12 @@
* @since 2.1
*/
-public interface ParameterizedODEWithJacobians
- extends ParameterizedODE {
+public interface ODEWithJacobians extends FirstOrderDifferentialEquations {
+
+ /** Get the number of parameters.
+ * @return number of parameters
+ */
+ int getParametersDimension();
/** Compute the partial derivatives of ODE with respect to state.
* @param t current value of the independent <I>time</I> variable
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/jacobians/FirstOrderIntegratorWithJacobiansTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/jacobians/FirstOrderIntegratorWithJacobiansTest.java?rev=919963&r1=919962&r2=919963&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/jacobians/FirstOrderIntegratorWithJacobiansTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/jacobians/FirstOrderIntegratorWithJacobiansTest.java Sun Mar 7 10:59:33 2010
@@ -275,7 +275,7 @@
Assert.assertTrue(stopTime < 5.0 * Math.PI);
}
- private static class Brusselator implements ParameterizedODEWithJacobians {
+ private static class Brusselator implements ParameterizedODE, ODEWithJacobians {
private double b;
@@ -323,7 +323,7 @@
};
/** ODE representing a point moving on a circle with provided center and angular rate. */
- private static class Circle implements ParameterizedODEWithJacobians {
+ private static class Circle implements ODEWithJacobians {
private final double[] y0;
private double cx;
@@ -341,16 +341,6 @@
return 2;
}
- public void setParameter(int i, double p) {
- if (i == 0) {
- cx = p;
- } else if (i == 1) {
- cy = p;
- } else {
- omega = p;
- }
- }
-
public int getParametersDimension() {
return 3;
}