fittheory: Fit theory definition

class silx.math.fit.fittheory.FitTheory(function, parameters, estimate=None, configure=None, derivative=None, config_widget=None, description=None, pymca_legacy=False)[source]

This class defines a fit theory, which consists of:

  • a model function, the actual function to be fitted
  • parameters names
  • an estimation function, that return the estimated initial parameters that serve as input for silx.math.fit.leastsq()
  • an optional configuration function, that can be used to modify configuration parameters to alter the behavior of the fit function and the estimation function
  • an optional derivative function, that replaces the default model derivative used in silx.math.fit.leastsq()
  • an optional configuration widget, that can be called for interactively modifying the configuration when running a fit from a GUI
function = None

The function must have the signature f(x, *params), where x is an array of values for the independent variable, and params are the parameters to be fitted.

The number of parameters must be the same as in parameters, or a multiple of this number if the function is defined as a sum of a variable number of base functions and if estimate is designed to be able to estimate the number of needed base functions.

parameters = None

List of parameters names.

This list can contain the minimum number of parameters, if the function takes a variable number of parameters, and if the estimation function is responsible for finding the number of required parameters

estimate = None

The estimation function should have the following signature:

f(x, y) -> (estimated_param, constraints)

Parameters:

  • x is a sequence of values for the independent variable
  • y is a sequence of the same length as x containing the data to be fitted

Return values:

  • estimated_param is a sequence of estimated fit parameters to be used as initial values for an iterative fit.
  • constraints is a sequence of shape (n, 3), where n is the number of estimated parameters, containing the constraints for each parameter to be fitted. See silx.math.fit.leastsq() for more explanations about constraints.
configure = None

The optional configuration function must conform to the signature f(**kw) -> dict (i.e it must accept any named argument and return a dictionary). It can be used to modify configuration parameters to alter the behavior of the fit function and the estimation function.

derivative = None

The optional derivative function must conform to the signature model_deriv(xdata, parameters, index), where parameters is a sequence with the current values of the fitting parameters, index is the fitting parameter index for which the the derivative has to be provided in the supplied array of xdata points.

config_widget = None

Optional configuration dialog widget that can allow users to modify the fit and estimation configuration.

This widget must store the modified configuration parameters in a dictionary attribute output.

The widget must define, or inherit from qt.QDialog, following methods which are executed in that order:

  • show()
  • exec_()
  • result(): must return True if the new configuration in config_widget.output is to be accepted, False if it is to be rejected / ignored (e.g. if the user clicked a Cancel button)
description = None

Optional description string for this particular fit theory.

pymca_legacy = None

This attribute can be set to True to indicate that the theory is a PyMca legacy theory.

This tells silx.math.fit.fitmanager that the signature of the estimate function is:

f(x, y, bg, xscaling, yscaling) -> (estimated_param, constraints)
default_estimate(x=None, y=None, bg=None)[source]

Default estimate function. Return an array of ones as the initial estimated parameters, and set all constraints to zero (FREE)

Previous topic

fitmanager: Fit functions manager

Next topic

fittheories: Fit theories for fitmanager

This Page