gpt4 book ai didi

java SVD JAMA 错误结果

转载 作者:行者123 更新时间:2023-12-02 00:22:51 27 4
gpt4 key购买 nike

我有这个数组

double a[][] = {{1,1,1}, {0,1,1} , { 1,0,0}
,{0,1,0},{1,0,0},{1,0,1},{1,1,1},{1,1,1},{1,0,1},{0,2,0},{0,1,1}};

我想要获得 SVD(奇异值解压缩),这是代码

Matrix A = new Matrix(a);
SingularValueDecomposition s = A.svd();
Matrix U = s.getU();
Matrix S = s.getS();
Matrix V = s.getV();

Matrix K = U.times(S.times(V.inverse()));
System.out.println("A=\n" + A);
System.out.println("U=\n" + U);
System.out.println("S=\n" + S);
System.out.println("V=\n" + V);
System.out.println("K=\n" + K);

我使用了 JAMA 库,得到了这些结果

U=
0.42012156898152025 -0.07479925424066838 -0.04597243910578701
0.29948675880470416 0.20009225506128975 0.4078276625537902
0.12063481017681585 -0.27489150930195816 -0.4538001016595771
0.15756100229407313 0.3046476172068067 -0.2006466962808193
0.12063481017681585 -0.27489150930195816 -0.4538001016595771
0.2625605666874469 -0.379446871447475 0.15467425717503247
0.42012156898152014 -0.0747992542406683 -0.04597243910578692
0.42012156898152014 -0.0747992542406683 -0.04597243910578692
0.2625605666874469 -0.379446871447475 0.15467425717503247
0.31512200458814627 0.6092952344136134 -0.4012933925616386
0.29948675880470416 0.20009225506128975 0.4078276625537902

S=
4.098871971532176 0.0 0.0
0.0 2.361570801317849 0.0
0.0 0.0 1.2736686819384786

V=
0.49446664222485476 -0.6491757618976977 -0.5779909773443018
0.6458223761096932 0.7194469174866516 -0.2555574131873014
0.581735505399926 -0.24691489036406603 0.7749947346102383

但是V错了,应该是这样的

V= -0.49446664222485476 0.6491757618976977 -0.5779909773443018
-0.6458223761096932 0.7194469174866516 -0.2555574131873014
-0.581735505399926 0.24691489036406603 0.7749947346102383

这确实是一个拥抱错误,因为在 multibluein USV 之后我得到了这个 matirx,只需看看 E-16

K=
1.0000000000000013 1.0000000000000004 1.000000000000001
4.996003610813204E-16 1.0 0.9999999999999998
1.0000000000000002 -3.885780586188048E-16 8.881784197001252E-16
-1.1102230246251565E-16 1.0000000000000002 1.3877787807814457E-16
1.0000000000000002 -3.885780586188048E-16 8.881784197001252E-16
1.0000000000000004 -5.551115123125783E-16 1.0000000000000004
1.0000000000000009 1.0000000000000002 1.0000000000000007
1.0000000000000009 1.0000000000000002 1.0000000000000007
1.0000000000000004 -5.551115123125783E-16 1.0000000000000004
-2.220446049250313E-16 2.0000000000000004 2.7755575615628914E-16
4.996003610813204E-16 1.0 0.9999999999999998

请帮帮我,我该怎么办,哪里错了,JAMA错了吗?!

最佳答案

结果看起来正确。在矩阵 K 中,像 1.0000000000000013 和 4.996003610813204E-16 这样的值分别[非常接近]1 和 0。这里发生了浮点错误,这就是数字略有偏差的原因。 Matlab 也做同样的事情。

关于java SVD JAMA 错误结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10615757/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com