dwvisser.analysis
Class NonLinearFit
java.lang.Object
|
+--dwvisser.analysis.NonLinearFit
- Direct Known Subclasses:
- GaussianFit
- public abstract class NonLinearFit
- extends java.lang.Object
This abstract class uses LevenbergMarquadt to do non-linear parametric function fitting.
An actual class should define additional parameters and add them to parameters
,
It should implement estimate()
, valueAt()
, and derivative().
- Version:
- 0.5, 8/28/98
- Author:
- Dale Visser
- See Also:
valueAt(double)
,
derivative(double, java.lang.String)
,
Fit
,
LevenbergMarquadt
,
GaussianFit
,
Fit#estimate
Field Summary |
protected Parameter |
chisq
the calculated reduced chi-squared statistic |
protected double[] |
counts
The histogram to be fitted. |
protected double[] |
errors
The errors associatied with counts . |
protected LevenbergMarquadt |
lm
does the actual matrix algebra to find the best fit |
protected int |
maxCH
the int value of hi |
protected int |
minCH
the int value of lo |
Constructor Summary |
NonLinearFit(double[] spectrum,
double[] errors,
int minCh,
int maxCh)
Class constructor. |
Method Summary |
protected void |
addParameter(Parameter newParameter)
Makes a parameterTable from parameters . |
double |
calculate(int channel)
Calculate function value for specific channel in the histogram. |
abstract double |
derivative(double x,
java.lang.String parameterName)
Evaluates derivative with respect to parameterName at x . |
java.lang.String |
doFit()
Perform fit calulation and return a status String . |
abstract void |
estimate()
Estimate parameters for which the user requests estimation. |
Parameter |
getParameter(java.lang.String which)
Allows access to parameters by name for modification. |
double |
p(java.lang.String which)
Returns double value of parameter indicated by name. |
void |
setParameter(java.lang.String which,
double value)
Set a parameter designated by name to a new value. |
abstract double |
valueAt(double x)
Evaluates at x for given parameters. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
counts
protected double[] counts
- The histogram to be fitted.
errors
protected double[] errors
- The errors associatied with
counts
.
lm
protected LevenbergMarquadt lm
- does the actual matrix algebra to find the best fit
chisq
protected Parameter chisq
- the calculated reduced chi-squared statistic
minCH
protected int minCH
- the
int
value of lo
maxCH
protected int maxCH
- the
int
value of hi
NonLinearFit
public NonLinearFit(double[] spectrum,
double[] errors,
int minCh,
int maxCh)
- Class constructor. This is still an abstract class. Specific subclass constructors
will call this before executing their own constructors.
addParameter
protected void addParameter(Parameter newParameter)
- Makes a
parameterTable
from parameters
.
- See Also:
#parameterTable
,
#parameters
estimate
public abstract void estimate()
throws FitException
- Estimate parameters for which the user requests estimation. Unnecessary to implement, but very useful since
good guesses are usually needed to find the fit.
- Throws:
FitException
- thrown if unrecoverable error occurs during estimation
valueAt
public abstract double valueAt(double x)
- Evaluates at x for given parameters.
- Parameters:
x
- value at which to evaluate the fit function
- Returns:
- value of fit function at
x
derivative
public abstract double derivative(double x,
java.lang.String parameterName)
- Evaluates derivative with respect to
parameterName
at x
.
- Parameters:
parameterName
- the name of the parameter to differentiate with respect tox
- value to evalueate at
- Returns:
- df(
x
)/d(parameterName
) at x
doFit
public java.lang.String doFit()
throws FitException
- Perform fit calulation and return a status
String
.
Calls LevenbergMarquadt
several times, which determines changes in
parameter values likely to reduce chi-squared. When reductions are no longer significant,
it stops. If there is no covergence, it stops after 10 iterations.
- Returns:
- message with number of iterations and degrees of freedom to fit
- Throws:
FitException
- thrown if unrecoverable error occurs during fit
p
public double p(java.lang.String which)
- Returns
double
value of parameter indicated by name.
- Parameters:
which
- the name of the parameter
- Returns:
- the current value of the parameter
setParameter
public void setParameter(java.lang.String which,
double value)
throws FitException
- Set a parameter designated by name to a new value.
- Parameters:
which
- the name of the parametervalue
- the value to assign
- Throws:
FitException
- thrown if unrecoverable error occurs
getParameter
public Parameter getParameter(java.lang.String which)
- Allows access to parameters by name for modification.
- Parameters:
which
- the name of the parameter
- Returns:
- the
Parameter
object
calculate
public double calculate(int channel)
- Calculate function value for specific channel in the histogram.
- Parameters:
channel
- the channel to evaluate the function at
- Returns:
- the value of the function at
channel