public class CurveFitter
extends java.lang.Object
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.
Constructor and Description |
---|
CurveFitter(DifferentiableMultivariateVectorialOptimizer optimizer)
Simple constructor.
|
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(ParametricRealFunction f,
double[] initialGuess)
Fit a curve.
|
WeightedObservedPoint[] |
getObservations()
Get the observed points.
|
public CurveFitter(DifferentiableMultivariateVectorialOptimizer optimizer)
optimizer
- optimizer to use for the fittingpublic void addObservedPoint(double x, double y)
Calling this method is equivalent to call
addObservedPoint(1.0, x, y)
.
x
- abscissa of the pointy
- observed value of the point at x, after fitting we should
have f(x) as close as possible to this valueaddObservedPoint(double, double, double)
,
addObservedPoint(WeightedObservedPoint)
,
getObservations()
public void addObservedPoint(double weight, double x, double y)
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 f(x) as close as possible to this valueaddObservedPoint(double, double)
,
addObservedPoint(WeightedObservedPoint)
,
getObservations()
public void addObservedPoint(WeightedObservedPoint observed)
observed
- observed point to addaddObservedPoint(double, double)
,
addObservedPoint(double, double, double)
,
getObservations()
public WeightedObservedPoint[] getObservations()
addObservedPoint(double, double)
,
addObservedPoint(double, double, double)
,
addObservedPoint(WeightedObservedPoint)
public void clearObservations()
public double[] fit(ParametricRealFunction f, double[] initialGuess) throws FunctionEvaluationException, OptimizationException, java.lang.IllegalArgumentException
This method compute the coefficients of the curve that best
fit the sample of observed points previously given through calls
to the addObservedPoint
method.
f
- parametric function to fitinitialGuess
- first guess of the function parametersFunctionEvaluationException
- if the objective function throws one during the searchOptimizationException
- if the algorithm failed to convergejava.lang.IllegalArgumentException
- if the start point dimension is wrongCopyright © 2010 - 2020 Adobe. All Rights Reserved