where Q = ATA and c = −ATy. This problem is convex, as Q is positive semidefinite and the non-negativity constraints form a convex feasible set.[7]
Algorithms
The first widely used algorithm for solving this problem is an active-set method published by Lawson and Hanson in their 1974 book Solving Least Squares Problems.[5]: 291 In pseudocode, this algorithm looks as follows:[1][2]
Inputs:
a real-valued matrix A of dimension m × n,
a real-valued vector y of dimension m,
a real value ε, the tolerance for the stopping criterion.
Initialize:
Set P = ∅.
Set R = {1, ..., n}.
Set x to an all-zero vector of dimension n.
Set w = AT(y − Ax).
Let wR denote the sub-vector with indexes from R
Main loop: while R ≠ ∅ and max(wR) > ε:
Let j in R be the index of max(wR) in w.
Add j to P.
Remove j from R.
Let AP be A restricted to the variables included in P.
Let s be vector of same length as x. Let sP denote the sub-vector with indexes from P, and let sR denote the sub-vector with indexes from R.
Set sP = ((AP)TAP)−1 (AP)Ty
Set sR to zero
While min(sP) ≤ 0:
Let α = min xi/xi − si for i in P where si ≤ 0.
Set x to x + α(s − x).
Move to R all indices j in P such that xj ≤ 0.
Set sP = ((AP)TAP)−1 (AP)Ty
Set sR to zero.
Set x to s.
Set w to AT(y − Ax).
Output: x
This algorithm takes a finite number of steps to reach a solution and smoothly improves its candidate solution as it goes (so it can find good approximate solutions when cut off at a reasonable number of iterations), but is very slow in practice, owing largely to the computation of the pseudoinverse((AP)TAP)−1.[1] Variants of this algorithm are available in MATLAB as the routine lsqnonneg[8][1] and in SciPy as optimize.nnls.[9]
Many improved algorithms have been suggested since 1974.[1] Fast NNLS (FNNLS) is an optimized version of the Lawson–Hanson algorithm.[2] Other algorithms include variants of Landweber's gradient descent method[10] and coordinate-wise optimization based on the quadratic programming problem above.[7]
^Boutsidis, Christos; Drineas, Petros (2009). "Random projections for the nonnegative least-squares problem". Linear Algebra and Its Applications. 431 (5–7): 760–771. arXiv:0812.4547. doi:10.1016/j.laa.2009.03.026.
^ abFranc, Vojtěch; Hlaváč, Václav; Navara, Mirko (2005). "Sequential Coordinate-Wise Algorithm for the Non-negative Least Squares Problem". Computer Analysis of Images and Patterns. Lecture Notes in Computer Science. Vol. 3691. pp. 407–414. doi:10.1007/11556121_50. ISBN978-3-540-28969-2.
^"lsqnonneg". MATLAB Documentation. Retrieved October 28, 2022.