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

public Class CurveFitter<T extends ParametricUnivariateFunction>

extends Object
Class Inheritance
Known Direct Subclasses
org.apache.commons.math3.fitting.GaussianFitter, org.apache.commons.math3.fitting.HarmonicFitter, org.apache.commons.math3.fitting.PolynomialFitter
Annotations
@Deprecated
Type Parameters
<T>
Function to use for the fit.
Imports
java.util.ArrayList, .List, org.apache.commons.math3.analysis.MultivariateVectorFunction, .MultivariateMatrixFunction, .ParametricUnivariateFunction, org.apache.commons.math3.optim.MaxEval, .InitialGuess, .PointVectorValuePair, org.apache.commons.math3.optim.nonlinear.vector.MultivariateVectorOptimizer, .ModelFunction, .ModelFunctionJacobian, .Target, .Weight

Deprecated

As of 3.3. Please use AbstractCurveFitter and WeightedObservedPoints instead.

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

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
CurveFitter.TheoreticalValuesFunction

Vectorial function computing function theoretical values.

Field Summary

Modifier and TypeField and Description
private final List<WeightedObservedPoint>
observations

Observed points.

private final MultivariateVectorOptimizer
optimizer

Deprecated as a consequence of MultivariateVectorOptimizer being deprecated.
Optimizer to use for the fitting.

Constructor Summary

AccessConstructor and Description
public
CurveFitter(final MultivariateVectorOptimizer
Optimizer to use for the fitting.
optimizer
)
Deprecated as a consequence of MultivariateVectorOptimizer being deprecated.

Simple constructor.

Method Summary

Modifier and TypeMethod and Description
public void
addObservedPoint(double
abscissa of the point
x
,
double
observed value of the point at x, after fitting we should have f(x) as close as possible to this value
y
)

Add an observed (x,y) point to the sample with unit weight.

public void
addObservedPoint(double
weight of the observed point in the fit
weight
,
double
abscissa of the point
x
,
double
observed value of the point at x, after fitting we should have f(x) as close as possible to this value
y
)

Add an observed weighted (x,y) point to the sample.

public void
addObservedPoint(WeightedObservedPoint
observed point to add
observed
)

Add an observed weighted (x,y) point to the sample.

public void
clearObservations()

Remove all observations.

public double[]

Returns:

the fitted parameters.
fit
(T
parametric function to fit.
f
,
final double[]
first guess of the function parameters.
initialGuess
)

Fit a curve.

public double[]

Returns:

the fitted parameters.
fit
(int
Maximum number of function evaluations.
maxEval
,
T
parametric function to fit.
f
,
final double[]
first guess of the function parameters.
initialGuess
)

Fit a curve.

public WeightedObservedPoint[]

Returns:

observed points
getObservations
()

Get the observed points.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

observationsback to summary
private final List<WeightedObservedPoint> observations

Observed points.

optimizerback to summary
private final MultivariateVectorOptimizer optimizer

Deprecated

as a consequence of MultivariateVectorOptimizer being deprecated. See corresponding docs for further information.

Optimizer to use for the fitting.

Constructor Detail

CurveFitterback to summary
public CurveFitter(final MultivariateVectorOptimizer optimizer)

Deprecated

as a consequence of MultivariateVectorOptimizer being deprecated. See corresponding docs for further information.

Simple constructor.

Parameters
optimizer:MultivariateVectorOptimizer

Optimizer to use for the fitting.

Since
3.1

Method Detail

addObservedPointback to summary
public void addObservedPoint(double x, double y)

Add an observed (x,y) point to the sample with unit weight.

Calling this method is equivalent to call addObservedPoint(1.0, x, y).

Parameters
x:double

abscissa of the point

y:double

observed value of the point at x, after fitting we should have f(x) as close as possible to this value

See Also
addObservedPoint(double, double, double), addObservedPoint(WeightedObservedPoint), getObservations()
addObservedPointback to summary
public void addObservedPoint(double weight, double x, double y)

Add an observed weighted (x,y) point to the sample.

Parameters
weight:double

weight of the observed point in the fit

x:double

abscissa of the point

y:double

observed value of the point at x, after fitting we should have f(x) as close as possible to this value

See Also
addObservedPoint(double, double), addObservedPoint(WeightedObservedPoint), getObservations()
addObservedPointback to summary
public void addObservedPoint(WeightedObservedPoint observed)

Add an observed weighted (x,y) point to the sample.

Parameters
observed:WeightedObservedPoint

observed point to add

See Also
addObservedPoint(double, double), addObservedPoint(double, double, double), getObservations()
clearObservationsback to summary
public void clearObservations()

Remove all observations.

fitback to summary
public double[] fit(T f, final 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:T

parametric function to fit.

initialGuess:double[]

first guess of the function parameters.

Returns:double[]

the fitted parameters.

Exceptions
DimensionMismatchException:
if the start point dimension is wrong.
fitback to summary
public double[] fit(int maxEval, T f, final 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
maxEval:int

Maximum number of function evaluations.

f:T

parametric function to fit.

initialGuess:double[]

first guess of the function parameters.

Returns:double[]

the fitted parameters.

Exceptions
TooManyEvaluationsException:
if the number of allowed evaluations is exceeded.
DimensionMismatchException:
if the start point dimension is wrong.
Since
3.0
getObservationsback to summary
public WeightedObservedPoint[] getObservations()

Get the observed points.

Returns:WeightedObservedPoint[]

observed points

See Also
addObservedPoint(double, double), addObservedPoint(double, double, double), addObservedPoint(WeightedObservedPoint)
org.apache.commons.math3.fitting back to summary

private Class CurveFitter.TheoreticalValuesFunction

extends Object
Class Inheritance
  • java.lang.Object
  • org.apache.commons.math3.fitting.CurveFitter.TheoreticalValuesFunction

Vectorial function computing function theoretical values.

Field Summary

Modifier and TypeField and Description
private final ParametricUnivariateFunction
f

Function to fit.

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public ModelFunction

Returns:

the model function values.
getModelFunction
()
Deprecated as a consequence of ModelFunction being deprecated.

public ModelFunctionJacobian

Returns:

the model function Jacobian.
getModelFunctionJacobian
()
Deprecated as a consequence of ModelFunctionJacobian being deprecated.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

fback to summary
private final ParametricUnivariateFunction f

Function to fit.

Constructor Detail

TheoreticalValuesFunctionback to summary
pack-priv TheoreticalValuesFunction(final ParametricUnivariateFunction f)
Parameters
f:ParametricUnivariateFunction

function to fit.

Method Detail

getModelFunctionback to summary
public ModelFunction getModelFunction()

Deprecated

as a consequence of ModelFunction being deprecated. See corresponding docs for further information.

Returns:ModelFunction

the model function values.

getModelFunctionJacobianback to summary
public ModelFunctionJacobian getModelFunctionJacobian()

Deprecated

as a consequence of ModelFunctionJacobian being deprecated. See corresponding docs for further information.

Returns:ModelFunctionJacobian

the model function Jacobian.