Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## ij.measure
Class CurveFitter

    java.lang.Object
      ij.measure.CurveFitter

public class CurveFitter
extends java.lang.Object

Curve fitting class based on the Simplex method described in the article "Fitting Curves to Data" in the May 1984 issue of Byte magazine, pages 340-362. 2001/02/14: Midified to handle a gamma variate curve. Uses altered Simplex method based on method in "Numerical Recipes in C". This method tends to converge closer in less iterations. Has the option to restart the simplex at the initial best solution in case it is "stuck" in a local minimum (by default, restarted once). Also includes settings dialog option for user control over simplex parameters and functions to evaluate the goodness-of-fit. The results can be easily reported with the getResultString() method.

Version:
  1.0
Author:
  Kieran Holland (email: holki659@student.otago.ac.nz)

Field Summary
`static int` | `EXP_WITH_OFFSET`
`static int` | `EXPONENTIAL`
`static java.lang.String[]` | `fitList`
`static java.lang.String[]` | `fList`
`static int` | `GAMMA_VARIATE`
`static int` | `IterFactor`
`static int` | `LOG`
`static int` | `LOG2`
`static int` | `POLY2`
`static int` | `POLY3`
`static int` | `POLY4`
`static int` | `POWER`
`static int` | `RODBARD`
`static int` | `RODBARD2`
`static int` | `STRAIGHT_LINE`

Constructor Summary
`CurveFitter(double[] xData, double[] yData)` Construct a new CurveFitter.

Method Summary
`void` | `doFit(int fitType)` Perform curve fitting with the simplex method doFit(fitType) just does the fit doFit(fitType, true) pops up a dialog allowing control over simplex parameters alpha is reflection coefficient (-1) beta is contraction coefficient (0.5) gamma is expansion coefficient (2)
`void` | `doFit(int fitType, boolean showSettings)`
`static double` | `f(int fit, double[] p, double x)` Returns "fit" function value for parameters "p" at "x"
`double` | `getFitGoodness()` Get a measure of "goodness of fit" where 1.0 is best.
`int` | `getIterations()` Get number of iterations performed
`static int` | `getMax(double[] array)` Gets index of highest value in an array.
`int` | `getMaxIterations()` Get maximum number of iterations allowed
`int` | `getNumParams()` Get number of parameters for current fit function
`double[]` | `getParams()` Get the set of parameter values from the best corner of the simplex
`double[]` | `getResiduals()` Returns residuals array ie.
`int` | `getRestarts()` Get number of simplex restarts to do
`java.lang.String` | `getResultString()` Get a string description of the curve fitting results for easy output.
`double` | `getRSquared()` Returns R^2, where 1.0 is best.
`double` | `getSD()` Returns the standard deviation of the residuals.
`double` | `getSumResidualsSqr()`
`void` | `setInitialParameters(double[] params)` Sets the initial parameters, which override the default initial parameters.
`void` | `setMaxIterations(int x)` Set maximum number of iterations allowed
`void` | `setRestarts(int x)` Set number of simplex restarts to do

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### STRAIGHT_LINE

    public static final int STRAIGHT_LINE

See Also:
  Constant Field Values

### POLY2

    public static final int POLY2

See Also:
  Constant Field Values

### POLY3

    public static final int POLY3

See Also:
  Constant Field Values

### POLY4

    public static final int POLY4

See Also:
  Constant Field Values

### EXPONENTIAL

    public static final int EXPONENTIAL

See Also:
  Constant Field Values

### POWER

    public static final int POWER

See Also:
  Constant Field Values

### LOG

    public static final int LOG

See Also:
  Constant Field Values

### RODBARD

    public static final int RODBARD

See Also:
  Constant Field Values

### GAMMA_VARIATE

    public static final int GAMMA_VARIATE

See Also:
  Constant Field Values

### LOG2

    public static final int LOG2

See Also:
  Constant Field Values

### RODBARD2

    public static final int RODBARD2

See Also:
  Constant Field Values

### EXP_WITH_OFFSET

    public static final int EXP_WITH_OFFSET

See Also:
  Constant Field Values

### IterFactor

    public static final int IterFactor

See Also:
  Constant Field Values

### fitList

    public static final java.lang.String[] fitList

### fList

    public static final java.lang.String[] fList

Constructor Detail

### CurveFitter

    public CurveFitter(double[] xData,
                       double[] yData)

  Construct a new CurveFitter.

Method Detail

### doFit

    public void doFit(int fitType)

  Perform curve fitting with the simplex method doFit(fitType) just does the fit doFit(fitType, true) pops up a dialog allowing control over simplex parameters alpha is reflection coefficient (-1) beta is contraction coefficient (0.5) gamma is expansion coefficient (2)

### doFit

    public void doFit(int fitType,
                      boolean showSettings)

### getNumParams

    public int getNumParams()

  Get number of parameters for current fit function

### f

    public static double f(int fit,
                           double[] p,
                           double x)

  Returns "fit" function value for parameters "p" at "x"

### getParams

    public double[] getParams()

  Get the set of parameter values from the best corner of the simplex

### getResiduals

    public double[] getResiduals()

  Returns residuals array ie. differences between data and curve.

### getSumResidualsSqr

    public double getSumResidualsSqr()

### getSD

    public double getSD()

  Returns the standard deviation of the residuals.

### getRSquared

    public double getRSquared()

  Returns R^2, where 1.0 is best.

           r^2 = 1 - SSE/SSD

           where:	 SSE = sum of the squares of the errors
                       SSD = sum of the squares of the deviations about the mean.

### getFitGoodness

    public double getFitGoodness()

  Get a measure of "goodness of fit" where 1.0 is best.

### getResultString

    public java.lang.String getResultString()

  Get a string description of the curve fitting results for easy output.

### getIterations

    public int getIterations()

  Get number of iterations performed

### getMaxIterations

    public int getMaxIterations()

  Get maximum number of iterations allowed

### setMaxIterations

    public void setMaxIterations(int x)

  Set maximum number of iterations allowed

### getRestarts

    public int getRestarts()

  Get number of simplex restarts to do

### setRestarts

    public void setRestarts(int x)

  Set number of simplex restarts to do

### setInitialParameters

    public void setInitialParameters(double[] params)

  Sets the initial parameters, which override the default initial parameters.

### getMax

    public static int getMax(double[] array)

  Gets index of highest value in an array.

  Returns:
    Index of highest value.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD