001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.math3.fitting;
018
019import org.apache.commons.math3.analysis.polynomials.PolynomialFunction;
020import org.apache.commons.math3.optim.nonlinear.vector.MultivariateVectorOptimizer;
021
022/**
023 * Polynomial fitting is a very simple case of {@link CurveFitter curve fitting}.
024 * The estimated coefficients are the polynomial coefficients (see the
025 * {@link #fit(double[]) fit} method).
026 *
027 * @version $Id: PolynomialFitter.java 1416643 2012-12-03 19:37:14Z tn $
028 * @since 2.0
029 * @deprecated As of 3.3. Please use {@link PolynomialCurveFitter} and
030 * {@link WeightedObservedPoints} instead.
031 */
032@Deprecated
033public class PolynomialFitter extends CurveFitter<PolynomialFunction.Parametric> {
034    /**
035     * Simple constructor.
036     *
037     * @param optimizer Optimizer to use for the fitting.
038     */
039    public PolynomialFitter(MultivariateVectorOptimizer optimizer) {
040        super(optimizer);
041    }
042
043    /**
044     * Get the coefficients of the polynomial fitting the weighted data points.
045     * The degree of the fitting polynomial is {@code guess.length - 1}.
046     *
047     * @param guess First guess for the coefficients. They must be sorted in
048     * increasing order of the polynomial's degree.
049     * @param maxEval Maximum number of evaluations of the polynomial.
050     * @return the coefficients of the polynomial that best fits the observed points.
051     * @throws org.apache.commons.math3.exception.TooManyEvaluationsException if
052     * the number of evaluations exceeds {@code maxEval}.
053     * @throws org.apache.commons.math3.exception.ConvergenceException
054     * if the algorithm failed to converge.
055     */
056    public double[] fit(int maxEval, double[] guess) {
057        return fit(maxEval, new PolynomialFunction.Parametric(), guess);
058    }
059
060    /**
061     * Get the coefficients of the polynomial fitting the weighted data points.
062     * The degree of the fitting polynomial is {@code guess.length - 1}.
063     *
064     * @param guess First guess for the coefficients. They must be sorted in
065     * increasing order of the polynomial's degree.
066     * @return the coefficients of the polynomial that best fits the observed points.
067     * @throws org.apache.commons.math3.exception.ConvergenceException
068     * if the algorithm failed to converge.
069     */
070    public double[] fit(double[] guess) {
071        return fit(new PolynomialFunction.Parametric(), guess);
072    }
073}