LevMar

class sherpa.optmethods.LevMar(name: str = 'levmar', **kwargs)[source] [edit on github]

Bases: OptMethod

Levenberg-Marquardt optimization method.

The Levenberg-Marquardt method is an interface to the MINPACK subroutine lmdif to find the local minimum of nonlinear least squares functions of several variables by a modification of the Levenberg-Marquardt algorithm [1].

Attributes:
ftolnumber

The function tolerance to terminate the search for the minimum; the default is FLT_EPSILON ~ 1.19209289551e-07, where FLT_EPSILON is the smallest number x such that 1.0 != 1.0 + x. The conditions are satisfied when both the actual and predicted relative reductions in the sum of squares are, at most, ftol.

xtolnumber

The relative error desired in the approximate solution; default is FLT_EPSILON ~ 1.19209289551e-07, where FLT_EPSILON is the smallest number x such that 1.0 != 1.0 + x. The conditions are satisfied when the relative error between two consecutive iterates is, at most, xtol.

gtolnumber

The orthogonality desired between the function vector and the columns of the jacobian; default is FLT_EPSILON ~ 1.19209289551e-07, where FLT_EPSILON is the smallest number x such that 1.0 != 1.0 + x. The conditions are satisfied when the cosine of the angle between fvec and any column of the jacobian is, at most, gtol in absolute value.

maxfevint or None

The maximum number of function evaluations; the default value of None means to use 1024 * n, where n is the number of free parameters.

epsfcnnumber

This is used in determining a suitable step length for the forward-difference approximation; default is FLT_EPSILON ~ 1.19209289551e-07, where FLT_EPSILON is the smallest number x such that 1.0 != 1.0 + x. This approximation assumes that the relative errors in the functions are of the order of epsfcn. If epsfcn is less than the machine precision, it is assumed that the relative errors in the functions are of the order of the machine precision.

factorint

Used in determining the initial step bound; default is 100. The initial step bound is set to the product of factor and the euclidean norm of diag*x if nonzero, or else to factor itself. In most cases, factor should be from the interval (.1,100.).

numcoresint

The number of CPU cores to use. The default is 1.

verbose: int

The amount of information to print during the fit. The default is 0, which means no output.

Methods

fit(statfunc, pars, parmins, parmaxes[, ...])

Run the optimiser.

References

[1]

J.J. More, “The Levenberg Marquardt algorithm: implementation and theory,” in Lecture Notes in Mathematics 630: Numerical Analysis, G.A. Watson (Ed.), Springer-Verlag: Berlin, 1978, pp.105-116.

Attributes Summary

default_config

The default settings for the optimiser.

Methods Summary

fit(statfunc, pars, parmins, parmaxes[, ...])

Run the optimiser.

Attributes Documentation

default_config

The default settings for the optimiser.

Methods Documentation

fit(statfunc: Callable[[Sequence[float] | ndarray], tuple[float, ndarray]], pars: Sequence[float] | ndarray, parmins: Sequence[float] | ndarray, parmaxes: Sequence[float] | ndarray, statargs: Any = None, statkwargs: Any = None) tuple[bool, ndarray, float, str, dict[str, Any]] [edit on github]

Run the optimiser.

Changed in version 4.18.0: The statargs and statkwargs arguments are now ignored.

Changed in version 4.16.0: The statkwargs argument now defaults to None rather than {}.

Parameters:
statfuncfunction

Given a list of parameter values as the first argument and, as the remaining positional arguments, statargs and statkwargs as keyword arguments, return the statistic value.

parssequence

The start position of the model parameter values.

parminssequence

The minimum allowed values for each model parameter. This must match the length of pars.

parmaxessequence

The maximum allowed values for each model parameter. This must match the length of pars.

statargsoptional

This is currently unused.

statkwargsdict, optional

This is currently unused.

Returns:
newparstuple

The tuple contains: boolean indicating whether the optimization succeeded or not, the best fit parameters as a NumPy array, the statistic value at the best-fit location, a string message indicating the status, and a dictionary containing information about the optimisation (this depends on the optimiser).