tfmri.linalg.conjugate_gradient
tfmri.linalg.conjugate_gradient¶
- conjugate_gradient(operator, rhs, preconditioner=None, x=None, tol=1e-05, max_iterations=20, bypass_gradient=False, name=None)[source]¶
Conjugate gradient solver.
Solves a linear system of equations \(Ax = b\) for self-adjoint, positive definite matrix \(A\) and right-hand side vector \(b\), using an iterative, matrix-free algorithm where the action of the matrix \(A\) is represented by
operator
. The iteration terminates when either the number of iterations exceedsmax_iterations
or when the residual norm has been reduced totol
times its initial value, i.e. \((\left\| b - A x_k \right\| <= \mathrm{tol} \left\| b \right\|\\)\).Note
This function is similar to
tf.linalg.experimental.conjugate_gradient
, except it adds support for complex-valued linear systems and for imaging operators.- Parameters
operator – A
LinearOperator
that is self-adjoint and positive definite.rhs – A tf.Tensor of shape
[..., N]
. The right hand-side of the linear system.preconditioner – A
LinearOperator
that approximates the inverse ofA
. An efficient preconditioner could dramatically improve the rate of convergence. Ifpreconditioner
represents matrixM``(``M
approximatesA^{-1}
), the algorithm usespreconditioner.apply(x)
to estimateA^{-1}x
. For this to be useful, the cost of applyingM
should be much lower than computingA^{-1}
directly.x –
A tf.Tensor of shape
[..., N]
. The initial guess for the solution.tol – A float scalar convergence tolerance.
max_iterations – An int giving the maximum number of iterations.
bypass_gradient – A boolean. If True, the gradient with respect to
rhs
will be computed by applying the inverse ofoperator
to the upstream gradient with respect tox
(through CG iteration), instead of relying on TensorFlow’s automatic differentiation. This may reduce memory usage when training neural networks, butoperator
must not have any trainable parameters. If False, gradients are computed normally. For more details, see ref. [1].name – A name scope for the operation.
- Returns
A namedtuple representing the final state with fields
i: A scalar
int32
tf.Tensor. Number of iterations executed.- x: A rank-1 tf.Tensor of shape
[..., N]
containing the computed solution.
- x: A rank-1 tf.Tensor of shape
r: A rank-1 tf.Tensor of shape
[.., M]
containing the residual vector.p: A rank-1 tf.Tensor of shape
[..., N]
.A
-conjugate basis vector.gamma: \(r dot M dot r\), equivalent to \(||r||_2^2\) when
preconditioner=None
.
- Raises
ValueError – If
operator
is not self-adjoint and positive definite.
References
- 1
Aggarwal, H. K., Mani, M. P., & Jacob, M. (2018). MoDL: Model-based deep learning architecture for inverse problems. IEEE transactions on medical imaging, 38(2), 394-405.