Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.

Thank you for your help.

share|improve this question

2 Answers 2

Have your tried Weka? It's Java and under GNU General Public License. It's mainly a GUI-Tool for experiments, but you can use it as a library too. It should have implementations of linear regressions.

share|improve this answer
    
Thank you for answer but Weka does not seem to have the features I need. I have not found non-negative linear regression, nor multiple linear regression. Maybe I've missed something? –  Cedric Buron Nov 26 '13 at 11:32
    
not sure what "logistic" means, but what about weka.sourceforge.net/doc.packages/supervisedAttributeScaling/…? –  Thomas Uhrig Nov 26 '13 at 12:43
    
Thank you much. Logistic regression is different from linear regression, quite far actually. It is actually a binary predictor. –  Cedric Buron Nov 26 '13 at 13:02
up vote 0 down vote accepted

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.