pylops.optimization.basic.cg

pylops.optimization.basic.cg(Op, y, x0=None, niter=10, tol=0.0001, rtol=0.0, rtol1=0.0, show=False, itershow=(10, 10, 10), callback=None, preallocate=False)[source]

Conjugate gradient

Solve a square system of equations given an operator Op and data y using conjugate gradient iterations.

Parameters:
Oppylops.LinearOperator

Operator to invert of size \([N \times N]\)

ynumpy.ndarray

Data of size \([N \times 1]\)

x0numpy.ndarray, optional

Initial guess

niterint, optional

Number of iterations

tolfloat, optional

Absolute tolerance on residual norm. Stops the solver when the residual norm is below this value.

rtolfloat, optional

Relative tolerance on residual norm wrt initial residual norm. Stops the solver when the ratio of the current residual norm to the initial residual norm is below this value.

rtol1float, optional

Relative tolerance on residual norm wrt to data. Stops the solver when the ratio of the current residual norm to the data norm is below this value.

showbool, optional

Display iterations log

itershowtuple, optional

Display set log for the first N1 steps, last N2 steps, and every N3 steps in between where N1, N2, N3 are the three element of the list.

callbackcallable, optional

Function with signature (callback(x)) to call after each iteration where x is the current model vector

preallocatebool, optional

Added in version 2.6.0.

Pre-allocate all variables used by the solver

Returns:
xnumpy.ndarray

Estimated model of size \([N \times 1]\)

iitint

Number of executed iterations

costnumpy.ndarray, optional

History of the L2 norm of the residual

Notes

See pylops.optimization.cls_basic.CG