pymoto.solvers.CG

class pymoto.solvers.CG(A=None, preconditioner: Preconditioner = <pymoto.solvers.iterative.Preconditioner object>, tol: float = 1e-07, maxit: int = 10000, restart: int = 50, verbosity: int = 0)

Preconditioned conjugate gradient method Works for positive-definite self-adjoint matrices (\(A=A^H\))

References

Ji & Li (2017), A breakdown-free BCG method. DOI 10.1007/s10543-016-0631-z

https://www.cs.odu.edu/~yaohang/portfolio/BIT2017.pdf

Shewchuck (1994), Introduction to CG method without the agonzing pain.

https://www.cs.cmu.edu/~quake-papers/painless-conjugate-gradient.pdf

__init__(A=None, preconditioner: Preconditioner = <pymoto.solvers.iterative.Preconditioner object>, tol: float = 1e-07, maxit: int = 10000, restart: int = 50, verbosity: int = 0)

Initialize the CG solver

Parameters:
  • A (matrix, optional) – The matrix

  • preconditioner (Preconditioner, optional) – Preconditioner to use

  • tol (float, optional) – Convergence tolerance. Defaults to 1e-7.

  • maxit (int, optional) – Maximum number of iterations. Defaults to 10000.

  • restart (int, optional) – Restart every Nth iteration. Defaults to 50.

  • verbosity (int, optional) – Log level. Defaults to 0.

Methods

__init__([A])

Initialize the CG solver

residual(A, x, b[, trans])

Calculates the (relative) residual of the linear system of equations

solve(rhs[, x0, trans])

Solves the linear system of equations \(\mathbf{A} \mathbf{x} = \mathbf{b}\)

update(A)

Updates with a new matrix of the same structure

Attributes

defined

update(A)

Updates with a new matrix of the same structure

Parameters:

A (matrix) – The new matrix of size (N, N)

Returns:

self

solve(rhs, x0=None, trans='N')

Solves the linear system of equations \(\mathbf{A} \mathbf{x} = \mathbf{b}\)

Parameters:
  • rhs – Right hand side \(\mathbf{b}\) of shape (N) or (N, K) for multiple right-hand-sides

  • x0 (optional) – Initial guess for the solution

  • trans (optional) – Option to transpose matrix ‘N’: A @ x == rhs (default) Normal matrix ‘T’: A^T @ x == rhs Transposed matrix ‘H’: A^H @ x == rhs Hermitian transposed matrix (conjugate transposed)

Returns:

Solution vector \(\mathbf{x}\) of same shape as \(\mathbf{b}\)

defined = True
static residual(A, x, b, trans='N')

Calculates the (relative) residual of the linear system of equations

The residual is calculated as \(r = \frac{\left| \mathbf{A} \mathbf{x} - \mathbf{b} \right|}{\left| \mathbf{b} \right|}\)

Parameters:
  • A – The matrix

  • x – Solution vector

  • b – Right-hand side

  • trans (optional) – Matrix tranformation (N is normal, T is transposed, H is hermitian transposed)

Returns:

Residual value