PolynomialFitter.java

  1. /*
  2.  * Licensed to the Apache Software Foundation (ASF) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * The ASF licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *      http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.apache.commons.math3.fitting;

  18. import org.apache.commons.math3.analysis.polynomials.PolynomialFunction;
  19. import org.apache.commons.math3.optim.nonlinear.vector.MultivariateVectorOptimizer;

  20. /**
  21.  * Polynomial fitting is a very simple case of {@link CurveFitter curve fitting}.
  22.  * The estimated coefficients are the polynomial coefficients (see the
  23.  * {@link #fit(double[]) fit} method).
  24.  *
  25.  * @since 2.0
  26.  * @deprecated As of 3.3. Please use {@link PolynomialCurveFitter} and
  27.  * {@link WeightedObservedPoints} instead.
  28.  */
  29. @Deprecated
  30. public class PolynomialFitter extends CurveFitter<PolynomialFunction.Parametric> {
  31.     /**
  32.      * Simple constructor.
  33.      *
  34.      * @param optimizer Optimizer to use for the fitting.
  35.      */
  36.     public PolynomialFitter(MultivariateVectorOptimizer optimizer) {
  37.         super(optimizer);
  38.     }

  39.     /**
  40.      * Get the coefficients of the polynomial fitting the weighted data points.
  41.      * The degree of the fitting polynomial is {@code guess.length - 1}.
  42.      *
  43.      * @param guess First guess for the coefficients. They must be sorted in
  44.      * increasing order of the polynomial's degree.
  45.      * @param maxEval Maximum number of evaluations of the polynomial.
  46.      * @return the coefficients of the polynomial that best fits the observed points.
  47.      * @throws org.apache.commons.math3.exception.TooManyEvaluationsException if
  48.      * the number of evaluations exceeds {@code maxEval}.
  49.      * @throws org.apache.commons.math3.exception.ConvergenceException
  50.      * if the algorithm failed to converge.
  51.      */
  52.     public double[] fit(int maxEval, double[] guess) {
  53.         return fit(maxEval, new PolynomialFunction.Parametric(), guess);
  54.     }

  55.     /**
  56.      * Get the coefficients of the polynomial fitting the weighted data points.
  57.      * The degree of the fitting polynomial is {@code guess.length - 1}.
  58.      *
  59.      * @param guess First guess for the coefficients. They must be sorted in
  60.      * increasing order of the polynomial's degree.
  61.      * @return the coefficients of the polynomial that best fits the observed points.
  62.      * @throws org.apache.commons.math3.exception.ConvergenceException
  63.      * if the algorithm failed to converge.
  64.      */
  65.     public double[] fit(double[] guess) {
  66.         return fit(new PolynomialFunction.Parametric(), guess);
  67.     }
  68. }