Class SymmLQ
Implementation of the SYMMLQ iterative linear solver proposed by Paige and Saunders (1975). This implementation is largely based on the FORTRAN code by Pr. Michael A. Saunders, available here.
SYMMLQ is designed to solve the system of linear equations A · x = b
where A is an n × n self-adjoint linear operator (defined as a
RealLinearOperator), and b is a given vector. The operator A is not
required to be positive definite. If A is known to be definite, the method of
conjugate gradients might be preferred, since it will require about the same
number of iterations as SYMMLQ but slightly less work per iteration.
SYMMLQ is designed to solve the system (A - shift · I) · x = b, where shift is a specified scalar value. If shift and b are suitably chosen, the computed vector x may approximate an (unnormalized) eigenvector of A, as in the methods of inverse iteration and/or Rayleigh-quotient iteration. Again, the linear operator (A - shift · I) need not be positive definite (but must be self-adjoint). The work per iteration is very slightly less if shift = 0.
Preconditioning
Preconditioning may reduce the number of iterations required. The solver may be provided with a positive definite preconditioner M = PT · P that is known to approximate (A - shift · I)-1 in some sense, where matrix-vector products of the form M · y = x can be computed efficiently. Then SYMMLQ will implicitly solve the system of equations P · (A - shift · I) · PT · xhat = P · b, i.e. Ahat · xhat = bhat, where Ahat = P · (A - shift · I) · PT, bhat = P · b, and return the solution x = PT · xhat. The associated residual is rhat = bhat - Ahat · xhat = P · [b - (A - shift · I) · x] = P · r.
In the case of preconditioning, the IterativeLinearSolverEvents that
this solver fires are such that
IterativeLinearSolverEvent.getNormOfResidual() returns the norm of
the preconditioned, updated residual, ||P · r||, not the norm
of the true residual ||r||.
Default stopping criterion
A default stopping criterion is implemented. The iterations stop when || rhat || ≤ δ || Ahat || || xhat ||, where xhat is the current estimate of the solution of the transformed system, rhat the current estimate of the corresponding residual, and δ a user-specified tolerance.
Iteration count
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. If the user requires checks on the symmetry of A, this entails one further matrix-vector product in the initial phase. This further product is not accounted for in the iteration count. In other words, the number of iterations required to reach convergence will be identical, whether checks have been required or not.
The present definition of the iteration count differs from that adopted in the original FOTRAN code, where the initialization phase was not taken into account.
Initial guess of the solution
The x parameter in
solve(RealLinearOperator, RealVector, RealVector),solve(RealLinearOperator, RealLinearOperator, RealVector, RealVector)},solveInPlace(RealLinearOperator, RealVector, RealVector),solveInPlace(RealLinearOperator, RealLinearOperator, RealVector, RealVector),solveInPlace(RealLinearOperator, RealLinearOperator, RealVector, RealVector, boolean, double),
Exception context
Besides standard DimensionMismatchException, this class might throw
NonSelfAdjointOperatorException if the linear operator or the
preconditioner are not symmetric. In this case, the ExceptionContext
provides more information
- key
"operator"points to the offending linear operator, say L, - key
"vector1"points to the first offending vector, say x, - key
"vector2"points to the second offending vector, say y, such that xT · L · y ≠ yT · L · x (within a certain accuracy).
NonPositiveDefiniteOperatorException might also be thrown in case the
preconditioner is not positive definite. The relevant keys to the
ExceptionContext are
- key
"operator", which points to the offending linear operator, say L, - key
"vector", which points to the offending vector, say x, such that xT · L · x invalid input: '<' 0.
References
- Paige and Saunders (1975)
- C. C. Paige and M. A. Saunders, Solution of Sparse Indefinite Systems of Linear Equations, SIAM Journal on Numerical Analysis 12(4): 617-629, 1975
- Since:
- 3.0
-
Constructor Summary
ConstructorsConstructorDescriptionSymmLQ(int maxIterations, double delta, boolean check) Creates a new instance of this class, with default stopping criterion.SymmLQ(IterationManager manager, double delta, boolean check) Creates a new instance of this class, with default stopping criterion and custom iteration manager. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleangetCheck()Returnstrueif symmetry of the matrix, and symmetry as well as positive definiteness of the preconditioner should be checked.Returns an estimate of the solution to the linear system A · x = b.solve(RealLinearOperator a, RealLinearOperator m, RealVector b, boolean goodb, double shift) Returns an estimate of the solution to the linear system (A - shift · I) · x = b.solve(RealLinearOperator a, RealLinearOperator m, RealVector b, RealVector x) Returns an estimate of the solution to the linear system A · x = b.Returns an estimate of the solution to the linear system A · x = b.solve(RealLinearOperator a, RealVector b, boolean goodb, double shift) Returns the solution to the system (A - shift · I) · x = b.solve(RealLinearOperator a, RealVector b, RealVector x) Returns an estimate of the solution to the linear system A · x = b.Returns an estimate of the solution to the linear system A · x = b.solveInPlace(RealLinearOperator a, RealLinearOperator m, RealVector b, RealVector x, boolean goodb, double shift) Returns an estimate of the solution to the linear system (A - shift · I) · x = b.Returns an estimate of the solution to the linear system A · x = b.Methods inherited from class org.apache.commons.math3.linear.PreconditionedIterativeLinearSolver
checkParametersMethods inherited from class org.apache.commons.math3.linear.IterativeLinearSolver
checkParameters, getIterationManager
-
Constructor Details
-
SymmLQ
public SymmLQ(int maxIterations, double delta, boolean check) Creates a new instance of this class, with default stopping criterion. Note that settingchecktotrueentails an extra matrix-vector product in the initial phase.- Parameters:
maxIterations- the maximum number of iterationsdelta- the δ parameter for the default stopping criterioncheck-trueif self-adjointedness of both matrix and preconditioner should be checked
-
SymmLQ
Creates a new instance of this class, with default stopping criterion and custom iteration manager. Note that settingchecktotrueentails an extra matrix-vector product in the initial phase.- Parameters:
manager- the custom iteration managerdelta- the δ parameter for the default stopping criterioncheck-trueif self-adjointedness of both matrix and preconditioner should be checked
-
-
Method Details
-
getCheck
public final boolean getCheck()Returnstrueif symmetry of the matrix, and symmetry as well as positive definiteness of the preconditioner should be checked.- Returns:
trueif the tests are to be performed
-
solve
public RealVector solve(RealLinearOperator a, RealLinearOperator m, RealVector b) throws NullArgumentException, NonSquareOperatorException, DimensionMismatchException, MaxCountExceededException, NonSelfAdjointOperatorException, NonPositiveDefiniteOperatorException, IllConditionedOperatorException Returns an estimate of the solution to the linear system A · x = b.- Overrides:
solvein classPreconditionedIterativeLinearSolver- Parameters:
a- the linear operator A of the systemm- the preconditioner, M (can benull)b- the right-hand side vector- Returns:
- a new vector containing the solution
- Throws:
NonSelfAdjointOperatorException- ifgetCheck()istrue, andaormis not self-adjointNonPositiveDefiniteOperatorException- ifmis not positive definiteIllConditionedOperatorException- ifais ill-conditionedNullArgumentException- if one of the parameters isnullNonSquareOperatorException- ifaormis not squareDimensionMismatchException- ifmorbhave dimensions inconsistent withaMaxCountExceededException- at exhaustion of the iteration count, unless a customcallbackhas been set at construction of theIterationManager
-
solve
public RealVector solve(RealLinearOperator a, RealLinearOperator m, RealVector b, boolean goodb, double shift) throws NullArgumentException, NonSquareOperatorException, DimensionMismatchException, MaxCountExceededException, NonSelfAdjointOperatorException, NonPositiveDefiniteOperatorException, IllConditionedOperatorException Returns an estimate of the solution to the linear system (A - shift · I) · x = b.If the solution x is expected to contain a large multiple of
b(as in Rayleigh-quotient iteration), then better precision may be achieved withgoodbset totrue; this however requires an extra call to the preconditioner.shiftshould be zero if the system A · x = b is to be solved. Otherwise, it could be an approximation to an eigenvalue of A, such as the Rayleigh quotient bT · A · b / (bT · b) corresponding to the vector b. If b is sufficiently like an eigenvector corresponding to an eigenvalue near shift, then the computed x may have very large components. When normalized, x may be closer to an eigenvector than b.- Parameters:
a- the linear operator A of the systemm- the preconditioner, M (can benull)b- the right-hand side vectorgoodb- usuallyfalse, except ifxis expected to contain a large multiple ofbshift- the amount to be subtracted to all diagonal elements of A- Returns:
- a reference to
x(shallow copy) - Throws:
NullArgumentException- if one of the parameters isnullNonSquareOperatorException- ifaormis not squareDimensionMismatchException- ifmorbhave dimensions inconsistent withaMaxCountExceededException- at exhaustion of the iteration count, unless a customcallbackhas been set at construction of theIterationManagerNonSelfAdjointOperatorException- ifgetCheck()istrue, andaormis not self-adjointNonPositiveDefiniteOperatorException- ifmis not positive definiteIllConditionedOperatorException- ifais ill-conditioned
-
solve
public RealVector solve(RealLinearOperator a, RealLinearOperator m, RealVector b, RealVector x) throws NullArgumentException, NonSquareOperatorException, DimensionMismatchException, NonSelfAdjointOperatorException, NonPositiveDefiniteOperatorException, IllConditionedOperatorException, MaxCountExceededException Returns an estimate of the solution to the linear system A · x = b.- Overrides:
solvein classPreconditionedIterativeLinearSolver- Parameters:
a- the linear operator A of the systemm- the preconditioner, M (can benull)b- the right-hand side vectorx- not meaningful in this implementation; should not be considered as an initial guess (more)- Returns:
- a new vector containing the solution
- Throws:
NonSelfAdjointOperatorException- ifgetCheck()istrue, andaormis not self-adjointNonPositiveDefiniteOperatorException- ifmis not positive definiteIllConditionedOperatorException- ifais ill-conditionedNullArgumentException- if one of the parameters isnullNonSquareOperatorException- ifaormis not squareDimensionMismatchException- ifm,borx0have dimensions inconsistent withaMaxCountExceededException- at exhaustion of the iteration count, unless a customcallbackhas been set at construction of theIterationManager
-
solve
public RealVector solve(RealLinearOperator a, RealVector b) throws NullArgumentException, NonSquareOperatorException, DimensionMismatchException, NonSelfAdjointOperatorException, IllConditionedOperatorException, MaxCountExceededException Returns an estimate of the solution to the linear system A · x = b.- Overrides:
solvein classPreconditionedIterativeLinearSolver- Parameters:
a- the linear operator A of the systemb- the right-hand side vector- Returns:
- a new vector containing the solution
- Throws:
NonSelfAdjointOperatorException- ifgetCheck()istrue, andais not self-adjointIllConditionedOperatorException- ifais ill-conditionedNullArgumentException- if one of the parameters isnullNonSquareOperatorException- ifais not squareDimensionMismatchException- ifbhas dimensions inconsistent withaMaxCountExceededException- at exhaustion of the iteration count, unless a customcallbackhas been set at construction of theIterationManager
-
solve
public RealVector solve(RealLinearOperator a, RealVector b, boolean goodb, double shift) throws NullArgumentException, NonSquareOperatorException, DimensionMismatchException, NonSelfAdjointOperatorException, IllConditionedOperatorException, MaxCountExceededException Returns the solution to the system (A - shift · I) · x = b.If the solution x is expected to contain a large multiple of
b(as in Rayleigh-quotient iteration), then better precision may be achieved withgoodbset totrue.shiftshould be zero if the system A · x = b is to be solved. Otherwise, it could be an approximation to an eigenvalue of A, such as the Rayleigh quotient bT · A · b / (bT · b) corresponding to the vector b. If b is sufficiently like an eigenvector corresponding to an eigenvalue near shift, then the computed x may have very large components. When normalized, x may be closer to an eigenvector than b.- Parameters:
a- the linear operator A of the systemb- the right-hand side vectorgoodb- usuallyfalse, except ifxis expected to contain a large multiple ofbshift- the amount to be subtracted to all diagonal elements of A- Returns:
- a reference to
x - Throws:
NullArgumentException- if one of the parameters isnullNonSquareOperatorException- ifais not squareDimensionMismatchException- ifbhas dimensions inconsistent withaMaxCountExceededException- at exhaustion of the iteration count, unless a customcallbackhas been set at construction of theIterationManagerNonSelfAdjointOperatorException- ifgetCheck()istrue, andais not self-adjointIllConditionedOperatorException- ifais ill-conditioned
-
solve
public RealVector solve(RealLinearOperator a, RealVector b, RealVector x) throws NullArgumentException, NonSquareOperatorException, DimensionMismatchException, NonSelfAdjointOperatorException, IllConditionedOperatorException, MaxCountExceededException Returns an estimate of the solution to the linear system A · x = b.- Overrides:
solvein classPreconditionedIterativeLinearSolver- Parameters:
a- the linear operator A of the systemb- the right-hand side vectorx- not meaningful in this implementation; should not be considered as an initial guess (more)- Returns:
- a new vector containing the solution
- Throws:
NonSelfAdjointOperatorException- ifgetCheck()istrue, andais not self-adjointIllConditionedOperatorException- ifais ill-conditionedNullArgumentException- if one of the parameters isnullNonSquareOperatorException- ifais not squareDimensionMismatchException- ifborx0have dimensions inconsistent withaMaxCountExceededException- at exhaustion of the iteration count, unless a customcallbackhas been set at construction of theIterationManager
-
solveInPlace
public RealVector solveInPlace(RealLinearOperator a, RealLinearOperator m, RealVector b, RealVector x) throws NullArgumentException, NonSquareOperatorException, DimensionMismatchException, NonSelfAdjointOperatorException, NonPositiveDefiniteOperatorException, IllConditionedOperatorException, MaxCountExceededException Returns an estimate of the solution to the linear system A · x = b. The solution is computed in-place (initial guess is modified).- Specified by:
solveInPlacein classPreconditionedIterativeLinearSolver- Parameters:
a- the linear operator A of the systemm- the preconditioner, M (can benull)b- the right-hand side vectorx- the vector to be updated with the solution;xshould not be considered as an initial guess (more)- Returns:
- a reference to
x0(shallow copy) updated with the solution - Throws:
NonSelfAdjointOperatorException- ifgetCheck()istrue, andaormis not self-adjointNonPositiveDefiniteOperatorException- ifmis not positive definiteIllConditionedOperatorException- ifais ill-conditionedNullArgumentException- if one of the parameters isnullNonSquareOperatorException- ifaormis not squareDimensionMismatchException- ifm,borx0have dimensions inconsistent withaMaxCountExceededException- at exhaustion of the iteration count, unless a customcallbackhas been set at construction of theIterationManager
-
solveInPlace
public RealVector solveInPlace(RealLinearOperator a, RealLinearOperator m, RealVector b, RealVector x, boolean goodb, double shift) throws NullArgumentException, NonSquareOperatorException, DimensionMismatchException, NonSelfAdjointOperatorException, NonPositiveDefiniteOperatorException, IllConditionedOperatorException, MaxCountExceededException Returns an estimate of the solution to the linear system (A - shift · I) · x = b. The solution is computed in-place.If the solution x is expected to contain a large multiple of
b(as in Rayleigh-quotient iteration), then better precision may be achieved withgoodbset totrue; this however requires an extra call to the preconditioner.shiftshould be zero if the system A · x = b is to be solved. Otherwise, it could be an approximation to an eigenvalue of A, such as the Rayleigh quotient bT · A · b / (bT · b) corresponding to the vector b. If b is sufficiently like an eigenvector corresponding to an eigenvalue near shift, then the computed x may have very large components. When normalized, x may be closer to an eigenvector than b.- Parameters:
a- the linear operator A of the systemm- the preconditioner, M (can benull)b- the right-hand side vectorx- the vector to be updated with the solution;xshould not be considered as an initial guess (more)goodb- usuallyfalse, except ifxis expected to contain a large multiple ofbshift- the amount to be subtracted to all diagonal elements of A- Returns:
- a reference to
x(shallow copy). - Throws:
NullArgumentException- if one of the parameters isnullNonSquareOperatorException- ifaormis not squareDimensionMismatchException- ifm,borxhave dimensions inconsistent witha.MaxCountExceededException- at exhaustion of the iteration count, unless a customcallbackhas been set at construction of theIterationManagerNonSelfAdjointOperatorException- ifgetCheck()istrue, andaormis not self-adjointNonPositiveDefiniteOperatorException- ifmis not positive definiteIllConditionedOperatorException- ifais ill-conditioned
-
solveInPlace
public RealVector solveInPlace(RealLinearOperator a, RealVector b, RealVector x) throws NullArgumentException, NonSquareOperatorException, DimensionMismatchException, NonSelfAdjointOperatorException, IllConditionedOperatorException, MaxCountExceededException Returns an estimate of the solution to the linear system A · x = b. The solution is computed in-place (initial guess is modified).- Overrides:
solveInPlacein classPreconditionedIterativeLinearSolver- Parameters:
a- the linear operator A of the systemb- the right-hand side vectorx- the vector to be updated with the solution;xshould not be considered as an initial guess (more)- Returns:
- a reference to
x0(shallow copy) updated with the solution - Throws:
NonSelfAdjointOperatorException- ifgetCheck()istrue, andais not self-adjointIllConditionedOperatorException- ifais ill-conditionedNullArgumentException- if one of the parameters isnullNonSquareOperatorException- ifais not squareDimensionMismatchException- ifborx0have dimensions inconsistent withaMaxCountExceededException- at exhaustion of the iteration count, unless a customcallbackhas been set at construction of theIterationManager
-