commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
Subject svn commit: r592093 - in /commons/proper/math/trunk/src/test/org/apache/commons/math/estimation: GaussNewtonEstimatorTest.java LevenbergMarquardtEstimatorTest.java
Date Mon, 05 Nov 2007 17:11:30 GMT
Author: luc
Date: Mon Nov  5 09:11:29 2007
New Revision: 592093

URL: http://svn.apache.org/viewvc?rev=592093&view=rev
Log:
improved test coverage

Modified:
    commons/proper/math/trunk/src/test/org/apache/commons/math/estimation/GaussNewtonEstimatorTest.java
    commons/proper/math/trunk/src/test/org/apache/commons/math/estimation/LevenbergMarquardtEstimatorTest.java

Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/estimation/GaussNewtonEstimatorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/estimation/GaussNewtonEstimatorTest.java?rev=592093&r1=592092&r2=592093&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/estimation/GaussNewtonEstimatorTest.java
(original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/estimation/GaussNewtonEstimatorTest.java
Mon Nov  5 09:11:29 2007
@@ -445,21 +445,39 @@
 
   }
 
+  public void testMaxIterations() {
+      Circle circle = new Circle(98.680, 47.345);
+      circle.addPoint( 30.0,  68.0);
+      circle.addPoint( 50.0,  -6.0);
+      circle.addPoint(110.0, -20.0);
+      circle.addPoint( 35.0,  15.0);
+      circle.addPoint( 45.0,  97.0);
+      try {
+        GaussNewtonEstimator estimator = new GaussNewtonEstimator(4, 1.0e-14, 1.0e-14);
+        estimator.estimate(circle);
+        fail("an exception should have been caught");
+      } catch (EstimationException ee) {
+        // expected behavior
+      } catch (Exception e) {
+        fail("wrong exception type caught");
+      }
+    }
+
   public void testCircleFitting() throws EstimationException {
-    Circle circle = new Circle(98.680, 47.345);
-    circle.addPoint( 30.0,  68.0);
-    circle.addPoint( 50.0,  -6.0);
-    circle.addPoint(110.0, -20.0);
-    circle.addPoint( 35.0,  15.0);
-    circle.addPoint( 45.0,  97.0);
-    GaussNewtonEstimator estimator = new GaussNewtonEstimator(100, 1.0e-10, 1.0e-10);
-    estimator.estimate(circle);
-    double rms = estimator.getRMS(circle);
-    assertEquals(1.768262623567235,  Math.sqrt(circle.getM()) * rms,  1.0e-10);
-    assertEquals(69.96016176931406, circle.getRadius(), 1.0e-10);
-    assertEquals(96.07590211815305, circle.getX(),      1.0e-10);
-    assertEquals(48.13516790438953, circle.getY(),      1.0e-10);
-  }
+      Circle circle = new Circle(98.680, 47.345);
+      circle.addPoint( 30.0,  68.0);
+      circle.addPoint( 50.0,  -6.0);
+      circle.addPoint(110.0, -20.0);
+      circle.addPoint( 35.0,  15.0);
+      circle.addPoint( 45.0,  97.0);
+      GaussNewtonEstimator estimator = new GaussNewtonEstimator(100, 1.0e-10, 1.0e-10);
+      estimator.estimate(circle);
+      double rms = estimator.getRMS(circle);
+      assertEquals(1.768262623567235,  Math.sqrt(circle.getM()) * rms,  1.0e-10);
+      assertEquals(69.96016176931406, circle.getRadius(), 1.0e-10);
+      assertEquals(96.07590211815305, circle.getX(),      1.0e-10);
+      assertEquals(48.13516790438953, circle.getY(),      1.0e-10);
+    }
 
   public void testCircleFittingBadInit() throws EstimationException {
     Circle circle = new Circle(-12, -12);

Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/estimation/LevenbergMarquardtEstimatorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/estimation/LevenbergMarquardtEstimatorTest.java?rev=592093&r1=592092&r2=592093&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/estimation/LevenbergMarquardtEstimatorTest.java
(original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/estimation/LevenbergMarquardtEstimatorTest.java
Mon Nov  5 09:11:29 2007
@@ -446,23 +446,55 @@
 
   }
 
-  public void testCircleFitting() throws EstimationException {
-    Circle circle = new Circle(98.680, 47.345);
-    circle.addPoint( 30.0,  68.0);
-    circle.addPoint( 50.0,  -6.0);
-    circle.addPoint(110.0, -20.0);
-    circle.addPoint( 35.0,  15.0);
-    circle.addPoint( 45.0,  97.0);
-    LevenbergMarquardtEstimator estimator = new LevenbergMarquardtEstimator();
-    estimator.estimate(circle);
-    assertTrue(estimator.getCostEvaluations() < 10);
-    assertTrue(estimator.getJacobianEvaluations() < 10);
-    double rms = estimator.getRMS(circle);
-    assertEquals(1.768262623567235,  Math.sqrt(circle.getM()) * rms,  1.0e-10);
-    assertEquals(69.96016176931406, circle.getRadius(), 1.0e-10);
-    assertEquals(96.07590211815305, circle.getX(),      1.0e-10);
-    assertEquals(48.13516790438953, circle.getY(),      1.0e-10);
+  public void testControlParameters() throws EstimationException {
+      Circle circle = new Circle(98.680, 47.345);
+      circle.addPoint( 30.0,  68.0);
+      circle.addPoint( 50.0,  -6.0);
+      circle.addPoint(110.0, -20.0);
+      circle.addPoint( 35.0,  15.0);
+      circle.addPoint( 45.0,  97.0);
+      checkEstimate(circle, 100.0, 1000, 1.0e-10, 1.0e-10, 1.0e-10, false);
+      checkEstimate(circle, 1.0e-12, 10, 1.0e-20, 1.0e-20, 1.0e-20, true);
   }
+
+  private void checkEstimate(EstimationProblem problem,
+                             double initialStepBoundFactor, int maxCostEval,
+                             double costRelativeTolerance, double parRelativeTolerance,
+                             double orthoTolerance, boolean shouldFail) {
+      try {
+        LevenbergMarquardtEstimator estimator = new LevenbergMarquardtEstimator();
+        estimator.setInitialStepBoundFactor(initialStepBoundFactor);
+        estimator.setMaxCostEval(maxCostEval);
+        estimator.setCostRelativeTolerance(costRelativeTolerance);
+        estimator.setParRelativeTolerance(parRelativeTolerance);
+        estimator.setOrthoTolerance(orthoTolerance);
+        estimator.estimate(problem);
+        assertTrue(! shouldFail);
+      } catch (EstimationException ee) {
+          System.out.println(ee.getClass().getName() + " " + ee.getMessage());
+        assertTrue(shouldFail);
+      } catch (Exception e) {
+        fail("wrong exception type caught");
+      }
+    }
+
+  public void testCircleFitting() throws EstimationException {
+      Circle circle = new Circle(98.680, 47.345);
+      circle.addPoint( 30.0,  68.0);
+      circle.addPoint( 50.0,  -6.0);
+      circle.addPoint(110.0, -20.0);
+      circle.addPoint( 35.0,  15.0);
+      circle.addPoint( 45.0,  97.0);
+      LevenbergMarquardtEstimator estimator = new LevenbergMarquardtEstimator();
+      estimator.estimate(circle);
+      assertTrue(estimator.getCostEvaluations() < 10);
+      assertTrue(estimator.getJacobianEvaluations() < 10);
+      double rms = estimator.getRMS(circle);
+      assertEquals(1.768262623567235,  Math.sqrt(circle.getM()) * rms,  1.0e-10);
+      assertEquals(69.96016176931406, circle.getRadius(), 1.0e-10);
+      assertEquals(96.07590211815305, circle.getX(),      1.0e-10);
+      assertEquals(48.13516790438953, circle.getY(),      1.0e-10);
+    }
 
   public void testCircleFittingBadInit() throws EstimationException {
     Circle circle = new Circle(-12, -12);



Mime
View raw message