org.apache.commons.math.optimization.fitting
Class PolynomialFitter

java.lang.Object
  extended by org.apache.commons.math.optimization.fitting.PolynomialFitter

public class PolynomialFitter
extends Object

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
Version:
$Revision: 1073270 $ $Date: 2011-02-22 10:19:27 +0100 (mar. 22 f??vr. 2011) $

Nested Class Summary
private static class PolynomialFitter.ParametricPolynomial
          Dedicated parametric polynomial class.
 
Field Summary
private  int degree
          Polynomial degree.
private  CurveFitter fitter
          Fitter for the coefficients.
 
Constructor Summary
PolynomialFitter(int degree, DifferentiableMultivariateVectorialOptimizer optimizer)
          Simple constructor.
 
Method Summary
 void addObservedPoint(double weight, double x, double y)
          Add an observed weighted (x,y) point to the sample.
 void clearObservations()
          Remove all observations.
 PolynomialFunction fit()
          Get the polynomial fitting the weighted (x, y) points.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fitter

private final CurveFitter fitter
Fitter for the coefficients.


degree

private final int degree
Polynomial degree.

Constructor Detail

PolynomialFitter

public PolynomialFitter(int degree,
                        DifferentiableMultivariateVectorialOptimizer optimizer)
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 polynomial
optimizer - optimizer to use for the fitting
Method Detail

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 fit
x - abscissa of the point
y - 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

public PolynomialFunction fit()
                       throws OptimizationException
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


Copyright (c) 2003-2013 Apache Software Foundation