From d088734d253b465a58fa3d2b0b5d639e92cfaa9c Mon Sep 17 00:00:00 2001 From: William Barker Date: Sun, 7 Jun 2009 21:24:18 +0000 Subject: [PATCH] Serialization changes for optimization. Still need to add junit test, but for this it doesn't look like a blocker. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@782468 13f79535-47bb-0310-9956-ffa450edef68 --- .../DifferentiableMultivariateRealOptimizer.java | 4 +--- .../DifferentiableMultivariateVectorialOptimizer.java | 4 +--- .../MultiStartDifferentiableMultivariateRealOptimizer.java | 3 ++- .../math/optimization/direct/DirectSearchOptimizer.java | 7 +------ .../general/AbstractLeastSquaresOptimizer.java | 3 --- .../general/AbstractScalarDifferentiableOptimizer.java | 3 --- .../math/optimization/general/GaussNewtonOptimizer.java | 4 +++- .../optimization/general/LevenbergMarquardtOptimizer.java | 3 ++- .../general/NonLinearConjugateGradientOptimizer.java | 4 ++-- .../commons/math/optimization/general/Preconditioner.java | 4 +--- .../general/NonLinearConjugateGradientOptimizerTest.java | 1 - .../org/apache/commons/math/random/RandomDataTest.java | 5 +++++ 12 files changed, 18 insertions(+), 27 deletions(-) diff --git a/src/java/org/apache/commons/math/optimization/DifferentiableMultivariateRealOptimizer.java b/src/java/org/apache/commons/math/optimization/DifferentiableMultivariateRealOptimizer.java index f278bd37c..8f2e9d4be 100644 --- a/src/java/org/apache/commons/math/optimization/DifferentiableMultivariateRealOptimizer.java +++ b/src/java/org/apache/commons/math/optimization/DifferentiableMultivariateRealOptimizer.java @@ -17,8 +17,6 @@ package org.apache.commons.math.optimization; -import java.io.Serializable; - import org.apache.commons.math.FunctionEvaluationException; import org.apache.commons.math.analysis.DifferentiableMultivariateRealFunction; @@ -32,7 +30,7 @@ import org.apache.commons.math.analysis.DifferentiableMultivariateRealFunction; * @version $Revision$ $Date$ * @since 2.0 */ -public interface DifferentiableMultivariateRealOptimizer extends Serializable { +public interface DifferentiableMultivariateRealOptimizer { /** Set the maximal number of iterations of the algorithm. * @param maxIterations maximal number of function calls diff --git a/src/java/org/apache/commons/math/optimization/DifferentiableMultivariateVectorialOptimizer.java b/src/java/org/apache/commons/math/optimization/DifferentiableMultivariateVectorialOptimizer.java index 86a69c0d0..6853768b9 100644 --- a/src/java/org/apache/commons/math/optimization/DifferentiableMultivariateVectorialOptimizer.java +++ b/src/java/org/apache/commons/math/optimization/DifferentiableMultivariateVectorialOptimizer.java @@ -17,8 +17,6 @@ package org.apache.commons.math.optimization; -import java.io.Serializable; - import org.apache.commons.math.FunctionEvaluationException; import org.apache.commons.math.analysis.DifferentiableMultivariateVectorialFunction; @@ -32,7 +30,7 @@ import org.apache.commons.math.analysis.DifferentiableMultivariateVectorialFunct * @version $Revision$ $Date$ * @since 2.0 */ -public interface DifferentiableMultivariateVectorialOptimizer extends Serializable { +public interface DifferentiableMultivariateVectorialOptimizer { /** Set the maximal number of iterations of the algorithm. * @param maxIterations maximal number of function calls diff --git a/src/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateRealOptimizer.java b/src/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateRealOptimizer.java index c2179384b..7ccd0a187 100644 --- a/src/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateRealOptimizer.java +++ b/src/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateRealOptimizer.java @@ -17,6 +17,7 @@ package org.apache.commons.math.optimization; +import java.io.Serializable; import java.util.Arrays; import java.util.Comparator; @@ -38,7 +39,7 @@ import org.apache.commons.math.random.RandomVectorGenerator; * @since 2.0 */ public class MultiStartDifferentiableMultivariateRealOptimizer - implements DifferentiableMultivariateRealOptimizer { + implements DifferentiableMultivariateRealOptimizer, Serializable { /** Serializable version identifier. */ private static final long serialVersionUID = -3220364832729994537L; diff --git a/src/java/org/apache/commons/math/optimization/direct/DirectSearchOptimizer.java b/src/java/org/apache/commons/math/optimization/direct/DirectSearchOptimizer.java index b8dd6a5c9..2b3b55b57 100644 --- a/src/java/org/apache/commons/math/optimization/direct/DirectSearchOptimizer.java +++ b/src/java/org/apache/commons/math/optimization/direct/DirectSearchOptimizer.java @@ -86,12 +86,7 @@ import org.apache.commons.math.optimization.SimpleScalarValueChecker; * @version $Revision$ $Date$ * @since 1.2 */ -public abstract class DirectSearchOptimizer implements MultivariateRealOptimizer, Serializable { - // TODO: Add Serializable documentation - // TODO: Check Serializable implementation - - /** Serializable version identifier. */ - private static final long serialVersionUID = 4299910390345933369L; +public abstract class DirectSearchOptimizer implements MultivariateRealOptimizer { /** Simplex. */ protected RealPointValuePair[] simplex; diff --git a/src/java/org/apache/commons/math/optimization/general/AbstractLeastSquaresOptimizer.java b/src/java/org/apache/commons/math/optimization/general/AbstractLeastSquaresOptimizer.java index b9d73871d..b83f1a688 100644 --- a/src/java/org/apache/commons/math/optimization/general/AbstractLeastSquaresOptimizer.java +++ b/src/java/org/apache/commons/math/optimization/general/AbstractLeastSquaresOptimizer.java @@ -41,9 +41,6 @@ import org.apache.commons.math.optimization.VectorialPointValuePair; */ public abstract class AbstractLeastSquaresOptimizer implements DifferentiableMultivariateVectorialOptimizer { - /** Serializable version identifier */ - private static final long serialVersionUID = 5413193243329026789L; - /** Default maximal number of iterations allowed. */ public static final int DEFAULT_MAX_ITERATIONS = 100; diff --git a/src/java/org/apache/commons/math/optimization/general/AbstractScalarDifferentiableOptimizer.java b/src/java/org/apache/commons/math/optimization/general/AbstractScalarDifferentiableOptimizer.java index aa9ac518b..2bca3dd2d 100644 --- a/src/java/org/apache/commons/math/optimization/general/AbstractScalarDifferentiableOptimizer.java +++ b/src/java/org/apache/commons/math/optimization/general/AbstractScalarDifferentiableOptimizer.java @@ -41,9 +41,6 @@ public abstract class AbstractScalarDifferentiableOptimizer /** Default maximal number of iterations allowed. */ public static final int DEFAULT_MAX_ITERATIONS = 100; - /** Serializable version identifier. */ - private static final long serialVersionUID = 1357126012308766636L; - /** Maximal number of iterations allowed. */ private int maxIterations; diff --git a/src/java/org/apache/commons/math/optimization/general/GaussNewtonOptimizer.java b/src/java/org/apache/commons/math/optimization/general/GaussNewtonOptimizer.java index d7071ccac..f6ae5e92c 100644 --- a/src/java/org/apache/commons/math/optimization/general/GaussNewtonOptimizer.java +++ b/src/java/org/apache/commons/math/optimization/general/GaussNewtonOptimizer.java @@ -17,6 +17,8 @@ package org.apache.commons.math.optimization.general; +import java.io.Serializable; + import org.apache.commons.math.FunctionEvaluationException; import org.apache.commons.math.linear.DecompositionSolver; import org.apache.commons.math.linear.DenseRealMatrix; @@ -42,7 +44,7 @@ import org.apache.commons.math.optimization.VectorialPointValuePair; * */ -public class GaussNewtonOptimizer extends AbstractLeastSquaresOptimizer { +public class GaussNewtonOptimizer extends AbstractLeastSquaresOptimizer implements Serializable { /** Serializable version identifier */ private static final long serialVersionUID = 7011643996279553223L; diff --git a/src/java/org/apache/commons/math/optimization/general/LevenbergMarquardtOptimizer.java b/src/java/org/apache/commons/math/optimization/general/LevenbergMarquardtOptimizer.java index 55cb8b4e6..94aee343c 100644 --- a/src/java/org/apache/commons/math/optimization/general/LevenbergMarquardtOptimizer.java +++ b/src/java/org/apache/commons/math/optimization/general/LevenbergMarquardtOptimizer.java @@ -16,6 +16,7 @@ */ package org.apache.commons.math.optimization.general; +import java.io.Serializable; import java.util.Arrays; import org.apache.commons.math.FunctionEvaluationException; @@ -99,7 +100,7 @@ import org.apache.commons.math.optimization.VectorialPointValuePair; * @since 2.0 * */ -public class LevenbergMarquardtOptimizer extends AbstractLeastSquaresOptimizer { +public class LevenbergMarquardtOptimizer extends AbstractLeastSquaresOptimizer implements Serializable { /** Serializable version identifier */ private static final long serialVersionUID = 8851282236194244323L; diff --git a/src/java/org/apache/commons/math/optimization/general/NonLinearConjugateGradientOptimizer.java b/src/java/org/apache/commons/math/optimization/general/NonLinearConjugateGradientOptimizer.java index 0dc76ed3d..d474afbc7 100644 --- a/src/java/org/apache/commons/math/optimization/general/NonLinearConjugateGradientOptimizer.java +++ b/src/java/org/apache/commons/math/optimization/general/NonLinearConjugateGradientOptimizer.java @@ -45,7 +45,7 @@ import org.apache.commons.math.optimization.SimpleVectorialValueChecker; public class NonLinearConjugateGradientOptimizer extends AbstractScalarDifferentiableOptimizer - implements DifferentiableMultivariateRealOptimizer { + implements DifferentiableMultivariateRealOptimizer, Serializable { /** Serializable version identifier. */ private static final long serialVersionUID = -6545223926568155458L; @@ -242,7 +242,7 @@ public class NonLinearConjugateGradientOptimizer } /** Default identity preconditioner. */ - private static class IdentityPreconditioner implements Preconditioner { + private static class IdentityPreconditioner implements Preconditioner, Serializable { /** Serializable version identifier. */ private static final long serialVersionUID = 1868235977809734023L; diff --git a/src/java/org/apache/commons/math/optimization/general/Preconditioner.java b/src/java/org/apache/commons/math/optimization/general/Preconditioner.java index 0471c6296..e1300b335 100644 --- a/src/java/org/apache/commons/math/optimization/general/Preconditioner.java +++ b/src/java/org/apache/commons/math/optimization/general/Preconditioner.java @@ -17,8 +17,6 @@ package org.apache.commons.math.optimization.general; -import java.io.Serializable; - import org.apache.commons.math.FunctionEvaluationException; /** @@ -27,7 +25,7 @@ import org.apache.commons.math.FunctionEvaluationException; * @version $Revision$ $Date$ * @since 2.0 */ -public interface Preconditioner extends Serializable { +public interface Preconditioner { /** * Precondition a search direction. diff --git a/src/test/org/apache/commons/math/optimization/general/NonLinearConjugateGradientOptimizerTest.java b/src/test/org/apache/commons/math/optimization/general/NonLinearConjugateGradientOptimizerTest.java index e0482975f..59334e787 100644 --- a/src/test/org/apache/commons/math/optimization/general/NonLinearConjugateGradientOptimizerTest.java +++ b/src/test/org/apache/commons/math/optimization/general/NonLinearConjugateGradientOptimizerTest.java @@ -191,7 +191,6 @@ extends TestCase { new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE); optimizer.setMaxIterations(100); optimizer.setPreconditioner(new Preconditioner() { - private static final long serialVersionUID = -2935127802358453014L; public double[] precondition(double[] point, double[] r) { double[] d = r.clone(); d[0] /= 72.0; diff --git a/src/test/org/apache/commons/math/random/RandomDataTest.java b/src/test/org/apache/commons/math/random/RandomDataTest.java index 6d674210a..5117422bc 100644 --- a/src/test/org/apache/commons/math/random/RandomDataTest.java +++ b/src/test/org/apache/commons/math/random/RandomDataTest.java @@ -21,6 +21,7 @@ import junit.framework.TestSuite; import java.util.HashSet; import org.apache.commons.math.RetryTestCase; +import org.apache.commons.math.TestUtils; import org.apache.commons.math.stat.Frequency; import org.apache.commons.math.stat.inference.ChiSquareTestImpl; import org.apache.commons.math.stat.descriptive.SummaryStatistics; @@ -607,6 +608,10 @@ public class RandomDataTest extends RetryTestCase { } } + // Disable until we have equals + //public void testSerial() { + // assertEquals(randomData, TestUtils.serializeAndRecover(randomData)); + //} private int findPerm(int[][] p, int[] samp) { for (int i = 0; i < p.length; i++) {