Fast non-negative least squares.
- [b,xi] = fastnnls(x,y,tol,b0,eqconst,xi);
Solves the equation xb = y subject to the constraint that b is non-negative. The inputs are the matrix of predictor variables x, vector or matrix of predicted variables y. Optional inputs include: tolerance on the size of a regression coefficient that is considered zero, tol, initial guess for the regression vectors, b0, the equality constraints matrix, eqconst, containing a value of NaN to indicate an unconstrained value or any finite value to indicate a constrained value. The optional input xi is the cached inverses output by a previous run of fastnnls (see outputs) or 0 (zero) to disable caching.
The outputs are the non-negatively constrained least squares solution, b, and the cache of x inverses, xi. If input y is a matrix, the result is the solution for each column of y calculated independently.
NOTE: The function fasternnls performs the same operation with the same regression rules but is optimized for matrix performance. In general fasternnls will give far better performance than fastnnls and will always give the same result.
FASTNNLS is fastest when a good estimate of the regression vector b0 is input. This eliminates much of the computation involved in determining which coefficients will be nonzero in the final regression vector. This makes it very useful in alternating least squares routines. Note that the input b0 must be a feasible (i.e. nonnegative) solution.
The FASTNNLS algorithm is based on work by Bro and de Jong, J. Chemo., 11(5), 393-401, 1997.
- x = the matrix of predictor variables,
- y = vector or matrix of predicted variables. If (y) is a matrix, the result is the solution for each column calculated independently.
- tol = tolerance on the size of a regression coefficient that is considered zero. Not supplied or empty matrix is implies the default value of tol = max(size(x))\*norm(x,1)\*eps).
- b0 = initial guess for the regression vectors. Default or empty matrix is interpreted as no known intial guess,
- eqconst = equality constraints matrix equal in size to b0 and containing a value of NaN to indicate an value not equality-constrained or any finite value to indicate an equality-constrained value. An empty matrix indicates no equality constraints on any elements.
- xi = cached inverses output by a previous run of fastnnls (see outputs) or 0 (zero) to disable caching. An empty matrix is valid as a placeholder in the inputs.