next up previous contents_motif.gif
Next: 8 Description of all Up: 7.6 ScientificPython-2.4.5 Previous: 7.6.3 Scientific.Statistics.correlation

7.6.4 Scientific.Functions.LeastSquares

Description: General non-linear least-squares fit using the Levenberg-Marquardt algorithm and automatic derivatives. The parameter model specifies the function to be fitted. It will be called with two parameters: the first is a tuple containing all fit parameters, and the second is the first element of a data point (see below). The return value must be a number. Since automatic differentiation is used to obtain the derivatives with respect to the parameters, the function may only use the mathematical functions known to the module FirstDerivatives. The parameter parameter is a tuple of initial values for the fit parameters. The parameter data is a list of data points to which the model is to be fitted. Each data point is a tuple of length two or three. Its first element specifies the independent variables of the model. It is passed to the model function as its first parameter, but not used in any other way. The second element of each data point tuple is the number that the return value of the model function is supposed to match as well as possible. The third element (which defaults to 1.) is the statistical variance of the data point, i.e. the inverse of its statistical weight in the fitting procedure. The function returns a list containing the optimal parameter values and the chi-squared value describing the quality of the fit.

Example:
  >>> from Numeric import exp
  >>> def f(param, t):
  ...     return param[0]*exp(-param[1]/t)
  ...
  >>> data = [(100, 4.999e-8),(200, 5.307e+2),
    (300, 1.289e+6),(400, 6.559e+7)]
  >>> print leastSquaresFit(f, (1e13,4700), data)
  ([8641551709749.7666, 4715.4677901570467], 1080.2526437958597)


next up previous contents_motif.gif
Next: 8 Description of all Up: 7.6 ScientificPython-2.4.5 Previous: 7.6.3 Scientific.Statistics.correlation
Frank Bertoldi 2005-11-10