scipy 1.8.0 Pypi GitHub Homepage
Other Docs
NotesParametersReturnsBackRef
leastsq(func, x0, args=(), Dfun=None, full_output=0, col_deriv=0, ftol=1.49012e-08, xtol=1.49012e-08, gtol=0.0, maxfev=0, epsfcn=None, factor=100, diag=None)
x = arg min(sum(func(y)**2,axis=0))
         y

Notes

"leastsq" is a wrapper around MINPACK's lmdif and lmder algorithms.

cov_x is a Jacobian approximation to the Hessian of the least squares objective function. This approximation assumes that the objective function is based on the difference between some observed target data (ydata) and a (non-linear) function of the parameters :None:None:`f(xdata, params)` :

func(params) = ydata - f(xdata, params)

so that the objective function is :

  min   sum((ydata - f(xdata, params))**2, axis=0)
params

The solution, x, is always a 1-D array, regardless of the shape of :None:None:`x0`, or whether :None:None:`x0` is a scalar.

Parameters

func : callable

Should take at least one (possibly length N vector) argument and returns M floating point numbers. It must not return NaNs or fitting might fail. M must be greater than or equal to N .

x0 : ndarray

The starting estimate for the minimization.

args : tuple, optional

Any extra arguments to func are placed in this tuple.

Dfun : callable, optional

A function or method to compute the Jacobian of func with derivatives across the rows. If this is None, the Jacobian will be estimated.

full_output : bool, optional

non-zero to return all optional outputs.

col_deriv : bool, optional

non-zero to specify that the Jacobian function computes derivatives down the columns (faster, because there is no transpose operation).

ftol : float, optional

Relative error desired in the sum of squares.

xtol : float, optional

Relative error desired in the approximate solution.

gtol : float, optional

Orthogonality desired between the function vector and the columns of the Jacobian.

maxfev : int, optional

The maximum number of calls to the function. If :None:None:`Dfun` is provided, then the default :None:None:`maxfev` is 100*(N+1) where N is the number of elements in x0, otherwise the default :None:None:`maxfev` is 200*(N+1).

epsfcn : float, optional

A variable used in determining a suitable step length for the forward- difference approximation of the Jacobian (for Dfun=None). Normally the actual step length will be sqrt(epsfcn)*x If epsfcn is less than the machine precision, it is assumed that the relative errors are of the order of the machine precision.

factor : float, optional

A parameter determining the initial step bound ( factor * || diag * x|| ). Should be in interval (0.1, 100) .

diag : sequence, optional

N positive entries that serve as a scale factors for the variables.

Returns

x : ndarray

The solution (or the result of the last iteration for an unsuccessful call).

cov_x : ndarray

The inverse of the Hessian. :None:None:`fjac` and :None:None:`ipvt` are used to construct an estimate of the Hessian. A value of None indicates a singular matrix, which means the curvature in parameters x is numerically flat. To obtain the covariance matrix of the parameters x, :None:None:`cov_x` must be multiplied by the variance of the residuals -- see curve_fit.

infodict : dict

a dictionary of optional outputs with the keys:

nfev

The number of function calls

fvec

The function evaluated at the output

fjac

A permutation of the R matrix of a QR factorization of the final approximate Jacobian matrix, stored column wise. Together with ipvt, the covariance of the estimate can be approximated.

ipvt

An integer array of length N which defines a permutation matrix, p, such that fjac*p = q*r, where r is upper triangular with diagonal elements of nonincreasing magnitude. Column j of p is column ipvt(j) of the identity matrix.

qtf

The vector (transpose(q) * fvec).

mesg : str

A string message giving information about the cause of failure.

ier : int

An integer flag. If it is equal to 1, 2, 3 or 4, the solution was found. Otherwise, the solution was not found. In either case, the optional output variable 'mesg' gives more information.

Minimize the sum of squares of a set of equations.

See Also

least_squares

Newer interface to solve nonlinear least-squares problems with bounds on the variables. See method=='lm' in particular.

Examples

>>> from scipy.optimize import leastsq
... def func(x):
...  return 2*(x-3)**2+1
... leastsq(func, 0) (array([2.99999999]), 1)
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

scipy.optimize._minpack_py.leastsq scipy.optimize._minpack_py.curve_fit

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /scipy/optimize/_minpack_py.py#279
type: <class 'function'>
Commit: