commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From er...@apache.org
Subject svn commit: r1347184 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math3/optimization/fitting/PolynomialFitter.java test/java/org/apache/commons/math3/optimization/fitting/PolynomialFitterTest.java
Date Wed, 06 Jun 2012 22:33:42 GMT
Author: erans
Date: Wed Jun  6 22:33:42 2012
New Revision: 1347184

URL: http://svn.apache.org/viewvc?rev=1347184&view=rev
Log:
MATH-800
Deprecated "PolynomialFitter" and adapted unit test to use "CurveFitter"
directly.

Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optimization/fitting/PolynomialFitter.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/fitting/PolynomialFitterTest.java

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optimization/fitting/PolynomialFitter.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optimization/fitting/PolynomialFitter.java?rev=1347184&r1=1347183&r2=1347184&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optimization/fitting/PolynomialFitter.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optimization/fitting/PolynomialFitter.java
Wed Jun  6 22:33:42 2012
@@ -26,8 +26,14 @@ import org.apache.commons.math3.optimiza
  * searched by a least square estimator.</p>
  * @version $Id$
  * @since 2.0
+ *
+ * @deprecated Since 3.1 (to be removed in 4.0, see <a href="https://issues.apache.org/jira/browse/MATH-800">MATH-800</a>).
+ * Please use {@link CurveFitter} directly, by passing an instance of
+ * {@link org.apache.commons.math3.analysis.polynomials.PolynomialFunction.Parametric PolynomialFunction.Parametric}
+ * as an argument to the
+ * {@link CurveFitter#fit(int,org.apache.commons.math3.analysis.ParametricUnivariateFunction,double[])
fit}
+ * method.
  */
-
 public class PolynomialFitter extends CurveFitter {
     /** Polynomial degree. */
     private final int degree;

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/fitting/PolynomialFitterTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/fitting/PolynomialFitterTest.java?rev=1347184&r1=1347183&r2=1347184&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/fitting/PolynomialFitterTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/fitting/PolynomialFitterTest.java
Wed Jun  6 22:33:42 2012
@@ -24,11 +24,16 @@ import org.apache.commons.math3.exceptio
 import org.apache.commons.math3.optimization.DifferentiableMultivariateVectorOptimizer;
 import org.apache.commons.math3.optimization.general.GaussNewtonOptimizer;
 import org.apache.commons.math3.optimization.general.LevenbergMarquardtOptimizer;
+import org.apache.commons.math3.optimization.SimpleVectorValueChecker;
 import org.apache.commons.math3.util.FastMath;
 
 import org.junit.Test;
 import org.junit.Assert;
 
+/**
+ * Test for class {@link CurveFitter} where the function to fit is a
+ * polynomial.
+ */
 public class PolynomialFitterTest {
 
     @Test
@@ -37,13 +42,15 @@ public class PolynomialFitterTest {
         for (int degree = 1; degree < 10; ++degree) {
             PolynomialFunction p = buildRandomPolynomial(degree, randomizer);
 
-            PolynomialFitter fitter =
-                new PolynomialFitter(degree, new LevenbergMarquardtOptimizer());
+            CurveFitter fitter = new CurveFitter(new LevenbergMarquardtOptimizer());
             for (int i = 0; i <= degree; ++i) {
                 fitter.addObservedPoint(1.0, i, p.value(i));
             }
 
-            PolynomialFunction fitted = new PolynomialFunction(fitter.fit());
+            final double[] init = new double[degree + 1];
+            PolynomialFunction fitted = new PolynomialFunction(fitter.fit(Integer.MAX_VALUE,
+                                                                          new PolynomialFunction.Parametric(),
+                                                                          init));
 
             for (double x = -1.0; x < 1.0; x += 0.01) {
                 double error = FastMath.abs(p.value(x) - fitted.value(x)) /
@@ -60,14 +67,16 @@ public class PolynomialFitterTest {
         for (int degree = 0; degree < 10; ++degree) {
             PolynomialFunction p = buildRandomPolynomial(degree, randomizer);
 
-            PolynomialFitter fitter =
-                new PolynomialFitter(degree, new LevenbergMarquardtOptimizer());
+            CurveFitter fitter = new CurveFitter(new LevenbergMarquardtOptimizer());
             for (double x = -1.0; x < 1.0; x += 0.01) {
                 fitter.addObservedPoint(1.0, x,
                                         p.value(x) + 0.1 * randomizer.nextGaussian());
             }
 
-            PolynomialFunction fitted = new PolynomialFunction(fitter.fit());
+            final double[] init = new double[degree + 1];
+            PolynomialFunction fitted = new PolynomialFunction(fitter.fit(Integer.MAX_VALUE,
+                                                                          new PolynomialFunction.Parametric(),
+                                                                          init));
 
             for (double x = -1.0; x < 1.0; x += 0.01) {
                 double error = FastMath.abs(p.value(x) - fitted.value(x)) /
@@ -77,7 +86,6 @@ public class PolynomialFitterTest {
             }
         }
         Assert.assertTrue(maxError > 0.01);
-
     }
 
     @Test
@@ -89,9 +97,7 @@ public class PolynomialFitterTest {
     @Test
     public void testRedundantUnsolvable() {
         // Gauss-Newton should not be able to solve redundant information
-        DifferentiableMultivariateVectorOptimizer optimizer =
-            new GaussNewtonOptimizer(true);
-        checkUnsolvableProblem(optimizer, false);
+        checkUnsolvableProblem(new GaussNewtonOptimizer(true, new SimpleVectorValueChecker(1e-15,
1e-15)), false);
     }
 
     private void checkUnsolvableProblem(DifferentiableMultivariateVectorOptimizer optimizer,
@@ -100,7 +106,7 @@ public class PolynomialFitterTest {
         for (int degree = 0; degree < 10; ++degree) {
             PolynomialFunction p = buildRandomPolynomial(degree, randomizer);
 
-            PolynomialFitter fitter = new PolynomialFitter(degree, optimizer);
+            CurveFitter fitter = new CurveFitter(optimizer);
 
             // reusing the same point over and over again does not bring
             // information, the problem cannot be solved in this case for
@@ -111,7 +117,10 @@ public class PolynomialFitterTest {
             }
 
             try {
-                fitter.fit();
+                final double[] init = new double[degree + 1];
+                fitter.fit(Integer.MAX_VALUE,
+                           new PolynomialFunction.Parametric(),
+                           init);
                 Assert.assertTrue(solvable || (degree == 0));
             } catch(ConvergenceException e) {
                 Assert.assertTrue((! solvable) && (degree > 0));



Mime
View raw message