Top Description Fields Constructors Methods
org.apache.commons.math3.fitting

public Class PolynomialCurveFitter

extends AbstractCurveFitter
Class Inheritance
Imports
java.util.Collection, org.apache.commons.math3.analysis.polynomials.PolynomialFunction, org.apache.commons.math3.exception.MathInternalError, org.apache.commons.math3.fitting.leastsquares.LeastSquaresBuilder, .LeastSquaresProblem, org.apache.commons.math3.linear.DiagonalMatrix

Fits points to a polynomial function.
The size of the initial guess array 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

Field Summary

Modifier and TypeField and Description
private static final PolynomialFunction.Parametric
FUNCTION

Parametric function to be fitted.

private final double[]
initialGuess

Initial guess.

private final int
maxIter

Maximum number of iterations of the optimization algorithm.

Constructor Summary

AccessConstructor and Description
private
PolynomialCurveFitter(double[]
Initial guess.
initialGuess
,
int
Maximum number of iterations of the optimization algorithm.
maxIter
)

Contructor used by the factory methods.

Method Summary

Modifier and TypeMethod and Description
public static PolynomialCurveFitter

Returns:

a curve fitter.
create
(int
Degree of the polynomial to be fitted.
degree
)

Creates a default curve fitter.

protected LeastSquaresProblem
getProblem(Collection<WeightedObservedPoint>
Sample points.
observations
)

Implements abstract org.apache.commons.math3.fitting.AbstractCurveFitter.getProblem.

Creates a least squares problem corresponding to the appropriate curve.

public PolynomialCurveFitter

Returns:

a new instance.
withMaxIterations
(int
maximum number of iterations
newMaxIter
)

Configure the maximum number of iterations.

public PolynomialCurveFitter

Returns:

a new instance.
withStartPoint
(double[]
new start point (initial guess)
newStart
)

Configure the start point (initial guess).

Inherited from org.apache.commons.math3.fitting.AbstractCurveFitter:
fitgetOptimizer

Field Detail

FUNCTIONback to summary
private static final PolynomialFunction.Parametric FUNCTION

Parametric function to be fitted.

initialGuessback to summary
private final double[] initialGuess

Initial guess.

maxIterback to summary
private final int maxIter

Maximum number of iterations of the optimization algorithm.

Constructor Detail

PolynomialCurveFitterback to summary
private PolynomialCurveFitter(double[] initialGuess, int maxIter)

Contructor used by the factory methods.

Parameters
initialGuess:double[]

Initial guess.

maxIter:int

Maximum number of iterations of the optimization algorithm.

Exceptions
MathInternalError:
if initialGuess is null.

Method Detail

createback to summary
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 to Integer#MAX_VALUE.

Parameters
degree:int

Degree of the polynomial to be fitted.

Returns:PolynomialCurveFitter

a curve fitter.

See Also
withStartPoint(double[]), withMaxIterations(int)
getProblemback to summary
protected LeastSquaresProblem getProblem(Collection<WeightedObservedPoint> observations)

Implements abstract org.apache.commons.math3.fitting.AbstractCurveFitter.getProblem.

Doc from org.apache.commons.math3.fitting.AbstractCurveFitter.getProblem.

Creates a least squares problem corresponding to the appropriate curve.

Parameters
observations:Collection<WeightedObservedPoint>

Sample points.

Returns:LeastSquaresProblem

the least squares problem to use for fitting the curve to the given points.

Annotations
@Override
withMaxIterationsback to summary
public PolynomialCurveFitter withMaxIterations(int newMaxIter)

Configure the maximum number of iterations.

Parameters
newMaxIter:int

maximum number of iterations

Returns:PolynomialCurveFitter

a new instance.

withStartPointback to summary
public PolynomialCurveFitter withStartPoint(double[] newStart)

Configure the start point (initial guess).

Parameters
newStart:double[]

new start point (initial guess)

Returns:PolynomialCurveFitter

a new instance.