QRFitter = class QRFitter(BaseFitter) |
|
QRFitter(xdata, model, map=False, keep=None)
Fitter for linear models, using QR decomposition.
The QRFitter class is to be used in conjunction with Model classes, linear
in its parameters.
For Linear models the matrix equation
H * p = β
is solved for p. H is the Hessian matrix ( D * w * D^T )
and β is the inproduct of the data with the D, design matrix.
β = y * w * D^T
The QRFitter class use QR decomposition which effectively is an inversion
of the hessian matrix such that
p = β * inverse( H )
It can be more efficient if
similar ydata needs to be fitter to the same model and xdata.
In that case it uses the same decomposition for all fits.
Examples
--------
# assume x and y are numpy.asarray data arrays:
>>> x = numpy.asarray.range( 100 )
>>> poly = PolynomialModel( 1 ) # line
>>> fitter = QRFitter( x, poly )
>>> for k in range( 1, 4 ) :
>>> y = numpy.arange( 100 ) // k # digitization noise
>>> param = fitter.fit( y ) # use same QR decomposition
>>> stdev = fitter.stdevs # stdevs on the parameters
>>> print( k, param )
>>> print( " ", stdev )
Category: Mathematics/Fitting
Attributes
----------
needsNewDecomposition : bool
True when starting. Thereafter False,
i.e. the previous QR-decomposition is used, unless weights are used.
Only for linear fitters, setting it to false might improve efficiency.
It only works properly when the model, the x-data etc are exactly the
same in the previous run.
Whenever weights are used, it always needs a new decomposition.
qrmat : matrix
matrix formed by q * inverse( r ), where q,r is the QR decomposition
of the design matrix.
qrmat is to be multiplied with the data vector to get the solution. |
|
- Method resolution order:
- QRFitter
- BaseFitter
- builtins.object
Constructor:
- QRFitter( xdata, model, map=False, keep=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 also `fit( ..., keep=dict )`
Methods defined here:
- fit( ydata, weights=None, accuracy=None, keep=None )
- Return model parameters fitted to the data, including weights.
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.
Raises
------
ValueError when ydata or weights contain a NaN
Methods inherited from BaseFitter:
- checkNan( ydata, weights=None, accuracy=None )
- chiSquared( ydata, params=None, weights=None )
- fitpostscript( ydata, plot=False )
- fitprolog( ydata, weights=None, accuracy=None, keep=None )
- getCovarianceMatrix()
- getDesign( params=None, xdata=None, index=None )
- getEvidence( limits=None, noiseLimits=None )
- getHessian( params=None, weights=None, index=None )
- getInverseHessian( params=None, weights=None, index=None )
- getLogLikelihood( autoscale=False, var=1.0)
- getLogZ( limits=None, noiseLimits=None )
- getScale()
- getStandardDeviations()
- getVector( ydata, index=None )
- insertParameters( fitpar, index=None, into=None )
- keepFixed( keep=None )
- limitsFit( fitmethod, ydata, weights=None, keep=None )
- makeVariance( scale=None )
- modelFit( ydata, weights=None, keep=None )
- monteCarloError( xdata=None, monteCarlo=None )
- normalize( normdfdp, normdata, weight=1.0)
- plotResult( xdata=None, ydata=None, model=None, residuals=True, confidence=False, show=True )
- setMinimumScale( scale=0)
|
|