Eigen-unsupported  3.4.90 (git rev 67eeba6e720c5745abc77ae6c92ce0a44aa7b7ae)
Eigen::NNLS< MatrixType_ > Class Template Reference

Detailed Description

template<class MatrixType_>
class Eigen::NNLS< MatrixType_ >

Implementation of the Non-Negative Least Squares (NNLS) algorithm.

Template Parameters
MatrixTypeThe type of the system matrix \(A\).

This class implements the NNLS algorithm as described in "SOLVING LEAST SQUARES PROBLEMS", Charles L. Lawson and Richard J. Hanson, Prentice-Hall, 1974. This algorithm solves a least squares problem iteratively and ensures that the solution is non-negative. I.e.

\[ \min \left\Vert Ax-b\right\Vert_2^2\quad s.t.\, x\ge 0 \]

The algorithm solves the constrained least-squares problem above by iteratively improving an estimate of which constraints are active (elements of \(x\) equal to zero) and which constraints are inactive (elements of \(x\) greater than zero). Each iteration, an unconstrained linear least-squares problem solves for the components of \(x\) in the (estimated) inactive set and the sets are updated. The unconstrained problem minimizes \(\left\Vert A^Nx^N-b\right\Vert_2^2\), where \(A^N\) is a matrix formed by selecting all columns of A which are in the inactive set \(N\).

See the wikipedia page on non-negative least squares for more background information.

Note
Please note that it is possible to construct an NNLS problem for which the algorithm does not converge. In practice these cases are extremely rare.

Public Types

typedef Matrix< Scalar, RowsAtCompileTime, 1 > RhsVectorType
 
typedef Matrix< Scalar, ColsAtCompileTime, 1 > SolutionVectorType
 

Public Member Functions

template<typename MatrixDerived >
NNLS< MatrixType > & compute (const EigenBase< MatrixDerived > &A)
 
ComputationInfo info () const
 
Index iterations () const
 
Index maxIterations () const
 
 NNLS (const MatrixType &A, Index max_iter=-1, Scalar tol=NumTraits< Scalar >::dummy_precision())
 Constructs a NNLS sovler and initializes it with the given system matrix A. More...
 
NNLS< MatrixType > & setMaxIterations (Index maxIters)
 
NNLS< MatrixType > & setTolerance (const Scalar &tolerance)
 
const SolutionVectorTypesolve (const RhsVectorType &b)
 Solves the NNLS problem. More...
 
Scalar tolerance () const
 
const SolutionVectorTypex () const
 Returns the solution if a problem was solved. If not, an uninitialized vector may be returned.
 

Member Typedef Documentation

◆ RhsVectorType

template<class MatrixType_ >
typedef Matrix<Scalar, RowsAtCompileTime, 1> Eigen::NNLS< MatrixType_ >::RhsVectorType

Type of a column vector of the system matrix \(A\).

◆ SolutionVectorType

template<class MatrixType_ >
typedef Matrix<Scalar, ColsAtCompileTime, 1> Eigen::NNLS< MatrixType_ >::SolutionVectorType

Type of a row vector of the system matrix \(A\).

Constructor & Destructor Documentation

◆ NNLS()

template<typename MatrixType >
Eigen::NNLS< MatrixType >::NNLS ( const MatrixType &  A,
Index  max_iter = -1,
Scalar  tol = NumTraits<Scalar>::dummy_precision() 
)

Constructs a NNLS sovler and initializes it with the given system matrix A.

Parameters
ASpecifies the system matrix.
max_iterSpecifies the maximum number of iterations to solve the system.
tolSpecifies the precision of the optimum. This is an absolute tolerance on the gradient of the Lagrangian, \(A^T(Ax-b)-\lambda\) (with Lagrange multipliers \(\lambda\)).

Member Function Documentation

◆ compute()

template<typename MatrixType >
template<typename MatrixDerived >
NNLS< MatrixType > & Eigen::NNLS< MatrixType >::compute ( const EigenBase< MatrixDerived > &  A)

Initializes the solver with the matrix A for further solving NNLS problems.

This function mostly initializes/computes the preconditioner. In the future we might, for instance, implement column reordering for faster matrix vector products.

◆ info()

template<class MatrixType_ >
ComputationInfo Eigen::NNLS< MatrixType_ >::info ( ) const
inline
Returns
Success if the iterations converged, and an error values otherwise.

◆ iterations()

template<class MatrixType_ >
Index Eigen::NNLS< MatrixType_ >::iterations ( ) const
inline
Returns
the number of iterations (least-squares solves) performed during the last solve

◆ maxIterations()

template<class MatrixType_ >
Index Eigen::NNLS< MatrixType_ >::maxIterations ( ) const
inline
Returns
the max number of iterations. It is either the value set by setMaxIterations or, by default, twice the number of columns of the matrix.

◆ setMaxIterations()

template<class MatrixType_ >
NNLS<MatrixType>& Eigen::NNLS< MatrixType_ >::setMaxIterations ( Index  maxIters)
inline

Sets the max number of iterations. Default is twice the number of columns of the matrix. The algorithm requires at least k iterations to produce a solution vector with k non-zero entries.

◆ setTolerance()

template<class MatrixType_ >
NNLS<MatrixType>& Eigen::NNLS< MatrixType_ >::setTolerance ( const Scalar &  tolerance)
inline

Sets the tolerance threshold used by the stopping criteria.

This is an absolute tolerance on the gradient of the Lagrangian, \(A^T(Ax-b)-\lambda\) (with Lagrange multipliers \(\lambda\)).

◆ solve()

template<typename MatrixType >
const NNLS< MatrixType >::SolutionVectorType & Eigen::NNLS< MatrixType >::solve ( const RhsVectorType b)

Solves the NNLS problem.

The dimension of b must be equal to the number of rows of A, given to the constructor.

Returns
The approximate solution vector \( x \). Use info() to determine if the solve was a success or not.
See also
info()

◆ tolerance()

template<class MatrixType_ >
Scalar Eigen::NNLS< MatrixType_ >::tolerance ( ) const
inline
Returns
the tolerance threshold used by the stopping criteria.
See also
setTolerance()

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