commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Cedric Martin <bugv...@gmail.com>
Subject [math] Jama Matrix to Math Commons (Least squares and Recursive least squares)
Date Wed, 27 Apr 2011 13:52:19 GMT
Hi all,

I have a simplistic implementation of least squares using Jama Matrix which
I would like to migrate to Math Commons if possible.  I'm running into
issues where the LUDecomposition requires a square matrix, and what I want
to offer is a rectangular matrix.  The following code will hopefully clarify
(note that the following code does produce the expected results, using Jama
Matrix)):


 Matrix matrixX = new Matrix(*length, order*);

Matrix matrixY = new Matrix(length, 1);

  for (int j = 0; j < this.order; j++) {

 for (int i = 0; i < length; i++) {

 matrixX.set(i, j, Math.pow(i + offset, j));

 }

}


 double[] values = super.getValues();


 for (int i = 0; i < length; i++) {

 matrixY.set(i, 0, values[i]);

}


 double[] result = { 0.0, 0.0 };


 if (length >= this.order) {

 result = matrixX.solve(matrixY).getRowPackedCopy();

}


Would anyone be able to help me with this?  Am I simply be using the wrong
objects?

I also have to build a simple Recursive least squares implementation using
similar objects (RealMatrix I'm assuming), would anyone be able to point me
in the right direction for this as well, while using the Commons Math
library?


Thank you very much!

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message