scipy
Routines¶
Fitter¶
lsqfit
uses routines from the open-source scipy
Python module
provided it is installed. These routines are used in place of GSL routines
if the latter are not installed. There is one fitter available for use by
lsqfit.nonlinear_fit
.
- class lsqfit.scipy_least_squares(x0, n, f, tol=(1e-08, 1e-08, 1e-08), maxit=1000, **extra_args)¶
scipy
fitter for nonlinear least-squares multidimensional fits.scipy_least_squares
is a function-class whose constructor does a least-squares fit by minimizingsum_i f_i(x)**2
as a function of vectorx
.scipy_least_squares
is a wrapper for thescipy.optimize.least_squares
.- Parameters:
x0 (array of floats) – Starting point for minimization.
n (positive int) – Length of vector returned by the fit function
f(x)
.f (array-valued function) –
sum_i f_i(x)**2
is minimized by varying parametersx
. The parameters are a 1-dnumpy
array of either numbers orgvar.GVar
s.tol (float or tuple) –
Assigning
tol=(xtol, gtol, ftol)
causes the fit to stop searching for a minimum when any ofxtol >=
relative change in parameters between iterationsgtol >=
relative size of gradient ofchi**2
ftol >=
relative change inchi**2
between iterationsis statisfied. See the
scipy.optimize.least_squares
documentation detailed definitions of the stopping conditions. Typically one setsxtol=1/10**d
whered
is the number of digits of precision desired in the result, whilegtol<<1
andftol<<1
. Settingtol=eps
whereeps
is a number is equivalent to settingtol=(eps,1e-10,1e-10)
. Settingtol=(eps1,eps2)
is equivlent to settingtol=(eps1,eps2,1e-10)
. Default istol=1e-5
.method (str or None) –
Minimization algorithm. Options include:
'trf'
Trusted Region Reflective algorithm (default). Best choice with bounded parameters.
'dogbox'
dogleg algorithm adapted for bounded parameters.
'lm'
Levenberg-Marquardt algorithm as implemented in MINPACK. Best for smaller problems. Does not work with bounded parameters (bounds are ignored).
Setting
method=None
implies the default'trf'
.maxit (int) – Maximum number of function evaluations in search for minimum; default is 1000.
Other arguments include:
x_jac
,loss
,tr_solver
,f_scale
,tr_options
,bounds
. See the documentation forscipy.optimize.least_squares
for information about these and other options.lsqfit.scipy_least_squares
objects have the following attributes.- x¶
Location of the most recently computed (best) fit point.
- Type:
array
- cov¶
Covariance matrix at the minimum point.
- Type:
array
- description¶
Short description of internal fitter settings.
- Type:
str
- f¶
Fit function value
f(x)
at the minimum in the most recent fit.- Type:
array
- J¶
Gradient
J_ij = df_i/dx[j]
for most recent fit.- Type:
array
- nit¶
Number of function evaluations used in last fit to find the minimum.
- Type:
int
- stopping_criterion¶
Criterion used to stop fit:
didn’t converge
xtol >=
relative change in parameters between iterationsgtol >=
relative size of gradient ofchi**2
ftol >=
relative change inchi**2
between iterations
- Type:
int
- error¶
None
if fit successful; an error message otherwise.- Type:
str or None
- results¶
Results returned by
scipy.optimize.least_squares
.- Type:
dict
Minimizer¶
The lsqfit.empbayes_fit()
uses a minimizer from the scipy
module to minimize logGBF
.
- class lsqfit.scipy_multiminex(x0, f, tol=1e-4, maxit=1000, step=1, alg='nmsimplex2', analyzer=None)¶
scipy
minimizer for multidimensional functions.scipy_multiminex
is a function-class whose constructor minimizes a multidimensional functionf(x)
by varying vectorx
. This routine does not use user-supplied information about the gradient off(x)
.scipy_multiminex
is a wrapper for theminimize
scipy
function. It gives access to only part of that function.- Parameters:
x0 (array of floats) – Starting point for minimization search.
f – Function
f(x)
to be minimized by varying vectorx
.tol (float) – Minimization stops when
x
has converged to with tolerancetol
; default is1e-4
.maxit (positive int) – Maximum number of iterations in search for minimum; default is 1000.
analyzer (function) – Optional function of the current
x
. This can be used to inspect intermediate steps in the minimization, if needed.step (bool) – Included for consistency with GSL routines but ignored in
scipy
routine.
lsqfit.scipy_multiminex
objects have the following attributes.- x¶
Location of the minimum.
- Type:
array
- f¶
Value of function
f(x)
at the minimum.- Type:
float
- nit¶
Number of iterations required to find the minimum.
- Type:
int
- error¶
None
if fit successful; an error message otherwise.- Type:
Noe or str