public class ConjugateGradient extends PreconditionedIterativeLinearSolver
This is an implementation of the conjugate gradient method for
RealLinearOperator
. It follows closely the template by Barrett et al. (1994) (figure 2.5). The linear system at
hand is A · x = b, and the residual is r = b - A · x.
A default stopping criterion is implemented. The iterations stop when || r || ≤ δ || b ||, where b is the right-hand side vector, r the current estimate of the residual, and δ a user-specified tolerance. It should be noted that r is the so-called updated residual, which might differ from the true residual due to rounding-off errors (see e.g. Strakos and Tichy, 2002).
In the present context, an iteration should be understood as one evaluation of the matrix-vector product A · x. The initialization phase therefore counts as one iteration.
Besides standard MathIllegalArgumentException
, this class might throw
MathIllegalArgumentException
if the linear operator or
the preconditioner are not positive definite.
"operator"
points to the offending linear operator, say L,"vector"
points to the offending vector, say x, such that
xT · L · x < 0.Modifier and Type | Field and Description |
---|---|
static String |
OPERATOR
Key for the exception context.
|
static String |
VECTOR
Key for the exception context.
|
Constructor and Description |
---|
ConjugateGradient(int maxIterations,
double delta,
boolean check)
Creates a new instance of this class, with default
stopping criterion.
|
ConjugateGradient(IterationManager manager,
double delta,
boolean check)
Creates a new instance of this class, with default
stopping criterion and custom iteration manager.
|
Modifier and Type | Method and Description |
---|---|
boolean |
getCheck()
Returns
true if positive-definiteness should be checked for both
matrix and preconditioner. |
RealVector |
solveInPlace(RealLinearOperator a,
RealLinearOperator m,
RealVector b,
RealVector x0)
Returns an estimate of the solution to the linear system A · x =
b.
|
checkParameters, solve, solve, solve, solve, solveInPlace
checkParameters, getIterationManager
public static final String OPERATOR
public static final String VECTOR
public ConjugateGradient(int maxIterations, double delta, boolean check)
maxIterations
- the maximum number of iterationsdelta
- the δ parameter for the default stopping criterioncheck
- true
if positive definiteness of both matrix and
preconditioner should be checkedpublic ConjugateGradient(IterationManager manager, double delta, boolean check) throws NullArgumentException
manager
- the custom iteration managerdelta
- the δ parameter for the default stopping criterioncheck
- true
if positive definiteness of both matrix and
preconditioner should be checkedNullArgumentException
- if manager
is null
public final boolean getCheck()
true
if positive-definiteness should be checked for both
matrix and preconditioner.true
if the tests are to be performedpublic RealVector solveInPlace(RealLinearOperator a, RealLinearOperator m, RealVector b, RealVector x0) throws MathIllegalArgumentException, NullArgumentException, MathIllegalStateException
solveInPlace
in class PreconditionedIterativeLinearSolver
a
- the linear operator A of the systemm
- the preconditioner, M (can be null
)b
- the right-hand side vectorx0
- the initial guess of the solutionx0
(shallow copy) updated with the
solutionMathIllegalArgumentException
- if a
or m
is
not positive definiteNullArgumentException
- if one of the parameters is null
MathIllegalStateException
- at exhaustion of the iteration count,
unless a custom
callback
has been set at construction of the IterationManager
Copyright © 2016–2017 Hipparchus.org. All rights reserved.