commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t.@apache.org
Subject [12/18] [math] Remove deprecated optimization package.
Date Wed, 25 Feb 2015 21:49:40 GMT
http://git-wip-us.apache.org/repos/asf/commons-math/blob/b4669aad/src/main/java/org/apache/commons/math4/optimization/direct/NelderMeadSimplex.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/optimization/direct/NelderMeadSimplex.java b/src/main/java/org/apache/commons/math4/optimization/direct/NelderMeadSimplex.java
deleted file mode 100644
index f193ccf..0000000
--- a/src/main/java/org/apache/commons/math4/optimization/direct/NelderMeadSimplex.java
+++ /dev/null
@@ -1,283 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.math4.optimization.direct;
-
-import java.util.Comparator;
-
-import org.apache.commons.math4.analysis.MultivariateFunction;
-import org.apache.commons.math4.optimization.PointValuePair;
-
-/**
- * This class implements the Nelder-Mead simplex algorithm.
- *
- * @deprecated As of 3.1 (to be removed in 4.0).
- * @since 3.0
- */
-@Deprecated
-public class NelderMeadSimplex extends AbstractSimplex {
-    /** Default value for {@link #rho}: {@value}. */
-    private static final double DEFAULT_RHO = 1;
-    /** Default value for {@link #khi}: {@value}. */
-    private static final double DEFAULT_KHI = 2;
-    /** Default value for {@link #gamma}: {@value}. */
-    private static final double DEFAULT_GAMMA = 0.5;
-    /** Default value for {@link #sigma}: {@value}. */
-    private static final double DEFAULT_SIGMA = 0.5;
-    /** Reflection coefficient. */
-    private final double rho;
-    /** Expansion coefficient. */
-    private final double khi;
-    /** Contraction coefficient. */
-    private final double gamma;
-    /** Shrinkage coefficient. */
-    private final double sigma;
-
-    /**
-     * Build a Nelder-Mead simplex with default coefficients.
-     * The default coefficients are 1.0 for rho, 2.0 for khi and 0.5
-     * for both gamma and sigma.
-     *
-     * @param n Dimension of the simplex.
-     */
-    public NelderMeadSimplex(final int n) {
-        this(n, 1d);
-    }
-
-    /**
-     * Build a Nelder-Mead simplex with default coefficients.
-     * The default coefficients are 1.0 for rho, 2.0 for khi and 0.5
-     * for both gamma and sigma.
-     *
-     * @param n Dimension of the simplex.
-     * @param sideLength Length of the sides of the default (hypercube)
-     * simplex. See {@link AbstractSimplex#AbstractSimplex(int,double)}.
-     */
-    public NelderMeadSimplex(final int n, double sideLength) {
-        this(n, sideLength,
-             DEFAULT_RHO, DEFAULT_KHI, DEFAULT_GAMMA, DEFAULT_SIGMA);
-    }
-
-    /**
-     * Build a Nelder-Mead simplex with specified coefficients.
-     *
-     * @param n Dimension of the simplex. See
-     * {@link AbstractSimplex#AbstractSimplex(int,double)}.
-     * @param sideLength Length of the sides of the default (hypercube)
-     * simplex. See {@link AbstractSimplex#AbstractSimplex(int,double)}.
-     * @param rho Reflection coefficient.
-     * @param khi Expansion coefficient.
-     * @param gamma Contraction coefficient.
-     * @param sigma Shrinkage coefficient.
-     */
-    public NelderMeadSimplex(final int n, double sideLength,
-                             final double rho, final double khi,
-                             final double gamma, final double sigma) {
-        super(n, sideLength);
-
-        this.rho = rho;
-        this.khi = khi;
-        this.gamma = gamma;
-        this.sigma = sigma;
-    }
-
-    /**
-     * Build a Nelder-Mead simplex with specified coefficients.
-     *
-     * @param n Dimension of the simplex. See
-     * {@link AbstractSimplex#AbstractSimplex(int)}.
-     * @param rho Reflection coefficient.
-     * @param khi Expansion coefficient.
-     * @param gamma Contraction coefficient.
-     * @param sigma Shrinkage coefficient.
-     */
-    public NelderMeadSimplex(final int n,
-                             final double rho, final double khi,
-                             final double gamma, final double sigma) {
-        this(n, 1d, rho, khi, gamma, sigma);
-    }
-
-    /**
-     * Build a Nelder-Mead simplex with default coefficients.
-     * The default coefficients are 1.0 for rho, 2.0 for khi and 0.5
-     * for both gamma and sigma.
-     *
-     * @param steps Steps along the canonical axes representing box edges.
-     * They may be negative but not zero. See
-     */
-    public NelderMeadSimplex(final double[] steps) {
-        this(steps, DEFAULT_RHO, DEFAULT_KHI, DEFAULT_GAMMA, DEFAULT_SIGMA);
-    }
-
-    /**
-     * Build a Nelder-Mead simplex with specified coefficients.
-     *
-     * @param steps Steps along the canonical axes representing box edges.
-     * They may be negative but not zero. See
-     * {@link AbstractSimplex#AbstractSimplex(double[])}.
-     * @param rho Reflection coefficient.
-     * @param khi Expansion coefficient.
-     * @param gamma Contraction coefficient.
-     * @param sigma Shrinkage coefficient.
-     * @throws IllegalArgumentException if one of the steps is zero.
-     */
-    public NelderMeadSimplex(final double[] steps,
-                             final double rho, final double khi,
-                             final double gamma, final double sigma) {
-        super(steps);
-
-        this.rho = rho;
-        this.khi = khi;
-        this.gamma = gamma;
-        this.sigma = sigma;
-    }
-
-    /**
-     * Build a Nelder-Mead simplex with default coefficients.
-     * The default coefficients are 1.0 for rho, 2.0 for khi and 0.5
-     * for both gamma and sigma.
-     *
-     * @param referenceSimplex Reference simplex. See
-     * {@link AbstractSimplex#AbstractSimplex(double[][])}.
-     */
-    public NelderMeadSimplex(final double[][] referenceSimplex) {
-        this(referenceSimplex, DEFAULT_RHO, DEFAULT_KHI, DEFAULT_GAMMA, DEFAULT_SIGMA);
-    }
-
-    /**
-     * Build a Nelder-Mead simplex with specified coefficients.
-     *
-     * @param referenceSimplex Reference simplex. See
-     * {@link AbstractSimplex#AbstractSimplex(double[][])}.
-     * @param rho Reflection coefficient.
-     * @param khi Expansion coefficient.
-     * @param gamma Contraction coefficient.
-     * @param sigma Shrinkage coefficient.
-     * @throws org.apache.commons.math4.exception.NotStrictlyPositiveException
-     * if the reference simplex does not contain at least one point.
-     * @throws org.apache.commons.math4.exception.DimensionMismatchException
-     * if there is a dimension mismatch in the reference simplex.
-     */
-    public NelderMeadSimplex(final double[][] referenceSimplex,
-                             final double rho, final double khi,
-                             final double gamma, final double sigma) {
-        super(referenceSimplex);
-
-        this.rho = rho;
-        this.khi = khi;
-        this.gamma = gamma;
-        this.sigma = sigma;
-    }
-
-    /** {@inheritDoc} */
-    @Override
-    public void iterate(final MultivariateFunction evaluationFunction,
-                        final Comparator<PointValuePair> comparator) {
-        // The simplex has n + 1 points if dimension is n.
-        final int n = getDimension();
-
-        // Interesting values.
-        final PointValuePair best = getPoint(0);
-        final PointValuePair secondBest = getPoint(n - 1);
-        final PointValuePair worst = getPoint(n);
-        final double[] xWorst = worst.getPointRef();
-
-        // Compute the centroid of the best vertices (dismissing the worst
-        // point at index n).
-        final double[] centroid = new double[n];
-        for (int i = 0; i < n; i++) {
-            final double[] x = getPoint(i).getPointRef();
-            for (int j = 0; j < n; j++) {
-                centroid[j] += x[j];
-            }
-        }
-        final double scaling = 1.0 / n;
-        for (int j = 0; j < n; j++) {
-            centroid[j] *= scaling;
-        }
-
-        // compute the reflection point
-        final double[] xR = new double[n];
-        for (int j = 0; j < n; j++) {
-            xR[j] = centroid[j] + rho * (centroid[j] - xWorst[j]);
-        }
-        final PointValuePair reflected
-            = new PointValuePair(xR, evaluationFunction.value(xR), false);
-
-        if (comparator.compare(best, reflected) <= 0 &&
-            comparator.compare(reflected, secondBest) < 0) {
-            // Accept the reflected point.
-            replaceWorstPoint(reflected, comparator);
-        } else if (comparator.compare(reflected, best) < 0) {
-            // Compute the expansion point.
-            final double[] xE = new double[n];
-            for (int j = 0; j < n; j++) {
-                xE[j] = centroid[j] + khi * (xR[j] - centroid[j]);
-            }
-            final PointValuePair expanded
-                = new PointValuePair(xE, evaluationFunction.value(xE), false);
-
-            if (comparator.compare(expanded, reflected) < 0) {
-                // Accept the expansion point.
-                replaceWorstPoint(expanded, comparator);
-            } else {
-                // Accept the reflected point.
-                replaceWorstPoint(reflected, comparator);
-            }
-        } else {
-            if (comparator.compare(reflected, worst) < 0) {
-                // Perform an outside contraction.
-                final double[] xC = new double[n];
-                for (int j = 0; j < n; j++) {
-                    xC[j] = centroid[j] + gamma * (xR[j] - centroid[j]);
-                }
-                final PointValuePair outContracted
-                    = new PointValuePair(xC, evaluationFunction.value(xC), false);
-                if (comparator.compare(outContracted, reflected) <= 0) {
-                    // Accept the contraction point.
-                    replaceWorstPoint(outContracted, comparator);
-                    return;
-                }
-            } else {
-                // Perform an inside contraction.
-                final double[] xC = new double[n];
-                for (int j = 0; j < n; j++) {
-                    xC[j] = centroid[j] - gamma * (centroid[j] - xWorst[j]);
-                }
-                final PointValuePair inContracted
-                    = new PointValuePair(xC, evaluationFunction.value(xC), false);
-
-                if (comparator.compare(inContracted, worst) < 0) {
-                    // Accept the contraction point.
-                    replaceWorstPoint(inContracted, comparator);
-                    return;
-                }
-            }
-
-            // Perform a shrink.
-            final double[] xSmallest = getPoint(0).getPointRef();
-            for (int i = 1; i <= n; i++) {
-                final double[] x = getPoint(i).getPoint();
-                for (int j = 0; j < n; j++) {
-                    x[j] = xSmallest[j] + sigma * (x[j] - xSmallest[j]);
-                }
-                setPoint(i, new PointValuePair(x, Double.NaN, false));
-            }
-            evaluate(evaluationFunction, comparator);
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/commons-math/blob/b4669aad/src/main/java/org/apache/commons/math4/optimization/direct/PowellOptimizer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/optimization/direct/PowellOptimizer.java b/src/main/java/org/apache/commons/math4/optimization/direct/PowellOptimizer.java
deleted file mode 100644
index a0a396e..0000000
--- a/src/main/java/org/apache/commons/math4/optimization/direct/PowellOptimizer.java
+++ /dev/null
@@ -1,352 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.math4.optimization.direct;
-
-import org.apache.commons.math4.analysis.MultivariateFunction;
-import org.apache.commons.math4.analysis.UnivariateFunction;
-import org.apache.commons.math4.exception.NotStrictlyPositiveException;
-import org.apache.commons.math4.exception.NumberIsTooSmallException;
-import org.apache.commons.math4.optimization.ConvergenceChecker;
-import org.apache.commons.math4.optimization.GoalType;
-import org.apache.commons.math4.optimization.MultivariateOptimizer;
-import org.apache.commons.math4.optimization.PointValuePair;
-import org.apache.commons.math4.optimization.univariate.BracketFinder;
-import org.apache.commons.math4.optimization.univariate.BrentOptimizer;
-import org.apache.commons.math4.optimization.univariate.SimpleUnivariateValueChecker;
-import org.apache.commons.math4.optimization.univariate.UnivariatePointValuePair;
-import org.apache.commons.math4.util.FastMath;
-import org.apache.commons.math4.util.MathArrays;
-
-/**
- * Powell algorithm.
- * This code is translated and adapted from the Python version of this
- * algorithm (as implemented in module {@code optimize.py} v0.5 of
- * <em>SciPy</em>).
- * <br/>
- * The default stopping criterion is based on the differences of the
- * function value between two successive iterations. It is however possible
- * to define a custom convergence checker that might terminate the algorithm
- * earlier.
- * <br/>
- * The internal line search optimizer is a {@link BrentOptimizer} with a
- * convergence checker set to {@link SimpleUnivariateValueChecker}.
- *
- * @deprecated As of 3.1 (to be removed in 4.0).
- * @since 2.2
- */
-@Deprecated
-public class PowellOptimizer
-    extends BaseAbstractMultivariateOptimizer<MultivariateFunction>
-    implements MultivariateOptimizer {
-    /**
-     * Minimum relative tolerance.
-     */
-    private static final double MIN_RELATIVE_TOLERANCE = 2 * FastMath.ulp(1d);
-    /**
-     * Relative threshold.
-     */
-    private final double relativeThreshold;
-    /**
-     * Absolute threshold.
-     */
-    private final double absoluteThreshold;
-    /**
-     * Line search.
-     */
-    private final LineSearch line;
-
-    /**
-     * This constructor allows to specify a user-defined convergence checker,
-     * in addition to the parameters that control the default convergence
-     * checking procedure.
-     * <br/>
-     * The internal line search tolerances are set to the square-root of their
-     * corresponding value in the multivariate optimizer.
-     *
-     * @param rel Relative threshold.
-     * @param abs Absolute threshold.
-     * @param checker Convergence checker.
-     * @throws NotStrictlyPositiveException if {@code abs <= 0}.
-     * @throws NumberIsTooSmallException if {@code rel < 2 * Math.ulp(1d)}.
-     */
-    public PowellOptimizer(double rel,
-                           double abs,
-                           ConvergenceChecker<PointValuePair> checker) {
-        this(rel, abs, FastMath.sqrt(rel), FastMath.sqrt(abs), checker);
-    }
-
-    /**
-     * This constructor allows to specify a user-defined convergence checker,
-     * in addition to the parameters that control the default convergence
-     * checking procedure and the line search tolerances.
-     *
-     * @param rel Relative threshold for this optimizer.
-     * @param abs Absolute threshold for this optimizer.
-     * @param lineRel Relative threshold for the internal line search optimizer.
-     * @param lineAbs Absolute threshold for the internal line search optimizer.
-     * @param checker Convergence checker.
-     * @throws NotStrictlyPositiveException if {@code abs <= 0}.
-     * @throws NumberIsTooSmallException if {@code rel < 2 * Math.ulp(1d)}.
-     */
-    public PowellOptimizer(double rel,
-                           double abs,
-                           double lineRel,
-                           double lineAbs,
-                           ConvergenceChecker<PointValuePair> checker) {
-        super(checker);
-
-        if (rel < MIN_RELATIVE_TOLERANCE) {
-            throw new NumberIsTooSmallException(rel, MIN_RELATIVE_TOLERANCE, true);
-        }
-        if (abs <= 0) {
-            throw new NotStrictlyPositiveException(abs);
-        }
-        relativeThreshold = rel;
-        absoluteThreshold = abs;
-
-        // Create the line search optimizer.
-        line = new LineSearch(lineRel,
-                              lineAbs);
-    }
-
-    /**
-     * The parameters control the default convergence checking procedure.
-     * <br/>
-     * The internal line search tolerances are set to the square-root of their
-     * corresponding value in the multivariate optimizer.
-     *
-     * @param rel Relative threshold.
-     * @param abs Absolute threshold.
-     * @throws NotStrictlyPositiveException if {@code abs <= 0}.
-     * @throws NumberIsTooSmallException if {@code rel < 2 * Math.ulp(1d)}.
-     */
-    public PowellOptimizer(double rel,
-                           double abs) {
-        this(rel, abs, null);
-    }
-
-    /**
-     * Builds an instance with the default convergence checking procedure.
-     *
-     * @param rel Relative threshold.
-     * @param abs Absolute threshold.
-     * @param lineRel Relative threshold for the internal line search optimizer.
-     * @param lineAbs Absolute threshold for the internal line search optimizer.
-     * @throws NotStrictlyPositiveException if {@code abs <= 0}.
-     * @throws NumberIsTooSmallException if {@code rel < 2 * Math.ulp(1d)}.
-     * @since 3.1
-     */
-    public PowellOptimizer(double rel,
-                           double abs,
-                           double lineRel,
-                           double lineAbs) {
-        this(rel, abs, lineRel, lineAbs, null);
-    }
-
-    /** {@inheritDoc} */
-    @Override
-    protected PointValuePair doOptimize() {
-        final GoalType goal = getGoalType();
-        final double[] guess = getStartPoint();
-        final int n = guess.length;
-
-        final double[][] direc = new double[n][n];
-        for (int i = 0; i < n; i++) {
-            direc[i][i] = 1;
-        }
-
-        final ConvergenceChecker<PointValuePair> checker
-            = getConvergenceChecker();
-
-        double[] x = guess;
-        double fVal = computeObjectiveValue(x);
-        double[] x1 = x.clone();
-        int iter = 0;
-        while (true) {
-            ++iter;
-
-            double fX = fVal;
-            double fX2 = 0;
-            double delta = 0;
-            int bigInd = 0;
-            double alphaMin = 0;
-
-            for (int i = 0; i < n; i++) {
-                final double[] d = MathArrays.copyOf(direc[i]);
-
-                fX2 = fVal;
-
-                final UnivariatePointValuePair optimum = line.search(x, d);
-                fVal = optimum.getValue();
-                alphaMin = optimum.getPoint();
-                final double[][] result = newPointAndDirection(x, d, alphaMin);
-                x = result[0];
-
-                if ((fX2 - fVal) > delta) {
-                    delta = fX2 - fVal;
-                    bigInd = i;
-                }
-            }
-
-            // Default convergence check.
-            boolean stop = 2 * (fX - fVal) <=
-                (relativeThreshold * (FastMath.abs(fX) + FastMath.abs(fVal)) +
-                 absoluteThreshold);
-
-            final PointValuePair previous = new PointValuePair(x1, fX);
-            final PointValuePair current = new PointValuePair(x, fVal);
-            if (!stop && checker != null) {
-                stop = checker.converged(iter, previous, current);
-            }
-            if (stop) {
-                if (goal == GoalType.MINIMIZE) {
-                    return (fVal < fX) ? current : previous;
-                } else {
-                    return (fVal > fX) ? current : previous;
-                }
-            }
-
-            final double[] d = new double[n];
-            final double[] x2 = new double[n];
-            for (int i = 0; i < n; i++) {
-                d[i] = x[i] - x1[i];
-                x2[i] = 2 * x[i] - x1[i];
-            }
-
-            x1 = x.clone();
-            fX2 = computeObjectiveValue(x2);
-
-            if (fX > fX2) {
-                double t = 2 * (fX + fX2 - 2 * fVal);
-                double temp = fX - fVal - delta;
-                t *= temp * temp;
-                temp = fX - fX2;
-                t -= delta * temp * temp;
-
-                if (t < 0.0) {
-                    final UnivariatePointValuePair optimum = line.search(x, d);
-                    fVal = optimum.getValue();
-                    alphaMin = optimum.getPoint();
-                    final double[][] result = newPointAndDirection(x, d, alphaMin);
-                    x = result[0];
-
-                    final int lastInd = n - 1;
-                    direc[bigInd] = direc[lastInd];
-                    direc[lastInd] = result[1];
-                }
-            }
-        }
-    }
-
-    /**
-     * Compute a new point (in the original space) and a new direction
-     * vector, resulting from the line search.
-     *
-     * @param p Point used in the line search.
-     * @param d Direction used in the line search.
-     * @param optimum Optimum found by the line search.
-     * @return a 2-element array containing the new point (at index 0) and
-     * the new direction (at index 1).
-     */
-    private double[][] newPointAndDirection(double[] p,
-                                            double[] d,
-                                            double optimum) {
-        final int n = p.length;
-        final double[] nP = new double[n];
-        final double[] nD = new double[n];
-        for (int i = 0; i < n; i++) {
-            nD[i] = d[i] * optimum;
-            nP[i] = p[i] + nD[i];
-        }
-
-        final double[][] result = new double[2][];
-        result[0] = nP;
-        result[1] = nD;
-
-        return result;
-    }
-
-    /**
-     * Class for finding the minimum of the objective function along a given
-     * direction.
-     */
-    private class LineSearch extends BrentOptimizer {
-        /**
-         * Value that will pass the precondition check for {@link BrentOptimizer}
-         * but will not pass the convergence check, so that the custom checker
-         * will always decide when to stop the line search.
-         */
-        private static final double REL_TOL_UNUSED = 1e-15;
-        /**
-         * Value that will pass the precondition check for {@link BrentOptimizer}
-         * but will not pass the convergence check, so that the custom checker
-         * will always decide when to stop the line search.
-         */
-        private static final double ABS_TOL_UNUSED = Double.MIN_VALUE;
-        /**
-         * Automatic bracketing.
-         */
-        private final BracketFinder bracket = new BracketFinder();
-
-        /**
-         * The "BrentOptimizer" default stopping criterion uses the tolerances
-         * to check the domain (point) values, not the function values.
-         * We thus create a custom checker to use function values.
-         *
-         * @param rel Relative threshold.
-         * @param abs Absolute threshold.
-         */
-        LineSearch(double rel,
-                   double abs) {
-            super(REL_TOL_UNUSED,
-                  ABS_TOL_UNUSED,
-                  new SimpleUnivariateValueChecker(rel, abs));
-        }
-
-        /**
-         * Find the minimum of the function {@code f(p + alpha * d)}.
-         *
-         * @param p Starting point.
-         * @param d Search direction.
-         * @return the optimum.
-         * @throws org.apache.commons.math4.exception.TooManyEvaluationsException
-         * if the number of evaluations is exceeded.
-         */
-        public UnivariatePointValuePair search(final double[] p, final double[] d) {
-            final int n = p.length;
-            final UnivariateFunction f = new UnivariateFunction() {
-                    public double value(double alpha) {
-                        final double[] x = new double[n];
-                        for (int i = 0; i < n; i++) {
-                            x[i] = p[i] + alpha * d[i];
-                        }
-                        final double obj = PowellOptimizer.this.computeObjectiveValue(x);
-                        return obj;
-                    }
-                };
-
-            final GoalType goal = PowellOptimizer.this.getGoalType();
-            bracket.search(f, goal, 0, 1);
-            // Passing "MAX_VALUE" as a dummy value because it is the enclosing
-            // class that counts the number of evaluations (and will eventually
-            // generate the exception).
-            return optimize(Integer.MAX_VALUE, f, goal,
-                            bracket.getLo(), bracket.getHi(), bracket.getMid());
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/commons-math/blob/b4669aad/src/main/java/org/apache/commons/math4/optimization/direct/SimplexOptimizer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/optimization/direct/SimplexOptimizer.java b/src/main/java/org/apache/commons/math4/optimization/direct/SimplexOptimizer.java
deleted file mode 100644
index 0adcdb3..0000000
--- a/src/main/java/org/apache/commons/math4/optimization/direct/SimplexOptimizer.java
+++ /dev/null
@@ -1,233 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.math4.optimization.direct;
-
-import java.util.Comparator;
-
-import org.apache.commons.math4.analysis.MultivariateFunction;
-import org.apache.commons.math4.exception.NullArgumentException;
-import org.apache.commons.math4.optimization.ConvergenceChecker;
-import org.apache.commons.math4.optimization.GoalType;
-import org.apache.commons.math4.optimization.MultivariateOptimizer;
-import org.apache.commons.math4.optimization.OptimizationData;
-import org.apache.commons.math4.optimization.PointValuePair;
-import org.apache.commons.math4.optimization.SimpleValueChecker;
-
-/**
- * This class implements simplex-based direct search optimization.
- *
- * <p>
- *  Direct search methods only use objective function values, they do
- *  not need derivatives and don't either try to compute approximation
- *  of the derivatives. According to a 1996 paper by Margaret H. Wright
- *  (<a href="http://cm.bell-labs.com/cm/cs/doc/96/4-02.ps.gz">Direct
- *  Search Methods: Once Scorned, Now Respectable</a>), they are used
- *  when either the computation of the derivative is impossible (noisy
- *  functions, unpredictable discontinuities) or difficult (complexity,
- *  computation cost). In the first cases, rather than an optimum, a
- *  <em>not too bad</em> point is desired. In the latter cases, an
- *  optimum is desired but cannot be reasonably found. In all cases
- *  direct search methods can be useful.
- * </p>
- * <p>
- *  Simplex-based direct search methods are based on comparison of
- *  the objective function values at the vertices of a simplex (which is a
- *  set of n+1 points in dimension n) that is updated by the algorithms
- *  steps.
- * <p>
- * <p>
- *  The {@link #setSimplex(AbstractSimplex) setSimplex} method <em>must</em>
- *  be called prior to calling the {@code optimize} method.
- * </p>
- * <p>
- *  Each call to {@link #optimize(int,MultivariateFunction,GoalType,double[])
- *  optimize} will re-use the start configuration of the current simplex and
- *  move it such that its first vertex is at the provided start point of the
- *  optimization. If the {@code optimize} method is called to solve a different
- *  problem and the number of parameters change, the simplex must be
- *  re-initialized to one with the appropriate dimensions.
- * </p>
- * <p>
- *  Convergence is checked by providing the <em>worst</em> points of
- *  previous and current simplex to the convergence checker, not the best
- *  ones.
- * </p>
- * <p>
- * This simplex optimizer implementation does not directly support constrained
- * optimization with simple bounds, so for such optimizations, either a more
- * dedicated method must be used like {@link CMAESOptimizer} or {@link
- * BOBYQAOptimizer}, or the optimized method must be wrapped in an adapter like
- * {@link MultivariateFunctionMappingAdapter} or {@link
- * MultivariateFunctionPenaltyAdapter}.
- * </p>
- *
- * @see AbstractSimplex
- * @see MultivariateFunctionMappingAdapter
- * @see MultivariateFunctionPenaltyAdapter
- * @see CMAESOptimizer
- * @see BOBYQAOptimizer
- * @deprecated As of 3.1 (to be removed in 4.0).
- * @since 3.0
- */
-@SuppressWarnings("boxing") // deprecated anyway
-@Deprecated
-public class SimplexOptimizer
-    extends BaseAbstractMultivariateOptimizer<MultivariateFunction>
-    implements MultivariateOptimizer {
-    /** Simplex. */
-    private AbstractSimplex simplex;
-
-    /**
-     * Constructor using a default {@link SimpleValueChecker convergence
-     * checker}.
-     * @deprecated See {@link SimpleValueChecker#SimpleValueChecker()}
-     */
-    @Deprecated
-    public SimplexOptimizer() {
-        this(new SimpleValueChecker());
-    }
-
-    /**
-     * @param checker Convergence checker.
-     */
-    public SimplexOptimizer(ConvergenceChecker<PointValuePair> checker) {
-        super(checker);
-    }
-
-    /**
-     * @param rel Relative threshold.
-     * @param abs Absolute threshold.
-     */
-    public SimplexOptimizer(double rel, double abs) {
-        this(new SimpleValueChecker(rel, abs));
-    }
-
-    /**
-     * Set the simplex algorithm.
-     *
-     * @param simplex Simplex.
-     * @deprecated As of 3.1. The initial simplex can now be passed as an
-     * argument of the {@link #optimize(int,MultivariateFunction,GoalType,OptimizationData[])}
-     * method.
-     */
-    @Deprecated
-    public void setSimplex(AbstractSimplex simplex) {
-        parseOptimizationData(simplex);
-    }
-
-    /**
-     * Optimize an objective function.
-     *
-     * @param maxEval Allowed number of evaluations of the objective function.
-     * @param f Objective function.
-     * @param goalType Optimization type.
-     * @param optData Optimization data. The following data will be looked for:
-     * <ul>
-     *  <li>{@link org.apache.commons.math4.optimization.InitialGuess InitialGuess}</li>
-     *  <li>{@link AbstractSimplex}</li>
-     * </ul>
-     * @return the point/value pair giving the optimal value for objective
-     * function.
-     */
-    @Override
-    protected PointValuePair optimizeInternal(int maxEval, MultivariateFunction f,
-                                              GoalType goalType,
-                                              OptimizationData... optData) {
-        // Scan "optData" for the input specific to this optimizer.
-        parseOptimizationData(optData);
-
-        // The parent's method will retrieve the common parameters from
-        // "optData" and call "doOptimize".
-        return super.optimizeInternal(maxEval, f, goalType, optData);
-    }
-
-    /**
-     * Scans the list of (required and optional) optimization data that
-     * characterize the problem.
-     *
-     * @param optData Optimization data. The following data will be looked for:
-     * <ul>
-     *  <li>{@link AbstractSimplex}</li>
-     * </ul>
-     */
-    private void parseOptimizationData(OptimizationData... optData) {
-        // The existing values (as set by the previous call) are reused if
-        // not provided in the argument list.
-        for (OptimizationData data : optData) {
-            if (data instanceof AbstractSimplex) {
-                simplex = (AbstractSimplex) data;
-                continue;
-            }
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override
-    protected PointValuePair doOptimize() {
-        if (simplex == null) {
-            throw new NullArgumentException();
-        }
-
-        // Indirect call to "computeObjectiveValue" in order to update the
-        // evaluations counter.
-        final MultivariateFunction evalFunc
-            = new MultivariateFunction() {
-                public double value(double[] point) {
-                    return computeObjectiveValue(point);
-                }
-            };
-
-        final boolean isMinim = getGoalType() == GoalType.MINIMIZE;
-        final Comparator<PointValuePair> comparator
-            = new Comparator<PointValuePair>() {
-            public int compare(final PointValuePair o1,
-                               final PointValuePair o2) {
-                final double v1 = o1.getValue();
-                final double v2 = o2.getValue();
-                return isMinim ? Double.compare(v1, v2) : Double.compare(v2, v1);
-            }
-        };
-
-        // Initialize search.
-        simplex.build(getStartPoint());
-        simplex.evaluate(evalFunc, comparator);
-
-        PointValuePair[] previous = null;
-        int iteration = 0;
-        final ConvergenceChecker<PointValuePair> checker = getConvergenceChecker();
-        while (true) {
-            if (iteration > 0) {
-                boolean converged = true;
-                for (int i = 0; i < simplex.getSize(); i++) {
-                    PointValuePair prev = previous[i];
-                    converged = converged &&
-                        checker.converged(iteration, prev, simplex.getPoint(i));
-                }
-                if (converged) {
-                    // We have found an optimum.
-                    return simplex.getPoint(0);
-                }
-            }
-
-            // We still need to search.
-            previous = simplex.getPoints();
-            simplex.iterate(evalFunc, comparator);
-            ++iteration;
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/commons-math/blob/b4669aad/src/main/java/org/apache/commons/math4/optimization/direct/package-info.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/optimization/direct/package-info.java b/src/main/java/org/apache/commons/math4/optimization/direct/package-info.java
deleted file mode 100644
index 57b385d..0000000
--- a/src/main/java/org/apache/commons/math4/optimization/direct/package-info.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/**
- *
- * <p>
- * This package provides optimization algorithms that don't require derivatives.
- * </p>
- *
- */
-package org.apache.commons.math4.optimization.direct;

http://git-wip-us.apache.org/repos/asf/commons-math/blob/b4669aad/src/main/java/org/apache/commons/math4/optimization/fitting/CurveFitter.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/optimization/fitting/CurveFitter.java b/src/main/java/org/apache/commons/math4/optimization/fitting/CurveFitter.java
deleted file mode 100644
index 7b3a429..0000000
--- a/src/main/java/org/apache/commons/math4/optimization/fitting/CurveFitter.java
+++ /dev/null
@@ -1,298 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.math4.optimization.fitting;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.commons.math4.analysis.DifferentiableMultivariateVectorFunction;
-import org.apache.commons.math4.analysis.MultivariateMatrixFunction;
-import org.apache.commons.math4.analysis.ParametricUnivariateFunction;
-import org.apache.commons.math4.analysis.differentiation.DerivativeStructure;
-import org.apache.commons.math4.analysis.differentiation.MultivariateDifferentiableVectorFunction;
-import org.apache.commons.math4.optimization.DifferentiableMultivariateVectorOptimizer;
-import org.apache.commons.math4.optimization.MultivariateDifferentiableVectorOptimizer;
-import org.apache.commons.math4.optimization.PointVectorValuePair;
-
-/** Fitter for parametric univariate real functions y = f(x).
- * <br/>
- * When a univariate real function y = f(x) does depend on some
- * unknown parameters p<sub>0</sub>, p<sub>1</sub> ... p<sub>n-1</sub>,
- * this class can be used to find these parameters. It does this
- * by <em>fitting</em> the curve so it remains very close to a set of
- * observed points (x<sub>0</sub>, y<sub>0</sub>), (x<sub>1</sub>,
- * y<sub>1</sub>) ... (x<sub>k-1</sub>, y<sub>k-1</sub>). This fitting
- * is done by finding the parameters values that minimizes the objective
- * function &sum;(y<sub>i</sub>-f(x<sub>i</sub>))<sup>2</sup>. This is
- * really a least squares problem.
- *
- * @param <T> Function to use for the fit.
- *
- * @deprecated As of 3.1 (to be removed in 4.0).
- * @since 2.0
- */
-@Deprecated
-public class CurveFitter<T extends ParametricUnivariateFunction> {
-
-    /** Optimizer to use for the fitting.
-     * @deprecated as of 3.1 replaced by {@link #optimizer}
-     */
-    @Deprecated
-    private final DifferentiableMultivariateVectorOptimizer oldOptimizer;
-
-    /** Optimizer to use for the fitting. */
-    private final MultivariateDifferentiableVectorOptimizer optimizer;
-
-    /** Observed points. */
-    private final List<WeightedObservedPoint> observations;
-
-    /** Simple constructor.
-     * @param optimizer optimizer to use for the fitting
-     * @deprecated as of 3.1 replaced by {@link #CurveFitter(MultivariateDifferentiableVectorOptimizer)}
-     */
-    @Deprecated
-    public CurveFitter(final DifferentiableMultivariateVectorOptimizer optimizer) {
-        this.oldOptimizer = optimizer;
-        this.optimizer    = null;
-        observations      = new ArrayList<WeightedObservedPoint>();
-    }
-
-    /** Simple constructor.
-     * @param optimizer optimizer to use for the fitting
-     * @since 3.1
-     */
-    public CurveFitter(final MultivariateDifferentiableVectorOptimizer optimizer) {
-        this.oldOptimizer = null;
-        this.optimizer    = optimizer;
-        observations      = new ArrayList<WeightedObservedPoint>();
-    }
-
-    /** Add an observed (x,y) point to the sample with unit weight.
-     * <p>Calling this method is equivalent to call
-     * {@code addObservedPoint(1.0, x, y)}.</p>
-     * @param x abscissa of the point
-     * @param y observed value of the point at x, after fitting we should
-     * have f(x) as close as possible to this value
-     * @see #addObservedPoint(double, double, double)
-     * @see #addObservedPoint(WeightedObservedPoint)
-     * @see #getObservations()
-     */
-    public void addObservedPoint(double x, double y) {
-        addObservedPoint(1.0, x, y);
-    }
-
-    /** Add an observed weighted (x,y) point to the sample.
-     * @param weight weight of the observed point in the fit
-     * @param x abscissa of the point
-     * @param y observed value of the point at x, after fitting we should
-     * have f(x) as close as possible to this value
-     * @see #addObservedPoint(double, double)
-     * @see #addObservedPoint(WeightedObservedPoint)
-     * @see #getObservations()
-     */
-    public void addObservedPoint(double weight, double x, double y) {
-        observations.add(new WeightedObservedPoint(weight, x, y));
-    }
-
-    /** Add an observed weighted (x,y) point to the sample.
-     * @param observed observed point to add
-     * @see #addObservedPoint(double, double)
-     * @see #addObservedPoint(double, double, double)
-     * @see #getObservations()
-     */
-    public void addObservedPoint(WeightedObservedPoint observed) {
-        observations.add(observed);
-    }
-
-    /** Get the observed points.
-     * @return observed points
-     * @see #addObservedPoint(double, double)
-     * @see #addObservedPoint(double, double, double)
-     * @see #addObservedPoint(WeightedObservedPoint)
-     */
-    public WeightedObservedPoint[] getObservations() {
-        return observations.toArray(new WeightedObservedPoint[observations.size()]);
-    }
-
-    /**
-     * Remove all observations.
-     */
-    public void clearObservations() {
-        observations.clear();
-    }
-
-    /**
-     * Fit a curve.
-     * This method compute the coefficients of the curve that best
-     * fit the sample of observed points previously given through calls
-     * to the {@link #addObservedPoint(WeightedObservedPoint)
-     * addObservedPoint} method.
-     *
-     * @param f parametric function to fit.
-     * @param initialGuess first guess of the function parameters.
-     * @return the fitted parameters.
-     * @throws org.apache.commons.math4.exception.DimensionMismatchException
-     * if the start point dimension is wrong.
-     */
-    public double[] fit(T f, final double[] initialGuess) {
-        return fit(Integer.MAX_VALUE, f, initialGuess);
-    }
-
-    /**
-     * Fit a curve.
-     * This method compute the coefficients of the curve that best
-     * fit the sample of observed points previously given through calls
-     * to the {@link #addObservedPoint(WeightedObservedPoint)
-     * addObservedPoint} method.
-     *
-     * @param f parametric function to fit.
-     * @param initialGuess first guess of the function parameters.
-     * @param maxEval Maximum number of function evaluations.
-     * @return the fitted parameters.
-     * @throws org.apache.commons.math4.exception.TooManyEvaluationsException
-     * if the number of allowed evaluations is exceeded.
-     * @throws org.apache.commons.math4.exception.DimensionMismatchException
-     * if the start point dimension is wrong.
-     * @since 3.0
-     */
-    public double[] fit(int maxEval, T f,
-                        final double[] initialGuess) {
-        // prepare least squares problem
-        double[] target  = new double[observations.size()];
-        double[] weights = new double[observations.size()];
-        int i = 0;
-        for (WeightedObservedPoint point : observations) {
-            target[i]  = point.getY();
-            weights[i] = point.getWeight();
-            ++i;
-        }
-
-        // perform the fit
-        final PointVectorValuePair optimum;
-        if (optimizer == null) {
-            // to be removed in 4.0
-            optimum = oldOptimizer.optimize(maxEval, new OldTheoreticalValuesFunction(f),
-                                            target, weights, initialGuess);
-        } else {
-            optimum = optimizer.optimize(maxEval, new TheoreticalValuesFunction(f),
-                                         target, weights, initialGuess);
-        }
-
-        // extract the coefficients
-        return optimum.getPointRef();
-    }
-
-    /** Vectorial function computing function theoretical values. */
-    @Deprecated
-    private class OldTheoreticalValuesFunction
-        implements DifferentiableMultivariateVectorFunction {
-        /** Function to fit. */
-        private final ParametricUnivariateFunction f;
-
-        /** Simple constructor.
-         * @param f function to fit.
-         */
-        public OldTheoreticalValuesFunction(final ParametricUnivariateFunction f) {
-            this.f = f;
-        }
-
-        /** {@inheritDoc} */
-        public MultivariateMatrixFunction jacobian() {
-            return new MultivariateMatrixFunction() {
-                public double[][] value(double[] point) {
-                    final double[][] jacobian = new double[observations.size()][];
-
-                    int i = 0;
-                    for (WeightedObservedPoint observed : observations) {
-                        jacobian[i++] = f.gradient(observed.getX(), point);
-                    }
-
-                    return jacobian;
-                }
-            };
-        }
-
-        /** {@inheritDoc} */
-        public double[] value(double[] point) {
-            // compute the residuals
-            final double[] values = new double[observations.size()];
-            int i = 0;
-            for (WeightedObservedPoint observed : observations) {
-                values[i++] = f.value(observed.getX(), point);
-            }
-
-            return values;
-        }
-    }
-
-    /** Vectorial function computing function theoretical values. */
-    private class TheoreticalValuesFunction implements MultivariateDifferentiableVectorFunction {
-
-        /** Function to fit. */
-        private final ParametricUnivariateFunction f;
-
-        /** Simple constructor.
-         * @param f function to fit.
-         */
-        public TheoreticalValuesFunction(final ParametricUnivariateFunction f) {
-            this.f = f;
-        }
-
-        /** {@inheritDoc} */
-        public double[] value(double[] point) {
-            // compute the residuals
-            final double[] values = new double[observations.size()];
-            int i = 0;
-            for (WeightedObservedPoint observed : observations) {
-                values[i++] = f.value(observed.getX(), point);
-            }
-
-            return values;
-        }
-
-        /** {@inheritDoc} */
-        public DerivativeStructure[] value(DerivativeStructure[] point) {
-
-            // extract parameters
-            final double[] parameters = new double[point.length];
-            for (int k = 0; k < point.length; ++k) {
-                parameters[k] = point[k].getValue();
-            }
-
-            // compute the residuals
-            final DerivativeStructure[] values = new DerivativeStructure[observations.size()];
-            int i = 0;
-            for (WeightedObservedPoint observed : observations) {
-
-                // build the DerivativeStructure by adding first the value as a constant
-                // and then adding derivatives
-                DerivativeStructure vi = new DerivativeStructure(point.length, 1, f.value(observed.getX(), parameters));
-                for (int k = 0; k < point.length; ++k) {
-                    vi = vi.add(new DerivativeStructure(point.length, 1, k, 0.0));
-                }
-
-                values[i++] = vi;
-
-            }
-
-            return values;
-        }
-
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/commons-math/blob/b4669aad/src/main/java/org/apache/commons/math4/optimization/fitting/GaussianFitter.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/optimization/fitting/GaussianFitter.java b/src/main/java/org/apache/commons/math4/optimization/fitting/GaussianFitter.java
deleted file mode 100644
index bf0f03d..0000000
--- a/src/main/java/org/apache/commons/math4/optimization/fitting/GaussianFitter.java
+++ /dev/null
@@ -1,365 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.math4.optimization.fitting;
-
-import java.util.Arrays;
-import java.util.Comparator;
-
-import org.apache.commons.math4.analysis.function.Gaussian;
-import org.apache.commons.math4.exception.NotStrictlyPositiveException;
-import org.apache.commons.math4.exception.NullArgumentException;
-import org.apache.commons.math4.exception.NumberIsTooSmallException;
-import org.apache.commons.math4.exception.OutOfRangeException;
-import org.apache.commons.math4.exception.ZeroException;
-import org.apache.commons.math4.exception.util.LocalizedFormats;
-import org.apache.commons.math4.optimization.DifferentiableMultivariateVectorOptimizer;
-import org.apache.commons.math4.util.FastMath;
-
-/**
- * Fits points to a {@link
- * org.apache.commons.math4.analysis.function.Gaussian.Parametric Gaussian} function.
- * <p>
- * Usage example:
- * <pre>
- *   GaussianFitter fitter = new GaussianFitter(
- *     new LevenbergMarquardtOptimizer());
- *   fitter.addObservedPoint(4.0254623,  531026.0);
- *   fitter.addObservedPoint(4.03128248, 984167.0);
- *   fitter.addObservedPoint(4.03839603, 1887233.0);
- *   fitter.addObservedPoint(4.04421621, 2687152.0);
- *   fitter.addObservedPoint(4.05132976, 3461228.0);
- *   fitter.addObservedPoint(4.05326982, 3580526.0);
- *   fitter.addObservedPoint(4.05779662, 3439750.0);
- *   fitter.addObservedPoint(4.0636168,  2877648.0);
- *   fitter.addObservedPoint(4.06943698, 2175960.0);
- *   fitter.addObservedPoint(4.07525716, 1447024.0);
- *   fitter.addObservedPoint(4.08237071, 717104.0);
- *   fitter.addObservedPoint(4.08366408, 620014.0);
- *   double[] parameters = fitter.fit();
- * </pre>
- *
- * @since 2.2
- * @deprecated As of 3.1 (to be removed in 4.0).
- */
-@Deprecated
-public class GaussianFitter extends CurveFitter<Gaussian.Parametric> {
-    /**
-     * Constructs an instance using the specified optimizer.
-     *
-     * @param optimizer Optimizer to use for the fitting.
-     */
-    public GaussianFitter(DifferentiableMultivariateVectorOptimizer optimizer) {
-        super(optimizer);
-    }
-
-    /**
-     * Fits a Gaussian function to the observed points.
-     *
-     * @param initialGuess First guess values in the following order:
-     * <ul>
-     *  <li>Norm</li>
-     *  <li>Mean</li>
-     *  <li>Sigma</li>
-     * </ul>
-     * @return the parameters of the Gaussian function that best fits the
-     * observed points (in the same order as above).
-     * @since 3.0
-     */
-    public double[] fit(double[] initialGuess) {
-        final Gaussian.Parametric f = new Gaussian.Parametric() {
-                @Override
-                public double value(double x, double ... p) {
-                    double v = Double.POSITIVE_INFINITY;
-                    try {
-                        v = super.value(x, p);
-                    } catch (NotStrictlyPositiveException e) { // NOPMD
-                        // Do nothing.
-                    }
-                    return v;
-                }
-
-                @Override
-                public double[] gradient(double x, double ... p) {
-                    double[] v = { Double.POSITIVE_INFINITY,
-                                   Double.POSITIVE_INFINITY,
-                                   Double.POSITIVE_INFINITY };
-                    try {
-                        v = super.gradient(x, p);
-                    } catch (NotStrictlyPositiveException e) { // NOPMD
-                        // Do nothing.
-                    }
-                    return v;
-                }
-            };
-
-        return fit(f, initialGuess);
-    }
-
-    /**
-     * Fits a Gaussian function to the observed points.
-     *
-     * @return the parameters of the Gaussian function that best fits the
-     * observed points (in the same order as above).
-     */
-    public double[] fit() {
-        final double[] guess = (new ParameterGuesser(getObservations())).guess();
-        return fit(guess);
-    }
-
-    /**
-     * Guesses the parameters {@code norm}, {@code mean}, and {@code sigma}
-     * of a {@link org.apache.commons.math4.analysis.function.Gaussian.Parametric}
-     * based on the specified observed points.
-     */
-    public static class ParameterGuesser {
-        /** Normalization factor. */
-        private final double norm;
-        /** Mean. */
-        private final double mean;
-        /** Standard deviation. */
-        private final double sigma;
-
-        /**
-         * Constructs instance with the specified observed points.
-         *
-         * @param observations Observed points from which to guess the
-         * parameters of the Gaussian.
-         * @throws NullArgumentException if {@code observations} is
-         * {@code null}.
-         * @throws NumberIsTooSmallException if there are less than 3
-         * observations.
-         */
-        public ParameterGuesser(WeightedObservedPoint[] observations) {
-            if (observations == null) {
-                throw new NullArgumentException(LocalizedFormats.INPUT_ARRAY);
-            }
-            if (observations.length < 3) {
-                throw new NumberIsTooSmallException(observations.length, 3, true);
-            }
-
-            final WeightedObservedPoint[] sorted = sortObservations(observations);
-            final double[] params = basicGuess(sorted);
-
-            norm = params[0];
-            mean = params[1];
-            sigma = params[2];
-        }
-
-        /**
-         * Gets an estimation of the parameters.
-         *
-         * @return the guessed parameters, in the following order:
-         * <ul>
-         *  <li>Normalization factor</li>
-         *  <li>Mean</li>
-         *  <li>Standard deviation</li>
-         * </ul>
-         */
-        public double[] guess() {
-            return new double[] { norm, mean, sigma };
-        }
-
-        /**
-         * Sort the observations.
-         *
-         * @param unsorted Input observations.
-         * @return the input observations, sorted.
-         */
-        private WeightedObservedPoint[] sortObservations(WeightedObservedPoint[] unsorted) {
-            final WeightedObservedPoint[] observations = unsorted.clone();
-            final Comparator<WeightedObservedPoint> cmp
-                = new Comparator<WeightedObservedPoint>() {
-                public int compare(WeightedObservedPoint p1,
-                                   WeightedObservedPoint p2) {
-                    if (p1 == null && p2 == null) {
-                        return 0;
-                    }
-                    if (p1 == null) {
-                        return -1;
-                    }
-                    if (p2 == null) {
-                        return 1;
-                    }
-                    if (p1.getX() < p2.getX()) {
-                        return -1;
-                    }
-                    if (p1.getX() > p2.getX()) {
-                        return 1;
-                    }
-                    if (p1.getY() < p2.getY()) {
-                        return -1;
-                    }
-                    if (p1.getY() > p2.getY()) {
-                        return 1;
-                    }
-                    if (p1.getWeight() < p2.getWeight()) {
-                        return -1;
-                    }
-                    if (p1.getWeight() > p2.getWeight()) {
-                        return 1;
-                    }
-                    return 0;
-                }
-            };
-
-            Arrays.sort(observations, cmp);
-            return observations;
-        }
-
-        /**
-         * Guesses the parameters based on the specified observed points.
-         *
-         * @param points Observed points, sorted.
-         * @return the guessed parameters (normalization factor, mean and
-         * sigma).
-         */
-        private double[] basicGuess(WeightedObservedPoint[] points) {
-            final int maxYIdx = findMaxY(points);
-            final double n = points[maxYIdx].getY();
-            final double m = points[maxYIdx].getX();
-
-            double fwhmApprox;
-            try {
-                final double halfY = n + ((m - n) / 2);
-                final double fwhmX1 = interpolateXAtY(points, maxYIdx, -1, halfY);
-                final double fwhmX2 = interpolateXAtY(points, maxYIdx, 1, halfY);
-                fwhmApprox = fwhmX2 - fwhmX1;
-            } catch (OutOfRangeException e) {
-                // TODO: Exceptions should not be used for flow control.
-                fwhmApprox = points[points.length - 1].getX() - points[0].getX();
-            }
-            final double s = fwhmApprox / (2 * FastMath.sqrt(2 * FastMath.log(2)));
-
-            return new double[] { n, m, s };
-        }
-
-        /**
-         * Finds index of point in specified points with the largest Y.
-         *
-         * @param points Points to search.
-         * @return the index in specified points array.
-         */
-        private int findMaxY(WeightedObservedPoint[] points) {
-            int maxYIdx = 0;
-            for (int i = 1; i < points.length; i++) {
-                if (points[i].getY() > points[maxYIdx].getY()) {
-                    maxYIdx = i;
-                }
-            }
-            return maxYIdx;
-        }
-
-        /**
-         * Interpolates using the specified points to determine X at the
-         * specified Y.
-         *
-         * @param points Points to use for interpolation.
-         * @param startIdx Index within points from which to start the search for
-         * interpolation bounds points.
-         * @param idxStep Index step for searching interpolation bounds points.
-         * @param y Y value for which X should be determined.
-         * @return the value of X for the specified Y.
-         * @throws ZeroException if {@code idxStep} is 0.
-         * @throws OutOfRangeException if specified {@code y} is not within the
-         * range of the specified {@code points}.
-         */
-        private double interpolateXAtY(WeightedObservedPoint[] points,
-                                       int startIdx,
-                                       int idxStep,
-                                       double y)
-            throws OutOfRangeException {
-            if (idxStep == 0) {
-                throw new ZeroException();
-            }
-            final WeightedObservedPoint[] twoPoints
-                = getInterpolationPointsForY(points, startIdx, idxStep, y);
-            final WeightedObservedPoint p1 = twoPoints[0];
-            final WeightedObservedPoint p2 = twoPoints[1];
-            if (p1.getY() == y) {
-                return p1.getX();
-            }
-            if (p2.getY() == y) {
-                return p2.getX();
-            }
-            return p1.getX() + (((y - p1.getY()) * (p2.getX() - p1.getX())) /
-                                (p2.getY() - p1.getY()));
-        }
-
-        /**
-         * Gets the two bounding interpolation points from the specified points
-         * suitable for determining X at the specified Y.
-         *
-         * @param points Points to use for interpolation.
-         * @param startIdx Index within points from which to start search for
-         * interpolation bounds points.
-         * @param idxStep Index step for search for interpolation bounds points.
-         * @param y Y value for which X should be determined.
-         * @return the array containing two points suitable for determining X at
-         * the specified Y.
-         * @throws ZeroException if {@code idxStep} is 0.
-         * @throws OutOfRangeException if specified {@code y} is not within the
-         * range of the specified {@code points}.
-         */
-        private WeightedObservedPoint[] getInterpolationPointsForY(WeightedObservedPoint[] points,
-                                                                   int startIdx,
-                                                                   int idxStep,
-                                                                   double y)
-            throws OutOfRangeException {
-            if (idxStep == 0) {
-                throw new ZeroException();
-            }
-            for (int i = startIdx;
-                 idxStep < 0 ? i + idxStep >= 0 : i + idxStep < points.length;
-                 i += idxStep) {
-                final WeightedObservedPoint p1 = points[i];
-                final WeightedObservedPoint p2 = points[i + idxStep];
-                if (isBetween(y, p1.getY(), p2.getY())) {
-                    if (idxStep < 0) {
-                        return new WeightedObservedPoint[] { p2, p1 };
-                    } else {
-                        return new WeightedObservedPoint[] { p1, p2 };
-                    }
-                }
-            }
-
-            // Boundaries are replaced by dummy values because the raised
-            // exception is caught and the message never displayed.
-            // TODO: Exceptions should not be used for flow control.
-            throw new OutOfRangeException(y,
-                                          Double.NEGATIVE_INFINITY,
-                                          Double.POSITIVE_INFINITY);
-        }
-
-        /**
-         * Determines whether a value is between two other values.
-         *
-         * @param value Value to test whether it is between {@code boundary1}
-         * and {@code boundary2}.
-         * @param boundary1 One end of the range.
-         * @param boundary2 Other end of the range.
-         * @return {@code true} if {@code value} is between {@code boundary1} and
-         * {@code boundary2} (inclusive), {@code false} otherwise.
-         */
-        private boolean isBetween(double value,
-                                  double boundary1,
-                                  double boundary2) {
-            return (value >= boundary1 && value <= boundary2) ||
-                (value >= boundary2 && value <= boundary1);
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/commons-math/blob/b4669aad/src/main/java/org/apache/commons/math4/optimization/fitting/HarmonicFitter.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/optimization/fitting/HarmonicFitter.java b/src/main/java/org/apache/commons/math4/optimization/fitting/HarmonicFitter.java
deleted file mode 100644
index 938156d..0000000
--- a/src/main/java/org/apache/commons/math4/optimization/fitting/HarmonicFitter.java
+++ /dev/null
@@ -1,384 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.math4.optimization.fitting;
-
-import org.apache.commons.math4.analysis.function.HarmonicOscillator;
-import org.apache.commons.math4.exception.MathIllegalStateException;
-import org.apache.commons.math4.exception.NumberIsTooSmallException;
-import org.apache.commons.math4.exception.ZeroException;
-import org.apache.commons.math4.exception.util.LocalizedFormats;
-import org.apache.commons.math4.optimization.DifferentiableMultivariateVectorOptimizer;
-import org.apache.commons.math4.util.FastMath;
-
-/**
- * Class that implements a curve fitting specialized for sinusoids.
- *
- * Harmonic fitting is a very simple case of curve fitting. The
- * estimated coefficients are the amplitude a, the pulsation &omega; and
- * the phase &phi;: <code>f (t) = a cos (&omega; t + &phi;)</code>. They are
- * searched by a least square estimator initialized with a rough guess
- * based on integrals.
- *
- * @deprecated As of 3.1 (to be removed in 4.0).
- * @since 2.0
- */
-@Deprecated
-public class HarmonicFitter extends CurveFitter<HarmonicOscillator.Parametric> {
-    /**
-     * Simple constructor.
-     * @param optimizer Optimizer to use for the fitting.
-     */
-    public HarmonicFitter(final DifferentiableMultivariateVectorOptimizer optimizer) {
-        super(optimizer);
-    }
-
-    /**
-     * Fit an harmonic function to the observed points.
-     *
-     * @param initialGuess First guess values in the following order:
-     * <ul>
-     *  <li>Amplitude</li>
-     *  <li>Angular frequency</li>
-     *  <li>Phase</li>
-     * </ul>
-     * @return the parameters of the harmonic function that best fits the
-     * observed points (in the same order as above).
-     */
-    public double[] fit(double[] initialGuess) {
-        return fit(new HarmonicOscillator.Parametric(), initialGuess);
-    }
-
-    /**
-     * Fit an harmonic function to the observed points.
-     * An initial guess will be automatically computed.
-     *
-     * @return the parameters of the harmonic function that best fits the
-     * observed points (see the other {@link #fit(double[]) fit} method.
-     * @throws NumberIsTooSmallException if the sample is too short for the
-     * the first guess to be computed.
-     * @throws ZeroException if the first guess cannot be computed because
-     * the abscissa range is zero.
-     */
-    public double[] fit() {
-        return fit((new ParameterGuesser(getObservations())).guess());
-    }
-
-    /**
-     * This class guesses harmonic coefficients from a sample.
-     * <p>The algorithm used to guess the coefficients is as follows:</p>
-     *
-     * <p>We know f (t) at some sampling points t<sub>i</sub> and want to find a,
-     * &omega; and &phi; such that f (t) = a cos (&omega; t + &phi;).
-     * </p>
-     *
-     * <p>From the analytical expression, we can compute two primitives :
-     * <pre>
-     *     If2  (t) = &int; f<sup>2</sup>  = a<sup>2</sup> &times; [t + S (t)] / 2
-     *     If'2 (t) = &int; f'<sup>2</sup> = a<sup>2</sup> &omega;<sup>2</sup> &times; [t - S (t)] / 2
-     *     where S (t) = sin (2 (&omega; t + &phi;)) / (2 &omega;)
-     * </pre>
-     * </p>
-     *
-     * <p>We can remove S between these expressions :
-     * <pre>
-     *     If'2 (t) = a<sup>2</sup> &omega;<sup>2</sup> t - &omega;<sup>2</sup> If2 (t)
-     * </pre>
-     * </p>
-     *
-     * <p>The preceding expression shows that If'2 (t) is a linear
-     * combination of both t and If2 (t): If'2 (t) = A &times; t + B &times; If2 (t)
-     * </p>
-     *
-     * <p>From the primitive, we can deduce the same form for definite
-     * integrals between t<sub>1</sub> and t<sub>i</sub> for each t<sub>i</sub> :
-     * <pre>
-     *   If2 (t<sub>i</sub>) - If2 (t<sub>1</sub>) = A &times; (t<sub>i</sub> - t<sub>1</sub>) + B &times; (If2 (t<sub>i</sub>) - If2 (t<sub>1</sub>))
-     * </pre>
-     * </p>
-     *
-     * <p>We can find the coefficients A and B that best fit the sample
-     * to this linear expression by computing the definite integrals for
-     * each sample points.
-     * </p>
-     *
-     * <p>For a bilinear expression z (x<sub>i</sub>, y<sub>i</sub>) = A &times; x<sub>i</sub> + B &times; y<sub>i</sub>, the
-     * coefficients A and B that minimize a least square criterion
-     * &sum; (z<sub>i</sub> - z (x<sub>i</sub>, y<sub>i</sub>))<sup>2</sup> are given by these expressions:</p>
-     * <pre>
-     *
-     *         &sum;y<sub>i</sub>y<sub>i</sub> &sum;x<sub>i</sub>z<sub>i</sub> - &sum;x<sub>i</sub>y<sub>i</sub> &sum;y<sub>i</sub>z<sub>i</sub>
-     *     A = ------------------------
-     *         &sum;x<sub>i</sub>x<sub>i</sub> &sum;y<sub>i</sub>y<sub>i</sub> - &sum;x<sub>i</sub>y<sub>i</sub> &sum;x<sub>i</sub>y<sub>i</sub>
-     *
-     *         &sum;x<sub>i</sub>x<sub>i</sub> &sum;y<sub>i</sub>z<sub>i</sub> - &sum;x<sub>i</sub>y<sub>i</sub> &sum;x<sub>i</sub>z<sub>i</sub>
-     *     B = ------------------------
-     *         &sum;x<sub>i</sub>x<sub>i</sub> &sum;y<sub>i</sub>y<sub>i</sub> - &sum;x<sub>i</sub>y<sub>i</sub> &sum;x<sub>i</sub>y<sub>i</sub>
-     * </pre>
-     * </p>
-     *
-     *
-     * <p>In fact, we can assume both a and &omega; are positive and
-     * compute them directly, knowing that A = a<sup>2</sup> &omega;<sup>2</sup> and that
-     * B = - &omega;<sup>2</sup>. The complete algorithm is therefore:</p>
-     * <pre>
-     *
-     * for each t<sub>i</sub> from t<sub>1</sub> to t<sub>n-1</sub>, compute:
-     *   f  (t<sub>i</sub>)
-     *   f' (t<sub>i</sub>) = (f (t<sub>i+1</sub>) - f(t<sub>i-1</sub>)) / (t<sub>i+1</sub> - t<sub>i-1</sub>)
-     *   x<sub>i</sub> = t<sub>i</sub> - t<sub>1</sub>
-     *   y<sub>i</sub> = &int; f<sup>2</sup> from t<sub>1</sub> to t<sub>i</sub>
-     *   z<sub>i</sub> = &int; f'<sup>2</sup> from t<sub>1</sub> to t<sub>i</sub>
-     *   update the sums &sum;x<sub>i</sub>x<sub>i</sub>, &sum;y<sub>i</sub>y<sub>i</sub>, &sum;x<sub>i</sub>y<sub>i</sub>, &sum;x<sub>i</sub>z<sub>i</sub> and &sum;y<sub>i</sub>z<sub>i</sub>
-     * end for
-     *
-     *            |--------------------------
-     *         \  | &sum;y<sub>i</sub>y<sub>i</sub> &sum;x<sub>i</sub>z<sub>i</sub> - &sum;x<sub>i</sub>y<sub>i</sub> &sum;y<sub>i</sub>z<sub>i</sub>
-     * a     =  \ | ------------------------
-     *           \| &sum;x<sub>i</sub>y<sub>i</sub> &sum;x<sub>i</sub>z<sub>i</sub> - &sum;x<sub>i</sub>x<sub>i</sub> &sum;y<sub>i</sub>z<sub>i</sub>
-     *
-     *
-     *            |--------------------------
-     *         \  | &sum;x<sub>i</sub>y<sub>i</sub> &sum;x<sub>i</sub>z<sub>i</sub> - &sum;x<sub>i</sub>x<sub>i</sub> &sum;y<sub>i</sub>z<sub>i</sub>
-     * &omega;     =  \ | ------------------------
-     *           \| &sum;x<sub>i</sub>x<sub>i</sub> &sum;y<sub>i</sub>y<sub>i</sub> - &sum;x<sub>i</sub>y<sub>i</sub> &sum;x<sub>i</sub>y<sub>i</sub>
-     *
-     * </pre>
-     * </p>
-     *
-     * <p>Once we know &omega;, we can compute:
-     * <pre>
-     *    fc = &omega; f (t) cos (&omega; t) - f' (t) sin (&omega; t)
-     *    fs = &omega; f (t) sin (&omega; t) + f' (t) cos (&omega; t)
-     * </pre>
-     * </p>
-     *
-     * <p>It appears that <code>fc = a &omega; cos (&phi;)</code> and
-     * <code>fs = -a &omega; sin (&phi;)</code>, so we can use these
-     * expressions to compute &phi;. The best estimate over the sample is
-     * given by averaging these expressions.
-     * </p>
-     *
-     * <p>Since integrals and means are involved in the preceding
-     * estimations, these operations run in O(n) time, where n is the
-     * number of measurements.</p>
-     */
-    public static class ParameterGuesser {
-        /** Amplitude. */
-        private final double a;
-        /** Angular frequency. */
-        private final double omega;
-        /** Phase. */
-        private final double phi;
-
-        /**
-         * Simple constructor.
-         *
-         * @param observations Sampled observations.
-         * @throws NumberIsTooSmallException if the sample is too short.
-         * @throws ZeroException if the abscissa range is zero.
-         * @throws MathIllegalStateException when the guessing procedure cannot
-         * produce sensible results.
-         */
-        public ParameterGuesser(WeightedObservedPoint[] observations) {
-            if (observations.length < 4) {
-                throw new NumberIsTooSmallException(LocalizedFormats.INSUFFICIENT_OBSERVED_POINTS_IN_SAMPLE,
-                                                    observations.length, 4, true);
-            }
-
-            final WeightedObservedPoint[] sorted = sortObservations(observations);
-
-            final double aOmega[] = guessAOmega(sorted);
-            a = aOmega[0];
-            omega = aOmega[1];
-
-            phi = guessPhi(sorted);
-        }
-
-        /**
-         * Gets an estimation of the parameters.
-         *
-         * @return the guessed parameters, in the following order:
-         * <ul>
-         *  <li>Amplitude</li>
-         *  <li>Angular frequency</li>
-         *  <li>Phase</li>
-         * </ul>
-         */
-        public double[] guess() {
-            return new double[] { a, omega, phi };
-        }
-
-        /**
-         * Sort the observations with respect to the abscissa.
-         *
-         * @param unsorted Input observations.
-         * @return the input observations, sorted.
-         */
-        private WeightedObservedPoint[] sortObservations(WeightedObservedPoint[] unsorted) {
-            final WeightedObservedPoint[] observations = unsorted.clone();
-
-            // Since the samples are almost always already sorted, this
-            // method is implemented as an insertion sort that reorders the
-            // elements in place. Insertion sort is very efficient in this case.
-            WeightedObservedPoint curr = observations[0];
-            for (int j = 1; j < observations.length; ++j) {
-                WeightedObservedPoint prec = curr;
-                curr = observations[j];
-                if (curr.getX() < prec.getX()) {
-                    // the current element should be inserted closer to the beginning
-                    int i = j - 1;
-                    WeightedObservedPoint mI = observations[i];
-                    while ((i >= 0) && (curr.getX() < mI.getX())) {
-                        observations[i + 1] = mI;
-                        if (i-- != 0) {
-                            mI = observations[i];
-                        }
-                    }
-                    observations[i + 1] = curr;
-                    curr = observations[j];
-                }
-            }
-
-            return observations;
-        }
-
-        /**
-         * Estimate a first guess of the amplitude and angular frequency.
-         * This method assumes that the {@link #sortObservations(WeightedObservedPoint[])} method
-         * has been called previously.
-         *
-         * @param observations Observations, sorted w.r.t. abscissa.
-         * @throws ZeroException if the abscissa range is zero.
-         * @throws MathIllegalStateException when the guessing procedure cannot
-         * produce sensible results.
-         * @return the guessed amplitude (at index 0) and circular frequency
-         * (at index 1).
-         */
-        private double[] guessAOmega(WeightedObservedPoint[] observations) {
-            final double[] aOmega = new double[2];
-
-            // initialize the sums for the linear model between the two integrals
-            double sx2 = 0;
-            double sy2 = 0;
-            double sxy = 0;
-            double sxz = 0;
-            double syz = 0;
-
-            double currentX = observations[0].getX();
-            double currentY = observations[0].getY();
-            double f2Integral = 0;
-            double fPrime2Integral = 0;
-            final double startX = currentX;
-            for (int i = 1; i < observations.length; ++i) {
-                // one step forward
-                final double previousX = currentX;
-                final double previousY = currentY;
-                currentX = observations[i].getX();
-                currentY = observations[i].getY();
-
-                // update the integrals of f<sup>2</sup> and f'<sup>2</sup>
-                // considering a linear model for f (and therefore constant f')
-                final double dx = currentX - previousX;
-                final double dy = currentY - previousY;
-                final double f2StepIntegral =
-                    dx * (previousY * previousY + previousY * currentY + currentY * currentY) / 3;
-                final double fPrime2StepIntegral = dy * dy / dx;
-
-                final double x = currentX - startX;
-                f2Integral += f2StepIntegral;
-                fPrime2Integral += fPrime2StepIntegral;
-
-                sx2 += x * x;
-                sy2 += f2Integral * f2Integral;
-                sxy += x * f2Integral;
-                sxz += x * fPrime2Integral;
-                syz += f2Integral * fPrime2Integral;
-            }
-
-            // compute the amplitude and pulsation coefficients
-            double c1 = sy2 * sxz - sxy * syz;
-            double c2 = sxy * sxz - sx2 * syz;
-            double c3 = sx2 * sy2 - sxy * sxy;
-            if ((c1 / c2 < 0) || (c2 / c3 < 0)) {
-                final int last = observations.length - 1;
-                // Range of the observations, assuming that the
-                // observations are sorted.
-                final double xRange = observations[last].getX() - observations[0].getX();
-                if (xRange == 0) {
-                    throw new ZeroException();
-                }
-                aOmega[1] = 2 * Math.PI / xRange;
-
-                double yMin = Double.POSITIVE_INFINITY;
-                double yMax = Double.NEGATIVE_INFINITY;
-                for (int i = 1; i < observations.length; ++i) {
-                    final double y = observations[i].getY();
-                    if (y < yMin) {
-                        yMin = y;
-                    }
-                    if (y > yMax) {
-                        yMax = y;
-                    }
-                }
-                aOmega[0] = 0.5 * (yMax - yMin);
-            } else {
-                if (c2 == 0) {
-                    // In some ill-conditioned cases (cf. MATH-844), the guesser
-                    // procedure cannot produce sensible results.
-                    throw new MathIllegalStateException(LocalizedFormats.ZERO_DENOMINATOR);
-                }
-
-                aOmega[0] = FastMath.sqrt(c1 / c2);
-                aOmega[1] = FastMath.sqrt(c2 / c3);
-            }
-
-            return aOmega;
-        }
-
-        /**
-         * Estimate a first guess of the phase.
-         *
-         * @param observations Observations, sorted w.r.t. abscissa.
-         * @return the guessed phase.
-         */
-        private double guessPhi(WeightedObservedPoint[] observations) {
-            // initialize the means
-            double fcMean = 0;
-            double fsMean = 0;
-
-            double currentX = observations[0].getX();
-            double currentY = observations[0].getY();
-            for (int i = 1; i < observations.length; ++i) {
-                // one step forward
-                final double previousX = currentX;
-                final double previousY = currentY;
-                currentX = observations[i].getX();
-                currentY = observations[i].getY();
-                final double currentYPrime = (currentY - previousY) / (currentX - previousX);
-
-                double omegaX = omega * currentX;
-                double cosine = FastMath.cos(omegaX);
-                double sine = FastMath.sin(omegaX);
-                fcMean += omega * currentY * cosine - currentYPrime * sine;
-                fsMean += omega * currentY * sine + currentYPrime * cosine;
-            }
-
-            return FastMath.atan2(-fsMean, fcMean);
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/commons-math/blob/b4669aad/src/main/java/org/apache/commons/math4/optimization/fitting/PolynomialFitter.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/optimization/fitting/PolynomialFitter.java b/src/main/java/org/apache/commons/math4/optimization/fitting/PolynomialFitter.java
deleted file mode 100644
index 3773acb..0000000
--- a/src/main/java/org/apache/commons/math4/optimization/fitting/PolynomialFitter.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.math4.optimization.fitting;
-
-import org.apache.commons.math4.analysis.polynomials.PolynomialFunction;
-import org.apache.commons.math4.optimization.DifferentiableMultivariateVectorOptimizer;
-
-/**
- * Polynomial fitting is a very simple case of {@link CurveFitter curve fitting}.
- * The estimated coefficients are the polynomial coefficients (see the
- * {@link #fit(double[]) fit} method).
- *
- * @deprecated As of 3.1 (to be removed in 4.0).
- * @since 2.0
- */
-@Deprecated
-public class PolynomialFitter extends CurveFitter<PolynomialFunction.Parametric> {
-    /** Polynomial degree.
-     * @deprecated
-     */
-    @Deprecated
-    private final int degree;
-
-    /**
-     * Simple constructor.
-     * <p>The polynomial fitter built this way are complete polynomials,
-     * ie. a n-degree polynomial has n+1 coefficients.</p>
-     *
-     * @param degree Maximal degree of the polynomial.
-     * @param optimizer Optimizer to use for the fitting.
-     * @deprecated Since 3.1 (to be removed in 4.0). Please use
-     * {@link #PolynomialFitter(DifferentiableMultivariateVectorOptimizer)} instead.
-     */
-    @Deprecated
-    public PolynomialFitter(int degree, final DifferentiableMultivariateVectorOptimizer optimizer) {
-        super(optimizer);
-        this.degree = degree;
-    }
-
-    /**
-     * Simple constructor.
-     *
-     * @param optimizer Optimizer to use for the fitting.
-     * @since 3.1
-     */
-    public PolynomialFitter(DifferentiableMultivariateVectorOptimizer optimizer) {
-        super(optimizer);
-        degree = -1; // To avoid compilation error until the instance variable is removed.
-    }
-
-    /**
-     * Get the polynomial fitting the weighted (x, y) points.
-     *
-     * @return the coefficients of the polynomial that best fits the observed points.
-     * @throws org.apache.commons.math4.exception.ConvergenceException
-     * if the algorithm failed to converge.
-     * @deprecated Since 3.1 (to be removed in 4.0). Please use {@link #fit(double[])} instead.
-     */
-    @Deprecated
-    public double[] fit() {
-        return fit(new PolynomialFunction.Parametric(), new double[degree + 1]);
-    }
-
-    /**
-     * Get the coefficients of the polynomial fitting the weighted data points.
-     * The degree of the fitting polynomial is {@code guess.length - 1}.
-     *
-     * @param guess First guess for the coefficients. They must be sorted in
-     * increasing order of the polynomial's degree.
-     * @param maxEval Maximum number of evaluations of the polynomial.
-     * @return the coefficients of the polynomial that best fits the observed points.
-     * @throws org.apache.commons.math4.exception.TooManyEvaluationsException if
-     * the number of evaluations exceeds {@code maxEval}.
-     * @throws org.apache.commons.math4.exception.ConvergenceException
-     * if the algorithm failed to converge.
-     * @since 3.1
-     */
-    public double[] fit(int maxEval, double[] guess) {
-        return fit(maxEval, new PolynomialFunction.Parametric(), guess);
-    }
-
-    /**
-     * Get the coefficients of the polynomial fitting the weighted data points.
-     * The degree of the fitting polynomial is {@code guess.length - 1}.
-     *
-     * @param guess First guess for the coefficients. They must be sorted in
-     * increasing order of the polynomial's degree.
-     * @return the coefficients of the polynomial that best fits the observed points.
-     * @throws org.apache.commons.math4.exception.ConvergenceException
-     * if the algorithm failed to converge.
-     * @since 3.1
-     */
-    public double[] fit(double[] guess) {
-        return fit(new PolynomialFunction.Parametric(), guess);
-    }
-}


Mime
View raw message