Java Non-negative multiple linear regression library

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.


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

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
        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. [3] Donghui Chen et Robert J Plemmons : Nonnegativity constraints in numerical analysis. In Symposium on the Birth of Numerical Analysis, pages 109โ€“140, 2009.

Leave a Reply

Your email address will not be published. Required fields are marked *