commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From er...@apache.org
Subject svn commit: r1189750 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/optimization/ main/java/org/apache/commons/math/optimization/direct/ main/java/org/apache/commons/math/optimization/univariate/ test/java/org/apache/commons/mat...
Date Thu, 27 Oct 2011 13:34:09 GMT
Author: erans
Date: Thu Oct 27 13:34:08 2011
New Revision: 1189750

URL: http://svn.apache.org/viewvc?rev=1189750&view=rev
Log:
MATH-413
Removed "setConvergenceChecker"; convergence checker is passed at construction.

Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/BaseMultiStartMultivariateRealOptimizer.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/BaseMultiStartMultivariateVectorialOptimizer.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/BaseOptimizer.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/BaseAbstractScalarOptimizer.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/BaseAbstractVectorialOptimizer.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/univariate/AbstractUnivariateRealOptimizer.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/univariate/BrentOptimizer.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/univariate/MultiStartUnivariateRealOptimizer.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateRealOptimizerTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateVectorialOptimizerTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/MultiStartMultivariateRealOptimizerTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/general/LevenbergMarquardtOptimizerTest.java

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/BaseMultiStartMultivariateRealOptimizer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/BaseMultiStartMultivariateRealOptimizer.java?rev=1189750&r1=1189749&r2=1189750&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/BaseMultiStartMultivariateRealOptimizer.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/BaseMultiStartMultivariateRealOptimizer.java
Thu Oct 27 13:34:08 2011
@@ -127,11 +127,6 @@ public class BaseMultiStartMultivariateR
     }
 
     /** {@inheritDoc} */
-    public void setConvergenceChecker(ConvergenceChecker<RealPointValuePair> checker)
{
-        optimizer.setConvergenceChecker(checker);
-    }
-
-    /** {@inheritDoc} */
     public ConvergenceChecker<RealPointValuePair> getConvergenceChecker() {
         return optimizer.getConvergenceChecker();
     }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/BaseMultiStartMultivariateVectorialOptimizer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/BaseMultiStartMultivariateVectorialOptimizer.java?rev=1189750&r1=1189749&r2=1189750&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/BaseMultiStartMultivariateVectorialOptimizer.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/BaseMultiStartMultivariateVectorialOptimizer.java
Thu Oct 27 13:34:08 2011
@@ -128,11 +128,6 @@ public class BaseMultiStartMultivariateV
     }
 
     /** {@inheritDoc} */
-    public void setConvergenceChecker(ConvergenceChecker<VectorialPointValuePair> checker)
{
-        optimizer.setConvergenceChecker(checker);
-    }
-
-    /** {@inheritDoc} */
     public ConvergenceChecker<VectorialPointValuePair> getConvergenceChecker() {
         return optimizer.getConvergenceChecker();
     }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/BaseOptimizer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/BaseOptimizer.java?rev=1189750&r1=1189749&r2=1189750&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/BaseOptimizer.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/BaseOptimizer.java
Thu Oct 27 13:34:08 2011
@@ -52,13 +52,6 @@ public interface BaseOptimizer<PAIR> {
     int getEvaluations();
 
     /**
-     * Set the convergence checker.
-     *
-     * @param checker Object to use to check for convergence.
-     */
-    void setConvergenceChecker(ConvergenceChecker<PAIR> checker);
-
-    /**
      * Get the convergence checker.
      *
      * @return the object used to check for convergence.

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/BaseAbstractScalarOptimizer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/BaseAbstractScalarOptimizer.java?rev=1189750&r1=1189749&r2=1189750&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/BaseAbstractScalarOptimizer.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/BaseAbstractScalarOptimizer.java
Thu Oct 27 13:34:08 2011
@@ -77,11 +77,6 @@ public abstract class BaseAbstractScalar
     }
 
     /** {@inheritDoc} */
-    public void setConvergenceChecker(ConvergenceChecker<RealPointValuePair> convergenceChecker)
{
-        this.checker = convergenceChecker;
-    }
-
-    /** {@inheritDoc} */
     public ConvergenceChecker<RealPointValuePair> getConvergenceChecker() {
         return checker;
     }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/BaseAbstractVectorialOptimizer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/BaseAbstractVectorialOptimizer.java?rev=1189750&r1=1189749&r2=1189750&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/BaseAbstractVectorialOptimizer.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/BaseAbstractVectorialOptimizer.java
Thu Oct 27 13:34:08 2011
@@ -79,11 +79,6 @@ public abstract class BaseAbstractVector
     }
 
     /** {@inheritDoc} */
-    public void setConvergenceChecker(ConvergenceChecker<VectorialPointValuePair> convergenceChecker)
{
-        this.checker = convergenceChecker;
-    }
-
-    /** {@inheritDoc} */
     public ConvergenceChecker<VectorialPointValuePair> getConvergenceChecker() {
         return checker;
     }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/univariate/AbstractUnivariateRealOptimizer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/univariate/AbstractUnivariateRealOptimizer.java?rev=1189750&r1=1189749&r2=1189750&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/univariate/AbstractUnivariateRealOptimizer.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/univariate/AbstractUnivariateRealOptimizer.java
Thu Oct 27 13:34:08 2011
@@ -35,7 +35,7 @@ import org.apache.commons.math.optimizat
 public abstract class AbstractUnivariateRealOptimizer
     implements UnivariateRealOptimizer {
     /** Convergence checker. */
-    private ConvergenceChecker<UnivariateRealPointValuePair> checker;
+    private final ConvergenceChecker<UnivariateRealPointValuePair> checker;
     /** Evaluations counter. */
     private final Incrementor evaluations = new Incrementor();
     /** Optimization type */
@@ -49,6 +49,13 @@ public abstract class AbstractUnivariate
     /** Function to optimize. */
     private UnivariateRealFunction function;
 
+    /**
+     * @param checker Convergence checking procedure.
+     */
+    protected AbstractUnivariateRealOptimizer(ConvergenceChecker<UnivariateRealPointValuePair>
checker) {
+        this.checker = checker;
+    }
+
     /** {@inheritDoc} */
     public int getMaxEvaluations() {
         return evaluations.getMaximalCount();
@@ -138,13 +145,6 @@ public abstract class AbstractUnivariate
     /**
      * {@inheritDoc}
      */
-    public void setConvergenceChecker(ConvergenceChecker<UnivariateRealPointValuePair>
c) {
-        checker = c;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
     public ConvergenceChecker<UnivariateRealPointValuePair> getConvergenceChecker()
{
         return checker;
     }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/univariate/BrentOptimizer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/univariate/BrentOptimizer.java?rev=1189750&r1=1189749&r2=1189750&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/univariate/BrentOptimizer.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/univariate/BrentOptimizer.java
Thu Oct 27 13:34:08 2011
@@ -31,10 +31,6 @@ import org.apache.commons.math.optimizat
  * If the function is defined on some interval {@code (lo, hi)}, then
  * this method finds an approximation {@code x} to the point at which
  * the function attains its minimum.
- * <br/>
- * The user is responsible for calling {@link
- * #setConvergenceChecker(ConvergenceChecker) ConvergenceChecker}
- * prior to using the optimizer.
  *
  * @version $Id$
  * @since 2.0
@@ -68,11 +64,16 @@ public class BrentOptimizer extends Abst
      *
      * @param rel Relative threshold.
      * @param abs Absolute threshold.
+     * @param checker Additional, user-defined, convergence checking
+     * procedure.
      * @throws NotStrictlyPositiveException if {@code abs <= 0}.
      * @throws NumberIsTooSmallException if {@code rel < 2 * Math.ulp(1d)}.
      */
     public BrentOptimizer(double rel,
-                          double abs) {
+                          double abs,
+                          ConvergenceChecker<UnivariateRealPointValuePair> checker)
{
+        super(checker);
+
         if (rel < MIN_RELATIVE_TOLERANCE) {
             throw new NumberIsTooSmallException(rel, MIN_RELATIVE_TOLERANCE, true);
         }
@@ -83,6 +84,25 @@ public class BrentOptimizer extends Abst
         absoluteThreshold = abs;
     }
 
+    /**
+     * The arguments are used implement the original stopping criterion
+     * of Brent's algorithm.
+     * {@code abs} and {@code rel} define a tolerance
+     * {@code tol = rel |x| + abs}. {@code rel} should be no smaller than
+     * <em>2 macheps</em> and preferably not much less than <em>sqrt(macheps)</em>,
+     * where <em>macheps</em> is the relative machine precision. {@code abs}
must
+     * be positive.
+     *
+     * @param rel Relative threshold.
+     * @param abs Absolute threshold.
+     * @throws NotStrictlyPositiveException if {@code abs <= 0}.
+     * @throws NumberIsTooSmallException if {@code rel < 2 * Math.ulp(1d)}.
+     */
+    public BrentOptimizer(double rel,
+                          double abs) {
+        this(rel, abs, null);
+    }
+
     /** {@inheritDoc} */
     @Override
     protected UnivariateRealPointValuePair doOptimize() {

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/univariate/MultiStartUnivariateRealOptimizer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/univariate/MultiStartUnivariateRealOptimizer.java?rev=1189750&r1=1189749&r2=1189750&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/univariate/MultiStartUnivariateRealOptimizer.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/univariate/MultiStartUnivariateRealOptimizer.java
Thu Oct 27 13:34:08 2011
@@ -88,13 +88,6 @@ public class MultiStartUnivariateRealOpt
     /**
      * {@inheritDoc}
      */
-    public void setConvergenceChecker(ConvergenceChecker<UnivariateRealPointValuePair>
checker) {
-        optimizer.setConvergenceChecker(checker);
-    }
-
-    /**
-     * {@inheritDoc}
-     */
     public ConvergenceChecker<UnivariateRealPointValuePair> getConvergenceChecker()
{
         return optimizer.getConvergenceChecker();
     }

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateRealOptimizerTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateRealOptimizerTest.java?rev=1189750&r1=1189749&r2=1189750&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateRealOptimizerTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateRealOptimizerTest.java
Thu Oct 27 13:34:08 2011
@@ -44,7 +44,8 @@ public class MultiStartDifferentiableMul
         circle.addPoint( 35.0,  15.0);
         circle.addPoint( 45.0,  97.0);
         NonLinearConjugateGradientOptimizer underlying =
-            new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE);
+            new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE,
+                                                    new SimpleScalarValueChecker(1.0e-10,
1.0e-10));
         JDKRandomGenerator g = new JDKRandomGenerator();
         g.setSeed(753289573253l);
         RandomVectorGenerator generator =
@@ -52,7 +53,6 @@ public class MultiStartDifferentiableMul
                                                   new GaussianRandomGenerator(g));
         MultiStartDifferentiableMultivariateRealOptimizer optimizer =
             new MultiStartDifferentiableMultivariateRealOptimizer(underlying, 10, generator);
-        optimizer.setConvergenceChecker(new SimpleScalarValueChecker(1.0e-10, 1.0e-10));
         RealPointValuePair optimum =
             optimizer.optimize(200, circle, GoalType.MINIMIZE, new double[] { 98.680, 47.345
});
         Assert.assertEquals(200, optimizer.getMaxEvaluations());

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateVectorialOptimizerTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateVectorialOptimizerTest.java?rev=1189750&r1=1189749&r2=1189750&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateVectorialOptimizerTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateVectorialOptimizerTest.java
Thu Oct 27 13:34:08 2011
@@ -100,7 +100,8 @@ public class MultiStartDifferentiableMul
         LinearProblem problem =
             new LinearProblem(new double[][] { { 2 } }, new double[] { 3 });
         DifferentiableMultivariateVectorialOptimizer underlyingOptimizer =
-            new GaussNewtonOptimizer(true);
+            new GaussNewtonOptimizer(true,
+                                     new SimpleVectorialValueChecker(1.0e-6, 1.0e-6));
         JDKRandomGenerator g = new JDKRandomGenerator();
         g.setSeed(16069223052l);
         RandomVectorGenerator generator =
@@ -108,7 +109,6 @@ public class MultiStartDifferentiableMul
         MultiStartDifferentiableMultivariateVectorialOptimizer optimizer =
             new MultiStartDifferentiableMultivariateVectorialOptimizer(underlyingOptimizer,
                                                                        10, generator);
-        optimizer.setConvergenceChecker(new SimpleVectorialValueChecker(1.0e-6, 1.0e-6));
 
         // no optima before first optimization attempt
         try {
@@ -132,10 +132,11 @@ public class MultiStartDifferentiableMul
         Assert.assertEquals(100, optimizer.getMaxEvaluations());
     }
 
-    @Test(expected = TestException.class)
+    @Test(expected=TestException.class)
     public void testNoOptimum() {
         DifferentiableMultivariateVectorialOptimizer underlyingOptimizer =
-            new GaussNewtonOptimizer(true);
+            new GaussNewtonOptimizer(true,
+                                     new SimpleVectorialValueChecker(1.0e-6, 1.0e-6));
         JDKRandomGenerator g = new JDKRandomGenerator();
         g.setSeed(12373523445l);
         RandomVectorGenerator generator =
@@ -143,7 +144,6 @@ public class MultiStartDifferentiableMul
         MultiStartDifferentiableMultivariateVectorialOptimizer optimizer =
             new MultiStartDifferentiableMultivariateVectorialOptimizer(underlyingOptimizer,
                                                                        10, generator);
-        optimizer.setConvergenceChecker(new SimpleVectorialValueChecker(1.0e-6, 1.0e-6));
         optimizer.optimize(100, new DifferentiableMultivariateVectorialFunction() {
                 public MultivariateMatrixFunction jacobian() {
                     return null;

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/MultiStartMultivariateRealOptimizerTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/MultiStartMultivariateRealOptimizerTest.java?rev=1189750&r1=1189749&r2=1189750&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/MultiStartMultivariateRealOptimizerTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/MultiStartMultivariateRealOptimizerTest.java
Thu Oct 27 13:34:08 2011
@@ -32,7 +32,8 @@ public class MultiStartMultivariateRealO
     @Test
     public void testRosenbrock() {
         Rosenbrock rosenbrock = new Rosenbrock();
-        SimplexOptimizer underlying = new SimplexOptimizer();
+        SimplexOptimizer underlying
+            = new SimplexOptimizer(new SimpleScalarValueChecker(-1, 1.0e-3));
         NelderMeadSimplex simplex = new NelderMeadSimplex(new double[][] {
                 { -1.2,  1.0 }, { 0.9, 1.2 } , {  3.5, -2.3 }
             });
@@ -43,7 +44,6 @@ public class MultiStartMultivariateRealO
             new UncorrelatedRandomVectorGenerator(2, new GaussianRandomGenerator(g));
         MultiStartMultivariateRealOptimizer optimizer =
             new MultiStartMultivariateRealOptimizer(underlying, 10, generator);
-        optimizer.setConvergenceChecker(new SimpleScalarValueChecker(-1, 1.0e-3));
         RealPointValuePair optimum =
             optimizer.optimize(1100, rosenbrock, GoalType.MINIMIZE, new double[] { -1.2,
1.0 });
 

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/general/LevenbergMarquardtOptimizerTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/general/LevenbergMarquardtOptimizerTest.java?rev=1189750&r1=1189749&r2=1189750&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/general/LevenbergMarquardtOptimizerTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/general/LevenbergMarquardtOptimizerTest.java
Thu Oct 27 13:34:08 2011
@@ -478,8 +478,8 @@ public class LevenbergMarquardtOptimizer
         for (int i = 0; i < points.length; ++i) {
             circle.addPoint(points[i][0], points[i][1]);
         }
-        LevenbergMarquardtOptimizer optimizer = new LevenbergMarquardtOptimizer();
-        optimizer.setConvergenceChecker(new SimpleVectorialValueChecker(1.0e-8, 1.0e-8));
+        LevenbergMarquardtOptimizer optimizer
+            = new LevenbergMarquardtOptimizer(new SimpleVectorialValueChecker(1.0e-8, 1.0e-8));
         VectorialPointValuePair optimum =
             optimizer.optimize(100, circle, target, weights, new double[] { -12, -12 });
         Point2D.Double center = new Point2D.Double(optimum.getPointRef()[0], optimum.getPointRef()[1]);



Mime
View raw message