I am working on a Java project, and I have to compute a multiple linear regression, but I want the gotten parameters to be non-negative. Is there an existing commercial-friendly-licensed library to do such a thing? I’ve been looking for Non-Negative Least Squares libs, without success.
Answer
Well, I could not find any pure java library so I built it myself from the article of [1], wich can be found in [2] and [3]. I give the algorithm:
P, R are the active and the passive sets. t() is transpose
The problem is to solve Ax = b under the condition x>0
P=null R = {1,2,...,m} x = 0 w = t(A)*(b-A*x) while R<>null and max{wi|i in R}>0 do: j = argmax{wi|i in R} P = P U {j} R = R{j} s[P] = invert[t(A[P])A[P]]t(A[P])b while sp<=0 do: a = -min{xi/(di-xi)|i in P and di<0} x = x + a*s -x update(P) update(R) sP = invert[t(A[P])A[P]]t(A[P])b sR = 0 x = s w = t(A)*(b-A*x) return x
For the other definitions, I strongly advise to read the papers [2] and [3], which are online (see below for the links ๐ )
[1] Lawson, C. L., & Hanson, R. J. (1974). Solving least squares problems (Vol. 161). Englewood Cliffs, NJ: Prentice-hall. [2] Rasmus Bro et Sijmen De Jong : A fast non-negativity-constrained least squares algorithm. Journal of chemometrics, 11(5) :393โ401, 1997. http://www.researchgate.net/publication/230554373_A_fast_non-negativity-constrained_least_squares_algorithm/file/79e41501a40da0224e.pdf [3] Donghui Chen et Robert J Plemmons : Nonnegativity constraints in numerical analysis. In Symposium on the Birth of Numerical Analysis, pages 109โ140, 2009. http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.157.9203&rep=rep1&type=pdf