[英]Scipy Linear algebra LinearOperator function utilised in Conjugate Gradient
I am preconditioning a matrix using spilu, however, to pass this preconditioner into cg (the built in conjugate gradient method) it is necessary to use the LinearOperator function, can someone explain to me the parameter matvec, and why I need to use it. 我正在使用spilu预处理矩阵,但是,要将此预处理器传递到cg(内置共轭梯度方法)中,必须使用LinearOperator函数,有人可以向我解释参数matvec以及为什么需要使用它。 Below is my current code 下面是我当前的代码
Ainv=scla.spilu(A,drop_tol= 1e-7)
Ainv=scla.LinearOperator(Ainv.shape,matvec=Ainv)
scla.cg(A,b,maxiter=maxIterations, M = Ainv)
However this doesnt work and I am given the error TypeError: 'SuperLU' object is not callable. 但是,这不起作用,并且给我错误TypeError:'SuperLU'对象不可调用。 I have played around and tried 我玩了,尝试
Ainv=scla.LinearOperator(Ainv.shape,matvec=Ainv.solve)
instead. 代替。 This seems to work but I want to know why matvec needs Ainv.solve rather than just Ainv, and is it the right thing to feed LinearOperator? 这似乎可行,但是我想知道为什么matvec需要Ainv.solve而不是仅Ainv,并且喂LinearOperator是正确的做法吗?
Thanks for your time 谢谢你的时间
Without having much experience with this part of scipy, some comments: 在没有这部分scipy经验的情况下,一些评论:
LinearOperator
, but you might do 根据文档,您不必使用LinearOperator
,但是您可以使用
M : {sparse matrix, dense matrix, LinearOperator}
, so you can use explicit matrices too! M : {sparse matrix, dense matrix, LinearOperator}
,因此您也可以使用显式矩阵! LinearOperator
: LinearOperator
的想法/优点:
Many iterative methods (eg cg, gmres) do not need to know the individual entries of a matrix to solve a linear system A*x=b. Such solvers only require the computation of matrix vector products
Many iterative methods (eg cg, gmres) do not need to know the individual entries of a matrix to solve a linear system A*x=b. Such solvers only require the computation of matrix vector products
docs Many iterative methods (eg cg, gmres) do not need to know the individual entries of a matrix to solve a linear system A*x=b. Such solvers only require the computation of matrix vector products
docs
solve()
here is not to form the inverse explicitly (which might be very costly) 不使用逆矩阵,而是 在此处 使用 solve()
的想法不是 显式地形成 逆矩阵 (这可能会非常昂贵)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.