pyeeg.solvers.conjugate_gradient
- pyeeg.solvers.conjugate_gradient(A, b, x0=None, tol=1e-10, max_iter=None, lambda_=0.0, preconditioner=None, verbose=False)
Solve the linear system Ax = b using the Conjugate Gradient method. A must be square, symmetric and positive-definite.
Parameters: A : ndarray
Symmetric positive-definite matrix.
- bndarray
Right-hand side vector.
- x0ndarray, optional
Initial guess for the solution.
- tolfloat, optional
Tolerance for convergence.
- max_iterint, optional
Maximum number of iterations.
- lambda_float, optional
Regularization parameter (Tikhonov regularization).
- preconditionerfunction, optional
Function that applies the preconditioner (e.g. Incomplete Cholesky or Diagonal). The function must take a vector as input and return the preconditioned vector.
Returns: x : ndarray
Solution vector.
Note: The Conjugate Gradient method is an iterative method that solves the linear system Ax = b. If A is not a square matrix we request the user to fall back on the normal equation (X^T X + lambda I) x = X^T y, where A = X^T X and b = X^T y, which is then solvable using the CG method.