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 * @since 2.0 028 * @deprecated As of 3.3. Please use {@link PolynomialCurveFitter} and 029 * {@link WeightedObservedPoints} instead. 030 */ 031@Deprecated 032public class PolynomialFitter extends CurveFitter<PolynomialFunction.Parametric> { 033 /** 034 * Simple constructor. 035 * 036 * @param optimizer Optimizer to use for the fitting. 037 */ 038 public PolynomialFitter(MultivariateVectorOptimizer optimizer) { 039 super(optimizer); 040 } 041 042 /** 043 * Get the coefficients of the polynomial fitting the weighted data points. 044 * The degree of the fitting polynomial is {@code guess.length - 1}. 045 * 046 * @param guess First guess for the coefficients. They must be sorted in 047 * increasing order of the polynomial's degree. 048 * @param maxEval Maximum number of evaluations of the polynomial. 049 * @return the coefficients of the polynomial that best fits the observed points. 050 * @throws org.apache.commons.math3.exception.TooManyEvaluationsException if 051 * the number of evaluations exceeds {@code maxEval}. 052 * @throws org.apache.commons.math3.exception.ConvergenceException 053 * if the algorithm failed to converge. 054 */ 055 public double[] fit(int maxEval, double[] guess) { 056 return fit(maxEval, new PolynomialFunction.Parametric(), guess); 057 } 058 059 /** 060 * Get the coefficients of the polynomial fitting the weighted data points. 061 * The degree of the fitting polynomial is {@code guess.length - 1}. 062 * 063 * @param guess First guess for the coefficients. They must be sorted in 064 * increasing order of the polynomial's degree. 065 * @return the coefficients of the polynomial that best fits the observed points. 066 * @throws org.apache.commons.math3.exception.ConvergenceException 067 * if the algorithm failed to converge. 068 */ 069 public double[] fit(double[] guess) { 070 return fit(new PolynomialFunction.Parametric(), guess); 071 } 072}