diff --git a/src/main/java/org/apache/commons/math/optimization/fitting/ParametricRealFunction.java b/src/main/java/org/apache/commons/math/analysis/ParametricUnivariateRealFunction.java similarity index 87% rename from src/main/java/org/apache/commons/math/optimization/fitting/ParametricRealFunction.java rename to src/main/java/org/apache/commons/math/analysis/ParametricUnivariateRealFunction.java index 2a7111a2d..167af220c 100644 --- a/src/main/java/org/apache/commons/math/optimization/fitting/ParametricRealFunction.java +++ b/src/main/java/org/apache/commons/math/analysis/ParametricUnivariateRealFunction.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.commons.math.optimization.fitting; +package org.apache.commons.math.analysis; /** * An interface representing a real function that depends on one independent @@ -23,7 +23,7 @@ package org.apache.commons.math.optimization.fitting; * * @version $Revision$ $Date$ */ -public interface ParametricRealFunction { +public interface ParametricUnivariateRealFunction { /** * Compute the value of the function. * @@ -31,7 +31,7 @@ public interface ParametricRealFunction { * @param parameters Function parameters. * @return the value. */ - double value(double x, double[] parameters); + double value(double x, double ... parameters); /** * Compute the gradient of the function with respect to its parameters. @@ -40,5 +40,5 @@ public interface ParametricRealFunction { * @param parameters Function parameters. * @return the value. */ - double[] gradient(double x, double[] parameters); + double[] gradient(double x, double ... parameters); } diff --git a/src/main/java/org/apache/commons/math/optimization/fitting/CurveFitter.java b/src/main/java/org/apache/commons/math/optimization/fitting/CurveFitter.java index ccf069f2e..6f113326a 100644 --- a/src/main/java/org/apache/commons/math/optimization/fitting/CurveFitter.java +++ b/src/main/java/org/apache/commons/math/optimization/fitting/CurveFitter.java @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.List; import org.apache.commons.math.analysis.DifferentiableMultivariateVectorialFunction; +import org.apache.commons.math.analysis.ParametricUnivariateRealFunction; import org.apache.commons.math.analysis.MultivariateMatrixFunction; import org.apache.commons.math.optimization.DifferentiableMultivariateVectorialOptimizer; import org.apache.commons.math.optimization.VectorialPointValuePair; @@ -121,7 +122,7 @@ public class CurveFitter { * @throws org.apache.commons.math.exception.MathUserException if the * parametric function throws one. */ - public double[] fit(final ParametricRealFunction f, final double[] initialGuess) { + public double[] fit(final ParametricUnivariateRealFunction f, final double[] initialGuess) { return fit(Integer.MAX_VALUE, f, initialGuess); } @@ -143,7 +144,7 @@ public class CurveFitter { * @throws org.apache.commons.math.exception.MathUserException if the * parametric function throws one. */ - public double[] fit(int maxEval, final ParametricRealFunction f, + public double[] fit(int maxEval, final ParametricUnivariateRealFunction f, final double[] initialGuess) { // prepare least squares problem double[] target = new double[observations.size()]; @@ -168,12 +169,12 @@ public class CurveFitter { private class TheoreticalValuesFunction implements DifferentiableMultivariateVectorialFunction { /** Function to fit. */ - private final ParametricRealFunction f; + private final ParametricUnivariateRealFunction f; /** Simple constructor. * @param f function to fit. */ - public TheoreticalValuesFunction(final ParametricRealFunction f) { + public TheoreticalValuesFunction(final ParametricUnivariateRealFunction f) { this.f = f; } diff --git a/src/main/java/org/apache/commons/math/optimization/fitting/GaussianFitter.java b/src/main/java/org/apache/commons/math/optimization/fitting/GaussianFitter.java index 9d1907eae..613831e81 100644 --- a/src/main/java/org/apache/commons/math/optimization/fitting/GaussianFitter.java +++ b/src/main/java/org/apache/commons/math/optimization/fitting/GaussianFitter.java @@ -86,7 +86,7 @@ public class GaussianFitter { /** * Fits Gaussian function to the observed points. * It will call the base class - * {@link CurveFitter#fit(ParametricRealFunction,double[]) fit} method. + * {@link CurveFitter#fit(ParametricUnivariateRealFunction,double[]) fit} method. * * @return the Gaussian function that best fits the observed points. * @see CurveFitter diff --git a/src/main/java/org/apache/commons/math/optimization/fitting/HarmonicFitter.java b/src/main/java/org/apache/commons/math/optimization/fitting/HarmonicFitter.java index 009eba4b2..02dd08efc 100644 --- a/src/main/java/org/apache/commons/math/optimization/fitting/HarmonicFitter.java +++ b/src/main/java/org/apache/commons/math/optimization/fitting/HarmonicFitter.java @@ -21,6 +21,7 @@ import org.apache.commons.math.exception.NumberIsTooSmallException; import org.apache.commons.math.exception.util.LocalizedFormats; import org.apache.commons.math.optimization.DifferentiableMultivariateVectorialOptimizer; import org.apache.commons.math.optimization.OptimizationException; +import org.apache.commons.math.analysis.ParametricUnivariateRealFunction; import org.apache.commons.math.util.FastMath; /** This class implements a curve fitting specialized for sinusoids. @@ -102,7 +103,7 @@ public class HarmonicFitter { } /** Parametric harmonic function. */ - private static class ParametricHarmonicFunction implements ParametricRealFunction { + private static class ParametricHarmonicFunction implements ParametricUnivariateRealFunction { /** {@inheritDoc} */ public double value(double x, double[] parameters) { diff --git a/src/main/java/org/apache/commons/math/optimization/fitting/ParametricGaussianFunction.java b/src/main/java/org/apache/commons/math/optimization/fitting/ParametricGaussianFunction.java index 1dc9bae68..0b430359a 100644 --- a/src/main/java/org/apache/commons/math/optimization/fitting/ParametricGaussianFunction.java +++ b/src/main/java/org/apache/commons/math/optimization/fitting/ParametricGaussianFunction.java @@ -23,7 +23,7 @@ import org.apache.commons.math.exception.DimensionMismatchException; import org.apache.commons.math.exception.util.LocalizedFormats; import org.apache.commons.math.exception.ZeroException; import org.apache.commons.math.exception.NullArgumentException; -import org.apache.commons.math.optimization.fitting.ParametricRealFunction; +import org.apache.commons.math.analysis.ParametricUnivariateRealFunction; /** * A Gaussian function. Specifically: @@ -53,7 +53,7 @@ import org.apache.commons.math.optimization.fitting.ParametricRealFunction; * @since 2.2 * @version $Revision$ $Date$ */ -public class ParametricGaussianFunction implements ParametricRealFunction, Serializable { +public class ParametricGaussianFunction implements ParametricUnivariateRealFunction, Serializable { /** Serializable version Id. */ private static final long serialVersionUID = -3875578602503903233L; diff --git a/src/main/java/org/apache/commons/math/optimization/fitting/PolynomialFitter.java b/src/main/java/org/apache/commons/math/optimization/fitting/PolynomialFitter.java index 48ed93a92..5e4f6ca9a 100644 --- a/src/main/java/org/apache/commons/math/optimization/fitting/PolynomialFitter.java +++ b/src/main/java/org/apache/commons/math/optimization/fitting/PolynomialFitter.java @@ -18,6 +18,7 @@ package org.apache.commons.math.optimization.fitting; import org.apache.commons.math.analysis.polynomials.PolynomialFunction; +import org.apache.commons.math.analysis.ParametricUnivariateRealFunction; import org.apache.commons.math.optimization.DifferentiableMultivariateVectorialOptimizer; /** This class implements a curve fitting specialized for polynomials. @@ -80,7 +81,7 @@ public class PolynomialFitter { /** * Dedicated parametric polynomial class. */ - private static class ParametricPolynomial implements ParametricRealFunction { + private static class ParametricPolynomial implements ParametricUnivariateRealFunction { /** {@inheritDoc} */ public double[] gradient(double x, double[] parameters) { diff --git a/src/site/xdoc/changes.xml b/src/site/xdoc/changes.xml index 8f7af9139..f8e1e9435 100644 --- a/src/site/xdoc/changes.xml +++ b/src/site/xdoc/changes.xml @@ -52,6 +52,10 @@ The type attribute can be add,update,fix,remove. If the output is not quite correct, check for invisible trailing spaces! --> + + The interface "ParametricRealFunction" (in package "optimization.fitting") has + been renamed to "ParametricUnivariateRealFunction" and moved to package "analysis". + TestUtils is thread-hostile. Remove getters and setters, and make static variables final. diff --git a/src/test/java/org/apache/commons/math/optimization/fitting/CurveFitterTest.java b/src/test/java/org/apache/commons/math/optimization/fitting/CurveFitterTest.java index f94da301b..be74ad13e 100644 --- a/src/test/java/org/apache/commons/math/optimization/fitting/CurveFitterTest.java +++ b/src/test/java/org/apache/commons/math/optimization/fitting/CurveFitterTest.java @@ -19,6 +19,7 @@ package org.apache.commons.math.optimization.fitting; import org.apache.commons.math.exception.MathUserException; import org.apache.commons.math.optimization.general.LevenbergMarquardtOptimizer; +import org.apache.commons.math.analysis.ParametricUnivariateRealFunction; import org.apache.commons.math.util.FastMath; import org.junit.Assert; import org.junit.Test; @@ -36,7 +37,7 @@ public class CurveFitterTest { fitter.addObservedPoint(1.655d, 0.9474675497289684); fitter.addObservedPoint(1.725d, 0.9013594835804194d); - ParametricRealFunction sif = new SimpleInverseFunction(); + ParametricUnivariateRealFunction sif = new SimpleInverseFunction(); double[] initialguess1 = new double[1]; initialguess1[0] = 1.0d; @@ -60,7 +61,7 @@ public class CurveFitterTest { fitter.addObservedPoint(1.655d, 0.9474675497289684); fitter.addObservedPoint(1.725d, 0.9013594835804194d); - ParametricRealFunction sif = new SimpleInverseFunction(); + ParametricUnivariateRealFunction sif = new SimpleInverseFunction(); double[] initialguess1 = new double[1]; initialguess1[0] = 1.0d; @@ -85,7 +86,7 @@ public class CurveFitterTest { curveFitter.addObservedPoint(250, 45087); curveFitter.addObservedPoint(500, 50683); - ParametricRealFunction f = new ParametricRealFunction() { + ParametricUnivariateRealFunction f = new ParametricUnivariateRealFunction() { public double value(double x, double[] parameters) { @@ -136,7 +137,7 @@ public class CurveFitterTest { } - private static class SimpleInverseFunction implements ParametricRealFunction { + private static class SimpleInverseFunction implements ParametricUnivariateRealFunction { public double value(double x, double[] parameters) { return parameters[0] / x + (parameters.length < 2 ? 0 : parameters[1]);