commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t.@apache.org
Subject [3/5] [math] Remove deprecated classes in optim package.
Date Sat, 11 Apr 2015 14:06:08 GMT
http://git-wip-us.apache.org/repos/asf/commons-math/blob/e31fde87/src/test/java/org/apache/commons/math4/optim/nonlinear/vector/jacobian/RandomCirclePointGenerator.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/optim/nonlinear/vector/jacobian/RandomCirclePointGenerator.java
b/src/test/java/org/apache/commons/math4/optim/nonlinear/vector/jacobian/RandomCirclePointGenerator.java
deleted file mode 100644
index d969b57..0000000
--- a/src/test/java/org/apache/commons/math4/optim/nonlinear/vector/jacobian/RandomCirclePointGenerator.java
+++ /dev/null
@@ -1,91 +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.optim.nonlinear.vector.jacobian;
-
-import org.apache.commons.math4.distribution.NormalDistribution;
-import org.apache.commons.math4.distribution.RealDistribution;
-import org.apache.commons.math4.distribution.UniformRealDistribution;
-import org.apache.commons.math4.geometry.euclidean.twod.Vector2D;
-import org.apache.commons.math4.random.RandomGenerator;
-import org.apache.commons.math4.random.Well44497b;
-import org.apache.commons.math4.util.FastMath;
-import org.apache.commons.math4.util.MathUtils;
-
-/**
- * Factory for generating a cloud of points that approximate a circle.
- */
-@Deprecated
-public class RandomCirclePointGenerator {
-    /** RNG for the x-coordinate of the center. */
-    private final RealDistribution cX;
-    /** RNG for the y-coordinate of the center. */
-    private final RealDistribution cY;
-    /** RNG for the parametric position of the point. */
-    private final RealDistribution tP;
-    /** Radius of the circle. */
-    private final double radius;
-
-    /**
-     * @param x Abscissa of the circle center.
-     * @param y Ordinate of the circle center.
-     * @param radius Radius of the circle.
-     * @param xSigma Error on the x-coordinate of the circumference points.
-     * @param ySigma Error on the y-coordinate of the circumference points.
-     * @param seed RNG seed.
-     */
-    public RandomCirclePointGenerator(double x,
-                                      double y,
-                                      double radius,
-                                      double xSigma,
-                                      double ySigma,
-                                      long seed) {
-        final RandomGenerator rng = new Well44497b(seed);
-        this.radius = radius;
-        cX = new NormalDistribution(rng, x, xSigma,
-                                    NormalDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
-        cY = new NormalDistribution(rng, y, ySigma,
-                                    NormalDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
-        tP = new UniformRealDistribution(rng, 0, MathUtils.TWO_PI);
-    }
-
-    /**
-     * Point generator.
-     *
-     * @param n Number of points to create.
-     * @return the cloud of {@code n} points.
-     */
-    public Vector2D[] generate(int n) {
-        final Vector2D[] cloud = new Vector2D[n];
-        for (int i = 0; i < n; i++) {
-            cloud[i] = create();
-        }
-        return cloud;
-    }
-
-    /**
-     * Create one point.
-     *
-     * @return a point.
-     */
-    private Vector2D create() {
-        final double t = tP.sample();
-        final double pX = cX.sample() + radius * FastMath.cos(t);
-        final double pY = cY.sample() + radius * FastMath.sin(t);
-
-        return new Vector2D(pX, pY);
-    }
-}

http://git-wip-us.apache.org/repos/asf/commons-math/blob/e31fde87/src/test/java/org/apache/commons/math4/optim/nonlinear/vector/jacobian/RandomStraightLinePointGenerator.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/optim/nonlinear/vector/jacobian/RandomStraightLinePointGenerator.java
b/src/test/java/org/apache/commons/math4/optim/nonlinear/vector/jacobian/RandomStraightLinePointGenerator.java
deleted file mode 100644
index 41def57..0000000
--- a/src/test/java/org/apache/commons/math4/optim/nonlinear/vector/jacobian/RandomStraightLinePointGenerator.java
+++ /dev/null
@@ -1,99 +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.optim.nonlinear.vector.jacobian;
-
-import java.awt.geom.Point2D;
-
-import org.apache.commons.math4.distribution.NormalDistribution;
-import org.apache.commons.math4.distribution.RealDistribution;
-import org.apache.commons.math4.distribution.UniformRealDistribution;
-import org.apache.commons.math4.random.RandomGenerator;
-import org.apache.commons.math4.random.Well44497b;
-
-/**
- * Factory for generating a cloud of points that approximate a straight line.
- */
-@Deprecated
-public class RandomStraightLinePointGenerator {
-    /** Slope. */
-    private final double slope;
-    /** Intercept. */
-    private final double intercept;
-    /** RNG for the x-coordinate. */
-    private final RealDistribution x;
-    /** RNG for the error on the y-coordinate. */
-    private final RealDistribution error;
-
-    /**
-     * The generator will create a cloud of points whose x-coordinates
-     * will be randomly sampled between {@code xLo} and {@code xHi}, and
-     * the corresponding y-coordinates will be computed as
-     * <pre><code>
-     *  y = a x + b + N(0, error)
-     * </code></pre>
-     * where {@code N(mean, sigma)} is a Gaussian distribution with the
-     * given mean and standard deviation.
-     *
-     * @param a Slope.
-     * @param b Intercept.
-     * @param sigma Standard deviation on the y-coordinate of the point.
-     * @param lo Lowest value of the x-coordinate.
-     * @param hi Highest value of the x-coordinate.
-     * @param seed RNG seed.
-     */
-    public RandomStraightLinePointGenerator(double a,
-                                            double b,
-                                            double sigma,
-                                            double lo,
-                                            double hi,
-                                            long seed) {
-        final RandomGenerator rng = new Well44497b(seed);
-        slope = a;
-        intercept = b;
-        error = new NormalDistribution(rng, 0, sigma,
-                                       NormalDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
-        x = new UniformRealDistribution(rng, lo, hi);
-    }
-
-    /**
-     * Point generator.
-     *
-     * @param n Number of points to create.
-     * @return the cloud of {@code n} points.
-     */
-    public Point2D.Double[] generate(int n) {
-        final Point2D.Double[] cloud = new Point2D.Double[n];
-        for (int i = 0; i < n; i++) {
-            cloud[i] = create();
-        }
-        return cloud;
-    }
-
-    /**
-     * Create one point.
-     *
-     * @return a point.
-     */
-    private Point2D.Double create() {
-        final double abscissa = x.sample();
-        final double yModel = slope * abscissa + intercept;
-        final double ordinate = yModel + error.sample();
-
-        return new Point2D.Double(abscissa, ordinate);
-    }
-}

http://git-wip-us.apache.org/repos/asf/commons-math/blob/e31fde87/src/test/java/org/apache/commons/math4/optim/nonlinear/vector/jacobian/StatisticalReferenceDataset.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/optim/nonlinear/vector/jacobian/StatisticalReferenceDataset.java
b/src/test/java/org/apache/commons/math4/optim/nonlinear/vector/jacobian/StatisticalReferenceDataset.java
deleted file mode 100644
index 8265215..0000000
--- a/src/test/java/org/apache/commons/math4/optim/nonlinear/vector/jacobian/StatisticalReferenceDataset.java
+++ /dev/null
@@ -1,385 +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.optim.nonlinear.vector.jacobian;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.util.ArrayList;
-
-import org.apache.commons.math4.analysis.MultivariateMatrixFunction;
-import org.apache.commons.math4.analysis.MultivariateVectorFunction;
-import org.apache.commons.math4.optim.nonlinear.vector.ModelFunction;
-import org.apache.commons.math4.optim.nonlinear.vector.ModelFunctionJacobian;
-import org.apache.commons.math4.util.MathArrays;
-
-/**
- * This class gives access to the statistical reference datasets provided by the
- * NIST (available
- * <a href="http://www.itl.nist.gov/div898/strd/general/dataarchive.html">here</a>).
- * Instances of this class can be created by invocation of the
- * {@link StatisticalReferenceDatasetFactory}.
- */
-@Deprecated
-public abstract class StatisticalReferenceDataset {
-
-    /** The name of this dataset. */
-    private final String name;
-
-    /** The total number of observations (data points). */
-    private final int numObservations;
-
-    /** The total number of parameters. */
-    private final int numParameters;
-
-    /** The total number of starting points for the optimizations. */
-    private final int numStartingPoints;
-
-    /** The values of the predictor. */
-    private final double[] x;
-
-    /** The values of the response. */
-    private final double[] y;
-
-    /**
-     * The starting values. {@code startingValues[j][i]} is the value of the
-     * {@code i}-th parameter in the {@code j}-th set of starting values.
-     */
-    private final double[][] startingValues;
-
-    /** The certified values of the parameters. */
-    private final double[] a;
-
-    /** The certified values of the standard deviation of the parameters. */
-    private final double[] sigA;
-
-    /** The certified value of the residual sum of squares. */
-    private double residualSumOfSquares;
-
-    /** The least-squares problem. */
-    private final LeastSquaresProblem problem;
-
-    /**
-     * Creates a new instance of this class from the specified data file. The
-     * file must follow the StRD format.
-     *
-     * @param in the data file
-     * @throws IOException if an I/O error occurs
-     */
-    public StatisticalReferenceDataset(final BufferedReader in)
-        throws IOException {
-
-        final ArrayList<String> lines = new ArrayList<String>();
-        for (String line = in.readLine(); line != null; line = in.readLine()) {
-            lines.add(line);
-        }
-        int[] index = findLineNumbers("Data", lines);
-        if (index == null) {
-            throw new AssertionError("could not find line indices for data");
-        }
-        this.numObservations = index[1] - index[0] + 1;
-        this.x = new double[this.numObservations];
-        this.y = new double[this.numObservations];
-        for (int i = 0; i < this.numObservations; i++) {
-            final String line = lines.get(index[0] + i - 1);
-            final String[] tokens = line.trim().split(" ++");
-            // Data columns are in reverse order!!!
-            this.y[i] = Double.parseDouble(tokens[0]);
-            this.x[i] = Double.parseDouble(tokens[1]);
-        }
-
-        index = findLineNumbers("Starting Values", lines);
-        if (index == null) {
-            throw new AssertionError(
-                                     "could not find line indices for starting values");
-        }
-        this.numParameters = index[1] - index[0] + 1;
-
-        double[][] start = null;
-        this.a = new double[numParameters];
-        this.sigA = new double[numParameters];
-        for (int i = 0; i < numParameters; i++) {
-            final String line = lines.get(index[0] + i - 1);
-            final String[] tokens = line.trim().split(" ++");
-            if (start == null) {
-                start = new double[tokens.length - 4][numParameters];
-            }
-            for (int j = 2; j < tokens.length - 2; j++) {
-                start[j - 2][i] = Double.parseDouble(tokens[j]);
-            }
-            this.a[i] = Double.parseDouble(tokens[tokens.length - 2]);
-            this.sigA[i] = Double.parseDouble(tokens[tokens.length - 1]);
-        }
-        if (start == null) {
-            throw new IOException("could not find starting values");
-        }
-        this.numStartingPoints = start.length;
-        this.startingValues = start;
-
-        double dummyDouble = Double.NaN;
-        String dummyString = null;
-        for (String line : lines) {
-            if (line.contains("Dataset Name:")) {
-                dummyString = line
-                    .substring(line.indexOf("Dataset Name:") + 13,
-                               line.indexOf("(")).trim();
-            }
-            if (line.contains("Residual Sum of Squares")) {
-                final String[] tokens = line.split(" ++");
-                dummyDouble = Double.parseDouble(tokens[4].trim());
-            }
-        }
-        if (Double.isNaN(dummyDouble)) {
-            throw new IOException(
-                                  "could not find certified value of residual sum of squares");
-        }
-        this.residualSumOfSquares = dummyDouble;
-
-        if (dummyString == null) {
-            throw new IOException("could not find dataset name");
-        }
-        this.name = dummyString;
-
-        this.problem = new LeastSquaresProblem();
-    }
-
-    class LeastSquaresProblem {
-        public ModelFunction getModelFunction() {
-            return new ModelFunction(new MultivariateVectorFunction() {
-                    public double[] value(final double[] a) {
-                        final int n = getNumObservations();
-                        final double[] yhat = new double[n];
-                        for (int i = 0; i < n; i++) {
-                            yhat[i] = getModelValue(getX(i), a);
-                        }
-                        return yhat;
-                    }
-                });
-        }
-
-        public ModelFunctionJacobian getModelFunctionJacobian() {
-            return new ModelFunctionJacobian(new MultivariateMatrixFunction() {
-                    public double[][] value(final double[] a)
-                        throws IllegalArgumentException {
-                        final int n = getNumObservations();
-                        final double[][] j = new double[n][];
-                        for (int i = 0; i < n; i++) {
-                            j[i] = getModelDerivatives(getX(i), a);
-                        }
-                        return j;
-                    }
-                });
-        }
-    }
-
-    /**
-     * Returns the name of this dataset.
-     *
-     * @return the name of the dataset
-     */
-    public String getName() {
-        return name;
-    }
-
-    /**
-     * Returns the total number of observations (data points).
-     *
-     * @return the number of observations
-     */
-    public int getNumObservations() {
-        return numObservations;
-    }
-
-    /**
-     * Returns a copy of the data arrays. The data is laid out as follows <li>
-     * {@code data[0][i] = x[i]},</li> <li>{@code data[1][i] = y[i]},</li>
-     *
-     * @return the array of data points.
-     */
-    public double[][] getData() {
-        return new double[][] {
-            MathArrays.copyOf(x), MathArrays.copyOf(y)
-        };
-    }
-
-    /**
-     * Returns the x-value of the {@code i}-th data point.
-     *
-     * @param i the index of the data point
-     * @return the x-value
-     */
-    public double getX(final int i) {
-        return x[i];
-    }
-
-    /**
-     * Returns the y-value of the {@code i}-th data point.
-     *
-     * @param i the index of the data point
-     * @return the y-value
-     */
-    public double getY(final int i) {
-        return y[i];
-    }
-
-    /**
-     * Returns the total number of parameters.
-     *
-     * @return the number of parameters
-     */
-    public int getNumParameters() {
-        return numParameters;
-    }
-
-    /**
-     * Returns the certified values of the paramters.
-     *
-     * @return the values of the parameters
-     */
-    public double[] getParameters() {
-        return MathArrays.copyOf(a);
-    }
-
-    /**
-     * Returns the certified value of the {@code i}-th parameter.
-     *
-     * @param i the index of the parameter
-     * @return the value of the parameter
-     */
-    public double getParameter(final int i) {
-        return a[i];
-    }
-
-    /**
-     * Reurns the certified values of the standard deviations of the parameters.
-     *
-     * @return the standard deviations of the parameters
-     */
-    public double[] getParametersStandardDeviations() {
-        return MathArrays.copyOf(sigA);
-    }
-
-    /**
-     * Returns the certified value of the standard deviation of the {@code i}-th
-     * parameter.
-     *
-     * @param i the index of the parameter
-     * @return the standard deviation of the parameter
-     */
-    public double getParameterStandardDeviation(final int i) {
-        return sigA[i];
-    }
-
-    /**
-     * Returns the certified value of the residual sum of squares.
-     *
-     * @return the residual sum of squares
-     */
-    public double getResidualSumOfSquares() {
-        return residualSumOfSquares;
-    }
-
-    /**
-     * Returns the total number of starting points (initial guesses for the
-     * optimization process).
-     *
-     * @return the number of starting points
-     */
-    public int getNumStartingPoints() {
-        return numStartingPoints;
-    }
-
-    /**
-     * Returns the {@code i}-th set of initial values of the parameters.
-     *
-     * @param i the index of the starting point
-     * @return the starting point
-     */
-    public double[] getStartingPoint(final int i) {
-        return MathArrays.copyOf(startingValues[i]);
-    }
-
-    /**
-     * Returns the least-squares problem corresponding to fitting the model to
-     * the specified data.
-     *
-     * @return the least-squares problem
-     */
-    public LeastSquaresProblem getLeastSquaresProblem() {
-        return problem;
-    }
-
-    /**
-     * Returns the value of the model for the specified values of the predictor
-     * variable and the parameters.
-     *
-     * @param x the predictor variable
-     * @param a the parameters
-     * @return the value of the model
-     */
-    public abstract double getModelValue(final double x, final double[] a);
-
-    /**
-     * Returns the values of the partial derivatives of the model with respect
-     * to the parameters.
-     *
-     * @param x the predictor variable
-     * @param a the parameters
-     * @return the partial derivatives
-     */
-    public abstract double[] getModelDerivatives(final double x,
-                                                 final double[] a);
-
-    /**
-     * <p>
-     * Parses the specified text lines, and extracts the indices of the first
-     * and last lines of the data defined by the specified {@code key}. This key
-     * must be one of
-     * </p>
-     * <ul>
-     * <li>{@code "Starting Values"},</li>
-     * <li>{@code "Certified Values"},</li>
-     * <li>{@code "Data"}.</li>
-     * </ul>
-     * <p>
-     * In the NIST data files, the line indices are separated by the keywords
-     * {@code "lines"} and {@code "to"}.
-     * </p>
-     *
-     * @param lines the line of text to be parsed
-     * @return an array of two {@code int}s. First value is the index of the
-     *         first line, second value is the index of the last line.
-     *         {@code null} if the line could not be parsed.
-     */
-    private static int[] findLineNumbers(final String key,
-                                         final Iterable<String> lines) {
-        for (String text : lines) {
-            boolean flag = text.contains(key) && text.contains("lines") &&
-                           text.contains("to") && text.contains(")");
-            if (flag) {
-                final int[] numbers = new int[2];
-                final String from = text.substring(text.indexOf("lines") + 5,
-                                                   text.indexOf("to"));
-                numbers[0] = Integer.parseInt(from.trim());
-                final String to = text.substring(text.indexOf("to") + 2,
-                                                 text.indexOf(")"));
-                numbers[1] = Integer.parseInt(to.trim());
-                return numbers;
-            }
-        }
-        return null;
-    }
-}

http://git-wip-us.apache.org/repos/asf/commons-math/blob/e31fde87/src/test/java/org/apache/commons/math4/optim/nonlinear/vector/jacobian/StatisticalReferenceDatasetFactory.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/optim/nonlinear/vector/jacobian/StatisticalReferenceDatasetFactory.java
b/src/test/java/org/apache/commons/math4/optim/nonlinear/vector/jacobian/StatisticalReferenceDatasetFactory.java
deleted file mode 100644
index 99995e8..0000000
--- a/src/test/java/org/apache/commons/math4/optim/nonlinear/vector/jacobian/StatisticalReferenceDatasetFactory.java
+++ /dev/null
@@ -1,203 +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.optim.nonlinear.vector.jacobian;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-
-import org.apache.commons.math4.util.FastMath;
-
-/**
- * A factory to create instances of {@link StatisticalReferenceDataset} from
- * available resources.
- */
-@Deprecated
-public class StatisticalReferenceDatasetFactory {
-
-    private StatisticalReferenceDatasetFactory() {
-        // Do nothing
-    }
-
-    /**
-     * Creates a new buffered reader from the specified resource name.
-     *
-     * @param name the name of the resource
-     * @return a buffered reader
-     * @throws IOException if an I/O error occurred
-     */
-    public static BufferedReader createBufferedReaderFromResource(final String name)
-        throws IOException {
-        final InputStream resourceAsStream;
-        resourceAsStream = StatisticalReferenceDatasetFactory.class
-            .getResourceAsStream(name);
-        if (resourceAsStream == null) {
-            throw new IOException("could not find resource " + name);
-        }
-        return new BufferedReader(new InputStreamReader(resourceAsStream));
-    }
-
-    public static StatisticalReferenceDataset createKirby2()
-        throws IOException {
-        final BufferedReader in = createBufferedReaderFromResource("Kirby2.dat");
-        StatisticalReferenceDataset dataset = null;
-        try {
-            dataset = new StatisticalReferenceDataset(in) {
-
-                @Override
-                public double getModelValue(final double x, final double[] a) {
-                    final double p = a[0] + x * (a[1] + x * a[2]);
-                    final double q = 1.0 + x * (a[3] + x * a[4]);
-                    return p / q;
-                }
-
-                @Override
-                public double[] getModelDerivatives(final double x,
-                                                    final double[] a) {
-                    final double[] dy = new double[5];
-                    final double p = a[0] + x * (a[1] + x * a[2]);
-                    final double q = 1.0 + x * (a[3] + x * a[4]);
-                    dy[0] = 1.0 / q;
-                    dy[1] = x / q;
-                    dy[2] = x * dy[1];
-                    dy[3] = -x * p / (q * q);
-                    dy[4] = x * dy[3];
-                    return dy;
-                }
-            };
-        } finally {
-            in.close();
-        }
-        return dataset;
-    }
-
-    public static StatisticalReferenceDataset createHahn1()
-        throws IOException {
-        final BufferedReader in = createBufferedReaderFromResource("Hahn1.dat");
-        StatisticalReferenceDataset dataset = null;
-        try {
-            dataset = new StatisticalReferenceDataset(in) {
-
-                @Override
-                public double getModelValue(final double x, final double[] a) {
-                    final double p = a[0] + x * (a[1] + x * (a[2] + x * a[3]));
-                    final double q = 1.0 + x * (a[4] + x * (a[5] + x * a[6]));
-                    return p / q;
-                }
-
-                @Override
-                public double[] getModelDerivatives(final double x,
-                                                    final double[] a) {
-                    final double[] dy = new double[7];
-                    final double p = a[0] + x * (a[1] + x * (a[2] + x * a[3]));
-                    final double q = 1.0 + x * (a[4] + x * (a[5] + x * a[6]));
-                    dy[0] = 1.0 / q;
-                    dy[1] = x * dy[0];
-                    dy[2] = x * dy[1];
-                    dy[3] = x * dy[2];
-                    dy[4] = -x * p / (q * q);
-                    dy[5] = x * dy[4];
-                    dy[6] = x * dy[5];
-                    return dy;
-                }
-            };
-        } finally {
-            in.close();
-        }
-        return dataset;
-    }
-
-    public static StatisticalReferenceDataset createMGH17()
-        throws IOException {
-        final BufferedReader in = createBufferedReaderFromResource("MGH17.dat");
-        StatisticalReferenceDataset dataset = null;
-        try {
-            dataset = new StatisticalReferenceDataset(in) {
-
-                @Override
-                public double getModelValue(final double x, final double[] a) {
-                    return a[0] + a[1] * FastMath.exp(-a[3] * x) + a[2] *
-                           FastMath.exp(-a[4] * x);
-                }
-
-                @Override
-                public double[] getModelDerivatives(final double x,
-                                                    final double[] a) {
-                    final double[] dy = new double[5];
-                    dy[0] = 1.0;
-                    dy[1] = FastMath.exp(-x * a[3]);
-                    dy[2] = FastMath.exp(-x * a[4]);
-                    dy[3] = -x * a[1] * dy[1];
-                    dy[4] = -x * a[2] * dy[2];
-                    return dy;
-                }
-            };
-        } finally {
-            in.close();
-        }
-        return dataset;
-    }
-
-    public static StatisticalReferenceDataset createLanczos1()
-        throws IOException {
-        final BufferedReader in =
-            createBufferedReaderFromResource("Lanczos1.dat");
-        StatisticalReferenceDataset dataset = null;
-        try {
-            dataset = new StatisticalReferenceDataset(in) {
-
-                @Override
-                public double getModelValue(final double x, final double[] a) {
-                    System.out.println(a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]);
-                    return a[0] * FastMath.exp(-a[3] * x) +
-                           a[1] * FastMath.exp(-a[4] * x) +
-                           a[2] * FastMath.exp(-a[5] * x);
-                }
-
-                @Override
-                public double[] getModelDerivatives(final double x,
-                    final double[] a) {
-                    final double[] dy = new double[6];
-                    dy[0] = FastMath.exp(-x * a[3]);
-                    dy[1] = FastMath.exp(-x * a[4]);
-                    dy[2] = FastMath.exp(-x * a[5]);
-                    dy[3] = -x * a[0] * dy[0];
-                    dy[4] = -x * a[1] * dy[1];
-                    dy[5] = -x * a[2] * dy[2];
-                    return dy;
-                }
-            };
-        } finally {
-            in.close();
-        }
-        return dataset;
-    }
-
-    /**
-     * Returns an array with all available reference datasets.
-     *
-     * @return the array of datasets
-     * @throws IOException if an I/O error occurs
-     */
-    public StatisticalReferenceDataset[] createAll()
-        throws IOException {
-        return new StatisticalReferenceDataset[] {
-            createKirby2(), createMGH17()
-        };
-    }
-}

http://git-wip-us.apache.org/repos/asf/commons-math/blob/e31fde87/src/test/java/org/apache/commons/math4/optim/nonlinear/vector/jacobian/StraightLineProblem.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/optim/nonlinear/vector/jacobian/StraightLineProblem.java
b/src/test/java/org/apache/commons/math4/optim/nonlinear/vector/jacobian/StraightLineProblem.java
deleted file mode 100644
index e93c604..0000000
--- a/src/test/java/org/apache/commons/math4/optim/nonlinear/vector/jacobian/StraightLineProblem.java
+++ /dev/null
@@ -1,169 +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.optim.nonlinear.vector.jacobian;
-
-import java.util.ArrayList;
-
-import org.apache.commons.math4.analysis.MultivariateMatrixFunction;
-import org.apache.commons.math4.analysis.MultivariateVectorFunction;
-import org.apache.commons.math4.analysis.UnivariateFunction;
-import org.apache.commons.math4.optim.nonlinear.vector.ModelFunction;
-import org.apache.commons.math4.optim.nonlinear.vector.ModelFunctionJacobian;
-import org.apache.commons.math4.stat.regression.SimpleRegression;
-
-/**
- * Class that models a straight line defined as {@code y = a x + b}.
- * The parameters of problem are:
- * <ul>
- *  <li>{@code a}</li>
- *  <li>{@code b}</li>
- * </ul>
- * The model functions are:
- * <ul>
- *  <li>for each pair (a, b), the y-coordinate of the line.</li>
- * </ul>
- */
-@Deprecated
-class StraightLineProblem {
-    /** Cloud of points assumed to be fitted by a straight line. */
-    private final ArrayList<double[]> points;
-    /** Error (on the y-coordinate of the points). */
-    private final double sigma;
-
-    /**
-     * @param error Assumed error for the y-coordinate.
-     */
-    public StraightLineProblem(double error) {
-        points = new ArrayList<double[]>();
-        sigma = error;
-    }
-
-    public void addPoint(double px, double py) {
-        points.add(new double[] { px, py });
-    }
-
-    /**
-     * @return the list of x-coordinates.
-     */
-    public double[] x() {
-        final double[] v = new double[points.size()];
-        for (int i = 0; i < points.size(); i++) {
-            final double[] p = points.get(i);
-            v[i] = p[0]; // x-coordinate.
-        }
-
-        return v;
-    }
-
-    /**
-     * @return the list of y-coordinates.
-     */
-    public double[] y() {
-        final double[] v = new double[points.size()];
-        for (int i = 0; i < points.size(); i++) {
-            final double[] p = points.get(i);
-            v[i] = p[1]; // y-coordinate.
-        }
-
-        return v;
-    }
-
-    public double[] target() {
-        return y();
-    }
-
-    public double[] weight() {
-        final double weight = 1 / (sigma * sigma);
-        final double[] w = new double[points.size()];
-        for (int i = 0; i < points.size(); i++) {
-            w[i] = weight;
-        }
-
-        return w;
-    }
-
-    public ModelFunction getModelFunction() {
-        return new ModelFunction(new MultivariateVectorFunction() {
-                public double[] value(double[] params) {
-                    final Model line = new Model(params[0], params[1]);
-
-                    final double[] model = new double[points.size()];
-                    for (int i = 0; i < points.size(); i++) {
-                        final double[] p = points.get(i);
-                        model[i] = line.value(p[0]);
-                    }
-
-                    return model;
-                }
-            });
-    }
-
-    public ModelFunctionJacobian getModelFunctionJacobian() {
-        return new ModelFunctionJacobian(new MultivariateMatrixFunction() {
-                public double[][] value(double[] point) {
-                    return jacobian(point);
-                }
-            });
-    }
-
-    /**
-     * Directly solve the linear problem, using the {@link SimpleRegression}
-     * class.
-     */
-    public double[] solve() {
-        final SimpleRegression regress = new SimpleRegression(true);
-        for (double[] d : points) {
-            regress.addData(d[0], d[1]);
-        }
-
-        final double[] result = { regress.getSlope(), regress.getIntercept() };
-        return result;
-    }
-
-    private double[][] jacobian(double[] params) {
-        final double[][] jacobian = new double[points.size()][2];
-
-        for (int i = 0; i < points.size(); i++) {
-            final double[] p = points.get(i);
-            // Partial derivative wrt "a".
-            jacobian[i][0] = p[0];
-            // Partial derivative wrt "b".
-            jacobian[i][1] = 1;
-        }
-
-        return jacobian;
-    }
-
-    /**
-     * Linear function.
-     */
-    public static class Model implements UnivariateFunction {
-        final double a;
-        final double b;
-
-        public Model(double a,
-                     double b) {
-            this.a = a;
-            this.b = b;
-        }
-
-        public double value(double x) {
-            return a * x + b;
-        }
-    }
-}


Mime
View raw message