![]() |
OpenMS
|
Wrapper around the Lawson-Hanson non-negative least squares (NNLS) Fortran routine. More...
#include <OpenMS/ML/NNLS/NonNegativeLeastSquaresSolver.h>
Public Types | |
| enum | RETURN_STATUS { SOLVED , ITERATION_EXCEEDED } |
| Return status of solve. More... | |
Static Public Member Functions | |
| static Int | solve (const Matrix< double > &A, const Matrix< double > &b, Matrix< double > &x) |
Solve argmin_{x >= 0} ||Ax - b||_2 without modifying the inputs. | |
| static Int | solve (double *A, int A_rows, int A_cols, std::vector< double > &b, std::vector< double > &x) |
| In-place pointer overload of solve. | |
| static Int | solve (Matrix< double > &A, std::vector< double > &b, std::vector< double > &x) |
In-place Matrix / std::vector overload of solve. | |
Wrapper around the Lawson-Hanson non-negative least squares (NNLS) Fortran routine.
Solves the constrained least-squares problem argmin_{x >= 0} ||Ax - b||_2 with all entries of x required to be non-negative.
Three overloads are provided:
Matrix-based one that copies its inputs;Matrix / std::vector convenience wrapper around the pointer overload. | enum RETURN_STATUS |
|
static |
Solve argmin_{x >= 0} ||Ax - b||_2 without modifying the inputs.
Copies A and b internally, then runs NNLS on the copies and writes the result into x (resized to A.cols() rows, 1 column).
| [in] | A | Input matrix of size m x n. |
| [in] | b | Input vector as a column matrix of size m x 1. |
| [out] | x | Receives the non-negative solution as a column matrix of size n x 1. |
| Exception::InvalidParameter | when A.rows() does not match b.rows(), or when the underlying NNLS routine reports an invalid dimension (should not happen in practice). |
|
static |
In-place pointer overload of solve.
Operates directly on the caller-owned buffer for A and the b vector, so neither needs to be copied. After the call the contents of A and b are clobbered by the NNLS workspace and should not be read again.
| [in,out] | A | Pointer to a column-major double buffer of length A_rows * A_cols. The caller retains ownership, must keep the buffer valid for the duration of the call, and must not pass nullptr or a buffer that is shorter than required. The contents are unspecified on return. |
| [in] | A_rows | Number of rows of A (> 0). |
| [in] | A_cols | Number of columns of A (> 0). |
| [in,out] | b | Right-hand side of size A_rows; contents are unspecified on return. |
| [out] | x | Receives the non-negative solution of size A_cols (resized internally). |
| Exception::InvalidParameter | when A_rows does not match b.size(), or when the underlying NNLS routine reports an invalid dimension. |
Matrix overload for additional bounds checking; a future revision may adopt std::span.
|
static |
In-place Matrix / std::vector overload of solve.
Delegates to the pointer overload using A.data(), so A and b are clobbered by the NNLS workspace and should not be read after the call.
| [in,out] | A | Input matrix of size m x n; contents are unspecified on return. |
| [in,out] | b | Right-hand side of size m; contents are unspecified on return. |
| [out] | x | Receives the non-negative solution of size n (resized internally). |
| Exception::InvalidParameter | when A.rows() does not match b.size(), or when the underlying NNLS routine reports an invalid dimension. |