org.apache.commons.math3.optimization.fitting

## Class CurveFitter

• Direct Known Subclasses:
GaussianFitter, HarmonicFitter, PolynomialFitter

```public class CurveFitter
extends Object```
Fitter for parametric univariate real functions y = f(x).

When a univariate real function y = f(x) does depend on some unknown parameters p0, p1 ... pn-1, this class can be used to find these parameters. It does this by fitting the curve so it remains very close to a set of observed points (x0, y0), (x1, y1) ... (xk-1, yk-1). This fitting is done by finding the parameters values that minimizes the objective function ∑(yi-f(xi))2. This is really a least squares problem.

Since:
2.0
Version:
\$Id: CurveFitter.java 1244107 2012-02-14 16:17:55Z erans \$
• ### Constructor Summary

Constructors
Constructor and Description
`CurveFitter(DifferentiableMultivariateVectorOptimizer optimizer)`
Simple constructor.
• ### Method Summary

Methods
Modifier and Type Method and Description
`void` ```addObservedPoint(double x, double y)```
Add an observed (x,y) point to the sample with unit weight.
`void` ```addObservedPoint(double weight, double x, double y)```
Add an observed weighted (x,y) point to the sample.
`void` `addObservedPoint(WeightedObservedPoint observed)`
Add an observed weighted (x,y) point to the sample.
`void` `clearObservations()`
Remove all observations.
`double[]` ```fit(int maxEval, ParametricUnivariateFunction f, double[] initialGuess)```
Fit a curve.
`double[]` ```fit(ParametricUnivariateFunction f, double[] initialGuess)```
Fit a curve.
`WeightedObservedPoint[]` `getObservations()`
Get the observed points.
• ### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`
• ### Constructor Detail

• #### CurveFitter

`public CurveFitter(DifferentiableMultivariateVectorOptimizer optimizer)`
Simple constructor.
Parameters:
`optimizer` - optimizer to use for the fitting
• ### Method Detail

• #### clearObservations

`public void clearObservations()`
Remove all observations.
• #### fit

```public double[] fit(ParametricUnivariateFunction f,
double[] initialGuess)```
Fit a curve. This method compute the coefficients of the curve that best fit the sample of observed points previously given through calls to the `addObservedPoint` method.
Parameters:
`f` - parametric function to fit.
`initialGuess` - first guess of the function parameters.
Returns:
the fitted parameters.
Throws:
`DimensionMismatchException` - if the start point dimension is wrong.
• #### fit

```public double[] fit(int maxEval,
ParametricUnivariateFunction f,
double[] initialGuess)```
Fit a curve. This method compute the coefficients of the curve that best fit the sample of observed points previously given through calls to the `addObservedPoint` method.
Parameters:
`f` - parametric function to fit.
`initialGuess` - first guess of the function parameters.
`maxEval` - Maximum number of function evaluations.
Returns:
the fitted parameters.
Throws:
`TooManyEvaluationsException` - if the number of allowed evaluations is exceeded.
`DimensionMismatchException` - if the start point dimension is wrong.
Since:
3.0