LevMar¶
-
class
decida.LevMar.
LevMar
(function, parobj, dataobj, **kwargs)¶ Bases:
decida.ItclObjectx.ItclObjectx
synopsis:
Levenberg-Marquardt linear least-squares minimization.
LevMar performs linear least-squares minimization. It is used to fit a specified model equation set to data, by adjusting parameter values in the equation set. LevMar uses the Parameters class to manage the parameter set.
LevMar is adapted from the mpfit module, which is based on MINPACK-1. The document strings from mpfit, and the MINPACK-1 source-code are referenced at the bottom of this page. These are more detailed than the documentation shown here.
LevMar is still under development.
The Fitter class is a wrapper around LevMar, which makes its use somewhat easier.
constructor arguments:
function (function)
A function which includes the model to fit. The required arguments to function are a Parameters object and a Data object. Each used parameter current value is available by indexing the Parameters object by the parameter name. The Data object must contain a column with the data points to be fit: the data column is specified by the “meast_col” configuration option to LevMar. The function generates a model column and an error column.parobj (Parameters object handle)
The Parameters object which manages the parameter values.dataobj (Data object handle)
The Data object which manages the measurement, model, and error values.**kwargs (dict)
keyword=value specifications: configuration-optionsconfiguration options:
debug (bool, default=False)
enable debug mode, which prints out more information during minimization.quiet (bool, default=False)
disable printing of information during minimization.meast_col (str, default=””)
The data column which contains the data to be fitted.model_col (str, default=””)
The data column which is to be created to fit the meast_col data.error_col (str, default=””)
The relative or absolute error between the model_col and meast_col data.ftol (float, default=1e_10)
Relative sum-of-squares error tolerance for convergence.xtol (float, default=1e_10)
Relative approximate solution error tolerance for convergence.gtol (float, default=1e_10)
Minimum value of the gradient norm: measure of the orthogonality between parameter Jacobian and function for convergence.maxiter (int, default=200)
Maximum number of Levenberg-Marquardt iterations.factor (float, default=100.0)
Parameter-step scaling factor.damp (float, default=0.0)
Parameter-step damping factor.nprint (int, default=1)
Number of iterations to skip before printing information.iterfunct (function, default=None)
Specify a different iteration function to print values of the parameters at each Levenberg-Marquart iteration. The required parameters of the iteration function are:
parobj
The Parameters object handle.iter
The iteration number.fnorm2
The current sum-of-squares norm.Other parameters are passed as keyword=value pairs, specified in the iterkw configuration option.
iterkw (dict, default={})
Keyword options for the user-defined iteration function.nocovar (bool, default=False)
Disable covarianace calculation (if performed in user function).fastnorm (bool, default=False)
Use a faster calculation of error norma.rescale (bool, default=False)
Use the tuple specified in the diag configuration option to rescale.autoderiv (bool, default=True)
If True, compute Jacobian numerically.diag (tuple, default=None)
Set of values to rescale error.epsfcn (float, default=None)
Used to determine numerical derivative step.example (from test_LevMar):
from decida.LevMar import LevMar from decida.Parameters import Parameters from decida.Data import Data def lcfunc(parobj, dataobj): L = parobj["L"] Co = parobj["Co"] Cu = parobj["Cu"] C1 = parobj["C1"] C2 = parobj["C2"] a2 = C2*16.0 c2 = (C2-C1)*8.0 b2 = (C2-C1)*24.0 dataobj.set("Cc = (floor(vc/4.0)+fmod(vc,4)*0.25)*$Cu") dataobj.set("Cf = $a2 - $b2*vf + $c2*vf^2") dataobj.set("Ct = $Co + Cc + Cf") dataobj.set("fhat = 1.0/(2*pi*sqrt($L*Ct))") dataobj.set("residual = fhat - freq") parobj = Parameters(specs=( ("L" , 2400e-12, False, True, False, 0.0, 0.0), ("Co", 250e-15, True, True, False, 0.0, 0.0), ("Cu", 60e-15, True, True, False, 0.0, 0.0), ("C1", 23e-15, True, True, False, 0.0, 0.0), ("C2", 27e-15, True, True, False, 0.0, 0.0), )) dataobj = Data() dataobj.read("lcdata.col") optobj = LevMar(lcfunc, parobj, dataobj, meast_col="freq", model_col="fhat", error_col="residual", quiet=False, debug=False ) optobj.fit() print(optobj.status()) print("parameters = ", parobj.values())
public methods:
- public methods from ItclObjectx
-
fit
()¶ fit model to data.
results:
- Fits model to specified data.
-
status
()¶ return optimizer status.
results:
- Returns the optimizer status message.
more documentation: