class Fitter( BaseFitter ) | Source |
---|
Fitter for linear models.
The Fitter class is to be used in conjunction with Model classes.
The Fitter class and its descendants fit data to a model. Fitter itself is the variant for linear models, ie. models linear in its parameters.
Examples
# assume x and y are numpy.asarray data arrays
x = numpy.arange( 100 )
y = numpy.arange( 100 ) // 4 # digitization noise
poly = PolynomialModel( 1 ) # line
fitter = Fitter( x, poly )
param = fitter.fit( y )
stdev = fitter.stdevs # stdevs on the parameters
chisq = fitter.chisq
scale = fitter.scale # noise scale
yfit = fitter.getResult( ) # fitted values
yfit = poly( x ) # same as previous
yband = fitter.monteCarloError( ) # 1 sigma confidence region
Limitations
- The Fitter does not work with limits.
- The calculation of the evidence is an Gaussian approximation which is
only exact for linear models with a fixed scale.
Author Do Kester
Fitter( xdata, model, map=False, keep=None, fixedScale=None ) |
---|
Create a new Fitter, providing xdatas and model.
A Fitter class is defined by its model and the input vector (the independent variable). When a fit to another model and/or another input vector is needed a new object should be created.
Parameters
- xdata : array_like
array of independent input values - model : Model
the model function to be fitted - map : bool (False)
When true, the xdata should be interpreted as a map.
The fitting is done on the pixel indices of the map,
using ImageAssistant - keep : dict of {int:float}
dictionary of indices (int) to be kept at a fixed value (float)
The values of keep will be used by the Fitter as long as the Fitter exists.
See alsofit( ..., keep=dict )
- fixedScale : float
the fixed noise scale
fit( ydata, weights=None, accuracy=None, keep=None, plot=False ) |
---|
For Linear models the matrix equation
H * p = β
is solved for p. H is the Hessian matrix ( D * w * DT ) and β is the inproduct of the data with the D, design matrix.
β = y * w * DT
Parameters
- ydata : array_like
the data vector to be fitted - weights : array_like
weights pertaining to the data ( = 1.0 / sigma^2 ) - accuracy : float or array_like
accuracy of (individual) data - keep : dict of {int:float}
dictionary of indices (int) to be kept at a fixed value (float)
The values will override those at initialization.
They are only used in this call of fit. - plot : bool
Plot the results
Raises
ValueError when ydata or weights contain a NaN
Methods inherited from BaseFitter |
---|
- setMinimumScale( scale=0 )
- fitprolog( ydata, weights=None, accuracy=None, keep=None )
- fitpostscript( ydata, plot=False )
- keepFixed( keep=None )
- insertParameters( fitpar, index=None, into=None )
- modelFit( ydata, weights=None, keep=None )
- limitsFit( ydata, weights=None, keep=None )
- checkNan( ydata, weights=None, accuracy=None )
- getVector( ydata, index=None )
- getHessian( params=None, weights=None, index=None )
- getInverseHessian( params=None, weights=None, index=None )
- getCovarianceMatrix( )
- makeVariance( scale=None )
- normalize( normdfdp, normdata, weight=1.0 )
- getDesign( params=None, xdata=None, index=None )
- chiSquared( ydata, params=None, weights=None )
- getStandardDeviations( )
- monteCarloError( xdata=None, monteCarlo=None)
- getScale( )
- getEvidence( limits=None, noiseLimits=None )
- getLogLikelihood( autoscale=False, var=1.0 )
- getLogZ( limits=None, noiseLimits=None )
- plotResult( xdata=None, ydata=None, model=None, residuals=True,