scipy.sparse.linalg.lsmr

scipy.sparse.linalg.lsmr(A, b, damp=0.0, atol=1e-06, btol=1e-06, conlim=100000000.0, maxiter=None, show=False, x0=None)[源代码]

最小二乘问题的迭代求解器。

最小二乘法求解线性方程组。 Ax = b 。如果系统不一致,它就会解决最小二乘问题。 min ||b - Ax||_2A 是m×n维的矩形矩阵,其中允许所有情况:m=n、m>n或m<n。 b 是长度为m的向量。矩阵A可以是稠密的或稀疏的(通常是稀疏的)。

参数
A{稀疏矩阵,ndarray,LinearOperator}

线性系统中的矩阵A。或者, A 可以是线性运算符,它可以产生 AxA^H x 使用,例如, scipy.sparse.linalg.LinearOperator

b类似阵列,形状(m,)

矢量 b 在线性系统中。

damp浮动

正则化最小二乘法的阻尼因子。 lsmr 解决正则化最小二乘问题:

min ||(b) - (  A   )x||
    ||(0)   (damp*I) ||_2

其中DAMP是标量。如果DAMP为NONE或0,则无需正则化即可求解系统。默认值为0。

ATOL,BTOL浮动,可选

止动公差。 lsmr 继续迭代,直到取决于ATOL和BTOL的某个向后误差估计小于某个量。让我们 r = b - Ax 是当前近似解的残差向量 x 。如果 Ax = b 似乎是一致的, lsmr 在下列情况下终止 norm(r) <= atol * norm(A) * norm(x) + btol * norm(b) 。否则, lsmr 在下列情况下终止 norm(A^H r) <= atol * norm(A) * norm(r) 。如果两个公差均为1.0E-6(默认值),则最终 norm(r) 应该精确到6位左右。(决赛) x 通常会有较少的正确数字,具体取决于 cond(A) 和Lambda的大小。)如果 atolbtol 为None,则将使用默认值1.0E-6。理想情况下,它们应该是对以下条目中的相对误差的估计 Ab 分别为。例如,如果的条目 A 有7个正确的数字,设置 atol = 1e-7 。这可以防止算法在输入数据的不确定性之外进行不必要的工作。

conlim浮动,可选

lsmr 如果估计为 cond(A) 超过 conlim 。对于兼容的系统 Ax = b ,康利姆可以大到1.0E+12(比方说)。对于最小二乘问题, conlim 应小于1.0E+8。如果 conlim 为NONE,默认值为1e+8,最大精度可通过设置 atol = btol = conlim = 0 ,但是迭代次数可能会过多。默认值为1e8。

maxiter整型,可选

lsmr 如果迭代次数达到 maxiter 。默认值为 maxiter = min(m, n) 。对于状况不佳的系统,值较大的 maxiter 可能需要。默认值为False。

show布尔值,可选

如果出现以下情况,则打印迭代日志 show=True 。默认值为False。

x0ARRAY_LIKE,Shape(n,),可选

初步猜测 x ,如果没有使用零。默认值为None。

1.0.0 新版功能.

退货
xNdarray of Floor(浮子线)

返回了最小二乘解。

istop集成

istop给出了停止的原因::

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集成

使用的迭代次数。

normr浮动

norm(b-Ax)

normar浮动

norm(A^H (b - Ax))

norma浮动

norm(A)

conda浮动

A的条件数。

normx浮动

norm(x)

注意事项

0.11.0 新版功能.

参考文献

1

方东昌,M.A.Saunders,“LSMR:一种求解稀疏最小二乘问题的迭代算法”,SIAM J.Sci.计算机,卷。33,第2950-2971页,2011年。 arXiv:1006.0758

2

LSMR软件,https://web.stanford.edu/group/SOL/software/lsmr/

示例

>>> from scipy.sparse import csc_matrix
>>> from scipy.sparse.linalg import lsmr
>>> A = csc_matrix([[1., 0.], [1., 1.], [0., 1.]], dtype=float)

第一个示例具有平凡的解决方案 [0, 0]

>>> b = np.array([0., 0., 0.], dtype=float)
>>> x, istop, itn, normr = lsmr(A, b)[:4]
>>> istop
0
>>> x
array([0., 0.])

停止码 istop=0 RETURN表示找到了一个零向量作为解决方案。退回的解决方案 x 确实包含了 [0., 0.] 。下一个示例有一个非常重要的解决方案:

>>> b = np.array([1., 0., -1.], dtype=float)
>>> x, istop, itn, normr = lsmr(A, b)[:4]
>>> istop
1
>>> x
array([ 1., -1.])
>>> itn
1
>>> normr
4.440892098500627e-16

如图所示 istop=1lsmr 找到了符合容差限制的解决方案。给定的解决方案 [1., -1.] 显然是解了这个方程式。其余返回值包括有关迭代次数的信息 (itn=1 )和所解方程的左侧和右侧的剩余差。最后一个示例演示了方程没有解的情况下的行为:

>>> b = np.array([1., 0.01, -1.], dtype=float)
>>> x, istop, itn, normr = lsmr(A, b)[:4]
>>> istop
2
>>> x
array([ 1.00333333, -0.99666667])
>>> A.dot(x)-b
array([ 0.00333333, -0.00333333,  0.00333333])
>>> normr
0.005773502691896255

istop 指示系统不一致,因此 x 而是相应的最小二乘问题的近似解。 normr 包含找到的最小距离。