Home | Trees | Indices | Help |
---|
|
A minimizer class on the lmfit Python package, which provides a simple, flexible interface to non-linear least-squares optimization, or curve fitting. The package is build around the Levenberg-Marquardt algorithm of scipy, but 2 other minimizers: limited memory Broyden-Fletcher-Goldfarb-Shanno and simulated annealing are partly supported as well. For the Levenberg-Marquardt algorithm, the estimated uncertainties and correlation between fitted variables are calculated as well.
This minimizer finds the best parameters to fit a given Model or Function to a set of data. You only need to provide the Model and data. Weighted fitting is supported.
This minimizer uses the basic residual function:
residuals = ( data - model(x) ) * weights
If a more advanced residual functions is required, fx when working with multi dimentional data, the used can specify its own residual function in the provided Function or Model, or by setting the resfunc keyword. This residual function needs to be of the following call sign:
resfunc(synth, data, weights=None, errors=None, **kwargs)
A Function is basicaly a function together with a list of the parameters that is needs. In the internal representation the parameters are represented as a Parameters object. However, the user does not need to now how to handle this, and can just provided or retrieve the parameter values using arrays. Every fitting parameter are extensions of simple numerical variables with the following properties:
A Model is a combination of Functions with its own parameter set. The Functions are provided as a list, and a gamma function can be given to describe how the functions are combined. Methods to handle the parameters in a model are provided, but the user is recommended handle the parameters at Function level as the naming of the parameters changes at Model level.
|
|||
|
|||
Inherited from |
|||
Error determination | |||
---|---|---|---|
dict |
|
||
(array, array, 2d array) |
|
||
array or dict |
|
||
Plotting Functions | |||
|
|||
|
|||
|
|||
|
|||
|
|||
Advanced attributes | |||
|
|||
|
|||
|
|||
Internal Functions | |||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|
|||
Inherited from |
|
x.__init__(...) initializes x; see help(type(x)) for signature
|
Returns the confidence intervalls of the given parameters. This function uses the F-test method described below to calculate confidence intervalls. The sigma parameter describes which confidence level is required in percentage: sigma=0.654 corresponds with the standard 1 sigma level, 0.95 with 2 sigma and 0.997 with 3 sigma. The output is a dictionary containing for each parameter the lower and upper boundary of the asked confidence level. If short_output is True, an array of tupples is returned instead. When only one parameter is given, and short_output is True, only a tupple of the lower and upper boundary is returned. The confidence intervalls calculated with this function are stored in the Model or Function as well. F-testThe F-test is used to compare the null model, which is the best fit found by the minimizer, with an alternate model, where one of the parameters is fixed to a specific value. The value is changed util the differnce between chi2_0 and chi2_f can't be explained by the loss of a degree of freedom with a certain confidence. F = (chi2_f / chi2_0 - 1) * (N-P)/P_fix N is the number of data-points, P the number of parameter of the null model. P_fix is the number of fixed parameters (or to be more clear, the difference of number of parameters betweeen the null model and the alternate model). This method relies completely on the I(conf_interval) method of the lmfit package.
|
Calculates the confidence interval for 2 given parameters. Both the confidence interval calculated using the F-test method from the estimate_error method, and the normal chi squares can be obtained using the ctype keyword. The confidence intervall is returned as a grid, together with the x and y distribution of the parameters: (x-values, y-values, grid)
|
Use Monte-Carlo simulations to estimate the error of each parameter. In this approach each datapoint is perturbed by its error, and for each new dataset best fitting parameters are calculated. The MC error of a parameter is its deviation over all iterations (points). The errors supplied to this function will overwrite the errors already stored in this Minimizer. If however no errors are supplied, the already stored ones will be used. For now only symetric errors are supported. Currently all datapoints are considered to have a symetric gaussian distribution, but in future version more distributions will be supported. The MC errors are saved in the Model or Function supplied to this fitter, and can be returned as an array (short_output=True), or as a dictionary (short_output=False).
|
Plot the original data together with the best fit results. This method has some functionality to plot multi-dimensional data, but is limited to 2D data which it will plot consecutively allong the specified axis.
|
Plot the residuals of the best fit. This method has some functionality to plot multi-dimensional data, but is limited to 2D data which it will plot consecutively allong the specified axis.
|
Creates a basic plot with the fit results and corresponding residuals. This method has some functionality to plot multi-dimensional data, but is up till now limited to 2D data which it will plot consecutively allong the specified axis. Based on the plot_fit and plot_residuals functions
|
Plot the confidence interval for 2 given parameters. Both the confidence interval calculated using the F-test method from the estimate_error method, and the normal chi squares can be plotted using the type keyword. In case of chi2, the log10 of the chi squares is plotted to improve the clarity of the plot. Extra kwargs are passed to
|
Plot the convergence path of the results from grid_minimize stored in this minimizer. The start values of the two selected parameters are plotted conected to there final best fit values, while using a color coding for the chisqr value of the fit result.
|
set minimizer
|
set error
|
get minimizer grid
|
String representation of the Minimizer object
|
Home | Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Fri Mar 30 10:45:20 2018 | http://epydoc.sourceforge.net |