org.jscience.mathematics.analysis.fitting
Class AbstractCurveFitter

java.lang.Object
  extended by org.jscience.mathematics.analysis.fitting.AbstractCurveFitter
All Implemented Interfaces:
java.io.Serializable, EstimationProblem
Direct Known Subclasses:
HarmonicFitter, PolynomialFitter

public abstract class AbstractCurveFitter
extends java.lang.Object
implements EstimationProblem, java.io.Serializable

This class is the base class for all curve fitting classes in the package.

This class handles all common features of curve fitting like the sample points handling. It declares two methods (valueAt(double) and partial(double, org.jscience.mathematics.analysis.estimation.EstimatedParameter)) which should be implemented by sub-classes to define the precise shape of the curve they represent.

See Also:
Serialized Form

Nested Class Summary
 class AbstractCurveFitter.FitMeasurement
          This class represents the fit measurements.
 
Field Summary
protected  EstimatedParameter[] coefficients
          Coefficients of the function
protected  java.util.List measurements
          Measurements vector
 
Constructor Summary
protected AbstractCurveFitter(EstimatedParameter[] coefficients, int maxIterations, double convergence, double steadyStateThreshold, double epsilon)
          Simple constructor.
protected AbstractCurveFitter(int n, int maxIterations, double convergence, double steadyStateThreshold, double epsilon)
          Simple constructor.
 
Method Summary
 void addWeightedPair(double weight, double x, double y)
          Add a weighted (x,y) pair to the sample.
 double[] fit()
          Perform the fitting.
 EstimatedParameter[] getAllParameters()
          Get all the parameters of the problem.
 WeightedMeasurement[] getMeasurements()
          Get the measurements of an estimation problem.
 EstimatedParameter[] getUnboundParameters()
          Get the unbound parameters of the problem.
abstract  double partial(double x, EstimatedParameter p)
          Get the derivative of the function at x with respect to parameter p.
protected  void sortMeasurements()
          Utility method to sort the measurements with respect to the abscissa.
abstract  double valueAt(double x)
          Get the value of the function at x according to the current parameters value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

coefficients

protected EstimatedParameter[] coefficients
Coefficients of the function


measurements

protected java.util.List measurements
Measurements vector

Constructor Detail

AbstractCurveFitter

protected AbstractCurveFitter(int n,
                              int maxIterations,
                              double convergence,
                              double steadyStateThreshold,
                              double epsilon)
Simple constructor.

Parameters:
n - number of coefficients in the underlying function
maxIterations - maximum number of iterations allowed
convergence - criterion threshold below which we do not need to improve the criterion anymore
steadyStateThreshold - steady state detection threshold, the problem has reached a steady state (read converged) if Math.abs (Jn - Jn-1) < Jn * convergence, where Jn and Jn-1 are the current and preceding criterion value (square sum of the weighted residuals of considered measurements).
epsilon - threshold under which the matrix of the linearized problem is considered singular (see SquareMatrix.solve).

AbstractCurveFitter

protected AbstractCurveFitter(EstimatedParameter[] coefficients,
                              int maxIterations,
                              double convergence,
                              double steadyStateThreshold,
                              double epsilon)
Simple constructor.

Parameters:
coefficients - first estimate of the coefficients. A reference to this array is hold by the newly created object. Its elements will be adjusted during the fitting process and they will be set to the adjusted coefficients at the end.
maxIterations - maximum number of iterations allowed
convergence - criterion threshold below which we do not need to improve the criterion anymore
steadyStateThreshold - steady state detection threshold, the problem has reached a steady state (read converged) if Math.abs (Jn - Jn-1) < Jn * convergence, where Jn and Jn-1 are the current and preceding criterion value (square sum of the weighted residuals of considered measurements).
epsilon - threshold under which the matrix of the linearized problem is considered singular (see SquareMatrix.solve).
Method Detail

addWeightedPair

public void addWeightedPair(double weight,
                            double x,
                            double y)
Add a weighted (x,y) pair to the sample.

Parameters:
weight - weight of this pair in the fit
x - abscissa
y - ordinate, we have y = f (x)

fit

public double[] fit()
             throws EstimationException
Perform the fitting.

This method compute the coefficients of the curve that best fit the sample of weighted pairs previously given through calls to the addWeightedPair method.

Returns:
coefficients of the curve
Throws:
EstimationException - if the fitting is not possible (for example if the sample has to few independant points)

getMeasurements

public WeightedMeasurement[] getMeasurements()
Description copied from interface: EstimationProblem
Get the measurements of an estimation problem.

Specified by:
getMeasurements in interface EstimationProblem
Returns:
measurements

getUnboundParameters

public EstimatedParameter[] getUnboundParameters()
Get the unbound parameters of the problem. For a curve fitting, none of the function coefficient is bound.

Specified by:
getUnboundParameters in interface EstimationProblem
Returns:
unbound parameters

getAllParameters

public EstimatedParameter[] getAllParameters()
Get all the parameters of the problem.

Specified by:
getAllParameters in interface EstimationProblem
Returns:
parameters

sortMeasurements

protected void sortMeasurements()
Utility method to sort the measurements with respect to the abscissa.

This method is provided as a utility for derived classes. As an example, the HarmonicFitter class needs it in order to compute a first guess of the coefficients to initialize the estimation algorithm.


valueAt

public abstract double valueAt(double x)
Get the value of the function at x according to the current parameters value.

Parameters:
x - abscissa at which the theoretical value is requested
Returns:
theoretical value at x

partial

public abstract double partial(double x,
                               EstimatedParameter p)
Get the derivative of the function at x with respect to parameter p.

Parameters:
x - abscissa at which the partial derivative is requested
p - parameter with respect to which the derivative is requested
Returns:
partial derivative