## ij.measure Class CurveFitter

```java.lang.Object
ij.measure.CurveFitter
```

`public class CurveFitterextends 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` `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()`
SD = sqrt(sum of residuals squared / number of params+1)
` double` `getSumResidualsSqr()`

` 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`
Constant Field Values

### POLY2

`public static final int POLY2`
Constant Field Values

### POLY3

`public static final int POLY3`
Constant Field Values

### POLY4

`public static final int POLY4`
Constant Field Values

### EXPONENTIAL

`public static final int EXPONENTIAL`
Constant Field Values

### POWER

`public static final int POWER`
Constant Field Values

### LOG

`public static final int LOG`
Constant Field Values

### RODBARD

`public static final int RODBARD`
Constant Field Values

### GAMMA_VARIATE

`public static final int GAMMA_VARIATE`
Constant Field Values

### LOG2

`public static final int LOG2`
Constant Field Values

### RODBARD2

`public static final int RODBARD2`
Constant Field Values

### IterFactor

`public static final int IterFactor`
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()`
SD = sqrt(sum of residuals squared / number of params+1)

### 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

### getMax

`public static int getMax(double[] array)`
Gets index of highest value in an array.

Parameters:
`Double` - array.
Returns:
Index of highest value.