Fitting is done by nonlinear least-squares regression. You can provide an analytic derivative or let it do numerical derivatives.
Certain pathological curves, e.g. linear regression, must override this to prevent an invalid number of curves from being set. The rest of y'all can leave it be.
If the "Component"s already exist, they will be re-used. Typically, consumers in the GUI re-use the same curves tree
each time the params change.
fitters
class NLFitter:
__init__( self )
initParams( self, nParamToFit, param_0, param_1, ... )
nParamToFit
only this many params will be fit; the rest can be used as outputs; e.g. curve area in GaussFit.py
param_i
a tuple: (name, initial_val, min_val, max_val)
Subclasses must call this in their constructor.
initComponent( self, param )
param
a qubtree.Node containing one child per parameter.
Override in your subclass to set appropriate param values for a new component. See GaussFit.py for an example.
getEqn( self )
setParamsFromData( self )
Change the param vals in self.params (a qubtree.Node).
func( self, paramvals, x )
paramvals
a list of param vals for one component, in the order passed to initParams()
x
the x value at which to evaluate the function
You must override in your subclass. Calculates the function value of one component at x.
deriv( self, paramvals, x )
paramvals
a list of param vals for one component, in the order passed to initParams()
x
the x value at which to evaluate the derivatives
You must override in your subclass. Calculates the derivative of one component at x, w.r.t. each param. Returns a list in the same order as paramvals.
onFitDone( self )
promptOptions( self )
fit( self, maxIter, precision )
setNumComponents( self, n )
getNumComponents( self )
getParamList( self, component_i )
updateParamLists( self )
(for speed, they are stored and ordinarily not recomputed.)
useData( self, dataset )
Gives the fitter a data series to fit, then calls setParamsFromData.
dataset
a qubtree.Node with children "X" and "Y"
getCurves( self, curves )
The first "Component" is the sum of the rest, so there are getNumComponents() + 1 of them.
Each "Component" has data of length len(self.X).