Solving matrices using decomposition

85 views
Skip to first unread message

Morten Wollsen

unread,
Sep 28, 2011, 7:58:30 AM9/28/11
to jblas-users
Hello

First a huge thank for creating this package!

I have some problems with the decompositions, and how to use the
results for solving a matrix as a linear system. Could you post an
example of how to do so?

Also an example of how to solve a linear system using SVD would be
appreciated.

Thanks

Morten

mikiobraun

unread,
Sep 30, 2011, 6:07:08 AM9/30/11
to jblas-users
Hi Morten,

I'm not sure if I've understood correctly what you're interested in.
Usually, the results are more stable numerically if you directly solve
the equation using one of the functions in the org.jblas.Solve class.

What you can do is to decompose a matrix first via SVD and then
compute the inverse of a vector quickly.

So in essence, you say that X = USV', where U and V are matrices with
the singular vectors in the columns, and S is a diagonal matrix which
contains the singular values. Then, you can compute the inverse by

X^-1 = V S^-1 U'

Computing the inverse of S is simple, you only have to invert the
elements on the diagonal. You should probably regularize a bit, for
example by mapping the entries s => 1 / (s + e) where e is small, for
example 10^-6 or so.

In code, this would look like this:

DoubleMatrix X = new DoubleMatrix(...);
DoubleMatrix y = new DoubleMatrix(...); // a vector

DoubleMatrix[] svd = Singular.sparseSVD(X);

double eps = 1e-6;

DoubleMatrix invS = svd.add(eps).rdiv(1.0);

DoubleMatrix z =
svd[2].mmul(DoubleMatrix.diag(invS).mmul(svd[0].transpose().mmul(y)));

If I'm not mistaken ;)

-M
Reply all
Reply to author
Forward
0 new messages