Package org.apache.commons.math3.fitting
Class PolynomialCurveFitter
- java.lang.Object
-
- org.apache.commons.math3.fitting.AbstractCurveFitter
-
- org.apache.commons.math3.fitting.PolynomialCurveFitter
-
public class PolynomialCurveFitter extends AbstractCurveFitter
Fits points to apolynomialfunction.
The size of theinitial guessarray defines the degree of the polynomial to be fitted. They must be sorted in increasing order of the polynomial's degree. The optimal values of the coefficients will be returned in the same order.- Since:
- 3.3
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.commons.math3.fitting.AbstractCurveFitter
AbstractCurveFitter.TheoreticalValuesFunction
-
-
Field Summary
Fields Modifier and Type Field Description private static PolynomialFunction.ParametricFUNCTIONParametric function to be fitted.private double[]initialGuessInitial guess.private intmaxIterMaximum number of iterations of the optimization algorithm.
-
Constructor Summary
Constructors Modifier Constructor Description privatePolynomialCurveFitter(double[] initialGuess, int maxIter)Contructor used by the factory methods.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static PolynomialCurveFittercreate(int degree)Creates a default curve fitter.protected LeastSquaresProblemgetProblem(java.util.Collection<WeightedObservedPoint> observations)Creates a least squares problem corresponding to the appropriate curve.PolynomialCurveFitterwithMaxIterations(int newMaxIter)Configure the maximum number of iterations.PolynomialCurveFitterwithStartPoint(double[] newStart)Configure the start point (initial guess).-
Methods inherited from class org.apache.commons.math3.fitting.AbstractCurveFitter
fit, getOptimizer
-
-
-
-
Field Detail
-
FUNCTION
private static final PolynomialFunction.Parametric FUNCTION
Parametric function to be fitted.
-
initialGuess
private final double[] initialGuess
Initial guess.
-
maxIter
private final int maxIter
Maximum number of iterations of the optimization algorithm.
-
-
Constructor Detail
-
PolynomialCurveFitter
private PolynomialCurveFitter(double[] initialGuess, int maxIter)Contructor used by the factory methods.- Parameters:
initialGuess- Initial guess.maxIter- Maximum number of iterations of the optimization algorithm.- Throws:
MathInternalError- ifinitialGuessisnull.
-
-
Method Detail
-
create
public static PolynomialCurveFitter create(int degree)
Creates a default curve fitter. Zero will be used as initial guess for the coefficients, and the maximum number of iterations of the optimization algorithm is set toInteger.MAX_VALUE.- Parameters:
degree- Degree of the polynomial to be fitted.- Returns:
- a curve fitter.
- See Also:
withStartPoint(double[]),withMaxIterations(int)
-
withStartPoint
public PolynomialCurveFitter withStartPoint(double[] newStart)
Configure the start point (initial guess).- Parameters:
newStart- new start point (initial guess)- Returns:
- a new instance.
-
withMaxIterations
public PolynomialCurveFitter withMaxIterations(int newMaxIter)
Configure the maximum number of iterations.- Parameters:
newMaxIter- maximum number of iterations- Returns:
- a new instance.
-
getProblem
protected LeastSquaresProblem getProblem(java.util.Collection<WeightedObservedPoint> observations)
Creates a least squares problem corresponding to the appropriate curve.- Specified by:
getProblemin classAbstractCurveFitter- Parameters:
observations- Sample points.- Returns:
- the least squares problem to use for fitting the curve to the
given
points.
-
-