Class PolynomialFitter
java.lang.Object
org.apache.commons.math.optimization.fitting.PolynomialFitter
This class implements a curve fitting specialized for polynomials.
Polynomial fitting is a very simple case of curve fitting. The estimated coefficients are the polynomial coefficients. They are searched by a least square estimator.
- Since:
- 2.0
-
Constructor Summary
ConstructorsConstructorDescriptionPolynomialFitter(int degree, DifferentiableMultivariateVectorialOptimizer optimizer) Simple constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddObservedPoint(double weight, double x, double y) Add an observed weighted (x,y) point to the sample.voidRemove all observations.fit()Get the polynomial fitting the weighted (x, y) points.
-
Constructor Details
-
PolynomialFitter
Simple constructor.The polynomial fitter built this way are complete polynomials, ie. a n-degree polynomial has n+1 coefficients.
- Parameters:
degree- maximal degree of the polynomialoptimizer- optimizer to use for the fitting
-
-
Method Details
-
addObservedPoint
public void addObservedPoint(double weight, double x, double y) Add an observed weighted (x,y) point to the sample.- Parameters:
weight- weight of the observed point in the fitx- abscissa of the pointy- observed value of the point at x, after fitting we should have P(x) as close as possible to this value
-
clearObservations
public void clearObservations()Remove all observations.- Since:
- 2.2
-
fit
Get the polynomial fitting the weighted (x, y) points.- Returns:
- polynomial function best fitting the observed points
- Throws:
OptimizationException- if the algorithm failed to converge
-