View source on GitHub |

Conjugate gradient solver.

```
tf.linalg.experimental.conjugate_gradient(
operator,
rhs,
preconditioner=None,
x=None,
tol=1e-05,
max_iter=20,
name='conjugate_gradient'
)
```

Solves a linear system of equations `A*x = rhs`

for self-adjoint, positive
definite matrix `A`

and right-hand side vector `rhs`

, 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
exceeds `max_iter`

or when the residual norm has been reduced to `tol`

times its initial value, i.e. \(||rhs - A x_k|| <= tol ||rhs||\).

#### Args:

: A`operator`

`LinearOperator`

that is self-adjoint and positive definite.: A possibly batched vector of shape`rhs`

`[..., N]`

containing the right-hand size vector.: A`preconditioner`

`LinearOperator`

that approximates the inverse of`A`

. An efficient preconditioner could dramatically improve the rate of convergence. If`preconditioner`

represents matrix`M`

(`M`

approximates`A^{-1}`

), the algorithm uses`preconditioner.apply(x)`

to estimate`A^{-1}x`

. For this to be useful, the cost of applying`M`

should be much lower than computing`A^{-1}`

directly.: A possibly batched vector of shape`x`

`[..., N]`

containing the initial guess for the solution.: A float scalar convergence tolerance.`tol`

: An integer giving the maximum number of iterations.`max_iter`

: A name scope for the operation.`name`

#### Returns:

: A namedtuple representing the final state with fields:`output`

- i: A scalar
`int32`

`Tensor`

. Number of iterations executed. - x: A rank-1
`Tensor`

of shape`[..., N]`

containing the computed solution. - r: A rank-1
`Tensor`

of shape`[.., M]`

containing the residual vector. - p: A rank-1
`Tensor`

of shape`[..., N]`

.`A`

-conjugate basis vector. - gamma: \(r \dot M \dot r\), equivalent to \(||r||_2^2\) when
`preconditioner=None`

.

- i: A scalar