OpenMS
Loading...
Searching...
No Matches
NonNegativeLeastSquaresSolver Class Reference

Wrapper for a non-negative least squares (NNLS) solver. More...

#include <OpenMS/ML/NNLS/NonNegativeLeastSquaresSolver.h>

Public Types

enum  RETURN_STATUS { SOLVED , ITERATION_EXCEEDED }
 

Static Public Member Functions

static Int solve (const Matrix< double > &A, const Matrix< double > &b, Matrix< double > &x)
 Solve the non-negative least square problem Ax=b, where x>0.
 
static Int solve (double *A, int A_rows, int A_cols, std::vector< double > &b, std::vector< double > &x)
 Solve the non-negative least square problem Ax=b, where x>0. Works in-place.
 
static Int solve (Matrix< double > &A, std::vector< double > &b, std::vector< double > &x)
 Solve the non-negative least square problem Ax=b using Matrix and vectors.
 

Detailed Description

Wrapper for a non-negative least squares (NNLS) solver.

It solves Ax=b, where x>0 in the least squares sense (i.e. minimum residual)

Member Enumeration Documentation

◆ RETURN_STATUS

Enumerator
SOLVED 
ITERATION_EXCEEDED 

Member Function Documentation

◆ solve() [1/3]

static Int solve ( const Matrix< double > &  A,
const Matrix< double > &  b,
Matrix< double > &  x 
)
static

Solve the non-negative least square problem Ax=b, where x>0.

This overload copies the input matrix and vector before solving, preserving the originals.

Parameters
[in]AInput matrix A of size m x n
[in]bInput vector (OpenMS::Matrix with one column) b of size m x 1
[out]xOutput vector (OpenMS::Matrix with one column) with non-negative least square solution of size n x 1
Returns
status of solution (either NonNegativeLeastSquaresSolver::SOLVED, NonNegativeLeastSquaresSolver::ITERATION_EXCEEDED)
Exceptions
Exception::InvalidParametersif Matrix dimensions do not fit

◆ solve() [2/3]

static Int solve ( double *  A,
int  A_rows,
int  A_cols,
std::vector< double > &  b,
std::vector< double > &  x 
)
static

Solve the non-negative least square problem Ax=b, where x>0. Works in-place.

This version works directly on raw buffers and modifies inputs in-place for efficiency.

Parameters
[in,out]APointer to matrix data of size m x n (need memory-contiguous representation in column-major order, i.e., A_rows * A_cols doubles). Must be non-null and point to a buffer of at least A_rows * A_cols doubles. The caller retains ownership and must ensure A remains valid for the duration of this call. Modified in-place by the solver; contents are undefined after the call. Passing nullptr or an insufficiently sized buffer results in undefined behavior.
[in]A_rowsNumber of rows in A (must be > 0)
[in]A_colsNumber of columns in A (must be > 0)
[in,out]bInput vector b of size m. Modified in-place by the solver.
[out]xOutput vector with non-negative least square solution of size n.
Returns
status of solution (either NonNegativeLeastSquaresSolver::SOLVED, NonNegativeLeastSquaresSolver::ITERATION_EXCEEDED)
Exceptions
Exception::InvalidParametersif A_rows does not match b.size()
Note
For a safer interface with bounds checking, prefer the Matrix<double>& overload. A future revision may adopt std::span for improved pointer safety.

◆ solve() [3/3]

static Int solve ( Matrix< double > &  A,
std::vector< double > &  b,
std::vector< double > &  x 
)
static

Solve the non-negative least square problem Ax=b using Matrix and vectors.

This overload works with OpenMS Matrix and std::vector, modifying inputs in-place for efficiency.

Parameters
[in,out]AInput matrix A of size m x n. Modified in-place by the solver.
[in,out]bInput vector b of size m. Modified in-place by the solver.
[out]xOutput vector with non-negative least square solution of size n.
Returns
status of solution (either NonNegativeLeastSquaresSolver::SOLVED, NonNegativeLeastSquaresSolver::ITERATION_EXCEEDED)
Exceptions
Exception::InvalidParametersif Matrix dimensions do not fit