pylops.optimization.cls_basic.CG

class pylops.optimization.cls_basic.CG(Op, callbacks=None)[source]

Conjugate gradient

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

Parameters:
Op : pylops.LinearOperator

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

Notes

Solve the \(\mathbf{y} = \mathbf{Op}\,\mathbf{x}\) problem using conjugate gradient iterations [1].

[1]Hestenes, M R., Stiefel, E., “Methods of Conjugate Gradients for Solving Linear Systems”, Journal of Research of the National Bureau of Standards. vol. 49. 1952.

Methods

__init__(Op[, callbacks]) Initialize self.
callback(x, *args, **kwargs) Callback routine
finalize([show]) Finalize solver
run(x[, niter, show, itershow]) Run solver
setup(y[, x0, niter, tol, show]) Setup solver
solve(y[, x0, niter, tol, show, itershow]) Run entire solver
step(x[, show]) Run one step of solver
setup(y, x0=None, niter=None, tol=0.0001, show=False)[source]

Setup solver

Parameters:
y : np.ndarray

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

x0 : np.ndarray, optional

Initial guess of size \([N \times 1]\). If None, initialize internally as zero vector

niter : int, optional

Number of iterations (default to None in case a user wants to manually step over the solver)

tol : float, optional

Tolerance on residual norm

show : bool, optional

Display setup log

Returns:
x : np.ndarray

Initial guess of size \([N \times 1]\)

step(x, show=False)[source]

Run one step of solver

Parameters:
x : np.ndarray

Current model vector to be updated by a step of CG

show : bool, optional

Display iteration log

Returns:
x : np.ndarray

Updated model vector

run(x, niter=None, show=False, itershow=[10, 10, 10])[source]

Run solver

Parameters:
x : np.ndarray

Current model vector to be updated by multiple steps of CG

niter : int, optional

Number of iterations. Can be set to None if already provided in the setup call

show : bool, optional

Display logs

itershow : list, 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.

Returns:
x : np.ndarray

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

finalize(show=False)[source]

Finalize solver

Parameters:
show : bool, optional

Display finalize log

solve(y, x0=None, niter=10, tol=0.0001, show=False, itershow=[10, 10, 10])[source]

Run entire solver

Parameters:
y : np.ndarray

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

x0 : np.ndarray, optional

Initial guess of size \([N \times 1]\). If None, initialize internally as zero vector

niter : int, optional

Number of iterations

tol : float, optional

Tolerance on residual norm

show : bool, optional

Display logs

itershow : list, 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.

Returns:
x : np.ndarray

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

iit : int

Number of executed iterations

cost : numpy.ndarray, optional

History of the L2 norm of the residual