commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gilles Sadowski <gil...@harfang.homelinux.org>
Subject Re: svn commit: r1424107 - in /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/analysis/differentiation: DSCompilerTest.java DerivativeStructureTest.java FiniteDifferencesDifferentiatorTest.java
Date Thu, 20 Dec 2012 00:14:50 GMT
On Wed, Dec 19, 2012 at 09:10:21PM -0000, luc@apache.org wrote:
> Author: luc
> Date: Wed Dec 19 21:10:20 2012
> New Revision: 1424107
> 
> URL: http://svn.apache.org/viewvc?rev=1424107&view=rev
> Log:
> Added new tests.
> 
> Modified:
>     commons/proper/math/trunk/src/test/java/org/apache/commons/math3/analysis/differentiation/DSCompilerTest.java
>     commons/proper/math/trunk/src/test/java/org/apache/commons/math3/analysis/differentiation/DerivativeStructureTest.java
>     commons/proper/math/trunk/src/test/java/org/apache/commons/math3/analysis/differentiation/FiniteDifferencesDifferentiatorTest.java
> 
> Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/analysis/differentiation/DSCompilerTest.java
> URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/analysis/differentiation/DSCompilerTest.java?rev=1424107&r1=1424106&r2=1424107&view=diff
> ==============================================================================
> --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/analysis/differentiation/DSCompilerTest.java
(original)
> +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/analysis/differentiation/DSCompilerTest.java
Wed Dec 19 21:10:20 2012
> @@ -21,6 +21,7 @@ import java.lang.reflect.Field;
>  import java.util.HashMap;
>  import java.util.Map;
>  
> +import org.apache.commons.math3.exception.DimensionMismatchException;
>  import org.apache.commons.math3.util.ArithmeticUtils;
>  import org.junit.Assert;
>  import org.junit.Test;
> @@ -128,6 +129,16 @@ public class DSCompilerTest {
>  
>      }
>  
> +    @Test(expected=DimensionMismatchException.class)
> +    public void testIncompatbileParams() {
> +        DSCompiler.getCompiler(3, 2).checkCompatibility(DSCompiler.getCompiler(4, 2));
> +    }
> +
> +    @Test(expected=DimensionMismatchException.class)
> +    public void testIncompatbileOrder() {
> +        DSCompiler.getCompiler(3, 3).checkCompatibility(DSCompiler.getCompiler(3, 2));
> +    }
> +

There typos in the method names: "Incompatbile" instead of "Incompatible".

Gilles

>      @Test
>      public void testSymmetry() {
>          for (int i = 0; i < 6; ++i) {
> 
> Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/analysis/differentiation/DerivativeStructureTest.java
> URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/analysis/differentiation/DerivativeStructureTest.java?rev=1424107&r1=1424106&r2=1424107&view=diff
> ==============================================================================
> --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/analysis/differentiation/DerivativeStructureTest.java
(original)
> +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/analysis/differentiation/DerivativeStructureTest.java
Wed Dec 19 21:10:20 2012
> @@ -225,24 +225,37 @@ public class DerivativeStructureTest {
>                                                      -2, dsZ,
>                                                      1, new DerivativeStructure(8, dsZ.multiply(dsX),
>                                                                                 -1, dsY).pow(3));
> +                    DerivativeStructure dsOther =
> +                            new DerivativeStructure(1, dsX,
> +                                                    5, dsX.multiply(dsY),
> +                                                    -2, dsZ).add(new DerivativeStructure(8,
dsZ.multiply(dsX),
> +                                                                                   
     -1, dsY).pow(3));
>                      double f = x + 5 * x * y - 2 * z + FastMath.pow(8 * z * x - y, 3);
>                      Assert.assertEquals(f, ds.getValue(),
>                                          FastMath.abs(epsilon * f));
> +                    Assert.assertEquals(f, dsOther.getValue(),
> +                                        FastMath.abs(epsilon * f));
>  
>                      // df/dx = 1 + 5 y + 24 (8 z x - y)^2 z
>                      double dfdx = 1 + 5 * y + 24 * z * FastMath.pow(8 * z * x - y, 2);
>                      Assert.assertEquals(dfdx, ds.getPartialDerivative(1, 0, 0),
>                                          FastMath.abs(epsilon * dfdx));
> +                    Assert.assertEquals(dfdx, dsOther.getPartialDerivative(1, 0, 0),
> +                                        FastMath.abs(epsilon * dfdx));
>  
>                      // df/dxdy = 5 + 48 z*(y - 8 z x)
>                      double dfdxdy = 5 + 48 * z * (y - 8 * z * x);
>                      Assert.assertEquals(dfdxdy, ds.getPartialDerivative(1, 1, 0),
>                                          FastMath.abs(epsilon * dfdxdy));
> +                    Assert.assertEquals(dfdxdy, dsOther.getPartialDerivative(1, 1, 0),
> +                                        FastMath.abs(epsilon * dfdxdy));
>  
>                      // df/dxdydz = 48 (y - 16 z x)
>                      double dfdxdydz = 48 * (y - 16 * z * x);
>                      Assert.assertEquals(dfdxdydz, ds.getPartialDerivative(1, 1, 1),
>                                          FastMath.abs(epsilon * dfdxdydz));
> +                    Assert.assertEquals(dfdxdydz, dsOther.getPartialDerivative(1, 1,
1),
> +                                        FastMath.abs(epsilon * dfdxdydz));
>  
>                  }
>                  
> @@ -507,6 +520,51 @@ public class DerivativeStructureTest {
>      }
>  
>      @Test
> +    public void testPrimitiveRemainder() {
> +        double epsilon = 1.0e-15;
> +        for (int maxOrder = 0; maxOrder < 5; ++maxOrder) {
> +            for (double x = -1.7; x < 2; x += 0.2) {
> +                DerivativeStructure dsX = new DerivativeStructure(2, maxOrder, 0, x);
> +                for (double y = -1.7; y < 2; y += 0.2) {
> +                    DerivativeStructure remainder = dsX.remainder(y);
> +                    DerivativeStructure ref = dsX.subtract(x - (x % y));
> +                    DerivativeStructure zero = remainder.subtract(ref);
> +                    for (int n = 0; n <= maxOrder; ++n) {
> +                        for (int m = 0; m <= maxOrder; ++m) {
> +                            if (n + m <= maxOrder) {
> +                                Assert.assertEquals(0, zero.getPartialDerivative(n,
m), epsilon);
> +                            }
> +                        }
> +                    }
> +                }
> +            }
> +        }
> +    }
> +
> +    @Test
> +    public void testRemainder() {
> +        double epsilon = 1.0e-15;
> +        for (int maxOrder = 0; maxOrder < 5; ++maxOrder) {
> +            for (double x = -1.7; x < 2; x += 0.2) {
> +                DerivativeStructure dsX = new DerivativeStructure(2, maxOrder, 0, x);
> +                for (double y = -1.7; y < 2; y += 0.2) {
> +                    DerivativeStructure dsY = new DerivativeStructure(2, maxOrder, 1,
y);
> +                    DerivativeStructure remainder = dsX.remainder(dsY);
> +                    DerivativeStructure ref = dsX.subtract(dsY.multiply((x - (x % y))
/ y));
> +                    DerivativeStructure zero = remainder.subtract(ref);
> +                    for (int n = 0; n <= maxOrder; ++n) {
> +                        for (int m = 0; m <= maxOrder; ++m) {
> +                            if (n + m <= maxOrder) {
> +                                Assert.assertEquals(0, zero.getPartialDerivative(n,
m), epsilon);
> +                            }
> +                        }
> +                    }
> +                }
> +            }
> +        }
> +    }
> +
> +    @Test
>      public void testExp() {
>          double[] epsilon = new double[] { 1.0e-16, 1.0e-16, 1.0e-16, 1.0e-16, 1.0e-16
};
>          for (int maxOrder = 0; maxOrder < 5; ++maxOrder) {
> 
> Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/analysis/differentiation/FiniteDifferencesDifferentiatorTest.java
> URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/analysis/differentiation/FiniteDifferencesDifferentiatorTest.java?rev=1424107&r1=1424106&r2=1424107&view=diff
> ==============================================================================
> --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/analysis/differentiation/FiniteDifferencesDifferentiatorTest.java
(original)
> +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/analysis/differentiation/FiniteDifferencesDifferentiatorTest.java
Wed Dec 19 21:10:20 2012
> @@ -108,6 +108,7 @@ public class FiniteDifferencesDifferenti
>              DerivativeStructure dsX  = new DerivativeStructure(1, maxError.length -
1, 0, x);
>              DerivativeStructure yRef = gaussian.value(dsX);
>              DerivativeStructure y    = f.value(dsX);
> +            Assert.assertEquals(f.value(dsX.getValue()), f.value(dsX).getValue(), 1.0e-15);
>              for (int order = 0; order <= yRef.getOrder(); ++order) {
>                  maxError[order] = FastMath.max(maxError[order],
>                                          FastMath.abs(yRef.getPartialDerivative(order)
-
> @@ -297,9 +298,16 @@ public class FiniteDifferencesDifferenti
>          });
>  
>          for (double x = -10; x < 10; x += 0.1) {
> -            DerivativeStructure[] y = f.value(new DerivativeStructure(1, 2, 0, x));
> +            DerivativeStructure dsX = new DerivativeStructure(1, 2, 0, x);
> +            DerivativeStructure[] y = f.value(dsX);
>              double cos = FastMath.cos(x);
>              double sin = FastMath.sin(x);
> +            double[] f1 = f.value(dsX.getValue());
> +            DerivativeStructure[] f2 = f.value(dsX);
> +            Assert.assertEquals(f1.length, f2.length);
> +            for (int i = 0; i < f1.length; ++i) {
> +                Assert.assertEquals(f1[i], f2[i].getValue(), 1.0e-15);
> +            }
>              Assert.assertEquals( cos, y[0].getValue(), 7.0e-16);
>              Assert.assertEquals( sin, y[1].getValue(), 7.0e-16);
>              Assert.assertEquals(-sin, y[0].getPartialDerivative(1), 6.0e-14);
> @@ -328,11 +336,21 @@ public class FiniteDifferencesDifferenti
>          });
>  
>          for (double x = -1; x < 1; x += 0.02) {
> -            DerivativeStructure[][] y = f.value(new DerivativeStructure(1, 2, 0, x));
> +            DerivativeStructure dsX = new DerivativeStructure(1, 2, 0, x);
> +            DerivativeStructure[][] y = f.value(dsX);
>              double cos = FastMath.cos(x);
>              double sin = FastMath.sin(x);
>              double cosh = FastMath.cosh(x);
>              double sinh = FastMath.sinh(x);
> +            double[][] f1 = f.value(dsX.getValue());
> +            DerivativeStructure[][] f2 = f.value(dsX);
> +            Assert.assertEquals(f1.length, f2.length);
> +            for (int i = 0; i < f1.length; ++i) {
> +                Assert.assertEquals(f1[i].length, f2[i].length);
> +                for (int j = 0; j < f1[i].length; ++j) {
> +                    Assert.assertEquals(f1[i][j], f2[i][j].getValue(), 1.0e-15);
> +                }
> +            }
>              Assert.assertEquals(cos,   y[0][0].getValue(), 7.0e-18);
>              Assert.assertEquals(sin,   y[0][1].getValue(), 6.0e-17);
>              Assert.assertEquals(cosh,  y[1][0].getValue(), 3.0e-16);
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Mime
View raw message