la4j没有正确计算矩阵的SVD?

时间:2018-05-22 18:15:15

标签: java linear-algebra la4j

我有以下矩阵:

 0.003,0.013,0.022,0.013,0.003
 0.013,0.060,0.098,0.060,0.013
 0.022,0.098,0.162,0.098,0.022
 0.013,0.060,0.098,0.060,0.013
 0.003,0.013,0.022,0.013,0.003

我正在尝试使用la4j来计算其奇异值分解,使用以下代码:

  SingularValueDecompositor SVD = new SingularValueDecompositor(A);
  Matrix[] factorization = SVD.decompose();

  Matrix U = factorization[0];
  Matrix D = factorization[1];
  Matrix V = factorization[2];

然而, U,D,V的结果依次为:

0.102,-0.826, 0.307,-0.456,-0.071
0.456,-0.175,-0.859,-0.155,-0.017
0.751, 0.423, 0.374,-0.337,-0.059
0.456,-0.320, 0.166, 0.740, 0.339
0.102,-0.076, 0.029, 0.327,-0.936

-----------
.2873094460,.0000000000,.0000000000,.0000000000,.0000000000
.0000000000,.0000000000,.0000000000,.0000000000,.0000000000
.0000000000,.0000000000,.0000000000,.0000000000,.0000000000
.0000000000,.0000000000,.0000000000,.0000000000,.0000000000
.0000000000,.0000000000,.0000000000,.0000000000,.0000000000

-----------
0.102,-0.051, 0.975,-0.148,-0.122
0.456, 0.870, 0.030, 0.186, 0.027
0.751,-0.481,-0.015, 0.374, 0.253
0.456,-0.079,-0.221,-0.627,-0.586
0.102, 0.061,-0.009,-0.640, 0.759

并且这三个矩阵相乘

0.003,-0.001,0.028,-0.004,-0.004
0.013,-0.007,0.128,-0.019,-0.016
0.022,-0.011,0.210,-0.032,-0.026
0.013,-0.007,0.128,-0.019,-0.016
0.003,-0.001,0.028,-0.004,-0.004

这不是A.我认为问题的一部分可能是实际的对角线奇异值小于0.001(除了第一个),因此它们不会出现。 (小数是10位的原因是因为我将小数格式设置为)。我的问题是,如何解决这个问题并获得所有奇异值?

1 个答案:

答案 0 :(得分:1)

奇异值分解尝试将矩阵A = U * D * V'分解为V',其中V// Instead of A = U.multiply(D.multiply(V)); // Try A = U.multiply(D.multiply(V.transpose())); // You should get back: 0.0030 0.0134 0.0220 0.0134 0.0030 0.0134 0.0597 0.0984 0.0597 0.0134 0.0220 0.0984 0.1620 0.0984 0.0220 0.0134 0.0597 0.0984 0.0597 0.0134 0.0030 0.0134 0.0220 0.0134 0.0030 的转置。

{{1}}