Class SymmLQ.State
- java.lang.Object
-
- org.apache.commons.math3.linear.SymmLQ.State
-
- Enclosing class:
- SymmLQ
private static class SymmLQ.State extends java.lang.ObjectA simple container holding the non-final variables used in the iterations. Making the current state of the solver visible from the outside is necessary, because during the iterations,
xdoes not exactly hold the current estimate of the solution. Indeed,xneeds in general to be moved from the LQ point to the CG point. Besides, additional upudates must be carried out in casegoodbis set totrue.In all subsequent comments, the description of the state variables refer to their value after a call to
update(). In these comments, k is the current number of evaluations of matrix-vector products.
-
-
Field Summary
Fields Modifier and Type Field Description private RealLinearOperatoraReference to the linear operator.private RealVectorbReference to the right-hand side vector.private doublebetaThe value of beta[k+1].private doublebeta1The value of beta[1].private booleanbIsNullThe value ofb == 0(exact floating-point equality).private doublebstepThe value of bstep[k-1].(package private) static doubleCBRT_MACH_PRECThe cubic root ofMACH_PREC.private doublecgnormThe estimate of the norm of P * rC[k].private booleanchecktrueif symmetry of matrix and conditioner must be checked.private doubledbarThe value of dbar[k+1] = -beta[k+1] * c[k-1].private doubledeltaThe value of the custom tolerance δ for the default stopping criterion.private doublegammaZetaThe value of gamma[k] * zeta[k].private doublegbarThe value of gbar[k].private doublegmaxThe value of max(|alpha[1]|, gamma[1], ..., gamma[k-1]).private doublegminThe value of min(|alpha[1]|, gamma[1], ..., gamma[k-1]).private booleangoodbCopy of thegoodbparameter.private booleanhasConvergedtrueif the default convergence criterion is verified.private doublelqnormThe estimate of the norm of P * rL[k-1].private RealLinearOperatormReference to the preconditioner, M.(package private) static doubleMACH_PRECThe machine precision.private RealVectormbThe value of M * b.private doubleminusEpsZetaThe value of (-eps[k+1] * zeta[k-1]).private doubleoldbThe value of beta[k].private RealVectorr1The value of beta[k] * M^(-1) * P' * v[k].private RealVectorr2The value of beta[k+1] * M^(-1) * P' * v[k+1].private doublernormThe value of the updated, preconditioned residual P * r.private doubleshiftCopy of theshiftparameter.private doublesnprodThe value of s[1] * ...private doubletnormAn estimate of the square of the norm of A * V[k], based on Paige and Saunders (1975), equation (3.3).private RealVectorwbarThe value of P' * wbar[k] or P' * (wbar[k] - s[1] * ...private RealVectorxLA reference to the vector to be updated with the solution.private RealVectoryThe value of beta[k+1] * P' * v[k+1].private doubleynorm2The value of zeta[1]^2 + ...
-
Constructor Summary
Constructors Constructor Description State(RealLinearOperator a, RealLinearOperator m, RealVector b, boolean goodb, double shift, double delta, boolean check)Creates and inits to k = 1 a new instance of this class.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) booleanbEqualsNullVector()Returnstrueif the right-hand side vector is zero exactly.(package private) booleanbetaEqualsZero()Returnstrueifbetais essentially zero.private static voidcheckSymmetry(RealLinearOperator l, RealVector x, RealVector y, RealVector z)Performs a symmetry check on the specified linear operator, and throws an exception in case this check fails.private static voiddaxpbypz(double a, RealVector x, double b, RealVector y, RealVector z)A BLAS-like function, for the operation z ← a · x + b · y + z.private static voiddaxpy(double a, RealVector x, RealVector y)A clone of the BLASDAXPYfunction, which carries out the operation y ← a · x + y.(package private) doublegetNormOfResidual()Returns the norm of the updated, preconditioned residual.(package private) booleanhasConverged()Returnstrueif the default stopping criterion is fulfilled.(package private) voidinit()Performs the initial phase of the SYMMLQ algorithm.(package private) voidrefineSolution(RealVector x)Move to the CG point if it seems better.private static voidthrowNPDLOException(RealLinearOperator l, RealVector v)Throws a newNonPositiveDefiniteOperatorExceptionwith appropriate context.(package private) voidupdate()Performs the next iteration of the algorithm.private voidupdateNorms()Computes the norms of the residuals, and checks for convergence.
-
-
-
Field Detail
-
CBRT_MACH_PREC
static final double CBRT_MACH_PREC
The cubic root ofMACH_PREC.
-
MACH_PREC
static final double MACH_PREC
The machine precision.
-
a
private final RealLinearOperator a
Reference to the linear operator.
-
b
private final RealVector b
Reference to the right-hand side vector.
-
check
private final boolean check
trueif symmetry of matrix and conditioner must be checked.
-
delta
private final double delta
The value of the custom tolerance δ for the default stopping criterion.
-
beta
private double beta
The value of beta[k+1].
-
beta1
private double beta1
The value of beta[1].
-
bstep
private double bstep
The value of bstep[k-1].
-
cgnorm
private double cgnorm
The estimate of the norm of P * rC[k].
-
dbar
private double dbar
The value of dbar[k+1] = -beta[k+1] * c[k-1].
-
gammaZeta
private double gammaZeta
The value of gamma[k] * zeta[k]. Was calledrhs1in the initial code.
-
gbar
private double gbar
The value of gbar[k].
-
gmax
private double gmax
The value of max(|alpha[1]|, gamma[1], ..., gamma[k-1]).
-
gmin
private double gmin
The value of min(|alpha[1]|, gamma[1], ..., gamma[k-1]).
-
goodb
private final boolean goodb
Copy of thegoodbparameter.
-
hasConverged
private boolean hasConverged
trueif the default convergence criterion is verified.
-
lqnorm
private double lqnorm
The estimate of the norm of P * rL[k-1].
-
m
private final RealLinearOperator m
Reference to the preconditioner, M.
-
minusEpsZeta
private double minusEpsZeta
The value of (-eps[k+1] * zeta[k-1]). Was calledrhs2in the initial code.
-
mb
private final RealVector mb
The value of M * b.
-
oldb
private double oldb
The value of beta[k].
-
r1
private RealVector r1
The value of beta[k] * M^(-1) * P' * v[k].
-
r2
private RealVector r2
The value of beta[k+1] * M^(-1) * P' * v[k+1].
-
rnorm
private double rnorm
-
shift
private final double shift
Copy of theshiftparameter.
-
snprod
private double snprod
The value of s[1] * ... * s[k-1].
-
tnorm
private double tnorm
An estimate of the square of the norm of A * V[k], based on Paige and Saunders (1975), equation (3.3).
-
wbar
private RealVector wbar
The value of P' * wbar[k] or P' * (wbar[k] - s[1] * ... * s[k-1] * v[1]) ifgoodbistrue. Was calledwin the initial code.
-
xL
private final RealVector xL
A reference to the vector to be updated with the solution. Contains the value of xL[k-1] ifgoodbisfalse, (xL[k-1] - bstep[k-1] * v[1]) otherwise.
-
y
private RealVector y
The value of beta[k+1] * P' * v[k+1].
-
ynorm2
private double ynorm2
The value of zeta[1]^2 + ... + zeta[k-1]^2.
-
bIsNull
private boolean bIsNull
The value ofb == 0(exact floating-point equality).
-
-
Constructor Detail
-
State
State(RealLinearOperator a, RealLinearOperator m, RealVector b, boolean goodb, double shift, double delta, boolean check)
Creates and inits to k = 1 a new instance of this class.- 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 Adelta- the δ parameter for the default stopping criterioncheck-trueif self-adjointedness of both matrix and preconditioner should be checked
-
-
Method Detail
-
checkSymmetry
private static void checkSymmetry(RealLinearOperator l, RealVector x, RealVector y, RealVector z) throws NonSelfAdjointOperatorException
Performs a symmetry check on the specified linear operator, and throws an exception in case this check fails. Given a linear operator L, and a vector x, this method checks that x' · L · y = y' · L · x (within a given accuracy), where y = L · x.- Parameters:
l- the linear operator Lx- the candidate vector xy- the candidate vector y = L · xz- the vector z = L · y- Throws:
NonSelfAdjointOperatorException- when the test fails
-
throwNPDLOException
private static void throwNPDLOException(RealLinearOperator l, RealVector v) throws NonPositiveDefiniteOperatorException
Throws a newNonPositiveDefiniteOperatorExceptionwith appropriate context.- Parameters:
l- the offending linear operatorv- the offending vector- Throws:
NonPositiveDefiniteOperatorException- in any circumstances
-
daxpy
private static void daxpy(double a, RealVector x, RealVector y)A clone of the BLASDAXPYfunction, which carries out the operation y ← a · x + y. This is for internal use only: no dimension checks are provided.- Parameters:
a- the scalar by whichxis to be multipliedx- the vector to be added toyy- the vector to be incremented
-
daxpbypz
private static void daxpbypz(double a, RealVector x, double b, RealVector y, RealVector z)A BLAS-like function, for the operation z ← a · x + b · y + z. This is for internal use only: no dimension checks are provided.- Parameters:
a- the scalar by whichxis to be multipliedx- the first vector to be added tozb- the scalar by whichyis to be multipliedy- the second vector to be added tozz- the vector to be incremented
-
refineSolution
void refineSolution(RealVector x)
Move to the CG point if it seems better. In this version of SYMMLQ, the convergence tests involve only cgnorm, so we're unlikely to stop at an LQ point, except if the iteration limit interferes.
Additional upudates are also carried out in case
goodbis set totrue.- Parameters:
x- the vector to be updated with the refined value of xL
-
init
void init()
Performs the initial phase of the SYMMLQ algorithm. On return, the value of the state variables ofthisobject correspond to k = 1.
-
update
void update()
Performs the next iteration of the algorithm. The iteration count should be incremented prior to calling this method. On return, the value of the state variables ofthisobject correspond to the current iteration countk.
-
updateNorms
private void updateNorms()
-
hasConverged
boolean hasConverged()
Returnstrueif the default stopping criterion is fulfilled.- Returns:
trueif convergence of the iterations has occurred
-
bEqualsNullVector
boolean bEqualsNullVector()
Returnstrueif the right-hand side vector is zero exactly.- Returns:
- the boolean value of
b == 0
-
betaEqualsZero
boolean betaEqualsZero()
Returnstrueifbetais essentially zero. This method is used to check for early stop of the iterations.- Returns:
trueifbeta <MACH_PREC
-
getNormOfResidual
double getNormOfResidual()
Returns the norm of the updated, preconditioned residual.- Returns:
- the norm of the residual, ||P * r||
-
-