MFEM  v4.6.0
Finite element discretization library
Public Types | Public Member Functions | List of all members
mfem::NNLSSolver Class Reference

#include <solvers.hpp>

Inheritance diagram for mfem::NNLSSolver:
[legend]
Collaboration diagram for mfem::NNLSSolver:
[legend]

Public Types

enum  QRresidualMode { QRresidualMode::off, QRresidualMode::on, QRresidualMode::hybrid }
 
- Public Types inherited from mfem::Operator
enum  DiagonalPolicy { DIAG_ZERO, DIAG_ONE, DIAG_KEEP }
 Defines operator diagonal policy upon elimination of rows and/or columns. More...
 
enum  Type {
  ANY_TYPE, MFEM_SPARSEMAT, Hypre_ParCSR, PETSC_MATAIJ,
  PETSC_MATIS, PETSC_MATSHELL, PETSC_MATNEST, PETSC_MATHYPRE,
  PETSC_MATGENERIC, Complex_Operator, MFEM_ComplexSparseMat, Complex_Hypre_ParCSR,
  Complex_DenseMat, MFEM_Block_Matrix, MFEM_Block_Operator
}
 Enumeration defining IDs for some classes derived from Operator. More...
 

Public Member Functions

 NNLSSolver ()
 
 ~NNLSSolver ()
 
void SetOperator (const Operator &op) override
 The operator must be a DenseMatrix. More...
 
void Mult (const Vector &w, Vector &sol) const override
 Operator application: y=A(x). More...
 
void SetVerbosity (int v)
 
void SetTolerance (double tol)
 
void SetMinNNZ (int min_nnz)
 Set the minimum number of nonzeros required for the solution. More...
 
void SetMaxNNZ (int max_nnz)
 
void SetResidualChangeTolerance (double tol)
 Set threshold on relative change in residual over nStallCheck_ iterations. More...
 
void SetZeroTolerance (double tol)
 
void SetRHSDelta (double d)
 Set RHS vector constant shift, defining rhs_lb and rhs_ub in Solve(). More...
 
void SetOuterIterations (int n)
 Set the maximum number of outer iterations in Solve(). More...
 
void SetInnerIterations (int n)
 Set the maximum number of inner iterations in Solve(). More...
 
void SetStallCheck (int n)
 Set the number of iterations to use for stall checking. More...
 
void SetNormalize (bool n)
 Set a flag to determine whether to call NormalizeConstraints(). More...
 
void SetQRResidualMode (const QRresidualMode qr_residual_mode)
 
void Solve (const Vector &rhs_lb, const Vector &rhs_ub, Vector &soln) const
 Solve the NNLS problem. Specifically, we find a vector soln, such that rhs_lb < mat*soln < rhs_ub is satisfied, where mat is the DenseMatrix input to SetOperator(). More...
 
void NormalizeConstraints (Vector &rhs_lb, Vector &rhs_ub) const
 
- Public Member Functions inherited from mfem::Solver
 Solver (int s=0, bool iter_mode=false)
 Initialize a square Solver with size s. More...
 
 Solver (int h, int w, bool iter_mode=false)
 Initialize a Solver with height h and width w. More...
 
- Public Member Functions inherited from mfem::Operator
void InitTVectors (const Operator *Po, const Operator *Ri, const Operator *Pi, Vector &x, Vector &b, Vector &X, Vector &B) const
 Initializes memory for true vectors of linear system. More...
 
 Operator (int s=0)
 Construct a square Operator with given size s (default 0). More...
 
 Operator (int h, int w)
 Construct an Operator with the given height (output size) and width (input size). More...
 
int Height () const
 Get the height (size of output) of the Operator. Synonym with NumRows(). More...
 
int NumRows () const
 Get the number of rows (size of output) of the Operator. Synonym with Height(). More...
 
int Width () const
 Get the width (size of input) of the Operator. Synonym with NumCols(). More...
 
int NumCols () const
 Get the number of columns (size of input) of the Operator. Synonym with Width(). More...
 
virtual MemoryClass GetMemoryClass () const
 Return the MemoryClass preferred by the Operator. More...
 
virtual void MultTranspose (const Vector &x, Vector &y) const
 Action of the transpose operator: y=A^t(x). The default behavior in class Operator is to generate an error. More...
 
virtual void AddMult (const Vector &x, Vector &y, const double a=1.0) const
 Operator application: y+=A(x) (default) or y+=a*A(x). More...
 
virtual void AddMultTranspose (const Vector &x, Vector &y, const double a=1.0) const
 Operator transpose application: y+=A^t(x) (default) or y+=a*A^t(x). More...
 
virtual void ArrayMult (const Array< const Vector *> &X, Array< Vector *> &Y) const
 Operator application on a matrix: Y=A(X). More...
 
virtual void ArrayMultTranspose (const Array< const Vector *> &X, Array< Vector *> &Y) const
 Action of the transpose operator on a matrix: Y=A^t(X). More...
 
virtual void ArrayAddMult (const Array< const Vector *> &X, Array< Vector *> &Y, const double a=1.0) const
 Operator application on a matrix: Y+=A(X) (default) or Y+=a*A(X). More...
 
virtual void ArrayAddMultTranspose (const Array< const Vector *> &X, Array< Vector *> &Y, const double a=1.0) const
 Operator transpose application on a matrix: Y+=A^t(X) (default) or Y+=a*A^t(X). More...
 
virtual OperatorGetGradient (const Vector &x) const
 Evaluate the gradient operator at the point x. The default behavior in class Operator is to generate an error. More...
 
virtual void AssembleDiagonal (Vector &diag) const
 Computes the diagonal entries into diag. Typically, this operation only makes sense for linear Operators. In some cases, only an approximation of the diagonal is computed. More...
 
virtual const OperatorGetProlongation () const
 Prolongation operator from linear algebra (linear system) vectors, to input vectors for the operator. NULL means identity. More...
 
virtual const OperatorGetRestriction () const
 Restriction operator from input vectors for the operator to linear algebra (linear system) vectors. NULL means identity. More...
 
virtual const OperatorGetOutputProlongation () const
 Prolongation operator from linear algebra (linear system) vectors, to output vectors for the operator. NULL means identity. More...
 
virtual const OperatorGetOutputRestrictionTranspose () const
 Transpose of GetOutputRestriction, directly available in this form to facilitate matrix-free RAP-type operators. More...
 
virtual const OperatorGetOutputRestriction () const
 Restriction operator from output vectors for the operator to linear algebra (linear system) vectors. NULL means identity. More...
 
void FormLinearSystem (const Array< int > &ess_tdof_list, Vector &x, Vector &b, Operator *&A, Vector &X, Vector &B, int copy_interior=0)
 Form a constrained linear system using a matrix-free approach. More...
 
void FormRectangularLinearSystem (const Array< int > &trial_tdof_list, const Array< int > &test_tdof_list, Vector &x, Vector &b, Operator *&A, Vector &X, Vector &B)
 Form a column-constrained linear system using a matrix-free approach. More...
 
virtual void RecoverFEMSolution (const Vector &X, const Vector &b, Vector &x)
 Reconstruct a solution vector x (e.g. a GridFunction) from the solution X of a constrained linear system obtained from Operator::FormLinearSystem() or Operator::FormRectangularLinearSystem(). More...
 
void FormSystemOperator (const Array< int > &ess_tdof_list, Operator *&A)
 Return in A a parallel (on truedofs) version of this square operator. More...
 
void FormRectangularSystemOperator (const Array< int > &trial_tdof_list, const Array< int > &test_tdof_list, Operator *&A)
 Return in A a parallel (on truedofs) version of this rectangular operator (including constraints). More...
 
void FormDiscreteOperator (Operator *&A)
 Return in A a parallel (on truedofs) version of this rectangular operator. More...
 
void PrintMatlab (std::ostream &out, int n, int m=0) const
 Prints operator with input size n and output size m in Matlab format. More...
 
virtual void PrintMatlab (std::ostream &out) const
 Prints operator in Matlab format. More...
 
virtual ~Operator ()
 Virtual destructor. More...
 
Type GetType () const
 Return the type ID of the Operator class. More...
 

Additional Inherited Members

- Public Attributes inherited from mfem::Solver
bool iterative_mode
 If true, use the second argument of Mult() as an initial guess. More...
 
- Protected Member Functions inherited from mfem::Operator
void FormConstrainedSystemOperator (const Array< int > &ess_tdof_list, ConstrainedOperator *&Aout)
 see FormSystemOperator() More...
 
void FormRectangularConstrainedSystemOperator (const Array< int > &trial_tdof_list, const Array< int > &test_tdof_list, RectangularConstrainedOperator *&Aout)
 see FormRectangularSystemOperator() More...
 
OperatorSetupRAP (const Operator *Pi, const Operator *Po)
 Returns RAP Operator of this, using input/output Prolongation matrices Pi corresponds to "P", Po corresponds to "Rt". More...
 
- Protected Attributes inherited from mfem::Operator
int height
 Dimension of the output / number of rows in the matrix. More...
 
int width
 Dimension of the input / number of columns in the matrix. More...
 

Detailed Description

Non-negative least squares (NNLS) solver class, for computing a vector with non-negative entries approximately satisfying an under-determined linear system.

Definition at line 1252 of file solvers.hpp.

Member Enumeration Documentation

◆ QRresidualMode

Enumerated types of QRresidual mode. Options are 'off': the residual is calculated normally, 'on': the residual is calculated using the QR method, 'hybrid': the residual is calculated normally until we experience rounding errors, then the QR method is used. The default is 'hybrid', which should see the best performance. Recommend using 'hybrid' or 'off' only, since 'on' is computationally expensive.

Enumerator
off 
on 
hybrid 

Definition at line 1309 of file solvers.hpp.

Constructor & Destructor Documentation

◆ NNLSSolver()

mfem::NNLSSolver::NNLSSolver ( )

Definition at line 3558 of file solvers.cpp.

◆ ~NNLSSolver()

mfem::NNLSSolver::~NNLSSolver ( )
inline

Definition at line 1257 of file solvers.hpp.

Member Function Documentation

◆ Mult()

void mfem::NNLSSolver::Mult ( const Vector x,
Vector y 
) const
overridevirtual

Operator application: y=A(x).

Implements mfem::Operator.

Definition at line 3620 of file solvers.cpp.

◆ NormalizeConstraints()

void mfem::NNLSSolver::NormalizeConstraints ( Vector rhs_lb,
Vector rhs_ub 
) const

Normalize the constraints such that the tolerances for each constraint (i.e. (UB - LB)/2) are equal. This seems to help the performance in most cases.

Definition at line 3588 of file solvers.cpp.

◆ SetInnerIterations()

void mfem::NNLSSolver::SetInnerIterations ( int  n)
inline

Set the maximum number of inner iterations in Solve().

Definition at line 1293 of file solvers.hpp.

◆ SetMaxNNZ()

void mfem::NNLSSolver::SetMaxNNZ ( int  max_nnz)
inline

Set the maximum number of nonzeros required for the solution, as an early termination condition.

Definition at line 1278 of file solvers.hpp.

◆ SetMinNNZ()

void mfem::NNLSSolver::SetMinNNZ ( int  min_nnz)
inline

Set the minimum number of nonzeros required for the solution.

Definition at line 1274 of file solvers.hpp.

◆ SetNormalize()

void mfem::NNLSSolver::SetNormalize ( bool  n)
inline

Set a flag to determine whether to call NormalizeConstraints().

Definition at line 1299 of file solvers.hpp.

◆ SetOperator()

void mfem::NNLSSolver::SetOperator ( const Operator op)
overridevirtual

The operator must be a DenseMatrix.

Implements mfem::Solver.

Definition at line 3566 of file solvers.cpp.

◆ SetOuterIterations()

void mfem::NNLSSolver::SetOuterIterations ( int  n)
inline

Set the maximum number of outer iterations in Solve().

Definition at line 1290 of file solvers.hpp.

◆ SetQRResidualMode()

void mfem::NNLSSolver::SetQRResidualMode ( const QRresidualMode  qr_residual_mode)

Set the residual calculation mode for the NNLS solver. See QRresidualMode enum above for details.

Definition at line 3579 of file solvers.cpp.

◆ SetResidualChangeTolerance()

void mfem::NNLSSolver::SetResidualChangeTolerance ( double  tol)
inline

Set threshold on relative change in residual over nStallCheck_ iterations.

Definition at line 1281 of file solvers.hpp.

◆ SetRHSDelta()

void mfem::NNLSSolver::SetRHSDelta ( double  d)
inline

Set RHS vector constant shift, defining rhs_lb and rhs_ub in Solve().

Definition at line 1287 of file solvers.hpp.

◆ SetStallCheck()

void mfem::NNLSSolver::SetStallCheck ( int  n)
inline

Set the number of iterations to use for stall checking.

Definition at line 1296 of file solvers.hpp.

◆ SetTolerance()

void mfem::NNLSSolver::SetTolerance ( double  tol)
inline

Definition at line 1271 of file solvers.hpp.

◆ SetVerbosity()

void mfem::NNLSSolver::SetVerbosity ( int  v)
inline

Set verbosity. If set to 0: print nothing; if 1: just print results; if 2: print short update on every iteration; if 3: print longer update each iteration.

Definition at line 1269 of file solvers.hpp.

◆ SetZeroTolerance()

void mfem::NNLSSolver::SetZeroTolerance ( double  tol)
inline

Definition at line 1284 of file solvers.hpp.

◆ Solve()

void mfem::NNLSSolver::Solve ( const Vector rhs_lb,
const Vector rhs_ub,
Vector soln 
) const

Solve the NNLS problem. Specifically, we find a vector soln, such that rhs_lb < mat*soln < rhs_ub is satisfied, where mat is the DenseMatrix input to SetOperator().

The method by which we find the solution is the active-set method developed by Lawson and Hanson (1974) using lapack. To decrease rounding errors in the case of very tight tolerances, we have the option to compute the residual using the QR factorization of A, by res = b - Q*Q^T*b. This residual calculation results in less rounding error, but is more computationally expensive. To select whether to use the QR residual method or not, see set_qrresidual_mode above.

Definition at line 3668 of file solvers.cpp.


The documentation for this class was generated from the following files: