bundles / scipy 1.17.1 / scipy / sparse / linalg / _isolve / lsmr / lsmr
function
scipy.sparse.linalg._isolve.lsmr:lsmr
Signature
def lsmr ( A , b , damp = 0.0 , atol = 1e-06 , btol = 1e-06 , conlim = 100000000.0 , maxiter = None , show = False , x0 = None ) Summary
Iterative solver for least-squares problems.
Extended Summary
lsmr solves the system of linear equations Ax = b. If the system is inconsistent, it solves the least-squares problem min ||b - Ax||_2. A is a rectangular matrix of dimension m-by-n, where all cases are allowed: m = n, m > n, or m < n. b is a vector of length m. The matrix A may be dense or sparse (usually sparse).
Parameters
A: {sparse array, ndarray, LinearOperator}Matrix A in the linear system. Alternatively,
Acan be a linear operator which can produceAxandA^H xusing, e.g.,scipy.sparse.linalg.LinearOperator.b: array_like, shape (m,)Vector
bin the linear system.damp: floatDamping factor for regularized least-squares. lsmr solves the regularized least-squares problem
min ||(b) - ( A )x|| ||(0) (damp*I) ||_2
where damp is a scalar. If damp is None or 0, the system is solved without regularization. Default is 0.
atol, btol: float, optionalStopping tolerances. lsmr continues iterations until a certain backward error estimate is smaller than some quantity depending on atol and btol. Let
r = b - Axbe the residual vector for the current approximate solutionx. IfAx = bseems to be consistent, lsmr terminates whennorm(r) <= atol * norm(A) * norm(x) + btol * norm(b). Otherwise, lsmr terminates whennorm(A^H r) <= atol * norm(A) * norm(r). If both tolerances are 1.0e-6 (default), the finalnorm(r)should be accurate to about 6 digits. (The finalxwill usually have fewer correct digits, depending oncond(A)and the size of LAMBDA.) Ifatolorbtolis None, a default value of 1.0e-6 will be used. Ideally, they should be estimates of the relative error in the entries ofAandbrespectively. For example, if the entries ofAhave 7 correct digits, setatol = 1e-7. This prevents the algorithm from doing unnecessary work beyond the uncertainty of the input data.conlim: float, optionallsmr terminates if an estimate of
cond(A)exceedsconlim. For compatible systemsAx = b, conlim could be as large as 1.0e+12 (say). For least-squares problems,conlimshould be less than 1.0e+8. Ifconlimis None, the default value is 1e+8. Maximum precision can be obtained by settingatol = btol = conlim = 0, but the number of iterations may then be excessive. Default is 1e8.maxiter: int, optionallsmr terminates if the number of iterations reaches
maxiter. The default ismaxiter = min(m, n). For ill-conditioned systems, a larger value ofmaxitermay be needed. Default is False.show: bool, optionalPrint iterations logs if
show=True. Default is False.x0: array_like, shape (n,), optionalInitial guess of
x, if None zeros are used. Default is None.
Returns
x: ndarray of floatLeast-square solution returned.
istop: intistop gives the reason for stopping
istop = 0 means x=0 is a solution. If x0 was given, then x=x0 is a solution. = 1 means x is an approximate solution to A@x = B, according to atol and btol. = 2 means x approximately solves the least-squares problem according to atol. = 3 means COND(A) seems to be greater than CONLIM. = 4 is the same as 1 with atol = btol = eps (machine precision) = 5 is the same as 2 with atol = eps. = 6 is the same as 3 with CONLIM = 1/eps. = 7 means ITN reached maxiter before the other stopping conditions were satisfied.
itn: intNumber of iterations used.
normr: floatnorm(b-Ax)normar: floatnorm(A^H (b - Ax))norma: floatnorm(A)conda: floatCondition number of A.
normx: floatnorm(x)
Notes
Examples
import numpy as np from scipy.sparse import csc_array from scipy.sparse.linalg import lsmr A = csc_array([[1., 0.], [1., 1.], [0., 1.]], dtype=float)✓
b = np.array([0., 0., 0.], dtype=float) x, istop, itn, normr = lsmr(A, b)[:4] istop x✓
b = np.array([1., 0., -1.], dtype=float) x, istop, itn, normr = lsmr(A, b)[:4] istop x itn normr✓
b = np.array([1., 0.01, -1.], dtype=float) x, istop, itn, normr = lsmr(A, b)[:4] istop✓
x A.dot(x)-b✗
normr
✓Aliases
-
scipy.sparse.linalg.lsmr