commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
Subject svn commit: r651058 - /commons/sandbox/nabla/trunk/src/test/java/org/apache/commons/nabla/automatic/functions/
Date Wed, 23 Apr 2008 20:52:39 GMT
Author: luc
Date: Wed Apr 23 13:52:36 2008
New Revision: 651058

URL: http://svn.apache.org/viewvc?rev=651058&view=rev
Log:
added tests for singular values

Modified:
    commons/sandbox/nabla/trunk/src/test/java/org/apache/commons/nabla/automatic/functions/AcosGeneratorTest.java
    commons/sandbox/nabla/trunk/src/test/java/org/apache/commons/nabla/automatic/functions/AsinGeneratorTest.java
    commons/sandbox/nabla/trunk/src/test/java/org/apache/commons/nabla/automatic/functions/AtanGeneratorTest.java
    commons/sandbox/nabla/trunk/src/test/java/org/apache/commons/nabla/automatic/functions/Log10GeneratorTest.java
    commons/sandbox/nabla/trunk/src/test/java/org/apache/commons/nabla/automatic/functions/Log1pGeneratorTest.java
    commons/sandbox/nabla/trunk/src/test/java/org/apache/commons/nabla/automatic/functions/LogGeneratorTest.java
    commons/sandbox/nabla/trunk/src/test/java/org/apache/commons/nabla/automatic/functions/SqrtGeneratorTest.java

Modified: commons/sandbox/nabla/trunk/src/test/java/org/apache/commons/nabla/automatic/functions/AcosGeneratorTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/test/java/org/apache/commons/nabla/automatic/functions/AcosGeneratorTest.java?rev=651058&r1=651057&r2=651058&view=diff
==============================================================================
--- commons/sandbox/nabla/trunk/src/test/java/org/apache/commons/nabla/automatic/functions/AcosGeneratorTest.java
(original)
+++ commons/sandbox/nabla/trunk/src/test/java/org/apache/commons/nabla/automatic/functions/AcosGeneratorTest.java
Wed Apr 23 13:52:36 2008
@@ -18,6 +18,11 @@
 
 import org.apache.commons.nabla.ReferenceFunction;
 import org.apache.commons.nabla.automatic.AbstractMathTest;
+import org.apache.commons.nabla.automatic.AutomaticDifferentiator;
+import org.apache.commons.nabla.core.DifferentialPair;
+import org.apache.commons.nabla.core.DifferentiationException;
+import org.apache.commons.nabla.core.UnivariateDerivative;
+import org.apache.commons.nabla.core.UnivariateDifferentiable;
 
 public class AcosGeneratorTest extends AbstractMathTest {
 
@@ -26,6 +31,38 @@
             public double f(double t) { return Math.acos(t); }
             public double fPrime(double t) { return -1 / Math.sqrt(1 - t * t); }
         }, -0.99, 0.99, 30, 0.0);
+    }
+
+    public void testSingularityPlus() throws DifferentiationException {
+        UnivariateDerivative derivative =
+            new AutomaticDifferentiator().differentiate(new UnivariateDifferentiable() {
+                public double f(double t) { return Math.acos(t); }
+            });
+
+        double dPlus = derivative.f(new DifferentialPair(1, 1)).getFirstDerivative();
+        assertTrue(Double.isInfinite(dPlus));
+        assertTrue(dPlus > 0);
+
+        double dMinus = derivative.f(new DifferentialPair(1, -1)).getFirstDerivative();
+        assertTrue(Double.isInfinite(dMinus));
+        assertTrue(dMinus < 0);
+
+    }
+
+    public void testSingularityMinus() throws DifferentiationException {
+        UnivariateDerivative derivative =
+            new AutomaticDifferentiator().differentiate(new UnivariateDifferentiable() {
+                public double f(double t) { return Math.acos(t); }
+            });
+
+        double dPlus = derivative.f(new DifferentialPair(-1, 1)).getFirstDerivative();
+        assertTrue(Double.isInfinite(dPlus));
+        assertTrue(dPlus > 0);
+
+        double dMinus = derivative.f(new DifferentialPair(-1, -1)).getFirstDerivative();
+        assertTrue(Double.isInfinite(dMinus));
+        assertTrue(dMinus < 0);
+
     }
 
 }

Modified: commons/sandbox/nabla/trunk/src/test/java/org/apache/commons/nabla/automatic/functions/AsinGeneratorTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/test/java/org/apache/commons/nabla/automatic/functions/AsinGeneratorTest.java?rev=651058&r1=651057&r2=651058&view=diff
==============================================================================
--- commons/sandbox/nabla/trunk/src/test/java/org/apache/commons/nabla/automatic/functions/AsinGeneratorTest.java
(original)
+++ commons/sandbox/nabla/trunk/src/test/java/org/apache/commons/nabla/automatic/functions/AsinGeneratorTest.java
Wed Apr 23 13:52:36 2008
@@ -18,6 +18,11 @@
 
 import org.apache.commons.nabla.ReferenceFunction;
 import org.apache.commons.nabla.automatic.AbstractMathTest;
+import org.apache.commons.nabla.automatic.AutomaticDifferentiator;
+import org.apache.commons.nabla.core.DifferentialPair;
+import org.apache.commons.nabla.core.DifferentiationException;
+import org.apache.commons.nabla.core.UnivariateDerivative;
+import org.apache.commons.nabla.core.UnivariateDifferentiable;
 
 public class AsinGeneratorTest extends AbstractMathTest {
 
@@ -26,6 +31,38 @@
             public double f(double t) { return Math.asin(t); }
             public double fPrime(double t) { return 1 / Math.sqrt(1 - t * t); }
         }, -0.99, 0.99, 30, 0.0);
+    }
+
+    public void testSingularityPlus() throws DifferentiationException {
+        UnivariateDerivative derivative =
+            new AutomaticDifferentiator().differentiate(new UnivariateDifferentiable() {
+                public double f(double t) { return Math.asin(t); }
+            });
+
+        double dPlus = derivative.f(new DifferentialPair(1, 1)).getFirstDerivative();
+        assertTrue(Double.isInfinite(dPlus));
+        assertTrue(dPlus < 0);
+
+        double dMinus = derivative.f(new DifferentialPair(1, -1)).getFirstDerivative();
+        assertTrue(Double.isInfinite(dMinus));
+        assertTrue(dMinus > 0);
+
+    }
+
+    public void testSingularityMinus() throws DifferentiationException {
+        UnivariateDerivative derivative =
+            new AutomaticDifferentiator().differentiate(new UnivariateDifferentiable() {
+                public double f(double t) { return Math.asin(t); }
+            });
+
+        double dPlus = derivative.f(new DifferentialPair(-1, 1)).getFirstDerivative();
+        assertTrue(Double.isInfinite(dPlus));
+        assertTrue(dPlus < 0);
+
+        double dMinus = derivative.f(new DifferentialPair(-1, -1)).getFirstDerivative();
+        assertTrue(Double.isInfinite(dMinus));
+        assertTrue(dMinus > 0);
+
     }
 
 }

Modified: commons/sandbox/nabla/trunk/src/test/java/org/apache/commons/nabla/automatic/functions/AtanGeneratorTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/test/java/org/apache/commons/nabla/automatic/functions/AtanGeneratorTest.java?rev=651058&r1=651057&r2=651058&view=diff
==============================================================================
--- commons/sandbox/nabla/trunk/src/test/java/org/apache/commons/nabla/automatic/functions/AtanGeneratorTest.java
(original)
+++ commons/sandbox/nabla/trunk/src/test/java/org/apache/commons/nabla/automatic/functions/AtanGeneratorTest.java
Wed Apr 23 13:52:36 2008
@@ -18,6 +18,11 @@
 
 import org.apache.commons.nabla.ReferenceFunction;
 import org.apache.commons.nabla.automatic.AbstractMathTest;
+import org.apache.commons.nabla.automatic.AutomaticDifferentiator;
+import org.apache.commons.nabla.core.DifferentialPair;
+import org.apache.commons.nabla.core.DifferentiationException;
+import org.apache.commons.nabla.core.UnivariateDerivative;
+import org.apache.commons.nabla.core.UnivariateDifferentiable;
 
 public class AtanGeneratorTest extends AbstractMathTest {
 
@@ -26,6 +31,34 @@
             public double f(double t) { return Math.atan(t); }
             public double fPrime(double t) { return 1 / (1 + t * t); }
         }, -1.5, 1.5, 30, 0.0);
+    }
+
+    public void testSingularityPlus() throws DifferentiationException {
+        UnivariateDerivative derivative =
+            new AutomaticDifferentiator().differentiate(new UnivariateDifferentiable() {
+                public double f(double t) { return Math.atan(t); }
+            });
+
+        double dPlus = derivative.f(new DifferentialPair(Double.POSITIVE_INFINITY, 1)).getFirstDerivative();
+        assertEquals(0, dPlus, 0);
+
+        double dMinus = derivative.f(new DifferentialPair(Double.POSITIVE_INFINITY, -1)).getFirstDerivative();
+        assertEquals(0, dMinus, 0);
+
+    }
+
+    public void testSingularityMinus() throws DifferentiationException {
+        UnivariateDerivative derivative =
+            new AutomaticDifferentiator().differentiate(new UnivariateDifferentiable() {
+                public double f(double t) { return Math.atan(t); }
+            });
+
+        double dPlus = derivative.f(new DifferentialPair(Double.NEGATIVE_INFINITY, 1)).getFirstDerivative();
+        assertEquals(0, dPlus, 0);
+
+        double dMinus = derivative.f(new DifferentialPair(Double.NEGATIVE_INFINITY, -1)).getFirstDerivative();
+        assertEquals(0, dMinus, 0);
+
     }
 
 }

Modified: commons/sandbox/nabla/trunk/src/test/java/org/apache/commons/nabla/automatic/functions/Log10GeneratorTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/test/java/org/apache/commons/nabla/automatic/functions/Log10GeneratorTest.java?rev=651058&r1=651057&r2=651058&view=diff
==============================================================================
--- commons/sandbox/nabla/trunk/src/test/java/org/apache/commons/nabla/automatic/functions/Log10GeneratorTest.java
(original)
+++ commons/sandbox/nabla/trunk/src/test/java/org/apache/commons/nabla/automatic/functions/Log10GeneratorTest.java
Wed Apr 23 13:52:36 2008
@@ -18,6 +18,11 @@
 
 import org.apache.commons.nabla.ReferenceFunction;
 import org.apache.commons.nabla.automatic.AbstractMathTest;
+import org.apache.commons.nabla.automatic.AutomaticDifferentiator;
+import org.apache.commons.nabla.core.DifferentialPair;
+import org.apache.commons.nabla.core.DifferentiationException;
+import org.apache.commons.nabla.core.UnivariateDerivative;
+import org.apache.commons.nabla.core.UnivariateDifferentiable;
 
 public class Log10GeneratorTest extends AbstractMathTest {
 
@@ -26,6 +31,22 @@
             public double f(double t) { return Math.log10(t); }
             public double fPrime(double t) { return 1 / (Math.log(10) * t); }
         }, 0.1, 10, 50, 0.0);
+    }
+
+    public void testSingularity() throws DifferentiationException {
+        UnivariateDerivative derivative =
+            new AutomaticDifferentiator().differentiate(new UnivariateDifferentiable() {
+                public double f(double t) { return Math.log10(t); }
+            });
+
+        double dPlus = derivative.f(new DifferentialPair(0, 1)).getFirstDerivative();
+        assertTrue(Double.isInfinite(dPlus));
+        assertTrue(dPlus > 0);
+
+        double dMinus = derivative.f(new DifferentialPair(0, -1)).getFirstDerivative();
+        assertTrue(Double.isInfinite(dMinus));
+        assertTrue(dMinus < 0);
+
     }
 
 }

Modified: commons/sandbox/nabla/trunk/src/test/java/org/apache/commons/nabla/automatic/functions/Log1pGeneratorTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/test/java/org/apache/commons/nabla/automatic/functions/Log1pGeneratorTest.java?rev=651058&r1=651057&r2=651058&view=diff
==============================================================================
--- commons/sandbox/nabla/trunk/src/test/java/org/apache/commons/nabla/automatic/functions/Log1pGeneratorTest.java
(original)
+++ commons/sandbox/nabla/trunk/src/test/java/org/apache/commons/nabla/automatic/functions/Log1pGeneratorTest.java
Wed Apr 23 13:52:36 2008
@@ -18,6 +18,11 @@
 
 import org.apache.commons.nabla.ReferenceFunction;
 import org.apache.commons.nabla.automatic.AbstractMathTest;
+import org.apache.commons.nabla.automatic.AutomaticDifferentiator;
+import org.apache.commons.nabla.core.DifferentialPair;
+import org.apache.commons.nabla.core.DifferentiationException;
+import org.apache.commons.nabla.core.UnivariateDerivative;
+import org.apache.commons.nabla.core.UnivariateDifferentiable;
 
 public class Log1pGeneratorTest extends AbstractMathTest {
 
@@ -26,6 +31,22 @@
             public double f(double t) { return Math.log1p(t); }
             public double fPrime(double t) { return 1 / (1 + t); }
         }, -0.2, 0.2, 50, 0.0);
+    }
+
+    public void testSingularity() throws DifferentiationException {
+        UnivariateDerivative derivative =
+            new AutomaticDifferentiator().differentiate(new UnivariateDifferentiable() {
+                public double f(double t) { return Math.log1p(t); }
+            });
+
+        double dPlus = derivative.f(new DifferentialPair(-1, 1)).getFirstDerivative();
+        assertTrue(Double.isInfinite(dPlus));
+        assertTrue(dPlus > 0);
+
+        double dMinus = derivative.f(new DifferentialPair(-1, -1)).getFirstDerivative();
+        assertTrue(Double.isInfinite(dMinus));
+        assertTrue(dMinus < 0);
+
     }
 
 }

Modified: commons/sandbox/nabla/trunk/src/test/java/org/apache/commons/nabla/automatic/functions/LogGeneratorTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/test/java/org/apache/commons/nabla/automatic/functions/LogGeneratorTest.java?rev=651058&r1=651057&r2=651058&view=diff
==============================================================================
--- commons/sandbox/nabla/trunk/src/test/java/org/apache/commons/nabla/automatic/functions/LogGeneratorTest.java
(original)
+++ commons/sandbox/nabla/trunk/src/test/java/org/apache/commons/nabla/automatic/functions/LogGeneratorTest.java
Wed Apr 23 13:52:36 2008
@@ -18,6 +18,11 @@
 
 import org.apache.commons.nabla.ReferenceFunction;
 import org.apache.commons.nabla.automatic.AbstractMathTest;
+import org.apache.commons.nabla.automatic.AutomaticDifferentiator;
+import org.apache.commons.nabla.core.DifferentialPair;
+import org.apache.commons.nabla.core.DifferentiationException;
+import org.apache.commons.nabla.core.UnivariateDerivative;
+import org.apache.commons.nabla.core.UnivariateDifferentiable;
 
 public class LogGeneratorTest extends AbstractMathTest {
 
@@ -26,6 +31,22 @@
             public double f(double t) { return Math.log(t); }
             public double fPrime(double t) { return 1 / t; }
         }, 0.1, 10, 50, 0.0);
+    }
+
+    public void testSingularity() throws DifferentiationException {
+        UnivariateDerivative derivative =
+            new AutomaticDifferentiator().differentiate(new UnivariateDifferentiable() {
+                public double f(double t) { return Math.log(t); }
+            });
+
+        double dPlus = derivative.f(new DifferentialPair(0, 1)).getFirstDerivative();
+        assertTrue(Double.isInfinite(dPlus));
+        assertTrue(dPlus > 0);
+
+        double dMinus = derivative.f(new DifferentialPair(0, -1)).getFirstDerivative();
+        assertTrue(Double.isInfinite(dMinus));
+        assertTrue(dMinus < 0);
+
     }
 
 }

Modified: commons/sandbox/nabla/trunk/src/test/java/org/apache/commons/nabla/automatic/functions/SqrtGeneratorTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/test/java/org/apache/commons/nabla/automatic/functions/SqrtGeneratorTest.java?rev=651058&r1=651057&r2=651058&view=diff
==============================================================================
--- commons/sandbox/nabla/trunk/src/test/java/org/apache/commons/nabla/automatic/functions/SqrtGeneratorTest.java
(original)
+++ commons/sandbox/nabla/trunk/src/test/java/org/apache/commons/nabla/automatic/functions/SqrtGeneratorTest.java
Wed Apr 23 13:52:36 2008
@@ -18,6 +18,11 @@
 
 import org.apache.commons.nabla.ReferenceFunction;
 import org.apache.commons.nabla.automatic.AbstractMathTest;
+import org.apache.commons.nabla.automatic.AutomaticDifferentiator;
+import org.apache.commons.nabla.core.DifferentialPair;
+import org.apache.commons.nabla.core.DifferentiationException;
+import org.apache.commons.nabla.core.UnivariateDerivative;
+import org.apache.commons.nabla.core.UnivariateDifferentiable;
 
 public class SqrtGeneratorTest extends AbstractMathTest {
 
@@ -26,6 +31,22 @@
             public double f(double t) { return Math.sqrt(t); }
             public double fPrime(double t) { return 1 / (2 * Math.sqrt(t)); }
         }, 0.001, 10, 50, 0.0);
+    }
+
+    public void testSingularity() throws DifferentiationException {
+        UnivariateDerivative derivative =
+            new AutomaticDifferentiator().differentiate(new UnivariateDifferentiable() {
+                public double f(double t) { return Math.sqrt(t); }
+            });
+
+        double dPlus = derivative.f(new DifferentialPair(0, 1)).getFirstDerivative();
+        assertTrue(Double.isInfinite(dPlus));
+        assertTrue(dPlus > 0);
+
+        double dMinus = derivative.f(new DifferentialPair(0, -1)).getFirstDerivative();
+        assertTrue(Double.isInfinite(dMinus));
+        assertTrue(dMinus < 0);
+
     }
 
 }



Mime
View raw message