mrpro.algorithms.optimizers.cg
- mrpro.algorithms.optimizers.cg(operator: LinearOperator, right_hand_side: Tensor, initial_value: Tensor | None = None, max_iterations: int = 128, tolerance: float = 0.0001, callback: Callable[[CGStatus], None] | None = None) Tensor [source]
CG for solving a linear system \(Hx=b\).
Thereby, \(H\) is a linear self-adjoint operator, \(b\) is the right-hand-side of the system and \(x\) is the sought solution.
Note that this implementation allows for simultaneously solving a batch of \(N\) problems of the form \(H_i x_i = b_i\) with \(i=1,...,N\).
Thereby, the underlying assumption is that the considered problem is \(Hx=b\) with \(H:= diag(H_1, ..., H_N)\) and \(b:= [b_1, ..., b_N]^T\).
Thus, if all \(H_i\) are self-adjoint, so is \(H\) and the CG can be applied. Note however, that the accuracy of the obtained solutions might vary among the different problems. Note also that we don’t test if the input operator is self-adjoint or not.
Further, note that if the condition of \(H\) is very large, a small residual does not necessarily imply that the solution is accurate.
- Parameters:
operator – self-adjoint operator (named H above)
right_hand_side – right-hand-side of the system (named b above)
initial_value – initial value of the algorithm; if None, it will be set to right_hand_side
max_iterations – maximal number of iterations
tolerance – tolerance for the residual; if set to zero, the maximal number of iterations is the only stopping criterion used to stop the cg
callback – function to be called at each iteration
- Return type:
an approximate solution of the linear system Hx=b